public function getAll() { static $all_modules_data = false; if ($all_modules_data === false) { $all_modules_data = fx::collection(); $vendor_dirs = glob(fx::path('@module/*')); foreach ($vendor_dirs as $vendor_dir) { if (!is_dir($vendor_dir)) { continue; } $vendor_name = fx::path()->fileName($vendor_dir); $vendor_modules = glob($vendor_dir . '/*'); foreach ($vendor_modules as $mod_dir) { if (!is_dir($mod_dir)) { continue; } $module_name = fx::path()->fileName($mod_dir); //fx::debug($vendor_name.'/'.$module_name); $module = array('vendor' => $vendor_name, 'name' => $module_name); $module_class = $vendor_name . "\\" . $module_name . "\\Module"; if (class_exists($module_class)) { $module['object'] = new $module_class(); } $all_modules_data[] = $module; } } } return $all_modules_data; }
protected function up() { $content_com = fx::component('floxim.main.content'); fx::db()->query(array('insert into {{field}} ( `component_id` , `keyword` , `name_en` , `name_ru` , `type`) VALUES (%d, "type", "Type", "Тип", 1)', $content_com['id'])); fx::cache('meta')->flush(); }
public function execDown() { $name = $this->getName(); // check not exec run if (!($migration = fx::data('patch_migration')->where('name', $name)->one())) { return; } // exec $this->down(); // remove mark $migration->delete(); }
public function build($data) { $index_by_parent = array(); $children_key = $this->childrenKey; $linkers = isset($data->linkers) ? $data->linkers : null; if ($linkers) { $this->linkers = $linkers; } foreach ($data as $item) { if (in_array($item['id'], $this->extraRootIds)) { continue; } $pid = $item[$this->parentKey]; if (!isset($index_by_parent[$pid])) { $index_by_parent[$pid] = $this->fork(); $index_by_parent[$pid]->addFilter($this->parentKey, $pid); } $index_by_parent[$pid][] = $item; } $non_root = array(); foreach ($data as $item) { if (isset($index_by_parent[$item['id']])) { if (isset($item[$children_key]) && $item[$children_key] instanceof \Floxim\Floxim\System\Collection) { $item[$children_key]->concat($index_by_parent[$item['id']]); } else { $item[$children_key] = $index_by_parent[$item['id']]; } $non_root = array_merge($non_root, $index_by_parent[$item['id']]->getValues('id')); } elseif (!isset($item[$children_key])) { $item[$children_key] = fx::collection(); } } $final_data = array(); foreach ($data as $index => $item) { if (in_array($item['id'], $non_root)) { if ($linkers && isset($linkers[$index])) { unset($linkers[$index]); } continue; } $final_data[$index] = $item; } $this->data = $final_data; //$this->data = $data->findRemove('id', $non_root)->getData(); if ($this->count() > 0) { $first_item = $this->first(); $this->addFilter($this->parentKey, $first_item[$this->parentKey]); } }
public function attValueEnd($ch) { $this->c_quote = $this->att_quote; $c_val = $this->stack; $res = parent::attValueEnd($ch); if ($this->debug) { fx::debug($res === false, $c_val); } if ($res !== false) { $this->c_att['value'] = $c_val; $this->addAtt(); $this->stack = ''; } $this->c_quote = null; return $res; }
public function find($name) { $dir = fx::path('@floxim/update/migration'); // get migrations $migration_files = glob($dir . '/m*_' . $name . '.php'); if (!$migration_files) { return null; } foreach ($migration_files as $migration_file) { $info = pathinfo($migration_file); require_once $migration_file; $class_name = $info['filename']; $m = new $class_name(); return $m; } }
public function redirect($target_url, $status = 301) { if (fx::env('ajax')) { ob_start(); ?> <script type="text/javascript"> document.location.href = '<?php echo $target_url; ?> '; </script> <?php echo trim(ob_get_clean()); fx::complete(); die; } $this->status($status); header("Location: " . $target_url); fx::complete(); die; }
public function process($data) { $com_content_id = fx::component('floxim.main.content')->get('id'); $res = array(); foreach ($this->getFields() as $f) { $type = $f['type']; $field_keyword = $f['keyword']; if (!in_array($type, array('string', 'text'))) { continue; } if ($f['component_id'] === $com_content_id) { continue; } if ($field_keyword === 'keyword') { continue; } $prop_tpl = $this[$field_keyword]; $tpl_obj = fx::template()->virtual($prop_tpl); $tpl_obj->isAdmin(false); $res[$field_keyword] = $tpl_obj->render($data); } return $res; }
public static function decl($word, $number) { return fx::util()->getDeclensionByNumber($word, $number); }
public function getContentDumpTables($items) { $items = $items->group('type'); $tables = array(); foreach ($items as $com_keyword => $data) { $com = fx::component($com_keyword); $com_tables = $com->getAllTables(); foreach ($com_tables as $t) { if (!isset($tables[$t])) { $tables[$t] = array(); } $tables[$t] = array_merge($tables[$t], $data->getValues('id')); } } return $tables; }
public function makeTree($parent_field = 'parent_id', $children_field = 'nested', $id_field = 'id') { $index_by_parent = array(); foreach ($this as $item) { $pid = $item[$parent_field]; if (!isset($index_by_parent[$pid])) { $index_by_parent[$pid] = fx::collection(); $index_by_parent[$pid]->is_sortable = $this->is_sortable; } $index_by_parent[$pid][] = $item; } foreach ($this as $item) { if (isset($index_by_parent[$item[$id_field]])) { $item[$children_field] = $index_by_parent[$item[$id_field]]; $this->findRemove($id_field, $index_by_parent[$item[$id_field]]->getValues($id_field)); } else { $item[$children_field] = null; } } return $this; }
protected function up() { // create table fx::db()->query("\n CREATE TABLE IF NOT EXISTS {{option}} (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `keyword` varchar(255) NOT NULL,\n `name` varchar(255) NOT NULL,\n `value` text NOT NULL,\n `autoload` tinyint(1) NOT NULL DEFAULT '1',\n PRIMARY KEY (`id`),\n KEY `autoload` (`autoload`),\n KEY `keyword` (`keyword`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n "); }
protected function up() { fx::db()->query("\n INSERT INTO {{option}} (`id`, `keyword`, `name`, `value`, `autoload`) VALUES (NULL, 'fx.version', 'Current floxim version', '0.1.1', '1');\n "); }
protected function exportFile($fileRel) { $pathSource = fx::path($fileRel); $pathDist = $this->pathExportTmp . DIRECTORY_SEPARATOR . $this->pathRelDataFile . $fileRel; if (file_exists($pathSource) and !file_exists($pathDist)) { fx::files()->copy($pathSource, $pathDist); } }
public function handleInfoblock($callback, $infoblock, $params = array()) { $full_config = $this->getConfig(); $action = fx::util()->camelToUnderscore($this->action); if (!isset($full_config['actions'][$action])) { return; } $config = $full_config['actions'][$action]; if (!isset($config[$callback])) { return; } foreach ($config[$callback] as $c_callback) { if (is_callable($c_callback)) { call_user_func($c_callback, $infoblock, $this, $params); } } }
<?php // start microtime for debugger/profiler define('FX_START_MICROTIME', microtime(true)); // use realpath() to fix slashes in Windows // C:/domains/site -> C:\domains\site define("DOCUMENT_ROOT", realpath($_SERVER['DOCUMENT_ROOT'])); ini_set('memory_limit', '256m'); ini_set('display_errors', 'on'); error_reporting(255); // read config $config_file = DOCUMENT_ROOT . '/config.php'; if (!file_exists($config_file) || !($config_res = (include_once $config_file))) { header("Location: /install/"); die; } // Register Composer Auto Loader $loader = (require_once DOCUMENT_ROOT . '/vendor/autoload.php'); $loader->add('Floxim', DOCUMENT_ROOT . '/vendor'); // Register Floxim Auto Loader Floxim\Floxim\System\ClassLoader::register(); Floxim\Floxim\System\ClassLoader::addDirectories(array(DOCUMENT_ROOT . '/module')); // Register global short alias class_alias('\\Floxim\\Floxim\\System\\Fx', 'fx'); // Load config fx::load($config_res);
protected function up() { \fx::data('floxim.main.page')->all()->apply(function ($c) { $c->set('url', preg_replace("~^/~", '', $c['url']))->save(); }); }
public static function findThumbs($source_path) { $res = array(); $rel_path = fx::path()->http($source_path); $dir = glob(fx::path('@thumbs') . '/*'); if (!$dir) { return $res; } foreach ($dir as $sub) { if (is_dir($sub)) { $check_path = fx::path()->abs($sub . $rel_path); if (fx::path()->isFile($check_path)) { $res[] = $check_path; } } } return $res; }
public static function loadFullDataForCache() { $finder = new static(); static::prepareFullDataForCacheFinder($finder); $all = $finder->all(); $res = array(); foreach ($all as $item) { $res[$item['id']] = $item; } return fx::collection($res); }
<?php ini_set('display_errors', 'off'); try { require_once 'boot.php'; $result = fx::router()->route(); if (fx::env('ajax')) { $result = fx::page()->ajaxResponse($result); } echo $result; fx::complete(); } catch (\Exception $e) { fx::log($e, $e->getTraceAsString()); if (!fx::env('ajax') || fx::env('console')) { fx::debug($e, $e->getTraceAsString()); } }
<?php return array('actions' => array('*auth_form' => array('name' => fx::alang('Login form', 'floxim.main.user'), 'settings' => array('redirect_location_type' => array('label' => fx::alang('After login', 'floxim.main.user'), 'type' => 'select', 'values' => array(array('refresh', fx::alang('Refresh current page')), array('home', fx::alang('Redirect to homepage')), array('custom', fx::alang('Redirect to custom URL...')))), 'ajax' => array('type' => 'checkbox', 'label' => fx::alang('Use AJAX'), 'value' => 1), 'redirect_location_custom' => array('label' => fx::alang('Target URL'), 'type' => 'string', 'parent' => array('redirect_location_type' => 'custom')))), '*cross_site*' => array('disabled' => true), '*greet' => array('name' => fx::alang('Greet and logout widget', 'floxim.main.user')), '*recover_form' => array('name' => fx::alang('Recover password form', 'floxim.main.user')), '*form_create*' => array('name' => fx::alang('Registration form', 'floxim.main.user'), 'settings' => array('force_login' => array('type' => 'checkbox', 'label' => fx::alang('Login after registration'))))));
public function getAreaInfoblocks($area_id) { // do nothing if the areas are not loaded yet if (is_null($this->areas)) { return array(); } // or give them from cache if (isset($this->areas_cache[$area_id])) { return $this->areas_cache[$area_id]; } $area_blocks = isset($this->areas[$area_id]) ? $this->areas[$area_id] : array(); if (!$area_blocks || !(is_array($area_blocks) || $area_blocks instanceof \ArrayAccess)) { $area_blocks = array(); } $area_blocks = fx::collection($area_blocks)->sort(function ($a, $b) { $a_pos = $a->getPropInherited('visual.priority'); $b_pos = $b->getPropInherited('visual.priority'); return $a_pos - $b_pos; }); $area_blocks->findRemove(function ($ib) { return $ib->isDisabled(); }); $this->areas_cache[$area_id] = $area_blocks; return $area_blocks; }
public function offsetSet($offset, $value) { $offset_exists = array_key_exists($offset, $this->data); $offsets = $this->getAvailableOffsets(); $offset_type = null; if (isset($offsets[$offset])) { $offset_meta = $offsets[$offset]; $offset_type = $offset_meta['type']; } switch ($offset_type) { case self::OFFSET_LANG: $offset = $offset . '_' . fx::config('lang.admin'); break; case self::OFFSET_RELATION: $relation = $offset_meta['relation']; if ($relation[0] === Finder::BELONGS_TO && $value instanceof Entity) { $c_rel_field = $relation[2]; $value_id = $value['id']; if ($c_rel_field && $value_id) { $this[$c_rel_field] = $value_id; } } break; } if (!$this->is_loaded && $this->is_saved) { $this->data[$offset] = $value; return; } // use non-strict '==' because int values from db becomes strings - should be fixed if ($offset_exists && $this->data[$offset] == $value) { return; } if (!isset($this->modified_data[$offset])) { $this->modified_data[$offset] = isset($this->data[$offset]) ? $this->data[$offset] : null; $this->modified[] = $offset; } $this->data[$offset] = $value; }
public function dump($params) { $dump_path = fx::config('dev.mysqldump_path'); if (!$dump_path) { return; } if (is_string($params)) { $params = array('file' => $params); } if (!$params['file']) { return; } $target_file = fx::path($params['file']); $params = array_merge(array('data' => true, 'schema' => true, 'add' => false, 'where' => false, 'tables' => array()), $params); $command = $dump_path . ' -u' . fx::config('db.user') . ' -p' . fx::config('db.password') . ' --host=' . fx::config('db.host'); $command .= ' ' . fx::config('db.name'); if (!$params['schema']) { $command .= ' --no-create-info'; } if (!$params['data']) { $command .= ' --no-data'; } $command .= ' --skip-comments'; if ($params['where']) { $command .= ' --where="' . $params['where'] . '"'; } foreach ($params['tables'] as $t) { $command .= ' ' . $this->replacePrefix('{{' . $t . '}}'); } $do_gzip = isset($params['gzip']) && $params['gzip'] || preg_match("~\\.gz\$~", $target_file); if ($do_gzip) { $target_file = preg_replace("~\\.gz\$~", '', $target_file); } $command .= ($params['add'] ? ' >> ' : ' > ') . $target_file; exec($command); if ($do_gzip && file_exists($target_file)) { $gzipped_file = $target_file . '.gz'; $gzipped = gzopen($gzipped_file, 'w'); $raw = fopen($target_file, 'r'); while (!feof($raw)) { $s = fgets($raw, 4096); gzputs($gzipped, $s, 4096); } fclose($raw); gzclose($gzipped); unlink($target_file); return $gzipped_file; } }
protected function entry() { $c_time = microtime(true); $memory = memory_get_usage(true); $backtrace = array_slice(debug_backtrace(), 4, 2); $meta = array('time' => $c_time - $this->start_time, 'passed' => $c_time - $this->last_time, 'memory' => $memory); $this->last_time = $c_time; if (isset($backtrace[0]['file'])) { $meta['file'] = $backtrace[0]['file']; $meta['line'] = $backtrace[0]['line']; } $caller = ''; if (isset($backtrace[1])) { if (isset($backtrace[1]['class'])) { $caller = $backtrace[1]['class']; $caller .= $backtrace[1]['type']; } if (isset($backtrace[1]['function'])) { $caller .= $backtrace[1]['function']; } } $meta['caller'] = $caller; $args = func_get_args(); $items = array(); $light_mode = fx::config('dev.debug_light'); foreach ($args as $a) { $type = gettype($a); if ($type == 'array' || $type == 'object') { if ($light_mode) { $a = '[' . ($type === 'object' ? get_class($a) : $type) . ']'; } else { $a = print_r($a, 1); } } $items[] = array($type, $a); } return array($meta, $items); }
public function processTemplate() { if (!$this->mail_template) { return; } $tpl = $this->mail_template; $props = array('subject', 'message'); $res = array(); foreach ($props as $prop) { $prop_tpl = $tpl[$prop]; $tpl_obj = fx::template()->virtual($prop_tpl); $tpl_obj->isAdmin(false); $res[$prop] = $tpl_obj->render($this->data); } $this->subject($res['subject']); $this->message($res['message']); if ($tpl['from']) { $this->from($tpl['from']); } if ($tpl['bcc']) { $this->bcc($tpl['bcc']); } }
/** * Удаляет из временной таблицы текущие данные * * @throws \Exception */ protected function removeDataFromTmpTable() { if ($this->key) { fx::db()->query("delete from {{" . $this->tmpTable . "}} where `key` = '{$this->key}'"); } }
/** * Store params by keys in DB * * @param $keys */ public function store($keys) { if (!is_array($keys)) { $keys = array($keys); } foreach ($keys as $key) { if (!($option = fx::data('option')->where('keyword', $key)->one())) { $option = fx::data('option')->create(array('keyword' => $key)); } $option['value'] = $this->get($key); $option->save(); } }
public function GET_POST($item = "") { if (empty($this->_GET) && empty($this->_POST)) { return array(); } if ($item) { return array_key_exists($item, $this->_GET) ? fx::db()->escape($this->_GET[$item]) : (array_key_exists($item, $this->_POST) ? fx::db()->escape($this->_POST[$item]) : null); } $data = array_merge($this->_POST, $this->_GET); foreach ($data as $k => &$v) { $v = fx::db()->escape($v); } return $data; }
protected static function getLayoutPreviewCookieName($site_id = null) { if (!$site_id) { $site_id = fx::env('site_id'); } return 'fx_layout_preview_' . $site_id; }