function impose_post_teaser(&$object, $post_type, $use_teaser_type = 'fixed')
 {
     global $current_user, $scoper, $wp_query;
     require_once dirname(__FILE__) . '/teaser_rs.php';
     $teaser_replace = array();
     $teaser_prepend = array();
     $teaser_append = array();
     $teaser_replace[$post_type]['post_content'] = ScoperTeaser::get_teaser_text('replace', 'content', 'post', $post_type, $current_user);
     $teaser_replace[$post_type]['post_excerpt'] = ScoperTeaser::get_teaser_text('replace', 'excerpt', 'post', $post_type, $current_user);
     $teaser_prepend[$post_type]['post_excerpt'] = ScoperTeaser::get_teaser_text('prepend', 'excerpt', 'post', $post_type, $current_user);
     $teaser_append[$post_type]['post_excerpt'] = ScoperTeaser::get_teaser_text('append', 'excerpt', 'post', $post_type, $current_user);
     $teaser_prepend[$post_type]['post_name'] = ScoperTeaser::get_teaser_text('prepend', 'name', 'post', $post_type, $current_user);
     $teaser_append[$post_type]['post_name'] = ScoperTeaser::get_teaser_text('append', 'name', 'post', $post_type, $current_user);
     $force_excerpt = array();
     $force_excerpt[$post_type] = 'excerpt' == $use_teaser_type;
     $args = array('teaser_prepend' => $teaser_prepend, 'teaser_append' => $teaser_append, 'teaser_replace' => $teaser_replace, 'force_excerpt' => $force_excerpt);
     ScoperTeaser::apply_post_teaser($object, $post_type, $args);
     $wp_query->is_404 = false;
     $wp_query->is_attachment = true;
     $wp_query->is_single = true;
     $wp_query->is_singular = true;
     $object->ancestors = array($object->post_parent);
     $wp_query->post_count = 1;
     $wp_query->is_attachment = true;
     $wp_query->posts[] = $object;
     if (isset($wp_query->query_vars['error'])) {
         unset($wp_query->query_vars['error']);
     }
     if (isset($wp_query->query['error'])) {
         $wp_query->query['error'] = '';
     }
 }
 function posts_teaser($results, $tease_otypes, $args = '')
 {
     $defaults = array('user' => '', 'use_object_roles' => -1, 'use_term_roles' => -1, 'request' => '');
     $args = array_merge($defaults, (array) $args);
     extract($args);
     global $wpdb, $scoper, $wp_query;
     if (did_action('wp_meta') && !did_action('wp_head')) {
         return $results;
     }
     if (!is_object($user)) {
         global $current_user;
         $user = $current_user;
     }
     $teaser_replace = array();
     $teaser_prepend = array();
     $teaser_append = array();
     foreach ($tease_otypes as $object_type) {
         $teaser_replace[$object_type]['post_content'] = ScoperTeaser::get_teaser_text('replace', 'content', 'post', $object_type, $user);
         $teaser_prepend[$object_type]['post_content'] = ScoperTeaser::get_teaser_text('prepend', 'content', 'post', $object_type, $user);
         $teaser_append[$object_type]['post_content'] = ScoperTeaser::get_teaser_text('append', 'content', 'post', $object_type, $user);
         $teaser_replace[$object_type]['post_excerpt'] = ScoperTeaser::get_teaser_text('replace', 'excerpt', 'post', $object_type, $user);
         $teaser_prepend[$object_type]['post_excerpt'] = ScoperTeaser::get_teaser_text('prepend', 'excerpt', 'post', $object_type, $user);
         $teaser_append[$object_type]['post_excerpt'] = ScoperTeaser::get_teaser_text('append', 'excerpt', 'post', $object_type, $user);
         $teaser_prepend[$object_type]['post_title'] = ScoperTeaser::get_teaser_text('prepend', 'name', 'post', $object_type, $user);
         $teaser_append[$object_type]['post_title'] = ScoperTeaser::get_teaser_text('append', 'name', 'post', $object_type, $user);
     }
     global $scoper_teaser_filtered_ids;
     if (!isset($scoper->teaser_ids)) {
         $scoper->teaser_ids = array();
     }
     $excerpt_teaser = array();
     $more_teaser = array();
     $x_chars_teaser = array();
     foreach ($tease_otypes as $object_type) {
         $teaser_type = scoper_get_otype_option('use_teaser', 'post', $object_type);
         if ('excerpt' == $teaser_type) {
             $excerpt_teaser[$object_type] = true;
         } elseif ('more' == $teaser_type) {
             $excerpt_teaser[$object_type] = true;
             $more_teaser[$object_type] = true;
         } elseif ('x_chars' == $teaser_type) {
             $excerpt_teaser[$object_type] = true;
             $more_teaser[$object_type] = true;
             $x_chars_teaser[$object_type] = true;
         }
     }
     // strip content from all $results rows not in $items
     $args = array('teaser_prepend' => $teaser_prepend, 'teaser_append' => $teaser_append, 'teaser_replace' => $teaser_replace, 'excerpt_teaser' => $excerpt_teaser, 'more_teaser' => $more_teaser, 'x_chars_teaser' => $x_chars_teaser);
     foreach (array_keys($results) as $key) {
         if (is_array($results[$key])) {
             $id = $results[$key]['ID'];
         } else {
             $id = $results[$key]->ID;
         }
         if (!$scoper_teaser_filtered_ids || !in_array($id, $scoper_teaser_filtered_ids)) {
             if (isset($results[$key]->post_type)) {
                 $object_type = $results[$key]->post_type;
             } else {
                 $object_type = $scoper->data_sources->get_from_db('type', 'post', $id);
             }
             if (!in_array($object_type, $tease_otypes)) {
                 continue;
             }
             ScoperTeaser::apply_teaser($results[$key], 'post', $object_type, $args);
         }
     }
     return $results;
 }
 function flt_nav_menu_items($items, $menu_name, $args)
 {
     global $wpdb;
     $item_types = array();
     foreach ($items as $key => $item) {
         if (!isset($item_types[$item->type])) {
             $item_types["{$item->type}"] = array();
         }
         if (!isset($item_types[$item->type][$item->object])) {
             $item_types[$item->type][$item->object] = array($key => $item->object_id);
         } else {
             $item_types[$item->type][$item->object][$key] = $item->object_id;
         }
     }
     $teaser_enabled = scoper_get_otype_option('do_teaser', 'post');
     // remove unreadable terms
     if (isset($item_types['taxonomy'])) {
         foreach ($item_types['taxonomy'] as $taxonomy => $item_ids) {
             if ($teaser_enabled) {
                 if ($taxonomy_obj = get_taxonomy($taxonomy)) {
                     foreach ($taxonomy_obj->object_type as $post_type) {
                         // don't remove a term if it is associated with a post type that's being teased
                         if (scoper_get_otype_option('use_teaser', 'post', $post_type)) {
                             continue 2;
                         }
                     }
                 }
             }
             /*
             $query_base = "SELECT t.term_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE 1=1 AND tt.taxonomy = '$taxonomy'";
             $query = apply_filters( 'terms_request_rs', $query_base, $taxonomy ); //, array( 'skip_teaser' => true ) );
             $okay_ids = scoper_get_col($query);
             */
             $hide_empty = isset($args['hide_empty']) ? $args['hide_empty'] : 0;
             $okay_ids = get_terms($taxonomy, "fields=ids&hierarchical=0&hide_empty={$hide_empty}");
             if ($remove_ids = array_diff($item_ids, $okay_ids)) {
                 $items = array_diff_key($items, $remove_ids);
             }
         }
     }
     // remove unreadable posts
     if (isset($item_types['post_type'])) {
         foreach ($item_types['post_type'] as $post_type => $item_ids) {
             $where = apply_filters('objects_where_rs', '', 'post', $post_type, array('skip_teaser' => true));
             $okay_ids = scoper_get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = '{$post_type}' {$where} AND ID IN ('" . implode("','", $item_ids) . "')");
             if ($remove_ids = array_diff($item_ids, $okay_ids)) {
                 if ($teaser_enabled && scoper_get_otype_option('use_teaser', 'post', $post_type)) {
                     require_once dirname(__FILE__) . '/teaser_rs.php';
                     $teaser_prepend = ScoperTeaser::get_teaser_text('prepend', 'name', 'post', $post_type);
                     $teaser_append = ScoperTeaser::get_teaser_text('append', 'name', 'post', $post_type);
                     foreach (array_keys($remove_ids) as $key) {
                         $items[$key]->title = $teaser_prepend . $items[$key]->title . $teaser_append;
                     }
                 } else {
                     $items = array_diff_key($items, $remove_ids);
                 }
             }
         }
     }
     return $items;
 }