Exemplo n.º 1
0
 function __construct($base = null)
 {
     if (!$base) {
         $base = loader::get_root() . '../cache/';
     }
     $this->set_root($base);
 }
Exemplo n.º 2
0
 /**
  * @param array
  *   server = path to file
  */
 function connect()
 {
     if (!class_exists('SQLite3', 0)) {
         throw new dbal_exception('Sqlite support not compiled with PHP!');
     }
     if (empty($this->dbname)) {
         throw new dbal_exception('Sqlite connect empty database!');
     }
     // check is relative path (to site root)
     // $dbname = (substr($this->dbname, 0, 1) == '/')
     //    ? substr($this->dbname, 1)
     //    : ('../' . $this->dbname);
     $this->_db_file = loader::get_root($this->dbname);
     if (!file_exists($this->_db_file)) {
         throw new dbal_exception('No database: ' . $this->_db_file);
     }
     core::dprint(array('CONNECT %s %s', __CLASS__, $this->_db_file), core::E_SQL);
     $error = '';
     $this->_connect_id = new SQLite3($this->_db_file, SQLITE3_OPEN_READWRITE);
     if ($this->_connect_id) {
         $this->_connect_id->exec('PRAGMA short_column_names = 1');
         $this->_connect_id->exec('PRAGMA encoding = "UTF-8"');
     } else {
         throw new dbal_exception('Cant connect to database ' . $this->_db_file);
     }
     return $this->_connect_id;
 }
Exemplo n.º 3
0
 /**
  * To disable chroot
  * [lib_sape_cacher]
  * root = cache
  * 
  * @param mixed $config
  */
 function configure($config)
 {
     if (isset($config['root'])) {
         $this->set_root(loader::get_root($config['root'] . '/'));
     }
     if (isset($config['subdir_length'])) {
         $this->subdir_length = $config['subdir_length'];
     }
 }
Exemplo n.º 4
0
 /**
  * Create
  */
 function __construct()
 {
     $memcache_domain = 'i' . substr(md5(loader::get_root()), 27);
     try {
         $this->engines['mem'] = new MultiCacheMemcache();
         $this->engines['mem']->set_domain($memcache_domain);
     } catch (exception $e) {
         // no memcache
         $this->engines['mem'] = false;
     }
     $this->engines['file'] = new MultiCacheFile();
     $this->engines['file']->cacheDir = loader::get_root() . '../cache/system';
 }
Exemplo n.º 5
0
 /**
  * Register module
  * @throws modules_exception
  * @return object|bool module
  */
 public function register($module)
 {
     core::dprint('[mod_register] ' . $module);
     $module_class = loader::CLASS_PREFIX . $module;
     $module_path = loader::get_root() . loader::DIR_MODULES . $module . '/';
     $module_file = $module_path . 'module' . loader::DOT_PHP;
     if (!fs::file_exists($module_file)) {
         throw new modules_exception('Failed to register module ' . $module . '. File does not exists');
     }
     require_once $module_file;
     $this->set($module, new $module_class($module_path));
     return $this->get($module);
 }
Exemplo n.º 6
0
 function __construct($config)
 {
     $this->_config = $config;
     $this->persistency = @$config['persistency'];
     $this->user = $config['login'];
     $this->password = $config['password'];
     $this->server = isset($config['server']) ? $config['server'] : 'localhost';
     $this->dbname = $config['database'];
     $this->prefix = $config['prefix'];
     $this->root = loader::get_root();
     if (is_callable(array($this, 'configure'))) {
         $this->configure($config);
     }
 }
Exemplo n.º 7
0
 /**
  * Set root
  */
 static function set_template($template)
 {
     if (defined('IN_EDITOR')) {
         self::$template_dir = loader::get_root() . loader::DIR_EDITOR . loader::DIR_TEMPLATES;
     } else {
         self::$template_dir = loader::get_root() . loader::DIR_TEMPLATES . $template;
     }
     self::$parser->template_dir = self::$template_dir;
     /*
      * If using template, compile directory must exists /cache/tpl/{template}
      */
     $c_postfix = defined('IN_EDITOR') ? 'editor/' : $template . '/';
     self::$parser->compile_dir = loader::get_root() . loader::DIR_TEMPLATES_C . $c_postfix;
     self::$parser->cache_dir = loader::get_root() . loader::DIR_TEMPLATES_C . $c_postfix;
 }
Exemplo n.º 8
0
 /**
  * Create a database handle
  * Factory method
  * @param array params
  *  engine - pdo
  *      type - mysql
  *
  * @return \Doctrine\DBAL\Connection
  */
 public static function get_doctrine($id = self::DEFAULT_CONNECTION, array $config = array())
 {
     if (empty($config) && !isset(self::$dbs[$id])) {
         throw new dbal_exception('Try to get unloaded db connection : ' . $id);
     }
     $engine = @$config['engine'] ?: 'pdo_mysql';
     if (isset(self::$dbs[$id])) {
         return self::$dbs[$id];
     }
     core::dprint('[dbloader|doctrine::get] ' . $id . '(' . $engine . ')');
     if ($engine == 'null') {
         if (!class_exists('null_db', 0)) {
             require "modules/core/dbal/null.php";
         }
         $conn = new null_db();
         self::$dbs[$id] = $conn;
     } else {
         $d_config = new \Doctrine\DBAL\Configuration();
         $d_config->setSQLLogger(new \SatCMS\Modules\Core\Dbal\Doctrine\Logger());
         /*
         *    'dbname'    => @$config['database']
            , 'user'      => @$config['login'] ?: 'root'
            , 'password'  => @$config['password']
            , 'host'      => @$config['server'] ?: 'localhost'
            , 'driver'    => $engine
            , 'path'      => (isset($config['path']) ? loader::get_root($config['path']) : null)
         */
         $connection_params = array('driver' => $engine, 'prefix' => @$config['prefix'], 'charset' => 'UTF8');
         unset($config['engine']);
         // fix path
         if (isset($config['path'])) {
             $config['path'] = loader::get_root($config['path']);
         }
         // merge params
         $connection_params = array_merge($connection_params, $config);
         core::dprint_r($connection_params);
         try {
             $conn = \Doctrine\DBAL\DriverManager::getConnection($connection_params, $d_config);
             self::$dbs[$id] = $conn;
         } catch (Exception $e) {
             core::dprint($e->getMessage());
             return false;
         }
     }
     return self::$dbs[$id];
 }
Exemplo n.º 9
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;
     }
 }
Exemplo n.º 10
0
 /**
  * To disable chroot
  * [lib_cache]
  * file_root = cache/system 
  * 
  * @param mixed $c
  */
 function configure($c)
 {
     if (isset($c['file_root'])) {
         $this->cacheDir = loader::get_root($c['file_root']);
     }
 }
Exemplo n.º 11
0
*/
// header("X-LIGHTTPD-send-file: " . $_GET['id']);
// header("X-Sendfile: " . $_GET['id']);
// header("X-Sendfile: /home/thumb/lexiclips.com/public_html/uploads/videos/original/48.mp4");
require "../modules/core/loader.php";
core::set_debug(666);
ini_set('display_errors', 'on');
error_reporting(E_ALL);
$core = core::get_instance();
if (($user = core::lib('auth')->get_user()) && !$user->payd_user) {
    die('Restricted');
} else {
    // Send file
    $id = functions::request_var('id', '');
    $file = loader::get_root() . substr($id, 1);
    if (strpos($id, '/uploads/videos') !== false && ($file = loader::get_root() . substr($id, 1)) && file_exists($file) && is_readable($file)) {
        $mime_type = 'video/mp4';
        // 'video/H264';
        if (false !== strpos($id, 'videos/original')) {
            $mime_type = "application/force-download";
        }
        //header('Content-disposition: attachment;filename="' . (basename($file)) . '";');
        header('Content-type: ' . $mime_type);
        header('Content-length: ' . filesize($file));
        header("X-LIGHTTPD-send-file: " . $file);
        die;
        // readfile($file);
    } else {
        header(' ', true, 403);
        echo "Restticted";
    }
Exemplo n.º 12
0
 /**
  * Create uploads
  */
 function create_upload_dir()
 {
     if ($dir = $this->get_uploads_path()) {
         $dir = loader::get_root() . $dir;
         return mkdir($dir, 0770);
     }
     return false;
 }
Exemplo n.º 13
0
<?php

/**
 * Sape interface
 * 
 * @package    TwoFace
 * @author     Golovkin Vladimir <*****@*****.**> http://www.skillz.ru
 * @copyright  SurSoft (C) 2008
 * @version    $Id: sape.php,v 1.2 2009/08/05 08:45:21 surg30n Exp $
 */
$_su = core::get_instance()->get_cfg_var('sape_user');
if (!empty($_su)) {
    if (!defined('_SAPE_USER')) {
        define(_SAPE_USER, $_su);
    }
    require_once loader::get_root() . $_su . '/sape.php';
}
if (!class_exists('SAPE_client')) {
    class SAPE_client
    {
        function SAPE_client($p = array())
        {
            // mock
            core::dprint('[LIB_SAPE] Using mock', core::E_ERROR);
        }
    }
}
class sape extends SAPE_client
{
    function __construct()
    {
Exemplo n.º 14
0
 /**
  * Set root
  */
 static function set_template($template)
 {
     if (core::in_editor()) {
         self::$template_dir = loader::get_public() . loader::DIR_EDITOR . loader::DIR_TEMPLATES;
     } else {
         self::$template_dir = loader::get_public() . loader::DIR_TEMPLATES . $template;
     }
     self::$parser->template_dir = self::$template_dir;
     /*
      * If using template, compile directory must exists /cache/tpl/{template}
      */
     $c_postfix = core::in_editor() ? 'editor/' : $template . '/';
     self::$parser->compile_dir = loader::get_root(loader::DIR_TEMPLATES_C . $c_postfix);
     self::$parser->cache_dir = loader::get_root(loader::DIR_TEMPLATES_C . $c_postfix);
     if (!file_exists(self::$parser->compile_dir)) {
         mkdir(self::$parser->compile_dir, 0777, true);
         // chmod this right
     }
     /*
     if (!file_exists(self::$parser->cache_dir)) {            
         mkdir(self::$parser->cache_dir, 0777, true); // chmod this right
     }
     */
 }
Exemplo n.º 15
0
 /** 
  * Parse module langwords into one
  * huge array. Used in templates later.
  * Module lang start with m_
  * [lang.var]
  */
 public function import_langwords($module)
 {
     $lang = $this->get_cfg_var('lang');
     $lang_file = loader::get_root() . loader::DIR_MODULES . $module . '/' . loader::DIR_LANGS . $lang;
     if (fs::file_exists($lang_file)) {
         $temp = parse_ini_file($lang_file, true);
         self::dprint('[LANG_INCLUDE] ' . $lang_file . " (x" . count($temp) . ")");
         if ('core' == $module) {
             $this->langwords = array_merge_recursive($this->langwords, $temp);
         } else {
             $this->langwords['m_'][$module] = $temp;
         }
     }
 }
Exemplo n.º 16
0
 /**
  * Check file presents
  * @param string file name
  * @param mixed FALSE(default) - filename must be full path, otherwise ROOT_PATH added
  */
 public static function file_exists($name, $prefix = false)
 {
     return file_exists(($prefix === false ? '' : loader::get_root()) . $name);
 }
Exemplo n.º 17
0
 /**
  * format on modify
  */
 private function format_field_on_modify($vf, &$fld, $current)
 {
     $type = $vf['type'];
     /**
      * @todo must validate and normilize all input (utf8)
      */
     switch ($type) {
         case 'boolean':
             //---------------
             $fld = intval($fld);
             // 1 OR 0
             break;
         case 'text':
             //---------------
             // normalize utf!
             // remove trailing <br> (jquery wys)
             if (preg_match('/<br>$/', $fld)) {
                 $fld = preg_replace('/<br>$/', '', $fld);
             }
             // validate here
             if (!empty($vf['format'])) {
                 $fld = core::lib('validator')->parse_str($fld, $vf['format']);
             } else {
                 // default is strip tags
                 // use empty format for deny this rule
                 // var_dump($fld, strip_tags($fld, false));
                 if (!isset($vf['format'])) {
                     $fld = core::lib('validator')->parse_str($fld, 'strip_tags');
                 }
             }
             break;
         case 'position':
             //---------------
             $fld = (int) $fld;
             break;
         case 'numeric':
             //---------------
             $fld = floatval($fld);
             break;
             /**
              * Время unix приходит в строковом формате,
              * изменяем его в числовой вид
              * If time already number, pass it throw.
              */
         /**
          * Время unix приходит в строковом формате,
          * изменяем его в числовой вид
          * If time already number, pass it throw.
          */
         case 'unixtime':
             //---------------
             // raw, wihtout format
             if (isset($vf['no_check'])) {
                 break;
             }
             // default date modificator
             if ($fld == 'now') {
                 $fld = time();
             }
             if (intval($fld) > 9999) {
                 $fld = intval($fld);
             } else {
                 $fld = strtotime($fld);
             }
             break;
         case 'file':
         case 'image':
             //---------------
             // $control = $this->create_control('image');
             // $control->modify($vf, $fld);
             $pinfo = array();
             if (!empty($fld['name'])) {
                 $pinfo = isset($fld['name']) ? pathinfo($fld['name']) : false;
                 $pinfo['extension'] = strtolower($pinfo['extension']);
             }
             if (!empty($fld['size']) && (empty($vf['allow']) || !empty($vf['allow']) && in_array($pinfo['extension'], $vf['allow']))) {
                 $path = loader::get_root() . 'uploads/' . $vf['storage'];
                 // reuse name, if it here already
                 if (!empty($current['file'])) {
                     // unlink?
                     $this->format_field_on_remove($vf, $fld, $current);
                 }
                 // $naming = isset($vf['unique']) ? (md5(microtime(true)) . '.' . $pinfo['extension']) : false;
                 $naming = md5(microtime(true)) . '.' . $pinfo['extension'];
                 if (!empty($vf['spacing'])) {
                     $path .= '/' . substr($naming, 0, $vf['spacing']);
                     if (!is_dir($path)) {
                         mkdir($path);
                     }
                 }
                 $file = core::lib('uploader')->upload_file($fld, $path, $naming, array('force_override' => true));
                 // fix bad \\
                 $fld['file'] = str_replace(array('\\\\', '\\'), '/', $file);
                 // override type with extension
                 $fld['type'] = $pinfo['extension'];
                 // make max_width
                 if (!empty($vf['max_width'])) {
                     core::lib('images')->resample_image($fld['file'], $fld['file'], $vf['max_width']);
                 }
                 // make thumbnail
                 if (!empty($vf['thumbnail'])) {
                     $t_width = $vf['thumbnail'];
                     $t_height = false;
                     if (is_array($t_width)) {
                         $t_height = $t_width[1];
                         $t_width = $t_width[0];
                     }
                     // resample_image($src, $dst, $new_width, $new_height = false)
                     core::lib('images')->resample_image($fld['file'], preg_replace('@\\.([^\\.]+)$@', '.thumb.$1', $fld['file']), $t_width, $t_height);
                 }
                 // make max_width
                 if (!empty($vf['width']) && !empty($vf['height'])) {
                     core::lib('images')->resample_image($fld['file'], $fld['file'], $vf['width'], $vf['height']);
                 }
                 unset($fld['error']);
                 unset($fld['tmp_name']);
             } else {
                 $fld = $current;
             }
             // core::var_dump($fld);
             break;
             /*
             on success
             
                 'name' => string 'icq_avatar_sm.jpg.gif' (length=21)
                 'type' => string 'image/gif' (length=9)
                 'tmp_name' => string '/tmp/phpBINfkc' (length=14)
                 'error' => int 0
                 'size' => int 2745  
             
             on error
             
                 'name' => string '' (length=0)
                 'type' => string '' (length=0)
                 'tmp_name' => string '' (length=0)
                 'error' => int 4
                 'size' => int 0
             */
         /*
         on success
         
             'name' => string 'icq_avatar_sm.jpg.gif' (length=21)
             'type' => string 'image/gif' (length=9)
             'tmp_name' => string '/tmp/phpBINfkc' (length=14)
             'error' => int 0
             'size' => int 2745  
         
         on error
         
             'name' => string '' (length=0)
             'type' => string '' (length=0)
             'tmp_name' => string '' (length=0)
             'error' => int 4
             'size' => int 0
         */
         default:
             break;
     }
 }
Exemplo n.º 18
0
<?php

//not implemented
return;
set_time_limit(0);
define('DISABLE_TR', 1);
require "../_loader.php";
$core = core::get_instance();
$file = loader::get_root() . 'modules/content/tests/news_import/img/1.jpg';
$collection = $core->class_register('test_images');
$data = array();
$data['title'] = uniqid();
$data['active'] = 1;
$filename = $file;
printf("exists %d <br/><br/>", file_exists($filename));
$data['image'] = array('name' => basename($filename), 'tmp_name' => $filename, 'size' => 1);
$id = $collection->create($data);
$item = $collection->get_last_item();
$item = $collection->load_only_id($item->id);
echo "1)<br/><br/>";
var_dump($item->image, $item->render());
echo "<br/><br/>2)<br/><br/>";
$item = $collection->load_only_id($item->id);
var_dump($item->image, $item->render());
Exemplo n.º 19
0
 function __construct($config)
 {
     $this->_config = $config;
     $this->_debug_file = loader::get_root() . $this->_debug_file;
     $this->persistency = @$config['persistency'];
     $this->user = $config['login'];
     $this->password = $config['password'];
     $this->server = isset($config['server']) ? $config['server'] : 'localhost';
     $this->dbname = $config['database'];
     $this->prefix = $config['prefix'];
     $this->root = loader::get_root();
     $this->cache_enabled = core::get_instance()->get_cfg_var('enable_sql_cache') ? true : false;
     $this->cache_path = $this->root . $this->cache_path;
 }
Exemplo n.º 20
0
 function _init_apc()
 {
     if (!isset($this->engines['apc'])) {
         $apc_domain = 'i' . substr(md5(loader::get_root()), 27);
         try {
             $this->engines['apc'] = new MultiCacheApc();
             $this->engines['apc']->set_domain($apc_domain);
             $this->engines['apc']->set_conn_string(@$this->_config['apc']);
             $this->engines['apc']->getApc();
         } catch (exception $e) {
             // no apccache
             core::dprint('apc not available: ' . $e->getMessage(), core::E_ERROR);
             $this->engines['apc'] = false;
         }
     }
     return $this->engines['apc'];
 }