Advertisement
Guest User

newsmanager-search

a guest
Feb 8th, 2012
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. add_action('search-index', 'i18n_search_nm_index');
  2. add_filter('search-item', 'i18n_search_nm_item');
  3.  
  4. function i18n_search_nm_index() {
  5.   $posts = nm_get_posts();
  6.   foreach ($posts as $post) {
  7.   $id=$post->slug;
  8.   $title = strip_tags(strip_decode($post->title));
  9.   $file = NMPOSTPATH . "$id.xml";
  10.   $post = @getXML($file);
  11.   $content = html_entity_decode(strip_tags(htmlspecialchars_decode($post->content)), ENT_QUOTES, 'UTF-8');;
  12.   i18n_search_index_item('nm:'.$id, null, $date, $date, null, $title, $content);
  13.   }
  14. }
  15.  
  16. function i18n_search_nm_item($id, $language, $creDate, $pubDate, $score) {
  17.  
  18.   if (!class_exists('I18nSearchNewsManangerResultItem')) {
  19.    class I18nSearchNewsManangerResultItem extends I18nSearchResultItem {
  20.       protected $data = null;
  21.       protected function get($name) {
  22.         if (!$this->data) {
  23.   $slug=substr($this->id,3);
  24.   $file = NMPOSTPATH . "$slug.xml";
  25.   $post = @getXML($file);
  26.     if (!post) return null;
  27.         }
  28.         switch ($name) {
  29.           case 'title': return strip_tags(strip_decode($post->title));
  30.           case 'content': return null;
  31.           case 'link':  $url = nm_get_url('post') . $slug;return $url;
  32.           default: return @$post>title;
  33.         }
  34.       }
  35.     }
  36.  
  37.   }
  38.  
  39.   if (substr($id,0,3) == 'nm:') {
  40.     // return the result item, if it is an item of our plugin
  41.     return new I18nSearchNewsManangerResultItem($id, $language, $creDate, $pubDate, $score);
  42.   }
  43.   // item is not from our plugin - maybe from another plugin
  44.   return null;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement