Ejemplo n.º 1
0
 public function testDelete()
 {
     /* @var $object \fpcm\model\articles\article */
     $object = new fpcm\model\articles\article($GLOBALS['objectId']);
     $result = $object->delete();
     $this->assertTrue($result);
     if ($object->exists()) {
         $this->assertEquals(1, $object->getDeleted());
     } else {
         $this->assertFalse($object->exists());
     }
     $GLOBALS['objectId'] = null;
 }
Ejemplo n.º 2
0
 /**
  * Controller ausführen
  * @return boolean
  */
 public function process()
 {
     switch ($this->action) {
         case 'page':
             $page = $this->getRequestVar('page');
             if (is_null($page)) {
                 return;
             }
             $content = ' ' . $this->param . ' ' . $page;
             print $this->isUtf8 ? $content : utf8_decode($content);
             break;
         case 'title':
             if ($this->getRequestVar('module') != 'fpcm/article' || is_null($this->getRequestVar('id'))) {
                 return;
             }
             $article = new \fpcm\model\articles\article($this->getRequestVar('id'));
             $content = ' ' . $this->param . ' ' . $article->getTitle();
             print $this->isUtf8 ? $content : utf8_decode($content);
             break;
     }
 }
Ejemplo n.º 3
0
 public function import()
 {
     $items = $this->getItems();
     foreach ($items as $item) {
         if (!in_array(md5($item->guid), $this->feedIds)) {
             continue;
         }
         $article = new \fpcm\model\articles\article();
         $article->setTitle((string) $item->title);
         $article->setContent((string) $item->content);
         $article->setCreatetime(strtotime((string) $item->published));
         $article->setChangetime(time());
         $article->setChangeuser($this->session->getUserId());
         $article->setCreateuser($this->userId);
         $article->setCategories($this->categories);
         $res = $article->save();
         if ($res === false) {
             trigger_error("Error while import of article with title '{$article->getTitle()}'. Cancel import process.");
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Controller-Processing
  */
 public function process()
 {
     parent::process();
     $id = (int) $this->getRequestVar('id');
     $db = $this->initDatabase();
     if (!$db) {
         die('0');
     }
     $tmp1 = new \fpcm\model\files\tempfile(\fpcm\modules\nkorg\classicimporter\nkorgclassicimporter::mappingUser);
     $usermapping = $tmp1->getContent();
     $usermapping = json_decode($tmp1->getContent(), true);
     $tmp2 = new \fpcm\model\files\tempfile(\fpcm\modules\nkorg\classicimporter\nkorgclassicimporter::mappingCategories);
     $categorymapping = $tmp2->getContent();
     $categorymapping = json_decode($tmp2->getContent(), true);
     if ($tmp2->getFilesize() > 0 && !is_array($categorymapping) || $tmp1->getFilesize() > 0 && !is_array($usermapping)) {
         trigger_error('Unable to parse user or category mapping files');
         die('0');
     }
     $newspost = $db->fetch($db->select('newsposts', '*', "id = {$id}"));
     $article = new \fpcm\model\articles\article();
     $content = html_entity_decode(htmlspecialchars_decode(utf8_encode($newspost->content)));
     $search = array('/data/upload/', '/thumb_');
     $replace = array('/data/uploads/', '/thumbs/');
     $titel = html_entity_decode(htmlspecialchars_decode(utf8_encode($newspost->titel)));
     $article->setContent(str_replace($search, $replace, $content));
     $article->setTitle($titel);
     $article->setCreatetime($newspost->writtentime);
     $article->setChangetime($newspost->editedtime ? $newspost->editedtime : $newspost->writtentime);
     $article->setComments($newspost->comments_active);
     $article->setDeleted($newspost->is_deleted);
     $article->setDraft($newspost->ispreview);
     $article->setArchived($newspost->is_archived);
     $article->setPinned($newspost->is_pinned);
     if ($newspost->writtentime > time()) {
         $article->setPostponed(true);
     }
     $article->setCategories(array(1));
     $newcategories = array();
     $oldcategories = explode(';', $newspost->category);
     if (is_array($categorymapping)) {
         if (count($oldcategories)) {
             foreach ($oldcategories as $categorie) {
                 if (!isset($categorymapping[$categorie])) {
                     continue;
                 }
                 $newcategories[] = (int) $categorymapping[$categorie];
             }
         }
     } else {
         $categoryList = new \fpcm\model\categories\categoryList();
         $categories = $categoryList->getCategoriesAll();
         foreach ($oldcategories as $categorie) {
             if (!isset($categories[$categorie])) {
                 continue;
             }
             $newcategories[] = $categories[$categorie]->getId();
         }
     }
     if (count($newcategories)) {
         $article->setCategories($newcategories);
     }
     if (is_array($usermapping) && isset($usermapping[$newspost->author])) {
         $article->setCreateuser($usermapping[$newspost->author]);
         $article->setChangeuser($usermapping[$newspost->author]);
     } else {
         $article->setCreateuser($newspost->author);
         $article->setChangeuser($newspost->author);
     }
     $article->prepareDataSave(true);
     $newid = $article->save();
     if (!$newid) {
         trigger_error('Unable to import article with ID ' . $id . '! Skipping comments...');
         usleep(500000);
         die('0');
     }
     $id = $newid != $id ? $newid : $id;
     $comments = $db->fetch($db->select('comments', '*', "newsid = {$id}"), true);
     if (!count($comments)) {
         usleep(750000);
         die('1');
     }
     foreach ($comments as $comment) {
         $newcomment = new \fpcm\model\comments\comment();
         $newcomment->setName(utf8_encode(htmlspecialchars_decode($comment->author_name)));
         $newcomment->setEmail(utf8_encode(htmlspecialchars_decode($comment->author_email)));
         $newcomment->setWebsite(utf8_encode(htmlspecialchars_decode($comment->author_url)));
         $newcomment->setText(htmlspecialchars_decode(utf8_encode($comment->comment_text)));
         $newcomment->setCreatetime($comment->comment_time);
         $newcomment->setIpaddress($comment->ip);
         $newcomment->setChangeuser($this->session->getUserId());
         $newcomment->setChangetime(time());
         if ($comment->status == 2) {
             $newcomment->setApproved(0);
         } elseif ($comment->status == 1) {
             $newcomment->setPrivate(1);
         } else {
             $newcomment->setApproved(1);
         }
         $newcomment->setArticleid($id);
         $newcomment->save();
     }
     usleep(750000);
     die('1');
 }