PageRenderTime 54ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/RosterGallery/inc/functions.php

http://wowroster-addons.googlecode.com/
PHP | 1161 lines | 962 code | 135 blank | 64 comment | 99 complexity | 97f88082694473ba8a7e0d0b80502e3c MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. class ssconfig
  3. {
  4. //global $wordings;
  5. var $message;
  6. var $message2;
  7. var $message3;
  8. var $sql_debug;
  9. var $id;
  10. var $min;
  11. var $max;
  12. var $c;
  13. function setSqlDebug( $message )
  14. {
  15. $this->sql_debug .= "$message\n";
  16. }
  17. function emptyMessage()
  18. {
  19. $this->message = "";
  20. }
  21. function setMessage( $message )
  22. {
  23. $this->message .= "$message\n";
  24. }
  25. function setAdminMessage( $message3 )
  26. {
  27. $this->message3 .= "$message3\n";
  28. }
  29. function getvars( $varname )
  30. {
  31. $var = NULL;
  32. if ( isset($HTTP_GET_VARS[$varname]) != '')
  33. {
  34. $var = $HTTP_GET_VARS[$varname];
  35. }
  36. else if ( isset($_GET[$varname]) != '')
  37. {
  38. $var = $_GET[$varname];
  39. }
  40. return $var;
  41. }
  42. function checkDir( $dir , $check=0 , $chmod=0 )
  43. {
  44. // See if it exists
  45. if( file_exists(ROSTER_BASE.$dir) )
  46. {
  47. if( $check )
  48. {
  49. if( !is_writable(ROSTER_BASE.$dir) )
  50. {
  51. if( $chmod )
  52. {
  53. if( chmod( ROSTER_BASE.$dir,0777 ) )
  54. return TRUE;
  55. else
  56. return FALSE;
  57. }
  58. else
  59. return FALSE;
  60. }
  61. }
  62. return TRUE;
  63. }
  64. }
  65. #
  66. # end of dir structire
  67. #
  68. function checkDirst( $ssfolder, $check=0, $chmod=0 )
  69. { global $roster, $addon;
  70. $ft=0;
  71. foreach( $ssfolder as $dir )
  72. {
  73. // See if it exists
  74. if( file_exists($addon['dir'].$dir) )
  75. {
  76. if( $check )
  77. {
  78. if( !is_writable($addon['dir'].$dir) )
  79. {
  80. if( $chmod )
  81. {
  82. if( chmod( $addon['dir'].$dir,0777 ) ){
  83. return TRUE;
  84. }
  85. else
  86. {
  87. return FALSE;
  88. }
  89. }
  90. else
  91. {
  92. return FALSE;
  93. }
  94. }
  95. return TRUE;
  96. }
  97. $ft = ( $ft + 1 );
  98. //echo "".$dir." Present<br>";
  99. }
  100. else
  101. {
  102. //echo "".$dir." Not Present<br>";
  103. }
  104. }
  105. //echo $ft;
  106. return $ft;
  107. }
  108. #
  109. # end of dir structire
  110. #
  111. function makesubDir( $ssfolder )
  112. {
  113. foreach( $ssfolder as $dir )
  114. {
  115. // See if it exists
  116. if( !file_exists($dir) )
  117. {
  118. if( mkdir($dir) )
  119. {
  120. chmod( $dir,0777 );
  121. $this->setinstallMessage("Screenshot folder '".$dir."' created");
  122. }
  123. }
  124. else
  125. {
  126. $this->setinstallMessage("Could not create Screenshot folder ".$dir." or it exists");
  127. }
  128. }
  129. }
  130. function makeDir( $dir )
  131. {
  132. if( mkdir($dir) )
  133. {
  134. chmod( $dir,0777 );
  135. $this->setinstallMessage("Screenshot folder created");
  136. return TRUE;
  137. }
  138. else
  139. {
  140. $this->setinstallMessage("Could not create Screenshot folder");
  141. return FALSE;
  142. }
  143. }
  144. /**
  145. * Get the Messages
  146. *
  147. * @return string | Full HTML table with messages
  148. */
  149. function getconfig(){
  150. global $wowdb;
  151. }
  152. function getMessage()
  153. {
  154. global $roster, $addon;
  155. $message = $this->message;
  156. $output = '';
  157. if( !empty($message) )
  158. {
  159. // Replace newline feeds with <br />, then newline
  160. $messageArr = explode("\n",$message);
  161. $row=0;
  162. foreach( $messageArr as $line )
  163. {
  164. if( $line != '' )
  165. {
  166. $output .= ''.$line.'<BR>';
  167. }
  168. }
  169. return $output;
  170. }
  171. else
  172. {
  173. return '';
  174. }
  175. }
  176. function getAdminMessage()
  177. {
  178. global $roster, $addon;
  179. $message = $this->message3;
  180. if( !empty($message) )
  181. {
  182. // Replace newline feeds with <br />, then newline
  183. $messageArr = explode("\n",$message);
  184. $row=0;
  185. foreach( $messageArr as $line )
  186. {
  187. if( $line != '' )
  188. {
  189. $output .= ''.$line.'<BR>';
  190. }
  191. }
  192. return $output;
  193. }
  194. else
  195. {
  196. return '';
  197. }
  198. }
  199. // new function for voting
  200. function vote( $id, $vote ){
  201. global $roster;
  202. $query = "SELECT * FROM `".ROSTER_SCREENTABLE."` WHERE `id` ='".$id."'";
  203. $result = $roster->db->query($query) or die_quietly($roster->db->error(),'Database Error',basename(__FILE__),__LINE__,$query);
  204. $row = $roster->db->fetch($result);
  205. $count = ( $row['votes'] + 1);
  206. $rate = ( $row['rateing'] + $vote );
  207. $query1 = "UPDATE `".ROSTER_SCREENTABLE."` SET `votes` = '".$count."' , `rateing` = '".$rate."' WHERE `id` ='".$id."'";
  208. $result1 = $roster->db->query($query1) or die_quietly($roster->db->error(),'Database Error',basename(__FILE__),__LINE__,$query1);
  209. //$row = $wowdb->fetch_array($result);
  210. if ($result1){
  211. $this->setMessage( '<span class="green"> Vote Accepted! </span>' );
  212. }
  213. }
  214. // end new function
  215. /*
  216. Change catagory function for admin section error function "CC"
  217. */
  218. function changecat($id, $new, $old, $addon_cfg, $file, $path){
  219. global $roster, $addon;
  220. $old_path = $path.''.$old.'/'.$file;
  221. $new_path = $path.''.$new.'/'.$file;
  222. if (file_exists($old_path))
  223. {
  224. if (!file_exists($new_path))
  225. {
  226. if (copy ($old_path, $new_path))
  227. {
  228. unlink ($old_path);
  229. }
  230. }
  231. else
  232. {
  233. $this->setMessage( '<span class="red">ERROR RG:001-CC - Selected dir "'.$new_path.'" does not exist</span>' );
  234. }
  235. }
  236. else
  237. {
  238. $this->setMessage( '<span class="red">ERROR RG:001-CC - Selected dir "'.$old_path.'" does not exist</span>' );
  239. }
  240. $query = "UPDATE `".ROSTER_SCREENTABLE."` SET `catagory` = '".$new."' WHERE `id` = '".$id."'";
  241. $result = $roster->db->query($query) or die_quietly($roster->db->error(),'Database Error',basename(__FILE__),__LINE__,$query);
  242. $this->setMessage( '<span class="green">Image with ID '.$id.' has been changed from Catagory ['.$addon_cfg['rg_'.$old.''].'] to ['.$addon_cfg['rg_'.$new.''].']</span>' );
  243. }
  244. function approvesc( $approve ){
  245. global $roster, $addon;
  246. $query = "UPDATE `".ROSTER_SCREENTABLE."` SET `approve` = 'YES' WHERE `id` ='".$approve."'";
  247. $result = $roster->db->query($query) or die_quietly($roster->db->error(),'Database Error',basename(__FILE__),__LINE__,$query);
  248. $this->setMessage( '<span class="green">Image with ID '.$approve.' is now Approved</span>' );
  249. }
  250. /*
  251. delete screenshoot function
  252. error = DS
  253. */
  254. function deletesc( $delete ){
  255. global $roster, $addon;
  256. $query5 = "SELECT * FROM `".ROSTER_SCREENTABLE."` WHERE id='".$delete."' ";
  257. $result5 = $roster->db->query($query5) or die_quietly($roster->db->error(),'Database Error',basename(__FILE__),__LINE__,$query5);
  258. $row = $roster->db->fetch($result5);
  259. //any other code tidbits here, error pages etc
  260. $roster->db->query("DELETE FROM `".ROSTER_SCREENTABLE."` WHERE id='$delete' ");
  261. $dir = "screenshots/";
  262. $filename = $row['catagory']."/".$row['file'].'.'.$row['ext'];
  263. $filename2 = "thumbs/".$row['file'].'-thumb.'.$row['ext'];
  264. if( empty($delete) )
  265. {
  266. $this->setMessage( 'Please select an image to delete' );
  267. return FALSE;
  268. }
  269. else
  270. {
  271. if( file_exists($dir.$filename) )
  272. {
  273. if( unlink($dir.$filename) && unlink($dir.$filename2))
  274. {
  275. $this->setMessage( '<span class="green">'.$filename.' & '.$filename2.'</span>: <span class="red">Deleted</span>' );
  276. return TRUE;
  277. }
  278. else
  279. {
  280. $this->setMessage( '<span class="red">ERROR RG:002-DS - '.str_replace( '\\','/',$dir ).$filename.': Could not be deleted</span>' );
  281. return FALSE;
  282. }
  283. }
  284. else
  285. {
  286. $this->setMessage( '<span class="red">ERROR RG:001-DS - '.$dir.$filename.' Does not exist Cannot Delete</span>' );
  287. }
  288. }
  289. }
  290. function uploadwmImage( $dir, $filename){
  291. global $roster, $addon;
  292. $target_path = $dir."/".basename( $_FILES['wmfile']['name']);
  293. if(move_uploaded_file($_FILES['wmfile']['tmp_name'], $target_path)) {
  294. $this->setMessage("The file ".basename( $_FILES['wmfile']['name'])." has been uploaded <br> To the Watermark Directory");
  295. }else{
  296. $this->setMessage("Your uploaded was unseccessful<BR>");
  297. exit;
  298. }
  299. }
  300. function uploadImage( $dir , $filename, $caption, $catagory, $desc, $width ,$height, $wm_loc, $wm_use, $wm_file, $wm_dir, $table, $size )
  301. { global $roster, $addon;
  302. $frame3 = $addon['dir'].$wm_dir.'/frame_layer_3.png';
  303. $tempg = $addon['dir'].$wm_dir.'/temp.gif';
  304. $tempg2 = $addon['dir'].$wm_dir.'/temp2.gif';
  305. $tempj = $addon['dir'].$wm_dir.'/temp.jpg';
  306. $tempj2 = $addon['dir'].$wm_dir.'/temp2.jpg';
  307. $tempp = $addon['dir'].$wm_dir.'/temp.png';
  308. $tempp2 = $addon['dir'].$wm_dir.'/temp2.png';
  309. $fname = '';
  310. $extension = '';
  311. $upfilename = '';
  312. $extension = substr($filename, strrpos($filename, '.')+1);
  313. $target_path = $dir.$catagory."/";
  314. $sql = "SELECT * FROM `".$table."` ORDER BY `id` DESC LIMIT 0 , 1";
  315. $result = $roster->db->query($sql);// or die_quietly($roster->db->error(),'Database Error',basename(__FILE__),__LINE__,$sql);
  316. $pict = $roster->db->fetch($result);
  317. list($name, $num) = explode("ss", $pict['file']);
  318. $fname ="ss".($num + 1);
  319. $uploadcompleate = null;
  320. $target_path = $target_path . basename( $fname.".".$extension );
  321. $fileloc = $dir.$catagory."/". basename( $fname );
  322. $upfilename = $fname.".".$extension;
  323. $sizea = (filesize($_FILES['userfile']['tmp_name']) / 1024);
  324. if (filesize($sizea) <= $size ){
  325. if ($extension == "jpg" OR $extension == "gif" OR $extension == "JPG" OR $extension == "GIF" OR $extension == "jpeg" OR $extension == "JPEG")
  326. {
  327. if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) {
  328. $sql2 = "INSERT INTO `".$table."` ( `id` , `file` , `caption` , `disc` , `ext`, `catagory`, `approve` ) VALUES ( NULL , '".$fname."', '".$caption."', '".$desc."' , '".$extension."', '".$catagory."', '');";
  329. $result2 = $roster->db->query($sql2) or die_quietly($roster->db->error(),'Database Error',basename(__FILE__),__LINE__,$sql2);
  330. ///////// Start the thumbnail generation//////////////
  331. $n_width= $width; // Fix the width of the thumb nail images
  332. $n_height= $height; // Fix the height of the thumb nail imaage
  333. # Path of the Origional Uploaded image
  334. $tsrc1 = $dir.$catagory.'/'.$fname.".".$extension;
  335. # Path where thumb nail image will be stored
  336. $tsrc= $dir.'/thumbs/'.$fname."-thumb.".$extension;
  337. #///////////////////////////////// Starting of GIF thumb nail creation///////////
  338. if (@$extension=="gif" OR $extension=="GIF")
  339. {
  340. $im=ImageCreateFromGIF($tsrc1);
  341. $frame4=ImageCreateFromPNG($frame3);
  342. $width=ImageSx($im); // Original picture width is stored
  343. $height=ImageSy($im); // Original picture height is stored
  344. $width1=ImageSx($frame4); // Original picture width is stored
  345. $height1=ImageSy($frame4); // Original picture height is stored
  346. //create new blank image
  347. $newimage=$this->imagecreatetruecolortrans($n_width, $n_height);
  348. //create new blank image for the border
  349. $frame5=$this->imagecreatetruecolortrans($n_width, $n_height);
  350. //resise the screenshot to the new size -6px for the border
  351. imageCopyResized($newimage,$im,0,0,0,0,($n_width - 6),($n_height - 6),$width,$height);
  352. // resize the border to fit the screenshot
  353. imageCopyResized($frame5,$frame4,0,0,0,0,$n_width,$n_height,$width1,$height1);
  354. // add a water mark to the screenshoot
  355. $oldimage = $this->addwatermark($im, $wm_loc, $wm_use, $wm_file, $wm_dir);
  356. // create a temp image to continue the process
  357. imageGIF($newimage,$tempg);
  358. // create temp image of the border
  359. imagePNG($frame5,$tempg2);
  360. // add the border
  361. $im2 = $this->addborderimg($tempg,$tempg2,$n_height, $n_width);
  362. //watermark the origional image
  363. $im2 = $this->addwatermark($im2, $wm_loc, $wm_use, $wm_file, $wm_dir);
  364. // create the screen shoot image
  365. imageGIF($im2,$tsrc);
  366. // save the origional image
  367. imageGIF($oldimage,$tsrc1);
  368. }
  369. if($extension=="jpg" OR $extension=="jpeg" OR $extension=="JPEG" OR $extension=="JPG")
  370. {
  371. $im=ImageCreateFromJPEG($tsrc1);
  372. $frame4=ImageCreateFromPNG($frame3);
  373. $width=ImageSx($im); // Original picture width is stored
  374. $height=ImageSy($im); // Original picture height is stored
  375. $width1=ImageSx($frame4); // Original picture width is stored
  376. $height1=ImageSy($frame4); // Original picture height is stored
  377. //create new blank image
  378. $newimage=$this->imagecreatetruecolortrans($n_width, $n_height);
  379. //create new blank image for the border
  380. $frame5=$this->imagecreatetruecolortrans($n_width, $n_height);
  381. //resise the screenshot to the new size -6px for the border
  382. imageCopyResized($newimage,$im,0,0,0,0,($n_width - 6),($n_height - 6),$width,$height);
  383. // resize the border to fit the screenshot
  384. imageCopyResized($frame5,$frame4,0,0,0,0,$n_width,$n_height,$width1,$height1);
  385. // add a water mark to the screenshoot
  386. $oldimage = $this->addwatermark($im, $wm_loc, $wm_use, $wm_file, $wm_dir);
  387. // create a temp image to continue the process
  388. imageJPEG($newimage,$tempj);
  389. //create tempimage of the border
  390. imagePNG($frame5,$tempj2);
  391. // add the border
  392. $im2 = $this->addborderimg($tempj,$tempj2,$n_height, $n_width);
  393. //watermark the origional image
  394. $im2 = $this->addwatermark($im2, $wm_loc, $wm_use, $wm_file, $wm_dir);
  395. // create the screen shoot image
  396. imageJPEG($im2,$tsrc);
  397. // save the origional image
  398. imageJPEG($oldimage,$tsrc1);
  399. }
  400. if($extension=="png" OR $extension=="PNG"){
  401. $im=ImageCreateFromPNG($tsrc1);
  402. $frame4=ImageCreateFromPNG($frame3);
  403. $width=ImageSx($im); // Original picture width is stored
  404. $height=ImageSy($im); // Original picture height is stored
  405. $width1=ImageSx($frame4); // Original picture width is stored
  406. $height1=ImageSy($frame4); // Original picture height is stored
  407. //create new blank image
  408. $newimage=$this->imagecreatetruecolortrans($n_width, $n_height);
  409. //create new blank image for the border
  410. $frame5=$this->imagecreatetruecolortrans($n_width, $n_height);
  411. //resise the screenshot to the new size -6px for the border
  412. imageCopyResized($newimage,$im,0,0,0,0,($n_width - 6),($n_height - 6),$width,$height);
  413. // resize the border to fit the screenshot
  414. imageCopyResized($frame5,$frame4,0,0,0,0,$n_width,$n_height,$width1,$height1);
  415. // add a water mark to the screenshoot
  416. $oldimage = $this->addwatermark($im, $wm_loc, $wm_use, $wm_file, $wm_dir);
  417. // create a temp image to continue the process
  418. imagePNG($newimage,$tempp);
  419. //create tempimage of the border
  420. imagePNG($frame5,$tempp2);
  421. // add the border
  422. $im2 = $this->addborderimg($tempp,$tempp2,$n_height, $n_width);
  423. //watermark the origional image
  424. $im2 = $this->addwatermark($im2, $wm_loc, $wm_use, $wm_file, $wm_dir);
  425. // create the screen shoot image
  426. imagePNG($im2,$tsrc);
  427. // save the origional image
  428. imagePNG($oldimage,$tsrc1);
  429. }
  430. chmod("$tsrc",0777);
  431. $uploadcompleate = True;
  432. }
  433. else
  434. {
  435. $this->setMessage("File could not be uploaded to \"".$target_path."\" Check chmod of file path");
  436. }
  437. }
  438. else
  439. {
  440. $this->setMessage('<span class="red">ERROR RG:002-UP - Your uploaded file "'.$_FILES['userfile']['name'].'" must be (jpg gif png). Other file types are not allowed</span>');
  441. }
  442. if (!$uploadcompleate)
  443. {
  444. $this->setMessage('<span class="red">ERROR RG:002-UP - Your uploaded file "'.$_FILES['userfile']['name'].'" must be (jpg gif png). Other file types are not allowed</span>');
  445. }
  446. if ($uploadcompleate){
  447. $this->setMessage("The file ".basename( $_FILES['userfile']['name'])." has been uploaded as ".$upfilename." - Pending admin approval");
  448. }
  449. }
  450. else
  451. {
  452. $this->setMessage('<span class="red">ERROR RG:001-UP - The file '.basename( $_FILES['userfile']['name']).' is to large must be '.$size.'kb or less</span>');
  453. }
  454. }
  455. #
  456. ##########################################################################################################
  457. #
  458. # This is where the new Border system starts
  459. #
  460. # Adds a border to the image like the blizzard image gallory lol yoink!!!
  461. #
  462. function addborderimg($temp,$frame3,$width ,$height){
  463. $im2 = $this->imagecreatetruecolortrans( $height,$width ) or die('Cannot Initialize new GD image stream');
  464. // sould combine the blank image and frame 1
  465. if( file_exists($temp) )
  466. {
  467. $this->combineImage( $im2,$temp,(__LINE__),3,3 );
  468. }
  469. if( file_exists($frame3) )
  470. {
  471. $this->combineImage( $im2,$frame3,(__LINE__),0,0 );
  472. }
  473. return $im2;
  474. }
  475. function imagecreatetruecolortrans($x,$y)
  476. {
  477. $i = @imagecreatetruecolor($x,$y)
  478. or debugMode( (__LINE__),'Cannot Initialize new GD image stream','',0,'Make sure you have the latest version of GD2 installed' );
  479. $b = imagecreatefromstring(base64_decode($this->blankpng()));
  480. imagealphablending($i,false);
  481. imagesavealpha($i,true);
  482. imagecopyresized($i,$b,0,0,0,0,$x,$y,imagesx($b),imagesy($b));
  483. imagealphablending($i,true);
  484. return $i;
  485. }
  486. function blankpng()
  487. {
  488. $c = "iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29m".
  489. "dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADqSURBVHjaYvz//z/DYAYAAcTEMMgBQAANegcCBNCg".
  490. "dyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAAN".
  491. "egcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQ".
  492. "oHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAA".
  493. "DXoHAgTQoHcgQAANegcCBNCgdyBAgAEAMpcDTTQWJVEAAAAASUVORK5CYII=";
  494. return $c;
  495. }
  496. #
  497. ##########################################################################################################
  498. #
  499. # This is where the new water mark systen starts : Took some time but i got it
  500. #
  501. # Now the WM system add the watermark to the uploaded image i hope
  502. #
  503. function addwatermark($newimage, $wm_loc, $wm_use, $wm_file, $wm_dir){
  504. global $roster, $addon;
  505. $widthtn=ImageSx($newimage); // thumb width is stored
  506. $heightn=ImageSy($newimage); // thumb width is stored
  507. $wm = $addon['dir'].$wm_dir.'/'.$wm_file;
  508. if( file_exists($wm)){
  509. $blah = getimagesize($wm);
  510. $type = $blah['mime'];
  511. $widthwm = $blah[0];
  512. $heightwm = $blah[1];
  513. # this is where we determin where to place the water mark we ar gona
  514. # allways ass a 5pix buffer incase the image uses the hole image size
  515. # 1 = top left - 2 = top right - 3 = bottom left - 4 = bottom right
  516. if ($wm_loc == 1){
  517. $lox = 8;
  518. $loy = 8;
  519. }
  520. if ($wm_loc == 2){
  521. $lox = (($widthtn - $widthwm) - 8);
  522. $loy = 8;
  523. }
  524. if ($wm_loc == 3){
  525. $lox = 8;
  526. $loy = (($heightn - $heightwm) - 8);
  527. }
  528. if ($wm_loc == 4){
  529. $lox = (($widthtn - $widthwm) - 8);
  530. $loy = (($heightn - $heightwm) - 8);
  531. }
  532. $this->combineImage( $newimage,$wm,(__LINE__),$lox,$loy );
  533. }
  534. else {
  535. $this->setMessage("watermark ".$wm." does not exist");
  536. }
  537. return $newimage;
  538. }
  539. function reset_values()
  540. {
  541. $this->assignstr = '';
  542. }
  543. function processData($data)
  544. {
  545. global $roster, $addon_cfg, $addon;
  546. //global $addon_cfg, $addon;
  547. $this->reset_values();
  548. foreach( $data as $settingName => $settingValue )
  549. {
  550. if( $settingName != 'process' )
  551. {
  552. $update_sql[] = "UPDATE `roster_addon_config` SET `config_value` = '".$roster->db->escape( $settingValue )."' WHERE `config_name` = '".$settingName."';";
  553. }
  554. }
  555. // Update DataBase
  556. if( is_array($update_sql) )
  557. {
  558. foreach( $update_sql as $sql )
  559. {
  560. $queries[] = $sql;
  561. $result = $roster->db->query($sql);
  562. if( !$result )
  563. {
  564. $this->setMessage('<span style="color:#0099FF;font-size:11px;">Error saving settings</span><br />MySQL Said:<br /><pre>'.$roster->db->error().'</pre>');
  565. }
  566. }
  567. $this->setMessage('<span style="color:#0099FF;font-size:11px;">Settings have been changed</span>');
  568. }
  569. else
  570. {
  571. $this->setMessage('<span style="color:#0099FF;font-size:11px;">No changes have been made</span>');
  572. }
  573. }
  574. function get_size2($path)
  575. {
  576. if(!is_dir($path)) return filesize($path);
  577. if ($handle = opendir($path)) {
  578. $size = 0;
  579. while (false !== ($file = readdir($handle))) {
  580. if($file!='.' && $file!='..'){
  581. $size += filesize($path.'/'.$file);
  582. $size += $this->get_size2($path.'/'.$file);
  583. }
  584. }
  585. closedir($handle);
  586. //echo "-".$size."<br>";
  587. return $size;
  588. }
  589. }
  590. function get_size($dirr ,$ssfolder)
  591. {
  592. $size = 0;
  593. foreach( $ssfolder as $path )
  594. {
  595. $path = $dirr.$path;
  596. if(!is_dir($path)) return filesize($path);
  597. if ($handle = opendir($path)) {
  598. while (false !== ($file = readdir($handle)))
  599. {
  600. if($file!='.' && $file!='..'){
  601. $size += filesize($path.''.$file);
  602. //$size += $this->get_size2($path.''.$file);
  603. }
  604. }closedir($handle);
  605. }//closedir($handle);
  606. }
  607. $size = $this->size_hum_read($size);
  608. return $size;
  609. }
  610. function size_hum_read($size){
  611. /*
  612. Returns a human readable size
  613. */
  614. $i=0;
  615. $iec = array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
  616. while (($size/1024)>1) {
  617. $size=$size/1024;
  618. $i++;
  619. }
  620. return substr($size,0,strpos($size,'.')+3).$iec[$i];
  621. }
  622. function deleteDir($dir)
  623. {
  624. if (substr($dir,-1) != "/") $dir .= "/";
  625. if (!is_dir($dir)) return false;
  626. if (($dh = opendir($dir)) !== false) {
  627. while (($entry = readdir($dh)) !== false) {
  628. if ($entry != "." && $entry != "..") {
  629. if (is_file($dir . $entry) || is_link($dir . $entry)) unlink($dir . $entry);
  630. else if (is_dir($dir . $entry)) $this->deleteDir($dir . $entry);
  631. }
  632. }
  633. closedir($dh);
  634. rmdir($dir);
  635. return true;
  636. }
  637. return false;
  638. }
  639. function assign_vars($vararray)
  640. {
  641. foreach ($vararray as $key => $val)
  642. {
  643. $this->_tpldata[$key] = $val;
  644. }
  645. return true;
  646. }
  647. function onOff($bool)
  648. {
  649. if($bool)
  650. {
  651. return "<span class=\"green\">On</span>";
  652. }
  653. else
  654. {
  655. return "<span class=\"red\">Off</span>";
  656. }
  657. }
  658. function combineImage( $image,$filename,$line,$x_loc,$y_loc )
  659. {
  660. $info = getimagesize($filename);
  661. switch( $info['mime'] )
  662. {
  663. case 'image/jpeg' :
  664. $im_temp = @imagecreatefromjpeg($filename);
  665. break;
  666. case 'image/png' :
  667. $im_temp = @imagecreatefrompng($filename);
  668. break;
  669. case 'image/gif' :
  670. $im_temp = @imagecreatefromgif($filename);
  671. break;
  672. default:
  673. break;
  674. }
  675. // Get the image dimentions
  676. $im_temp_width = imageSX( $im_temp );
  677. $im_temp_height = imageSY( $im_temp );
  678. // Copy created image into main image
  679. @imagecopy( $image,$im_temp,$x_loc,$y_loc,0,0,$im_temp_width,$im_temp_height );
  680. // Destroy the temp image
  681. if( isset($im_temp) )
  682. {
  683. @imageDestroy( $im_temp );
  684. }
  685. }
  686. function combineImage2( $image, $filename, $line, $x_loc, $y_loc )
  687. {
  688. $info = getimagesize($filename);
  689. switch( $info['mime'] )
  690. {
  691. case 'image/jpeg' :
  692. $im_temp = @imagecreatefromjpeg($filename);
  693. break;
  694. case 'image/png' :
  695. $im_temp = @imagecreatefrompng($filename);
  696. break;
  697. case 'image/gif' :
  698. $im_temp = @imagecreatefromgif($filename);
  699. break;
  700. default:
  701. break;
  702. }
  703. // Get the image dimentions
  704. $im_temp_width = imageSX( $im_temp );
  705. $im_temp_height = imageSY( $im_temp );
  706. // Copy created image into main image
  707. @imagecopy( $image,$im_temp,$x_loc,$y_loc,0,0,$im_temp_width,$im_temp_height );
  708. // Destroy the temp image
  709. if( isset($im_temp) )
  710. {
  711. @imageDestroy( $im_temp );
  712. }
  713. }
  714. function debugMode( $line,$message,$file=null,$config=null,$message2=null )
  715. {
  716. global $im;
  717. // Destroy the image
  718. if( isset($im) )
  719. imageDestroy($im);
  720. if( is_numeric($line) )
  721. $line -= 1;
  722. $error_text = 'Error!';
  723. $line_text = 'Line: '.$line;
  724. $file = ( !empty($file) ? 'File: '.$file : '' );
  725. $config = ( $config ? 'Check the config file' : '' );
  726. $message2 = ( !empty($message2) ? $message2 : '' );
  727. $lines = array();
  728. $lines[] = array( 's' => $error_text, 'f' => 5, 'c' => 'red' );
  729. $lines[] = array( 's' => $line_text, 'f' => 3, 'c' => 'blue' );
  730. $lines[] = array( 's' => $file, 'f' => 2, 'c' => 'green' );
  731. $lines[] = array( 's' => $message, 'f' => 2, 'c' => 'black' );
  732. $lines[] = array( 's' => $config, 'f' => 2, 'c' => 'black' );
  733. $lines[] = array( 's' => $message2, 'f' => 2, 'c' => 'black' );
  734. $height = $width = 0;
  735. foreach( $lines as $line )
  736. {
  737. if( strlen($line['s']) > 0 )
  738. {
  739. $line_width = ImageFontWidth($line['f']) * strlen($line['s']);
  740. $width = ( ($width < $line_width) ? $line_width : $width );
  741. $height += ImageFontHeight($line['f']);
  742. }
  743. }
  744. $im = @imagecreate($width+1,$height);
  745. if( $im )
  746. {
  747. $white = imagecolorallocate( $im, 255, 255, 255 );
  748. $red = imagecolorallocate( $im, 255, 0, 0 );
  749. $green = imagecolorallocate( $im, 0, 255, 0 );
  750. $blue = imagecolorallocate( $im, 0, 0, 255 );
  751. $black = imagecolorallocate( $im, 0, 0, 0 );
  752. $linestep = 0;
  753. foreach( $lines as $line )
  754. {
  755. if( strlen($line['s']) > 0 )
  756. {
  757. imagestring( $im, $line['f'], 1, $linestep, $this->utf8_to_nce($line['s']), $$line['c'] );
  758. $linestep += ImageFontHeight($line['f']);
  759. }
  760. }
  761. header( 'Content-type: image/gif' );
  762. imagegif( $im );
  763. imageDestroy( $im );
  764. }
  765. else
  766. {
  767. if( !empty($file) )
  768. {
  769. $file = "[<span style=\"color:green\">$file</span>]";
  770. }
  771. $string = "<strong><span style=\"color:red\">Error!</span></strong>";
  772. $string .= "<span style=\"color:blue\">Line $line:</span> $message $file\n<br /><br />\n";
  773. if( $config )
  774. {
  775. $string .= "$config\n<br />\n";
  776. }
  777. if( !empty($message2) )
  778. {
  779. $string .= "$message2\n";
  780. }
  781. print $string;
  782. }
  783. exit();
  784. }
  785. function utf8_to_nce( $utf = '' )
  786. {
  787. if($utf == '')
  788. {
  789. return($utf);
  790. }
  791. $max_count = 5; // flag-bits in $max_mark ( 1111 1000 == 5 times 1)
  792. $max_mark = 248; // marker for a (theoretical ;-)) 5-byte-char and mask for a 4-byte-char;
  793. $html = '';
  794. for($str_pos = 0; $str_pos < strlen($utf); $str_pos++)
  795. {
  796. $old_val = ord( $utf{$str_pos} );
  797. $new_val = 0;
  798. $utf8_marker = 0;
  799. // skip non-utf-8-chars
  800. if( $old_val > 127 )
  801. {
  802. $mark = $max_mark;
  803. for($byte_ctr = $max_count; $byte_ctr > 2; $byte_ctr--)
  804. {
  805. // actual byte is utf-8-marker?
  806. if( ( $old_val & $mark ) == ( ($mark << 1) & 255 ) )
  807. {
  808. $utf8_marker = $byte_ctr - 1;
  809. break;
  810. }
  811. $mark = ($mark << 1) & 255;
  812. }
  813. }
  814. // marker found: collect following bytes
  815. if($utf8_marker > 1 and isset( $utf{$str_pos + 1} ) )
  816. {
  817. $str_off = 0;
  818. $new_val = $old_val & (127 >> $utf8_marker);
  819. for($byte_ctr = $utf8_marker; $byte_ctr > 1; $byte_ctr--)
  820. {
  821. // check if following chars are UTF8 additional data blocks
  822. // UTF8 and ord() > 127
  823. if( (ord($utf{$str_pos + 1}) & 192) == 128 )
  824. {
  825. $new_val = $new_val << 6;
  826. $str_off++;
  827. // no need for Addition, bitwise OR is sufficient
  828. // 63: more UTF8-bytes; 0011 1111
  829. $new_val = $new_val | ( ord( $utf{$str_pos + $str_off} ) & 63 );
  830. }
  831. // no UTF8, but ord() > 127
  832. // nevertheless convert first char to NCE
  833. else
  834. {
  835. $new_val = $old_val;
  836. }
  837. }
  838. // build NCE-Code
  839. $html .= '&#'.$new_val.';';
  840. // Skip additional UTF-8-Bytes
  841. $str_pos = $str_pos + $str_off;
  842. }
  843. else
  844. {
  845. $html .= chr($old_val);
  846. $new_val = $old_val;
  847. }
  848. }
  849. return($html);
  850. }
  851. function listFiles( $dir , $ext )
  852. {
  853. $arrFiles = array();
  854. // Open the directory
  855. $tmp_dir = @opendir( $dir );
  856. if( !empty($tmp_dir) )
  857. {
  858. // Read the files
  859. while( $file = readdir($tmp_dir) )
  860. {
  861. $pfad_info = pathinfo($file);
  862. if( is_array($ext) )
  863. {
  864. if( in_array(strtolower($pfad_info['extension']),$ext))
  865. {
  866. $name = str_replace('.'.$pfad_info['extension'],'',$file);
  867. $arrFiles += array($file => $name);
  868. }
  869. }
  870. else
  871. {
  872. if( strtolower($pfad_info['extension']) == strtolower($ext) )
  873. {
  874. $name = str_replace('.'.$pfad_info['extension'],'',$file);
  875. $arrFiles += array($file => $name);
  876. }
  877. }
  878. }
  879. // close the directory
  880. closedir($tmp_dir);
  881. //sort the list
  882. asort($arrFiles);
  883. }
  884. return $arrFiles;
  885. }
  886. #######
  887. ####### Some new functions i created to see if i can get less and less hard coded veriables
  888. #######
  889. #
  890. # first new way to call Image Thumbnail and prepare it for output
  891. #
  892. function getimage($id , $iflib, $iflb, $disc, $title, $path, $path2, $rating, $width, $height, $cat){
  893. global $roster, $addon;
  894. $img = '';
  895. if ($disc == ''){
  896. $disc = $roster->locale->act['nodisc'];
  897. }
  898. if ($title == ''){
  899. $title = $roster->locale->act['nocaption'];
  900. }
  901. if ($rating == ''){
  902. $disc = $roster->locale->act['norating'];
  903. }
  904. if ($iflib == 1){
  905. $tool = makeOverlib( $disc , $caption=$title.' ~ '.$rating, $caption_color='' , $mode=0 , $locale='' , $extra_parameters='' );
  906. }
  907. if ($iflb == 1){
  908. $img .= '
  909. <div style="cursor:help;" '.$tool.'>
  910. <a href="'.$path2.'" rel="lightbox" title="'.$title.' '.$rating.'<br>'.$disc.'" >
  911. <img src="' . $path.'" width="'.$width.'" height="'.$height."\"></a></div>\n\n";
  912. }else{
  913. $img .= '
  914. <div style="cursor:help;" '.$tool.'>
  915. <a href="'.makelink().'&id='.$id.'" title="'.$title.' '.$rating.'">
  916. <img src="' . $path.'" width="'.$width.'" height="'.$height."\"></a></div>\n\n";
  917. }
  918. return $img;
  919. }
  920. function createOptionList( $values , $selected , $id , $type='' , $param='' )
  921. {
  922. if( !empty($selected) )
  923. {
  924. $select_one = true;
  925. }
  926. $option_list = "\n <select class=\"sc_select\" name=\"{$id}\" $param>\n <option value=\"\">--None--</option>\n";
  927. foreach( $values as $Aname => $Avalue )
  928. {
  929. switch ($type)
  930. {
  931. case 0: // name value
  932. case 'list':
  933. $value = $Avalue;
  934. $name = $Aname;
  935. break;
  936. case 1: // value name
  937. case 'rev':
  938. $value = $Aname;
  939. $name = $Avalue;
  940. break;
  941. case 2: // name name
  942. case 'name':
  943. $value = $Aname;
  944. $name = $Aname;
  945. break;
  946. case 3: // value value
  947. case 'value':
  948. $value = $Avalue;
  949. $name = $Avalue;
  950. break;
  951. default:
  952. $value = $Avalue;
  953. $name = $Aname;
  954. break;
  955. }
  956. if( $selected == $value && $select_one )
  957. {
  958. $option_list .= " <option value=\"{$value}\" selected=\"selected\">->{$name}<-</option>\n";
  959. $select_one = false;
  960. }
  961. else
  962. {
  963. $option_list .= " <option value=\"{$value}\">{$name}</option>\n";
  964. }
  965. }
  966. $option_list .= " </select>";
  967. return $option_list;
  968. }
  969. function createTip( $content , $caption )
  970. {
  971. $tipsettings = ",WRAP";
  972. if( !empty($caption) )
  973. $caption2 = ",CAPTION,'$caption'";
  974. $tip = "<div style=\"cursor:help;\" onmouseover=\"overlib('$content'$caption2$tipsettings);\" onmouseout=\"return nd();\">$caption</div>";
  975. return $tip;
  976. }
  977. }
  978. ?>