Ejemplo n.º 1
0
 /**
  * Get a instance.
  *
  * @return \Jobqueue\Queue
  */
 public static function instance()
 {
     if (is_null(static::$instance)) {
         static::$instance = new static(Context::instance());
     }
     return static::$instance;
 }
Ejemplo n.º 2
0
 /**
  *  Get the singleton instance
  *
  * @return unknown
  */
 public static function getInstance()
 {
     if (!is_object(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Ejemplo n.º 3
0
 public static function get_instance()
 {
     if (empty(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Ejemplo n.º 4
0
 /**
  * Class constructor.
  *
  * @param Page $page Current page object.
  */
 public function __construct($page)
 {
     $this->page = $page;
     $this->blocks = array();
     $this->context = Context::instance('\\Innomedia\\Context');
     // Check if a local template file exists.
     $tpl = $this->context->getGridsHome() . $this->page->getTheme() . '.local.tpl.php';
     if (!file_exists($tpl)) {
         // Check if a predefined template file exists.
         $tpl = $this->context->getGridsHome() . $this->page->getTheme() . '.tpl.php';
         if (!file_exists($tpl)) {
             // Check if a local default template file exists.
             $tpl = $this->context->getGridsHome() . 'default.local.tpl.php';
             if (!file_exists($tpl)) {
                 // Check if a default template file exists.
                 $tpl = $this->context->getGridsHome() . 'default.tpl.php';
                 if (!file_exists($tpl)) {
                     // No template file found, send error.
                     $this->context->getResponse()->sendError(WebAppResponse::SC_INTERNAL_SERVER_ERROR, 'No theme grid found');
                 }
             }
         }
     }
     // Call the template constructor with the found template file.
     parent::__construct($tpl);
     // Set the blocks list in the template blocks variable.
     $this->setArray('blocks', $this->blocks);
 }
Ejemplo n.º 5
0
 public function before()
 {
     parent::before();
     $this->_ctx = Context::instance();
     $this->_ctx->request($this->request)->response($this->response);
     View_Front::bind_global('ctx', $this->_ctx);
 }
 /**
  * Get the singleton instance of the Context
  * @return Context
  */
 public static function getInstance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Ejemplo n.º 7
0
 /**
  * Generate a Response for the 401 Exception.
  * 
  * The user should be redirect to a login page.
  * 
  * @return Response
  */
 public function get_response()
 {
     Flash::set('protected_page', Context::instance()->get_page());
     if (($page = Model_Page_Front::findByField('behavior_id', 'protected_page')) !== FALSE) {
         return Request::factory($page->url)->execute();
     }
     throw new HTTP_Exception_401($this->message);
 }
Ejemplo n.º 8
0
 /**
  * @param Model_Widget_Hybrid
  * @param array $field
  * @param array $row
  * @param string $fid
  * @return mixed
  */
 public static function fetch_widget_field($widget, $field, $row, $fid, $recurse)
 {
     $related_widget = NULL;
     Context::instance()->set($field->inject_key, explode(',', $row[$fid]));
     if ($recurse > 0 and isset($widget->doc_fetched_widgets[$fid])) {
         if (!empty($row[$fid])) {
             $related_widget = self::_fetch_related_widget($widget, $row, $fid, $recurse, $field->inject_key, TRUE);
         }
     }
     return !empty($related_widget) ? $related_widget : $row[$fid];
 }
Ejemplo n.º 9
0
 public function action_forgot()
 {
     if ($this->request->method() == Request::POST) {
         $this->auto_render = FALSE;
         $widget = Widget_Manager::factory('User_Forgot');
         Context::instance()->set('email', Arr::path($this->request->post(), 'forgot.email'));
         $widget->set_values(array('next_url' => Route::get('user')->uri(array('action' => 'login'))))->on_page_load();
     }
     $this->set_title(__('Forgot password'));
     $this->template->content = View::factory('system/forgot');
 }
Ejemplo n.º 10
0
 /**
  * Получение виджетов блока без вывода.
  * 
  * Для вывода данных блока
  * 
  *		$widget = Block::get('block_name', $params);
  *		if(is_array($widget))
  *		{
  *			foreach($widget as $data)
  *			{
  *				echo $data;
  *			}
  *		}
  *		else
  *			echo $widget;
  * 
  * @param string $name
  * @param array $params Дополнительные параметры доступные в виджете
  * @return array
  */
 public static function get($name, array $params = array())
 {
     $ctx = Context::instance();
     $widgets = $ctx->get_widgets_by_block($name);
     foreach ($widgets as $widget) {
         if ($widget instanceof View) {
             $widget->bind('ctx', $ctx)->set('params', $params);
         } else {
             if ($widget instanceof Model_Widget_Decorator) {
                 $widget->set_params($params);
             }
         }
     }
     return $widgets;
 }
Ejemplo n.º 11
0
 /**
  * 
  * @param array $row
  * @param integr $fid
  * @param integer $recurse
  * @return array
  */
 protected static function _fetch_related_widget($widget, $row, $fid, $recurse, $key = 'ids', $fetch = FALSE)
 {
     $widget_id = Arr::get($widget->doc_fetched_widgets, $fid);
     if (empty($widget_id)) {
         return NULL;
     }
     $widget = Context::instance()->get_widget($widget_id);
     if (!$widget) {
         $widget = Widget_Manager::load($widget_id);
     }
     if ($widget === NULL) {
         return array();
     }
     $widget->{$key} = $row[$fid];
     if ($fetch === FALSE) {
         return $widget->get_document($row[$fid], $recurse - 1);
     } else {
         return $widget->fetch_data();
     }
 }
Ejemplo n.º 12
0
 public function doGet(\Innomatic\Webapp\WebAppRequest $req, \Innomatic\Webapp\WebAppResponse $res)
 {
     // Start Innomatic
     $innomatic = \Innomatic\Core\InnomaticContainer::instance('\\Innomatic\\Core\\InnomaticContainer');
     $innomatic->setInterface(\Innomatic\Core\InnomaticContainer::INTERFACE_EXTERNAL);
     $root = \Innomatic\Core\RootContainer::instance('\\Innomatic\\Core\\RootContainer');
     $innomatic_home = $root->getHome() . 'innomatic/';
     $innomatic->bootstrap($innomatic_home, $innomatic_home . 'core/conf/innomatic.ini');
     // Start Innomatic domain
     \Innomatic\Core\InnomaticContainer::instance('\\Innomatic\\Core\\InnomaticContainer')->startDomain(\Innomatic\Webapp\WebAppContainer::instance('\\Innomatic\\Webapp\\WebAppContainer')->getCurrentWebApp()->getName());
     // Innomedia page
     $scope_page = 'frontend';
     // Check if the page exists in the page tree
     $pageSearch = PageTree::findPageByPath(substr($req->getPathInfo(), 1));
     if ($pageSearch === false) {
         // This is a static page (excluding the home page).
         $location = explode('/', $req->getPathInfo());
         $module_name = isset($location[1]) ? $location[1] : '';
         $page_name = isset($location[2]) ? $location[2] : '';
         $pageId = isset($location[3]) ? $location[3] : 0;
     } else {
         // This is the home page or a content page.
         $module_name = $pageSearch['module'];
         $page_name = $pageSearch['page'];
         $pageId = $pageSearch['page_id'];
     }
     // Define Innomatic context
     $home = \Innomatic\Webapp\WebAppContainer::instance('\\Innomatic\\Webapp\\WebAppContainer')->getCurrentWebApp()->getHome();
     $context = Context::instance('\\Innomedia\\Context');
     $context->setRequest($req)->setResponse($res)->process();
     // Build Innomedia page
     $page = new Page($module_name, $page_name, $pageId, $scope_page);
     $page->parsePage();
     // Check if the page is valid
     if (!$page->isValid()) {
         $res->sendError(\Innomatic\Webapp\WebAppResponse::SC_NOT_FOUND, $req->getRequestURI());
     } else {
         $page->build();
     }
 }
Ejemplo n.º 13
0
<?php

defined('SYSPATH') or die('No direct script access.');
// При сохранении страницы обновление тегов
Observer::observe(array('page_add_after_save', 'page_edit_after_save'), function ($page) {
    $tags = Request::current()->post('page_tags');
    if ($tags !== NULL) {
        Model_Page_Tag::save_by_page($page->id, $tags);
    }
});
// Загрузка шаблона с тегами в блок с метатегами в редактор страницы
Observer::observe('view_page_edit_meta', function ($page) {
    echo View::factory('page/tags', array('tags' => Model_Page_Tag::find_by_page($page->id)));
});
Observer::observe('layout_backend_head_before', function () {
    echo '<script type="text/javascript">var TAG_SEPARATOR = "' . Model_Tag::SEPARATOR . '";</script>';
});
// При выводе списка стран запускается метод custom_filter и передача в него
// Database_query_builder, в этом обсервере можно дополнять этот запрос
Observer::observe('frontpage_custom_filter', function ($sql, $page) {
    $tags = Context::instance()->get('tag');
    if (empty($tags)) {
        return;
    }
    $sql->join(array(Model_Page_Tag::TABLE_NAME, 'pts'), 'inner')->distinct(TRUE)->on('pts.page_id', '=', 'page.id')->join(array(Model_Tag::TABLE_NAME, 'ts'))->on('pts.tag_id', '=', 'ts.id')->where('ts.name', 'in', explode(',', $tags));
});
Ejemplo n.º 14
0
 /**
  * Get a singleton context
  *
  * @return Context
  */
 public static function getContext()
 {
     if (!isset(self::$instance)) {
         self::$instance = new Context();
     }
     return self::$instance;
 }
Ejemplo n.º 15
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
Observer::observe('template_before_render', function ($request) {
    if (in_array($request->controller(), array('Page', 'Widgets'))) {
        Assets::js('controller.widgets', ADMIN_RESOURCES . 'js/controller/widgets.js', 'global');
    }
});
Observer::observe('frontpage_found', function ($page) {
    $widgets = Widget_Manager::get_widgets_by_page($page->id);
    Context::instance()->register_widgets($widgets)->init_widgets();
    /**
     * Запуск метода в виджетах текущей страницы 
     * Model_Widget_Decorator::on_page_load
     */
    Observer::notify('on_page_load');
    /**
     * Блок служит для помещения в него виджета с произволным PHP кодом,
     * который выполняется до загрузки HTML, вывод данных в этом блоке делать
     * не надо
     */
    Block::run('PRE');
});
Observer::observe('frontpage_after_render', function () {
    /**
     * Запуск метода в виджетах текущей страницы 
     * Model_Widget_Decorator::after_page_load
     */
    Observer::notify('after_page_load');
    /**
     * Блок служит для помещения в него виджета с произволным PHP кодом,
Ejemplo n.º 16
0
            @class_alias("{$name}_Core", "{$name}");
        }
    } else {
        if (file_exists(SYSTEM_ROOT . '/helper/' . $raw_file)) {
            require_once SYSTEM_ROOT . '/helper/' . $raw_file;
            @class_alias("{$name}_Helper", "{$name}");
        } else {
            if (file_exists(SYSTEM_ROOT . '/library/' . $raw_file)) {
                require_once SYSTEM_ROOT . '/library/' . $raw_file;
                if (!$force_core) {
                    @class_alias("{$name}_Core", "{$name}");
                }
            } else {
                throw new Exception("Class Not Found: {$name}");
            }
        }
    }
}
// __autoload()
// Tricky bugger. If we have documents stored in session, and this is pre-autoloader we can't find any classes.
session_start();
if (false === strpos($_SERVER['REQUEST_URI'], Config::get('xoket.location'))) {
    die('Configuration Error - xoket.location is invalid.');
}
$uri = substr($_SERVER['REQUEST_URI'], strlen(Config::get('xoket.location')));
$uri = URI::route($uri);
Request::load($uri);
$context = Context::instance();
$context->headers();
echo $context->execute();
Flash::update();
Ejemplo n.º 17
0
 /**
  * Метод вызывается в момент загрузки объекта из БД
  * 
  * @return array
  */
 public function __wakeup()
 {
     $this->_ctx = Context::instance();
     $this->_set_type();
 }
Ejemplo n.º 18
0
 /**
  * Returns a list of pages not requiring a valid id.
  *
  * @return array
  */
 public static function getNoInstancePagesList()
 {
     $context = Context::instance('\\Innomedia\\Context');
     $list = array();
     if ($dm = opendir($context->getModulesHome())) {
         while (($module = readdir($dm)) !== false) {
             if ($module != '.' and $module != '..' and file_exists($context->getModulesHome() . $module . '/pages/') and $dh = opendir($context->getModulesHome() . $module . '/pages/')) {
                 while (($file = readdir($dh)) !== false) {
                     if ($file != '.' and $file != '..' and is_file($context->getModulesHome() . $module . '/pages/' . $file) and strrpos($file, '.yml') and !strrpos($file, '.local.yml')) {
                         $pageName = substr($file, 0, strrpos($file, '.yml'));
                         if (file_exists($context->getModulesHome() . $module . '/pages/' . $pageName . '.local.yml')) {
                             $yamlFile = $context->getModulesHome() . $module . '/pages/' . $pageName . '.local.yml';
                         } else {
                             $yamlFile = $context->getModulesHome() . $module . '/pages/' . $pageName . '.yml';
                         }
                         $pageDef = yaml_parse_file($yamlFile);
                         if (!isset($pageDef['properties']['requiresid']) or $pageDef['properties']['requiresid'] == false) {
                             $list[] = $module . '/' . $pageName;
                         }
                     }
                 }
                 closedir($dh);
             }
         }
         closedir($dm);
     }
     return $list;
 }
Ejemplo n.º 19
0
 public function before()
 {
     Context::instance()->request($this->request);
     parent::before();
 }
Ejemplo n.º 20
0
 /**
  * 
  * @param string $uri
  */
 protected final function _match_route($uri)
 {
     $default_method = 'execute';
     foreach ($this->routes() as $_uri => $params) {
         if (!isset($params['method'])) {
             $params['method'] = $default_method;
         }
         // The URI should be considered literal except for keys and optional parts
         // Escape everything preg_quote would escape except for : ( ) < >
         $expression = preg_replace('#' . self::REGEX_ESCAPE . '#', '\\\\$0', $_uri);
         // Insert default regex for keys
         $expression = str_replace(array('<', '>'), array('(?P<', '>' . self::REGEX_SEGMENT . ')'), $expression);
         if (isset($params['regex'])) {
             $search = $replace = array();
             foreach ($params['regex'] as $key => $value) {
                 $search[] = "<{$key}>" . Route::REGEX_SEGMENT;
                 $replace[] = "<{$key}>{$value}";
             }
             // Replace the default regex with the user-specified regex
             $expression = str_replace($search, $replace, $expression);
         }
         if (!preg_match('#^' . $expression . '$#uD', $uri, $matches)) {
             continue;
         }
         foreach ($matches as $key => $value) {
             if (is_int($key)) {
                 // Skip all unnamed keys
                 continue;
             }
             // Set the value for all matched keys
             $this->_params[$key] = $value;
             Context::instance()->set('.' . $key, $value);
         }
         $this->_matched_route = $_uri;
         return $params['method'];
     }
     $this->_params = preg_split('/\\//', $uri, -1, PREG_SPLIT_NO_EMPTY);
     return $default_method;
 }
Ejemplo n.º 21
0
 /**
  * 
  * @param string $key
  * @return string
  */
 public function parse_meta($key, $value = NULL)
 {
     if ($value === NULL) {
         $value = strtr($this->{$key}, array('\'' => '\\\'', '\\' => '\\\\'));
     }
     $fields = array();
     $found = preg_match_all('/(?<!\\{)\\{(' . '((\\$|\\:)[A-Za-z0-9_\\-\\.\\/]+(\\|[\\w\\ ]*)?)' . '|[\\.]+' . ')\\}(?!\\})/u', $value, $fields);
     if ($found) {
         $fields = array_unique($fields[1]);
         $parts = array();
         foreach ($fields as $i => $field) {
             $patterns[] = '/(?<!\\{)\\{' . preg_quote($field, '/') . '\\}(?!\\})/u';
             switch ($field) {
                 case '.':
                     // Current page
                     if ($key == 'meta_title') {
                         $parts[] = $this->title();
                     }
                     break;
                 case '..':
                     // Parent page
                     if ($this->parent() instanceof Model_Page_Front) {
                         $parts[] = $this->parent()->{$key}();
                     }
                     break;
                 default:
                     // Level
                     if (Valid::numeric($field) and $this->level() != $field and $this->parent($field) instanceof Model_Page_Front) {
                         $parts[] = $this->parent($field)->{$key}();
                     }
                     break;
             }
             $param = NULL;
             $meta_param = NULL;
             $default = NULL;
             if (strpos($field, '|') !== FALSE) {
                 list($field, $default) = explode('|', $field, 2);
             }
             switch ($field[0]) {
                 case '$':
                     $param = substr($field, 1);
                     break;
                 case ':':
                     $meta_param = substr($field, 1);
                     break;
             }
             if ($param !== NULL) {
                 if (strpos($param, 'site.') !== FALSE) {
                     $parts[] = Config::get('site', substr($param, 5), $default);
                 } else {
                     if (strpos($param, 'ctx.') !== FALSE) {
                         $parts[] = Context::instance()->get(substr($param, 4));
                     } else {
                         if (strpos($param, 'parent.') !== FALSE and $this->parent() instanceof Model_Page_Front and method_exists($this->parent(), substr($param, 7))) {
                             $parts[] = $this->parent()->{substr($param, 7)}();
                         } else {
                             if (method_exists($this, $param)) {
                                 $parts[] = $this->{$param}();
                             }
                         }
                     }
                 }
             }
             if ($meta_param !== NULL) {
                 $parts[] = Arr::get($this->_meta_params, $meta_param, $default);
             }
         }
         $value = preg_replace($patterns, $parts, $value);
     }
     return $value;
 }
Ejemplo n.º 22
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
Observer::observe('frontpage_requested', function ($request_uri) {
    $server_uri = $_SERVER['REQUEST_URI'];
    $server_uri = trim(parse_url($server_uri, PHP_URL_PATH), '/');
    $ctx = Context::instance()->set('url_segments', preg_split('/\\//', $request_uri, -1, PREG_SPLIT_NO_EMPTY));
    if (!empty($server_uri) and strlen(URL_SUFFIX) > 0 and Config::get('site', 'check_url_suffix') == Config::YES) {
        $request_uri = $request_uri . URL_SUFFIX;
        if ($server_uri !== $request_uri) {
            $ctx->throw_404();
        }
    }
});
Observer::observe('frontpage_found', function ($page) {
    if ($page->is_password_protected()) {
        throw new HTTP_Exception_Front_401('Page protected');
    }
});
// Update page last-modified date
Observer::observe('widget_set_location', function ($page_ids) {
    ORM::factory('page')->set_update_date($page_ids);
});
Ejemplo n.º 23
0
 /**
  * Формирование Database_Query_Builder в части филтрации документов
  * 
  * @param array $filters
  * @param array $t
  * @param Database_Query_Builder $query
  * @return Database_Query_Builder
  */
 protected function _fetch_filters(array $filters, &$t, &$query)
 {
     if (empty($filters)) {
         return $query;
     }
     $field_names = array_flip($this->get_field_names());
     $ds_fields = $this->get_fields();
     $sys_fields = $this->get_system_fields();
     foreach ($filters as $pos => $data) {
         $params = array();
         $field = $data['field'];
         if (!empty($data['params'])) {
             parse_str($data['params'], $params);
         }
         $condition = $data['condition'];
         $type = $data['type'];
         $invert = !empty($data['invert']);
         $value = Arr::get($data, 'value');
         if ($value !== NULL and $type != self::VALUE_PLAIN) {
             $ctx = Context::instance();
             $request = Request::initial();
             switch ($type) {
                 case self::VALUE_BEHAVIOR:
                     if ($ctx->behavior_router() instanceof Behavior_Route) {
                         $value = $ctx->behavior_router()->param($value);
                         break;
                     }
                 case self::VALUE_GET:
                     $value = $request->query($value);
                     break;
                 case self::VALUE_POST:
                     $value = $request->post($value);
                     break;
                 default:
                     $value = $ctx->get($value);
                     break;
             }
         }
         if ($value === NULL) {
             continue;
         }
         $field_id = strpos($field, '$') == 1 ? Context::instance()->get(substr($field, 1)) : $field;
         if (isset($sys_fields[$field_id])) {
             $field = $sys_fields[$field_id];
         } else {
             if (isset($ds_fields[$field_id])) {
                 $field = $ds_fields[$field_id];
             } else {
                 if (isset($field_names[$field_id])) {
                     $field = $ds_fields[$field_names[$field_id]];
                 } else {
                     $field = NULL;
                 }
             }
         }
         if (!$field instanceof DataSource_Hybrid_Field) {
             continue;
         }
         if (!isset($t[$field->ds_id])) {
             $query->join('dshybrid_' . $field->ds_id, 'dfilter' . $pos)->on('dfilter' . $pos . '.id', '=', 'ds.id');
             $t[$field->ds_id] = TRUE;
         }
         $in = FALSE;
         switch ($condition) {
             case self::COND_EQ:
                 $value = explode(',', $value);
                 if ($value[0] == '*') {
                     break;
                 } elseif (count($value) > 1) {
                     $in = TRUE;
                 } else {
                     $value = $value[0];
                 }
                 break;
             case self::COND_CONTAINS:
                 $value = explode(',', $value);
                 $in = TRUE;
                 break;
             case self::COND_BTW:
                 $value = explode(',', $value, 2);
                 if (count($value) != 2) {
                     break;
                 }
                 break;
             default:
                 $value = $value;
         }
         $in = $in === TRUE ? 'IN' : '=';
         if (is_array($value)) {
             foreach ($value as $i => $v) {
                 if ($this->is_db_function($value)) {
                     $value[$i] = DB::expr($v);
                 }
             }
         } else {
             if ($this->is_db_function($value)) {
                 $value = DB::expr($value);
             }
         }
         if (isset($params['db_function']) and !$this->is_db_function($params['db_function'])) {
             unset($params['db_function']);
         }
         $conditions = array($in, 'BETWEEN', '>', '<', '>=', '<=', 'IN', 'LIKE');
         $condition = Arr::get($conditions, $condition, '=');
         if ($invert === TRUE) {
             switch ($condition) {
                 case '>':
                     $condition = '<=';
                     break;
                 case '<':
                     $condition = '>=';
                     break;
                 case '=':
                     $condition = '!=';
                     break;
                 case 'IN':
                 case 'LIKE':
                 case 'BETWEEN':
                     $condition = 'NOT ' . $condition;
                     break;
                 case '>=':
                     $condition = '<';
                     break;
                 case '<=':
                     $condition = '>';
                     break;
             }
         }
         $type = NULL;
         $fid = NULL;
         foreach ($ds_fields as $id => $f) {
             if ($f->key == $field->key) {
                 $type = $f->type;
                 $fid = $id;
             }
         }
         $field->filter_condition($query, $condition, $value, $params);
     }
     unset($field_names, $ds_fields, $sys_fields, $filters);
     return $query;
 }
Ejemplo n.º 24
0
 protected function _get_field_value($field)
 {
     $key = $field['id'];
     $value = NULL;
     $src = $field['source'] % 10;
     switch ($src) {
         case self::CTX:
             $value = Context::instance()->get($key);
             break;
         case self::GET:
             $value = Request::current()->query($key);
             break;
         case self::POST:
             $value = Request::current()->post($key);
             break;
         case self::COOKIE:
             $value = Cookie::get($key);
             break;
         case self::SESSION:
             $value = Session::instance()->get($key);
     }
     switch ($field['type']) {
         case self::HTML:
             $value = Kses::filter($value, $this->allowed_tags);
             break;
         case self::TXT:
             $value = HTML::chars($value);
     }
     return $value;
 }
Ejemplo n.º 25
0
 /**
  * Returns module full path in tenant webapp folder.
  *
  * @access public
  * @return void
  */
 public function getHome()
 {
     return Context::instance('\\Innomedia\\Context')->getModulesHome() . $this->name . '/';
 }