示例#1
0
/**
 * Returns an array of ids for posts that have the specified tag
 *
 * @param string
 * @return array
 */
function get_posts_with_tag($tag)
{
    $tag_ext = Extend::where('key', '=', 'post_tags')->get();
    $tag_id = $tag_ext[0]->id;
    $prefix = Config::db('prefix', '');
    $posts = array();
    foreach (Query::table($prefix . 'post_meta')->where('extend', '=', $tag_id)->where('data', 'LIKE', '%' . $tag . '%')->get() as $meta) {
        $posts[] = $meta->post;
    }
    return array_unique($posts);
}
示例#2
0
     $vars['field'] = $extend;
     $vars['pagetypes'] = Query::table(Base::table('pagetypes'))->sort('key')->get();
     return View::create('extend/fields/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer');
 });
 Route::post('admin/extend/fields/edit/(:num)', function ($id) {
     $input = Input::get(array('type', 'field', 'key', 'label', 'attributes', 'pagetype'));
     if (empty($input['key'])) {
         $input['key'] = $input['label'];
     }
     $input['key'] = slug($input['key'], '_');
     array_walk_recursive($input, function (&$value) {
         $value = eq($value);
     });
     $validator = new Validator($input);
     $validator->add('valid_key', function ($str) use($id, $input) {
         return Extend::where('key', '=', $str)->where('type', '=', $input['type'])->where('id', '<>', $id)->count() == 0;
     });
     $validator->check('key')->is_max(1, __('extend.key_missing'))->is_valid_key(__('extend.key_exists'));
     $validator->check('label')->is_max(1, __('extend.label_missing'));
     if ($errors = $validator->errors()) {
         Input::flash();
         Notify::error($errors);
         return Response::redirect('admin/extend/fields/edit/' . $id);
     }
     if ($input['field'] == 'image') {
         $attributes = Json::encode($input['attributes']);
     } elseif ($input['field'] == 'file') {
         $attributes = Json::encode(array('attributes' => array('type' => $input['attributes']['type'])));
     } else {
         $attributes = '';
     }
/**
 * Returns an array of unique tags that exist on post given post,
 * empty array if no tags are found.
 *
 * @return array
 */
function get_tags_for_post($post_id)
{
    $tag_ext = Extend::where('key', '=', 'post_tags')->where('type', '=', 'post')->get();
    $tag_id = $tag_ext[0]->id;
    $prefix = Config::db('prefix', '');
    $tags = array();
    $index = 0;
    $meta = Query::table($prefix . 'post_meta')->left_join('posts', 'posts.id', '=', 'post_meta.post')->where('posts.status', '=', 'published')->where('extend', '=', $tag_id)->where('post', '=', $post_id)->get();
    $post_meta = json_decode($meta[0]->data);
    if (!trim($post_meta->text) == "") {
        foreach (explode(",", $post_meta->text) as $tag_text) {
            $tags[$index] = trim($tag_text);
            $index += 1;
        }
    }
    return array_unique($tags);
}