Ejemplo n.º 1
0
 public function action_save()
 {
     if ($_POST && $_FILES) {
         $imageChanged = false;
         $data = (object) $this->sanitize($_POST);
         $update = false;
         if ($data->id == "") {
             $editorial = ORM::factory("editorial");
         } else {
             $editorial = ORM::factory("editorial", $data->id);
         }
         if (in_array($_FILES['image']['type'], $this->allowed)) {
             Upload::$default_directory = Kohana::config('myshot.basePath');
             if ($stage_path = Upload::save($_FILES['image'])) {
                 $imageChanged = true;
                 Library_Akamai::factory()->addToDir($stage_path, 'editorials');
             }
         }
         $editorial->title = $data->title;
         $editorial->image = $imageChanged ? Kohana::config('myshot.cdn') . 'editorials/' . basename($stage_path) : $editorial->image;
         $editorial->image_alt = $data->image_alt;
         $editorial->link = $data->link;
         $editorial->link_text = $data->link_text;
         $editorial->text = $data->text;
         $editorial->save();
         Message::set(Message::SUCCESS, $update ? "You have sucessfully updated the editorial." : "You have sucessfully added the editorial.");
     }
     Request::instance()->redirect('admin/editorials');
 }
Ejemplo n.º 2
0
 public function action_save($pid = null)
 {
     $data = (object) filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
     $photo = ORM::factory("dlsliderphoto", $pid);
     $slider = ORM::factory("dlslidergroup", $data->slider_id);
     $new = empty($photo->id);
     if (!$slider->loaded()) {
         Message::set(Message::ERROR, "Something unexpected happened. Please try again.");
         $this->request->redirect("admin/dlslider/");
         return;
     }
     $files = Validate::factory($_FILES);
     $files->rule('photo', 'Upload::type', array(array('jpg', 'png', 'gif')));
     foreach ($data as $val) {
         if (empty($val)) {
             Message::set(Message::ERROR, "All fields must be filled in.");
             $this->request->redirect("admin/dlslider/edit/{$slider->id}");
             return;
         }
     }
     $photo->title = $data->title;
     $photo->teaser = $data->teaser;
     $photo->link_text = $data->linktext;
     $photo->link = $data->link;
     $photo->saved = isset($data->save) ? 1 : 0;
     if (empty($photo->position)) {
         $photo->position = $slider->allPhotos->count() + 1;
     }
     if ($files->check()) {
         if ($_FILES['photo']['error'] == 0) {
             $filename = upload::save($_FILES['photo'], $_FILES['photo']['name'], Kohana::config('myshot.relativeBase'));
             // New file name
             $new_filename = rand(0, 1000) . "_" . substr($_FILES['photo']['name'], 0, strlen($_FILES['photo']['name']) - 4) . '-resized' . substr($_FILES['photo']['name'], -4);
             $localFile = Kohana::config('myshot.relativeBase') . $new_filename;
             // Resize, sharpen, and save the image
             Image::factory($filename)->resize(Model_DLSliderPhoto::WIDTH, Model_DLSliderPhoto::HEIGHT, Image::WIDTH)->crop(Model_DLSliderPhoto::WIDTH, Model_DLSliderPhoto::HEIGHT, 0, 0)->save($localFile);
             Library_Akamai::factory()->addToDir($localFile, "dlslider", date("Y-m"));
             $photo->filename = "dlslider/" . date("Y-m") . "/{$new_filename}";
             // Remove the temporary files
             unlink($filename);
             unlink($localFile);
         }
     }
     if (empty($photo->filename)) {
         Message::set(Message::ERROR, "Something was wrong with the file to upload. Please check the file try again.");
         $this->request->redirect("admin/dlslider/edit/{$slider->id}");
         return;
     }
     $photo->save();
     if ($new) {
         DB::update("dl_slider_group_dl_slider_photos")->set(array("position" => $slider->allPhotos->count()))->where("dl_slider_group_id", "=", $slider->id)->where("dl_slider_photos_id", "=", $photo->id)->execute();
     }
     !$slider->has("photos", $photo) ? $slider->add("photos", $photo) : null;
     Message::set(Message::SUCCESS, "Image Added");
     $this->request->redirect("admin/dlslider/edit/{$slider->id}");
 }
Ejemplo n.º 3
0
 public function resizeHonor($path, $height)
 {
     $img = Image::factory($path);
     $path_info = pathinfo($path);
     $savedAt = $path_info['dirname'] . '/' . $path_info['filename'] . '_x' . $height . '.' . $path_info['extension'];
     if ($img->height > $height) {
         $img->resize(NULL, $height, Image::HEIGHT);
     }
     if ($img->save($savedAt)) {
         Library_Akamai::factory()->addToDir($savedAt, Kohana::config('akamai.honordir'));
         return $savedAt;
     }
 }
Ejemplo n.º 4
0
 public function reset_crop($photo)
 {
     $photo->moderation_status_id = '1';
     $path = Kohana::config('myshot.basePath');
     if (!empty($photo->small)) {
         if (file_exists($path . $photo->small)) {
             unlink($path . $photo->small);
         }
     }
     if (!empty($photo->thumbnail)) {
         if (file_exists($path . $photo->thumbnail)) {
             unlink($path . $photo->thumbnail);
         }
     }
     Library_Akamai::factory()->remove($photo->small)->remove($photo->thumbnail);
     return TRUE;
 }
Ejemplo n.º 5
0
 public function action_avatars($grp = 0)
 {
     $basePath = APPPATH . "cache/";
     $this->template->content = "<pre>";
     if (!$this->active) {
         $this->template->content = "*";
         return;
     }
     $avatars = ORM::factory("avatar")->where("thumbnail", "NOT LIKE", "%/%")->where("moderation_status_id", "=", 2)->offset($grp * $this->grpSize)->limit($this->grpSize)->find_all();
     $akm = Library_Akamai::factory();
     foreach ($avatars as $avatar) {
         $this->template->content .= "{$avatar->id}: {$avatar->original} || {$avatar->created} \r\n";
         $finalPath = $avatar->creationYear() . "/" . $avatar->creationMonth() . "/";
         $thumb = $avatar->thumbnail;
         $medium = $avatar->medium;
         $large = $avatar->large;
         $original = $avatar->original;
         $akm->pull($avatar->thumbnail)->pull($avatar->medium)->pull($avatar->large);
         $akm->addToDir($basePath . $avatar->thumbnail, $avatar->creationYear(), $avatar->creationMonth())->addToDir($basePath . $avatar->medium, $avatar->creationYear(), $avatar->creationMonth())->addToDir($basePath . $avatar->large, $avatar->creationYear(), $avatar->creationMonth());
         $avatar->thumbnail = $finalPath . $avatar->thumbnail;
         $avatar->medium = $finalPath . $avatar->medium;
         $avatar->large = $finalPath . $avatar->large;
         $avatar->save();
         //cleanup remote
         $akm->remove($thumb)->remove($medium)->remove($large);
         //cleanup local
         unlink($basePath . $thumb);
         unlink($basePath . $medium);
         unlink($basePath . $large);
         try {
             $akm->pull($avatar->original);
             $akm->addToDir($basePath . $avatar->original, $avatar->creationYear(), $avatar->creationMonth());
             $avatar->original = $finalPath . $avatar->original;
             $avatar->save();
             $akm->remove($original);
             unlink($basePath . $original);
         } catch (ErrorException $e) {
             $this->template->content .= "--";
         }
         $this->template->content .= "***********\r\n";
     }
     $this->template->content .= "</pre>";
 }
Ejemplo n.º 6
0
 public function delete($id = NULL)
 {
     if (!$this->loaded()) {
         $this->find($id);
     }
     $base = Kohana::config('myshot.basePath');
     if (file_exists($base . $this->thumbnail) and !empty($this->thumbnail)) {
         unlink($base . $this->thumbnail);
     }
     if (file_exists($base . $this->medium) and !empty($this->medium)) {
         unlink($base . $this->medium);
     }
     if (file_exists($base . $this->large) and !empty($this->large)) {
         unlink($base . $this->large);
     }
     if (file_exists($base . $this->original) and !empty($this->original)) {
         unlink($base . $this->original);
     }
     Library_Akamai::factory()->remove($this->thumbnail)->remove($this->medium)->remove($this->large)->remove($this->original);
     parent::delete($id);
 }
Ejemplo n.º 7
0
 public function action_save()
 {
     $data = (object) filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
     $background = ORM::factory("background", $data->id);
     if (!$background->loaded()) {
         $background = ORM::factory("background");
     }
     $background->color = $data->color;
     if ($_FILES["image"]["error"] == 0) {
         $filename = upload::save($_FILES['image'], $_FILES['image']['name'], Kohana::config('myshot.relativeBase'));
         $thumbName = substr($_FILES['image']['name'], 0, strlen($_FILES['image']['name']) - 4) . '-thumb' . substr($_FILES['image']['name'], -4);
         $localThumb = Kohana::config('myshot.relativeBase') . $thumbName;
         Image::factory($filename)->resize(100, 91, Image::WIDTH)->save($localThumb);
         Library_Akamai::factory()->addToDir($filename, "backgrounds")->addToDir($localThumb, "backgrounds");
         $background->path = "backgrounds/" . $_FILES['image']['name'];
         $background->thumb = "backgrounds/" . $thumbName;
         unlink($filename);
         unlink($localThumb);
     }
     $background->save();
     Helper_Background::renderCSS();
     $this->request->redirect("admin/backgrounds");
 }
Ejemplo n.º 8
0
 private function editAward($award)
 {
     $data = Arr::merge($this->sanitize($_POST), $_FILES);
     $award->title = $data['name'];
     $award->desc = $data['description'];
     if (isset($data['photo']) && $data['photo']['name'] != "") {
         Upload::$default_directory = Kohana::config('myshot.basePath');
         if ($stage_path = Upload::save($data['photo'])) {
             foreach ($award->_images as $image) {
                 $name = (string) $image->type->name;
                 if ($image->type->name == self::FULL) {
                     $path_info = pathinfo($stage_path);
                     $savedAt = $path_info['dirname'] . '/' . $path_info['filename'] . '.' . $path_info['extension'];
                     Library_Akamai::factory()->addToDir($savedAt, Kohana::config('akamai.honordir'));
                     $image->path = $this->webpath($stage_path);
                 } else {
                     $image->path = $this->webPath($this->resizeHonor($stage_path, ImageTypes::types()->{$name}->size));
                 }
                 $image->save();
             }
         }
     }
     $award->save();
 }
Ejemplo n.º 9
0
 public function action_view($photo_id)
 {
     $photo = ORM::factory('photo')->where('id', '=', $photo_id)->where('moderation_status_id', '=', '2')->find();
     if ($photo->loaded()) {
         if (isset($_POST['comment'])) {
             Request::factory('comments/on/' . $photo_id)->execute();
         }
         if (isset($_POST['awards']) && Helper_Account::is_admin()) {
             $gamePhoto = Helper_Game::getUser($photo->user->id)->getItem($photo_id);
             foreach ($_POST['awards'] as $awardId) {
                 $award = ORM::factory('game_Award', $awardId);
                 if (!$gamePhoto->hasAward($award)) {
                     $gamePhoto->addAward($award);
                     Helper_Game::logEvent(Helper_Game::AWARD_GIVEN, $photo->user->id, $photo->id, array('honor_id' => $award->id, 'type' => 'game_Award'));
                 }
             }
             Message::set(Message::SUCCESS, 'Awards updated.');
         }
         //get dimensions if not present
         if (empty($photo->width)) {
             try {
                 $akm = Library_Akamai::factory();
                 $akm->pull($photo->original);
                 $location = Kohana::config('myshot.basePath') . $photo->original;
                 $img = Image::factory($location);
                 $photo->width = $img->width;
                 $photo->height = $img->height;
                 $photo->save();
                 unlink($location);
             } catch (Kohana_Exception $e) {
                 //don't do anything. It is jut too late to get the size of the photo
             }
         }
         $photo->increment_view();
         $dphoto = ORM::factory("DailyPhoto")->order_by("day", "DESC")->find();
         $galleries = ORM::factory("gallery")->find_all();
         $gall_ids = array();
         foreach ($galleries as $gallery) {
             //array_push($gall_ids, array($gallery->id => $gallery->name));
             $gall_ids[$gallery->id] = $gallery->name;
         }
         $user_photos = $photo->user->photos->where('moderation_status_id', '=', '2')->order_by('order', 'ASC')->find_all();
         $this->template->title = $photo->name . ' Photo - National Geographic Kids My Shot';
         $this->template->content = View::factory('photos/view');
         $this->template->content->set(array('user' => $photo->user, 'photo' => $photo, 'user_owns_page' => $photo->user->id == $this->user->id, 'allAwards' => Helper_Game::getSite()->awards, 'awards' => Helper_Game::getUser($photo->user->id)->getItem($photo->id)->awards, 'isaFan' => $this->user->id ? Helper_Game::getUser($this->user->id)->isFollowing($photo->user->id) : false, 'isFav' => $this->user->isFavorite($photo_id), 'loggedin' => $this->user->id !== null, 'user_photos' => $user_photos, 'order' => Helper_Photos::get_order_array($user_photos), 'comments' => $photo->readableComments(), 'lastDaily' => $dphoto, 'awaiting_comments' => ORM::factory('comment')->where('photo_id', '=', $photo_id)->where('moderation_status_id', '=', '1')->where('user_id', '=', $this->user->id)->find_all()));
         $this->template->content->galleries = $gall_ids;
         $this->template->styles = array('public/js/vendor/rating/jquery.rating.css' => 'screen', 'public/js/vendor/datepicker/jquery-ui-1.8.5.custom.css' => 'screen');
         $this->template->scripts = array('public/js/vendor/rating/jquery.MetaData.js', 'public/js/vendor/rating/jquery.rating.pack.js', 'public/js/vendor/jquery.jcarousel.js', 'public/js/vendor/swfobject.js', 'public/js/photos/view.js', 'public/js/vendor/word-count.js', 'public/js/vendor/jquery.tools.min.js', 'public/js/vendor/jquery-ui-1.8.5.custom.min.js', 'public/js/vendor/fl_runcontent.js', 'public/js/photos/caption-this.js', 'public/js/photos/award.js');
         $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar());
     } else {
         Message::set(Message::NOTICE, 'The photo you requested doesn\'t exist!');
         Request::instance()->redirect('/');
     }
 }
Ejemplo n.º 10
0
 public function delete($id = NULL)
 {
     if (!$this->loaded()) {
         $this->find($id);
     }
     $base = Kohana::config('myshot.basePath');
     $caption_this_photo = ORM::factory('captionthisphoto')->where('photo_id', '=', $this->id)->find();
     if ($caption_this_photo->loaded()) {
         $caption_this_photo->delete();
     }
     if (file_exists($base . $this->thumbnail) and !empty($this->thumbnail)) {
         unlink($base . $this->thumbnail);
     }
     if (file_exists($base . $this->small) and !empty($this->small)) {
         unlink($base . $this->small);
     }
     if (file_exists($base . $this->medium) and !empty($this->medium)) {
         unlink($base . $this->medium);
     }
     if (file_exists($base . $this->large) and !empty($this->large)) {
         unlink($base . $this->large);
     }
     if (file_exists($base . $this->original) and !empty($this->original)) {
         unlink($base . $this->original);
     }
     Library_Akamai::factory()->remove($this->thumbnail)->remove($this->small)->remove($this->medium)->remove($this->large)->remove($this->original);
     //remove all the comments for this photo
     foreach ($this->comments->find_all() as $comment) {
         $comment->delete();
     }
     //remove all game logs for this photo
     $userItems = ORM::factory("Game_UserItem")->where("item_id", "=", $this->id)->find_all();
     foreach ($userItems as $item) {
         $item->delete();
     }
     //find all logs that refer to this photo and delete them as well
     $logInfos = ORM::factory("Game_LogInfo")->and_where_open()->where("name", "like", "photo")->or_where("name", "like", "photo_id")->and_where_close()->where("data", "=", $this->id)->find_all();
     foreach ($logInfos as $logInfo) {
         $logInfo->_eventLog->delete();
     }
     parent::delete($this->id);
 }
Ejemplo n.º 11
0
 public function upload_all($avatar)
 {
     $basePath = Kohana::config('myshot.basePath');
     $finalPath = $avatar->creationYear() . "/" . $avatar->creationMonth() . "/";
     Library_Akamai::factory()->addToDir($basePath . $avatar->thumbnail, $avatar->creationYear(), $avatar->creationMonth())->addToDir($basePath . $avatar->medium, $avatar->creationYear(), $avatar->creationMonth())->addToDir($basePath . $avatar->large, $avatar->creationYear(), $avatar->creationMonth())->addToDir($basePath . $avatar->original, $avatar->creationYear(), $avatar->creationMonth());
     //remove local copies
     if (file_exists($basePath . $avatar->thumbnail) and !empty($avatar->thumbnail)) {
         unlink($basePath . $avatar->thumbnail);
     }
     if (file_exists($basePath . $avatar->medium) and !empty($avatar->medium)) {
         unlink($basePath . $avatar->medium);
     }
     if (file_exists($basePath . $avatar->large) and !empty($avatar->large)) {
         unlink($basePath . $avatar->large);
     }
     if (file_exists($basePath . $avatar->original) and !empty($avatar->original)) {
         unlink($basePath . $avatar->original);
     }
     if (strpos($avatar->thumbnail, $finalPath) === false) {
         $avatar->thumbnail = $finalPath . $avatar->thumbnail;
         $avatar->medium = $finalPath . $avatar->medium;
         $avatar->large = $finalPath . $avatar->large;
         $avatar->original = $finalPath . $avatar->original;
         $avatar->save();
     }
 }
Ejemplo n.º 12
0
 public function upload_all($photo)
 {
     $basePath = Kohana::config('myshot.basePath');
     $finalPath = $photo->creationYear() . "/" . $photo->creationMonth() . "/";
     Library_Akamai::factory()->addToDir($basePath . $photo->thumbnail, $photo->creationYear(), $photo->creationMonth())->addToDir($basePath . $photo->small, $photo->creationYear(), $photo->creationMonth())->addToDir($basePath . $photo->medium, $photo->creationYear(), $photo->creationMonth())->addToDir($basePath . $photo->large, $photo->creationYear(), $photo->creationMonth())->addToDir($basePath . $photo->original, $photo->creationYear(), $photo->creationMonth());
     //delete photos off of this server
     Helper_Photos::deleteAllLocal($photo);
     //update locations in database
     if (strpos($photo->thumbnail, $finalPath) === false) {
         $photo->thumbnail = $finalPath . $photo->thumbnail;
         $photo->small = $finalPath . $photo->small;
         $photo->medium = $finalPath . $photo->medium;
         $photo->large = $finalPath . $photo->large;
         $photo->original = $finalPath . $photo->original;
         $photo->save();
     }
 }
Ejemplo n.º 13
0
 private function editBadge($badge)
 {
     $data = Arr::merge($this->sanitize($_POST), $_FILES);
     $badge->title = $data['name'];
     $badge->desc = $data['description'];
     if (isset($data['startstop'])) {
         $badge->available = $data['startyear'] . "-" . $data['startmonth'] . "-" . $data['startday'];
         $badge->expiration = $data['endyear'] . "-" . $data['endmonth'] . "-" . $data['endday'];
     } else {
         $badge->data->available = null;
         $badge->data->expiration = null;
     }
     //Delete unused rules
     foreach ($badge->rules as $rule) {
         $stillHere = false;
         for ($i = 0; $i < count($data['rule_id']); ++$i) {
             if ($data['rule_id'][$i] == $rule->id) {
                 $stillHere = true;
                 break;
             }
         }
         if (!$stillHere) {
             $rule->delete();
         }
     }
     //Add new ones and update existing
     for ($i = 0; $i < count($data['rule_name']); ++$i) {
         $event = ORM::factory('game_Event', $data['event'][$i]);
         if ($data['rule_id'][$i] == 0) {
             $rule = $badge->createRule($data['rule_name'][$i], $event, $data['event_amount'][$i]);
         } else {
             $rule = ORM::factory("game_Rule", $data['rule_id'][$i]);
             $rule->name = $data['rule_name'][$i];
             $rule->event_id = $event->id;
             $rule->amount = $data['event_amount'][$i];
         }
         if ($data['data_key'][$i] != '' && $data['data_key'][$i] != 'key name') {
             $rule->log_info_name = $data['data_key'][$i];
             $rule->operator = $data['data_method'][$i];
             $rule->contains_data = $data['data_content'][$i];
         }
         $rule->save();
     }
     if (isset($data['photo']) && $data['photo']['name'] != "") {
         Upload::$default_directory = Kohana::config('myshot.basePath');
         if ($stage_path = Upload::save($data['photo'])) {
             foreach ($badge->_images as $image) {
                 $name = (string) $image->type->name;
                 if ($image->type->name == self::FULL) {
                     $path_info = pathinfo($stage_path);
                     $savedAt = $path_info['dirname'] . '/' . $path_info['filename'] . '.' . $path_info['extension'];
                     Library_Akamai::factory()->addToDir($savedAt, Kohana::config('akamai.honordir'));
                     $image->path = $this->webpath($stage_path);
                 } else {
                     $image->path = $this->webPath($this->resizeHonor($stage_path, ImageTypes::types()->{$name}->size));
                 }
                 $image->save();
             }
         }
     }
     $badge->save();
 }