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 :     );
18 :     extract(lAtts($standardAtts $customAtts$atts));
19 :     if ( ! is_null($expires) )
20 :         switch ( $expires ) {
21 :             case 'any':
22 :                 $where_exp[] = 'Expires > 0';
23 :                 break;
24 :             case 'past':
25 :                 $where_exp[] = 'Expires <= now() and Expires > 0';
26 :                 break;
27 :             case 'future':
28 :                 $where_exp[] = 'Expires > now()';
29 :                 break;
30 :             case 0:
31 :                 $where_exp[] = 'Expires = 0';
32 :         }
33 : 
34 :     if ( ! is_null($article_image) )
35 :         $where_exp[] = 'Image ' . ( $article_image '!' '' ) . "= ''";
36 : 
37 :     if ( $customFields )
38 :         foreach( $customFields as $i => $field )
39 :                 // to prevent conflicts between named atts and custom fields
40 :             if ( ! array_key_exists($field$standardAtts) and isset($atts[$field]) ) {
41 :                 $value $atts[$field];
42 :                 switch ( $value ) {
43 :                     case '':
44 :                         $where_exp[] = "custom_$i = ''";
45 :                         break;
46 :                     default:
47 :                         $where_exp[] = "custom_$i regexp '$value'";
48 :                 }
49 :             }
50 : 
51 :     if ( $multidoc and _soo_multidoc_ids_init() ) {
52 :         global $soo_multidoc;
53 :         $where_exp[] = "ID not in (" implode(','$soo_multidoc['noindex']) . ")";
54 :     }
55 : 
56 :     if ( $where $where_exp[] = $where;
57 : 
58 :     $select '*';
59 :     $table safe_pfx('textpattern');
60 :     $where_exp = isset($where_exp) ? ' where ' implode(' and '$where_exp) : '';
61 : 
62 :     if ( $index_field ) {
63 :         $i array_search($index_field$customFields);
64 :         if ( $i ) {
65 :             $regexp "'^(" implode('|'do_list($index_ignore)) . ")$'";
66 :             $select .= ", trim(Title) as index_title, substring_index(trim(Title),' ',1) as first_word, substring(trim(Title), locate(' ',trim(Title))+1) as remaining_words";
67 :             $update[] = array(
68 :                 'set' => "custom_$i = concat(remaining_words, ', ', first_word)",
69 :                 'where' => "first_word regexp $regexp and custom_$i = ''",
70 :             );
71 :             $update[] = array(
72 :                 'set' => "custom_$i = trim(Title)",
73 :                 'where' => "custom_$i = ''",
74 :             );
75 : 
76 :         }
77 :     }
78 : 
79 :     if ( ! safe_query("create temporary table $table select $select from $table" $where_exp) )
80 :         return;
81 : 
82 :     if ( $update_set )
83 :         $update[] = array(
84 :             'set' => $update_set,
85 :             'where' => $update_where $update_where '1=1',
86 :         );
87 : 
88 :     if ( ! empty($update) )
89 :         foreach ( $update as $u )
90 :             safe_update('textpattern'$u['set'], $u['where']);
91 : 
92 :     $out parse($thing);
93 :     safe_query("drop temporary table $table");
94 :     return $out;
95 : 
96 : }