Пример #1
0
 public function validate()
 {
     $res = true;
     if (!$this['keyword']) {
         $this->validate_errors[] = array('field' => 'keyword', 'text' => fx::alang('Specify field keyword', 'system'));
         $res = false;
     }
     if ($this['keyword'] && !preg_match("/^[a-z][a-z0-9_]*\$/i", $this['keyword'])) {
         $this->validate_errors[] = array('field' => 'keyword', 'text' => fx::alang('Field keyword can contain only letters, numbers, and the underscore character', 'system'));
         $res = false;
     }
     $modified = $this->modified_data['keyword'] && $this->modified_data['keyword'] != $this->data['keyword'];
     if (!$this->column_created && !$this->getPayload('skip_sql') && $this['component_id'] && ($modified || !$this['id'])) {
         /// Edit here
         $component = fx::data('component')->where('id', $this['component_id'])->one();
         $chain = $component->getChain();
         foreach ($chain as $c_level) {
             if (fx::db()->columnExists($c_level->getContentTable(), $this->data['keyword'])) {
                 $this->validate_errors[] = array('field' => 'keyword', 'text' => fx::alang('This field already exists', 'system'));
                 $res = false;
             }
         }
     }
     if (!$this['name']) {
         $this->validate_errors[] = array('field' => 'name', 'text' => fx::alang('Specify field name', 'system'));
         $res = false;
     }
     return $res;
 }
Пример #2
0
 public function formatSettings()
 {
     $fields = array();
     $fields[] = array('id' => 'format[source]', 'name' => 'format[source]', 'type' => 'hidden', 'value' => 'manual');
     $fields[] = array('name' => 'format[values]', 'label' => fx::alang('Elements', 'system'), 'type' => 'set', 'tpl' => array(array('name' => 'id', 'type' => 'string'), array('name' => 'value', 'type' => 'string')), 'values' => $this['format']['values'] ? $this['format']['values'] : array(), 'labels' => array('id', 'value'));
     return $fields;
 }
Пример #3
0
 public function validate()
 {
     $res = true;
     if (!$this['name']) {
         $this->validate_errors[] = array('field' => 'name', 'text' => fx::alang('Specify the name of the widget', 'system'));
         $res = false;
     }
     if (!$this['keyword']) {
         $this->validate_errors[] = array('field' => 'keyword', 'text' => fx::alang('Enter the keyword of widget', 'system'));
         $res = false;
     }
     if ($this['keyword'] && !preg_match("/^[a-z0-9_\\.]+\$/i", $this['keyword'])) {
         $this->validate_errors[] = array('field' => 'keyword', 'text' => fx::alang('Keyword can contain only letters and numbers', 'system') . ' / ' . $this['keyword']);
         $res = false;
     }
     if ($this['keyword']) {
         $widgets = fx::data('widget')->all();
         foreach ($widgets as $widget) {
             if ($widget['id'] != $this['id'] && $widget['keyword'] == $this['keyword']) {
                 $this->validate_errors[] = array('field' => 'keyword', 'text' => fx::alang('This keyword is used by widget', 'system') . ' "' . $widget['name'] . '"');
                 $res = false;
             }
         }
     }
     return $res;
 }
Пример #4
0
 protected function getFakeIb()
 {
     static $fake_counter = 0;
     $fake_ib = fx::data('infoblock')->create();
     $fake_ib['id'] = 'fake-' . $fake_counter++;
     $fake_ib['name'] = fx::alang('New infoblock');
     return $fake_ib;
 }
Пример #5
0
 public function validate()
 {
     $res = true;
     if (!$this['name']) {
         $this->validate_errors[] = array('field' => 'name', 'text' => fx::alang('Enter the name of the site', 'system'));
         $res = false;
     }
     return $res;
 }
Пример #6
0
 public function formatSettings()
 {
     $fields = array();
     $comp_values = array_merge(fx::data('component')->getSelectValues(), array(array('site', 'Site'), array('component', 'Component'), array('infoblock', 'Infoblock'), array('lang', 'Language')));
     $fields[] = array('id' => 'format[target]', 'name' => 'format[target]', 'label' => fx::alang('Links to', 'system'), 'type' => 'select', 'values' => $comp_values, 'value' => $this['format']['target'] ? $this['format']['target'] : '');
     $fields[] = array('id' => 'format[prop_name]', 'name' => 'format[prop_name]', 'label' => fx::alang('Key name for the property', 'system'), 'value' => $this->getPropName());
     $fields[] = array('id' => 'format[is_parent]', 'name' => 'format[is_parent]', 'label' => fx::alang('Bind value to the parent', 'system'), 'type' => 'checkbox', 'value' => $this['format']['is_parent']);
     $fields[] = array('id' => 'format[render_type]', 'name' => 'format[render_type]', 'label' => fx::alang('Render type', 'system'), 'type' => 'select', 'values' => array('livesearch' => fx::alang('Live search', 'system'), 'select' => fx::alang('Simple select', 'system')), 'value' => $this['format']['render_type']);
     return $fields;
 }
Пример #7
0
 public function validateValue($value)
 {
     if (!is_array($value) && !is_object($value)) {
         $value = trim($value);
     }
     if ($this['is_required'] && !$value) {
         $this->error = sprintf(fx::alang('Field "%s" is required'), $this['name']);
         return false;
     }
     return true;
 }
Пример #8
0
 public function show($input)
 {
     $this->response->breadcrumb->addItem(fx::alang('Console'), '#admin.console.show');
     $this->response->submenu->setMenu('console');
     $fields = array('console_text' => array('name' => 'console_text', 'type' => 'text', 'code' => 'htmlmixed', 'value' => isset($input['console_text']) ? $input['console_text'] : '<?php' . "\n"));
     $fields[] = $this->ui->hidden('entity', 'console');
     $fields[] = $this->ui->hidden('action', 'execute');
     $this->response->addFormButton(array('label' => fx::alang('Execute') . ' (Ctrl+Enter)', 'is_submit' => false, 'class' => 'execute'));
     $this->response->addFields($fields);
     fx::page()->addJsFile(fx::path('@floxim') . '/Admin/js/console.js');
     return array('show_result' => 1);
 }
Пример #9
0
 public function show($input)
 {
     $log_id = $input['params'][0];
     $logger = fx::debug();
     $meta = $logger->getIndex($log_id);
     $this->response->breadcrumb->addItem(fx::alang('Logs'), '#admin.log.all');
     if ($meta) {
         $name = '[' . $meta['method'] . '] ' . $meta['url'] . ', ' . date('d.m.Y, H:i:s', round($meta['start']));
         $this->response->breadcrumb->addItem($name, '#admin.log.show');
     }
     $this->response->submenu->setMenu('log');
     return array('fields' => array(array('type' => 'buttons', 'buttons' => array(array('type' => 'button', 'label' => fx::alang('Delete', 'system'), 'options' => array('action' => 'drop_log', 'entity' => 'log', 'fx_admin' => 'true', 'log_id' => $log_id)), array('type' => 'button', 'label' => fx::alang('Delete all', 'system'), 'options' => array('action' => 'drop_all', 'entity' => 'log', 'fx_admin' => 'true')))), array('type' => 'html', 'html' => '<div class="fx_debug_entries">' . $logger->showItem($log_id) . "</div>")));
 }
Пример #10
0
 /**
  * Get fields for website create/edit form
  *
  * @param type fx_site $site
  *
  * @return array
  */
 protected function getFields($site)
 {
     $main_fields = array();
     $main_fields[] = $this->ui->input('name', fx::alang('Site name', 'system'), $site['name']);
     $main_fields[] = $this->ui->input('domain', fx::alang('Domain', 'system'), $site['domain']);
     $main_fields[] = array('name' => 'mirrors', 'label' => fx::alang('Aliases', 'system'), 'value' => $site['mirrors'], 'type' => 'text');
     $languages = fx::data('lang')->all()->getValues('lang_code', 'lang_code');
     $main_fields[] = array('name' => 'language', 'type' => 'select', 'values' => $languages, 'value' => $site['language'], 'label' => fx::alang('Language', 'system'));
     $layouts = fx::data('layout')->all();
     $layouts_select = array();
     foreach ($layouts as $layout) {
         $layouts_select[] = array($layout['id'], $layout['name']);
     }
     $main_fields[] = array('name' => 'layout_id', 'type' => 'select', 'values' => $layouts_select, 'value' => $site['layout_id'], 'label' => fx::alang('Layout', 'system'));
     return $main_fields;
 }
Пример #11
0
 public function getVendorField()
 {
     $field = array('name' => 'vendor', 'label' => fx::alang('Vendor', 'system'), 'type' => 'select', 'values' => array());
     $vendor = fx::config('dev.vendor');
     $vendor = explode(",", $vendor);
     foreach ($vendor as $num => $part) {
         $part = trim($part);
         if (empty($part)) {
             unset($vendor[$num]);
         }
     }
     $vendor[] = 'my';
     foreach ($vendor as $v) {
         $v = fx::util()->underscoreToCamel($v, true);
         $field['values'][$v] = $v;
     }
     return $field;
 }
Пример #12
0
 public function __construct()
 {
     $this->options['login'] = '******';
     $this->options['action_link'] = fx::config('path.admin');
     $this->addMoreMenu(Controller\Adminpanel::getMoreMenu());
     $this->addButtons(Controller\Adminpanel::getButtons());
     $main_menu = array('manage' => array('name' => fx::alang('Management', 'system'), 'key' => 'manage', 'href' => '/floxim/#admin.administrate.site.all'), 'develop' => array('name' => fx::alang('Development', 'system'), 'key' => 'develop', 'href' => '/floxim/#admin.component.all'));
     $site = fx::env('site');
     if ($site) {
         $main_menu['site'] = array('name' => fx::env('site')->getLocalDomain(), 'key' => 'site', 'href' => '/');
         $other_sites = fx::data('site')->where('id', $site['id'], '!=')->all();
         if (count($other_sites) > 0) {
             $main_menu['site']['children'] = array();
             foreach ($other_sites as $other_site) {
                 $domain = $other_site->getLocalDomain();
                 $main_menu['site']['children'][] = array('name' => $domain, 'href' => 'http://' . $domain . '/');
             }
         }
     }
     $this->addMainMenu($main_menu);
 }
Пример #13
0
 public function configColumns($settings)
 {
     $variants = array('n-w', 'w-n', 'w-w', 'n-w-n', 'w-w-w', 'n-n-w', 'w-n-n', 'n-w-w', 'w-w-n', 'w-n-w');
     $values = array();
     foreach ($variants as $var) {
         $parts = explode("-", $var);
         $count_wide = 0;
         foreach ($parts as $p) {
             if ($p === 'w') {
                 $count_wide++;
             }
         }
         $b = 'fx_grid_livesearch';
         $bv = $b . '_variant';
         $val = '<span class="' . $bv . ' ' . $bv . '__' . count($parts) . '_cols ' . $bv . '__' . $var . ' ' . $bv . '__' . $count_wide . '_w">';
         foreach ($parts as $part) {
             $val .= '<span class="' . $b . '_col ' . $b . '_col__' . $part . '"></span>';
         }
         $val .= '</span>';
         $val = str_replace('"', '\'', $val);
         $values[] = array('id' => $var, 'name' => $val);
     }
     return array('name' => fx::alang('Columns'), 'settings' => array('cols' => array('label' => fx::alang('Columns'), 'type' => 'livesearch', 'allow_empty' => false, 'values' => $values, 'value' => 'n-w')));
 }
Пример #14
0
<?php

use Floxim\Floxim\System\Fx as fx;
$source_ibs = fx::data('infoblock')->getContentInfoblocks('floxim.nav.section')->find('site_id', fx::env('site')->get('id'))->getValues('name', 'id');
return array('actions' => array('*list*' => array('icon' => 'Nav', 'name' => 'Меню', 'defaults' => array('!is_pass_through' => true, '!limit' => 0, '!create_record_ib' => false, '!sorting' => 'manual', '!sorting_dir' => 'asc', '!pagination' => false, '!submenu' => 'none'), 'settings' => array('extra_infoblocks' => array('name' => 'extra_infoblocks', 'label' => 'Добавить ссылки из другого блока', 'type' => 'livesearch', 'is_multiple' => true, 'ajax_preload' => true, 'content_type' => 'infoblock', 'conditions' => array('controller' => array(fx::data('component', 'page')->getAllVariants()->getValues(function ($ch) {
    return $ch['keyword'];
}), 'IN'), 'id' => array($this->getParam('infoblock_id'), '!='), 'site_id' => fx::env('site_id'), 'action' => 'list_infoblock')))), 'list_infoblock' => array('name' => 'Меню', 'default_scope' => function () {
    $ds = fx::env('site')->get('index_page_id') . '-descendants-';
    return $ds;
}), 'breadcrumbs' => array('icon' => 'Nav', 'icon_extra' => 'bre', 'name' => fx::alang('Breadcrumbs', 'component_section'), 'settings' => array('header_only' => array('name' => 'header_only', 'type' => 'checkbox', 'label' => fx::alang('Show only header?', 'component_section'))))));
Пример #15
0
 protected function afterDelete()
 {
     parent::afterDelete();
     fx::alang()->dropDictFiles($this['dict']);
 }
Пример #16
0
 public function formatSettings()
 {
     $fields = array();
     if (!$this['component_id']) {
         return $fields;
     }
     $com = fx::data('component', $this['component_id']);
     $chain = $com->getChain();
     $chain_ids = $chain->getValues('id');
     $link_fields = fx::data('field')->where('type', Field\Entity::FIELD_LINK)->where('component_id', 0, '!=')->all();
     // select from the available fields-links
     $linking_field_values = array();
     // array of InputB with specification of the data type
     $res_datatypes = array();
     // array of InputB with specification of the field for many-many
     $res_many_many_fields = array();
     // array of InputB with specification of the type for many-many
     $res_many_many_types = array();
     foreach ($link_fields as $lf) {
         if (in_array($lf['format']['target'], $chain_ids)) {
             // the component that owns the current box-link
             $linking_field_owner_component = fx::data('component', $lf['component_id']);
             $linking_field_values[] = array($lf['id'], $linking_field_owner_component['keyword'] . '.' . $lf['keyword']);
             // get the list of references component and all of its descendants
             $component_tree = fx::data('component')->getSelectValues($lf['component_id']);
             $res_datatypes[$lf['id']] = array();
             foreach ($component_tree as $com_variant) {
                 $linking_component = fx::data('component', $com_variant[0]);
                 $res_datatypes[$lf['id']][] = array($com_variant[0], $com_variant[1]);
                 // For links many_many relations
                 // get the field-component links that point to other components
                 $linking_component_links = $linking_component->getAllFields()->find('type', Field\Entity::FIELD_LINK)->find('id', $lf['id'], '!=');
                 // exclude fields, connected to the parent
                 if ($lf['format']['is_parent']) {
                     $linking_component_links = $linking_component_links->find('keyword', 'parent_id', '!=');
                 }
                 if (count($linking_component_links) === 0) {
                     continue;
                 }
                 // key for many-many
                 $mmf_key = $lf['id'] . '_' . $com_variant[0];
                 $res_many_many_fields[$mmf_key] = array(array('', '--'));
                 foreach ($linking_component_links as $linking_component_link) {
                     // skip pseudo-components
                     // @todo needs a better workaround
                     if (in_array($linking_component_link['format']['target'], array('lang', 'site', 'infoblock'))) {
                         continue;
                     }
                     $res_many_many_fields[$mmf_key][] = array($linking_component_link['id'], $linking_component_link['keyword']);
                     $target_component = fx::data('component', $linking_component_link['format']['target']);
                     $end_tree = fx::data('component')->getSelectValues($target_component['id']);
                     $mmt_key = $mmf_key . '|' . $linking_component_link['id'];
                     $res_many_many_types[$mmt_key] = array();
                     foreach ($end_tree as $end_com) {
                         $end_component = fx::data('component', $end_com[0]);
                         $res_many_many_types[$mmt_key][] = array($end_com[0], $end_component['keyword']);
                     }
                 }
             }
         }
     }
     $fields[] = array('id' => 'format[linking_field]', 'name' => 'format[linking_field]', 'label' => fx::alang('Linking field'), 'type' => 'select', 'values' => $linking_field_values, 'value' => $this['format']['linking_field']);
     foreach ($res_datatypes as $rel_field_id => $linking_datatype) {
         $field_id = 'format[linking_field_' . $rel_field_id . '_datatype]';
         $fields[] = array('id' => $field_id, 'name' => $field_id, 'type' => 'select', 'label' => fx::alang('Linked datatype'), 'parent' => array('format[linking_field]' => $rel_field_id), 'values' => $linking_datatype, 'value' => $this['format']['linking_datatype']);
     }
     foreach ($res_many_many_fields as $res_mmf_key => $mm_fields) {
         list($check_field, $check_type) = explode("_", $res_mmf_key);
         $field_id = 'format[linking_mm_field_' . $res_mmf_key . ']';
         $fields[] = array('id' => $field_id, 'name' => $field_id, 'type' => 'select', 'label' => 'Many-many field', 'parent' => array('format[linking_field_' . $check_field . '_datatype]' => $check_type, 'format[linking_field]' => $check_field), 'values' => $mm_fields, 'value' => $this['format']['mm_field']);
     }
     foreach ($res_many_many_types as $res_mmt_key => $mmt_fields) {
         list($check_mmf, $check_field) = explode("|", $res_mmt_key);
         $field_id = 'format[linking_mm_type_' . str_replace("|", "_", $res_mmt_key) . ']';
         $fields[] = array('id' => $field_id, 'name' => $field_id, 'type' => 'select', 'label' => 'Many-many datatype', 'parent' => array('format[linking_mm_field_' . $check_mmf . ']' => $check_field), 'values' => $mmt_fields, 'value' => $this['format']['mm_datatype']);
     }
     $fields[] = array('id' => 'format[render_type]', 'name' => 'format[render_type]', 'label' => fx::alang('Render type', 'system'), 'type' => 'select', 'values' => array('livesearch' => fx::alang('Live search', 'system'), 'table' => fx::alang('Fields table', 'system')), 'value' => $this['format']['render_type']);
     fx::log($fields);
     return $fields;
 }
Пример #17
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;
 }
Пример #18
0
 protected function setLayout($c_patch = null)
 {
     $this->response->breadcrumb->addItem(fx::alang('Patches', 'system'), '#admin.patch.all');
     if ($c_patch) {
         $this->response->breadcrumb->addItem($c_patch['to'], '#admin.patch.view(' . $c_patch['id'] . ')');
     }
     $this->response->submenu->setMenu('patch');
 }
Пример #19
0
 public function getItemName($scenario = 'one')
 {
     $lang = fx::alang()->getLang();
     $decl = $this['declension'];
     // this should be done via some config in future
     $declension_map = array('ru' => array('add' => 'singular.acc', 'add_many' => 'plural.acc', 'one' => 'singular.nom', 'list' => 'plural.nom', 'with' => 'plural.inst', 'in' => 'singular.prep', 'of' => 'singular.gen'));
     if (isset($declension_map[$lang])) {
         $map = $declension_map[$lang];
         if ($scenario && isset($map[$scenario])) {
             $form = explode(".", $map[$scenario]);
             if (isset($decl[$form[1]]) && isset($decl[$form[1]][$form[0]])) {
                 $res = $decl[$form[1]][$form[0]];
                 if ($res) {
                     return $res;
                 }
             }
         }
     }
     $item_name = $this['item_name'];
     return empty($item_name) ? $this['name'] : $item_name;
 }
Пример #20
0
 public function editItem($component, $input)
 {
     $this->response->submenu->setSubactive('items');
     $items_url = '#admin.component.edit(' . $component['id'] . ',items)';
     $this->response->breadcrumb->addItem(fx::alang('Items'), $items_url);
     $this->response->breadcrumb->addItem(fx::alang('Edit'));
     $ctr = new Content(array('content_type' => $component['keyword'], 'content_id' => $input['params'][2], 'reload_url' => $items_url, 'mode' => 'backoffice', 'do_return' => true), 'add_edit');
     $res = $ctr->process();
     return $res;
 }
Пример #21
0
 public function settingsSave($input)
 {
     $name = trim($input['name']);
     if (!$name) {
         $result['status'] = 'error';
         $result['text'][] = fx::alang('Enter the layout name', 'system');
         $result['fields'][] = 'name';
     } else {
         $template = fx::data('template')->getById($input['id']);
         if ($template) {
             $result['status'] = 'ok';
             $template->set('name', $name)->save();
         } else {
             $result['status'] = 'error';
             $result['text'][] = fx::alang('Layout not found', 'system');
         }
     }
     return $result;
 }
Пример #22
0
 protected function form($info)
 {
     $fields[] = $this->ui->input('f_email', fx::alang('Email', 'system'), $info['email']);
     $fields[] = $this->ui->input('f_name', fx::alang('User name', 'system'), $info['name']);
     $fields[] = $this->ui->password('password', fx::alang('Password', 'system'));
     $fields[] = $this->ui->password('password2', fx::alang('Confirm password', 'system'));
     if ($this->allowEditAdmin($info)) {
         $fields[] = array('type' => 'checkbox', 'name' => 'f_is_admin', 'label' => fx::alang('Is admin?', 'system'), 'value' => $info['is_admin']);
     }
     $fields[] = $this->ui->hidden('posting');
     $fields[] = $this->ui->hidden('entity', 'user');
     return $fields;
 }
Пример #23
0
 /**
  * List all content of specified type
  *
  * @param type $input
  */
 public function all($input)
 {
     $content_type = $input['content_type'];
     $list = array('type' => 'list', 'values' => array(), 'labels' => array('id' => 'ID'), 'entity' => 'content');
     if ($content_type === 'content') {
         $list['labels']['type'] = 'Type';
     }
     $com = fx::data('component', $content_type);
     $fields = $com->getAllFields();
     $ib_field = $fields->findOne('keyword', 'infoblock_id');
     if ($ib_field) {
         $list['labels']['infoblock'] = $ib_field['name'];
     }
     $fields->findRemove(function ($f) {
         if ($f['keyword'] === 'parent_id' || $f['keyword'] === 'type' || $f['keyword'] === 'site_id') {
             return false;
         }
         return $f['type_of_edit'] == Field\Entity::EDIT_NONE;
     });
     foreach ($fields as $f) {
         $list['labels'][$f['keyword']] = $f['name'];
     }
     $finder = fx::content($content_type);
     $pager = $finder->createPager(array('url_template' => $input['url_template'], 'current_page' => $input['page'], 'items_per_page' => 100));
     $items = $finder->all();
     $list['pager'] = $pager->getData();
     $ib_ids = $items->getValues('infoblock_id');
     $infoblocks = fx::data('infoblock', $ib_ids)->indexUnique('id');
     foreach ($items as $item) {
         $r = array('id' => $item['id']);
         $r['type'] = $item['type'];
         $c_ib = $infoblocks->findOne('id', $item['infoblock_id']);
         $r['infoblock'] = $c_ib ? $c_ib['name'] : '-';
         foreach ($fields as $f) {
             $val = $item[$f['keyword']];
             switch ($f['type']) {
                 case Field\Entity::FIELD_LINK:
                     if ($val) {
                         $linked = fx::data($f->getRelatedType(), $val);
                         $val = $linked['name'];
                     }
                     break;
                 case Field\Entity::FIELD_STRING:
                 case Field\Entity::FIELD_TEXT:
                     $val = strip_tags($val);
                     $val = mb_substr($val, 0, 150);
                     break;
                 case Field\Entity::FIELD_IMAGE:
                     $val = fx::image($val, 'max-width:100px,max-height:50px');
                     $val = '<img src="' . $val . '" alt="" />';
                     break;
                 case Field\Entity::FIELD_MULTILINK:
                     $val = fx::alang('%d items', 'system', count($val));
                     break;
             }
             $r[$f['keyword']] = $val;
         }
         $list['values'][] = $r;
     }
     $this->response->addButtons(array(array('key' => "delete", 'content_type' => $content_type)));
     return array('fields' => array('list' => $list));
 }
Пример #24
0
 public function validate()
 {
     if ($this->isModified('email')) {
         $existing = fx::data('floxim.user.user')->where('email', $this['email'])->where('id', $this['id'], '!=')->one();
         if ($existing) {
             $this->invalid(fx::alang('This email is already used', 'system'), 'email');
         }
     }
     if ($this->isModified('password')) {
         $password = $this->getPayload('plain_password');
         if (is_null($password)) {
             $password = $this['password'];
         }
         if (!empty($password)) {
             $confirm = $this->getPayload('confirm_password');
             if (!is_null($confirm) && $confirm !== $password) {
                 $this->invalid(fx::alang('Passwords do not match', 'system'), 'confirm_password');
             }
         } elseif (!$this['id']) {
             $this->invalid('Passwords can not be empty', 'password');
         }
     }
     $pres = parent::validate();
     return $pres;
 }
Пример #25
0
 public function getTemplateRecordAtts($collection, $index)
 {
     $entity_meta = array($this->get('id'), $this->getType(false));
     $linkers = null;
     if (is_object($collection) && $collection->linkers) {
         $linkers = $collection->linkers;
         if (isset($collection->linkers[$index])) {
             $linker = $linkers[$index];
             $entity_meta[] = $linker['id'];
             $entity_meta[] = $linker['type'];
         }
     }
     $entity_atts = array('data-fx_entity' => $entity_meta, 'class' => 'fx_entity' . (is_object($collection) && $collection->is_sortable ? ' fx_sortable' : ''));
     if (!$this->isVisible()) {
         $entity_atts['class'] .= ' fx_entity_hidden' . (!$collection || count($collection) === 1 ? '_single' : '');
     }
     $com = $this->getComponent();
     $entity_atts['data-fx_entity_name'] = fx::util()->ucfirst($com->getItemName('one'));
     $is_placeholder = $this->isAdderPlaceholder();
     if ($is_placeholder) {
         $entity_atts['class'] .= ' fx_entity_adder_placeholder';
     }
     if (isset($this['_meta'])) {
         $c_meta = $this['_meta'];
         if ($is_placeholder) {
             $c_meta['has_page'] = $this->hasPage();
             $c_meta['publish'] = $this->getDefaultPublishState();
         }
         $entity_atts['data-fx_entity_meta'] = $c_meta;
     }
     // fields to edit in panel
     $att_fields = array();
     $forced = $this->getForcedEditableFields();
     if (is_array($forced) && count($forced)) {
         foreach ($forced as $field_keyword) {
             $field_meta = $this->getFieldMeta($field_keyword);
             if (!is_array($field_meta)) {
                 continue;
             }
             // !!! hardcode
             if ($is_placeholder && $field_keyword === 'is_published') {
                 $field_meta['current_value'] = $this->getDefaultPublishState();
             } else {
                 $field_meta['current_value'] = $this[$field_keyword];
             }
             $att_fields[] = $field_meta;
         }
     }
     if ($linkers && $linkers->linkedBy) {
         if (!$linker) {
             fx::log($collection, $linkers);
             return $entity_atts;
         }
         $linker_field = $linker->getFieldMeta($linkers->linkedBy);
         $linker_collection_field = $linkers->selectField;
         if (!$is_placeholder && $linker_collection_field && $linker_collection_field['params']['content_type']) {
             $linker_type = $linker_collection_field['params']['content_type'];
         } else {
             $linker_type = $this['type'];
             $linker_field['params']['conditions'] = array(array('type', $linker_type));
         }
         $linker_field['params']['content_type'] = $linker_type;
         $linker_field['label'] = fx::alang('Select') . ' ' . mb_strtolower(fx::component($linker_type)->getItemName('add'));
         if (!$linker_collection_field || !$linker_collection_field['allow_select_doubles']) {
             $linker_field['params']['skip_ids'] = array();
             foreach ($collection->getValues('id') as $col_id) {
                 if ($col_id !== $this['id']) {
                     $linker_field['params']['skip_ids'][] = $col_id;
                 }
             }
         }
         $linker_field['current_value'] = $linker[$linkers->linkedBy];
         $att_fields[] = $linker_field;
     }
     if (!$this['id'] && (!$this['parent_id'] || !$this['infoblock_id']) && !$this->hasPage()) {
         $att_fields = array_merge($this->getStructureFields(), $att_fields);
     }
     foreach ($att_fields as $field_key => $field_meta) {
         $field_meta['in_att'] = true;
         // real field
         if (isset($field_meta['id']) && isset($field_meta['content_id'])) {
             $field_keyword = $field_meta['id'] . '_' . $field_meta['content_id'];
         } else {
             $field_keyword = $field_key;
             $field_meta['id'] = $field_key;
         }
         $template_field = new \Floxim\Floxim\Template\Field($field_meta['current_value'], $field_meta);
         $entity_atts['data-fx_force_edit_' . $field_keyword] = $template_field->__toString();
     }
     return $entity_atts;
 }
Пример #26
0
 public function formatSettings()
 {
     $fields = array(array('type' => 'checkbox', 'name' => 'html', 'label' => fx::alang('allow HTML tags', 'system')));
     return $fields;
 }
Пример #27
0
<?php

use Floxim\Floxim\System\Fx as fx;
return array('actions' => array('show' => array('name' => 'Произвольный HTML-код', 'settings' => array('code' => array('type' => 'text', 'label' => fx::alang('HTML code snippet'), 'code' => true)))));
Пример #28
0
 public static function getButtons()
 {
     $result = array('source' => array('add' => array('title' => fx::alang('add', 'system'), 'type' => 'text'), 'edit' => array('title' => fx::alang('edit', 'system')), 'on' => array('title' => fx::alang('on', 'system')), 'off' => array('title' => fx::alang('off', 'system')), 'settings' => array('title' => fx::alang('settings', 'system')), 'delete' => array('title' => fx::alang('delete', 'system')), 'select_block' => array('title' => fx::alang('Select parent block', 'system')), 'upload' => array('title' => fx::alang('Upload file', 'system')), 'download' => array('title' => fx::alang('Download file', 'system')), 'map' => array('title' => fx::alang('Site map', 'system')), 'export' => array('title' => fx::alang('Export', 'system')), 'store' => array('title' => fx::alang('Download from FloximStore', 'system')), 'import' => array('title' => fx::alang('Import', 'system')), 'change_password' => array('title' => fx::alang('Change password', 'system')), 'undo' => array('title' => fx::alang('Cancel', 'system')), 'redo' => array('title' => fx::alang('Redo', 'system')), 'more' => array('title' => fx::alang('More', 'system'))), 'map' => array('page' => explode(",", 'add,divider,edit,on,off,delete,divider,select_block,settings')));
     return $result;
 }
Пример #29
0
 public function transformToFloxim()
 {
     $tokens = $this->tokenize();
     $tree = $this->makeTree($tokens);
     $unnamed_replaces = array();
     $tree->apply(function (HtmlToken $n) use(&$unnamed_replaces) {
         if ($n->name == 'text') {
             return;
         }
         if (preg_match('~\\{[\\%|\\$]~', $n->source)) {
             $n->source = Html::parseFloximVarsInAtts($n->source);
         }
         $subroot = $n->hasAttribute('fx:omit') ? '' : ' subroot="true"';
         if (($n->name == 'script' || $n->name == 'style') && !$n->hasAttribute('fx:raw')) {
             $n->setAttribute('fx:raw', 'true');
         }
         if ($n->hasAttribute('fx:raw')) {
             $raw_value = $n->getAttribute('fx:raw');
             if ($raw_value != 'false') {
                 $n->addChildFirst(HtmlToken::create('{raw}'));
                 $n->addChild(HtmlToken::create('{/raw}'));
             }
             $n->removeAttribute('fx:raw');
         }
         if ($n->name == 'meta' && ($layout_id = $n->getAttribute('fx:layout'))) {
             $layout_name = $n->getAttribute('fx:name');
             $tpl_tag = '{template id="' . $layout_id . '" name="' . $layout_name . '" of="layout:show"}';
             $tpl_tag .= '{apply id="_layout_body"}';
             $content = $n->getAttribute('content');
             $vars = explode(",", $content);
             foreach ($vars as $var) {
                 $var = trim($var);
                 $negative = false;
                 if (preg_match("~^!~", $var)) {
                     $negative = true;
                     $var = preg_replace("~^!~", '', $var);
                 }
                 $tpl_tag .= '{$' . $var . ' select="' . ($negative ? 'false' : 'true') . '" /}';
             }
             $tpl_tag .= '{/call}{/template}';
             $n->parent->addChildBefore(HtmlToken::create($tpl_tag), $n);
             $n->remove();
             return;
         }
         if ($fx_replace = $n->getAttribute('fx:replace')) {
             $replace_atts = explode(",", $fx_replace);
             foreach ($replace_atts as $replace_att) {
                 if (!isset($unnamed_replaces[$replace_att])) {
                     $unnamed_replaces[$replace_att] = 0;
                 }
                 $var_name = 'replace_' . $replace_att . '_' . $unnamed_replaces[$replace_att];
                 $unnamed_replaces[$replace_att]++;
                 $default_val = $n->getAttribute($replace_att);
                 switch ($replace_att) {
                     case 'src':
                         $var_title = fx::alang('Picture', 'system');
                         break;
                     case 'href':
                         $var_title = fx::alang('Link', 'system');
                         break;
                     default:
                         $var_title = $replace_att;
                         break;
                 }
                 $n->setAttribute($replace_att, '{%' . $var_name . ' title="' . $var_title . '"}' . $default_val . '{/%' . $var_name . '}');
                 $n->removeAttribute('fx:replace');
             }
         }
         if ($var_name = $n->getAttribute('fx:var')) {
             if (!preg_match("~^[\$\\%]~", $var_name)) {
                 $var_name = '%' . $var_name;
             }
             $n->addChildFirst(HtmlToken::create('{' . $var_name . '}'));
             $n->addChild(HtmlToken::create('{/' . $var_name . '}'));
             $n->removeAttribute('fx:var');
         }
         $tpl_id = $n->getAttribute('fx:template');
         $macro_id = $n->getAttribute('fx:macro');
         if ($tpl_id || $macro_id) {
             if ($macro_id) {
                 $tpl_id = $macro_id;
             }
             if (preg_match("~\\[(.+?)\\]~s", $tpl_id, $tpl_test)) {
                 $tpl_test = preg_replace("~[\r\n]~", ' ', $tpl_test[1]);
                 $tpl_id = preg_replace("~\\[.+?\\]~s", '', $tpl_id);
             }
             $tpl_macro_tag = '{template id="' . $tpl_id . '" ';
             if ($macro_id) {
                 $tpl_macro_tag .= ' is_macro="true" ';
             }
             $tpl_macro_tag .= $subroot;
             if ($n->hasAttribute('fx:abstract')) {
                 $tpl_macro_tag .= ' is_abstract="true" ';
                 $n->removeAttribute('fx:abstract');
             }
             if ($tpl_for = $n->getAttribute('fx:of')) {
                 $tpl_macro_tag .= ' of="' . $tpl_for . '"';
                 $n->removeAttribute('fx:of');
             }
             if ($tpl_test || ($tpl_test = $n->getAttribute('fx:test'))) {
                 $tpl_macro_tag .= ' test="' . $tpl_test . '" ';
                 $n->removeAttribute('fx:test');
             }
             if ($tpl_name = $n->getAttribute('fx:name')) {
                 $tpl_macro_tag .= ' name="' . $tpl_name . '"';
                 $n->removeAttribute('fx:name');
             }
             if ($n->offset && $n->end_offset) {
                 $tpl_macro_tag .= ' offset="' . $n->offset[0] . ',' . $n->end_offset[1] . '" ';
             }
             if ($tpl_size = $n->getAttribute('fx:size')) {
                 $tpl_macro_tag .= ' size="' . $tpl_size . '" ';
                 $n->removeAttribute('fx:size');
             }
             if ($tpl_suit = $n->getAttribute('fx:suit')) {
                 $tpl_macro_tag .= ' suit="' . $tpl_suit . '"';
                 $n->removeAttribute('fx:suit');
             }
             if ($n->hasAttribute('fx:priority')) {
                 $tpl_priority = $n->getAttribute('fx:priority');
                 $tpl_macro_tag .= ' priority="' . $tpl_priority . '" ';
                 $n->removeAttribute('fx:priority');
             }
             $tpl_macro_tag .= '}';
             $n->wrap($tpl_macro_tag, '{/template}');
             $n->removeAttribute('fx:template');
             $n->removeAttribute('fx:macro');
         }
         if ($n->hasAttribute('fx:each')) {
             $each_id = $n->getAttribute('fx:each');
             $each_id = trim($each_id, '{}');
             $each_id = str_replace('"', '\\"', $each_id);
             $each_macro_tag = '{each ';
             $each_macro_tag .= $subroot;
             $each_macro_tag .= ' select="' . $each_id . '"';
             if ($each_as = $n->getAttribute('fx:as')) {
                 $each_macro_tag .= ' as="' . $each_as . '"';
                 $n->removeAttribute('fx:as');
             }
             if ($each_key = $n->getAttribute('fx:key')) {
                 $each_macro_tag .= ' key="' . $each_key . '"';
                 $n->removeAttribute('fx:key');
             }
             if ($prefix = $n->getAttribute('fx:prefix')) {
                 $each_macro_tag .= ' prefix="' . $prefix . '"';
                 $n->removeAttribute('fx:prefix');
             }
             if ($extract = $n->getAttribute('fx:extract')) {
                 $each_macro_tag .= ' extract="' . $extract . '"';
                 $n->removeAttribute('fx:extract');
             }
             if ($separator = $n->getAttribute('fx:separator')) {
                 $each_macro_tag .= ' separator="' . $separator . '"';
                 $n->removeAttribute('fx:separator');
             }
             $each_macro_tag .= '}';
             $n->wrap($each_macro_tag, '{/each}');
             $n->removeAttribute('fx:each');
         }
         if ($area_id = $n->getAttribute('fx:area')) {
             $n->removeAttribute('fx:area');
             $area = '{area id="' . $area_id . '" ';
             if ($area_size = $n->getAttribute('fx:size')) {
                 $area .= 'size="' . $area_size . '" ';
                 $n->removeAttribute('fx:size');
             } elseif ($area_size = $n->getAttribute('fx:area-size')) {
                 // use when fx:area and fx:template are placed on the same node
                 $area .= 'size="' . $area_size . '" ';
                 $n->removeAttribute('fx:area-size');
             }
             if ($area_suit = $n->getAttribute('fx:suit')) {
                 $area .= 'suit="' . $area_suit . '" ';
                 $n->removeAttribute('fx:suit');
             }
             if ($area_render = $n->getAttribute('fx:area-render')) {
                 $area .= 'render="' . $area_render . '" ';
                 $n->removeAttribute('fx:area-render');
             }
             if ($area_name = $n->getAttribute('fx:area-name')) {
                 $area .= 'name="' . $area_name . '" ';
                 $n->removeAttribute('fx:area-name');
             }
             $area .= '}';
             $n->addChildFirst(HtmlToken::create($area));
             $n->addChild(HtmlToken::create('{/area}'));
         }
         if ($n->hasAttribute('fx:item')) {
             $item_att = $n->getAttribute('fx:item');
             $n->removeAttribute('fx:item');
             $n->wrap('{item' . ($item_att ? ' test="' . $item_att . '"' : '') . $subroot . '}', '{/item}');
         }
         if ($n->hasAttribute('fx:aif')) {
             $if_test = $n->getAttribute('fx:aif');
             $ep = new ExpressionParser();
             $empty_cond = $ep->build($if_test);
             $class_code = '<?php echo (' . $empty_cond . ' ? "" : " fx_view_hidden ");?>';
             $n->addClass($class_code);
             $n->removeAttribute('fx:aif');
             $if_test .= ' || $_is_admin';
             $n->wrap('{if test="' . $if_test . '"}', '{/if}');
         }
         if ($n->hasAttribute('fx:if')) {
             $if_test = $n->getAttribute('fx:if');
             $n->removeAttribute('fx:if');
             $n->wrap('{if test="' . $if_test . '"}', '{/if}');
         }
         if ($with_each = $n->getAttribute('fx:with-each')) {
             $n->removeAttribute('fx:with-each');
             $weach_macro_tag = '{with-each ' . $with_each . '}';
             if ($separator = $n->getAttribute('fx:separator')) {
                 $weach_macro_tag .= '{separator}' . $separator . '{/separator}';
                 $n->removeAttribute('fx:separator');
             }
             $n->wrap($weach_macro_tag, '{/with-each}');
         }
         if ($with = $n->getAttribute('fx:with')) {
             $n->removeAttribute('fx:with');
             $n->wrap('{with select="' . $with . '" ' . $subroot . '}', '{/with}');
         }
         if ($n->hasAttribute('fx:separator')) {
             $n->wrap('{separator}', '{/separator}');
             $n->removeAttribute('fx:separator');
         }
         if ($elseif_test = $n->getAttribute('fx:elseif')) {
             $n->removeAttribute('fx:elseif');
             $n->wrap('{elseif test="' . $elseif_test . '"}', '{/elseif}');
         }
         if ($n->hasAttribute('fx:else')) {
             $n->removeAttribute('fx:else');
             $n->wrap('{else}', '{/else}');
         }
         if ($n->hasAttribute('fx:add')) {
             $add_mode = $n->getAttribute('fx:add');
             $n->removeAttribute('fx:add');
             $n->wrap('<?php $this->pushMode("add", "' . $add_mode . '"); ?>', '<?php $this->popMode("add"); ?>');
         }
         if ($n->hasAttribute('fx:omit')) {
             $omit = $n->getAttribute('fx:omit');
             if (empty($omit) || $omit == 'true') {
                 $omit = true;
             } else {
                 $ep = new ExpressionParser();
                 $omit = $ep->compile($ep->parse($omit));
             }
             $n->omit = $omit;
             $n->removeAttribute('fx:omit');
         }
         if ($n->hasAttribute('fx:e')) {
             $e_value = $n->getAttribute('fx:e');
             $n->addClass('{bem_element}' . $e_value . '{/bem_element}');
             $n->removeAttribute('fx:e');
         }
         if ($n->hasAttribute('fx:b')) {
             $b_value = $n->getAttribute('fx:b');
             $n->addClass('{bem_block}' . $b_value . '{/bem_block}');
             $n->removeAttribute('fx:b');
             $n->parent->addChildAfter(HtmlToken::create('<?php $this->bemStopBlock(); ?>'), $n);
         }
     });
     $res = $tree->serialize();
     //fx::log($res);
     return $res;
 }
Пример #30
0
 protected function initMenuUser($id)
 {
     $this->type = 'full';
     $user = fx::data('user')->getById($id);
     if (!$user) {
         $this->error = fx::alang('User not found', 'system');
     } else {
         $this->title = $user['name'];
         $this->backlink = 'user.all';
         $this->menu[] = $this->addNode('profile', fx::alang('Profile', 'system'), 'user.full(' . $user['id'] . ')');
     }
 }