/** * This is a standard function that is called with the results of the * form supplied by News_admin_modify() to update a current item * * @param int 'sid' the id of the item to be updated * @param int 'objectid' generic object id maps to sid if present * @param string 'title' the title of the news item * @param string 'urltitle' the title of the news item formatted for the url * @param string 'language' the language of the news item * @param string 'bodytext' the summary text of the news item * @param int 'bodytextcontenttype' the content type of the summary text * @param string 'extendedtext' the body text of the news item * @param int 'extendedtextcontenttype' the content type of the body text * @param string 'notes' any administrator notes * @param int 'published_status' the published status of the item * @param int 'displayonindex' display the article on the index page * @author Mark West * @return bool true */ public function update($args) { $this->checkCsrfToken(); $story = FormUtil::getPassedValue('story', isset($args['story']) ? $args['story'] : null, 'POST'); $files = News_ImageUtil::reArrayFiles(FormUtil::getPassedValue('news_files', null, 'FILES')); if (!empty($story['objectid'])) { $story['sid'] = $story['objectid']; } // Validate the essential parameters if (empty($story['sid'])) { return LogUtil::registerArgsError(); } // Get the unedited news article for the permissions check $item = ModUtil::apiFunc('News', 'user', 'get', array('sid' => $story['sid'])); if ($item === false) { return LogUtil::registerError($this->__('Error! No such article found.'), 404); } $this->throwForbiddenUnless(SecurityUtil::checkPermission('News::', $item['cr_uid'] . '::' . $item['sid'], ACCESS_EDIT), LogUtil::getErrorMsgPermission()); // Reformat the attributes array if (isset($story['attributes'])) { $story['__ATTRIBUTES__'] = News_Util::reformatAttributes($story['attributes']); unset($story['attributes']); } // Validate the input $validationerror = News_Util::validateArticle($story); $hookvalidators = $this->notifyHooks(new Zikula_ValidationHook('news.ui_hooks.articles.validate_edit', new Zikula_Hook_ValidationProviders()))->getValidators(); if ($hookvalidators->hasErrors()) { $validationerror .= $this->__('Error! Hooked content does not validate.') . "\n"; } // if the user has selected to preview the article we then route them back // to the new function with the arguments passed here if ($story['action'] == 0 || $validationerror !== false) { // log the error found if any if ($validationerror !== false) { LogUtil::registerError(nl2br($validationerror)); } // back to the referer form SessionUtil::setVar('newsitem', $story); return $this->redirect(ModUtil::url('News', 'admin', 'modify')); } else { // As we're not previewing the item let's remove it from the session SessionUtil::delVar('newsitem'); } // Check if the article goes from pending to published if ($item['published_status'] == News_Api_User::STATUS_PENDING && $story['published_status'] == News_Api_User::STATUS_PUBLISHED) { $story['approver'] = UserUtil::getVar('uid'); } $modvars = $this->getVars(); // Handle Images if ($modvars['picupload_enabled']) { if (isset($story['del_pictures']) && !empty($story['del_pictures'])) { $deletedPics = News_ImageUtil::deleteImagesByName($modvars['picupload_uploaddir'], $story['del_pictures']); $story['pictures'] = $story['pictures'] - $deletedPics; } if (isset($deletedPics) && ($deletedPics > 0)) { $nextImageId = News_ImageUtil::renumberImages($item['pictures'], $story['sid']); } else { $nextImageId = isset($story['pictures']) ? $story['pictures'] : 0; } if (isset($files) && !empty($files)) { list($files, $story) = News_ImageUtil::validateImages($files, $story); $story['pictures'] = News_ImageUtil::resizeImages($story['sid'], $files, $nextImageId); // resize and move the uploaded pics } } // Update the story if (ModUtil::apiFunc('News', 'admin', 'update', array( 'sid' => $story['sid'], 'cr_uid' => $story['cr_uid'], 'contributor' => UserUtil::getVar('uname', $story['cr_uid'], $item['contributor']), 'title' => $story['title'], 'urltitle' => $story['urltitle'], '__CATEGORIES__' => isset($story['__CATEGORIES__']) ? $story['__CATEGORIES__'] : null, '__ATTRIBUTES__' => isset($story['__ATTRIBUTES__']) ? $story['__ATTRIBUTES__'] : null, 'language' => isset($story['language']) ? $story['language'] : '', 'hometext' => isset($story['hometext']) ? $story['hometext'] : '', 'hometextcontenttype' => $story['hometextcontenttype'], 'bodytext' => isset($story['bodytext']) ? $story['bodytext'] : '', 'bodytextcontenttype' => $story['bodytextcontenttype'], 'notes' => isset($story['notes']) ? $story['notes'] : '', 'displayonindex' => isset($story['displayonindex']) ? $story['displayonindex'] : 0, 'allowcomments' => isset($story['allowcomments']) ? $story['allowcomments'] : 0, 'unlimited' => isset($story['unlimited']) ? $story['unlimited'] : null, 'from' => $story['from'], 'tonolimit' => isset($story['tonolimit']) ? $story['tonolimit'] : null, 'to' => $story['to'], 'approver' => $story['approver'], 'weight' => isset($story['weight']) ? $story['weight'] : 0, 'pictures' => $story['pictures'], 'action' => $story['action']))) { // Success LogUtil::registerStatus($this->__('Done! Saved your changes.')); } // Let any hooks know that we have edited an item. $url = new Zikula_ModUrl('News', 'user', 'display', ZLanguage::getLanguageCode(), array('sid' => $story['sid'])); $this->notifyHooks(new Zikula_ProcessHook('news.ui_hooks.articles.process_edit', $story['sid'], $url)); // release pagelock if (ModUtil::available('PageLock')) { ModUtil::apiFunc('PageLock', 'user', 'releaseLock', array('lockName' => "Newsnews{$story['sid']}")); } // clear article and view caches ModUtil::apiFunc('News', 'user', 'clearItemCache', $story); return $this->redirect(ModUtil::url('News', 'admin', 'view')); }