Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

804 lines
26 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. $ConvertCommand='convert';
  3. $ComposeCommand='composite';
  4. // Include this function on your pages
  5. function BEGIN_GZ(){
  6. ob_start();
  7. ob_implicit_flush(false);
  8. };
  9. function END_GZ() {
  10. global $HTTP_ACCEPT_ENCODING;
  11. if( headers_sent() ){
  12. $encoding = false;
  13. }elseif( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false ){
  14. $encoding = 'x-gzip';
  15. }elseif( strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false ){
  16. $encoding = 'gzip';
  17. }else{
  18. $encoding = false;
  19. }
  20. if( $encoding ){
  21. $contents = ob_get_contents();
  22. ob_end_clean();
  23. header('Content-Encoding: '.$encoding);
  24. print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
  25. $size = strlen($contents);
  26. $contents = gzcompress($contents, 9);
  27. $contents = substr($contents, 0, $size);
  28. print($contents);
  29. exit();
  30. }else{
  31. ob_end_flush();
  32. exit();
  33. }
  34. };
  35. function handle_pereodical_jobs(){
  36. global $DATABASE;
  37. $QS="SELECT * FROM site_tasks WHERE DATEDIFF(CURDATE(),ts)>1 OR ts = 0";
  38. $result=$DATABASE->Query($QS,false);
  39. foreach($result as $CT){
  40. switch($CT['task_id']){
  41. case 'vip-top':{
  42. check_vip_tops();
  43. break;
  44. };
  45. case 'vip-status':{
  46. check_vip_stat();
  47. break;
  48. };
  49. case 'pic-rate':{
  50. check_pic_rate();
  51. break;
  52. };
  53. case 'user-stat':{
  54. check_usr_stat();
  55. break;
  56. };
  57. };
  58. $QS="UPDATE site_tasks SET ts=CURDATE() WHERE id={$CT['id']}";
  59. $DATABASE->Query($QS,false);
  60. };
  61. };
  62. function GetColorOfImage($FS,$Mode=0){
  63. $im=imagecreatefromjpeg($FS);
  64. $P1=imagecolorat($im,0,0);
  65. $P2=imagecolorat($im,200,0);
  66. $P3=imagecolorat($im,200,200);
  67. $P4=imagecolorat($im,0,200);
  68. switch($Mode){
  69. case 0:{
  70. $CT=imagecolorsforindex($im,$P1);
  71. $CI['red']=$CT['red'];$CI['green']=$CT['green'];$CI['blue']=$CT['blue'];
  72. $CT=imagecolorsforindex($im,$P1);
  73. $CI['red']+=$CT['red'];$CI['green']+=$CT['green'];$CI['blue']+=$CT['blue'];
  74. $CT=imagecolorsforindex($im,$P1);
  75. $CI['red']+=$CT['red'];$CI['green']+=$CT['green'];$CI['blue']+=$CT['blue'];
  76. $CT=imagecolorsforindex($im,$P1);
  77. $CI['red']+=$CT['red'];$CI['green']+=$CT['green'];$CI['blue']+=$CT['blue'];
  78. $CI['red']=round($CI['red']/4);$CI['green']=round($CI['green']/4);$CI['blue']=round($CI['blue']/4);
  79. $RetColor="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
  80. break;
  81. };
  82. case 1:{
  83. $CI=imagecolorsforindex($im,$P1);
  84. $RetColor="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
  85. break;
  86. };
  87. case 2:{
  88. $CI=imagecolorsforindex($im,$P2);
  89. $RetColor="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
  90. break;
  91. };
  92. case 3:{
  93. $CI=imagecolorsforindex($im,$P3);
  94. $RetColor="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
  95. break;
  96. };
  97. case 4:{
  98. $CI=imagecolorsforindex($im,$P4);
  99. $RetColor="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
  100. break;
  101. };
  102. case 5:{
  103. $CI=imagecolorsforindex($im,$P1);
  104. $RetColor[]="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
  105. $CI=imagecolorsforindex($im,$P2);
  106. $RetColor[]="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
  107. $CI=imagecolorsforindex($im,$P3);
  108. $RetColor[]="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
  109. $CI=imagecolorsforindex($im,$P4);
  110. $RetColor[]="#".dechex($CI['red']).dechex($CI['green']).dechex($CI['blue']);
  111. break;
  112. };
  113. };
  114. return $RetColor;
  115. };
  116. function check_vip_tops(){
  117. global $DATABASE;
  118. $WQS="SELECT * FROM top_vips WHERE DATEDIFF(CURDATE(),ts)> (days-3)"; // Warning Query
  119. $result=$DATABASE->Query($WQS,false);
  120. foreach($result as $WR) top_exp3d($WR);
  121. $CQS="DELETE FROM top_vips WHERE DATEDIFF(CURDATE(),ts)> days"; // Clearup Query
  122. $DATABASE->Query($CQS,false);
  123. };
  124. function check_vip_stat(){
  125. global $DATABASE;
  126. $WQS="SELECT * FROM vips WHERE DATEDIFF(CURDATE(),ts)> ((month_counts*30)-3)"; // Warning Query
  127. $result=$DATABASE->Query($WQS,false);
  128. foreach($result as $WR) vip_exp3d($WR);
  129. $CQS="DELETE FROM vips WHERE DATEDIFF(CURDATE(),ts)> (month_counts*30)"; // Clearup Query
  130. $DATABASE->Query($CQS,false);
  131. };
  132. function check_pic_rate(){
  133. global $DATABASE;
  134. $QS="UPDATE photos SET views = 1";
  135. $DATABASE->Query($QS,false);
  136. };
  137. function check_usr_stat(){};
  138. function vip_exp3d($WR){
  139. $WarnText='Your VIP status is about to expire in three (3) days.';
  140. $user=load_profile($WR['account_id']);
  141. DeliverAdminMessage($user['email'],'',$WarnText);
  142. };
  143. function top_exp3d($WR){
  144. $WarnText='Your VIP Top Listing on folowing region '. PrintHTTP_DecorateGeoLocation($WR['city'],$WR['state'],$WR['country'],$WR['region']) .' about to expire';
  145. $user=load_profile($WR['account_id']);
  146. DeliverAdminMessage($user['email'],'',$WarnText);
  147. };
  148. function isBot(){
  149. $BAgents=array('google','yahoo','spider','crawler','bot','msn');
  150. $RetVal=false;
  151. for($index=0;$index<count($BAgents);$index++)
  152. if ( strlen(strstr(strtolower($_SERVER['HTTP_USER_AGENT']),$BAgents[$index]))>0 ) $RetVal=true;
  153. return $RetVal;
  154. };
  155. function WatermarkIt($IMGName){
  156. global $ComposeCommand,$SYSPath;
  157. list($width, $height, $type, $attr) = getimagesize($IMGName);
  158. if($width<400){
  159. $MarkFile = getcwd().'/style/img/heraldic_100.png';
  160. } else {
  161. $MarkFile = getcwd().'/style/img/heraldic_200.png';
  162. };
  163. $THBName=getcwd()."/tmp/".basename($IMGName);
  164. $runStr = $ComposeCommand . ' -gravity SouthEast "' . $MarkFile . '" "' . $IMGName . '" "' . $THBName . '"';
  165. $RetCode =`$runStr`;
  166. unlink($IMGName);
  167. $MD5Code=md5_file($THBName);
  168. copy($THBName,$IMGName);
  169. unlink($THBName);
  170. return $MD5Code;
  171. };
  172. function ResizePicIfNeeded_SYSTEM($IMGName){
  173. global $ConvertCommand,$SYSPath;
  174. list($width, $height, $type, $attr) = getimagesize($IMGName);
  175. if( $width > 600 )
  176. {
  177. $DW = 600;
  178. $DH = $height * 600 / $width;
  179. $resize='-gaussian 1x1+5+5 -resize '.$DW.'x'.$DH;
  180. } else {
  181. $resize='';
  182. };
  183. $THBName=$SYSPath."tmp/".basename($IMGName);
  184. //echo "$IMGName --> $THBName";
  185. $runStr = $ConvertCommand .' "'.$IMGName.'" -flatten '.$resize.' -antialias -normalize -enhance -sharpen 5 "'.$THBName.'"';
  186. $runStr = $ConvertCommand .' "'.$IMGName.'" -flatten '.$resize.' -adaptive-blur 3x3+10+10 -normalize -enhance -sharpen 1 "'.$THBName.'"';//PRiSHIKI
  187. $runStr = $ConvertCommand .' "'.$IMGName.'" -flatten '.$resize.' -normalize -sharpen 0.2 "'.$THBName.'"';
  188. $RetCode =`$runStr`;
  189. unlink($IMGName);
  190. $FileName=getcwd().'/photos/'.md5_file($THBName).'.jpg';
  191. copy($THBName,$FileName);
  192. unlink($THBName);
  193. return $FileName;
  194. };
  195. function ImageNotTooSmall($FNAME){
  196. global $MinimalSize;
  197. list($width, $height, $type, $attr) = getimagesize($FNAME);
  198. return $MinimalSize<($width*$height);
  199. };
  200. function SetImageSizeFromFile($ID=0,$IMGName=''){
  201. list($width, $height, $type, $attr) = getimagesize($IMGName);
  202. if ($ID>0) {
  203. if($width && $height){
  204. SetImageSize($ID,$width,$height);
  205. } else DeleteItem($ID);
  206. };
  207. }
  208. function CreateThumb200($IMGName, $THBName, $ID=0){
  209. global $ConvertCommand,$SYSPath;
  210. list($width, $height, $type, $attr) = getimagesize($IMGName);
  211. if ($ID>0){
  212. if($width && $height){
  213. SetImageSize($ID,$width,$height);
  214. } else return false;
  215. };
  216. $retcode=false;
  217. if(is_writable (dirname(dirname($THBName)))){
  218. if (!is_dir(dirname($THBName))){
  219. mkdir (dirname($THBName));
  220. $retcode=true;
  221. };
  222. $retcode=true;
  223. if( $width > $height ){
  224. $runStr = $ConvertCommand .' "'.$IMGName.'" -crop '.$height.'x'.$height.'!+0+0 -flatten -resize 200x200 "'.$THBName.'"';
  225. } else {
  226. $runStr = $ConvertCommand .' "'.$IMGName.'" -crop '.$width.'x'.$width.'!+0+0 -flatten -resize 200x200 "'.$THBName.'"';
  227. }
  228. echo $runStr."\n";
  229. $RetCode =`$runStr`;
  230. echo $RetCode."\n";
  231. };
  232. return $retcode;
  233. };
  234. function CreateThumb100($IMGName){
  235. global $ConvertCommand,$SYSPath;
  236. list($width, $height, $type, $attr) = getimagesize($IMGName);
  237. $THBName=$SYSPath."photos/thumbs/".basename($IMGName,'.jpg').'.jpg';
  238. if( $width > $height ){
  239. $runStr = $ConvertCommand .' "'.$IMGName.'" -crop '.$height.'x'.$height.'!+0+0 -flatten -resize 100x100 "'.$THBName.'"';
  240. } else {
  241. $runStr = $ConvertCommand .' "'.$IMGName.'" -crop '.$width.'x'.$width.'!+0+0 -flatten -resize 100x100 "'.$THBName.'"';
  242. }
  243. $RetCode =`$runStr`;
  244. };
  245. function CreateThumb50($IMGName){
  246. global $ConvertCommand,$SYSPath;
  247. list($width, $height, $type, $attr) = getimagesize($IMGName);
  248. $THBName=$SYSPath."photos/thumbs/".basename($IMGName,'.jpg').'_50.jpg';
  249. if( $width > $height ){
  250. $runStr = $ConvertCommand .' "'.$IMGName.'" -crop '.$height.'x'.$height.'!+0+0 -flatten -resize 50x50 "'.$THBName.'"';
  251. } else {
  252. $runStr = $ConvertCommand .' "'.$IMGName.'" -crop '.$width.'x'.$width.'!+0+0 -flatten -resize 50x50 "'.$THBName.'"';
  253. }
  254. $RetCode =`$runStr`;
  255. };
  256. function GetPicParam($PID){
  257. global $WEBPath,$SYSPath;
  258. $PSPath=$SYSPath.'photos/'.$PID.'.jpg';
  259. if (file_exists($PSPath)){
  260. $RetVal= getimagesize($PSPath);
  261. }else {
  262. $RetVal= array(200,200);
  263. };
  264. return $RetVal;
  265. };
  266. function PrintDATA_Picture_Path($ItemID,$PTyp=0){
  267. global $WEBPath,$SYSPath, $ShowImagesLocal, $ShowThumbnailsLocal;
  268. $NPPath="style/img/nopic.gif";
  269. $ADPath="style/img/mopic.gif";
  270. if ($ItemID){
  271. $Data=GetItemData($ItemID);
  272. //print_r($Data);
  273. if(($Data['remote']=='disable') || $ShowImagesLocal || $ShowThumbnailsLocal ){
  274. $PSPath=$SYSPath . substr($Data['fs_path'],3);
  275. $DP=substr(dirname($Data['fs_path']),3).'/thumb';
  276. $FN=basename($Data['fs_path']);
  277. $CC=false;
  278. $RetVal='';
  279. if (file_exists($PSPath)){
  280. switch ($PTyp){
  281. case 0:{
  282. $PTPath=$PSPath;
  283. break;
  284. };
  285. case 1:{
  286. if ($ShowThumbnailsLocal){
  287. $PTPath=$SYSPath.$DP.'/'.$FN;
  288. if(!file_exists($PTPath)){
  289. $CC=CreateThumb200( $PSPath, $PTPath , $ItemID );
  290. };
  291. } else {
  292. $RetVal=$Data['thumbnail_url'];
  293. };
  294. break;
  295. };
  296. };
  297. if ( file_exists($PTPath)){
  298. if ($PTyp>0){
  299. if ($RetVal=='') $RetVal=$WEBPath.'/'.$DP.'/'.$FN;
  300. } else {
  301. $RetVal=$WEBPath.'/'.substr($Data['fs_path'],3);
  302. };
  303. } elseif(!$CC) {
  304. $RetVal=$WEBPath.$ADPath .'" '.$PTPath ;
  305. } else {
  306. DeleteItem($ItemID);
  307. $RetVal=$WEBPath.$NPPath;
  308. };
  309. } elseif( $PTyp==0 && !$ShowImagesLocal ){
  310. $RetVal=$Data['url'];
  311. } elseif( $PTyp==1 && !$ShowThumbnailsLocal){
  312. $RetVal=$Data['thumbnail_url'];
  313. } elseif( $PTyp==1 && $ShowThumbnailsLocal ){
  314. $PTPath=$SYSPath.$DP.'/'.$FN;
  315. if(file_exists($PTPath)){
  316. $RetVal=$WEBPath.'/'.$DP.'/'.$FN;
  317. } else $RetVal=$WEBPath.$NPPath;
  318. };
  319. } else {
  320. if($PTyp>0){
  321. $DP=substr(dirname($Data['fs_path']),3).'/thumb';
  322. $FN=basename($Data['fs_path']);
  323. $PTPath=$SYSPath.$DP.'/'.$FN;
  324. if(file_exists($PTPath)===false){
  325. $RetVal=$Data['thumbnail_url'];
  326. } else $RetVal=$WEBPath.'/'.$DP.'/'.$FN;
  327. } else {
  328. $RetVal=$Data['url'];
  329. };
  330. };
  331. } else {
  332. $RetVal=$WEBPath . $NPPath;
  333. };
  334. return $RetVal;
  335. };
  336. function GetBackPath(){
  337. if ($_SERVER['HTTP_REFERER']){
  338. return ltrim(strrchr($_SERVER['HTTP_REFERER'],'/'),'/');
  339. } else {
  340. return '';
  341. };
  342. };
  343. function PictureUpload(){//$SID
  344. global $CUser;
  345. $maxSize = 2097152; // 2 Megs by default
  346. if( isset($_FILES['DTA']) ){
  347. if(strstr($_FILES['DTA']['type'], 'image') === false){
  348. $RetVal="<center><font color=Red><br><strong>The Uploaded File Isn't Image</strong><br><br></font></center>";
  349. } elseif ($_FILES['DTA']['size'] > $maxSize ){
  350. $RetVal="<center><font color=Red><br><strong>The Uploaded File Is Too Big</strong><br><br></font></center>";
  351. } else {
  352. $target_path = getcwd() . "/tmp/";
  353. $picture_path= getcwd() . "/photos/";
  354. $target_path .= basename( $_FILES['DTA']['tmp_name']);//$_FILES['DTA']['name']);
  355. $srcpath=$_FILES['DTA']['tmp_name'];
  356. //echo "Trying to move $srcpath ==> $target_path \n<br>";
  357. if( @move_uploaded_file($srcpath, $target_path)){
  358. list($width, $height, $type, $attr) = getimagesize($target_path);
  359. if ( ($width/10)*($height/10)<625 ) {
  360. @unlink($target_path);
  361. $RetVal="<center><font color=Red><br><strong>File ". basename( $_FILES['DTA']['name'])." is too small<br>Please upload the image that is bigger then 250x250</strong><br><br></font></center>";
  362. } else {
  363. $picture_path.=md5_file($target_path).'.jpg';
  364. @copy($target_path,$picture_path);
  365. @unlink($target_path);
  366. $picture_path=ResizePicIfNeeded_SYSTEM($picture_path);
  367. WatermarkIt($picture_path);
  368. $PictureName=basename($picture_path,'.jpg');
  369. CreateThumb50($picture_path);
  370. CreateThumb100($picture_path);
  371. CreateThumb200($picture_path);
  372. //echo "File Moved $srcpath ==> $target_path \n<br>";
  373. if(isset($_POST['PIN'])) $PIPIN=1; else $PIPIN=0;
  374. if( AddPicture($PictureName,$CUser['id'],$PIPIN,$CUser['vip']) ){ //AddBanner($_POST['TTL'],$_POST['URL'],$target_path, $SID) !== false
  375. $RetVal="<center><br><strong>File ". basename( $_FILES['DTA']['name'])." Uploaded</strong><br><br></center>";
  376. } else {
  377. $RetVal="<center><font color=Red><br><strong>Error to add record into Database!</strong><br><br></font></center>";
  378. };
  379. };
  380. } else {
  381. $RetVal="<center><font color=Red><br><strong>Error to add record into Database!</strong><br><br></font></center>";
  382. };
  383. };
  384. };
  385. return $RetVal;
  386. }
  387. function make_300thumb($FileName){
  388. list($width, $height, $type, $attr) = getimagesize($FileName);
  389. #echo "IPR: $width, $height, $type, $attr\n";
  390. if( $type == 1 ) $bim=LoadGif($FileName);
  391. if( $type == 2 ) $bim=LoadJpeg($FileName);
  392. if( $type == 3 ) $bim=LoadPng($FileName);
  393. #var_dump(gd_info());
  394. $Rim = ResizeIMG($bim,$width,$height,300);
  395. $entry = "$FileName.987987";
  396. $JCod=imagegif($Rim,$entry, 100);
  397. $handle = fopen($entry, 'r') or die( "Cannot open temporary Image [ $entry ]\n\n");
  398. $BytesRead=fread($handle,filesize($entry));
  399. if ( !$BytesRead ){
  400. echo " Read Failed Or File is Empty\n";
  401. }
  402. fclose($handle);
  403. unlink($entry);
  404. return $BytesRead;
  405. };
  406. function make_100thumb($FileName){
  407. list($width, $height, $type, $attr) = getimagesize($FileName);
  408. #echo "IPR: $width, $height, $type, $attr\n";
  409. if( $type == 1 ) $bim=LoadGif($FileName);
  410. if( $type == 2 ) $bim=LoadJpeg($FileName);
  411. if( $type == 3 ) $bim=LoadPng($FileName);
  412. #var_dump(gd_info());
  413. $Rim = ResizeIMG($bim,$width,$height);
  414. $entry = "$FileName.987987";
  415. $JCod=imagegif($Rim,$entry, 100);
  416. $handle = fopen($entry, 'r') or die( "Cannot open temporary Image [ $entry ]\n\n");
  417. $BytesRead=fread($handle,filesize($entry));
  418. if ( !$BytesRead ){
  419. echo " Read Failed Or File is Empty\n";
  420. }
  421. fclose($handle);
  422. unlink($entry);
  423. return $BytesRead;
  424. };
  425. function make_40thumb($FileName){
  426. list($width, $height, $type, $attr) = getimagesize($FileName);
  427. #echo "IPR: $width, $height, $type, $attr\n";
  428. if( $type == 1 ) $bim=LoadGif($FileName);
  429. if( $type == 2 ) $bim=LoadJpeg($FileName);
  430. if( $type == 3 ) $bim=LoadPng($FileName);
  431. #var_dump(gd_info());
  432. $Rim = ResizeIMG($bim,$width,$height,40);
  433. $entry = "$FileName.987987";
  434. $JCod=imagegif($Rim,$entry, 100);
  435. $handle = fopen($entry, 'r') or die( "Cannot open temporary Image [ $entry ]\n\n");
  436. $BytesRead=fread($handle,filesize($entry));
  437. if ( !$BytesRead ){
  438. echo " Read Failed Or File is Empty\n";
  439. }
  440. fclose($handle);
  441. unlink($entry);
  442. return $BytesRead;
  443. };
  444. function make_thumb_system($IMGName){
  445. global $TempDir;
  446. $THBName="$IMGName.987987";
  447. //echo "$IMGName --> $THBName";
  448. $RetCode =`convert "$IMGName" -sample 300x300 -flatten -resize 100x100 -normalize -enhance -sharpen 5 $THBName`;
  449. //$RetCode =`convert "$IMGName" -sample 300x300 -flatten -median 1.8 -resize 100x100 -unsharp 3x3+30+50 -normalize -enhance -sharpen 5 $THBName`;
  450. $handle = fopen($THBName, 'r') or die( "CreateThumbnail: Cannot open thumb/temp Image $THBName\n Rectode: $RetCode\n");
  451. $TData=fread($handle,filesize($THBName));
  452. fclose($handle);
  453. unlink($THBName);
  454. return $TData;
  455. };
  456. function LoadGif ($imgname)
  457. {
  458. $im = @imagecreatefromgif ($imgname); /* Attempt to open */
  459. if (!$im) { /* See if it failed */
  460. $im = imagecreatetruecolor(150, 30); /* Create a blank image */
  461. $bgc = imagecolorallocate ($im, 255, 255, 255);
  462. $tc = imagecolorallocate ($im, 0, 0, 0);
  463. imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
  464. /* Output an errmsg */
  465. imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc);
  466. }
  467. return $im;
  468. }
  469. function LoadJpeg($imgname)
  470. {
  471. $im = @imagecreatefromjpeg($imgname); /* Attempt to open */
  472. if (!$im) { /* See if it failed */
  473. $im = imagecreatetruecolor(150, 30); /* Create a blank image */
  474. $bgc = imagecolorallocate($im, 255, 255, 255);
  475. $tc = imagecolorallocate($im, 0, 0, 0);
  476. imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
  477. /* Output an errmsg */
  478. imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
  479. }
  480. return $im;
  481. }
  482. function LoadPNG($imgname)
  483. {
  484. $im = @imagecreatefrompng($imgname); /* Attempt to open */
  485. if (!$im) { /* See if it failed */
  486. $im = imagecreatetruecolor(150, 30); /* Create a blank image */
  487. $bgc = imagecolorallocate($im, 255, 255, 255);
  488. $tc = imagecolorallocate($im, 0, 0, 0);
  489. imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
  490. /* Output an errmsg */
  491. imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
  492. }
  493. return $im;
  494. }
  495. function ResizePicIfNeeded_SYSTEMd($IMGName){
  496. global $ConvertCommand,$TempDir;
  497. list($width, $height, $type, $attr) = getimagesize($IMGName);
  498. if( $width > 600 )
  499. {
  500. $DW = 600;
  501. $DH = $height * 600 / $width;
  502. $THBName="$IMGName.12387";
  503. //echo "$IMGName --> $THBName";
  504. $runStr = $ConvertCommand .' "'.$IMGName.'" -flatten -resize '.$DW.'x'.$DH.' -normalize -enhance -sharpen 5 "'.$THBName.'"';
  505. $RetCode =`$runStr`;
  506. //$RetCode =`convert "$IMGName" -sample 300x300 -flatten -median 1.8 -resize 100x100 -unsharp 3x3+30+50 -normalize -enhance -sharpen 5 $THBName`;
  507. $handle = fopen($THBName, 'r') or die( "ResizeImage: Cannot open thumb/temp Image $THBName\n Rectode: $RetCode\n");
  508. $TData=fread($handle,filesize($THBName));
  509. fclose($handle);
  510. unlink($THBName);
  511. } else {
  512. $handle = fopen($IMGName, 'r') or die( "ResizeImage: Cannot read Image $IMGName\n");
  513. $TData=fread($handle,filesize($IMGName));
  514. fclose($handle);
  515. unlink($IMGName);
  516. };
  517. return $TData;
  518. };
  519. function ResizePicIfNeeded_PHP($FileName)
  520. {
  521. $fHandle = fopen( $FileName, 'r' );
  522. $BytesRead = fread($fHandle,filesize($FileName));
  523. fclose( $fHandle );
  524. list($width, $height, $type, $attr) = getimagesize($FileName);
  525. if( $width > 600 )
  526. {
  527. //echo "IPR: $width, $height, $type, $attr\n";
  528. if( $type == 1 ) $bim=LoadGif($FileName);
  529. if( $type == 2 ) $bim=LoadJpeg($FileName);
  530. if( $type == 3 ) $bim=LoadPng($FileName);
  531. $DW = 600;
  532. $DH = $height * 600 / $width;
  533. $Rim = @imagecreatetruecolor($DW, $DH)
  534. or die("Cannot Initialize new GD image stream");
  535. $background_color = imagecolorallocatealpha($Rim, 0, 0, 0, 175);
  536. imagecopyresized($Rim,$bim,0,0,0,0,$DW,$DH,$width,$height);
  537. $entry = "$FileName.456456";
  538. $JCod=imagegif($Rim,$entry, 100);
  539. $handle = fopen($entry, 'r') or die( "Cannot open temporary Image [ $entry ]\n\n");
  540. $BytesRead=fread($handle,filesize($entry));
  541. if ( !$BytesRead )
  542. echo " Read Failed Or File is Empty\n";
  543. fclose($handle);
  544. unlink($entry);
  545. }
  546. return $BytesRead;
  547. }
  548. function ResizeIMG($image,$width,$height,$MAX=100){
  549. $kt=$width/$height;
  550. if( $kt > 1 ){
  551. $DW=$MAX;
  552. $DH=$MAX/$kt;
  553. } else {
  554. $DW=$MAX*$kt;
  555. $DH=$MAX;
  556. };
  557. $im = @imagecreatetruecolor($DW, $DH)
  558. or die("Cannot Initialize new GD image stream");
  559. $background_color = imagecolorallocate($im, 0, 0, 0);
  560. imagecopyresized($im,$image,0,0,0,0,$DW,$DH,$width,$height);
  561. return $im;
  562. }
  563. $DirID=0;
  564. function listDrives($CDrive){ //Windows Servers Only
  565. for($i=65;$i<91;$i++){
  566. $DLetter=chr($i);
  567. if ( @chdir("$DLetter:\\")){
  568. if ($DLetter!==$CDrive){
  569. echo "<OPTION value=\"$DLetter\">$DLetter:</OPTION>\n";
  570. } else {
  571. echo "<OPTION selected value=\"$DLetter\">$DLetter:</OPTION>\n";
  572. }
  573. };
  574. };
  575. };
  576. function ListDir($Path){
  577. if (is_dir($Path)){
  578. $CDir = opendir($Path);
  579. while (false !== ($entry=readdir($CDir))){
  580. if (($entry !==".")&&(is_dir($Path.$entry))){
  581. echo "<OPTION value=\"$entry\">$entry</OPTION>\n";
  582. };
  583. };
  584. closedir($CDir);
  585. } else {
  586. echo "Error -> Dir is not dir :(\n\n";
  587. };
  588. };
  589. function ListFiles($Path){
  590. if (is_dir($Path)){
  591. $CDir = opendir($Path);
  592. while (false !== ($entry=readdir($CDir))){
  593. if (is_dir($Path.$entry)===false){
  594. echo "<OPTION value=\"$entry\">$entry</OPTION>\n";
  595. };
  596. };
  597. closedir($CDir);
  598. } else {
  599. echo "Error -> Dir is not dir :(\n\n";
  600. };
  601. };
  602. function Scan_Dir($level, $AddToDB, $DBlink ,$ParentDirID){
  603. global $DirParentColName,$PicDateColumn,$PicThumbColumn,$PicDataColName,$PicDescColName,$PicDirColName,$DirTitleColName,$DBName,$DBHost,$DBUser,$DBPassword,$DBTablePic,$DBTableDir,$PicThumbColName, $PicMD5KeyColName;
  604. $DirName=getcwd();
  605. if ($CDir=opendir($DirName)){
  606. if ($AddToDB){
  607. $DirName=strrchr($DirName,'/');
  608. $DirName=mysql_escape_string($DirName);
  609. $result = mysql_db_query ($DBName,"INSERT INTO $DBTableDir SET $DirTitleColName='$DirName',$DirParentColName='$ParentDirID'",$DBlink)
  610. or die("Invalid query: " . mysql_error());
  611. $result = mysql_db_query ($DBName,"Select * FROM $DBTableDir ",$DBlink)
  612. or die("Invalid query: " . mysql_error());
  613. $CDirID = mysql_num_rows($result);
  614. };
  615. echo "\nDescriptor: ".$CDir." CdirID=".$CDirID."\n";
  616. echo "Path: ".getcwd()."\n";
  617. while (false !== ($entry=readdir($CDir))){
  618. if (($entry !==".") && ($entry !=="..")){
  619. if ( ($level>0) && (is_dir($entry) )){
  620. if (chdir($entry)){
  621. Scan_Dir($level-1,$AddToDB,$DBlink,$CDirID);
  622. chdir("..");
  623. };
  624. };
  625. if (preg_match("/^.+\.(jpeg|jpg|gif|bmp|pcx|bmx|png)/i",$entry)){
  626. echo "Adding File:".$entry;
  627. if ($AddToDB) {
  628. $MD5String=md5_file($entry);#bin2hex(md5_file($entry,true));
  629. echo "MD5: $MD5String ";
  630. $handle = fopen($entry, 'r') or die( "Cannot open temporary Image\n\n");
  631. $BytesRead=fread($handle,filesize($entry));
  632. if ( !$BytesRead ){
  633. echo " Read Failed Or File is Empty\n";
  634. } else {
  635. echo " Ok\n";
  636. };
  637. fclose($handle);
  638. # Altering thumbnails making
  639. # $ThumbPic = make_thumb($entry);
  640. $EThumbPic = "NULL";# mysql_escape_string($ThumbPic);
  641. $EPicture = mysql_escape_string($BytesRead);
  642. $entry=mysql_escape_string($entry);
  643. $result = mysql_db_query ($DBName,"INSERT INTO $DBTablePic SET $PicDataColName='$EPicture', $PicDescColName='$entry', $PicDirColName='$CDirID', $PicMD5KeyColName='$MD5String' , $PicThumbColName=$EThumbPic ",$DBlink)
  644. or die("Invalid query: " . mysql_error());
  645. };
  646. };
  647. };
  648. };
  649. closedir($CDir);
  650. };
  651. };
  652. function GenerateNewUserMail()
  653. {
  654. global $CUser, $Labels;
  655. $msg = $Labels->GetLabel('_MSGHDR_');
  656. $msg .= '<br><br>';
  657. $msg .= $Labels->GetLabel('_MSGBDY_NEWUSR_');
  658. $msg = nl2br( $msg );
  659. $msg = str_replace( '%LOGIN_ID%', $CUser['id'], $msg );
  660. $msg = str_replace( '%PASSWORD%', $CUser['password'], $msg );
  661. SendEmail( $CUser['email'], $CUser['name'], "noreply@vicesisters.com", "Welcome to ViceSisters!", null, $msg );
  662. }
  663. function CountryFlagURL($CountryID){
  664. global $DATABASE;
  665. $QS="SELECT sign FROM countries WHERE id={$CountryID}";
  666. $Val=$DATABASE->Query($QS,true);
  667. $F_path='style/img/flags/'. strtolower($Val[0]['sign']).'.png';
  668. $N_path='style/img/flags/xx.png';
  669. if(file_exists($F_path)) return $F_path; else return $N_path;
  670. }
  671. function SendEmail($email,$toname,$from,$fromname,$body,$subject='ViceSisters, Message response from your profile: ', $AdminDir='', $echo_to_screen = false ){
  672. global $MailAgent;
  673. //$message=htmlspecialchars($body);
  674. $headers = 'MIME-Version: 1.0' . "\r\n";
  675. $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
  676. $headers .= "To: $email\r\n";
  677. $headers .= "From: $fromname <$from>\r\n";
  678. $headers .= "Subject: $subject\r\n";
  679. $msg='<html>
  680. <head>
  681. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  682. <title>ViceSisters Mail Notification</title>
  683. </head>
  684. <body>
  685. '.nl2br($body).'
  686. <hr noshade size=1px>
  687. This message was automatically generated by <a href="http://www.vicesisters.com/">ViceSisters.com</a> Mailer.
  688. <br>
  689. Please do not reply to this message.
  690. </body></html>';
  691. if( !$echo_to_screen )
  692. {
  693. if ($MailAgent=='SENDMAIL'){
  694. //$tpl=file_get_contents("../functions/m_t.data");
  695. $tpl=file_get_contents( $AdminDir . "../functions/mail_template.html");
  696. $tpl=str_replace('<%MAIL_TO%>',"\"{$toname}\" <{$email}>",$tpl);
  697. //$tpl=str_replace('<%MAIL_SUBJECT>',"\"{$subject}\"",$tpl);
  698. $tpl=str_replace('<%MAIL_SUBJECT%>',$subject,$tpl);
  699. $tpl=str_replace('<%MAIL_BODY%>',$body,$tpl);
  700. @ini_set(sendmail_from, "$from"); // the INI lines are to force the From Address to be used !
  701. //if (!@mail($email, $subject, $msg, $headers, "-f$from"))
  702. if ( !mail($email, $subject,'',$tpl, "-f$from"))
  703. $return = false;
  704. else
  705. $return = true;
  706. @ini_restore(sendmail_from);
  707. return $return;
  708. } elseif ( $MailAgent=='CGP'){
  709. return Mailer($email,$subject,$body);
  710. } else {
  711. echo $headers.$msg;
  712. return true;
  713. };
  714. } else {
  715. echo $headers.$msg;
  716. return true;
  717. };
  718. };
  719. function Mailer( $to, $subject, $body, $id = '' ){
  720. global $CGP_SubmitPath;
  721. $tpl = '../functions/mail_template.html';
  722. if( !isset($id) || $id == '' )
  723. $id = rand( 1, 1000000 );
  724. $msg = file_get_contents( $tpl );
  725. $msg = str_replace( '<%MAIL_TO%>', $to, $msg );
  726. $msg = str_replace( '<%MAIL_SUBJECT%>', $subject, $msg );
  727. $msg = str_replace( '<%MAIL_BODY%>', $body, $msg );
  728. $fH = fopen( $CGP_SubmitPath . md5($to . time() . $id) . $id . '.sub', "w" );
  729. if( !$fH )
  730. return false;
  731. fwrite( $fH, $msg, strlen($msg) );
  732. fclose( $fH );
  733. return true;
  734. }
  735. ?>