/**
  * Constructing crypt object
  *
  * @param string $db_link
  * @param string $class
  */
 public function __construct($crypt_link = null, $class = null, $options = [])
 {
     // if we need to use default link from application
     if ($crypt_link == null) {
         $crypt_link = application::get(['flag', 'global', 'crypt', 'default_crypt_link']);
         if (empty($crypt_link)) {
             throw new Exception('You must specify crypt link!');
         }
     }
     // get object from factory
     $temp = factory::get(['crypt', $crypt_link]);
     // if we have class
     if (!empty($class) && !empty($crypt_link)) {
         // replaces in case we have it as submodule
         $class = str_replace('.', '_', trim($class));
         // creating new class
         unset($this->object);
         $this->object = new $class($crypt_link, $options);
         factory::set(['crypt', $crypt_link], ['object' => $this->object, 'class' => $class]);
     } else {
         if (!empty($temp['object'])) {
             $this->object = $temp['object'];
         } else {
             throw new Exception('You must specify crypt link and/or class!');
         }
     }
 }
Exemple #2
0
 public function init()
 {
     if ($this->_inited) {
         return;
     }
     $this->_inited = true;
     $config = application::get_instance()->config->user;
     $config->model = array();
     $config->model->user = isset($config->model->user) ? $config->model->user : $this->default_model_user;
     $this->model_user = '******' . $config->model->user;
     if (class_exists($this->model_user)) {
         $this->model_user = new $this->model_user();
         $this->_key = 'user_' . $this->model_user->name;
     }
     $this->model_usersoc = 'model_' . (isset($config->model->usersoc) ? $config->model->usersoc : $this->default_model_usersoc);
     $this->model_usersoc = class_exists($this->model_usersoc) ? new $this->model_usersoc() : null;
     if ($config->acl) {
         $this->model_role = 'model_' . (isset($config->model->role) ? $config->model->role : $this->default_model_role);
         $this->model_role = class_exists($this->model_role) ? new $this->model_role() : null;
         $this->model_rule = 'model_' . (isset($config->model->rule) ? $config->model->rule : $this->default_model_rule);
         $this->model_rule = class_exists($this->model_rule) ? new $this->model_rule() : null;
         $this->model_resource = 'model_' . (isset($config->model->resource) ? $config->model->resource : $this->default_model_resource);
         $this->model_resource = class_exists($this->model_resource) ? new $this->model_resource() : null;
         $this->model_role2role = 'model_' . (isset($config->model->role2role) ? $config->model->role2role : $this->default_model_role2role);
         $this->model_role2role = class_exists($this->model_role2role) ? new $this->model_role2role() : null;
         $this->model_rule2role = 'model_' . (isset($config->model->rule2role) ? $config->model->rule2role : $this->default_model_rule2role);
         $this->model_rule2role = class_exists($this->model_rule2role) ? new $this->model_rule2role() : null;
         $this->model_rule2resource = 'model_' . (isset($config->model->rule2resource) ? $config->model->rule2resource : $this->default_model_rule2resource);
         $this->model_rule2resource = class_exists($this->model_rule2resource) ? new $this->model_rule2resource() : null;
         $this->init_acl();
     }
     $this->salt = $config->salt;
     $this->login_auto();
 }
Exemple #3
0
 function __get($k)
 {
     if ($k == 'view') {
         return $this->view;
     }
     // Смысл класса сущности - в создании виртуальных переменных класса, не связанных с данными сущности. Виртуальная переменная транслируется в метод get_имя_паременной класса сущности, который должен вернуть ее значение
     $method = 'get_' . $k;
     $k_replaced = preg_replace('/\\_(valid|control|lang)$/i', '', $k);
     if (method_exists($this, $method)) {
         $ret = $this->{$method}();
     } else {
         $ret = $this->get($k);
         if ($ret === null && $k != $k_replaced) {
             $ret = $this->get($k_replaced);
         }
     }
     if ($k != $k_replaced) {
         $reg = application::get_instance()->controller->view->lang(true);
         if ($reg && array_key_exists('ml_' . $k_replaced . '_' . $reg->id, $this->_data)) {
             $ret_lang = $this->get('ml_' . $k_replaced . '_' . $reg->id);
             if (strlen($ret_lang) == 0) {
                 if (array_key_exists('ml_' . $k_replaced . '_' . application::get_instance()->controller->view->lang()->default->id, $this->_data)) {
                     $ret_lang = $this->get('ml_' . $k_replaced . '_' . application::get_instance()->controller->view->lang()->default->id);
                     if (strlen($ret_lang) > 0) {
                         $ret = $ret_lang;
                     }
                 }
             } else {
                 $ret = $ret_lang;
             }
         }
     }
     return $ret;
 }
Exemple #4
0
 /**
  * URL组装,兼容各种路由模式
  *
  * @param	string $url	如:admin://system/msg/send/username/args2 或者 system/msg/send/username/args2
  * @param	array $params 参数
  * @param	string $fragment 锚点名称或者框架名称
  * @return	string 完整的url
  */
 public static function build($uri, $params = array(), $fragment = '')
 {
     $uri = trim($uri, '/');
     //去掉开头结尾的 / 符号,或者去掉分隔符
     if (strpos($uri, '://') === false) {
         $uri = router::application() . '://' . $uri;
     }
     $uris = parse_url($uri);
     $paths = explode('/', trim($uris['path'], '/'));
     $urls = array();
     $urls['base'] = $uris['scheme'] == router::application() ? url::base() : application::settings($urls['scheme'], 'base');
     $urls['module'] = $uris['host'];
     $urls['controller'] = $paths[0];
     $urls['action'] = $paths[1];
     //zotop::dump($urls);
     if (zotop::config('zotop.url.model') == 0) {
     } else {
         $url = $urls['base'];
         if (zotop::config('zotop.url.model') == 2) {
             $url = $url . '?zotop=';
             //开启兼容模式
         }
         $url = $url . '/' . $urls['module'] . '/' . $urls['controller'] . '/' . $urls['action'];
         if (!empty($params)) {
             foreach ($params as $key => $value) {
                 $url .= '/' . $value;
             }
         }
     }
     if (!empty($fragment)) {
         $url .= '#' . $fragment;
     }
     return url::clean($url);
 }
 public function action_index()
 {
     // clear buffer
     helper_ob::clean_all();
     // validating
     do {
         $options = application::get('flag.numbers.backend.cron.base');
         // token
         if (!empty($options['token']) && request::input('token') != $options['token']) {
             break;
         }
         // ip
         if (!empty($options['ip']) && !in_array(request::ip(), $options['ip'])) {
             break;
         }
         // get date parts
         $date_parts = format::now('parts');
         print_r($date_parts);
         echo "GOOD\n";
     } while (0);
     // we need to validate token
     //$token = request::input('token');
     echo "OK\n";
     // exit
     exit;
 }
Exemple #6
0
 /**
  * Connect
  *
  * @param array $options
  * @return array
  */
 public function connect($options)
 {
     $result = ['success' => false, 'error' => []];
     $this->options = $options;
     // for deployed code the directory is different because we relate it based on code
     if (!empty($this->options['dir']) && application::is_deployed()) {
         $temp = $this->options['dir'][0] . $this->options['dir'][1];
         if ($temp == './') {
             $this->options['dir'] = './.' . $this->options['dir'];
         } else {
             $this->options['dir'] = '../';
         }
     }
     // check if we have valid directory
     if (empty($this->options['dir'])) {
         $result['error'][] = 'Storage directory does not exists or not provided!';
     } else {
         // fixing path
         $this->options['dir'] = rtrim($this->options['dir'], '/') . '/';
         // we need to create directory
         if (!empty($this->cache_key)) {
             $this->options['dir'] .= $this->cache_key . '/';
         }
         // we need to create cache directory
         if (!is_dir($this->options['dir'])) {
             if (!helper_file::mkdir($this->options['dir'], 0777)) {
                 $result['error'][] = 'Unable to create caching directory!';
                 return $result;
             }
         }
         $result['success'] = true;
     }
     return $result;
 }
 /**
  * Constructing cache object
  *
  * @param string $cache_link
  * @param string $class
  */
 public function __construct($cache_link = null, $class = null)
 {
     // if we need to use default link from application
     if (empty($cache_link)) {
         $cache_link = application::get(['flag', 'global', 'cache', 'default_cache_link']);
         if (empty($cache_link)) {
             throw new Exception('You must specify cache link and/or class!');
         }
     }
     // get object from factory
     $temp = factory::get(['cache', $cache_link]);
     // if we have class
     if (!empty($class) && !empty($cache_link)) {
         // replaces in case we have it as submodule
         $class = str_replace('.', '_', trim($class));
         // if we are replacing database connection with the same link we
         // need to manually close connection
         if (!empty($temp['object']) && $temp['class'] != $class) {
             $object = $temp['object'];
             $object->close();
             unset($this->object);
         }
         $this->object = new $class($cache_link);
         // putting every thing into factory
         factory::set(['cache', $cache_link], ['object' => $this->object, 'class' => $class]);
     } else {
         if (!empty($temp['object'])) {
             $this->object = $temp['object'];
         } else {
             throw new Exception('You must specify cache link and/or class!');
         }
     }
 }
Exemple #8
0
 function get_url_valid()
 {
     if ($this->url) {
         return $this->url;
     }
     $route = $this->route ? $this->route : 'default';
     $p = array('controller' => $this->controller, 'action' => $this->action);
     if ($this->param) {
         if (is_string($this->param)) {
             $param = explode(',', $this->param);
             $map = is_string($this->map) ? explode(',', $this->map) : array();
             if ($map) {
                 foreach ($map as $n => $el) {
                     $el = trim($el);
                     if ($el) {
                         $p[$el] = trim(@$param[$n]);
                     }
                 }
             }
         } else {
             $pp = clone $this->param;
             if ($pp instanceof data) {
                 $pp = $pp->to_array();
             }
             $p = array_merge($p, $pp);
         }
     }
     $view = application::get_instance()->controller->view;
     $href = $view->url($p, $route);
     return $href;
 }
 /**
  * Initializing i18n
  *
  * @param array $options
  */
 public static function init($options = [])
 {
     $i18n = application::get('flag.global.i18n') ?? [];
     $i18n = array_merge_hard($i18n, $options ?? []);
     // determine final language
     $languages = factory::model('numbers_backend_i18n_languages_model_languages')->get();
     $final_language = application::get('flag.global.__language_code') ?? session::get('numbers.entity.format.language_code') ?? $i18n['language_code'] ?? 'sys';
     if (empty($languages[$final_language])) {
         $final_language = 'sys';
         $i18n['rtl'] = 0;
     }
     // put settings into system
     if (!empty($languages[$final_language])) {
         foreach ($languages[$final_language] as $k => $v) {
             $k = str_replace('lc_language_', '', $k);
             if (in_array($k, ['code', 'inactive'])) {
                 continue;
             }
             if (empty($v)) {
                 continue;
             }
             $i18n[$k] = $v;
         }
     }
     $i18n['language_code'] = $final_language;
     self::$options = $i18n;
     session::set('numbers.entity.format.language_code', $final_language);
     application::set('flag.global.i18n', $i18n);
     self::$initialized = true;
     // initialize the module
     return factory::submodule('flag.global.i18n.submodule')->init($i18n);
 }
Exemple #10
0
 public function init()
 {
     if ($this->data) {
         return;
     }
     $lang = application::get_instance()->config->translate->lang;
     if (file_exists(PATH_ROOT . '/' . DIR_LIBRARY . '/translate/' . $lang . '.php')) {
         $data = (include PATH_ROOT . '/' . DIR_LIBRARY . '/translate/' . $lang . '.php');
         if ($data) {
             $this->data = array_merge($this->data, $data);
         }
     }
     if (file_exists(PATH_ROOT . '/' . DIR_APPLICATION . '/translate/' . $lang . '.php')) {
         $data = (include PATH_ROOT . '/' . DIR_APPLICATION . '/translate/' . $lang . '.php');
         if ($data) {
             $this->data = array_merge($this->data, $data);
         }
     }
     if (class_exists('model_translate')) {
         $m = new model_translate();
         $data_db = $m->fetch_all();
         if ($data_db) {
             $data_array = array();
             foreach ($data_db as $el) {
                 $data_array[$el->key] = $el->value_lang;
             }
             $this->data = array_merge($this->data, $data_array);
         }
     }
 }
Exemple #11
0
 /**
  * Release the lock
  * 
  * @param string $id
  * @return boolean
  */
 public static function release($id)
 {
     $temp_dir = application::get(array('directory', 'temp'));
     if (isset($temp_dir['dir'])) {
         return unlink($temp_dir['dir'] . '__lock_' . $id);
     }
     return true;
 }
 /**
  * Add library to the application
  * 
  * @param string $library
  */
 public static function add($library)
 {
     $connected = application::get('flag.global.library.' . $library . '.connected');
     if (!$connected) {
         factory::submodule('flag.global.library.' . $library . '.submodule')->add();
         application::set('flag.global.library.' . $library . '.connected', true);
     }
 }
Exemple #13
0
 public static function call($message = 'Application Error', $code = 500)
 {
     $_SERVER['REQUEST_URI'] = '/error';
     header('HTTP/1.1 ' . $code . ' ' . $message);
     application::$instance = new application();
     application::get_instance()->bootstrap()->run();
     exit;
 }
Exemple #14
0
 public function getTemplatePath($action = '')
 {
     if (empty($this->template)) {
         $path = application::template($action);
         return $path;
     }
     return $this->template;
 }
Exemple #15
0
 public function template($path = '')
 {
     $path = trim($path, '/');
     if (empty($path)) {
         $path = application::module() . '/' . application::controller() . '/' . application::action() . '.php';
     }
     $template = ZOTOP_PATH_THEMES . DS . application::theme() . DS . 'template' . DS . str_replace('/', DS, $path);
     return $template;
 }
Exemple #16
0
 public function url($data = null, $route = 'default')
 {
     if ($data === null) {
         return $this;
     }
     $router = application::get_instance()->router;
     $request = application::get_instance()->request;
     return isset($router->route[$route]) ? $router->route[$route]->assemble($data, $request, $this->default) : '';
 }
 /**
  * Serve js and/or css files, mostly used in development
  *
  * @param string $filename
  */
 public static function serve_media_if_exists($filename, $application_path)
 {
     // we need to remove question mark and all after it
     if (strpos($filename, '?') !== false) {
         $temp = explode('?', $filename);
         $filename = $temp[0];
     }
     // generated files first
     if (strpos($filename, '/numbers/media_generated/') === 0) {
         $filename = str_replace('/numbers/media_generated/application_', '', $filename);
         $filename = $application_path . str_replace('_', '/', $filename);
     } else {
         if (strpos($filename, '/numbers/media_submodules/') === 0) {
             $temp = str_replace('/numbers/media_submodules/', '', $filename);
             $temp = str_replace('_', '/', $temp);
             $filename = './../libraries/vendor/' . $temp;
         } else {
             // we must return, do not exit !!!
             return;
         }
     }
     // check if file exists on file system
     if (!file_exists($filename)) {
         return;
     }
     // we need to know extension of a file
     $ext = pathinfo($filename, PATHINFO_EXTENSION);
     if ($ext == 'css' || $ext == 'js') {
         $new = $filename;
         $flag_scss = false;
         if (strpos($filename, '.scss.css') !== false) {
             $new = str_replace('.scss.css', '.scss', $new);
             $flag_scss = true;
         }
         if (file_exists($new)) {
             if ($ext == 'js') {
                 header('Content-Type: application/javascript');
                 echo file_get_contents($new);
             }
             if ($ext == 'css') {
                 header('Content-type: text/css');
                 if (!$flag_scss) {
                     echo file_get_contents($new);
                 } else {
                     if (application::get('dep.submodule.numbers.frontend.media.scss')) {
                         $temp = numbers_frontend_media_scss_base::serve($new);
                         if ($temp['success']) {
                             echo $temp['data'];
                         }
                     }
                 }
             }
             exit;
         }
     }
 }
 public function action_index()
 {
     $id = application::get(['mvc', 'controller_id']);
     if ($id) {
         $result = url_tinyurl::get($id);
         if ($result['success']) {
             request::redirect($result['data']['url']);
         }
     }
 }
 /**
  * Indicator whether widgets are enabled
  *
  * @param string $widget
  * @return boolean
  */
 public static function enabled($widget)
 {
     if (!application::get('numbers.data', ['backend_exists' => true])) {
         return false;
     }
     if (!application::get("flag.global.widgets.{$widget}.submodule")) {
         return false;
     }
     return true;
 }
Exemple #20
0
 public static function id()
 {
     $id = self::settings('id');
     if (strlen($id) == 32) {
         return $id;
     }
     $namespace = application::getApplication() . '://' . application::getModule() . '.' . application::getController() . '.' . application::getAction();
     $namespace = empty($id) ? $namespace : $namespace . '/' . $id;
     $namespace = md5($namespace);
     return $namespace;
 }
 /**
  * Model
  *
  * @param string $class
  */
 public static function model($class)
 {
     $temp = explode('__virtual__', $class);
     $last = array_pop($temp);
     // fetch submodule
     $submodule = application::get("flag.global.widgets.{$last}.submodule");
     $class = str_replace('.base__123', '', $submodule . '__123');
     $class = str_replace('.', '_', $class) . '_model_virtual_' . $last;
     // create an object
     $object = new $class(implode('__virtual__', $temp));
     return $object;
 }
Exemple #22
0
 public function set($lang)
 {
     if (application::get_instance()->config->resource->lang->type != 'session') {
         return false;
     }
     if ($lang) {
         session::set('lang', $lang);
     } else {
         session::remove('lang');
     }
     setcookie($this->_key, $lang, time() + 86400 * 30, '/');
 }
Exemple #23
0
 public function __construct($name, $param = array())
 {
     $this->name = $name;
     if (isset($param['id'])) {
         $this->id = $param['id'];
     }
     if (isset($param['class'])) {
         $this->class = $param['class'];
     }
     if (isset($param['view_script'])) {
         $this->view_script = $param['view_script'];
     }
     if (isset($param['frame_view_script'])) {
         $this->frame_view_script = $param['frame_view_script'];
     }
     if (isset($param['class_error'])) {
         $this->class_error = $param['class_error'];
     }
     if (isset($param['class_frame'])) {
         $this->class_frame = $param['class_frame'];
     }
     if (isset($param['class_control'])) {
         $this->class_control = $param['class_control'];
     }
     if (isset($param['class_label'])) {
         $this->class_label = $param['class_label'];
     }
     if (isset($param['label'])) {
         $this->label = $param['label'];
     }
     if (isset($param['attr'])) {
         $this->attr = $param['attr'];
     }
     if (isset($param['validator'])) {
         $this->validator = $param['validator'];
     }
     if (isset($param['description'])) {
         $this->description = $param['description'];
     }
     if (isset($param['required'])) {
         $this->required = $param['required'];
     }
     if (isset($param['value'])) {
         $this->value = $param['value'];
     }
     if (isset($param['attribute'])) {
         $this->attribute = new data($param['attribute']);
     }
     if (isset($param['item'])) {
         $this->item = new data($param['item']);
     }
     $this->view = application::get_instance()->controller->view;
 }
Exemple #24
0
 public function template($name = '')
 {
     if (file::exists($name)) {
         return $name;
     }
     $template = theme::template($name);
     if (file::exists($template)) {
         return $template;
     }
     $template = application::template($name);
     return $template;
 }
Exemple #25
0
 public function send()
 {
     if ($this->body) {
         $res = implode('', $this->body);
         $config = application::get_instance()->config->html;
         if ($config->compress && ob_start("ob_gzhandler")) {
             ini_set('zlib.output_compression_level', 6);
         } else {
             ob_start();
         }
         echo $res;
     }
 }
Exemple #26
0
 public function forward($action, $controller = null, $param = null)
 {
     $app = $this->layout = application::get_instance();
     $app->request->controller = $controller;
     if (!$app->request->controller) {
         $app->request->controller = str_replace('controller_', '', get_class($app->controller));
     }
     $app->request->action = $action;
     if ($param) {
         $app->request->param = new data($param);
     }
     $app->run_controller();
     exit;
 }
Exemple #27
0
 public function getTemplatePath($action = '')
 {
     if (empty($this->template)) {
         if (empty($action)) {
             $action = application::getAction();
         }
         $module = application::getModule();
         $controller = application::getController();
         $path = zotop::module($module, 'path');
         $path = $path . DS . router::application() . DS . 'template' . DS . $controller . DS . $action . '.php';
         return $path;
     }
     return $this->template;
 }
Exemple #28
0
 function url($url = '')
 {
     $url = $url ? $url : application::get_instance()->request->url;
     if (application::get_instance()->config->resource->lang) {
         $m = new model_lang();
         $langs = $m->fetch_col('stitle', array('show_it' => 1));
         $url = preg_replace('/^\\/(' . implode('|', $langs) . ')\\//si', '/', $url);
     }
     $m = new model_meta();
     $data = $m->fetch_by_url($url);
     if ($data) {
         $this->auto($data, false);
     }
 }
 /**
  * Delegate arguments to submodule
  *
  * @param string $flag
  * @param string $submodule
  * @param array $arguments
  * @return mixed
  */
 public static function delegate($flag, $submodule, $arguments)
 {
     $options = application::get($flag . '.' . $submodule . '.options');
     if (!empty($options)) {
         // todo: maybe add to first array instead to first element in arguments
         $arguments[0] = array_merge_hard($options, $arguments[0]);
     }
     // we need to determine whether we need to use additional submodule
     if (application::get($flag . '.' . $submodule . '.submodule') && empty($arguments[0]['flag_call_previous_parent'])) {
         return call_user_func_array([self::submodule($flag . '.' . $submodule . '.submodule'), $submodule], $arguments);
     } else {
         return call_user_func_array([self::submodule($flag . '.submodule'), $submodule], $arguments);
     }
 }
Exemple #30
0
 /**
  * Write content to file and sets permissions
  * 
  * @param string $filename
  * @param mixed $data
  * @param int $permission
  * @param int $flags
  * @param boolean $relative
  */
 public static function write($filename, $data, $permission = 0777, $flags = LOCK_EX, $relative = true)
 {
     // if we have relative path we convert it to full path
     if ($relative && $filename[0] == '.') {
         $path = application::get('application.path_full');
         $info = pathinfo($filename);
         $filename = realpath($path . $info['dirname']) . '/' . $info['basename'];
     }
     // write file
     if (file_put_contents($filename, $data, $flags) !== false) {
         @chmod($filename, $permission);
         return true;
     }
     return false;
 }