示例#1
0
 private function _handleImportKbArticle($xml)
 {
     static $categoryList = NULL;
     static $categoryMap = NULL;
     $title = (string) $xml->title;
     $created = intval((string) $xml->created_date);
     $content_b64 = (string) $xml->content;
     // Bad file
     if (empty($content_b64) || empty($title)) {
         return false;
     }
     if (NULL == $categoryMap || NULL == $categoryList) {
         $categoryList = DAO_KbCategory::getWhere();
         $categoryMap = DAO_KbCategory::getTreeMap();
     }
     // Handle multiple <categories> elements
     $categoryIds = array();
     foreach ($xml->categories as $eCategories) {
         $pid = 0;
         $ptr =& $categoryMap[$pid];
         $categoryId = 0;
         foreach ($eCategories->category as $eCategory) {
             $catName = (string) $eCategory;
             //			echo "Looking for '", $catName, "' under $pid ...<br>";
             if (NULL == ($categoryId = $this->_getCategoryChildByName($categoryList, $ptr, $catName))) {
                 $fields = array(DAO_KbCategory::NAME => $catName, DAO_KbCategory::PARENT_ID => $pid);
                 $categoryId = DAO_KbCategory::create($fields);
                 //				echo " - Not found, inserted as $categoryId<br>";
                 $categoryList[$categoryId] = DAO_KbCategory::get($categoryId);
                 if (!isset($categoryMap[$pid])) {
                     $categoryMap[$pid] = array();
                 }
                 $categoryMap[$pid][$categoryId] = 0;
                 $categoryMap[$categoryId] = array();
                 $categoryIds[] = $categoryId;
             } else {
                 $categoryIds[] = $categoryId;
                 //				echo " - Found at $categoryId !<br>";
             }
             $pid = $categoryId;
             $ptr =& $categoryMap[$categoryId];
         }
     }
     // Decode content
     $content = base64_decode($content_b64);
     // [TODO] Dupe check?  (title in category)
     $fields = array(DAO_KbArticle::TITLE => $title, DAO_KbArticle::UPDATED => $created, DAO_KbArticle::FORMAT => 1, DAO_KbArticle::CONTENT_RAW => $content, DAO_KbArticle::CONTENT => $content, DAO_KbArticle::VIEWS => 0);
     if (null !== ($articleId = DAO_KbArticle::create($fields))) {
         DAO_KbArticle::setCategories($articleId, $categoryIds, false);
         return true;
     }
     return false;
 }
示例#2
0
文件: App.php 项目: rmiddle/cerb4
 function showKbCategoryEditPanelAction()
 {
     $active_worker = CerberusApplication::getActiveWorker();
     if (!$active_worker->hasPriv('core.kb.categories.modify')) {
         return;
     }
     @($id = DevblocksPlatform::importGPC($_REQUEST['id']));
     @($root_id = DevblocksPlatform::importGPC($_REQUEST['root_id']));
     @($return = DevblocksPlatform::importGPC($_REQUEST['return']));
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->cache_lifetime = "0";
     $tpl->assign('path', $this->_TPL_PATH);
     $tpl->assign('root_id', $root_id);
     $tpl->assign('return', $return);
     if (!empty($id)) {
         $category = DAO_KbCategory::get($id);
         $tpl->assign('category', $category);
     }
     /*
      * [TODO] Remove the current category + descendents from the categories, 
      * so the worker can't create a closed subtree (e.g. category's parent is its child)
      */
     $categories = DAO_KbCategory::getWhere();
     $tpl->assign('categories', $categories);
     $levels = DAO_KbCategory::getTree(0);
     //$root_id
     $tpl->assign('levels', $levels);
     $tpl->display('file:' . $this->_TPL_PATH . 'ajax/subcategory_edit_panel.tpl');
 }