function d_filelist_cached($dir, $start, $length, $filter = '') { //sleep(1); $tmpdir = is_callable('get_tmp_dir') ? get_tmp_dir() : '/tmp'; $cache_prefix = $tmpdir . '/dolphin' . md5(__FILE__); $cache_dat = $cache_prefix . '.dat'; $cache_idx = $cache_prefix . '.idx'; $new = false; if (!file_exists($cache_dat) || filemtime($dir) > filemtime($cache_dat)) { $new = true; $fp = fopen($cache_dat, 'w+b'); $ifp = fopen($cache_idx, 'w+b'); } else { $fp = fopen($cache_dat, 'r+b'); $ifp = fopen($cache_idx, 'r+b'); list(, $l) = unpack('n', fread($fp, 2)); $cached_dir = fread($fp, $l); list(, $l) = unpack('n', fread($fp, 2)); $cached_filter = fread($fp, $l); if ($cached_dir != $dir || $cached_filter != $filter) { ftruncate($fp, 0); ftruncate($ifp, 0); fseek($fp, 0, SEEK_SET); fseek($ifp, 0, SEEK_SET); $new = true; } } $items = array(); $cnt = 0; $old_cwd = getcwd(); try { if (!@chdir($dir)) { throw new Exception('Could not chdir to the folder'); } if ($new) { fwrite($fp, pack('n', strlen($dir)) . $dir); fwrite($fp, pack('n', strlen($filter)) . $filter); $pos = ftell($fp); $dh = opendir('.'); if (!$dh) { throw new Exception('Could not open directory for reading'); } $filter = strtolower($filter); while (false !== ($f = readdir($dh))) { if ($f == '.' || $f == '..') { continue; } if (strlen($filter) && !substr_count(strtolower($f), $filter)) { continue; } fwrite($ifp, pack('NN', $pos, strlen($f))); fwrite($fp, $f); $pos += strlen($f); // ftell is not as fast as it should be, sadly } fflush($ifp); fflush($fp); } fseek($ifp, $start * 8); $first = true; $curr_idx = $start; while ($curr_idx < $start + $length) { list(, $pos, $l) = unpack('N2', fread($ifp, 8)); if ($first) { fseek($fp, $pos); $first = false; } $f = fread($fp, $l); if (!strlen($f)) { break; } if (strlen($f) != $l) { throw new Exception('Consistency error'); } $items[$curr_idx++] = array('name' => $f, 'size' => filesize($f), 'is_dir' => is_dir($f)); } $cnt = filesize($cache_idx) / 8; } catch (Exception $e) { fclose($fp); fclose($ifp); unlink($cache_dat); unlink($cache_idx); @chdir($old_cwd); return is_callable('d_error') ? d_error($e->getMessage()) : false; } if ($cnt < 500 && $length >= 500) { usort($items, 'd_filelist_cached_usort_cmp'); } @chdir($old_cwd); return array('items' => $items, 'cnt' => $cnt); }
readfile($pr); unlink($pr); //echo '1'; //header('location: ../images/thumb.jpg?'.rand()); } } if($ret != 0 && !send_thumbnail($f,$w,$h)) { //print_r(d_error('all')); //fputs(fopen('L:/log.txt','w'),ob_get_clean()); switch(d_error(NODEBUG)) { case NOMEMORY: $file = 'memory'; break; case NOGD: $file='gd'; break; case UNSUPP: $file = 'unsupported'; break; default: $file = 'small'; break; } header('Location: ../images/no-preview-'.$file.'.png');
$aps = array('aps' => array('alert' => $message, 'sound' => 'default')); APNS_DB::create_notification($row['device_id'], "shuttletrack:$route_id:$stop_id", $aps, False); break; } // make sure to unsubscribe this person so they don't // get a message every 10 seconds until their subscription times out $sql = "DELETE FROM ShuttleSubscription " . "WHERE device_id='" . $row['device_id'] . "' " . "AND device_type='" . $row['device_type'] . "' " . "AND route_id='" . $route_id . "' " . "AND stop_id='" . $stop_id . "'"; if (!db::$connection->query($sql)) { d_error("unsubscribe failed: {$db->errno} {$db->error} in $sql"); } } // if } // while } // else } /* // purge all subscriptions that have expired $sql = "SELECT * FROM ShuttleSubscription WHERE expire_time < $time"; if (!$result = db::$connection->query($sql)) { d_error("sql failed: {$db->errno} {$db->error} in $sql"); } else { while ($row = $result->fetch_assoc()) {
function d_ftpput_contents($f, $file, $_, $__, $contents) { if(!$fname = _tmpname()) return false; if(!$fp = fopen($fname, 'wb')) return d_error('Cannot create file in temp directory.'); fputs($fp, $contents); fclose($fp); return ftp_put(FTP_LINK,$f,$fname,FTP_BINARY); }
function del() { extract($GLOBALS); $log_file = $ddir . $key . $ext; $cgi_file = $ddir . $key . $ext_cgi; $log = @file($log_file); //ログを配列にぶちこむ $log_cgi = @file($cgi_file); if (!$log) { d_error("スレッドが無いよう"); } $line = sizeof($log); //ログの行数 $del_no -= 1; if ($log[$del_no] == "") { d_error("そんな記事ないよ(´・ω・`)"); } if ($line != count($log_cgi)) { d_error("DEBUG:ログの行数は不一致です。"); } list($dname, $demail, $dnow, $dcom, ) = explode(",", $log[$del_no]); list(, , , , , , $pass) = explode(",", $log_cgi[$del_no]); if ($delpwd != $ad_pass) { if (trim($pass) == "") { d_error("パスワードがありません。"); } if ($pass != substr(md5($delpwd), 2, 8)) { d_error("パスワードが違うみたい。。。"); } } $log[$del_no] = "{$aborn},,{$aborn},[i]この記事は投稿者によって削除されました[/i],\n"; if (!is_writable($log_file)) { d_error("削除できない。。。"); } $re = @fopen($log_file, "w") or d_error("削除できない。。。"); flock($re, 2); reset($log); fputs($re, implode('', $log)); fclose($re); $com = bb2html($com); include_once "index.inc"; head(); ?> <p>以下の記事を削除しました。たぶん。</p> <table> <tr><td>名前</td><td><?php echo $dname; ?> </td></tr> <tr><td>日付</td><td><?php echo $ddate; ?> </td></tr> <tr><td>記事</td><td><?php echo $dcom; ?> </td></tr> </table> <p><b><a href="<?php echo $dir_path; ?> index.html">掲示板に戻る</a></b></p> <?php foot(); }
function multipart_cont($cache) { if(is_bool($cache)) return $cache; /* this line should be here */ $keys = array_keys($cache); extract($cache); $cache = array(); list($b,$c,$s) = $processors; if($c == 'cont') $c = false; if($s == 'stop') $s = false; if($curfile) $files[] = 'i'.$curfile; /* * first symbol filename of $files will tell, what to do with file: * * i -- intermediate file, which needs continue processing (w/$resume_data) * n -- new file with unknown type: use all actions * d -- directory which should not be expanded, just execute processors * (needed for $dircall = 'after' and 'before') */ //echo "before hello world\n"; if(!@chdir($basedir)) return d_error('Cannot change directory to current'); //echo 'hello world'; while($it = array_pop($files)) { $a = $it[0]; /* action */ $name = substr($it, 1); $curfile = false; if(!have_time()) { $files[] = $it; foreach($keys as $key) $cache[$key] = $$key; return $cache; } if(is_file($name) || is_link($name) || $a == 'd' || $a == 'i')/*only execute processors*/ { /* for intermediate files we already have $resume_data from cache */ /* TODO: do not just skip errors at begin function */ if($a != 'i' && ($resume_data=$b($name, $data)) === false) continue; if($c) { $have = true; /* for case when $resume_data = true */ $curfile = $name; while(is_array($resume_data) && ($have=have_time())) { $resume_data = $c($name, $data, $resume_data); } if(!$have) { foreach($keys as $key) $cache[$key] = $$key; return $cache; } if($have && $s) { $s($name, $data, $resume_data); } } }else if(is_dir($name)) { setreadable($name, true); if(!@$dh = opendir($name)) continue; if(/*$dircall == 'both' || */$dircall == 'after') $files[] = 'd'.$name; /* * we just get a list of files (even without determining type) * because stat() (or is_file() or is_dir()) consumes much time. * it is important if directory is huge (5000-50000 files) */ while(false!==($f=readdir($dh))) { if($f=='.'||$f=='..') continue; $files[] = 'n'.$name.'/'.$f; } closedir($dh); if(/*$dircall == 'both' || */$dircall == 'before') $files[] = 'd'.$name; } } return true; }
public function send_push_notification($data, $device_token) { $payload = json_encode($data); // 1B command = 0 // 2B token length = 32 // 32B token // 2B payload length // ??B payload $message = chr(0) . chr(0) . chr(32) . pack('H*', $device_token) . chr(0) . chr(strlen($payload)) . $payload; // write data to socket if (!fwrite($this->push_socket, $message)) { d_error("failed to send payload={$payload}"); return False; } return True; }