public static function getPlanning($year, $group, $week, $h = false)
 {
     $groupModel = new GroupsModel();
     $ids = $groupModel->getIDs($year, $group);
     $ids = $ids[0];
     $identFile = new ConfigFileParser('app/config/ident.json');
     $ident = $identFile->getEntry('ident');
     $fileName = 'public/img/img_planning/' . $ids['ID'] . '_' . $week . ($h ? '_h' : '') . '.png';
     try {
         $file = new \SplFileObject($fileName, 'rw');
         if ($file->getMTime() < time() - 900) {
             throw new \RuntimeException();
         }
     } catch (\RuntimeException $e) {
         $fp = fopen($fileName, 'w+');
         $url = 'http://planning.univ-amu.fr/ade/imageEt?identifier=' . $ident . '&projectId=8&idPianoWeek=' . $week . '&idPianoDay=0,1,2,3,4,5&idTree=' . $ids['IDTREE'] . '&width=1000&height=700&lunchName=REPAS&displayMode=1057855&showLoad=false&ttl=1405063872880000&displayConfId=' . ($h ? '60' : '59');
         $ch = curl_init(str_replace(" ", "%20", $url));
         curl_setopt($ch, CURLOPT_TIMEOUT, 50);
         curl_setopt($ch, CURLOPT_FILE, $fp);
         curl_setopt($ch, CURLOPT_FILE, $fp);
         curl_exec($ch);
         curl_close($ch);
     }
     return '/' . $fileName;
 }
Beispiel #2
0
 public function purgeAll($check_expiry = false)
 {
     if (!$this->is_init) {
         return false;
     }
     $dir = dir($this->settings['path']);
     if ($check_expiry) {
         if (is_numeric($check_expiry)) {
             $now = $check_expiry;
         } else {
             $now = time();
         }
         $threshold = $now - $this->settings['cache_duration'];
     }
     $prefixLength = strlen($this->settings['key_prefix']);
     while (($entry = $dir->read()) !== false) {
         if (substr($entry, 0, $prefixLength) !== $this->settings['key_prefix']) {
             continue;
         }
         if ($this->_openFile($entry) === false) {
             continue;
         }
         if ($check_expiry) {
             $mtime = $this->file->getMTime();
             if ($mtime > $threshold) {
                 continue;
             }
             $expires = (int) $this->file->current();
             if ($expires > $now) {
                 continue;
             }
         }
         $path = $this->file->getRealPath();
         $this->file = null;
         if (file_exists($path)) {
             unlink($path);
         }
     }
     $dir->close();
     return true;
 }
 /**
  * 获取文件列表
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2012-07-17 12:46:02
  *
  * @param string $node 节点路径
  *
  * @return array 文件列表
  */
 private function _getFile($node)
 {
     $node = trim($node, '/');
     $this->_denyDirectory($node);
     $file_arr = array();
     $directory = PACKER_JS_PATH . $node . '/';
     $k = 0;
     if (is_dir($directory)) {
         $date_format = sys_config('sys_timezone_datetime_format');
         $d = dir($directory);
         while ($f = $d->read()) {
             if ($f == '.' || $f == '..' || substr($f, 0, 1) == '.') {
                 continue;
             }
             $filename = $directory . '/' . $f;
             if (is_dir($filename)) {
                 $file_arr[$k] = array('text' => $f, 'checked' => $f == 'pack' ? null : false, 'id' => $node . '/' . $f);
                 $file_arr[$k]['data'] = $this->_getFile($f);
                 $k++;
             } elseif (substr($f, -3) == '.js' && !in_array($f, array('app.js'))) {
                 $desc = '';
                 //js文件说明
                 $file = new SplFileObject($filename);
                 if (!strpos($filename, '.min.')) {
                     $file->fgets();
                     $desc = trim(str_replace('*', '', $file->fgets()));
                     //第二行为文件说明
                 }
                 $file_arr[] = array('text' => $f, 'id' => $node . '/' . $f, 'leaf' => true, 'checked' => $node == 'pack' ? null : false, 'filesize' => format_size($file->getSize()), 'filemtime' => new_date($date_format, $file->getMTime()), 'desc' => $desc);
             }
         }
         //end while
         $d->close();
     }
     //end if
     return $file_arr;
 }
Beispiel #4
0
 /**
  * Used to clear a directory of matching files.
  *
  * @param string $path The path to search.
  * @param integer $now The current timestamp
  * @param integer $threshold Any file not modified after this value will be deleted.
  * @return void
  */
 protected function _clearDirectory($path, $now, $threshold)
 {
     $prefixLength = strlen($this->settings['prefix']);
     if (!is_dir($path)) {
         return;
     }
     $dir = dir($path);
     while (($entry = $dir->read()) !== false) {
         if (substr($entry, 0, $prefixLength) !== $this->settings['prefix']) {
             continue;
         }
         $filePath = $path . $entry;
         if (!file_exists($filePath) || is_dir($filePath)) {
             continue;
         }
         $file = new SplFileObject($path . $entry, 'r');
         if ($threshold) {
             $mtime = $file->getMTime();
             if ($mtime > $threshold) {
                 continue;
             }
             $expires = (int) $file->current();
             if ($expires > $now) {
                 continue;
             }
         }
         if ($file->isFile()) {
             $filePath = $file->getRealPath();
             $file = null;
             //@codingStandardsIgnoreStart
             @unlink($filePath);
             //@codingStandardsIgnoreEnd
         }
     }
 }
Beispiel #5
0
 private function _getFile($download = false)
 {
     if (!$this->authed && !$this->config->readonly) {
         echo json_encode(array('status' => false, 'message' => 'not authenticated'));
         exit;
     }
     if (!$this->requestDir || !is_file($this->requestDir)) {
         header('Status: 404 Not Found');
         header('HTTP/1.0 404 Not Found');
         exit;
     }
     $file = new SplFileObject($this->requestDir);
     // not really sure if this range shit works. stole it from an old script i wrote
     if (isset($_SERVER['HTTP_RANGE'])) {
         list($size_unit, $range_orig) = explode('=', $_SERVER['HTTP_RANGE'], 2);
         if ($size_unit == 'bytes') {
             list($range, $extra_ranges) = explode(',', $range_orig, 2);
         } else {
             $range = '';
         }
         if ($range) {
             list($seek_start, $seek_end) = explode('-', $range, 2);
         }
         $seek_end = empty($seek_end) ? $size - 1 : min(abs(intval($seek_end)), $size - 1);
         $seek_start = empty($seek_start) || $seek_end < abs(intval($seek_start)) ? 0 : max(abs(intval($seek_start)), 0);
         if ($seek_start > 0 || $seek_end < $size - 1) {
             header('HTTP/1.1 206 Partial Content');
         } else {
             header('HTTP/1.1 200 OK');
         }
         header('Accept-Ranges: bytes');
         header('Content-Range: bytes ' . $seek_start . '-' . $seek_end . '/' . $size);
         $contentLength = $seek_end - $seek_start + 1;
     } else {
         header('HTTP/1.1 200 OK');
         header('Accept-Ranges: bytes');
         $contentLength = $file->getSize();
     }
     header('Pragma: public');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Date: ' . date('r'));
     header('Last-Modified: ' . date('r', $file->getMTime()));
     header('Content-Length: ' . $contentLength);
     header('Content-Transfer-Encoding: binary');
     if ($download) {
         header('Content-Disposition: attachment; filename="' . $file->getFilename() . '"');
         header('Content-Type: application/force-download');
     } else {
         header('Content-Type: ' . mime_content_type($file->getPathname()));
     }
     // i wrote this freading a really long time ago but it seems to be more robust than SPL. someone correct me if im wrong
     $fp = fopen($file->getPathname(), 'rb');
     fseek($fp, $seek_start);
     while (!feof($fp)) {
         set_time_limit(0);
         print fread($fp, 1024 * 8);
         flush();
         ob_flush();
     }
     fclose($fp);
     exit;
 }