Wordfest Page 3 of 3

soo_wordfest Source code

  1 : function soo_wordfest$atts ) {
  2 :     global $soo_wordfest;
  3 :     $integer_atts = array(
  4 :         'word_count'        => '',
  5 :         'max_word_count'    => '',
  6 :         'min_word_length'   => '',
  7 :         'max_word_length'   => '',
  8 :         'not_word_length'   => '',
  9 :     );
 10 :     $atts lAtts(array(
 11 :         'must_contain'      => '',
 12 :         'must_begin'        => '',
 13 :         'must_end'          => '',
 14 :         'anagram'           => '',
 15 :     ) + $integer_atts$atts);
 16 :     foreach ( $atts as $name => $value ) {
 17 :         if ( array_key_exists($name$integer_atts) )
 18 :             $value abs(intval($value));
 19 :         if ( is_string($value) )
 20 :             $value trim($value);
 21 :         if ( $name == 'anagram' )
 22 :             $value preg_replace('/[^a-z\s\']/i'''$value);
 23 :         if ( $value )
 24 :             $soo_wordfest[$name] = $value;
 25 :     }
 26 : }
 27 : 
 28 : function soo_wordfest_rules$atts ) {
 29 :     global $soo_wordfest;
 30 :     extract(lAtts(array(
 31 :         'html_id'       =>  '',
 32 :         'class'         =>  '',
 33 :         'wraptag'       =>  '',
 34 :         'break'         =>  '',
 35 :     ), $atts));
 36 : 
 37 :     foreach ( $soo_wordfest as $rule => $value ) {
 38 :         $display soo_wordfest_gTxt($rule);
 39 :         if ( is_string($value) ) {
 40 :             $is_plural str_word_count($value) > 1;
 41 :             $pattern '/\{([^}]+)\|([^}]+)\}/';
 42 :             preg_match($pattern$display$match);
 43 :             if ( count($match) ) {
 44 :                 $replacement $is_plural $match[2] : $match[1];
 45 :                 $display preg_replace($pattern$replacement$display);
 46 :             }
 47 :             $value soo_wordfest_gTxt('lquo') . $value .
 48 :                 soo_wordfest_gTxt('rquo');
 49 :         }
 50 :         $display str_replace('{x}'$value$display);
 51 :         if ( $value )
 52 :             $out[] = $display;
 53 :     }
 54 :     return doWrap($out$wraptag$break$class''''''$html_id);
 55 : }
 56 : 
 57 : function soo_if_wordfest$atts$thing ) {
 58 :     global $soo_wordfest;
 59 :     return parse(EvalElse($thingis_array($soo_wordfest)));
 60 : }
 61 : 
 62 : function soo_if_wordfestive$atts$thing ) {
 63 : 
 64 :     global $soo_wordfest$thiscomment;
 65 : 
 66 :     if ( is_array($soo_wordfest) )
 67 :         extract($soo_wordfest);
 68 :     else
 69 :         return;
 70 : 
 71 :     assert_comment();
 72 :     $comment trim(strtolower(strip_tags($thiscomment['message'])));
 73 : 
 74 :     $pass true;
 75 : 
 76 :     if ( ! empty($must_contain) )
 77 :         if ( $comment == str_ireplace($must_contain''$comment) )
 78 :             $pass false;
 79 : 
 80 :     if ( $pass and ! empty($must_begin) )
 81 :         if ( strtolower($must_begin) != substr($comment0strlen($must_begin)) )
 82 :             $pass false;
 83 : 
 84 :     if ( $pass and ! empty($must_end) )
 85 :         if ( strtolower($must_end) != substr($comment, - strlen($must_end)) )
 86 :             $pass false;
 87 : 
 88 :     if ( $pass and ! empty($word_count) )
 89 :         if ( $word_count != str_word_count($comment) )
 90 :             $pass false;
 91 : 
 92 :     if ( $pass and ! empty($max_word_count) )
 93 :         if ( $max_word_count str_word_count($comment) )
 94 :             $pass false;
 95 : 
 96 :     if ( $pass and ( ! empty($min_word_length) or ! empty($max_word_length)
 97 :         or ! empty($not_word_length) or ! empty($anagram) ) ) {
 98 : 
 99 :         $words preg_split('/[\W]+/'$comment);
100 :         foreach ( $words as $word )
101 :             $word_lengths[] = strlen($word);
102 :         $s_word_lengths array_unique($word_lengths);
103 :         sort($s_word_lengths);
104 :         if ( $s_word_lengths[0] == )
105 :             array_shift($s_word_lengths);
106 : 
107 :         if ( ! empty($min_word_length) )
108 :             if ( $min_word_length $s_word_lengths[0] )
109 :                 $pass false;
110 : 
111 :         if ( $pass and ! empty($max_word_length) )
112 :             if ( $max_word_length $s_word_lengths[count($s_word_lengths) - 1] )
113 :                 $pass false;
114 : 
115 :         if ( $pass and ! empty($not_word_length) )
116 :             if ( in_array($not_word_length$s_word_lengths) )
117 :                 $pass false;
118 : 
119 :         if ( $pass and ! empty($anagram) ) {
120 :             $anagram strtolower(preg_replace('/[^a-z]/i'''$anagram));
121 :             $letters str_split($anagram);
122 :             sort($letters);
123 :             $count count($letters);
124 :             $words preg_replace('/[^a-z]/i'''$words);
125 :             $match false;
126 :             while ( ! $match and count($words) ) {
127 :                 $test_string $words[0];
128 :                 $c_match strlen($test_string) == $count;
129 :                 $i 1;
130 :                 while ( ! $c_match and $i count($words) ) {
131 :                     $test_string .= $words[$i];
132 :                     $c_match strlen($test_string) == $count;
133 :                     if ( strlen($test_string) > $count )
134 :                         $i count($words);
135 :                     $i++;
136 :                 }
137 :                 if ( $c_match ) {
138 :                     $test_string strtolower($test_string);
139 :                     $test_array str_split($test_string);
140 :                     sort($test_array);
141 :                     $match = ( $letters == $test_array and $anagram != $test_string );
142 :                 }
143 :                 array_shift($words);
144 :             }
145 :             $pass $match;
146 :         }
147 :     }
148 : 
149 :     return parse(EvalElse($thing$pass));
150 : }
151 : 
152 :   //---------------------------------------------------------------------//
153 :  //                         MLP Pack definitions                        //
154 : //---------------------------------------------------------------------//
155 : 
156 : define('SOO_WORDFEST_PREFIX''soo_fest');
157 : global $soo_wordfest_strings;
158 : $soo_wordfest_strings = array(
159 :     'must_contain'      => 'contain the {word|phrase} {x}',
160 :     'must_begin'        => 'begin with the {word|phrase} {x}',
161 :     'must_end'          => 'end with the {word|phrase} {x}',
162 :     'word_count'        => 'be exactly {x} words long',
163 :     'max_word_count'    => 'not exceed {x} words',
164 :     'min_word_length'   => 'only use words that are at least {x} letters long',
165 :     'max_word_length'   => 'only use words that are not more than {x} letters long',
166 :     'not_word_length'   => 'avoid using {x}-letter words',
167 :     'anagram'           => 'contain an anagram of {x}',
168 :     'lquo'              => '“',
169 :     'rquo'              => '”',
170 : );
171 : 
172 : register_callback('soo_wordfest_enumerate_strings''l10n.enumerate_strings');
173 : 
174 : function soo_wordfest_enumerate_strings$event$step ''$pre ) {
175 :     global $soo_wordfest_strings;
176 :     $r = array(
177 :         'owner'     => 'soo_wordfest',
178 :         'prefix'    => SOO_WORDFEST_PREFIX,
179 :         'lang'      => 'en-us',
180 :         'event'     => 'public',
181 :         'strings'   => $soo_wordfest_strings,
182 :                 );
183 :     return $r;
184 : }
185 : 
186 : function soo_wordfest_gTxt$what $args = array() ) {
187 :     global $textarray;
188 :     global $soo_wordfest_strings;
189 : 
190 :     $key SOO_WORDFEST_PREFIX '-' $what;
191 :     $key strtolower($key);
192 : 
193 :     if(isset($textarray[$key]))
194 :         $str $textarray[$key];
195 : 
196 :     else {
197 :         $key strtolower($what);
198 : 
199 :         if( isset( $soo_wordfest_strings[$key] ) )
200 :             $str $soo_wordfest_strings[$key];
201 :         else
202 :             $str $what;
203 :     }
204 : 
205 :     if( !empty($args) )
206 :         $str strtr$str $args );
207 : 
208 :     return $str;
209 : }