php include HOST_ROOT kernel prototypes tree_structure php function ar

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
include HOST_ROOT.'kernel/prototypes/tree_structure.php';
function articles () {
$Articles = new Articles();
$Articles->__set('object', $Articles);
$Articles->process();
return $Articles->__get('output');
}
class Articles EXTENDS dynamicModule {
protected $catId = 0;
protected $artId = 0;
protected $url = null;
protected $structure = null;
public function detectAction() {
Meta::addPath('<a href="'.HTTP_ROOT.'/articles/">Статьи</a>');
$this->structure = new ArticlesStructure();
$matches = array();
if($_SERVER['REQUEST_URI'] == '/articles/') {
$this->catId = 0;
$this->action = 'getCategories';
} elseif(preg_match('!/articles/(.*)?/!', $_SERVER['REQUEST_URI'], $matches) && strpos($_SERVER['REQUEST_URI'], '.html') === false) {
if(isset($matches[1])) {
$this->url = $matches[1];
$this->action = 'listCategory';
}
} elseif(preg_match('!/(.*)?.html!', $_SERVER['REQUEST_URI'], $matches)) {
$url = explode('/', $matches[1]);
$index = sizeof($url);
$this->url = $url[$index-1];
$this->action = 'getArticle';
} else {
header('HTTP/1.0 404 Not Found');
header('Location: '.HTTP_ROOT.'/errors/404.html');
}
}
protected function getCategories() {
$categories = $this->structure->listNodes($this->catId);
if(is_array($categories) && sizeof($categories)) {
$catWrapper = Template::getView(HOST_ROOT.'app/modules/articles/views/wrapper.categories.list');
$catItem = Template::getView(HOST_ROOT.'app/modules/articles/views/single.categories.list');
$cats = '';
foreach ($categories as $category) {
$cats .= Template::mountVars($catItem, $category);
}
$this->output .= Template::wrapContent($catWrapper, $cats);
unset($category, $categories, $catItem, $catWrapper);
}
}
protected function createCategory() {
$data['title'] = addslashes($_POST['title']);
$data['description'] = addslashes($_POST['description']);
$data['parent_id'] = (int) $_POST['parent_id'];
$this->structure->addNode($data);
}
protected function updateCategory() {
$data['title'] = addslashes($_POST['title']);
$data['description'] = addslashes($_POST['description']);
$data['parent_id'] = (int) $_POST['parent_id'];
$data['url'] = addslashes($_POST['url']);
$this->structure->saveNode((int) $_POST['cat_id'], $data);
}
protected function listCategory() {
$query = 'SELECT `id` FROM %sinfo_categories WHERE url="'.$this->url.'"';
$category = $this->db->getItem($query);
$this->catId = isset($category['id']) ? (int) $category['id'] : 0;
$this->getCategories();
$this->getArticles();
}
protected function getArticles() {
$articles = $this->structure->listItems($this->catId);
if(!is_array($articles) || !sizeof($articles)) {
$this->output = 'Ошибка! Данная категория не содержит материалов!<br />
Вы можете вернуться к предыдущей странице и выбрать другую ссылку.';
return ;
}
$artWrapper = Template::getView(HOST_ROOT.'app/modules/articles/views/wrapper.articles.list');
$artItem = Template::getView(HOST_ROOT.'app/modules/articles/views/single.articles.list');
$articlesList = '';
foreach ($articles as $article) {
$articlesList .= Template::mountVars($artItem, $article);
}
$articlesList = Template::wrapContent($artWrapper, $articlesList);
// Additional Data
$data['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
$this->output = Template::mountVars($articlesList, $data);
}
protected function getArticle() {
$query = sprintf('SELECT * FROM %sinfo_articles WHERE url="%s"', DB_PREFIX, $this->url);
$article = $this->db->getItem($query);
print_r($article);
}
}
class ArticlesStructure EXTENDS TreeStructure {
protected function setData() {
$this->_Q_NODES_TABLE = 'info_categories';
$this->_Q_ITEMS_TABLE = 'info_articles';
}
}