function save_tags($id, $tags, $type = 1) { $tag_arr = parse_tag($tags); $tag_arr = array_unique($tag_arr); $this->db->select('#@tag_rel as tr left join #@tags as t on tr.tag_id=t.id', 'tag_id,name', 't.type=' . $type . ' and tr.rel_id=' . intval($id)); $exist_tags = $this->db->getAll(); //check exists tag and deleted $deleted = array(); $exists = array(); if ($exist_tags) { foreach ($exist_tags as $et) { $del_flag = true; foreach ($tag_arr as $k => $tag) { $tag = trim($tag); if ($et['name'] == $tag) { $exists[] = $et['tag_id']; $del_flag = false; unset($tag_arr[$k]); } } if ($del_flag) { $deleted[] = $et['tag_id']; } } } $this->remove_obj_tag($deleted, $id); $changed_tag_ids = $this->add_tags($tag_arr, $id, $type); $this->recount($deleted); $this->recount($changed_tag_ids); }
function view() { $id = intval($this->getGet('id')); $info = $this->mdl_photo->get_info($id); if (!$info || $info['deleted'] == '1') { showError(lang('photo_not_exists')); } if ($info['exif']) { $info['exif'] = @unserialize($info['exif']); $exif_obj =& loader::lib('exif'); $exif = $exif_obj->parse_exif($info['exif']); //Chief Exif $chief_exif = array('Model', 'ApertureFNumber', 'ExposureTime', 'Flash', 'FocalLength', 'ISOSpeedRatings', 'WhiteBalance', 'ExposureBiasValue', 'DateTimeOriginal', 'FocusDistance'); if (is_array($exif)) { foreach ($exif as $k => $v) { if (in_array($k, $chief_exif)) { $metas[] = array('key' => $k, 'value' => $v, 'cname' => lang('exif_' . $k)); } } } if (isset($metas)) { $this->output->set('metas', $metas); } } $info['tags_list'] = parse_tag($info['tags']); $album_info = $this->mdl_album->get_info($info['album_id']); if (!$this->mdl_album->check_album_priv($album_info['id'], $album_info)) { $this->_priv_page($album_info['id'], $album_info); exit; } $this->plugin->trigger('viewed_photo', $id); $this->mdl_photo->add_hit($id); $sort_setting = $this->_sort_setting(); list($sort, $sort_list) = get_sort_list($sort_setting, 'photo', 'tu_desc'); $nav['items'] = $this->mdl_photo->get_items(array('album_id' => $info['album_id']), $sort); $nav['rank_of'] = array_flip($nav['items']); $nav['first_rank'] = 0; $nav['last_rank'] = count($nav['items']) - 1; $nav['current_item'] = $id; $nav['current_rank'] = $nav['rank_of'][$id]; $nav['first_item'] = $nav['items'][$nav['first_rank']]; $nav['last_item'] = $nav['items'][$nav['last_rank']]; if ($nav['current_rank'] != $nav['first_rank']) { $nav['previous_item'] = $nav['items'][$nav['current_rank'] - 1]; } else { if ($nav['last_rank'] > 0) { $nav['previous_item'] = $nav['last_item']; } } if ($nav['current_rank'] != $nav['last_rank']) { $nav['next_item'] = $nav['items'][$nav['current_rank'] + 1]; } else { if ($nav['last_rank'] > 0) { $nav['next_item'] = $nav['first_item']; } } $ids = array(); array_push($ids, $nav['first_item']); array_push($ids, $nav['last_item']); if (isset($nav['previous_item'])) { array_push($ids, $nav['previous_item']); } if (isset($nav['next_item'])) { array_push($ids, $nav['next_item']); } $ids = array_unique($ids); $p_result = $this->mdl_photo->get_info($ids); $picture = array('previous' => false, 'next' => false, 'first' => false, 'last' => false); if ($p_result) { foreach ($p_result as $v) { if (isset($nav['previous_item']) and $v['id'] == $nav['previous_item']) { $i = 'previous'; $picture[$i] = $v; } if (isset($nav['next_item']) and $v['id'] == $nav['next_item']) { $i = 'next'; $picture[$i] = $v; } if (isset($nav['first_item']) and $v['id'] == $nav['first_item']) { $i = 'first'; $picture[$i] = $v; } if (isset($nav['last_item']) and $v['id'] == $nav['last_item']) { $i = 'last'; $picture[$i] = $v; } } } if ($this->setting->get_conf('system.enable_comment') && $album_info['enable_comment'] == 1) { $cpage = intval($this->getGet('cpage', 1)); $mdl_comment =& loader::model('comment'); $comments = $mdl_comment->get_all($cpage, array('status' => 1, 'pid' => 0, 'ref_id' => $id, 'type' => 2)); if ($comments['ls']) { foreach ($comments['ls'] as $k => $v) { $sub_comments = $mdl_comment->get_sub($v['id']); if ($sub_comments) { foreach ($sub_comments as $kk => $vv) { $sub_comments[$kk]['content'] = $this->plugin->filter('comment_content', $vv['content'], $vv['id']); } } $comments['ls'][$k]['content'] = $this->plugin->filter('comment_content', $v['content'], $v['id']); $comments['ls'][$k]['sub_comments'] = $sub_comments; } } $this->output->set('comments_list', $comments['ls']); $this->output->set('comments_total_page', $comments['total']); $this->output->set('comments_current_page', $comments['current']); $this->output->set('ref_id', $id); $this->output->set('comments_type', 2); $this->output->set('enable_comment', true); $this->output->set('enable_comment_captcha', $this->setting->get_conf('system.enable_comment_captcha')); } else { $this->output->set('enable_comment', false); } $this->output->set('photo_body_append', $this->plugin->filter('photo_body', '', $id)); $info['desc'] = $this->plugin->filter('photo_desc', $info['desc'], $album_info['id'], $id); $this->output->set('picture', $picture); $this->output->set('info', $info); $this->output->set('photo_col_ctl', $this->plugin->filter('photo_col_ctl', '', $id)); $this->output->set('photo_view_sidebar', $this->plugin->filter('photo_view_sidebar', '', $album_info['id'], $id)); //share $sharetitle = $this->setting->get_conf('site.share_title'); $this->output->set('sharetitle', str_replace('{name}', $info['name'], $sharetitle)); $this->output->set('current_rank', $nav['current_rank']); $this->output->set('last_rank', $nav['last_rank']); $this->output->set('current_photo', $nav['current_rank'] + 1); $this->output->set('album_info', $album_info); //面包屑 $crumb_nav = $this->mdl_cate->cate_path_link($album_info['cate_id']); $crumb_nav[] = array('name' => $album_info['name'], 'link' => site_link('photos', 'index', array('aid' => $album_info['id']))); $crumb_nav[] = array('name' => $info['name'], 'link' => site_link('photos', 'view', array('id' => $info['id']))); $this->page_crumb($crumb_nav); $page_title = $info['name'] . ' - ' . $album_info['name'] . ' - ' . $this->setting->get_conf('site.title'); $page_keywords = ($info['tags'] ? implode(',', $info['tags_list']) . ',' : '') . $this->setting->get_conf('site.keywords'); $page_description = $info['desc'] ? mycutstr(strip_tags($info['desc']), 200) : $this->setting->get_conf('site.description'); $this->page_init($page_title, $page_keywords, $page_description, $info['album_id'], $id); $this->render(); }
private function create_share_item($image_path, $image_num, $img_array) { $local_user = $this->current_user; $segment = spClass('Segment'); if ($image_path) { $cover_path = APP_PATH . $image_path . '_middle.jpg'; $img_pro = @getimagesize($cover_path); $img['width'] = $img_pro['0']; $img['height'] = $img_pro['1']; $imagelib = spClass('ImageLib'); $data['color'] = $imagelib->sample_color($cover_path); $data['img_pro'] = array_to_str($img, ','); $data['image_path'] = $image_path; } if ($img_array) { $data['images_array'] = serialize($img_array); } $data['title'] = $this->spArgs('title'); $data['category_id'] = $this->spArgs('category_id'); $data['user_id'] = $local_user['user_id']; $data['intro'] = $this->spArgs('intro'); $segment_str = $segment->segment($data['intro']); $data['intro'] = parse_tag($data['category_id'], $data['intro']); $at_array = $this->parse_at($data['intro']); $tag_parse = $this->parse_tag($data['intro']); $data['intro'] = $at_array['message']; $tags = str_replace(',', ' ', $this->spArgs('tags')); $data['intro_search'] .= ' ' . $segment->convert_to_py($tags); $data['intro_search'] .= ' ' . $segment->convert_to_py($tag_parse); $data['intro_search'] .= ' ' . $at_array['atsearch_str']; $data['intro_search'] .= $segment_str['py']; $data['keywords'] .= ' ' . $tags; $data['keywords'] .= ' ' . $tag_parse; $data['keywords'] .= ' ' . $segment_str['cn']; if ($groupid = $this->spArgs('groupid')) { $data['intro_search'] .= " group{$groupid}g"; } if ($topicid = $this->spArgs('topicid')) { $data['intro_search'] .= " topic{$topicid}t"; } $data['share_type'] = $this->spArgs('share_type', 'upload'); $data['price'] = $this->spArgs('price', '0'); if (!is_numeric($data['price'])) { $data['price'] = 0; } if ($this->is_editer()) { $data['is_show'] = 1; } else { $data['is_show'] = $this->settings['basic_setting']['site_need_verify'] && $this->permission['need_verify'] ? 0 : 1; } $data['reference_url'] = $this->spArgs('reference_url', ''); $data['reference_itemid'] = $this->spArgs('item_id', ''); $data['reference_channel'] = $this->spArgs('channel'); $data['promotion_url'] = $this->spArgs('promotion_url'); $data['total_images'] = $image_num; $share_attr = array(); if ($data['share_type'] == 'video') { $share_attr['video']['flv'] = $this->spArgs('flv', '', 'POST', 'false'); $share_attr['video']['imgurl'] = $image_path; $share_attr['video']['title'] = $data['title']; $data['share_attribute'] = serialize($share_attr); } $create_time = time(); $data['create_time'] = $create_time; $share_data['create_time'] = $create_time; $share_data['poster_id'] = $local_user['user_id']; $share_data['poster_nickname'] = $local_user['nickname']; $share_data['original_id'] = 0; $share_data['user_id'] = $local_user['user_id']; $share_data['user_nickname'] = $local_user['nickname']; $share_data['total_comments'] = 0; $share_data['total_likes'] = 0; $share_data['total_clicks'] = 0; $share_data['total_forwarding'] = 0; $share_data['album_id'] = $this->spArgs('album_id'); $share_data['category_id'] = $this->spArgs('category_id'); //$data['share'] = $share_data; $ptx_item = spClass('ptx_item'); //$ptx_item->linker['share']['enabled'] = true; $item_id = $ptx_item->create($data); $ptx_share = spClass('ptx_share'); $share_data['item_id'] = $item_id; $share_id = $ptx_share->create($share_data); $ptx_album = spClass('ptx_album'); $ptx_album->update_album_cover($share_data['album_id']); $event_dispatcher = spClass('event_dispatcher'); $event_data['to_user_id'] = $local_user['user_id']; $event_data['to_nickname'] = $local_user['nickname']; $event_data['share_id'] = $share_id; $event_data['share_title'] = $data['title']; if ($data['share_type'] == 'video') { $event_dispatcher->invoke('post_video', $event_data); } elseif ($data['share_type'] == 'article') { $event_dispatcher->invoke('post_article', $event_data); } else { $event_dispatcher->invoke('post_share', $event_data); } return true; }