Best Atoum code snippet using file.closeFile
index.php
Source:index.php
...213 continue;214 }215 $r_arr[]=$line;216 }217 closeFile ($rp);218 list($r_no,$oyasub,$n_,$v_,$c_,$u_,$img_,$_,$_,$thumb_,$pt_,$md5_,$to_,$pch_,$postedtime,$fp_time_,$h_,$uid_,$h_,$r_oya)=explode("\t",trim($r_arr[0]));219 //ã¬ã¹ãã¡ã¤ã«ã®1è¡ç®ã®ãã§ãã¯ãçµéæ¥æ°ããã°ã®1è¡ç®ã'oya'ãã©ãã確èªã220 $check_elapsed_days = check_elapsed_days($postedtime);221 $count_r_arr=count($r_arr);222 if($pictmp2){//ãçµµããã®æã¯æ°è¦æ稿ã«ãã223 //ãçµµããã®æã«æ¥æ°ãçµéãã¦ãããæ°è¦æ稿ã224 //ãçµµããã®æã«æ大ã¬ã¹æ°ãè¶
éãã¦ãããæ°è¦æ稿ã225 if($resto && (!$check_elapsed_days || $count_r_arr>$max_res || $r_no!==$resto || $r_oya!=='oya')){226 $resto='';227 }228 }229 if($resto && ($r_no!==$resto || $r_oya!=='oya')){230 return error($en? 'The article does not exist.':'è¨äºãããã¾ããã');231 }232 //ãçµµãã以å¤ã233 if($resto && !$check_elapsed_days){//æå®ããæ¥æ°ããå¤ãã¹ã¬ããã«ã¯æ稿ã§ããªãã234 return error($en? 'This thread is too old to post.':'ãã®ã¹ã¬ããã«ã¯æ稿ã§ãã¾ããã');235 }236 if($resto && $count_r_arr>$max_res){//æ大ã¬ã¹æ°è¶
éã237 return error($en?'The maximum number of replies has been exceeded.':'æ大ã¬ã¹æ°ãè¶
éãã¦ãã¾ãã');238 }239 $sub='Re: '.$oyasub;240 }241 //ãã¡ã¤ã«ã¢ãããã¼ã242 $up_tempfile = isset($_FILES['imgfile']['tmp_name']) ? $_FILES['imgfile']['tmp_name'] : ''; // ä¸æãã¡ã¤ã«å243 if(isset($_FILES['imgfile']['error']) && in_array($_FILES['imgfile']['error'],[1,2])){//容éãªã¼ãã¼244 return error($en? "Upload failed.The file size is too big.":"ã¢ãããã¼ãã«å¤±æãã¾ããããã¡ã¤ã«ãµã¤ãºã大ãããã¾ãã");245 } 246 if ($up_tempfile && $_FILES['imgfile']['error'] === UPLOAD_ERR_OK && ($use_upload || $adminpost)){247 if($resto && $up_tempfile && !$use_res_upload && !$adminpost){248 safe_unlink($up_tempfile);249 return error($en? 'You are not logged in in diary mode.':'æ¥è¨ã«ãã°ã¤ã³ãã¦ãã¾ããã');250 }251 $img_type = isset($_FILES['imgfile']['type']) ? $_FILES['imgfile']['type'] : '';252 if (!in_array($img_type, ['image/gif', 'image/jpeg', 'image/png','image/webp'])) {253 safe_unlink($up_tempfile);254 return error($en? 'This file is an unsupported format.':'対å¿ãã¦ããªããã©ã¼ãããã§ãã');255 }256 $upfile=TEMP_DIR.$time.'.tmp';257 move_uploaded_file($up_tempfile,$upfile);258 $tool = 'upload'; 259 260 }261 //ãçµµããã¢ãããã¼ã262 if($pictmp2 && is_file($tempfile)){263 $upfile=TEMP_DIR.$time.'.tmp';264 copy($tempfile, $upfile);265 chmod($upfile,0606);266 }267 //POSTãããå¤ããã°ãã¡ã¤ã«ã«æ ¼ç´ããæ¸å¼ã«ãã©ã¼ããã268 $formatted_post=create_formatted_text_from_post($name,$sub,$url,$com);269 $name = $formatted_post['name'];270 $sub = $formatted_post['sub'];271 $url = $formatted_post['url'];272 $com = $formatted_post['com'];273 if(!$name){274 if($name_input_required){275 safe_unlink($upfile);276 return error($en?'Please enter your name.':'ååãããã¾ããã');277 }else{278 $name='anonymous';279 }280 }281 if(!$upfile&&!$com){282 return error($en?'Please write something.':'ä½ãæ¸ãã¦ä¸ããã');283 }284 if(!$resto && !$allow_coments_only && !$upfile && !$adminpost){285 return error($en?'Please attach an image.':'ç»åãæ·»ä»ãã¦ãã ããã');286 }287 $hash = $pwd ? password_hash($pwd,PASSWORD_BCRYPT,['cost' => 5]) : '';288 setcookie("namec",$name,time()+(60*60*24*30),"","",false,true);289 setcookie("urlc",$url,time()+(60*60*24*30),"","",false,true);290 setcookie("pwdc",$pwd,time()+(60*60*24*30),"","",false,true);291 //ã¦ã¼ã¶ã¼id292 $userid = t(getId($userip));293 $verified = ($adminpost||($admin_pass && $pwd===$admin_pass)) ? 'adminpost' : ''; 294 //å
¨ä½ãã°ãéã295 $fp=fopen(LOG_DIR."alllog.log","r+");296 if(!$fp){297 safe_unlink($upfile);298 return error($en?'The operation failed.':'失æãã¾ããã');299 }300 flock($fp, LOCK_EX);301 $alllog_arr=[];302 while ($_line = fgets($fp)) {303 if(!trim($_line)){304 continue;305 }306 $alllog_arr[]=$_line;307 }308 $img_md5='';309 //ãã§ãã¯ããã¹ã¬ããæ°ãç»åãããªã15ãã³ã¡ã³ãã®ã¿ãªã5 310 $n= $upfile ? 15 : 5;311 $chk_log_arr=array_slice($alllog_arr,0,$n,false);312 $chk_com=[];313 $chk_images=[];314 $chk_resnos=[];315 foreach($chk_log_arr as $chk_log){316 list($chk_resno)=explode("\t",$chk_log);317 $chk_resnos[]=$chk_resno;318 }319 if($resto){//ã¬ã¹ã®æã¯ã¬ã¹ãã¡ã¤ã«ããã§ãã¯ã«è¿½å 320 $chk_resnos=array_merge($chk_resnos,[$resto]);321 } 322 foreach($chk_resnos as $chk_resno){323 if(is_file(LOG_DIR."{$chk_resno}.log")){324 $cp=fopen(LOG_DIR."{$chk_resno}.log","r");325 while($line=fgets($cp)){326 if(!trim($line)){327 continue;328 }329 $chk_ex_line=explode("\t",trim($line));330 list($no_,$sub_,$name_,$verified_,$com_,$url_,$imgfile_,$w_,$h_,$thumbnail_,$painttime_,$log_md5_,$tool_,$pchext_,$time_,$first_posted_time_,$host_,$userid_,$hash_,$oya_)=$chk_ex_line;331 $chk_time=(strlen($time_)>15) ? substr($time_,0,-6) : substr($time_,0,-3);332 if((int)time()-(int)$chk_time<1){//æ稿æå»ã®éè¤åé¿ã主ç®ç333 safe_unlink($upfile);334 closeFile($fp);335 safe_unlink($upfile);336 return error($en? 'Please wait a little.':'å°ãå¾
ã£ã¦ãã ããã');337 }338 if($host === $host_){339 $chk_com[$time_]=$chk_ex_line;//ã³ã¡ã³ã340 }341 if($upfile && $imgfile_){342 $chk_images[$time_]=$chk_ex_line;//ç»å343 }344 }345 fclose($cp);346 }347 }348 krsort($chk_com);349 $chk_com=array_slice($chk_com,0,20,false);350 foreach($chk_com as $line){351 list($_no_,$_sub_,$_name_,$_verified_,$_com_,$_url_,$_imgfile_,$_w_,$_h_,$_thumbnail_,$_painttime_,$_log_md5_,$_tool_,$_pchext_,$_time_,$_first_posted_time_,$_host_,$_userid_,$_hash_,$_oya_)=$line;352 if($com && ($com === $_com_)){353 closeFile($fp);354 safe_unlink($upfile);355 return error($en?'Post once by this comment.':'åãã³ã¡ã³ããããã¾ããã');356 }357 // ç»åã¢ãããã¼ãã¨ç»åãªãããããã®å¾
æ©æé358 $_chk_time_=(strlen($_time_)>15) ? substr($_time_,0,-6) : substr($_time_,0,-3);359 if($upfile && ((int)time()-(int)$_chk_time_<30)||(!$upfile && ((int)time()-(int)$_chk_time_)<15)){360 closeFile($fp);361 safe_unlink($upfile);362 return error($en? 'Please wait a little.':'å°ãå¾
ã£ã¦ãã ããã');363 }364 }365 if($upfile && is_file($upfile)){366 if(!$pictmp2){//å®ä½ãã¼ã¿ã®ç¸®å°367 $max_px=isset($max_px) ? $max_px : 1024;368 thumb(TEMP_DIR,$time.'.tmp',$time,$max_px,$max_px,['toolarge'=>1]);369 } 370 clearstatcache();371 $filesize=filesize($upfile);372 if($filesize > 800 * 1024){//æå®ãµã¤ãºãè¶
ãã¦ããã373 if ($im_jpg = png2jpg($upfile)) {//PNGâJPEGèªåå¤æ374 if(filesize($im_jpg)<$filesize){//JPEGã®ã»ããå°ããæã ã375 rename($im_jpg,$upfile);//JPEGã§ä¿å376 chmod($upfile,0606);377 } else{//PNGãããã¡ã¤ã«ãµã¤ãºã大ãããªãæã¯378 unlink($im_jpg);//ä½æããJPEGç»åãåé¤379 }380 }381 }382 if(!$pictmp2){383 clearstatcache();384 if(filesize($upfile) > $max_kb*1024){385 closeFile($fp);386 safe_unlink($upfile);387 return error($en? "Upload failed. File size exceeds {$max_kb}kb.":"ã¢ãããã¼ãã«å¤±æãã¾ããããã¡ã¤ã«å®¹éã{$max_kb}kbãè¶
ãã¦ãã¾ãã");388 }389 }390 list($w,$h)=getimagesize($upfile);391 $_img_type=mime_content_type($upfile);392 $ext=getImgType ($_img_type);393 if (!$ext) {394 closeFile($fp);395 safe_unlink($upfile);396 return error($en? 'This file is an unsupported format.':'対å¿ãã¦ããªããã©ã¼ãããã§ãã');397 }398 //åãç»åãã§ã㯠ã¢ãããã¼ãç»åã®ã¿ãã§ãã¯ãã¦ãçµµããã¯ãã§ãã¯ããªã399 if(!$pictmp2){400 401 $img_md5=md5_file($upfile);402 foreach($chk_images as $line){403 list($no_,$sub_,$name_,$verified_,$com_,$url_,$imgfile_,$w_,$h_,$thumbnail_,$painttime_,$log_md5,$tool_,$pchext_,$time_,$first_posted_time_,$host_,$userid_,$hash_,$oya_)=$line;404 if($log_md5 && ($log_md5 === $img_md5)){405 closeFile($fp);406 safe_unlink($upfile);407 return error($en?'Image already exists.':'åãç»åãããã¾ããã');408 }409 }410 }411 $imgfile=$time.$ext; 412 rename($upfile,IMG_DIR.$imgfile);413 }414 $src='';415 $pchext = '';416 if($pictmp2 && $imgfile){417 //PCHãã¡ã¤ã«ã¢ãããã¼ã418 // .pch, .spch,.chi,.psd ãã©ã³ã¯ ã©ãããè¿ã£ã¦ãã419 if ($pchext = check_pch_ext(TEMP_DIR.$picfile,['upload'=>true])) {420 $src = TEMP_DIR.$picfile.$pchext;421 $dst = IMG_DIR.$time.$pchext;422 if(copy($src, $dst)){423 chmod($dst,0606);424 }425 }426 }427 $thumbnail='';428 if($imgfile && is_file(IMG_DIR.$imgfile)){429 430 $max_w = $resto ? $res_max_w : $max_w; 431 $max_h = $resto ? $res_max_h : $max_h; 432 //縮å°è¡¨ç¤º433 list($w,$h)=image_reduction_display($w,$h,$max_w,$max_h);434 //ãµã ãã¤ã«435 if($use_thumb){436 if(thumb(IMG_DIR,$imgfile,$time,$max_w,$max_h)){437 $thumbnail='thumbnail';438 }439 }440 }441 //ãã°ã®çªå·ã®æ大å¤442 $no_arr = [];443 foreach($alllog_arr as $i => $_alllog){444 list($log_no,)=explode("\t",$_alllog);445 $no_arr[]=$log_no;446 }447 $max_no=0;448 if(!empty($no_arr)){449 $max_no=max($no_arr);450 }451 //æ¸ãè¾¼ããã°ã®æ¸å¼452 $line='';453 $newline='';454 if($resto){//ã¬ã¹ã®æã¯ã¹ã¬ããå¥ãã°ã«è¿½è¨455 //ãã¡ã¤ã«ããã¯ããç¶æ
ã§å度éã456 $rp=fopen(LOG_DIR."{$resto}.log","r+");457 if(!$rp){458 closeFile($fp);459 safe_unlink(IMG_DIR.$imgfile);460 return error($en?'The operation failed.':'失æãã¾ããã');461 }462 flock($rp, LOCK_EX);463 $r_arr=[];464 $r_oya='';465 $r_no='';466 while ($line = fgets($rp)) {467 if(!trim($line)){468 continue;469 }470 $r_arr[]=$line;471 }472 if(empty($r_arr)){473 closeFile($rp);474 closeFile($fp);475 safe_unlink(IMG_DIR.$imgfile);476 return error($en?'The operation failed.':'失æãã¾ããã');477 }478 //ãã¡ã¤ã«ããã¯ãããã£ãç¶æ
ã§å確èªã479 //ã¬ã¹å
ã¯oya?480 list($r_no,,,,,,,,,,,,,,,,,,,$r_oya)=explode("\t",trim($r_arr[0]));481 if($r_no!==$resto||$r_oya!=='oya'){482 closeFile($rp);483 closeFile($fp);484 safe_unlink(IMG_DIR.$imgfile);485 return error($en? 'The article does not exist.':'è¨äºãããã¾ããã');486 }487 $r_line = "$resto\t$sub\t$name\t$verified\t$com\t$url\t$imgfile\t$w\t$h\t$thumbnail\t$painttime\t$img_md5\t$tool\t$pchext\t$time\t$time\t$host\t$userid\t$hash\tres\n";488 $new_rline= implode("",$r_arr).$r_line;489 writeFile($rp,$new_rline);490 closeFile($rp);491 chmod(LOG_DIR.$resto.'.log',0600);492 if(!$sage){493 foreach($alllog_arr as $i =>$val){494 list($_no)=explode("\t",$val);495 if($resto==$_no){496 $newline = $val;//ã¬ã¹ãä»ããã¹ã¬ããã$newlineã«ä¿åããã¨ããå
¨ä½ãã°ã®å
é ã«è¿½å ãã¦ä¸ãã497 unset($alllog_arr[$i]);//ã¬ã¹ãä»ããã¹ã¬ãããå
¨ä½ãã°ãããã£ããåé¤498 break;499 }500 }501 }502 }else{503 //æå¾ã®è¨äºãã³ãã¼ã«+1504 $no=$max_no+1;505 $newline = "$no\t$sub\t$name\t$verified\t$com\t$url\t$imgfile\t$w\t$h\t$thumbnail\t$painttime\t$img_md5\t$tool\t$pchext\t$time\t$time\t$host\t$userid\t$hash\toya\n";506 file_put_contents(LOG_DIR.$no.'.log',$newline,LOCK_EX);//æ°è¦æ稿ã®æã¯ãè¨äºãã³ãã¼ã®ãã¡ã¤ã«ãä½æãã¦æ¸ãè¾¼ã507 chmod(LOG_DIR.$no.'.log',0600);508 }509 //ä¿å件æ°è¶
éå¦ç510 $countlog=count($alllog_arr);511 if($max_log && $countlog && ($max_log<=$countlog)){512 for($i=$max_log-1; $i<$countlog;++$i){513 if(!isset($alllog_arr[$i]) || !trim($alllog_arr[$i])){514 continue;515 }516 list($d_no,)=explode("\t",$alllog_arr[$i]);517 if(is_file(LOG_DIR."{$d_no}.log")){518 $dp = fopen(LOG_DIR."{$d_no}.log", "r");//åå¥ã¹ã¬ããã®ãã°ãéã519 flock($dp, LOCK_EX);520 while ($line = fgets($dp)) {521 if(!trim($line)){522 continue;523 }524 list($d_no,$_sub,$_name,$_verified,$_com,$_url,$d_imgfile,$_w,$_h,$_thumbnail,$_painttime,$_log_md5,$_tool,$_pchext,$d_time,$_first_posted_time,$_host,$_userid,$_hash,$_oya)=explode("\t",trim($line));525 delete_files ($d_imgfile, $d_time);//ä¸é£ã®ãã¡ã¤ã«ãåé¤526 }527 safe_unlink(LOG_DIR.$d_no.'.log');//ã¹ã¬ããåå¥ãã°ãã¡ã¤ã«åé¤528 closeFile($dp);529 } 530 unset($alllog_arr[$i]);//å
¨ä½ãã°è¨äºåé¤531 }532 }533 $newline.=implode("",$alllog_arr);534 writeFile ($fp, $newline);535 closeFile($fp);536 chmod(LOG_DIR.'alllog.log',0600);537 //ã¯ã¼ã¯ãã¡ã¤ã«åé¤538 safe_unlink($src);539 safe_unlink($tempfile);540 safe_unlink($up_tempfile);541 safe_unlink($upfile);542 safe_unlink(TEMP_DIR.$picfile.".dat");543 global $send_email,$to_mail,$root_url,$boardname;544 if($send_email){545 //template_ini.phpã§æªå®ç¾©ã®æã®åæå¤546 //ãã®ã¾ã¾ã§ãããã°å®ç¾©ä¸è¦547 defined('NOTICE_MAIL_TITLE') or define('NOTICE_MAIL_TITLE', 'è¨äºé¡å');548 defined('NOTICE_MAIL_IMG') or define('NOTICE_MAIL_IMG', 'æ稿ç»å');549 defined('NOTICE_MAIL_THUMBNAIL') or define('NOTICE_MAIL_THUMBNAIL', 'ãµã ãã¤ã«ç»å');550 defined('NOTICE_MAIL_ANIME') or define('NOTICE_MAIL_ANIME', 'ã¢ãã¡ãã¡ã¤ã«');551 defined('NOTICE_MAIL_URL') or define('NOTICE_MAIL_URL', 'è¨äºURL');552 defined('NOTICE_MAIL_REPLY') or define('NOTICE_MAIL_REPLY', 'ã¸ã®ã¬ã¹ãããã¾ãã');553 defined('NOTICE_MAIL_NEWPOST') or define('NOTICE_MAIL_NEWPOST', 'æ°è¦æ稿ãããã¾ãã');554 $data['to'] = $to_mail;555 $data['name'] = $name;556 $data['option'][] = 'URL,'.$url;557 $data['option'][] = NOTICE_MAIL_TITLE.','.$sub;558 if($imgfile) $data['option'][] = NOTICE_MAIL_IMG.','.$root_url.IMG_DIR.$imgfile;//æ¡å¼µåããã£ãã559 if(is_file(THUMB_DIR.$time.'s.jpg')) $data['option'][] = NOTICE_MAIL_THUMBNAIL.','.$root_url.THUMB_DIR.$time.'s.jpg';560 if($resto){561 $data['subject'] = '['.$boardname.'] No.'.$resto.NOTICE_MAIL_REPLY;562 $data['option'][] = "\n".NOTICE_MAIL_URL.','.$root_url.'?res='.$resto;563 }else{564 $data['subject'] = '['.$boardname.'] '.NOTICE_MAIL_NEWPOST;565 $data['option'][] = "\n".NOTICE_MAIL_URL.','.$root_url.'?res='.$no;566 }567 $data['comment'] = str_replace('"\n"',"\n",$com);568 noticemail::send($data);569 }570 //å¤ééä¿¡é²æ¢571 if($resto){572 return header('Location: ./?resno='.$resto.'#'.$time);573 }574 575return header('Location: ./');576}577//ãçµµããç»é¢578function paint(){579 global $boardname,$skindir,$pmax_w,$pmax_h,$en;580 $app = (string)filter_input(INPUT_POST,'app');581 $picw = filter_input(INPUT_POST,'picw',FILTER_VALIDATE_INT);582 $pich = filter_input(INPUT_POST,'pich',FILTER_VALIDATE_INT);583 $usercode = t((string)filter_input(INPUT_COOKIE, 'usercode'));584 $resto = t((string)filter_input(INPUT_POST, 'resto',FILTER_VALIDATE_INT));585 if(strlen($resto)>1000){586 return error($en?'Unknown error':'åé¡ãçºçãã¾ããã');587 }588 if($picw < 300) $picw = 300;589 if($pich < 300) $pich = 300;590 if($picw > $pmax_w) $picw = $pmax_w;591 if($pich > $pmax_h) $pich = $pmax_h;592 setcookie("appc", $app , time()+(60*60*24*30),"","",false,true);//ã¢ãã¬ããé¸æ593 setcookie("picwc", $picw , time()+(60*60*24*30),"","",false,true);//å¹
594 setcookie("pichc", $pich , time()+(60*60*24*30),"","",false,true);//é«ã595 $mode = filter_input(INPUT_POST, 'mode');596 $imgfile='';597 $pchfile='';598 $img_chi='';599 $img_klecks='';600 $anime=true;601 $rep=false;602 $paintmode='paintcom';603 session_sta();604 $adminpost=adminpost_valid();605 //pchãã¡ã¤ã«ã¢ãããã¼ããã¤ã³ã606 if($adminpost){607 $pchfilename = isset($_FILES['pchup']['name']) ? basename($_FILES['pchup']['name']) : '';608 609 $pchtmp=isset($_FILES['pchup']['tmp_name']) ? $_FILES['pchup']['tmp_name'] : '';610 if(isset($_FILES['pchup']['error']) && in_array($_FILES['pchup']['error'],[1,2])){//容éãªã¼ãã¼611 return error($en? 'The file size is too big.':'ãã¡ã¤ã«ãµã¤ãºã大ãããã¾ãã');612 } 613 if ($pchtmp && $_FILES['pchup']['error'] === UPLOAD_ERR_OK){614 615 $time = (string)(time().substr(microtime(),2,6));616 $pchext=pathinfo($pchfilename, PATHINFO_EXTENSION);617 $pchext=strtolower($pchext);//ãã¹ã¦å°æåã«618 //æ¡å¼µåãã§ãã¯619 if (!in_array($pchext, ['pch','chi','psd'])) {620 return error($en?'This file does not supported by the ability to load uploaded files onto the canvas.Supported formats are pch and chi.':'ã¢ãããã¼ããã¤ã³ãã§ä½¿ç¨ã§ãããã¡ã¤ã«ã¯pchãchiãpsdã§ãã');621 }622 $pchup = TEMP_DIR.'pchup-'.$time.'-tmp.'.$pchext;//ã¢ãããã¼ãããããã¡ã¤ã«å623 if(move_uploaded_file($pchtmp, $pchup)){//ã¢ãããã¼ãæåãªãç¶è¡624 $pchup=TEMP_DIR.basename($pchup);//ãã¡ã¤ã«ãéããã£ã¬ã¯ããªãåºå®625 if(!in_array(mime_content_type($pchup),["application/octet-stream","application/gzip","image/vnd.adobe.photoshop"])){626 safe_unlink($pchup);627 return error($en?'This file does not supported':'ãã¡ã¤ã«å½¢å¼ãä¸è´ãã¾ããã');628 }629 if($pchext==="pch"){630 $app='neo';631 $pchfile = $pchup;632 } elseif($pchext==="chi"){633 $app='chi';634 $img_chi = $pchup;635 } elseif($pchext==="psd"){636 $app='klecks';637 $img_klecks = $pchup;638 }639 }640 }641 }642 $repcode='';643 if($mode==="contpaint"){644 $imgfile = (string)filter_input(INPUT_POST,'imgfile');645 $ctype = (string)filter_input(INPUT_POST, 'ctype');646 $type = (string)filter_input(INPUT_POST, 'type');647 $no = filter_input(INPUT_POST, 'no',FILTER_VALIDATE_INT);648 $time = (string)filter_input(INPUT_POST, 'time');649 if(($type!=='rep') && is_file(LOG_DIR."{$no}.log")){650 651 $rp=fopen(LOG_DIR."{$no}.log","r");652 while ($line = fgets($rp)) {653 if(!trim($line)){654 continue;655 }656 list($no_,$sub_,$name_,$verified_,$com_,$url_,$imgfile_,$w_,$h_,$thumbnail_,$painttime_,$log_md5_,$tool_,$pchext_,$time_,$first_posted_time_,$host_,$userid_,$hash_,$oya_)=explode("\t",trim($line));657 if($time===$time_ && (int)$no==$no_){658 $resto=(trim($oya_)==='res') ? $no_ : '';659 break;660 }661 }662 closeFile ($rp);663 }664 list($picw,$pich)=getimagesize(IMG_DIR.$imgfile);//ãã£ã³ãã¹ãµã¤ãº665 $_pch_ext = check_pch_ext(IMG_DIR.$time,['upload'=>true]);666 if($ctype=='pch'&& $_pch_ext){//åç»ããç¶ã667 $pchfile = IMG_DIR.$time.$_pch_ext;668 }669 if($ctype=='img' && is_file(IMG_DIR.$imgfile)){//ç»åããç¶ã670 $anime=false;671 $animeform = false;672 $anime= false;673 $imgfile = IMG_DIR.$imgfile;674 if($_pch_ext==='.chi'){675 $img_chi =IMG_DIR.$time.'.chi';676 }677 if($_pch_ext==='.psd'){678 $img_klecks =IMG_DIR.$time.'.psd';679 }680 }681 if($type==='rep'){//ç»åå·®ãæã682 $rep=true;683 $pwd = t((string)filter_input(INPUT_POST, 'pwd'));684 $pwd=$pwd ? $pwd : t((string)filter_input(INPUT_COOKIE,'pwdc'));//æªå
¥åãªãCookieã®ãã¹ã¯ã¼ã685 if(strlen($pwd) > 100) return error($en? 'Password is too long.':'ãã¹ã¯ã¼ããé·ããã¾ãã');686 if($pwd){687 $pwd=openssl_encrypt ($pwd,CRYPT_METHOD, CRYPT_PASS, true, CRYPT_IV);//æå·å688 $pwd=bin2hex($pwd);//16é²æ°ã«689 }690 $userip = get_uip();691 $paintmode='picrep';692 $id=$time; //ãã³ãã¬ã¼ãã§ã使ç¨ã693 $repcode = substr(crypt(md5($no.$id.$userip.$pwd.date("Ymd", time())),time()),-8);694 //念ã®çºã«ã¨ã¹ã±ã¼ãæåãããã°ã¢ã«ãã¡ãããã«å¤æ695 $repcode = strtr($repcode,"!\"#$%&'()+,/:;<=>?@[\\]^`/{|}~","ABCDEFGHIJKLMNOabcdefghijklmn");696 }697 }698 $parameter_day = date("Ymd");//JavaScriptã®ãã£ãã·ã¥å¶å¾¡699 switch($app){700 case 'chi'://ChickenPaint701 702 $tool='chi';703 // HTMLåºå704 $templete='paint_chi.html';705 return include __DIR__.'/'.$skindir.$templete;706 case 'klecks':707 $tool ='klecks';708 $templete='paint_klecks.html';709 return include __DIR__.'/'.$skindir.$templete;710 case 'neo'://PaintBBS NEO711 $tool='neo';712 $appw = $picw + 150;//NEOã®å¹
713 $apph = $pich + 172;//NEOã®é«ã714 if($apph < 560){$apph = 560;}//æä½é«715 //åçãã¬ãã716 $palettetxt = $en? (is_file('palette_en.txt') ? 'palette_en.txt':'palette.txt') : 'palette.txt'; 717 $lines =file($palettetxt);718 $initial_palette = 'Palettes[0] = "#000000\n#FFFFFF\n#B47575\n#888888\n#FA9696\n#C096C0\n#FFB6FF\n#8080FF\n#25C7C9\n#E7E58D\n#E7962D\n#99CB7B\n#FCECE2\n#F9DDCF";';719 $pal=[];720 $DynP=[];721 foreach ( $lines as $i => $line ) {722 $line=str_replace(["\r","\n","\t"],"",$line);723 $line=h($line);724 list($pid,$pname,$pal[0],$pal[2],$pal[4],$pal[6],$pal[8],$pal[10],$pal[1],$pal[3],$pal[5],$pal[7],$pal[9],$pal[11],$pal[12],$pal[13]) = explode(",", $line);725 $DynP[]=$pname;726 $p_cnt=$i+1;727 $palettes = 'Palettes['.$p_cnt.'] = "#';728 ksort($pal);729 $palettes.=implode('\n#',$pal);730 $palettes.='";';731 $arr_pal[$i] = $palettes;732 }733 $palettes=$initial_palette.implode('',$arr_pal);734 $palsize = count($DynP) + 1;735 foreach ($DynP as $p){736 $arr_dynp[] = $p;737 }738 // HTMLåºå739 $templete='paint_neo.html';740 return include __DIR__.'/'.$skindir.$templete;741 default:742 return error($en?'The operation failed.':'失æãã¾ããã');743 }744}745// ãçµµããã³ã¡ã³ã 746function paintcom(){747 global $use_aikotoba,$boardname,$home,$skindir,$sage_all,$en;748 $token=get_csrf_token();749 $userip = get_uip();750 $usercode = filter_input(INPUT_COOKIE,'usercode');751 //ãã³ãã©ãªç»åãªã¹ãä½æ752 $uresto = '';753 $handle = opendir(TEMP_DIR);754 $tmps = [];755 while ($file = readdir($handle)) {756 if(!is_dir($file) && pathinfo($file, PATHINFO_EXTENSION)==='dat') {757 $fp = fopen(TEMP_DIR.$file, "r");758 $userdata = fread($fp, 1024);759 fclose($fp);760 list($uip,$uhost,$uagent,$imgext,$ucode,,$starttime,$postedtime,$uresto,$tool) = explode("\t", rtrim($userdata));761 $file_name = pathinfo($file, PATHINFO_FILENAME);762 $uresto = $uresto ? 'res' :''; 763 if(is_file(TEMP_DIR.$file_name.$imgext)){ //ç»åãããã°ãªã¹ãã«è¿½å 764 if($ucode === $usercode||$uip === $userip){765 $tmps[] = [$file_name.$imgext,$uresto];766 }767 }768 }769 }770 closedir($handle);771 if(!empty($tmps)){772 $pictmp = 2;773 sort($tmps);774 reset($tmps);775 foreach($tmps as $tmp){776 list($tmpfile,$resto)=$tmp;777 $tmp_img['src'] = TEMP_DIR.$tmpfile;778 $tmp_img['srcname'] = $tmpfile;779 $tmp_img['slect_src_val'] = $tmpfile.','.$resto;780 $tmp_img['date'] = date("Y/m/d H:i", filemtime($tmp_img['src']));781 $out['tmp'][] = $tmp_img;782 }783 }784 $aikotoba=aikotoba_valid();785 if(!$use_aikotoba){786 $aikotoba=true;787 }788 $namec = filter_input(INPUT_COOKIE,'namec');789 $pwdc=filter_input(INPUT_COOKIE,'pwdc');790 $urlc=(string)filter_input(INPUT_COOKIE,'urlc');791 // HTMLåºå792 $templete='paint_com.html';793 return include __DIR__.'/'.$skindir.$templete;794}795//ã³ã³ãã£ãã¥ã¼åç»é¢796function to_continue(){797 global $boardname,$use_diary,$use_aikotoba,$set_nsfw,$skindir,$en;798 $appc=(string)filter_input(INPUT_COOKIE,'appc');799 $pwdc=filter_input(INPUT_COOKIE,'pwdc');800 $no = (string)filter_input(INPUT_GET, 'no',FILTER_VALIDATE_INT);801 $id = (string)filter_input(INPUT_GET, 'id');//intã®ç¯å²å¤802 $flag = false;803 if(is_file(LOG_DIR."{$no}.log")){804 805 $rp=fopen(LOG_DIR."{$no}.log","r");806 while ($line = fgets($rp)) {807 if(!trim($line)){808 continue;809 }810 list($_no,$sub,$name,$verified,$com,$url,$imgfile,$w,$h,$thumbnail,$painttime,$log_md5,$tool,$pchext,$time,$first_posted_time,$host,$userid,$hash,$oya)=explode("\t",trim($line));811 if($id===$time && $no===$_no){812 $flag=true;813 break;814 }815 }816 closeFile ($rp);817 }818 if(!$flag || !$imgfile || !is_file(IMG_DIR.$imgfile)){//ç»åãç¡ãæã¯å¦çããªã819 return error($en? 'The article does not exist.':'è¨äºãããã¾ããã');820 }821 $picfile = IMG_DIR.$imgfile;822 list($picw, $pich) = getimagesize($picfile);823 $select_app = false;824 $app_to_use = false;825 $ctype_pch = false;826 $download_app_dat=true;827 if(($pchext==='.pch')&&is_file(IMG_DIR.$time.'.pch')){828 $ctype_pch = true;829 $app_to_use = "neo";830 831 }elseif(($pchext==='.chi')&&is_file(IMG_DIR.$time.'.chi')){832 $app_to_use = 'chi';833 }elseif(($pchext==='.psd')&&is_file(IMG_DIR.$time.'.psd')){834 $app_to_use = 'klecks';835 }else{836 $select_app = true;837 $download_app_dat=false;838 }839 //æ¥è¨å¤å®å¦ç840 session_sta();841 $adminpost=adminpost_valid();842 $adminmode = ($adminpost||admindel_valid());843 $aikotoba=aikotoba_valid();844 if(!$use_aikotoba){845 $aikotoba=true;846 }847 // nsfw848 $nsfwc=filter_input(INPUT_COOKIE,'nsfwc',FILTER_VALIDATE_BOOLEAN);849 // HTMLåºå850 $templete='continue.html';851 return include __DIR__.'/'.$skindir.$templete;852 853}854//ã¢ããªåºæãã¡ã¤ã«ã®ãã¦ã³ãã¼ã855function download_app_dat(){856 global $en;857 $pwd=filter_input(INPUT_POST,'pwd');858 $no = (string)filter_input(INPUT_POST, 'no',FILTER_VALIDATE_INT);859 $id = (string)filter_input(INPUT_POST, 'id');//intã®ç¯å²å¤860 if(!is_file(LOG_DIR."{$no}.log")){861 return error($en? 'The article does not exist.':'è¨äºãããã¾ããã');862 }863 $rp=fopen(LOG_DIR."{$no}.log","r");864 $flag=false;865 while ($line = fgets($rp)) {866 if(!trim($line)){867 continue;868 }869 list($_no,$sub,$name,$verified,$com,$url,$imgfile,$w,$h,$thumbnail,$painttime,$log_md5,$tool,$pchext,$time,$first_posted_time,$host,$userid,$hash,$oya)=explode("\t",trim($line));870 if($id==$time && $no===$_no){871 if(!adminpost_valid()&&!admindel_valid()&&(!$pwd || !password_verify($pwd,$hash))){872 return error($en?'Password is incorrect.':'ãã¹ã¯ã¼ããéãã¾ãã');873 }874 $flag=true;875 break;876 } 877 }878 closeFile ($rp);879 $filepath= ($flag && is_file(IMG_DIR.$time.$pchext)) ? IMG_DIR.$time.$pchext : '';880 if(!$filepath){881 return error($en?'The operation failed.':'失æãã¾ããã');882 }883 $mime_type = mime_content_type($filepath);884 header('Content-Type: '.$mime_type);885 header('Content-Length: '.filesize($filepath));886 header('Content-Disposition: attachment; filename="'.h(basename($filepath)).'"');887 readfile($filepath);888}889// ç»åå·®ãæã890function img_replace(){891 global $use_thumb,$max_w,$max_h,$res_max_w,$res_max_h,$max_px,$en,$use_upload;892 $no = t((string)filter_input(INPUT_POST, 'no',FILTER_VALIDATE_INT));893 $no = $no ? $no :t((string)filter_input(INPUT_GET, 'no',FILTER_VALIDATE_INT));894 $id = t((string)filter_input(INPUT_POST, 'id'));//intã®ç¯å²å¤895 $id = $id ? $id :t((string)filter_input(INPUT_GET, 'id'));896 $getpwd = t((string)filter_input(INPUT_GET, 'pwd'));897 $postpwd = t((string)filter_input(INPUT_POST, 'pwd'));898 $repcode = t((string)filter_input(INPUT_GET, 'repcode'));899 $userip = t(get_uip());900 //ãã¹ãåå¾901 $host = t(gethostbyaddr($userip));902 //ã¦ã¼ã¶ã¼id903 $userid = t(getId($userip));904 $getpwd = $getpwd ? hex2bin($getpwd): '';//ãã¤ããªã«905 $pwd = $getpwd ? 906 openssl_decrypt($getpwd,CRYPT_METHOD, CRYPT_PASS, true, CRYPT_IV):$postpwd;//復å·å907 if(strlen($pwd) > 100) return error($en? 'Password is too long.':'ãã¹ã¯ã¼ããé·ããã¾ãã');908 $adminpost=adminpost_valid();909 $admindel=admindel_valid();910 //ã¢ãããã¼ãç»åã®å·®ãæã911 $up_tempfile = isset($_FILES['imgfile']['tmp_name']) ? $_FILES['imgfile']['tmp_name'] : ''; // ä¸æãã¡ã¤ã«å912 if (isset($_FILES['imgfile']['error']) && $_FILES['imgfile']['error'] === UPLOAD_ERR_NO_FILE){913 return error($en?'Please attach an image.':'ç»åãæ·»ä»ãã¦ãã ããã');914 } 915 if(isset($_FILES['imgfile']['error']) && in_array($_FILES['imgfile']['error'],[1,2])){//容éãªã¼ãã¼916 return error($en? "Upload failed.The file size is too big.":"ã¢ãããã¼ãã«å¤±æãã¾ããããã¡ã¤ã«ãµã¤ãºã大ãããã¾ãã");917 } 918 $is_upload=false;919 $tool = '';920 if ($up_tempfile && $_FILES['imgfile']['error'] === UPLOAD_ERR_OK && ($use_upload || $admindel)){921 $img_type = isset($_FILES['imgfile']['type']) ? $_FILES['imgfile']['type'] : '';922 if (!in_array($img_type, ['image/gif', 'image/jpeg', 'image/png','image/webp'])) {923 safe_unlink($up_tempfile);924 return error($en? 'This file is an unsupported format.':'対å¿ãã¦ããªããã©ã¼ãããã§ãã');925 }926 check_csrf_token();927 $is_upload = true;928 $tool = 'upload';929 }930 $tempfile='';931 $file_name='';932 $starttime='';933 $postedtime='';934 $repfind=false;935 if(!$is_upload){936 /*--- ãã³ãã©ãªææ» ---*/937 $handle = opendir(TEMP_DIR);938 while ($file = readdir($handle)) {939 if(!is_dir($file) && pathinfo($file, PATHINFO_EXTENSION)==='dat') {940 $fp = fopen(TEMP_DIR.$file, "r");941 $userdata = fread($fp, 1024);942 fclose($fp);943 list($uip,$uhost,$uagent,$imgext,$ucode,$urepcode,$starttime,$postedtime,$uresto,$tool) = explode("\t", rtrim($userdata)."\t");//åºåãã®"\t"ãè¡æ«ã«944 $file_name = pathinfo($file, PATHINFO_FILENAME );//æ¡å¼µåé¤å»945 //ç»åããããèªèã³ã¼ããhitããã°æãã946 947 if($file_name && is_file(TEMP_DIR.$file_name.$imgext) && $urepcode === $repcode){948 $repfind=true;949 break;950 }951 }952 }953 closedir($handle);954 if(!$repfind){955 return error($en?'The operation failed.':'失æãã¾ããã');956 }957 $tempfile=TEMP_DIR.$file_name.$imgext;958 }959 if($up_tempfile && $is_upload && !is_file($up_tempfile)){960 return error($en?'Please attach an image.':'ç»åãæ·»ä»ãã¦ãã ããã');961 }962 //ãã°èªã¿è¾¼ã¿963 if(!is_file(LOG_DIR."{$no}.log")){964 if($is_upload){//該å½è¨äºãç¡ãæã¯ã¨ã©ã¼965 return error($en? 'The article does not exist.':'è¨äºãããã¾ããã');966 } 967 return paintcom();//該å½è¨äºãç¡ãæã¯æ°è¦æ稿ã968 }969 $fp=fopen(LOG_DIR."alllog.log","r+");970 flock($fp, LOCK_EX);971 $alllog_arr=[];972 while ($_line = fgets($fp)) {973 if(!trim($_line)){974 continue;975 }976 $alllog_arr[]=$_line; 977 }978 if(empty($alllog_arr)){979 closeFile($fp);980 return error($en?'The operation failed.':'失æãã¾ããã');981 }982 $rp=fopen(LOG_DIR."{$no}.log","r+");983 flock($rp, LOCK_EX);984 $r_arr=[];985 while ($line = fgets($rp)) {986 if(!trim($line)){987 continue;988 }989 $r_arr[]=$line;990 }991 if(empty($r_arr)){992 closeFile($rp);993 closeFile($fp);994 return error($en?'The operation failed.':'失æãã¾ããã');995 }996 $flag=false;997 foreach($r_arr as $i => $line){998 list($_no,$_sub,$_name,$_verified,$_com,$_url,$_imgfile,$_w,$_h,$_thumbnail,$_painttime,$_log_md5,$_tool,$_pchext,$_time,$_first_posted_time,$_host,$_userid,$_hash,$_oya)=explode("\t",trim($line));999 if($id===$_time && $no===$_no){1000 if(($is_upload) && ($_tool!=='upload')) {1001 closeFile($rp);1002 closeFile($fp);1003 return error($en?'The operation failed.':'失æãã¾ããã');1004 }1005 if(($is_upload && $admindel) || ($pwd && password_verify($pwd,$_hash))){1006 $flag=true;1007 break;1008 }1009 }1010 }1011 if(!check_elapsed_days($_time)&&(!$adminpost && !$admindel)){//æå®æ¥æ°ããå¤ãç»åå·®ãæãã¯æ°è¦æ稿ã«ãã1012 closeFile($rp);1013 closeFile($fp);1014 if($is_upload){1015 return error($en?'The operation failed.':'失æãã¾ããã');1016 } 1017 return paintcom();1018 }1019 if(!$flag){1020 closeFile($rp);1021 closeFile($fp);1022 return error($en?'The operation failed.':'失æãã¾ããã');1023 }1024 $time = (string)(time().substr(microtime(),2,6));1025 $testexts=['.gif','.jpg','.png','.webp'];1026 foreach($testexts as $testext){1027 if(is_file(IMG_DIR.$time.$testext)){1028 $time=(string)((int)time()+1).substr(microtime(),2,6);1029 break; 1030 }1031 }1032 1033 $upfile=TEMP_DIR.$time.'.tmp';1034 if($is_upload&&($_tool==='upload')){1035 if(is_file($up_tempfile)){1036 move_uploaded_file($up_tempfile,$upfile);1037 }1038 }else{1039 if(is_file($tempfile)){1040 copy($tempfile, $upfile);1041 }1042 }1043 if(!is_file($upfile)){1044 closeFile($rp);1045 closeFile($fp);1046 return error($en?'The operation failed.':'失æãã¾ããã');1047 } 1048 chmod($upfile,0606);1049 if($is_upload&&($_tool==='upload')){//å®ä½ãã¼ã¿ã®ç¸®å°1050 $max_px=isset($max_px) ? $max_px : 1024;1051 thumb(TEMP_DIR,$time.'.tmp',$time,$max_px,$max_px,['toolarge'=>1]);1052 } 1053 $filesize=filesize($upfile);1054 if($filesize > 800 * 1024){//æå®ãµã¤ãºãè¶
ãã¦ããã1055 if ($im_jpg = png2jpg($upfile)) {//PNGâJPEGèªåå¤æ1056 if(filesize($im_jpg)<$filesize){//JPEGã®ã»ããå°ããæã ã1057 rename($im_jpg,$upfile);//JPEGã§ä¿å1058 chmod($upfile,0606);1059 } else{//PNGãããã¡ã¤ã«ãµã¤ãºã大ãããªãæã¯1060 unlink($im_jpg);//ä½æããJPEGç»åãåé¤1061 }1062 }1063 }1064 1065 $img_type=mime_content_type($upfile);1066 $imgext = getImgType($img_type);1067 if (!$imgext) {1068 closeFile($fp);1069 closeFile($rp);1070 safe_unlink($upfile);1071 return error($en? 'This file is an unsupported format.':'対å¿ãã¦ããªããã©ã¼ãããã§ãã');1072 }1073 list($w, $h) = getimagesize($upfile);1074 $img_md5=md5_file($upfile);1075 1076 //ãã§ãã¯ããã¹ã¬ããæ°ã 1077 $n= 15;1078 $chk_log_arr=array_slice($alllog_arr,0,$n,false);1079 $chk_resnos=[];1080 foreach($chk_log_arr as $chk_log){1081 list($chk_resno)=explode("\t",$chk_log);1082 $chk_resnos[]=$chk_resno;1083 }1084 $chk_lines=[];1085 foreach($chk_resnos as $chk_resno){1086 if(($chk_resno!==$no)&&is_file(LOG_DIR."{$chk_resno}.log")){1087 $cp=fopen(LOG_DIR."{$chk_resno}.log","r");1088 while($line=fgets($cp)){1089 if(!trim($line)){1090 continue;1091 }1092 $chk_lines[]=$line;//ç»å1093 }1094 fclose($cp);1095 }1096 }1097 $chk_images=array_merge($chk_lines,$r_arr);1098 foreach($chk_images as $chk_line){1099 list($chk_no,$chk_sub,$chk_name,$chk_verified,$chk_com,$chk_url,$chk_imgfile,$chk_w,$chk_h,$chk_thumbnail,$chk_painttime,$chk_log_md5,$chk_tool,$chk_pchext,$chk_time,$chk_first_posted_time,$chk_host,$chk_userid,$chk_hash,$chk_oya_)=explode("\t",trim($chk_line));1100 $_chk_time=(strlen($chk_time)>15) ? substr($chk_time,0,-6) : substr($chk_time,0,-3);//ç§åä½ã«æ»ã1101 if($is_upload && (int)substr($time,0,-6)-(int)$_chk_time<1){//æ稿æå»ã®éè¤åé¿1102 safe_unlink($upfile);1103 closeFile($fp);1104 closeFile($rp);1105 return error($en? 'Please wait a little.':'å°ãå¾
ã£ã¦ãã ããã');1106 }1107 if(!$is_upload && (string)$time===(string)$chk_time){1108 $time=((int)substr($time,0,-6)+1).substr($time,-6);1109 }1110 if($is_upload && $chk_log_md5 && ($chk_log_md5 === $img_md5)){1111 safe_unlink($upfile);1112 closeFile($fp);1113 closeFile($rp);1114 return error($en?'Image already exists.':'åãç»åãããã¾ããã');1115 }1116 }1117 $imgfile = $time.$imgext;1118 rename($upfile,IMG_DIR.$imgfile);1119 chmod(IMG_DIR.$imgfile,0606);1120 $src='';1121 //PCHãã¡ã¤ã«ã¢ãããã¼ã1122 // .pch, .spch,.chi,.psd ãã©ã³ã¯ ã©ãããè¿ã£ã¦ãã1123 if ($pchext = check_pch_ext(TEMP_DIR . $file_name,['upload'=>true])) {1124 $src = TEMP_DIR . $file_name . $pchext;1125 $dst = IMG_DIR . $time . $pchext;1126 if(copy($src, $dst)){1127 chmod($dst, 0606);1128 }1129 }1130 list($w,$h)=getimagesize(IMG_DIR.$imgfile);1131 //縮å°è¡¨ç¤º 1132 $max_w = ($_oya==='res') ? $res_max_w : $max_w; 1133 $max_h = ($_oya==='res') ? $res_max_h : $max_h; 1134 list($w,$h)=image_reduction_display($w,$h,$max_w,$max_h);1135 1136 //ãµã ãã¤ã«1137 $thumbnail='';1138 if($use_thumb){1139 if(thumb(IMG_DIR,$imgfile,$time,$max_w,$max_h)){1140 $thumbnail='thumbnail';1141 }1142 }1143 //æç»æé追å 1144 $painttime = '';1145 if($starttime && is_numeric($starttime) && $postedtime && is_numeric($postedtime)){1146 $psec=(int)$postedtime-(int)$starttime;1147 $painttime=(int)$_painttime+(int)$psec;1148 }1149 1150 $new_line= "$_no\t$_sub\t$_name\t$_verified\t$_com\t$_url\t$imgfile\t$w\t$h\t$thumbnail\t$painttime\t$img_md5\t$tool\t$pchext\t$time\t$_first_posted_time\t$host\t$userid\t$_hash\t$_oya\n";1151 $r_arr[$i] = $new_line;1152 if($_oya ==='oya'){1153 $flag=false;1154 foreach($alllog_arr as $i => $val){1155 list($no_,$sub_,$name_,$verified_,$com_,$url_,$imgfile_,$w_,$h_,$thumbnail_,$painttime_,$log_md5_,$tool_,$pchext_,$time_,$first_posted_time_,$host_,$userid_,$hash_,$oya_) = explode("\t",trim($val));1156 1157 if(($id===$time_ && $no===$no_) &&1158 (($admindel && $is_upload ||1159 ($pwd && password_verify($pwd,$hash_))))){1160 $alllog_arr[$i] = $new_line;1161 $flag=true;1162 break;1163 }1164 }1165 if(!$flag){1166 closeFile($rp);1167 closeFile($fp);1168 safe_unlink(IMG_DIR.$imgfile);1169 return error($en?'The operation failed.':'失æãã¾ããã');1170 }1171 writeFile($fp,implode("",$alllog_arr));1172 }1173 writeFile($rp, implode("", $r_arr));1174 closeFile($rp);1175 closeFile($fp);1176 1177 //æ§ãã¡ã¤ã«åé¤1178 delete_files($_imgfile, $_time);1179 //ã¯ã¼ã¯ãã¡ã¤ã«åé¤1180 safe_unlink($src);1181 safe_unlink($tempfile);1182 safe_unlink($up_tempfile);1183 safe_unlink($upfile);1184 safe_unlink(TEMP_DIR.$file_name.".dat");1185 if($is_upload){1186 return edit_form($time,$no);//ç·¨éç»é¢ã«ãã©ã1187 }1188 return header('Location: ./?resno='.$no.'#'.$time);1189}1190// åç»è¡¨ç¤º1191function pchview(){1192 global $boardname,$skindir,$en;1193 $imagefile = filter_input(INPUT_GET, 'imagefile');1194 $no = (string)filter_input(INPUT_GET, 'no',FILTER_VALIDATE_INT);1195 $pch = pathinfo($imagefile, PATHINFO_FILENAME);1196 $pchext = check_pch_ext(IMG_DIR . $pch);1197 if(!$pchext){1198 return error('ãã¡ã¤ã«ãããã¾ããã');1199 }1200 $pchfile = IMG_DIR.$pch.$pchext;1201 list($picw, $pich) = getimagesize(IMG_DIR.$imagefile);1202 $appw = $picw < 200 ? 200 : $picw;1203 $apph = $pich < 200 ? 200 : $pich + 26;1204 // HTMLåºå1205 $templete='pch_view.html';1206 return include __DIR__.'/'.$skindir.$templete;1207}1208//åé¤åã®ç¢ºèªç»é¢1209function confirmation_before_deletion ($edit_mode=''){1210 global $boardname,$home,$petit_ver,$petit_lot,$skindir,$use_aikotoba,$set_nsfw,$en;1211 //管çè
å¤å®å¦ç1212 session_sta();1213 $admindel=admindel_valid();1214 $aikotoba=aikotoba_valid();1215 $userdel=isset($_SESSION['userdel'])&&($_SESSION['userdel']==='userdel_mode');1216 $resmode = filter_input(INPUT_POST,'resmode',FILTER_VALIDATE_BOOLEAN);1217 $resmode = $resmode ? 'true' : 'false';1218 $postpage = filter_input(INPUT_POST,'postpage',FILTER_VALIDATE_INT);1219 $postresno = filter_input(INPUT_POST,'postresno',FILTER_VALIDATE_INT);1220 $postpage = ($postpage || $postpage===0) ? $postpage : 0; 1221 $postresno = ($postresno) ? $postresno : false; 1222 $pwdc=filter_input(INPUT_COOKIE,'pwdc');1223 $edit_mode = filter_input(INPUT_POST,'edit_mode');1224 if(!($admindel||$userdel)){1225 return error($en?'The operation failed.':'失æãã¾ããã');1226 }1227 if($edit_mode!=='delmode' && $edit_mode!=='editmode'){1228 return error($en?'The operation failed.':'失æãã¾ããã');1229 }1230 $id = t((string)filter_input(INPUT_POST,'id'));//intã®ç¯å²å¤1231 $no = t((string)filter_input(INPUT_POST,'no',FILTER_VALIDATE_INT));1232 if(!is_file(LOG_DIR."{$no}.log")){1233 return error($en? 'The article does not exist.':'è¨äºãããã¾ããã');1234 }1235 $rp=fopen(LOG_DIR."{$no}.log","r");1236 flock($rp, LOCK_EX);1237 $r_arr=[];1238 while ($r_line = fgets($rp)) {1239 if(!trim($r_line)){1240 continue;1241 }1242 $r_arr[]=$r_line;1243 }1244 if(empty($r_arr)){1245 closeFile($rp);1246 return error($en?'The operation failed.':'失æãã¾ããã');1247 }1248 $find=false;1249 foreach($r_arr as $i =>$val){1250 $_line=explode("\t",trim($val));1251 list($_no,$sub,$name,$verified,$com,$url,$imgfile,$w,$h,$thumbnail,$painttime,$log_md5,$tool,$pchext,$time,$first_posted_time,$host,$userid,$hash,$oya)=$_line;1252 if($id===$time && $no===$_no){1253 $out[0][]=create_res($_line);1254 $find=true;1255 break;1256 1257 }1258 }1259 if(!$find){1260 closeFile ($rp);1261 return error($en?'The article was not found.':'è¨äºãè¦ã¤ããã¾ããã');1262 }1263 closeFile ($rp);1264 $token=get_csrf_token();1265 if(!$use_aikotoba){1266 $aikotoba=true;1267 }1268 // nsfw1269 $nsfwc=filter_input(INPUT_COOKIE,'nsfwc',FILTER_VALIDATE_BOOLEAN);1270 if($edit_mode==='delmode'){1271 $templete='before_del.html';1272 return include __DIR__.'/'.$skindir.$templete;1273 }1274 if($edit_mode==='editmode'){1275 $templete='before_edit.html';1276 return include __DIR__.'/'.$skindir.$templete;1277 }1278 return error($en?'The operation failed.':'失æãã¾ããã');1279}1280//ç·¨éç»é¢1281function edit_form($id='',$no=''){1282 global $petit_ver,$petit_lot,$home,$boardname,$skindir,$set_nsfw,$en,$max_kb;1283 $max_byte = $max_kb * 1024*2;1284 $token=get_csrf_token();1285 $admindel=admindel_valid();1286 $userdel=isset($_SESSION['userdel'])&&($_SESSION['userdel']==='userdel_mode');1287 $pwd=(string)filter_input(INPUT_POST,'pwd');1288 $pwdc=(string)filter_input(INPUT_COOKIE,'pwdc');1289 $pwd = $pwd ? $pwd : $pwdc;1290 1291 if(!($admindel||($userdel&&$pwd))){1292 return error($en?'The operation failed.':'失æãã¾ããã');1293 }1294 $id_and_no=(string)filter_input(INPUT_POST,'id_and_no');1295 if($id_and_no){1296 list($id,$no)=explode(",",trim($id_and_no));1297 }1298 if(!is_file(LOG_DIR."{$no}.log")){1299 return error($en? 'The article does not exist.':'è¨äºãããã¾ããã');1300 }1301 1302 $rp=fopen(LOG_DIR."{$no}.log","r");1303 flock($rp, LOCK_EX);1304 $r_arr=[];1305 while ($r_line = fgets($rp)) {1306 if(!trim($r_line)){1307 continue;1308 }1309 $r_arr[]=$r_line;1310 }1311 if(empty($r_arr)){1312 closeFile($rp);1313 return error($en?'The operation failed.':'失æãã¾ããã');1314 }1315 $flag=false;1316 foreach($r_arr as $val){1317 $line=explode("\t",trim($val));1318 list($_no,$sub,$name,$verified,$com,$url,$imgfile,$w,$h,$thumbnail,$painttime,$log_md5,$tool,$pchext,$time,$first_posted_time,$host,$userid,$hash,$oya)=$line;1319 if($id===$time && $no===$_no){1320 1321 if($admindel||(check_elapsed_days($time)&&$pwd&&password_verify($pwd,$hash))){1322 $flag=true;1323 break;1324 }1325 }1326 }1327 if(!$flag){1328 closeFile($rp);1329 return error($en?'The operation failed.':'失æãã¾ããã');1330 }1331 closeFile($rp);1332 $out[0][]=create_res($line);//$lineãããæ
å ±ãåãåºã;1333 $resno=filter_input(INPUT_POST,'postresno',FILTER_VALIDATE_INT);1334 $page=filter_input(INPUT_POST,'postpage',FILTER_VALIDATE_INT);1335 foreach($line as $i => $val){1336 $line[$i]=h($val);1337 }1338 list($_no,$sub,$name,$verified,$_com,$url,$imgfile,$w,$h,$thumbnail,$painttime,$log_md5,$tool,$pchext,$time,$first_posted_time,$host,$userid,$hash,$oya)=$line;1339 $com=h(str_replace('"\n"',"\n",$com));1340 $page = ($page||$page===0) ? $page : false; 1341 $resno = $resno ? $resno : false;1342 $nsfwc=filter_input(INPUT_COOKIE,'nsfwc',FILTER_VALIDATE_BOOLEAN);1343 // HTMLåºå1344 $templete='edit_form.html';1345 return include __DIR__.'/'.$skindir.$templete;1346}1347//ç·¨é1348function edit(){1349 global $name_input_required,$max_com,$en;1350 check_csrf_token();1351 //POSTãããå
容ãåå¾1352 $userip =t(get_uip());1353 //ãã¹ãåå¾1354 $host = t(gethostbyaddr($userip));1355 $userid = t(getId($userip));1356 $sub = t((string)filter_input(INPUT_POST,'sub'));1357 $name = t((string)filter_input(INPUT_POST,'name'));1358 $com = t((string)filter_input(INPUT_POST,'com'));1359 $url = t((string)filter_input(INPUT_POST,'url',FILTER_VALIDATE_URL));1360 $id = t((string)filter_input(INPUT_POST,'id'));//intã®ç¯å²å¤1361 $no = t((string)filter_input(INPUT_POST,'no',FILTER_VALIDATE_INT));1362 1363 $pwd=(string)filter_input(INPUT_POST,'pwd');1364 $pwdc=(string)filter_input(INPUT_COOKIE,'pwdc');1365 $pwd = $pwd ? $pwd : $pwdc;1366 session_sta();1367 $admindel=admindel_valid();1368 $userdel=isset($_SESSION['userdel'])&&($_SESSION['userdel']==='userdel_mode');1369 if(!($admindel||($userdel&&$pwd))){1370 return error($en?'The operation failed.':'失æãã¾ããã');1371 }1372 //NGã¯ã¼ããããã°æ絶1373 Reject_if_NGword_exists_in_the_post();1374 //POSTãããå¤ããã°ãã¡ã¤ã«ã«æ ¼ç´ããæ¸å¼ã«ãã©ã¼ããã1375 $formatted_post=create_formatted_text_from_post($name,$sub,$url,$com);1376 $name = $formatted_post['name'];1377 $sub = $formatted_post['sub'];1378 $url = $formatted_post['url'];1379 $com = $formatted_post['com'];1380 if(!$name){1381 if($name_input_required){1382 return error($en?'Please enter your name.':'ååãããã¾ããã');1383 }else{1384 $name='anonymous';1385 }1386 }1387 //ãã°èªã¿è¾¼ã¿1388 if(!is_file(LOG_DIR."{$no}.log")){1389 return error($en? 'The article does not exist.':'è¨äºãããã¾ããã');1390 }1391 $fp=fopen(LOG_DIR."alllog.log","r+");1392 flock($fp, LOCK_EX);1393 $r_arr=[];1394 $rp=fopen(LOG_DIR."{$no}.log","r+");1395 flock($rp, LOCK_EX);1396 while ($line = fgets($rp)) {1397 if(!trim($line)){1398 continue;1399 }1400 $r_arr[]=$line;1401 }1402 if(empty($r_arr)){1403 closeFile($rp);1404 closeFile($fp);1405 return error($en?'The operation failed.':'失æãã¾ããã');1406 }1407 $flag=false;1408 foreach($r_arr as $i => $line){1409 list($_no,$_sub,$_name,$_verified,$_com,$_url,$_imgfile,$_w,$_h,$_thumbnail,$_painttime,$_log_md5,$_tool,$_pchext,$_time,$_first_posted_time,$_host,$_userid,$_hash,$_oya)=explode("\t",trim($line));1410 if($id===$_time && $no===$_no){1411 if($admindel||(check_elapsed_days($_time)&&$pwd&&password_verify($pwd,$_hash))){1412 $flag=true;1413 break;1414 }1415 }1416 }1417 if(!$flag){1418 closeFile($rp);1419 closeFile($fp);1420 return error($en?'The operation failed.':'失æãã¾ããã');1421 }1422 if(!$_imgfile && !$com){1423 closeFile($rp);1424 closeFile($fp);1425 return error($en?'Please write something.':'ä½ãæ¸ãã¦ä¸ããã');1426 }1427 $sub=($_oya==='res') ? $_sub : $sub; 1428 $sub=(!$sub) ? ($en? 'No subject':'ç¡é¡') : $sub;1429 $new_line= "$_no\t$sub\t$name\t$_verified\t$com\t$url\t$_imgfile\t$_w\t$_h\t$_thumbnail\t$_painttime\t$_log_md5\t$_tool\t$_pchext\t$_time\t$_first_posted_time\t$host\t$userid\t$_hash\t$_oya\n";1430 $r_arr[$i] = $new_line;1431 if($_oya==='oya'){1432 $alllog_arr=[];1433 while ($_line = fgets($fp)) {1434 if(!trim($_line)){1435 continue;1436 }1437 $alllog_arr[]=$_line; 1438 }1439 if(empty($alllog_arr)){1440 closeFile($rp);1441 closeFile($fp);1442 return error($en?'The operation failed.':'失æãã¾ããã');1443 }1444 $flag=false;1445 foreach($alllog_arr as $i => $val){1446 list($no_,$sub_,$name_,$verified_,$com_,$url_,$imgfile_,$w_,$h_,$thumbnail_,$painttime_,$log_md5_,$tool_,$pchext_,$time_,$first_posted_time_,$host_,$userid_,$hash_,$oya_) = explode("\t",trim($val));1447 if(($id===$time_ && $no===$no_) &&1448 ($admindel || ($pwd && password_verify($pwd,$hash_)))){1449 $alllog_arr[$i] = $new_line;1450 $flag=true;1451 break;1452 }1453 }1454 if(!$flag){1455 closeFile($rp);1456 closeFile($fp);1457 return error($en?'The operation failed.':'失æãã¾ããã');1458 }1459 writeFile($fp,implode("",$alllog_arr));1460 }1461 writeFile($rp, implode("", $r_arr));1462 closeFile($rp);1463 closeFile($fp);1464 unset($_SESSION['userdel']);1465 return header('Location: ./?resno='.$no.'#'.$_time);1466}1467//è¨äºåé¤1468function del(){1469 global $en;1470 $pwd=(string)filter_input(INPUT_POST,'pwd');1471 $pwdc=(string)filter_input(INPUT_COOKIE,'pwdc');1472 $pwd = $pwd ? $pwd : $pwdc;1473 check_csrf_token();1474 session_sta();1475 $admindel=admindel_valid();1476 $userdel_mode=isset($_SESSION['userdel'])&&($_SESSION['userdel']==='userdel_mode');1477 if(!($admindel||($userdel_mode&&$pwd))){1478 return error($en?'The operation failed.':'失æãã¾ããã');1479 }1480 $id_and_no=(string)filter_input(INPUT_POST,'id_and_no');1481 if(!$id_and_no){1482 return error($en?'Please select an article.':'è¨äºãé¸æããã¦ãã¾ããã');1483 }1484 $id=$no='';1485 if($id_and_no){1486 list($id,$no)=explode(",",trim($id_and_no));1487 }1488 $fp=fopen(LOG_DIR."alllog.log","r+");1489 flock($fp, LOCK_EX);1490 if(!is_file(LOG_DIR."{$no}.log")){1491 return error($en? 'The article does not exist.':'è¨äºãããã¾ããã');1492 }1493 $rp=fopen(LOG_DIR."{$no}.log","r+");1494 flock($rp, LOCK_EX);1495 $r_arr=[];1496 while ($r_line = fgets($rp)) {1497 if(!trim($r_line)){1498 continue;1499 }1500 $r_arr[]=$r_line;1501 }1502 if(empty($r_arr)){1503 closeFile ($rp);1504 closeFile($fp);1505 return error($en?'The operation failed.':'失æãã¾ããã');1506 }1507 $find=false;1508 foreach($r_arr as $i =>$val){1509 list($_no,$sub,$name,$verified,$com,$url,$imgfile,$w,$h,$thumbnail,$painttime,$log_md5,$tool,$pchext,$time,$first_posted_time,$host,$userid,$hash,$oya)=explode("\t",trim($val));1510 if($id===$time && $no===$_no){1511 1512 if(!$admindel){1513 if(!$pwd||!password_verify($pwd,$hash)){1514 closeFile ($rp);1515 closeFile($fp);1516 return error($en?'The operation failed.':'失æãã¾ããã');1517 }1518 }1519 if($oya==='oya'){//ã¹ã¬ããåé¤1520 $alllog_arr=[];1521 while ($_line = fgets($fp)) {1522 if(!trim($_line)){1523 continue;1524 }1525 $alllog_arr[]=$_line; 1526 }1527 if(empty($alllog_arr)){1528 closeFile ($rp);1529 closeFile($fp);1530 return error($en?'The operation failed.':'失æãã¾ããã');1531 }1532 $flag=false;1533 foreach($alllog_arr as $i =>$_val){//å
¨ä½ãã°1534 list($no_,$sub_,$name_,$verified_,$com_,$url_,$_imgfile_,$w_,$h_,$thumbnail_,$painttime_,$log_md5_,$tool_,$pchext_,$time_,$first_posted_time_,$host_,$userid_,$hash_,$oya_)=explode("\t",trim($_val));1535 if(($id===$time_ && $no===$no_) &&1536 ($admindel || ($pwd && password_verify($pwd,$hash_)))){1537 unset($alllog_arr[$i]);1538 $flag=true;1539 break;1540 }1541 }1542 if(!$flag){1543 closeFile ($rp);1544 closeFile($fp);1545 return error($en?'The operation failed.':'失æãã¾ããã');1546 }1547 foreach($r_arr as $r_line) {//ã¬ã¹ãã¡ã¤ã«1548 list($_no,$_sub,$_name,$_verified,$_com,$_url,$_imgfile,$_w,$_h,$_thumbnail,$_painttime,$_log_md5,$_tool,$_pchext,$_time,$_first_posted_time,$_host,$_userid,$_hash,$_oya)=explode("\t",trim($r_line));1549 1550 delete_files ($_imgfile, $_time);//ä¸é£ã®ãã¡ã¤ã«ãåé¤1551 1552 }1553 writeFile($fp,implode("",$alllog_arr));1554 safe_unlink(LOG_DIR.$no.'.log');1555 1556 }else{1557 unset($r_arr[$i]);1558 delete_files ($imgfile, $time);//ä¸é£ã®ãã¡ã¤ã«ãåé¤1559 writeFile ($rp,implode("",$r_arr));1560 }1561 $find=true;1562 break;1563 }1564 }1565 closeFile ($rp);1566 closeFile($fp);1567 if(!$find){1568 return error($en?'The article was not found.':'è¨äºãè¦ã¤ããã¾ããã');1569 }1570 unset($_SESSION['userdel']);1571 $resno=(string)filter_input(INPUT_POST,'postresno');1572 //å¤ééä¿¡é²æ¢1573 if(filter_input(INPUT_POST,'resmode')==='true'){1574 if(!is_file(LOG_DIR.$resno.'.log')){1575 return header('Location: ./');1576 }1577 return header('Location: ./?resno='.$resno);1578 }1579 return header('Location: ./?page='.filter_input(INPUT_POST,'postpage'));1580}...
EditFile.php
Source:EditFile.php
1<?php2require_once 'Zend/Controller/Plugin/Abstract.php';3class Common_Plugin_EditFile extends Zend_Controller_Plugin_Abstract4{5 var $fPoint; //æ件æé 6 var $fName; //æ件å称 7 var $Count; //æ件è¡æ°8 9 //ææå®æ¡ä»¶æå¼æ件并éå® |LOCK_SH:读|LOCK_EX:å|LOCK_UN:éæ¾|LOCK_NB| 10 function OpenFile($Method="r",$Lock=LOCK_SH) 11 { 12 if(($Method == 'r' or $Method == 'r+') && !file_exists($this->fName)) 13 { 14 return false; 15 } 16 else 17 { 18 $this->fPoint = fopen($this->fName,$Method); 19 flock($this->fPoint,$Lock); 20 return true; 21 } 22 } 23 24 //å
³éæ件 25 function CloseFile() 26 { 27 if(isset($this->fPoint)) 28 { 29 flock($this->fPoint,LOCK_UN); 30 fclose($this->fPoint); 31 return true; 32 } 33 else 34 { 35 return false; 36 } 37 } 38 39 //读æ件å°<æ°ç»>,æ件æ¯è¡ä½æ°ç»çå¼,è¿åä¸ç»´æ°ç» 40 function FileToArr() 41 { 42 if(file_exists($this->fName)) 43 { 44 $rArr = file($this->fName); 45 return $rArr; 46 } 47 else 48 { 49 return array(); 50 } 51 } 52 53 //读æå®é¿åº¦çæ件å°<å符串>,没ææå®è¿åå
¨é¨ 54 function FileToStr($Size=0) 55 { 56 if($this->OpenFile()) 57 { 58 if ($Size < 1) 59 { 60 $Size = filesize($this->fName); 61 } 62 $rStr = fread($this->fPoint,$Size); 63 rewind($this->fPoint); 64 $this->CloseFile(); 65 return $rStr; 66 } 67 else 68 { 69 return ""; 70 } 71 } 72 //æ´æ¹æå®è¡çå符 73 function ModifyStr($id,$Data) 74 { 75 if($this->OpenFile('r+',LOCK_EX)) 76 { 77 $Next = 0; //åå§è¡è®¡æ° 78 while(!feof($this->fPoint)) 79 { 80 $Tell = ftell($this->fPoint); //ä¿åå¼å§è¯»åçä½ç½® 81 $Temp = fgets($this->fPoint,filesize($this->fName)*1024); //éè¡è¯»å 82 $Next++; 83 if($Next == $id) 84 { 85 $Str = fread($this->fPoint,filesize($this->fName)*1024); 86 $Len = strlen($Temp); 87 fseek($this->fPoint,$Tell); //åç»å½è¡å¼å§å¤ 88 $Write = str_pad($Data,$Len,"\x0E",STR_PAD_LEFT).$Str; 89 fputs($this->fPoint,$Write); //ææ°ä¸²åå
¥æ件 90 break; 91 } 92 } 93 $this->CloseFile(); 94 return true; 95 } 96 else 97 { 98 return false; 99 } 100 } 101 102 //å é¤æå®è¡çå符 103 function DeleteStr($id,$Data) 104 { 105 if($this->OpenFile('r+',LOCK_EX)) 106 { 107 $Next = 0; //åå§è¡è®¡æ° 108 while(!feof($this->fPoint)) 109 { 110 $Tell = ftell($this->fPoint); //ä¿åå¼å§è¯»åçä½ç½® 111 $Temp = fgets($this->fPoint,filesize($this->fName)*1024); //éè¡è¯»å 112 $Next++; 113 if($Next == $id) 114 { 115 $Len = strlen($Data); 116 fseek($this->fPoint,$Tell); //åç»å½è¡å¼å§å¤ 117 $Write = str_pad("\x0E",$Len,"\x0E",STR_PAD_LEFT); 118 fputs($this->fPoint,$Write); //ææ°ä¸²åå
¥æ件 119 break; 120 } 121 } 122 $this->CloseFile(); 123 return true; 124 } 125 else 126 { 127 return false; 128 } 129 } 130 //è·åæ»è¡æ°131 function GetCount() 132 { 133 return count($this->FileToArr()); 134 } 135 136 //åå
¥å符串å°æ件尾,å¦ææ件ä¸åå¨åæ°å»º 137 function WriteToEnd($String) 138 { 139 if($this->OpenFile("a",LOCK_EX)) 140 { 141 fputs($this->fPoint,$String); 142 $this->CloseFile(); 143 return true; 144 } 145 else 146 { 147 return false; 148 } 149 } 150 151 //è¦çåå
¥å符串,å¦ææ件ä¸åå¨åæ°å»º 152 function WriteToNull($String) 153 { 154 if($this->OpenFile("w",LOCK_EX)) 155 { 156 fputs($this->fPoint,$String); 157 $this->CloseFile(); 158 return true; 159 } 160 else 161 { 162 return false; 163 } 164 } 165}166?>...
CityRepositoryTest.php
Source:CityRepositoryTest.php
...7{8 /**9 * Factors:10 * - loadFile true/false11 * - closeFile true/false12 * - file Lines 0/or have it13 * Equivalence Classes:14 * - file has 0 line - loadFile true - closeFile true15 * - file has 0 line - loadFile true - closeFile false16 * - file has 0 line - loadFile false - closeFile true17 * - file has 0 line - loadFile false - closeFile false18 *19 * - file has lines - loadFile true - closeFile false20 * - file has lines - loadFile true - closeFile false21 * - file has lines - loadFile false - closeFile false22 * - file has lines - loadFile false - closeFile false23 * Limit values24 * - file has 1 line or have N don't change result limit are in 1 line25 */26 public function testGetCitiesOnEmptyFileCanLoadFileCanCloseFileReturnNull()27 {28 $cityRepository = Mockery::mock(CityRepository::class)->makePartial();29 $cityRepository->shouldReceive('getLine')->andReturn(false);30 $cityRepository->shouldReceive('loadFile')->andReturn(true);31 $cityRepository->shouldReceive('closeFile')->andReturn(true);32 /** @var CityRepository $cityRepository */33 $this->assertNull($cityRepository->getCities());34 }35 public function testGetCitiesOnEmptyFileCanLoadFileCantCloseFileReturnNull()36 {37 $cityRepository = Mockery::mock(CityRepository::class)->makePartial();38 $cityRepository->shouldReceive('getLine')->andReturn(false);39 $cityRepository->shouldReceive('loadFile')->andReturn(true);40 $cityRepository->shouldReceive('closeFile')->andReturn(false);41 /** @var CityRepository $cityRepository */42 $this->assertNull($cityRepository->getCities());43 }44 public function testGetCitiesOnEmptyFileCantLoadFileCanCloseFileReturnNull()45 {46 $cityRepository = Mockery::mock(CityRepository::class)->makePartial();47 $cityRepository->shouldReceive('getLine')->andReturn(false);48 $cityRepository->shouldReceive('loadFile')->andReturn(false);49 $cityRepository->shouldReceive('closeFile')->andReturn(true);50 /** @var CityRepository $cityRepository */51 $this->assertNull($cityRepository->getCities());52 }53 public function testGetCitiesOnEmptyFileCantLoadFileCantCloseFileReturnNull()54 {55 $cityRepository = Mockery::mock(CityRepository::class)->makePartial();56 $cityRepository->shouldReceive('getLine')->andReturn(false);57 $cityRepository->shouldReceive('loadFile')->andReturn(false);58 $cityRepository->shouldReceive('closeFile')->andReturn(false);59 /** @var CityRepository $cityRepository */60 $this->assertNull($cityRepository->getCities());61 }62 public function testGetCitiesOnNotEmptyFileCanLoadFileCanCloseFileReturnArray()63 {64 $cityRepository = Mockery::mock(CityRepository::class)->makePartial();65 $cityRepository->shouldReceive('getLine')->andReturn(CityRepositoryBuilder::VALID_MULTI_WORD_NAME_CITY_STRING, false);66 $cityRepository->shouldReceive('loadFile')->andReturn(true);67 $cityRepository->shouldReceive('closeFile')->andReturn(true);68 /** @var CityRepository $cityRepository */69 $this->assertIsArray($cityRepository->getCities());70 }71 public function testGetCitiesOnNotEmptyFileCanLoadFileCantCloseFileReturnNull()72 {73 $cityRepository = Mockery::mock(CityRepository::class)->makePartial();74 $cityRepository->shouldReceive('getLine')->andReturn(CityRepositoryBuilder::VALID_MULTI_WORD_NAME_CITY_STRING, false);75 $cityRepository->shouldReceive('loadFile')->andReturn(true);76 $cityRepository->shouldReceive('closeFile')->andReturn(false);77 /** @var CityRepository $cityRepository */78 $this->assertNull($cityRepository->getCities());79 }80 public function testGetCitiesOnNotEmptyFileCantLoadFileCanCloseFileReturnNull()81 {82 $cityRepository = Mockery::mock(CityRepository::class)->makePartial();83 $cityRepository->shouldReceive('getLine')->andReturn(CityRepositoryBuilder::VALID_MULTI_WORD_NAME_CITY_STRING, false);84 $cityRepository->shouldReceive('loadFile')->andReturn(false);85 $cityRepository->shouldReceive('closeFile')->andReturn(true);86 /** @var CityRepository $cityRepository */87 $this->assertNull($cityRepository->getCities());88 }89 public function testGetCitiesOnNotEmptyFileCantLoadFileCantCloseFileReturnNull()90 {91 $cityRepository = Mockery::mock(CityRepository::class)->makePartial();92 $cityRepository->shouldReceive('getLine')->andReturn(CityRepositoryBuilder::VALID_MULTI_WORD_NAME_CITY_STRING, false);93 $cityRepository->shouldReceive('loadFile')->andReturn(false);94 $cityRepository->shouldReceive('closeFile')->andReturn(false);95 /** @var CityRepository $cityRepository */96 $this->assertNull($cityRepository->getCities());97 }98}...
closeFile
Using AI Code Generation
1$file->closeFile();2$file->closeFile();3$file->closeFile();4$file->closeFile();5$file->closeFile();6$file->closeFile();7$file->closeFile();8$file->closeFile();9$file->closeFile();10$file->closeFile();11Use of fclose() function in PHP:12fclose(file_pointer);13Example: Use of fclose() function in PHP14$file_pointer = fopen("file.txt", "r");15fclose($file_pointer);
closeFile
Using AI Code Generation
1$file->closeFile();2$file->openFile();3$file->closeFile();4class file {5 public static function openFile() {6";7 }8 public static function closeFile() {9";10 }11}12file::closeFile();13file::openFile();14file::closeFile();
closeFile
Using AI Code Generation
1require_once('file.php');2$file = new file();3$file->closeFile();4require_once('file.php');5$file = new file();6$file->closeFile();
closeFile
Using AI Code Generation
1$fileobj = new File();2$fileobj->closeFile();3$fileobj = new File();4$fileobj->openFile();5include_once 'file name';6require_once 'file name';7$fileobj = new File();8$fileobj->closeFile();9$fileobj = new File();10$fileobj->openFile();11{12 function openFile()13 {14 echo "File Opened";15 }16 function closeFile()17 {18 echo "File Closed";19 }20}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with closeFile on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!