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; }
/** * publishAction * * Set a content to published by id * * @param id integer ID of content to be published */ public function publishAction() { $params = $this->getRequest()->getParams(); $contentId = (int) $params['content_id']; $auth = Zend_Auth::getInstance(); $username = null; $message = ''; if ($auth->hasIdentity()) { $userId = $auth->getIdentity()->user_id; $username = $auth->getIdentity()->username; $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)) { //$contentUrl = $this->baseUrl ."/". $this->view->language ."/view/".$contentId; $contentUrl = $this->_urlHelper->url(array('controller' => 'view', 'action' => $contentId, 'language' => $this->view->language), 'lang_default', true); $cntHasUsr = new Default_Model_ContentHasUser(); $userIsOwner = $cntHasUsr->contentHasOwner($userId, $contentId); if ($userIsOwner) { if ($content->publishContent($contentId)) { $message = $this->view->translate('content-publish-successful'); $message .= " " . $this->view->translate('content-publish-click'); $message .= " <a href=\"" . $contentUrl . "\">"; $message .= " " . $this->view->translate('content-publish-here'); $message .= "</a> "; $message .= " " . $this->view->translate('content-publish-view-content'); //$this->flash($message, $url); } else { $message = 'content-publish-not-successful'; //$this->flash($message, $url); } } else { $message = 'content-publish-not-owner'; //$this->flash($message, $url); } } else { $message = 'content-publish-invalid-content-id'; //$this->flash($message, $url); } } else { $message = 'content-publish-not-authed'; //$this->flash($message, $url); } // Add login to log $logger = Zend_Registry::get('logs'); if (isset($logger['contentpublish'])) { $logMessage = sprintf('Publish attempt FROM: %s USER: %s. MESSAGE: %s. CONTENT ID: %s.', $_SERVER['REMOTE_ADDR'], $username, $this->view->translate($message, 'en'), $contentId); $logger['contentpublish']->notice($logMessage); } $this->flash($message, $url); }