コード例 #1
0
ファイル: Page.php プロジェクト: piarsonforked/floxim
 /**
  * Add assets (js & css) to ajax responce via http headers
  */
 public function addAssetsAjax()
 {
     fx::http()->header('fx_assets_js', $this->files_js);
     fx::http()->header('fx_assets_css', $this->files_css);
 }
コード例 #2
0
ファイル: Files.php プロジェクト: floxim/floxim
 /**
  * get remote file
  * @todo: we should refactor this code to make it safer
  * it's better to fetch and check headers before getting file contents
  */
 public function saveRemoteFile($file, $dir = 'content', $name = null)
 {
     if (!preg_match("~^https?://~", $file)) {
         return;
     }
     $file_data = fx::http()->get($file, array(), array('timeout' => 10));
     $headers = fx::http()->getLastHeaders();
     $status = fx::http()->getLastStatus();
     if (!$file_data || $status['status_code'] >= 400) {
         return;
     }
     $file_name = $name ? $name : fx::path()->fileName($file);
     $extension = fx::path()->fileExtension($file_name);
     if (!$extension || !in_array($extension, $this->allowed_extensions)) {
         if (!isset($headers['content-type'])) {
             return;
         }
         $mime = $headers['content-type'];
         $extension = $this->getExtensionByMime($mime);
         if (!$extension || !in_array($extension, $this->allowed_extensions)) {
             return;
         }
         $file_name = preg_replace("~\\..+?\$~", '', $file_name);
         $file_name .= '.' . $extension;
     }
     $put_file = $this->getPutFilename($dir, $file_name);
     $full_path = fx::path('@files/' . $dir . '/' . $put_file);
     $this->writefile($full_path, $file_data);
     return $full_path;
 }