예제 #1
0
 private function _excel_add_image($sheet, $image, &$i)
 {
     if (!(string) $image) {
         return --$i ? '' : '';
     }
     download_web_file($image->url('350x230p'), $filepath = FCPATH . implode(DIRECTORY_SEPARATOR, array_merge(Cfg::system('orm_uploader', 'uploader', 'temp_directory'), array((string) $image))));
     $objDrawing = new PHPExcel_Worksheet_Drawing();
     $objDrawing->setPath($filepath);
     $j = $j = (ceil($i / 3) - 1) * 7 + 1;
     $objDrawing->setCoordinates(($i % 3 < 2 ? $i % 3 < 1 ? 'G' : 'A' : 'D') . $j);
     $objDrawing->setOffsetX(20);
     $objDrawing->setOffsetY(8);
     $objDrawing->setWidth(175);
     $objDrawing->setWorksheet($sheet);
     return $filepath;
 }
예제 #2
0
 public function icon($weather)
 {
     CallLog::create(array('weather_id' => $weather->id));
     if (($data = download_web_file('http://api.openweathermap.org/data/2.5/weather?lat=' . $weather->latitude . '&lon=' . $weather->longitude . '')) && ($data = json_decode($data))) {
         if (isset($data->weather[0]) && $data->weather[0]->icon && isset($data->main->temp)) {
             $weather->temperature = $data->main->temp;
             $weather->save();
             $file_path = array('resource', 'image', 'map', $data->weather[0]->icon . '.png');
             if (file_exists(implode(DIRECTORY_SEPARATOR, $file_path))) {
                 return array('temperature' => round($weather->temperature - 273.15), 'icon' => base_url($file_path));
             } else {
                 return '';
             }
         }
     }
     return '';
 }
예제 #3
0
 public function put_url($url)
 {
     if ($this->error) {
         return $this->getDebug() ? call_user_func_array('error', $this->error) : false;
     }
     $format = pathinfo($url, PATHINFO_EXTENSION);
     $temp = FCPATH . implode(DIRECTORY_SEPARATOR, array_merge($this->getTempDirectory(), array($this->getRandomName() . ($format ? '.' . $format : ''))));
     if (($temp = download_web_file($url, $temp)) && $this->put($temp, false)) {
         return file_exists($temp) ? @unlink($temp) : true;
     } else {
         return false;
     }
     return $this->getDebug() ? error('OrmUploader 錯誤!', '未知的 driver,系統尚未支援 ' . $this->getDriver() . ' 的空間!', '請檢查 config/system/orm_uploader.php 設定檔!') : false;
 }
예제 #4
0
 public function compressor($exceptionVersion = array(''), $includeVirtual = true)
 {
     if ($this->error) {
         return $this->getDebug() ? call_user_func_array('error', $this->error) : array();
     }
     $versions = array_merge($this->getVersions(), $includeVirtual ? $this->getVirtualVersions() : array());
     if ($exceptionVersion) {
         foreach ($versions as $key => $value) {
             if (in_array($key, $exceptionVersion)) {
                 unset($versions[$key]);
             }
         }
     }
     $files = array();
     foreach ($versions as $key => $version) {
         $files[$name = $key . $this->configs['separate_symbol'] . $this->getValue()] = download_web_file($this->url($key), FCPATH . implode(DIRECTORY_SEPARATOR, $fileName = array_merge($this->getTempDirectory(), array($name))));
     }
     if (!($files = array_filter($files))) {
         return true;
     }
     $this->CI->load->library('CompressorIo');
     $files = CompressorIo::postAndDownload($files, true);
     switch ($this->getDriver()) {
         case 'local':
             $path = FCPATH . implode(DIRECTORY_SEPARATOR, array_merge($this->getBaseDirectory(), $this->getSavePath())) . DIRECTORY_SEPARATOR;
             foreach ($files as $file) {
                 if (file_exists($file) && is_writable($file)) {
                     @rename($file, $path . pathinfo($file, PATHINFO_BASENAME));
                 }
             }
             return true;
             break;
         case 's3':
             $path = implode(DIRECTORY_SEPARATOR, array_merge($this->getBaseDirectory(), $this->getSavePath())) . DIRECTORY_SEPARATOR;
             foreach ($files as $file) {
                 if (file_exists($file) && is_writable($file)) {
                     if (!(S3::putObjectFile($file, $this->getS3Bucket(), $path . pathinfo($file, PATHINFO_BASENAME), S3::ACL_PUBLIC_READ, array(), array('Cache-Control' => 'max-age=315360000', 'Expires' => gmdate('D, d M Y H:i:s T', strtotime('+5 years')))) && @unlink($file))) {
                         return $this->getDebug() ? error('OrmImageUploader 錯誤!', '不明原因錯誤!', '請程式設計者確認狀況!') : false;
                     }
                 }
             }
             return true;
             break;
     }
     return $this->getDebug() ? error('OrmImageUploader 錯誤!', '未知的 driver,系統尚未支援 ' . $this->getDriver() . ' 的空間!', '請檢查 config/system/orm_uploader.php 設定檔!') : array();
 }
예제 #5
0
 public function put_url($url)
 {
     if ($this->error) {
         return $this->configs['debug'] ? call_user_func_array('error', $this->error) : false;
     }
     $temp = FCPATH . implode(DIRECTORY_SEPARATOR, array_merge($this->configs['temp_directory'], array($this->configs['temp_file_name'])));
     if (($temp = download_web_file($url, $temp)) && $this->put($temp, false)) {
         return file_exists($temp) ? @unlink($temp) : true;
     } else {
         return false;
     }
     return $this->configs['debug'] ? error('OrmImageUploader 錯誤!', '未知的 bucket,系統尚未支援' . $this->configs['bucket'] . ' 的空間!', '請檢查 config/system/orm_image_uploader.php 設定檔!') : false;
 }