public function __construct()
 {
     parent::__construct();
     if (!Cfg::system('delay_job', 'is_check') || !(($value = OAInput::post(Cfg::system('delay_job', 'key'))) !== null && $value == md5(Cfg::system('delay_job', 'value')))) {
         show_error('The delay job key or value error! Please confirm your program again.');
     }
 }
Beispiel #2
0
 public function __construct($orm = null, $column_name = null)
 {
     if (!($orm && $column_name && in_array($column_name, array_keys($orm->attributes())))) {
         return $this->error = array('OrmUploader 錯誤!', '初始化失敗!', '請檢查建構子參數!');
     }
     parent::__construct($orm, $column_name);
     $this->configs = Cfg::system('orm_uploader', 'file_uploader');
 }
Beispiel #3
0
 /**
  * Deletes all output cache file from a given uri
  *
  * @access public
  * @param string
  * @return bool
  */
 public function delete_all_cache($cache_append_path = null)
 {
     if (($CI =& get_instance()) && !isset($CI->cfg)) {
         $CI->load->library('cfg');
     }
     $path = implode(DIRECTORY_SEPARATOR, Cfg::system('cache', 'output')) . DIRECTORY_SEPARATOR;
     $cache_path = $path == '' ? APPPATH . 'cache/' : $path;
     $CI->load->helper('directory');
     return directory_clean(FCPATH . $cache_path);
 }
Beispiel #4
0
 public function __construct()
 {
     $this->CI =& get_instance();
     if (!self::$config) {
         self::$config = Cfg::system('elastica_search');
     }
     if (!self::$config['is_enabled']) {
         return;
     }
     if (self::$path === null) {
         array_pop(self::$path = explode(DIRECTORY_SEPARATOR, pathinfo(__FILE__, PATHINFO_DIRNAME)));
     }
     spl_autoload_register(array('Elastica_Core', '__autoload_elastica'));
 }
Beispiel #5
0
 function clean_cache_file($CI)
 {
     $CI->load->library('cfg');
     $cache = array();
     array_push($cache, Cfg::system('cache', 'file'));
     array_push($cache, Cfg::system('cache', 'output'));
     array_push($cache, Cfg::system('cache', 'config'));
     array_push($cache, Cfg::system('cache', 'model'));
     if (array_filter(array_map(function ($t) {
         return directory_delete(FCPATH . implode(DIRECTORY_SEPARATOR, $t), false);
     }, $cache))) {
         return '已經清除所有 file cache!';
     } else {
         return '清除 file cache 失敗!';
     }
 }
Beispiel #6
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;
 }
Beispiel #7
0
 public function __construct($fileName, $options = array())
 {
     parent::__construct($fileName);
     $this->configs = Cfg::system('image_gd_utility');
     $this->_init()->_setOptions($options);
 }
Beispiel #8
0
 public static function make_block9($files, $save)
 {
     if (!(count($files) >= 9)) {
         throw new ImageUtilityException('ImageUtility 錯誤!', '參數錯誤,files count:' . count($files), '參數 files 數量一定要大於 9!');
     }
     if (!(($module = Cfg::system('image_utility', 'module')) && in_array($module, array_keys($modules = Cfg::system('image_utility', 'modules'))))) {
         throw new ImageUtilityException('ImageUtility 錯誤!', '預設 module 錯誤!module:' . $module, '請檢查 config/system/image_utility.php 設定檔!');
     }
     if (!class_exists($modules[$module])) {
         include_once $modules[$module] . EXT;
     }
     return call_user_func_array(array($modules[$module], 'make_block9'), array($files, $save));
 }
Beispiel #9
0
 public function __construct($configs = array())
 {
     $this->CI =& get_instance();
     $this->CI->load->library("cfg");
     $this->configs = array_merge(Cfg::system('cell'), $configs);
     $this->setUseJsList(false);
     $this->setUseCssList(false);
 }
Beispiel #10
0
 public static function bind($column_name, $class_name = null)
 {
     if (!$column_name) {
         return error('OrmUploader 錯誤!', 'OrmUploader::bind 參數錯誤!', '請確認 OrmUploader::bind 的使用方法的正確性!');
     }
     if (!($trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT))) {
         return error('OrmUploader 錯誤!', '取得 debug_backtrace 發生錯誤,無法取得 debug_backtrace!', '請確認 OrmUploader::bind 的使用方法的正確性!');
     }
     if (!(isset($trace[1]['object']) && is_object($orm = $trace[1]['object']))) {
         return error('OrmUploader 錯誤!', '取得 debug_backtrace 回傳結構有誤,無法取得上層物件!', '請確認 OrmUploader::bind 的使用方法的正確性!');
     }
     if (!$class_name) {
         $class_name = get_class($orm) . Cfg::system('orm_uploader', 'instance', 'class_suffix');
     }
     if (is_readable($path = FCPATH . implode(DIRECTORY_SEPARATOR, array_merge(Cfg::system('orm_uploader', 'uploader', 'instance', 'directory'), array($class_name . EXT))))) {
         require_once $path;
     } else {
         $class_name = get_called_class();
     }
     return $object = new $class_name($orm, $column_name);
 }
 private function _combine_static_files()
 {
     if (ENVIRONMENT !== 'production' && Cfg::system('static', 'enable')) {
         return $this;
     }
     if (!is_writable($folder_path = FCPATH . implode(DIRECTORY_SEPARATOR, Cfg::system('static', 'assets_folder')) . DIRECTORY_SEPARATOR)) {
         return $this;
     }
     $this->load->driver('minify');
     foreach (array('js', 'css') as $key) {
         $list = $key . '_list';
         if ($this->{$list}) {
             $temp = ${$key} = array();
             foreach ($this->{$list} as $i => $value) {
                 if (!$value['is_minify'] || !preg_match("|^(" . preg_quote(base_url('')) . ")|", $value['path'])) {
                     if ($static_path = $this->_build_static_files($temp, $i, $key)) {
                         array_push(${$key}, $static_path, $value['path']) && ($temp = array());
                     } else {
                         (${$key} = array_merge(${$key}, $temp, array($value['path']))) && ($temp = array());
                     }
                 } else {
                     array_push($temp, $value['path']);
                 }
             }
             if ($static_path = $this->_build_static_files($temp, $i, $key)) {
                 array_push(${$key}, $static_path);
             } else {
                 ${$key} = array_merge(${$key}, $temp);
             }
             $this->{$list} = array_filter(${$key});
         }
     }
     return $this;
 }
Beispiel #12
0
 /**
  * Write a Cache File
  *
  * @access	public
  * @param 	string
  * @return	void
  */
 function _write_cache($output)
 {
     if (($CI =& get_instance()) && !isset($CI->cfg)) {
         $CI->load->library('cfg');
     }
     $path = implode(DIRECTORY_SEPARATOR, Cfg::system('cache', 'output')) . DIRECTORY_SEPARATOR;
     $ori_path = $path == '' ? APPPATH . 'cache/' : $path;
     $cache_path = $ori_path . ($this->cache_append_path == null ? '' : $this->cache_append_path);
     if (is_dir($ori_path) && is_really_writable($ori_path) && (!is_dir($cache_path) || !is_really_writable($cache_path))) {
         @mkdir($cache_path);
         @chmod($cache_path, 0777);
     }
     if (!is_dir($cache_path) or !is_really_writable($cache_path)) {
         log_message('error', "Unable to write cache file: " . $cache_path);
         return;
     }
     $uri = $CI->config->item('base_url') . $CI->config->item('index_page') . $CI->uri->uri_string();
     $uri = preg_replace('/^http(s)?:\\/\\//', '', $uri);
     $cache_path .= preg_replace('/\\/|:|\\./i', '_|_', $uri);
     if (!($fp = @fopen($cache_path, FOPEN_WRITE_CREATE_DESTRUCTIVE))) {
         log_message('error', "Unable to write cache file: " . $cache_path);
         return;
     }
     $expire = time() + $this->cache_expiration * 60;
     if (flock($fp, LOCK_EX)) {
         fwrite($fp, $expire . 'TS--->' . $output);
         flock($fp, LOCK_UN);
     } else {
         log_message('error', "Unable to secure a file lock for file at: " . $cache_path);
         return;
     }
     fclose($fp);
     @chmod($cache_path, FILE_WRITE_MODE);
     log_message('debug', "Cache file written: " . $cache_path);
 }
Beispiel #13
0
 function delay_job($class, $method, $params = array())
 {
     if (!($class && $method)) {
         return false;
     }
     if (($CI =& get_instance()) && !isset($CI->cfg)) {
         $CI->load->library('cfg');
     }
     $params = Cfg::system('delay_job', 'is_check') ? array_merge($params, array(Cfg::system('delay_job', 'key') => md5(Cfg::system('delay_job', 'value')))) : $params;
     return send_post(base_url(array_merge(Cfg::system('delay_job', 'controller_directory'), array($class, $method))), $params, Cfg::system('delay_job', 'is_wait_log'));
 }
Beispiel #14
0
 public static function recover($mode, $conditions = array())
 {
     if (!(class_exists($ori_model = get_called_class()) && class_exists($delete_model = 'Delete' . $ori_model))) {
         showError('The origin model or delete mode error!');
     }
     if (!(count($delete_columns = array_keys($delete_model::table()->columns)) && count($ori_columns = array_keys($ori_model::table()->columns)) && count($ori_columns) == count($delete_columns) - 1 && ($i = array_search('id', $delete_columns)) !== false)) {
         showError('The origin model or delete mode columns error!');
     }
     if (!in_array($mode, array('one', 'all'))) {
         showError('The mode type error!');
     }
     $origin_id = Cfg::system('model', 'recycle', 'origin_id');
     $conditions['select'] = implode(',', array_map(function ($delete_column) {
         return '`' . $delete_column . '`';
     }, $delete_columns));
     $conditions['order'] = isset($conditions['order']) ? $conditions['order'] : 'id DESC';
     switch ($mode) {
         case 'one':
             if (is_object($delete_object = $delete_model::find($mode, $conditions))) {
                 $sql = array();
                 foreach ($delete_columns as $delete_column) {
                     if ($delete_column != 'id') {
                         $sql[$delete_column == $origin_id ? 'id' : $delete_column] = $delete_object->{$delete_column};
                     }
                 }
                 return count($sql) && is_object($ori_object = $ori_model::create($sql)) && $ori_object->is_valid() && $delete_object->delete() ? $ori_object : false;
             }
             break;
         case 'all':
             unset($delete_columns[$i]);
             $count = $delete_model::count($conditions);
             $conditions['limit'] = Cfg::system('model', 'recycle', 'limit');
             $delete_ids = array();
             for ($offset = isset($conditions['offset']) ? $conditions['offset'] : 0; $offset < $count; $offset += $conditions['limit']) {
                 $conditions['offset'] = $offset;
                 $delete_objects = $delete_model::find('all', $conditions);
                 if (count($delete_objects)) {
                     $sqls = array_filter(array_map(function ($delete_object) use($delete_columns, $origin_id) {
                         $sql = array();
                         foreach ($delete_columns as $delete_column) {
                             if ($delete_column != 'id') {
                                 $sql[$delete_column == $origin_id ? 'id' : $delete_column] = '"' . $delete_object->{$delete_column} . '"';
                             }
                         }
                         return count($sql) ? $sql : null;
                     }, $delete_objects));
                     if (count($sqls) && count($delete_objects) && count($delete_ids = array_merge($delete_ids, array_map(function ($delete_object) {
                         return $delete_object->id;
                     }, $delete_objects)))) {
                         $ori_model::query("INSERT INTO `" . $ori_model::table()->table . "`(" . implode(",", array_map(function ($ori_column) {
                             return "`" . $ori_column . "`";
                         }, $ori_columns)) . ") VALUES" . implode(',', array_map(function ($sql) {
                             return "(" . implode(",", $sql) . ")";
                         }, $sqls)));
                     }
                 }
             }
             if ($count = count($delete_ids)) {
                 $delete_model::delete_all(array('conditions' => array('id IN (?)', $delete_ids)));
             }
             return $count ? true : false;
             break;
         default:
             return false;
             break;
     }
 }
Beispiel #15
0
 public function getLoginUrl($config = array())
 {
     return parent::getLoginUrl(array_merge(array('scope' => Cfg::system('facebook', 'scope')), $config));
 }