/** * Get a index saved in the database. * * @param integer $idIndex * @return Index */ public function getIndex($idIndex) { $sql = "SELECT * FROM cindex WHERE id_index = '" . $idIndex . "'"; $res = DB::query($sql); $row = mysqli_fetch_assoc($res); $index = new Index($row['id_index'], $row["month"], $row['price'], $row['main_index'], $row['variation']); DB::free($res); return $index; }
/** * Get a myth saved in the database. * * @param integer $idMyth * @return Myth */ public function getMyth($idMyth) { $sql = "SELECT * FROM myth WHERE id_myth = '" . $idMyth . "'"; $res = DB::query($sql); $row = mysqli_fetch_assoc($res); $myth = new Myth($row['id_myth'], $row['text_myth']); DB::free($res); return $myth; }
/** * Get a note saved in the database. * * @param integer $idNote * @return Note */ public function getNote($idNote) { $sql = "SELECT * FROM note WHERE id_note = '" . $idNote . "'"; $res = DB::query($sql); $row = mysqli_fetch_assoc($res); $note = new Note($row['id_note'], $row["note"], $row['note_text']); DB::free($res); return $note; }
/** * Get a post saved in the database. * * @param integer $idPost * @return Post */ public function getPost($idPost) { $sql = "SELECT * FROM post WHERE id_post = '" . $idPost . "'"; $res = DB::query($sql); $row = mysqli_fetch_assoc($res); $post = new Post($row['id_post'], $row["title"], $row['headline'], $row['date'], $row['body'], $row["source"], $row["post_image"], $row["type_image"], $row['category']); DB::free($res); return $post; }
/** * Get a provider saved in the database. * * @param integer $idProviderCategory * @return ProviderCategory */ public function getProviderCategory($idProviderCategory) { $sql = "SELECT * FROM provider_category WHERE id_provider_category = '" . $idProviderCategory . "'"; $res = DB::query($sql); $row = mysqli_fetch_assoc($res); $providerCategory = new ProviderCategory($row['id_provider_category'], $row['category_name']); DB::free($res); return $providerCategory; }
/** * Get a client saved in the database. * * @param integer $idClient * @return Client */ public function getClient($idClient) { $mcrypt = new MCrypt(); $sql = "SELECT * FROM client WHERE id_client = '" . $idClient . "'"; $res = DB::query($sql); $row = mysqli_fetch_assoc($res); $client = new Client($row['id_client'], $row["client_name"], $row['agent'], $row['address'], $row["phone"], $row['email'], $row['website'], $row['user'], $mcrypt->decrypt($row['password'])); DB::free($res); return $client; }
/** * Get the gallery linked to a slider. * * @param integer $idSlider * @return array */ public function getGallery($idSlider) { $gallery = array(); $sql = "SELECT * FROM slider_image \n\t\t\tWHERE id_slider = '" . $idSlider . "' \n\t\t\tORDER BY id_slider_image ASC"; $res = DB::query($sql); while ($row = mysqli_fetch_assoc($res)) { $gallery[] = new SliderImage($row['id_slider_image'], $row["id_slider"], $row['slider_image'], $row['type_image']); } DB::free($res); return $gallery; }
/** * Get the gallery linked to a post. * * @param integer $idPost * @return array */ public function getGallery($idPost) { $gallery = array(); $sql = "SELECT * FROM post_image \n\t\t\tWHERE id_post = '" . $idPost . "' \n\t\t\tORDER BY id_post_image ASC"; $res = DB::query($sql); while ($row = mysqli_fetch_assoc($res)) { $gallery[] = new PostImage($row['id_post_image'], $row["id_post"], $row['post_image'], $row['type_image']); } DB::free($res); return $gallery; }
/** * Get the gallery linked to a info. * * @param integer $idInfo * @return array */ public function getGallery($idInfo) { $gallery = array(); $sql = "SELECT * FROM info_file \n\t\t\tWHERE id_info = '" . $idInfo . "' \n\t\t\tORDER BY id_info_file ASC"; $res = DB::query($sql); while ($row = mysqli_fetch_assoc($res)) { $gallery[] = new InfoFile($row['id_info_file'], $row["id_info"], $row['info_file'], $row['type_file']); } DB::free($res); return $gallery; }
/** * Confirms the existence of the user. * * @param string $user * @param string $password * @return integer */ private function searchUser($user, $password) { /* Search for the user in the database */ $sql = "SELECT * FROM user WHERE user = '******'"; $res = DB::query($sql); $row = mysqli_fetch_assoc($res); /* If the user exists verify the password */ if (mysqli_num_rows($res)) { DB::free($res); $mcrypt = new MCrypt(); //echo $mcrypt->encrypt(""); if ($row["password"] === $mcrypt->encrypt($password)) { $res = 1; } else { $res = 0; } } else { $res = 0; } return $res; }
/** * Vytvoreni vypisu prispevku * * Type Popis Vars * 1 komentare sekce zamknute komentare 1/0 * 2 komentare článku zamknute komentare 1/0 * 3 prispevky v knize [polozek na stranu, povoleno prispivani 1/0, zamknuto 1/0] * 5 temata ve foru [polozek na stranu, povoleno prispivani 1/0, zamknuto 1/0] * 6 odpovedi na tema [polozek na stranu, povoleno prispivani 1/0, zamknuto 1/0, id tematu] * 7 vypis vzkazu [zamknuto 1/0] * 8 vypis pluginpostu [polozek na stranu, povoleno prispivani 1/0, zamknuto 1/0, plugin flag, radit sestupne 1/0, [titulek / null]] * * @param int $type typ prispevku * @param int $home id polozky asociovane s komentari * @param mixed $vars promenna nastaveni podle typu * @param bool $force_locked vynutit zamknuty stav * @param string|null $url vlastni url nebo null (= automaticky) * @return string */ function _postsOutput($type, $home, $vars, $force_locked = false, $url = null) { global $_lang; /* --- typ --- */ // vychozi hodnoty $desc = "DESC "; $ordercol = 'id'; $countcond = "type=" . $type . " AND xhome=-1 AND home=" . $home; $locked_textid = ''; $autolast = false; $postlink = false; $pluginflag = null; // url if (!isset($url)) { $url = _indexOutput_url; } $url_html = _htmlStr($url); switch ($type) { // komentare v sekci case 1: $posttype = 1; $xhome = -1; $subclass = "comments"; $title = $_lang['posts.comments']; $addlink = $_lang['posts.addcomment']; $nopostsmessage = $_lang['posts.nocomments']; $postsperpage = _commentsperpage; $canpost = _loginright_postcomments; $locked = _boolean($vars); $replynote = true; break; // komentare u clanku // komentare u clanku case 2: $posttype = 2; $xhome = -1; $subclass = "comments"; $title = $_lang['posts.comments']; $addlink = $_lang['posts.addcomment']; $nopostsmessage = $_lang['posts.nocomments']; $postsperpage = _commentsperpage; $canpost = _loginright_postcomments; $locked = _boolean($vars); $replynote = true; break; // prispevky v knize // prispevky v knize case 3: $posttype = 3; $xhome = -1; $subclass = "book"; $title = null; $addlink = $_lang['posts.addpost']; $nopostsmessage = $_lang['posts.noposts']; $postsperpage = $vars[0]; $canpost = $vars[1]; $locked = _boolean($vars[2]); $replynote = true; break; // temata ve foru // temata ve foru case 5: $posttype = 5; $xhome = -1; $subclass = "book"; $title = null; $addlink = $_lang['posts.addtopic']; $nopostsmessage = $_lang['posts.notopics']; $postsperpage = $vars[0]; $canpost = $vars[1]; $locked = _boolean($vars[2]); $replynote = true; $ordercol = 'bumptime'; $locked_textid = '3'; break; // odpovedi v tematu // odpovedi v tematu case 6: $posttype = 5; $xhome = $vars[3]; $subclass = "book"; $title = null; $addlink = $_lang['posts.addanswer']; $nopostsmessage = $_lang['posts.noanswers']; $postsperpage = $vars[0]; $canpost = $vars[1]; $locked = _boolean($vars[2]); $replynote = false; $desc = ""; $countcond = "type=5 AND xhome=" . $xhome . " AND home=" . $home; $autolast = isset($_GET['autolast']); $postlink = true; break; // odpovedi v konverzaci // odpovedi v konverzaci case 7: $posttype = 6; $xhome = null; $subclass = "book"; $title = null; $addlink = $_lang['posts.addanswer']; $nopostsmessage = $_lang['posts.noanswers']; $postsperpage = _messagesperpage; $canpost = true; $locked = _boolean($vars[0]); $replynote = false; $desc = ""; $countcond = "type=6 AND home=" . $home; $locked_textid = '4'; $autolast = true; break; // plugin posty // plugin posty case 8: $posttype = 7; $xhome = -1; $subclass = "book"; $title = isset($vars[5]) ? $vars[5] : null; $addlink = $_lang['posts.addpost']; $nopostsmessage = $_lang['posts.noposts']; $postsperpage = $vars[0]; $canpost = $vars[1]; $locked = _boolean($vars[2]); $replynote = true; $pluginflag = $vars[3]; $countcond .= " AND flag=" . $pluginflag; if (!$vars[4]) { $desc = ''; } break; } // vynutit uzamceni parametrem if ($force_locked) { $locked = true; } // extend $callback = null; _extend('call', 'posts.output', array('type' => $type, 'home' => $home, 'xhome' => $xhome, 'vars' => $vars, 'post_type' => $posttype, 'plugin_flag' => $pluginflag, 'canpost' => &$canpost, 'locked' => &$locked, 'autolast' => &$autolast, 'post_link' => &$postlink, 'posts_per_page' => &$postsperpage, 'sql_desc' => &$desc, 'sql_ordercol' => &$ordercol, 'sql_countcond' => &$countcond, 'callback' => &$callback)); /* --- vystup --- */ $output = "\n <div class='anchor'><a name='posts'></a></div>\n <div class='posts-" . $subclass . "'>\n "; if ($title != null) { $output .= "<h2>" . $title . _linkRss($home, $posttype) . "</h2>\n"; } $output .= "<div class='posts-form' id='post-form'>\n"; /* --- priprava strankovani --- */ $paging = _resultPaging($url_html, $postsperpage, "posts", $countcond, "#posts", null, $autolast); /* --- zprava --- */ if (isset($_GET['r'])) { switch ($_GET['r']) { case 0: $output .= _formMessage(2, $_lang['posts.failed']); break; case 1: $output .= _formMessage(1, $_lang[$type != 5 ? 'posts.added' : 'posts.topicadded']); break; case 2: $output .= _formMessage(2, str_replace("*postsendexpire*", _postsendexpire, $_lang['misc.requestlimit'])); break; case 3: $output .= _formMessage(2, $_lang['posts.guestnamedenied']); break; case 4: $output .= _formMessage(2, $_lang['xsrf.msg']); break; } } /* --- formular nebo odkaz na pridani --- */ if (!$locked and (isset($_GET['addpost']) or isset($_GET['replyto']))) { // nacteni cisla prispevku pro odpoved if ($xhome == -1) { if (isset($_GET['replyto']) and $_GET['replyto'] != -1) { $reply = intval($_GET['replyto']); if ($replynote) { $output .= "<p>" . $_lang['posts.replynote'] . " (<a href='" . $url_html . "#posts'>" . $_lang['global.cancel'] . "</a>).</p>"; } } else { $reply = -1; } } else { $reply = $xhome; } // formular nebo prihlaseni if ($canpost) { $form = _uniForm("postform", array('posttype' => $type, 'pluginflag' => $pluginflag, 'posttarget' => $home, 'xhome' => $reply, 'url' => $url)); $output .= $form[0]; } else { $loginform = _uniForm("login", array(), true); $output .= "<p>" . $_lang['posts.loginrequired'] . "</p>" . $loginform[0]; } } else { if (!$locked) { $output .= "<a href='" . _addGetToLink($url_html, "addpost&page=" . $paging[2]) . "#posts'><strong>" . $addlink . " ></strong></a>"; } else { $output .= "<img src='" . _templateImage("icons/lock.png") . "' alt='stop' class='icon' /> <strong>" . $_lang['posts.locked' . $locked_textid] . "</strong>"; } } $output .= "</div>\n<div class='hr'><hr /></div>\n\n"; /* --- vypis --- */ if (_pagingmode == 1 or _pagingmode == 2) { $output .= $paging[0]; } // zaklad query if ($type == 5) { $sql = "SELECT id,author,guest,subject,time,ip,locked,bumptime,sticky,(SELECT COUNT(id) FROM `" . _mysql_prefix . "-posts` WHERE type=5 AND xhome=post.id) AS answer_count"; } else { $sql = "SELECT id,xhome,subject,text,author,guest,time,ip" . _extend('buffer', 'posts.columns'); } $sql .= " FROM `" . _mysql_prefix . "-posts` AS post"; // podminky a razeni $sql .= " WHERE post.type=" . $posttype . (isset($xhome) ? " AND post.xhome=" . $xhome : '') . " AND post.home=" . $home . (isset($pluginflag) ? " AND post.flag=" . $pluginflag : ''); $sql .= " ORDER BY " . ($type == 5 ? 'sticky DESC,' : '') . $ordercol . ' ' . $desc . $paging[1]; // dotaz $query = DB::query($sql); unset($sql); // nacteni prispevku do pole $items = array(); if ($type == 5) { $item_ids_with_answers = array(); } while ($item = DB::row($query)) { $items[$item['id']] = $item; if ($type == 5 && $item['answer_count'] != 0) { $item_ids_with_answers[] = $item['id']; } } // uvolneni dotazu DB::free($query); if ($type == 5) { // posledni prispevek (pro vypis temat) if (!empty($item_ids_with_answers)) { $topicextra = DB::query("SELECT * FROM (SELECT id,xhome,author,guest FROM `" . _mysql_prefix . "-posts` AS reply WHERE type=5 AND home=" . $home . " AND xhome IN(" . implode(',', $item_ids_with_answers) . ") ORDER BY reply.id DESC) AS replies GROUP BY xhome"); while ($item = DB::row($topicextra)) { if (!isset($items[$item['xhome']])) { if (_dev) { trigger_error('Nenalezen domovsky prispevek pro odpoved #' . $item['id'], E_USER_WARNING); } continue; } $items[$item['xhome']]['_lastpost'] = $item; } } } elseif (!empty($items)) { // odpovedi (pro komentare) $answers = DB::query("SELECT id,xhome,text,author,guest,time,ip FROM `" . _mysql_prefix . "-posts` WHERE type=" . $posttype . " AND home=" . $home . (isset($pluginflag) ? " AND flag=" . $pluginflag : '') . " AND xhome IN(" . implode(',', array_keys($items)) . ") ORDER BY id"); while ($item = DB::row($answers)) { if (!isset($items[$item['xhome']])) { if (_dev) { trigger_error('Nenalezen domovsky prispevek pro odpoved #' . $item['id'], E_USER_WARNING); } continue; } if (!isset($items[$item['xhome']]['_answers'])) { $items[$item['xhome']]['_answers'] = array(); } $items[$item['xhome']]['_answers'][] = $item; } DB::free($answers); } // vypis if (!empty($items)) { // vypis prispevku nebo temat if ($type != 5) { $hl = true; foreach ($items as $item) { // nacteni autora if ($item['guest'] == "") { $author = _linkUser($item['author'], "post-author"); } else { $author = "<span class='post-author-guest' title='" . _showIP($item['ip']) . "'>" . $item['guest'] . "</span>"; } // odkazy pro spravu $post_access = _postAccess($item); if ($type < 6 or $type > 7 or $post_access) { $actlinks = " <span class='post-actions'>"; if (($type < 6 or $type > 7) && !$locked) { $actlinks .= "<a href='" . _addGetToLink($url_html, "replyto=" . $item['id']) . "#posts'>" . $_lang['posts.reply'] . "</a>"; } if ($post_access) { $actlinks .= (($type < 6 or $type > 7) ? " " : '') . "<a href='index.php?m=editpost&id=" . $item['id'] . "'>" . $_lang['global.edit'] . "</a>"; } $actlinks .= "</span>"; } else { $actlinks = ""; } // avatar if (_show_avatars) { $avatar = _getAvatar($item['author']); } else { $avatar = null; } // prispevek $hl = !$hl; _extend('call', 'posts.post', array('item' => &$item, 'avatar' => &$avatar, 'type' => $type)); if (null === $callback) { $output .= "<div id='post-" . $item['id'] . "' class='post" . ($hl ? ' post-hl' : '') . (isset($avatar) ? ' post-withavatar' : '') . "'><div class='post-head'>" . $author; if ($type < 6 || $type > 7) { $output .= ", <span class='post-subject'>" . $item['subject'] . "</span> "; } $output .= "<span class='post-info'>(" . _formatTime($item['time']) . ")</span>" . $actlinks . ($postlink ? "<a class='post-postlink' href='" . _addGetToLink($url_html, 'page=' . $paging[2]) . "#post-" . $item['id'] . "'><span>#" . str_pad($item['id'], 6, '0', STR_PAD_LEFT) . "</span></a>" : '') . "</div><div class='post-body" . (isset($avatar) ? ' post-body-withavatar' : '') . "'>" . $avatar . '<div class="post-body-text">' . _parsePost($item['text']) . "</div></div></div>\n"; } else { $output .= call_user_func($callback, array('item' => $item, 'avatar' => $avatar, 'author' => $author, 'actlinks' => $actlinks, 'page' => $paging[2], 'postlink' => $postlink)); } // odpovedi if (($type < 6 || $type > 7) && isset($item['_answers'])) { foreach ($item['_answers'] as $answer) { // jmeno autora if ($answer['guest'] == "") { $author = _linkUser($answer['author'], "post-author"); } else { $author = "<span class='post-author-guest' title='" . _showIP($answer['ip']) . "'>" . $answer['guest'] . "</span>"; } // odkazy pro spravu if (_postAccess($answer)) { $actlinks = " <span class='post-actions'><a href='index.php?m=editpost&id=" . $answer['id'] . "'>" . $_lang['global.edit'] . "</a></span>"; } else { $actlinks = ""; } // avatar if (_show_avatars) { $avatar = _getAvatar($answer['author']); } else { $avatar = null; } _extend('call', 'posts.post', array('item' => &$answer, 'avatar' => &$avatar, 'type' => $type)); if (null === $callback) { $output .= "<div id='post-" . $answer['id'] . "' class='post-answer" . (isset($avatar) ? ' post-answer-withavatar' : '') . "'><div class='post-head'>" . $author . " " . $_lang['posts.replied'] . " <span class='post-info'>(" . _formatTime($answer['time']) . ")</span>" . $actlinks . "</div><div class='post-body" . (isset($avatar) ? ' post-body-withavatar' : '') . "'>" . $avatar . '<div class="post-body-text">' . _parsePost($answer['text']) . "</div></div></div>\n"; } else { $output .= call_user_func($callback, array('item' => $answer, 'avatar' => $avatar, 'author' => $author, 'actlinks' => $actlinks, 'page' => $paging[2], 'postlink' => $postlink)); } } } } if (_pagingmode == 2 or _pagingmode == 3) { $output .= "<br />" . $paging[0]; } } else { // tabulka s tematy $hl = false; $output .= "\n<table class='topic-table'>\n<thead><tr><td colspan='2'><strong>" . $_lang['posts.topic'] . "</strong></td><td><strong>" . $_lang['global.answersnum'] . "</strong></td><td><strong>" . $_lang['global.lastanswer'] . "</strong></td></tr></thead>\n<tbody>\n"; foreach ($items as $item) { // nacteni autora if ($item['guest'] == "") { $author = _linkUser($item['author'], "post-author", false, false, 16); } else { $author = "<span class='post-author-guest' title='" . _showIP($item['ip']) . "'>" . _cutStr($item['guest'], 16) . "</span>"; } // nacteni jmena autora posledniho prispevku if (isset($item['_lastpost'])) { if ($item['_lastpost']['author'] != -1) { $lastpost = _linkUser($item['_lastpost']['author'], "post-author", false, false, 16); } else { $lastpost = "<span class='post-author-guest'>" . _cutStr($item['_lastpost']['guest'], 16) . "</span>"; } } else { $lastpost = "-"; } // vyber ikony if ($item['sticky']) { $icon = 'sticky'; } elseif ($item['locked']) { $icon = 'locked'; } elseif ($item['answer_count'] == 0) { $icon = 'new'; } elseif ($item['answer_count'] < _topic_hot_ratio) { $icon = 'normal'; } else { $icon = 'hot'; } // mini strankovani $tpages = ''; $tpages_num = ceil($item['answer_count'] / _commentsperpage); if ($tpages_num == 0) { $tpages_num = 1; } if ($tpages_num > 1) { $tpages .= '<span class=\'topic-pages\'>'; for ($i = 1; $i <= 3 && $i <= $tpages_num; ++$i) { $tpages .= "<a href='index.php?m=topic&id=" . $item['id'] . "&page=" . $i . "#posts'>" . $i . '</a>'; } if ($tpages_num > 3) { $tpages .= "<a href='index.php?m=topic&id=" . $item['id'] . "&page=" . $tpages_num . "'>" . $tpages_num . ' →</a>'; } $tpages .= '</span>'; } // vystup radku $output .= "<tr class='topic-" . $icon . ($hl ? ' topic-hl' : '') . "'><td class='topic-icon-cell'><a href='index.php?m=topic&id=" . $item['id'] . "'><img src='" . _templateImage('icons/topic-' . $icon . '.png') . "' alt='" . $_lang['posts.topic.' . $icon] . "' /></a></td><td class='topic-main-cell'><a href='index.php?m=topic&id=" . $item['id'] . "'>" . $item['subject'] . "</a>" . $tpages . "<br />" . $author . " <small class='post-info'>(" . _formatTime($item['time']) . ")</small></td><td>" . $item['answer_count'] . "</td><td>" . $lastpost . ($item['answer_count'] != 0 ? "<br /><small class='post-info'>(" . _formatTime($item['bumptime']) . ")</small>" : '') . "</td></tr>\n"; $hl = !$hl; } $output .= "</tbody></table><br />\n\n"; if (_pagingmode == 2 or _pagingmode == 3) { $output .= $paging[0] . "<br />"; } // posledni odpovedi $output .= "\n<div class='hr'><hr /></div><br />\n<h3>" . $_lang['posts.forum.lastact'] . "</h3>\n"; $query = DB::query("SELECT topic.id AS topic_id,topic.subject AS topic_subject,answer.author,answer.guest,answer.time FROM `" . _mysql_prefix . "-posts` AS answer JOIN `" . _mysql_prefix . "-posts` AS topic ON(topic.type=5 AND topic.id=answer.xhome) WHERE answer.type=5 AND answer.home=" . $home . " AND answer.xhome!=-1 ORDER BY answer.id DESC LIMIT " . _extratopicslimit); if (DB::size($query) != 0) { $output .= "<ul>\n"; while ($item = DB::row($query)) { if ($item['guest'] == "") { $author = _linkUser($item['author']); } else { $author = "<span class='post-author-guest'>" . $item['guest'] . "</span>"; } $output .= "<li><a href='index.php?m=topic&id=" . $item['topic_id'] . "'>" . $item['topic_subject'] . "</a> <small>(" . $_lang['global.postauthor'] . " " . $author . " " . _formatTime($item['time']) . ")</small></li>\n"; } $output .= "</ul>\n\n"; } else { $output .= "<p>" . $_lang['global.nokit'] . "</p>"; } } } else { $output .= "<p>" . $nopostsmessage . "</p>"; } $output .= "</div>"; return $output; }
$sql = 'SELECT img.id,img.prev,img.full,img.ord,img.home,img.title,gal.title AS gal_title,gal.title_seo,gal.var2 FROM `' . _mysql_prefix . '-images` AS img'; // join na galerii $sql .= ' JOIN `' . _mysql_prefix . '-root` AS gal ON(gal.id=img.home)'; // podminky $sql .= ' WHERE gal.visible=1'; if ($public) { $sql .= ' AND gal.public=1'; } $sql .= ' AND ' . _tmpSearchQuery('img', array('title')); // vykonani a nacteni vysledku $q = DB::query($sql . ' LIMIT 20'); while ($r = DB::row($q)) { $link = _addGetToLink(_linkRoot($r['home'], $r['title_seo']), 'page=' . _resultPagingGetItemPage($r['var2'], "images", "ord<" . $r['ord'] . " AND home=" . $r['home'])); $results[] = array($link, $r['gal_title'], ($r['title'] !== '' ? $r['title'] . '<br />' : '') . _galleryImage($r, 'search', 128, 128)); } DB::free($q); } // extend _extend('call', 'mod.search.results', array('results' => &$results, 'query' => $search_query, 'query_sql' => $search_query_sql)); // vypis vysledku if (count($results) != 0) { foreach ($results as $item) { $module .= "\n<h2 class='list-title'><a href='" . $item[0] . "'>" . $item[1] . "</a></h2>\n<p class='list-perex'>" . $item[2] . "</p>\n"; if (isset($item[3])) { $module .= "<div class='list-info'>" . $item[3] . "</div>\n"; } } } else { $module .= "<br />" . _formMessage(1, $_lang['mod.search.noresult']); } } else {
if (_checkboxLoad("users")) { $users_time = time() - $_POST['users-time'] * 7 * 24 * 60 * 60; $users_group = intval($_POST['users-group']); if ($users_group == -1) { $users_group = ""; } else { $users_group = " AND `group`=" . $users_group; } if ($prev) { $prev_count['admin.users.users'] = DB::count(_mysql_prefix . '-users', 'id!=0 AND activitytime<' . $users_time . $users_group); } else { $userids = DB::query("SELECT id FROM `" . _mysql_prefix . "-users` WHERE id!=0 AND activitytime<" . $users_time . $users_group); while ($userid = DB::row($userids)) { _deleteUser($userid['id']); } DB::free($userids); } } // udrzba if (_checkboxLoad('maintenance') && !$prev) { SL::doMaintenance(); } // optimalizace if (_checkboxLoad('optimize') && !$prev) { $tables = array(); $q = DB::query('SHOW TABLES LIKE \'' . _mysql_prefix . '-%\''); while ($r = DB::rown($q)) { DB::query('OPTIMIZE TABLE `' . $r[0] . '`'); } } // zprava
/** * List action * @param array $params * @param array $action * @param AdminBread $bread * @return array */ public static function listAction(array $params, array $action, AdminBread $bread) { /* ----- prepare query ----- */ // format condition if ('1' !== $action['query_cond']) { $cond = $bread->formatSql($action['query_cond'], $action['query_cond_params']); } else { $cond = $action['query_cond']; } // format sql $sql = $bread->formatSql($action['query'], array('columns' => $action['columns'], 'table' => '`' . $bread->formatTable($bread->table) . "`", 'table_alias' => $bread->tableAlias, 'cond' => $cond)); // add order by if (!empty($action['query_orderby'])) { $sql .= " ORDER BY {$action['query_orderby']}"; } /* ----- init paginator ----- */ if ($action['paginator']) { $total = DB::query_row('SELECT COUNT(*) total FROM `' . $bread->formatTable($bread->table) . '` ' . $bread->tableAlias . ' WHERE ' . $cond); $paging = _resultPaging(_htmlStr($params['url']), $action['paginator_size'], intval($total['total'])); $sql .= " {$paging[1]}"; } else { $paging = null; } /* ----- fetch data ----- */ $result = DB::query($sql); if (false === $result) { return array(null, self::ACTION_ERR); } /* ----- render ----- */ $out = $bread->render($action['template'], array('result' => $result, 'count' => DB::size($result), 'paging' => $paging, 'self' => $params['action'])); DB::free($result); // return return array(null, $out); }
/** * Sestavit a provest dotaz na cestu * @param array $columns * @param int $nodeId * @param int|null $nodeLevel * @return array */ public function loadPath(array $columns, $nodeId, $nodeLevel = null) { // zjistit uroven uzlu if (null === $nodeLevel) { $nodeLevel = DB::query_row('SELECT ' . $this->levelColumn . ' FROM `' . $this->table . '` WHERE ' . $this->idColumn . '=' . DB::val($nodeId)); if (false === $nodeLevel) { throw new RuntimeException(sprintf('Neexistujici uzel "%s"', $nodeId)); } $nodeLevel = $nodeLevel[$this->levelColumn]; } // pripravit sloupce $columns = array_merge(array($this->idColumn, $this->parentColumn, $this->levelColumn, $this->depthColumn), $columns); $columnCount = sizeof($columns); // sestavit dotaz $sql = 'SELECT '; for ($i = 0; $i <= $nodeLevel; ++$i) { for ($j = 0; $j < $columnCount; ++$j) { if (0 !== $i || 0 !== $j) { $sql .= ','; } $sql .= 'n' . $i . '.' . $columns[$j]; } } $sql .= ' FROM `' . $this->table . '` n0'; for ($i = 1; $i <= $nodeLevel; ++$i) { $sql .= sprintf(_nl . ' JOIN `%s` n%s ON(n%2$s.%s=n%s.%s)', $this->table, $i, $this->idColumn, $i - 1, $this->parentColumn); } $sql .= ' WHERE n0.' . $this->idColumn . '=' . DB::val($nodeId); // nacist uzly $nodes = array(); $nodeIndex = 0; $query = DB::query($sql); $row = DB::rown($query); for ($i = $nodeLevel * $columnCount; isset($row[$i]); $i -= $columnCount) { for ($j = 0; $j < $columnCount; ++$j) { $nodes[$nodeIndex][$columns[$j]] = $row[$i + $j]; } ++$nodeIndex; } DB::free($query); return $nodes; }
/** * Sestavit kod menu * @param int|null $ord_start minimalni poradove cislo * @param int|null $ord_end maximalni poradove cislo * @param string $parent_class trida hlavniho tagu menu * @return string */ function _templateMenu($ord_start = null, $ord_end = null, $parent_class = 'menu') { $output = ""; if (defined("_indexOutput_pid")) { $pid = _indexOutput_pid; } else { $pid = -1; } if (!_notpublicsite or _loginindicator) { // limit if ($ord_start === null or $ord_end === null) { $ord_limit = $inter_ord_limit = ""; } else { $ord_limit = " AND page.ord>=" . intval($ord_start) . " AND page.ord<=" . intval($ord_end); $inter_ord_limit = " AND inter.ord>=" . intval($ord_start) . " AND inter.ord<=" . intval($ord_end); } // nacteni dat $tree = array(); $query = DB::query("SELECT page.id,page.type,page.title,page.title_seo,page.level,page.var1,page.var2,page.intersection FROM `" . _mysql_prefix . "-root` AS page LEFT JOIN `" . _mysql_prefix . "-root` AS inter ON(page.intersection=inter.id) WHERE page.visible=1 AND page.type!=4 AND (inter.id IS NULL" . $ord_limit . " OR inter.visible=1 AND inter.var2=1" . $inter_ord_limit . ") ORDER BY page.intersection,page.ord"); while ($item = DB::row($query)) { if ($item['intersection'] == -1) { $tree[$item['id']] = $item; } else { if (!isset($tree[$item['intersection']]['children'])) { $tree[$item['intersection']]['children'] = array(); } $tree[$item['intersection']]['children'][] = $item; } } DB::free($query); // sestaveni kodu $output .= "<" . _template_menu_parent . " class='" . $parent_class . "'>\n"; $counter = 0; $last = sizeof($tree) - 1; foreach ($tree as $item) { // rozsireni, priprava $classes = array(); _extend('call', 'tpl.menu.item', array('item' => &$item, 'classes' => &$classes, 'sub' => false)); // zpracovani polozky if (empty($item['children'])) { // stranka if ($item['id'] == $pid) { $classes[] = 'act'; } if ($item['type'] == 6 and $item['var1'] == 1) { $target = " target='_blank'"; } else { $target = ""; } $link = "<a href='" . _linkRoot($item['id'], $item['title_seo']) . "'" . $target . ">" . $item['title'] . "</a>"; } else { // polozky rozcestniku $icounter = 0; $ilast = sizeof($item['children']) - 1; $childactive = false; $link_sublistitems = ''; foreach ($item['children'] as $iitem) { _extend('call', 'tpl.menu.item', array('item' => &$iitem, 'sub' => true)); $classes[] = 'menu-item-' . str_replace('/', '_', $iitem['title_seo']); if ($iitem['id'] == $pid) { $classes[] = 'act'; $childactive = true; } if ($icounter === 0) { $classes[] = 'first'; } if ($icounter !== 0 && $icounter === $ilast) { $classes[] = 'last'; } if ($iitem['type'] == 6 and $iitem['var1'] == 1) { $target = " target='_blank'"; } else { $target = ""; } $link_sublistitems .= " <li" . (!empty($classes) ? ' class="' . implode(' ', $classes) . '"' : '') . "><a href='" . _linkRoot($iitem['id'], $iitem['title_seo']) . "'" . $target . ">" . $iitem['title'] . "</a></li>\n"; $classes = array(); ++$icounter; } if (!$childactive && $item['id'] == $pid) { $childactive = true; } $classes[] = 'menu-dropdown'; if ($childactive || $item['id'] == $pid) { $classes[] = 'act'; } $link = "<a href='" . _linkRoot($item['id'], $item['title_seo']) . "' class='menu-dropdown-link'>" . $item['title'] . "</a>"; if ($link_sublistitems !== '') { $link .= "\n<ul class='menu-dropdown-list'>\n" . $link_sublistitems . "</ul>\n"; } } $classes[] = 'menu-item-' . str_replace('/', '_', $item['title_seo']); if ($counter === 0) { $classes[] = 'first'; } if ($counter !== 0 && $counter === $last) { $classes[] = 'last'; } $output .= "<" . _template_menu_child . (!empty($classes) ? ' class="' . implode(' ', $classes) . '"' : '') . ">" . $link . "</" . _template_menu_child . ">\n"; ++$counter; } $output .= "</" . _template_menu_parent . ">"; } return $output; }
/** * Sestavit vystup pro toolbar * * @return string */ protected function toolbarOutput() { $now = microtime(true); // ziskat sql log $sqlLog = $this->logger->getLog(); // zjistit neoptimalizovane query $sqlLogSlow = array(); $explainExtraSlowIndicators = array('Using temporary' => 0); foreach ($sqlLog as $sqlIndex => $sql) { if (1 !== preg_match('/^(?!\\s*EXPLAIN)(\\s*[a-z_]+)*\\s*SELECT/i', $sql)) { continue; } $explainQuery = DB::query('EXPLAIN ' . $sql, true, false); if ($explainQuery) { while ($explainRow = DB::row($explainQuery)) { $explainExtra = preg_split('/\\s*;\\s*/', $explainRow['Extra']); for ($i = 0; isset($explainExtra[$i]); ++$i) { if (isset($explainExtraSlowIndicators[$explainExtra[$i]])) { $sqlLogSlow[$sqlIndex] = $explainRow['Extra']; break 2; } } } DB::free($explainQuery); } } $sqlLogSlowCount = sizeof($sqlLogSlow); // vystup $out = '<div id="devkit-toolbar">'; // info $out .= '<div class="devkit-section devkit-info">' . _systemversion . ' ' . SL::$states[_systemstate] . _systemstate_revision . '</div>'; // cas $out .= '<div class="devkit-section devkit-time">' . round(($now - SL::$start) * 1000) . 'ms</div>'; // pamet $out .= '<div class="devkit-section devkit-memory">' . number_format(round(memory_get_peak_usage() / 1048576), 1, '.', ',') . 'MB</div>'; // databaze $out .= '<div class="devkit-section devkit-database devkit-toggleable">' . sizeof($sqlLog) . (0 !== $sqlLogSlowCount ? ' <span class="devkit-blood">(' . $sqlLogSlowCount . ' slow)</span>' : '') . '</div>'; $out .= '<div class="devkit-content"><div><div class="devkit-heading">SQL log</div><ol>'; foreach ($sqlLog as $sqlIndex => $sql) { if (isset($sqlLogSlow[$sqlIndex])) { $out .= '<li class="devkit-slow-query" title="' . _htmlStr($sqlLogSlow[$sqlIndex]) . '"'; } else { $out .= '<li'; } $out .= '><input type="text" size="' . strlen($sql) . '" class="devkit-selectable" value="' . _htmlStr($sql) . "\" readonly></li>\n"; } $out .= '</ol></div></div>'; // request $out .= '<div class="devkit-section devkit-request devkit-toggleable">' . '$_GET(' . sizeof($_GET) . ') $_POST(' . sizeof($_POST) . ') $_COOKIE(' . sizeof($_COOKIE) . ') $_SESSION(' . sizeof($_SESSION) . ')</div>'; $out .= '<div class="devkit-content"><div>'; foreach (array('_GET', '_POST', '_COOKIE', '_SESSION') as $globalVarName) { $globalVarSize = sizeof($GLOBALS[$globalVarName]); if (0 === $globalVarSize) { continue; } $out .= '<div class="devkit-heading devkit-hideshow">$' . $globalVarName . ' (' . $globalVarSize . ')</div>'; if ($globalVarSize > 0) { $out .= '<div class="devkit-request-dump devkit-hideshow-target">' . $this->dump($GLOBALS[$globalVarName]) . '</div>'; } } $out .= '</div></div>'; // login $out .= '<a href="' . _indexroot . 'index.php?m=login"><div class="devkit-section devkit-login">' . (_loginindicator ? _loginname : '---') . '</div></a>'; // close $out .= '<div class="devkit-close">×</div>'; $out .= '</div>'; return $out; }
/** * Get all system tables * @return array */ protected function _get_tables() { $tables = array(); $q = DB::query('SHOW TABLES LIKE \'' . _mysql_prefix . '-%\''); while ($r = DB::rown($q)) { $tables[] = $r[0]; } DB::free($q); return $tables; }
/** * Inicializovat system * * @param string $root relativni cesta do korenoveho adresare * @param string|null $configFile cesta ke konfiguracnimu skriptu nebo null(= vychozi) * @param bool $envChanges provest zmeny v prostredi (error reporting, locale, header, ...) 1/0 * @param bool $lightMode odlehceny mod (pouze pripojeni k db, bez session, nastaveni, lokalizace, atd) 1/0 * @param bool $databaseEnabled inicializovat pripojeni k databazi 1/0 * @param bool $runCron automaticky spustit cron, je-li aktivovan 1/0 */ public static function init($root, $configFile = null, $envChanges = true, $lightMode = false, $databaseEnabled = true, $runCron = true) { if (self::$initialized) { throw new BadMethodCallException(); } $initialized = true; self::$start = microtime(true); /* ---- konfigurace ---- */ if (null === $configFile) { self::$configFile = $root . 'config.php'; } else { self::$configFile = $configFile; } self::$envChanges = $envChanges; self::$lightMode = $lightMode; self::$databaseEnabled = $databaseEnabled; self::$imageError = $root . 'remote/image_error.png'; // soubor s nastavenim require self::$configFile; // doplneni konfigurace (kvuli kompatibilite) if (!isset($locale)) { $locale = array('czech', 'utf8', 'cz_CZ'); } if (!isset($timezone)) { $timezone = 'Europe/Prague'; } if (!isset($geo)) { $geo = array(50.5, 14.26, 90.583333); } if (!isset($port)) { // pokud neni uveden $port, muze byt definovan jako soucast $server (server:port) if (false !== ($serverColonPos = strpos($server, ':'))) { $port = (int) substr($server, $serverColonPos + 1); $server = substr($server, 0, $serverColonPos); } else { $port = ini_get('mysqli.default_port'); } } // systemove konstanty define('_indexroot', $root); define('_core', '1'); define('_nl', "\n"); define('_sessionprefix', md5($server . $database . $user . $prefix) . '-'); if (!defined('_administration')) { define('_administration', 0); } define('_dev', isset($dev) ? $dev : true); // vyvojovy mod 1/0 define('_systemstate', 0); // 0 = beta, 1 = rc, 2 = stable define('_systemstate_revision', 0); // revize systemu define('_systemversion', '7.5.5'); // verze systemu define('_mysql_prefix', $prefix); define('_mysql_db', $database); define('_upload_dir', _indexroot . 'upload/'); define('_plugin_dir', _indexroot . 'plugins/common/'); define('_tmp_dir', _indexroot . 'data/tmp/'); define('_void_file', _indexroot . 'data/void.nodelete'); define('_geo_latitude', $geo[0]); define('_geo_longitude', $geo[1]); define('_geo_zenith', $geo[2]); /* ---- autoloader ---- */ require _indexroot . 'require/class/class_loader.php'; self::$classLoader = new ClassLoader(); self::$classLoader->setDebug(_dev)->registerClassMap(array('AdminBread' => _indexroot . 'require/class/admin_bread.php', 'Color' => _indexroot . 'require/class/color.php', 'DBDump' => _indexroot . 'require/class/dbdump.php', 'KZip' => _indexroot . 'require/class/kzip.php', 'KZipStream' => _indexroot . 'require/class/kzip.php', 'TreeManager' => _indexroot . 'require/class/tree_manager.php', 'TreeReader' => _indexroot . 'require/class/tree_reader.php', 'LangPack' => _indexroot . 'require/class/lang_pack.php', 'FileCache' => _indexroot . 'require/class/file_cache.php'))->register(); /* ---- upravy PHP prostredi ---- */ if ($envChanges) { // kontrola verze PHP a pritomnosti rozsireni if (version_compare(PHP_VERSION, '5.1.0', '<')) { _systemFailure('Je vyžadováno PHP 5.1.0 nebo novější.'); } if (!extension_loaded('mbstring')) { _systemFailure('Chybí PHP rozšíření <code>mbstring</code> (Multibyte String Functions).'); } if (!extension_loaded('mysqli')) { _systemFailure('Chybí PHP rozšíření <code>mysqli</code>, které je potřebné pro práci s databází.'); } // kontrola a nastaveni $_SERVER['REQUEST_URI'] if (!isset($_SERVER['REQUEST_URI'])) { if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; } elseif (isset($_SERVER['HTTP_REQUEST_URI'])) { $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_REQUEST_URI']; } else { if (isset($_SERVER['SCRIPT_NAME'])) { $_SERVER['HTTP_REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; } else { $_SERVER['HTTP_REQUEST_URI'] = $_SERVER['PHP_SELF']; } if (!empty($_SERVER['QUERY_STRING'])) { $_SERVER['HTTP_REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; } $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_REQUEST_URI']; } } // vyruseni register_globals if (ini_get('register_globals') != '') { foreach (array_keys($_REQUEST) as $key) { unset($GLOBALS[$key]); } } // vypnuti magic_quotes if (get_magic_quotes_gpc()) { $search = array(&$_GET, &$_POST, &$_COOKIE); for ($i = 0; isset($search[$i]); ++$i) { foreach ($search[$i] as &$value) { if (is_array($value)) { $search[] =& $value; } else { $value = stripslashes($value); } } unset($search[$i]); } if (function_exists('set_magic_quotes_runtime')) { @set_magic_quotes_runtime(0); } unset($search, $i, $value); } // hlaseni chyb $err_rep = E_ALL; if (_dev) { $disable = array(); } else { $disable = array('E_NOTICE ', 'E_USER_NOTICE', 'E_DEPRECATED', 'E_STRICT'); } for ($i = 0; isset($disable[$i]); ++$i) { if (defined($disable[$i])) { $err_rep &= ~constant($disable[$i]); } } error_reporting($err_rep); // casove pasmo @setlocale(LC_TIME, $locale); if (function_exists('date_default_timezone_set')) { date_default_timezone_set($timezone); } // interni kodovani mb_internal_encoding('UTF-8'); // vychozi hlavicky if (!defined('_header')) { header('Content-Type: text/html; charset=UTF-8'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() - 604800) . ' GMT'); } elseif (_header) { header(_header); } } /* ---- nacteni funkci ---- */ require _indexroot . 'require/functions.php'; if (isset($_GET['___identify'])) { echo 'SunLight CMS ', _systemversion, ' ', self::$states[_systemstate], _systemstate_revision; exit; } /* ---- pripojeni k mysql ---- */ if ($databaseEnabled) { $con = @mysqli_connect($server, $user, $password, $database, $port); if (!is_object($con)) { _systemFailure('Připojení k databázi se nezdařilo. Důvodem je pravděpodobně výpadek serveru nebo chybné přístupové údaje.</p><hr /><pre>' . _htmlStr(mysqli_connect_error()) . '</pre><hr /><p>Zkontrolujte přístupové údaje v souboru <em>config.php</em>.'); } $con->set_charset('utf8'); DB::$con = $con; DB::query('SET sql_mode=\'\''); } /* ---- konstanty nastaveni, jazykovy soubor, motiv, session ---- */ if (!$lightMode) { // definovani konstant nastaveni $query = DB::query('SELECT * FROM `' . _mysql_prefix . '-settings`', true); $directive = array('banned' => ''); if (DB::error() != false) { _systemFailure('Připojení k databázi proběhlo úspěšně, ale dotaz na databázi selhal.</p><hr /><pre>' . _htmlStr(DB::error()) . '</pre><hr /><p>Zkontrolujte, zda je databáze správně nainstalovaná.'); } while ($item = DB::row($query)) { if (isset($directive[$item['var']])) { // direktiva $directive[$item['var']] = $item['val']; } elseif ($item['var'][0] === '.') { // nastaveni zacinajici teckou self::$settings[substr($item['var'], 1)] = $item['val']; } else { // konstanta define('_' . $item['var'], $item['val']); } } DB::free($query); // nastavit interval pro maintenance self::$cronIntervals['maintenance'] = _maintenance_interval; // ip adresa klienta if (empty($_SERVER['REMOTE_ADDR'])) { $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; } if (_proxy_mode && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } define('_userip', trim(($addr_comma = strrpos($ip, ',')) === false ? $ip : substr($ip, $addr_comma + 1))); // poinstalacni kontrola if (_install_check) { require _indexroot . 'require/installcheck.php'; } // kontrola verze databaze if (!defined('_dbversion') or !_checkVersion('database', _dbversion)) { _systemFailure('Verze nainstalované databáze není kompatibilní s verzí systému. Pokud byl právě aplikován patch pro přechod na novější verzi, pravděpodobně jste zapoměl(a) spustit skript pro aktualizaci databáze.'); } // inicializace session require _indexroot . 'require/session.php'; // inicializace jazykoveho souboru if (_loginindicator and _language_allowcustom and _loginlanguage != "") { $language = _loginlanguage; } else { $language = _language; } $langfile = _indexroot . 'plugins/languages/' . $language . '.php'; $langfile_default = _indexroot . 'plugins/languages/default.php'; if (file_exists($langfile)) { $GLOBALS['_lang'] = (require $langfile); define('_active_language', $language); } else { if (file_exists($langfile_default)) { $GLOBALS['_lang'] = (require $langfile_default); define('_active_language', 'default'); } else { _systemFailure('Zvolený ani přednastavený jazykový soubor nebyl nalezen.'); } } // kontrola verze jazykoveho souboru if (!_checkVersion('language_file', $GLOBALS['_lang']['main.version'])) { DB::query('UPDATE `' . _mysql_prefix . '-settings` SET val="default" WHERE var="language"'); _systemFailure('Zvolený jazykový soubor není kompatibilní s verzí systému.'); } // kontrola blokace IP if ($directive['banned'] !== '' && !_administration) { $directive['banned'] = explode("\n", $directive['banned']); for ($i = 0; isset($directive['banned'][$i]); ++$i) { if (0 === strncmp($directive['banned'][$i], _userip, strlen($directive['banned'][$i]))) { header('HTTP/1.0 403 Forbidden'); if (defined('_header')) { die('Your IP address is banned'); } require _indexroot . 'require/ipban.php'; die; } } } // motiv $template = _indexroot . 'plugins/templates/' . _template . '/template.php'; $template_config = _indexroot . 'plugins/templates/' . _template . '/config.php'; if (!file_exists($template) or !file_exists($template_config)) { DB::query('UPDATE `' . _mysql_prefix . '-settings` SET val=\'default\' WHERE var=\'template\''); _systemFailure('Zvolený motiv ' . _template . ' nebyl nalezen. Přepnuto na výchozí motiv.'); } require $template_config; // kontrola verze motivu if (!_checkVersion('template', _template_version) and !_administration) { _systemFailure('Zvolený motiv není kompatibilní s verzí systému.'); } // nacist rozsireni _extendLoad(); // udalost inicializace systemu _extend('call', 'sys.init'); // systemove callbacky _extend('reg', 'sys.cron.maintenance', array(__CLASS__, 'doMaintenance')); // cron if (_cron_auto && $runCron) { self::runCron(); } } }
/** * Obnovit stav hloubky v cele vetvi * @param int $currentNodeId * @parma bool|null $isRootNode */ protected function doRefreshDepth($currentNodeId, $isRootNode = null) { // zjistit korenovy uzel $rootNodeId = $currentNodeId; if (true !== $isRootNode && null !== $currentNodeId) { $rootNodeId = $this->getRoot($currentNodeId); } // pripravit frontu a depth mapu $queue = array(array($rootNodeId, 0, array())); $depthmap = array(); // traverzovat frontu for ($i = 0; isset($queue[$i]); ++$i) { // vyhledat potomky if (null !== $queue[$i][0]) { $childCondition = $this->parentColumn . '=' . DB::val($queue[$i][0]); } else { $childCondition = $this->parentColumn . ' IS NULL'; } $children = DB::query($s = 'SELECT ' . $this->idColumn . ',' . $this->depthColumn . ' FROM `' . $this->table . '` WHERE ' . $childCondition); if (DB::size($children) > 0) { // uzel ma potomky, pridat do fronty if (null !== $queue[$i][0]) { $childParents = array_merge(array($queue[$i][0]), $queue[$i][2]); } else { $childParents = $queue[$i][2]; } while ($child = DB::row($children)) { $queue[] = array($child[$this->idColumn], $child[$this->depthColumn], $childParents); } } DB::free($children); // aktualizovat urovne nadrazenych uzlu if (null !== $queue[$i][0] && !isset($depthmap[$queue[$i][0]])) { $depthmap[$queue[$i][0]] = 0; } for ($j = 0; isset($queue[$i][2][$j]); ++$j) { $currentDepth = $j + 1; if (!isset($depthmap[$queue[$i][2][$j]]) || $depthmap[$queue[$i][2][$j]] < $currentDepth) { $depthmap[$queue[$i][2][$j]] = $currentDepth; } } unset($queue[$i]); } // aplikovat depth mapu foreach ($depthmap as $nodeId => $newDepth) { DB::update($this->table, $this->idColumn . '=' . DB::val($nodeId), array($this->depthColumn => $newDepth)); } }