Пример #1
0
 public function __construct($context, $box_id, $loop = null)
 {
     if (fx::isAdmin()) {
         self::addAdminAssets();
         $this->avail = $this->getAvailFields($context);
     }
     $this->box_id = $box_id;
     $param_id = $this->getParamId();
     $data = $context->get($param_id);
     if (is_string($data) && !empty($data)) {
         $data = json_decode($data, true);
     }
     //fx::log($this, $data);
     if (!$data || !isset($data['is_stored'])) {
         $groups = $context->get('groups');
         $default_data = $this->prepareGroups($groups);
         $data = $data ? \Floxim\Floxim\System\Util::fullMerge($data, $default_data) : $default_data;
     }
     $this->data = $data;
     //fx::log('set data', $this->data);
     if ($loop) {
         $this->containing_loop = $loop;
         $box = $this;
         $loop->onStop(function () use($box) {
             $box->export();
         });
     }
 }
Пример #2
0
 public static function addAdminAssets()
 {
     if (fx::isAdmin()) {
         $path = fx::path('@module/Floxim/Ui/Grid');
         fx::page()->addJsFile($path . '/grid-builder.js');
         fx::page()->addCssBundle(array($path . '/grid-builder.less'));
     }
 }
Пример #3
0
 public function route($url = null, $context = null)
 {
     if (!fx::isAdmin()) {
         return null;
     }
     if (!preg_match("~^/\\~ib/(\\d+|fake(?:\\-\\d+)?)@(\\d+)~", $url, $ib_info)) {
         return null;
     }
     $c_url = fx::input()->fetchGetPost('_ajax_base_url');
     if ($c_url) {
         $_SERVER['REQUEST_URI'] = $c_url;
         $path = fx::router()->getPath(fx::path()->removeBase($c_url));
         if ($path) {
             fx::env('page', $path->last());
         } else {
             fx::env('page', fx::router('error')->getErrorPage());
         }
         $c_url = parse_url($c_url);
         if (isset($c_url['query'])) {
             parse_str($c_url['query'], $_GET);
         }
     }
     $ib_id = $ib_info[1];
     $page_id = $ib_info[2];
     if (!fx::env('page') && $page_id) {
         $page = fx::data('floxim.main.content', $page_id);
         fx::env('page', $page);
     }
     fx::env('ajax', true);
     $page_infoblocks = fx::router('front')->getPageInfoblocks($page_id, fx::env('layout'));
     fx::page()->setInfoblocks($page_infoblocks);
     // import layout template to recreate real env
     fx::router('front')->importLayoutTemplate();
     // front end can try to reload the layout which is out of date
     // when updating from "layout settings" panel
     $infoblock = fx::data('infoblock', $ib_id);
     if (!$infoblock && isset($_POST['infoblock_is_layout']) || $infoblock->isLayout()) {
         //$infoblock = $layout_infoblock;
         $infoblock = fx::router('front')->getLayoutInfoblock(fx::env('page'));
     }
     fx::http()->status('200');
     $infoblock_overs = null;
     if (fx::isAdmin() && isset($_POST['override_infoblock'])) {
         $infoblock_overs = fx::input('post', 'override_infoblock');
         if (is_string($infoblock_overs)) {
             parse_str($infoblock_overs, $infoblock_overs);
             $infoblock_overs = fx::input()->prepareSuperglobal($infoblock_overs);
         }
         $infoblock->override($infoblock_overs);
     }
     $infoblock->overrideParam('ajax_mode', true);
     $res = $infoblock->render();
     return $res;
 }
Пример #4
0
 protected function showAdminPanel()
 {
     if (!fx::isAdmin()) {
         return;
     }
     // initialize the admin panel
     $p = fx::page();
     $js_config = new Admin\Configjs();
     $p->addJsText("\$fx.init(" . $js_config->getConfig() . ");");
     $p->setAfterBody(Admin\Controller\Adminpanel::panelHtml());
 }
Пример #5
0
 public function getFinder()
 {
     $finder = parent::getFinder();
     if (!fx::isAdmin()) {
         if ($own_comments = $this->getOwnComments()) {
             $finder->whereOr(array('is_moderated', 1), array('id', $own_comments));
         } else {
             $finder->where('is_moderated', 1);
         }
     }
     return $finder;
 }
Пример #6
0
 public function doAuthForm()
 {
     $user = fx::user();
     if (!$user->isGuest()) {
         if (!fx::isAdmin()) {
             return false;
         }
         //$this->_meta['hidden'] = true;
     }
     $form = $user->getAuthForm();
     if ($this->getParam('ajax')) {
         $this->ajaxForm($form);
     }
     $this->trigger('form_ready', array('form' => $form));
     if ($form->isSent() && !$form->hasErrors()) {
         $vals = $form->getValues();
         if (!$user->login($vals['email'], $vals['password'], $vals['remember'])) {
             $form->addError(fx::lang('User not found or password is wrong'), 'password');
         } else {
             $location = $_SERVER['REQUEST_URI'];
             if ($location === '/floxim/') {
                 $location = '/';
             }
             switch ($this->getParam('redirect_location_type')) {
                 case 'refresh':
                 default:
                     $target_location = $location;
                     break;
                 case 'home':
                     $target_location = '/';
                     break;
                 case 'custom':
                     $target_location = $this->getParam('redirect_location_custom');
                     if (empty($target_location)) {
                         $target_location = '/';
                     }
                     break;
             }
             // send admin to cross-auth page
             if ($user->isAdmin()) {
                 fx::input()->setCookie('fx_target_location', $target_location);
                 fx::http()->redirect('@home/~ajax/floxim.user.user:cross_site_auth_form');
             }
             fx::http()->redirect($target_location);
         }
     }
     return array('form' => $form);
 }
Пример #7
0
 public function doShow()
 {
     $area_name = 'blockset_' . $this->input['infoblock_id'];
     $blocks = fx::page()->getAreaInfoblocks($area_name);
     if ($this->getParam('is_fake')) {
         foreach (range(1, 3) as $n) {
             $blocks[] = $this->getFakeIb();
         }
     } else {
         if ($this->getParam('add_new_infoblock')) {
             $blocks[] = $this->getFakeIb();
         }
     }
     $res = parent::doShow();
     $res += array('items' => $blocks, 'area' => $area_name);
     if (count($blocks) == 0 && !fx::isAdmin()) {
         $this->_meta['disabled'] = true;
     }
     return $res;
 }
Пример #8
0
 public function process()
 {
     $res = parent::process();
     $is_new = $this->isNewBlock();
     $this->assign('is_overriden', $this->getParam('is_overriden'));
     if (isset($res['areas'])) {
         foreach ($res['areas'] as $i => &$area) {
             if (!isset($area['id'])) {
                 $area['id'] = 'grid_' . (isset($area['keyword']) ? $area['keyword'] : $i) . '_' . $this->getParam('infoblock_id');
             }
             $area['blocks'] = !$is_new ? fx::page()->getAreaInfoblocks($area['id']) : array();
             if (!$area['name']) {
                 $area['name'] = fx::alang('Column %s', null, $i + 1);
             }
             if (fx::isAdmin()) {
                 if ($is_new || $this->getParam('is_overriden') && count($area['blocks']) === 0) {
                     $area['placeholder'] = fx::alang('%s is empty, you can add blocks here', null, $area['name']);
                 }
             }
         }
     }
     return $res;
 }
Пример #9
0
 /**
  * @return string
  */
 public function adminOffice()
 {
     self::addAdminFiles();
     if (fx::isAdmin()) {
         $panel = Adminpanel::panelHtml();
         $res = fx::template('@admin:back_office')->render(array('panel' => $panel));
         $js_config = new FxAdmin\Configjs();
         fx::page()->addJsText("\$fx.init(" . $js_config->getConfig() . ");");
     } else {
         $auth_form = fx::controller('user:auth_form')->render('user:auth_form');
         $recover_form = fx::controller('user:recover_form', array('email' => isset($_POST['email']) ? $_POST['email'] : null))->render('user:recover_form');
         $res = fx::template('@admin:authorize')->render(array('auth_form' => $auth_form, 'recover_form' => $recover_form));
     }
     return fx::page()->postProcess($res);
 }
Пример #10
0
 protected function addInfoblockMeta($html_result)
 {
     $controller_meta = $this->getResultMeta();
     if (!fx::isAdmin() && (!isset($controller_meta['ajax_access']) || !$controller_meta['ajax_access'])) {
         return $html_result;
     }
     $ib_info = array('id' => $this['id']);
     if (($vis = $this->getVisual()) && $vis['id']) {
         $ib_info['visual_id'] = $vis['id'];
     }
     $ib_info['controller'] = $this->getPropInherited('controller') . ':' . $this->getPropInherited('action');
     $ib_info['name'] = $this['name'];
     $meta = array('data-fx_infoblock' => $ib_info, 'class' => 'fx_infoblock fx_infoblock_' . $this['id']);
     foreach ($this->infoblock_meta as $meta_key => $meta_val) {
         // register only non-empty props
         if ($meta_val && !is_array($meta_val) || count($meta_val) > 0) {
             $meta['data-fx_' . $meta_key] = $meta_val;
         }
     }
     if (isset($_POST['_ajax_base_url'])) {
         $meta['data-fx_ajax_base_url'] = $_POST['_ajax_base_url'];
     }
     if ($this->isFake()) {
         $meta['class'] .= ' fx_infoblock_fake';
         if (!$this->getIbController()) {
             $controller_meta['hidden_placeholder'] = fx::alang('Fake infoblock data', 'system');
         }
     }
     if (isset($controller_meta['hidden']) && $controller_meta['hidden']) {
         $meta['class'] .= ' fx_infoblock_hidden';
     }
     if (count($controller_meta) > 0 && fx::isAdmin()) {
         $meta['data-fx_controller_meta'] = $controller_meta;
     }
     if ($this->isLayout()) {
         $meta['class'] .= ' fx_unselectable';
         $html_result = preg_replace_callback('~<body[^>]*?>~is', function ($matches) use($meta) {
             $body_tag = Template\HtmlToken::createStandalone($matches[0]);
             $body_tag->addMeta($meta);
             return $body_tag->serialize();
         }, $html_result);
     } elseif ($this->output_is_subroot && preg_match("~^(\\s*?)(<[^>]+?>)~", $html_result)) {
         $html_result = preg_replace_callback("~^(\\s*?)(<[^>]+?>)~", function ($matches) use($meta) {
             $tag = Template\HtmlToken::createStandalone($matches[2]);
             $tag->addMeta($meta);
             return $matches[1] . $tag->serialize();
         }, $html_result);
     } else {
         $html_proc = new Template\Html($html_result);
         $html_result = $html_proc->addMeta($meta, mb_strlen($html_result) > 10000);
     }
     return $html_result;
 }
Пример #11
0
 public function render($data = array())
 {
     if (isset($data['_idle'])) {
         $this->context->isIdle(true);
         unset($data['_idle']);
     }
     if (count($data) > 0) {
         $this->context->push($data);
     }
     ob_start();
     if (!is_null($this->forced_method)) {
         $method = $this->forced_method;
     } else {
         $method = self::getActionMethod($this->action, $this->context);
         if (!$method) {
             throw new \Exception('No template: ' . get_class($this) . '.' . $this->action);
         }
     }
     if ($this->level > 50) {
         fx::log('recursion in', get_class($this), $method);
         return '<div class="fx_template_error">bad recursion?</div>';
     }
     $profiler = $this->getProfiler();
     if ($profiler) {
         $sign = preg_replace("~^fx_template_~", '', get_class($this)) . '::' . preg_replace("~^tpl_~", '', $method);
         $profiler->block('<b style="color:#009;">tpl:</b> ' . $sign);
     }
     try {
         $this->{$method}($this->context);
     } catch (\Exception $e) {
         if (preg_match("~Less_Exception~", get_class($e))) {
             fx::log('Less compiler exception', get_class($this) . ':' . $method, $e->getMessage(), $e->currentFile);
         } else {
             fx::log('template exception', $e->getMessage());
         }
     }
     $result = ob_get_clean();
     if (fx::isAdmin()) {
         if ($this->context->isIdle()) {
             if ($profiler) {
                 $profiler->stop();
             }
             return $result;
         }
         if (!$this->parent) {
             self::$count_replaces++;
             $result = Template::replaceAreas($result);
             $result = Field::replaceFields($result);
         }
     }
     if ($profiler) {
         $profiler->stop();
     }
     return $result;
 }
Пример #12
0
 public function doListSelected()
 {
     $is_overriden = $this->getParam('is_overriden');
     $linkers = null;
     // preview
     if ($is_overriden) {
         $content_ids = array();
         $selected_val = $this->getParam('selected');
         if (is_array($selected_val)) {
             $content_ids = $selected_val;
         }
     } else {
         // normal
         $linkers = $this->getSelectedLinkers();
         $content_ids = $linkers->getValues('linked_id');
     }
     $this->listen('query_ready', function ($e) use($content_ids) {
         $e['query']->where('id', $content_ids);
     });
     if ($linkers) {
         $this->listen('items_ready', function ($e) use($linkers) {
             $c = $e['items'];
             $real_c = $c->fork();
             $real_linkers = $linkers->fork();
             foreach ($linkers as $l) {
                 $linked = $c->findOne('id', $l['linked_id']);
                 if ($linked) {
                     $real_c[] = $linked;
                     $real_linkers[] = $l;
                 }
             }
             $real_c->linkers = $real_linkers;
             $e['items'] = $real_c;
         });
     } else {
         $this->listen('items_ready', function ($e) use($content_ids) {
             $c = $e['items'];
             $real_c = $c->fork();
             $ctr = $e['controller'];
             if ($ctr->getParam('sorting') === 'manual') {
                 foreach ($content_ids as $c_id) {
                     $linked = $c->findOne('id', $c_id);
                     $real_c[] = $linked;
                 }
             } else {
                 $counts = array_count_values($content_ids);
                 foreach ($c as $linked) {
                     $c_count = $counts[$linked['id']];
                     foreach (range(1, $c_count) as $n) {
                         $real_c[] = $linked;
                     }
                 }
             }
             $e['items'] = $real_c;
         });
     }
     if (!isset($this->_meta['fields'])) {
         $this->_meta['fields'] = array();
     }
     $this->doList();
     $items = $this->getResult('items');
     $common_page = $this->getCommonInfoblockPage($items);
     if ($common_page) {
         $this->assign('more_url', $common_page['url']);
     }
     // if we are admin and not viewing the block in preview mode,
     // let's add livesearch field loaded with the selected values
     if (!$is_overriden && fx::isAdmin()) {
         $selected_field = $this->getSelectedField(false);
         $selected_field['value'] = array();
         // filter result by selected content ids,
         // because some items can be added from inherited controllers (e.g. menu with subsections)
         $selected_items = $items->find('id', $content_ids);
         foreach ($selected_items as $selected_item) {
             $selected_field['value'][] = array('name' => $selected_item['name'], 'id' => $selected_item['id']);
         }
         $selected_field['var_type'] = 'ib_param';
         unset($selected_field['ajax_preload']);
         //$this->_meta['fields'][] = $selected_field;
         // allow select the same item several times
         $selected_field['allow_select_doubles'] = $this->getParam('allow_select_doubles');
         if ($items->linkers) {
             $items->linkers->selectField = $selected_field;
             $items->linkers->linkedBy = 'linked_id';
         }
     }
 }
Пример #13
0
 public function checkRights()
 {
     if (fx::isAdmin()) {
         return true;
     }
     if ($this['type_of_edit'] == Entity::EDIT_ALL || empty($this['type_of_edit'])) {
         return true;
     }
     return false;
 }
Пример #14
0
<?php

use Floxim\Floxim\System\Fx as fx;
$component = $this->getComponent();
$sort_fields = $component->getAllFields()->find(function ($f) {
    if ($f instanceof \Floxim\Floxim\Field\Link || $f instanceof \Floxim\Floxim\Field\MultiLink || $f instanceof \Floxim\Floxim\Field\Text || $f instanceof \Floxim\Floxim\Field\Image || in_array($f['keyword'], array('priority', 'is_published', 'is_branch_published', 'type', 'url', 'h1', 'title'))) {
        return false;
    }
    return true;
})->getValues(fx::isAdmin() ? 'name' : 'id', 'keyword');
$content_exists = fx::content($component['keyword'])->contentExists();
$is_new_infoblock = !$this->getParam('infoblock_id');
$component_infoblocks = fx::data('infoblock')->getContentInfoblocks($component['keyword']);
fx::cdebug(debug_backtrace());
return array('actions' => array('*list*' => array('settings' => array('limit' => array('label' => fx::alang('Count entries', 'controller_component'), 'class_name' => 'fx_field_limit'), 'pagination' => array('label' => fx::alang('Paginate?', 'controller_component'), 'type' => 'hidden', 'parent' => array('limit' => '!=')), 'sorting' => array('name' => 'sorting', 'label' => fx::alang('Sorting', 'controller_component'), 'type' => 'select', 'values' => $sort_fields), 'sorting_dir' => array('name' => 'sorting_dir', 'label' => fx::alang('Order', 'controller_component'), 'type' => 'select', 'values' => array('asc' => fx::alang('Ascending', 'controller_component'), 'desc' => fx::alang('Descending', 'controller_component')), 'parent' => array('sorting' => '!=manual')))), '*list' => array('disabled' => true), '*list_infoblock' => array('name' => fx::util()->ucfirst($component->getItemName('list')), 'install' => function ($ib, $ctr, $params) {
    $ctr->bindLostContent($ib, $params);
}, 'default_scope' => function () {
    $ds = fx::env('page_id') . '-this-';
    return $ds;
}, 'settings' => array('sorting' => array('values' => array(array('manual', fx::alang('Manual', 'controller_component'))) + $sort_fields)) + $this->getParentConfigFields() + $this->getTargetConfigFields() + $this->getLostContentField(), 'defaults' => array('!pagination' => true)), '*list_filtered' => array('name' => fx::util()->ucfirst(fx::alang('%s by filter', 'controller_component', $component->getItemName('list'))), 'settings' => array('conditions' => function ($ctr) {
    return $ctr->getConditionsField();
}, 'sorting' => array('values' => array(array('manual', fx::alang('Manual', 'controller_component'))) + $sort_fields)), 'defaults' => array('limit' => 10)), '*list_selected' => array('name' => fx::util()->ucfirst(fx::alang('%s selected', 'controller_component', $component->getItemName('list'))), 'settings' => array('selected' => function ($ctr) {
    return $ctr->getSelectedField();
}, 'allow_select_doubles' => array('type' => 'checkbox', 'label' => fx::alang('Allow doubles', 'controller_component')), 'is_pass_through' => array('label' => fx::alang('Pass-through data', 'controller_component'), 'type' => 'checkbox', 'parent' => array('scope[complex_scope]' => '!~this')), 'sorting' => array('values' => array(array('manual', fx::alang('Manual', 'controller_component'))) + $sort_fields)), 'defaults' => array('!pagination' => false, '!limit' => 0, '!allow_select_doubles' => true, 'is_pass_through' => 'false'), 'save' => function ($ib, $ctr, $params) {
    // update linkers
    $ctr->saveSelectedLinkers($params['params']['selected']);
}, 'delete' => function ($ib, $ctr, $params) {
    // drop linkers
    $ctr->dropSelectedLinkers();
}), '*list_filtered*, *list_selected*, *listing_by*' => array('check_context' => function () use($content_exists) {
    return $content_exists;
Пример #15
0
 public function doBreadcrumbs()
 {
     $entity_page = fx::env('page');
     $entity_page['active'] = true;
     if ($this->getParam('header_only')) {
         $pages = new System\Collection(array($entity_page));
     } else {
         $pages = $entity_page->getPath();
     }
     if (fx::isAdmin()) {
         $pages->show_hidden_items = true;
     }
     return array('items' => $pages);
 }