Пример #1
0
 public function install($input)
 {
     $patch_id = $input['params'][0];
     if (!$patch_id) {
         return;
     }
     $patch = fx::data('patch', $patch_id);
     if (!$patch) {
         return;
     }
     $this->response->addField(array('type' => 'label', 'value' => '<p>' . sprintf(fx::alang('Installing patch %s...', 'system'), $patch['to']) . '</p>'));
     $res = false;
     try {
         $res = $patch->install();
     } catch (Exception $e) {
         $this->response->addField(array('type' => 'label', 'value' => '<p style="color:#F00;">' . $e->getMessage() . '</p>'));
     }
     if (!$res) {
         $this->response->addField(array('type' => 'label', 'value' => '<p style="color:#F00;">Install failed!</p>'));
     } else {
         // retrieve changes
         $changes = '<ul>';
         $logs = fx::changelog($patch['to']);
         foreach ($logs as $log) {
             $changes .= "<li>{$log['message']}</li>";
         }
         $changes .= '</ul>';
         $this->response->addField(array('type' => 'label', 'value' => '<p>Patch installed sucessfully!</p>' . $changes));
     }
     $this->response->addField(array('type' => 'button', 'url' => 'patch.all', 'label' => 'Back'));
     $this->setLayout($patch);
 }
Пример #2
0
 protected function deleteInfoblocks()
 {
     $infoblocks = fx::data('infoblock')->where('site_id', $this['id'])->all();
     foreach ($infoblocks as $infoblock) {
         $infoblock->delete();
     }
 }
Пример #3
0
 public function doNeighbours()
 {
     $item = fx::env('page');
     $q = $this->getFinder()->order(null)->limit(1)->where('site_id', fx::env('site_id'));
     $q_next = clone $q;
     $q_prev = clone $q;
     if ($this->getParam('sorting') === 'auto' && $item['infoblock_id']) {
         $item_ib_params = fx::data('infoblock', $item['infoblock_id'])->get('params');
         $ib_sorting = $item_ib_params['sorting'];
         $this->setParam('sorting', $ib_sorting == 'manual' || $ib_sorting == 'auto' ? 'priority' : $ib_sorting);
         $this->setParam('sorting_dir', $item_ib_params['sorting_dir']);
     }
     $sort_field = $this->getParam('sorting', 'priority');
     if ($sort_field === 'auto') {
         $sort_field = 'priority';
     }
     $dir = strtolower($this->getParam('sorting_dir', 'asc'));
     $where_prev = array(array($sort_field, $item[$sort_field], $dir == 'asc' ? '<' : '>'));
     $where_next = array(array($sort_field, $item[$sort_field], $dir == 'asc' ? '>' : '<'));
     $group_by_parent = $this->getParam('group_by_parent');
     if ($group_by_parent) {
         $c_parent = fx::content($item['parent_id']);
         // todo: psr0 need verify
         $q_prev->order('parent.priority', 'desc')->where('parent.priority', $c_parent['priority'], '<=');
         $q_next->order('parent.priority', 'asc')->where('parent.priority', $c_parent['priority'], '>=');
         $where_prev[] = array('parent_id', $item['parent_id'], '!=');
         $where_next[] = array('parent_id', $item['parent_id'], '!=');
     }
     $q_prev->order($sort_field, $dir == 'asc' ? 'desc' : 'asc')->where($where_prev, null, 'or');
     $prev = $q_prev->all();
     $q_next->order($sort_field, $dir)->where($where_next, null, 'or');
     $next = $q_next->all();
     //fx::log($q_prev->showQuery(), $q_next->showQuery());
     return array('prev' => $prev, 'current' => $item, 'next' => $next);
 }
Пример #4
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;
 }
Пример #5
0
 public function getErrorPage($site_id = null)
 {
     if (is_null($site_id)) {
         $site_id = fx::env('site_id');
     }
     $error_page = fx::data('page', fx::data('site', $site_id)->get('error_page_id'));
     return $error_page;
 }
Пример #6
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;
 }
Пример #7
0
 public function install(\Floxim\Floxim\Component\Infoblock\Entity $ib, $ctr, $params)
 {
     if (!isset($params['form_id']) || !$params['form_id']) {
         $form = fx::data('floxim.form.form')->create(array('name' => 'My new form'));
         $form->save();
         $ib->digSet('params.form_id', $form['id']);
         $ib->save();
         fx::log('ib savd', $ib, $params, $form);
     }
 }
Пример #8
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;
 }
Пример #9
0
 public static function getPath($id)
 {
     if (!is_numeric($id)) {
         return $id;
     }
     $file = fx::data('filetable', $id);
     if (!$file) {
         return null;
     }
     return $file->getHttpPath();
 }
Пример #10
0
 protected function beforeSave()
 {
     parent::beforeSave();
     unset($this['is_stub']);
     if (!$this['priority'] && $this['layout_id']) {
         $last_vis = fx::data('infoblock_visual')->where('layout_id', $this['layout_id'])->where('area', $this['area'])->order(null)->order('priority', 'desc')->one();
         $this['priority'] = $last_vis['priority'] + 1;
     }
     if ($this->needRecountFiles) {
         $this->recountFiles();
     }
 }
Пример #11
0
 protected function handleLinkers()
 {
     fx::listen('after_delete', function ($e) {
         $entity = $e['entity'];
         if (!$entity->isInstanceOf('floxim.main.content') || $entity->isInstanceOf('floxim.main.linker')) {
             return;
         }
         $linkers = fx::data('floxim.main.linker')->where('linked_id', $entity['id'])->all();
         $linkers->apply(function ($l) {
             $l->delete();
         });
     });
 }
Пример #12
0
 public function doAdd()
 {
     if (isset($_POST["addcomment"]) && isset($_POST["user_name"]) && !empty($_POST["user_name"]) && isset($_POST["comment_text"]) && !empty($_POST["comment_text"])) {
         $comments = fx::data('comment')->create(array('user_name' => $_POST["user_name"], 'comment_text' => $_POST["comment_text"], 'publish_date' => date("Y-m-d H:i:s"), 'parent_id' => $this->getParentId(), 'infoblock_id' => $this->getParam('target_infoblock_id')));
         $comments->save();
         if (!isset($_COOKIE["own_comments"])) {
             setcookie('own_comments', $comments["id"], time() + 60 * 60 * 24 * 30);
         } else {
             setcookie('own_comments', $_COOKIE["own_comments"] . ',' . $comments["id"], time() + 60 * 60 * 24 * 30);
         }
         fx::http()->refresh();
     }
 }
Пример #13
0
 public function getData()
 {
     $data = parent::getData();
     $types_by_id = $data->getValues('type', 'id');
     unset($types_by_id['']);
     if (count($types_by_id) == 0) {
         return $data;
     }
     $base_component = fx::component($this->component_id);
     $base_type = $base_component['keyword'];
     $base_table = $base_component->getContentTable();
     $types = array();
     foreach ($types_by_id as $id => $type) {
         if ($type != $base_type) {
             if (!isset($types[$type])) {
                 $types[$type] = array();
             }
             $types[$type][] = $id;
         }
     }
     foreach ($types as $type => $ids) {
         if (!$type) {
             continue;
         }
         $type_tables = array_reverse(fx::data($type)->getTables());
         $missed_tables = array();
         foreach ($type_tables as $table) {
             if ($table == $base_table) {
                 break;
             }
             $missed_tables[] = $table;
         }
         $base_missed_table = array_shift($missed_tables);
         if (!$base_missed_table) {
             fx::log('empty base table');
             continue;
         }
         $q = "SELECT * FROM `{{" . $base_missed_table . "}}` \n";
         foreach ($missed_tables as $mt) {
             $q .= " INNER JOIN `{{" . $mt . '}}` ON `{{' . $mt . '}}`.id = `{{' . $base_missed_table . "}}`.id\n";
         }
         $q .= "WHERE `{{" . $base_missed_table . "}}`.id IN (" . join(", ", $ids) . ")";
         $extensions = fx::db()->getIndexedResults($q);
         foreach ($data as $data_index => $data_item) {
             if (isset($extensions[$data_item['id']])) {
                 $data[$data_index] = array_merge($data_item, $extensions[$data_item['id']]);
             }
         }
     }
     return $data;
 }
 protected function up()
 {
     $new_fields = array(array('keyword' => 'is_published', 'name_en' => 'Is published?', 'name_ru' => '', 'type' => '5', 'not_null' => '0', 'priority' => '267', 'searchable' => '0', 'default' => '1', 'type_of_edit' => '1', 'checked' => '1', 'form_tab' => '0'), array('keyword' => 'is_branch_published', 'name_en' => 'Is branch published?', 'name_ru' => '', 'type' => '5', 'not_null' => '0', 'priority' => '268', 'searchable' => '0', 'default' => '1', 'type_of_edit' => '3', 'checked' => '1', 'form_tab' => '0'));
     $content_id = fx::data('component', 'content')->get('id');
     foreach ($new_fields as $field_props) {
         $field_props['component_id'] = $content_id;
         $field = fx::data('field')->create($field_props);
         $field->save();
         fx::log('add field', $field);
     }
     fx::data('component')->dropStoredStaticCache();
     fx::db()->query('update {{floxim_main_content}} set is_published = 1, is_branch_published = 1');
     fx::cache('meta')->delete('schema');
 }
Пример #15
0
 public function getFormFieldCondition($field)
 {
     $jsf = $field->getJsField($this);
     $form = $this['form'];
     if (!$form) {
         $form = fx::data('floxim.form.form')->create();
     }
     $inputs = $form->getInputs();
     $jsf['fields'] = array();
     foreach ($inputs as $input) {
         $jsf['fields'][] = array('name' => $input['label'], 'type' => 'string', 'id' => $input['id'], 'keyword' => 'field.' . $input['id']);
     }
     return $jsf;
 }
Пример #16
0
 protected function getLayout()
 {
     if ($this->_layout) {
         return $this->_layout;
     }
     $page = fx::data('page', $this->getParam('page_id'));
     if ($page['layout_id']) {
         $layout_id = $page['layout_id'];
     } else {
         $site = fx::data('site', $page['site_id']);
         $layout_id = $site['layout_id'];
     }
     $this->_layout = fx::data('layout', $layout_id);
     return $this->_layout;
 }
Пример #17
0
 /**
  * Create / load component entity from passed args
  *
  * @param string|int $keyword Keyword or id for existing component
  * @param string|bool $name
  * @param string|bool $itemName
  * @param string $parent Parent component keyword
  * @param bool $overwrite Overwrite existing component
  *
  * @return \Floxim\Floxim\Component\Component\Entity
  */
 public function loadComponent($keyword, $name = false, $itemName = false, $parent = 'content')
 {
     if (is_numeric($keyword)) {
         $com = fx::data('component', $keyword);
     } else {
         $keyword_parts = explode('.', $keyword);
         if (count($keyword_parts) != 3) {
             $this->usageError('Name need format "vendor.module.name"');
         }
         $name = $name ? $name : preg_replace("~^.+\\..+\\.~", '', $keyword);
         $itemName = $itemName ? $itemName : $name;
         $parent_id = fx::data('component', $parent)->get('id');
         $com = fx::data('component')->create(array('keyword' => $keyword, 'name' => $name, 'item_name' => $itemName, 'parent_id' => $parent_id));
     }
     return $com;
 }
Пример #18
0
 public function validate()
 {
     if (!parent::validate()) {
         return false;
     }
     $existing = fx::data('lang_string')->where('string', $this['string'])->where('dict', $this['dict'])->where('id', $this['id'], '!=')->all();
     foreach ($existing as $double) {
         if ($double['string'] == $this['string']) {
             //fx::log('nop', $double['string'], $this['string']);
             $this->validate_errors[] = 'String "' . $this['string'] . '" already exists in the "' . $this['dict'] . '" dictionary';
             return false;
         }
         //fx::log('double by case?', $this, $double);
     }
     return true;
 }
Пример #19
0
 public static function getMainMenu()
 {
     $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) {
         $other_sites = fx::data('site')->where('id', $site['id'], '!=')->all();
         if (count($other_sites) > 0) {
             $main_menu['site'] = array('name' => fx::env('site')->getLocalDomain(), 'key' => 'site', 'href' => '/');
             $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 . '/');
             }
         }
     }
     fx::trigger('admin_main_menu_ready', array('menu' => &$main_menu));
     return $main_menu;
 }
Пример #20
0
 protected function beforeInsert()
 {
     $entities = $this->getMultilangEntities();
     fx::log('ess', $entities);
     foreach ($entities as $e) {
         $fields = fx::data($e)->getMultiLangFields();
         fx::log('fld', $e, $fields);
         if (count($fields) > 0) {
             $q = "ALTER TABLE `{{" . $e . "}}` ";
             $parts = array();
             foreach ($fields as $f) {
                 $parts[] = "ADD COLUMN `" . $f . "_" . $this['lang_code'] . "` VARCHAR(255) ";
             }
             $q .= join(", ", $parts);
             fx::log('qr', $q);
             fx::db()->query($q);
         }
     }
 }
Пример #21
0
 public function getForPage($page_id = null)
 {
     $page = $page_id instanceof System\Entity ? $page_id : fx::data('page', $page_id);
     if (!$page) {
         return fx::collection();
     }
     //$ids = $page->getParentIds();
     $ids = $page->getPath()->getValues('id');
     $ids[] = $page['id'];
     $ids[] = 0;
     // root
     $infoblocks = $this->where('page_id', $ids)->where('site_id', $page['site_id'])->all();
     foreach ($infoblocks as $ib) {
         if (!$ib->isAvailableOnPage($page)) {
             $infoblocks->remove($ib);
         }
     }
     return $infoblocks;
 }
Пример #22
0
 public function addField($field)
 {
     if (is_array($field)) {
         if (!isset($field['type'])) {
             $field['type'] = 'text';
         }
         if ($field['type'] === 'submit') {
             $field['type'] = 'button';
         }
         $field['type'] = 'floxim.form.' . $field['type'];
         $field = fx::data('floxim.form.field')->generate($field);
     }
     $field['form'] = $this;
     $this['fields'][] = $field;
     if ($this->isSent()) {
         $field->loadValue($this->getInput());
     }
     return $this;
 }
Пример #23
0
 /**
  * get page (urlAlias) by url string
  *
  * @param string url string
  *
  * @return object page
  */
 public function getByUrl($url, $site_id = null)
 {
     $url_variants = array($url);
     if ($site_id === null) {
         $site_id = fx::env('site_id');
     }
     $url_with_no_params = preg_replace("~\\?.+\$~", '', $url);
     $url_variants[] = preg_match("~/\$~", $url_with_no_params) ? preg_replace("~/\$~", '', $url_with_no_params) : $url_with_no_params . '/';
     if ($url_with_no_params != $url) {
         $url_variants[] = $url_with_no_params;
     }
     // get alias by url
     $alias = fx::data('urlAlias')->where('url', $url_variants)->where('site_id', $site_id)->one();
     if (!$alias) {
         return null;
     }
     // get page by id
     $page = $this->getById($alias['page_id']);
     return $page;
 }
Пример #24
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);
 }
Пример #25
0
 public function editSave($input)
 {
     $widget = fx::data('widget')->getById($input['id']);
     $result['status'] = 'ok';
     // save settings
     if ($input['phase'] == 'settings') {
         $params = array('name', 'description', 'embed');
         if (!trim($input['name'])) {
             $result['status'] = 'error';
             $result['text'][] = fx::alang('Enter the widget name', 'system');
             $result['fields'][] = 'name';
         }
         if ($result['status'] == 'ok') {
             foreach ($params as $v) {
                 $widget->set($v, trim($input[$v]));
             }
             $widget->save();
         }
     }
     return $result;
 }
Пример #26
0
 public function init()
 {
     fx::template()->import('floxim.layout.wrapper');
     fx::listen('before_save', function ($e) {
         $entity = $e['entity'];
         if (!$entity instanceof \Floxim\Floxim\Component\InfoblockVisual\Entity) {
             return;
         }
         if (!preg_match("~column_new-in-(\\d+)~", $entity['area'], $column_infoblock_id)) {
             return;
         }
         $column_infoblock_id = $column_infoblock_id[1];
         $column = fx::data('floxim.layout.column')->create(array('infoblock_id' => $column_infoblock_id));
         if (preg_match("~(before|after)-(\\d+)~", $entity['area'], $rel_col)) {
             $column['__move_' . $rel_col[1]] = $rel_col[2];
         }
         fx::log($rel_col, $column);
         $column->save();
         $entity['area'] = $column['area_keyword'];
     });
 }
Пример #27
0
 protected function dumpDictionary($dict, $file)
 {
     if (!isset($this->lang)) {
         $this->setLang();
     }
     $data = fx::data('lang_string')->where('dict', $dict)->all();
     $res = array();
     foreach ($data as $s) {
         $res[$s['string']] = $s['lang_' . $this->lang];
     }
     fx::files()->writefile($file, "<?php\nreturn " . var_export($res, 1) . ";");
 }
Пример #28
0
 public function deleteSave($input)
 {
     $es = $this->entity_type;
     $result = array('status' => 'ok');
     $ids = $input['id'];
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     foreach ($ids as $id) {
         try {
             $component = fx::data($es, $id);
             $component->delete();
         } catch (\Exception $e) {
             $result['status'] = 'error';
             $result['text'][] = $e->getMessage();
         }
     }
     return $result;
 }
Пример #29
0
 public function settingsSave($input)
 {
     $site = fx::data('site')->getById($input['id']);
     $result = array('status' => 'ok', 'reload' => '#admin.site.all');
     $params = array('name', 'domain', 'mirrors', 'language', 'robots', 'layout_id', 'index_page_id', 'error_page_id', 'offline_text');
     foreach ($params as $v) {
         if (isset($input[$v])) {
             $site[$v] = $input[$v];
         }
     }
     $site->save();
     return $result;
 }
Пример #30
0
 public function getLayoutInfoblock($page)
 {
     if (!is_object($page)) {
         fx::log(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS));
     }
     $path = $page->getPath()->copy()->reverse();
     foreach ($path as $c_page) {
         if (method_exists($c_page, 'getLayoutInfoblock')) {
             $layout_ib = $c_page->getLayoutInfoblock();
             break;
         }
     }
     if ($layout_ib->getVisual()->get('is_stub') || !$layout_ib->getTemplate()) {
         $suitable = new Template\Suitable();
         //$infoblocks = $page->getPageInfoblocks();
         $infoblocks = fx::data('infoblock')->getForPage($page);
         // delete all parent layouts from collection
         $infoblocks->findRemove(function ($ib) use($layout_ib) {
             return $ib->isLayout() && $ib['id'] !== $layout_ib['id'];
         });
         $suitable->suit($infoblocks, fx::env('layout_id'));
         return $infoblocks->findOne(function ($ib) {
             return $ib->isLayout();
         });
     }
     return $layout_ib;
 }