/** * Render content. * * @return string */ public function render() { $attributes = array(); // Custom URL $url = $this->url ? $this->url : Anqh::page_meta('url'); if ($url) { $attributes['addthis:url'] = $url; } // Custom title $title = $this->title ? $this->title : Anqh::page_meta('title'); if ($title) { $attributes['addthis:title'] = $title; } ob_start(); ?> <div class="addthis_toolbox addthis_floating_style addthis_32x32_style"<?php echo HTML::attributes($attributes); ?> > <a class="addthis_button_facebook"></a> <a class="addthis_button_twitter"></a> <a class="addthis_button_google_plusone_share"></a> <a class="addthis_button_email"></a> </div> <script> var addthis_config = { data_track_clickback: true, pubid: '<?php echo Kohana::$config->load('site.share'); ?> ' } , addthis_share = { templates: { twitter: '{{title}}: {{url}} (via @<?php echo Kohana::$config->load('site.share'); ?> )' } }; </script> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=<?php echo Kohana::$config->load('site.share'); ?> "></script> <?php return ob_get_clean(); }
/** * Construct controller */ public function after() { if ($user = self::_get_user(false)) { Anqh::page_meta('type', 'profile'); Anqh::page_meta('title', HTML::chars($user->username)); Anqh::page_meta('profile:username', HTML::chars($user->username)); switch ($user->gender) { case 'f': Anqh::page_meta('profile:gender', 'female'); break; case 'm': Anqh::page_meta('profile:gender', 'male'); break; } if ($image = $user->get_image_url()) { Anqh::page_meta('image', $image); } Anqh::share(true); } parent::after(); }
/** * Controller default action */ public function action_index() { // Newsfeed if ($newsfeed = Arr::get($_GET, 'newsfeed')) { // Newsfeed changed if (Visitor::$user && in_array($newsfeed, array(View_Newsfeed::TYPE_ALL, View_Newsfeed::TYPE_FRIENDS))) { Visitor::$user->setting('ui.newsfeed', $newsfeed); Visitor::$user->save(); } // Ajax if ($this->_request_type === Controller::REQUEST_AJAX) { echo $this->section_newsfeed(); exit; } } // Build page Anqh::page_meta('type', 'website'); // Newsfeed $this->view->add(View_Page::COLUMN_CENTER, $this->section_newsfeed()); // Login if (!Visitor::$user) { $this->view->add(View_Page::COLUMN_LEFT, $this->section_signin()); } // Shouts $this->view->add(View_Page::COLUMN_LEFT, $this->section_shouts()); // News $this->view->add(View_Page::COLUMN_RIGHT, $this->section_news()); // Birthdays or friend suggestions if (Visitor::$user && rand(0, 10) < 5) { $this->view->add(View_Page::COLUMN_RIGHT, $this->section_friend_suggestions()); } else { $this->view->add(View_Page::COLUMN_RIGHT, $this->section_birthdays()); } // Online // $this->view->add(View_Page::COLUMN_RIGHT, $this->section_online()); }
/** * Action: image */ public function action_image() { $gallery_id = (int) $this->request->param('gallery_id'); $image_id = $this->request->param('id'); /** @var Model_Gallery $gallery */ $gallery = Model_Gallery::factory($gallery_id); if (!$gallery->loaded()) { throw new Model_Exception($gallery, $gallery_id); } Permission::required($gallery, Model_Gallery::PERMISSION_READ); $images = $gallery->images(); // Find current, previous and next images $i = 0; /** @var Model_Image $next */ /** @var Model_Image $previous */ /** @var Model_Image $current */ $previous = $next = $current = null; foreach ($images as $image) { $i++; if (!is_null($current)) { // Current was found last round $next = $image; $i--; break; } else { if ($image->id == $image_id) { // Current found now $current = $image; // Fix state to loaded to perform update instead of insert when saving $current->state(AutoModeler::STATE_LOADED); } else { // No current found $previous = $image; } } } // Show image if (!is_null($current)) { // Comments section if (Permission::has($gallery, Model_Gallery::PERMISSION_COMMENTS)) { $errors = array(); $values = array(); // Handle comment if (Permission::has($gallery, Model_Gallery::PERMISSION_COMMENT) && $_POST) { try { $comment = Model_Image_Comment::factory()->add(Visitor::$user->id, null, Arr::get($_POST, 'comment'), Arr::get($_POST, 'private'), $current); $current->comment_count++; $current->save(); if ($current->author_id != Visitor::$user->id) { $target = Model_User::find_user($current->author_id); Notification_Galleries::image_comment(Visitor::$user, $target, $current, $comment->comment); } $gallery->comment_count++; $gallery->save(); if (!$comment->private) { // Noted users foreach ($current->notes() as $note) { if ($note->user_id) { $target = Model_User::find_user($note->user_id); Notification_Galleries::image_comment(Visitor::$user, $target, $current, $comment->comment); } } // Newsfeed NewsfeedItem_Galleries::comment(Visitor::$user, $gallery, $current); } // Redirect back to image if not ajax if ($this->_request_type !== Controller::REQUEST_AJAX) { $this->request->redirect(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $current->id, 'action' => ''))); return; } } catch (Validation_Exception $e) { $errors = $e->array->errors('validation'); $values = $comment; } } else { if (Visitor::$user) { // Clear new comment count? // @TODO: Remove, deprecated after new notification system if ($current->author_id == Visitor::$user->id && $current->new_comment_count > 0) { $current->new_comment_count = 0; $current->save(); } foreach ($current->notes() as $note) { if ($note->user_id == Visitor::$user->id) { $note->state(AutoModeler::STATE_LOADED); $save = false; if ($note->new_comment_count > 0) { $note->new_comment_count = 0; $save = true; } if ($note->new_note > 0) { $note->new_note = null; $save = true; } if ($save) { $note->save(); } } } } } // Get view $section_comments = $this->section_image_comments($current); $section_comments->errors = $errors; $section_comments->values = $values; } else { if (!Visitor::$user) { // Guest user $section_comments = $this->section_image_comments_teaser($current->comment_count); } } if (isset($section_comments) && $this->_request_type === Controller::REQUEST_AJAX) { $this->response->body($section_comments); return; } // Build page // Image actions if (Permission::has($gallery, Model_Gallery::PERMISSION_UPDATE)) { $this->view->actions[] = array('link' => Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $current->id, 'action' => 'default')) . '?token=' . Security::csrf(), 'text' => '<i class="icon-home"></i> ' . __('Set gallery default'), 'class' => 'btn-inverse image-default'); } if (Permission::has($current, Model_Image::PERMISSION_DELETE)) { $this->view->actions[] = array('link' => Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $current->id, 'action' => 'delete')) . '?token=' . Security::csrf(), 'text' => '<i class="icon-trash"></i> ' . __('Delete'), 'class' => 'btn-inverse image-delete'); } if (Permission::has($current, Model_Image::PERMISSION_REPORT)) { $this->view->actions[] = array('link' => Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $current->id, 'action' => 'report')), 'text' => '<i class="icon-warning-sign"></i> ' . __('Report'), 'class' => 'btn-inverse dialogify', 'data-dialog-title' => __('Report image')); } // Gallery actions $this->_set_page_actions(Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_CREATE)); $this->_set_gallery($gallery); array_unshift($this->view->tabs, array('link' => Route::model($gallery), 'text' => '« ' . __('Gallery'))); $this->view->tabs['gallery'] = array('link' => Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $current->id)), 'text' => '<i class="icon-camera-retro"></i> ' . __('Photo')); // Event info if ($event = $gallery->event()) { $this->view->subtitle = Controller_Events::_event_subtitle($event); } // Pagination $previous_url = $previous ? Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $previous->id, 'action' => '')) . '#title' : null; $next_url = $next ? Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $next->id, 'action' => '')) . '#title' : null; $this->view->add(View_Page::COLUMN_TOP, $this->section_image_pagination($previous_url, $next_url)); // Image $current->view_count++; $current->save(); $this->view->add(View_Page::COLUMN_TOP, $this->section_image($current, $gallery, $next_url)); // Comments if (isset($section_comments)) { $this->view->add(View_Page::COLUMN_CENTER, $section_comments); } // Share Anqh::page_meta('title', __('Image') . ': ' . $gallery->name); Anqh::page_meta('url', URL::site(Route::url('gallery_image', array('id' => $current->id, 'gallery_id' => $gallery->id, 'action' => '')), true)); if ($current->description) { Anqh::page_meta('description', $current->description); } Anqh::page_meta('image', URL::site($current->get_url('thumbnail'), true)); Anqh::page_meta('twitter:card', 'photo'); Anqh::share(true); } }
/** * Render Open Graph. * * @return string */ protected function _open_graph() { $meta = array(); foreach ((array) Anqh::page_meta() as $key => $value) { $meta[] = strpos($key, 'twitter:') === 0 ? '<meta name="' . $key . '" content="' . HTML::chars($value) . '" />' : '<meta property="' . $key . '" content="' . HTML::chars($value) . '" />'; } return $meta ? implode("\n", $meta) : ''; }
/** * Action: music track */ public function action_track() { $track_id = (int) $this->request->param('id'); // Load track $track = Model_Music_Track::factory($track_id); if (!$track->loaded()) { throw new Model_Exception($track, $track_id); } Permission::required($track, Model_Music_Track::PERMISSION_READ); // Build page $author = $track->author(); $this->view = new View_Page($track->name); $this->view->tab = 'music'; $this->view->subtitle = __('By :user :ago', array(':user' => HTML::user($track->author(), null, null, Route::url('profile_music', array('username' => urlencode($author['username'])))), ':ago' => HTML::time(Date::fuzzy_span($track->created), $track->created))); // Set actions $this->_set_page_actions(false); $this->view->actions[] = array('link' => Route::model($track, 'listen'), 'text' => '<i class="fa fa-play"></i> ' . __('Listen'), 'class' => 'btn btn-primary', 'target' => '_blank', 'rel' => 'nofollow'); $this->view->tabs['music'] = array('link' => Route::model($track), 'text' => $track->type == Model_Music_Track::TYPE_MIX ? __('Mixtape') : __('Track')); if ($track->forum_topic_id) { $this->view->tabs[] = array('link' => Route::url('forum_topic', array('id' => $track->forum_topic_id)), 'text' => __('Forum') . ' »'); } if (Permission::has($track, Model_Music_Track::PERMISSION_UPDATE)) { $this->view->actions[] = array('link' => Route::model($track, 'edit'), 'text' => '<i class="fa fa-edit"></i> ' . __('Edit')); } // Share Anqh::page_meta('type', $track->type == Model_Music_Track::TYPE_MIX ? 'album' : 'song'); Anqh::page_meta('title', $track->name); Anqh::page_meta('url', URL::site(Route::model($track), true)); Anqh::page_meta('description', $track->description); if (Valid::url($track->cover)) { Anqh::page_meta('image', $track->cover); } Anqh::share(true); // Content $this->view->add(View_Page::COLUMN_CENTER, $this->section_track_main($track)); $this->view->add(View_Page::COLUMN_RIGHT, $this->section_track_info($track)); }
/** * Destroy controller. */ public function after() { if ($this->_request_type !== Controller::REQUEST_INITIAL) { // AJAX and HMVC requests $this->response->body((string) $this->response->body()); } else { if ($this->auto_render) { // Normal requests // Footer $section = new View_Events_List(); $section->class .= ' col-sm-4'; $section->title = __('New events'); $section->events = Model_Event::factory()->find_new(10); $this->view->add(View_Page::COLUMN_FOOTER, $section); $section = new View_Topics_List(); $section->class .= ' col-sm-4'; $section->topics = Model_Forum_Topic::factory()->find_by_latest_post(10); $this->view->add(View_Page::COLUMN_FOOTER, $section); $section = new View_Blogs_List(); $section->class .= ' col-sm-4'; $section->title = __('New blogs'); $section->blog_entries = Model_Blog_Entry::factory()->find_new(10); $this->view->add(View_Page::COLUMN_FOOTER, $section); // Ads /* $ads = Kohana::$config->load('site.ads'); if ($ads && $ads['enabled']) { foreach ($ads['slots'] as $ad => $slot) { if ($slot == 'side') { $this->view->add(View_Page::COLUMN_SIDE, View::factory('ads/' . $ad)); } else { Widget::add($slot, View::factory('ads/' . $ad), Widget::MIDDLE); } } }*/ // Theme $theme = $this->session->get('theme'); //Arr::get($_COOKIE, 'theme'); if (!in_array($theme, array_keys(Kohana::$config->load('site.themes')))) { if (Visitor::$user) { $theme = Visitor::$user->setting('ui.theme'); } if (!$theme) { $theme = Kohana::$config->load('site.theme'); } $this->session->set('theme', $theme); } // Do some CSS magic to page class $page_class = array_merge(array('theme-' . $theme, Visitor::$user ? 'authenticated' : 'unauthenticated'), explode(' ', $this->page_class)); $page_class = implode(' ', array_unique($page_class)); // Set the generic page variables $this->view->language = $this->language; $this->view->id = $this->page_id; $this->view->class = $page_class; if ($this->page_actions) { $this->view->tabs = $this->page_actions; } if ($this->page_breadcrumbs) { $this->view->breadcrumbs = $this->page_breadcrumbs; } // Set meta data if (!Anqh::page_meta('title')) { Anqh::page_meta('title', $this->view->title ? $this->view->title : Kohana::$config->load('site.site_name')); } // And finally the profiler stats if (Visitor::$user && Visitor::$user->has_role('admin')) { Widget::add('foot', new View_Generic_Debug()); Widget::add('foot', View::factory('profiler/stats')); } } } parent::after(); }
/** * Action: event */ public function action_event() { $event_id = (int) $this->request->param('id'); // Load event /** @var Model_Event $event */ $event = Model_Event::factory($event_id); if (!$event->loaded()) { throw new Model_Exception($event, $event_id); } Permission::required($event, Model_Event::PERMISSION_READ); // Build page $this->view->title = $event->name; $this->view->subtitle = self::_event_subtitle($event); // Set actions if (Permission::has($event, Model_Event::PERMISSION_UPDATE)) { $this->view->actions[] = array('link' => Route::model($event, 'edit'), 'text' => '<i class="fa fa-edit"></i> ' . __('Edit event')); $this->view->actions[] = array('link' => Route::model($event, 'flyer'), 'text' => '<i class="fa fa-upload"></i> ' . __('Upload flyer'), 'class' => !count($event->flyers()) ? 'btn btn-primary' : null); } if (Permission::has($event, Model_Event::PERMISSION_FAVORITE)) { if ($event->is_favorite(Visitor::$user)) { $this->view->actions[] = array('link' => Route::model($event, 'unfavorite') . '?token=' . Security::csrf(), 'text' => '<i class="fa fa-heart"></i> ' . __('Remove favorite')); } else { $this->view->actions[] = array('link' => Route::model($event, 'favorite') . '?token=' . Security::csrf(), 'text' => '<i class="fa fa-heart"></i> ' . __('Add to favorites'), 'class' => 'btn-lovely favorite-add'); } } // Set tabs $this->view->tab = 'event'; $this->view->tabs['event'] = array('link' => Route::model($event), 'text' => __('Event')); if ($event->author_id) { $this->view->tabs['organizer'] = array('link' => URL::user($event->author_id), 'text' => __('Organizer') . ' »'); } if ($event->stamp_begin < time()) { // Link to gallery only after the event has begun $this->view->tabs[] = array('link' => Route::get('gallery_event')->uri(array('id' => $event->id)), 'text' => __('Gallery') . ' »'); } $this->view->tabs[] = array('link' => Route::get('forum_event')->uri(array('id' => $event->id)), 'text' => __('Forum') . ' »'); // Share Anqh::page_meta('type', 'activity'); Anqh::page_meta('title', $event->name); Anqh::page_meta('url', URL::site(Route::get('event')->uri(array('id' => $event->id, 'action' => '')), true)); Anqh::page_meta('description', date('l ', $event->stamp_begin) . Date::format(Date::DMY_SHORT, $event->stamp_begin) . ' @ ' . $event->venue_name); if ($flyer = $event->flyer()) { Anqh::page_meta('image', $flyer->image_url(Model_Image::SIZE_THUMBNAIL)); } Anqh::share(true); // Event main info $this->view->add(View_Page::COLUMN_CENTER, $this->section_event_main($event)); // Flyers $this->view->add(View_Page::COLUMN_RIGHT, $this->section_carousel($event)); // Event side info //$this->view->add(View_Page::COLUMN_SIDE, $this->section_event_info($event)); // Favorites if ($event->favorite_count) { $this->view->add(View_Page::COLUMN_RIGHT, $this->section_event_favorites($event)); } }
/** * Action: index */ public function action_index() { // Go to post? $topic_id = (int) $this->request->param('topic_id'); if ($topic_id) { $post_id = (int) $this->request->param('id'); } else { $topic_id = (int) $this->request->param('id'); } // Load topic /** @var Model_Forum_Private_Topic|Model_Forum_Topic $topic */ $topic = $this->private ? Model_Forum_Private_Topic::factory($topic_id) : Model_Forum_Topic::factory($topic_id); if (!$topic->loaded()) { throw new Model_Exception($topic, $topic_id); } Permission::required($topic, Model_Forum_Topic::PERMISSION_READ); // Did we request single post with ajax? if (($this->ajax || $this->internal) && isset($post_id)) { $this->history = false; $post = $this->private ? Model_Forum_Private_Post::factory($post_id) : Model_Forum_Post::factory($post_id); if (!$post->loaded()) { throw new Model_Exception($topic, $topic_id); } // Permission is already checked by the topic, no need to check for post $this->response->body($this->section_post($topic, $post)); return; } // Update counts if ($this->private) { $topic->mark_as_read(Visitor::$user); } if (!Visitor::$user || $topic->author_id != Visitor::$user->id) { $topic->read_count++; $topic->save(); } // Build page $this->view = new View_Page(); $this->view->title = $topic->name; $this->view->title_html = Forum::topic($topic); $this->view->subtitle = __($topic->post_count == 1 ? ':posts post' : ':posts posts', array(':posts' => Num::format($topic->post_count, 0))); $this->view->tab = 'topic'; $this->page_actions['topic'] = array('link' => Route::model($topic), 'text' => __('Topic')); // Breadcrumbs $this->page_breadcrumbs[] = HTML::anchor(Route::url('forum'), __('Forum')); // Public topic extras if (!$this->private) { $this->page_breadcrumbs[] = HTML::anchor(Route::model($topic->area()), $topic->area()->name); // Quotes are supported only in public forum as we get notifications anyway in private if (Visitor::$user) { $quotes = Model_Forum_Quote::factory()->find_by_user(Visitor::$user); if (count($quotes)) { foreach ($quotes as $quote) { if ($topic->id == $quote->forum_topic_id) { $quote->delete(); break; } } } } // Facebook Anqh::page_meta('title', $topic->name); Anqh::page_meta('url', URL::site(Route::url('forum_topic', array('id' => $topic->id, 'action' => '')), true)); Anqh::share(true); // Model binding $area = $topic->area(); if ($topic->bind_id && ($bind_config = $area->bind_config())) { if ($bind_model = $topic->bind_model()) { // Set actions $this->page_actions[] = array('link' => Route::model($bind_model), 'text' => $bind_config['link']); /* // Set views foreach ((array)$bind['view'] as $view) { $this->view->add(View_Page::COLUMN_RIGHT, View_Module::factory($view, array( $bind['model'] => $model, )), Widget::TOP); }*/ } } } else { $this->page_breadcrumbs[] = HTML::anchor(Forum::private_messages_url(), __('Private messages')); } // Set actions if (Permission::has($topic, Model_Forum_Topic::PERMISSION_UPDATE)) { $this->view->actions[] = array('link' => Route::model($topic, 'edit'), 'text' => __('Edit topic')); } if (Permission::has($topic, Model_Forum_Topic::PERMISSION_POST)) { $this->view->actions[] = array('link' => Request::current_uri() . '#reply', 'text' => __('Reply to topic'), 'class' => 'btn btn-primary topic-post'); } // Pagination $this->view->add(View_Page::COLUMN_CENTER, $pagination = $this->section_pagination($topic)); $this->view->subtitle .= ', ' . __($pagination->total_pages == 1 ? ':pages page' : ':pages pages', array(':pages' => Num::format($pagination->total_pages, 0))); $this->view->subtitle .= ', ' . __($topic->read_count == 1 ? ':views view' : ':views views', array(':views' => Num::format($topic->read_count, 0))); // Go to post? if (isset($post_id)) { $pagination->item($topic->get_post_number($post_id) + 1); // We need to set pagination urls manually if jumped to a post $pagination->base_url = Route::model($topic); } // Recipients if ($this->private) { $this->view->add(View_Page::COLUMN_RIGHT, $this->section_recipients($topic)); } // Posts $this->view->add(View_Page::COLUMN_CENTER, $this->section_topic($topic, $pagination)); // Reply if (Permission::has($topic, Model_Forum_Topic::PERMISSION_POST)) { // Old post warning if ($topic->last_posted && time() - $topic->last_posted > Date::YEAR) { $this->view->add(View_Page::COLUMN_CENTER, $this->section_ancient_warning($topic->last_posted)); } $section = $this->section_post_edit(View_Forum_PostEdit::REPLY, $this->private ? Model_Forum_Private_Post::factory() : Model_Forum_Post::factory()); $section->forum_topic = $topic; $this->view->add(View_Page::COLUMN_CENTER, $section); } // Pagination $this->view->add(View_Page::COLUMN_CENTER, $pagination); $this->_side_views(); }