コード例 #1
0
ファイル: ZFrontModule.php プロジェクト: kimthangatm/zcms
 /**
  * Set default template
  */
 protected final function _setTemplateDefault()
 {
     $config = PDI::getDefault()->get('config');
     $cache = ZCache::getInstance('ZCMS_APPLICATION');
     $templateDefault = $cache->get('DEFAULT_TEMPLATE');
     if ($templateDefault === null) {
         /**
          * @var CoreTemplates $templateDefault
          */
         $templateDefault = CoreTemplates::findFirst('published = 1 AND location = \'frontend\'');
         $templateDefault = $templateDefault->base_name;
         $cache->save('DEFAULT_TEMPLATE', $templateDefault);
     }
     if ($templateDefault) {
         $config->frontendTemplate->defaultTemplate = $templateDefault;
         PDI::getDefault()->set('config', $config);
     }
 }
コード例 #2
0
ファイル: ZWidget.php プロジェクト: kimthangatm/zcms
 /**
  * Save widget
  *
  * @param $sidebar
  * @param integer $ordering
  * @param integer $id
  * @param mixed $newInstance
  * @param string $themeName
  * @return bool
  */
 public final function save($sidebar, $ordering = null, $id = null, $newInstance = null, $themeName = null)
 {
     $ordering = intval($ordering);
     if ($this->validation) {
         if (!$themeName) {
             /**
              * @var CoreTemplates $CoreTemplates
              */
             $CoreTemplates = CoreTemplates::findFirst("location = 'frontend' AND published = 1");
             $themeName = $CoreTemplates->base_name;
         }
         /**
          * @var CoreWidgetValues $CoreWidgetValues
          */
         if ((int) $id) {
             $CoreWidgetValues = CoreWidgetValues::findFirst($id);
         } else {
             $CoreWidgetValues = new CoreWidgetValues();
         }
         $CoreWidgetValues->reOder('sidebar_base_name = ?0', [0 => $sidebar]);
         $queryUp = "UPDATE core_widget_values SET ordering = ordering + 1 WHERE ordering >= {$ordering} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
         $queryDown = "UPDATE core_widget_values SET ordering = ordering - 1 WHERE ordering < {$ordering} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
         $this->db->execute($queryDown);
         $this->db->execute($queryUp);
         $CoreWidgetValues->sidebar_base_name = $sidebar;
         $CoreWidgetValues->theme_name = $themeName;
         $CoreWidgetValues->class_name = $this->_widget_name . '_Widget';
         $CoreWidgetValues->options = $this->_processOptions($id, $newInstance);
         $CoreWidgetValues->published = 1;
         $CoreWidgetValues->ordering = $ordering;
         $CoreWidgetValues->title = $this->_title;
         if ($CoreWidgetValues->save()) {
             //Do something
         } else {
             //Do something
         }
         $this->_id = $CoreWidgetValues->widget_value_id;
         $CoreWidgetValues->reOder('sidebar_base_name = ?0', [0 => $sidebar]);
         return true;
     }
     return false;
 }
コード例 #3
0
ファイル: CoreTemplates.php プロジェクト: kimthangatm/zcms
 /**
  * Set default template
  *
  * @param $base_name
  * @param $location
  * @return bool
  */
 public function setDefaultTemplate($base_name, $location)
 {
     if (!($location == 'frontend' || $location == 'backend')) {
         $this->getDI()->get('flashSession')->error('gb_location_template_must_be_backend_or_frontend');
         return false;
     }
     /**
      * @var CoreTemplates $defaultTemplate
      */
     $defaultTemplate = CoreTemplates::findFirst(['conditions' => "location = ?0 AND base_name = ?1", 'bind' => [$location, $base_name]]);
     if ($defaultTemplate) {
         $phql = "UPDATE ZCMS\\Core\\Models\\CoreTemplates SET published = 0 WHERE location = '{$location}'";
         if ($this->getDI()->get('modelsManager')->createQuery($phql)->execute()) {
             $defaultTemplate->published = 1;
             if ($defaultTemplate->save()) {
                 file_put_contents(APP_DIR . "/" . $location . "/index.volt", '{% extends "../../../templates/' . $location . "/" . $base_name . '/index.volt" %}');
                 return true;
             }
         }
     }
     return false;
 }
コード例 #4
0
 /**
  * Update widget order
  *
  * @return PResponse
  * @throws Exception
  */
 public function updateWidgetOrderAction()
 {
     $response = new PResponse();
     $content = '';
     $response->setHeader("Content-Type", "application/json");
     if ($this->request->isAjax()) {
         $widget_id = $this->request->getPost('widget_id', 'int');
         $newIndex = $this->request->getPost('index', 'int');
         $sidebar = str_replace(' ', '', $this->request->getPost('sidebar_name', ['string', 'striptags']));
         if ($widget_id && $newIndex && $sidebar) {
             /**
              * @var CoreWidgetValues $widget
              */
             $widget = CoreWidgetValues::findFirst($widget_id);
             /**
              * @var CoreSidebars $CoreSidebars
              */
             $CoreSidebars = CoreSidebars::findFirst(['conditions' => 'sidebar_base_name = ?1', 'bind' => [1 => $sidebar]]);
             if ($widget && $CoreSidebars) {
                 /**
                  * @var CoreTemplates $defaultFrontendTemplate
                  */
                 $defaultFrontendTemplate = CoreTemplates::findFirst("location = 'frontend' AND published = 1");
                 $themeName = $defaultFrontendTemplate->base_name;
                 $widget->reOder('sidebar_base_name = ?1', [1 => $CoreSidebars->sidebar_base_name]);
                 $widget->reOder('sidebar_base_name = ?1', [1 => $widget->sidebar_base_name]);
                 if ($widget->ordering > $newIndex) {
                     $queryUp = "UPDATE core_widget_values SET ordering = ordering + 1 WHERE ordering >= {$newIndex} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
                     $queryDown = "UPDATE core_widget_values SET ordering = ordering - 1 WHERE ordering < {$newIndex} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
                 } elseif ($widget->ordering < $newIndex) {
                     $queryUp = "UPDATE core_widget_values SET ordering = ordering + 1 WHERE ordering > {$newIndex} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
                     $queryDown = "UPDATE core_widget_values SET ordering = ordering - 1 WHERE ordering <= {$newIndex} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
                 }
                 if (isset($queryUp) && isset($queryDown)) {
                     $this->db->execute($queryUp);
                     $this->db->execute($queryDown);
                 }
                 $widget->ordering = $newIndex;
                 $widget->sidebar_base_name = $CoreSidebars->sidebar_base_name;
                 if ($widget->save()) {
                     $content = '1';
                     $widget->reOder('sidebar_base_name = ?1', [1 => $sidebar]);
                     $widget->reOder('sidebar_base_name = ?1', [1 => $CoreSidebars->sidebar_base_name]);
                 } else {
                     //Do something
                 }
             }
         }
     }
     $response->setJsonContent($content);
     return $response;
 }
コード例 #5
0
ファイル: IndexController.php プロジェクト: kimthangatm/zcms
 /**
  * Published template
  *
  * @param int $id
  * @param string $redirect
  * @param bool $log
  * @return \Phalcon\Http\ResponseInterface|void
  */
 public function publishAction($id = null, $redirect = null, $log = true)
 {
     //Add template language
     $this->_addTemplateLang();
     $id = (int) $id;
     /**
      * @var CoreTemplates $templateMustPublish
      */
     $templateMustPublish = CoreTemplates::findFirst($id);
     if ($templateMustPublish) {
         $query = "UPDATE core_templates SET published = 0 WHERE location = '{$templateMustPublish->location}'";
         $this->db->execute($query);
         $templateMustPublish->published = 1;
         $templateMustPublish->save();
         file_put_contents(APP_DIR . '/' . $templateMustPublish->location . '/index.volt', '{% extends "../../../templates/' . $templateMustPublish->location . '/' . $templateMustPublish->base_name . '/index.volt" %}');
         if ($templateMustPublish->location == 'frontend') {
             //Do something
         } elseif ($templateMustPublish->location == 'backend') {
             //Do something
         }
         $this->flashSession->success(__('m_template_notice_template_is_active', ['1' => __($templateMustPublish->name), '2' => $templateMustPublish->location]));
     } else {
         $this->flashSession->error(__('m_template_notice_template_not_exists'));
     }
     return $this->response->redirect('/admin/template/');
 }