Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 function saveArticleEditPanelAction()
 {
     $active_worker = CerberusApplication::getActiveWorker();
     if (!$active_worker->hasPriv('core.kb.articles.modify')) {
         return;
     }
     $translate = DevblocksPlatform::getTranslationService();
     @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0));
     @($do_delete = DevblocksPlatform::importGPC($_REQUEST['do_delete'], 'integer', 0));
     @($title = DevblocksPlatform::importGPC($_REQUEST['title'], 'string'));
     @($category_ids = DevblocksPlatform::importGPC($_REQUEST['category_ids'], 'array', array()));
     @($content_raw = DevblocksPlatform::importGPC($_REQUEST['content_raw'], 'string'));
     @($format = DevblocksPlatform::importGPC($_REQUEST['format'], 'integer', 0));
     if (!empty($id) && !empty($do_delete)) {
         // Delete
         DAO_KbArticle::delete($id);
     } else {
         // Create|Modify
         // Sanitize
         if ($format > 2 || $format < 0) {
             $format = 0;
         }
         if (empty($title)) {
             $title = '(' . $translate->_('kb_article.title') . ')';
         }
         switch ($format) {
             default:
             case 0:
                 // plaintext
                 $content_html = $content_raw;
                 break;
             case 1:
                 // HTML
                 $content_html = $content_raw;
                 break;
         }
         if (empty($id)) {
             // create
             $fields = array(DAO_KbArticle::TITLE => $title, DAO_KbArticle::FORMAT => $format, DAO_KbArticle::CONTENT_RAW => $content_raw, DAO_KbArticle::CONTENT => $content_html, DAO_KbArticle::UPDATED => time());
             $id = DAO_KbArticle::create($fields);
         } else {
             // update
             $fields = array(DAO_KbArticle::TITLE => $title, DAO_KbArticle::FORMAT => $format, DAO_KbArticle::CONTENT_RAW => $content_raw, DAO_KbArticle::CONTENT => $content_html, DAO_KbArticle::UPDATED => time());
             DAO_KbArticle::update($id, $fields);
         }
         DAO_KbArticle::setCategories($id, $category_ids, true);
     }
 }