Exemplo n.º 1
0
    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;
    }
Exemplo n.º 2
0
 public function __construct($params = null, $data = array())
 {
     $this->data = $data;
     $this->mailer = new \PHPMailer();
     $this->mailer->CharSet = 'utf-8';
     if (!is_array($params)) {
         $params = array();
     }
     if (!isset($params['from'])) {
         $from = fx::config('mail.from');
         if (!$from) {
             $from = 'noreply@' . fx::env('host');
         }
         $params['from'] = $from;
     }
     foreach (array('host', 'password', 'user', 'port') as $smtp_prop) {
         if (!isset($params['smtp_' . $smtp_prop]) && ($conf_prop = fx::config('mail.smtp_' . $smtp_prop))) {
             $params['smtp_' . $smtp_prop] = $conf_prop;
         }
     }
     $this->setParams($params);
 }
Exemplo n.º 3
0
 /**
  * Импорт контента из каталога в узел дерева
  *
  * @param $dir
  * @param $pageInsert
  */
 public function importContentFromDir($pageInsert, $dir)
 {
     $this->currentDir = $dir = fx::path('@files/export/');
     /**
      * Проверим страницу назначение на существование
      * Если null - это экспорт всего сайта
      */
     if ($pageInsert) {
         if (!($this->contentRootNew = fx::data('floxim.main.content', $pageInsert))) {
             throw new \Exception("Content by ID ({$pageInsert}) not found");
         }
     }
     /**
      * Определяем текущий сайт
      */
     if (!$this->siteNew and !($this->siteNew = fx::env()->getSite())) {
         throw new \Exception("Not defined current site");
     }
     /**
      * Получаем мета информацию импорта
      */
     if (!$this->readMetaInfo($dir)) {
         throw new \Exception("Can't read meta info");
     }
     if (!$pageInsert and $this->metaInfo['export_type'] != 'site' or $pageInsert and $this->metaInfo['export_type'] != 'content') {
         throw new \Exception("Неверный тип у источника импорта: " . $this->metaInfo['export_type']);
     }
     $this->pathRelDataDb = $this->metaInfo['paths']['data_db'];
     $this->pathRelDataFile = $this->metaInfo['paths']['data_file'];
     /**
      * Генерируем уникальный ключ для идентификации импорта в таблице временных данных
      */
     $this->generateKey();
     /**
      * Импортируем все модули с компонентами
      */
     $this->importModules($dir);
     /**
      * Предварительно загружаем все данные БД во временную таблицу
      */
     if (!$this->checkTmpTableExists()) {
         throw new \Exception("Not found import tmp table {$this->tmpTable}");
     }
     $this->loadAllDataToTmpTable($dir);
     $_this = $this;
     /**
      * Получаем старый корневой узел
      */
     $itemTmp = $this->getTmpRowContent($this->metaInfo['content_root_id']);
     $this->contentRootOld = $itemTmp['data'];
     /**
      * Импортируем системные данные
      */
     $this->readTmpDataTable(array(array('component_type', 'system')), function ($item) use($_this) {
         $_this->insertSystemItem($item);
     });
     /**
      * Импортируем данные контента
      */
     $this->readTmpDataTable(array(array('component_type', 'content')), function ($item) use($_this) {
         $_this->insertContentItem($item);
     });
     /**
      * Запускаем отложенные коллбэки
      */
     $this->runCallbacksIdUpdate();
     /**
      * Удаляем из таблицы временные данные
      */
     $this->removeDataFromTmpTable();
 }
Exemplo n.º 4
0
 public function offsetGet($offset)
 {
     if ($offset === 'id') {
         return isset($this->data['id']) ? $this->data['id'] : null;
     }
     // handle template-content vars like $item['%description']
     if ($offset[0] === '%') {
         $offset = mb_substr($offset, 1);
         if (!isset($this[$offset]) || $this->allowTemplateOverride) {
             $template = fx::env()->getCurrentTemplate();
             if ($template && $template instanceof Template\Template) {
                 $template_value = $template->v($offset . "_" . $this['id']);
                 if ($template_value) {
                     return $template_value;
                 }
             }
         }
     }
     $offset_type = null;
     $offsets = $this->getAvailableOffsets();
     if (isset($offsets[$offset])) {
         $offset_meta = $offsets[$offset];
         $offset_type = $offset_meta['type'];
     }
     // execute getter everytime
     if ($offset_type === self::OFFSET_GETTER) {
         return call_user_func(array($this, $offset_meta['method']));
     }
     // execute external callback
     if ($offset_type === self::OFFSET_CALLBACK) {
         return call_user_func($offset_meta['callback'], $this);
     }
     // we have stored value, so return it
     if (array_key_exists($offset, $this->data)) {
         return $this->data[$offset];
     }
     // multi-lang value
     if ($offset_type === self::OFFSET_LANG) {
         $lang_offset = $offset . '_' . fx::config('lang.admin');
         if (!empty($this->data[$lang_offset])) {
             return $this->data[$lang_offset];
         }
         return $this->data[$offset . '_en'];
     }
     // relation lazy-loading
     if ($offset_type === self::OFFSET_RELATION) {
         $finder = $this->getFinder();
         $finder->addRelated($offset, new Collection(array($this)));
         if (!isset($this->data[$offset])) {
             return null;
         }
         return $this->data[$offset];
     }
     if ($offset_type === self::OFFSET_SELECT) {
         $real_value = $this->data[$offset_meta['real_offset']];
         return $offset_meta['values'][$real_value];
     }
 }
Exemplo n.º 5
0
 public static function cdebug()
 {
     if (fx::env('console') !== true) {
         return;
     }
     call_user_func_array('fx::debug', func_get_args());
 }
Exemplo n.º 6
0
 /**
  * 
  */
 public function dumpSiteData($site_id = null, $target_file = null)
 {
     if (is_null($site_id)) {
         $site_id = fx::env('site_id');
     }
     if (is_null($target_file)) {
         $dir = '@files/export/site_' . $site_id;
         fx::files()->mkdir($dir);
         $target_file = fx::path()->abs($dir . '/data.sql');
     }
     // export the site
     fx::db()->dump(array('tables' => array('site'), 'where' => 'id = ' . $site_id, 'schema' => false, 'file' => $target_file));
     // export infoblocks
     fx::db()->dump(array('tables' => array('infoblock'), 'where' => 'site_id = ' . $site_id, 'schema' => false, 'file' => $target_file, 'add' => true));
     // export URL aliases
     fx::db()->dump(array('tables' => array('url_alias'), 'where' => 'site_id = ' . $site_id, 'schema' => false, 'file' => $target_file, 'add' => true));
     // export infoblock_visual
     $infoblock_ids = fx::data('infoblock')->where('site_id', $site_id)->all()->getValues('id');
     fx::db()->dump(array('tables' => array('infoblock_visual'), 'where' => 'infoblock_id IN (' . join(", ", $infoblock_ids) . ')', 'schema' => false, 'file' => $target_file, 'add' => true));
     // export main content table
     fx::db()->dump(array('tables' => array('floxim_main_content'), 'where' => 'site_id  = ' . $site_id, 'schema' => false, 'file' => $target_file, 'add' => true));
     // get existing content items
     $items = fx::db()->getResults('select id, type from {{floxim_main_content}} where site_id = ' . $site_id);
     $tables = $this->getContentDumpTables(fx::collection($items));
     foreach ($tables as $t => $item_ids) {
         if ($t === 'floxim_main_content') {
             continue;
         }
         // export content table
         fx::db()->dump(array('tables' => array($t), 'where' => 'id IN (' . join(',', $item_ids) . ')', 'schema' => false, 'file' => $target_file, 'add' => true));
     }
 }
Exemplo n.º 7
0
<?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());
    }
}
Exemplo n.º 8
0
 protected static function getLayoutPreviewCookieName($site_id = null)
 {
     if (!$site_id) {
         $site_id = fx::env('site_id');
     }
     return 'fx_layout_preview_' . $site_id;
 }
Exemplo n.º 9
0
 public function postProcess($buffer)
 {
     $r = '';
     if (isset($this->metatags['seo_title'])) {
         $r = "<title>" . strip_tags($this->metatags['seo_title']) . "</title>" . PHP_EOL;
     }
     if (isset($this->metatags['seo_description'])) {
         $r .= '<meta name="description" content="' . strip_tags($this->metatags['seo_description']) . '" />' . PHP_EOL;
     }
     if (isset($this->metatags['seo_keywords'])) {
         $r .= '<meta name="keywords" content="' . strip_tags($this->metatags['seo_keywords']) . '" />' . PHP_EOL;
     }
     $r .= $this->getAssetsCode();
     if (!preg_match("~<head(\\s[^>]*?|)>~i", $buffer)) {
         if (preg_match("~<html[^>]*?>~i", $buffer)) {
             $buffer = preg_replace("~<html[^>]*?>~i", '$0<head> </head>', $buffer);
         } else {
             $buffer = '<html><head> </head>' . $buffer . '</html>';
         }
     }
     //$buffer = preg_replace("~<head(\s[^>]*?|)>~", '$0'.$r, $buffer);
     $buffer = preg_replace("~<title>.+</title>~i", '', $buffer);
     $buffer = preg_replace("~</head\\s*?>~i", $r . '$0', $buffer);
     if (count($this->after_body)) {
         $after_body = $this->after_body;
         $buffer = preg_replace_callback('~<body[^>]*?>~i', function ($body) use($after_body) {
             return $body[0] . join("\r\n", $after_body);
         }, $buffer);
     }
     $buffer = str_replace("<body", "<body data-fx_page_id='" . fx::env('page_id') . "'", $buffer);
     if (fx::isAdmin()) {
         $js = '<script type="text/javascript">' . PHP_EOL;
         if ($js_text = $this->getJsText()) {
             $js .= join(PHP_EOL, $js_text) . PHP_EOL;
         }
         $js .= '</script>' . PHP_EOL;
         $buffer = str_replace('</body>', $js . '</body>', $buffer);
     }
     return $buffer;
 }
Exemplo n.º 10
0
 /**
  * Print args to the output
  */
 public function debug()
 {
     $e = call_user_func_array(array($this, 'entry'), func_get_args());
     $this->printEntry($e);
     static $head_files_added = false;
     if (!$head_files_added) {
         fx::page()->addCssFile(fx::path('@floxim/Admin/style/debug.less'));
         fx::page()->addJsFile(FX_JQUERY_PATH);
         fx::page()->addJsFile(fx::path('@floxim/Admin/js/fxj.js'));
         fx::page()->addJsFile(fx::path('@floxim/Admin/js/debug.js'));
         register_shutdown_function(function () {
             if (!fx::env()->get('complete_ok')) {
                 echo fx::page()->getAssetsCode();
             }
         });
         $head_files_added = true;
     }
 }
Exemplo n.º 11
0
<?php

require_once 'boot.php';
$result = fx::router()->route();
if (fx::env('ajax')) {
    fx::page()->addAssetsAjax();
}
echo $result;
fx::complete();