public function recountFiles() { $modified_params = $this->getModifiedParams(); $fxPath = fx::path(); foreach ($modified_params as $field => $params) { $all_params = $this[$field]; foreach ($params as $pk => $pv) { if (self::checkValueIsFile($pv['new'])) { fx::log($pv, 'is file'); $ib = $this['infoblock']; $site_id = $ib ? $ib['site_id'] : fx::env('site_id'); $file_name = $fxPath->fileName($pv['new']); $new_path = $fxPath->abs('@content_files/' . $site_id . '/visual/' . $file_name); $move_from = $fxPath->abs($pv['new']); if (file_exists($move_from)) { fx::files()->move($move_from, $new_path); $all_params[$pk] = $fxPath->removeBase($fxPath->http($new_path)); } } if ($pv['old']) { $old_path = $fxPath->abs(FX_BASE_URL . $pv['old']); if (self::checkValueIsFile($old_path)) { fx::files()->rm($old_path); } } } $this[$field] = $all_params; } }
public function route($url = null, $context = null) { $thumbs_path = fx::path()->http('@thumbs'); if (substr($url, 0, strlen($thumbs_path)) !== $thumbs_path) { return null; } $dir = substr($url, strlen($thumbs_path)); preg_match("~/([^/]+)(/.+\$)~", $dir, $parts); $config = $parts[1]; $source_path = $parts[2]; $source_abs = fx::path($source_path); if (!file_exists($source_abs)) { echo 'nof'; return null; } $target_dir = dirname(fx::path($url)); if (!file_exists($target_dir) || !is_dir($target_dir)) { echo 'notarg'; return null; } $config = $config . '.async-false.output-true'; $config = \Floxim\Floxim\System\Thumb::readConfigFromPathString($config); fx::image($source_path, $config); fx::log('thumb done'); fx::complete(); die; }
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); } }
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'); }
public function addSave($input) { $result = array('status' => 'ok'); $data['name'] = trim($input['name']); $data['keyword'] = $this->getFullKeyword($input); $widget = fx::data('widget')->create($data); if (!$widget->validate()) { $result['status'] = 'error'; $result['errors'] = $widget->getValidateErrors(); $result['text'] = 'Error'; fx::log('invald', $result); return $result; } $widget->save(); fx::console('widget scaffold --id=' . $widget['id']); $result['reload'] = '#admin.widget.all'; return $result; }
public function addSave($input) { $result = array('status' => 'ok'); $lang = fx::data('lang')->create(array('en_name' => $input['en_name'], 'native_name' => $input['native_name'], 'lang_code' => $input['lang_code'])); if (!$lang->validate()) { $result['status'] = 'error'; $result['errors'] = $lang->getValidateErrors(); return $result; } try { fx::log('saving', $lang); $lang->save(); fx::log('svd', $lang); } catch (Exception $e) { $result['status'] = 'error'; $result['text'][] = $e->getMessage(); } return $result; }
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); } } }
public function doColumns() { $cols = $this->getParam('cols', 'n-w'); $parts = explode("-", $cols); $res = array(); $count_wide = 0; foreach ($parts as $col_num => $col) { $res[] = array('keyword' => 'col_' . ($col_num + 1), 'size' => $col === 'n' ? 'narrow' : 'wide', 'width' => $col); if ($col === 'w') { $count_wide++; } } return array('areas' => $res, 'cols' => $cols, 'count_wide' => $count_wide); $form = $this->ajaxForm(); $form->addFields(array('test' => array('type' => 'text', 'label' => "Test", 'value' => 'ok'), 'livesearch' => array('type' => 'livesearch', 'label' => 'Complex', 'values' => array('test' => 'Test <b>So</b> Cool!<br /><span style='font-size:12px; color:#999;'>not joking</span>', 'west' => 'West'), 'value' => array('test'), 'is_multiple' => true, 'params' => array('multiple' => true)), 'cnt' => array('type' => 'livesearch', 'label' => 'Section', 'is_multiple' => true, 'params' => array('content_type' => 'floxim.nav.section')))); if ($form->isSent()) { fx::log($form, $form->getValues()); } $this->assign('form', $form); }
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']; }); }
/** * Perform all registered routers, to return most suitable controller * @param string $url * @param array $context * @return fx_controller */ public function route($url = null, $context = array()) { if (is_null($url)) { $url = getenv('REQUEST_URI'); } if (!isset($context['site_id'])) { $env_site = fx::env('site'); $context['site_id'] = $env_site ? $env_site['id'] : null; } foreach ($this->routers as $router_key => $r) { $result = $r['router']->route($url, $context); if ($result !== null && $result !== false) { $log_option = fx::config('dev.log_routes'); if (is_bool($log_option) && $log_option || is_array($log_option) && in_array($router_key, $log_option) || is_string($log_option) && $log_option === $router_key) { fx::log('routed', $router_key, $url); } if ($result instanceof \Floxim\Floxim\System\Controller) { $result = $result->process(); } return $result; } } }
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; }
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; }
public function addDefaultSourceDirs() { $template_name = $this->getTemplateName(); if (!$this->isAliased()) { $dir = self::nameToPath($this->getTemplateName()); $dirs = array($dir); foreach ($dirs as $dir) { try { $this->addSourceDir($dir); } catch (\Exception $e) { fx::log('Error while adding template source dir', $e->getMessage()); } } } if (isset(self::$source_paths[$template_name])) { foreach (self::$source_paths[$template_name] as $sp) { try { $this->addSource($sp); } catch (\Exception $ex) { } } } }
/** * wrap ib's output */ protected function wrapOutput($output) { $wrapper = $this->getPropInherited('visual.wrapper'); if (!$wrapper) { return $output; } $tpl_wrap = fx::template($wrapper); if (!$tpl_wrap) { return $output; } $tpl_wrap->isWrapper(true); $wrap_params = $this->getPropInherited('visual.wrapper_visual'); if (!is_array($wrap_params)) { $wrap_params = array(); } $wrap_params['content'] = $output; $wrap_params['infoblock'] = $this; $is_admin = fx::isAdmin(); try { $result = $tpl_wrap->render($wrap_params); } catch (\Exception $e) { fx::log('error while wrapping ib #' . $this['id'], $e->getMessage()); $result = $output; } if ($is_admin) { $this->infoblock_meta['wrapper_params'] = $tpl_wrap->getRegisteredParams(); } $this->output_is_subroot = $tpl_wrap->is_subroot; return $result; }
public static function isPhpSyntaxCorrect($code) { $braces = 0; $inString = 0; $code = preg_replace("~^\\s*\\<\\?(php)?~", '', $code); $code = preg_replace("~\\?>\\s*\$~", '', $code); // First of all, we need to know if braces are correctly balanced. // This is not trivial due to variable interpolation which // occurs in heredoc, backticked and double quoted strings $all_tokens = token_get_all('<?php ' . $code); foreach ($all_tokens as $token) { if (is_array($token)) { switch ($token[0]) { case T_CURLY_OPEN: case T_DOLLAR_OPEN_CURLY_BRACES: case T_START_HEREDOC: ++$inString; break; case T_END_HEREDOC: --$inString; break; } } else { if ($inString & 1) { switch ($token) { case '`': case '"': --$inString; break; } } else { switch ($token) { case '`': case '"': ++$inString; break; case '{': ++$braces; break; case '}': if ($inString) { --$inString; } else { --$braces; if ($braces < 0) { break 2; } } break; } } } } // Display parse error messages and use output buffering to catch them $prev_ini_log_errors = @ini_set('log_errors', false); $prev_ini_display_errors = @ini_set('display_errors', true); // If $braces is not zero, then we are sure that $code is broken. // We run it anyway in order to catch the error message and line number. // Else, if $braces are correctly balanced, then we can safely put // $code in a dead code sandbox to prevent its execution. // Note that without this sandbox, a function or class declaration inside // $code could throw a "Cannot redeclare" fatal error. $braces || ($code = "if(0){{$code}\n}"); register_shutdown_function(function () use($code) { if (!fx::env('complete_ok')) { fx::log('Died while compiling template', $code); } }); ob_start(); $eval_res = eval($code); if (false === $eval_res) { if ($braces) { $braces = PHP_INT_MAX; } else { // Get the maximum number of lines in $code to fix a border case false !== strpos($code, "\r") && ($code = strtr(str_replace("\r\n", "\n", $code), "\r", "\n")); $braces = substr_count($code, "\n"); } $buffer_output = ob_get_clean(); $buffer_output = strip_tags($buffer_output); // Get the error message and line number if (preg_match("'syntax error, (.+) in .+ on line (\\d+)\$'s", $buffer_output, $error_data)) { $error_data[2] = (int) $error_data[2]; $error_data = $error_data[2] <= $braces ? array_slice($error_data, 1) : array('unexpected $end' . substr($error_data[1], 14), $braces); } $error_data['raw_output'] = $buffer_output; $result = array('syntax error', $error_data); } else { ob_end_clean(); $result = true; } @ini_set('display_errors', $prev_ini_display_errors); @ini_set('log_errors', $prev_ini_log_errors); return $result; }
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; }
protected function afterDelete() { if ($this['component_id']) { if (self::getSqlTypeByType($this->data['type'])) { try { fx::db()->query("ALTER TABLE `{{" . $this->getTable() . "}}` DROP COLUMN `" . $this['keyword'] . "`"); } catch (\Exception $e) { fx::log('Drop field exception', $e->getMessage()); } } } parent::afterDelete(); }
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; }
protected function makeTree($tokens) { $stack = array(); $root = $tokens[0]; while ($token = array_shift($tokens)) { if ($token->type == 'unknown') { $this->solveUnclosed($token, $tokens); } if (preg_match("~^else~", $token->name) && $token->type == 'single') { $token->type = 'open'; } switch ($token->type) { case 'open': if (count($stack) > 0) { end($stack)->addChild($token); } $stack[] = $token; break; case 'close': if ($token->name == 'if') { do { $closed_token = array_pop($stack); } while ($closed_token->name != 'if'); } else { $closed_token = array_pop($stack); if ($closed_token && $token->name != $closed_token->name) { fx::log('Wrong template node nesting', $token->dump(), $closed_token->dump()); } } if ($token->name == 'if' || $token->name == 'elseif') { // reading forward to check if there is nearby {elseif} / {else} tag $count_skipped = 0; foreach ($tokens as $next_token) { // skip empty tokens if ($next_token->isEmpty()) { $count_skipped++; continue; } if ($next_token->type != 'close' && ($next_token->name == 'elseif' || $next_token->name == 'else')) { $next_token->stack_extra = true; $stack[] = $closed_token; foreach (range(1, $count_skipped) as $skip) { array_shift($tokens); } } break; } } if ($token->name == 'template' && $closed_token->name == 'template') { $this->templateToEach($closed_token); } if ($closed_token->stack_extra) { array_pop($stack); } break; case 'single': default: $stack_last = end($stack); if (!$stack_last) { echo "Template error: stack empty, trying to add: "; echo "<pre>" . htmlspecialchars(print_r($token, 1)) . "</pre>"; die; } $stack_last->addChild($token); break; } } return $root; }
<?php use Floxim\Floxim\System\Fx as fx; // if request directs right to /floxim/index.php // e.g. admin interface // current dir /vendor/floxim/floxim/ //require_once(dirname(__FILE__) . '/../../../boot.php'); $boot = $_SERVER['DOCUMENT_ROOT'] . '/boot.php'; require_once $boot; register_shutdown_function(function () { if (!fx::env()->get('complete_ok')) { $ob_level = ob_get_level(); $res = ''; for ($i = 0; $i < $ob_level; $i++) { $res .= ob_get_clean(); } if (fx::config('dev.on')) { echo fx::page()->postProcess($res); } fx::log('down', $res, $_SERVER, $_POST); } }); $result = fx::router()->route(); if ($result) { $result = $result instanceof \Floxim\Floxim\System\Controller ? $result->process() : $result; if (fx::env('ajax')) { fx::page()->addAssetsAjax(); } echo $result; fx::complete(); }
protected function deleteContentTable() { try { $contents = fx::data($this['keyword'])->all(); foreach ($contents as $content) { $content->delete(); } } catch (\Exception $e) { fx::log('Delete content error:', $e->getMessage()); } $sql = "DROP TABLE `{{" . $this->getContentTable() . "}}`"; fx::db()->query($sql); }
public function makeTree($tokens) { $root = new HtmlToken(); $root->name = 'root'; $stack = array($root); $token_index = -1; while ($token = array_shift($tokens)) { $token_index++; switch ($token->type) { case 'open': if (count($stack) > 0) { end($stack)->addChild($token); } $stack[] = $token; break; case 'close': $closed_tag = array_pop($stack); if ($closed_tag->name != $token->name) { $start_offset = $closed_tag->offset[0]; $end_offset = $token->offset[0]; $start_line = mb_substr_count(mb_substr($this->_string, 0, $start_offset), "\n") + 1; $end_line = mb_substr_count(mb_substr($this->_string, 0, $end_offset), "\n") + 1; $msg = "HTML parser error: " . "start tag " . $closed_tag->source . " (line " . $start_line . ") " . "doesn't match end tag </" . $token->name . '> (line ' . $end_line . ')'; $e = new \Exception($msg); $e->html = $this->_string; throw $e; } if ($token->offset) { $closed_tag->end_offset = $token->offset; } break; case 'single': default: $stack_last = end($stack); if (!$stack_last) { fx::log("fx_template_html tree error", $tokens, $root); echo fx_debug("fx_template_html error: stack empty, trying to add: ", '#' . $token_index, $token, $tokens, $root); echo "fx_template_html error: stack empty, trying to add: "; echo "<pre>" . htmlspecialchars(print_r($token, 1)) . "</pre>"; die; } $stack_last->addChild($token); break; } } // in the stack should be kept only for the <root> if (count($stack) > 1) { fx::log("All closed, but stack not empty!", $stack); //die(); } return $root; }
public function saveVar($input) { $result = array(); if (isset($input['page_id'])) { fx::env('page_id', $input['page_id']); } $ib = fx::data('infoblock', $input['infoblock']['id']); if ($ib->isLayout()) { $root_ib = $ib->getRootInfoblock(); $ib_visual = $root_ib->getVisual(); } elseif ($visual_id = fx::dig($input, 'infoblock.visual_id')) { $ib_visual = fx::data('infoblock_visual', $visual_id); } else { $ib_visual = $ib->getVisual(); } // group vars by type to process content vars first // because we need content id for 'content-visual' vars on adding a new entity $vars = fx::collection($input['vars'])->apply(function ($v) { if ($v['var']['type'] == 'livesearch' && !$v['value']) { $v['value'] = array(); } })->group(function ($v) { return $v['var']['var_type']; }); $contents = fx::collection(); $new_entity = null; if (isset($input['new_entity_props'])) { $new_props = $input['new_entity_props']; $new_com = fx::component($new_props['type']); $new_entity = fx::content($new_props['type'])->create($new_props); $contents['new@' . $new_com['id']] = $new_entity; // we are working with linker and user pressed "add new" button to create linked entity if (isset($input['create_linked_entity'])) { $linked_entity_com = fx::component($input['create_linked_entity']); $linked_entity = fx::content($linked_entity_com['keyword'])->create(); $contents['new@' . $linked_entity_com['id']] = $linked_entity; // bind the new entity to the linker prop if (isset($new_props['_link_field'])) { $link_field = $new_com->getFieldByKeyword($new_props['_link_field'], true); $target_prop = $link_field['format']['prop_name']; $new_entity[$target_prop] = $linked_entity; } } } if (isset($vars['content'])) { $content_groups = $vars['content']->group(function ($v) { $vid = $v['var']['content_id']; if (!$vid) { $vid = 'new'; } return $vid . '@' . $v['var']['content_type_id']; }); foreach ($content_groups as $content_id_and_type => $content_vars) { list($content_id, $content_type_id) = explode("@", $content_id_and_type); if ($content_id !== 'new') { $c_content = fx::content($content_type_id, $content_id); if (!$c_content) { continue; } $contents[$content_id_and_type] = $c_content; } $vals = array(); foreach ($content_vars as $var) { $vals[$var['var']['name']] = $var['value']; } if (isset($contents[$content_id_and_type])) { $contents[$content_id_and_type]->setFieldValues($vals, array_keys($vals)); } else { fx::log('Content not found in group', $contents, $content_id, $vals); } } } $new_id = false; $result['saved_entities'] = array(); foreach ($contents as $cid => $c) { try { $c->save(); $result['saved_entities'][] = $c->get(); if ($cid == 'new') { $new_id = $c['id']; } } catch (\Exception $e) { $result['status'] = 'error'; if ($e instanceof \Floxim\Floxim\System\Exception\EntityValidation) { $result['errors'] = $e->toResponse(); } break; } } if (isset($vars['visual'])) { foreach ($vars['visual'] as $c_var) { $var = $c_var['var']; $value = $c_var['value']; $var['id'] = preg_replace("~\\#new_id\\#\$~", $new_id, $var['id']); $visual_set = $var['template_is_wrapper'] ? 'wrapper_visual' : 'template_visual'; if ($value == 'null') { $value = null; } $c_visual = $ib_visual[$visual_set]; if (!is_array($c_visual)) { $c_visual = array(); } if ($value == 'null') { unset($c_visual[$var['id']]); } else { $c_visual[$var['id']] = $value; } $ib_visual[$visual_set] = $c_visual; } $ib_visual->save(); } if (isset($vars['ib_param'])) { $modified_params = array(); foreach ($vars['ib_param'] as $c_var) { $var = $c_var['var']; $value = $c_var['value']; if (!isset($var['stored']) || $var['stored'] && $var['stored'] != 'false') { $ib->digSet('params.' . $var['name'], $value); } $modified_params[$var['name']] = $value; } if (count($modified_params) > 0) { $controller = $ib->initController(); $ib->save(); $controller->handleInfoblock('save', $ib, array('params' => $modified_params)); } } return $result; }