/** * Display detail of an album * * @param int $id * @return Response */ public function albumDetail($id) { // Find album by ID $album = Album::where('status', Constants::$COMMON_STATUSES['public'])->find($id); if (empty($album)) { return App::abort('404'); } $images = $album->publicImages()->paginate($this->pageSize); $this->setViewData('model', $album); $this->setViewData('images', $images); return $this->createView('public.album-detail'); }
private function getViewProfileDatas($user_id) { $privacy = Privacy::where('name', "Công khai")->get()->first(); $datas = array(); if (FEUsersHelper::isCurrentUser($user_id)) { $entries = Entry::where('user_id', $user_id)->orderBy('updated_at', 'DESC')->paginate($this->entries_per_page); $left_albums = Album::where('user_id', $user_id)->orderBy('updated_at', 'DESC')->get(); } else { $entries = Entry::where('user_id', $user_id)->where('privacy', $privacy->id)->orderBy('updated_at', 'DESC')->paginate($this->entries_per_page); $left_albums = Album::where('user_id', $user_id)->where('privacy', 1)->orderBy('updated_at', 'DESC')->get(); } return array("entries" => $entries, "left_albums" => $left_albums); }
public function getView($id) { $album = Album::where('id', '=', $id)->first(); $pictures = Picture::where('album_id', '=', $id)->orderBy('votes', 'desc')->paginate(12); // layouts variables $this->layout->title = $album->name . ' | Нещо Шантаво'; $this->layout->canonical = 'https://neshto.shantavo.com/album/' . $id; $this->layout->robots = 'index,follow,noodp,noydir'; $this->layout->description = 'Това е албум'; $this->layout->keywords = 'начало, нещо шантаво, team navy pier'; // nesting the view into the layout $this->layout->nest('content', 'album.view', array('album' => $album, 'pictures' => $pictures)); }
public function index() { $user_id = Input::get('user_id'); $user = User::find($user_id); if ($user) { if (FEUsersHelper::isCurrentUser($user->id)) { $albums_d = Album::where('user_id', '=', $user->id); } else { $albums_d = Album::where('user_id', '=', $user->id)->where('privacy', PrivaciesHelper::getId("Công khai")); } return View::make('frontend/photos/albums/index')->with('user', $user)->with('albums', $albums_d->paginate($this->album_per_page)); } else { return Redirect::to('/'); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $data = Input::except(array('_token', '_method')); $trimmedData = $this->trimData($data, array()); $album = Album::where('name', $trimmedData['name'])->get()->first(); if (!empty($album)) { Session::flash('flash_error', trans('message.album.error.already_exist')); return Redirect::route('secured.album.create')->withInput(); } $currentUser = $this->getCurrentUser(); $album = new Album(); $album->fill($trimmedData); $album->owner_id = $currentUser->id; if (!$album->save()) { $errors = $album->errors(); return Redirect::route('secured.album.create')->withInput()->withErrors($errors); } return Redirect::route('secured.album.index'); }
public function index() { $datas = Input::all(); $params = array(); if (isset($datas['u'])) { $params['user_id'] = $datas['u']; } if (isset($datas['title'])) { $params['title'] = $datas['title']; } if (isset($datas['category'])) { $params['category_id'] = $datas['category']; } $albums_d = Album::where('public', '=', '1'); foreach ($params as $key => $param) { if ($key == 'title') { $op = 'LIKE'; $param = "%" . $param . "%"; } if ($key == 'user_id' || $key == 'category_id') { $op = '='; } $albums_d = Album::where($key, $op, $param); } if (Input::get('s') == 'like') { $albums = $albums_d->orderBy('updated_at', 'DESC')->get()->sortBy(function ($album) { return $album->images->sum('count_like'); }, SORT_REGULAR, true); } else { $albums = $albums_d->orderBy('updated_at', 'DESC')->get(); } if (!empty($params['user_id'])) { $view = View::make('frontend/albums/my-images')->with('albums', $albums); } else { $view = View::make('frontend/index')->with('albums', $albums); } if (!empty($params['category_id'])) { $view->with('category_title', Category::find($params['category_id'])->title); } return $view; }
public function collectoinAlbumIsEmpty() { $collection = Album::where('title', '=', 'foo')->get(); var_dump($collection->isEmpty()); }
public function editAlbum() { if (!Auth::check()) { return Response::json(array('errCode' => 1, 'message' => '请登录')); } $album_id = Input::get('album_id'); $name = Input::get('album_name'); $validation = Validator::make(array('name' => $name), array('name' => 'required')); if ($validation->fails()) { return Response::json(array('errCode' => 2, 'message' => '请填写相册名字')); } $album = Album::where('id', '=', $album_id)->first(); if ($album == null) { return Response::json(array('errCode' => 3, 'message' => '相册不存在!')); } if ($album->user_id != Auth::user()->id) { return Response::json(array('errCode' => 4, 'message' => '不可以修改他人的相册!')); } $album->title = $name; if ($album->save()) { return Response::json(array('errCode' => 0, 'message' => '相册名修改成功!')); } return Response::json(array('errCode' => 4, 'message' => '相册名修改失败!')); }
function aggregate($type, $options = array()) { $options = array_merge(array('featured' => false), $options); $shared_params = array(); if ($type === 'tag') { $shared_params['tags'] = $options['tag_slug']; } else { if ($type === 'category') { $shared_params['category'] = $options['category']; } } $album_params = $shared_params; $date_marker = false; if ($type === 'date') { $s = new Setting(); $s->where('name', 'site_timezone')->get(); $tz = new DateTimeZone($s->value); $offset = $tz->getOffset(new DateTime('now', new DateTimeZone('UTC'))); if ($offset === 0) { $shift = ''; } else { $shift = ($offset < 0 ? '-' : '+') . abs($offset); } // Need to - the offset here, as we need to shift this timestamp by the inverse of the offset to match DB UTC time. // For example. Midnight in user's time (say, CT -5) is UTC+5. $album_params['before'] = $date_marker = strtotime("{$options['year']}-{$options['month']}-{$options['day']} 23:59:59") - $offset; } $aggregate = $essay_ids = $album_ids = $content_ids = $updated_album_ids = $exclude_albums = $exclude_content = $sets = $range = array(); $t = new Text(); $t->select('id, featured, featured_image_id, published_on')->where('page_type', 0)->where('published', 1); if ($type === 'date') { $t->where("YEAR(FROM_UNIXTIME({$t->table}.published_on{$shift}))", $options['year'])->where("MONTH(FROM_UNIXTIME({$t->table}.published_on{$shift}))", $options['month'])->where("DAY(FROM_UNIXTIME({$t->table}.published_on{$shift}))", $options['day']); } else { if ($type === 'tag') { $t->where_related('tag', 'id', $options['tag']); } else { $t->where_related('category', 'id', $options['category']); } } if ($options['featured']) { $t->where('featured', 1); } $t->include_related('album', 'id')->order_by($t->table . '.published_on DESC')->get_iterated(); foreach ($t as $essay) { $essay_ids[$essay->id] = $essay->published_on; $aggregate[] = array('type' => 'essay', 'id' => $essay->id, 'date' => $essay->published_on, 'featured' => $essay->featured); if ($essay->album_id) { $exclude_albums[] = $essay->album_id; } if (is_numeric($essay->featured_image_id)) { $exclude_content[] = $essay->featured_image_id; } } $a = new Album(); $a->select('id, featured, published_on, left_id, right_id, level')->where('visibility', 0)->where('deleted', 0)->where('total_count >', 0); if ($type === 'date') { $a->where("YEAR(FROM_UNIXTIME({$a->table}.published_on{$shift}))", $options['year'])->where("MONTH(FROM_UNIXTIME({$a->table}.published_on{$shift}))", $options['month'])->where("DAY(FROM_UNIXTIME({$a->table}.published_on{$shift}))", $options['day']); } else { if ($type === 'tag') { $a->where_related('tag', 'id', $options['tag']); } else { $a->where_related('category', 'id', $options['category']); } } if ($options['featured']) { $a->where('featured', 1); } $a->include_related('content', 'id')->order_by($a->table . '.published_on DESC')->get_iterated(); foreach ($a as $album) { if (is_numeric($album->content_id)) { $exclude_content[] = $album->content_id; } if (!array_key_exists($album->id, $album_ids) && !in_array($album->id, $exclude_albums)) { $album_ids[$album->id] = $album->published_on; $aggregate[] = array('type' => 'album', 'id' => $album->id, 'date' => $album->published_on, 'featured' => $album->featured); } if ($album->level < 2) { $range = array_merge($range, range($album->left_id, $album->right_id)); } if ($album->level > 1) { $sets[$album->id] = $album->left_id; } } foreach ($sets as $id => $left) { if (in_array($left, $range)) { unset($album_ids[$id]); foreach ($aggregate as $i => $info) { if ($info['type'] === 'album' && $info['id'] == $id) { unset($aggregate[$i]); } } } } $c = new Content(); $c->select('id, published_on, featured'); if (!empty($exclude_content)) { $c->where_not_in('id', $exclude_content); } $c->where('visibility', 0)->where('deleted', 0); if ($type === 'date') { $c->include_related('album')->where("YEAR(FROM_UNIXTIME({$c->table}.published_on{$shift}))", $options['year'])->where("MONTH(FROM_UNIXTIME({$c->table}.published_on{$shift}))", $options['month'])->where("DAY(FROM_UNIXTIME({$c->table}.published_on{$shift}))", $options['day'])->group_start()->where($a->table . '.id', null)->or_where($a->table . '.deleted', 0)->group_end(); } else { if ($type === 'tag') { $c->where_related('tag', 'id', $options['tag']); } else { $c->where_related('category', 'id', $options['category']); } } if ($options['featured']) { $c->where('featured', 1); } $c->order_by($c->table . '.published_on DESC')->get_iterated(); foreach ($c as $content) { if ($content->album_id && $content->album_visibility < 1 && $content->album_published_on <= $date_marker) { if (!isset($updated_album_ids[$content->album_id])) { $updated_album_ids[$content->album_id] = array('items' => array($content->id), 'date' => $content->published_on, 'featured' => $content->album_featured); } else { $updated_album_ids[$content->album_id]['items'][] = $content->id; $updated_album_ids[$content->album_id]['date'] = max($content->published_on, $updated_album_ids[$content->album_id]['date']); } } else { if (!$content->album_id) { $content_ids[$content->id] = $content->published_on; $aggregate[] = array('type' => 'content', 'id' => $content->id, 'date' => $content->published_on, 'featured' => $content->featured); } } } foreach ($updated_album_ids as $id => $a) { $aggregate[] = array('type' => 'updated_album', 'id' => $id, 'date' => $a['date'], 'featured' => $a['featured']); } $total = count($aggregate); if (!function_exists('_sort')) { function _sort($one, $two) { if ($one['featured'] && !$two['featured']) { return -1; } else { if ($one['featured'] && $two['featured']) { return $one['date'] < $two['date'] ? 1 : -1; } } return $two['featured'] || $one['date'] < $two['date'] || $one['date'] === $two['date'] && $two['id'] > $one['id'] ? 1 : -1; } } usort($aggregate, '_sort'); $stream = array('page' => (int) isset($options['page']) ? (int) $options['page'] : 1, 'pages' => (int) ceil($total / $options['limit']), 'per_page' => (int) min($options['limit'], $total), 'total' => (int) $total); $load = array_slice($aggregate, ($stream['page'] - 1) * $options['limit'], $options['limit']); $counts = array('essays' => count($essay_ids), 'albums' => count($album_ids), 'content' => count($content_ids)); $counts['total'] = $counts['essays'] + $counts['albums'] + $counts['content']; $updated_album_ids_arr = $updated_album_ids; $essay_ids = $album_ids = $content_ids = $updated_album_ids = $final = $index = array(); foreach ($load as $i => $item) { $index[$item['type'] . '-' . $item['id']] = $i; ${$item['type'] . '_ids'}[] = $item['id']; } if (!empty($essay_ids)) { $e = new Text(); $e->where_in('id', $essay_ids)->get_iterated(); foreach ($e as $essay) { $final[$index['essay-' . $essay->id]] = $essay->to_array($shared_params); } } if (!empty($album_ids)) { $a = new Album(); $a->where_in('id', $album_ids)->get_iterated(); foreach ($a as $album) { $final[$index['album-' . $album->id]] = $album->to_array($album_params); } } if (!empty($content_ids)) { $c = new Content(); $c->where_in('id', $content_ids)->get_iterated(); foreach ($c as $content) { $final[$index['content-' . $content->id]] = $content->to_array(array_merge($shared_params, array('order_by' => 'published_on'))); } } if (!empty($updated_album_ids)) { $a = new Album(); $a->where_in('id', $updated_album_ids)->get_iterated(); foreach ($a as $album) { $arr = $album->to_array(); $arr['event_type'] = 'album_update'; $arr['content'] = array(); $info = $updated_album_ids_arr[$album->id]; $c = new Content(); $c->where_in('id', $info['items'])->order_by('published_on DESC')->get_iterated(); foreach ($c as $i => $content) { $carr = $content->to_array(array('order_by' => 'published_on', 'in_album' => $album)); if ($i === 0) { $arr['date'] = $carr['date']; } $arr['content'][] = $carr; } $final[$index['updated_album-' . $album->id]] = $arr; } } ksort($final); $stream['items'] = array_values($final); return array($stream, $counts); }
/** * Process upload image file to server and save to database * * @param int $albumId * @param array $errors */ private function processUploadImage($albumId, &$errors) { if (!Input::hasFile('imageFile')) { $errors = trans('message.common.error.file_not_found'); return false; } $currentUser = $this->getCurrentUser(); // Find album $album = Album::where('id', $albumId)->where('owner_id', $currentUser->id)->get()->first(); if (empty($album)) { $errors = trans('message.album.error.album_not_found'); return false; } $file = Input::file('imageFile'); // Upload image file to server and create thumbnail image $uploadedFileName = Utilities::uploadFile($file); if (empty($uploadedFileName)) { $errors = trans('message.common.error.upload_failed'); return false; } // Save data to database $extension = $file->getClientOriginalExtension(); $model = new Image(); $model->name = $uploadedFileName; $model->extension = $extension; $model->album_id = $albumId; $model->status = Input::get('status'); if (!$model->save()) { $errors = $model->errors(); return false; } return true; }
public function getAlbums() { if (Auth::guest()) { return Redirect::secure('/'); } // layouts variables $this->layout->title = 'Албуми | Нещо Шантаво'; $this->layout->canonical = 'https://neshto.shantavo.com/user/albums'; $albums = Album::where('user_id', '=', Auth::user()->id)->get(); $categories = Category::all(); // nesting the view into the layout $this->layout->nest('content', 'user.albums', array('albums' => $albums, 'categories' => $categories)); }
<?php $albums = new Album(); $albums->where('listed', 0)->get(); $albums->update_all('visibility', 1); $done = true;
function index() { list($params, $id, $slug) = $this->parse_params(func_get_args()); // Create or update if ($this->method != 'get') { $c = new Content(); switch ($this->method) { case 'post': case 'put': if ($this->method == 'put') { // Update $c->get_by_id($id); if (!$c->exists()) { $this->error('404', "Content with ID: {$id} not found."); return; } $c->old_published_on = $c->published_on; $c->old_captured_on = $c->captured_on; $c->old_uploaded_on = $c->uploaded_on; if (isset($_POST['slug'])) { $c->current_slug = $c->slug; } } if (isset($_REQUEST['name'])) { if (isset($_REQUEST['upload_session_start'])) { $s = new Setting(); $s->where('name', 'last_upload')->get(); if ($s->exists() && $s->value != $_REQUEST['upload_session_start']) { $s->value = $_REQUEST['upload_session_start']; $s->save(); } } $file_name = $c->clean_filename($_REQUEST['name']); $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0; $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0; $tmp_dir = FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'tmp'; $tmp_path = $tmp_dir . DIRECTORY_SEPARATOR . $file_name; make_child_dir($tmp_dir); if ($chunks == 0 || $chunk == $chunks - 1) { if (isset($_REQUEST['text'])) { $path = FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR; $internal_id = false; } else { if (isset($_REQUEST['plugin'])) { $info = pathinfo($_REQUEST['name']); $path = FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $_REQUEST['plugin'] . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR; $file_name = $_REQUEST['basename'] . '.' . $info['extension']; $internal_id = false; } else { list($internal_id, $path) = $c->generate_internal_id(); } } if ($path) { $path .= $file_name; if ($chunks == 0) { $tmp_path = $path; } } else { $this->error('500', 'Unable to create directory for upload.'); return; } } // Look for the content type header if (isset($_SERVER["HTTP_CONTENT_TYPE"])) { $contentType = $_SERVER["HTTP_CONTENT_TYPE"]; } else { if (isset($_SERVER["CONTENT_TYPE"])) { $contentType = $_SERVER["CONTENT_TYPE"]; } else { $contentType = ''; } } if (strpos($contentType, "multipart") !== false) { if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) { $out = fopen($tmp_path, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file $in = fopen($_FILES['file']['tmp_name'], "rb"); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { $this->error('500', 'Unable to read input stream.'); return; } fclose($out); unlink($_FILES['file']['tmp_name']); } else { $this->error('500', 'Unable to write to output file.'); return; } } else { $this->error('500', 'Unable to move uploaded file.'); return; } } else { $out = fopen($tmp_path, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file $in = fopen("php://input", "rb"); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { $this->error('500', 'Unable to read uploaded file.'); return; } fclose($out); } else { $this->error('500', 'Unable to open output stream.'); return; } } if ($chunk < $chunks - 1) { // Don't continue until all chunks are uploaded exit; } else { if ($chunks > 0) { // Done, move to permanent location and save to DB rename($tmp_path, $path); } } if (!$internal_id) { // Custom text uploads can stop here die(json_encode(array('filename' => $file_name))); } $from = array(); $from['filename'] = $file_name; $from['internal_id'] = $internal_id; $from['file_modified_on'] = time(); } else { if (isset($_POST['localfile'])) { $filename = basename($_REQUEST['localfile']); list($internal_id, $path) = $c->generate_internal_id(); if (!file_exists($_REQUEST['localfile'])) { $this->error('500', '"localfile" does not exist.'); return; } if ($path) { $path .= $filename; } else { $this->error('500', 'Unable to create directory for upload.'); return; } copy($_REQUEST['localfile'], $path); $from = array(); $from['filename'] = $filename; $from['internal_id'] = $internal_id; $from['file_modified_on'] = time(); } else { if (isset($_POST['from_url'])) { $filename = basename($_POST['from_url']); list($internal_id, $path) = $c->generate_internal_id(); if ($path) { $path .= $filename; } else { $this->error('500', 'Unable to create directory for upload.'); return; } if ($this->_download(urldecode($_POST['from_url']), $path, true) && file_exists($path)) { $from = array(); $from['filename'] = $filename; $from['internal_id'] = $internal_id; $from['file_modified_on'] = time(); } else { $this->error('500', 'Unable to import file from provided URL.'); return; } } else { if (is_null($id)) { $this->error('403', 'New content records must be accompanied by an upload.'); return; } } } } if (isset($from)) { $from = array_merge($_POST, $from); } else { $from = $_POST; } if (isset($_REQUEST['rotate']) && is_numeric($_REQUEST['rotate']) && $c->exists()) { $r = $_REQUEST['rotate']; if (abs($r) != 90) { $this->error('403', 'Rotation can only be done in multiples of 90.'); return; } if (empty($c->storage_url)) { $path = $c->path_to_original(); $info = pathinfo($path); $midsize_path = preg_replace('/\\.' . $info['extension'] . '$/', '.1600.' . $info['extension'], $path); if (file_exists($midsize_path)) { $midsize = $midsize_path; } } else { $path = tempnam(sys_get_temp_dir(), 'original'); file_put_contents($path, file_get_contents($c->storage_url)); if (!empty($c->storage_url_midsize)) { $midsize = tempnam(sys_get_temp_dir(), 'midsize'); file_put_contents($midsize, file_get_contents($c->storage_url_midsize)); } } $s = new Setting(); $s->where('name', 'image_processing_library')->get(); include_once FCPATH . 'app' . DIRECTORY_SEPARATOR . 'koken' . DIRECTORY_SEPARATOR . 'DarkroomUtils.php'; $d = DarkroomUtils::init($s->value); $d->rotate($path, $r); if (isset($midsize)) { $d->rotate($midsize, $r); } if (!empty($c->storage_url)) { $key = $c->path . '/' . $c->filename; Shutter::store_original($path, $c->path . '/' . $c->filename); unlink($path); if (isset($midsize)) { $info = pathinfo($key); $key = preg_replace('/\\.' . $info['extension'] . '$/', '.1600.' . $info['extension'], $key); Shutter::store_original($midsize, $key); unlink($midsize); } } $c->clear_cache(); $from['width'] = $c->height; $from['height'] = $c->width; $from['aspect_ratio'] = $from['width'] / $from['height']; $from['file_modified_on'] = time(); } if (isset($_REQUEST['reset_internal_id']) && $_REQUEST['reset_internal_id'] && $c->exists()) { list($from['internal_id'], ) = $c->generate_internal_id(true); } $hook = 'content.' . ($id ? 'update' : 'create'); if (isset($from['filename']) && $id) { $c->clear_cache(); $hook .= '_with_upload'; $c->_before(); } $from = Shutter::filter("api.{$hook}", array_merge($from, array('id' => $id, 'file' => isset($path) ? $path : $c->path_to_original()))); unset($from['file']); try { $c->from_array($from, array(), true); } catch (Exception $e) { $this->error('400', $e->getMessage()); return; } if (isset($_POST['tags'])) { $c->_format_tags($_POST['tags']); } else { if ($this->method === 'put' && isset($_POST['visibility'])) { $c->_update_tag_counts(); } } $c->_readify(); $content = $c->to_array(array('auth' => true)); if ($hook === 'content.create' || $hook === 'content.update_with_upload') { if (ENVIRONMENT === 'production') { $this->load->library('mcurl'); if ($this->mcurl->is_enabled()) { $options = array(CURLOPT_HTTPHEADER => array('Connection: Close', 'Keep-Alive: 0')); $this->mcurl->add_call('normal', 'get', $content['presets']['medium_large']['url'], array(), $options); $this->mcurl->add_call('cropped', 'get', $content['presets']['medium_large']['cropped']['url'], array(), $options); $this->mcurl->execute(); } } $external_storage_url = Shutter::store_original($c->path_to_original(), str_replace('/storage/originals/', '', $content['original']['relative_url'])); if ($external_storage_url) { unlink($c->path_to_original()); $o = new Content(); $o->where('id', $content['id'])->update(array('storage_url' => $external_storage_url)); $content['storage_url'] = $external_storage_url; } } Shutter::hook($hook, $content); // Important to prevent failures from Lr plugin header('Connection: close'); $this->redirect("/content/{$c->id}" . (isset($params['context']) ? '/context:' . $params['context'] : '')); break; case 'delete': if (is_null($id)) { $this->error('403', 'Required parameter "id" not present.'); return; } else { $t = new Tag(); if (is_numeric($id)) { $content = $c->get_by_id($id); if ($c->exists()) { $trash = new Trash(); $this->db->query("DELETE from {$trash->table} WHERE id = 'content-{$c->id}'"); $c->do_delete(); } else { $this->error('404', "Content with ID: {$id} not found."); return; } } else { $is_trash = $id === 'trash'; if ($id === 'trash') { $id = array(); $trash = new Trash(); $trash->like('id', 'content-')->select_func('REPLACE', '@id', 'content-', '', 'actual_id')->get_iterated(); foreach ($trash as $item) { $id[] = (int) $item->actual_id; } } else { $id = explode(',', $id); } /* Multiple delete /content/n1/n2/n3 */ // Keep track of tags to -- $tags = array(); $c->where_in('id', $id); $contents = $c->get_iterated(); $trash = new Trash(); foreach ($contents as $c) { if ($c->exists()) { $tags = array_merge($tags, $c->tags); $this->db->query("DELETE from {$trash->table} WHERE id = 'content-{$c->id}'"); $c->do_delete(); } } } } exit; break; } } $c = new Content(); if ($slug || isset($id) && strpos($id, ',') === false) { $options = array('context' => false, 'neighbors' => false); $options = array_merge($options, $params); $original_context = $options['context']; if ($options['context'] && !in_array($options['context'], array('stream', 'favorites', 'features')) && strpos($options['context'], 'tag-') !== 0 && strpos($options['context'], 'category-') !== 0) { if (is_numeric($options['context'])) { $context_field = 'id'; } else { $context_field = 'slug'; $options['context'] = str_replace('slug-', '', $options['context']); } $a = new Album(); $a->group_start()->where($context_field, $options['context'])->or_where('internal_id', $options['context'])->group_end()->get(); $c->include_join_fields()->where_related_album('id', $a->id); } $with_token = false; if (is_numeric($id)) { $content = $c->where('deleted', 0)->get_by_id($id); } else { if ($slug) { $content = $c->where('deleted', 0)->group_start()->where('internal_id', $slug)->or_where('slug', $slug)->or_like('old_slug', ',' . $slug . ',', 'both')->group_end()->get(); } else { $content = $c->where('deleted', 0)->where('internal_id', $id)->get(); } if ($content->exists() && $content->internal_id === (is_null($id) ? $slug : $id)) { $with_token = true; } } if ($content->exists()) { if ($c->visibility == 1 && !$this->auth && !$with_token || !$this->auth && !is_numeric($id) && $c->visibility == 2) { $this->error('403', 'Private content.'); return; } $options['auth'] = $this->auth; if ($options['neighbors']) { // Make sure $neighbors is at least 2 $options['neighbors'] = max($options['neighbors'], 2); // Make sure neighbors is even if ($options['neighbors'] & 1 != 0) { $options['neighbors']++; } $options['neighbors'] = $options['neighbors'] / 2; $single_neighbors = false; } else { $options['neighbors'] = 1; $single_neighbors = true; } if ($options['context'] && !in_array($original_context, array('stream', 'favorites', 'features')) && strpos($original_context, 'tag-') !== 0 && strpos($original_context, 'category-') !== 0) { $options['in_album'] = $a; } $final = $content->to_array($options); if ($options['context']) { // TODO: Performance check $next = new Content(); $prev = new Content(); $in_a = new Album(); $next->where('deleted', 0); $prev->where('deleted', 0); $options['context'] = urldecode($options['context']); if (!in_array($original_context, array('stream', 'favorites', 'features')) && strpos($original_context, 'tag-') !== 0 && strpos($original_context, 'category-') !== 0) { if (!isset($options['context_order'])) { list($options['context_order'], $options['context_order_direction']) = explode(' ', $a->sort); } $final['context']['album'] = $a->to_array(array('auth' => $this->auth || $options['context'] === $a->internal_id)); $in_a->where("{$context_field} !=", $options['context']); $next->where_related_album('id', $a->id); $prev->where_related_album('id', $a->id); if ($options['context_order'] === 'manual') { $next->order_by_join_field('album', 'order', 'ASC')->group_start()->where_join_field('album', 'order >', $content->join_order)->or_group_start()->where_join_field('album', 'order', $content->join_order)->where_join_field('album', 'id >', $content->join_id)->group_end()->group_end(); $prev->order_by_join_field('album', 'order', 'DESC')->group_start()->where_join_field('album', 'order <', $content->join_order)->or_group_start()->where_join_field('album', 'order', $content->join_order)->where_join_field('album', 'id <', $content->join_id)->group_end()->group_end(); } else { $next_operator = strtolower($options['context_order_direction']) === 'desc' ? '<' : '>'; $prev_operator = $next_operator === '<' ? '>' : '<'; $next->group_start()->where($options['context_order'] . " {$next_operator}", $content->{$options['context_order']})->or_group_start()->where($options['context_order'], $content->{$options['context_order']})->where("id {$next_operator}", $content->id)->group_end()->group_end(); $prev->group_start()->where($options['context_order'] . " {$prev_operator}", $content->{$options['context_order']})->or_group_start()->where($options['context_order'], $content->{$options['context_order']})->where("id {$prev_operator}", $content->id)->group_end()->group_end(); } if (!$this->auth) { $next->where('visibility <', $final['context']['album']['visibility'] < 1 ? 1 : 2); $prev->where('visibility <', $final['context']['album']['visibility'] < 1 ? 1 : 2); } $in_album = $a; $final['context']['type'] = 'album'; $final['context']['title'] = $a->title; $final['context']['__koken_url'] = $final['context']['album']['__koken_url']; $final['context']['url'] = $final['context']['album']['url']; } else { if (!isset($options['context_order'])) { $options['context_order'] = 'captured_on'; $options['context_order_direction'] = 'DESC'; } else { if ($options['context_order'] === 'manual' && $original_context === 'favorites') { $options['context_order'] = 'favorite_order'; $options['context_order_direction'] = 'ASC'; } else { if ($options['context_order'] === 'manual' && $original_context === 'features') { $options['context_order'] = 'featured_order'; $options['context_order_direction'] = 'ASC'; } } } $next_operator = strtolower($options['context_order_direction']) === 'desc' ? '<' : '>'; $prev_operator = $next_operator === '<' ? '>' : '<'; $next->group_start()->where($options['context_order'] . " {$next_operator}", $content->{$options['context_order']})->or_group_start()->where($options['context_order'], $content->{$options['context_order']})->where("id {$next_operator}", $content->id)->group_end()->group_end(); $prev->group_start()->where($options['context_order'] . " {$prev_operator}", $content->{$options['context_order']})->or_group_start()->where($options['context_order'], $content->{$options['context_order']})->where("id {$prev_operator}", $content->id)->group_end()->group_end(); if (strpos($original_context, 'tag-') === 0) { $tag = str_replace('tag-', '', urldecode($original_context)); $t = new Tag(); $t->where('name', $tag)->get(); if ($t->exists()) { $next->where_related_tag('id', $t->id); $prev->where_related_tag('id', $t->id); $final['context']['type'] = 'tag'; $final['context']['title'] = $tag; $final['context']['slug'] = $tag; $t->model = 'tag_contents'; $t->slug = $t->name; $url = $t->url(); if ($url) { list($final['context']['__koken_url'], $final['context']['url']) = $url; } } } else { if (strpos($original_context, 'category-') === 0) { $category = str_replace('category-', '', $original_context); $cat = new Category(); $cat->where('slug', $category)->get(); if ($cat->exists()) { $next->where_related_category('id', $cat->id); $prev->where_related_category('id', $cat->id); $final['context']['type'] = 'category'; $final['context']['title'] = $cat->title; $final['context']['slug'] = $cat->slug; $cat->model = 'category_contents'; $url = $cat->url(); if ($url) { list($final['context']['__koken_url'], $final['context']['url']) = $url; } } } else { if ($original_context === 'favorites') { $url_data = $prev->get_data(); $urls = $prev->form_urls(); $next->where('favorite', 1); $prev->where('favorite', 1); $final['context']['type'] = 'favorite'; $final['context']['title'] = $url_data['favorite']['plural']; $final['context']['__koken_url'] = $urls['favorites']; if ($final['context']['__koken_url']) { $final['context']['url'] = $prev->get_base() . $final['context']['__koken_url'] . (defined('DRAFT_CONTEXT') && !is_numeric(DRAFT_CONTEXT) ? '&preview=' . DRAFT_CONTEXT : ''); } } else { if ($original_context === 'features') { $url_data = $prev->get_data(); $urls = $prev->form_urls(); $next->where('featured', 1); $prev->where('featured', 1); $final['context']['type'] = 'feature'; $final['context']['title'] = $url_data['feature']['plural']; $final['context']['__koken_url'] = isset($urls['features']) ? $urls['features'] : false; if ($final['context']['__koken_url']) { $final['context']['url'] = $prev->get_base() . $final['context']['__koken_url'] . (defined('DRAFT_CONTEXT') && !is_numeric(DRAFT_CONTEXT) ? '&preview=' . DRAFT_CONTEXT : ''); } } } } } if (!$this->auth) { $next->where('visibility', 0); $prev->where('visibility', 0); } $in_album = false; } $max = $next->get_clone()->count(); $min = $prev->get_clone()->count(); $final['context']['total'] = $max + $min + 1; $final['context']['position'] = $min + 1; $pre_limit = $next_limit = $options['neighbors']; if ($min < $pre_limit) { $next_limit += $pre_limit - $min; $pre_limit = $min; } if ($max < $next_limit) { $pre_limit = min($min, $pre_limit + ($next_limit - $max)); $next_limit = $max; } $final['context']['previous'] = array(); $final['context']['next'] = array(); if ($next_limit > 0) { if ($options['context_order'] !== 'manual') { $next->order_by($options['context_order'] . ' ' . $options['context_order_direction'] . ', id ' . $options['context_order_direction']); } $next->limit($next_limit)->get_iterated(); foreach ($next as $c) { $final['context']['next'][] = $c->to_array(array('auth' => $this->auth, 'in_album' => $in_album, 'context' => $original_context)); } } if ($pre_limit > 0) { if ($options['context_order'] !== 'manual') { $dir = strtolower($options['context_order_direction']) === 'desc' ? 'asc' : 'desc'; $prev->order_by($options['context_order'] . ' ' . $dir . ', id ' . $dir); } $prev->limit($pre_limit)->get_iterated(); foreach ($prev as $c) { $final['context']['previous'][] = $c->to_array(array('auth' => $this->auth, 'in_album' => $in_album, 'context' => $original_context)); } $final['context']['previous'] = array_reverse($final['context']['previous']); } } } else { $this->error('404', "Content with ID: {$id} not found."); return; } } else { if (isset($params['custom'])) { $final = $c->to_array_custom($params['custom']); } else { $c->where('deleted', 0); $params['auth'] = $this->auth; $final = $c->listing($params, $id); } } $this->set_response_data($final); }
public function getView($id) { $data['category'] = Category::where('id', $id)->first(); $data['albums'] = Album::where('category_id', $id)->where('public', '=', 1)->get(); return View::make('frontend/categories/view')->with('data', $data); }
<?php $albums = new Album(); $albums->where('sort', '[object Object]')->get(); $albums->update_all('sort', 'manual ASC'); $done = true;
public function getViewImages() { if (UsersHelper::checkLogged()) { $data['albums'] = Album::where('user_id', Session::get('current_user'))->get(); return View::make('frontend/users/view-images')->with('data', $data); } else { return Redirect::to('home/index'); } }
$fields = $this->db->query("SHOW COLUMNS FROM {$t->table}"); $run = true; if ($fields) { $result = $fields->result(); if ($result && strtolower($result[0]->Type) === 'int(9)') { $run = false; } } if ($run) { $this->db->query("TRUNCATE TABLE {$t->table}"); $this->db->query("ALTER TABLE {$t->table} DROP COLUMN count"); $this->db->query("ALTER TABLE {$c->table} DROP COLUMN count"); $this->db->query("ALTER TABLE {$t->table} DROP COLUMN id"); $this->db->query("ALTER TABLE {$t->table} ADD id INT(9) AUTO_INCREMENT PRIMARY KEY FIRST"); $a = new Album(); $c = new Content(); $t = new Text(); $this->db->query("ALTER TABLE {$a->table} DROP COLUMN tags_migrated"); $this->db->query("ALTER TABLE {$c->table} DROP COLUMN tags_migrated"); $this->db->query("ALTER TABLE {$t->table} DROP COLUMN tags_migrated"); $this->db->query("ALTER TABLE {$a->table} ADD tags_migrated TINYINT(1) DEFAULT 0"); $this->db->query("ALTER TABLE {$c->table} ADD tags_migrated TINYINT(1) DEFAULT 0"); $this->db->query("ALTER TABLE {$t->table} ADD tags_migrated TINYINT(1) DEFAULT 0"); $this->db->query("ALTER TABLE {$a->table} CHANGE tags tags_old TEXT"); $this->db->query("ALTER TABLE {$c->table} CHANGE tags tags_old TEXT"); $this->db->query("ALTER TABLE {$t->table} CHANGE tags tags_old TEXT"); $a->where('tags_old', null)->update(array('tags_migrated' => 1)); $c->where('tags_old', null)->update(array('tags_migrated' => 1)); $t->where('tags_old', null)->update(array('tags_migrated' => 1)); } $done = true;
public function getAlbumName() { $album = Album::where('id', '=', $this->album_id)->first(); return $album->name; }
function _all($params) { $s = new Setting(); $s->where('name', 'site_timezone')->get(); $tz = new DateTimeZone($s->value); $offset = $tz->getOffset(new DateTime('now', new DateTimeZone('UTC'))); if ($offset === 0) { $shift = ''; } else { $shift = ($offset < 0 ? '-' : '+') . abs($offset); } $content_col = $params['content_column']; $select = "COUNT(*) as count, YEAR(FROM_UNIXTIME({$content_col}{$shift})) as event_year"; $group = 'event_year'; $order = 'event_year DESC'; if (!$params['scope'] || $params['scope'] !== 'year') { $select .= ", MONTH(FROM_UNIXTIME({$content_col}{$shift})) as event_month"; $group .= ',event_month'; $order .= ',event_month DESC'; } if (!$params['limit_to'] && !$params['scope']) { $select .= ", DAY(FROM_UNIXTIME({$content_col}{$shift})) as event_day"; $group .= ',event_day'; $order .= ',event_day DESC'; } $a = new Album(); $c = new Content(); $t = new Text(); $c->select(str_replace($content_col, $c->table . '.' . $content_col, $select))->include_related('album', 'id')->where('visibility', 0)->where('deleted', 0); if (!$params['limit_to']) { $c->group_start()->where('album_id', null)->or_where($c->table . '.published_on > `' . $a->table . '`.`published_on`')->group_end(); } $a->select(str_replace($content_col, 'published_on', $select))->where('visibility', 0)->where('deleted', 0)->where('total_count >', 0); $t->select(str_replace($content_col, 'published_on', $select))->where('page_type', 0)->where('published', 1); if ($params['featured']) { $c->where('featured', 1); $a->where('featured', 1); $t->where('featured', 1); } $c->group_by($group)->order_by($order); $t->group_by($group)->order_by($order); $a->group_by($group)->order_by($order); $dates = array(); if (!$params['limit_to'] || $params['limit_to'] === 'content') { foreach ($c->get_iterated() as $content) { if ($params['scope'] === 'year') { $key = "{$content->event_year}"; } else { if ($params['limit_to'] || $params['scope']) { $key = "{$content->event_year}-{$content->event_month}"; } else { $key = "{$content->event_year}-{$content->event_month}-{$content->event_day}"; } } $key = strtotime($key); if (is_numeric($content->event_year)) { $dates[$key] = array('year' => (int) $content->event_year, 'month' => (int) $content->event_month, 'day' => (int) $content->event_day, 'counts' => array('content' => (int) $content->count, 'albums' => 0, 'essays' => 0)); } } } if (!$params['limit_to'] || $params['limit_to'] === 'albums') { foreach ($a->get_iterated() as $album) { if ($params['scope'] === 'year') { $key = "{$album->event_year}"; } else { if ($params['limit_to'] || $params['scope']) { $key = "{$album->event_year}-{$album->event_month}"; } else { $key = "{$album->event_year}-{$album->event_month}-{$album->event_day}"; } } $key = strtotime($key); if (is_numeric($album->event_year)) { if (!isset($dates[$key])) { $dates[$key] = array('year' => (int) $album->event_year, 'month' => (int) $album->event_month, 'day' => (int) $album->event_day, 'counts' => array('content' => 0, 'albums' => (int) $album->count, 'essays' => 0)); } else { $dates[$key]['counts']['albums'] = (int) $album->count; } } } } if (!$params['limit_to'] || $params['limit_to'] === 'essays') { foreach ($t->get_iterated() as $essay) { if ($params['scope'] === 'year') { $key = "{$essay->event_year}"; } else { if ($params['limit_to'] || $params['scope']) { $key = "{$essay->event_year}-{$essay->event_month}"; } else { $key = "{$essay->event_year}-{$essay->event_month}-{$essay->event_day}"; } } $key = strtotime($key); if (is_numeric($essay->event_year)) { if (!isset($dates[$key])) { $dates[$key] = array('year' => (int) $essay->event_year, 'month' => (int) $essay->event_month, 'day' => (int) $essay->event_day, 'counts' => array('content' => 0, 'albums' => 0, 'essays' => (int) $essay->count)); } else { $dates[$key]['counts']['essays'] = (int) $essay->count; } } } } krsort($dates); return $dates; }
function content() { list($params, $id, $slug) = $this->parse_params(func_get_args()); $params['auth'] = $this->auth; $a = new Album(); $c = new Content(); if (is_null($id) && !$slug) { $this->error('403', 'Required parameter "id" not present.'); return; } else { if (is_array($id)) { list($id, $content_id) = $id; } } if ($this->method != 'get') { $album = $a->get_by_id($id); if (!$album->exists()) { $this->error('404', 'Album not found.'); return; } $tail = ''; if (isset($params['order'])) { if ($album->album_type == 2) { $this->_order($params['order'], $album); } else { $ids = explode(',', $params['order']); $new_order_map = array(); foreach ($ids as $key => $val) { $pos = $key + 1; $new_order_map[$val] = $pos; } $album->trans_begin(); foreach ($album->contents->include_join_fields()->get_iterated() as $c) { if (isset($new_order_map[$c->id]) && $new_order_map[$c->id] != $c->join_order) { $album->set_join_field($c, 'order', $new_order_map[$c->id]); } } $album->trans_commit(); } } else { if (!isset($content_id)) { $this->error('403', 'Required content id not present.'); return; } else { if ($album->album_type == 1) { $this->error('403', 'You cannot manually add content to smart albums.'); return; } } if ($id == $content_id && $album->album_type == 2) { $this->error('403', 'Album cannot be added to itself.'); return; } $album->manage_content($content_id, $this->method, $this->input->post('match_album_visibility')); } if ($this->method == 'delete') { exit; } else { $this->redirect("/albums/{$album->id}/content"); exit; } } $with_token = false; if (is_numeric($id)) { $album = $a->where('deleted', 0)->get_by_id($id); } else { if ($slug) { $album = $a->where('deleted', 0)->group_start()->where('internal_id', $slug)->or_where('slug', $slug)->or_like('old_slug', ',' . $slug . ',', 'both')->group_end()->get(); } else { $album = $a->where('deleted', 0)->where('internal_id', $id)->get(); } if ($album->exists() && $album->internal_id === (is_null($id) ? $slug : $id)) { $with_token = true; } } if ($album->exists()) { if ($album->visibility > 0 && !$this->auth && !$with_token) { if ($album->visibility > 1) { // Private content should 404, leave no trace, etc. $this->error('404', 'Album not found.'); } else { $this->error('403', 'Private content.'); } return; } } else { $this->error('404', 'Album not found.'); return; } $order = explode(' ', $album->sort); if (!isset($params['order_by'])) { $params['order_by'] = $order[0]; if (count($order) > 1) { $params['order_direction'] = $order[1]; } } if ($album->album_type == 2) { $options = array('neighbors' => false, 'include_empty_neighbors' => false, 'order_by' => 'manual', 'with_context' => true); $params = array_merge($options, $params); if ($params['order_by'] === 'manual') { $params['order_by'] = 'left_id'; $params['order_direction'] = 'asc'; } $final = $album->listing($params); } else { $options = array('order_by' => 'manual', 'covers' => null, 'neighbors' => false, 'include_empty_neighbors' => false, 'in_album' => $album, 'with_context' => true, 'is_cover' => true, 'visibility' => 'any'); if (!isset($params['visibility']) && $with_token) { $params['visibility'] = 'album'; } $params = array_merge($options, $params); $params['auth'] = $this->auth || $with_token; if ($params['covers']) { if ($params['order_by'] === 'manual') { $params['order_by'] = 'cover_id'; } $c = $album->covers; } else { $c->where('deleted', 0); if (!is_null($params['covers'])) { $cids = array(); foreach ($album->covers->get_iterated() as $cover) { $cids[] = $cover->id; } $c->where_not_in('id', $cids); } $c->where_related_album('id', $album->id); if ($params['order_by'] === 'manual') { $params['order_by'] = 'order'; $params['order_direction'] = 'asc'; } } $final = $c->listing($params); } $params['include_parent'] = true; unset($params['category']); unset($params['tags']); $final['album'] = $album->to_array($params); if (isset($params['context_set']) && $album->level > 1) { $parent = new Album(); $parent->where('left_id <', $album->left_id)->where('level <', $album->level)->where('visibility', $album->visibility)->where('deleted', 0)->order_by('left_id DESC')->limit(1)->get(); list($params['context_order'], $params['context_order_direction']) = explode(' ', $parent->sort); } if (isset($final['album']['covers']) && !empty($final['album']['covers']) && isset($final['content'])) { $covers = array(); foreach ($final['album']['covers'] as $cover) { $covers[] = $cover['id']; } $primary = false; foreach ($final['content'] as &$c) { $c['is_cover'] = in_array($c['id'], $covers); if ($c['is_cover'] && !$primary) { $c['is_primary_cover'] = true; $primary = true; } else { $c['is_primary_cover'] = false; } } } if ($params['with_context']) { $final['album']['context'] = $album->context($params, $this->auth); } $this->set_response_data($final); }
<?php $a = new Album(); $fields = $this->db->query("SHOW COLUMNS FROM {$a->table}"); $result = $fields->result(); $columns = array(); foreach ($result as $field) { $columns[] = $field->Field; } if (in_array('tags_migrated', $columns)) { foreach ($a->where('tags_migrated', 0)->limit(50)->get_iterated() as $album) { $album->_format_tags(trim($album->tags_old, ',')); $album->tags_migrated = 1; $album->save(); } if ($a->where('tags_migrated', 0)->count() === 0) { $done = true; } } else { $done = true; }
function build_autos($items, $data, $user) { foreach ($items as $index => &$item) { if (isset($item['auto'])) { if (isset($data['urls'][$item['auto']])) { $item['path'] = $data['urls'][$item['auto']]; } else { if ($item['auto'] === 'set') { $item['path'] = ''; } } if ($item['auto'] === 'profile') { switch ($item['id']) { case 'twitter': $item['path'] = 'https://twitter.com/' . $user->twitter; break; default: $item['path'] = $user->{$item['id']}; if (empty($item['path'])) { unset($items[$index]); continue; } break; } if (!isset($item['label']) || empty($item['label'])) { $item['label'] = ucwords($item['id']) . ($item['id'] === 'google' ? '+' : ''); } } else { if ($item['auto'] === 'rss') { $item['path'] = '/feed/' . $item['id'] . ($item['id'] === 'essay' ? 's' : '') . '/recent.rss'; if (!isset($item['label'])) { $item['label'] = $data['url_data'][$item['id']]['plural'] . ' RSS'; } } else { if (preg_match('/s$/', $item['auto']) || $item['auto'] === 'timeline') { if ($item['auto'] === 'timeline' && isset($item['year'])) { $item['path'] .= $item['year'] . '/'; if (isset($item['month']) && $item['month'] !== false && $item['month'] !== 'any') { $m = str_pad($item['month'], 2, '0', STR_PAD_LEFT); $item['path'] .= $m . '/'; } } if (strpos($item['auto'], '_') !== false) { foreach (array('id', 'slug', 'month', 'year', 'day') as $id) { if ($id === 'month') { if (!isset($item['month']) || $item['month'] === 'any' || $item['month'] === false) { $item['month'] = ''; } else { $item['month'] = str_pad($item['month'], 2, '0', STR_PAD_LEFT); } } if ($id === 'day' && !isset($item['day'])) { $item['day'] = ''; } if ($id === 'slug' && !isset($item['slug']) && isset($item['id'])) { if (strpos($item['auto'], 'tag_') === 0) { $item['slug'] = $item['id']; } else { $c = new Category(); if (is_numeric($item['id'])) { $c->select('slug')->get_by_id($item['id']); $item['slug'] = $c->slug; } else { $item['slug'] = $item['id']; } } } if (isset($item[$id])) { $item['path'] = str_replace(":{$id}", $item[$id], $item['path']); } } } else { if (!isset($item['label'])) { $item['label'] = $data['url_data'][$item['auto'] === 'categories' ? 'category' : rtrim($item['auto'], 's')]['plural']; } } } else { if ($item['auto'] === 'home') { if (!isset($item['label'])) { $item['label'] = $data['url_data']['home']; } $item['path'] = '/home/'; } else { if ($item['auto'] === 'album' || $item['auto'] === 'set') { $a = new Album(); $a->select('id,slug,created_on,title'); if (is_numeric($item['id'])) { $a->where('id', $item['id']); } else { $a->where('slug', $item['id'])->or_where('internal_id', $item['id']); } $a->get(); if (!$a->exists()) { unset($items[$index]); continue; } $item['path'] = str_replace(':id', $a->id, $item['path']); $item['path'] = str_replace(':slug', $a->slug, $item['path']); $item['path'] = str_replace(':year', date('Y', $a->created_on), $item['path']); $item['path'] = str_replace(':month', date('m', $a->created_on), $item['path']); $item['path'] = str_replace(':day', date('d', $a->created_on), $item['path']); if (!isset($item['label'])) { $item['label'] = $a->title; } } else { if ($item['auto'] === 'page' || $item['auto'] === 'essay') { $t = new Text(); $t->select('id,slug,published_on,title'); if (is_numeric($item['id'])) { $t->where('id', $item['id']); } else { $t->where('slug', $item['id']); } $t->get(); if (!$t->exists()) { unset($items[$index]); continue; } $item['path'] = str_replace(':id', $t->id, $item['path']); $item['path'] = str_replace(':slug', $t->slug, $item['path']); $item['path'] = str_replace(':year', date('Y', $t->published_on), $item['path']); $item['path'] = str_replace(':month', date('m', $t->published_on), $item['path']); $item['path'] = str_replace(':day', date('d', $t->published_on), $item['path']); if (!isset($item['label'])) { $item['label'] = $t->title; } } else { if ($item['auto'] === 'content') { $c = new Content(); $c->select('id,slug,captured_on,title'); if (isset($item['album_id'])) { $item['path'] = preg_replace('/:(id|slug)/', ':album_$1', $data['urls']['album']) . substr(str_replace(':year/:month/', '', $data['urls']['content']), 1); $a = new Album(); $a->select('id,slug,created_on,title'); if (is_numeric($item['album_id'])) { $a->where('id', $item['album_id']); } else { $a->where('slug', $item['album_id'])->or_where('internal_id', $item['album_id']); } $a->get(); if (!$a->exists()) { unset($items[$index]); continue; } $item['path'] = str_replace(':album_id', $a->id, $item['path']); $item['path'] = str_replace(':album_slug', $a->slug, $item['path']); $date = $a->created_on; } else { $date = $c->captured_on; } if (is_numeric($item['id'])) { $c->where('id', $item['id']); } else { $c->where('slug', $item['id'])->or_where('internal_id', $item['id']); } $c->get(); if (!$c->exists()) { unset($items[$index]); continue; } $item['path'] = str_replace(':id', $c->id, $item['path']); $item['path'] = str_replace(':slug', $c->slug, $item['path']); $item['path'] = str_replace(':year', date('Y', $date), $item['path']); $item['path'] = str_replace(':month', date('m', $date), $item['path']); $item['path'] = str_replace(':day', date('d', $date), $item['path']); if (!isset($item['label'])) { $item['label'] = $c->title; } if (isset($item['lightbox']) && $item['lightbox']) { $item['path'] .= 'lightbox/'; } } else { if ($item['auto'] === 'tag') { $item['path'] = str_replace(':slug', $item['id'], $item['path']); } } } } } } } } if ($item['auto'] !== 'profile') { $item['path'] = str_replace(array(':year', ':month'), '', $item['path']); $item['path'] = preg_replace('/[\\(\\)\\?\\:]/', '', $item['path']); $item['path'] = preg_replace('~[/]+~', '/', $item['path']); } } } return $items; }
/** * Add information from $this->files to the database * * @return boolean */ protected function toDB() { if (!$this->files) { $this->addError('No files where found!'); return false; } foreach ($this->files as $album => $images) { $album = $album ? $album : 'Undefined'; $a = Album::where('title', $album)->first(); $a = $a ? $a : new Album(); $a->folder = $this->urlSafe($album); $a->title = $album; $a->save(); if (!$a->id) { $this->addError('Error saving album to database!'); return false; } foreach ($images as $image) { $i = Image::where('image', $image['newfilename'] . '.' . $image['ext'])->first(); $i = $i ? $i : new Image(); $i->image = $image['newfilename'] . '.' . $image['ext']; $i->title = $image['filename']; $i->text = $image['text']; $i->album()->associate($a); $i->save(); if (!$i->id) { $this->addError('Error saving image to database!'); return false; } if ($image['cover']) { $a->image_id = $i->id; $a->save(); } } } return true; }
public function album() { $user_id = Input::get('user_id'); if ($user_id != null) { $user = User::find($user_id); } else { if (!Auth::check()) { return Redirect::back(); } $user = Auth::user(); } $albums = $user->hasManyAlbums()->get(); if ($albums != null) { foreach ($albums as $album) { $album->albumCount = $album->hasManyPictures()->count(); $pictures = $album->hasManyPictures()->get(); $pictures = $pictures->toArray(); if ($pictures == null) { $album->picture = "http://7xk6xh.com1.z0.glb.clouddn.com/album_03.png"; } else { $album->picture = $pictures[0]['picture']; } $album->save(); } } $albums = Album::where('user_id', '=', $user->id)->paginate(6); return View::make('userCenter.photo-album')->with(array('albums' => $albums, 'user' => $user, 'links' => $this->link())); }
function to_array($options = array()) { $options = array_merge(array('with_covers' => true, 'auth' => false), $options); $koken_url_info = $this->config->item('koken_url_info'); $exclude = array('deleted', 'total_count', 'video_count', 'featured_order', 'tags_old', 'old_slug'); $dates = array('created_on', 'modified_on', 'featured_on', 'published_on'); $strings = array('title', 'summary', 'description'); $bools = array('featured'); list($data, $public_fields) = $this->prepare_for_output($options, $exclude, $bools, $dates, $strings); if (!$options['auth'] && $data['visibility'] < 1) { unset($data['internal_id']); } if (!$data['featured']) { unset($data['featured_on']); } $sort = array(); list($sort['by'], $sort['direction']) = explode(' ', $data['sort']); $data['sort'] = $sort; $data['__koken__'] = 'album'; if (array_key_exists('album_type', $data)) { switch ($data['album_type']) { case 2: $data['album_type'] = 'set'; break; case 1: $data['album_type'] = 'smart'; break; default: $data['album_type'] = 'standard'; } } if ($this->album_type == 2) { $sum = new Album(); $sum->select_sum('total_count')->select_sum('video_count')->where('right_id <', $this->right_id)->where('left_id >', $this->left_id)->where('album_type', 0)->where('visibility', 0)->get(); $data['counts'] = array('total' => (int) $this->total_count, 'videos' => (int) $sum->video_count, 'images' => $sum->total_count - $sum->video_count); } else { $data['counts'] = array('total' => (int) $this->total_count, 'videos' => (int) $this->video_count, 'images' => $this->total_count - $this->video_count); } $data['tags'] = $this->_get_tags_for_output($options); $data['categories'] = array('count' => is_null($this->category_count) ? $this->categories->count() : (int) $this->category_count, 'url' => $koken_url_info->base . 'api.php?/albums/' . $data['id'] . '/categories'); $data['topics'] = array('count' => is_null($this->text_count) ? $this->text->count() : (int) $this->text_count, 'url' => $koken_url_info->base . 'api.php?/albums/' . $data['id'] . '/topics'); if ($options['with_covers']) { $data['covers'] = $existing = array(); $covers = $this->covers; if (isset($options['before'])) { $covers->where('published_on <=', $options['before']); $data['__cover_hint_before'] = $options['before']; } $covers->include_related_count('albums', NULL, array('visibility' => 0)); $covers->include_related_count('categories'); foreach ($covers->order_by("covers_{$this->db_join_prefix}albums_covers.id ASC")->get_iterated() as $f) { if ($f->exists()) { $data['covers'][] = $f->to_array(array('in_album' => $this)); $existing[] = $f->id; } } $covers_count_set = false; if ($this->album_type == 2) { $covers_count_set = $this->covers->count(); } if ($covers_count_set !== false && $covers_count_set < 3) { $a = new Album(); $ids = $a->select('id')->where('right_id <', $this->right_id)->where('left_id >', $this->left_id)->where('visibility', $this->visibility)->get_iterated(); $id_arr = array(); foreach ($ids as $id) { $id_arr[] = $id->id; } if (!empty($id_arr)) { $c = new Content(); $q = "SELECT DISTINCT cover_id FROM {$this->db_join_prefix}albums_covers WHERE album_id IN (" . join(',', $id_arr) . ")"; if (!empty($existing)) { $q .= ' AND cover_id NOT IN(' . join(',', $existing) . ')'; } $covers = $c->query($q . "GROUP BY album_id LIMIT " . (3 - $covers_count_set)); $f_ids = array(); foreach ($covers as $f) { $f_ids[] = $f->cover_id; } if (!empty($f_ids)) { $c->where_in('id', $f_ids)->get_iterated(); foreach ($c as $content) { // TODO: auth needs to be passed in here array_unshift($data['covers'], $content->to_array(array('in_album' => $this))); } } } } // Latest covers first $data['covers'] = array_reverse($data['covers']); } if (isset($options['order_by']) && in_array($options['order_by'], array('created_on', 'modified_on'))) { $data['date'] =& $data[$options['order_by']]; } else { $data['date'] =& $data['published_on']; } if ($data['level'] > 1 && (!array_key_exists('include_parent', $options) || $options['include_parent'])) { $parent = new Album(); $parent->where('left_id <', $data['left_id'])->where('level <', $data['level'])->where('visibility', $this->visibility)->where('deleted', 0)->order_by('left_id DESC')->limit(1)->get(); $data['parent'] = $parent->to_array(); } else { if ($data['level'] == 1) { $data['parent'] = false; } } $cat = isset($options['category']) ? $options['category'] : (isset($options['context']) && strpos($options['context'], 'category-') === 0 ? str_replace('category-', '', $options['context']) : false); if ($cat) { if (is_numeric($cat)) { foreach ($this->categories->get_iterated() as $c) { if ($c->id == $cat) { $cat = $c->slug; break; } } } } $data['url'] = $this->url(array('date' => $data['published_on'], 'tag' => isset($options['tags']) ? $options['tags'] : (isset($options['context']) && strpos($options['context'], 'tag-') === 0 ? str_replace('tag-', '', $options['context']) : false), 'category' => $cat)); if ($data['url']) { list($data['__koken_url'], $data['url']) = $data['url']; $data['canonical_url'] = $data['url']; } if (!$options['auth'] && $data['visibility'] > 0) { unset($data['url']); } if (array_key_exists('visibility', $data)) { switch ($data['visibility']) { case 1: $raw = 'unlisted'; break; case 2: $raw = 'private'; break; default: $raw = 'public'; break; } $data['visibility'] = array('raw' => $raw, 'clean' => ucwords($raw)); $data['public'] = $raw === 'public'; } return Shutter::filter('api.album', array($data, $this, $options)); }
<?php $c = new Album(); $c->where('slug', NULL)->or_where('slug', '')->limit(100)->get_iterated(); foreach ($c as $content) { $content->slug = '__generate__'; $content->save(); } $c = new Album(); if ($c->where('slug', NULL)->or_where('slug', '')->count() === 0) { $done = true; }
public function getIndex() { $data['albums'] = Album::where('public', '=', 1)->get(); return View::make('frontend/index')->with('data', $data); }
<?php $url = new Url(); $current = $url->order_by('id DESC')->limit(1)->get(); $config = unserialize($current->data); $sort = 'manual ASC'; foreach ($config as $url_conf) { if ($url_conf['type'] === 'album') { $setSort = $url_conf['data']['order']; } else { if ($url_conf['type'] === 'content' && isset($url_conf['data']['album_order'])) { $sort = $url_conf['data']['album_order']; } } } $albums = new Album(); $albums->where('album_type', 0)->get(); $albums->update_all('sort', $sort); $sets = new Album(); $sets->where('album_type', 2)->get(); $sets->update_all('sort', $setSort); $done = true;
<?php $a = new Album(); foreach ($a->where('visibility >', 0)->get_iterated() as $album) { $album->update_counts(); } $done = true;