/** * Render view. * * @return string */ public function content() { ob_start(); echo '<figure>', HTML::image($this->image->get_url(Model_Image::SIZE_THUMBNAIL)), '</figure>'; // Tagged people $notes = $this->image->notes(); if (count($notes)) { $names = array(); /** @var Model_Image_Note $note */ foreach ($notes as $note) { $user = $note->user(); $names[] = $user ? HTML::user($user['username']) : HTML::chars($note->name); } echo implode(', ', $names); } // Copyright if ($this->image->author_id) { echo '<br />© ', HTML::user($this->image->author_id); } // Comments if ($this->image->comment_count) { echo '<span class="stats"><i class="icon-comment"></i> ' . $this->image->comment_count . '</span>'; } return ob_get_clean(); }
/** * Render view. * * @return string */ public function content() { ob_start(); $gallery = $this->image->gallery(); echo Form::open(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $this->image->id, 'action' => 'report')), array('class' => Request::current()->is_ajax() ? 'ajaxify' : '')); ?> <fieldset> <?php echo Form::control_group(Form::input('reason', null, array('class' => 'input-block-level')), array('name' => __('Reason')), null, __('You can enter an optional reason for reporting this image, e.g. why it should be removed')); ?> </fieldset> <fieldset class="form-actions"> <?php echo Form::button('save', __('Report'), array('type' => 'submit', 'class' => 'btn btn-danger btn-large')); ?> <?php echo Request::current()->is_ajax() ? '' : HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $this->image->id, 'action' => '')), __('Cancel'), array('class' => 'cancel')); ?> <?php echo Form::csrf(); ?> </fieldset> <?php return ob_get_clean(); }
/** * Render view. * * @return string */ public function content() { ob_start(); if ($this->image) { $image = HTML::image(is_string($this->image) ? $this->image : $this->image->get_url(), array('width' => 290)); ?> <div id="slideshow-image"> <?php echo isset($this->link) && $this->link ? HTML::anchor($this->link, $image) : $image; ?> </div> <?php } else { ?> <div class="well"> <?php echo __('No images yet.'); ?> </div> <?php } return ob_get_clean(); }
private function get_notes($image_id) { $image = new Model_Image($image_id); $notes = array(); if ($image->loaded()) { $notes = $this->parse_db_data($image->notes->find_all()); } return $notes; }
/** * Render view. * * @return string */ public function content() { ob_start(); echo '<figure>', HTML::image($this->image->get_url(Model_Image::SIZE_THUMBNAIL)), '</figure>'; // Comments if ($this->image->comment_count) { echo '<span class="stats"><i class="icon-comment"></i> ' . $this->image->comment_count . '</span>'; } return ob_get_clean(); }
private function _viewSourceById($id) { $imageModel = new Model_Image(); $imageRow = $imageModel->fetchRow($imageModel->getAdapter()->quoteInto("id = ?", $id)); if (count($imageRow) && isset($imageRow->filename)) { $file = new Garp_File('image'); $url = $file->getUrl($imageRow->filename); header("Location: " . $url); // @codingStandardsIgnoreStart exit; // @codingStandardsIgnoreEnd } throw new Zend_Controller_Action_Exception("Sorry, I can't find the requested image.", 404); }
public function action_upload() { $out = array('status' => 'no'); $val = \Validation::forge(); $val->add_field('key2', 'Element id', 'required|min_length[1]|max_length[20]'); $val->add_field('key1', 'Device id', 'required|min_length[1]|max_length[20]'); $val->add_field('key3', 'Template or device', 'required|min_length[1]|max_length[20]'); if ($val->run()) { $uploaddir = DOCROOT . 'images/uploads/'; $name = basename($_FILES['image']['name']); $uploadfile = $uploaddir . $name; if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) { if ($val->validated('key3') != 'true') { $this->tmpl = false; $element = Model_Device_Fieldset::find($val->validated('key2')); } else { $this->tmpl = true; $element = Model_Device_Template_Field::find($val->validated('key2')); } if ($element) { $imageOnHdd = \Image::forge()->load($uploadfile); $sizes = $imageOnHdd->sizes(); //add new image in database $props = array('name' => $name, 'elementID' => $element->id, 'type' => $this->sizeType($sizes), 'width' => 0, 'height' => 0); if ($this->tmpl) { $img = new Model_Device_Template_Image($props); $prefix = 'temp'; } else { $prefix = ''; $img = new Model_Image($props); } $new_width = $sizes->width >= 1000 ? 1000 : $sizes->width; $new_height = $sizes->height >= 750 ? 750 : $sizes->height; //resize original image 1000x1000px to folder > public/images //make thumb 135x135px to folder public/images/thumb if ($img->save()) { $imageOnHdd->resize($new_width, $new_height, true, false)->save(DOCROOT . 'images/' . $prefix . $img->id . '.png')->config('quality', 70)->crop_resize(85, 85, true, false)->save(DOCROOT . 'images/tumb/' . $prefix . $img->id . '.png'); $resized = \Image::forge()->load(DOCROOT . 'images/' . $prefix . $img->id . '.png')->sizes(); $img->width = $resized->width; $img->height = $resized->height; $img->save(); unlink($uploadfile); $out = array('id' => $img->id, 'type' => $img->type, 'status' => 'ok', 'h' => $img->height, 'w' => $img->width); } } } } echo json_encode($out); }
public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
/** * Get newsfeed item as HTML * * @static * @param Model_NewsfeedItem $item * @return string */ public static function get(Model_NewsFeedItem $item) { $text = ''; switch ($item->type) { case self::TYPE_DEFAULT_IMAGE: $image = Model_Image::factory($item->data['image_id']); if ($image->loaded()) { $text = __('changed their default image'); } break; case self::TYPE_FRIEND: if ($item->is_aggregate()) { if ($links = self::get_links($item)) { $text = __('added :friends as friends', array(':friends' => Text::implode_and($links))); } } else { if ($link = self::get_link($item)) { $text = __('added :friend as a friend', array(':friend' => $link)); } } break; case self::TYPE_LOGIN: $text = __('logged in'); break; } return $text; }
/** * 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; }
/** * Get additional content data selected * * @param $result = Query result */ public static function post_find($result) { if ($result !== null) { if (is_array($result)) { foreach ($result as $item) { // It will first check if we already have result in temporary result, // and only execute query if we dont. That way we dont have duplicate queries // Get content images $item->get_images = static::lazy_load(function () use($item) { return Model_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'images'); // Get content files $item->get_files = static::lazy_load(function () use($item) { return Model_File::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'files'); // Get content videos $item->get_videos = static::lazy_load(function () use($item) { return Model_Video::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'videos'); } } } // return the result return $result; }
/** * Get comment image * * @return Model_Image */ public function image() { try { return $this->image_id ? Model_Image::factory($this->image_id) : null; } catch (AutoModeler_Exception $e) { return null; } }
/** * Render view. * * @return string */ public function content() { ob_start(); ?> <div class="image"> <figure> <?php echo HTML::image($this->image->get_url()); ?> </figure> </div> <?php return ob_get_clean(); }
/** * add_relation * @return type */ public static function add_relation() { try { if (!self::validation_add_relation()) { return self::error(); } # lat&lng -> geohash $geohash = Util_Geohash::encode(Input::post('lat'), Input::post('lng')); # transaction DB::start_transaction(); # shop_id指定 if (is_null(Input::post('shop_id'))) { # new shop $shop_id = Model_Shop::add(Input::post('shop_name')); } else { $data = Model_Shop::get_by_pk("shop", Input::post('shop_id')); if (!$data) { throw new Exception('shop_id ' . Input::post('shop_id') . " is not exsits."); } $shop_id = $data['shop_id']; } # new shop geo add if (is_null(Input::post('shop_id'))) { if (!self::add($shop_id, Input::post('lat'), Input::post('lng'), $geohash)) { throw new Exception("insert geo fail."); } } # fileupload & setting self::$file_name = self::file_upload($shop_id); self::$file_path = self::UPLOAD_DIR . Input::post('shop_id') . DS . self::$file_name; if (!self::$file_name) { throw new Exception('file upload fail.'); } # image resize # todo # image add if (!Model_Image::add($shop_id, Input::post('user_id'), self::$file_name)) { throw new Exception("insert image fail."); } # commit DB::commit_transaction(); # success $data = ['status' => CREATED]; } catch (Exception $ex) { # 画像ファイルが存在すれば削除 if (is_file(self::$file_path)) { unlink(self::$file_path); } # rollback DB::rollback_transaction(); $data = ['status' => DATABASE_ERROR, 'message' => '[database error]insert table fail.']; Log::error($ex); } return $data; }
public static function save_uploaded_image($image, $target_path) { if (Model_Image::validate_uploaded_image($image)) { if ($file = Upload::save($image, NULL, DOCROOT . "images/")) { Image::factory($file)->save($target_path); // Delete the temporary file unlink($file); return TRUE; } } return FALSE; }
protected function _save_image($image, $project_id, $file_id, $filename = NULL) { if (!$filename) { $filename = $file_id . "_" . $project_id . "_" . strtolower(Text::random('alnum', 32)) . '.' . pathinfo($image['name'], PATHINFO_EXTENSION); } $target_path = DOCROOT . 'images/projects/' . $project_id . '/' . $filename; if (Model_Image::save_uploaded_image($image, $target_path)) { return $filename; } else { return FALSE; } }
/** * Render view. * * @return string */ public function content() { ob_start(); echo '<figure>', HTML::image($this->image->get_url(Model_Image::SIZE_THUMBNAIL)), '</figure>'; // Tagged people if ($this->image->description) { $names = array(); foreach (explode(',', $this->image->description) as $name) { $names[] = HTML::user(trim($name)); } echo __('In picture: :users', array(':users' => implode(', ', $names))); } // Copyright if ($this->image->author_id) { echo '<br />© ', HTML::user($this->image->author_id); } // Comments if ($this->image->comment_count) { echo '<span class="stats"><i class="icon-comment"></i> ' . $this->image->comment_count . '</span>'; } return ob_get_clean(); }
public function pageAction() { // action body $idpage = $this->_getParam('idpage', 0); $this->view->content = Model_Page::getById($idpage, $this->view->lang); $this->view->gallery = Model_Image::getAll($this->view->content->idgallery); $this->view->video = Model_Image::getAll($this->view->content->idvideo); $this->view->audio = Model_Image::getAll($this->view->content->idaudio); if (is_object($this->view->content)) { $this->view->pageTitle = $this->view->content->title; $this->view->headMeta()->appendName('keywords', $this->view->content->keyword); $this->view->headMeta()->appendName('description', $this->view->content->description); } //@TODO додати на сторінку title keywords description }
public function action_settings() { $system_settings = ORM::factory('Systemsetting')->find_all(); if ($this->request->post()) { $values = $this->request->post(); switch ($this->request->param('id')) { case 'save': foreach ($system_settings as $setting) { // save new logo: if ($setting->name == 'logo_ext') { $image = $_FILES['logo']; if ($this->request->post('delete_logo')) { unlink(DOCROOT . 'images/logo' . '.' . $setting->value); $setting->value = NULL; } if (Model_Image::validate_uploaded_image($image)) { if (Model_Image::save_uploaded_image($image, DOCROOT . 'images/logo' . '.' . pathinfo($image['name'], PATHINFO_EXTENSION))) { // delete old logo image if the old one has different file extension than the new one if ($setting->value && $setting->value != pathinfo($image['name'], PATHINFO_EXTENSION)) { unlink(DOCROOT . 'images/logo' . '.' . $setting->value); } $setting->value = pathinfo($image['name'], PATHINFO_EXTENSION); } } } else { $setting->value = $this->request->post($setting->name); } try { $setting->save(); } catch (ORM_Validation_Exception $e) { $this->template->data["errors"] = $e->errors('models'); } } break; } if (!$this->template->data["errors"]) { $this->redirect('admin/system/settings/save'); } } else { $values = array(); foreach ($system_settings as $setting) { $values[$setting->name] = $setting->value; } } $this->template->values = $values; $this->template->templates = $this->get_templates(); $this->template->languages = ORM::factory('Language')->get_languages(); }
public function uploadfileAction($filePrefix = 'file_', $fileSize, $tmpFileName, $destinationFile, $resize_params = null, $thumbs_params = null) { if ($fileSize <= 2097152) { if (move_uploaded_file($tmpFileName, $destinationFile)) { $nufile = $filePrefix . uniqid() . '.jpg'; rename($destinationFile, UPLOADS_PATH . '/' . $nufile); $image = new Model_Image(); $image->load(UPLOADS_PATH . '/' . $nufile); if ($resize_params && !empty($resize_params)) { if (count($resize_params) == 1) { $image->resizeToHeight($resize_params[0]); } else { $image->resize($resize_params[0], $resize_params[1]); // 640 x 480 } $image->save(UPLOADS_PATH . '/' . $nufile); } //create thumbs dir if not exist if (!is_dir(UPLOADS_PATH . '/thumbs')) { mkdir(UPLOADS_PATH . '/thumbs'); } //create thumb image in thumbs dir using Model_Image if ($thumbs_params && !empty($thumbs_params)) { if (count($thumbs_params) == 1) { $image->resizeToWidth($thumbs_params[0]); } else { $image->resize($thumbs_params[0], $thumbs_params[1]); // 640 x 480 } $image->save(UPLOADS_PATH . '/thumbs/th_' . $nufile); } //create db record $nufile_id = $this->insertData("Files", array("Created" => date('Y-m-d H:i:s'), "LastEdited" => date('Y-m-d H:i:s'), "Filename" => $nufile)); } } return array('FileID' => $nufile_id, 'Filename' => $nufile); }
/** * Get newsfeed item as HTML * * @static * @param Model_NewsfeedItem $item * @return string */ public static function get(Model_NewsFeedItem $item) { $text = ''; switch ($item->type) { case self::TYPE_DEFAULT_IMAGE: $image = Model_Image::factory($item->data['image_id']); if ($image->loaded()) { $text = __('changed their default image'); } break; case self::TYPE_FRIEND: $friend = Model_User::find_user($item->data['friend_id']); if ($friend->loaded()) { $text = __('added :friend as a friend', array(':friend' => HTML::user($friend))); } break; case self::TYPE_LOGIN: $text = __('logged in'); break; } return $text; }
/** * Get notification as HTML. * * @static * @param Model_Notification * @return string */ public static function get(Model_Notification $notification) { $text = ''; switch ($notification->type) { case self::TYPE_IMAGE_COMMENT: $user = Model_User::find_user($notification->user_id); $image = Model_Image::factory($notification->data_id); if ($user->loaded() && $image->loaded()) { $gallery = $image->gallery(); $text = __(':user commented your :photo: <em>:comment</em>', array(':user' => HTML::user($user), ':photo' => HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), __('photo'), array('class' => 'hoverable')), ':comment' => Text::smileys(Text::auto_link_urls(HTML::chars($notification->text))))); } else { $notification->delete(); } break; case self::TYPE_IMAGE_NOTE: $user = Model_User::find_user($notification->user_id); $image = Model_Image::factory($notification->data_id); if ($user->loaded() && $image->loaded()) { $gallery = $image->gallery(); $text = __(':user tagged you to a :photo', array(':user' => HTML::user($user), ':photo' => HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), __('photo'), array('class' => 'hoverable')))); } else { $notification->delete(); } break; case self::TYPE_IMAGE_REPORT: $user = Model_User::find_user($notification->user_id); $image = Model_Image::factory($notification->data_id); if ($user->loaded() && $image->loaded()) { $gallery = $image->gallery(); $text = __(':user reported a :photo: <em>:reason</em>', array(':user' => HTML::user($user), ':photo' => HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), __('photo'), array('class' => 'hoverable')), ':reason' => $notification->text ? HTML::chars($notification->text) : __('No reason'))); } else { $notification->delete(); } break; } return $text; }
/** * Get additional content data selected * * @param $result = Query result */ public static function post_find($result) { if ($result !== null) { if (is_array($result)) { foreach ($result as $item) { // It will first check if we already have result in temporary result, // and only execute query if we dont. That way we dont have duplicate queries // Get content images $item->get_images = static::lazy_load(function () use($item) { return Model_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'images'); // Get content files $item->get_files = static::lazy_load(function () use($item) { return Model_File::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'files'); // Get content videos $item->get_videos = static::lazy_load(function () use($item) { return Model_Video::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'videos'); // Get content children $item->get_children = static::lazy_load(function () use($item) { return Model_Casestudy::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'children'); // Get content accordions $item->get_accordions = static::lazy_load(function () use($item) { return Model_Accordion::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc'))); }, $item->id, 'accordions'); // Get content children $item->get_seo = static::lazy_load(function () use($item) { return Model_Seo::find_one_by_content_id($item->id); }, $item->id, 'seo', 'object'); // Get related products $item->get_related_products = static::lazy_load(function () use($item) { $related = Model_Application_To_Related::find(function ($query) use($item) { return $query->where('application_id', $item->id); }, 'related_id'); if (!empty($related)) { $related = '(' . implode(',', array_keys($related)) . ')'; return \Product\Model_Product::find(function ($query) use($related, $item) { $query->where('id', 'IN', \DB::expr($related)); $query->where('id', '<>', $item->id); $query->order_by('sort', 'asc'); return $query; }, 'id'); } return array(); }, $item->id, 'related_products'); // Get hotspot images $item->get_hotspot = static::lazy_load(function () use($item) { $return = new \stdClass(); $return->images = Model_Application_Image::find_by_application_id($item->id); return $return; }, $item->id, 'hotspot', 'object'); } } } // return the result return $result; }
/** * Prepare venue for data array. * * @param Model_Venue $venue * @param array $fields * @return array */ protected function _prepare_venue(Model_Venue $venue, array $fields = null) { $data = array(); if (!$fields) { $fields = self::$_fields; } foreach ($fields as $field) { switch ($field) { // Raw value case 'id': case 'name': case 'description': case 'hours': case 'address': case 'zip': case 'info': case 'latitude': case 'longitude': case 'created': case 'modified': case 'foursquare_id': case 'foursquare_category_id': $data[$field] = $venue->{$field}; break; // Custom value // Custom value case 'city': $data[$field] = $venue->city_name; break; case 'default_image': $image = new Model_Image($venue->default_image_id); $data[$field] = $image->loaded() ? $image->get_url() : ''; break; case 'homepage': $data[$field] = $venue->url; break; case 'url': $data[$field] = URL::site(Route::model($venue), true); break; } } return $data; }
/** * Get the image of current EXIF data. * * @return Model_Image */ public function image() { return Model_Image::factory($this->image_id); }
/** * Get image comments section. * * @param Model_Image $image * @param string $route * @return View_Generic_Comments */ public function section_image_comments(Model_Image $image, $route = 'gallery_image_comment') { $section = new View_Generic_Comments($image->comments(self::$user)); $section->delete = Route::url($route, array('id' => '%d', 'commentaction' => 'delete')) . '?token=' . Security::csrf(); $section->private = false; return $section; }
/** * Action: image */ public function action_image() { $this->history = false; $user = $this->_get_user(); Permission::required($user, Model_User::PERMISSION_UPDATE, self::$user); // Change default image if ($image_id = (int) Arr::get($_REQUEST, 'default')) { /** @var Model_Image $image */ $image = Model_Image::factory($image_id); if (Security::csrf_valid() && $image->loaded() && $user->has('images', $image->id)) { $user->default_image_id = $image->id; $user->picture = $image->get_url(); $user->save(); } $cancel = true; } // Delete existing if ($image_id = (int) Arr::get($_REQUEST, 'delete')) { /** @var Model_Image $image */ $image = Model_Image::factory($image_id); if (Security::csrf_valid() && $image->loaded() && $user->has('images', $image->id)) { $user->remove('image', $image->id); if ($image->id === $user->default_image_id) { $user->default_image_id = null; $user->picture = null; } $user->save(); $image->delete(); } $cancel = true; } // Cancel change if (isset($cancel) || isset($_REQUEST['cancel'])) { $this->request->redirect(URL::user($user)); } $image = Model_Image::factory(); $image->author_id = $user->id; $image->created = time(); // Handle post $errors = array(); if ($_POST && $_FILES) { $image->file = Arr::get($_FILES, 'file'); try { $image->save(); // Add exif, silently continue if failed - not critical try { $exif = Model_Image_Exif::factory(); $exif->image_id = $image->id; $exif->save(); } catch (Kohana_Exception $e) { } // Set the image as user image $user->relate('images', array($image->id)); $user->default_image_id = $image->id; $user->picture = $image->get_url(); // @TODO: Legacy, will be removed after migration $user->save(); // Newsfeed NewsfeedItem_User::default_image($user, $image); $this->request->redirect(URL::user($user)); } catch (Validation_Exception $e) { $errors = $e->array->errors('validation'); } catch (Kohana_Exception $e) { $errors = array('file' => __('Failed with image')); } } // Build page $this->_set_page($user); $this->view->tab = 'profile'; $this->view->add(View_Page::COLUMN_MAIN, $this->section_upload(URL::user($user), $errors)); }
/** * Delete content image * * @param $image_id = Image ID * @param $content_id = Content ID */ public function action_delete_image($image_id = false, $content_id = false) { // Accordion from home page? if ($content_id == 1) { \Config::load('page::accordion_banner', 'details', true, true); } if ($image_id && $content_id) { $images = Model_Image::find(array('where' => array('content_id' => $content_id), 'order_by' => array('sort' => 'asc')), 'id'); if ($images) { if (isset($images[$image_id])) { $image = $images[$image_id]; // If there is only one image and image is required if (count($images) == 1) { if (\Config::get('details.image.required', false)) { \Messages::error('You can\'t delete all images. Please add new image in order to delete this one.'); } else { // Reset sort fields \DB::update(Model_Image::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $image->sort)->execute(); // Delete image $this->delete_image($image->image); $image->delete(); \Messages::success('Image was successfully deleted.'); } } else { if ($image->cover == 1) { \Messages::error('You can\'t delete cover image. Set different image as cover in order to delete this one.'); } else { // Reset sort fields \DB::update(Model_Image::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $image->sort)->execute(); // Delete image $this->delete_image($image->image); $image->delete(); \Messages::success('Image was successfully deleted.'); } } } else { \Messages::error('Image you are trying to delete don\'t exists. Check your url and try again.'); } } else { \Messages::error('Content Image you are trying to delete don\'t exists. Check your url and try again.'); } } \Response::redirect(\Input::referrer()); }
/** * Get user's new comment counts * * @return array */ public function find_new_comments() { $new = array(); // Profile comments if ($this->new_comment_count) { $new['new-comments'] = HTML::anchor(URL::user($this), __(':comments', array(':comments' => '<div></div><var>' . $this->new_comment_count . '</var>')), array('title' => __('New comments'))); } // Blog comments $blog_comments = Model_Blog_Entry::find_new_comments($this); 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), __(':comments', array(':comments' => '<div></div><var>' . $new_comments . '</var>')), array('title' => __('New blog comments'))); } unset($blog_comments); // Forum quotes $forum_quotes = Model_Forum_Quote::find_by_user($this); 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' => Route::model_id($quote->topic), 'id' => $quote->post->id)) . '#post-' . $quote->post->id, __(':quotes', array(':quotes' => '<div></div><var>' . $new_quotes . '</var>')), array('title' => __('Forum quotes'))); } // Images waiting for approval if (Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_APPROVE_WAITING, $this)) { $gallery_approvals = Model_Gallery::find_pending(Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_APPROVE, $this) ? null : $this); if (count($gallery_approvals)) { $new_approvals = count($gallery_approvals); $new['new-gallery-approvals'] = HTML::anchor(Route::get('galleries')->uri(array('action' => 'approval')), __(':galleries', array(':galleries' => '<div></div><var>' . $new_approvals . '</var>')), array('title' => __('Galleries waiting for approval'))); } } // Image comments $image_comments = Model_Image::find_new_comments($this); if (count($image_comments)) { $new_comments = 0; foreach ($image_comments as $image) { $new_comments += $image->new_comment_count; } $new['new-image-comments'] = HTML::anchor(Route::get('gallery_image')->uri(array('gallery_id' => Route::model_id(Model_Gallery::find_by_image($image->id)), 'id' => $image->id, 'action' => '')), __(':comments', array(':comments' => '<div></div><var>' . $new_comments . '</var>')), array('title' => __('New image comments'))); } unset($image_comments); // Private messages return $new; }
/** * Prepare user for data array * * @param Model_User $user * @param array $fields * @return array */ protected function _prepare_user(Model_User $user, array $fields = null) { $data = array(); empty($fields) and $fields = self::$_fields; foreach ($fields as $field) { switch ($field) { // Raw value case 'id': case 'username': case 'homepage': case 'gender': case 'description': case 'logins': case 'posts': case 'adds': case 'signature': case 'title': case 'dob': case 'latitude': case 'longitude': case 'created': case 'modified': case 'last_login': $data[$field] = $user->{$field}; break; // Custom value // Custom value case 'city': $data[$field] = ($city = $user->city()) ? $city->name : $user->city_name; break; case 'avatar': $data[$field] = $user->avatar ? URL::site($user->avatar, true) : URL::site('avatar/unknown.png'); break; case 'picture': if ($user->default_image_id) { $image = new Model_Image($user->default_image_id); $data[$field] = $image->loaded() ? $image->get_url() : ''; } else { if (Valid::url($user->picture)) { $data[$field] = URL::site($user->picture, true); } else { $data[$field] = null; } } break; case 'url': $data[$field] = URL::site(URL::user($user), true); break; } } return $data; }