Example #1
0
 /**
  * Check user permissions and authentication
  */
 public function checkAuth()
 {
     $user = User::getInstance();
     $uid = false;
     if ($user->isAuthorized()) {
         $uid = $user->id;
     }
     if (!$uid) {
         if (Request::isAjax()) {
             Response::jsonError($this->_lang->MSG_AUTHORIZE);
         } else {
             $this->loginAction();
         }
     }
     /*
      * Check CSRF token
      */
     if ($this->_configFrontend->get('use_csrf_token') && Request::hasPost()) {
         $csrf = new Security_Csrf();
         $csrf->setOptions(array('lifetime' => $this->_configFrontend->get('use_csrf_token_lifetime'), 'cleanupLimit' => $this->_configFrontend->get('use_csrf_token_garbage_limit')));
         if (!$csrf->checkHeader() && !$csrf->checkPost()) {
             $this->_errorResponse($this->_lang->MSG_NEED_CSRF_TOKEN);
         }
     }
     $this->_user = $user;
 }
Example #2
0
 /**
  * Get Db Connection config
  * @param string $name
  * @throws Exception
  * @return Config_Abstract
  */
 public function getDbConfig($name)
 {
     $workMode = $this->_appConfig->get('development');
     if (!isset($this->_dbConfigs[$workMode][$name])) {
         $dbConfigPaths = $this->_appConfig->get('db_configs');
         if (!isset($dbConfigPaths[$workMode])) {
             throw new Exception('Invalid application work mode ' . $workMode);
         }
         $this->_dbConfigs[$workMode][$name] = Config::factory(Config::File_Array, $dbConfigPaths[$workMode]['dir'] . $name . '.php');
     }
     return $this->_dbConfigs[$workMode][$name];
 }
Example #3
0
 protected function _checkCanLock()
 {
     if ($this->_lock && !$this->_lock->launch(get_called_class() . '-' . $this->_config->get('thread'))) {
         return false;
     }
     return true;
 }
Example #4
0
 /**
  * Launch job  using file lock
  * console command ./console.php /console/[task]/[time limit]/[thread]
  * @param string $name
  * @param string $method
  */
 protected function _launchJob($name, $method = 'run')
 {
     $appCfg = $this->_configs->get($name);
     $time = Request::getInstance()->getPart(2);
     $thread = intval(Request::getInstance()->getPart(3));
     $appCfg['thread'] = $thread;
     if ($time) {
         $this->_cronConfig['time_limit'] = $time;
         $this->_cronConfig['intercept_timeout'] = $time;
     }
     $lock = new Cron_Lock($this->_cronConfig);
     if ($this->_log) {
         $lock->setLogsAdapter($this->_log);
     }
     $adapter = $appCfg['adapter'];
     $config = new Config_Simple($name . '_job');
     $config->setData($appCfg);
     $config->set('lock', $lock);
     $o = new $adapter($config);
     if (!$o->{$method}()) {
         $msg = '1 ' . $name . '_job' . ': error';
     } else {
         $msg = '0 ' . $name . '_job' . ': ' . $o->getStatString();
     }
     $this->_logMessage($msg);
     echo $msg . "\n";
     $lock->finish();
 }
Example #5
0
 /**
  * Show login form
  */
 protected function loginAction()
 {
     $template = new Template();
     $template->set('wwwRoot', $this->_configMain->get('wwwroot'));
     Response::put($template->render('./templates/system/' . $this->_configBackend->get('theme') . '/login.php'));
     Application::close();
 }
Example #6
0
 /**
  * Include required JavaScript files defined in the configuration file
  */
 public function includeScripts()
 {
     $resource = Resource::getInstance();
     $media = Model::factory('Medialib');
     $media->includeScripts();
     $includesPath = $this->configMain->get('configs') . 'js_inc_backend.php';
     $cfg = Config::factory(Config::File_Array, $includesPath);
     $resource->addJs('/js/lib/jquery.js', 0, true, 'head');
     if ($this->configMain->get('development')) {
         $resource->addJs('/js/lib/extjs4/ext-all-debug.js', 0, true, 'head');
     } else {
         $resource->addJs('/js/lib/extjs4/ext-all.js', 0, true, 'head');
     }
     $resource->addJs('/js/lang/' . $this->configMain['language'] . '.js', 1, true, 'head');
     $resource->addJs('/js/lib/extjs4/locale/ext-lang-' . $this->configMain['language'] . '.js', 2, true, 'head');
     $resource->addJs('/js/app/system/common.js', 3, false, 'head');
     $resource->addJs('/js/lib/extjs4/ext-theme-gray.js', 2);
     $resource->addCss('/js/lib/extjs4/resources/css/ext-all-gray.css');
     $resource->addCss('/templates/system/default/css/style.css');
     if ($cfg->getCount()) {
         $js = $cfg->get('js');
         if (!empty($js)) {
             foreach ($js as $file => $config) {
                 $resource->addJs($file, $config['order'], $config['minified']);
             }
         }
         $css = $cfg->get('css');
         if (!empty($css)) {
             foreach ($css as $file => $config) {
                 $resource->addCss($file, $config['order']);
             }
         }
     }
 }
Example #7
0
 /**
  * Check and fix config file, update old config structure
  */
 public function fixConfig()
 {
     $fields = array_keys($this->getFieldsConfig(false));
     $cfg =& $this->_config->dataLink();
     foreach ($fields as $name) {
         /*
          * config validation for links
          */
         if ($this->isLink($name)) {
             $v =& $cfg['fields'][$name];
             $isRequired = $this->isRequired($name);
             if ($this->isDictionaryLink($name)) {
                 $v['db_isNull'] = false;
                 if ($isRequired) {
                     $v['db_default'] = false;
                 } else {
                     $v['db_default'] = '';
                 }
             } elseif ($this->isObjectLink($name)) {
                 $v['db_isNull'] = (bool) (!$isRequired);
                 $v['db_type'] = 'bigint';
                 $v['db_default'] = false;
                 $v['db_unsigned'] = true;
             } elseif ($this->isMultiLink($name)) {
                 $v['db_type'] = 'longtext';
                 $v['db_isNull'] = false;
                 $v['db_default'] = '';
             }
         }
     }
     unset($v);
     unset($cfg);
 }
Example #8
0
 /**
  * Save changes
  * @return boolean
  */
 public function saveChanges()
 {
     if (!$this->_data->save()) {
         return false;
     }
     $dm = new Dictionary_Manager();
     $dm->resetCache();
     return true;
 }
Example #9
0
 public function __construct($name)
 {
     parent::__construct($name);
     /*
      * Read config from file
      */
     $data = $this->_readFile($name);
     if (is_array($data)) {
         $this->_data = $data;
     } else {
         $this->_data = array();
     }
 }
Example #10
0
 public function migrateLocale()
 {
     $langDictionary = Dictionary::getInstance('sysdocs_language');
     $langs = $langDictionary->getData();
     $fields = $this->config->get('fields');
     foreach ($langs as $k => $v) {
         foreach ($fields as $class => $cfg) {
             $t = microtime(true);
             $this->output('Migrate localization...' . $class . ' ' . $k);
             $this->migrateRecords($class, $this->vers, $k, $cfg);
             $this->output('OK ' . number_format(microtime(true) - $t, 3) . 's.');
         }
     }
 }
Example #11
0
 protected function _initExternals()
 {
     $eExpert = $this->_getExternalsExpert();
     if (!$eExpert->hasExternals()) {
         return;
     }
     /*
      * Register external classes
      */
     $classes = $eExpert->getClasses();
     if (!empty($classes)) {
         $this->_autoloader->addMap($classes);
     }
     /*
      * Register external objects
      */
     $objects = $eExpert->getObjects();
     if (!empty($objects)) {
         Db_Object_Config::registerConfigs($objects);
     }
     $curLang = $this->_config->get('language');
     /*
      * Register external translations
      */
     $translations = $eExpert->getTranslations($curLang);
     if (!empty($translations)) {
         Db_Object_Config::getTranslator()->addTranslations($translations);
     }
     $dictionaries = $eExpert->getDictionaries();
     if (!empty($dictionaries)) {
         Dictionary::addExternal($dictionaries);
     }
     $langs = $eExpert->getLangs($curLang);
     if (!empty($langs)) {
         foreach ($langs as $name => $path) {
             Lang::addDictionaryLoader($name, $path, Config::File_Array);
         }
     }
     /*
      * Inject Externals Expert
      */
     $page = Page::getInstance()->setExternalsExpert($eExpert);
 }
Example #12
0
 /**
  * Get localization config
  * @param string $dictionary
  * @return array
  */
 public function getLocalistaion($dictionary)
 {
     $dFile = $this->_appConfig->get('lang_path') . $dictionary . '.php';
     $dictionaryData = array();
     if (file_exists($dFile)) {
         $dictionaryData = (include $dFile);
         if (!is_array($dictionaryData)) {
             $dictionaryData = array();
         }
     }
     if (strpos($dictionary, '/') !== false) {
         $index = $this->getIndex($dictionary);
     } else {
         $index = $this->getIndex();
     }
     if (!is_array($index)) {
         return array();
     }
     $keys = array_keys($dictionaryData);
     $newKeys = array_diff($keys, $index);
     $result = array();
     foreach ($index as $dKey) {
         $value = '';
         $sync = true;
         if (isset($dictionaryData[$dKey])) {
             $value = $dictionaryData[$dKey];
         } else {
             $sync = false;
         }
         $result[] = array('id' => $dKey, 'key' => $dKey, 'title' => $value, 'sync' => $sync);
     }
     if (!empty($newKeys)) {
         foreach ($newKeys as $key) {
             $result[] = array('id' => $key, 'key' => $key, 'title' => $dictionaryData[$key], 'sync' => true);
         }
     }
     return $result;
 }
Example #13
0
 /**
  * Get configuration of code templates (for replacing)
  * @return array
  */
 public function getReplaceConfig()
 {
     $templates = $this->_designerConfig->get('templates');
     return array(array('tpl' => $templates['wwwroot'], 'value' => $this->_appConfig->get('wwwroot')), array('tpl' => $templates['adminpath'], 'value' => $this->_appConfig->get('adminPath')), array('tpl' => $templates['urldelimiter'], 'value' => $this->_appConfig->get('urlDelimiter')));
 }
Example #14
0
    public function addGridMethods(Designer_Project $project, Ext_Object $grid, $object, $vc = false)
    {
        $methodsManager = $project->getMethodManager();
        $m = $methodsManager->addMethod($grid->getName(), 'initComponent', array(), '
            this.addDesignerItems();
            this.callParent();

            if(!Ext.isEmpty(this.canEdit) && !Ext.isEmpty(this.setCanEdit)){
                this.setCanEdit(this.canEdit);
            }else{
                this.canEdit = false;
            }

            if(!Ext.isEmpty(this.canDelete) && !Ext.isEmpty(this.setCanDelete)){
                this.setCanDelete(this.canDelete);
            }else{
                this.canDelete = false;
            }

            if(!Ext.isEmpty(this.canPublish) && !Ext.isEmpty(this.setCanPublish)){
                this.setCanPublish(this.canPublish);
            }else{
                this.canPublish = false;
            }
        ');
        $urlTemplates = $this->designerConfig->get('templates');
        $deleteUrl = Request::url(array($urlTemplates['adminpath'], $object, 'delete'));
        $m = $methodsManager->addMethod($grid->getName(), 'deleteRecord', array(array('name' => 'record', 'type' => 'Ext.data.record')), '
            Ext.Ajax.request({
                url:"' . $deleteUrl . '",
                method: "post",
                scope:this,
                params:{
                    id: record.get("id")
                },
                success: function(response, request) {
                    response =  Ext.JSON.decode(response.responseText);
                    if(response.success){
                        this.getStore().remove(record);
                    }else{
                        Ext.Msg.alert(appLang.MESSAGE , response.msg);
                    }
                },
                failure:function(){
                    Ext.Msg.alert(appLang.MESSAGE, appLang.MSG_LOST_CONNECTION);
                }
		    });
          ');
        $m->setDescription('Delete record');
        $m = $methodsManager->addMethod($grid->getName(), 'setCanEdit', array(array('name' => 'canEdit', 'type' => 'boolean')), '
        this.canEdit = canEdit;
        if(canEdit){
          this.childObjects.addButton.show();
        }else{
          this.childObjects.addButton.hide();
        }
        this.getView().refresh();
    ');
        $m->setDescription('Set edit permission');
        $m = $methodsManager->addMethod($grid->getName(), 'setCanDelete', array(array('name' => 'canDelete', 'type' => 'boolean')), ' this.canDelete = canDelete;');
        $m->setDescription('Set delete permission');
        if ($vc) {
            $m = $methodsManager->addMethod($grid->getName(), 'setCanPublish', array(array('name' => 'canPublish', 'type' => 'boolean')), 'this.canPublish = canPublish;');
            $m->setDescription('Set publish permission');
        }
        $editCode = '
        var win = Ext.create("' . $project->namespace . '.editWindow", {
  		          dataItemId:id,
  		          canDelete:this.canDelete,';
        if ($vc) {
            $editCode .= '
                  canPublish:this.canPublish,';
        }
        $editCode .= 'canEdit:this.canEdit';
        $editCode .= '
  		    });

            win.on("dataSaved",function(){
                this.getStore().load();
              ';
        if (!$vc) {
            $editCode .= 'win.close();';
        }
        $editCode .= '},this);

            win.show();
    ';
        $m = $methodsManager->addMethod($grid->getName(), 'showEditWindow', array(array('name' => 'id', 'type' => 'integer')), $editCode);
        $m->setDescription('Show editor window');
    }