public function indexAction() { // Compile all social info. $owner_social = array(); $social_types = $this->config->fa->social->toArray(); $escaper = new \Phalcon\Escaper(); foreach ($social_types as $social_category => $social_items) { foreach ($social_items as $social_type => $social_info) { $owner_social_item = $this->owner->contact->{$social_type}; if (empty($owner_social_item)) { continue; } $social_image = $this->url->getStatic('img/contact/' . $social_type . '.gif'); $social_title = $social_info['name'] . ': ' . $escaper->escapeHtmlAttr($owner_social_item); if ($social_info['format']) { $social_url = sprintf($social_info['format'], $escaper->escapeUrl($owner_social_item)); $owner_social[] = '<a href="' . $social_url . '" target="_blank"><img class="contacticon" src="' . $social_image . '" title="' . $social_title . '"></a>'; } else { $owner_social[] = '<img class="contacticon" src="' . $social_image . '" title="' . $social_title . '">'; } } } $this->view->owner_social = $owner_social; // Commission information $has_commissions = $this->owner->commission_types->count() == 0; $this->view->has_commissions = $has_commissions; $this->view->accept_trades = $this->owner->getVariable('accept_trades'); $this->view->accept_commissions = $this->owner->getVariable('accept_commissions'); // Maturity Rating Filter if ($this->fa->canSeeArt('adult')) { $maturity_filter = array(Upload::RATING_GENERAL, Upload::RATING_ADULT, Upload::RATING_MATURE); } elseif ($this->fa->canSeeArt('mature')) { $maturity_filter = array(Upload::RATING_GENERAL, Upload::RATING_MATURE); } else { $maturity_filter = array(Upload::RATING_GENERAL); } // Profile picture. if ($this->owner->profile_pic) { $profile_pic = Upload::find($this->owner->profile_pic); if ($profile_pic instanceof Upload && in_array($profile_pic->rating, $maturity_filter)) { if ($profile_pic->rating == Upload::RATING_ADULT) { $this->fa->setPageHasMatureContent(); } $this->view->profile_pic = $profile_pic; } } // Featured picture if ($this->owner->featured) { $featured_pic = Upload::find($this->owner->featured); if ($featured_pic instanceof Upload && in_array($featured_pic->rating, $maturity_filter)) { if ($featured_pic->rating == Upload::RATING_ADULT) { $this->fa->setPageHasMatureContent(); } $this->view->featured_pic = $featured_pic; } } // Upload data $uploads = $this->em->createQuery('SELECT up FROM Entity\\Upload up WHERE up.is_scrap = 0 AND up.rating IN (:ratings) AND up.user_id = :user_id ORDER BY up.id DESC')->setParameter('ratings', $maturity_filter)->setParameter('user_id', $this->owner->id)->setMaxResults(14)->execute(); if ($uploads) { foreach ($uploads as $row) { if ($row->rating == Upload::RATING_ADULT) { $this->fa->setPageHasMatureContent(); } } $this->view->latest_uploads = $uploads; } // Favorite filters $fav_maturity_filter = $maturity_filter; if ($this->acl->isAllowed('administer all') || $this->user->id == $this->owner->id) { $fav_filter = 'n'; } else { $fav_filter = $this->owner->getVariable('hide_favorites'); } switch ($fav_filter) { case 'e': // hide everything $fav_maturity_filter = null; break; case 'ma': // hide adult+mature unset($fav_maturity_filter[Upload::RATING_MATURE], $fav_maturity_filter[Upload::RATING_ADULT]); break; case 'a': // hide adult unset($fav_maturity_filter[Upload::RATING_ADULT]); break; case 'n': // hide nothing // hide nothing default: // No changes. break; } // Favorites if (!empty($fav_maturity_filter)) { $latest_faves = $this->em->createQuery('SELECT f, up FROM Entity\\Favorite f JOIN f.upload up WHERE f.user_id = :user_id AND up.rating IN (:ratings) ORDER BY f.id DESC')->setParameter('user_id', $this->owner->id)->setParameter('ratings', $fav_maturity_filter)->setMaxResults(14)->execute(); if ($latest_faves) { foreach ($latest_faves as $row) { if ($row->rating == Upload::RATING_ADULT) { $this->fa->setPageHasMatureContent(); } } $this->view->latest_faves = $latest_faves; } } // Watched by / Is watching counts $watched_by_count = $this->em->createQuery('SELECT COUNT(w.id) FROM Entity\\Watch w WHERE w.target_id = :user_id')->setParameter('user_id', $this->owner->id)->getSingleScalarResult(); $this->view->num_watched_by = $watched_by_count; $watching_count = $this->em->createQuery('SELECT COUNT(w.id) FROM Entity\\Watch w WHERE w.user_id = :user_id')->setParameter('user_id', $this->owner->id)->getSingleScalarResult(); $this->view->num_watching = $watching_count; // Most recent journal $journal = $this->em->createQuery('SELECT j FROM Entity\\Journal j WHERE j.user_id = :user_id ORDER BY j.id DESC')->setParameter('user_id', $this->owner->id)->setMaxResults(1)->getOneOrNullResult(); $this->view->journal = $journal; // Shouts $shouts = $this->em->createQuery('SELECT s, us FROM Entity\\Shout s JOIN s.sender us WHERE s.recipient_id = :user_id ORDER BY s.id DESC')->setParameter('user_id', $this->owner->id)->setMaxResults(12)->execute(); $this->view->shouts = $shouts; // New shout form. $shout_form_config = $this->current_module_config->forms->shout->toArray(); $shout_form_config['action'] = $this->url->routeFromHere(array('action' => 'shout')); $shout_form = new \FA\Form($shout_form_config); $this->view->shout_form = $shout_form; }
public function favoriteAction() { $csrf_key = $this->getParam('key'); // Verify this isn't a cross-domain attack before proceeding if ($this->csrf->verify($csrf_key, '_upload_content')) { // TODO: Check comment hiding rate limit here! $upload_id = (int) $this->getParam('id'); $upload = Upload::find($upload_id); // Verifying if the Upload exists if (!$upload instanceof Upload) { throw new \FA\Exception('Upload not found!'); } $favorite = $this->em->createQuery('SELECT f FROM \\Entity\\Favorite f WHERE f.upload_id = :upload_id')->setParameter('upload_id', $upload->id)->getArrayResult(); // Verify the user can even progress further //self::_userCheck($upload); // If the favorite exists, delete it. If not, create it! // TODO: Look into soft deleting if (count($favorite) > 0) { \FA\Utilities::print_r($favorite); } else { $favorite = new Favorite(); $favorite->upload = $upload; $favorite->user = $this->user; $favorite->save(); } // Redirect to the Upload page to our comment! // TODO: Add a way to auto-lock on to the comment. Maybe a perma-link style approach? return $this->redirectToName('upload_view', array('id' => $upload->id)); } }
public function indexAction() { $upload_id = (int) $this->getParam('id'); // Grab the submission information (Which includes the uploader's info and comments) $upload = Upload::find($upload_id); if (!$upload instanceof Upload) { throw new \FA\Exception('Upload not found!'); } $view = $this->view; $view->upload = $upload; $view->is_favorited = false ? '+Favorite' : '-Favorite'; $view->comment_csrf_str = $this->csrf->generate('_upload_comments'); $view->upload_csrf_str = $this->csrf->generate('_upload_content'); $view->file_mime = $upload->getMIME(); $view->keyword_arr = $upload->getKeywords(); $view->created_at = \FA\Utilities::fa_date_format($upload->created_at, $upload->user->getTimezoneDiff()); if ($this->user != NULL) { // Determine if the user is the owner of the upload $view->is_owner = $upload->user->id == $this->user->id; // Get if the user prefer fullview first $view->fullview = $this->user->fullview ? 'true' : 'false'; // Apparently, Volt doesn't seem to want convert straight to string } // Comments! // Create the comment forms $form_config = $this->current_module_config->forms->upload_comment->toArray(); $form_config['action'] = $this->url->named('upload_view', array('id' => $upload->id)) . '/comment/new'; // Add the action so they can actually comment! $view->comment_form = new \FA\Form($form_config); // Reply form. Uses the same config, but different id. $form_config['action'] = ''; // No need for this. $form_config['id'] = 'reply_form'; $view->reply_form = new \FA\Form($form_config); // Edit form. Same story. $form_config['id'] = 'edit_form'; $view->edit_form = new \FA\Form($form_config); // Construct the comments $comment_ents = \Entity\UploadComment::getRepository()->findBy(array('upload_id' => $upload->id), array('id' => 'DESC')); // TODO: Move to CommentTrait for a more global use // Initialize our upload comment array $up_comments = array(); foreach ($comment_ents as $comment) { // Get the comment's parents $parent_path = array_reverse($comment->getParentPath()); // Map the array, creating new arrays along the way $results = self::_mapArray($parent_path, array($comment), 'a'); // Merge our new array with our overall one! $up_comments = array_merge_recursive($results, $up_comments); } // Flatten the array to allow Volt to run through it without issue $view->upload_comments = \Nette\Utils\Arrays::flatten($up_comments); // Only need to do these when users with access need to see these stats. if ($this->acl->isAllowed('administer all')) { $view->total_deleted_comments = 0; $view->total_deleted_comments_by_admin = 0; $view->total_deleted_comments_by_uploader = 0; $view->total_deleted_comments_by_poster = 0; // Get the total comments deleted foreach ($comment_ents as $comment) { $deleting_user = $comment->deleting_user; if ($deleting_user != NULL) { // Post has been deleted $view->total_deleted_comments++; // Determine who deleted it! if ($deleting_user->id == $comment->user_id) { // Poster deleted it! $view->total_deleted_comments_by_poster++; } elseif ($deleting_user->id == $upload->user . id) { // Uploader deleted it! $view->total_deleted_comments_by_uploader++; } elseif ($this->acl->userAllowed('administer all', $deleting_user)) { // Admin deleted it! $view->total_deleted_comments_by_admin++; } } } } // Grab the EXIF info (If any) and pass it to the view // TODO: Will need to determine if we need to include more or less information //$exif = exif_read_data($upload->getFullPath(), 'EXIF'); //$view->exif_info = ($exif ? $exif : ''); // Legacy stuff // TODO: Move this off to either ACL or some other config. Most if not all is controller specific $view->edit_duration_sec = \Entity\UploadComment::getEditDuration(); $view->STATIC_ASSET_MODIFICATION_DATE = self::STATIC_ASSET_MODIFICATION_DATE; // Assuming this is for versioning. }