PageRenderTime 63ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/includes/functions.php

https://github.com/aravindc/pixelpost
PHP | 1914 lines | 1377 code | 287 blank | 250 comment | 220 complexity | 024395ad045985167033ef7965137b56 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // SVN file version:
  3. // $Id$
  4. /**
  5. * PP_unregister_GLOBALS() - Turn register globals off
  6. *
  7. * @return null Will return null if register_globals PHP directive was disabled
  8. * @author Wordpress 2.60
  9. */
  10. function PP_unregister_GLOBALS() {
  11. if ( !ini_get('register_globals') )
  12. return;
  13. if ( isset($_REQUEST['GLOBALS']) )
  14. die('GLOBALS overwrite attempt detected');
  15. // Variables that shouldn't be unset
  16. $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
  17. $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
  18. foreach ( $input as $k => $v )
  19. if ( !in_array($k, $noUnset) && isset($GLOBALS[$k]) ) {
  20. $GLOBALS[$k] = NULL;
  21. unset($GLOBALS[$k]);
  22. }
  23. }
  24. /**
  25. * Magic Quotes KILLER *dun! dun! dun!*
  26. *
  27. * Will strip all formating applied by magic quotes to any GLOBAL listed in the $in array
  28. * All data will have to be manually escaped before use.
  29. *
  30. * FYI: Magic quotes will be DEPRECIATED and REMOVED from PHP as of version 6!
  31. * @author http://talks.php.net/show/php-best-practices/26
  32. */
  33. if(get_magic_quotes_gpc())
  34. {
  35. if(isset($_GET) OR isset($_POST))// OR isset($_COOKIE) OR isset($_SESSION)
  36. {
  37. $in = array(&$_GET, &$_POST);//, &$_COOKIE, &$_SESSION);
  38. while(list($k,$v) = each($in))
  39. {
  40. foreach($v as $key => $val)
  41. {
  42. if(!is_array($val))
  43. {
  44. $in[$k][$key] = stripslashes($val);
  45. continue;
  46. }
  47. $in[] =& $in[$k][$key];
  48. }
  49. }
  50. //var_dump($in);
  51. unset($in);
  52. }
  53. }
  54. /**
  55. * Compile the specified file, executing any PHP code it contains and return it as a string.
  56. * Used to include template HTML files.
  57. *
  58. */
  59. function compile($file) {
  60. if(@is_readable($file)){
  61. ob_start();
  62. require $file;
  63. return ob_get_clean();
  64. }else{
  65. return false;
  66. }
  67. }
  68. /**
  69. * Check if directory exists. If it does not, attempt to create it.
  70. *
  71. */
  72. function check_and_set($directory)
  73. {
  74. if(@file_exists($directory))
  75. {
  76. if(@is__writable($directory))
  77. {
  78. return "ok";
  79. }
  80. else
  81. {
  82. if(@chmod($directory, 0777))
  83. {
  84. return "ok";
  85. }
  86. else
  87. {
  88. return "chmod";
  89. }
  90. }
  91. }
  92. else
  93. {
  94. if(@mkdir($directory))
  95. {
  96. return check_and_set($directory);
  97. }
  98. else
  99. {
  100. return "create";
  101. }
  102. }
  103. }
  104. /**
  105. * Will work despite of Windows ACLs bug
  106. *
  107. * NOTE: use a trailing slash for folders!!!
  108. *
  109. * See http://bugs.php.net/bug.php?id=27609 AND http://bugs.php.net/bug.php?id=30931
  110. * Source: <http://www.php.net/is_writable#73596>
  111. *
  112. */
  113. function is__writable($path)
  114. {
  115. // recursively return a temporary file path
  116. if($path{strlen($path)-1} == '/')
  117. {
  118. return is__writable($path.uniqid(mt_rand()).'.tmp');
  119. }
  120. elseif(is_dir($path))
  121. {
  122. return is__writable($path.'/'.uniqid(mt_rand()).'.tmp');
  123. }
  124. // check tmp file for read/write capabilities
  125. $rm = file_exists($path);
  126. $f = @fopen($path, 'a');
  127. if($f===false){ return false; }
  128. fclose($f);
  129. if(!$rm){ unlink($path); }
  130. return true;
  131. }
  132. /**
  133. * Check for a valid email address
  134. *
  135. */
  136. function check_email_address($email)
  137. {
  138. if(preg_match('/[\x00-\x1F\x7F-\xFF]/', $email)) // Check for invalid characters
  139. {
  140. return false;
  141. }
  142. if(!preg_match('/^[^@]{1,64}@[^@]{1,255}$/', $email)) // Check that there's one @ symbol, and that the lengths are right
  143. {
  144. return false;
  145. }
  146. $email_array = explode('@', $email); // Split it into sections to make life easier
  147. $local_array = explode('.', $email_array[0]); // Check local section
  148. foreach($local_array as $local_part)
  149. {
  150. if(!preg_match('/^(([A-Za-z0-9!#$%&\'*+\/=?^_`{|}~-]+)|("[^"]+"))$/', $local_part))
  151. {
  152. return false;
  153. }
  154. }
  155. if(preg_match('/^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}$/', $email_array[1]) OR preg_match('/^\[(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}\]$/', $email_array[1])) // Check domain section
  156. {
  157. return true; // If an IP address
  158. }
  159. else
  160. { // If not an IP address
  161. $domain_array = explode('.', $email_array[1]);
  162. if(sizeof($domain_array) < 2)
  163. {
  164. return false; // Not enough parts to be a valid domain
  165. }
  166. foreach($domain_array as $domain_part)
  167. {
  168. if(!preg_match('/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]))$/', $domain_part))
  169. {
  170. return false;
  171. }
  172. }
  173. return true;
  174. }
  175. }
  176. /**
  177. * Returns the Pixelpost version by looking at the database. Returns 0 if not installed.
  178. *
  179. */
  180. function Get_Pixelpost_Version($prefix)
  181. {
  182. // First, check to see if we are >= v1.4
  183. $query = mysql_query("SELECT `version` FROM `{$prefix}version` ORDER BY `version` DESC LIMIT 1");
  184. if($query)
  185. {
  186. if($row = mysql_fetch_array($query,MYSQL_NUM))
  187. {
  188. if($row[0] > 1.3) return $row[0];
  189. }
  190. }
  191. // Second, check to see if we are installed?
  192. $query = @mysql_query("SELECT COUNT(admin) FROM `{$prefix}config`");
  193. if($query)
  194. {
  195. if($row = mysql_fetch_array($query,MYSQL_NUM))
  196. {
  197. if($row[0] > 0) return 1.3; // This could also be 1.2, but that is okay
  198. }
  199. }
  200. return 0; // Everything failed, must not be installed
  201. }
  202. /**
  203. * Print an images comments
  204. *
  205. */
  206. function print_comments($imageid)
  207. {
  208. global $pixelpost_db_prefix, $lang_no_comments_yet, $lang_visit_homepage, $cfgrow;
  209. $image_comments = '<ul>';
  210. $cquery = mysql_query("SELECT `datetime`, `message`, `name`, `url`, `email` FROM `".$pixelpost_db_prefix."comments` WHERE `parent_id` = '".$imageid."' AND `publish` = 'yes' ORDER BY `id` ASC");
  211. $comment_count = 0;
  212. while(list($comment_datetime, $comment_message, $comment_name, $comment_url, $comment_email) = mysql_fetch_row($cquery))
  213. {
  214. $comment_name = pullout($comment_name);
  215. $comment_email = pullout($comment_email);
  216. $comment_message = pullout($comment_message);
  217. if($comment_url != "")
  218. {
  219. if(preg_match('/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}'.'((:[0-9]{1,5})?\/.*)?$/i' ,$comment_url))
  220. {
  221. $comment_name = "<a href=\"$comment_url\" title=\"$lang_visit_homepage\" target=\"_blank\" rel=\"nofollow\">$comment_name</a>";
  222. }
  223. else
  224. {
  225. unset($comment_url);
  226. $comment_name = "$comment_name";
  227. }
  228. }
  229. $comment_datetime = strtotime($comment_datetime);
  230. $comment_datetime = date($cfgrow['dateformat'],$comment_datetime);
  231. if($comment_email == $cfgrow['email'])
  232. { // admin comment
  233. $image_comments .= "<li class=\"admin_comment\">$comment_message<br />$comment_name @ $comment_datetime</li>";
  234. }
  235. else
  236. {
  237. $image_comments .= "<li>$comment_message<br />$comment_name @ $comment_datetime</li>";
  238. }
  239. $comment_count++;
  240. }
  241. if($comment_count == 0){ $image_comments .= "<li>$lang_no_comments_yet</li>"; }
  242. $image_comments .= '</ul>';
  243. return $image_comments;
  244. }
  245. /**
  246. * Return upload error string
  247. *
  248. */
  249. function check_upload($string)
  250. {
  251. global $admin_lang_pp_up_error_0, $admin_lang_pp_up_error_1, $admin_lang_pp_up_error_2, $admin_lang_pp_up_error_3, $admin_lang_pp_up_error_4;
  252. $error_explained = array(
  253. "0" => "$admin_lang_pp_up_error_0",
  254. "1" => "$admin_lang_pp_up_error_1",
  255. "2" => "$admin_lang_pp_up_error_2",
  256. "3" => "$admin_lang_pp_up_error_3",
  257. "4" => "$admin_lang_pp_up_error_4"
  258. //"6" => "$admin_lang_pp_up_error_6",
  259. //"7" => "$admin_lang_pp_up_error_7"
  260. );
  261. $result = $error_explained[$string];
  262. return($result);
  263. }
  264. /**
  265. * Create a thumbnail
  266. *
  267. */
  268. function createthumbnail($file)
  269. {
  270. global $pixelpost_db_prefix;
  271. $img = null;
  272. $cfgquery = mysql_query("SELECT * FROM `".$pixelpost_db_prefix."config`");
  273. $cfgrow = mysql_fetch_array($cfgquery,MYSQL_ASSOC);
  274. // credit to codewalkers.com - there is 90% a tutorial there
  275. $max_width = $cfgrow['thumbwidth'];
  276. $max_height = $cfgrow['thumbheight'];
  277. $image_base = rtrim($cfgrow['imagepath'],"/");
  278. $image_path = $image_base.'/'.$file;
  279. $image_path_exp = explode('.', $image_path);
  280. $image_path_end = end($image_path_exp);
  281. $ext = strtolower($image_path_end);
  282. if($ext == 'jpg' || $ext == 'jpeg')
  283. {
  284. $img = @imagecreatefromjpeg($image_path);
  285. }
  286. elseif($ext == 'png')
  287. {
  288. $img = @imagecreatefrompng($image_path);
  289. }
  290. elseif($ext == 'gif')
  291. {
  292. $img = @imagecreatefromgif($image_path);
  293. }
  294. if($img)
  295. {
  296. $width = imagesx($img);
  297. $height = imagesy($img);
  298. $scale = max($max_width/$width, $max_height/$height);
  299. if($scale < 1)
  300. {
  301. $new_width = floor($scale*$width);
  302. $new_height = floor($scale*$height);
  303. $tmp_img = imagecreatetruecolor($new_width,$new_height);
  304. if(function_exists('imagecopyresampled')) // GD >= 2.0.1
  305. {
  306. imagecopyresampled($tmp_img, $img, 0,0,0,0,$new_width,$new_height,$width,$height);
  307. }
  308. else
  309. { // GD <= 2.0
  310. imagecopyresized($tmp_img, $img, 0,0,0,0,$new_width,$new_height,$width,$height);
  311. }
  312. imagedestroy($img);
  313. if($cfgrow['thumb_sharpening'] != 0)
  314. {
  315. $tmp_img = unsharp_mask($tmp_img, $cfgrow['thumb_sharpening']);
  316. }
  317. $img = $tmp_img;
  318. }
  319. if($cfgrow['crop'] == "yes" | $cfgrow['crop'] == "12c")
  320. { // crop
  321. $tmp_img = imagecreatetruecolor($max_width,$max_height);
  322. if(function_exists('imagecopyresampled'))
  323. {
  324. imagecopyresampled($tmp_img, $img, 0,0,0,0,$max_width,$max_height,$max_width,$max_height);
  325. }
  326. else
  327. {
  328. imagecopyresized($tmp_img, $img, 0,0,0,0,$max_width,$max_height,$max_width,$max_height);
  329. }
  330. imagedestroy($img);
  331. if($cfgrow['thumb_sharpening'] != 0)
  332. {
  333. $tmp_img = unsharp_mask($tmp_img, $cfgrow['thumb_sharpening']);
  334. }
  335. $img = $tmp_img;
  336. }
  337. touch($cfgrow['thumbnailpath']."thumb_$file");
  338. imagejpeg($img,$cfgrow['thumbnailpath']."thumb_$file",$cfgrow['compression']);
  339. $thumbimage = $cfgrow['thumbnailpath']."thumb_$file";
  340. chmod($thumbimage,0644);
  341. }
  342. }
  343. function unsharp_mask($img, $sharpeningsetting){
  344. ////////////////////////////////////////////////////////////////////////////////////////////////
  345. ////
  346. //// Unsharp Mask for PHP - version 2.1.1
  347. ////
  348. //// Unsharp mask algorithm by Torstein HØnsi 2003-07.
  349. //// thoensi_at_netcom_dot_no.
  350. //// Please leave this notice.
  351. ////
  352. ///////////////////////////////////////////////////////////////////////////////////////////////
  353. // $img is an image that is already created within php using
  354. // imgcreatetruecolor. No url! $img must be a truecolor image.
  355. switch ($sharpeningsetting) {
  356. case 1: //light
  357. $amount= 15; //typically 50 - 200
  358. $radius= 0.3; //typically 0.5 - 1
  359. $threshold= 2; //typically 0 - 5
  360. break;
  361. case 2: //medium
  362. $amount= 30; //typically 50 - 200
  363. $radius= 0.3; //typically 0.5 - 1
  364. $threshold= 1; //typically 0 - 5
  365. break;
  366. case 3: //high
  367. $amount= 50; //typically 50 - 200
  368. $radius= 0.3; //typically 0.5 - 1
  369. $threshold= 3; //typically 0 - 5
  370. break;
  371. case 4: //ultra-high
  372. $amount= 70; //typically 50 - 200
  373. $radius= 0.3; //typically 0.5 - 1
  374. $threshold= 3; //typically 0 - 5
  375. break;
  376. }
  377. // Attempt to calibrate the parameters to Photoshop:
  378. if($amount > 500) $amount = 500;
  379. $amount = $amount * 0.016;
  380. if($radius > 50) $radius = 50;
  381. $radius = $radius * 2;
  382. if($threshold > 255) $threshold = 255;
  383. $radius = abs(round($radius)); // Only integers make sense.
  384. if($radius == 0) { return $img; imagedestroy($img); break; }
  385. $w = imagesx($img);
  386. $h = imagesy($img);
  387. $imgCanvas = imagecreatetruecolor($w, $h);
  388. $imgBlur = imagecreatetruecolor($w, $h);
  389. // Gaussian blur matrix:
  390. //
  391. // 1 2 1
  392. // 2 4 2
  393. // 1 2 1
  394. //
  395. //////////////////////////////////////////////////
  396. if(function_exists('imageconvolution')){ // PHP >= 5.1
  397. $matrix = array(
  398. array( 1, 2, 1 ),
  399. array( 2, 4, 2 ),
  400. array( 1, 2, 1 )
  401. );
  402. imagecopy ($imgBlur, $img, 0, 0, 0, 0, $w, $h);
  403. imageconvolution($imgBlur, $matrix, 16, 0);
  404. }else{
  405. // Move copies of the image around one pixel at the time and merge them with weight
  406. // according to the matrix. The same matrix is simply repeated for higher radii.
  407. for ($i = 0; $i < $radius; $i++) {
  408. imagecopy ($imgBlur, $img, 0, 0, 1, 0, $w - 1, $h); // left
  409. imagecopymerge ($imgBlur, $img, 1, 0, 0, 0, $w, $h, 50); // right
  410. imagecopymerge ($imgBlur, $img, 0, 0, 0, 0, $w, $h, 50); // center
  411. imagecopy ($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);
  412. imagecopymerge ($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 33.33333 ); // up
  413. imagecopymerge ($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 25); // down
  414. }
  415. }
  416. if($threshold>0){
  417. // Calculate the difference between the blurred pixels and the original
  418. // and set the pixels
  419. for ($x = 0; $x < $w-1; $x++) { // each row
  420. for ($y = 0; $y < $h; $y++) { // each pixel
  421. $rgbOrig = ImageColorAt($img, $x, $y);
  422. $rOrig = (($rgbOrig >> 16) & 0xFF);
  423. $gOrig = (($rgbOrig >> 8) & 0xFF);
  424. $bOrig = ($rgbOrig & 0xFF);
  425. $rgbBlur = ImageColorAt($imgBlur, $x, $y);
  426. $rBlur = (($rgbBlur >> 16) & 0xFF);
  427. $gBlur = (($rgbBlur >> 8) & 0xFF);
  428. $bBlur = ($rgbBlur & 0xFF);
  429. // When the masked pixels differ less from the original
  430. // than the threshold specifies, they are set to their original value.
  431. $rNew = (abs($rOrig - $rBlur) >= $threshold)
  432. ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig))
  433. : $rOrig;
  434. $gNew = (abs($gOrig - $gBlur) >= $threshold)
  435. ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig))
  436. : $gOrig;
  437. $bNew = (abs($bOrig - $bBlur) >= $threshold)
  438. ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig))
  439. : $bOrig;
  440. if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) {
  441. $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);
  442. ImageSetPixel($img, $x, $y, $pixCol);
  443. }
  444. }
  445. }
  446. }
  447. else{
  448. for ($x = 0; $x < $w; $x++) { // each row
  449. for ($y = 0; $y < $h; $y++) { // each pixel
  450. $rgbOrig = ImageColorAt($img, $x, $y);
  451. $rOrig = (($rgbOrig >> 16) & 0xFF);
  452. $gOrig = (($rgbOrig >> 8) & 0xFF);
  453. $bOrig = ($rgbOrig & 0xFF);
  454. $rgbBlur = ImageColorAt($imgBlur, $x, $y);
  455. $rBlur = (($rgbBlur >> 16) & 0xFF);
  456. $gBlur = (($rgbBlur >> 8) & 0xFF);
  457. $bBlur = ($rgbBlur & 0xFF);
  458. $rNew = ($amount * ($rOrig - $rBlur)) + $rOrig;
  459. if($rNew>255){$rNew=255;}
  460. elseif($rNew<0){$rNew=0;}
  461. $gNew = ($amount * ($gOrig - $gBlur)) + $gOrig;
  462. if($gNew>255){$gNew=255;}
  463. elseif($gNew<0){$gNew=0;}
  464. $bNew = ($amount * ($bOrig - $bBlur)) + $bOrig;
  465. if($bNew>255){$bNew=255;}
  466. elseif($bNew<0){$bNew=0;}
  467. $rgbNew = ($rNew << 16) + ($gNew <<8) + $bNew;
  468. ImageSetPixel($img, $x, $y, $rgbNew);
  469. }
  470. }
  471. }
  472. imagedestroy($imgCanvas);
  473. imagedestroy($imgBlur);
  474. return $img;
  475. }
  476. function sql_query($str)
  477. {
  478. $query = "$str";
  479. $result = mysql_query($query) || die(mysql_error());
  480. }
  481. function sql_array($str)
  482. {
  483. $query = mysql_query($str) or die( mysql_error());
  484. $row = mysql_fetch_array($query,MYSQL_BOTH);
  485. return $row;
  486. }
  487. function clean($str)
  488. {
  489. $str = addslashes($str);
  490. return $str;
  491. }
  492. function pullout($str)
  493. {
  494. $str = stripslashes($str);
  495. return $str;
  496. }
  497. function clean_url($str)
  498. {
  499. $url = EscapeShellCmd($str);
  500. return $str;
  501. }
  502. /**
  503. * UTF8 unserialize function
  504. *
  505. */
  506. function mb_unserialize($serial_str)
  507. {
  508. $serial_str = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $serial_str);
  509. return unserialize($serial_str);
  510. }
  511. /**
  512. * Book a visitor
  513. *
  514. */
  515. function book_visitor($str)
  516. {
  517. if(!isset($_COOKIE['lastvisit'])) // If the cookie 'lastvisit' is not set, count the person
  518. {
  519. global $cfgrow;
  520. $datetime = gmdate("Y-m-d H:i:s",gmdate("U")+(3600 * $cfgrow['timezone']));
  521. $host = $_SERVER['HTTP_HOST'];
  522. if(isset($_SERVER['HTTP_REFERER']))
  523. {
  524. $referer = addslashes($_SERVER['HTTP_REFERER']);
  525. $refererhost = parse_url($referer);
  526. $refererhost = $refererhost['host'];
  527. if($refererhost == $host)
  528. {
  529. $referer = "";
  530. }
  531. }
  532. else
  533. {
  534. $referer="";
  535. }
  536. $ua = addslashes($_SERVER['HTTP_USER_AGENT']);
  537. $ip = $_SERVER['REMOTE_ADDR'];
  538. $ruri = addslashes($_SERVER['REQUEST_URI']);
  539. $query = mysql_query("INSERT INTO `$str`(`id`,`datetime`,`host`,`referer`,`ua`,`ip`,`ruri`) VALUES (NULL,'$datetime','$host','$referer','$ua','$ip','$ruri')");
  540. }
  541. }
  542. /**
  543. * Start the database connection
  544. *
  545. */
  546. function start_mysql($config_file = 'includes/pixelpost.php', $request_uri = 'front')
  547. {
  548. global $pixelpost_db_host, $pixelpost_db_user, $pixelpost_db_pass, $pixelpost_db_pixelpost;
  549. $dir = 'templates';
  550. if(!file_exists($dir ."/splash_page.html"))
  551. {
  552. $dir = '../templates';
  553. }
  554. if(!file_exists($config_file))
  555. {
  556. show_splash("Connect DB Error: ". mysql_error()." Cause #1",$dir);
  557. }
  558. if(!mysql_connect($pixelpost_db_host, $pixelpost_db_user, $pixelpost_db_pass))
  559. {
  560. if($request_uri == 'admin')
  561. {
  562. header("Location: install.php?view=db_fix");
  563. exit;
  564. }
  565. else
  566. {
  567. show_splash("Connect DB Error: ". mysql_error()." Cause #2",$dir);
  568. }
  569. }
  570. if(!mysql_select_db($pixelpost_db_pixelpost))
  571. {
  572. if($request_uri == 'admin')
  573. {
  574. header("Location: install.php?view=db_fix");
  575. exit;
  576. }
  577. else
  578. {
  579. show_splash("Select DB Error: ". mysql_error()." Cause #2",$dir);
  580. }
  581. }
  582. }
  583. /**
  584. * Show splash screen
  585. *
  586. */
  587. function show_splash($extra_message,$splash_dir)
  588. {
  589. if(file_exists($splash_dir."/splash_page.html"))
  590. {
  591. $splash = file_get_contents($splash_dir.'/splash_page.html');
  592. $splash = ereg_replace("<ERROR_MESSAGE>",$extra_message,$splash);
  593. die($splash);
  594. }
  595. else
  596. {
  597. die($extra_message);
  598. }
  599. }
  600. /**
  601. * Reduce EXIF
  602. *
  603. */
  604. function &reduceExif($exifvalue)
  605. {
  606. $vals = split("/",$exifvalue);
  607. if(count($vals) == 2)
  608. {
  609. // MJS 29092005 - Code to deal with exposure times of > 1 sec
  610. if($vals[1] == 0)
  611. {
  612. $exposure = round($vals[0].$vals[1],2);
  613. }
  614. else
  615. {
  616. $exposure = round($vals[0]/$vals[1],2);
  617. if($exposure < 1)
  618. {
  619. $exposure = '1/'.round($vals[1]/$vals[0],0);
  620. }
  621. }
  622. }
  623. else $exposure = round($vals[0]/$vals[1], 2);
  624. return $exposure;
  625. }
  626. /**
  627. * Create categories HTML table
  628. *
  629. */
  630. function category_list_as_table($categories, $cfgrow)
  631. {
  632. global $pixelpost_db_prefix;
  633. if(!is_array($categories)){ $categories = array(); }
  634. // get the id and name of the first entered category, default category.
  635. $query = mysql_query("SELECT * FROM `".$pixelpost_db_prefix."categories` ORDER BY `id` ASC LIMIT 0,1");
  636. list($firstid,$firstname) = mysql_fetch_row($query);
  637. $getid = isset($_GET['id']);
  638. $getid = intval($getid);
  639. // begin of category-list as a table
  640. $x = 0;
  641. $query = mysql_query("SELECT t1.id, `name`, `alt_name`, `image_id` FROM `".$pixelpost_db_prefix."categories` AS t1 LEFT JOIN `".$pixelpost_db_prefix."catassoc` t2 ON t2.cat_id = t1.id AND t2.image_id = '$getid' ORDER BY t1.name");
  642. while(list($id,$name) = mysql_fetch_row($query))
  643. {
  644. echo "<table id='cattable'><tr>";
  645. $catcounter = 0;
  646. $query = mysql_query("SELECT t1.id, `name`, `alt_name`, `image_id` FROM `".$pixelpost_db_prefix."categories` AS t1 LEFT JOIN `".$pixelpost_db_prefix."catassoc` t2 ON t2.cat_id = t1.id AND t2.image_id = '$getid' ORDER BY t1.name");
  647. while(list($id,$name,$alt_name,$image_id) = mysql_fetch_row($query))
  648. {
  649. $name = pullout($name);
  650. $alt_name = ($cfgrow['altlangfile'] != 'Off') ? " (".pullout($alt_name).")" : null;
  651. $id = pullout($id);
  652. $catcounter++;
  653. $inarow = 4;
  654. if(($image_id != "" AND isset($_GET['view']) AND $_GET['view'] == 'images') || in_array($id,$categories))
  655. {
  656. echo "<td><input type='checkbox' CHECKED name='category[]' value='".$id."' id='cat".$x."'/>&nbsp;<label for='cat".$x."'>".$name.$alt_name."</label></td>";
  657. }
  658. else
  659. {
  660. //if($firstid == $id && $_GET['view']!='images') // if it is the first defualt category in the new_image page
  661. echo "<td><input type='checkbox' name='category[]' value='".$id."' id='cat".$x."'/>&nbsp;<label for='cat".$x."'>".$name.$alt_name."</label></td>";
  662. //else // if it is other categories in the new image page
  663. //echo "<td><input type='checkbox' name='category[]' value='".$id."' id='cat".$x."'/>&nbsp;<label for='cat".$x."'>".$name.$alt_name."</label></td>";
  664. }
  665. if($catcounter % $inarow == 0)
  666. {
  667. echo "\n</tr><tr>\n";
  668. }
  669. else
  670. {
  671. echo "\n";
  672. }
  673. $x++;
  674. }
  675. }
  676. if($catcounter % $inarow > 0){ echo "</tr>"; }
  677. echo "</table>\n\n";
  678. }
  679. /**
  680. * Refresh the addon table
  681. *
  682. */
  683. function refresh_addons_table($dir){
  684. add_new_addons_2table($dir);
  685. delete_obsolete_addon($dir);
  686. }
  687. /**
  688. * Add a new addon to the addons table
  689. *
  690. */
  691. function add_new_addons_2table($dir){
  692. global $pixelpost_db_prefix;
  693. $query = mysql_query("SELECT * FROM `".$pixelpost_db_prefix."addons` LIMIT 1");
  694. if($query){
  695. $str = '';
  696. if($handle = opendir($dir))
  697. {
  698. while(false !== ($file = readdir($handle)))
  699. {
  700. if($file != "." && $file != "..")
  701. {
  702. $ftype = '';
  703. if(is_dir($dir."/".$file))
  704. {
  705. $sub_dir = $file;
  706. if(substr($sub_dir, 0, 1)=="_")
  707. { // only suck in files from folders starting with a _
  708. // read through the files in this folder (only one level deep)
  709. if($handle_subdir = opendir($dir."/".$sub_dir))
  710. {
  711. while(false !== ($file_subdir = readdir($handle_subdir)))
  712. {
  713. if($file_subdir != "." && $file_subdir != "..")
  714. {
  715. $farry = explode('.', $file_subdir);
  716. reset($farry);
  717. $filename = current($farry);
  718. $filename_exp = explode('_', $filename);
  719. if(is_array($filename_exp)){ $filename_crnt = current($filename_exp); }
  720. $addontype = strtolower($filename_crnt);
  721. $farry_end = end($farry);
  722. $ftype = strtolower($farry_end);
  723. $filename = $sub_dir."/".$filename;
  724. }
  725. if($ftype == "php" AND !check_addon_exists($filename,$pixelpost_db_prefix))
  726. {
  727. switch (strtolower($addontype)){
  728. case "admin":
  729. $query = "INSERT INTO `{$pixelpost_db_prefix}addons` VALUES ( NULL, '$filename', 'off', '".strtolower($addontype)."')";
  730. break;
  731. case "front":
  732. $query = "INSERT INTO `{$pixelpost_db_prefix}addons` VALUES ( NULL, '$filename', 'off', '".strtolower($addontype)."')";
  733. break;
  734. default:
  735. $query = "INSERT INTO `{$pixelpost_db_prefix}addons` VALUES ( NULL, '$filename', 'off', 'normal')";
  736. break;
  737. }
  738. mysql_query($query);
  739. if(mysql_error()){ echo 'Failed to insert addon: ' .$filename .'.php'; }
  740. }
  741. }
  742. closedir($handle_subdir);
  743. }
  744. }
  745. }
  746. else
  747. {
  748. $farry = explode('.', $file);
  749. reset($farry);
  750. $filename = current($farry);
  751. $filename_exp = explode('_', $filename);
  752. if(is_array($filename_exp)){ $filename_crnt = current($filename_exp); }
  753. $addontype = strtolower($filename_crnt);
  754. $farry_end = end($farry);
  755. $ftype = strtolower($farry_end);
  756. }
  757. if($ftype == "php" AND !check_addon_exists($filename,$pixelpost_db_prefix))
  758. {
  759. switch (strtolower($addontype)){
  760. case "admin":
  761. $query = "INSERT INTO {$pixelpost_db_prefix}addons VALUES ( NULL, '$filename', 'off', '".strtolower($addontype)."')";
  762. break;
  763. case "front":
  764. $query = "INSERT INTO {$pixelpost_db_prefix}addons VALUES ( NULL, '$filename', 'off', '".strtolower($addontype)."')";
  765. break;
  766. default:
  767. $query = "INSERT INTO {$pixelpost_db_prefix}addons VALUES ( NULL, '$filename', 'off', 'normal')";
  768. break;
  769. }
  770. mysql_query( $query);
  771. if(mysql_error()){ echo 'Failed to insert addon: ' .$filename .'.php'; }
  772. }
  773. }
  774. }
  775. closedir($handle);
  776. }
  777. }
  778. }
  779. /**
  780. * Deletes the table row of the previously removed addon
  781. *
  782. */
  783. function delete_obsolete_addon($dir)
  784. {
  785. global $pixelpost_db_prefix;
  786. $query = mysql_query("SELECT * FROM `".$pixelpost_db_prefix."addons` LIMIT 1");
  787. if($query)
  788. {
  789. $query = mysql_query("SELECT `id`, `addon_name` FROM `".$pixelpost_db_prefix."addons`");
  790. while(@list($id, $addon_name) = mysql_fetch_row($query))
  791. {
  792. if(!file_exists($dir.$addon_name.'.php'))
  793. {
  794. mysql_query("DELETE FROM `".$pixelpost_db_prefix."addons` WHERE `id` = '$id'");
  795. if(mysql_error()){ echo 'Failed to delete the addon_name: '.$addon_name; }
  796. }
  797. }
  798. }
  799. }
  800. /**
  801. * Check existence of an addon in the addons table
  802. *
  803. */
  804. function check_addon_exists($name,$db_prefix)
  805. {
  806. $returnvalue = FALSE;
  807. $query = "select id from {$db_prefix}addons where addon_name='$name'";
  808. $query = mysql_query($query);
  809. while (list($id)= mysql_fetch_row($query))
  810. {
  811. if (is_numeric($id)) $returnvalue = TRUE;
  812. }
  813. return $returnvalue;
  814. }
  815. /**
  816. * Check existence of a table
  817. *
  818. */
  819. function is_table_created($table_name)
  820. {
  821. global $pixelpost_db_prefix;
  822. $query = mysql_query("SELECT `id` FROM `{$pixelpost_db_prefix}".$table_name."` LIMIT 1");
  823. if(!$query)
  824. {
  825. return false;
  826. }
  827. return true;
  828. }
  829. /**
  830. * Check if a field exists inside a table
  831. *
  832. */
  833. function is_field_exists($fieldname,$table)
  834. {
  835. global $pixelpost_db_prefix, $pixelpost_db_pixelpost, $table_name;
  836. $table = $pixelpost_db_prefix.$table;
  837. $fieldexists = FALSE;
  838. $t = 0;
  839. $attention_call = '';
  840. if($table != '')
  841. {
  842. $result_id = mysql_list_fields($pixelpost_db_pixelpost, $table);
  843. for($t = 0; $t < mysql_num_fields($result_id); $t++)
  844. {
  845. $msql_fname = mysql_field_name($result_id, $t);
  846. if(strtolower($fieldname) == strtolower($msql_fname))
  847. {
  848. $fieldexists = TRUE;
  849. break;
  850. }
  851. }
  852. }
  853. return $fieldexists;
  854. }
  855. //----------- for addons in admin panel
  856. /**
  857. * Add admin functions
  858. *
  859. */
  860. function add_admin_functions($function_name, $function_workspace,$function_menu ='' ,$function_submenu ='')
  861. {
  862. global $addon_admin_functions;
  863. $wrkspc_fcn = array('function_name' => $function_name,
  864. 'workspace' => $function_workspace,
  865. 'menu_name' => $function_menu,
  866. 'submenu_name' => $function_submenu
  867. );
  868. $c = count($addon_admin_functions);
  869. $end = array($c => $wrkspc_fcn);
  870. $addon_admin_functions = array_merge($addon_admin_functions, $end);
  871. }
  872. /**
  873. * Add front functions
  874. *
  875. */
  876. function add_front_functions($function_name, $function_workspace)
  877. {
  878. global $addon_front_functions;
  879. $wrkspc_fcn = array('function_name' => $function_name,
  880. 'workspace' => $function_workspace
  881. );
  882. $c = count($addon_front_functions);
  883. $end = array($c => $wrkspc_fcn);
  884. //var_dump($c);
  885. if($c > 0){
  886. $addon_front_functions = array_merge($addon_front_functions, $end);
  887. }
  888. }
  889. /**
  890. * Evaluates the admin workspace menu functions
  891. *
  892. */
  893. function eval_addon_admin_workspace_menu($workspace,$menu_name ='')
  894. {
  895. global $addon_admin_functions;
  896. for($i = 0 ; $i < count($addon_admin_functions) ; $i++)
  897. {
  898. $funcs = $addon_admin_functions[$i];
  899. $view_menu = $menu_name ."view";
  900. // if action is needed
  901. if ($funcs['workspace']== strtolower($workspace))
  902. {
  903. // if main menu
  904. if($funcs['workspace']=='admin_main_menu')
  905. {
  906. echo "<a href='".$_SERVER['PHP_SELF']."?view=".rawurlencode(strtolower($funcs['menu_name']))."'>".$funcs['menu_name']."</a>";
  907. continue;
  908. }
  909. // no menu
  910. if($menu_name == '')
  911. {
  912. if($funcs['workspace']=='admin_main_menu_contents' & isset($_GET['view']) AND $_GET['view']!=rawurldecode(strtolower($funcs['menu_name']))) continue;
  913. call_user_func ($funcs['function_name']);
  914. }
  915. else
  916. {
  917. if($_GET['view'] == strtolower($menu_name) && $_GET[$view_menu] == rawurldecode(strtolower($funcs['submenu_name'])))
  918. {
  919. call_user_func ($funcs['function_name']);
  920. }
  921. }
  922. }
  923. }
  924. }
  925. /**
  926. * Evaluates the front workspace functions
  927. *
  928. */
  929. function eval_addon_front_workspace($workspace)
  930. {
  931. global $addon_front_functions;
  932. for ($i = 0 ; $i < count($addon_front_functions) ; $i++)
  933. {
  934. $funcs = $addon_front_functions[$i];
  935. if($funcs['workspace']== strtolower($workspace))
  936. {
  937. call_user_func ($funcs['function_name']);
  938. }
  939. }
  940. }
  941. /**
  942. * Create the admin addon array
  943. *
  944. */
  945. function create_admin_addon_array()
  946. {
  947. global $addon_admin_functions, $pixelpost_db_prefix;
  948. if(isset($_GET['view']) AND $_GET['view'] != "addons" OR !isset($_GET['view']))
  949. {
  950. $addons = mysql_query("SELECT * FROM `{$pixelpost_db_prefix}addons` WHERE `status` = 'on' AND `type` = 'admin' ORDER BY `id` ASC");
  951. while(list($id, $filename, $status, $addon_type) = mysql_fetch_row($addons))
  952. {
  953. require_once(ADDON_DIR.$filename.'.php');
  954. }
  955. }
  956. }
  957. /**
  958. * Create the front addon array
  959. *
  960. */
  961. function create_front_addon_array()
  962. {
  963. global $addon_front_functions, $pixelpost_db_prefix;
  964. $query = mysql_query("SELECT * FROM `{$pixelpost_db_prefix}addons` WHERE `status` = 'on' AND `type` = 'front'");
  965. while(list($id, $filename, $status, $addon_type) = mysql_fetch_row($query))
  966. {
  967. include_once(ADDON_DIR.$filename.'.php');
  968. }
  969. }
  970. /**
  971. * Print the sub-menus title
  972. *
  973. */
  974. function echo_addon_admin_menus($addon_admin_menus,$menu_name,$additional = '')
  975. {
  976. for($i = 0 ; $i < count($addon_admin_menus) ; $i++)
  977. {
  978. $submenus = $addon_admin_menus[$i];
  979. if($submenus['menu_name'] == $menu_name)
  980. {
  981. $submenu_name = $submenus['submenu_name'];
  982. $menuitem = strtolower($menu_name).'view';
  983. $submenuitem = strtolower($submenu_name);
  984. $selecteclass = '';
  985. if(isset($_GET[$menuitem]) && ($_GET[$menuitem] == $submenuitem))
  986. {
  987. $selecteclass='selectedsubmenu';
  988. }
  989. $toecho ="|<a class='".$selecteclass."' href='?view=".rawurlencode(strtolower($menu_name)) ."&amp;".rawurlencode($menuitem) ."=".rawurlencode($submenuitem).$additional."' id='".$menu_name.str_replace(' ','_',$submenu_name)."'>" .strtoupper($submenu_name) ."</a>";
  990. echo $toecho;
  991. }
  992. }
  993. }
  994. /**
  995. * Count addon admin menus
  996. *
  997. */
  998. function count_addon_admin_menus($addon_admin_menus,$menu_name,$additional = '')
  999. {
  1000. $menu_items = 0;
  1001. for($i = 0 ; $i < count($addon_admin_menus) ; $i++)
  1002. {
  1003. $submenus = $addon_admin_menus[$i];
  1004. if($submenus['menu_name'] == $menu_name)
  1005. {
  1006. $menu_items=$menu_items+1;
  1007. }
  1008. }
  1009. return $menu_items;
  1010. }
  1011. //============================= TIMEZONE SECTION BEGINS ========================
  1012. /**
  1013. * Creates dropdown menu options of available timezones
  1014. *
  1015. */
  1016. function timezone_select()
  1017. {
  1018. global $tz_array, $cfgrow;
  1019. $default = ($cfgrow['timezone'] == '0') ? '0' : $cfgrow['timezone'];
  1020. $tz_select = '';
  1021. foreach($tz_array as $offset => $zone)
  1022. {
  1023. if(is_numeric($offset))
  1024. {
  1025. $selected = ($offset == $default) ? ' selected="selected"' : '';
  1026. $tz_select .= "<option value=\"$offset\"$selected>$zone</option>\n";
  1027. }
  1028. }
  1029. return $tz_select;
  1030. }
  1031. $tz_array = array('-12' => '[UTC - 12]',
  1032. '-11' => '[UTC - 11]',
  1033. '-10' => '[UTC - 10]',
  1034. '-9.5' => '[UTC - 9:30]',
  1035. '-9' => '[UTC - 9]',
  1036. '-8' => '[UTC - 8]',
  1037. '-7' => '[UTC - 7]',
  1038. '-6' => '[UTC - 6]',
  1039. '-5' => '[UTC - 5]',
  1040. '-4' => '[UTC - 4]',
  1041. '-3.5' => '[UTC - 3:30]',
  1042. '-3' => '[UTC - 3]',
  1043. '-2' => '[UTC - 2]',
  1044. '-1' => '[UTC - 1]',
  1045. '0' => '[UTC]',
  1046. '1' => '[UTC + 1]',
  1047. '2' => '[UTC + 2]',
  1048. '3' => '[UTC + 3]',
  1049. '3.5' => '[UTC + 3:30]',
  1050. '4' => '[UTC + 4]',
  1051. '4.5' => '[UTC + 4:30]',
  1052. '5' => '[UTC + 5]',
  1053. '5.5' => '[UTC + 5:30]',
  1054. '5.75' => '[UTC + 5:45]',
  1055. '6' => '[UTC + 6]',
  1056. '6.5' => '[UTC + 6:30]',
  1057. '7' => '[UTC + 7]',
  1058. '8' => '[UTC + 8]',
  1059. '8.75' => '[UTC + 8:45]',
  1060. '9' => '[UTC + 9]',
  1061. '9.5' => '[UTC + 9:30]',
  1062. '10' => '[UTC + 10]',
  1063. '10.5' => '[UTC + 10:30]',
  1064. '11' => '[UTC + 11]',
  1065. '11.5' => '[UTC + 11:30]',
  1066. '12' => '[UTC + 12]',
  1067. '12.75' => '[UTC + 12:45]',
  1068. '13' => '[UTC + 13]',
  1069. '14' => '[UTC + 14]'
  1070. );
  1071. //============================= TIMEZONE SECTION ENDS ========================
  1072. //============================= CONTROL SPAM SECTION BEGINS ========================
  1073. // Update the ban list if the form is called
  1074. function update_banlist()
  1075. {
  1076. global $pixelpost_db_prefix;
  1077. $result = '';
  1078. if(isset($_POST['banlistupdate']))
  1079. {
  1080. // moderation list
  1081. if(isset($_POST['moderation_list']))
  1082. {
  1083. $banlist = str_replace( "\r\n", "\n", $_POST['moderation_list']);
  1084. $banlist = str_replace( "\r", "\n", $banlist);
  1085. if(version_compare(phpversion(),"4.3.0")=="-1")
  1086. {
  1087. $banlist = mysql_escape_string($banlist);
  1088. }
  1089. else
  1090. {
  1091. $banlist = mysql_real_escape_string($banlist);
  1092. }
  1093. $query = "UPDATE `{$pixelpost_db_prefix}banlist` SET `moderation_list` = '$banlist' LIMIT 1";
  1094. mysql_query($query) ;
  1095. if(mysql_error()){ $result .= "$admin_lang_spam_err_2".mysql_error()."<br/>"; }
  1096. }
  1097. // black list
  1098. if(isset( $_POST['blacklist']))
  1099. {
  1100. $banlist = str_replace( "\r\n", "\n", $_POST['blacklist']);
  1101. $banlist = str_replace( "\r", "\n", $banlist);
  1102. if(version_compare(phpversion(),"4.3.0")=="-1")
  1103. {
  1104. $banlist = mysql_escape_string($banlist);
  1105. }
  1106. else
  1107. {
  1108. $banlist = mysql_real_escape_string($banlist);
  1109. }
  1110. $query = "UPDATE `{$pixelpost_db_prefix}banlist` SET `blacklist` = '$banlist' LIMIT 1";
  1111. mysql_query($query) ;
  1112. if(mysql_error()){ $result .= "$admin_lang_spam_err_3".mysql_error()."<br/>"; }
  1113. }
  1114. // referer ban list
  1115. if(isset($_POST['ref_ban_list']))
  1116. {
  1117. $banlist = str_replace( "\r\n", "\n", $_POST['ref_ban_list']);
  1118. $banlist = str_replace( "\r", "\n", $banlist);
  1119. if(version_compare(phpversion(), "4.3.0")=="-1")
  1120. {
  1121. $banlist = mysql_escape_string($banlist);
  1122. }
  1123. else
  1124. {
  1125. $banlist = mysql_real_escape_string($banlist);
  1126. }
  1127. $query = "UPDATE `{$pixelpost_db_prefix}banlist` SET `ref_ban_list` = '$banlist' LIMIT 1";
  1128. mysql_query($query) ;
  1129. if(mysql_error()){ $result .= "$admin_lang_spam_err_4 ".mysql_error()."<br/>"; }
  1130. }
  1131. // acceptable_num_links
  1132. if(isset($_POST['acceptable_num_links']))
  1133. {
  1134. $acceptable_num_links = clean($_POST['acceptable_num_links']);
  1135. $query = "UPDATE `{$pixelpost_db_prefix}banlist` SET `acceptable_num_links` = '$acceptable_num_links' LIMIT 1";
  1136. mysql_query($query) ;
  1137. if(mysql_error()){ $result .= "$admin_lang_spam_err_5 ".mysql_error()."<br/>"; }
  1138. }
  1139. if(!isset($result)) $result = "$admin_lang_spam_upd";
  1140. $result = $result."<br/>";
  1141. }
  1142. return $result;
  1143. }
  1144. function clean_banlists($p_value)
  1145. {
  1146. if(is_array($p_value))
  1147. {
  1148. if(count($p_value) == 0)
  1149. {
  1150. $p_value = null;
  1151. }
  1152. else
  1153. {
  1154. foreach($p_value as $m_key => $m_value)
  1155. {
  1156. $p_value[$m_key] = clean_banlists ($m_value);
  1157. if (empty ($p_value[$m_key])) unset ($p_value[$m_key]);
  1158. }
  1159. }
  1160. }
  1161. else
  1162. {
  1163. if(empty($p_value))
  1164. {
  1165. $p_value = null;
  1166. }
  1167. }
  1168. return $p_value;
  1169. }
  1170. /**
  1171. * Get the moderation list
  1172. *
  1173. */
  1174. function get_moderation_banlist()
  1175. {
  1176. global $pixelpost_db_prefix;
  1177. $query = mysql_query("SELECT `moderation_list` FROM `{$pixelpost_db_prefix}banlist` LIMIT 1")or die(mysql_error());
  1178. if($row = mysql_fetch_row($query)){ $banlist = $row[0]; }
  1179. $moderation_ban_list_array = split("[\n|\r]", $banlist);
  1180. $unique_moderation_ban_list_array = array_keys(array_flip($moderation_ban_list_array));
  1181. $cleaned_moderation_ban_list_array = clean_banlists ($unique_moderation_ban_list_array);
  1182. $banlist = implode("\n", $cleaned_moderation_ban_list_array);
  1183. if(count($moderation_ban_list_array) > count($cleaned_moderation_ban_list_array))
  1184. { //the list needs to be updated in the db.;
  1185. $_POST['banlistupdate'] = true;
  1186. $_POST['moderation_list'] = $banlist;
  1187. update_banlist();
  1188. unset($_POST['banlistupdate']);
  1189. unset($_POST['moderation_list']);
  1190. }
  1191. return $banlist;
  1192. }
  1193. /**
  1194. * Get the blacklist
  1195. *
  1196. */
  1197. function get_blacklist()
  1198. {
  1199. global $pixelpost_db_prefix;
  1200. $query = mysql_query("SELECT `blacklist` FROM `{$pixelpost_db_prefix}banlist` LIMIT 1")or die( mysql_error());
  1201. if($row = mysql_fetch_row($query)){ $banlist = $row[0]; }
  1202. $blacklist_array = split("[\n|\r]", $banlist);
  1203. $unique_blacklist_array = array_keys(array_flip($blacklist_array));
  1204. $cleaned_blacklist_array = clean_banlists ($unique_blacklist_array);
  1205. $banlist = implode("\n", $cleaned_blacklist_array);
  1206. if(count($blacklist_array) > count($cleaned_blacklist_array))
  1207. { //the list needs to be updated in the db.;
  1208. $_POST['banlistupdate'] = true;
  1209. $_POST['blacklist'] = $banlist;
  1210. update_banlist();
  1211. unset($_POST['banlistupdate']);
  1212. unset($_POST['blacklist']);
  1213. }
  1214. return $banlist;
  1215. }
  1216. /**
  1217. * Get the ref_ban_list
  1218. *
  1219. */
  1220. function get_ref_ban_list()
  1221. {
  1222. global $pixelpost_db_prefix;
  1223. $query = mysql_query("SELECT `ref_ban_list` FROM `{$pixelpost_db_prefix}banlist` LIMIT 1") or die( mysql_error());
  1224. if($row = mysql_fetch_row($query)){ $banlist = $row[0]; }
  1225. $ref_ban_list_array = split("[\n|\r]", $banlist);
  1226. $unique_ref_ban_list_array = array_keys(array_flip($ref_ban_list_array));
  1227. $cleaned_ref_ban_list_array = clean_banlists ($unique_ref_ban_list_array);
  1228. $banlist = implode("\n", $cleaned_ref_ban_list_array);
  1229. if (count($ref_ban_list_array) > count($cleaned_ref_ban_list_array))
  1230. { //the list needs to be updated in the db.;
  1231. $_POST['banlistupdate'] = true;
  1232. $_POST['ref_ban_list'] = $banlist;
  1233. update_banlist();
  1234. unset($_POST['banlistupdate']);
  1235. unset($_POST['ref_ban_list']);
  1236. }
  1237. return $banlist;
  1238. }
  1239. /**
  1240. * Prevent bad comments
  1241. *
  1242. */
  1243. function check_moderation_blacklist($cmnt_message,$cmnt_ip,$cmnt_name,$field)
  1244. {
  1245. global $pixelpost_db_prefix;
  1246. // help from wordpress codes
  1247. $query = mysql_query("SELECT `".$field."` FROM `{$pixelpost_db_prefix}banlist` LIMIT 1");
  1248. $bad_keys = mysql_fetch_array($query,MYSQL_ASSOC);
  1249. $words = explode("\n", $bad_keys[$field]);
  1250. foreach($words as $word)
  1251. {
  1252. $word = trim($word);
  1253. // Skip empty lines
  1254. if(empty($word)){ continue; }
  1255. // Do some escaping magic so that '#' chars in the
  1256. // spam words don't break things:
  1257. $word = preg_quote($word, '#');
  1258. $pattern = "#$word#i";
  1259. if(preg_match($pattern, $cmnt_message)){ return true; }
  1260. if(preg_match($pattern, $cmnt_ip)){ return true; }
  1261. if(preg_match($pattern, $cmnt_name)){ return true; }
  1262. /*
  1263. if( preg_match($pattern, $comment)){ return true; }
  1264. if( preg_match($pattern, $user_ip)){ return true; }
  1265. if( preg_match($pattern, $user_agent)){ return true; }
  1266. */
  1267. }
  1268. return false;
  1269. }
  1270. // is it in blacklist
  1271. function is_comment_in_blacklist($cmnt_message,$cmnt_ip,$cmnt_name)
  1272. {
  1273. return check_moderation_blacklist($cmnt_message,$cmnt_ip,$cmnt_name,'blacklist');
  1274. }
  1275. // is it in blacklist
  1276. function is_comment_in_moderation_list($cmnt_message,$cmnt_ip,$cmnt_name)
  1277. {
  1278. return check_moderation_blacklist($cmnt_message,$cmnt_ip,$cmnt_name,'moderation_list');
  1279. }
  1280. // Clean the ref list entry. No HTTP
  1281. function clean_reflist($entry)
  1282. {
  1283. $entry = explode('http://',$entry);
  1284. $entry = end($entry);
  1285. $entry = end(explode('https://',$entry));
  1286. return $entry;
  1287. }
  1288. // is ref list entry an IP?
  1289. function is_entry_ip($entry)
  1290. {
  1291. $entry = explode('.',$entry);
  1292. $entry = current($entry);
  1293. $entry = trim($entry);
  1294. return is_numeric($entry);
  1295. }
  1296. /**
  1297. * Create the .htaccess for copy paste
  1298. *
  1299. */
  1300. function create_htaccess_banlist()
  1301. {
  1302. $badreflist = "SetEnvIfNoCase Referer \".*(";
  1303. $ref_banlist = get_ref_ban_list();
  1304. $ref_banlist = explode("\n",$ref_banlist);
  1305. $denylist = '';
  1306. if(is_array($ref_banlist))
  1307. {
  1308. foreach($ref_banlist as $entry)
  1309. {
  1310. if($entry==''){ continue; }
  1311. $entry = trim($entry);
  1312. $entry = clean_reflist($entry);
  1313. if(is_entry_ip($entry))
  1314. {
  1315. $denylist .= "deny from " .$entry."\n";
  1316. }
  1317. else
  1318. {
  1319. $badreflist .= $entry."|";
  1320. }
  1321. }
  1322. }
  1323. else
  1324. {
  1325. $entry = trim($ref_banlist);
  1326. $entry = clean_reflist($entry);
  1327. if(is_entry_ip($entry))
  1328. {
  1329. $denylist .= "deny from " .$entry."\n";
  1330. }
  1331. else
  1332. {
  1333. $badreflist .= $entry."|";
  1334. }
  1335. }
  1336. $badreflist .="baccarat.host-c.com).*\" BadReferrer\norder deny,allow\n";
  1337. $badreflist .="deny from env=BadReferrer";
  1338. $to_htaccess = $denylist.$badreflist;
  1339. return $to_htaccess;
  1340. }
  1341. /**
  1342. * Compare the moderation list with comments
  1343. *
  1344. */
  1345. function moderate_past_with_list()
  1346. {
  1347. global $pixelpost_db_prefix, $admin_lang_spam_err_6, $admin_lang_spam_com_upd;
  1348. $additional_msg = '';
  1349. $where ='';
  1350. if(isset($_GET['antispamaction']) AND $_GET['antispamaction']=='moderation')
  1351. {
  1352. $banlist = get_moderation_banlist();
  1353. $banlist = str_replace( "\r\n", "\n",$banlist);
  1354. $banlist = str_replace( "\r", "\n", $banlist);
  1355. $banlist = explode("\n",$banlist);
  1356. if(is_array($banlist))
  1357. {
  1358. foreach($banlist as $entry)
  1359. {
  1360. if($entry==''){ continue; }
  1361. $entry = trim($entry);
  1362. $where .= " `message` LIKE '%{$entry}%' OR `name` LIKE '%{$entry}%' OR `ip` LIKE '%{$entry}%' OR ";
  1363. }
  1364. }
  1365. else
  1366. {
  1367. $entry = trim($ref_banlist);
  1368. $where .= " `message` LIKE '%{$entry}%' OR `name` LIKE '%{$entry}%' OR `ip` LIKE '%{$entry}%' OR ";
  1369. }
  1370. $where .= ' 0 ';
  1371. $query = "UPDATE `{$pixelpost_db_prefix}comments` SET `publish` = 'no' WHERE $where ";
  1372. mysql_query($query);
  1373. if(mysql_error())
  1374. {
  1375. $additional_msg = $admin_lang_spam_err_6.'&nbsp;'.mysql_error().'<br />';
  1376. }
  1377. else
  1378. {
  1379. $additional_msg = $admin_lang_spam_com_upd.'<br />';
  1380. }
  1381. }
  1382. $additional_msg = $additional_msg;
  1383. return $additional_msg;
  1384. }
  1385. /**
  1386. * Delete comments which contains words from the blacklist
  1387. *
  1388. */
  1389. function delete_past_with_list()
  1390. {
  1391. global $pixelpost_db_prefix, $admin_lang_spam_com_del, $admin_lang_spam_err_7;
  1392. $additional_msg = '';
  1393. $where ='';
  1394. if(isset($_GET['antispamaction']) AND $_GET['antispamaction']=='deletecmnt')
  1395. {
  1396. $banlist = get_blacklist();
  1397. $banlist = str_replace( "\r\n", "\n",$banlist);
  1398. $banlist = str_replace( "\r", "\n", $banlist);
  1399. $banlist = explode("\n",$banlist);
  1400. if(is_array($banlist))
  1401. {
  1402. foreach($banlist as $entry)
  1403. {
  1404. if($entry==''){ continue; }
  1405. $entry = trim($entry);
  1406. $where .= " `message` LIKE '%{$entry}%' OR `name` LIKE '%{$entry}%' OR `ip` LIKE '%{$entry}%' OR ";
  1407. }
  1408. }
  1409. else
  1410. {
  1411. $entry = trim($ref_banlist);
  1412. $where .= " `message` LIKE '%{$entry}%' OR `name` LIKE '%{$entry}%' OR `ip` LIKE '%{$entry}%' OR ";
  1413. }
  1414. $where .= ' 0 ';
  1415. $query = "DELETE FROM `{$pixelpost_db_prefix}comments` WHERE $where ";
  1416. mysql_query($query);
  1417. if(mysql_error())
  1418. {
  1419. $additional_msg = $admin_lang_spam_err_7.'&nbsp;'.mysql_error().'<br />';
  1420. }
  1421. else
  1422. {
  1423. $additional_msg = $admin_lang_spam_com_del.'<br />';
  1424. }
  1425. }
  1426. $additional_msg = $additional_msg;
  1427. return $additional_msg;
  1428. }
  1429. /**
  1430. * Delete refs that are listed in the ref ban list
  1431. *
  1432. */
  1433. function delete_from_badreferer_list()
  1434. {
  1435. global $pixelpost_db_prefix, $admin_lang_spam_err_8, $admin_lang_spam_visit_del;
  1436. $additional_msg = '';
  1437. $where ='';
  1438. if(isset($_GET['antispamaction']) AND $_GET['antispamaction']=='deleterefs')
  1439. {
  1440. $banlist = get_ref_ban_list();
  1441. $banlist = str_replace( "\r\n", "\n",$banlist);
  1442. $banlist = str_replace( "\r", "\n", $banlist);
  1443. $banlist = explode("\n",$banlist);
  1444. if(is_array($banlist))
  1445. {
  1446. foreach($banlist as $entry)
  1447. {
  1448. if($entry==''){ continue; }
  1449. $entry = trim($entry);
  1450. $where .= " `referer` LIKE '%{$entry}%' OR ";
  1451. }// end for each
  1452. }
  1453. else
  1454. {
  1455. $entry = trim($ref_banlist);
  1456. $where .= " `referer` LIKE '%{$entry}%' OR ";
  1457. }
  1458. $where .= ' 0 ';
  1459. $query = "DELETE FROM `{$pixelpost_db_prefix}visitors` WHERE $where ";
  1460. mysql_query($query);
  1461. if(mysql_error())
  1462. {
  1463. $additional_msg = $admin_lang_spam_err_8.'&nbsp;'.mysql_error().'<br />';
  1464. }
  1465. else
  1466. {
  1467. $additional_msg = $admin_lang_spam_visit_del.'<br />';
  1468. }
  1469. }
  1470. $additional_msg = $additional_msg;
  1471. return $additional_msg;
  1472. }
  1473. //============================= ANTI SPAM SECTION ENDS ========================
  1474. function clean_comment($string)
  1475. {
  1476. $string = strip_tags($string);
  1477. $string = htmlspecialchars($string,ENT_QUOTES);
  1478. $string = addslashes($string);
  1479. return $string;
  1480. }
  1481. //=============================== TAGS SECTION BEGINS ===========================
  1482. function save_tags_new($tags_str,$theid,$alt = '')
  1483. {
  1484. global $pixelpost_db_prefix;
  1485. if(strlen($tags_str) > 0)
  1486. {
  1487. $strtr_arr = array(',' => ' ', ';' => ' ');
  1488. $tags = strtr($tags_str, $strtr_arr);
  1489. $pat1 = '/([^a-zA-Z 0-9_-\pL]+)/u';
  1490. $pat2 = '/([^a-zA-Z 0-9_-]+)/';
  1491. $tags_org = $tags;
  1492. if(($tags = preg_replace($pat1, '_', $tags)) === NULL){ $tags = preg_replace($pat2, '_', $tags_org); }
  1493. $pat2 = array('/ _ /', '/ _/', '/(_){2,}/','/ - /', '/ -/', '/(-){2,}/');
  1494. $rep2 = array('', '', '_', '', '', '-');
  1495. $tags = preg_replace( $pat2, $rep2, $tags);
  1496. $tags_arr = preg_split('/[ ]{1,}/',$tags,-1,PREG_SPLIT_NO_EMPTY);
  1497. $query_val = array();
  1498. foreach($tags_arr as $val)
  1499. {
  1500. $query_val[] = "( " . $theid . ",'" . $val . "')";
  1501. }
  1502. $sql_tag = mysql_query("INSERT INTO `".$pixelpost_db_prefix."tags` (img_id, ".$alt."tag) VALUES ".implode(",", $query_val)."");
  1503. }
  1504. }
  1505. function list_tags_edit($id,$alt = '')
  1506. {
  1507. global $pixelpost_db_prefix;
  1508. $tags = '';
  1509. $query = mysql_query("SELECT `".$alt."tag` FROM `".$pixelpost_db_prefix."tags` WHERE `img_id` = ".$id." AND `".$alt."tag` NOT LIKE '' ORDER BY `".$alt."tag` ASC");
  1510. while(list($tag) = mysql_fetch_row($query))
  1511. {
  1512. $tags .= ' '.$tag;
  1513. }
  1514. return trim($tags);
  1515. }
  1516. function del_tags_edit($id,$alt = '')
  1517. {
  1518. global $pixelpost_db_prefix;
  1519. mysql_query("DELETE FROM `".$pixelpost_db_prefix."tags` WHERE `img_id` = ".$id." AND `".$alt."tag` NOT LIKE ''");
  1520. }
  1521. function save_tags_edit($tags_str,$id,$alt = '')
  1522. {
  1523. global $pixelpost_db_prefix;
  1524. del_tags_edit($id, $alt);
  1525. save_tags_new($tags_str, $id, $alt);
  1526. }
  1527. //
  1528. //=============================== TAGS SECTION ENDS =============================
  1529. //============================= LANGUAGE SECTION BEGINS =========================
  1530. function create_language_url_from_tag($language_link_abr, $language_link_full)
  1531. {
  1532. // changing $_SERVER['argv'] to $_SERVER['QUERY_STRING'], because argv may be not "on"
  1533. if(($_SERVER['QUERY_STRING'] == "") OR (substr($_SERVER['QUERY_STRING'],0,5)=="lang="))
  1534. {
  1535. $language_link="<a href='".$_SERVER['PHP_SELF']."?lang=".strtolower( $language_link_abr)."'>".$language_link_full."</a>";
  1536. }
  1537. else
  1538. {
  1539. // removed &lang=XX from query string, otherways it is added which each language change
  1540. $arguments=preg_replace('/\&lang=\w{2}/', '',$_SERVER['QUERY_STRING']);
  1541. $arguments=str_replace("&","&amp;", $arguments);
  1542. $language_link="<a href='".$_SERVER['PHP_SELF']."?".$arguments."&amp;lang=".strtolower( $language_link_abr)."'>".$language_link_full."</a>";
  1543. }
  1544. return $language_link;
  1545. }
  1546. function replace_alt_lang_tags( $tpl, $language_abr, $PP_supp_lang, $cfgrow)
  1547. {
  1548. global $lang_alt_lang_dutch,$lang_alt_lang_english,$lang_alt_lang_french,$lang_alt_lang_german;
  1549. global $lang_alt_lang_italian,$lang_alt_lang_norwegian,$lang_alt_lang_persian,$lang_alt_lang_polish;
  1550. global $lang_alt_lang_portuguese,$lang_alt_lang_simplified_chinese,$lang_alt_lang_spanish,$lang_alt_lang_swedish;
  1551. $default_language_abr = strtolower($PP_supp_lang[$cfgrow['langfile']][0]);
  1552. $alt_language_abr = strtolower($PP_supp_lang[$cfgrow['altlangfile']][0]);
  1553. $link_language_abr = ($language_abr == $default_language_abr) ? $alt_language_abr : $default_language_abr;
  1554. // Determine the full name of the link_language
  1555. foreach ($PP_supp_lang as $key => $row)
  1556. {
  1557. foreach($row as $cell)
  1558. {
  1559. if($cell == strtoupper($link_language_abr)){ $language_link_key = $key; }
  1560. }
  1561. }
  1562. $language_link_name = "lang_alt_lang_".$language_link_key;
  1563. $language_link_full = ${$language_link_name};
  1564. $language_link = create_language_url_from_tag($link_language_abr, $language_link_full);
  1565. // Create one template tag for all templates and both languages
  1566. $tpl = str_replace("<ALTERNATIVE_LANGUAGE>",$language_link,$tpl);
  1567. // support for <LANGUAGE=XX> TAG
  1568. preg_match_all("/<(\s*language\s*=\s*([^<>\s]*)\s*)>/iU", $tpl, $matches);
  1569. for($i = 0; $i < count($matches[0]); $i++)
  1570. {
  1571. foreach($PP_supp_lang as $key => $row)
  1572. {
  1573. foreach($row as $cell)
  1574. {
  1575. if($cell == strtoupper($matches[2][$i])){ $language_link_key = $key; }
  1576. }
  1577. }
  1578. $alt_language_link=create_language_url_from_tag( $matches[2][$i],$PP_supp_lang[$language_link_key][1]);
  1579. $tpl = str_replace("<LANGUAGE=".$matches[2][$i].">",$alt_language_link,$tpl);
  1580. }
  1581. // return the template
  1582. return $tpl;
  1583. }
  1584. function translation_data()
  1585. {
  1586. global $admin_lang_pp_lng_fname, $admin_lang_pp_lng_author, $admin_lang_pp_lng_ver, $admin_lang_pp_lng_email;
  1587. $d = dir("../language");
  1588. $dir_con = array();
  1589. while(false !== ($entry = $d->read()))
  1590. {
  1591. ($entry != '.' && $entry != '..') ? $dir_con[] = $entry : '';
  1592. }
  1593. $d->close();
  1594. sort($dir_con);
  1595. $out = '<table border="0" cellspacing="5">
  1596. <tr>
  1597. <td><b>'.$admin_lang_pp_lng_fname.'</b></td>
  1598. <td><b>'.$adm…

Large files files are truncated, but you can click here to view the full file