Esempio n. 1
0
File: share.php Progetto: anqh/anqh
    /**
     * 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();
    }
Esempio n. 2
0
File: user.php Progetto: 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();
 }
Esempio n. 3
0
File: index.php Progetto: anqh/anqh
 /**
  * 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());
 }
Esempio n. 4
0
File: topic.php Progetto: 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();
 }
Esempio n. 5
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);
     }
 }
Esempio n. 6
0
File: friend.php Progetto: anqh/anqh
 /**
  * Delete friendship.
  *
  * @static
  * @param   integer  $user_id
  * @param   integer  $friend_id
  * @return  boolean
  */
 public static function unfriend($user_id, $friend_id)
 {
     $deleted = DB::delete('friends')->where('user_id', '=', $user_id)->and_where('friend_id', '=', $friend_id)->execute();
     Anqh::cache_delete('friends_' . $user_id);
     Anqh::cache_delete('friends_of_' . $friend_id);
     return (bool) $deleted;
 }
Esempio n. 7
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();
 }
Esempio n. 8
0
File: user.php Progetto: anqh/anqh
 /**
  * Get user id from data
  *
  * @static
  * @param   mixed  $user
  * @return  integer
  */
 public static function user_id($user)
 {
     if (is_int($user) || is_numeric($user)) {
         // Already got id
         return (int) $user;
     } else {
         if (is_array($user)) {
             // Got user array
             return (int) Arr::get($user, 'id');
         } else {
             if ($user instanceof Model_User) {
                 // Got user model
                 return $user->id;
             } else {
                 if (is_string($user)) {
                     // Got user name
                     $username = Text::clean($user);
                     if (!($id = (int) Anqh::cache_get('user_uid_' . $username))) {
                         if ($user = Model_User::find_user($user)) {
                             $id = $user->id;
                             Anqh::cache_set('user_uid_' . $username, $id, Date::DAY);
                         }
                     }
                     return $id;
                 }
             }
         }
     }
     return 0;
 }
Esempio n. 9
0
File: ignore.php Progetto: anqh/core
 /**
  * Delete ignore.
  *
  * @static
  * @param   integer  $user_id
  * @param   integer  $ignore_id
  * @return  boolean
  */
 public static function unignore($user_id, $ignore_id)
 {
     $deleted = DB::delete('ignores')->where('user_id', '=', $user_id)->and_where('ignore_id', '=', $ignore_id)->execute();
     Anqh::cache_delete('ignores_' . $user_id);
     Anqh::cache_delete('ignorers_' . $ignore_id);
     return (bool) $deleted;
 }
Esempio n. 10
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));
     }
 }
Esempio n. 11
0
defined('SYSPATH') or die('No direct access allowed.');
/**
 * Visitor section
 *
 * @package    Anqh
 * @author     Antti Qvickström
 * @copyright  (c) 2010-2011 Antti Qvickström
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 */
if ($user) {
    // Member
    ?>
<ul>

	<?php 
    if ($new_comments = Anqh::notifications($user)) {
        ?>
	<li class="menu-messages">
		<ul class="new-messages">
			<?php 
        foreach ($new_comments as $class => $link) {
            ?>
			<li class="<?php 
            echo $class;
            ?>
"><?php 
            echo $link;
            ?>
</li>
			<?php 
        }
Esempio n. 12
0
File: page.php Progetto: anqh/anqh
    /**
     * Render visitor.
     *
     * @return  string
     */
    protected function _visitor()
    {
        ob_start();
        ?>

	<li id="notifications"><?php 
        echo implode(' ', Anqh::notifications(Visitor::$user));
        ?>
</li>

	<li class="hidden-xs">
		<?php 
        echo HTML::avatar(Visitor::$user->avatar_url, Visitor::$user->username, 'small');
        ?>
	</li>

	<li id="visitor" class="dropdown">
		<a class="user dropdown-toggle" href="#menu-profile" data-toggle="dropdown"><?php 
        echo HTML::chars(Visitor::$user->username);
        ?>
 <span class="caret"></span></i></a>
		<ul class="dropdown-menu pull-right" role="menu">
			<?php 
        foreach (Kohana::$config->load('site.menu_visitor') as $item) {
            ?>
			<li role="menuitem"><?php 
            echo HTML::anchor($item['url'], '<i class="' . $item['icon'] . '"></i> ' . $item['text']);
            ?>
</li>
			<?php 
        }
        ?>
			<?php 
        if (Visitor::$user->has_role('admin')) {
            ?>
			<li role="presentation" class="dropdown-header"><?php 
            echo __('Admin functions');
            ?>
</li>
				<?php 
            foreach (Kohana::$config->load('site.menu_admin') as $item) {
                ?>
			<li role="menuitem"><?php 
                echo HTML::anchor($item['url'], '<i class="' . $item['icon'] . '"></i> ' . $item['text'], Arr::get($item, 'attributes'));
                ?>
</li>
				<?php 
            }
            ?>
			<?php 
        }
        ?>
		</ul>
	</li>

<?php 
        return ob_get_clean();
    }
Esempio n. 13
0
 /**
  * Load Foursquare data
  *
  * @return  array
  */
 public function foursquare()
 {
     if ($this->foursquare_id) {
         // Use cache to avoid flooding Foursquare
         $foursquare = Anqh::cache_get('foursquare_venue_' . $this->foursquare_id);
         if (!$foursquare) {
             // Store the original request
             $request = $_REQUEST;
             $_REQUEST = array('method' => 'venue', 'vid' => $this->foursquare_id);
             $response = Request::factory(Route::url('api_venues', array('action' => 'foursquare', 'format' => 'json')))->execute()->body();
             // Restore the original request
             $_REQUEST = $request;
             $foursquare = Arr::path(json_decode($response, true), 'venue.venue');
             // Cache results for 15 minutes
             Anqh::cache_set('foursquare_venue_' . $this->foursquare_id, $foursquare, 60 * 15);
         }
         return $foursquare;
     }
 }
Esempio n. 14
0
File: music.php Progetto: 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));
 }
Esempio n. 15
0
File: page.php Progetto: anqh/anqh
 /**
  * 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();
 }
Esempio n. 16
0
File: page.php Progetto: anqh/core
 /**
  * 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
             // Stylesheets
             $styles = array('ui/jquery-ui.css', 'http://fonts.googleapis.com/css?family=Terminal+Dosis');
             // Skins
             $selected_skin = $this->session->get('skin', 'blue');
             // Less files needed to build a skin
             $less_imports = array('ui/mixin.less', 'ui/anqh.less');
             $skins = array(HTML::style('static/css/bootstrap.css'), HTML::style('static/css/bootstrap-responsive.css'));
             foreach (array('blue') as $skin) {
                 $skinsi[] = Less::style('ui/' . $skin . '.less', array('title' => $skin, 'rel' => $skin == $selected_skin ? 'stylesheet' : 'alternate stylesheet'), false, $less_imports);
             }
             // Footer
             $section = new View_Events_List();
             $section->class .= ' span4';
             $section->title = __('New events');
             $section->events = Model_Event::factory()->find_new(10);
             Widget::add('footer', $section);
             $section = new View_Topics_List();
             $section->class .= ' span4';
             $section->title = __('New posts');
             $section->topics = Model_Forum_Topic::factory()->find_by_latest_post(10);
             Widget::add('footer', $section);
             $section = new View_Blogs_List();
             $section->class .= ' span4';
             $section->title = __('New blogs');
             $section->blog_entries = Model_Blog_Entry::factory()->find_new(10);
             Widget::add('footer', $section);
             // 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));
             }
             // 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"));
             }
             // 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);
             					}
             				}
             			}*/
             // Do some CSS magic to page class
             $page_class = array_merge(array($this->language, $this->request->action(), self::$user ? 'authenticated' : 'unauthenticated'), explode(' ', $this->page_class));
             $page_class = implode(' ', array_unique($page_class));
             // Set the generic page variables
             $this->view->styles = $styles;
             $this->view->skins = $skins;
             $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;
             }
             // 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'));
             }
         }
     }
     parent::after();
 }
Esempio n. 17
0
File: share.php Progetto: anqh/core
    /**
     * Render content.
     *
     * @return  string
     */
    public function content()
    {
        static $script = true;
        $attributes = array();
        // Custom URL
        $url = $this->url ? $this->url : Anqh::open_graph('url');
        if ($url) {
            $attributes['addthis:url'] = $url;
        }
        // Custom title
        $title = $this->title ? $this->title : Anqh::open_graph('title');
        if ($title) {
            $attributes['addthis:title'] = $title;
        }
        ob_start();
        ?>

<div class="addthis_toolbox addthis_default_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"><?php 
        echo HTML::image('static/img/google-plus.png', array('alt' => 'Google +1', 'width' => 32, 'height' => 32));
        ?>
</a>
	<a class="addthis_button_email"></a>
	<a class="addthis_button_compact"></a>
	<a class="addthis_counter addthis_bubble_style"></a>
</div>

<?php 
        if ($script) {
            ?>
	<?php 
            if (Kohana::$config->load('site.google_analytics')) {
                ?>

<script>
	var addthis_config, addthis_share;
	head.ready('google-analytics',	function() {
		addthis_config = {
			data_ga_tracker: tracker,
			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');
                ?>
)'
			}
		};

		var at = document.createElement('script'); at.type = 'text/javascript'; at.async = true;
		at.src = 'http://s7.addthis.com/js/250/addthis_widget.js';
		(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(at);
	});
</script>

	<?php 
            } else {
                ?>

<script src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=<?php 
                echo Kohana::$config->load('site.share');
                ?>
"></script>

<?php 
            }
        }
        // Add JavaScript only once
        $script = false;
        return ob_get_clean();
    }
Esempio n. 18
0
File: events.php Progetto: 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));
     }
 }
Esempio n. 19
0
File: topic.php Progetto: 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();
 }
Esempio n. 20
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));
     }
 }
Esempio n. 21
0
File: page.php Progetto: anqh/core
    /**
     * Render visitor.
     *
     * @return  string
     */
    protected function _visitor()
    {
        ob_start();
        /*
        // Sunrise
        if (self::$_user && self::$_user->latitude && self::$_user->longitude) {
        	$latitude  = self::$_user->latitude;
        	$longitude = self::$_user->longitude;
        } else {
        	$latitude  = 60.1829;
        	$longitude = 24.9549;
        }
        $sun = date_sun_info(time(), $latitude, $longitude);
        $sunrise = __(':day, week :week | Sunrise: :sunrise | Sunset: :sunset', array(
        	':day'     => strftime('%A'),
        	':week'    => strftime('%V'),
        	':sunrise' => Date::format(Date::TIME, $sun['sunrise']),
        	':sunset'  => Date::format(Date::TIME, $sun['sunset'])
        ));
        */
        ?>

	<nav id="visitor" class="navbar-text">
		<ul class="nav" role="menubar">
			<li class="menuitem-notifications"><span><?php 
        echo implode(' ', Anqh::notifications(self::$_user));
        ?>
</span></li>
			<li role="menuitem" class="menuitem-profile"><?php 
        echo HTML::avatar(self::$_user->avatar, self::$_user->username, true);
        ?>
</li>

			<li class="dropdown menu-me" role="menuitem" aria-haspopup="true">
				<a class="dropdown-toggle" href="#" data-toggle="dropdown"><?php 
        echo HTML::chars(self::$_user->username);
        ?>
 <b class="caret"></b></a>
				<ul class="dropdown-menu pull-right" role="menu">
					<li role="menuitem"><?php 
        echo HTML::anchor(URL::user(self::$_user->username), '<i class="icon-user icon-white"></i> ' . __('Profile'));
        ?>
<li>
					<li role="menuitem"><?php 
        echo HTML::anchor(Forum::private_messages_url(), '<i class="icon-envelope icon-white"></i> ' . __('Private messages'));
        ?>
</li>
					<li role="menuitem"><?php 
        echo HTML::anchor(URL::user(self::$_user, 'favorites'), '<i class="icon-calendar icon-white"></i> ' . __('Favorites'));
        ?>
</li>
					<li role="menuitem"><?php 
        echo HTML::anchor(URL::user(self::$_user, 'friends'), '<i class="icon-heart icon-white"></i> ' . __('Friends'));
        ?>
</li>
					<li role="menuitem"><?php 
        echo HTML::anchor(URL::user(self::$_user, 'ignores'), '<i class="icon-ban-circle icon-white"></i> ' . __('Ignores'));
        ?>
</li>
					<li role="menuitem"><?php 
        echo HTML::anchor(URL::user(self::$_user, 'settings'), '<i class="icon-cog icon-white"></i> ' . __('Settings'));
        ?>
</li>
					<?php 
        if (self::$_user->has_role('admin')) {
            ?>
					<li class="divider"></li>
					<li class="nav-header"><?php 
            echo __('Admin functions');
            ?>
</li>
					<li role="menuitem" class="admin"><?php 
            echo HTML::anchor(Route::url('roles'), '<i class="icon-asterisk icon-white"></i> ' . __('Roles'));
            ?>
</li>
					<li role="menuitem" class="admin"><?php 
            echo HTML::anchor(Route::url('tags'), '<i class="icon-tags icon-white"></i> ' . __('Tags'));
            ?>
</li>
					<li role="menuitem" class="admin"><?php 
            echo HTML::anchor('#debug', '<i class="icon-signal icon-white"></i> ' . __('Profiler'), array('onclick' => "\$('div.kohana').toggle();"));
            ?>
</li>
					<?php 
        }
        ?>
					<li class="divider"></li>
					<li role="menuitem">
						<?php 
        echo HTML::anchor(Route::url('sign', array('action' => 'out')), '<i class="icon-off icon-white"></i> ' . __('Sign out'));
        ?>
					</li>
				</ul>
			</li>

			<li class="dropdown menu-search" role="menuitem" aria-haspopup="true">
					<a class="dropdown-toggle" href="#" data-toggle="dropdown"><i class="icon-search icon-white"></i> <b class="caret"></b></a>
					<ul class="dropdown-menu pull-right" role="menu">
						<li role="menuitem">
							<?php 
        echo Form::open(null, array('id' => 'form-search-events', 'class' => 'hidden-phone'));
        ?>
							<label class="span2">
								<i class="icon-calendar icon-white"></i>
								<?php 
        echo Form::input('search-events', null, array('class' => 'input-small search-query', 'placeholder' => __('Search events..'), 'title' => __('Enter at least 3 characters')));
        ?>
							</label>
							<?php 
        echo Form::close();
        ?>
						</li>
						<li role="menuitem">
							<?php 
        echo Form::open(null, array('id' => 'form-search-users', 'class' => 'hidden-phone'));
        ?>
							<label class="span2">
								<i class="icon-user icon-white"></i>
								<?php 
        echo Form::input('search-users', null, array('class' => 'input-small search-query', 'placeholder' => __('Search users..'), 'title' => __('Enter at least 2 characters')));
        ?>
							</label>
							<?php 
        echo Form::close();
        ?>
						</li>
					</ul>
			</li>


		</ul>
	</nav><!-- #visitor -->


<?php 
        return ob_get_clean();
    }
Esempio n. 22
0
File: share.php Progetto: anqh/core
<?php

defined('SYSPATH') or die('No direct access allowed.');
/**
 * AddThis
 *
 * @package    Anqh
 * @author     Antti Qvickström
 * @copyright  (c) 2011 Antti Qvickström
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 */
$attributes = array();
// Custom URL
if ($url = Anqh::open_graph('url')) {
    $attributes['addthis:url'] = $url;
}
// Custom title
if ($title = Anqh::open_graph('title')) {
    $attributes['addthis:title'] = $title;
}
?>
<div class="addthis_toolbox addthis_pill_combo"<?php 
echo HTML::attributes($attributes);
?>
>
	<a class="addthis_button_facebook_like"></a>
	<a class="addthis_button_tweet" tw:count="horizontal"></a>
	<a class="addthis_counter addthis_pill_style"></a>
</div>