Example #1
0
File: user.php Project: anqh/anqh
 /**
  * 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();
 }
Example #2
0
 /**
  * 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);
     }
     // Are we approving pending images?
     if ($this->request->action() == 'approve') {
         // Can we see galleries with un-approved images?
         Permission::required($gallery, Model_Gallery::PERMISSION_APPROVE_WAITING, self::$user);
         // Can we see all of them and approve?
         $approve = Permission::has($gallery, Model_Gallery::PERMISSION_APPROVE, self::$user);
         $images = $gallery->find_images_pending($approve ? null : self::$user);
     } else {
         Permission::required($gallery, Model_Gallery::PERMISSION_READ, self::$user);
         $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 (!isset($approve) && Permission::has($gallery, Model_Gallery::PERMISSION_COMMENTS, self::$user)) {
             $errors = array();
             $values = array();
             // Handle comment
             if (Permission::has($gallery, Model_Gallery::PERMISSION_COMMENT, self::$user) && $_POST) {
                 try {
                     $comment = Model_Image_Comment::factory()->add(self::$user->id, $current, Arr::get($_POST, 'comment'), Arr::get($_POST, 'private'));
                     $current->comment_count++;
                     if ($current->author_id != self::$user->id) {
                         $current->new_comment_count++;
                     }
                     $current->save();
                     $gallery->comment_count++;
                     $gallery->save();
                     if (!$comment->private) {
                         // Noted users
                         foreach ($current->notes() as $note) {
                             $note->state(AutoModeler::STATE_LOADED);
                             $note->new_comment_count++;
                             $note->save();
                         }
                         // Newsfeed
                         NewsfeedItem_Galleries::comment(self::$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 (self::$user) {
                     // Clear new comment count?
                     if ($current->author_id == self::$user->id && $current->new_comment_count > 0) {
                         $current->new_comment_count = 0;
                         $current->save();
                     }
                     foreach ($current->notes() as $note) {
                         if ($note->user_id == self::$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 (!self::$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
         $this->view = View_Page::factory(__('Gallery'));
         // Image actions
         if (Permission::has($gallery, Model_Gallery::PERMISSION_UPDATE, self::$user)) {
             $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 icon-white"></i> ' . __('Set default'), 'class' => 'btn-inverse image-default');
         }
         if (Permission::has($current, Model_Image::PERMISSION_DELETE, self::$user)) {
             $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 icon-white"></i> ' . __('Delete'), 'class' => 'btn-inverse image-delete');
         }
         // Gallery actions
         $this->_set_page_actions(Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_CREATE, self::$user));
         $this->_set_gallery($gallery);
         array_unshift($this->view->tabs, array('link' => Route::model($gallery), 'text' => '&laquo; ' . __('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 icon-white"></i> ' . __('Photo'));
         // Pagination
         $previous_url = $previous ? Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $previous->id, 'action' => $approve ? 'approve' : '')) . '#title' : null;
         $next_url = $next ? Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $next->id, 'action' => $approve ? 'approve' : '')) . '#title' : null;
         $this->view->add(View_Page::COLUMN_TOP, $this->section_image_pagination($previous_url, $next_url, $i, count($images)));
         // Image
         if (!isset($approve)) {
             $current->view_count++;
             $current->save();
         }
         $this->view->add(View_Page::COLUMN_TOP, $this->section_image($current, $gallery, $next_url, (bool) $approve));
         // Comments
         if (isset($section_comments)) {
             $this->view->add(View_Page::COLUMN_MAIN, $section_comments);
         }
         // Share
         if (Kohana::$config->load('site.facebook')) {
             Anqh::open_graph('title', __('Image') . ': ' . $gallery->name);
             Anqh::open_graph('url', URL::site(Route::url('gallery_image', array('id' => $current->id, 'gallery_id' => $gallery->id, 'action' => '')), true));
             if ($current->description) {
                 Anqh::open_graph('description', $current->description);
             }
             Anqh::open_graph('image', URL::site($current->get_url('thumbnail'), true));
         }
         Anqh::share(true);
         $this->view->add(View_Page::COLUMN_SIDE, $this->section_share());
         // Image info
         $this->view->add(View_Page::COLUMN_SIDE, $this->section_image_info($current));
     }
 }
Example #3
0
File: topic.php Project: anqh/forum
 /**
  * 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, self::$user);
     // 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(self::$user);
     }
     if (!self::$user || $topic->author_id != self::$user->id) {
         $topic->read_count++;
         $topic->save();
     }
     // Build page
     $this->view = new View_Page();
     $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' => '<i class="icon-comment icon-white"></i> ' . __('Topic'));
     // Public topic extras
     if (!$this->private) {
         // Quotes are supported only in public forum as we get notifications anyway in private
         if (self::$user) {
             $quotes = Model_Forum_Quote::factory()->find_by_user(self::$user);
             if (count($quotes)) {
                 foreach ($quotes as $quote) {
                     if ($topic->id == $quote->forum_topic_id) {
                         $quote->delete();
                         break;
                     }
                 }
             }
         }
         // Facebook
         if (Kohana::$config->load('site.facebook')) {
             Anqh::open_graph('title', $topic->name);
             Anqh::open_graph('url', URL::site(Route::url('forum_topic', array('id' => $topic->id, 'action' => '')), true));
         }
         Anqh::share(true);
         // Model binding
         $area = $topic->area();
         if ($area->type == Model_Forum_Area::TYPE_BIND && $topic->bind_id) {
             if ($bind = Model_Forum_Area::get_binds($area->bind)) {
                 $model = AutoModeler::factory($bind['model'], $topic->bind_id);
                 if ($model->loaded()) {
                     // Set actions
                     $this->page_actions[] = array('link' => Route::model($model), 'text' => $bind['link']);
                     // Set views
                     foreach ((array) $bind['view'] as $view) {
                         $this->view->add(View_Page::COLUMN_SIDE, View_Module::factory($view, array($bind['model'] => $model)), Widget::TOP);
                     }
                 }
             }
         }
     }
     // Public topic extras
     // Set actions
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_POST, self::$user)) {
         $this->view->actions[] = array('link' => Request::current_uri() . '#reply', 'text' => '<i class="icon-comment icon-white"></i> ' . __('Reply to topic'), 'class' => 'btn btn-primary topic-post');
     }
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_UPDATE, self::$user)) {
         $this->view->actions[] = array('link' => Route::model($topic, 'edit'), 'text' => '<i class="icon-edit icon-white"></i> ' . __('Edit topic'));
     }
     // Breadcrumbs
     $this->page_breadcrumbs[] = HTML::anchor(Route::url('forum_group'), __('Forum'));
     $this->page_breadcrumbs[] = HTML::anchor(Route::model($topic->area()), $topic->area()->name);
     // Pagination
     $this->view->add(View_Page::COLUMN_MAIN, $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_MAIN, $this->section_recipients($topic));
         $this->view->add(View_Page::COLUMN_MAIN, '<hr />');
     }
     // Posts
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_topic($topic, $pagination));
     // Reply
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_POST, self::$user)) {
         $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_MAIN, $section);
     }
     // Pagination
     $this->view->add(View_Page::COLUMN_MAIN, $pagination);
     $this->_side_views();
 }
Example #4
0
 /**
  * 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' => '&laquo; ' . __('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);
     }
 }
Example #5
0
 /**
  * Destroy controller
  */
 public function after()
 {
     if ($this->ajax || $this->internal) {
         // AJAX and HMVC requests
         $this->response->body($this->response->body() . '');
     } else {
         if ($this->auto_render) {
             // Normal requests
             $session = Session::instance();
             // Save current URI
             /* Moved to Controller
             			if ($this->history && $this->response->status() < 400) {
             				$uri = $this->request->current_uri();
             				unset($this->breadcrumb[$uri]);
             				$this->breadcrumb = array_slice($this->breadcrumb, -9, 9, true);
             				$this->breadcrumb[$uri] = $this->page_title;
             				$session
             					->set('history', $uri . ($_GET ? URL::query($_GET) : ''))
             					->set('breadcrumb', $this->breadcrumb);
             			}
             			 */
             // Controller name as the default page id if none set
             empty($this->page_id) and $this->page_id = $this->request->controller();
             // Stylesheets
             $styles = array('ui/boot.css' => null, 'ui/typo.css' => null, 'ui/base.css' => null, 'ui/jquery-ui.css' => null, 'http://fonts.googleapis.com/css?family=Nobile:regular,bold' => null);
             // Generic views
             Widget::add('breadcrumb', View::factory('generic/breadcrumb', array('breadcrumb' => $this->breadcrumb, 'last' => !$this->history)));
             Widget::add('actions', View::factory('generic/actions', array('actions' => $this->page_actions)));
             Widget::add('navigation', View::factory('generic/navigation', array('items' => Kohana::$config->load('site.menu'), 'selected' => $this->page_id)));
             if (!empty($this->tabs)) {
                 Widget::add('subnavigation', View::factory('generic/navigation', array('items' => $this->tabs, 'selected' => $this->tab_id)));
             }
             /*
             			Widget::add('tabs', View::factory('generic/tabs_top', array(
             				'tabs'     => $this->tabs,
             				'selected' => $this->tab_id
             			)));
             */
             // Footer
             Widget::add('footer', View_Module::factory('events/event_list', array('mod_id' => 'footer-events-new', 'mod_class' => 'article grid4 first cut events', 'mod_title' => __('New events'), 'events' => Model_Event::factory()->find_new(10))));
             Widget::add('footer', View_Module::factory('forum/topiclist', array('mod_id' => 'footer-topics-active', 'mod_class' => 'article grid4 cut topics', 'mod_title' => __('New posts'), 'topics' => Model_Forum_Topic::factory()->find_by_latest_post(10))));
             Widget::add('footer', View_Module::factory('blog/entry_list', array('mod_id' => 'footer-blog-entries', 'mod_class' => 'article grid4 cut blogentries', 'mod_title' => __('New blogs'), 'entries' => Model_Blog_Entry::factory()->find_new(10))));
             // Skin
             $skins = Kohana::$config->load('site.skins');
             $skin = 'dark';
             //$session->get('skin', 'dark');
             $skin_imports = array('ui/mixin.less', 'ui/grid.less', 'ui/layout.less', 'ui/widget.less', 'ui/custom.less');
             // Dock
             $classes = array();
             foreach ($skins as $skin_name => &$skin_config) {
                 $skin_config['path'] = 'ui/' . $skin_name . '/skin.less';
                 $classes[] = HTML::anchor(Route::get('setting')->uri(array('action' => 'skin', 'value' => $skin_name)), $skin_config['name'], array('class' => 'theme', 'rel' => $skin_name));
             }
             //Widget::add('dock', __('Theme') . ': ' . implode(', ', $classes));
             // Language selection
             $available_languages = Kohana::$config->load('locale.languages');
             if (count($available_languages)) {
                 $languages = array();
                 foreach ($available_languages as $lang => $locale) {
                     $languages[] = HTML::anchor('set/lang/' . $lang, HTML::chars($locale[2]));
                 }
                 //				Widget::add('dock', ' | ' . __('Language: ') . implode(', ', $languages));
             }
             // Search
             /*
             			Widget::add('search', View_Module::factory('generic/search', array(
             				'mod_id' => 'search'
             			)));
             */
             // Visitor card
             Widget::add('visitor', View::factory('generic/visitor', array('user' => self::$user)));
             // Time & weather
             Widget::add('dock', ' | ' . View::factory('generic/clock', array('user' => self::$user)));
             // Pin
             Widget::add('dock', ' | ' . HTML::anchor('#pin', '&#9650;', array('title' => __('Lock menu'), 'class' => 'icon unlock', 'onclick' => '$("#header").toggleClass("pinned"); return false;')));
             // End
             Widget::add('end', View::factory('generic/end'));
             // Analytics
             if ($google_analytics = Kohana::$config->load('site.google_analytics')) {
                 Widget::add('head', HTML::script_source("\nvar tracker;\nhead.js(\n\t{ 'google-analytics': 'http://www.google-analytics.com/ga.js' },\n\tfunction() {\n\t\ttracker = _gat._getTracker('" . $google_analytics . "');\n\t\ttracker._trackPageview();\n\t}\n);\n"));
             }
             // Open Graph
             $og = array();
             foreach ((array) Anqh::open_graph() as $key => $value) {
                 $og[] = '<meta property="' . $key . '" content="' . HTML::chars($value) . '" />';
             }
             if (!empty($og)) {
                 Widget::add('head', implode("\n", $og));
             }
             // Share
             if (Anqh::share()) {
                 if ($share = Kohana::$config->load('site.share')) {
                     // 3rd party share
                     Widget::add('share', View_Module::factory('share/share', array('mod_class' => 'like', 'id' => $share)));
                     Widget::add('foot', View::factory('share/foot', array('id' => $share)));
                 } else {
                     if ($facebook = Kohana::$config->load('site.facebook')) {
                         // Facebook Like
                         Widget::add('share', View_Module::factory('facebook/like'));
                         Widget::add('ad_top', View::factory('facebook/connect', array('id' => $facebook)));
                     }
                 }
             }
             // Ads
             $ads = Kohana::$config->load('site.ads');
             if ($ads && $ads['enabled']) {
                 foreach ($ads['slots'] as $ad => $slot) {
                     Widget::add($slot, View::factory('ads/' . $ad), Widget::MIDDLE);
                 }
             }
             // And finally the profiler stats
             if (self::$user && self::$user->has_role('admin')) {
                 //in_array(Kohana::$environment, array(Kohana::DEVELOPMENT, Kohana::TESTING))) {
                 Widget::add('foot', View::factory('generic/debug'));
                 Widget::add('foot', View::factory('profiler/stats'));
             }
             // Do some CSS magic to page class
             $page_class = explode(' ', $this->language . ' ' . $session->get('page_width', 'fixed') . ' ' . $session->get('page_main', 'left') . ' ' . $this->request->action() . ' ' . $this->page_class);
             // Controller set classes
             $page_class = implode(' ', array_unique(array_map('trim', $page_class)));
             // Bind the generic page variables
             $this->template->set('styles', $styles)->set('skin', $skin)->set('skins', $skins)->set('skin_imports', $skin_imports)->set('language', $this->language)->set('page_id', $this->page_id)->set('page_class', $page_class)->set('page_title', $this->page_title)->set('page_subtitle', $this->page_subtitle);
             // Add statistics
             $queries = 0;
             if (Kohana::$profiling) {
                 foreach (Profiler::groups() as $group => $benchmarks) {
                     if (strpos($group, 'database') === 0) {
                         $queries += count($benchmarks);
                     }
                 }
             }
             $total = array('{memory_usage}' => number_format((memory_get_peak_usage() - KOHANA_START_MEMORY) / 1024, 2) . 'KB', '{execution_time}' => number_format(microtime(true) - KOHANA_START_TIME, 5), '{database_queries}' => $queries, '{included_files}' => count(get_included_files()));
             $this->template = strtr($this->template, $total);
             // Render page
             if ($this->auto_render === true) {
                 $this->response->body($this->template);
             }
         }
     }
     return parent::after();
 }
Example #6
0
 /**
  * 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, self::$user);
     // Build page
     $this->view = View_Page::factory($event->name);
     $this->view->subtitle = $this->_event_subtitle($event);
     // Set actions
     if (Permission::has($event, Model_Event::PERMISSION_FAVORITE, self::$user)) {
         if ($event->is_favorite(self::$user)) {
             $this->view->actions[] = array('link' => Route::model($event, 'unfavorite') . '?token=' . Security::csrf(), 'text' => '<i class="icon-heart icon-white"></i> ' . __('Remove favorite'), 'class' => 'btn-inverse favorite-delete');
         } else {
             $this->view->actions[] = array('link' => Route::model($event, 'favorite') . '?token=' . Security::csrf(), 'text' => '<i class="icon-heart icon-white"></i> ' . __('Add to favorites'), 'class' => 'btn-lovely favorite-add');
         }
     }
     $this->view->tab = 'event';
     $this->view->tabs['event'] = array('link' => Route::model($event), 'text' => '<i class="icon-calendar icon-white"></i> ' . __('Event'));
     $this->view->tabs[] = array('link' => Route::get('gallery_event')->uri(array('id' => $event->id)), 'text' => '<i class="icon-camera icon-white"></i> ' . __('Gallery') . ' &raquo;');
     $this->view->tabs[] = array('link' => Route::get('forum_event')->uri(array('id' => $event->id)), 'text' => '<i class="icon-comment icon-white"></i> ' . __('Forum') . ' &raquo;');
     if (Permission::has($event, Model_Event::PERMISSION_UPDATE, self::$user)) {
         $this->view->actions[] = array('link' => Route::model($event, 'edit'), 'text' => '<i class="icon-edit icon-white"></i> ' . __('Edit event'));
         $this->view->actions[] = array('link' => Route::model($event, 'image'), 'text' => '<i class="icon-picture icon-white"></i> ' . __('Add flyer'), 'class' => !count($event->flyers()) ? 'btn btn-primary' : null);
     }
     // Share
     if (Kohana::$config->load('site.facebook')) {
         Anqh::open_graph('type', 'activity');
         Anqh::open_graph('title', $event->name);
         Anqh::open_graph('url', URL::site(Route::get('event')->uri(array('id' => $event->id, 'action' => '')), true));
         Anqh::open_graph('description', date('l ', $event->stamp_begin) . Date::format(Date::DMY_SHORT, $event->stamp_begin) . ' @ ' . $event->venue_name);
         if ($event->flyer_front()) {
             Anqh::open_graph('image', $event->flyer_front()->get_url('thumbnail'));
         }
     }
     Anqh::share(true);
     // Event main info
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_event_main($event));
     $this->view->add(View_Page::COLUMN_SIDE, $this->section_share());
     // Flyers
     $this->view->add(View_Page::COLUMN_SIDE, $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_SIDE, $this->section_event_favorites($event));
     }
 }
Example #7
0
File: page.php Project: anqh/anqh
    /**
     * Render foot.
     *
     * @return  string
     */
    protected function _foot()
    {
        ob_start();
        // todo: Move to page controller
        ?>

<?php 
        echo HTML::script('//maps.googleapis.com/maps/api/js?sensor=false&libraries=places');
        ?>

<script>
	var Anqh = {
		APIURL: '<?php 
        echo Kohana::$config->load('api.url');
        ?>
' || '/api'
	};

	head.js(
		{ 'jquery':        '//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js' },
		{ 'jquery-ui':     '//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js' },
		{ 'bootstrap':     '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js' },
		{ 'typeahead':     '//cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.9.3/typeahead.min.js' },
		{ 'select2':       '//cdnjs.cloudflare.com/ajax/libs/select2/3.4.5/select2.min.js' },
		{ 'geocomplete':   '//cdnjs.cloudflare.com/ajax/libs/geocomplete/1.4/jquery.geocomplete.min.js' },
		{ 'imgareaselect': '//cdnjs.cloudflare.com/ajax/libs/imgareaselect/0.9.10/js/jquery.imgareaselect.min.js' },
		{ 'lazyload':      '//cdnjs.cloudflare.com/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js' },
		{ 'vendor':        '<?php 
        echo $this->base;
        ?>
static/js/c/vendor.min.js?_=<?php 
        echo filemtime('static/js/c/vendor.min.js');
        ?>
' },
		{ 'anqh':          '<?php 
        echo $this->base;
        ?>
static/js/c/anqh.min.js?_=<?php 
        echo filemtime('static/js/c/anqh.min.js');
        ?>
' },
		function _loaded() {

			// Search
			var $search = $('form[role=search]');
			if ($search.length) {
				$search.on('submit', function(event) {
					event.preventDefault();
				});

				$search.find('[name=search_events]').autocompleteEvent({
					action:   'redirect'
				});
				$search.find('[name=search_users]').autocompleteUser({
					action:   'redirect'
				});
				$search.find('[name=search_images]').autocompleteUser({
					action:   'redirect',
					position: { my: 'right top', at: 'right bottom', of: '#form-search-images', collision: 'flip' }
				});
			}

		}
	);
</script>

<?php 
        echo Widget::get('foot');
        echo Ads::foot();
        if (Anqh::share()) {
            echo new View_Generic_Share();
        }
        return ob_get_clean();
    }
Example #8
0
File: music.php Project: anqh/anqh
 /**
  * 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') . ' &raquo;');
     }
     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));
 }
Example #9
0
File: events.php Project: anqh/anqh
 /**
  * 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') . ' &raquo;');
     }
     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') . ' &raquo;');
     }
     $this->view->tabs[] = array('link' => Route::get('forum_event')->uri(array('id' => $event->id)), 'text' => __('Forum') . ' &raquo;');
     // 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));
     }
 }
Example #10
0
File: topic.php Project: anqh/anqh
 /**
  * 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();
 }