/** * Returns an array of all blog entries. * * @return mixed * Returns an array of all blog entries, or null if there are no * blog entries. */ public function getAllBlogEntries() { $blogEntries = new Datasource_Cms_Connect_BlogEntries(); return $blogEntries->getAll(); }
/** * Responsible for validating and either saving or rejecting new and modified Connect * blog entries. */ protected function _saveBlogEntry() { //First perform the image upload validation. $params = Zend_Registry::get('params'); $upload = new Zend_File_Transfer_Adapter_Http(); $upload->setDestination($params->cms->imageUploadPath); $upload->addValidator('Extension', false, $params->cms->imageAllowedTypes); $upload->addValidator('Count', false, $params->cms->imageNumberAllowed); $upload->addValidator('Size', false, $params->cms->imageMaxUploadSize); /* $upload->addValidator('ImageSize', false, array( 'minwidth' => $params->cms->imageMinWidth, 'maxwidth' => $params->cms->imageMaxWidth, 'minheight' => $params->cms->imageMinHeight, 'maxheight' => $params->cms->imageMaxHeight )); */ //Call isUploaded(), which will return true if the user has uploaded an image. if ($upload->isUploaded()) { if ($upload->receive()) { //The file has been uploaded succesfully. Make a note of its uploaded location //so that we can write this to the database. $this->view->uploadSuccess = true; $imageName = $upload->getFileName(null, false); } else { //Communicate image upload failure return false; } } //Validate the rest of the inputs. $requiredText = new Zend_Validate(); $requiredText->addValidator(new Zend_Validate_NotEmpty()); $validators = array('id' => array('allowEmpty' => true), 'title' => $requiredText, 'summary' => $requiredText, 'article' => $requiredText, 'status' => $requiredText, 'imageName' => array('allowEmpty' => true), 'tagString' => array('allowEmpty' => true)); $input = new Zend_Filter_Input(null, $validators, $_POST); if ($input->isValid()) { //Determine if we are using the newly uploaded image (if any), or if we are //preserving a previously uploaded iimage (if any). $imageNameToSave = null; if (!empty($imageName)) { //Newly uploaded $imageNameToSave = $imageName; } else { if (!empty($input->imageName)) { //Previously uploaded $imageNameToSave = $input->imageName; } } //Prepare the tags. if (empty($input->tagString)) { $blogEntryTags = null; } else { $blogEntryTags = explode(',', $input->tagString); //Ensure no 'empty string' tags are added to the datasource. $cleanedTags = array(); foreach ($blogEntryTags as $currentTag) { if (empty($currentTag)) { continue; } if (preg_match("/^\\s+\$/", $currentTag)) { continue; } $cleanedTags[] = trim($currentTag); } $blogEntryTags = $cleanedTags; } //Now save to the database $blogEntries = new Datasource_Cms_Connect_BlogEntries(); if (!$input->id) { // This is a new user message so we need to create a new ID $blogEntryID = $blogEntries->addNew(new Zend_Date(), $input->title, $input->summary, $input->article, $input->status, $imageNameToSave, $blogEntryTags); } else { // This is an existing article so we can just update the data $blogEntryID = $input->id; $blogEntries->saveChanges($input->id, new Zend_Date(), $input->title, $input->summary, $input->article, $input->status, $imageNameToSave, $blogEntryTags); } $returnVal = true; } else { // Invalid data in form $returnVal = false; } return $returnVal; }