Esempio n. 1
0
 /**
  * Activate filter
  */
 function activate()
 {
     core::dprint('Activate RSS');
     tpl_loader::set_template('rss');
     core::lib('renderer')->set_content_type('text/xml');
     // 'application/rss+xml'
 }
Esempio n. 2
0
 /**
  * Run block
  * Called from module::run_block
  * 
  * Params passed to 'block.data' 
  * action converted to object!
  * 
  * Extended params passed to {$block.params}
  * 
  * @throws modules_exception
  */
 function run($action, $params)
 {
     $_tag = $this->get_context()->get_tag();
     core::dprint('[BLOCK] start ' . $_tag . '::' . $action, core::E_DEBUG);
     $return = false;
     // @todo check for callable
     if (is_callable(array($this, $action))) {
         if (!empty($params)) {
             // convert parameters to object
             $c_params = functions::array2object($params);
             $data = call_user_func(array($this, $action), $c_params);
         } else {
             $data = call_user_func(array($this, $action));
         }
         // get block builtin properties
         $props = $this->get_block($action);
         // assign params
         $props['params'] = $params;
         $return = $this->get_context()->get_core()->lib('renderer')->render_block($props, $data);
     } else {
         throw new modules_exception('Not callable action supplied - ' . $action);
     }
     core::dprint('[/BLOCK] end ' . $_tag . '::' . $action, core::E_DEBUG);
     return $return;
 }
Esempio n. 3
0
 function run()
 {
     /**@var tf_sat $sat */
     $sat = core::module('sat');
     $site = $sat->get_current_site();
     $json_file = loader::get_public('assets/' . $site->domain . '.json');
     $last_mod = @filemtime($json_file);
     $tree_last_mod = 0;
     if ($last_mod) {
         $last_node = $sat->get_node_handle()->set_where('site_id = %d', $sat->get_current_site_id())->set_order('updated_at DESC')->load_first();
         $tree_last_mod = $last_node ? $last_node->updated_at : 0;
         core::dprint(__METHOD__ . ': cached');
         // uptodate
         if ($tree_last_mod <= $last_mod) {
             $this->renderer->set_ajax_answer(file_get_contents($json_file))->ajax_flush();
             return;
         }
     }
     core::dprint(__METHOD__ . ': fetch!');
     $tree = $sat->get_current_site_tree();
     $allowedKeys = array('title', 'url');
     array_walk($tree, function (&$v) use($allowedKeys) {
         $v = array_intersect_key($v, array_flip($allowedKeys));
     });
     $tree = array_values($tree);
     // cache
     file_put_contents($json_file, functions::json_encode($tree));
     $this->renderer->set_ajax_answer($tree)->ajax_flush();
 }
Esempio n. 4
0
 /**
  * Load smarty3 
  * @param mixed $params
  * @return Smarty3
  */
 static function _init_smarty3($params)
 {
     $smarty = false;
     // check smarty autoload
     $status = class_exists('Smarty');
     $file = loader::get_public() . loader::DIR_EXT . 'smarty3/Smarty.php';
     if (!file_exists($file)) {
         throw new lib_exception('Smarty3 file not found');
     }
     require $file;
     if (!class_exists('Smarty3', false)) {
         throw new lib_exception('Smarty3 class not found');
     }
     $smarty = new Smarty3();
     $smarty->debugging = isset($params['debugging']) ? $params['debugging'] : core::selfie()->cfg('debug_templates', false);
     $smarty->caching = isset($params['caching']) ? $params['caching'] : false;
     $smarty->cache_lifetime = isset($params['cache_lifetime']) ? $params['cache_lifetime'] : 120;
     $smarty->cache_locking = true;
     $smarty->compile_check = isset($params['compile_check']) ? $params['compile_check'] : true;
     $smarty->force_compile = isset($params['force_compile']) ? $params['force_compile'] : false;
     $smarty->merge_compiled_includes = false;
     $smarty->error_reporting = error_reporting() & ~E_NOTICE;
     $smarty->addPluginsDir(loader::get_public() . loader::DIR_EXT . 'smarty3/plugins');
     // add asset compiler plugin
     $smarty->addPluginsDir(loader::get_public(loader::DIR_EXT . 'smarty-sacy'));
     core::dprint(array('[smarty3] dist:%s %s debugging: %s, caching: %s, force: %s, ttl: %d', $status ? 'composer' : 'old', Smarty3::SMARTY_VERSION, $smarty->debugging ? 'yes' : 'no', $smarty->caching ? 'yes' : 'no', $smarty->force_compile ? 'yes' : 'no', $smarty->cache_lifetime), core::E_RENDER);
     $template = core::selfie()->cfg('template');
     self::$parser = $smarty;
     self::set_template($template);
     return $smarty;
 }
Esempio n. 5
0
 /**
  * Activate filter
  */
 function activate()
 {
     core::dprint('Activate RSS');
     // tpl_loader::set_template('');
     core::lib('renderer')->set_page_template('root.embed');
     tf_request::set_ident('embed', 'yes');
 }
Esempio n. 6
0
 /**
  * Remember!
  * Assign current item in controller for comment linking!
  */
 function run()
 {
     if (loader::in_ajax() !== true) {
         throw new controller_exception('Cant touch this ' . __METHOD__);
         return false;
     }
     core::dprint('run comment modify');
     $pctl = core::modules()->get_router()->get_controller();
     $user = core::lib('auth')->get_user();
     /**
      * Parent item, must be assigned thru @see module_controller::set_current_item()
      * @var abs_collection_item
      */
     $post = $pctl->get_current_item();
     // var_dump(get_class($post), core::get_modules()->get_router()->get_name());
     if (!$post) {
         throw new controller_exception('No item assigned');
     }
     if (!$post->has_behavior('sat.commentable')) {
         throw new controller_exception('Not commentable');
     }
     $comments = $post->behavior('sat.commentable')->get_attach_model();
     //get_comments();
     $request = core::lib('request');
     $renderer = core::lib('renderer');
     $user_id = core::lib('auth')->get_user()->id;
     $pid = (int) $request->post('pid', 0);
     $limit = core::selfie()->cfg('comment_interval', 60);
     $auth = core::lib('auth');
     /** @var aregistry $sd */
     $sd = $auth->get_current_session()->get_storage();
     $time = $sd->comments_last_time;
     //$time = $comments->get_last_time($pid, $user_id);
     // disallow by interval
     if ($time && $time + $limit > time()) {
         $pctl->set_null_template();
         $renderer->set_ajax_answer(array('status' => false, 'id' => 0, 'message' => vsprintf(i18n::T('sat\\comment_interval_restriction'), $time + $limit - time())))->ajax_flush();
         // else core::get_instance()->set_message(array('content', 'comment_interval_restriction'));
         return;
         // exit
     }
     $sd->comments_last_time = time();
     $username = functions::request_var('username', '');
     $text = functions::request_var('text', '');
     $api = functions::request_var('api');
     $id = $comments->modify(array('user_ip' => core::lib('auth')->get_user_ip(true), 'user_id' => $user_id, 'ctype_id' => $post->get_ctype_id(), 'username' => $username, 'pid' => $pid, 'text' => $text, 'type' => functions::request_var('type', 0), 'tpid' => functions::request_var('tpid', 0), 'api' => $api));
     $comment = $comments->get_item_by_id($id);
     if (!$comment) {
         throw new controller_exception('[ajax] Comment create failed');
     }
     $comment->load_secondary();
     $renderer->set_data('comment', $comment->render())->set_ajax_answer(array('status' => true, 'id' => $id))->set_ajax_message(i18n::T('sat\\comment_posted'));
     //->set_main_template('content/comment/view');
     $renderer->ajax_flush('shared/comments/comment');
     // alright, update counter
     return $id;
 }
Esempio n. 7
0
 function load_level(&$i)
 {
     core::dprint(array('load:: %d - %s', $i, $this->title));
     $this->load_secondary();
     if ($i > 1) {
         --$i;
         foreach ($this->_childrens as $c) {
             $c->load_level($i);
         }
     }
     return $this;
 }
Esempio n. 8
0
 function init($root)
 {
     if ($root) {
         $this->_root = $root;
         $file = $this->_root . 'template.php';
         if (file_exists($file)) {
             core::dprint(array('Load template config : %s', $file), core::E_DEBUG3);
             $this->init_config($this->_normalize(include $file));
         }
     }
     return $this;
 }
Esempio n. 9
0
 /**
  * Doamin matched in initial_route
  */
 function set_current()
 {
     $this->_current = true;
     if (0 != $this->template) {
         $core = core::get_instance();
         $templates = $core->get_cfg_var('templates');
         if (isset($templates[$this->template])) {
             core::dprint(array('SITE_LAYOUT : %s', $templates[$this->template]), core::E_DEBUG1);
             core::lib('renderer')->set_layout($templates[$this->template]);
         }
     }
 }
Esempio n. 10
0
 /** utf8-cp1251 */
 static function convert_from($input)
 {
     if (empty($input)) {
         return $input;
     }
     if (self::$_charset == self::UNICODE) {
         return $input;
     }
     if (is_array($input)) {
         return self::convert_from_array($input);
     }
     $return = is_string($input) ? iconv(self::UNICODE, str_replace('-', '', self::$_charset), $input) : $input;
     if (!$return) {
         core::dprint(array('strings::convert_from fail %s', $input), core::E_DEBUG3);
     }
     return $return;
 }
Esempio n. 11
0
 /**
  * Upload
  * @param array $_FILES[key]
  * @param string dst_path (dir)
  * @param string force use name
  * @param array config for uploader
  *   force_override => bool
  */
 function upload_file(array $file_data, $to_file, $use_name = false, $config = array())
 {
     if (!is_dir($to_file) || !is_writable($to_file)) {
         throw new uploader_exception('Destanation not available ' . $to_file);
     }
     // $file_type      = $file_data['type'];
     $file_tmpfile = $file_data['tmp_name'];
     $file_name = $file_data['name'];
     $file_size = $file_data['size'];
     if (substr($to_file, -1, 1) != '/') {
         $to_file .= '/';
     }
     if ($file_size <= 0) {
         throw new uploader_exception('Nothing uploaded ' . $to_file);
     }
     if ($use_name) {
         $file_name = $use_name;
     } else {
         // remove bad charz
         $file_name = preg_replace('[^a-z0-9_]i', '', $file_name);
         if (substr($file_name, 0, 1) == '.') {
             $file_name = date('jny_His') . $file_name;
         }
         //пустое имя файла заменяем на дату
     }
     $to_file = $to_file . $file_name;
     if (file_exists($to_file) && empty($config['force_override'])) {
         throw new uploader_exception("File {$file_name} exists. Cant overwrite.");
     }
     $u_uploadsucc = false;
     core::dprint(array('Uploading %s -> %s', $file_tmpfile, $to_file));
     if (!empty($file_tmpfile) && is_file($file_tmpfile)) {
         if (copy($file_tmpfile, $to_file)) {
             $u_uploadsucc = true;
             @chmod($to_file, 0777);
         } else {
             if (move_uploaded_file($file_tmpfile, $to_file)) {
                 $u_uploadsucc = true;
                 @chmod($to_file, 0777);
             }
         }
         $l_size_after = filesize($to_file);
     }
     return $to_file;
 }
Esempio n. 12
0
/**
 * Block entry point
 * 
 * @param array
 *     module                  // module tag
 *     action                  // block action
 *     cache                   // seconds, cache data
 *     other params
 */
function smarty_function_block($params, &$smarty)
{
    $core = core::get_instance();
    foreach ($params as $k => $v) {
        if (!isset(${$k})) {
            ${$k} = $v;
        }
    }
    $cache_this = false;
    // $core->time_check('c1', true, true);
    if (isset($cache)) {
        $cacher_factory = core::lib('cache');
        if ($cacher_factory->has_memory()) {
            $cacher = $cacher_factory->get_memory_handle();
            $cache_time = $cache;
            unset($params['cache']);
            $cache_id = 'block_' . md5(serialize($params));
            $result = $cacher->get($cache_id, false);
            if (false !== $result) {
                core::dprint('cache hit : ' . $params['action'] . ' - ' . $core->time_check('c1', true));
                return $result;
            }
            $cache_this = true;
        }
    }
    try {
        if (empty($module)) {
            $module = 'core';
        }
        if ($pmod = $core->module($module)) {
            unset($params['action'], $params['module']);
            $result = $pmod->run_block($action, $params);
            if ($cache_this) {
                $cacher->set($cache_id, $result, $cache_time);
            }
            // core::var_dump('no cache : ' . $cache_id, $core->time_check('c1', true));
            return $result;
        }
    } catch (modules_exception $e) {
        return '[block] ' . $e->getMessage();
    }
    return false;
}
Esempio n. 13
0
 /**
  * Create a database handle
  * Factory method
  * @param array params
  */
 public static function get(array $config)
 {
     $engine = $config['engine'];
     if (isset(self::$dbs[$engine])) {
         return self::$dbs[$engine];
     }
     $engine_script = loader::get_root() . loader::DIR_MODULES . 'core/dbal/' . $engine . loader::DOT_PHP;
     core::dprint('[db] ' . $engine_script);
     fs::req($engine_script, true);
     if (!isset($config['server'])) {
         $config['server'] = 'localhost';
     }
     // create instance
     $class = "{$engine}_db";
     try {
         return self::$dbs[$engine] = new $class($config['server'], $config['login'], $config['password'], $config['database'], $config['prefix']);
     } catch (dbal_exception $e) {
         return false;
     }
 }
Esempio n. 14
0
 /**
  * Run
  * PHP5.4: Declaration of users_controller::run() should be compatible with front_controller::run($route, $params) : 2048
  * @return template
  */
 public function run($r, $params = null)
 {
     // base routes
     if ($this->router->get_current_route()) {
         return parent::run($r, $params);
     }
     $this->set_section_name('users');
     // default action
     if (empty($r->action)) {
         $r->action = 'users';
     }
     $this->set_req($r);
     if (!is_callable(array($this, $r->action))) {
         throw new controller_exception('No such action', router_exception::ERROR);
     }
     // call method
     core::dprint('users_controller::' . $r->action);
     call_user_func(array($this, $r->action), $r);
     return $this->get_template();
 }
Esempio n. 15
0
 /**
  * Threader::Threader()
  *
  * The constructor which opens the process.
  *
  * @param mixed $cmd - Execute a shell command
  * @param mixed $vars - Pass arguments to shell command
  * @param string $name - Identifies your thread (useful for debug)
  * @return void
  */
 function Threader($cmd = null, $vars = null, $name = null, $stdout_file = null)
 {
     $descriptorspec = array(self::STDIN => array("pipe", "r"), self::STDOUT => array("pipe", "w"), self::STDERR => array("pipe", "w"));
     if ($stdout_file) {
         $this->_stdout_file = $stdout_file;
         $descriptorspec[self::STDOUT] = array("file", $stdout_file, "w");
         core::dprint('[THREAD] LOG ' . $stdout_file);
     }
     $pipes = array();
     if (!empty($cmd)) {
         $this->threadName = $name;
         try {
             //    if ($err = stream_get_contents($pipes[2]))
             $command = "{$cmd} {$vars}";
             $this->rid = proc_open($command, $descriptorspec, $this->pipes, null, null);
             @stream_set_blocking($this->pipes[self::STDIN], 0);
             @stream_set_blocking($this->pipes[self::STDOUT], 0);
             @stream_set_blocking($this->pipes[self::STDERR], 0);
             @stream_set_write_buffer($this->pipes[self::STDIN], 0);
             @stream_set_write_buffer($this->pipes[self::STDOUT], 0);
             @stream_set_write_buffer($this->pipes[self::STDERR], 0);
             /*                
                          stream_set_blocking($this->pipes[self::STDIN]  , 0);
                          stream_set_blocking($this->pipes[self::STDOUT] , 0);
                          stream_set_blocking($this->pipes[self::STDERR] , 0);
                          
                          // don't buffer stdout or stderr
                          stream_set_write_buffer($this->pipes[self::STDIN], 0);
                          stream_set_write_buffer($this->pipes[self::STDOUT], 0);
                          stream_set_write_buffer($this->pipes[self::STDERR], 0);
             */
             // Display the current STDOUT meta data.
             // print_r(stream_get_meta_data($this->pipes[self::STDIN]));
             core::dprint("[THREAD] " . $command);
             $this->active = true;
         } catch (exception $e) {
             $this->active = false;
             $this->error = $e->getMessage();
         }
     }
 }
Esempio n. 16
0
 /**
  * Create a database handle
  * Factory method
  * @param array params
  *  engine - pdo
  *      type - mysql
  */
 public static function get(array $config)
 {
     require_once 'modules/core/dbal/dbal.php';
     $engine = $config['engine'];
     $type = @$config['type'];
     $key = $engine . $type;
     if (isset(self::$dbs[$key])) {
         return self::$dbs[$key];
     }
     $engine_script = loader::DIR_MODULES . 'core/dbal/' . $engine . loader::DOT_PHP;
     core::dprint('[db] ' . $engine_script);
     fs::req($engine_script, true);
     // create instance
     $class = "{$engine}_db";
     try {
         return self::$dbs[$key] = new $class($config);
     } catch (dbal_exception $e) {
         core::dprint($e->getMessage());
         return false;
     }
 }
Esempio n. 17
0
 /**
  * Page hit
  * $cacher->cache_page($_SERVER['REQUEST_URI'], $this->lib('auth')->get_user());
  */
 function cache_page($uri, $buffer)
 {
     if (!$this->_enabled) {
         return false;
     }
     $hash = $this->_hash($uri);
     core::dprint('cache_page - prepare ' . $uri . ' x ' . $hash);
     // if cached item already loaded
     if ($this->_cache_item) {
         $item = $this->_cache_item;
     } else {
         $item = $this->get_by_hash($hash);
     }
     if ($item) {
         $just_cached = false;
         /*
          array('hits' => 10, 'per' => '600', 'cache' => 180)
         */
         if (!$item->is_cached()) {
             $period = $item->access_time - $item->prev_access_time;
             foreach ($this->_threshold_table as $row) {
                 if ($row['per'] <= $period && $row['hits'] - 1 <= $item->counter) {
                     // found rule
                     core::var_dump($row);
                     $this->_cache_page($item, $buffer, $row);
                     $just_cached = true;
                     break;
                 }
             }
         }
         // already hitted
         if (!$just_cached) {
             $item->hit();
         }
     } else {
         // new
         $this->handle->create(array('url' => $uri, 'url_hash' => $hash));
     }
 }
Esempio n. 18
0
 /**
  * Construct
  */
 function __construct($config)
 {
     $this->config = $config;
     $config = $this->check_config();
     // if (empty($config['server'])) $config['server'] = 'localhost';
     if (!extension_loaded('pdo')) {
         throw new dbal_exception('The PDO extension is required');
     }
     if (!in_array($config['type'], PDO::getAvailableDrivers())) {
         throw new dbal_exception("PDO {$config['type']} driver is not installed");
     }
     try {
         $dsn = $this->make_dsn();
         core::dprint($dsn);
         $this->db_connect_id = new PDO($dsn, $this->config['login'], $this->config['password'], $this->config['driver_options']);
         // set the PDO connection to perform case-folding on array keys, or not
         // $this->db_connection_id->setAttribute(PDO::ATTR_CASE, $this->_caseFolding);
         // always use exceptions.
         $this->db_connect_id->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $e) {
         throw new dbal_exception($e->getMessage());
     }
 }
Esempio n. 19
0
 /**
  * Create handle
  * @param array params
  */
 public static function factory($parms = 'smarty')
 {
     $smarty = false;
     // $test = loader::$root_path . loader::DIR_MODULES . 'core/tplparser/smarty/Smarty.class.php';
     $test = loader::get_root() . loader::DIR_EXT . 'smarty/Smarty.class.php';
     if (fs::file_exists($test)) {
         require $test;
         $smarty = new Smarty();
         $smarty->compile_check = true;
         $smarty->force_compile = false;
         // true;
         $template = core::get_instance()->get_cfg_var('template');
         $smarty->caching = false;
         //TRUE;
         //$smarty->cache_lifetime = 3600;
         $smarty->debugging = core::get_instance()->get_cfg_var('debug_templates');
     } else {
         $smarty = new tplparser_mock();
         core::dprint('[tplparser] using mock');
     }
     self::$parser = $smarty;
     self::set_template($template);
     return $smarty;
 }
Esempio n. 20
0
 /**
  * Run 
  * /usr/local/bin/ffmpeg -i ./268988.wmv -an -ss 00:00:03 -t 00:00:01 -r 1 -y -s 320x240 ./frame%d.wmv.jpg
  */
 protected function run()
 {
     $cmd = $this->ffmpeg_exe . ' ' . $this->ffmpeg_params . ' 2>&1';
     $this->_output = false;
     if ($this->valid_encoder()) {
         $this->_output = shell_exec($cmd);
     }
     core::dprint($cmd);
     return $this->_output;
 }
Esempio n. 21
0
 /**    
  * Widgets Block
  * @param array (name[@parent], id)
  * @return string list
  */
 function widgets($params = false)
 {
     /** @var tf_sat $module */
     $module = $this->get_context();
     $where = 'site_id = ' . $module->get_current_site_id() . ' AND ';
     if (isset($params->name)) {
         $where .= sprintf('name = "%s"', $params->name);
     } else {
         if (isset($params->id)) {
             $where .= sprintf('id = "%d"', $params->id);
         }
     }
     $widget_group = $module->get_widget_group_handle()->set_where($where)->set_limit(1)->load()->get_item();
     if (!$widget_group) {
         core::dprint(__METHOD__ . ' widget group not found');
         return false;
     }
     $widget_group->get_widgets()->parse_data();
     return $widget_group->render();
 }
Esempio n. 22
0
 /**
  * format on load
  * Cast data to original type
  */
 function format_field_on_load($vf, &$fld)
 {
     $type = $vf['type'];
     switch ($type) {
         case 'unixtime':
             //---------------
             $fld = (int) $fld;
             break;
         case 'boolean':
             //---------------
             $fld = (bool) $fld;
             break;
         case 'numeric':
             //---------------
             if (!empty($vf['float'])) {
                 $fld = (double) $fld;
             } else {
                 if (!empty($vf['long'])) {
                     $fld = (double) $fld;
                 } else {
                     $fld = (int) $fld;
                 }
             }
             break;
         case 'file':
         case 'image':
             //---------------
             // if length of sql-text is not enought, unserialize will fail!
             // unserialize value from storage
             if (!empty($fld) && !is_array($fld)) {
                 $fld = @unserialize($fld);
                 if (false === $fld) {
                     core::dprint(array('WARNING! Unserialize failed %s : %s', get_class($this), $vf['type']), core::E_ERROR);
                 }
             }
             if (!is_array($fld)) {
                 $fld = array();
             }
             if (!empty($fld['file'])) {
                 $spacing_path = '';
                 if (!empty($vf['spacing'])) {
                     $spacing_path = '/' . substr(substr($fld['file'], strrpos($fld['file'], '/', 0)), 1, $vf['spacing']);
                 }
                 // make url for it
                 $fld['url'] = core::get_instance()->get_static_url() . '/uploads/' . $vf['storage'] . $spacing_path . substr($fld['file'], strrpos($fld['file'], '/', 0));
                 if (!empty($vf['thumbnail'])) {
                     $fld['thumbnail'] = array('url' => preg_replace('@\\.([^\\.]+)$@', '.thumb.$1', $fld['url']), 'file' => preg_replace('@\\.([^\\.]+)$@', '.thumb.$1', $fld['file']));
                 }
                 if (!empty($vf['original'])) {
                     $fld['original'] = array('url' => preg_replace('@\\.([^\\.]+)$@', '.orig.$1', $fld['url']), 'file' => preg_replace('@\\.([^\\.]+)$@', '.orig.$1', $fld['file']));
                 }
             }
             break;
     }
 }
Esempio n. 23
0
/**
 * Block entry point
 * 
 * @param array
 *     module                  // module tag
 *     action                  // block action
 *     cache                   // seconds, cache data
 *     other params
 * @param Smarty3 $smarty
 */
function smarty_function_satblock($params, &$smarty)
{
    if (empty($params['action'])) {
        throw new block_exception('Bad action');
    }
    $orig_params = $params;
    $orig_action = $params['action'];
    // module.action
    if (strpos($params['action'], '.') !== false) {
        $t = explode('.', $params['action']);
        $params['action'] = $t[1];
        $params['module'] = $t[0];
    }
    $action = @$params['action'];
    $module = @$params['module'];
    $cache = @$params['cache'];
    $cache_id = null;
    $cacher = null;
    $with_cache = false;
    $cached = false;
    $buffer = null;
    $core = core::selfie();
    // unpack params to local scope
    // extract($params, EXTR_SKIP);
    /**
     * Cache block
     */
    if (!empty($cache)) {
        /** @var cache $cacher_factory */
        $cacher_factory = core::lib('cache');
        $cacher = $cacher_factory->has_memory() ? $cacher_factory->get_memory_handle() : $cacher_factory->get_file_handle();
        if ($cacher) {
            $cache_time = $cache;
            unset($params['cache']);
            $cache_id = 'block_' . md5(serialize($params));
            $result = $cacher->get($cache_id, false);
            if (null !== $result) {
                core::dprint('..block cached "' . $orig_action . '" using ' . get_class($cacher), core::E_NOTICE);
                $buffer = $result;
                $cached = true;
            }
            $with_cache = true;
        }
    }
    if (!$cached) {
        try {
            if (empty($module)) {
                $module = 'core';
            }
            if ($pmod = core::module($module)) {
                unset($params['action'], $params['module']);
                // Run block action
                $buffer = $pmod->run_block($action, $params);
                if ($with_cache) {
                    $cacher->set($cache_id, $buffer, $cache_time);
                }
            }
        } catch (module_exception $e) {
            return '[block] module-error: ' . $e->getMessage();
        } catch (block_exception $e) {
            return '[block] error: ' . $e->getMessage();
        }
    }
    // debug block
    if (core::is_debug() && $core->cfg('debug_templates')) {
        $dparams = array();
        foreach ($orig_params as $pk => $pv) {
            $dparams[] = sprintf('data-%s = "%s"' . PHP_EOL, $pk, $pv);
        }
        /** @var Smarty_Template_Source $source */
        $source = $smarty->source;
        // @todo how to get current line?
        // $dparams []= sprintf('data-parent-template = "%s"' . PHP_EOL, $source->filepath);
        $dsparams = join(' ', $dparams);
        $buffer = <<<DBG
        <satblock class="sat-block" {$dsparams}>
        {$buffer}
        </satblock>
DBG;
    }
    return $buffer;
}
Esempio n. 24
0
 /**
  * SQL query
  *
  * @param mixed $query
  * @param mixed $transaction
  */
 function sql_query($query, $options = null)
 {
     if (empty($query)) {
         core::dprint('Empty sql_query call');
         return false;
     }
     if (is_array($query)) {
         $query = vsprintf($query[0], array_slice($query, 1));
     }
     $starttime = microtime(true);
     ++$this->_counter;
     $tm_ = core::get_instance()->time_check('mysql', 1, 1);
     unset($this->query_result);
     $this->num_queries++;
     $this->_connect();
     if (!$this->_connect_id && class_exists('core', 0)) {
         core::dprint(array('[SQL_ERROR] no connect %s', $query), core::E_SQL);
     }
     if (!empty($options['mysql_unbuffered'])) {
         $this->query_result = mysql_unbuffered_query($query, $this->_connect_id);
     } else {
         $this->query_result = mysql_query($query, $this->_connect_id);
     }
     $this->_last_query = $query;
     if ($this->query_result) {
         $endtime = microtime(true);
         $this->sql_time += $endtime - $starttime;
         if (core::get_instance()->cfg('debug_sql') >= 100) {
             core::dprint('<b>' . $this->_counter . ' ' . $this->num_queries . ')  ' . htmlspecialchars($query) . ' [' . round($this->sql_time, 4) . 'ms]</b>');
             // debug code idea by jovani (phpbbguru.net/community/profile.php?mode=viewprofile&u=12)
             if (strtoupper(substr($query, 0, 6)) == "SELECT") {
                 $x = mysql_query("EXPLAIN {$query}", $this->_connect_id);
                 $z = array();
                 while ($y = mysql_fetch_array($x, MYSQL_ASSOC)) {
                     core::dprint("&nbsp;&nbsp;&raquo; tbl = " . $y['table'] . " type = " . $y['type'] . " possible = " . $y['possible_keys'] . " used = " . $y['key'] . " len = " . $y['key_len'] . " ref = " . $y['ref'] . " rows = " . $y['rows'] . " extra = " . $y['Extra']);
                 }
                 mysql_free_result($x);
             }
         }
         // replace password in query for log
         $query = preg_replace("#password = '******'#U", "password = '******'", $query);
         if (core::get_instance()->get_cfg_var('debug_sql')) {
             $tm_ = core::get_instance()->time_check('mysql', 1);
             core::dprint($this->_counter . '. ' . $query . ' --[time : ' . $tm_ . ' s]', core::E_SQL);
             if (0 && ($console = core::lib('console'))) {
                 $dbg_trace = $console->debug_backtrace_smart();
                 if (isset($dbg_trace[2]) && !isset($dbg_trace[2]['class'])) {
                     $dbg_trace[2]['class'] = '';
                 }
                 $dbg_info = $dbg_trace[1]['file'] . ' in ' . $dbg_trace[1]['line'] . (!isset($dbg_trace[2]) ? '' : " ({$dbg_trace[2]['class']}::{$dbg_trace[2]['function']}) ");
                 core::dprint(' -- in ' . $dbg_info);
             }
         }
     } else {
         $endtime = microtime(true);
         $this->sql_time += $endtime - $starttime;
         if (core::get_instance()->get_cfg_var('debug_sql')) {
             $tm_ = core::get_instance()->time_check('mysql', 1);
             $err = $this->sql_error();
             core::dprint('[* SQL FAIL] ' . $query, core::E_SQL);
             core::dprint('[* SQL FAIL] ' . $err['message'] . ' : ' . $err['code'] . ' --[time : ' . $tm_ . ' s]', core::E_SQL);
         }
     }
     return $this->query_result;
 }
Esempio n. 25
0
<?php

require "./loader.php";
$cooks = core::lib('sape_cacher')->get('cookie', 1);
//var_dump($cooks);
$prolong_days = 14;
foreach ($cooks as $s0 => $cook) {
    foreach ($cook as $s1 => $host) {
        foreach ($host as $s2 => $path) {
            foreach ($path as $s3 => $data) {
                if (!empty($data['expires'])) {
                    $prolongated = date('Y-m-d H:i:s', time() + 24 * 3600 * $prolong_days);
                    core::dprint(array('[COOKIE] prolongate from %s to %s', $data['expires'], $prolongated));
                    $cooks[$s0][$s1][$s2][$s3]['expires'] = $prolongated;
                }
            }
        }
    }
}
/*
  [0]=>
  array(1) {
    ["moswar.ru"]=>
    array(1) {
      ["/"]=>
      array(4) {
        ["PHPSESSID"]=>
        array(6) {
          ["name"]=>
          string(9) "PHPSESSID"
          ["value"]=>
Esempio n. 26
0
 /**
  * get related field value for parent item
  *
  * whereis PID!!!
  * @return extrafs_value_item
  */
 function get_field_value($force = false)
 {
     if (!$this->get_container()->get_extra_fs_values_collection()) {
         return false;
     }
     /*
      clone-error-fix test:
      var_dump($this->get_container()->get_parent()->get_id());
     */
     if (!isset($this->_field_value) || $force) {
         /*
             $p = $this->get_container()->get_parent();
             $p->get_id();
             $this->_field_value =
             $this->container->get_module()->get_value_handle()
                 ->set_limit(1)
                 ->set_where('fid = %d AND pid = %d', $this->id, $p->id)
                 ->load()
                 ->get_item();
         */
         $this->_field_value = $this->get_container()->get_extra_fs_values_collection()->get_item_by_prop('fid', $this->id);
         core::dprint(array('try fid: %d : %s', $this->id, $this->_field_value ? '+' : '-'));
         /** FORMATTED VALUE */
         $this->fvalue = $this->efs_format_load($this->_field_value ? $this->efs_format_unserialize($this->_field_value->value) : null);
         // core::var_dump($this->fvalue);
     }
     return $this->_field_value;
 }
Esempio n. 27
0
 /**
  * Unlink
  * @return bool status
  */
 public static function unlink($file)
 {
     core::dprint('fs::unlink ' . $file);
     if (!file_exists($file)) {
         return false;
     }
     unlink($file);
     return true;
 }
Esempio n. 28
0
 /**
  * Wget url
  * @param string url
  * @param mixed to file/buffer
  * @throws leecher_exception
  */
 function wget($url, $to_file = false, $arguments = array())
 {
     $ip = $this->_last_ip ? $this->_last_ip : 'default';
     core::dprint("[WGET][{$ip}] {$url} |ref {$this->_referer}  " . ($this->_block_activity ? ' @@BLOCKED@@' : '') . ($this->_postValues ? '[POST]' : ''), core::E_TRACE);
     if ($this->_block_activity) {
         return false;
     }
     $this->_redirects = array();
     //$arguments = array();
     $_arguments = array();
     if (!empty($this->_postValues)) {
         $_arguments['PostValues'] = $this->_postValues;
         $_arguments["RequestMethod"] = "POST";
         $this->_postValues = null;
     }
     $error = $this->GetRequestArguments($url, $arguments);
     $arguments["Referer"] = $this->_referer;
     $error = $this->Open($arguments);
     if (!empty($error)) {
         throw new http_exception('open : ' . $error, 0, $this);
     }
     $arguments = array_merge($arguments, $_arguments);
     $error = $this->SendRequest($arguments);
     if (!empty($error)) {
         $this->_defaults();
         throw new http_exception('send : ' . $error, 0, $this);
     }
     $headers = array();
     $error = $this->ReadReplyHeaders($headers);
     $this->_defaults();
     /*var_dump($headers, $this->response_status);*/
     if (!empty($error)) {
         throw new http_exception('ReadReplyHeaders : ' . $error, 0, $this);
     }
     if ($this->response_status == "404") {
         throw new http_exception('Not found : ' . $url, 404, $this);
     }
     /*
     switch($this->response_status)
     $headers["location"]
     */
     // Get body
     $buffer = '';
     $output = '';
     for (;;) {
         $error = $this->ReadReplyBody($buffer, 2048);
         if ($error != "" || strlen($buffer) == 0) {
             break;
         }
         $output .= $buffer;
     }
     $this->Close();
     if ($to_file) {
         file_put_contents($to_file, $output);
     } else {
         return $output;
     }
 }
Esempio n. 29
0
 /**
  * on editor action
  * 
  * Called in editor to module
  * 
  * @return array(
  *   'layout'                = false
  *   'template'              = false
  * )
  */
 function on_editor()
 {
     core::lib('editor')->assign_module_menu($this->get_editor_actions());
     // Controller action
     $controller_action = '';
     // modify ident var 'c' (if empty)
     if (empty(core::get_params()->c) && !empty($this->editor_default_action)) {
         core::get_params()->c = $this->editor_default_action;
     }
     $controller_action = preg_replace('/[^a-z\\d\\_]/i', '', core::get_params()->c);
     core::dprint("on_editor controller: " . $controller_action);
     if (empty($controller_action)) {
         throw new editor_exception('Empty action');
     }
     // check user has access
     core::lib('editor')->on_editor($this);
     // dispatch
     if (!empty($controller_action)) {
         $controller_action_file = $this->root_dir . "editor/controllers/{$controller_action}" . loader::DOT_PHP;
         if (fs::file_exists($controller_action_file, false)) {
             require $controller_action_file;
             // run controller object, if present
             $controller_class = $this->get_name() . '_' . $controller_action . '_controller';
             if (class_exists($controller_class, 0)) {
                 core::dprint("run controller object : {$controller_class}");
                 /** @var editor_controller $controller */
                 $controller = new $controller_class($this);
                 $controller->run();
                 $layout = $controller->get_layout();
                 $template = $controller->get_template();
                 $this->renderer->set_page_template($layout)->set_main_template($template);
             } else {
                 throw new core_exception('Bad controller class name ' . $controller_class);
             }
         } else {
             core::dprint('[ERROR] Unable to execute ' . $controller_action_file);
         }
     }
     /*  @return main template
      */
     /*
     return array(
         'layout'    => $layout,
         'template'  => $template
     );
     */
 }
Esempio n. 30
0
 /**
  * @param array 
  *    array(
  *    'from', 
  *    'subject', 
  *    'to', 
  *    'msg', 
  *    'is_html'
  *   )
  * 
  * @return bool result
  */
 function email($m)
 {
     /* init with exceptions */
     $mailer = new tf_php_mailer(true);
     $mailer->configure($this->config);
     $mailer->SMTPAuth = false;
     $mailer->From = $m['from'];
     // отправитель
     $mailer->Subject = $m['subject'];
     //$emailer->AltBody = 'Чтобы увидеть текст, включите отображение html в настройках почтового клиента.';
     $mailer->CharSet = $this->_charset;
     $mailer->FromName = empty($m['from_name']) ? '' : $m['from_name'];
     $mailer->ClearAddresses();
     $mailer->AddAddress($m['to']);
     $mailer->Body = $m['msg'];
     $mailer->isHTML(isset($m['is_html']));
     if (!empty($m['bcc'])) {
         if (is_string($m['bcc'])) {
             $m['bcc'] = explode(',', $m['bcc']);
         }
         foreach ($m['bcc'] as $bcc) {
             $bcc = trim($bcc);
             if (!empty($bcc)) {
                 $mailer->AddBCC($bcc);
             }
         }
     }
     if (!empty($m['cc'])) {
         if (is_string($m['cc'])) {
             $m['cc'] = explode(',', $m['cc']);
         }
         foreach ($m['cc'] as $cc) {
             $cc = trim($cc);
             if (!empty($cc)) {
                 $mailer->AddCC($cc);
             }
         }
     }
     $ret_message = '';
     try {
         $ret = $mailer->send();
     } catch (phpmailerException $e) {
         $ret = false;
         $ret_message = $e->getMessage();
     }
     $ret_message = ($ret ? 'OK ' : 'FAIL ') . $ret_message;
     // trace
     core::dprint("emailer {$m['from']} --> {$m['to']} " . $ret_message, core::E_TRACE);
     return $ret;
 }