예제 #1
0
 function getrecentcontentAction()
 {
     // Get requests
     $offset = isset($this->params['offset']) ? $this->params['offset'] : 0;
     $contentType = isset($this->params['type']) ? $this->params['type'] : 'all';
     // Get models
     $contentModel = new Default_Model_Content();
     $contentHasTagModel = new Default_Model_ContentHasTag();
     // Get recent post data
     $recentposts_raw = $contentModel->listRecent($contentType, $offset, 15, 'created', $this->view->language, -1);
     $recentposts = array();
     // Gather data for recent posts
     $i = 0;
     foreach ($recentposts_raw as $post) {
         $tags = $contentHasTagModel->getContentTags($post['id_cnt']);
         $this->gtranslate->setLangFrom($post['language_cnt']);
         $translang = $this->gtranslate->getLangPair();
         $recentposts[$i]['original'] = $post;
         $recentposts[$i]['translated'] = $this->gtranslate->translateContent($post);
         $recentposts[$i]['original']['tags'] = $tags;
         $recentposts[$i]['translated']['tags'] = $tags;
         $recentposts[$i]['original']['translang'] = $translang;
         $recentposts[$i]['translated']['translang'] = $translang;
         $i++;
     }
     $this->view->recentposts = $recentposts;
 }
예제 #2
0
 function generateAction()
 {
     //Copy&Paste from RssController \o/ :D
     // Set an empty layout for view
     $this->_helper->layout()->setLayout('empty');
     // Make baseurl absolute URL
     $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl();
     $this->view->absoluteBaseUrl = $absoluteBaseUrl;
     // Get parameters
     $params = $this->getRequest()->getParams();
     // Get content type
     $cty = isset($params['type']) ? $params['type'] : 'all';
     // Get number of items
     $count = isset($params['count']) ? $params['count'] : 10;
     //$lang = ($this->view->language == "en" || $this->view->language == "fi") ? $this->view->language : "en";
     //$lang = $this->view->language;
     // Set array for content data
     $data = array();
     // Get recent content by type
     $content = new Default_Model_Content();
     $data = $content->getRecentByLangAndType($this->view->language, $cty, $count);
     // Get tags for contents
     $tags_model = new Default_Model_ContentHasTag();
     $usersid_model = new Default_Model_ContentHasUser();
     $users_model = new Default_Model_User();
     $i = 0;
     foreach ($data as $dataRow) {
         $tags = $tags_model->getContentTags($dataRow['id_cnt']);
         $user = $users_model->getContentOwner($dataRow['id_cnt']);
         $data[$i]['author'] = $user['login_name_usr'];
         $tagNames = array();
         foreach ($tags as $tag) {
             $tagNames[] = $tag['name_tag'];
         }
         $data[$i]['tags'] = join(", ", $tagNames);
         $i++;
     }
     // Set to view
     $this->view->contentData = $data;
 }
예제 #3
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;
 }
예제 #4
0
 public function flagAction()
 {
     // Set an empty layout for view
     $this->_helper->layout()->setLayout('empty');
     // Get requests
     $params = $this->getRequest()->getParams();
     $flaggedId = $params['flaggedid'];
     // Models for the job
     $auth = Zend_Auth::getInstance()->getIdentity();
     $userId = $auth->user_id;
     $flagmodel = new Default_Model_ContentFlags();
     $flagExists = $flagmodel->flagExists($flaggedId, $userId);
     $contentmodel = new Default_Model_Content();
     $contentExists = $contentmodel->checkIfContentExists($flaggedId);
     if ($contentExists == true) {
         if ($flagExists == true) {
             $success = 0;
         } elseif ($flagExists == false) {
             $success = 1;
             $flagmodel->addFlag($flaggedId, $userId);
         }
     } elseif ($contentExists == false) {
         $success = 0;
     }
     $this->view->success = $success;
 }
예제 #5
0
 private function _getContentInfo($updatedCounts)
 {
     //print_r($updatedCounts);die;
     $uniqueContents = array();
     $contentsToFetch = array();
     $contents = array();
     foreach ($updatedCounts as $k => $arrayBin) {
         foreach ($arrayBin as $bin => $arrayContent) {
             if (is_array($arrayContent)) {
                 foreach ($arrayContent as $cnt_id => $count) {
                     $uniqueContents[$k][$cnt_id] = 1;
                     $contentsToFetch[$cnt_id] = 1;
                 }
             }
         }
     }
     $contentsToFetch = array_keys($contentsToFetch);
     $contentModel = new Default_Model_Content();
     $contentInfo = $contentModel->getContentRows($contentsToFetch);
     foreach ($contentInfo as $k => $content) {
         foreach ($uniqueContents as $l => $arrayContents) {
             if (isset($arrayContents[$content['id_cnt']])) {
                 $contents[$l][$content['id_cnt']] = $content;
                 continue 2;
             }
         }
     }
     return $contents;
 }
예제 #6
0
 /**
  * unlinkAction
  *
  * Shows user contents which are linket to campaign. User can select and remove link.
  *
  * @author Mikko Korpinen
  */
 public function unlinkAction()
 {
     // Get authentication
     $auth = Zend_Auth::getInstance();
     // If user has identity
     if ($auth->hasIdentity()) {
         // Get requests
         $params = $this->getRequest()->getParams();
         $relatestoid = $params['relatestoid'];
         if (!isset($relatestoid)) {
             $redirectUrl = $this->_urlHelper->url(array('controller' => 'campaign', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
             $this->_redirector->gotoUrl($redirectUrl);
         }
         $contenttype = '';
         $campaigns = array();
         $model_content = new Default_Model_Content();
         $contentexists = $model_content->checkIfContentExists($relatestoid);
         if ($contentexists) {
             $relatesToContent = $model_content->getDataAsSimpleArray($relatestoid);
             $this->view->relatesToContentTitle = $relatesToContent['title_cnt'];
             $model_content_types = new Default_Model_ContentTypes();
             $model_cmp_has_cnt = new Default_Model_CampaignHasContent();
             $contenttype = $model_content_types->getTypeById($relatesToContent['id_cty_cnt']);
             $contentCampaigns = $model_cmp_has_cnt->getContentCampaigns($relatestoid);
         }
         $this->view->contentexists = $contentexists;
         $this->view->relatesToId = $relatestoid;
         $this->view->linkingContentType = $contenttype;
         $this->view->campaigns = $contentCampaigns;
     } else {
         // If not logged, redirecting to system message page
         $message = 'content-link-not-logged';
         $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
         $this->flash($message, $url);
     }
 }
예제 #7
0
 public function viewAction()
 {
     if (Zend_Controller_Action_HelperBroker::hasHelper('redirector')) {
         $redirector = Zend_Controller_Action_HelperBroker::getExistingHelper('redirector');
     }
     $hometargeturl = $this->_urlHelper->url(array('controller' => 'index', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
     // Get user identity
     $auth = Zend_Auth::getInstance();
     // Disable edit profile by default
     $userEdit = false;
     // Get params
     $params = $this->getRequest()->getParams();
     if (isset($params['user'])) {
         // Get username from params
         $username = $params['user'];
     } else {
         $redirector->gotoUrl($hometargeturl);
     }
     // Get content types
     $contentTypes = new Default_Model_ContentTypes();
     $this->view->content_types = $contentTypes->getAllNamesAndIds();
     // Get user data from User Model
     $user = new Default_Model_User();
     $data = $user->getUserByName($username);
     if ($data == null) {
         $redirector->gotoUrl($hometargeturl);
     }
     $this->view->user = $data;
     $id = $data['id_usr'];
     $topListClasses = $user->getUserTopList();
     $topListUsers = $topListClasses['Users'];
     if ($id != 0) {
         $topListUsers->addUser($id);
     }
     $topList = $topListUsers->getTopList();
     // Get public user data from UserProfiles Model
     $userProfile = new Default_Model_UserProfiles();
     $dataa = $userProfile->getPublicData($id);
     if (isset($dataa['biography'])) {
         $dataa['biography'] = str_replace("\n", '<br>', $dataa['biography']);
     }
     // User weblinks
     $userWeblinksModel = new Default_Model_UserWeblinks();
     $dataa['userWeblinks'] = $userWeblinksModel->getUserWeblinks($id);
     $i = 0;
     foreach ($dataa['userWeblinks'] as $weblink) {
         if (strlen($weblink['name_uwl']) == 0 || strlen($weblink['url_uwl']) == 0) {
             unset($dataa['userWeblinks'][$i]);
         }
         $i++;
     }
     // $dataa is an array with key=>val like firstname => "Joel Peeloten"
     // This was replaced with get public data and the foreach above
     // Kept here just in case for the future
     /*
     $dataa['gender'] 		= $userprofile->getUserProfileValue($id, 'gender');
     		$dataa['surname'] 		= $userprofile->getUserProfileValue($id, 'surname');
     		$dataa['firstname'] 	= $userprofile->getUserProfileValue($id, 'firstname');
     		$dataa['category'] 		= $userprofile->getUserProfileValue($id, 'user category');
     		$dataa['profession']	= $userprofile->getUserProfileValue($id, 'profession');
     		$dataa['company'] 		= $userprofile->getUserProfileValue($id, 'company');
     		$dataa['biography'] 	= $userprofile->getUserProfileValue($id, 'biography');
     		$dataa['city'] 			= $userprofile->getUserProfileValue($id, 'city');
     		$dataa['phone'] 		= $userprofile->getUserProfileValue($id, 'phone');
     		$dataa['birthday'] 		= $userprofile->getUserProfileValue($id, 'birthday');
     */
     // No countries in countries_ctr and not very good table at all?
     // This would be better: http://snipplr.com/view/6636/mysql-table--iso-country-list-with-abbreviations/
     /*
     		$dataa['country'] = $userProfile->getUserProfileValue($id, 'country');
     
     $userCountry = new Default_Model_UserCountry();
     		$dataa['country'] = $userCountry->getCountryNameById(
         $dataa['country']['profile_value_usp']
     );
     */
     // Get content user has released
     $type = isset($params['type']) ? $params['type'] : 0;
     $temp = array();
     // Initialize content counts
     $dataa['contentCounts']['all'] = 0;
     $dataa['contentCounts']['user_edit'] = 0;
     $dataa['contentCounts']['problem'] = 0;
     $dataa['contentCounts']['finfo'] = 0;
     $dataa['contentCounts']['idea'] = 0;
     // Count amount of content user has published
     // and check unpublished so only owner can see it.
     $cntModel = new Default_Model_Content();
     $contentList = array();
     foreach ($user->getUserContent($data['id_usr'], array('order' => 'DESC')) as $k => $c) {
         // If user not logged in and content not published,
         // remove content from list
         if (!$auth->hasIdentity() && $c['published_cnt'] == 0) {
             //unset($contentList[$k]);
             // Else if user logged in and not owner of unpublished content,
             // remove content from list
         } else {
             if (isset($c['id_usr']) && $auth->hasIdentity() && $c['id_usr'] != $auth->getIdentity()->user_id && $c['published_cnt'] == 0) {
                 //unset($contentList[$k]);
                 // Else increase content counts and sort content by content type
             } else {
                 if (isset($c['key_cty'])) {
                     // Set content to array by its content type
                     //$temp[$c['key_cty']][] = $c;
                     //$temp[] = $c;
                     // Increase total count
                     $dataa['contentCounts']['all']++;
                     // Set content type count to 0 if count is not set
                     if (!isset($dataa['contentCounts'][$c['key_cty']])) {
                         $dataa['contentCounts'][$c['key_cty']] = 0;
                     }
                     // Increase content type count
                     $dataa['contentCounts'][$c['key_cty']]++;
                 }
                 if ($c['published_cnt'] == 0) {
                     $dataa['contentCounts']['user_edit']++;
                 }
                 $c['hasCntLinks'] = $cntModel->hasCntLinks($c['id_cnt']);
                 $c['hasCmpLinks'] = $cntModel->hasCmpLinks($c['id_cnt']);
                 $contentList[] = $c;
             }
         }
     }
     // end foreach
     // If user is logged in, and viewing self; allow edit
     if ($auth->hasIdentity()) {
         $identity = $auth->getIdentity();
         if ($data['id_usr'] == $identity->user_id) {
             $userEdit = true;
         }
     }
     // if ($auth->hasIdentity() && $data['id_usr'] == $auth->getIdentity()->user_id) {
     $myFavourites = $this->getFavouriteRows($data['id_usr']);
     //print_r($dataa);print_r($favouriteList);die;
     //}
     //Zend_Debug::dump("" === null);
     //Zend_Debug::dump($dataa['contentCounts']['idea']);
     //Zend_Debug::dump($dataa['contentCounts']['idea'] == "");
     //die;
     //	My Posts box data
     $box = new Oibs_Controller_Plugin_AccountViewBox();
     $box->setHeader("My Posts")->setClass("right")->setName("my-posts")->addTab("All", "all", "all selected", $dataa['contentCounts']['all'])->addTab("Challenges", "problem", "challenges", $dataa['contentCounts']['problem'])->addTab("Ideas", "idea", "ideas", $dataa['contentCounts']['idea'])->addTab("Visions", "finfo", "visions", $dataa['contentCounts']['finfo']);
     //Zend_Debug::dump($dataa); die;
     if ($dataa['contentCounts']['user_edit'] && $userEdit) {
         $box->addTab("Saved", "user_edit", "saved", $dataa['contentCounts']['user_edit']);
     }
     $boxes[] = $box;
     $box = new Oibs_Controller_Plugin_AccountViewBox();
     $box->setHeader("My Groups")->setClass("left")->setName("my_groups")->addTab("All", "all", "all selected");
     $boxes[] = $box;
     $views = new Default_Model_ContentViews();
     $myViews = $this->getViewRows($data['id_usr']);
     $myViews = array_merge($myViews, $myFavourites['contents']);
     //print_r($myViews);die;
     $box = new Oibs_Controller_Plugin_AccountViewBox();
     $box->setHeader("My Views & Favourites")->setName("my-views")->setClass("right")->addTab("Views", "views", "views selected")->addTab("Updated", "updated", "fvr_updated", $myFavourites['counts']['updated'])->addTab("Challenges", "problem", "fvr_problem", $myFavourites['counts']['problem'])->addTab("Ideas", "idea", "fvr_idea", $myFavourites['counts']['idea'])->addTab("Visions", "finfo", "fvr_finfo", $myFavourites['counts']['finfo']);
     //$boxes[] = $box;
     $myReaders = $user->getUsersViewers($data['id_usr']);
     $box = new Oibs_Controller_Plugin_AccountViewBox();
     $box->setHeader("My Readers")->setClass("left")->setName("my-reads")->addTab("Readers", "readers", "all selected");
     //$boxes[] = $box;
     /*Box for user profile custom layout settings*/
     $box = new Oibs_Controller_Plugin_AccountViewBox();
     $box->setHeader("Custom Layout")->setClass("wide")->setName("my-custom-layout")->addTab("Customize", "fonts", "all selected");
     //$boxes[] = $box;
     $customLayoutForm = new Default_Form_AccountCustomLayoutSettingsForm();
     // Set to view
     // Comment module
     $comments = new Oibs_Controller_Plugin_Comments("account", $id);
     $this->view->jsmetabox->append('commentUrls', $comments->getUrls());
     // enable comment form
     if ($auth->hasIdentity()) {
         $comments->allowComments(true);
     }
     $comments->loadComments();
     $this->view->user_has_image = $user->userHasProfileImage($data['id_usr']);
     $this->view->userprofile = $dataa;
     $this->view->comments = $comments;
     $this->view->authorContents = $contentList;
     /*$temp*/
     $this->view->boxes = $boxes;
     $this->view->myViews = $myViews;
     $this->view->myReaders = $myReaders;
     $this->view->user_edit = $userEdit;
     $this->view->topList = $topList;
     $this->view->type = $type;
     $this->view->customLayoutSettingsForm = $customLayoutForm;
     $group_model = new Default_Model_UserHasGroup();
     $usergroups = $group_model->getGroupsByUserId($id);
     $this->view->usergroups = $usergroups;
 }
예제 #8
0
파일: Content.php 프로젝트: jannev/site
 /**
  *   removeContent
  *   Removes specified content from the database and all related stuff
  *
  *   @param int id_cnt The id of content to be removed
  *   @return boolean array $contentRemoveChecker
  *   @author Mikko Korpinen
  */
 public function removeContentAndDepending($id_cnt = 0)
 {
     $contentRemoveChecker = array('removeContentFromCampaign' => true, 'removeContentFromContent' => true, 'removeContentFromFutureinfoClasses' => true, 'removeContentFromIndustries' => true, 'removeContentFromInnovationTypes' => true, 'removeContentFromRelatedCompanies' => true, 'removeContentRelatedCompanies' => true, 'removeContentFromTags' => true, 'removeContentTags' => true, 'removeContentFromUser' => true, 'removeContentViews' => true, 'removeContentFlags' => true, 'removeContentCommentFlags' => true, 'removeContentRatings' => true, 'removeContentFiles' => true, 'removeUserFromFavorites' => true, 'removeContent' => true, 'removeContentComments' => true);
     // cnt_has_cmp
     $cmpHasCnt = new Default_Model_CampaignHasContent();
     if (!$cmpHasCnt->removeContentCampaignLinks($id_cnt)) {
         $contentRemoveChecker['removeContentFromCampaign'] = false;
     }
     // cnt_has_cnt
     $cntHasCnt = new Default_Model_ContentHasContent();
     if (!$cntHasCnt->removeContentFromContents($id_cnt)) {
         $contentRemoveChecker['removeContentFromContent'] = false;
     }
     // cnt_has_fic
     /* not used
                 $cntHasFic = new Default_Model_ContentHasFutureinfoClasses();
                 if (!$cntHasFic->removeFutureinfoClassesFromContent($id_cnt))
                     $contentRemoveChecker['removeContentFromFutureinfoClasses'] = false;
     			*/
     // cnt_has_grp
     // Not used?
     // cnt_has_ind
     /* not used
        $cntHasInd = new Default_Model_ContentHasIndustries();
        if (!$cntHasInd->removeIndustriesFromContent($id_cnt))
            $contentRemoveChecker['removeContentFromIndustries'] = false;
        */
     // cnt_has_ivt
     /* not used
        $cntHasIvt = new Default_Model_ContentHasInnovationTypes();
        if (!$cntHasIvt->removeInnovationTypesFromContent($id_cnt))
            $contentRemoveChecker['removeContentFromInnovationTypes'] = false;
        */
     // related_companies_rec and cnt_has_rec
     $cntHasRec = new Default_Model_ContentHasRelatedCompany();
     $recs = $cntHasRec->getContentRelComps($id_cnt);
     $rec = new Default_Model_RelatedCompanies();
     foreach ($recs as $id_rec) {
         if (!$cntHasRec->checkIfOtherContentHasRelComp($id_rec['id_rec'], $id_cnt)) {
             if (!$rec->removeRelComp($id_rec['id_rec'])) {
                 $contentRemoveChecker['removeRelatedCompanies'] = false;
             }
         }
     }
     if (!$cntHasRec->removeContentRelComps($id_cnt)) {
         $contentRemoveChecker['removeContentFromRelatedCompanies'] = false;
     }
     // tags_tag and cnt_has_tag
     $cntHasTag = new Default_Model_ContentHasTag();
     $tags = $cntHasTag->getContentTags($id_cnt);
     $tag = new Default_Model_Tags();
     foreach ($tags as $id_tag) {
         if (!$cntHasTag->checkIfOtherContentHasTag($id_tag['id_tag'], $id_cnt)) {
             if (!$tag->removeTag($id_tag['id_tag'])) {
                 $contentRemoveChecker['removeTags'] = false;
             }
         }
     }
     if (!$cntHasTag->removeContentTags($id_cnt)) {
         $contentRemoveChecker['removeContentFromTags'] = false;
     }
     // cnt_has_usr
     $cntHasUsr = new Default_Model_ContentHasUser();
     if (!$cntHasUsr->removeUserFromContent($id_cnt)) {
         $contentRemoveChecker['removeContentFromUser'] = false;
     }
     // cnt_publish_times_pbt
     // Not used?
     // cnt_views_vws
     $cntWiewsVws = new Default_Model_ContentViews();
     if (!$cntWiewsVws->removeContentViews($id_cnt)) {
         $contentRemoveChecker['removeContentViews'] = false;
     }
     // Flags from content_flags_cfl
     $contentflagmodel = new Default_Model_ContentFlags();
     $cnfl_ids = $contentflagmodel->getFlagsByContentId($id_cnt);
     if (is_array($cnfl_ids)) {
         foreach ($cnfl_ids as $cfl_id) {
             if (!$contentflagmodel->removeFlag($cfl_id)) {
                 $contentRemoveChecker['removeContentFlags'] = false;
             }
         }
     }
     // Flags from comment_flags_cfl
     $commentflagmodel = new Default_Model_CommentFlags();
     $cmfl_ids = $commentflagmodel->getFlagsByContentId($id_cnt);
     if (is_array($cmfl_ids)) {
         foreach ($cmfl_ids as $cfl_id) {
             if (!$commentflagmodel->removeFlag($cfl_id)) {
                 $contentRemoveChecker['removeContentCommentFlags'] = false;
             }
         }
     }
     // content_ratings_crt
     $contentRatingRct = new Default_Model_ContentRatings();
     if (!$contentRatingRct->removeContentRatings($id_cnt)) {
         $contentRemoveChecker['removeContentRatings'] = false;
     }
     // files_fil
     $files = new Default_Model_Files();
     if (!$files->removeFiles($id_cnt, "content")) {
         $contentRemoveChecker['removeContentFiles'] = false;
     }
     // links_lnk
     // Not used?
     // usr_has_fvr
     $usrHasFvr = new Default_Model_UserHasFavourites();
     if (!$usrHasFvr->removeAllContentFromFavouritesByContentId($id_cnt)) {
         $contentRemoveChecker['removeUserFromFavorites'] = false;
     }
     // contents_cnt
     $contentmodel = new Default_Model_Content();
     if (!$contentmodel->removeContent($id_cnt)) {
         $contentRemoveChecker['removeContent'] = false;
     }
     // coments_cmt
     $commentmodel = new Default_Model_Comments();
     if (!$commentmodel->removeAllContentComments($id_cnt)) {
         $contentRemoveChecker['removeContentComments'] = false;
     }
     return $contentRemoveChecker;
 }
예제 #9
0
 /**
  *   index page: Contains the content viewing functionality.
  *
  *   @todo   Implement group ownership user images and content links
  *   @todo   Include translation and content info for page title
  *   @todo   More from box should show ratings
  *   @todo   If not ajax "more from", at least separate to proper MVC
  *   @todo   Look over comment loading for data being fetched and not shown
  *   @todo   Comment rating, userpic (maybe not)
  *
  *   @param  id      integer     id of content to view
  *   @param  page    integer     (optional) Page number for paginator
  *   @param  count   integer     (optional) Count of content for paginator
  *   @param  rate    integer     (optional) Rating given by user
  */
 function indexAction()
 {
     // get requests
     $request = $this->getRequest();
     $params = $request->getParams();
     $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
     $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl();
     // get content id from params, if not set or invalid, send a message
     $id = (int) $params['content_id'];
     if ($id == 0) {
         $this->flash('content-not-found', $baseUrl . '/' . $this->view->language . '/msg/');
     }
     // Get specific content data -- this could fail? Needs check?
     $contentModel = new Default_Model_Content();
     $contentData = $contentModel->getDataAsSimpleArray($id);
     // Translate content data
     $this->gtranslate->setLangFrom($contentData['language_cnt']);
     $contentData = $this->gtranslate->translateContent($contentData);
     $filesModel = new Default_Model_Files();
     $files = $filesModel->getFilenamesByCntId($id);
     // Get content owner id (groups to be implemented later)
     $contentHasUserModel = new Default_Model_ContentHasUser();
     $owner = $contentHasUserModel->getContentOwners($id);
     $ownerId = $owner['id_usr'];
     // Get authentication
     $auth = Zend_Auth::getInstance();
     if ($contentData['published_cnt'] == 0 && $auth->getIdentity()->user_id != $ownerId && !in_array("admin", $this->view->logged_user_roles)) {
         $this->flash('content-not-found', $baseUrl . '/' . $this->view->language . '/msg/');
     }
     // get rating from params (if set)
     $rate = isset($params['rate']) ? $params['rate'] : "NONE";
     // get favourite method, "add" or "remove"
     //$favouriteMethod = isset($params['favourite']) ? $params['favourite'] : "NONE";
     // get page number and comments per page (if set)
     $page = isset($params['page']) ? $params['page'] : 1;
     $count = isset($params['count']) ? $params['count'] : 10;
     // turn commenting off by default
     $user_can_comment = false;
     // turn rating off by default
     $user_can_rate = false;
     // Comment model
     $comment = new Default_Model_Comments();
     $parentId = isset($params['replyto']) ? $params['replyto'] : 0;
     // If user has identity
     if ($auth->hasIdentity() && $contentData['published_cnt'] == 1) {
         // enable comment form
         $user_can_comment = true;
         // enable rating if the content was not published by the user
         // (also used for flagging)
         if ($ownerId != $auth->getIdentity()->user_id) {
             $user_can_rate = true;
         }
         // generate comment form
         $comment_form = new Default_Form_CommentForm($parentId);
         // if there is something in POST
         if ($request->isPost()) {
             // Get comment form data
             $formData = $this->_request->getPost();
             // Validate and save comment data
             if ($comment_form->isValid($formData)) {
                 $user_id = $auth->getIdentity()->user_id;
                 $comment->addComment($id, $user_id, $formData);
                 $comment_form = new Default_Form_CommentForm($parentId);
                 if ($user_id != $ownerId) {
                     $user = new Default_Model_User();
                     $comment_sender = $user->getUserNameById($user_id);
                     $Default_Model_privmsg = new Default_Model_PrivateMessages();
                     $data = array();
                     $data['privmsg_sender_id'] = 0;
                     $data['privmsg_receiver_id'] = $ownerId;
                     $data['privmsg_header'] = 'You have new comment!';
                     $data['privmsg_message'] = '<a href="' . $baseUrl . "/" . $this->view->language . '/account/view/user/' . $comment_sender . '">' . $comment_sender . '</a> commented your content <a href="' . $baseUrl . "/" . $this->view->language . '/view/' . $id . '">' . $contentData['title_cnt'] . '</a>';
                     $data['privmsg_email'] = '';
                     // Send email to contentowner about new comment
                     // if its allowed
                     $notificationsModel = new Default_Model_Notifications();
                     $notifications = $notificationsModel->getNotificationsById($ownerId);
                     if (in_array('comment', $notifications)) {
                         $emailNotification = new Oibs_Controller_Plugin_Email();
                         $emailNotification->setNotificationType('comment')->setSenderId($user_id)->setReceiverId($ownerId)->setParameter('URL', $absoluteBaseUrl . "/en")->setParameter('SENDER-NAME', $comment_sender)->setParameter('CONTENT-ID', $id)->setParameter('CONTENT-TITLE', $contentData['title_cnt'])->setParameter('COMMENT', $formData['comment_message']);
                         if ($emailNotification->isValid()) {
                             $emailNotification->send();
                         } else {
                             //echo $emailNotification->getErrorMessage(); die;
                         }
                     }
                     $Default_Model_privmsg->addMessage($data);
                 }
             }
             // end if
         }
         // end if
         $this->view->comment_form = $comment_form;
     }
     // end if
     // get content type of the specific content viewed
     $contentTypesModel = new Default_Model_ContentTypes();
     $contentType = $contentTypesModel->getTypeById($contentData['id_cty_cnt']);
     // Get content innovation type / industry / division / group / class
     // and send to view... somehow.
     // TO BE IMPLEMENTED
     // Get content owner data
     $userModel = new Default_Model_User();
     $userData = $userModel->getSimpleUserDataById($ownerId);
     // get content owner picture ... to be implemented later
     $userImage = $userModel->getUserImageData($ownerId);
     // get other content from user.. function needs a looking-over!
     // Also it needs to be separated from this action so the MVC-is correct!
     $moreFromUser = $userModel->getUserContent($ownerId, 0, $id);
     // get related contents
     $relatedContents = $contentModel->getRelatedContents($id);
     // get (VIEWED) content views (returns a string directly)
     $contentViewsModel = new Default_Model_ContentViews();
     if (!$this->alreadyViewed($id)) {
         $contentViewsModel->increaseViewCount($id);
     }
     $views = $contentViewsModel->getViewsByContentId($id);
     // get content rating (returns a string directly)
     $contentRatingsModel = new Default_Model_ContentRatings();
     //$rating = $contentRatingsModel->getById($id);
     $rating = $contentRatingsModel->getPercentagesById($id);
     // $rate is gotten from params[], 1 and -1 are the only allowed
     if ($rate != "NONE" && ($rate == 1 || $rate == -1) && $auth->hasIdentity()) {
         if ($contentRatingsModel->addRating($id, $auth->getIdentity()->user_id, $rate)) {
             $this->view->savedRating = $rate;
             //$rating = $contentRatingsModel->getById($id);
             $rating = $contentRatingsModel->getPercentagesById($id);
         } else {
             $this->flash('rating-failed-msg', $baseUrl . '/en/msg/');
         }
     }
     // get contents total favourites
     $userFavouritesModel = new Default_Model_UserHasFavourites();
     $totalFavourites = $userFavouritesModel->getUsersCountByFavouriteContent($id);
     $totalFavourites = $totalFavourites[0]['users_count_fvr'];
     $isFavourite = $userFavouritesModel->checkIfContentIsUsersFavourite($id, $auth->getIdentity()->user_id);
     /*
      * favouritemethod comes from parameters sent by
      * ajax function (ajaxLoad_favourite(method)) in index.phtml in /view/.
      * this function gets parameter "method" (add/remove) from onClick event that is in index.ajax.phtml.
      * if this onClick event is activated by clicking "heart" (icon_fav_on/off) icon in content view page,
      * it runs the ajaxLoad_favourite(method) function which sends parameter "favourite" (add/remove) to
      * this viewController which then handles the adding or removing the content from favourites.
      */
     if ($favouriteMethod != "NONE" && $auth->hasIdentity()) {
         $favouriteUserId = $auth->getIdentity()->user_id;
         //If favourite method was "add", then add content to user favourites
         if ($favouriteMethod == "add" && !$isFavourite) {
             if ($userFavouritesModel->addContentToFavourites($id, $favouriteUserId)) {
                 $this->view->favouriteMethod = $favouriteMethod;
             } else {
                 $this->flash('favourite-adding-failed', $baseUrl . '/en/msg');
             }
         } elseif ($favouriteMethod == "remove" && $isFavourite) {
             if ($userFavouritesModel->removeUserFavouriteContent($id, $favouriteUserId)) {
                 $this->view->favouriteMethod = $favouriteMethod;
             } else {
                 $this->flash('favourite-removing-failed', $baseUrl . '/en/msg');
             }
         } else {
             unset($favouriteMethod);
         }
     }
     $favourite = array('total_favourites' => $totalFavourites, 'is_favourite' => $isFavourite);
     $languagesModel = new Default_Model_Languages();
     $languageName = $languagesModel->getLanguageByLangCode($contentData['language_cnt']);
     $gtranslateLangPair = $this->gtranslate->getLangPair();
     // get content tags - functions returns names as well
     // needs updating to proper MVC?
     $contentHasTagModel = new Default_Model_ContentHasTag();
     $tags = $contentHasTagModel->getContentTags($id);
     //echo "<pre>"; print_r($tags); echo "</pre>"; die;
     // get content links, to be implemented
     $links = array();
     // Get all content campaigns
     $campaignHasContentModel = new Default_Model_CampaignHasContent();
     $campaigns = $campaignHasContentModel->getContentCampaigns($id);
     // This functionality needs looking over (code and general idea)
     // get content family (array of children, parents and siblings)
     $contentHasContentModel = new Default_Model_ContentHasContent();
     $family = $contentHasContentModel->getContentFamilyTree($id);
     // split family array to child, parent and sibling arrays (full content)
     $children = array();
     $children_siblings = array();
     if (isset($family['children'])) {
         foreach ($family['children'] as $child) {
             $contenttypeid = $contentModel->getContentTypeIdByContentId((int) $child);
             $contenttype = $contentTypesModel->getTypeById($contenttypeid);
             if ($contenttype == "idea") {
                 $children[] = $contentModel->getDataAsSimpleArray((int) $child);
             } else {
                 $children_siblings[] = $contentModel->getDataAsSimpleArray((int) $child);
             }
             // $i++;
         }
     }
     $parents = array();
     $parent_siblings = array();
     if (isset($family['parents'])) {
         foreach ($family['parents'] as $parent) {
             $contenttypeid = $contentModel->getContentTypeIdByContentId((int) $parent);
             $contenttype = $contentTypesModel->getTypeById($contenttypeid);
             if ($contenttype == "idea") {
                 $parents[] = $contentModel->getDataAsSimpleArray((int) $parent);
             } else {
                 $parent_siblings[] = $contentModel->getDataAsSimpleArray((int) $parent);
             }
         }
     }
     // Here we get the rival solutions for a solution
     $rivals = array();
     if ($contentType == "idea" && isset($family['parents'])) {
         $i = 0;
         // First here is checked the parents of this solution (=the problem
         // or the future info)
         foreach ($family['parents'] as $parent) {
             // Get the family of the problem or future info
             $parents_family = $contentHasContentModel->getContentFamilyTree((int) $parent);
             // Get the children of the problem or future info
             if (isset($parents_family['children'])) {
                 // Going through the children
                 foreach ($parents_family['children'] as $parent_child) {
                     // Those children are rivals which are not this solution
                     // which is currently viewed
                     if ((int) $parent_child != $id) {
                         $rivals[$i] = $contentModel->getDataAsSimpleArray((int) $parent_child);
                     }
                 }
             }
             $i++;
         }
     }
     // get comments data
     // $commentList = $comment->getAllByContentId($id, $page, $count);
     $commentList = $comment->getCommentsByContent($id);
     $commentsSorted = array();
     $this->getCommentChilds($commentList, $commentsSorted, 0, 0, 3);
     // Get total comment count
     $commentCount = $comment->getCommentCountByContentId($id);
     // Calculate total page count
     $pageCount = ceil($commentCount / $count);
     // Custom pagination to fix memory error on large amount of data
     $paginator = new Zend_View();
     $paginator->setScriptPath('../application/views/scripts');
     $paginator->pageCount = $pageCount;
     $paginator->currentPage = $page;
     $paginator->pagesInRange = 10;
     // get content industries -- will be updated later.
     $cntHasIndModel = new Default_Model_ContentHasIndustries();
     $hasIndustry = $cntHasIndModel->getIndustryIdOfContent($id);
     $industriesModel = new Default_Model_Industries();
     $industriesArray = $industriesModel->getAllContentIndustryIds($hasIndustry);
     // roll values to an array
     /*$industries = array();
             foreach ($industriesArray as $industry) {
                 $value = $industriesModel->getNameById($industry);
                 // $industriesModel->getNameById($industry);
     
                if (!empty($value)) {
                     $industries[] = $value;
                 }
             }*/
     // Check if and when the content is modified and if its more than 10minutes ago add for the view
     $dateCreated = strtotime($contentData['created_cnt']);
     $dateModified = strtotime($contentData['modified_cnt']);
     $modified = 0;
     if (($dateModified - $dateCreated) / 60 > 10) {
         $modified = $contentData['modified_cnt'];
     }
     // Inject data to view
     $this->view->files = $files;
     $this->view->id = $id;
     $this->view->userImage = $userImage;
     $this->view->commentPaginator = $paginator;
     $this->view->commentData = $commentsSorted;
     $this->view->user_can_comment = $user_can_comment;
     $this->view->user_can_rate = $user_can_rate;
     $this->view->contentData = $contentData;
     $this->view->modified = $modified;
     $this->view->userData = $userData;
     $this->view->moreFromUser = $moreFromUser;
     $this->view->relatedContents = $relatedContents;
     $this->view->views = $views;
     $this->view->rating = $rating;
     $this->view->languageName = $languageName;
     $this->view->gtranslateLangPair = $gtranslateLangPair;
     $this->view->tags = $tags;
     $this->view->links = $links;
     $this->view->parents = $parents;
     $this->view->parent_siblings = $parent_siblings;
     $this->view->children = $children;
     $this->view->children_siblings = $children_siblings;
     $this->view->rivals = $rivals;
     $this->view->comments = $commentCount;
     $this->view->contentType = $contentType;
     $this->view->count = $count;
     $this->view->campaigns = $campaigns;
     //$this->view->favourite			= $favourite;
     // Inject title to view
     $this->view->title = $this->view->translate('index-home') . " - " . $contentData['title_cnt'];
 }
예제 #10
0
 /**
  *    generateAction
  *    
  *    Generate RSS feeds
  *
  *   @param  type    string      (optional) Content type ('problem' / 'finfo' / 'idea' / 'all'), 'all' by default
  *   @param  count   integer     (optional) How many items to generate
  *   
  */
 public function generateAction()
 {
     // Set an empty layout for view
     $this->_helper->layout()->setLayout('empty');
     // Set custom RSS cache (lifetime 10 minutes)
     $cacheFrontend = array('lifetime' => 600, 'automatic_serialization' => true);
     $cacheBackend = array('cache_dir' => '../tmp/');
     $cache = Zend_Cache::factory('core', 'File', $cacheFrontend, $cacheBackend);
     // Make baseurl absolute URL
     $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl();
     $this->view->absoluteBaseUrl = $absoluteBaseUrl;
     // Get parameters
     $params = $this->getRequest()->getParams();
     // Get content type
     $cty = isset($params['type']) ? $params['type'] : 'all';
     // Get number of items
     $count = isset($params['count']) ? $params['count'] : 10;
     // Set array for content data
     $data = array();
     // Get recent content by type
     $content = new Default_Model_Content();
     $data = $content->listRecent($cty, 1, $count, null, $this->view->language, null);
     // Set to view
     $this->view->cache = $cache;
     $this->view->cacheIdentifier = 'RSS_' . md5($cty . $count);
     $this->view->contentData = $data;
 }
예제 #11
0
 public function contentfavouriteAction()
 {
     // Get authentication
     $auth = Zend_Auth::getInstance();
     $favouriteUserId = 0;
     if ($auth->hasIdentity()) {
         $favouriteUserId = $auth->getIdentity()->user_id;
     }
     $params = $this->getRequest()->getParams();
     // get favourite method, "add" or "remove"
     $favouriteMethod = isset($params['method']) ? $params['method'] : "NONE";
     $id = isset($params['id_cnt']) ? $params['id_cnt'] : "0";
     // Get contents total favourites
     $userFavouritesModel = new Default_Model_UserHasFavourites();
     $contentModel = new Default_Model_Content();
     $totalFavourites = $userFavouritesModel->getUsersCountByFavouriteContent($id);
     $totalFavourites = $totalFavourites[0]['users_count_fvr'];
     $isFavourite = $userFavouritesModel->checkIfContentIsUsersFavourite($id, $favouriteUserId);
     $isOwner = $contentModel->checkIfUserIsOwner($id, $favouriteUserId);
     if ($favouriteMethod != "NONE" && $auth->hasIdentity() && !$isOwner) {
         //If favourite method was "add", then add content to user favourites
         if ($favouriteMethod == "add" && !$isFavourite) {
             if ($userFavouritesModel->addContentToFavourites($id, $favouriteUserId)) {
                 $isFavourite = true;
                 $totalFavourites++;
             } else {
                 $this->flash('favourite-adding-failed', $baseUrl . '/en/msg');
             }
         } elseif ($favouriteMethod == "remove" && $isFavourite) {
             if ($userFavouritesModel->removeUserFavouriteContent($id, $favouriteUserId)) {
                 $isFavourite = false;
                 $totalFavourites--;
             } else {
                 $this->flash('favourite-removing-failed', $baseUrl . '/en/msg');
             }
         } else {
             unset($favouriteMethod);
         }
     }
     $favourite = array('total_favourites' => $totalFavourites, 'is_favourite' => $isFavourite);
     $thie->view->userid = $favouriteUserId;
     $this->view->favourite = $favourite;
 }
예제 #12
0
 /**
  *   index page: Contains the content viewing functionality.
  *
  *   @todo   Implement group ownership user images and content links
  *   @todo   Include translation and content info for page title
  *   @todo   More from box should show ratings
  *   @todo   If not ajax "more from", at least separate to proper MVC
  *   @todo   Look over comment loading for data being fetched and not shown
  *   @todo   Comment rating, userpic (maybe not)
  *
  *   @param  id      integer     id of content to view
  *   @param  page    integer     (optional) Page number for paginator
  *   @param  count   integer     (optional) Count of content for paginator
  *   @param  rate    integer     (optional) Rating given by user
  */
 function indexAction()
 {
     // get requests
     $request = $this->getRequest();
     $params = $request->getParams();
     $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
     $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl();
     // get content id from params, if not set or invalid, send a message
     $id = (int) $params['content_id'];
     if ($id == 0) {
         $this->flash('content-not-found', $baseUrl . '/' . $this->view->language . '/msg/');
     }
     // Get specific content data -- this could fail? Needs check?
     $contentModel = new Default_Model_Content();
     $contentData = $contentModel->getDataAsSimpleArray($id);
     $isTranslated = isset($params['notranslate']) ? false : true;
     if ($isTranslated) {
         // Translate content data
         $this->gtranslate->setLangFrom($contentData['language_cnt']);
         $contentData = $this->gtranslate->translateContent($contentData);
     }
     $filesModel = new Default_Model_Files();
     $files = $filesModel->getFilenames($id, "content");
     // Get content owner id (groups to be implemented later)
     $contentHasUserModel = new Default_Model_ContentHasUser();
     $owner = $contentHasUserModel->getContentOwners($id);
     $ownerId = $owner['id_usr'];
     // Get authentication
     $auth = Zend_Auth::getInstance();
     // Get user_id
     $usrId = 0;
     if ($auth->hasIdentity()) {
         $usrId = $auth->getIdentity()->user_id;
     }
     if ($contentData['published_cnt'] == 0 && $usrId != $ownerId && !in_array("admin", $this->view->logged_user_roles)) {
         $this->flash('content-not-found', $baseUrl . '/' . $this->view->language . '/msg/');
     }
     // get rating from params (if set)
     $rate = isset($params['rate']) ? $params['rate'] : "NONE";
     // get page number and comments per page (if set)
     $page = isset($params['page']) ? $params['page'] : 1;
     // turn commenting off by default
     $user_can_comment = false;
     // turn rating off by default
     $user_can_rate = false;
     // user is not owner by default
     $user_is_owner = false;
     // Comment model
     $comment = new Default_Model_Comments();
     $favouriteModel = new Default_Model_UserHasFavourites();
     $cntHasUsrModel = new Default_Model_ContentHasUser();
     //$parentId = isset($params['replyto']) ? $params['replyto'] : 0;
     // If user has identity
     if ($auth->hasIdentity() && $contentData['published_cnt'] == 1) {
         // enable rating if the content was not published by the user
         // (also used for flagging)
         if ($ownerId != $auth->getIdentity()->user_id) {
             $user_can_rate = true;
         }
         // Check if user is owner of content
         if ($ownerId == $auth->getIdentity()->user_id) {
             $user_is_owner = true;
         }
         if ($favouriteModel->checkIfContentIsUsersFavourite($id, $usrId)) {
             $favouriteModel->updateLastChecked($usrId, $id);
             $profileModel = new Default_Model_UserProfiles();
             $profileModel->deleteNotificationCache($id, $usrId);
         }
         if ($user_is_owner) {
             $cntHasUsrModel->updateLastChecked($ownerId, $id);
             $profileModel = new Default_Model_UserProfiles();
             $profileModel->deleteNotificationCache($id, $usrId);
         }
         // generate comment form
         //$comment_form = new Default_Form_CommentForm($parentId);
         // if there is something in POST
         /*if ($request->isPost()) {
                       
                               if($user_id != $ownerId) {
                                   $user = new Default_Model_User();
                                   $comment_sender = $user->getUserNameById($user_id);
                                   
                                   $Default_Model_privmsg = new Default_Model_PrivateMessages();
                                   $data = array();
                                   $data['privmsg_sender_id'] = 0;
                                   $data['privmsg_receiver_id'] = $ownerId;
                                   $data['privmsg_header'] = 'You have new comment!';
                                   $data['privmsg_message'] = '<a href="'.$baseUrl."/".$this->view->language.'/account/view/user/'.$comment_sender.'">'
                                   .$comment_sender.'</a> commented your content <a href="'.$baseUrl."/".$this->view->language.'/view/'.$id.'">'.$contentData['title_cnt'].'</a>';
                                   $data['privmsg_email'] = '';
                                   
                                   // Send email to contentowner about new comment
                                   // if its allowed
                                   $notificationsModel = new Default_Model_Notifications();
           						$notifications = $notificationsModel->getNotificationsById($ownerId);
           
           	                    if (in_array('comment', $notifications)) {
           	                    	
           	                    	$emailNotification = new Oibs_Controller_Plugin_Email();
           	                    	$emailNotification->setNotificationType('comment')
           	                    					   ->setSenderId($user_id)
           	                    					   ->setReceiverId($ownerId)
           	                    					   ->setParameter('URL', $absoluteBaseUrl."/en")
           	                    					   ->setParameter('SENDER-NAME', $comment_sender)
           	                    					   ->setParameter('CONTENT-ID', $id)
           	                    					   ->setParameter('CONTENT-TITLE', $contentData['title_cnt'])
           	                    					   ->setParameter('COMMENT', $formData['comment_message']);
           	                    					   
           							if ($emailNotification->isValid()) {
           								$emailNotification->send();
           							} else {
           								//echo $emailNotification->getErrorMessage(); die;
           							}
           	                    }
                                   
                                   $Default_Model_privmsg->addMessage($data);
                           } // end if
                       }*/
         // end if
     }
     // end if
     // get content type of the specific content viewed
     $contentTypesModel = new Default_Model_ContentTypes();
     $contentType = $contentTypesModel->getTypeById($contentData['id_cty_cnt']);
     // Get content innovation type / industry / division / group / class
     // and send to view... somehow.
     // TO BE IMPLEMENTED
     // Get content owner data
     $userModel = new Default_Model_User();
     $userData = $userModel->getSimpleUserDataById($ownerId);
     // get content owner picture ... to be implemented later
     $userImage = $userModel->getUserImageData($ownerId);
     // get (VIEWED) content views (returns a string directly)
     $contentViewsModel = new Default_Model_ContentViews();
     if (!$this->alreadyViewed($id, $auth->hasIdentity() ? $auth->getIdentity()->username : "******")) {
         $contentViewsModel->increaseViewCount($id);
     }
     $views = $contentViewsModel->getViewsByContentId($id);
     $languagesModel = new Default_Model_Languages();
     $languageName = $languagesModel->getLanguageByLangCode($contentData['language_cnt']);
     $gtranslateLangPair = $this->gtranslate->getLangPair();
     // get content tags - functions returns names as well
     // needs updating to proper MVC?
     $contentHasTagModel = new Default_Model_ContentHasTag();
     $tags = $contentHasTagModel->getContentTags($id);
     if ($isTranslated) {
         $tags = $this->gtranslate->translateTags($tags);
     }
     // get content links, to be implemented
     $links = array();
     // Get all content campaigns
     // $campaignHasContentModel = new Default_Model_CampaignHasContent();
     // $campaigns = $campaignHasContentModel->getContentCampaigns($id);
     // This functionality needs looking over (code and general idea)
     // get content family (array of children, parents and siblings)
     $contentHasContentModel = new Default_Model_ContentHasContent();
     $family = $contentHasContentModel->getContentFamilyTree($id);
     // split family array to child, parent and sibling arrays (full content)
     $children = array();
     $children_siblings = array();
     //TODO: It would be best effiency to send just an array of childs to ContentModel
     //		and get all data in 1 query rather than querying many times. New function
     //		to models is needed for this or then edit the one we have now and allow it
     //		to have a possibility to receive ids as array.
     if (isset($family['children'])) {
         foreach ($family['children'] as $child) {
             $contenttypeid = $contentModel->getContentTypeIdByContentId((int) $child);
             $contenttype = $contentTypesModel->getTypeById($contenttypeid);
             if ($contenttype == "idea") {
                 $children[] = $contentModel->getDataAsSimpleArray((int) $child);
             } else {
                 $children_siblings[] = $contentModel->getDataAsSimpleArray((int) $child);
             }
             // $i++;
         }
     }
     $parents = array();
     $parent_siblings = array();
     if (isset($family['parents'])) {
         foreach ($family['parents'] as $parent) {
             $contenttypeid = $contentModel->getContentTypeIdByContentId((int) $parent);
             $contenttype = $contentTypesModel->getTypeById($contenttypeid);
             if ($contenttype == "idea") {
                 $parents[] = $contentModel->getDataAsSimpleArray((int) $parent);
             } else {
                 $parent_siblings[] = $contentModel->getDataAsSimpleArray((int) $parent);
             }
         }
     }
     // Here we get the rival solutions for a solution
     $rivals = array();
     if ($contentType == "idea" && isset($family['parents'])) {
         $i = 0;
         // First here is checked the parents of this solution (=the problem
         // or the future info)
         foreach ($family['parents'] as $parent) {
             // Get the family of the problem or future info
             $parents_family = $contentHasContentModel->getContentFamilyTree((int) $parent);
             // Get the children of the problem or future info
             if (isset($parents_family['children'])) {
                 // Going through the children
                 foreach ($parents_family['children'] as $parent_child) {
                     // Those children are rivals which are not this solution
                     // which is currently viewed
                     if ((int) $parent_child != $id) {
                         $rivals[$i] = $contentModel->getDataAsSimpleArray((int) $parent_child);
                     }
                 }
             }
             $i++;
         }
     }
     // get comments data
     // $commentList = $comment->getAllByContentId($id, $page, $count);
     /*$commentList = $comment->getCommentsByContent($id);
       
       $commentsSorted = array();
       $this->getCommentChilds($commentList, $commentsSorted, 0, 0, 3);
       
       // Get total comment count
       $commentCount = $comment->getCommentCountByContentId($id);
       
       // Calculate total page count
       $pageCount = ceil($commentCount / $count);
       
       // Custom pagination to fix memory error on large amount of data
       $paginator = new Zend_View();
       $paginator->setScriptPath('../application/views/scripts');
       $paginator->pageCount = $pageCount;
       $paginator->currentPage = $page;
       $paginator->pagesInRange = 10;*/
     // get content industries -- will be updated later.
     /*$cntHasIndModel = new Default_Model_ContentHasIndustries();
       $hasIndustry = $cntHasIndModel->getIndustryIdOfContent($id);
       
       $industriesModel = new Default_Model_Industries();
       $industriesArray = $industriesModel->getAllContentIndustryIds($hasIndustry);*/
     // roll values to an array
     /*$industries = array();
               foreach ($industriesArray as $industry) {
                   $value = $industriesModel->getNameById($industry);
                   // $industriesModel->getNameById($industry);
       
                  if (!empty($value)) {
                       $industries[] = $value;
                   }
               }*/
     // Check if and when the content is modified and if its more than 10minutes ago add for the view
     $dateCreated = strtotime($contentData['created_cnt']);
     $dateModified = strtotime($contentData['modified_cnt']);
     $modified = 0;
     if (($dateModified - $dateCreated) / 60 > 10) {
         $modified = $contentData['modified_cnt'];
     }
     // Comment module
     $comments = new Oibs_Controller_Plugin_Comments("content", $id);
     $this->view->jsmetabox->append('commentUrls', $comments->getUrls());
     // enable comment form
     if ($auth->hasIdentity() && $contentData['published_cnt'] == 1) {
         $comments->allowComments(true);
     }
     $comments->loadComments();
     //$contentData['references_cnt'];
     $contentData['references_cnt'] = Oibs_Controller_Plugin_Utils::clickable($contentData['references_cnt'], true);
     $contentData['body_cnt'] = Oibs_Controller_Plugin_Utils::clickable($contentData['body_cnt']);
     // Inject data to view
     $this->view->files = $files;
     $this->view->id = $id;
     $this->view->userImage = $userImage;
     $this->view->comments = $comments;
     $this->view->user_can_rate = $user_can_rate;
     $this->view->user_is_owner = $user_is_owner;
     $this->view->usrId = $usrId;
     $this->view->contentData = $contentData;
     $this->view->modified = $modified;
     $this->view->userData = $userData;
     $this->view->views = $views;
     $this->view->isTranslated = $isTranslated;
     $this->view->languageName = $languageName;
     $this->view->gtranslateLangPair = $gtranslateLangPair;
     $this->view->tags = $tags;
     $this->view->links = $links;
     $this->view->parents = $parents;
     $this->view->parent_siblings = $parent_siblings;
     $this->view->children = $children;
     $this->view->children_siblings = $children_siblings;
     $this->view->rivals = $rivals;
     $this->view->contentType = $contentType;
     //$this->view->campaigns          = $campaigns;
     $this->view->viewers = $this->getViewers($id);
     $this->view->boxStates = $this->getBoxStates();
     // Inject title to view
     $this->view->title = $this->view->translate('index-home') . " - " . $contentData['title_cnt'];
 }
예제 #13
0
 public function getUserViewedContents($id_usr, $limit = 10)
 {
     $select = $this->select()->from($this, 'id_cnt_vws')->setIntegrityCheck(false)->joinLeft('cnt_has_usr', 'id_cnt_vws = id_cnt', array())->where('id_usr != ?', $id_usr)->where('id_usr_vws = ?', $id_usr)->where('modified_vws is not null')->order('modified_vws DESC')->limit($limit);
     $rowset = $this->fetchAll($select);
     $contentModel = new Default_Model_Content();
     return $contentModel->getContentRows($rowset->toArray(), 'id_cnt_vws', true);
 }
예제 #14
0
 /**
  *	resultAction
  *
  *	Gets search results.
  *
  */
 function resultAction()
 {
     // assuming that the CleanQuery plugin has already stripped empty parameters
     // regenerate URI
     if (isset($_GET) && is_array($_GET) && !empty($_GET)) {
         $path = '';
         array_walk($_GET, array('SearchController', 'encodeParam'));
         foreach ($_GET as $key => $value) {
             if ($key != 'submit' && $key != 'submitsearch') {
                 $path .= '/' . $key . '/' . $value;
             }
         }
         $uri = $_SERVER['REQUEST_URI'];
         $path = substr($uri, 0, strpos($uri, '?')) . $path;
         $this->getResponse()->setRedirect($path, $this->_permanent ? 301 : 302);
         $this->getResponse()->sendResponse();
         return;
     }
     $params = $this->getRequest()->getParams();
     $data = array();
     // Get page number and items per page
     $page = isset($params['page']) ? $params['page'] : 1;
     $count = isset($params['count']) ? $params['count'] : 10;
     // Get list order value
     $order = isset($params['order']) ? $params['order'] : 'created';
     // disabled for now...
     // Search params
     //$search = isset($params['q']) ? $params['q'] : null;
     // quick fix enables the search string to last to the next page as well
     /****************************************************/
     $search_space = new Zend_Session_Namespace('search');
     if (isset($params['q'])) {
         $search_space->query = $params['q'];
     }
     $search = $search_space->query;
     /****************************************************/
     // Get data and content result count
     $contentModel = new Default_Model_Content();
     $data = $contentModel->getSearchResult($search, $page, $count, $order);
     $contentCount = $contentModel->getContentCountBySearch($search);
     $results = array();
     // gather other content data and insert to results array
     if (isset($data[0])) {
         $contentHasTagModel = new Default_Model_ContentHasTag();
         $contentRatingsModel = new Default_Model_ContentRatings();
         $i = 0;
         foreach ($data as $content) {
             $results[$i] = $content;
             $results[$i]['tags'] = $contentHasTagModel->getContentTags($content['id_cnt']);
             $results[$i]['ratingdata'] = $contentRatingsModel->getPercentagesById($content['id_cnt']);
             $i++;
         }
     }
     // Calculate total page count
     $pageCount = ceil($contentCount / $count);
     // Custom pagination to fix memory error on large amount of data
     $paginator = new Zend_View();
     $paginator->setScriptPath('../application/views/scripts');
     $paginator->pageCount = $pageCount;
     $paginator->currentPage = $page;
     $paginator->pagesInRange = 10;
     $this->view->search = $search;
     $this->view->page = $page;
     $this->view->contentPaginator = $paginator;
     $this->view->contentData = $results;
 }
예제 #15
0
 /**
  *	Show mainpage and list newest and most viewed ideas and problems
  */
 function indexAction()
 {
     // Variable for number recent campaigns to be sent to view
     $recentCampaignsCount = 0;
     $this->view->title = "index-home";
     // Get cache from registry
     $cache = Zend_Registry::get('cache');
     // $contentTypesModel = new Default_Model_ContentTypes();
     // $userModel = new Default_Model_User();
     // Load recent posts from cache
     $cachePosts = 'IndexPosts_' . $this->view->language;
     if (!($result = $cache->load($cachePosts))) {
         $contentModel = new Default_Model_Content();
         $contentHasTagModel = new Default_Model_ContentHasTag();
         // get data
         //($cty = 'all', $page = 1, $count = -1, $order = 'created', $lang = 'en', $ind = 0)
         $recentposts_raw = $contentModel->listRecent('all', 12, -1, 'created', $this->view->language, -1);
         $recentposts = array();
         $i = 0;
         // gather data for recent posts
         foreach ($recentposts_raw as $post) {
             $recentposts[$i] = $post;
             $recentposts[$i]['tags'] = $contentHasTagModel->getContentTags($post['id_cnt']);
             $i++;
         }
         // Save recent posts data to cache
         $cache->save($recentposts, $cachePosts);
     } else {
         $recentposts = $result;
     }
     // Load most popular tags from cache
     if (!($result = $cache->load('IndexTags'))) {
         $tagsModel = new Default_Model_Tags();
         $tags = $tagsModel->getPopular(20);
         /*
         // resize tags
         foreach ($tags as $k => $tag) {
             $size = round(50 + ($tag['count'] * 30));
             if ($size > 300) {
                 $size = 300;
             }
             $tags[$k]['tag_size'] = $size;
         }
         */
         // Action helper for tags
         $tags = $this->_helper->tagsizes->popularTagCalc($tags);
         // Action helper for define is tag running number divisible by two
         $tags = $this->_helper->tagsizes->isTagDivisibleByTwo($tags);
         // Save most popular tags data to cache
         $cache->save($tags, 'IndexTags');
     } else {
         $tags = $result;
     }
     // Laod most active users from cache
     if (!($result = $cache->load('IndexUsers'))) {
         $contentHasUserModel = new Default_Model_ContentHasUser();
         $activeusers = $contentHasUserModel->getMostActive(5);
         // Save most active users data to cache
         $cache->save($activeusers, 'IndexUsers');
     } else {
         $activeusers = $result;
     }
     // inject data to view
     if (isset($recentposts)) {
         $this->view->recentposts = $recentposts;
     } else {
         $this->view->recentposts = '';
     }
     // Get recent campaigns
     $grpmodel = new Default_Model_Groups();
     $campaignModel = new Default_Model_Campaigns();
     $recentcampaigns = $campaignModel->getRecent(5);
     // If you find (time to think of) a better way to do this, be my guest.
     $cmps_new = array();
     foreach ($recentcampaigns as $cmp) {
         $grp = $grpmodel->getGroupData($cmp['id_grp_cmp']);
         $cmp['group_name_grp'] = $grp['group_name_grp'];
         $cmps_new[] = $cmp;
     }
     // Get recent groups
     $grps = $grpmodel->getRecent(5);
     $grps_new = array();
     $grpadm = new Default_Model_GroupAdmins();
     foreach ($grps as $grp) {
         $adm = $grpadm->getGroupAdmins($grp['id_grp']);
         $grp['id_admin'] = $adm[0]['id_usr'];
         $grp['login_name_admin'] = $adm[0]['login_name_usr'];
         $grps_new[] = $grp;
     }
     $this->view->campaigns = $cmps_new;
     $this->view->groups = $grps_new;
     $this->view->poptags = $tags;
     $this->view->activeusers = $activeusers;
     $this->view->isLoggedIn = Zend_Auth::getInstance()->hasIdentity();
     $this->view->recentCampaignsCount = $recentCampaignsCount;
 }
예제 #16
0
파일: RssReader.php 프로젝트: jannev/site
 private function getContentTitle()
 {
     $cntModel = new Default_Model_Content();
     $cnt = $cntModel->getContentRow($this->id);
     return $cnt['title_cnt'];
 }
예제 #17
0
 public function deleteNotificationCache($id_cnt = 0, $user_id = 0)
 {
     $cache = Zend_Registry::get('cache');
     if ($id_cnt > 0) {
         if ($user_id == 0) {
             $contentModel = new Default_Model_Content();
             $owner = $contentModel->getOwnerId($id_cnt);
             $cache->remove('Notifications_' . $owner);
             $favouriteModel = new Default_Model_UserHasFavourites();
             $idlist = $favouriteModel->getAllUserIdsFromFavouriteContent($id_cnt);
             foreach ($idlist as $id) {
                 $cache->remove('Notifications_' . $id['id_usr']);
             }
         } else {
             $cache->remove('Notifications_' . $user_id);
         }
         return true;
     }
     return false;
 }