public function readData() { parent::readData(); VisitCountHandler::getInstance()->count(); WCF::getBreadcrumbs()->add(new Breadcrumb(WCF::getLanguage()->get('cms.page.news'), LinkHandler::getInstance()->getLink('NewsCategoryList', array('application' => 'cms')))); $this->commentObjectTypeID = CommentHandler::getInstance()->getObjectTypeID('de.codequake.cms.news.comment'); $this->commentManager = CommentHandler::getInstance()->getObjectType($this->commentObjectTypeID)->getProcessor(); $this->commentList = CommentHandler::getInstance()->getCommentList($this->commentManager, $this->commentObjectTypeID, $this->newsID); $newsEditor = new NewsEditor($this->news->getDecoratedObject()); $newsEditor->update(array('clicks' => $this->news->clicks + 1)); // get Tags if (MODULE_TAGGING) { $this->tags = $this->news->getTags(); } if ($this->news->teaser != '') { MetaTagHandler::getInstance()->addTag('description', 'description', $this->news->teaser); } else { MetaTagHandler::getInstance()->addTag('description', 'description', StringUtil::decodeHTML(StringUtil::stripHTML($this->news->getExcerpt()))); } if (!empty($this->tags)) { MetaTagHandler::getInstance()->addTag('keywords', 'keywords', implode(',', $this->tags)); } MetaTagHandler::getInstance()->addTag('og:title', 'og:title', $this->news->subject . ' - ' . WCF::getLanguage()->get(PAGE_TITLE), true); MetaTagHandler::getInstance()->addTag('og:url', 'og:url', LinkHandler::getInstance()->getLink('News', array('application' => 'cms', 'object' => $this->news->getDecoratedObject())), true); MetaTagHandler::getInstance()->addTag('og:type', 'og:type', 'article', true); if ($this->news->getImage() != null) { MetaTagHandler::getInstance()->addTag('og:image', 'og:image', $this->news->getImage()->getLink(), true); } if ($this->news->getUserProfile()->facebook != '') { MetaTagHandler::getInstance()->addTag('article:author', 'article:author', 'https://facebook.com/' . $this->news->getUserProfile()->facebook, true); } if (FACEBOOK_PUBLIC_KEY != '') { MetaTagHandler::getInstance()->addTag('fb:app_id', 'fb:app_id', FACEBOOK_PUBLIC_KEY, true); } MetaTagHandler::getInstance()->addTag('og:description', 'og:description', StringUtil::decodeHTML(StringUtil::stripHTML($this->news->getExcerpt())), true); if ($this->news->isNew()) { $newsAction = new NewsAction(array($this->news->getDecoratedObject()), 'markAsRead', array('viewableNews' => $this->news)); $newsAction->executeAction(); } // fetch likes if (MODULE_LIKE) { $objectType = LikeHandler::getInstance()->getObjectType('de.codequake.cms.likeableNews'); LikeHandler::getInstance()->loadLikeObjects($objectType, array($this->newsID)); $this->likeData = LikeHandler::getInstance()->getLikeObjects($objectType); } }
/** * @see \wcf\system\importer\IImporter::import() */ public function import($oldID, array $data, array $additionalData = array()) { $data['objectID'] = ImportHandler::getInstance()->getNewID('de.codequake.cms.news', $data['objectID']); if (!$data['objectID']) { return 0; } $attachmentID = parent::import($oldID, $data, $additionalData); if ($attachmentID && $attachmentID != $oldID) { // fix embedded attachments $news = new News($data['objectID']); if (($newMessage = $this->fixEmbeddedAttachments($news->message, $oldID, $attachmentID)) !== false) { $editor = new NewsEditor($news); $editor->update(array('message' => $newMessage)); } } return $attachmentID; }
public function create() { $data = $this->parameters['data']; // count attachments if (isset($this->parameters['attachmentHandler']) && $this->parameters['attachmentHandler'] !== null) { $data['attachments'] = count($this->parameters['attachmentHandler']); } if (LOG_IP_ADDRESS) { // add ip address if (!isset($data['ipAddress'])) { $data['ipAddress'] = WCF::getSession()->ipAddress; } } else { // do not track ip address if (isset($data['ipAddress'])) { unset($data['ipAddress']); } } $news = call_user_func(array($this->className, 'create'), $data); $newsEditor = new NewsEditor($news); // update attachments if (isset($this->parameters['attachmentHandler']) && $this->parameters['attachmentHandler'] !== null) { $this->parameters['attachmentHandler']->updateObjectID($news->newsID); } // handle categories $newsEditor->updateCategoryIDs($this->parameters['categoryIDs']); $newsEditor->setCategoryIDs($this->parameters['categoryIDs']); // langID != 0 $languageID = !isset($this->parameters['data']['languageID']) || $this->parameters['data']['languageID'] === null ? LanguageFactory::getInstance()->getDefaultLanguageID() : $this->parameters['data']['languageID']; // tags if (!empty($this->parameters['tags'])) { TagEngine::getInstance()->addObjectTags('de.codequake.cms.news', $news->newsID, $this->parameters['tags'], $languageID); } if (!$news->isDisabled) { // recent if ($news->userID !== null && $news->userID != 0) { UserActivityEventHandler::getInstance()->fireEvent('de.codequake.cms.news.recentActivityEvent', $news->newsID, $languageID, $news->userID, $news->time); UserActivityPointHandler::getInstance()->fireEvent('de.codequake.cms.activityPointEvent.news', $news->newsID, $news->userID); } // update search index SearchIndexManager::getInstance()->add('de.codequake.cms.news', $news->newsID, $news->message, $news->subject, $news->time, $news->userID, $news->username, $languageID); // reset storage UserStorageHandler::getInstance()->resetAll('cmsUnreadNews'); } return $news; }
public function save() { parent::save(); if ($this->time != '') { $dateTime = \DateTime::createFromFormat("Y-m-d H:i", $this->time, WCF::getUser()->getTimeZone()); } $data = array('languageID' => $this->languageID, 'subject' => $this->subject, 'time' => $this->time != '' ? $dateTime->getTimestamp() : TIME_NOW, 'teaser' => $this->teaser, 'message' => $this->text, 'userID' => WCF::getUser()->userID, 'username' => WCF::getUser()->username, 'isDisabled' => $this->time != '' && $dateTime->getTimestamp() > TIME_NOW ? 1 : 0, 'enableBBCodes' => $this->enableBBCodes, 'showSignature' => $this->showSignature, 'enableHtml' => $this->enableHtml, 'enableSmilies' => $this->enableSmilies, 'imageID' => $this->imageID ?: null, 'lastChangeTime' => TIME_NOW); $newsData = array('data' => $data, 'tags' => array(), 'attachmentHandler' => $this->attachmentHandler, 'categoryIDs' => $this->categoryIDs); $newsData['tags'] = $this->tags; $action = new NewsAction(array(), 'create', $newsData); $resultValues = $action->executeAction(); // save polls if (WCF::getSession()->getPermission('user.cms.news.canStartPoll') && MODULE_POLL) { $pollID = PollManager::getInstance()->save($resultValues['returnValues']->newsID); if ($pollID) { $editor = new NewsEditor($resultValues['returnValues']); $editor->update(array('pollID' => $pollID)); } } $this->saved(); HeaderUtil::redirect(LinkHandler::getInstance()->getLink('News', array('application' => 'cms', 'object' => $resultValues['returnValues']))); exit; }
public function updateLikeCounter($cumulativeLikes) { // update cumulative likes $editor = new NewsEditor($this->getDecoratedObject()); $editor->update(array('cumulativeLikes' => $cumulativeLikes)); }
public function updateCounter($objectID, $value) { $news = new News($objectID); $editor = new NewsEditor($news); $editor->update(array('comments' => $news->comments + $value)); }
$folder = substr($fileHash, 0, 2); //get size $size = filesize(CMS_DIR . 'images/news/' . $image->filename); //mime type $mime = FileUtil::getMimeType(CMS_DIR . 'images/news/' . $image->filename); //create db entry $action = new FileAction(array(), 'create', array('data' => array('title' => $image->getTitle(), 'filesize' => $size, 'fileType' => $mime, 'fileHash' => $fileHash, 'uploadTime' => TIME_NOW))); $action->executeAction(); $returnValues = $action->getReturnValues(); //set old IDs $oldIDs[$image->imageID] = $returnValues['returnValues']->fileID; if (!is_dir(CMS_DIR . 'files/' . $folder)) { FileUtil::makePath(CMS_DIR . 'files/' . $folder); } copy(CMS_DIR . 'images/news/' . $image->filename, CMS_DIR . 'files/' . $folder . '/' . $returnValues['returnValues']->fileID . '-' . $fileHash); @unlink(CMS_DIR . 'images/news/' . $image->filename); //insert into news image category $sql = "INSERT INTO cms" . WCF_N . "_file_to_category VALUES (?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($returnValues['returnValues']->fileID, $categoryID)); } //loop through news $list = new NewsList(); $list->readObjects(); foreach ($list->getObjects() as $news) { //check if image is set ( no foreign key is given :( ) if ($news->imageID !== 0 && isset($oldIDs[$news->imageID])) { $editor = new NewsEditor($news); $editor->update(array('imageID' => $oldIDs[$news->imageID])); } }