PageRenderTime 63ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/index.php

https://github.com/aravindc/pixelpost
PHP | 953 lines | 731 code | 68 blank | 154 comment | 91 complexity | 49d2af68b760bf158cf9babce5e44569 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. // SVN file version:
  3. // $Id$
  4. /*
  5. Pixelpost version 1.7.2
  6. Pixelpost www: http://www.pixelpost.org/
  7. Version 1.7.2:
  8. Development Team:
  9. Ramin Mehran, Will Duncan, Joseph Spurling,
  10. Piotr "GeoS" Galas, Dennis Mooibroek, Karin Uhlig, Jay Williams, David Kozikowski
  11. Former members of the Development Team:
  12. Connie Mueller-Goedecke
  13. Version 1.1 to Version 1.3: Linus <http://www.shapestyle.se>
  14. IMPORTANT!!!
  15. Due to the nature of the characterset used in this file it is important to save this
  16. file with an UTF-8 encoding.
  17. Contact: thecrew (at) pixelpost (dot) org
  18. Copyright 2007 Pixelpost.org <http://www.pixelpost.org>
  19. License: http://www.gnu.org/copyleft/gpl.html
  20. This program is free software; you can redistribute it and/or
  21. modify it under the terms of the GNU General Public License
  22. as published by the Free Software Foundation; either version 2
  23. of the License, or (at your option) any later version.
  24. This program is distributed in the hope that it will be useful,
  25. but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. GNU General Public License for more details.
  28. You should have received a copy of the GNU General Public License
  29. along with this program; if not, write to the Free Software
  30. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  31. */
  32. // the function below is from wordpress. It cleans globals set by register_globals is enabled;
  33. require_once("includes/functions.php");
  34. PP_unregister_GLOBALS();
  35. ini_set('arg_separator.output', '&amp;');
  36. error_reporting(0);
  37. /**
  38. * Define constants
  39. *
  40. */
  41. define('PHP_SELF', 'index.php');
  42. define('ADDON_DIR', 'addons/');
  43. define('ADMIN_DIR', 'admin/');
  44. if(file_exists("includes/pixelpost.php")){ require_once("includes/pixelpost.php"); }
  45. start_mysql('includes/pixelpost.php','front');
  46. /**
  47. * Load the $cfgrow configuration variable and set the upload directory
  48. *
  49. */
  50. if($cfgrow = sql_array("SELECT * FROM `".$pixelpost_db_prefix."config`"))
  51. {
  52. //$upload_dir = $cfgrow['imagepath'];
  53. }
  54. else
  55. {
  56. show_splash('Coming Soon. Not Installed Yet. Cause #1','templates');
  57. }
  58. /**
  59. * Begin frontpage addons
  60. *
  61. */
  62. refresh_addons_table(ADDON_DIR);
  63. $addon_front_functions = array(0 => array('function_name' => '', 'workspace' => '', 'menu_name' => '', 'submenu_name' => ''));
  64. $addon_admin_functions = array(0 => array('function_name' => '', 'workspace' => '', 'menu_name' => '', 'submenu_name' => ''));
  65. create_front_addon_array();
  66. session_start();
  67. // Initialize the workspace
  68. eval_addon_front_workspace('frontpage_init');
  69. // Fix proposed by tomyeah on the forum
  70. header('Content-Type: text/html; charset=utf-8');
  71. // Set a cookie for the visitor counter, re-count a person after 60 mins
  72. setcookie("lastvisit","expires in 60 minutes",time() +60*60);
  73. // save user info if requested
  74. if(isset($_POST['vcookie']))
  75. {
  76. $vcookiename = clean($_POST['name']);
  77. $vcookieurl = clean($_POST['url']);
  78. $vcookieemail = clean($_POST['email']);
  79. setcookie("visitorinfo","$vcookiename%$vcookieurl%$vcookieemail",time() +60*60*24*30); // save cookie 30 days
  80. }
  81. // cleanup $_GET['x']
  82. if(isset($_GET['x'])){ $_GET['x'] = eregi_replace('[^a-z0-9_-]', '', $_GET['x']); }
  83. if(isset($_GET['errors']) && $_SESSION["pixelpost_admin"])
  84. {
  85. error_reporting(E_ALL ^ E_NOTICE);
  86. }
  87. elseif(isset($_GET['errorsall']) && $_SESSION["pixelpost_admin"])
  88. {
  89. error_reporting(E_ALL);
  90. }
  91. if(isset($_GET['showimage'])){ $_GET['showimage'] = (int) $_GET['showimage']; }
  92. if($cfgrow['markdown'] == 'T'){ require_once("includes/markdown.php"); }
  93. /**
  94. * Added token support for use in forms (only if it is set to on)
  95. *
  96. */
  97. if($cfgrow['token'] == 'T')
  98. {
  99. if(!isset($_SESSION['token']))
  100. {
  101. $_SESSION['token'] = md5($_SERVER["HTTP_USER_AGENT"].$_SERVER["HTTP_ACCEPT_LANGUAGE"].$_SERVER["HTTP_ACCEPT_ENCODING"].$_SERVER["HTTP_ACCEPT_CHARSET"].$_SERVER["HTTP_ACCEPT"].$_SERVER["SERVER_SOFTWARE"].session_id().uniqid(rand(), TRUE));
  102. }
  103. if(!isset($_GET['x'])&&$_GET['x'] !== "save_comment")
  104. {
  105. $_SESSION['token_time'] = time();
  106. }
  107. }
  108. // book visitors
  109. if(strtolower($cfgrow['visitorbooking']) != 'no') { book_visitor($pixelpost_db_prefix.'visitors'); }
  110. // mod rewrite
  111. if(isset($mod_rewrite) AND $mod_rewrite == '1'){ $showprefix = ''; }else{ $showprefix = './'.PHP_SELF.'?showimage='; }
  112. // refresh the addons table
  113. //refresh_addons_table(ADDON_DIR);
  114. /**
  115. * Timezone variables
  116. *
  117. */
  118. $tz = $cfgrow['timezone'];
  119. $datetime = gmdate("Y-m-d H:i:s",time()+(3600 * $tz)); // current date+time
  120. $cdate = $datetime; // for future posting, current date+time
  121. /**
  122. * LANGUAGE SELECTION
  123. *
  124. * This is an array of all supported languages in PP. It contains the country abbreviation
  125. * and the native word for the language spoken in that country. This is used to get all
  126. * variables.
  127. *
  128. */
  129. /**
  130. * Query the database and pullout the language array(s).
  131. *
  132. */
  133. $query = mysql_query("SELECT * FROM `".$pixelpost_db_prefix."localization`");
  134. $row = mysql_fetch_array($query,MYSQL_ASSOC);
  135. /**
  136. * Unserialize the defualt language array using the UTF8 safe unserialize function, mb_unserialize.
  137. *
  138. */
  139. $PP_supp_lang = mb_unserialize(stripslashes($row['pp_supp_lang']));
  140. /**
  141. * If a user supplied language array exists,
  142. * Unserialize the user language array using the UTF8 safe unserialize function, mb_unserialize,
  143. * and merge with the default pixelpost array.
  144. *
  145. */
  146. if(!empty($row['user_supp_lang']))
  147. {
  148. $user_supp_lang = mb_unserialize(stripslashes($row['user_supp_lang']));
  149. $PP_supp_lang = array_merge($PP_supp_lang, $user_supp_lang);
  150. }
  151. /**
  152. * The default language is the language the user has set in the adminpanel
  153. * We have to find the abbreviation
  154. *
  155. */
  156. $default_language_abr = strtolower($PP_supp_lang[$cfgrow['langfile']][0]);
  157. /**
  158. * Try to find if another language was selected or not (different ways)
  159. * Set a cookie to the GET arg 'lang' if it exists.
  160. *
  161. */
  162. if(isset($_GET['lang']))
  163. {
  164. // cookie is saved for 30 days now
  165. setcookie ('lang', substr($_GET['lang'],0,2), time() +60*60*24*30, '/', false, 0);
  166. $language_abr = substr($_GET['lang'],0,2);
  167. }
  168. /**
  169. * Set the language variable to session 'lang' - this variable is the one used below
  170. *
  171. */
  172. $language_abr = "";
  173. if(isset($_COOKIE['lang'])) { $language_abr = $_COOKIE['lang']; }
  174. /**
  175. * Use the default language if none of the previous steps captured a language preference
  176. *
  177. */
  178. if(empty($language_abr)){ $language_abr = $default_language_abr; }
  179. /**
  180. * Override the language if $_GET['lang'] is set.
  181. *
  182. */
  183. if(isset($_GET['lang'])){ $language_abr = substr($_GET['lang'],0,2); }
  184. /**
  185. * Convert the two letter $language variable to full name of language file
  186. * (used in language file switch but not template switch (template uses abbreviation))
  187. *
  188. */
  189. foreach($PP_supp_lang as $key => $row)
  190. {
  191. foreach($row as $cell)
  192. {
  193. if($cell == strtoupper($language_abr)) { $language_full = $key; }
  194. }
  195. }
  196. /**
  197. * Get the language file based on the language selection
  198. *
  199. *
  200. * Always include the default language file (English) if it exists.
  201. * That way if we forget to update the variables in the alternative language files the English ones are shown.
  202. *
  203. */
  204. if(file_exists("language/lang-english.php"))
  205. {
  206. if(!isset($_GET['x']) OR ($_GET['x'] != "rss" AND $_GET['x'] != "atom"))
  207. {
  208. require_once("language/lang-english.php");
  209. }
  210. }
  211. // now replace the contents of the variables with the selected language.
  212. if(!empty($language_full))
  213. {
  214. // check if illegal characters are used
  215. if (!ereg("^[A-Za-z]+([0-9]+)?$", $language_full)) {
  216. echo '<b>Error:</b><br />Pixelpost cannot include this file. If you need assistance in resolving this error please visit the <a href="http://www.pixelpost.org/forum/">Pixelpost Forum</a>.';
  217. setcookie ('lang', "", time() - 3600, '/', false, 0);
  218. exit;
  219. } else {
  220. if(file_exists("language/lang-".$language_full.".php"))
  221. {
  222. if(!isset($_GET['x']) OR ($_GET['x'] != "rss" AND $_GET['x'] != "atom"))
  223. {
  224. require_once("language/lang-".$language_full.".php");
  225. }
  226. }
  227. else
  228. {
  229. echo '<b>Error:</b><br />No <b>language</b> folder exists or the file <b>"lang-'.$language_full.'.php"</b> is missing in that folder.<br />Make sure that you have uploaded all necessary files with the exact same names as mentioned here.';
  230. setcookie ('lang', "", time() - 3600, '/', false, 0);
  231. exit;
  232. }
  233. }
  234. }
  235. else
  236. {
  237. echo '<b>Error:</b><br />Pixelpost has problem selecting a default language.<br />Make sure that you have chosen a default language in the adminpanel.';
  238. setcookie ('lang', "", time() - 3600, '/', false, 0);
  239. exit;
  240. }
  241. // Double Quotes in <SITE_TITLE> break HTML Code
  242. $pixelpost_site_title = htmlspecialchars(pullout($cfgrow['sitetitle']),ENT_NOQUOTES);
  243. // Double Quotes in <SUB_TITLE> break HTML Code
  244. $pixelpost_sub_title = htmlspecialchars(pullout($cfgrow['subtitle']),ENT_NOQUOTES);
  245. /**
  246. * Added ability to use header and footers for templates. They are not needed but used if included in the template
  247. * Don't show header or footer if viewing comments in a popup
  248. *
  249. */
  250. if(isset($_GET['popup']) && $_GET['popup'] != "comment" || !isset($_GET['popup']))
  251. {
  252. if(file_exists("templates/".$cfgrow['template']."/header.html"))
  253. {
  254. $header = compile("templates/".$cfgrow['template']."/header.html");
  255. }
  256. if(file_exists("templates/".$cfgrow['template']."/footer.html"))
  257. {
  258. $footer = compile("templates/".$cfgrow['template']."/footer.html");
  259. }
  260. }
  261. /**
  262. * You can now add any template you want by just adding the template and a link to it. For example,
  263. * ?x=about will load the template about_template.html
  264. *
  265. */
  266. if(isset($_GET['x'])&& $_GET['x'] == "ref") { $_GET['x'] = "referer"; } // Maintain backwards compatibility with the referer template
  267. // Refererlog
  268. if(isset($_GET['x'])&&$_GET['x'] == "referer")
  269. {
  270. header("HTTP/1.0 404 Not Found");
  271. header("Status: 404 File Not Found!");
  272. echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><HTML><HEAD>\n<TITLE>404 Not Found</TITLE>\n</HEAD><BODY>\n<H1>Not Found</H1>\nThe requested URL /index.php was not found on this server.<P>\n<P>Additionally, a 404 Not Found\nerror was encountered while trying to use an ErrorDocument to handle the request.\n</BODY></HTML>";
  273. exit;
  274. }
  275. /**
  276. * Get the template file based on the language selection
  277. *
  278. */
  279. if($language_full==$cfgrow['langfile'])
  280. { // we have our default language from the PP installation, so we use our default templates
  281. if(isset($_GET['x']) && file_exists("templates/".$cfgrow['template']."/".$_GET['x']."_template.html"))
  282. {
  283. if(eregi("[.]",$_GET['x'])) { die("Come on! forget about it..."); }
  284. $tpl = compile("templates/".$cfgrow['template']."/".$_GET['x']."_template.html");
  285. }
  286. else
  287. {
  288. if(!file_exists("templates/".$cfgrow['template']."/image_template.html"))
  289. {
  290. echo '<b>Error:</b><br />No template folder exists by the name of <b>"' .$cfgrow['template'] .'"</b> or the file <b>image_template.html</b> is missing in that folder.<br />Make sure that you have uploaded all necessary files with the exact same names as mentioned here.';
  291. exit;
  292. }
  293. if(isset($_GET['x']) && $_GET['x'] != 'atom' && $_GET['x'] != 'comment_atom' && $_GET['x'] != 'rss' && $_GET['x'] != 'comment_rss' && $_GET['x'] != 'save_comment') // if the x=foo does not exist, error 404
  294. {
  295. header("HTTP/1.0 404 Not Found");
  296. header("Status: 404 File Not Found!");
  297. echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><HTML><HEAD>\n<TITLE>404 Not Found</TITLE>\n</HEAD><BODY>\n<H1>Not Found</H1>\nThe requested URL /index.php was not found on this server.<P>\n<P>Additionally, a 404 Not Found\nerror was encountered while trying to use an ErrorDocument to handle the request.\n</BODY></HTML>";
  298. exit;
  299. }
  300. $tpl = compile("templates/".$cfgrow['template']."/image_template.html");
  301. }
  302. }
  303. else
  304. {
  305. if(isset($_GET['x']) && file_exists("templates/".$cfgrow['template']."/".$_GET['x']."_".$language_abr."_template.html")) // we use our special designed language templates.
  306. {
  307. if (eregi("[.]",$_GET['x'])) { die("Come on! forget about it..."); }
  308. $tpl = compile("templates/".$cfgrow['template']."/".$_GET['x']."_".$language_abr."_template.html");
  309. }
  310. else
  311. {
  312. if(!file_exists("templates/".$cfgrow['template']."/image_".$language_abr."_template.html"))
  313. {
  314. echo '<b>Error:</b><br />No template folder exists by the name of <b>"' .$cfgrow['template'] .'"</b> or the file <b>image_'.$language_abr .'_template.html</b> is missing in that folder.<br />Make sure that you have uploaded all necessary files with the exact same names as mentioned here.<br /><br /><a href="'.PHP_SELF.'?lang='.$default_language_abr.'" alt="return to default language">Click here to return to the default language.</a>';
  315. exit;
  316. }
  317. if(isset($_GET['x']) && $_GET['x'] != 'atom' && $_GET['x'] != 'comment_atom' && $_GET['x'] != 'rss' && $_GET['x'] != 'comment_rss' && $_GET['x'] != 'save_comment') // if the x=foo does not exist, error 404
  318. {
  319. header("HTTP/1.0 404 Not Found");
  320. header("Status: 404 File Not Found!");
  321. echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><HTML><HEAD>\n<TITLE>404 Not Found</TITLE>\n</HEAD><BODY>\n<H1>Not Found</H1>\nThe requested URL /index.php was not found on this server.<P>\n<P>Additionally, a 404 Not Found\nerror was encountered while trying to use an ErrorDocument to handle the request.\n</BODY></HTML>";
  322. exit;
  323. }
  324. $tpl = compile("templates/".$cfgrow['template']."/image_".$language_abr."_template.html");
  325. }
  326. if($cfgrow['display_sort_by'] == 'headline') { $cfgrow['display_sort_by'] = 'alt_headline'; }
  327. if($cfgrow['display_sort_by'] == 'body') { $cfgrow['display_sort_by'] = 'alt_body'; }
  328. }
  329. if(isset($_GET['popup'])&&$_GET['popup'] == "comment")
  330. { // additional language file for comment template
  331. if(file_exists("templates/".$cfgrow['template']."/comment_".$language_abr."_template.html"))
  332. {
  333. $tpl = compile("templates/".$cfgrow['template']."/comment_".$language_abr."_template.html");
  334. }
  335. else
  336. { // if not existing or no additional language chosen, default template file is called without error
  337. $tpl = compile("templates/".$cfgrow['template']."/comment_template.html");
  338. }
  339. }
  340. // if showimage=badstuff or email, hijack!
  341. if(isset($_GET['showimage']) && !is_numeric($_GET['showimage']))
  342. {
  343. header("HTTP/1.0 404 Not Found");
  344. header("Status: 404 File Not Found!");
  345. echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><HTML><HEAD>\n<TITLE>404 Not Found</TITLE>\n</HEAD><BODY>\n<H1>Not Found</H1>\nDon't do that! go back to index.php! \n</BODY></HTML>";
  346. exit;
  347. }
  348. // Added ability to use header and footers for templates. They are not needed but used if included in the template
  349. if(isset($header)) { $tpl = $header . $tpl; }
  350. if(isset($footer)) { $tpl = $tpl. $footer; }
  351. // Get visitor count
  352. $visitors = sql_array("SELECT count(*) as `count` FROM `".$pixelpost_db_prefix."visitors`");
  353. $pixelpost_visitors = $visitors['count'];
  354. // Get number of photos in database
  355. $photonumb = sql_array("SELECT count(*) as `count` FROM `".$pixelpost_db_prefix."pixelpost` WHERE `datetime` <= '$datetime'");
  356. $pixelpost_photonumb = $photonumb['count'];
  357. // Get the display order
  358. if($cfgrow['display_order'] == 'default') { $display_order = 'DESC'; }else{ $display_order = 'ASC'; }
  359. /**
  360. * Images / Main site
  361. *
  362. */
  363. if(!isset($_GET['x']))
  364. {
  365. // Get Current Image.
  366. if(!isset($_SESSION["pixelpost_admin"]))
  367. {
  368. if(!isset($_GET['showimage']) || $_GET['showimage'] == "")
  369. {
  370. $row = sql_array("SELECT * FROM `".$pixelpost_db_prefix."pixelpost` WHERE `datetime` <= '$cdate' ORDER BY ".$cfgrow['display_sort_by']." ".$display_order." LIMIT 0,1");
  371. }
  372. else
  373. {
  374. $row = sql_array("SELECT * FROM `".$pixelpost_db_prefix."pixelpost` WHERE (`id` = '".$_GET['showimage']."') AND `datetime` <= '$cdate'");
  375. }
  376. }
  377. else
  378. {
  379. if(!isset($_GET['showimage']) || $_GET['showimage'] == "")
  380. {
  381. $row = sql_array("SELECT * FROM `".$pixelpost_db_prefix."pixelpost` ORDER BY ".$cfgrow['display_sort_by']." ".$display_order." LIMIT 0,1");
  382. }
  383. else
  384. {
  385. $row = sql_array("SELECT * FROM `".$pixelpost_db_prefix."pixelpost` WHERE (`id` = '".$_GET['showimage']."')");
  386. }
  387. }
  388. if(!$row['image']){ echo "$lang_nothing_to_show"; exit; }
  389. $image_name = $row['image'];
  390. if($language_abr == $default_language_abr)
  391. {
  392. $image_title = pullout($row['headline']);
  393. $image_notes = ($cfgrow['markdown'] == 'T') ? markdown(pullout($row['body'])) : pullout($row['body']);
  394. }
  395. else
  396. {
  397. $image_title = ($row['alt_headline']=='') ? pullout($row['headline']) : pullout($row['alt_headline']);
  398. if($row['alt_body']=='')
  399. {
  400. $image_notes = ($cfgrow['markdown'] == 'T') ? markdown(pullout($row['body'])) : pullout($row['body']);
  401. }
  402. else
  403. {
  404. $image_notes = ($cfgrow['markdown'] == 'T') ? markdown(pullout($row['alt_body'])) : pullout($row['alt_body']);
  405. }
  406. }
  407. $image_title = htmlspecialchars($image_title,ENT_NOQUOTES);
  408. $image_id = $row['id'];
  409. $image_datetime = $row['datetime'];
  410. $image_datetime_formatted = strtotime($image_datetime);
  411. $image_datetime_formatted = date($cfgrow['dateformat'],$image_datetime_formatted);
  412. $image_date = substr($row['datetime'],0,10);
  413. $image_time = substr($row['datetime'],11,5);
  414. $image_date_year_full = substr($row['datetime'],0,4);
  415. $image_date_year = substr($row['datetime'],2,2);
  416. $image_date_month = substr($row['datetime'],5,2);
  417. $image_date_day = substr($row['datetime'],8,2);
  418. $thumbnail_extra = getimagesize(ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image_name);
  419. $image_extra = getimagesize(ltrim($cfgrow['imagepath'], "./").$image_name);
  420. $image_width = $image_extra['0'];
  421. $image_height = $image_extra['1'];
  422. $tpl = str_replace("<IMAGE_WIDTH>",$image_width,$tpl);
  423. $tpl = str_replace("<IMAGE_HEIGHT>",$image_height,$tpl);
  424. $local_width = $thumbnail_extra['0'];
  425. $local_height = $thumbnail_extra['1'];
  426. $image_exif = $row['exif_info'];
  427. $image_thumbnail = "<a href='$showprefix$image_id'><img src='".ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image_name."' alt='$image_title' title='$image_title' width='$local_width' height='$local_height' /></a>";
  428. // thumnail no link
  429. $image_thumbnail_no_link = "<img src='".ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image_name."' alt='$image_title' title='$image_title' width='$local_width' height='$local_height' />";
  430. $image_permalink = "<a href='$showprefix$image_id'>$lang_permalink</a>"; // permalink automated for fancy url/no fancy
  431. // get previous image id and name
  432. if(!isset($_SESSION["pixelpost_admin"]))
  433. { //public
  434. $previous_row = sql_array("SELECT `id`,`headline`,`alt_headline`,`image`,`datetime` FROM `".$pixelpost_db_prefix."pixelpost` WHERE (`datetime` < '$image_datetime') AND (`datetime` <= '$cdate') ORDER BY `datetime` DESC LIMIT 0,1");
  435. }
  436. else
  437. { //admin
  438. $previous_row = sql_array("SELECT `id`,`headline`,`alt_headline`,`image`,`datetime` FROM `".$pixelpost_db_prefix."pixelpost` WHERE (`datetime` < '$image_datetime') ORDER BY `datetime` DESC LIMIT 0,1");
  439. }
  440. $image_previous_name = $previous_row['image'];
  441. $image_previous_id = $previous_row['id'];
  442. $image_previous_title = ($language_abr == $default_language_abr) ? pullout($previous_row['headline']) : pullout($previous_row['alt_headline']);
  443. $image_previous_datetime = $previous_row['datetime'];
  444. $image_previous_link = "<a href='$showprefix$image_previous_id'>$lang_previous</a>";
  445. if(!empty($image_previous_name)){ list($local_width,$local_height,$type,$attr) = getimagesize(ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image_previous_name); }
  446. $image_previous_thumbnail = "<a href='$showprefix$image_previous_id'><img src='".ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image_previous_name."' width='$local_width' height='$local_height' alt='$image_previous_title' title='$image_previous_title' /></a>";
  447. if($image_previous_id == "")
  448. {
  449. $image_previous_id = $image_id;
  450. $image_previous_title = "$lang_no_previous";
  451. $image_previous_link = "";
  452. $image_previous_thumbnail = "";
  453. }
  454. // get next image id and name
  455. if(!isset($_SESSION["pixelpost_admin"]))
  456. { //public
  457. $next_row = sql_array("SELECT `id`,`headline`,`alt_headline`,`image`,`datetime` FROM `".$pixelpost_db_prefix."pixelpost` WHERE (`datetime` > '$image_datetime') AND (`datetime` <= '$cdate') ORDER BY `datetime` ASC LIMIT 0,1");
  458. }
  459. else
  460. { //admin
  461. $next_row = sql_array("SELECT `id`,`headline`,`alt_headline`,`image`,`datetime` FROM `".$pixelpost_db_prefix."pixelpost` WHERE (`datetime` > '$image_datetime') ORDER BY `datetime` ASC LIMIT 0,1");
  462. }
  463. $image_next_name = $next_row['image'];
  464. $image_next_id = $next_row['id'];
  465. $image_next_title = ($language_abr == $default_language_abr) ? pullout($next_row['headline']) : pullout($next_row['alt_headline']);
  466. $image_next_datetime = $next_row['datetime'];
  467. $image_next_link = "<a href='$showprefix$image_next_id'>$lang_next</a>";
  468. if(!empty($image_next_name)){ list($local_width,$local_height,$type,$attr) = getimagesize(ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image_next_name); }
  469. $image_next_thumbnail = "<a href='$showprefix$image_next_id'><img src='".ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image_next_name."' alt='$image_next_title' width='$local_width' height='$local_height' title='$image_next_title' /></a>";
  470. if($image_next_id == "")
  471. {
  472. $image_next_id = $image_id;
  473. $image_next_title = "$lang_no_next";
  474. $image_next_link = "";
  475. $image_next_thumbnail = "";
  476. }
  477. // get first image
  478. if(!isset($_SESSION["pixelpost_admin"]))
  479. { //public
  480. $first_image_row = sql_array("SELECT `id`,`headline`,`alt_headline`,`image`,`datetime` FROM `".$pixelpost_db_prefix."pixelpost` WHERE (`datetime` <= '$cdate') ORDER BY `datetime` ASC LIMIT 0,1");
  481. }
  482. else
  483. { //admin
  484. $first_image_row = sql_array("SELECT `id`,`headline`,`alt_headline`,`image`,`datetime` FROM `".$pixelpost_db_prefix."pixelpost` ORDER BY `datetime` ASC LIMIT 0,1");
  485. }
  486. $first_image_name = $first_image_row['image'];
  487. $first_image_id = $first_image_row['id'];
  488. $first_image_title = ($language_abr == $default_language_abr) ? pullout($first_image_row['headline']) : pullout($first_image_row['alt_headline']);
  489. $first_image_datetime = $first_image_row['datetime'];
  490. $first_image_link = "<a href='$showprefix$first_image_id'>$lang_first</a>";
  491. if(!empty($first_image_name)){ list($local_width,$local_height,$type,$attr) = getimagesize(ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$first_image_name); }
  492. $first_image_thumbnail = "<a href='$showprefix$first_image_id'><img src='".ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$first_image_name."' alt='$first_image_title' width='$local_width' height='$local_height' title='$first_image_title' /></a>";
  493. if($first_image_id == $image_id)
  494. {
  495. $first_image_title = null;
  496. $first_image_link = null;
  497. $first_image_thumbnail = null;
  498. }
  499. // get latest image
  500. if(!isset($_SESSION["pixelpost_admin"]))
  501. { //public
  502. $last_image_row = sql_array("SELECT `id`,`headline`,`alt_headline`,`image`,`datetime` FROM `".$pixelpost_db_prefix."pixelpost` WHERE (`datetime` <= '$cdate') ORDER BY `datetime` DESC LIMIT 0,1");
  503. }
  504. else
  505. { //admin
  506. $last_image_row = sql_array("SELECT `id`,`headline`,`alt_headline`,`image`,`datetime` FROM `".$pixelpost_db_prefix."pixelpost` WHERE (`datetime` <= '$cdate') ORDER BY `datetime` DESC LIMIT 0,1");
  507. }
  508. $last_image_name = $last_image_row['image'];
  509. $last_image_id = $last_image_row['id'];
  510. $last_image_title = ($language_abr == $default_language_abr) ? pullout($last_image_row['headline']) : pullout($last_image_row['alt_headline']);
  511. $last_image_datetime = $last_image_row['datetime'];
  512. $last_image_link = "<a href='$showprefix$last_image_id'>$lang_latest</a>";
  513. if(!empty($last_image_name)){ list($local_width,$local_height,$type,$attr) = getimagesize(ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$last_image_name); }
  514. $last_image_thumbnail = "<a href='$showprefix$last_image_id'><img src='".ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$last_image_name."' alt='$last_image_title' width='$local_width' height='$local_height' title='$last_image_title' /></a>";
  515. if($last_image_id == $image_id)
  516. {
  517. $last_image_title = null;
  518. $last_image_link = null;
  519. $last_image_thumbnail = null;
  520. }
  521. if(function_exists('gd_info'))
  522. {
  523. $gd_info = gd_info();
  524. if($gd_info != "")
  525. {
  526. // check that gd is here before this
  527. $aheadnumb = sql_array("SELECT count(*) as count FROM `".$pixelpost_db_prefix."pixelpost` WHERE (`datetime` > '$image_datetime') AND (`datetime` <= '$cdate')");
  528. $aheadnumb = $aheadnumb['count'];
  529. $behindnumb = sql_array("SELECT count(*) as count FROM `".$pixelpost_db_prefix."pixelpost` WHERE (`datetime` < '$image_datetime') AND (`datetime` <= '$cdate')");
  530. $behindnumb = $behindnumb['count'];
  531. $aheadlimit = round(($cfgrow['thumbnumber']-1)/2);
  532. $behindlimit = round(($cfgrow['thumbnumber']-1)/2);
  533. if($aheadnumb <= $aheadlimit)
  534. {
  535. $behindlimit = ($cfgrow['thumbnumber']-1)-$aheadnumb;
  536. $aheadlimit = $aheadnumb;
  537. }
  538. if($behindnumb <= $behindlimit)
  539. {
  540. $aheadlimit = ($cfgrow['thumbnumber']-1)-$behindnumb;
  541. $behindlimit = $behindnumb;
  542. }
  543. $totalthumbcounter = 1;
  544. $ahead_thumbs = '';
  545. $ahead_thumbs_reverse = '';
  546. $thumbs_ahead = mysql_query("SELECT `id`,`headline`,`alt_headline`,`image` FROM `".$pixelpost_db_prefix."pixelpost` WHERE (`datetime` > '$image_datetime') AND (`datetime` <= '$cdate') ORDER BY `datetime` ASC LIMIT 0,$aheadlimit");
  547. while(list($id,$headline,$alt_headline,$image) = mysql_fetch_row($thumbs_ahead))
  548. {
  549. $headline = ($language_abr == $default_language_abr) ? pullout($headline) : pullout($alt_headline);
  550. $headline = htmlspecialchars($headline,ENT_QUOTES);
  551. if(!empty($image)){ list($local_width,$local_height,$type,$attr) = getimagesize(ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image); }
  552. $ahead_thumbs .= "<a href='$showprefix$id'><img src='".ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image."' alt='$headline' title='$headline' class='thumbnails' width='$local_width' height='$local_height' /></a>";
  553. $ahead_thumbs_reverse = "<a href='$showprefix$id'><img src='".ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image."' alt='$headline' title='$headline' class='thumbnails' width='$local_width' height='$local_height' /></a>" .$ahead_thumbs_reverse ;
  554. $totalthumbcounter++;
  555. }
  556. $behind_thumbs = "";
  557. $behind_thumbs_reverse = "";
  558. $thumbs_behind = mysql_query("SELECT `id`,`headline`,`alt_headline`,`image` FROM `".$pixelpost_db_prefix."pixelpost` WHERE (`datetime` < '$image_datetime') AND (`datetime` <= '$cdate') ORDER BY `datetime` DESC LIMIT 0,$behindlimit");
  559. while(list($id,$headline,$alt_headline,$image) = mysql_fetch_row($thumbs_behind)) {
  560. $headline = ($language_abr == $default_language_abr) ? pullout($headline) : pullout($alt_headline);
  561. $headline = htmlspecialchars($headline,ENT_QUOTES);
  562. if(!empty($image)){ list($local_width,$local_height,$type,$attr) = getimagesize(ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image); }
  563. $behind_thumbs = "<a href='$showprefix$id'><img src='".ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image."' alt='$headline' title='$headline' class='thumbnails' width='$local_width' height='$local_height' /></a>$behind_thumbs";
  564. $behind_thumbs_reverse .= "<a href='$showprefix$id'><img src='".ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image."' alt='$headline' title='$headline' class='thumbnails' width='$local_width' height='$local_height' /></a>";
  565. $totalthumbcounter++;
  566. }
  567. if(!empty($image_name)){ list($local_width,$local_height,$type,$attr) = getimagesize(ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image_name); }
  568. $thumbnail_row = "$behind_thumbs<a href='$showprefix$image_id'><img src='".ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image_name."' alt='$image_title' title='$image_title' class='current-thumbnail' width='$local_width' height='$local_height' /></a>$ahead_thumbs";
  569. $thumbnail_row_reverse = "$ahead_thumbs_reverse<a href='$showprefix$image_id'><img src='".ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$image_name."' alt='$image_title' title='$image_title' class='current-thumbnail' width='$local_width' height='$local_height' /></a>$behind_thumbs_reverse";
  570. $tpl = ereg_replace("<IMAGE_THUMBNAIL_ROW>",$thumbnail_row,$tpl);
  571. $tpl = ereg_replace("<IMAGE_THUMBNAIL_ROW_REV>",$thumbnail_row_reverse,$tpl);
  572. }
  573. }
  574. // Modified from Mark Lewin's hack for multiple categories
  575. $query = mysql_query("SELECT t1.cat_id,t2.name,t2.alt_name FROM `".$pixelpost_db_prefix."catassoc` AS t1 INNER JOIN `".$pixelpost_db_prefix."categories` t2 ON t1.cat_id = t2.id WHERE t1.image_id = '$image_id' ORDER BY t2.name");
  576. $image_category_number = 0;
  577. $image_category_all ="";
  578. $image_category_all_paged = "";
  579. while(list($cat_id,$name,$alt_name) = mysql_fetch_row($query))
  580. {
  581. $name = ($language_abr == $default_language_abr) ? pullout($name) : pullout($alt_name);
  582. $image_category_all .= "<a href='".PHP_SELF."?x=browse&amp;category=$cat_id'>" .$cfgrow['catgluestart'] .$name .$cfgrow['catglueend']."</a> &nbsp;";
  583. $image_category_all_paged .= "<a href='".PHP_SELF."?x=browse&amp;category=$cat_id&amp;pagenum=1'>" .$cfgrow['catgluestart'] .$name .$cfgrow['catglueend']."</a> &nbsp;";
  584. $image_category_number = $image_category_number +1;
  585. }
  586. $image_categoryword = ($image_category_number >1) ? "$lang_category_plural " : "$lang_category_singular ";
  587. $tpl = ereg_replace("<SITE_TITLE>",$pixelpost_site_title,$tpl);
  588. $tpl = ereg_replace("<SUB_TITLE>",$pixelpost_sub_title,$tpl);
  589. $tpl = ereg_replace("<SITE_URL>",$cfgrow['siteurl'],$tpl);
  590. $tpl = ereg_replace("<IMAGE_CATEGORY>",$image_categoryword." ".$image_category_all,$tpl);
  591. // for paged_archive addon
  592. $tpl = ereg_replace("<IMAGE_CATEGORY_PAGED>",$image_categoryword." ".$image_category_all_paged,$tpl);
  593. $tpl = ereg_replace("<IMAGE_DATE_YEAR_FULL>",$image_date_year_full,$tpl);
  594. $tpl = ereg_replace("<IMAGE_DATE_YEAR>",$image_date_year,$tpl);
  595. $tpl = ereg_replace("<IMAGE_DATE_MONTH>",$image_date_month,$tpl);
  596. $tpl = ereg_replace("<IMAGE_DATE_DAY>",$image_date_day,$tpl);
  597. $tpl = ereg_replace("<IMAGE_THUMBNAIL>",$image_thumbnail,$tpl);
  598. // thumbnail no link
  599. $tpl = ereg_replace("<IMAGE_THUMBNAIL_NO_LINK>",$image_thumbnail_no_link,$tpl);
  600. $tpl = ereg_replace("<IMAGE_DATE>",$image_date,$tpl);
  601. $tpl = ereg_replace("<IMAGE_TIME>",$image_time,$tpl);
  602. $tpl = ereg_replace("<IMAGE_NAME>",$image_name,$tpl);
  603. $tpl = ereg_replace("<IMAGE_TITLE>",$image_title,$tpl);
  604. $tpl = ereg_replace("<IMAGE_DATETIME>",$image_datetime_formatted,$tpl);
  605. $tpl = ereg_replace("<IMAGE_NOTES>",$image_notes,$tpl);
  606. // image notes without HTML tags and double quotes
  607. $image_notes_clean = strip_tags($image_notes);
  608. $image_notes_clean = htmlspecialchars($image_notes_clean,ENT_NOQUOTES);
  609. $image_notes_clean = str_replace('"',"'",$image_notes_clean);
  610. $tpl = ereg_replace("<IMAGE_NOTES_CLEAN>",$image_notes_clean,$tpl);
  611. $tpl = ereg_replace("<IMAGE_ID>",$image_id,$tpl);
  612. $tpl = ereg_replace("<IMAGE_PERMALINK>",$image_permalink,$tpl);
  613. $tpl = ereg_replace("<IMAGE_PREVIOUS_LINK>",$image_previous_link,$tpl);
  614. $tpl = ereg_replace("<IMAGE_PREVIOUS_THUMBNAIL>",$image_previous_thumbnail,$tpl);
  615. $tpl = ereg_replace("<IMAGE_PREVIOUS_ID>",$image_previous_id,$tpl);
  616. $tpl = ereg_replace("<IMAGE_PREVIOUS_TITLE>",$image_previous_title,$tpl);
  617. $tpl = ereg_replace("<IMAGE_NEXT_LINK>",$image_next_link,$tpl);
  618. $tpl = ereg_replace("<IMAGE_NEXT_ID>",$image_next_id,$tpl);
  619. $tpl = ereg_replace("<IMAGE_NEXT_TITLE>",$image_next_title,$tpl);
  620. $tpl = ereg_replace("<IMAGE_NEXT_THUMBNAIL>",$image_next_thumbnail,$tpl);
  621. $tpl = ereg_replace("<IMAGE_LAST_LINK>",$last_image_link,$tpl);
  622. $tpl = ereg_replace("<IMAGE_LAST_THUMBNAIL>",$last_image_thumbnail,$tpl);
  623. $tpl = ereg_replace("<IMAGE_LAST_ID>",$last_image_id,$tpl);
  624. $tpl = ereg_replace("<IMAGE_LAST_TITLE>",$last_image_title,$tpl);
  625. $tpl = ereg_replace("<IMAGE_FIRST_LINK>",$first_image_link,$tpl);
  626. $tpl = ereg_replace("<IMAGE_FIRST_ID>",$first_image_id,$tpl);
  627. $tpl = ereg_replace("<IMAGE_FIRST_TITLE>",$first_image_title,$tpl);
  628. $tpl = ereg_replace("<IMAGE_FIRST_THUMBNAIL>",$first_image_thumbnail,$tpl);
  629. // Added support for Thumbnail width and height
  630. $tpl = str_replace("<THUMBNAIL_WIDTH>",$cfgrow['thumbwidth'],$tpl);
  631. $tpl = str_replace("<THUMBNAIL_HEIGHT>",$cfgrow['thumbheight'],$tpl);
  632. // get number of comments
  633. $cnumb_row = sql_array("SELECT count(*) as count FROM ".$pixelpost_db_prefix."comments WHERE parent_id='$image_id' and publish='yes'");
  634. $image_comments_number = $cnumb_row['count'];
  635. // get latest comment
  636. $latest_comment = sql_array("SELECT parent_id FROM ".$pixelpost_db_prefix."comments WHERE publish='yes' ORDER BY id desc limit 0,1");
  637. $latest_comment = $latest_comment['parent_id'];
  638. $queryrow = sql_array("SELECT headline FROM ".$pixelpost_db_prefix."pixelpost WHERE id='$latest_comment'");
  639. $latest_comment_name = pullout($queryrow['headline']);
  640. // ##########################################################################################//
  641. // EXIF STUFF
  642. // ##########################################################################################//
  643. if($cfgrow['exif']=='T')
  644. {
  645. require_once('includes/functions_exif.php');
  646. if($image_exif!==null)
  647. {
  648. $tpl = replace_exif_tags ($language_full, $image_exif, $tpl);
  649. }
  650. else
  651. {
  652. $tpl = replace_exif_tags_null($tpl);
  653. }
  654. }
  655. else
  656. {
  657. require_once('includes/functions_exif.php');
  658. $tpl = replace_exif_tags_null($tpl);
  659. }
  660. /**
  661. * Build a string with all comments.
  662. * Only perform this code when the user has commenting enabled
  663. *
  664. */
  665. if(isset($_GET['x']) && ($_GET['x'] == "") or (isset($_GET['popup']) && $_GET['popup'] == "comment"))
  666. {
  667. $comment_id = (isset($_POST['parent_id'])) ? intval($_POST['parent_id']) : '';
  668. $comments_result = sql_array("SELECT `comments` FROM `".$pixelpost_db_prefix."pixelpost` WHERE `id` = '".$comment_id."'");
  669. $cmnt_setting = pullout($comments_result['comments']);
  670. if($cmnt_setting == 'F'){ die('Die you SPAMMER!!'); }
  671. }
  672. // visitor information in comments
  673. $vinfo_name = "";
  674. $vinfo_url = "";
  675. $vinfo_email = "";
  676. if(isset($_COOKIE['visitorinfo'])){ list($vinfo_name,$vinfo_url,$vinfo_email) = split("%",$_COOKIE['visitorinfo']); }
  677. $tpl = ereg_replace("<VINFO_NAME>",$vinfo_name,$tpl);
  678. $tpl = ereg_replace("<VINFO_URL>",$vinfo_url,$tpl);
  679. $tpl = ereg_replace("<VINFO_EMAIL>",$vinfo_email,$tpl);
  680. if($cfgrow['token'] == 'T')
  681. {
  682. $tpl = ereg_replace("<TOKEN>","<input type='hidden' name='token' value='".$_SESSION['token']."' />",$tpl);
  683. }
  684. else
  685. {
  686. $tpl = ereg_replace("<TOKEN>",null,$tpl);
  687. }
  688. if(isset($_GET['showimage']) && $_GET['showimage'] != "")
  689. {
  690. $imageid = $_GET['showimage'];
  691. }
  692. else
  693. {
  694. $imageid = $image_id;
  695. }
  696. $image_comments = print_comments($imageid);
  697. $tpl = ereg_replace("<IMAGE_COMMENTS>",$image_comments,$tpl);
  698. if((isset($_GET['popup']) && $_GET['popup'] == "comment") AND (!isset($_GET['x']) OR $_GET['x'] != "save_comment"))
  699. {
  700. require_once('includes/addons_lib.php');
  701. echo $tpl;
  702. exit;
  703. }
  704. } // End Images / Main site
  705. $tpl = ereg_replace("<SITE_TITLE>",$pixelpost_site_title,$tpl);
  706. $tpl = ereg_replace("<SUB_TITLE>",$pixelpost_sub_title,$tpl);
  707. // ##########################################################################################//
  708. // BROWSE STUFF
  709. // ##########################################################################################//
  710. if(isset($_GET['x']) && $_GET['x'] == "browse")
  711. {
  712. require_once("includes/functions_browse.php");
  713. }
  714. // ##########################################################################################//
  715. // FEED STUFF
  716. // ##########################################################################################//
  717. require_once("includes/functions_feeds.php");
  718. // ##########################################################################################//
  719. // Creating other tags
  720. // ########################################################################################
  721. $tpl = ereg_replace("<SITE_BROWSELINK>","./".PHP_SELF."?x=browse",$tpl);
  722. $tpl = ereg_replace("<SITE_BROWSELINK_PAGED>","./".PHP_SELF."?x=browse&amp;pagenum=1",$tpl);
  723. if(!isset($_GET['x']) || isset($_GET['showimage']))
  724. {
  725. $tpl = ereg_replace("<SITE_VISITORNUMBER>",$pixelpost_visitors,$tpl);
  726. $tpl = ereg_replace("<IMAGE_COMMENTS_NUMBER>",$image_comments_number,$tpl);
  727. $tpl = ereg_replace("<LATEST_COMMENT_ID>",$latest_comment,$tpl);
  728. $tpl = ereg_replace("<LATEST_COMMENT_NAME>",$latest_comment_name,$tpl);
  729. if($image_comments_number != 1)
  730. {
  731. $tpl = ereg_replace("<IMAGE_COMMENT_TEXT>",$lang_comment_plural,$tpl);
  732. }
  733. else
  734. {
  735. $tpl = ereg_replace("<IMAGE_COMMENT_TEXT>",$lang_comment_single,$tpl);
  736. }
  737. if($row['comments'] == 'F')
  738. {
  739. $tpl = ereg_replace("<COMMENT_POPUP>","<a href='".PHP_SELF."?showimage=$image_id' onclick=\"alert('$lang_comment_popup_disabled');\">$lang_comment_popup</a>",$tpl);
  740. }
  741. else
  742. {
  743. $tpl = ereg_replace("<COMMENT_POPUP>","<a href='".PHP_SELF."?showimage=$image_id' onclick=\"window.open('".PHP_SELF."?popup=comment&amp;showimage=$image_id','Comments','width=480,height=540,scrollbars=yes,resizable=yes');\">$lang_comment_popup</a>",$tpl);
  744. }
  745. }
  746. $tpl = str_replace("<BASE_HREF>","<base href='".$cfgrow['siteurl']."' />",$tpl);
  747. $tpl = ereg_replace("<SITE_URL>",$cfgrow['siteurl'],$tpl);
  748. $tpl = ereg_replace("<SITE_PHOTONUMBER>",$pixelpost_photonumb,$tpl);
  749. // ##########################################################################################//
  750. // COMMENT STUFF
  751. // ##########################################################################################//
  752. require_once("includes/functions_comments.php");
  753. // ##########################################################################################//
  754. // REPLACE LANGUAGE SPECIFIC TAGS
  755. // ##########################################################################################//
  756. if($cfgrow['altlangfile'] != 'Off'){ $tpl = replace_alt_lang_tags( $tpl, $language_abr, $PP_supp_lang, $cfgrow); }
  757. // ##########################################################################################//
  758. // SUCK IN ADDONS
  759. // ##########################################################################################//
  760. require_once('includes/addons_lib.php');
  761. // ##########################################################################################//
  762. // END - ECHO TEMPLATE
  763. // ##########################################################################################//
  764. if((isset($_GET['x']) && $_GET['x'] != "save_comment") || (!isset($_GET['x']))) { echo $tpl; }
  765. ?>