function get_config($name) { $db = new DB_SQL(); if (RDBMS == '4.1') { if (!defined('STATEMENT_SET')) { $query = sprintf("\n PREPARE \n get_config \n FROM 'SELECT \n config_value \n FROM \n %1\$s \n WHERE \n config_name = ?'", TABLE_CONFIG); $db->query($query); $query = sprintf("SET @config_name = '%1\$s'", $name); $db->query($query); $query = "EXECUTE get_config USING @config_name"; // definicja warunku::true define('STATEMENT_SET', true); } else { $query = sprintf("SET @config_name = '%1\$s'", $name); $db->query($query); $query = "EXECUTE get_config USING @config_name"; } } else { $query = sprintf("\n SELECT\n config_value\n FROM\n %1\$s\n WHERE\n config_name = '%2\$s'", TABLE_CONFIG, $name); } $db->query($query); $db->next_record(); return $db->f('config_value'); }
require_once '../inc/admin_lib.php'; // mysql_server_version get_mysql_server_version(); $lang = get_config('language_set'); require_once 'i18n/' . $lang . '/i18n.php'; require_once PATH_TO_CLASSES . '/cls_fast_template.php'; require_once PATH_TO_CLASSES . '/cls_permissions.php'; // inicjowanie klasy, wkazanie katalogu przechowuj±cego szablony $ft = new FastTemplate('./templates/' . $lang . '/tpl'); // egzemplarz klasy obs³uguj±cej bazê danych Core $db = new DB_SQL(); // pobieramy poziom uprawnieñ $query = sprintf("\r\n SELECT \r\n permission_level \r\n FROM \r\n %1\$s \r\n WHERE \r\n login = '******'", TABLE_USERS, $_SESSION['login']); $db->query($query); $db->next_record(); $privileges = $db->f('permission_level'); // egzemplarz klasy do obs³ugi uprawnieñ $perms = new permissions(); $permarr = $perms->getPermissions($privileges); $ft->assign(array('PERMS_USER' => false, 'PERMS_WRITER' => false, 'PERMS_MODERATOR' => false, 'PERMS_TPLEDITOR' => false, 'PERMS_ADMIN' => false)); switch ($privileges) { case '1': $privilege_level = 1; $ft->assign('PERMS_USER', true); break; case '3': $privilege_level = 2; $ft->assign('PERMS_USER', true); $ft->assign('PERMS_WRITER', true); break; case '7':
require "inc/main_lib.php"; // mysql_server_version get_mysql_server_version(); $db = new DB_SQL(); $query = sprintf("\r\n SELECT \r\n b.*, a.id, a.title \r\n FROM \r\n %1\$s b \r\n LEFT JOIN \r\n %2\$s a \r\n ON \r\n b.comments_id = a.id \r\n GROUP BY \r\n date \r\n DESC \r\n LIMIT \r\n %3\$d", TABLE_COMMENTS, TABLE_MAIN, 10); $db->query($query); $rewrite = get_config('mod_rewrite'); $lang = get_config('language_set'); $ft = new FastTemplate('./templates/' . $lang . '/main/tpl/'); $ft->define('xml_feed', 'xml_feed.tpl'); $ft->define_dynamic('xml_row', 'xml_feed'); $http_root = get_httproot(); $ft->assign(array('MAINSITE_LINK' => 'http://' . $http_root, 'NEWS_FEED' => false)); if ($db->num_rows() > 0) { while ($db->next_record()) { $date = $db->f("date"); $title = $db->f("title"); $text = $db->f("text"); $author = $db->f("author"); $id = $db->f("id"); $image = $db->f("image"); $comments_allow = $db->f("comments_allow"); $comments = $db->f("comments"); $date = coreRssDateConvert($date); $pattern = array("&", "<br />", "<", ">"); $replacement = array(" & ", "<br />", "<", ">"); $text = str_replace($pattern, $replacement, $text); $permanent_link = (bool) $rewrite ? $http_root . '1,' . $id . ',1,item.html' : $http_root . 'index.php?p=1&id=' . $id . ''; $ft->assign(array('DATE' => $date, 'TITLE' => $title, 'AUTHOR' => $author, 'PERMALINK' => $permanent_link, 'TEXT' => $text, 'DISPLAY_XML' => true)); $ft->parse('XML_ROW', ".xml_row"); }
$ft->assign(array('TITLE' => $i18n['index'][0], 'ERROR_MSG' => '', 'LANG' => $lang)); // deklaracja zmiennej $p $p = empty($_GET['p']) ? '' : $_GET['p']; if ($p == 'log') { $login = trim($_POST['login']); $password = trim(md5($_POST['password'])); if (empty($login) || empty($password)) { // U�ytkownik nie uzupe�ni� wszystkich p�l::form $ft->assign('ERROR_MSG', $i18n['index'][1]); $ft->parse('ROWS', '.form_login'); } else { $db = new DB_SQL(); $query = sprintf("\n SELECT \n active \n FROM \n %1\$s \n WHERE \n login = '******' \n AND \n password = '******'", TABLE_USERS, $login, $password); $db->query($query); if ($db->num_rows()) { if ($db->f('active') != 'N') { // Rejestrujemy zmienne sesyjne $_SESSION['login'] = $login; $_SESSION['loggedIn'] = TRUE; header('Location: main.php'); break; } else { // U�ytkownik nie zaaktywowa� konta::db $ft->assign('ERROR_MSG', $i18n['index'][2]); $ft->parse('ROWS', '.form_login'); } } else { // Niepoprawne dane wej�cia<->wyj�cia::form, db $ft->assign('ERROR_MSG', $i18n['index'][3]); $ft->parse('ROWS', '.form_login'); }
$simple = 1; $replacement = array('&', '<br />', '<', '>'); $pattern = array(' & ', '<br />', '<', '>'); $data = str_replace($pattern, $replacement, $data); $rss = new rss_parser($data, $simple); $allItems = $rss->getAllItems(); $itemCount = count($allItems); $ft->define_dynamic('rss_row', 'main_site'); for ($y = 0; $y < 5; $y++) { $ft->assign(array('PERMA_LINK' => $allItems[$y]['LINK'], 'NEWS_TITLE' => $allItems[$y]['TITLE'], 'DATE' => $allItems[$y]['DATE'], 'NEWS_TEXT' => str_cut(strip_tags($allItems[$y]['DESCRIPTION'])) . '...')); $ft->parse('ROWS', '.rss_row'); } } else { $ft->assign('GET_RSS', false); } // Inicjowanie egzemplarza klasy do obs³ugi Bazy Danych $db = new DB_SQL(); // Zliczenie wszystkich publikowanych wpisów $query = sprintf("\r\n SELECT \r\n count(*) AS id \r\n FROM \r\n %1\$s \r\n WHERE \r\n published = '%2\$d' \r\n ORDER BY \r\n date", TABLE_MAIN, 1); $db->query($query); $db->next_record(); $published_items = $db->f('id'); // Zliczenie wszystkich nie publikowanych wpisów $query = sprintf("\r\n SELECT \r\n count(*) AS id \r\n FROM \r\n %1\$s \r\n WHERE \r\n published = '%2\$d' \r\n ORDER BY \r\n date", TABLE_MAIN, -1); $db->query($query); $db->next_record(); $nonpublished_items = $db->f('id'); // Zliczenie wszystkich wpisów $num_items = $published_items + $nonpublished_items; $ft->assign(array('COUNT_NOTES' => $num_items, 'PUBLISHED_NOTES' => $published_items, 'NONPUBLISHED_NOTES' => $nonpublished_items)); $ft->parse('ROWS', 'main_site');
} break; case "remark": // zmiana pozycji wybranej kategorii if ($permarr['moderator']) { $move = intval($_GET['move']); $query = sprintf("\n UPDATE \n %1\$s \n SET \n category_order = category_order + '%2\$d' \n WHERE \n category_id='%3\$d'", TABLE_CATEGORY, $move, $_GET['id']); $db->query($query); // instancja potrzebna $sql = new DB_SQL(); $query = sprintf("\n SELECT * FROM \n %1\$s \n WHERE \n category_parent_id = '0' \n ORDER BY \n category_order \n ASC", TABLE_CATEGORY); $sql->query($query); $i = 10; $inc = 10; while ($sql->next_record()) { $cid = $sql->f("category_id"); $query = sprintf("\n UPDATE \n %1\$s \n SET \n category_order = '{$i}' \n WHERE \n category_id = '{$cid}'", TABLE_CATEGORY); $db->query($query); $i += 10; } header("Location: main.php?p=9"); exit; } else { $monit[] = $i18n['edit_category'][6]; foreach ($monit as $error) { $ft->assign('ERROR_MONIT', $error); $ft->parse('ROWS', ".error_row"); } $ft->parse('ROWS', "error_reporting"); } break;
$rss = new rss_parser($data, $simple); $allItems = $rss->getAllItems(); $itemCount = count($allItems); $ft->define_dynamic("rss_row", "main_site"); function str_cut($s, $i = 110, $c = ' ') { return substr($s, 0, strrpos(substr($s, 0, $i), $c)); } for ($y = 0; $y < 5; $y++) { $ft->assign(array('PERMA_LINK' => $allItems[$y]['LINK'], 'NEWS_TITLE' => $allItems[$y]['TITLE'], 'DATE' => $allItems[$y]['DATE'], 'NEWS_TEXT' => str_cut(strip_tags($allItems[$y]['DESCRIPTION'])) . '...')); $ft->parse('ROWS', ".rss_row"); } } else { $ft->assign('CORE_RSS', false); } // Inicjowanie egzemplarza klasy do obs³ugi Bazy Danych $db = new DB_SQL(); // Zliczenie wszystkich publikowanych wpisów $query = sprintf("\n SELECT \n count(*) AS id \n FROM \n %1\$s \n WHERE \n published = 1\n ORDER BY \n date", TABLE_MAIN); $db->query($query); $db->next_record(); $published_items = $db->f("id"); // Zliczenie wszystkich nie publikowanych wpisów $query = sprintf("\n SELECT \n count(*) AS id \n FROM \n %1\$s \n WHERE \n published = -1\n ORDER BY \n date", TABLE_MAIN); $db->query($query); $db->next_record(); $nonpublished_items = $db->f("id"); // Zliczenie wszystkich wpisów $num_items = $published_items + $nonpublished_items; $ft->assign(array('COUNT_NOTES' => $num_items, 'PUBLISHED_NOTES' => $published_items, 'NONPUBLISHED_NOTES' => $nonpublished_items)); $ft->parse('ROWS', "main_site");
$lang = get_config('language_set'); require_once 'i18n/' . $lang . '/i18n.php'; if (isset($_COOKIE['devlog_design']) && is_dir('./templates/' . $lang . '/' . $_COOKIE['devlog_design'] . '/tpl/')) { $theme = $_COOKIE['devlog_design']; } elseif (is_dir('./templates/' . $lang . '/main/tpl')) { $theme = 'main'; } else { printf('<div style="font-family: Arial, sans-serif; font-size: 16px; background-color: #ccc; border: 1px solid red; padding: 15px; text-align: center;">%s</div>', $i18n['design'][0]); exit; } @setcookie('devlog_design', $theme, time() + 3600 * 24 * 365); // inicjowanie klasy, wkazanie katalogu przechowuj±cego szablony $ft = new FastTemplate('./templates/' . $lang . '/' . $theme . '/tpl/'); $db = new DB_SQL(); $ft->define('photo_main', 'photo_main.tpl'); $ft->assign('TITLE', get_config('title_page')); $query = sprintf("\r\n SELECT \r\n image \r\n FROM \r\n %1\$s \r\n WHERE \r\n id = '%2\$d' \r\n LIMIT 1", $table = empty($_GET['p']) ? TABLE_MAIN : TABLE_PAGES, $_GET['id']); $db->query($query); $db->next_record(); $image = $db->f('image'); if (!empty($image)) { list($width, $height) = getimagesize("photos/" . $image); $ft->assign(array('IMAGE_NAME' => $image, 'IMAGE_WIDTH' => $width, 'IMAGE_HEIGHT' => $height, 'LANG' => $lang, 'THEME' => $theme)); $ft->parse('CONTENT', 'photo_main'); } else { // jesli ktos probuje grzebac w adresie url header("Location: index.php"); exit; } $ft->FastPrint('CONTENT'); exit;
break; } break; case "remark": // kolejnosc if ($permarr['moderator']) { $move = intval($_GET['move']); $query = sprintf("\n UPDATE \n %1\$s \n SET \n page_order = page_order + '%2\$d' \n WHERE \n id='%3\$d'", TABLE_PAGES, $move, $_GET['id']); $db->query($query); // instancja potrzebna $sql = new DB_SQL(); $query = sprintf("\n SELECT * FROM \n %1\$s \n WHERE \n parent_id = '0' \n ORDER BY \n page_order \n ASC", TABLE_PAGES); $sql->query($query); $i = 10; while ($sql->next_record()) { $pid = $sql->f("id"); $query = sprintf("\n UPDATE \n %1\$s \n SET \n page_order = '{$i}' \n WHERE \n id = '{$pid}'", TABLE_PAGES); $db->query($query); $i += 10; } header("Location: main.php?p=4"); exit; } else { $monit[] = $i18n['edit_category'][6]; foreach ($monit as $error) { $ft->assign('ERROR_MONIT', $error); $ft->parse('ROWS', ".error_row"); } $ft->parse('ROWS', "error_reporting"); } break;
} break; case "remark": // zmiana pozycji wybranego linku if ($permarr['moderator']) { $move = intval($_GET['move']); $query = sprintf("\r\n UPDATE \r\n %1\$s \r\n SET \r\n link_order = link_order + '%2\$d' \r\n WHERE \r\n id='%3\$d'", TABLE_LINKS, $move, $_GET['id']); $db->query($query); // instancja potrzebna $sql = new DB_SQL(); $query = sprintf("\r\n SELECT * FROM \r\n %1\$s \r\n ORDER BY \r\n link_order \r\n ASC", TABLE_LINKS); $sql->query($query); $i = 10; $inc = 10; while ($sql->next_record()) { $lid = $sql->f("id"); $query = sprintf("\r\n UPDATE \r\n %1\$s \r\n SET \r\n link_order = '{$i}' \r\n WHERE \r\n id = '{$lid}'", TABLE_LINKS); $db->query($query); $i += 10; } header("Location: main.php?p=12"); exit; } else { $monit[] = $i18n['edit_category'][6]; foreach ($monit as $error) { $ft->assign('ERROR_MONIT', $error); $ft->parse('ROWS', ".error_row"); } $ft->parse('ROWS', "error_reporting"); } break;
function list_assigned_categories($id) { global $ft, $rewrite; $query = sprintf("\r\n SELECT \r\n a.*, b.* \r\n FROM \r\n %1\$s a \r\n LEFT JOIN \r\n %2\$s b \r\n ON \r\n a.category_id = b.category_id \r\n WHERE \r\n a.news_id = '%3\$d'", TABLE_ASSIGN2CAT, TABLE_CATEGORY, $id); $sql = new DB_SQL(); $sql->query($query); $count_cats = $sql->nf(); $idx = 1; while ($sql->next_record()) { $cname = replace_amp($sql->f('category_name')); $cid = $sql->f('category_id'); $category_link = (bool) $rewrite ? sprintf('1,%s,4,item.html', $cid) : 'index.php?p=4&id=' . $cid; $ft->assign(array('CATEGORY_NAME' => $cname, 'CATEGORY_LINK' => $category_link, 'COMMA' => $count_cats == $idx ? '' : ', ')); $ft->parse('CAT_ROW', ".cat_row"); $idx++; } // CAT_ROW musi byc czyste $ft->clear_parse('CAT_ROW'); }
function get_editcategory_cat($category_id, $level) { global $ft, $idx1, $count, $i18n; $lang = get_config('language_set'); $query = sprintf("\n SELECT \n a.*, count(b.id) AS count \n FROM \n %1\$s a \n LEFT JOIN \n %2\$s b \n ON \n a.category_id = b.category_id \n WHERE \n category_parent_id = '%3\$d'\n GROUP BY \n category_id \n ORDER BY \n category_id \n ASC", TABLE_CATEGORY, TABLE_ASSIGN2CAT, $category_id); $db = new DB_SQL(); $db->query($query); while ($db->next_record()) { $category_id = $db->f("category_id"); $category_name = $db->f("category_name"); $cat_parent_id = $db->f("category_parent_id"); $category_descrition = $db->f("category_description"); $count = $db->f("count"); $ft->assign(array('CATEGORY_ID' => $category_id, 'CATEGORY_NAME' => str_repeat(' ', $level) . '<img src="templates/' . $lang . '/images/ar.gif" /> ' . $category_name, 'COUNT' => $count, 'REORDER_DOWN' => false, 'REORDER_UP' => false, 'CATEGORY_DESC' => empty($category_description) ? $i18n['edit_category'][4] : $category_description)); // deklaracja zmiennej $idx1::color switcher $idx1 = empty($idx1) ? '' : $idx1; $idx1++; // naprzemienne kolorowanie wierszy tabeli $ft->assign('ID_CLASS', $idx1 % 2 ? 'mainList' : 'mainListAlter'); $ft->parse('ROWS', ".row"); get_editcategory_cat($category_id, $level + 2); } }
function get_config($name) { $db = new DB_SQL(); if (!defined('RDBMS')) { define('RDBMS', '4.0'); } if (RDBMS == '4.1') { if (!defined('STATEMENT_SET')) { $query = sprintf("\n PREPARE \n get_config \n FROM 'SELECT \n config_value \n FROM \n %1\$s \n WHERE \n config_name = ?'", TABLE_CONFIG); $db->query($query); $query = sprintf("SET @config_name = '%1\$s'", $name); $db->query($query); $query = "EXECUTE get_config USING @config_name"; /* * TODO: * czy tutaj ta stala nie powinna nieco inaczej wygladac ? * zakladam, ze powyzszy sposob, czyli korzystae z prepared * statements bedziemy wykorzystywac szerzej. wiec nie moze byc * jedna stala o nieznaczacej zbyt wiele nazwie, i zeby sie ja * dalo wykorzystac szerzej, do wiekszej ilosci statementsow * * poza tym, nie mam teraz jak, ale warto by sprawdzic, jak dlugo * prepared statements 'utrzymuja' sie w bazie. bo zakladam ze dluzej * niz okres zycia tej stalej ? jesli nie, to korzystanie z tego jest * malo wygodne, i sensowne w tym wypadku. * * jesli prepared statements zyja wystarzajaca dlugo, np tyle samo * co otwarte polaczenie z sql, to moze warto wrzucac w jakas tablice * do sesji wartosci bool, czy dana 'przygotowana stala' zostala juz * zdefiniowana. * */ // definicja warunku::true define('STATEMENT_SET', true); } else { $query = sprintf("SET @config_name = '%1\$s'", $name); $db->query($query); $query = "EXECUTE get_config USING @config_name"; } } else { $query = sprintf("\n SELECT\n config_value\n FROM\n %1\$s\n WHERE\n config_name = '%2\$s'", TABLE_CONFIG, $name); } $db->query($query); $db->next_record(); return $db->f('config_value'); }
* by the Free Software Foundation; version 2 only. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ require_once 'inc/i18n.php'; require_once 'inc/common_lib.php'; define('PATH_TO_CLASSES', get_root() . '/administration/classes'); require PATH_TO_CLASSES . '/cls_db_mysql.php'; // dodawanie pliku konfigurujacego bibliotekê baz danych require 'administration/inc/config.php'; $db = new DB_SQL(); $sql = new DB_SQL(); $query = sprintf("\n CREATE TABLE IF NOT EXIST \n %1\$s (\n id int(7) NOT NULL auto_increment, \n news_id int(7) NOT NULL default '0', \n category_id int(7) NOT NULL default '0', \n PRIMARY KEY (id), \n KEY news_id (news_id, category_id)", TABLE_ASSIGN2CAT); $db->query($query); $db->next_record(); $query = sprintf("\n SELECT \n id, c_id \n FROM \n %1\$s", TABLE_MAIN); $db->query($query); while ($db->next_record()) { $id = $db->f('id'); $c_id = $db->f('c_id'); $query = sprintf("\n INSERT INTO \n %1\$s \n VALUES('', '%2\$d', '%3\$d')", TABLE_ASSIGN2CAT, $id, $c_id); $sql->query($query); $sql->next_record(); } $query = sprintf("\n ALTER TABLE \n %1\$s \n DROP \n c_id", TABLE_MAIN); $db->query($query); $db->next_record();
$ft->assign(array('TITLE' => $i18n['index'][0], 'ERROR_MSG' => '', 'CSS_HREF' => 'templates/' . $lang . '/css/style.css')); // deklaracja zmiennej $p $p = empty($_GET['p']) ? '' : $_GET['p']; if ($p == "log") { $login = trim($_POST['login']); $password = trim(md5($_POST['password'])); if (empty($login) or empty($password)) { // U¿ytkownik nie uzupe³ni³ wszystkich pól::form $ft->assign('ERROR_MSG', $i18n['index'][1]); $ft->parse('ROWS', ".form_login"); } else { $db = new DB_SQL(); $query = sprintf("\r\n SELECT \r\n active \r\n FROM \r\n %1\$s \r\n WHERE \r\n login = '******' \r\n AND \r\n password = '******'", TABLE_USERS, $login, $password); $db->query($query); if ($db->num_rows()) { if ($db->f("active") != "N") { // Rejestrujemy zmienne sesyjne $_SESSION["login"] = $login; $_SESSION["loggedIn"] = TRUE; header("Location: main.php"); break; } else { // U¿ytkownik nie zaaktywowa³ konta::db $ft->assign('ERROR_MSG', $i18n['index'][2]); $ft->parse('ROWS', ".form_login"); } } else { // Niepoprawne dane wej¶cia<->wyj¶cia::form, db $ft->assign('ERROR_MSG', $i18n['index'][3]); $ft->parse('ROWS', ".form_login"); }
$ft->assign('OVERWRITE_PHOTO', !empty($image) ? true : false); if (!empty($image)) { $ft->define("form_imageedit", "form_imageedit.tpl"); $ft->assign('IMAGE', $image); $ft->parse('IF_IMAGE_EXIST', ".form_imageedit"); } $query = sprintf("\r\n SELECT \r\n category_id, \r\n category_parent_id, \r\n category_name \r\n FROM \r\n %1\$s \r\n WHERE \r\n category_parent_id = '%2\$d'", TABLE_CATEGORY, 0); $sql = new DB_SQL(); $db->query($query); while ($db->next_record()) { $c_id = $db->f("category_id"); $c_name = $db->f("category_name"); $query = sprintf("\r\n SELECT * FROM \r\n %1\$s \r\n WHERE \r\n category_id = '%2\$d' \r\n AND \r\n news_id = '%3\$d'", TABLE_ASSIGN2CAT, $c_id, $_GET['id']); $sql->query($query); $sql->next_record(); $assigned = $sql->f("category_id"); $ft->assign(array('C_ID' => $c_id, 'C_NAME' => $c_name, 'PAD' => '', 'CURRENT_CAT' => $c_id == $assigned ? 'checked="checked"' : '')); $ft->define("form_noteedit", "form_noteedit.tpl"); $ft->define_dynamic("cat_row", "form_noteedit"); $ft->parse('CAT_ROW', ".cat_row"); get_editnews_assignedcat($c_id, 2); } $ft->parse('ROWS', "form_noteedit"); } break; case "delete": // usuwanie wybranego wpisu // potwierdzenie usuniecia wpisu $confirm = empty($_POST['confirm']) ? '' : $_POST['confirm']; switch ($confirm) { case $i18n['confirm'][0]:
function list_assigned_categories($id) { global $ft, $rewrite, $CoreRewrite; $query = sprintf("\n SELECT \n a.*, b.* \n FROM \n %1\$s a \n LEFT JOIN \n %2\$s b \n ON \n a.category_id = b.category_id \n WHERE \n a.news_id = '%3\$d'", TABLE_ASSIGN2CAT, TABLE_CATEGORY, $id); $sql = new DB_SQL(); $sql->query($query); $count_cats = $sql->nf(); $idx = 1; while ($sql->next_record()) { $cname = replace_amp($sql->f('category_name')); $cid = $sql->f('category_id'); $ft->assign(array('CATEGORY_NAME' => $cname, 'CATEGORY_LINK' => $CoreRewrite->category_news($cid, $rewrite), 'COMMA' => $count_cats == $idx ? '' : ', ')); $ft->parse('CAT_ROW', ".cat_row"); $idx++; } // CAT_ROW musi byc czyste $ft->clear_parse('CAT_ROW'); }