Beispiel #1
0
 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;
 }