public function contentflagsAction() { // Get all POST-parameters $posts = $this->_request->getPost(); // Get models for the job $contentflagmodel = new Default_Model_ContentFlags(); $commentflagmodel = new Default_Model_CommentFlags(); $contentmodel = new Default_Model_Content(); $commentmodel = new Default_Model_Comments(); // Get cache from registry $cache = Zend_Registry::get('cache'); $cachePosts = array(); if ($handle = opendir(APPLICATION_PATH . '/../tmp')) { while (false !== ($file = readdir($handle))) { if (strcmp(substr($file, 0, 24), "zend_cache---IndexPosts_") == 0) { $cachePosts[] = $file; } } closedir($handle); } // Recent posts id if ($posts) { // Remove content if ($posts['rm'] == "content") { foreach ($posts as $key => $post) { if ($key != "rm" && $key != "selectall") { // Remove content and all dependign stuff $content = new Default_Model_Content(); $contentRemoveChecker = $content->removeContentAndDepending($key); if (isset($cachePosts)) { // Remove recent post cache foreach ($cachePosts as $cachePost) { $cache->remove(mb_substr($cachePost, 13)); } } } } } // Unpublish content if ($posts['rm'] == "pubflag") { foreach ($posts as $key => $post) { if ($key != "rm" && $key != "selectall") { // Flags from content_flags_cfl $cfl_ids = $contentflagmodel->getFlagsByContentId($key); foreach ($cfl_ids as $cfl_id) { $contentflagmodel->removeFlag($cfl_id); } // Unpublish $contentmodel->publishContent($key, 0); if (isset($cachePosts)) { // Remove recent post cache foreach ($cachePosts as $cachePost) { $cache->remove(mb_substr($cachePost, 13)); } } } } } // Remove flags if ($posts['rm'] == "flag") { foreach ($posts as $key => $post) { if ($key != "rm" && $key != "selectall") { // Flags from content_flags_cfl $cfl_ids = $contentflagmodel->getFlagsByContentId($key); foreach ($cfl_ids as $cfl_id) { $contentflagmodel->removeFlag($cfl_id); } } } } } // Awesome algorithm for counting how many flags each flagged content has $flagItems = $contentflagmodel->getAllFlags(); $tmpCount = array(); foreach ($flagItems as $flagItem) { $tmpCount[$flagItem['id_content_cfl']]++; } arsort($tmpCount); $data = array(); $count = 0; // Loop and re-arrange our variables foreach ($tmpCount as $cnt_id => $cnt_count) { $content = $contentmodel->getById($cnt_id); $data[$count]['id'] = $cnt_id; $data[$count]['ctype'] = $content['Content']['Data']['id_cty_cnt']; $data[$count]['title'] = $content['Content']['Data']['title_cnt']; $data[$count]['lead'] = $content['Content']['Data']['lead_cnt']; $data[$count]['body'] = $content['Content']['Data']['body_cnt']; $data[$count]['count'] = $cnt_count; $data[$count]['url'] = $this->_urlHelper->url(array('controller' => 'view', 'action' => $cnt_id, 'language' => $this->view->language), 'lang_default', true); $count++; } // Go! $this->view->contents = $data; }
/** * removeAction * * Remove content * @author ???? ? ? & 2010 Mikko Korpinen */ public function removeAction() { $params = $this->getRequest()->getParams(); $contentId = (int) $params['content_id']; $auth = Zend_Auth::getInstance(); // Get cache from registry $cache = Zend_Registry::get('cache'); // Recent posts id $cachePosts = 'IndexPosts_' . $this->view->language; if ($auth->hasIdentity()) { $userId = $auth->getIdentity()->user_id; $content = new Default_Model_Content(); $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); if ($content->checkIfContentExists($contentId)) { $cntHasUsr = new Default_Model_ContentHasUser(); $userIsOwner = $cntHasUsr->contentHasOwner($userId, $contentId); if ($userIsOwner) { $contentRemoveSuccessful = true; // Remove content and all dependign stuff $content = new Default_Model_Content(); $contentRemoveChecker = $content->removeContentAndDepending($contentId); // Remove recent post cache $cache->remove($cachePosts); foreach ($contentRemoveChecker as $crc) { if (!$crc) { $contentRemoveSuccessful = false; break; } } if ($contentRemoveSuccessful == true) { $message = 'content-remove-successful'; $this->flash($message, $url); } else { $message = $this->view->translate('content-remove-not-successful') . '<br />'; // User don't have to see these explanations /* if(!$contentRemoveChecker['removeContentFromCampaign']) $message .= $this->view->translate('content-remove-removeContentFromCampaign') . '<br />'; if(!$contentRemoveChecker['removeContentFromContent']) $message .= $this->view->translate('content-remove-removeContentFromContent-not-successful') . '<br />'; //if(!$contentRemoveChecker['removeContentFromFutureinfoClasses']) $message .= $this->view->translate('content-remove-removeContentFromFutureinfoClasses-not-successful') . '<br />'; //if(!$contentRemoveChecker['removeContentFromIndustries']) $message .= $this->view->translate('content-remove-removeContentFromIndustries-not-successful') . '<br />'; //if(!$contentRemoveChecker['removeContentFromInnovationTypes']) $message .= $this->view->translate('content-remove-removeContentFromInnovationTypes-not-successful') . '<br />'; if(!$contentRemoveChecker['removeContentFromRelatedCompanies']) $message .= $this->view->translate('content-remove-removeContentFromRelatedCompanies-not-successful') . '<br />'; if(!$contentRemoveChecker['removeContentRelatedCompanies']) $message .= $this->view->translate('content-remove-removeContentRelatedCompanies-not-successful') . '<br />'; if(!$contentRemoveChecker['removeContentFromTags']) $message .= $this->view->translate('content-remove-removeContentFromTags-not-successful') . '<br />'; if(!$contentRemoveChecker['removeContentTags']) $message .= $this->view->translate('content-remove-removeContentTags-not-successful') . '<br />'; if(!$contentRemoveChecker['removeContentFromUser']) $message .= $this->view->translate('content-remove-removeContentFromUser-not-successful') . '<br />'; if(!$contentRemoveChecker['removeContentViews']) $message .= $this->view->translate('content-remove-removeContentViews-not-successful') . '<br />'; if(!$contentRemoveChecker['removeContentFlags']) $message .= $this->view->translate('content-remove-removeContentFlags-not-successful') . '<br />'; if(!$contentRemoveChecker['removeContentCommentFlags']) $message .= $this->view->translate('content-remove-removeContentCommentFlags-not-successful') . '<br />'; if(!$contentRemoveChecker['removeContentRatings']) $message .= $this->view->translate('content-remove-removeContentRatings-not-successful') . '<br />'; if(!$contentRemoveChecker['removeContentFiles']) $message .= $this->view->translate('content-remove-removeContentFiles-not-successful') . '<br />'; if(!$contentRemoveChecker['removeUserHasFavorites']) $message .= $this->view->translate('content-remove-removeUserHasFavorites-not-successful') . '<br />'; if(!$contentRemoveChecker['removeContent']) $message .= $this->view->translate('content-remove-removeContent-content-not-successful') . '<br />'; if(!$contentRemoveChecker['removeContentComments']) $message .= $this->view->translate('content-remove-removeContentComments-not-successful') . '<br />';*/ $this->flash($message, $url); } } else { $message = 'content-remove-not-owner'; $this->flash($message, $url); } } else { $message = 'content-remove-invalid-content-id'; $this->flash($message, $url); } } else { $message = 'content-remove-not-authed'; $this->flash($message, $url); } }