示例#1
0
 /**
  *   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);
 }
示例#2
0
文件: RssReader.php 项目: jannev/site
 private function isContentAdmin($userId)
 {
     $chuModel = new Default_Model_ContentHasUser();
     $owners = $chuModel->getContentOwners($this->id);
     if ($owners['id_usr'] == $userId) {
         $this->admin = true;
         return true;
     }
     return false;
 }
示例#3
0
 /**
  * removelinkAction
  *
  * Remove link to content from campaign
  *
  * @author Mikko Korpinen
  */
 public function removelinksAction()
 {
     // Get authentication
     $auth = Zend_Auth::getInstance();
     // If user has identity
     if ($auth->hasIdentity()) {
         $cmpId = $this->_request->getParam('cmpid');
         $this->view->cmpid = $cmpId;
         $cntId = $this->_request->getParam('cntid');
         $this->view->cntid = $cntId;
         if (!(isset($cmpId) && isset($cntId))) {
             $redirectUrl = $this->_urlHelper->url(array('controller' => 'campaign', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
             $this->_redirector->gotoUrl($redirectUrl);
         }
         $cntHasUsrModel = new Default_Model_ContentHasUser();
         $usrId = $auth->getIdentity()->user_id;
         if (!$cntHasUsrModel->contentHasOwner($usrId, $cntId)) {
             $redirectUrl = $this->_urlHelper->url(array('controller' => 'account', 'action' => 'view', 'user' => $auth->getIdentity()->username, 'language' => $this->language), 'lang_default', true);
             $this->_redirector->gotoUrl($redirectUrl);
         }
         $cmphascntmodel = new Default_Model_CampaignHasContent();
         $cmphascntmodel->removeContentFromCampaign($cmpId, $cntId);
         // TODO:
         // Tell the user that the unlink was created.
         // Redirect back to the user page
         $redirectUrl = $this->_urlHelper->url(array('controller' => 'account', 'action' => 'view', 'user' => $auth->getIdentity()->username, 'language' => $this->language), 'lang_default', true);
         $this->_redirector->gotoUrl($redirectUrl);
     } 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);
     }
 }
示例#4
0
 public function getUsersWhoFollowContent($id_cnt)
 {
     $favouriteModel = new Default_Model_UserHasFavourites();
     $userProfileModel = new Default_Model_UserProfiles();
     $contentHasUserModel = new Default_Model_ContentHasUser();
     $favouriteIds = $this->_simplifyArray($favouriteModel->getAllUserIdsFromFavouriteContent($id_cnt));
     $ownerIds = $this->_simplifyArray($contentHasUserModel->getContentOwners($id_cnt));
     $mergedIds = array_merge($favouriteIds, $ownerIds);
     $followingUsers = array_keys($userProfileModel->getUsersWhoFollowContents($mergedIds));
     return $followingUsers;
 }
示例#5
0
 /**
  * removeAction - Remove specified comment by content owner or comment owner
  *
  * @author Mikko Korpinen
  */
 public function removeAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         // Get requests
         $params = $this->getRequest()->getParams();
         $cmtid = $params['cmtid'];
         $cntid = $params['cntid'];
         $usrid = $auth->getIdentity()->user_id;
         $cntHasUsrModel = new Default_Model_ContentHasUser();
         $user_is_content_owner = $cntHasUsrModel->contentHasOwner($usrid, $cntid);
         $commentmodel = new Default_Model_Comments();
         $user_is_comment_owner = $commentmodel->userIsOwner($usrid, $cmtid);
         if ($user_is_content_owner || $user_is_comment_owner) {
             $flagmodel = new Default_Model_CommentFlags();
             $flags = $flagmodel->getFlagsByCommentId($cmtid);
             $commentExists = $commentmodel->commentExists($cmtid);
             if ($commentExists) {
                 if (count($flags) > 0) {
                     $flagmodel->removeFlagsByCommentId($cmtid);
                 }
                 $commentmodel->removeCommentText($cmtid);
             }
         }
         $redirectUrl = $this->_urlHelper->url(array('content_id' => $cntid, 'language' => $this->view->language), 'content_shortview', true);
         $this->_redirector->gotoUrl($redirectUrl);
     } else {
         $redirectUrl = $this->_urlHelper->url(array('language' => $this->view->language), 'index', true);
         $this->_redirector->gotoUrl($redirectUrl);
     }
 }
示例#6
0
文件: Content.php 项目: jannev/site
 /**
  *   getDataForView
  *
  *   Get content by id.
  *   Is this function used anywhere?
  *   If not, this function should probably be removed.
  *
  *   @param ineteger $id
  *   @return array
  */
 public function getDataForView($id = 0)
 {
     // Array for content data
     $data = array();
     // Find content row by id
     //$rowset = $this->find((int)$id)->current();
     $select = $this->_db->select()->from(array('contents_cnt' => 'contents_cnt'), array('*'))->where('id_cnt = ?', $id);
     $result = $this->_db->fetchAll($select);
     // If content was found
     if (count($result) == 1) {
         $data['Content']['Data'] = $result[0];
         // Find Ratings
         //$select_ratings = $this->select()->from('content_ratings_crt', array('SUM(rating_crt) AS rate_crt'));
         //$ratings = $rowset->findDependentRowset('Default_Model_ContentRatings', 'RatingsContent', $select_ratings)->toArray();
         $ratings = new Default_Model_ContentRatings();
         $rating = $ratings->getById($id);
         // Find content owners
         //$content_owner = $rowset->findManyToManyRowset('Default_Model_User', 'Default_Model_ContentHasUser');
         $cntHasUser = new Default_Model_ContentHasUser();
         $owners = $cntHasUser->getContentOwners($id);
         // Find owners
         $userModel = new Default_Model_User();
         $i = 0;
         foreach ($owners as $owner) {
             $data['Content']['Data']['Owners'][$i] = $userModel->getSimpleUserDataById($owner);
             $i++;
         }
         // Find content comments
         //$select_comment = $this->select()->order('created_cmt ASC');
         //$comments = $rowset->findDependentRowset('Default_Model_Comments', 'CommentContent', $select_comment);
         $commentModel = new Default_Model_Comments();
         $comments = $commentModel->getAllByContentId($id);
         /*  comment owner username is fetched in the previous query, no need for this anymore
             			 // Array for comment owners
             			 $comment_owners = array();
             
             			 // Go through all comments
             			 foreach($comments as $cmt)
             			 {
             			 // Find comment owner
             			 $usr = $cmt->findDependentRowset('Default_Model_User', 'CommentUser')->toArray();
             
             			 // If owner found
             			 if(!empty($usr))
             			 {
             			 // Specify comment owner
             			 $comment_owners[$usr[0]['id_usr']] = $usr[0];
             			 } // end if
             			 } // end foreach
             			 */
         // Find content keywords
         //$tags = $rowset->findManyToManyRowset('Default_Model_Tags', 'Default_Model_ContentHasTag')->toArray();
         $cntHasTag = new Default_Model_ContentHasTag();
         $tags = $cntHasTag->getContentTags($id);
         // Find content links - needs updating to this version
         $links = array();
         //$rowset->findDependentRowset('Default_Model_Links')->toArray();
         // Find related content
         //$$related_content = $rowset->findManyToManyRowset('Default_Model_Content', 'Default_Model_ContentHasContent', 'ParentContent', 'ChildContent')->toArray();
         $contentHasContent = new Default_Model_ContentHasContent();
         $familyTree = $contentHasContent->getContentFamilyTree($id);
         // echo"<pre>"; print_r($tagArray); echo"</pre>"; die;
         // Gather and format content data a bit
         $data['Content']['Data']['rating'] = $rating;
         //$data['Content']['Data']['owner'] = $owner;
         $data['Content']['Tags'] = $tags;
         $data['Content']['Links'] = $links;
         $data['Content']['FamilyTree'] = $familyTree;
         $data['Comments']['Data'] = $comments;
         //echo"<pre>"; print_r($comments); echo"</pre>"; die;
         //$data['Comments']['Posters']        = $comment_owners;
     }
     return $data;
 }
示例#7
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;
 }
示例#8
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'];
 }
示例#9
0
 /**
  *	Show mainpage and list newest and most viewed ideas and problems
  */
 function indexAction()
 {
     $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->tagCalc($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(10);
         // 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 = '';
     }
     $this->view->poptags = $tags;
     $this->view->activeusers = $activeusers;
     $this->view->isLoggedIn = Zend_Auth::getInstance()->hasIdentity();
 }
示例#10
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'];
 }
示例#11
0
文件: User.php 项目: jannev/site
 /**
  * sortUsersByContentInfo
  * 
  * Sorts $userIdList by $sort
  * 
  * @param ZEND SQL search query returning array of user id:s
  * @param string $sort
  * @return $resultList
  * @author Jari Korpela
  */
 public function sortUsersByContentInfo($search, $sort, $list, $limit)
 {
     $content = new Default_Model_ContentHasUser();
     $select = $content->select()->from('cnt_has_usr', array('id_usr'))->where('id_usr IN (?)', $search)->order(array($sort, 'id_usr'))->group('id_usr');
     if ($limit) {
         $select->limit($limit, 0);
     }
     //print_r($select->assemble());echo "\n";
     $result = $this->simplifyArray($content->_db->fetchAll($select), 'id_usr');
     if ($list) {
         $result = $this->addMissingIdsToResult($result, $this->simplifyArray($content->_db->fetchAll($search), 'id_usr'), $list);
     }
     return $result;
 }