public function generate($params = array()) { $form = $this->create($params); $form->is_generated = true; $form['fields'] = fx::collection(); return $form; }
public function getSavestring(System\Entity $content = null) { $old_value = $content[$this['keyword']]; $old_path = FX_BASE_URL . $old_value; if ($old_path === $this->value) { return $this->value; } $res = ''; if (!empty($this->value)) { $c_val = fx::path()->abs($this->value); if (file_exists($c_val) && is_file($c_val)) { $file_name = fx::path()->fileName($c_val); $path = fx::path('@content_files/' . $content['site_id'] . '/' . $content['type'] . '/' . $this['keyword'] . '/' . $file_name); $path = fx::files()->getPutFilePath($path); fx::files()->move($c_val, $path); $res = fx::path()->removeBase(fx::path()->http($path)); } } if (!empty($old_value)) { $old_value = fx::path()->abs($old_value); if (file_exists($old_value) && is_file($old_value)) { fx::files()->rm($old_value); } } return $res; }
public function route($url = null, $context = null) { $thumbs_path = fx::path()->http('@thumbs'); $thumbs_path_trimmed = fx::path()->removeBase($thumbs_path); if (substr($url, 0, strlen($thumbs_path_trimmed)) !== $thumbs_path_trimmed) { return null; } $dir = substr($url, strlen($thumbs_path_trimmed)); preg_match("~/([^/]+)(/.+\$)~", $dir, $parts); $config = $parts[1]; $source_path = $parts[2]; $source_abs = fx::path($source_path); if (!file_exists($source_abs)) { return null; } $target_dir = dirname(fx::path('@home/' . $url)); if (!file_exists($target_dir) || !is_dir($target_dir)) { return null; } $config = $config . '.async-false.output-true'; $config = \Floxim\Floxim\System\Thumb::readConfigFromPathString($config); fx::image($source_path, $config); fx::complete(); die; }
public function checkUpdates() { $stored = $this->all(); $url = fx::config('fx.update_url') . '?action=find&from=' . fx::version(); @($res = file_get_contents($url)); if (!$res) { return false; } $res = @json_decode($res); if ($res) { foreach ($res as $patch) { if ($stored->findOne('to', $patch->to)) { continue; } $new_patch = $this->create(array('to' => $patch->to, 'from' => $patch->from, 'url' => $patch->url, 'created' => $patch->created)); if ($patch->from == fx::version()) { $new_patch['status'] = 'ready'; } else { $new_patch['status'] = 'pending'; } $new_patch->save(); } } return true; }
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; }
public function run($args = null) { if (!$args) { $args = isset($_SERVER['argv']) ? $_SERVER['argv'] : array(__FILE__); } elseif (is_scalar($args)) { $arg_string = $args; $args = array(\Floxim\Floxim\System\Fx::path()->fileName(__FILE__)); foreach (self::parseArgs($arg_string) as $arg) { $args[] = $arg; } } $this->scriptName = $args[0]; array_shift($args); // Define command if (isset($args[0])) { $name = $args[0]; array_shift($args); } else { $name = 'help'; } // Create command if (!($command = $this->createCommand($name))) { $command = $this->createCommand('help'); } return $command->run($args); }
public function getSavestring(System\Entity $content = null) { $old_value = $content[$this['keyword']]; if ($old_value != $this->value) { if (!empty($old_value)) { $old_value = fx::path()->abs($old_value); if (file_exists($old_value) && is_file($old_value)) { fx::files()->rm($old_value); } } if (!empty($this->value)) { $c_val = fx::path()->abs($this->value); if (file_exists($c_val) && is_file($c_val)) { preg_match("~[^" . preg_quote(DIRECTORY_SEPARATOR) . ']+$~', $c_val, $fn); $path = fx::path()->http('@content_files/' . $content['site_id'] . '/' . $content['type'] . '/' . $this['keyword'] . '/' . $fn[0]); $try = 0; while (fx::path()->exists($path)) { $file_name = preg_replace("~(\\.[^\\.]+)\$~", "_" . $try . "\$1", $fn[0]); $try++; $path = fx::path()->http('@content_files/' . $content['type'] . '/' . $this['keyword'] . '/' . $file_name); } fx::files()->move($c_val, $path); } } } $res = isset($path) ? $path : $this->value; return $res; }
public function __construct($context, $box_id, $loop = null) { if (fx::isAdmin()) { self::addAdminAssets(); $this->avail = $this->getAvailFields($context); } $this->box_id = $box_id; $param_id = $this->getParamId(); $data = $context->get($param_id); if (is_string($data) && !empty($data)) { $data = json_decode($data, true); } //fx::log($this, $data); if (!$data || !isset($data['is_stored'])) { $groups = $context->get('groups'); $default_data = $this->prepareGroups($groups); $data = $data ? \Floxim\Floxim\System\Util::fullMerge($data, $default_data) : $default_data; } $this->data = $data; //fx::log('set data', $this->data); if ($loop) { $this->containing_loop = $loop; $box = $this; $loop->onStop(function () use($box) { $box->export(); }); } }
protected function getProfiler() { $profile = fx::config('dev.profile_controllers'); if ($profile) { return fx::profiler(); } }
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); }
protected function deleteInfoblocks() { $infoblocks = fx::data('infoblock')->where('site_id', $this['id'])->all(); foreach ($infoblocks as $infoblock) { $infoblock->delete(); } }
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; }
public static function checkValueIsFile($v) { if (empty($v)) { return false; } $files_path = fx::path('@files'); $path = fx::path(); return $path->isInside($v, $files_path) && $path->isFile($v); }
public function getDateFormats() { $formats = array('j %month:gen% Y', '%Month% Y', 'd.m.Y', 'd/m/Y', 'H:i'); $res = array(); foreach ($formats as $f) { $res[$f] = fx::date(time(), $f); } return $res; }
public function getBlocks() { $area_id = $this->getAreaId(); $blocks = fx::page()->getAreaInfoblocks($area_id); if (count($blocks) === 0) { return null; } return $blocks; }
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); } }
protected function getConfigSources() { $sources = array(); $c_name = $this->getControllerName(); $com_file = fx::path('@module/' . fx::getComponentPath($c_name) . '/cfg.php'); if (file_exists($com_file)) { $sources[] = $com_file; } return $sources; }
public function getEntityClassName($data) { $parts = explode('.', $data['keyword']); list($vendor, $module) = $parts; $class = fx::util()->underscoreToCamel($vendor) . "\\" . fx::util()->underscoreToCamel($module) . "\\Module"; if (class_exists($class)) { return $class; } return parent::getEntityClassName(); }
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; }
protected function showAdminPanel() { if (!fx::isAdmin()) { return; } // initialize the admin panel $p = fx::page(); $js_config = new Admin\Configjs(); $p->addJsText("\$fx.init(" . $js_config->getConfig() . ");"); $p->setAfterBody(Admin\Controller\Adminpanel::panelHtml()); }
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; }
protected function scaffold(\Floxim\Floxim\Component\Widget\Entity $com, $overwrite = false) { $source_path = fx::path('@floxim/Console/protected/widget'); $component_path = $com->getPath(); $file_list = $this->buildFileList($source_path, $component_path); foreach ($file_list as &$file_data) { $file_data['callback_content'] = function ($content) use($com) { return Widget::replacePlaceholder($content, $com); }; } $this->copyFiles($file_list); }
public function stop() { $session_key = fx::input()->fetchCookie($this->cookie_name); if (!$session_key) { return; } $this->setCookie(null, null); $session = $this->getByKey($session_key); if (!$session) { return; } $session->delete(); }
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(); } }
public function execute($input) { if ($input['console_text']) { ob_start(); $code = $input['console_text']; fx::env('console', true); fx::config('dev.on', true); $code = self::preProcess($code); eval($code); $res = ob_get_clean(); return array('result' => $res); } }
public function uploadSave($input) { $path = 'upload'; $result = fx::files()->saveFile($input['file'], $path); if (!$result) { $result = array('error_message' => 'Can not load this file'); fx::http()->status(500); } if (isset($input['format']) && !empty($input['format']) && isset($result['path'])) { $result['formatted_value'] = fx::image($result['path'], $input['format']); } return $result; }
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 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; }
public function offsetGet($offset) { if (!$this->is_generated || !in_array($offset, self::$editable_for_generated)) { return parent::offsetGet($offset); } $res = null; $template = fx::env()->getCurrentTemplate(); if ($template && ($context = $template->context)) { $res = $context->get('field_' . $this['name'] . '_' . $offset); } if ($res) { return $res; } return parent::offsetGet($offset); }
public function getPath($url, $site_id = null) { $url = fx::path()->removeBase($url); $url = preg_replace("~\\#.*\$~", '', $url); if (is_null($site_id)) { $site_id = fx::env('site_id'); } // @todo check if url contains another host name $url = preg_replace("~^https?://.+?/~", '/', $url); foreach ($this->routers as $rk => $r) { $result = $r['router']->getPath($url, $site_id); if ($result) { return $result; } } }