Dotclear

Changeset 721


Ignore:
Timestamp:
01/22/09 17:33:09 (14 years ago)
Author:
Tomtom33
Message:

Many changes :

  • Fixed SQL query
  • Fixed results display
  • Fixed post URL on different blog
  • Fixed cateogry URL on different blog
  • Fixed meta URL on different blog
  • Fixed pagination on multi blog search
Location:
plugins/multiBlogSearch
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • plugins/multiBlogSearch/_admin.php

    r717 r721  
    2323          '<fieldset><legend>'.__('Multi blog search').'</legend>'. 
    2424          '<p><label class="classic">'. 
    25           form::checkbox('multiblogsearch_enabled','1',$settings->multisearch_enabled). 
     25          form::checkbox('multiblogsearch_enabled','1',$settings->multiblogsearch_enabled). 
    2626          __('Enable multi blog Search').'</label></p>'. 
    2727          '</fieldset>'; 
     
    3030     public static function adminBeforeBlogSettingsUpdate(&$settings) 
    3131     { 
    32           $settings->setNameSpace('multiBlogSearch'); 
    33           $settings->put('multiblogsearch_enabled',!empty($_POST['multisearch_enabled']),'boolean',false); 
     32          $settings->setNameSpace('multiblogsearch'); 
     33          $settings->put('multiblogsearch_enabled',!empty($_POST['multiblogsearch_enabled']),'boolean'); 
    3434          $settings->setNameSpace('system'); 
    3535     } 
  • plugins/multiBlogSearch/_define.php

    r717 r721  
    1515          /* Description*/         "Find all posts in all blogs", 
    1616          /* Author */             "Tomtom (http://blog.zenstyle.fr)", 
    17           /* Version */            '0.2', 
     17          /* Version */            '0.3', 
    1818          /* Permissions */        'usage,contentadmin' 
    1919); 
  • plugins/multiBlogSearch/_public.php

    r717 r721  
    1616$core->tpl->addValue('MultiBlogSearchPaginationURL',array('multiBlogSearchTpl','paginationURL')); 
    1717$core->tpl->addValue('MultiBlogSearchBlogName',array('multiBlogSearchTpl','blogName')); 
     18$core->tpl->addValue('MultiBlogSearchEntryURL',array('multiBlogSearchTpl','entryURL')); 
     19$core->tpl->addValue('MultiBlogSearchCategoryURL',array('multiBlogSearchTpl','categoryURL')); 
     20$core->tpl->addValue('MultiBlogSearchMetaURL',array('multiBlogSearchTpl','metaURL')); 
    1821$core->tpl->addBlock('MultiBlogSearchEntries',array('multiBlogSearchTpl','entries')); 
    1922$core->tpl->addBlock('MultiBlogSearchPagination',array('multiBlogSearchTpl','pagination')); 
     
    2225class multiBlogSearchBehaviors extends dcUrlHandlers 
    2326{ 
    24      /** 
    25       * Adds multiBlogSearch templates 
    26       */ 
     27 
    2728     public static function addTplPath() 
    2829     { 
     
    3233     } 
    3334 
    34      /** 
    35       * Intercepts multiBlogSearch param in URI and serves right template 
    36       */ 
    3735     public static function multiBlogSearch() 
    3836     { 
     
    4644 
    4745          if ($GLOBALS['_search']) { 
    48                $_multiblogsearch = new multiBlogSearch($GLOBALS['core']); 
    49                $GLOBALS['_search_count'] = $_multiblogsearch->getMultiBlogPosts(array('search' => $GLOBALS['_search']),true)->f(0); 
     46               $GLOBALS['_ctx']->multiblogsearch = new multiBlogSearch($GLOBALS['core']); 
     47               $GLOBALS['_search_count'] = $GLOBALS['_ctx']->multiblogsearch->getPosts(array('search' => $GLOBALS['_search']),true)->f(0); 
    5048               self::serveDocument('multiblogsearch.html'); 
    5149               exit; 
     
    7169          $f = $GLOBALS['core']->tpl->getFilters($attr); 
    7270          return '<?php echo '.sprintf($f,'$_ctx->posts->blog_name').'; ?>'; 
     71     } 
     72 
     73     public static function entryURL($attr) 
     74     { 
     75          $f = $GLOBALS['core']->tpl->getFilters($attr); 
     76          return '<?php echo '.sprintf($f,'$_ctx->posts->blog_url.$core->url->getBase("post").'. 
     77          '"/".$_ctx->posts->post_url').'; ?>'; 
     78     } 
     79 
     80     public static function categoryURL($attr) 
     81     { 
     82          $f = $GLOBALS['core']->tpl->getFilters($attr); 
     83          return '<?php echo '.sprintf($f,'$_ctx->posts->blog_url.$core->url->getBase("category").'. 
     84          '"/".$_ctx->posts->cat_url').'; ?>'; 
     85     } 
     86      
     87     public static function metaURL($attr) 
     88     { 
     89          $f = $GLOBALS['core']->tpl->getFilters($attr); 
     90          return '<?php echo '.sprintf($f,'$_ctx->posts->blog_url.$core->url->getBase("tag").'. 
     91          '"/".rawurlencode($_ctx->meta->meta_id)').'; ?>'; 
    7392     } 
    7493 
     
    146165          } 
    147166 
    148           $sortby = 'post_dt'; 
    149           $order = 'desc'; 
     167          $sortby = 'blog_name'; 
     168          $order = 'asc'; 
    150169          if (isset($attr['sortby'])) { 
    151170               switch ($attr['sortby']) { 
     
    173192          $res = "<?php\n"; 
    174193          $res .= $p; 
    175           $res .= '$_multiblogsearch = new multiBlogSearch($core);'."\n"; 
    176194          $res .= '$_ctx->post_params = $params;'."\n"; 
    177           $res .= '$_ctx->posts = $_multiblogsearch->getMultiBlogPosts($params);'."\n"; 
    178           $res .= 'unset($params); unset($_multiblogsearch);'."\n"; 
     195          $res .= '$_ctx->posts = $_ctx->multiblogsearch->getPosts($params);'."\n"; 
     196          $res .= 'unset($params);'."\n"; 
    179197          $res .= "?>\n"; 
    180198 
     
    189207     { 
    190208          return 
    191           "<?php if (!multiBlogSearch::firstPostOfBlog(\$_ctx->posts)) : ?>". 
     209          "<?php if (\$_ctx->multiblogsearch->firstPostOfBlog(\$_ctx->posts)) : ?>". 
    192210          $content. 
    193211          "<?php endif; ?>"; 
     
    198216          $p = "<?php\n"; 
    199217          $p .= '$params = $_ctx->post_params;'."\n"; 
    200           $p .= '$_multiblogsearch = new multiBlogSearch($core);'."\n"; 
    201           $p .= '$_ctx->pagination = $_multiblogsearch->getMultiBlogPosts($params,true); unset($params);'."\n"; 
     218          $p .= '$_ctx->pagination = $_ctx->multiblogsearch->getPosts($params,true); unset($params);'."\n"; 
    202219          $p .= "?>\n"; 
    203220 
  • plugins/multiBlogSearch/default-templates/multiblogsearch.html

    r717 r721  
    7575 
    7676    <h2 class="post-title"><a 
    77     href="{{tpl:EntryURL}}">{{tpl:EntryTitle encode_html="1"}}</a></h2> 
     77    href="{{tpl:MultiBlogSearchEntryURL}}">{{tpl:EntryTitle encode_html="1"}}</a></h2> 
    7878 
    7979    <p class="post-info">{{tpl:lang By}} {{tpl:EntryAuthorLink}} 
    8080    {{tpl:lang on}} {{tpl:EntryDate}}, {{tpl:EntryTime}} 
    8181    <tpl:EntryIf has_category="1"> 
    82     - <a href="{{tpl:EntryCategoryURL}}">{{tpl:EntryCategory encode_html="1"}}</a> 
     82    - <a href="{{tpl:MultiBlogSearchCategoryURL}}">{{tpl:EntryCategory encode_html="1"}}</a> 
    8383    </tpl:EntryIf> 
    8484    </p> 
     
    8686    <tpl:EntryMetaData> 
    8787    <tpl:MetaDataHeader><ul class="post-tags"></tpl:MetaDataHeader> 
    88     <li><a href="{{tpl:MetaURL}}">{{tpl:MetaID}}</a></li> 
     88    <li><a href="{{tpl:MultiBlogSearchMetaURL}}">{{tpl:MetaID}}</a></li> 
    8989    <tpl:MetaDataFooter></ul></tpl:MetaDataFooter> 
    9090    </tpl:EntryMetaData> 
     
    9696    <tpl:EntryIf extended="1"> 
    9797      <div class="post-content">{{tpl:EntryExcerpt}}</div> 
    98       <p class="read-it"><a href="{{tpl:EntryURL}}" 
     98      <p class="read-it"><a href="{{tpl:MultiBlogSearchEntryURL}}" 
    9999      title="{{tpl:lang Continue reading}} {{tpl:EntryTitle encode_html="1"}}">{{tpl:lang Continue 
    100100      reading}}</a>...</p> 
     
    114114    </tpl:EntryIf> 
    115115    <tpl:EntryIf show_comments="1"> 
    116       <a href="{{tpl:EntryURL}}#comments" class="comment_count">{{tpl:EntryCommentCount}}</a> 
     116      <a href="{{tpl:MultiBlogSearchEntryURL}}#comments" class="comment_count">{{tpl:EntryCommentCount}}</a> 
    117117    </tpl:EntryIf> 
    118118    <tpl:EntryIf show_pings="1"> 
    119       <a href="{{tpl:EntryURL}}#pings" class="ping_count">{{tpl:EntryPingCount}}</a></tpl:EntryIf> 
     119      <a href="{{tpl:MultiBlogSearchEntryURL}}#pings" class="ping_count">{{tpl:EntryPingCount}}</a></tpl:EntryIf> 
    120120    <tpl:EntryIf has_attachment="1"> 
    121       <a href="{{tpl:EntryURL}}#attachments" class="attach_count">{{tpl:EntryAttachmentCount}}</a></tpl:EntryIf> 
     121      <a href="{{tpl:MultiBlogSearchEntryURL}}#attachments" class="attach_count">{{tpl:EntryAttachmentCount}}</a></tpl:EntryIf> 
    122122    <tpl:EntryIf operator="or" show_comments="1" show_pings="1" has_attachment="1"> 
    123123      </p> 
  • plugins/multiBlogSearch/inc/class.multi.blog.search.php

    r717 r721  
    1414{ 
    1515     protected $core; 
    16       
     16 
    1717     public function __construct(&$core) 
    1818     { 
    1919          $this->core =& $core; 
    2020     } 
    21       
    22      public function getMultiBlogPosts($params=array(),$count_only=false) 
     21 
     22     public function getPosts($params = array(),$count_only = false) 
    2323     { 
    2424          if ($count_only) 
     
    3535                    'post_content, post_content_xhtml, post_notes, '; 
    3636               } 
    37                 
     37 
    3838               if (!empty($params['columns']) && is_array($params['columns'])) { 
    3939                    $content_req .= implode(', ',$params['columns']).', '; 
    4040               } 
    41                 
     41 
    4242               $strReq = 
    4343               'SELECT P.post_id, P.blog_id, P.user_id, P.cat_id, post_dt, '. 
     
    4848               'U.user_name, U.user_firstname, U.user_displayname, U.user_email, '. 
    4949               'U.user_url, '. 
    50                'C.cat_title, C.cat_url, C.cat_desc, B.blog_name '; 
    51           } 
    52            
     50               'C.cat_title, C.cat_url, C.cat_desc, '. 
     51               'B.blog_url, B.blog_name '; 
     52          } 
     53 
    5354          $strReq .= 
    5455          'FROM '.$this->core->prefix.'post P '. 
    5556          'INNER JOIN '.$this->core->prefix.'user U ON U.user_id = P.user_id '. 
    56           'LEFT OUTER JOIN '.$this->core->prefix.'category C ON P.cat_id = C.cat_id '. 
    57           'LEFT OUTER JOIN '.$this->core->prefix.'blog B ON P.blog_id = B.blog_id '; 
    58            
     57          'NATURAL JOIN '.$this->core->prefix.'blog B '. 
     58          'LEFT OUTER JOIN '.$this->core->prefix.'category C ON P.cat_id = C.cat_id '; 
     59 
    5960          if (!empty($params['from'])) { 
    6061               $strReq .= $params['from'].' '; 
    6162          } 
    62            
     63 
    6364          $strReq .= 
    64           "WHERE P.blog_id != '' "; 
    65            
     65          "WHERE P.blog_id != '' AND B.blog_id = P.blog_id "; 
     66 
    6667          if (!$this->core->auth->check('contentadmin',$this->core->blog->id)) { 
    6768               $strReq .= 'AND ((post_status = 1 '; 
    68                 
     69 
    6970               if ($this->core->blog->without_password) { 
    7071                    $strReq .= 'AND post_password IS NULL '; 
    7172               } 
    7273               $strReq .= ') '; 
    73                 
     74 
    7475               if ($this->core->auth->userID()) { 
    7576                    $strReq .= "OR P.user_id = '".$this->con->escape($this->core->auth->userID())."')"; 
     
    7879               } 
    7980          } 
    80            
     81 
    8182          # Adding parameters 
    8283          if (isset($params['post_type'])) 
     
    9293               $strReq .= "AND post_type = 'post' "; 
    9394          } 
    94            
     95 
    9596          if (!empty($params['post_id'])) { 
    9697               if (is_array($params['post_id'])) { 
     
    101102               $strReq .= 'AND P.post_id '.$this->core->con->in($params['post_id']); 
    102103          } 
    103            
     104 
    104105          if (!empty($params['post_url'])) { 
    105106               $strReq .= "AND post_url = '".$this->core->con->escape($params['post_url'])."' "; 
    106107          } 
    107            
     108 
    108109          if (!empty($params['user_id'])) { 
    109110               $strReq .= "AND U.user_id = '".$this->core->con->escape($params['user_id'])."' "; 
    110111          } 
    111            
     112 
    112113          if (!empty($params['cat_id'])) 
    113114          { 
     
    130131               $strReq .= 'AND '.$this->core->blog->getPostsCategoryFilter($params['cat_url'],'cat_url').' '; 
    131132          } 
    132            
     133 
    133134          /* Other filters */ 
    134135          if (isset($params['post_status'])) { 
    135136               $strReq .= 'AND post_status = '.(integer) $params['post_status'].' '; 
    136137          } 
    137            
     138 
    138139          if (isset($params['post_selected'])) { 
    139140               $strReq .= 'AND post_selected = '.(integer) $params['post_selected'].' '; 
    140141          } 
    141            
     142 
    142143          if (!empty($params['post_year'])) { 
    143144               $strReq .= 'AND '.$this->core->con->dateFormat('post_dt','%Y').' = '. 
    144145               "'".sprintf('%04d',$params['post_year'])."' "; 
    145146          } 
    146            
     147 
    147148          if (!empty($params['post_month'])) { 
    148149               $strReq .= 'AND '.$this->core->con->dateFormat('post_dt','%m').' = '. 
    149150               "'".sprintf('%02d',$params['post_month'])."' "; 
    150151          } 
    151            
     152 
    152153          if (!empty($params['post_day'])) { 
    153154               $strReq .= 'AND '.$this->core->con->dateFormat('post_dt','%d').' = '. 
    154155               "'".sprintf('%02d',$params['post_day'])."' "; 
    155156          } 
    156            
     157 
    157158          if (!empty($params['post_lang'])) { 
    158159               $strReq .= "AND P.post_lang = '".$this->core->con->escape($params['post_lang'])."' "; 
    159160          } 
    160            
     161 
    161162          if (!empty($params['search'])) 
    162163          { 
    163164               $words = text::splitWords($params['search']); 
    164                 
     165      
    165166               if (!empty($words)) 
    166167               { 
     
    169170                         $this->core->callBehavior('multiBlogSearchPostsSearch',$this->core,array(&$words,&$strReq,&$params)); 
    170171                    } 
    171                      
     172 
    172173                    if ($words) 
    173174                    { 
     
    179180               } 
    180181          } 
    181            
     182 
    182183          if (!empty($params['sql'])) { 
    183184               $strReq .= $params['sql'].' '; 
    184185          } 
    185            
     186 
    186187          if (!$count_only) 
    187188          { 
     
    189190                    $strReq .= 'ORDER BY '.$this->core->con->escape($params['order']).' '; 
    190191               } else { 
    191                     $strReq .= 'ORDER BY blog_name ASC, post_dt DESC '; 
    192                } 
    193           } 
    194            
     192                    $strReq .= 'ORDER BY post_dt DESC, blog_name ASC '; 
     193               } 
     194               $strReq .= ', post_dt DESC '; 
     195          } 
     196 
    195197          if (!$count_only && !empty($params['limit'])) { 
    196                //$strReq .= $this->core->con->limit($params['limit']); 
    197           } 
    198 echo $strReq;//print_r($params['limit']); 
     198               $strReq .= $this->core->con->limit($params['limit']); 
     199          } 
     200 
    199201          $rs = $this->core->con->select($strReq); 
    200202          $rs->core = $this->core; 
    201203          $rs->_nb_media = array(); 
    202204          $rs->extend('rsExtPost'); 
    203            
     205 
    204206          # --BEHAVIOR-- multiBlogSearchGetPosts 
    205207          $this->core->callBehavior('multiBlogSearchGetPosts',$rs); 
    206            
     208 
    207209          return $rs; 
    208210     } 
    209       
    210      public static function firstPostOfBlog(&$rs) 
    211      { 
    212           $cblog = $rs->blog_id; //var_dump($rs->post_id); 
     211 
     212     public function firstPostOfBlog(&$rs) 
     213     { 
     214          if ($rs->index() == 0) { 
     215               return true; 
     216          } 
     217          $cblog = $rs->blog_id; 
    213218          $rs->movePrev(); 
    214           $nblog = $rs->blog_id; //var_dump($rs->post_id); 
    215           $rs->moveNext();  //var_dump($rs->count()); exit; //var_dump($cblog); exit; 
     219          $nblog = $rs->blog_id; 
     220          $rs->moveNext(); 
    216221          return $nblog != $cblog; 
    217222     } 
    218       
     223 
    219224     public static function paginationURL($offset = 0) 
    220225     { 
    221226          global $core; 
    222            
     227 
    223228          $args = $_SERVER['URL_REQUEST_PART']; 
    224229 
Note: See TracChangeset for help on using the changeset viewer.

Sites map