PLS I NEED YOUR HELP! Help on Reading and Editing of already Written CODE on php!

Reply

Join Date: Jul 2007
Posts: 55
Reputation: atplerry is an unknown quantity at this point 
Solved Threads: 3
atplerry atplerry is offline Offline
Junior Poster in Training

PLS I NEED YOUR HELP! Help on Reading and Editing of already Written CODE on php!

 
0
  #1
Aug 14th, 2008
Hello !
I am a student of a university i and we are group into different categories in executing a project. The Template of the project was design by our lecturer and they want us to read , interprete and edit a website written in php and was givien to us to work on Now a setup my wampserver copy the own site into my www root folder and and try to run the site but the site complan that the databases setting have not been config now i found out that there is an include file on the first line of every pages and i trace is i got the code which will be pasted below. The instruction is that we should not redesign another site but use the one given to create another database and connect it and work perfectly...
but i dont know where to edit o reconfigure the site to give it another database path and name cause they all look to odd another PLS I NEED YOUR HELP


This is the code below

  1. <?php
  2. /********************************************************
  3.  
  4. sNews 1.6
  5. Release date: May 16, 2007
  6. Developers version: 1.6.0 Stable
  7. Copyright (C) Solucija.com
  8. sNews is licensed under a Creative Commons License
  9.  
  10. *********************************************************/
  11. error_reporting(0);
  12.  
  13. /*** CONFIGURATION VARIABLES ***/
  14.  
  15. // DATABASE VARIABLES
  16. function db($variable) {
  17. $db = array();
  18. $db['website'] = 'http://www.nacossoau.org/news/';
  19. $db['dbhost'] = 'localhost'; //MySQL Host
  20. $db['dbname'] = 'nacoss_nacos'; //Database Name
  21. $db['dbuname'] = 'nacoss_opeawo'; //Database Username
  22. $db['dbpass'] = 'adeja'; //Database password
  23. $db['prefix'] = ''; //Database prefix
  24. $db['dberror'] = '<strong>There was an error while connecting to the database.</strong> <br /> Check your database settings.'; //Database error message
  25. return $db[$variable];
  26. }
  27.  
  28. // LANGUAGE VARIABLES
  29. function l($variable) {
  30. if (s('language') != 'EN' && file_exists('snews_'.s('language').'.php')) {include('snews_'.s('language').'.php');} else {
  31. $l = array();
  32.  
  33. #SITE LANGUAGE VARIABLES
  34. $l['home'] = 'Newshome';
  35. $l['home_sef'] = 'home'; //default value is used only if "home_SEF" is not set in the database - allowed characters are [a-z] [A-Z] [0-9] [-] [_]
  36. $l['archive'] = 'Archive';
  37. $l['rss_feed'] = 'RSS Feed';
  38. $l['contact'] = 'Contact';
  39. $l['sitemap'] = 'Site Map';
  40. #categories
  41. $l['month_names'] = 'January, February, March, April, May, June, July, August, September, October, November, December';
  42. #search
  43. $l['search_keywords'] = 'Find on NACOSSOAU';
  44. $l['search_button'] = 'Search';
  45. $l['search_results'] = 'Search results on NACOSSOAU';
  46. $l['charerror'] = 'At least 4 characters are needed to perform the search.';
  47. $l['noresults'] = 'There are no results for query ';
  48. $l['resultsfound'] = 'results were found for query';
  49. #comments
  50. $l['addcomment'] = 'Write a comment';
  51. $l['comment'] = 'Comment';
  52. $l['comment_info'] = 'Comment posted in';
  53. $l['page'] = 'Page';
  54. $l['on'] = 'on'; // preposition word used in comments infoline
  55. #paginator
  56. $l['first_page'] = 'First';
  57. $l['last_page'] = 'Last';
  58. $l['previous_page'] = 'Previous';
  59. $l['next_page'] = 'Next';
  60. $l['name'] = 'Name';
  61. #comments
  62. $l['comment_sent'] = 'Your comment has been sent';
  63. $l['comment_sent_approve'] = 'Your comment is waiting moderation.';
  64. $l['comment_error'] = 'Your comment was not sent';
  65. $l['comment_back'] = 'Back to your comment';
  66. $l['no_comment'] = 'This article hasn\'t been commented yet.';
  67. $l['no_comments'] = 'No comments at the moment';
  68. $l['ce_reasons'] = '<strong>Possible reasons:</strong> You left blank column, comment is too short or you haven\'t entered the right math captcha code.';
  69. $l['url'] = 'Website URL';
  70. #contact
  71. $l['required'] = '* = required field';
  72. $l['email'] = 'Email';
  73. $l['message'] = 'Message';
  74. $l['math_captcha'] = 'Perform an addition of two integers to avoid spam';
  75. $l['contact_sent'] = 'Thank you, your message has been sent.';
  76. $l['contact_not_sent'] = 'Your message was not sent';
  77. $l['message_error'] = '<strong>Possible reasons:</strong> You left name or message field blank, or email address does not exist.';
  78. #generic links
  79. $l['backhome'] = 'Back home';
  80. $l['backarticle'] = 'Back to article';
  81. $l['read_more'] = 'Continue reading';
  82. #contents error
  83. $l['article_not_exist'] = 'No contents yet';
  84. $l['category_not_exist'] = 'Requested category does not exist';
  85. $l['not_found'] = 'Content not found';
  86. #rss links
  87. $l['rss_articles'] = 'RSS Articles';
  88. $l['rss_pages'] = 'RSS Pages';
  89. $l['rss_comments'] = 'RSS Comments';
  90. $l['rss_comments_article'] = 'RSS Comments for this article';
  91.  
  92. #ADMINISTRATION LANGUAGE VARIABLES
  93. #administration
  94. $l['administration'] = 'Admin';
  95. $l['articles'] = 'Articles';
  96. $l['extra_contents'] = 'Extra contents';
  97. $l['pages'] = 'Pages';
  98. #basic buttons
  99. $l['view'] = 'View';
  100. $l['add_new'] = 'Add new';
  101. $l['admin_category'] = 'New Category';
  102. $l['article_new'] = 'New Article';
  103. $l['extra_new'] = 'New Extra Contents';
  104. $l['page_new'] = 'New Page';
  105. $l['edit'] = 'Edit';
  106. $l['delete'] = 'Delete';
  107. $l['save'] = 'Save';
  108. $l['submit'] = 'Submit';
  109. #settings
  110. $l['settings'] = 'Settings';
  111. $l['site_settings'] = 'Site';
  112. #login
  113. $l['login_status'] = 'Login status';
  114. $l['login'] = 'Login';
  115. $l['username'] = 'Username';
  116. $l['password'] = 'Password';
  117. $l['login_limit'] = 'User/pass limitations: 4-8 alphanumeric characters only';
  118. $l['logged_in'] = 'You are Logged In';
  119. $l['log_out'] = 'Logging out';
  120. $l['logout'] = 'Logout';
  121. #categories
  122. $l['categories'] = 'Categories';
  123. $l['category'] = 'Category';
  124. $l['appear_category'] = 'Appear only on Category';
  125. $l['appear_page'] = 'Appear only on Page';
  126. $l['add_category'] = 'New category';
  127. $l['category_order'] = 'Category order';
  128. $l['order_category'] = 'Reorder';
  129. $l['description'] = 'Description';
  130. $l['publish_category'] = 'Publish category';
  131. $l['status'] = 'Status:';
  132. $l['published'] = 'Published';
  133. $l['unpublished'] = '<span style="color: #FF0000">Unpublished</span>';
  134. #articles
  135. $l['article'] = 'Article';
  136. $l['article_date'] = 'Article date (enter a higher date for future posting)';
  137. $l['preview'] = 'Preview';
  138. $l['no_articles'] = 'No articles at the moment';
  139. #customize article
  140. $l['customize'] = 'Customize';
  141. $l['display_title'] = 'Display title';
  142. $l['display_info'] = 'Display info line (read more/ comments/ date)';
  143. $l['server_time'] = 'Time on Server';
  144. $l['future_posting'] = '<span style="color: #FF9900;">Future posting</span>';
  145. $l['publish_date'] = 'Publish Date';
  146. $l['day'] = 'Day';
  147. $l['month'] = 'Month';
  148. $l['year'] = 'Year';
  149. $l['hour'] = 'Hour';
  150. $l['minute'] = 'Minute';
  151. $l['publish_article'] = 'Publish article';
  152. $l['operation_completed'] = 'Operation completed successfully!';
  153. $l['deleted_success'] = 'Succesfully deleted';
  154. #files
  155. $l['files'] = 'Files';
  156. $l['upload'] = 'Upload';
  157. $l['view_files'] = 'View files in';
  158. $l['file_error'] = 'File could not be copied!';
  159. $l['deleted'] = 'File deleted!';
  160. #comments
  161. $l['comments'] = 'Comments';
  162. $l['enable_commenting'] = 'Enable comments';
  163. $l['edit_comment'] = 'Edit comment';
  164. $l['freeze_comments'] = 'Freeze comments';
  165. $l['unfreeze_comments'] = 'Unfreeze comments';
  166. $l['enable'] = 'Enable';
  167. $l['approved'] = 'Approved';
  168. $l['enabled'] = 'Enabled';
  169. $l['disabled'] = 'Disabled';
  170. $l['unapproved'] = 'Unapproved comments';
  171. $l['wait_approval'] = 'comments waiting approval';
  172. #article structure
  173. $l['title'] = 'Title';
  174. $l['sef_title'] = 'Search engine friendly title (will be used as link to the article)';
  175. $l['sef_title_cat'] = 'Search engine friendly title (will be used as link to the category)';
  176. $l['text'] = 'Text';
  177. $l['position'] = 'Position';
  178. $l['display_page'] = 'Page';
  179. $l['center'] = 'Center';
  180. $l['contents'] = 'Contents';
  181. $l['side'] = 'Extra contents';
  182. #errors
  183. $l['error_404'] = 'Requested contents could not be found. Please go back or use the search feature.';
  184. $l['error_not_logged_in'] = 'You are not currently logged in and so are not allowed to do that.';
  185. $l['admin_error'] = 'Error';
  186. $l['back'] = 'Back';
  187. $l['err_TitleEmpty'] = 'The Title cannot be empty.';
  188. $l['err_TitleExists'] = 'The Title already exists.';
  189. $l['err_SEFEmpty'] = 'The SEF Title cannot be empty.';
  190. $l['err_SEFExists'] = 'The SEF Title already exists.';
  191. $l['err_SEFIllegal'] = 'The SEF title you entered contains illegal characters.<br />You can only use <strong>a-z 0-9_-</strong><br />A new SEF url has been selected from the title. Please check it.';
  192. $l['errNote'] = '<br /><strong>Be careful:</strong> Due to the fact that when something goes wrong most posting options are lost, please check them before posting again.';
  193. $l['warning_delete'] = 'Are you sure you want to delete this?';
  194. $l['image_url'] = 'Enter Image URL';
  195. $l['image_alt'] = 'Enter Image Alt';
  196. $l['file_url'] = 'Enter File URL';
  197. $l['link_url'] = 'Enter Link URL';
  198. $l['link_title'] = 'Enter Link Title';
  199. #settings form
  200. $l['none'] = "None";
  201. $l['change_up'] = 'Change Username and Password';
  202. $l['newer_top'] = 'Newer on top';
  203. $l['newer_bottom'] = 'Newer on bottom';
  204. $l['err_Login'] = 'Wrong username and/or password and/or sum entered.';
  205. $l['pass_mismatch'] = 'Passwords are outside length limit or do not match';
  206. $l['a_username'] = 'Username';
  207. $l['a_password'] = 'Password';
  208. $l['a_password2'] = 'Repeat password';
  209. $l['a_display_page'] = "Use Page as Home Page";
  210. $l['a_display_new_on_home'] = 'Display new Articles on home';
  211. $l['a_display_pagination'] = 'Display Pagination on articles';
  212. $l['a_website_title'] = 'Website Title';
  213. $l['a_home_sef'] = 'Home SEF (used as link to <em>Home</em>)';
  214. $l['a_website_email'] = 'Email';
  215. $l['a_description'] = 'Default description META Tag (for search engines)';
  216. $l['a_keywords'] = 'Default keywords META Tag (keywords separated by comma)';
  217. $l['a_contact_info'] = 'Contact info';
  218. $l['a_contact_subject'] = 'Contact Form Subject';
  219. $l['a_word_filter_file'] = 'Badwords filter file';
  220. $l['a_word_filter_change'] = 'Badwords replacement word';
  221. $l['a_word_filter_enable'] = 'Enable Badwords filter';
  222. $l['error_file_name'] = '<br /><span style="color: #FF0000; font-weight: bold;">Include Error: Forbidden file name</span><br />';
  223. $l['error_file_exists'] = '<br /><span style="color: #FF0000; font-weight: bold;">Include Error: File doesn\'t exists</span><br />';
  224. $l['a_num_categories'] = 'Display number of articles next to a category';
  225. $l['charset'] = 'Default charset';
  226. $l['a_time_settings'] = 'Time and Locale settings';
  227. $l['a_date_format'] = 'Date Format';
  228. $l['a_comments_order'] = 'Comments Order';
  229. $l['a_comment_limit'] = 'Comment results per page';
  230. $l['a_rss_limit'] = 'RSS Articles Limit';
  231. $l['a_approve_comments'] = 'Approve comments before publishing';
  232. $l['a_article_limit'] = 'Articles per page limit';
  233. $l['a_language'] = 'sNews Language';
  234. $l['description_meta'] = 'Description META Tag (for search engines)';
  235. $l['keywords_meta'] = 'Keywords META Tag (keywords separated by comma)';
  236. $l['all'] = 'All';
  237.  
  238. #SYSTEM VARIABLES (not to be translated)
  239. $l['home_sef'] = s('home_sef') == '' ? $l['home_sef'] : s('home_sef'); //reassign $l['home_sef'] to system home_sef if system is set.
  240. $l['cat_listSEF'] = $l['home_sef'].',archive,contact,sitemap,rss-articles,rss-pages,rss-comments,login,administration,admin_category,admin_article,article_new,extra_new,page_new,categories,articles,extra_contents,pages,settings,files,logout'; //SEF links of the hardcoded categories
  241. $l['divider'] = '&middot;'; //divider character
  242. $l['paginator'] = 'p_'; // used in article pagination links
  243. $l['file_include_extensions'] = 'php,txt,inc,htm,html'; // list of file types available for inclusion routine
  244. $l['allowed_files'] = 'php,htm,html,txt,inc,css,js,swf'; // list of file types available for upload/file list routine
  245. $l['allowed_images'] = 'gif,jpg,jpeg,png'; // list of image types available for upload/file list routine
  246. $l['ignored_items'] = '.,..,cgi-bin,.htaccess,Thumbs.db,snews.php,index.php,style.css'; // list of files&folders ignored by upload/file list routine
  247.  
  248. } return $l[$variable];
  249. }
  250. /*** END OF SETTINGS & VARIABLES, EDIT BELOW THIS LINE ONLY IF YOU KNOW WHAT YOU'RE DOING ***/
  251.  
  252. // INFO LINE TAGS (readmore, comments, date)
  253.  
  254. function tags($tag) {
  255. $tags = array(); $tags['infoline'] = '<p class="date">,readmore,comments,date,edit,</p>';
  256. $tags['comments'] = '<div class="comment">,<p class="date">,name, '.l('on').' ,date,edit,</p>,<p>,comment,</p>,</div>';
  257. return $tags[$tag];
  258. }
  259.  
  260. // SITE SETTINGS - grab site settings from database
  261. function s($variable) {
  262. $query = "SELECT value FROM ".db('prefix')."settings WHERE name = '$variable'";
  263. $result = mysql_query($query);
  264. while ($r = mysql_fetch_array($result)) {$value = $r['value'];}
  265. return $value;
  266. }
  267.  
  268. // SESSION TOKEN
  269. function token() {
  270. $a = md5(substr(session_id(), 2, 7));
  271. $b = $_SERVER['HTTP_USER_AGENT'];
  272. $c = db('website');
  273. $token = md5($a.$b.$c);
  274. return $token;
  275. }
  276.  
  277. // STARTUP
  278. function snews_startup() {
  279. connect_to_db();
  280. $categorySEF = get_id('category');
  281. $articleSEF = get_id('article');
  282. if (false !== strpos($categorySEF, 'rss-')) {rss_contents($categorySEF, $articleSEF);}
  283. $homeSEF = l('home_sef');
  284. $categoryID = $categorySEF == $homeSEF ? 0 : retrieve('id', 'categories', 'seftitle', $categorySEF);
  285. $articleCatID = retrieve('category', 'articles', 'seftitle', $articleSEF);
  286. if (!empty($categorySEF) && $categorySEF != '404') {
  287. switch(true) {
  288. case ((!$categoryID || !is_numeric($categoryID)) && check_category($categorySEF) == false):
  289. case (!empty($articleSEF) && false === strpos($articleSEF,l('paginator')) && !is_numeric($articleCatID)):
  290. header('Location: '.db('website').'404/'); exit;
  291. break;
  292. }
  293. }
  294. if ($categorySEF == '404') {header('HTTP/1.1 404 Not Found');}
  295. update_articles();
  296. if (isset($_POST['Loginform'])) {
  297. $user = checkUserPass($_POST['uname']);
  298. $pass = checkUserPass($_POST['pass']);
  299. if (md5($user) === s('username') && md5($pass) === s('password') && mathCaptcha($_POST['calc'], $_POST['sum'])) {
  300. $_SESSION[db('website').'Logged_In'] = token();
  301. }}}
  302. snews_startup();
  303.  
  304. // 404 ERROR PAGE
  305. function error404() {echo l('error_404');}
  306.  
  307. // TITLE
  308. function title() {
  309. echo '<base href="'.db('website').'" />';
  310. $categorySEF = get_id('category'); $articleSEF = get_id('article');
  311. $categoryName = retrieve('name', 'categories', 'seftitle', $categorySEF);
  312. $articleTitle = retrieve('title', 'articles', 'seftitle', $articleSEF);
  313. if (!empty($articleTitle)) {$title = $articleTitle.' - ';}
  314. if (!empty($categoryName)) {$title .= $categoryName.' - ';}
  315. $title .= s('website_title');
  316. echo '<title>'.$title.'</title>';
  317. echo '<meta http-equiv="Content-Type" content="text/html; charset='.s('charset').'" />';
  318. if (!empty($articleSEF)) {
  319. $query = "SELECT * FROM ".db(prefix)."articles WHERE seftitle = '$articleSEF'";
  320. $result = mysql_query($query);
  321. while ($r = mysql_fetch_array($result)) {$dmeta = $r['description_meta']; $kmeta = $r['keywords_meta'];}
  322. }
  323. echo '<meta name="description" content="'.(!empty($dmeta) ? $dmeta : s('website_description')).'" />';
  324. echo '<meta name="keywords" content="'.(!empty($kmeta) ? $kmeta : s('website_keywords')).'" />';
  325. if ($_SESSION[db('website').'Logged_In'] == token()) {js();}
  326. }
  327.  
  328. //BREADCRUMBS
  329. function breadcrumbs() {
  330. $link = '<a href="'.db('website').'';
  331. if ($_SESSION[db('website').'Logged_In'] == token()) {echo $link.'administration/" title="'.l('administration').'">'.l('administration').'</a> '.l('divider').' ';}
  332. $categorySEF = get_id('category'); $articleSEF = get_id('article'); $home = l('home_sef');
  333. echo (!empty($categorySEF) || $categorySEF == $home || !empty($articleSEF)) ? $link.'" title="'.l('home').'">'.l('home').'</a>' : l('home');
  334. $categoryName = retrieve('name', 'categories', 'seftitle', $categorySEF);
  335. if (!empty($categoryName)) {
  336. echo ' '.l('divider').' '.(!empty($articleSEF) ? $link.$categorySEF.'/" title="'.$categoryName.'">'.$categoryName.'</a>' : $categoryName);
  337. }
  338. $articleTitle = retrieve('title', 'articles', 'seftitle', $articleSEF);
  339. if (!empty($articleTitle)) {echo ' '.l('divider').' '.$articleTitle;}
  340. if (check_category($categorySEF) == true && $categorySEF != $home && $categorySEF != 'administration') {echo ' '.l('divider').' '.l($categorySEF);}
  341. }
  342.  
  343. // LOGIN LOGOUT LINK
  344. function login_link() {
  345. $login = '<a href="'.db('website');
  346. $login .= $_SESSION[db('website').'Logged_In'] == token() ? 'administration/" title="'.l('administration').'">'.l('administration') : 'login/" title="'.l('login').'">'.l('login').'';
  347. $login .= '</a>';
  348. echo $login;
  349. }
  350.  
  351. // DISPLAY CATEGORIES
  352. function categories() {
  353. $categorySEF = get_id('category');
  354. $class = $category_title == $categorySEF ? ' class="current"' : '';
  355. echo '<li><a'.$class.' href="'.db('website').'" title="'.l('home').'">'.l('home').'</a></li>';
  356. $query = "SELECT * FROM ".db('prefix')."categories WHERE published = 'YES' ORDER BY catorder ASC";
  357. $result = mysql_query($query);
  358. while ($r = mysql_fetch_array($result)) {
  359. $calc_num_query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND category = $r[id] AND published = 1";
  360. $cm_result = mysql_query($calc_num_query);
  361. $num_rows = mysql_num_rows($cm_result);
  362. $category_title = $r['seftitle'];
  363. $class = $category_title == $categorySEF ? ' class="current"' : '';
  364. echo '<li><a'.$class.' href="'.db('website').$category_title.'/" title="'.$r['description'].'">'.$r['name'];
  365. echo (s('num_categories') == 'on' ? ' ('.$num_rows.')' : '').'</a></li>';
  366. }}
  367.  
  368. // DISPLAY PAGES
  369. function pages() {
  370. $categorySEF = get_id('category'); $pageSEF = get_id('article'); $home = l('home_sef');
  371. $class = (empty($categorySEF) || $categorySEF == $home && empty($pageSEF)) ? ' class="current"' : '';
  372. echo '<li><a'.$class.' href="'.db('website').'" title="'.l('home').'">'.l('home').'</a></li>';
  373. $class = ($categorySEF == 'archive') ? ' class="current"' : '';
  374. echo '<li><a'.$class.' href="'.db('website').'archive/" title="'.l('archive').'">'.l('archive').'</a></li>';
  375. $query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY id";
  376. $result = mysql_query($query);
  377. while ($r = mysql_fetch_array($result)) {
  378. $title = $r['title'];
  379. $class = ($pageSEF == $r['seftitle'])? ' class="current"' : '';
  380. if ($r['id'] != s('display_page')) {echo '<li><a'.$class.' href="'.db('website').l('home_sef').'/'.$r['seftitle'].'/" title="'.$title.'">'.$title.'</a></li>';}
  381. }
  382. $class = ($categorySEF == 'contact') ? ' class="current"': '';
  383. echo '<li><a'.$class.' href="'.db('website').'contact/" title="'.l('contact').'">'.l('contact').'</a></li>';
  384. $class = ($categorySEF == 'sitemap') ? ' class="current"': '';
  385. echo '<li><a'.$class.' href="'.db('website').'sitemap/" title="'.l('sitemap').'">'.l('sitemap').'</a></li>';
  386. }
  387.  
  388. //EXTRA CONTENT
  389. function extra($styleit = 0, $classname = '', $idname= '') {
  390. $categorySEF = get_id('category');
  391. $categoryId = (check_category($categorySEF) == true || empty($categorySEF) || $categorySEF == l('home_sef')) ? 0 : retrieve('id', 'categories', 'seftitle', $categorySEF);
  392. $pageSEF = get_id('article');
  393. $pageId = (empty($categorySEF)) ? 0 : retrieve('id', 'articles', 'seftitle', $pageSEF);
  394. $query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) = '2' AND published = 1 ORDER BY id DESC";
  395. $result = mysql_query($query);
  396. while ($r = mysql_fetch_array($result)) {
  397. $pos = $r['position']; $pos_depend = substr($pos, 1, 1); $pos_artID = substr($pos, 2);
  398. switch (true) {
  399. case ($pos_depend == 0 && $categoryId == 0): $print = true; break;
  400. case ($pos_depend == 1 && $categoryId == $pos_artID): $print = true; break;
  401. case ($pos_depend == 2 && $pageId == $pos_artID): $print = true; $category = -1; break;
  402. case ($pos_depend != '2' && $r['category'] == -1): $print = true; break; default: $print = false;
  403. }
  404. if ($print == true) {
  405. if ($styleit == 1) {
  406. $container ='<div';
  407. $container .= !empty($classname) ? ' class="'.$classname.'"' : '';
  408. $container .= !empty($idname) ? ' id="'.$idname.'"' : '';
  409. $container .= '>';
  410. echo $container;
  411. }
  412. echo $r['displaytitle'] == 'YES' ? '<h3>'.$r['title'].'</h3>' : '';
  413. file_include($r['text'], 9999000);
  414. echo $_SESSION[db('website').'Logged_In'] == token() ? '<p><a href="'.db('website').'index.php?action=admin_article&amp;id='.$r['id'].'" title="'.l('edit').' '.$r['seftitle'].'">'.l('edit').'</a></p>' : '';
  415. if ($styleit == 1) {echo '</div>';}
  416. }}}
  417.  
  418. // PAGINATOR
  419. function paginator($category, $pageNum, $maxPage, $article, $pagePrefix) {
  420. $link = ' <a href="'.db('website').$category.'/';
  421. if (!empty($article)) {$link .= $article.'/';}
  422. $prefix = !empty($pagePrefix) ? $pagePrefix : '';
  423. if ($pageNum > 1) {
  424. $goTo = (!empty($article) || (!empty($category) && $category != l('home_sef'))) ? $link : '<a href="'.db('website');
  425. $prev = (($pageNum-1)==1 ? $goTo : $link.$prefix.($pageNum - 1).'/').'" title="'.l('page').' '.($pageNum - 1).'">&lt; '.l('previous_page').'</a> ';
  426. $first = $goTo.'" title="'.l('first_page').' '.l('page').'">&lt;&lt; '.l('first_page').'</a>';
  427. }
  428. else {$prev = '&lt; '.l('previous_page'); $first = '&lt;&lt; '.l('first_page');}
  429. if ($pageNum < $maxPage) {
  430. $next = $link.$prefix.($pageNum + 1).'/" title="'.l('page').' '.($pageNum + 1).'">'.l('next_page').' &gt;</a> ';
  431. $last = $link.$prefix.$maxPage.'/" title="'.l('last_page').' '.l('page').'">'.l('last_page').' &gt;&gt;</a> ';
  432. }
  433. else {$next = l('next_page').' &gt; '; $last = l('last_page').' &gt;&gt;';}
  434. echo '<div class="paginator">'.$first.' '.$prev.' <strong> ['.$pageNum.'</strong> / <strong>'.$maxPage.'] </strong> '.$next.' '.$last.'</div>';
  435. }
  436.  
  437. // CENTER
  438. function center() {
  439. switch(true) {
  440. case isset($_GET['category']): $id = $action = get_id('category'); break;
  441. case isset($_GET['action']): $action = clean(cleanXSS($_GET['action'])); break;
  442. case isset($_GET['articleid']): $articleid = get_id('articleid'); break;
  443. }
  444. switch(true) {
  445. case isset($_POST['search_query']): search(); return; break;
  446. case isset($_POST['comment']): comment('comment_posted'); return; break;
  447. case isset($_POST['contactform']): contact(); return; break;
  448. case isset($_POST['Loginform']): administration(); return; break;
  449. case isset($_POST['submit_text']):
  450. if ($_SESSION[db('website').'Logged_In'] == token()) {processing(); return;}
  451. else {echo notification(1,l('error_not_logged_in'),'home');} break;
  452. }
  453. if ($_SESSION[db('website').'Logged_In'] == token()) {
  454. switch ($action) {
  455. case 'administration': administration(); return; break;
  456. case 'settings': settings(); return; break;
  457. case 'categories': admin_categories(); return; break;
  458. case 'admin_category': form_categories(); return; break;
  459. case 'articles': admin_articles('article_view'); return; break;
  460. case 'extra_contents': admin_articles('extra_view'); return; break;
  461. case 'pages': admin_articles('page_view'); return; break;
  462. case 'admin_article': form_articles(''); return; break;
  463. case 'article_new': form_articles('article_new'); return; break;
  464. case 'extra_new': form_articles('extra_new'); return; break;
  465. case 'page_new': form_articles('page_new'); return; break;
  466. case 'editcomment': edit_comment(); return; break;
  467. case 'files': files(); return; break;
  468. case 'process': processing(); return; break;
  469. case 'logout': session_destroy();
  470. echo '<meta http-equiv="refresh" content="1; url='.db('website').'">';
  471. echo '<h2>'.l('log_out').'</h2>'; return; break;
  472. }
  473. }
  474. switch ($action) {
  475. case 'archive': archive(); break;
  476. case 'sitemap': sitemap(); break;
  477. case 'contact': contact(); break;
  478. case 'login': login(); break;
  479. case '404': error404(); break;
  480. default:
  481. $article = get_id('article');
  482. $title_not_found = '<h2>'.l('not_found').'</h2>';
  483. $currentPage = strpos($article, l('paginator')) === 0 ? str_replace(l('paginator'), '', $article) : '';
  484. $home = l('home_sef'); $categorySEF = get_id('category');
  485. $categorySEF = empty($categorySEF) ? $home : $categorySEF;
  486. $use_cat_id = $categorySEF == $home ? 0 : retrieve('id', 'categories', 'seftitle', $categorySEF);
  487. $query_articles = "SELECT * FROM ".db('prefix')."articles WHERE published = 1 AND SUBSTRING(position, 1, 1) != '2'";
  488. if (!empty($article) && empty($currentPage)) {$query_articles .= " AND seftitle = '$article'";}
  489. else if ($categorySEF == $home && s('display_page') <> 0) {$id_page = s('display_page'); $query_articles .= " AND id = '$id_page'";}
  490. else {
  491. if (s('display_new_on_home') == 'on') {$query_articles .= $use_cat_id != 0 ? " AND category = $use_cat_id" : '';}
  492. else {$query_articles .= " AND category = $use_cat_id";}
  493. $query_articles .= " AND position <> 3 ORDER BY date DESC";
  494. $result_articles = mysql_query($query_articles);
  495. $numrows_articles = mysql_num_rows($result_articles);
  496. if (!$result_articles || !$numrows_articles) {echo $title_not_found; return;}
  497. else {
  498. $articleCount = s('article_limit');
  499. $article_limit = (empty($articleCount) || $articleCount < 1) ? 100 : $articleCount;
  500. $totalPages = ceil($numrows_articles/$article_limit);
  501. if (!isset($currentPage) || !is_numeric($currentPage) || $currentPage < 1) {$currentPage = 1;}
  502. else if ($currentPage > $totalPages) {$currentPage = $totalPages;}
  503. $query_articles .= " LIMIT ".($currentPage - 1) * $article_limit.", ".$article_limit;
  504. }
  505. }
  506. $result = mysql_query($query_articles);
  507. $numrows = mysql_num_rows($result);
  508. if (!$result || !$numrows) {echo $title_not_found;}
  509. else {
  510. $link = '<a href="'.db('website');
  511. while ($r = mysql_fetch_array($result)) {
  512. $infoline = $r['displayinfo'] == 'YES' ? true : false;
  513. $text = stripslashes($r['text']);
  514. if (!empty($currentPage)) {$short_display = strpos($text, '[break]'); $shorten = $short_display == 0 ? 9999000 : $short_display;}
  515. else {$shorten = 9999000;}
  516. $comments_query = "SELECT * FROM ".db('prefix')."comments WHERE articleid = $r[id] AND approved = 'True'";
  517. $comments_result = mysql_query($comments_query);
  518. $comments_num = mysql_num_rows($comments_result);
  519. $a_date_format = date(s('date_format'), strtotime($r['date']));
  520. $position = $r['position'];
  521. $category = $r['category'] == 0 ? $home : retrieve('seftitle', 'categories', 'id', $r['category']);
  522. $title = $r['title'];
  523. if ($r['displaytitle'] == 'YES') {echo '<h2>'.(strlen($text) > $shorten ? $link.$category.'/'.$r['seftitle'].'/" title="'.$title.'">'.$title.'</a>' : $title).'</h2>';}
  524. file_include(str_replace('[break]', '', $text), $shorten);
  525. $commentable = $r['commentable'];
  526. $edit_link = $link.'index.php?action=admin_article&amp;id='.$r['id'].'" title="'.l('edit').' '.$title.'">'.l('edit').'</a>';
  527. if (!empty($currentPage)) {
  528. if ($infoline == true) {
  529. $tag = explode(',', tags('infoline'));
  530. foreach ($tag as $tag) {
  531. switch (true) {
  532. case ($tag == 'date'): echo $a_date_format; break;
  533. case ($tag == 'readmore' && strlen($r['text']) > $shorten):
  534. echo $link.$category.'/'.$r['seftitle'].'/" title="'.l('read_more').'">'.l('read_more').'</a> '; break;
  535. case ($tag == 'comments' && ($commentable == 'YES' || $commentable == 'FREEZ')):
  536. echo $link.$category.'/'.$r['seftitle'].'/#'.l('comment').'1" title="'.l('comments').'">'.l('comments').' ('.$comments_num.')</a> '; break;
  537. case ($tag == 'edit' && $_SESSION[db('website').'Logged_In'] == token()): echo ' '.$edit_link; break;
  538. case ($tag != 'readmore' && $tag != 'comments' && $tag != 'edit'): echo $tag; break;
  539. }
  540. }
  541. }
  542. else if ($_SESSION[db('website').'Logged_In'] == token()) {echo '<p>'.$edit_link.'</p>';}
  543. }
  544. else if (substr($position, 0, 1) != '2' && empty($currentPage)) {
  545. if ($infoline == true) {
  546. $tag = explode(',', tags('infoline'));
  547. foreach ($tag as $tag ) {
  548. switch ($tag) {
  549. case 'date': echo $a_date_format; break;
  550. case 'readmore':
  551. case 'comments': ; break;
  552. case 'edit': if ($_SESSION[db('website').'Logged_In'] == token()) {echo ' '.$edit_link;} break;
  553. default: echo $tag;
  554. }
  555. }
  556. }
  557. else if ($_SESSION[db('website').'Logged_In'] == token()) {echo '<p>'.$edit_link.'</p>';}
  558. }
  559. }
  560. if (!empty($currentPage) && ($numrows_articles > $article_limit) && s('display_pagination') == 'on') {
  561. paginator($categorySEF, $currentPage, $totalPages, '', l('paginator'));
  562. }
  563. if (!empty($article) && empty($currentPage) && $infoline == true) {
  564. if ($commentable == 'YES') {comment('unfreezed');}
  565. else if ($commentable == 'FREEZ') {comment('freezed');}
  566. }}}}
  567.  
  568. // COMMENTS
  569. function comment($freeze_status) {
  570. $categorySEF = get_id('category'); $articleSEF = get_id('article');
  571. if (strpos($articleSEF, l('paginator')) === 0) {$articleSEF = str_replace(l('paginator'), '', $articleSEF);}
  572. $query = "SELECT id FROM ".db('prefix')."articles WHERE seftitle = '$articleSEF'";
  573. $result = mysql_query($query);
  574. while ($r = mysql_fetch_array($result)) {$articleId = $r['id'];}
  575. $commentsPage = get_id('commentspage');
  576. if (!isset($commentsPage) || !is_numeric($commentsPage) || $commentsPage < 1) {$commentsPage = 1;}
  577. $comments_order = s('comments_order');
  578. if (isset($_POST['comment'])) {
  579. $comment = cleanWords(trim($_POST['text']));
  580. $comment = strlen($comment) > 4 ? clean(cleanXSS($comment)) : null;
  581. $name = trim($_POST['name']);
  582. $name = strlen($name) > 1 ? clean(cleanXSS($name)) : null;
  583. $url = trim($_POST['url']);
  584. $url = (strlen($url) > 8 && strpos($url, '?') === false) ? clean(cleanXSS($url)) : null;
  585. $now = is_numeric($_POST['time']) ? $_POST['time'] : null;
  586. $post_article_id = (is_numeric($_POST['id']) && $_POST['id'] > 0) ? $_POST['id'] : null;
  587. $ip = (strlen($_POST['ip']) < 16) ? clean(cleanXSS($_POST['ip'])) : null;
  588. $doublecheck = retrieve('id', 'comments', 'comment', $comment);
  589. if ($ip == $_SERVER['REMOTE_ADDR'] && (time() - $now) > 4 && $comment && $name && $post_article_id && is_numeric($_POST['calc']) && mathCaptcha($_POST['calc'], $_POST['sum']) && !isset($doublecheck)) {
  590. $url = preg_match('/((http)+(s)?:(\/\/)|(www\.))([a-z0-9_\-]+)/', $url) ? $url : '';
  591. $url = substr($url, 0, 3) == 'www' ? 'http://'.$url : $url;
  592. $time = date("Y-m-d H:i:s");
  593. if(s('approve_comments') != 'on') {$approved = 'True';}
  594. $query = "INSERT INTO ".db('prefix')."comments(articleid, name, url, comment, time, approved) VALUES('$post_article_id', '$name', '$url', '$comment', '$time', '$approved')";
  595. mysql_query($query);
  596. $commentStatus = s('approve_comments') == 'on' ? l('comment_sent_approve') : l('comment_sent');
  597. }
  598. else {$commentStatus = l('comment_error'); $commentReason = l('ce_reasons');}
  599. echo '<h2>'.$commentStatus.'</h2>';
  600. if (!empty($commentReason)) {echo '<p>'.$commentReason.'</p>';}
  601. $postCat = clean(cleanXSS($_POST['category']));
  602. $postArt = clean(cleanXSS($_POST['article']));
  603. $back_link = db('website').$postCat.'/'.$postArt.'/';
  604. echo '<meta http-equiv="refresh" content="1; url='.db('website').$postCat.'/'.$postArt.'/">';
  605. }
  606. else {
  607. $commentCount = s('comment_limit');
  608. $comment_limit = (empty($commentCount) || $commentCount < 1) ? 100 : $commentCount;
  609. if(isset($commentsPage)) {$pageNum = $commentsPage;}
  610. $offset = ($pageNum - 1) * $comment_limit;
  611. $totalrows = "SELECT id FROM ".db('prefix')."comments WHERE articleid = $articleId AND approved = 'True'";
  612. $rowsresult = mysql_query($totalrows);
  613. $numrows = mysql_num_rows($rowsresult);
  614. if (!$numrows || !$rowsresult) {
  615. if ($freeze_status != 'freezed') {echo '<p>'.l('no_comment').'</p>';}
  616. }
  617. else {
  618. $query = "SELECT * FROM ".db('prefix')."comments WHERE articleid = $articleId AND approved = 'True' ORDER BY id $comments_order LIMIT $offset, $comment_limit";
  619. $result = mysql_query($query) or die(db('dberror'));
  620. $ordinal = 1;
  621. $date_format = s('date_format');
  622. $edit_link = ' <a href="'.db('website').'index.php?action=';
  623. while ($r = mysql_fetch_array($result)) {
  624. $date = date($date_format, strtotime($r['time']));
  625. $commentNum = $offset + $ordinal;
  626. $tag = explode(',', tags('comments'));
  627. foreach ($tag as $tag) {
  628. switch (true) {
  629. case ($tag == 'date'):
  630. echo '<a id="'.l('comment').$commentNum.'" name="'.l('comment').$commentNum.'" title="'.l('comment').' '.$commentNum.'"></a>'.$date;
  631. break;
  632. case ($tag == 'name'): $name = $r['name']; echo !empty($r['url']) ? '<a href="'.$r['url'].'" title="'.$r['url'].'" rel="nofollow">'.$name.'</a> ' : $name; break;
  633. case ($tag == 'comment'): echo $r['comment']; break;
  634. case ($tag == 'edit' && $_SESSION[db('website').'Logged_In'] == token()):
  635. echo $edit_link.'editcomment&amp;commentid='.$r['id'].'" title="'.l('edit').' '.l('comment').'">'.l('edit').'</a> ';
  636. echo $edit_link.'process&amp;task=deletecomment&amp;articleid='.$r['articleid'].'&amp;commentid='.$r['id'].'" title="'.l('delete').' '.l('comment').'" onclick="return pop()">'.l('delete').'</a>';
  637. break; case ($tag == 'edit'): ; break; default: echo $tag;
  638. }
  639. }
  640. $ordinal++;
  641. }
  642. $maxPage = ceil($numrows / $comment_limit); $back_to_page = ceil(($numrows + 1) / $comment_limit);
  643. if ($maxPage > 1) {paginator($categorySEF, $pageNum, $maxPage, $articleSEF, '');}
  644. }
  645. if ($freeze_status != 'freezed') {
  646. echo '<div class="commentsbox"><h2>'.l('addcomment').'</h2>';
  647. echo '<p>'.l('required').'</p>';
  648. echo html_input('form', '', 'post', '', '', '', '', '', '', '', '', '', 'post', db('website'), '');
  649. echo html_input('text', 'name', 'name', '', '* '.l('name'), 'text', '', '', '', '', '', '', '', '', '');
  650. echo html_input('text', 'url', 'url', '', l('url'), 'text', '', '', '', '', '', '', '', '', '');
  651. echo html_input('textarea', 'text', 'text', '', '* '.l('comment'), '', '', '', '', '', '5', '5', '', '', '');
  652. echo mathCaptcha();
  653. echo '<p>';
  654. echo html_input('hidden', 'category', 'category', $categorySEF, '', '', '', '', '', '', '', '', '', '', '');
  655. echo html_input('hidden', 'id', 'id', $articleId, '', '', '', '', '', '', '', '', '', '', '');
  656. echo html_input('hidden', 'article', 'article', $articleSEF, '', '', '', '', '', '', '', '', '', '', '');
  657. echo html_input('hidden', 'commentspage', 'commentspage', $back_to_page, '', '', '', '', '', '', '', '', '', '', '');
  658. echo html_input('hidden', 'ip', 'ip', $_SERVER['REMOTE_ADDR'], '', '', '', '', '', '', '', '', '', '', '');
  659. echo html_input('hidden', 'time', 'time', time(), '', '', '', '', '', '', '', '', '', '', '');
  660. echo html_input('submit', 'comment', 'comment', l('submit'), '', 'button', '', '', '', '', '', '', '', '', '');
  661. echo '</p></form></div>';
  662. }}}
  663.  
  664. // ARCHIVE
  665. function archive() {
  666. echo '<h2>'.l('archive').'</h2>';
  667. $query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = 1 ORDER BY date DESC";
  668. $result = mysql_query($query);
  669. echo '<p>';
  670. if (!$result || !mysql_num_rows($result)) {echo l('article_not_exist');}
  671. else {
  672. $home = l('home_sef');
  673. $home_name = l('home');
  674. $month_names = explode(', ', l('month_names'));
  675. while ($r = mysql_fetch_array($result)) {
  676. $year = substr($r['date'], 0, 4);
  677. $month = substr($r['date'], 5, 2) -1;
  678. $month_name = (substr($month, 0, 1) == 0) ? $month_names[substr($month, 1, 1)] : $month_names[$month];
  679. $categorySEF = $r['category'] != 0 ? find_cat_sef($r['category']) : $home;
  680. $articleSEF = retrieve('seftitle', 'articles', 'id', $r['id']);
  681. $cat_name = $r['category'] != 0 ? retrieve('name', 'categories', 'seftitle', $categorySEF) : $home_name;
  682. $title = $r['title'];
  683. if ($last <> $year.$month) {echo '<strong>'.$month_name.', '.$year.'</strong><br />';}
  684. echo l('divider').' <a href="'.db('website').$categorySEF.'/'.$articleSEF.'/" title="'.$title.'">'.$title.'</a> ('.$cat_name.')<br />';
  685. $last = $year.$month;
  686. }
  687. }
  688. echo '</p>';
  689. }
  690.  
  691. //SITEMAP
  692. function sitemap() {
  693. echo '<h2>'.l('sitemap').'</h2>';
  694. echo '<p><strong>'.l('pages').'</strong></p>';
  695. $link = l('divider').' <a href="'.db('website');
  696. echo '<p>'.$link.'" title="'.l('home').'">'.l('home').'</a><br />';
  697. echo l('divider').' <a href="'.db('website').'archive/">'.l('archive').'</a><br />';
  698. $query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 AND published = '1' ORDER BY date";
  699. $result = mysql_query($query);
  700. $home = l('home_sef');
  701. while ($r = mysql_fetch_array($result)) {
  702. $page_title = $r['title'];
  703. if ($r['id'] != s('display_page')) {echo l('divider').' <a href="'.db('website').$home.'/'.$r['seftitle'].'/" title="'.$page_title.'">'.$page_title.'</a><br />';}
  704. }
  705. echo $link.'contact/">'.l('contact').'</a><br />';
  706. echo $link.'sitemap/">'.l('sitemap').'</a><br />';
  707. echo $link.'rss/">'.l('rss_feed').'</a></p>';
  708. echo '<p><strong>'.l('articles').'</strong></p>';
  709. $art_query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = '1'";
  710. $query = $art_query." AND category = 0 ORDER BY date DESC";
  711. $result = mysql_query($query);
  712. echo '<p><strong><a href="'.db('website').'" title="'.l('home').'">'.l('home').'</a></strong><br />';
  713. while ($r = mysql_fetch_array($result)) {
  714. $art_title = $r['title'];
  715. echo $link.find_cat_sef($r['category']).'/'.$r['seftitle'].'/" title="'.$art_title.'">'.$art_title.'</a><br />';
  716. }
  717. echo '</p>';
  718. $cat_query = "SELECT * FROM ".db('prefix')."categories WHERE published = 'YES' ORDER BY catorder";
  719. $cat_result = mysql_query($cat_query);
  720. while ($c = mysql_fetch_array($cat_result)) {
  721. echo '<p><strong><a href="'.db('website').$c['seftitle'].'/" title="'.$c['description'].'">'.$c['name'].'</a></strong><br />';
  722. $catid = $c['id'];
  723. $query = $art_query." AND category = $catid ORDER BY id DESC";
  724. $result = mysql_query($query);
  725. while ($r = mysql_fetch_array($result)) {
  726. $date = date(s('date_format'), strtotime($r['date']));
  727. echo $link.$c['seftitle'].'/'.$r['seftitle'].'/" title="'.$r['title'].'">'.$r['title'].'</a><br />';
  728. }
  729. echo '</p>';
  730. }}
  731.  
  732. //NOTIFICATION
  733. function notification($error=0, $note='', $link='') {
  734. $title = $error== 0 ? l('operation_completed') : l('admin_error');
  735. $note = (!$note || empty($note)) ? '' : '<p>'.$note.'</p>';
  736. switch(true){
  737. case (!$link): $goto = ''; break;
  738. case ($link == 'home'): $goto = '<p><a href="'.db('website').'" title="'.l('backhome').'">'.l('backhome').'</a></p>'; break;
  739. case ($link != 'home'): $goto = '<p><a href="'.db('website').$link.'/" title="'.$link.'">'.l('back').'</a></p>'; break;
  740. }
  741. $output = '<h2>'.$title.'</h2>'.$note.$goto;
  742. return $output;
  743. }
  744.  
  745. // CONTACT FORM
  746. function contact() {
  747. if (!isset($_POST['contactform'])) {
  748. echo '<div class="commentsbox"><h2>'.l('contact').'</h2>';
  749. echo '<p>'.l('required').'</p>';
  750. echo html_input('form', '', 'post', '', '', '', '', '', '', '', '', '', 'post', db('website'), '');
  751. echo html_input('text', 'name', 'name', '', '* '.l('name'), 'text', '', '', '', '', '', '', '', '', '');
  752. echo html_input('text', 'email', 'email', '', '* '.l('email'), 'text', '', '', '', '', '', '', '', '', '');
  753. echo html_input('text', 'weblink', 'weblink', '', l('url'), 'text', '', '', '', '', '', '', '', '', '');
  754. echo html_input('textarea', 'message', 'message', '', '* '.l('message'), '', '', '', '', '', '5', '5', '', '', '');
  755. echo mathCaptcha();
  756. echo '<p>';
  757. echo html_input('hidden', 'ip', 'ip', $_SERVER['REMOTE_ADDR'], '', '', '', '', '', '', '', '', '', '', '');
  758. echo html_input('hidden', 'time', 'time', time(), '', '', '', '', '', '', '', '', '', '', '');
  759. echo html_input('submit', 'contactform', 'contactform', l('submit'), '', 'button', '', '', '', '', '', '', '', '', '');
  760. echo '</p></form></div>';
  761. $_SESSION[db('website').'contact'] = 0;
  762. }
  763. else {
  764. $to = s('website_email');
  765. $subject = s('contact_subject');
  766. $name = trim($_POST['name']);
  767. $name = strlen($name) > 1 ? clean(cleanXSS($name)) : null;
  768. $mail = trim($_POST['email']);
  769. $mail = trim($_POST['email']);
  770. $mail = (strlen($mail) > 7 && preg_match( '/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i' , $mail)) ? clean(cleanXSS($mail)) : null;
  771. $url = trim($_POST['weblink']);
  772. $url = (strlen($url) > 8 && strpos($url, '?') === false) ? clean(cleanXSS($url)) : null;
  773. $message = trim($_POST['message']);
  774. $message = strlen($message) > 9 ? stripslashes(cleanXSS($message)) : null;
  775. $message = strip_tags($message);
  776. $now = is_numeric($_POST['time']) ? $_POST['time'] : null;
  777. $ip = (strlen($_POST['ip']) < 16) ? clean(cleanXSS($_POST['ip'])) : null;
  778. if($_SESSION[db('website').'contact'] == 0){
  779. if ($ip == $_SERVER['REMOTE_ADDR'] && (time() - $now) > 4 && $name && $mail && $message && mathCaptcha($_POST['calc'], $_POST['sum'])) {
  780. $header = "MIME-Version: 1.0\n";
  781. $header .= "Content-type: text/plain; charset=".s('charset')."\n";
  782. $header .= "From: $name <$mail>\r\nReply-To: $name <$mail>\r\nReturn-Path: <$mail>\r\n";
  783. $addUrl = isset($url) ? l('url').': '.$url."\n\n" : '';
  784. $body = "Message from: ".$name." <$mail>\n".$addUrl.l('message').":\n".$message;
  785. mail($to, $subject, $body, $header);
  786. echo notification(0,l('contact_sent'),'home');
  787. $_SESSION[db('website').'contact'] = 1;
  788. }
  789. else {echo notification(1,l('contact_not_sent'),'contact');}
  790. }}}
  791.  
  792. // MENU ARTICLES
  793. function menu_articles($start, $size) {
  794. $query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = 1 ORDER BY date DESC LIMIT $start, $size";
  795. $result = mysql_query($query);
  796. if (!$result || !mysql_num_rows($result)) {echo '<li>'.l('no_articles').'</li>';}
  797. else {
  798. $home = l('home_sef');
  799. while ($r = mysql_fetch_array($result)) {
  800. $date = date(s('date_format'), strtotime($r['date']));
  801. $categorySEF = find_cat_sef($r['category']);
  802. $title = $r['category'] == 0 ? $home : retrieve('name', 'categories', 'seftitle', $categorySEF);
  803. echo '<li><a href="'.db('website').$categorySEF.'/'.$r['seftitle'].'/" title="'.$title.' ('.$date.')">'.$r['title'].'</a></li>';
  804. }}}
  805.  
  806. // NEW COMMENTS
  807. function new_comments($number, $stringlen) {
  808. $query = "SELECT * FROM ".db('prefix')."comments WHERE approved = 'True' ORDER BY id DESC LIMIT $number";
  809. $result = mysql_query($query);
  810. if (!$result || !mysql_num_rows($result)) {echo '<li>'.l('no_comments').'</li>';}
  811. else {
  812. $comment_limit = s('comment_limit') < 1 ? 1 : s('comment_limit');
  813. $comments_order = s('comments_order');
  814. while ($r = mysql_fetch_array($result)) {
  815. $art_query = "SELECT id FROM ".db('prefix')."comments WHERE articleid = '$r[articleid]' AND approved = 'True' ORDER BY id $comments_order";
  816. $art_result = mysql_query($art_query);
  817. $num = 1;
  818. while ($r_art = mysql_fetch_array($art_result)) {
  819. if ($r_art['id'] == $r['id']) {$ordinal = $num;}
  820. $num++;
  821. }
  822. $name = $r['name'];
  823. $comment = strip_tags($r['comment']);
  824. $page = ceil($ordinal / $comment_limit);
  825. $ncom = $name.' ('.$comment;
  826. $ncom = strlen($ncom) > $stringlen ? substr($ncom, 0, $stringlen - 3).'...' : $ncom;
  827. $ncom.= strlen($name) < $stringlen ? ')' : '';
  828. $ncom = str_replace(' ...', '...', $ncom);
  829. $articleSEF = retrieve('seftitle', 'articles', 'id', $r['articleid']);
  830. $articleCat = retrieve('category', 'articles', 'seftitle', $articleSEF);
  831. $categorySEF = find_cat_sef($articleCat);
  832. if (!empty($articleSEF)) {
  833. $paging = $page > 1 ? '/'.$page : '';
  834. echo '<li><a href="'.db('website').$categorySEF.'/'.$articleSEF.$paging.'/#'.l('comment').$ordinal.'" title="'.l('comment_info').' '.retrieve('title', 'articles', 'id', $r['articleid']).'">'.$ncom.'</a></li>';
  835. }}}}
  836.  
  837. // SEARCH FORM
  838. function searchform() { ?>
  839. <form id="search_engine" method="post" action="<?php echo db('website'); ?>" accept-charset="<?php echo s('charset');?>">
  840. <p><input class="searchfield" name="search_query" type="text" id="keywords" value="<?php echo l('search_keywords'); ?>" onfocus="document.forms['search_engine'].keywords.value='';" onblur="if (document.forms['search_engine'].keywords.value == '') document.forms['search_engine'].keywords.value='<?php echo l('search_keywords'); ?>';" />
  841. <input class="searchbutton" name="submit" type="submit" value="<?php echo l('search_button')?>" /></p>
  842. </form>
  843. <?php }
  844.  
  845. //SEARCH ENGINE
  846. function search() {
  847. $search_query = clean(cleanXSS($_POST['search_query']));
  848. echo '<h2>'.l(search_results).'</h2>';
  849. if (strlen($search_query) < 4 || $search_query == l('search_keywords')) {echo '<p>'.l(charerror).'</p>';}
  850. else {
  851. $keywords = explode(' ', $search_query);
  852. $keyCount = count($keywords);
  853. $query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) != '2' AND published = 1 AND";
  854. if ($keyCount > 1) {
  855. for ($i = 0; $i < $keyCount - 1; $i++) {$query = $query." (title LIKE '%$keywords[$i]%' || text LIKE '%$keywords[$i]%') &&";}
  856. $j = $keyCount - 1;
  857. $query = $query." (title LIKE '%$keywords[$j]%' || text LIKE '%$keywords[$j]%')";
  858. }
  859. else {$query = $query." (title LIKE '%$keywords[0]%' || text LIKE '%$keywords[0]%')";}
  860. $query = $query." ORDER BY id DESC";
  861. $result = mysql_query($query);
  862. $numrows = mysql_num_rows($result);
  863. if (!$numrows) {echo '<p>'.l('noresults').' <strong>'.stripslashes($search_query).'</strong>.</p>';}
  864. else {
  865. echo '<p><strong>'.$numrows.'</strong> '.l('resultsfound').' <strong>'.stripslashes($search_query).'</strong>.</p>';
  866. while ($r = mysql_fetch_array($result)) {
  867. $date = date(s('date_format'), strtotime($r['date']));
  868. echo '<p><a href="'.db('website').find_cat_sef($r['category']).'/'.$r['seftitle'].'/">'.$r['title'].'</a> - '.$date.'</p>';
  869. }
  870. }
  871. }
  872. echo '<p><br /><a href="'.db('website').'">'.l('backhome').'</a></p>';
  873. $searched = true;
  874. }
  875.  
  876. // RSS FEED - ARTICLES/PAGES/COMMENTS
  877. function rss_contents($rss_item, $artSEF=''){
  878. header('Content-type: text/xml; charset='.s('charset').'');
  879. $limit = s('rss_limit');
  880. switch($rss_item) {
  881. case 'rss-articles':
  882. $heading = l('articles');
  883. $query = "articles WHERE position = 1 AND published = 1 ORDER BY date";
  884. break;
  885. case 'rss-pages':
  886. $heading = l('pages');
  887. $query = "articles WHERE position = 3 AND published = 1 ORDER BY date";
  888. break;
  889. case 'rss-comments':
  890. $heading = l('comments');
  891. $artId = retrieve('id','articles','seftitle',$artSEF);
  892. $articleId = ($artId && is_numeric($artId)) ? "AND articleid = $artId" : '';
  893. $query = "comments WHERE approved = 'True' $articleId ORDER BY id";
  894. break;
  895. }
  896. $header = '<?xml version="1.0" encoding="'.s('charset').'"?>';
  897. $header .= '<rss version="2.0">';
  898. $header .= '<channel>';
  899. $header .= '<title><![CDATA['.s('website_title').']]></title>';
  900. $header .= '<description><![CDATA['.$heading.']]></description>';
  901. $header .= '<link>'.db('website').'</link>';
  902. $header .= '<copyright><![CDATA[Copyright '.s('website_title').']]></copyright>';
  903. $header .= '<generator>sNews CMS</generator>';
  904. $footer = '</channel>';
  905. $footer .= '</rss>';
  906. echo $header;
  907. $result = mysql_query("SELECT * FROM ".db('prefix')."$query DESC LIMIT $limit");
  908. $numrows = mysql_num_rows($result);
  909. $comments_order = s('comments_order');
  910. $ordinal = $comments_order == 'DESC' ? 1 : $numrows;
  911. $comment_limit = s('comment_limit') < 1 ? 1 : s('comment_limit');
  912. $comments_order = s('comments_order');
  913. while ($r = mysql_fetch_assoc($result)) {
  914. switch($rss_item) {
  915. case 'rss-articles':
  916. case 'rss-pages':
  917. $date = date('D, d M Y H:i:s +0000', strtotime($r['date']));
  918. $categorySEF = find_cat_sef($r['category']);
  919. $articleSEF = $r['seftitle'];
  920. $title = $r['title'];
  921. $text = $r['text'];
  922. break;
  923. case 'rss-comments';
  924. $subquery = "SELECT * FROM ".db('prefix')."comments WHERE articleid = $r[articleid] ORDER BY id $comments_order";
  925. $subresult = mysql_query($subquery);
  926. $num = 1;
  927. while ($subr = mysql_fetch_array($subresult)) {
  928. if ($subr['id'] == $r['id']) {$ordinal = $num;}
  929. $num++;
  930. }
  931. $page = ceil($ordinal / $comment_limit);
  932. $articleSEF = retrieve('seftitle', 'articles', 'id', $r['articleid']);
  933. $articleCat = retrieve('category', 'articles', 'seftitle', $articleSEF);
  934. $articleTitle = retrieve('title', 'articles', 'id', $r['articleid']);
  935. $categorySEF = find_cat_sef($articleCat);
  936. if (!empty($articleSEF)) {
  937. $paging = $page > 1 ? $page.'/' : '';
  938. $comment_link = $paging.'#'.l('comment').$ordinal;
  939. }
  940. $date = date('D, d M Y H:i:s +0000', strtotime($r['time']));
  941. $title = $articleTitle.' - '.$r['name'];
  942. $text = $r['comment'];
  943. break;
  944. }
  945. $link = db('website').$categorySEF.'/'.$articleSEF.'/'.$comment_link;
  946. $item = '<item>';
  947. $item .= '<title><![CDATA['.strip($title).']]></title>';
  948. $item .= '<description><![CDATA['.strip($text).']]></description>';
  949. $item .= '<pubDate>'.$date.'</pubDate>';
  950. $item .= '<link>'.$link.'</link>';
  951. $item .= '<guid>'.$link.'</guid>';
  952. $item .= '</item>';
  953. echo $item;
  954. }
  955. echo $footer;
  956. exit;
  957. }
  958.  
  959. // RSS FEED - LINK BUILDER
  960. function rss_links(){
  961. echo '<li>';
  962. echo '<a href="rss-articles/" title="'.l('rss_articles').'">'.l('rss_articles').'</a>';
  963. echo '</li>';
  964. $page_count = retrieve('COUNT(id)','articles','position',3);
  965. if ($page_count > 0) {
  966. echo '<li>';
  967. echo '<a href="rss-pages/" title="'.l('rss_pages').'">'.l('rss_pages').'</a>';
  968. echo '</li>';
  969. }
  970. echo '<li>';
  971. echo '<a href="rss-comments/" title="'.l('rss_comments').'">'.l('rss_comments').'</a>';
  972. echo '</li>';
  973. $articleSEF = get_id('article');
  974. if ($articleSEF) {
  975. $articleId = retrieve('id','articles','seftitle',$articleSEF);
  976. $comment_count = retrieve('COUNT(id)','comments','articleid',$articleId);
  977. if ($comment_count > 0) {
  978. echo '<li>';
  979. echo '<a href="rss-comments/'.$articleSEF.'/" title="'.l('rss_comments_article').'">'.l('rss_comments_article').'</a>';
  980. echo '</li>';
  981. }}}
  982.  
  983. // PREPARING ARTICLE FOR XML
  984. function strip($text) {
  985. $search = array('/\[include\](.*?)\[\/include\]/', '/\[break\]/', '/</', '/>/');
  986. $replace = array('', '', ' <', '> ');
  987. $output = preg_replace($search, $replace, $text);
  988. $output = stripslashes(strip_tags($output));
  989. return $output;
  990. }
  991.  
  992. // HTML ENTITIES
  993. function entity($item) {
  994. $item = htmlspecialchars($item, ENT_QUOTES, s('charset'));
  995. return $item;
  996. }
  997.  
  998. /*** ADMINISTRATIVE FUNCTIONS ***/
  999.  
  1000. // LOGIN
  1001. function login() {
  1002. if ($_SESSION[db('website').'Logged_In'] != token()) {
  1003. echo '<h2>'.l('login').'</h2>';
  1004. echo html_input('form', '', 'post', '', '', '', '', '', '', '', '', '', 'post', db('website').'administration/', '');
  1005. echo '<p>'.l('login_limit').'</p>';
  1006. echo html_input('text', 'uname', 'uname', '', l('username'), 'text', '', '', '', '', '', '', '', '', '');
  1007. echo html_input('password', 'pass', 'pass', '', l('password'), 'text', '', '', '', '', '', '', '', '', '');
  1008. echo mathCaptcha();
  1009. echo '<p>';
  1010. echo html_input('hidden', 'Loginform', 'Loginform', 'True', '', '', '', '', '', '', '', '', '', '', '');
  1011. echo html_input('submit', 'submit', 'submit', l('login'), '', 'button', '', '', '', '', '', '', '', '', '');
  1012. echo '</p></form>';
  1013. }
  1014. else {echo '<h2>'.l('logged_in').'</h2><p><a href="'.db('website').'logout/" title="'.l('logout').'">'.l('logout').'</a></p>';}
  1015. }
  1016.  
  1017. //CONTENTS COUNTER
  1018. function stats($field, $position) {
  1019. if (!empty($position)) {$pos = $position == 2 ? " WHERE SUBSTRING(position, 1, 1)= '$position'" :" WHERE position = '$position'";}
  1020. $query = 'SELECT id FROM '.db('prefix').$field.$pos;
  1021. $result = mysql_query($query);
  1022. $numrows = mysql_num_rows($result);
  1023. return $numrows;
  1024. }
  1025.  
  1026. // FORM GENERATOR
  1027. function html_input($type, $name, $id, $value, $label, $css, $script1, $script2, $script3, $checked, $rows, $cols, $method, $action, $legend) {
  1028. $lbl = !empty($label) ? '<label for="'.$id.'">'.$label.'</label>' : '';
  1029. $ID = !empty($id) ? ' id="'.$id.'"' : '';
  1030. $style = !empty($css) ? ' class="'.$css.'"' : '';
  1031. $js1 = !empty($script1) ? ' '.$script1 : '';
  1032. $js2 = !empty($script2) ? ' '.$script2 : '';
  1033. $js3 = !empty($script3) ? ' '.$script3 : '';
  1034. $attribs = $ID.$style.$js1.$js2.$js3;
  1035. $val = ' value="'.$value.'"';
  1036. $input = '<input type="'.$type.'" name="'.$name.'"'.$attribs;
  1037. switch($type) {
  1038. case 'form': $output = (!empty($method) && $method != 'end') ? '<form method="'.$method.'" action="'.$action.'"'.$attribs.' accept-charset="'.s('charset').'">' : '</form>'; break;
  1039. case 'fieldset': $output = (!empty($legend) && $legend != 'end') ? '<fieldset><legend'.$attribs.'>'.$legend.'</legend>' : '</fieldset>'; break;
  1040. case 'text':
  1041. case 'password': $output = '<p>'.$lbl.':<br />'.$input.$val.' /></p>'; break;
  1042. case 'checkbox':
  1043. case 'radio': $check = $checked == 'ok' ? ' checked="checked"' : ''; $output = '<p>'.$input.$check.' /> '.$lbl.'</p>'; break;
  1044. case 'hidden':
  1045. case 'submit':
  1046. case 'reset':
  1047. case 'button': $output = $input.$val.' />'; break;
  1048. case 'textarea': $output = '<p>'.$lbl.':<br /><textarea name="'.$name.'" rows="'.$rows.'" cols="'.$cols.'"'.$attribs.'>'.$value.'</textarea></p>'; break;
  1049. }
  1050. return $output;
  1051. }
  1052.  
  1053. // ADMINISTRATION FORM
  1054. function administration() {
  1055. if ($_SESSION[db('website').'Logged_In'] != token()) {echo notification(1,l('err_Login'),'login');}
  1056. else {
  1057. foreach ($_POST as $key) {unset($_POST[$key]);}
  1058. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '','<a href="http://snews.solucija.com/" title="sNews CMS">sNews</a> '.l('administration'));
  1059. echo '<p>'.l('categories').': <a href="admin_category/" title="'.l('add_new').'">'.l('add_new').'</a>';
  1060. $link = ' '.l('divider').' <a href="';
  1061. if (stats('categories','') > 0) {echo $link.'categories/" title="'.l('view').'">'.l('view').'</a>';}
  1062. echo '</p>';
  1063. echo '<p>'.l('articles').': <a href="article_new/" title="'.l('add_new').'">'.l('add_new').'</a>';
  1064. if (stats('articles',1) > 0) {echo $link.'articles/" title="'.l('view').'">'.l('view').'</a>';}
  1065. echo '</p>';
  1066. echo '<p>'.l('extra_contents').': <a href="extra_new/" title="'.l('add_new').'">'.l('add_new').'</a>';
  1067. if (stats('articles',2) > 0) {echo $link.'extra_contents/" title="'.l('view').'">'.l('view').'</a>';}
  1068. echo '</p>';
  1069. echo '<p>'.l('pages').': <a href="page_new/" title="'.l('add_new').'">'.l('add_new').'</a>';
  1070. if (stats('articles',3) > 0) {echo $link.'pages/" title="'.l('view').'">'.l('view').'</a>';}
  1071. echo '</p></fieldset>';
  1072. $query_comm = "SELECT * FROM ".db('prefix')."comments WHERE approved <> 'True'";
  1073. $result_comm = mysql_query($query_comm);
  1074. $unapproved = mysql_num_rows($result_comm);
  1075. if ($unapproved > 0) {
  1076. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', l('comments'));
  1077. echo '<p><a onclick="toggle(\'sub1\')" style="cursor: pointer;" title="'.l('unapproved').'">'.$unapproved.' '.l('wait_approval').'</a></p>';
  1078. echo '<div id="sub1" style="display: none;">';
  1079. while ($r = mysql_fetch_array($result_comm)) {
  1080. $articleTITLE = retrieve(title, articles, id, $r['articleid']);
  1081. echo '<p>'.$r['name'].' (<strong>'.$articleTITLE.'</strong>) '.l('divider').' <a href="'.db('website').'index.php?action=editcomment&amp;commentid='.$r['id'].'">'.l('edit').'</a></p>';
  1082. }
  1083. echo '</div>';
  1084. }
  1085. if ($unapproved > 0) {echo '</fieldset>';}
  1086. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', l('site_settings'));
  1087. echo '<p><a href="settings/" title="'.l('settings').'">'.l('settings').'</a></p>';
  1088. echo '<p><a href="files/" title="'.l('files').'">'.l('files').'</a></p></fieldset>';
  1089. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', l('login_status'));
  1090. echo '<p><a href="logout/" title="'.l('logout').'">'.l('logout').'</a></p></fieldset>';
  1091. }}
  1092.  
  1093. // SETTINGS FORM
  1094. function settings() {
  1095. echo html_input('form', '', '', '', '', '', '', '', '', '', '', '', 'post', 'index.php?action=process&amp;task=save_settings', '');
  1096. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '','<a title="'.l('settings').'" onclick="toggle(\'sub1\')" style="cursor: pointer;">'.l('settings').'</a>');
  1097. echo '<div id="sub1" style="display: none;">';
  1098. echo html_input('text', 'website_title', 'webtitle', s('website_title'), l('a_website_title'), '', '', '', '', '', '', '', '', '', '');
  1099. echo html_input('text', 'home_sef', 'webSEF', s('home_sef') == '' ? l('home_sef') : s('home_sef'), l('a_home_sef'), '', 'onkeypress="return SEFrestrict(event);"', '', '', '', '', '', '', '', '');
  1100. echo html_input('text', 'website_description', 'wdesc', s('website_description'), l('a_description'), '', '', '', '', '', '', '', '', '', '');
  1101. echo html_input('text', 'website_keywords', 'wkey', s('website_keywords'), l('a_keywords'), '', '', '', '', '', '', '', '', '', '');
  1102. echo '</div></fieldset>';
  1103. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', '<a title="'.l('a_contact_info').'" onclick="toggle(\'sub2\')" style="cursor: pointer;">'.l('a_contact_info').'</a>');
  1104. echo '<div id="sub2" style="display: none;">';
  1105. echo html_input('text', 'website_email', 'we', s('website_email'), l('a_website_email'), '', '', '', '', '', '', '', '', '', '');
  1106. echo html_input('text', 'contact_subject', 'cs', s('contact_subject'), l('a_contact_subject'), '', '', '', '', '', '', '', '', '', '');
  1107. echo '</div></fieldset>';
  1108. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', '<a title="'.l('a_time_settings').'" onclick="toggle(\'sub3\')" style="cursor: pointer;">'.l('a_time_settings').'</a>');
  1109. echo '<div id="sub3" style="display: none;">';
  1110. echo html_input('text', 'language', 'lang', s('language') == '' ? 'EN' : s('language'), l('a_language'), '', '', '', '', '', '', '', '', '', '');
  1111. echo html_input('text', 'charset', 'char', s('charset') == '' ? 'UTF-8' : s('charset'), l('charset'), '', '', '', '', '', '', '', '', '', '');
  1112. echo html_input('text', 'date_format', 'dt', s('date_format'), l('a_date_format'), '', '', '', '', '', '', '', '', '', '');
  1113. echo '</div></fieldset>';
  1114. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '','<a title="'.l('contents').'" onclick="toggle(\'sub4\')" style="cursor: pointer;">'.l('contents').'</a>');
  1115. echo '<div id="sub4" style="display: none;">';
  1116. echo html_input('text', 'article_limit', 'artl', s('article_limit'), l('a_article_limit'), '', '', '', '', '', '', '', '', '', '');
  1117. echo html_input('text', 'rss_limit', 'rssl', s('rss_limit'), l('a_rss_limit'), '', '', '', '', '', '', '', '', '', '');
  1118. echo '<p><label for="dp">'.l('a_display_page').':</label> <select name="display_page" id="dp">';
  1119. echo '<option value="0"'.(s('display_page') == 0 ? ' selected="selected"' : '').'>'.l('none').'</option>';
  1120. $query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY id ASC";
  1121. $result = mysql_query($query);
  1122. while ($r = mysql_fetch_array($result)) {
  1123. echo '<option value="'.$r['id'].'"';
  1124. if (s('display_page') == $r['id']) {echo ' selected="selected"';}
  1125. echo '>'.$r['title'].'</option>';
  1126. }
  1127. echo '</select></p>';
  1128. echo html_input('checkbox', 'display_new_on_home', 'dnoh', '', l('a_display_new_on_home'), '', '', '', '', (s('display_new_on_home') == 'on' ? 'ok' : ''), '', '', '', '', '');
  1129. echo html_input('checkbox', 'display_pagination', 'dpag', '', l('a_display_pagination'), '', '', '', '', (s('display_pagination') == 'on' ? 'ok' : ''), '', '', '', '', '');
  1130. echo html_input('checkbox', 'num_categories', 'nc', '', l('a_num_categories'), '', '', '', '', (s('num_categories') == 'on' ? 'ok' : ''), '', '', '', '', '');
  1131. echo '</div></fieldset>';
  1132. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', '<a title="'.l('comments').'" onclick="toggle(\'sub5\')" style="cursor: pointer;">'.l('comments').'</a>');
  1133. echo '<div id="sub5" style="display: none;">';
  1134. echo html_input('checkbox', 'approve_comments', 'ac', '', l('a_approve_comments'), '', '', '', '', (s('approve_comments') == 'on' ? 'ok' : ''), '', '', '', '', '');
  1135. echo '<p><label for="co">'.l('a_comments_order').':</label><br /><select id="co" name="comments_order">';
  1136. echo '<option value="DESC"'.(s('comments_order') == 'DESC' ? ' selected="selected"' : '').'>'.l('newer_top').'</option>';
  1137. echo '<option value="ASC"'.(s('comments_order') == 'ASC' ? ' selected="selected"' : '').'>'.l('newer_bottom').'</option></select></p>';
  1138. echo html_input('text', 'comment_limit', 'cl', s('comment_limit'), l('a_comment_limit'), '', '', '', '', '', '', '', '', '', '');
  1139. echo html_input('checkbox', 'word_filter_enable', 'wfe', '', l('a_word_filter_enable'), '', '', '', '', (s('word_filter_enable') == 'on' ? 'ok' : ''), '', '', '', '', '');
  1140. echo html_input('text', 'word_filter_file', 'wff', s('word_filter_file'), l('a_word_filter_file'), '', '', '', '', '', '', '', '', '', '');
  1141. echo html_input('text', 'word_filter_change', 'wfc', s('word_filter_change'), l('a_word_filter_change'), '', '', '', '', '', '', '', '', '', '');
  1142. echo '</div></fieldset><p>';
  1143. echo html_input('submit', 'save', 'save', l('save'), '', 'button', '', '', '', '', '', '', '', '', '');
  1144. echo '</p></form>';
  1145. echo html_input('form', '', '', '', '', '', '', '', '', '', '', '', 'post', 'index.php?action=process&amp;task=changeup', '');
  1146. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', '<a title="'.l('change_up').'" onclick="toggle(\'sub6\')" style="cursor: pointer;">'.l('change_up').'</a>');
  1147. echo '<div id="sub6" style="display: none;">';
  1148. echo '<p>'.l('login_limit').'</p>';
  1149. echo html_input('text', 'uname', 'uname', '', l('a_username'), '', '', '', '', '', '', '', '', '', '');
  1150. echo html_input('password', 'pass1', 'pass1', '', l('a_password'), '', '', '', '', '', '', '', '', '', '');
  1151. echo html_input('password', 'pass2', 'pass2', '', l('a_password2'), '', '', '', '', '', '', '', '', '', '');
  1152. echo '<p>';
  1153. echo html_input('hidden', 'task', 'task', 'changeup', '', '', '', '', '', '', '', '', '', '', '');
  1154. echo html_input('submit', 'submit_pass', 'submit_pass', l('save'), '', 'button', '', '', '', '', '', '', '', '', '');
  1155. echo '</p></div></fieldset></form>';
  1156. }
  1157.  
  1158. // CATEGORIES FORM
  1159. function form_categories() {
  1160. if (isset($_GET['id']) && is_numeric($_GET['id']) && !is_null($_GET['id'])) {
  1161. $categoryid = $_GET['id'];
  1162. $query = mysql_query("SELECT * FROM ".db('prefix')."categories WHERE id='$categoryid'");
  1163. $r = mysql_fetch_array($query);
  1164. $frm_action = db('website').'index.php?action=process&amp;task=admin_category&amp;id='.$categoryid;
  1165. $frm_add_edit = l('edit');
  1166. $frm_name = $r['name'];
  1167. $frm_sef_title = $r['seftitle'];
  1168. $frm_description = $r['description'];
  1169. $frm_publish = $r['published'] == 'YES' ? 'ok' : '';
  1170. $frm_task = 'edit_category';
  1171. $frm_submit = l('edit');
  1172. }
  1173. else {
  1174. $frm_action = db('website').'index.php?action=process&amp;task=admin_category';
  1175. $frm_add_edit = l('add_category');
  1176. $frm_name = $_POST['name'];
  1177. $frm_sef_title = $_POST['name'] == '' ? cleanSEF($_POST['name']) : cleanSEF($_POST['seftitle']);
  1178. $frm_description = '';
  1179. $frm_publish = 'ok';
  1180. $frm_task = 'add_category';
  1181. $frm_submit = l('add_category');
  1182. }
  1183. echo html_input('form', '', 'post', '', '', '', '', '', '', '', '', '', 'post', $frm_action, '');
  1184. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', $frm_add_edit);
  1185. echo html_input('text', 'name', 't', $frm_name, l('name'), '', 'onchange="genSEF(this,document.forms[\'post\'].seftitle)"', 'onkeyup="genSEF(this,document.forms[\'post\'].seftitle)"', '', '', '', '', '', '', '');
  1186. echo html_input('text', 'seftitle', 's', $frm_sef_title, l('sef_title_cat'), '', '', '', '', '', '', '', '', '', '');
  1187. echo html_input('text', 'description', 'desc', $frm_description, l('description'), '', '', '', '', '', '', '', '', '', '');
  1188. echo html_input('checkbox', 'publish', 'pub', 'YES', l('publish_category'), '', '', '', '', $frm_publish, '', '', '', '', '');
  1189. echo '</fieldset><p>';
  1190. echo html_input('hidden', 'task', 'task', 'admin_category', '', '', '', '', '', '', '', '', '', '', '');
  1191. echo html_input('submit', $frm_task, $frm_task, $frm_submit, '', 'button', '', '', '', '', '', '', '', '', '');
  1192. if (!empty($categoryid)) {
  1193. echo '&nbsp;&nbsp;';
  1194. echo html_input('hidden', 'id', 'id', $categoryid, '', '', '', '', '', '', '', '', '', '', '');
  1195. echo html_input('submit', 'delete_category', 'delete_category', l('delete'), '', 'button', 'onclick="javascript: return pop()"', '', '', '', '', '', '', '', '');
  1196. }
  1197. echo '</p></form>';
  1198. $query = "SELECT * FROM ".db('prefix')."categories WHERE published = 'YES' ORDER BY catorder ASC";
  1199. $result = mysql_query($query);
  1200. $numrows = mysql_num_rows($result);
  1201. if ($numrows > 1) {
  1202. echo html_input('form', '', '', '', '', '', '', '', '', '', '', '', 'post', 'index.php?action=process&amp;task=order_category', '');
  1203. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', l('category_order'));
  1204. $counter = 0;
  1205. while ($r = mysql_fetch_array($result)) {
  1206. echo '<p><input name="catorder['.$counter.']" type="text" id="cat'.$r['id'].'" value="'.$r['catorder'].'" size="1" /> <label for="cat'.$r['id'].'">'.$r['name'].'</label><input type="hidden" name="counter_id['.$counter.']" value="'.$r['id'].'" /></p>';
  1207. $counter++;
  1208. }
  1209. echo '</fieldset><p>';
  1210. echo html_input('hidden', 'counter', 'counter', $counter, '', '', '', '', '', '', '', '', '', '', '');
  1211. echo html_input('submit', 'order_category', 'order_category', l('order_category'), '', 'button', '', '', '', '', '', '', '', '', '');
  1212. echo '</p></form>';
  1213. }}
  1214.  
  1215. // ARTICLES - POSTING TIME
  1216. function posting_time($time='') {
  1217. echo '<p>'.l('day').':<select name="fposting_day">';
  1218. $thisDay = !empty($time) ? substr($time, 8, 2) : intval(date('d'));
  1219. for($i = 1; $i < 32; $i++) {
  1220. echo '<option value="'.$i.'"';
  1221. if($i == $thisDay) {echo ' selected="selected"';}
  1222. echo '>'.$i.'</option>';
  1223. }
  1224. echo '</select>'.l('month').':<select name="fposting_month">';
  1225. $thisMonth = !empty($time) ? substr($time, 5, 2) : intval(date('m'));
  1226. for($i = 1; $i < 13; $i++) {
  1227. echo '<option value="'.$i.'"';
  1228. if($i == $thisMonth) {echo ' selected="selected"';}
  1229. echo '>'. $i .'</option>';
  1230. }
  1231. echo '</select>'.l('year').':<select name="fposting_year">';
  1232. $thisYear = !empty($time) ? substr($time, 0, 4) : intval(date('Y'));
  1233. for($i = $thisYear; $i < $thisYear + 3; $i++) {
  1234. echo '<option value="'.$i.'"';
  1235. if($i == $thisYear) {echo ' selected="selected"';}
  1236. echo '>'.$i.'</option>';
  1237. }
  1238. echo '</select>'.l('hour').':<select name="fposting_hour">';
  1239. $thisHour = !empty($time) ? substr($time, 11, 2) : intval(date('H'));
  1240. for($i = 0; $i < 24; $i++) {
  1241. echo '<option value="'.$i.'"';
  1242. if($i == $thisHour) {echo ' selected="selected"';}
  1243. echo '>'.$i.'</option>';
  1244. }
  1245. echo '</select>'.l('minute').':<select name="fposting_minute">';
  1246. $thisMinute = !empty($time) ? substr($time, 14, 2) : intval(date('i'));
  1247. for($i = 0; $i < 60; $i++) {
  1248. echo '<option value="'.$i.'"';
  1249. if($i == $thisMinute) {echo ' selected="selected"';}
  1250. echo '>'.$i.'</option>';
  1251. }
  1252. echo '</select></p>';
  1253. }
  1254.  
  1255. // ARTICLES FORM
  1256. function form_articles($contents) {
  1257. if (is_numeric($_GET['id']) && !is_null($_GET['id'])) {
  1258. $id = $_GET['id'];
  1259. $query = mysql_query("SELECT * FROM ".db('prefix')."articles WHERE id='$id'");
  1260. $r = mysql_fetch_array($query);
  1261. $article_category = $r['category'];
  1262. $edit_option = substr($r['position'], 0, 1);
  1263. $edit_page = substr($r['position'], 2);
  1264. switch ($edit_option) {
  1265. case 1: $frm_fieldset = l('edit').' '.l('article'); $frm_position1 = 'selected="selected"'; break;
  1266. case 2: $frm_fieldset = l('edit').' '.l('extra_contents'); $frm_position2 = 'selected="selected"'; break;
  1267. case 3: $frm_fieldset = l('edit').' '.l('page'); $frm_position3 = 'selected="selected"'; break;
  1268. }
  1269. $frm_action = db('website').'index.php?action=process&amp;task=admin_article&amp;id='.$id;
  1270. $frm_title = $_SESSION['temp']['title'] ? $_SESSION['temp']['title'] : $r['title'];
  1271. $frm_sef_title = $_SESSION['temp']['seftitle'] ? cleanSEF($_SESSION['temp']['seftitle']) : $r['seftitle'];
  1272. $frm_text = str_replace('&', '&amp;', $_SESSION['temp']['text'] ? $_SESSION['temp']['text'] : $r['text']);
  1273. $frm_meta_desc = $_SESSION['temp']['description_meta'] ? cleanSEF($_SESSION['temp']['description_meta']) : $r['description_meta'];
  1274. $frm_meta_key = $_SESSION['temp']['keywords_meta'] ? cleanSEF($_SESSION['temp']['keywords_meta']) : $r['keywords_meta'];
  1275. $frm_display_title = $r['displaytitle'] == 'YES' ? 'ok' : '';
  1276. $frm_display_info = $r['displayinfo'] == 'YES' ? 'ok' : '';
  1277. $frm_publish = $r['published'] == 1 ? 'ok' : '';
  1278. $frm_commentable = ($r['commentable'] == 'YES' || $r['commentable'] == 'FREEZ') ? 'ok' : '';
  1279. $frm_task = 'edit_article';
  1280. $frm_submit = l('edit');
  1281. } else {
  1282. switch ($contents) {
  1283. case 'article_new': $frm_fieldset = l('article_new'); $pos = 1; $frm_position1 = 'selected="selected"'; break;
  1284. case 'extra_new': $frm_fieldset = l('extra_new'); $pos = 2; $frm_position2 = 'selected="selected"'; break;
  1285. case 'page_new': $frm_fieldset = l('page_new'); $pos = 3; $frm_position3 = 'selected="selected"'; break;
  1286. }
  1287. if (empty($frm_fieldset)) { $frm_fieldset = l('article_new'); }
  1288. $frm_action = db('website').'index.php?action=process&amp;task=admin_article';
  1289. $frm_title = $_SESSION['temp']['title'];
  1290. $frm_sef_title = cleanSEF($_SESSION['temp']['seftitle']);
  1291. $frm_text = $_SESSION['temp']['text'];
  1292. $frm_meta_desc = cleanSEF($_SESSION['temp']['description_meta']);
  1293. $frm_meta_key = cleanSEF($_SESSION['temp']['keywords_meta']);
  1294. $frm_display_title = 'ok';
  1295. $frm_display_info = ($contents == 'extra_new') ? '' : 'ok';
  1296. $frm_publish = 'ok';
  1297. $frm_commentable = ($contents == 'extra_new' || $contents == 'page_new') ? '' : 'ok';
  1298. $frm_task = 'add_article';
  1299. $frm_submit = l('submit');
  1300. }
  1301. echo '<div>';
  1302. echo html_input('form', '', 'post', '', '', '', '', '', '', '', '', '', 'post', $frm_action, '');
  1303. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', $frm_fieldset);
  1304. echo html_input('text', 'title', 'at', $frm_title, l('title'), '', 'onchange="genSEF(this,document.forms[\'post\'].seftitle)"', 'onkeyup="genSEF(this,document.forms[\'post\'].seftitle)"', '', '', '', '', '', '', '');
  1305. if ($contents == 'extra_new' || $edit_option == 2) {
  1306. echo '<div style="display: none;">';
  1307. echo html_input('text', 'seftitle', 'as', $frm_sef_title, l('sef_title'), '', '', '', '', '', '', '', '', '', '');
  1308. echo '</div>';
  1309. } else {
  1310. echo html_input('text', 'seftitle', 'as', $frm_sef_title, l('sef_title'), '', '', '', '', '', '', '', '', '', '');}
  1311. echo html_input('textarea', 'text', 'txt', $frm_text, l('text'), '', '', '', '', '', '2', '100', '', '', '');
  1312. echo '<p>';
  1313. echo html_input('button', 'strong', '', 'B', '', 'button', 'onclick="tag(\'strong\')"', '', '', '', '', '', '', '', '');
  1314. echo html_input('button', 'em', '', 'I', '', 'button', 'onclick="tag(\'em\')"', '', '', '', '', '', '', '', '');
  1315. echo html_input('button', 'strike', '', 'Strike', '', 'button', 'onclick="tag(\'strike\')"', '', '', '', '', '', '', '', '');
  1316. echo html_input('button', 'p', '', 'P', '', 'button', 'onclick="tag(\'p\')"', '', '', '', '', '', '', '', '');
  1317. echo html_input('button', 'br', '', 'BR', '', 'button', 'onclick="tag(\'br\')"', '', '', '', '', '', '', '', '');
  1318. echo html_input('button', 'break', '', 'Break', '', 'button', 'onclick="tag(\'break\')"', '', '', '', '', '', '', '', '');
  1319. echo html_input('button', 'img', '', 'Image', '', 'button', 'onclick="tag(\'img\')"', '', '', '', '', '', '', '', '');
  1320. echo html_input('button', 'link', '', 'Link', '', 'button', 'onclick="tag(\'link\')"', '', '', '', '', '', '', '', '');
  1321. echo html_input('button', 'include', '', 'Include', '', 'button', 'onclick="tag(\'include\')"', '', '', '', '', '', '', '', '');
  1322. echo '</p>';
  1323. if ($contents == 'article_new' || $edit_option == 1) {
  1324. echo html_input('checkbox', 'publish_article', 'pu', 'YES', l('publish_article'), '', '', '', '', $frm_publish, '', '', '', '', '');
  1325. }
  1326. echo '</fieldset>';
  1327. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', '<a title="'.l('customize').'" onclick="toggle(\'preview\')" style="cursor: pointer;">'.l('preview').'</a>');
  1328. echo '<div id="preview" style="display: none;"></div></fieldset>';
  1329. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', '<a title="'.l('customize').'" onclick="toggle(\'customize\')" style="cursor: pointer;">'.l('customize').'</a>');
  1330. echo '<div id="customize" style="display: none;">';
  1331. if ($contents != 'page_new' && $edit_option != 3) {
  1332. echo '<p><label for="cat">';
  1333. echo ($contents == 'extra_new' || $edit_option == 2) ? l('appear_category') : l('category');
  1334. echo ':</label><br /><select name="define_category" id="cat" onchange="dependancy();">';
  1335. if ($contents == 'extra_new' || $edit_option == 2) {echo '<option value="-1"'.($article_category == -1 ? ' selected="selected"' : '').'>'.l('all').'</option>';}
  1336. echo '<option value="0"'.(($article_category == 0 && $contents != 'extra_new') ? ' selected="selected"' : '').'>'.l('home').'</option>';
  1337. $category_query = "SELECT * FROM ".db('prefix')."categories WHERE published = 'YES' ORDER BY catorder ASC";
  1338. $category_result = mysql_query($category_query);
  1339. while ($cat = mysql_fetch_array($category_result)) {
  1340. echo '<option value="'.$cat['id'].'"';
  1341. if ($article_category == $cat['id']) {echo ' selected="selected"';}
  1342. echo '>'.$cat['name'].'</option>';
  1343. }
  1344. echo '</select></p>';
  1345. if ($contents == 'extra_new' || $edit_option == 2) {
  1346. echo '<p id="def_page"><label for="dp">'.l('appear_page').':</label><br /><select name="define_page" id="dp">';
  1347. echo '<option value="0"'.($edit_option != '2' ? ' selected="selected"' : '').'>'.l('all').'</option>';
  1348. $query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY id ASC";
  1349. $result = mysql_query($query);
  1350. while ($r = mysql_fetch_array($result)) {
  1351. echo '<option value="'.$r['id'].'"';
  1352. if ($edit_page == $r['id']) {echo ' selected="selected"';}
  1353. echo '>'.$r['title'].'</option>';
  1354. }
  1355. echo '</select></p>';
  1356. }
  1357. }
  1358. if (!empty($id)) {
  1359. echo '<p><label for="pos">'.l('position').':</label><br /><select name="position" id="pos">';
  1360. echo '<option value="1"'.$frm_position1.'>'.l('center').'</option>';
  1361. echo '<option value="2"'.$frm_position2.'>'.l('side').'</option>';
  1362. echo '<option value="3"'.$frm_position3.'>'.l('display_page').'</option>';
  1363. echo '</select></p>';
  1364. }
  1365. else {echo html_input('hidden', 'position', 'position', $pos, '', '', '', '', '', '', '', '', '', '', '');}
  1366. if ($contents != 'extra_new' && $edit_option != '2') {
  1367. echo html_input('text', 'description_meta', 'dm', $frm_meta_desc, l('description_meta'), '', '', '', '', '', '', '', '', '', '');
  1368. echo html_input('text', 'keywords_meta', 'km', $frm_meta_key, l('keywords_meta'), '', '', '', '', '', '', '', '', '', '');
  1369. }
  1370. echo html_input('checkbox', 'display_title', 'dt', 'YES', l('display_title'), '', '', '', '', $frm_display_title, '', '', '', '', '');
  1371. if ($contents != 'extra_new' && $edit_option != '2') {
  1372. echo html_input('checkbox', 'display_info', 'di', 'YES', l('display_info'), '', '', '', '', $frm_display_info, '', '', '', '', '');
  1373. echo html_input('checkbox', 'commentable', 'ca', 'YES', l('enable_commenting'), '', '', '', '', $frm_commentable, '', '', '', '', '');
  1374. if (!empty($id)) {
  1375. echo '<p><input name="freeze" type="checkbox" id="fc"';
  1376. if ($r['commentable'] == 'FREEZ') {echo ' checked="checked" />';}
  1377. else if ($r['commentable'] == 'YES') {echo ' />';}
  1378. echo ' <label for="fc"> '.l('freeze_comments').'</label></p>';
  1379. }
  1380. }
  1381. echo '</div></fieldset>';
  1382. if ($contents == 'article_new' || $edit_option == 1) {
  1383. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', '<a title="'.l('publish_date').'" onclick="toggle(\'admin_publish_date\')" style="cursor: pointer;">'.l('publish_date').'</a>');
  1384. echo '<div id="admin_publish_date" style="display: none;">';
  1385. echo html_input('checkbox', 'fposting', 'fp', 'YES', l('enable'), '', '', '', '', '', '', '', '', '', '');
  1386. echo '<p>'.l('server_time').': '.date('d.m.Y. H:i:s').'</p>';
  1387. echo '<p>'.l('article_date').'</p>';
  1388. !empty($id) ? posting_time($r['date']) : posting_time();
  1389. echo '</div></fieldset>';
  1390. }
  1391. echo '<p>';
  1392. echo html_input('hidden', 'task', 'task', 'admin_article', '', '', '', '', '', '', '', '', '', '', '');
  1393. echo html_input('submit', $frm_task, $frm_task, $frm_submit, '', 'button', '', '', '', '', '', '', '', '', '');
  1394. if (!empty($id)) {
  1395. echo html_input('hidden', 'id', 'id', $id, '', '', '', '', '', '', '', '', '', '', '');
  1396. echo html_input('submit', 'delete_article', 'delete_article', l('delete'), '', 'button', 'onclick="javascript: return pop()"', '', '', '', '', '', '', '', '');
  1397. }
  1398. echo '</p></form></div>';
  1399. }
  1400.  
  1401. // ARTICLES - ADMIN LIST
  1402. function admin_articles($contents) {
  1403. switch ($contents) {
  1404. case 'article_view': $title = l('articles'); $subquery = "WHERE position = 1"; break;
  1405. case 'extra_view': $title = l('extra_contents'); $subquery = "WHERE SUBSTRING(position,1,1) = '2'"; break;
  1406. case 'page_view': $title = l('pages'); $subquery = "WHERE position = 3"; break;
  1407. }
  1408. echo '<fieldset><legend>'.$title.'</legend>';
  1409. $query = "SELECT * FROM ".db('prefix')."articles $subquery ORDER BY date DESC";
  1410. $result = mysql_query($query);
  1411. if (!$result || !mysql_num_rows($result)) {echo '<p>'.l('article_not_exist').'</p>';}
  1412. else {
  1413. $i = 0;
  1414. while ($r = mysql_fetch_array($result)) {
  1415. $articleSEF = $contents != 'extra_view' ? $r['seftitle'].'/' : '';
  1416. echo '<p>'.date(s('date_format'), strtotime($r['date'])).' <strong>'.$r['title'].'</strong> '.l('divider').' <a href="'.db('website').find_cat_sef($r['category']).'/'.$articleSEF.'">'.l('view').'</a> ';
  1417. echo l('divider').' <a href="'.db('website').'index.php?action=admin_article&amp;id='.$r['id'].'">'.l('edit').'</a> ';
  1418. if ($r['published'] == 2) {echo l('divider').' ['.l('status').' '.l('future_posting').']';}
  1419. if ($r['published'] == 0) {echo l('divider').' ['.l('status').' '.l('unpublished').']';}
  1420. echo '</p>';
  1421. $i++;
  1422. }
  1423. echo '</fieldset>';
  1424. }}
  1425.  
  1426. //CATEGORIES - ADMIN LIST
  1427. function admin_categories() {
  1428. echo '<fieldset><legend>'.l('categories').'</legend>';
  1429. $query = "SELECT * FROM ".db('prefix')."categories ORDER BY catorder ASC";
  1430. $result = mysql_query($query);
  1431. if (!$result || !mysql_num_rows($result)) {echo '<p>'.l('category_not_exist').'</p>';}
  1432. else {
  1433. while ($r = mysql_fetch_array($result)) {
  1434. echo '<p><strong>'.$r['name'].'</strong> '.l('divider').' <a href="'.db('website').'index.php?action=admin_category&amp;id='.$r['id'].'" title="'.$r['description'].'">'.l('edit').'</a> ';
  1435. echo $r['published'] != 'YES' ? ' '.l('divider').' ['.l('status').' '.l('unpublished').']' : '';
  1436. echo '</p>';
  1437. }
  1438. }
  1439. echo '</fieldset>';
  1440. }
  1441.  
  1442. // COMMENTS - EDIT
  1443. function edit_comment() {
  1444. echo '<h2>'.l('edit_comment').'</h2>';
  1445. $commentid = $_GET['commentid'];
  1446. $query = mysql_query("SELECT * FROM ".db('prefix')."comments WHERE id='$commentid'");
  1447. $r = mysql_fetch_array($query);
  1448. $articleTITLE = retrieve(title, articles, id, $r['articleid']);
  1449. echo html_input('form', '', 'post', '', '', '', '', '', '', '', '', '', 'post', 'index.php?action=process&amp;task=editcomment&amp;id='.$commentid, '');
  1450. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', l('edit_comment').' (<strong>'.$articleTITLE.'</strong>)');
  1451. echo html_input('textarea', 'editedcomment', 'ec', stripslashes($r['comment']), l('comment'), '', '', '', '', '', '2', '100', '', '', '');
  1452. echo html_input('text', 'name', 'n', $r['name'], l('name'), '', '', '', '', '', '', '', '', '', '');
  1453. echo html_input('text', 'url', 'url', $r['url'], l('url'), '', '', '', '', '', '', '', '', '', '');
  1454. echo html_input('checkbox', 'approved', 'a', '', l('approved'), '', '', '', '', $r['approved'] == 'True' ? 'ok' : '', '', '', '', '', '');
  1455. echo '<p>';
  1456. echo html_input('hidden', 'id', 'id', $r['articleid'], '', '', '', '', '', '', '', '', '', '', '');
  1457. echo html_input('submit', 'submit_text', 'submit_text', l('edit'), '', 'button', '', '', '', '', '', '', '', '', '');
  1458. echo html_input('hidden', 'commentid', 'commentid', $r['id'], '', '', '', '', '', '', '', '', '', '', '');
  1459. echo html_input('submit', 'delete_text', 'delete_text', l('delete'), '', 'button', 'onclick="javascript: return pop()"', '', '', '', '', '', '', '', '');
  1460. echo '</p></fieldset></form>';
  1461. }
  1462.  
  1463. /*** PROCESSING (CATEGORIES, CONTENTS, COMMENTS) ***/
  1464. function processing() {
  1465. if ($_SESSION[db('website').'Logged_In'] != token()) {echo notification(1,l('error_not_logged_in'),'home');}
  1466. else {
  1467. $action = clean(cleanXSS($_GET['action']));
  1468. $id = clean(cleanXSS($_GET['id']));
  1469. $commentid = $_POST['commentid'];
  1470. $approved = $_POST['approved'] == 'on' ? 'True' : '';
  1471. $name = clean(entity($_POST['name']));
  1472. $category = $_POST['define_category'];
  1473. $description = clean(entity($_POST['description']));
  1474. $title = clean(entity($_POST['title']));
  1475. $seftitle = $_POST['seftitle'];
  1476. $url = cleanXSS($_POST['url']);
  1477. $comment = str_replace("\'", "'", $_POST['editedcomment']);
  1478. $text = $_POST['text'];
  1479. $date = date('Y-m-d H:i:s');
  1480. $description_meta = entity($_POST['description_meta']);
  1481. $keywords_meta = entity($_POST['keywords_meta']);
  1482. $display_title = $_POST['display_title'] == 'on' ? 'YES' : 'NO';
  1483. $display_info = $_POST['display_info'] == 'on' ? 'YES' : 'NO';
  1484. $commentable = $_POST['commentable'] == 'on' ? 'YES' : 'NO';
  1485. $freez = $_POST['freeze'] == 'on' ? 'YES' : 'NO';
  1486. if ($freez == 'YES' && $commentable == 'YES') {$commentable = 'FREEZ';}
  1487. $position = $_POST['position'];
  1488. if ($position == 2) {$position = $_POST['cat_dependant'] == 'on' ? 21 : 2;}
  1489. $publish_article = ($_POST['publish_article'] == 'on' || $position > 1) ? 1 : 0;
  1490. $publish_category = $_POST['publish'] == 'on' ? 'YES' : 'NO';
  1491. $fpost_enabled = false;
  1492. if($_POST['fposting'] == 'on') {
  1493. $fpost_enabled = true;
  1494. $publish_article = 2;
  1495. $date = $_POST['fposting_year'].'-'.$_POST['fposting_month'].'-'.$_POST['fposting_day'].' '.$_POST['fposting_hour'].':'.$_POST['fposting_minute'].':00';
  1496. }
  1497. $task = clean(cleanXSS($_GET['task']));
  1498. switch ($task) {
  1499. case 'save_settings':
  1500. if (isset($_POST['save'])) {
  1501. $website_title = $_POST['website_title'];
  1502. $home_sef = $_POST['home_sef'];
  1503. $website_description = $_POST['website_description'];
  1504. $website_keywords = $_POST['website_keywords'];
  1505. $website_email = $_POST['website_email'];
  1506. $contact_subject = $_POST['contact_subject'];
  1507. $language = $_POST['language'];
  1508. $charset = $_POST['charset'];
  1509. $date_format = $_POST['date_format'];
  1510. $article_limit = $_POST['article_limit'];
  1511. $rss_limit = $_POST['rss_limit'];
  1512. $display_page = $_POST['display_page'];
  1513. $display_new_on_home = $_POST['display_new_on_home'];
  1514. $display_pagination = $_POST['display_pagination'];
  1515. $num_categories = $_POST['num_categories'];
  1516. $approve_comments = $_POST['approve_comments'];
  1517. $comments_order = $_POST['comments_order'];
  1518. $comment_limit = $_POST['comment_limit'];
  1519. $word_filter_enable = $_POST['word_filter_enable'];
  1520. $word_filter_file = $_POST['word_filter_file'];
  1521. $word_filter_change = $_POST['word_filter_change'];
  1522. $ufield = array('website_title' => $website_title,'home_sef' => $home_sef,'website_description' => $website_description,'website_keywords' => $website_keywords,'website_email' => $website_email,'contact_subject' => $contact_subject,'language' => $language,'charset' => $charset,'date_format' => $date_format,'article_limit' => $article_limit,'rss_limit' => $rss_limit,'display_page' => $display_page,'comments_order' => $comments_order,'comment_limit' => $comment_limit,'word_filter_file' => $word_filter_file,'word_filter_change' => $word_filter_change,'display_new_on_home' => $display_new_on_home,'display_pagination' => $display_pagination,'num_categories' => $num_categories,'approve_comments' => $approve_comments,'word_filter_enable' => $word_filter_enable,);
  1523. while (list($key, $value) = each($ufield)) {
  1524. mysql_query("UPDATE ".db('prefix')."settings SET VALUE = '$value' WHERE name = '$key' LIMIT 1;");}
  1525. $query_begin = "UPDATE ".db('prefix')."settings SET VALUE = ";
  1526. echo notification(0,'','settings');
  1527. }
  1528. break;
  1529. case 'changeup':
  1530. if (isset($_POST['submit_pass'])) {
  1531. $user = checkUserPass($_POST['uname']);
  1532. $pass1 = checkUserPass($_POST['pass1']);
  1533. $pass2 = checkUserPass($_POST['pass2']);
  1534. if ($user && $pass1 && $pass2 && $pass1 === $pass2) {
  1535. $uname = md5($user);
  1536. $pass = md5($pass2);
  1537. $query = "UPDATE ".db('prefix')."settings SET VALUE=";
  1538. mysql_query($query."'$uname' WHERE name='username' LIMIT 1;");
  1539. mysql_query($query."'$pass' WHERE name='password' LIMIT 1;");
  1540. echo notification(0,'','administration');
  1541. }
  1542. else {echo notification(1,l('pass_mismatch'),'settings');}
  1543. }
  1544. break;
  1545. case 'admin_category':
  1546. switch(true) {
  1547. case(empty($name)): echo notification(1,l('err_TitleEmpty').l('errNote')); form_categories(); break;
  1548. case(empty($seftitle)): echo notification(1,l('err_SEFEmpty').l('errNote')); form_categories(); break;
  1549. case(check_if_unique('category_name', $name, $id)): echo notification(1,l('err_TitleExists').l('errNote')); form_categories(); break;
  1550. case(check_if_unique('category_seftitle', $seftitle, $id)): echo notification(1,l('err_SEFExists').l('errNote')); form_categories(); break;
  1551. case(cleancheckSEF($seftitle) == 'notok'): echo notification(1,l('err_SEFIllegal').l('errNote')); form_categories(); break;
  1552. default:
  1553. switch(true) {
  1554. case(isset($_POST['add_category'])):
  1555. mysql_query("INSERT INTO ".db('prefix')."categories(name, seftitle, description, published) VALUES('$name', '$seftitle', '$description', '$publish_category')");
  1556. break;
  1557. case(isset($_POST['edit_category'])):
  1558. mysql_query("UPDATE ".db('prefix')."categories SET name = '$name', seftitle = '$seftitle', description = '$description', published = '$publish_category' WHERE id = $id LIMIT 1;");
  1559. break;
  1560. case(isset($_POST['delete_category'])):
  1561. mysql_query("DELETE FROM ".db('prefix')."categories WHERE id = $id LIMIT 1;");
  1562. break;
  1563. }
  1564. echo notification(0,'','categories');
  1565. }
  1566. break;
  1567. case 'order_category':
  1568. if (isset($_POST['order_category'])) {
  1569. $counter = $_POST['counter'];
  1570. for($i = 0; $i < $counter; $i++) {
  1571. $category_order = $_POST['catorder'][$i];
  1572. $counter_id = $_POST['counter_id'][$i];
  1573. if (empty($category_order) || !is_numeric($category_order)) {$category_order = 0;}
  1574. mysql_query("UPDATE ".db('prefix')."categories SET catorder = '$category_order' WHERE id = '$counter_id' LIMIT 1;");
  1575. }
  1576. echo notification(0,'','categories');
  1577. }
  1578. break;
  1579. case 'admin_article';
  1580. if (substr($position, 0, 1) == 2) {
  1581. $category = $_POST['define_category'];
  1582. $page = $_POST['define_page'];
  1583. if ($category != -1) {$position = '21'.$category;}
  1584. else if ($page != 0) {$position = '22'.$page; $category = -1;}
  1585. }
  1586. $_SESSION['temp']['title'] = $title; $_SESSION['temp']['seftitle'] = $seftitle; $_SESSION['temp']['text'] = $text;
  1587. switch(true) {
  1588. case(empty($title)): echo notification(1,l('err_TitleEmpty').l('errNote')); form_articles(''); unset($_SESSION['temp']); break;
  1589. case(empty($seftitle)): echo notification(1,l('err_SEFEmpty').l('errNote')); $_SESSION['temp']['seftitle'] = $_SESSION['temp']['title']; form_articles(''); unset($_SESSION['temp']); break;
  1590. case(cleancheckSEF($seftitle) == 'notok'): echo notification(1,l('err_SEFIllegal').l('errNote')); form_articles(''); unset($_SESSION['temp']); break;
  1591. case(check_if_unique('article_title', $title, $id)): echo notification(1,l('err_TitleExists').l('errNote')); form_articles(''); unset($_SESSION['temp']); break;
  1592. case(check_if_unique('article_seftitle', $seftitle, $id)): echo notification(1,l('err_SEFExists').l('errNote')); form_articles(''); unset($_SESSION['temp']); break;
  1593. default:
  1594. $pos = substr($position, 0, 1);
  1595. switch ($pos) {case 1: $link = 'articles'; break; case 2: $link = 'extra_contents'; break; case 3: $link = 'pages'; break;}
  1596. switch(true) {
  1597. case(isset($_POST['add_article'])):
  1598. mysql_query("INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta) VALUES('$title', '$seftitle', '$text', '$date', '$category', '$position', '$display_title', '$display_info', '$commentable', '$publish_article', '$description_meta', '$keywords_meta')");
  1599. break;
  1600. case(isset($_POST['edit_article'])):
  1601. if ($fpost_enabled == true) {$future = " date = '$date',";}
  1602. mysql_query("UPDATE ".db('prefix')."articles SET title='$title', seftitle = '$seftitle', text = '$text',".$future." category = '$category', position = '$position', displaytitle = '$display_title', displayinfo = '$display_info', commentable = '$commentable', published = '$publish_article', description_meta = '$description_meta', keywords_meta = '$keywords_meta' WHERE id = '$id' LIMIT 1;");
  1603. break;
  1604. case(isset($_POST['delete_article'])):
  1605. mysql_query("DELETE FROM ".db('prefix')."articles WHERE id = $id LIMIT 1;");
  1606. mysql_query("DELETE FROM ".db('prefix')."comments WHERE articleid = $id LIMIT 1;");
  1607. break;
  1608. }
  1609. echo notification(0,'',$link); unset($_SESSION['temp']);
  1610. }
  1611. break;
  1612. case 'editcomment':
  1613. if (isset($_POST['submit_text'])) {
  1614. mysql_query("UPDATE ".db('prefix')."comments SET name = '$name', url = '$url', comment = '$comment', approved = '$approved' WHERE id = '$commentid' LIMIT 1;");
  1615. }
  1616. else if (isset($_POST['delete_text'])) {
  1617. mysql_query("DELETE FROM ".db('prefix')."comments WHERE id = $commentid LIMIT 1;");
  1618. }
  1619. $articleid = retrieve('articleid', 'comments', 'id', $commentid);
  1620. $link = find_cat_sef($categoryid).'/'.retrieve('seftitle', 'articles', 'id', $articleid);
  1621. echo notification(0,'',$link);
  1622. break;
  1623. case 'deletecomment':
  1624. $commentid = $_GET['commentid'];
  1625. $articleid = $_GET['articleid'];
  1626. mysql_query("DELETE FROM ".db('prefix')."comments WHERE id = $commentid LIMIT 1;");
  1627. $link = find_cat_sef($categoryid).'/'.retrieve('seftitle', 'articles', 'id', $articleid);
  1628. echo notification(0,'', $link);
  1629. break;
  1630. }
  1631. }}
  1632.  
  1633. /*** FILES ***/
  1634. function files() {
  1635. $upload_file = isset($_POST['upload']) ? $_POST['upload'] : null;
  1636. $ip = (isset($_POST['ip']) && $_POST['ip'] == $_SERVER['REMOTE_ADDR']) ? $_POST['ip'] : null;
  1637. $time = (isset($_POST['time']) && (time() - $_POST['time']) > 4) ? $_POST['time'] : null;
  1638. if ($ip && $time && $upload_file && $_SESSION[db('website').'Logged_In'] == token()) {
  1639. $ignore = explode(',', l('ignored_items'));
  1640. $file_types = explode(',', l('allowed_files'));
  1641. $image_types = explode(',', l('allowed_images'));
  1642. $extension = array_merge($file_types, $image_types);
  1643. if ($_FILES['imagefile']['type']) {
  1644. $filetemp = $_FILES['imagefile']['tmp_name'];
  1645. $filename = $_FILES['imagefile']['name'];
  1646. $filetype = $_FILES['imagefile']['type'];
  1647. if (!in_array(substr(strrchr($filename, '.'), 1), $extension) || in_array($filename, $ignore)) {echo notification(1,l('file_error'),'files');}
  1648. else {
  1649. $upload_dir = $_POST['upload_dir'].'/';
  1650. copy ($filetemp, $upload_dir.$filename) or die (l('file_error')); echo notification(0,'','files');
  1651. $kb_size = round(($_FILES['imagefile']['size'] / 1024), 1);
  1652. echo '<p><a href="'.$upload_dir.$filename.'" title="'.$filename.'">'.$filename.'</a> ['.$kb_size.' KB] ['.$filetype.']</p>';
  1653. }
  1654. }
  1655. else {echo notification(1,l('file_error'),'files');}
  1656. }
  1657. else {
  1658. if (isset($_GET['task']) == 'delete') {
  1659. $file_to_delete = $_GET['folder'].'/'.$_GET['file'];
  1660. @unlink($file_to_delete);
  1661. echo notification(0,'','files');
  1662. } else {
  1663. echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', l('upload'));
  1664. echo '<form method="post" action="files/" enctype="multipart/form-data">';
  1665. echo '<p><select name="upload_dir" id="ud1" onchange="goto(this.form);">';
  1666. echo '<option value=".">..</option>';
  1667. filelist('option',