Example #1
0
 /**
  * Get newsfeed item as HTML
  *
  * @param   Model_NewsfeedItem  $item
  * @return  string
  */
 public static function get(Model_NewsfeedItem $item)
 {
     $text = '';
     switch ($item->type) {
         case self::TYPE_COMMENT:
             $gallery = Model_Gallery::factory($item->data['gallery_id']);
             $image = Model_Image::factory($item->data['image_id']);
             if ($gallery->loaded() && $image->loaded()) {
                 $text = __('commented to an image<br />:gallery', array(':gallery' => HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), '<i class="icon-camera icon-white"></i> ' . HTML::chars($gallery->name), array('class' => 'hoverable'))));
             }
             break;
         case self::TYPE_COMMENT_FLYER:
             $flyer = Model_Flyer::factory($item->data['flyer_id']);
             if ($flyer->loaded()) {
                 $text = __('commented to a flyer<br />:flyer', array(':flyer' => HTML::anchor(Route::url('flyer', array('id' => $flyer->id)), '<i class="icon-picture icon-white"></i> ' . ($flyer->name ? HTML::chars($flyer->name) : __('flyer')), array('class' => 'hoverable'))));
             }
             break;
         case self::TYPE_FLYER_EDIT:
             $flyer = Model_Flyer::factory($item->data['flyer_id']);
             if ($flyer->loaded()) {
                 $text = __('updated flyer<br />:flyer', array(':flyer' => HTML::anchor(Route::url('flyer', array('id' => $flyer->id)), '<i class="icon-picture icon-white"></i> ' . ($flyer->name ? HTML::chars($flyer->name) : __('flyer')), array('class' => 'hoverable'))));
             }
             break;
         case self::TYPE_NOTE:
             $gallery = Model_Gallery::factory($item->data['gallery_id']);
             $image = Model_Image::factory($item->data['image_id']);
             $user = Model_User::find_user($item->data['user_id']);
             if ($gallery->loaded() && $image->loaded() && $user->loaded()) {
                 $text = __('tagged :user to an image<br />:gallery', array(':user' => HTML::user($user), ':gallery' => HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), '<i class="icon-tag icon-white"></i> ' . HTML::chars($gallery->name), array('class' => 'hoverable'))));
             }
             break;
     }
     return $text;
 }
Example #2
0
 /**
  * Edit gallery
  *
  * @param  integer  $gallery_id
  * @param  integer  $event_id
  */
 protected function _edit_gallery($gallery_id = null, $event_id = null)
 {
     $this->history = false;
     if ($gallery_id) {
         // Editing old
         $gallery = Model_Gallery::factory($gallery_id);
         if (!$gallery->loaded()) {
             throw new Model_Exception($gallery, $gallery_id);
         }
         Permission::required($gallery, Model_Gallery::PERMISSION_UPDATE, self::$user);
         $cancel = Route::model($gallery);
         $save = null;
         $upload = false;
     } else {
         // Creating new
         $gallery = Model_Gallery::factory();
         Permission::required($gallery, Model_Gallery::PERMISSION_CREATE, self::$user);
         $cancel = Request::back(Route::url('galleries'), true);
         $save = __('Continue');
         $upload = true;
         if ($event_id) {
             /** @var  Model_Event  $event */
             $event = Model_Event::factory($event_id);
         }
     }
     // Handle post
     $errors = array();
     if ($_POST || isset($_GET['from'])) {
         $event_id = $_POST ? (int) Arr::get($_POST, 'event') : (int) Arr::get($_GET, 'from');
         $event = Model_Event::factory($event_id);
         if (!$gallery->loaded() && $event->loaded()) {
             // Redirect to existing gallery if trying to create duplicate
             $old = Model_Gallery::factory()->find_by_event($event_id);
             if ($old->loaded()) {
                 $this->request->redirect(Route::model($old, 'upload'));
             }
             // Fill gallery info from event when creating new
             $gallery->name = $event->name;
             $gallery->date = $event->stamp_begin;
             $gallery->event_id = $event->id;
         } else {
             if ($gallery->loaded()) {
                 // Editing old
                 $gallery->set_fields(Arr::intersect($_POST, Model_Gallery::$editable_fields));
             }
         }
         try {
             $gallery->save();
             $this->request->redirect(Route::model($gallery, $upload ? 'upload' : null));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         }
     }
     // Build page
     $this->view = View_Page::factory(__('Upload images'));
     // Gallery edit form
     $section = $this->section_gallery_edit(isset($event) ? $event : null);
     $section->errors = $errors;
     $this->view->add(View_Page::COLUMN_MAIN, $section);
     // Gallery event info
     if (isset($event) && $event->loaded()) {
         $this->view->add(View_Page::COLUMN_MAIN, $this->section_event_info($event));
     }
     $this->view->add(View_Page::COLUMN_SIDE, $this->section_upload_help());
 }
Example #3
0
 /**
  * Get anchor to newsfeed item target.
  *
  * @static
  * @param   Model_NewsfeedItem  $item
  * @return  string
  */
 public static function get_link(Model_NewsfeedItem $item)
 {
     $text = '';
     switch ($item->type) {
         // Image
         case self::TYPE_COMMENT:
         case self::TYPE_NOTE:
             $gallery = Model_Gallery::factory($item->data['gallery_id']);
             $image = Model_Image::factory($item->data['image_id']);
             if ($gallery->loaded() && $image->loaded()) {
                 $text = HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), '<i class="fa fa-camera-retro"></i> ' . HTML::chars($gallery->name), array('class' => 'hoverable'));
             }
             break;
             // Flyer
         // Flyer
         case self::TYPE_COMMENT_FLYER:
         case self::TYPE_FLYER_EDIT:
             $flyer = Model_Flyer::factory($item->data['flyer_id']);
             if ($flyer->loaded()) {
                 $text = HTML::anchor(Route::url('flyer', array('id' => $flyer->id)), '<i class="fa fa-picture"></i> ' . ($flyer->name ? HTML::chars($flyer->name) : __('flyer')), array('class' => 'hoverable'));
             }
             break;
             // Gallery
         // Gallery
         case self::TYPE_UPLOAD:
             $gallery = Model_Gallery::factory($item->data['gallery_id']);
             if ($gallery->loaded()) {
                 $text = HTML::anchor(Route::model($gallery), '<i class="fa fa-camera-retro"></i> ' . HTML::chars($gallery->name), array('class' => 'hoverable'));
             }
             break;
     }
     return $text;
 }
 public function action_view($galleri)
 {
     $this->template->title = 'Änglarna Stockholms galleri: ' . html::chars($galleri);
     $this->template->content = View::factory('galleri/view')->set('images', Model_Gallery::factory($galleri)->load()->images)->set('title', $galleri);
 }
Example #5
0
File: core.php Project: anqh/core
 /**
  * Get user's new comment counts.
  *
  * @param   Model_User  $user
  * @return  array
  */
 public static function notifications(Model_User $user)
 {
     $new = array();
     // Profile comments
     if ($user->new_comment_count) {
         $new['new-comments'] = HTML::anchor(URL::user($user), '<i class="icon-comment icon-white"></i> ' . $user->new_comment_count, array('class' => 'badge badge-info', 'title' => __('New comments')));
     }
     // Forum private messages
     $private_messages = Forum::find_new_private_messages($user);
     if (count($private_messages)) {
         $new_messages = 0;
         foreach ($private_messages as $private_message) {
             $new_messages += $private_message->unread;
         }
         $new['new-private-messages'] = HTML::anchor(Route::model($private_message->topic()) . '?page=last#last', '<i class="icon-comment icon-white"></i> ' . $new_messages, array('class' => 'badge badge-info', 'title' => __('New private messages')));
     }
     unset($private_messages);
     // Blog comments
     $blog_comments = Model_Blog_Entry::factory()->find_new_comments($user);
     if (count($blog_comments)) {
         $new_comments = 0;
         foreach ($blog_comments as $blog_entry) {
             $new_comments += $blog_entry->new_comment_count;
         }
         $new['new-blog-comments'] = HTML::anchor(Route::model($blog_entry), '<i class="icon-comment icon-white"></i> ' . $new_comments, array('class' => 'badge badge-info', 'title' => __('New blog comments')));
     }
     unset($blog_comments);
     // Forum quotes
     $forum_quotes = Model_Forum_Quote::factory()->find_by_user($user);
     if (count($forum_quotes)) {
         $new_quotes = count($forum_quotes);
         $quote = $forum_quotes->current();
         $new['new-forum-quotes'] = HTML::anchor(Route::get('forum_post')->uri(array('topic_id' => $quote->forum_topic_id, 'id' => $quote->forum_post_id)) . '#post-' . $quote->forum_post_id, '<i class="icon-comment icon-white"></i> ' . $new_quotes, array('class' => 'badge badge-info', 'title' => __('Forum quotes')));
     }
     // Images waiting for approval
     if (Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_APPROVE_WAITING, $user)) {
         $gallery_approvals = Model_Gallery::factory()->find_pending(Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_APPROVE, $user) ? null : $user);
         if (count($gallery_approvals)) {
             $new_approvals = count($gallery_approvals);
             $new['new-gallery-approvals'] = HTML::anchor(Route::get('galleries')->uri(array('action' => 'approval')), '<i class="icon-exclamation-sign icon-white"></i> ' . $new_approvals, array('class' => 'badge badge-warning', 'title' => __('Galleries waiting for approval')));
         }
     }
     // Flyer comments
     $flyer_comments = Model_Flyer::factory()->find_new_comments($user);
     $flyers = array();
     if (count($flyer_comments)) {
         $new_comments = 0;
         foreach ($flyer_comments as $flyer) {
             $flyers[$flyer->image_id] = true;
             $new_comments += $flyer->image()->new_comment_count;
         }
         $new['new-flyer-comments'] = HTML::anchor(Route::get('flyer')->uri(array('id' => $flyer->id, 'action' => '')), '<i class="icon-picture icon-white"></i> ' . $new_comments, array('class' => 'badge badge-info', 'title' => __('New flyer comments')));
     }
     unset($flyer_comments);
     // Image comments
     $image_comments = Model_Image::factory()->find_new_comments($user);
     $note_comments = Model_Image_Note::factory()->find_new_comments($user);
     if (count($image_comments) || count($note_comments)) {
         $new_comments = 0;
         $new_image = null;
         foreach ($image_comments as $image) {
             // @TODO: Until flyer comments are fixed..
             if (!isset($flyers[$image->id])) {
                 $new_comments += $image->new_comment_count;
                 $new_image_id = $image->id;
             }
         }
         foreach ($note_comments as $note) {
             $new_comments += $note->new_comment_count;
             $new_image_id = $note->image_id;
         }
         if ($new_comments) {
             $new['new-image-comments'] = HTML::anchor(Route::get('gallery_image')->uri(array('gallery_id' => Route::model_id(Model_Gallery::find_by_image($new_image_id)), 'id' => $new_image_id, 'action' => '')), '<i class="icon-camera icon-white"></i> ' . $new_comments, array('class' => 'badge badge-info', 'title' => __('New image comments')));
         }
     }
     unset($image_comments, $note_comments, $new_image);
     // Image tags
     $notes = Model_Image_Note::factory()->find_new_notes($user);
     if (count($notes)) {
         $new_notes = 0;
         $new_note_image_id = null;
         /** @var  Model_Image_Note  $note */
         foreach ($notes as $note) {
             $new_notes++;
             $new_note_image_id = $note->image_id;
         }
         if ($new_notes) {
             $new['new-image-notes'] = HTML::anchor(Route::get('gallery_image')->uri(array('gallery_id' => Route::model_id(Model_Gallery::find_by_image($new_note_image_id)), 'id' => $new_note_image_id, 'action' => '')), '<i class="icon-tag icon-white"></i> ' . $new_notes, array('class' => 'badge badge-info', 'title' => __('New image tags')));
         }
     }
     unset($note_comments, $new_note_image_id);
     return $new;
 }