soo_article_filter Page 2 of 2

soo_article_filter source code

  1 : function soo_article_filter$atts$thing ) {
  2 : 
  3 :     global $pretext;
  4 :     if ( $pretext['q'] ) return parse($thing);
  5 : 
  6 :     $customFields getCustomFields();                      // field names
  7 :     $customAtts array_null(array_flip($customFields));
  8 :     $standardAtts = array(
  9 :         'expires'       => null,    // accept 'any', 'past', 'future', or 0
 10 :         'article_image' => null,    // boolean: 0 = no image, 1 = has image
 11 :         'multidoc'      => null,    // for soo_multidoc compatibility
 12 :         'index_ignore'  => 'a,an,the',  // leading words to move in index titles
 13 :         'index_field'   => null,    // custom field name for index-style title
 14 :         'update_set'    => null,    // SET clause for custom update query
 15 :         'update_where'  => null,    // WHERE clause for custom update query
 16 :         'where'         => null,    // raw WHERE expression for filter
 17 :         'limit'         => null,    // LIMIT value
 18 :         'offset'        => null,    // OFFSET value
 19 :         'sort'          => null,    // ORDER BY expression
 20 :     );
 21 :     extract(lAtts($standardAtts $customAtts$atts));
 22 :     if ( ! is_null($expires) )
 23 :         switch ( $expires ) {
 24 :             case 'any':
 25 :                 $where_exp[] = 'Expires > 0';
 26 :                 break;
 27 :             case 'past':
 28 :                 $where_exp[] = 'Expires <= now() and Expires > 0';
 29 :                 break;
 30 :             case 'future':
 31 :                 $where_exp[] = 'Expires > now()';
 32 :                 break;
 33 :             case 0:
 34 :                 $where_exp[] = 'Expires = 0';
 35 :         }
 36 : 
 37 :     if ( ! is_null($article_image) )
 38 :         $where_exp[] = 'Image ' . ( $article_image '!' '' ) . "= ''";
 39 : 
 40 :     if ( $customFields )
 41 :         foreach( $customFields as $i => $field )
 42 :                 // to prevent conflicts between named atts and custom fields
 43 :             if ( ! array_key_exists($field$standardAtts) and isset($atts[$field]) ) {
 44 :                 $value $atts[$field];
 45 :                 switch ( $value ) {
 46 :                     case '':
 47 :                         $where_exp[] = "custom_$i = ''";
 48 :                         break;
 49 :                     default:
 50 :                         $where_exp[] = "custom_$i regexp '$value'";
 51 :                 }
 52 :             }
 53 : 
 54 :     if ( $multidoc and _soo_multidoc_ids_init() ) {
 55 :         global $soo_multidoc;
 56 :         $where_exp[] = "ID not in (select id from " safe_pfx('soo_multidoc') . " where id != root)";
 57 :     }
 58 : 
 59 :     if ( $where $where_exp[] = $where;
 60 : 
 61 :     $select '*';
 62 :     $table safe_pfx('textpattern');
 63 :     $where_exp = isset($where_exp) ? ' where ' implode(' and '$where_exp) : '';
 64 :     $sort $sort ' order by ' doSlash($sort) : '';
 65 :     $limit $limit ' limit ' intval($offset) . ',' intval($limit) : '';
 66 : 
 67 :     if ( $index_field ) {
 68 :         $i array_search($index_field$customFields);
 69 :         if ( $i ) {
 70 :             $regexp "'^(" implode('|'do_list($index_ignore)) . ")$'";
 71 :             $select .= ", trim(Title) as index_title, substring_index(trim(Title),' ',1) as first_word, substring(trim(Title), locate(' ',trim(Title))+1) as remaining_words";
 72 :             $update[] = array(
 73 :                 'set' => "custom_$i = concat(remaining_words, ', ', first_word)",
 74 :                 'where' => "first_word regexp $regexp and custom_$i = ''",
 75 :             );
 76 :             $update[] = array(
 77 :                 'set' => "custom_$i = trim(Title)",
 78 :                 'where' => "custom_$i = ''",
 79 :             );
 80 : 
 81 :         }
 82 :     }
 83 : 
 84 :     if ( ! safe_query("create temporary table $table select $select from $table" $where_exp $sort $limit) )
 85 :         return;
 86 : 
 87 :     if ( $update_set )
 88 :         $update[] = array(
 89 :             'set' => $update_set,
 90 :             'where' => $update_where $update_where '1=1',
 91 :         );
 92 : 
 93 :     if ( ! empty($update) )
 94 :         foreach ( $update as $u )
 95 :             safe_update('textpattern'$u['set'], $u['where']);
 96 : 
 97 :     $out parse($thing);
 98 :     safe_query("drop temporary table $table");
 99 :     return $out;
100 : 
101 : }