示例#1
0
文件: Add.php 项目: sinfocol/gwf3
 private function onAdd()
 {
     $form = $this->getForm();
     if (false !== ($errors = $form->validate($this->module))) {
         return $errors . $this->templateAdd();
     }
     $cat = new GWF_Category(array('cat_tree_id' => 0, 'cat_tree_key' => $form->getVar('key'), 'cat_tree_pid' => 0, 'cat_tree_left' => 0, 'cat_tree_right' => 0, 'cat_group' => $form->getVar('group')));
     if (false === $cat->insert()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)) . $this->templateAdd();
     }
     $cat->rebuildFullTree();
     return $this->module->message('msg_added');
 }
示例#2
0
 public static function validateCat($arg, $allowZero = true)
 {
     if ($arg == 0 && $allowZero || GWF_Category::categoryExists($arg)) {
         return false;
     }
     return GWF_Module::loadModuleDB('Cateogry', false, true)->lang('err_cat');
 }
示例#3
0
文件: Add.php 项目: sinfocol/gwf3
 public function validate_catid(Module_News $module, $catid)
 {
     $catid = (int) $catid;
     if ($catid === 0) {
         return false;
     }
     if (!GWF_Category::categoryExists($catid)) {
         return $this->module->lang('err_cat');
     }
     return false;
 }
示例#4
0
 /**
  * Create a PageMenu-GWF_Category
  * @return int ID
  */
 public static function createPageMenuCategory()
 {
     require_once GWF_CORE_PATH . 'module/Category/Module_Category.php';
     # TODO: get module...
     # TODO: isEnabled
     if (false === ($cat = GWF_Category::getByKey('PageMenu'))) {
         # TODO: Create GWF_Category: PageMenu
         return 0;
     }
     return $cat->getId();
 }
示例#5
0
文件: Show.php 项目: sinfocol/gwf3
 private function sanitize()
 {
     if (false === ($this->cat = GWF_Category::getByID(Common::getGet('catid', 0)))) {
         $this->catid = 0;
         $this->catTitle = GWF_HTML::lang('no_category');
     } else {
         $this->catid = $this->cat->getID();
         $this->catTitle = $this->cat->getTranslatedText();
     }
     $news = GDO::table('GWF_News');
     $catQuery = $this->catid === 0 ? '1' : "news_catid={$this->catid}";
     $hiddenQuery = "news_options&1=0";
     $condition = "({$catQuery}) AND ({$hiddenQuery})";
     $this->numNews = $news->countRows($condition);
     $npp = $this->module->getNewsPerPage();
     $this->nPages = GWF_PageMenu::getPagecount($npp, $this->numNews);
     $this->page = intval(Common::clamp(Common::getGet('page', '1'), 1, $this->nPages));
 }
示例#6
0
 public static function getCategories()
 {
     $langid = GWF_Language::getCurrentID();
     $back = array();
     foreach (GDO::table(__CLASS__)->selectColumn('DISTINCT(`news_catid`)') as $catid) {
         if (false === ($cat = GWF_Category::getByID($catid))) {
             continue;
         }
         $cat->loadTranslations();
         $back[] = $cat->getTranslatedText($langid);
     }
     return $back;
 }
示例#7
0
文件: Edit.php 项目: sinfocol/gwf3
 public function onEdit(GWF_Category $cat)
 {
     $keyOld = $cat->getKey();
     $form = $this->getForm($cat);
     if (false !== ($error = $form->validate($this->module))) {
         return $error;
     }
     //		if ('' !== ($error = $form->validateVars(array('key', 'langid')))) {
     //			return $error;
     //		}
     // new translation
     $back = '';
     if (0 !== ($langid = (int) Common::getPost('langid', 0))) {
         $trans = Common::getPost('newtrans');
         if (false === $cat->saveTranslation($langid, $trans)) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
         $back .= $this->module->message('msg_trans_added', array(GWF_Language::getByID($langid)->display('lang_name'), GWF_HTML::display($keyOld), GWF_HTML::display($trans)));
     }
     // change key!
     $keyNew = $form->getVar('key');
     if ($keyOld !== $keyNew) {
         $cat->saveVar('key', $keyNew);
         $back .= $this->module->message('msg_new_key', array(GWF_HTML::display($keyOld), GWF_HTML::display($keyNew)));
     }
     # Change tree
     $parent = $form->getVar('parent', '0');
     $oldpar = $cat->getParentID();
     if ($oldpar !== $parent) {
         if (!$cat->saveVar('cat_tree_pid', $parent)) {
             $back .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         } else {
             $cat->rebuildFullTree();
             $back .= $this->module->message('msg_new_parent');
         }
     }
     if (!isset($_POST['trans']) || !is_array($_POST['trans'])) {
         $_POST['trans'] = array();
     }
     # update translation
     foreach ($_POST['trans'] as $langid => $textNew) {
         $textOld = $cat->getTranslation($langid);
         if ($textNew !== $textOld) {
             if (false === $cat->saveTranslation($langid, $textNew)) {
                 return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
             }
             $langname = GWF_Language::getByID($langid)->display('lang_name');
             $back .= $this->module->message('msg_trans_changed', array($langname, GWF_HTML::display($textNew)));
         }
     }
     return $back;
 }
示例#8
0
文件: Admin.php 项目: sinfocol/gwf3
 public function templateAdmin()
 {
     $tVars = array('cats' => GWF_Category::getAllCategoriesCached(), 'by' => 'catid', 'dir' => 'asc', 'sort_url' => '', 'url_new' => GWF_WEB_ROOT . 'category/add');
     return $this->module->templatePHP('admin.php', $tVars);
 }