本文整理汇总了PHP中Album::to_array方法的典型用法代码示例。如果您正苦于以下问题:PHP Album::to_array方法的具体用法?PHP Album::to_array怎么用?PHP Album::to_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Album
的用法示例。
在下文中一共展示了Album::to_array方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
//.........这里部分代码省略.........
}
}
$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()) {
示例2: index
function index()
{
// TODO: Make sure user is admin over content they trash
list($params, $id) = $this->parse_params(func_get_args());
if ($this->method != 'get') {
$c = new Content();
$a = new Album();
$t = new Trash();
$tag = new Tag();
$options = array('content' => array(), 'albums' => array());
$params = array_merge($options, $params);
if (!empty($params['content'])) {
$params['content'] = explode(',', $params['content']);
}
if (!empty($params['albums'])) {
$params['albums'] = explode(',', $params['albums']);
}
switch ($this->method) {
case 'post':
$q = array();
$content_ids = array();
$album_ids = array();
$now = time();
if (!empty($params['content'])) {
$content = $c->where_in('id', $params['content'])->get_iterated();
foreach ($content as $c) {
$q[] = "('content-{$c->id}', '" . $this->db->escape_str(utf8_encode(serialize($c->to_array(array('auth' => $this->auth))))) . "', {$now})";
}
}
if (!empty($params['albums'])) {
foreach ($params['albums'] as $album_id) {
$al = new Album();
$al->get_by_id($album_id);
if ($al->exists()) {
$q[] = "('album-{$al->id}', '" . $this->db->escape_str(utf8_encode(serialize($al->to_array()))) . "', {$now})";
$al->tree_trash();
foreach ($al->categories->get_iterated() as $category) {
$category->update_counts('album');
}
foreach ($al->tags->get_iterated() as $tag) {
$tag->update_counts('album');
}
}
}
$a->update_set_counts();
}
if (!empty($q)) {
$q = join(',', $q);
$this->db->query("INSERT INTO {$t->table} VALUES {$q} ON DUPLICATE KEY UPDATE data = VALUES(data)");
}
if (!empty($params['content'])) {
$c->where_in('id', $params['content'])->update('deleted', 1);
$albums = $a->where_in_related('content', 'id', $params['content'])->get_iterated();
foreach ($albums as $a) {
$a->update_counts();
}
$previews = $a->where_in_related('cover', 'id', $params['content'])->distinct()->get_iterated();
$prefix = preg_replace('/trash$/', '', $t->table);
$this->db->query("DELETE FROM {$prefix}join_albums_covers WHERE cover_id IN(" . join(',', $params['content']) . ")");
foreach ($previews as $a) {
$a->reset_covers();
}
foreach ($c->where_in('id', $params['content'])->get_iterated() as $content) {
foreach ($content->categories->get_iterated() as $category) {
$category->update_counts('content');
}
foreach ($content->tags->get_iterated() as $tag) {
$tag->update_counts('content');
}
}
}
$this->redirect('/trash');
break;
case 'delete':
$ids = array();
foreach ($params['content'] as $id) {
$ids[] = "'content-{$id}'";
}
foreach ($params['albums'] as $id) {
$ids[] = "'album-{$id}'";
}
if (!empty($ids)) {
$ids = join(',', $ids);
$this->db->query("DELETE FROM {$t->table} WHERE id IN ({$ids})");
}
if (!empty($params['albums'])) {
foreach ($params['albums'] as $album_id) {
$al = new Album();
$al->get_by_id($album_id);
if ($al->exists()) {
$al->tree_trash_restore();
foreach ($al->categories->get_iterated() as $category) {
$category->update_counts('album');
}
foreach ($al->tags->get_iterated() as $tag) {
$tag->update_counts('album');
}
}
}
$a->update_set_counts();
//.........这里部分代码省略.........
示例3: index
//.........这里部分代码省略.........
$_POST['internal_id'] = koken_rand();
} else {
$private[] = 'internal_id';
}
foreach ($private as $p) {
unset($_POST[$p]);
}
if ($a->has_db_permission('lock tables')) {
$s = new Slug();
$t = new Tag();
$c = new Content();
$cat = new Category();
$this->db->query("LOCK TABLE {$a->table} WRITE, {$c->table} WRITE, {$s->table} WRITE, {$t->table} WRITE, {$cat->table} WRITE, {$a->db_join_prefix}albums_content READ, {$a->db_join_prefix}albums_categories READ, {$a->db_join_prefix}albums_tags READ");
$locked = true;
} else {
$locked = false;
}
try {
$a->from_array($_POST, array(), true);
} catch (Exception $e) {
$this->error('400', $e->getMessage());
return;
}
if ($locked) {
$this->db->query('UNLOCK TABLES');
}
if (isset($_POST['tags'])) {
$a->_format_tags($_POST['tags']);
} else {
if ($this->method === 'put' && isset($_POST['visibility'])) {
$a->_update_tag_counts();
}
}
$arr = $a->to_array();
if ($this->method === 'post') {
Shutter::hook('album.create', $arr);
} else {
Shutter::hook('album.update', $arr);
}
if (isset($content_ids)) {
$clean = new Album();
$clean = $clean->get_by_id($a->id);
$clean->manage_content(join(',', $content_ids), 'post', true);
}
$this->redirect("/albums/{$a->id}");
break;
case 'delete':
if (is_null($id)) {
$this->error('403', 'Required parameter "id" not present.');
return;
} else {
$prefix = preg_replace('/albums$/', '', $a->table);
if ($id === 'trash') {
$id = array();
$trash = new Trash();
$trash->like('id', 'album-')->select_func('REPLACE', '@id', 'album-', '', 'actual_id')->get_iterated();
foreach ($trash as $item) {
$id[] = (int) $item->actual_id;
}
} else {
if (is_numeric($id)) {
$id = array($id);
} else {
$id = explode(',', $id);
}
}
示例4: array
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 {
//.........这里部分代码省略.........