Changeset 1410982
- Timestamp:
- 05/05/2016 12:43:58 PM (10 years ago)
- Location:
- upcast/trunk
- Files:
-
- 3 edited
-
settings.php (modified) (3 diffs)
-
style.css (modified) (1 diff)
-
upcast.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
upcast/trunk/settings.php
r1175654 r1410982 1 1 <?php 2 define('UPCAST_FIELD_NAMES','thumbnail,date,title,author,subject,category,description,link,url,image_link,image_url,thumbnail_url,content,duration,size ');2 define('UPCAST_FIELD_NAMES','thumbnail,date,title,author,subject,category,description,link,url,image_link,image_url,thumbnail_url,content,duration,size,search'); 3 3 define('UPCAST_HIDE_FIELD_NAMES','url,image_link,image_url,thumbnail_url'); 4 4 define('UPCAST_FILTER_FIELD_NAMES','author,subject,category'); … … 200 200 201 201 function preg_match_simple($pattern, $subject) { 202 return preg_match('/'.$pattern.'/ ', $subject);202 return preg_match('/'.$pattern.'/i', $subject); 203 203 } 204 204 … … 293 293 </div> 294 294 <div class="upcast-settings-header-text"> 295 <h2>Shortcode Settings</h2> <br>295 <h2>Shortcode Settings</h2> 296 296 <p>Add a podcast feed to any post or page by including the text <code>[upcast]</code></p> 297 <p>Include a search bar with the search attribute: <code>[upcast search="true"]</code></p> 298 <p>Display the feed's main image or thumbnail by including <code>[upcast_image]</code></p> 297 299 </div> 298 300 </div> -
upcast/trunk/style.css
r1175653 r1410982 2 2 3 3 input[type="text"].upcast { width: 150px } 4 input[type="text"].upcast.upcast_search { 5 width : 100px; 6 padding : 2px; 7 background : white; 8 } 9 select.upcast.upcast_search { 10 padding : 2px; 11 } 12 input[type="submit"].upcast.upcast_search { 13 border-radius: 5px; 14 display: inline-block; 15 padding: 3px; 16 text-decoration: none; 17 height: inherit; 18 text-transform: none; 19 margin: 0px; 20 background: none; 21 background-color: #CCCCCC; 22 border: inherit; 23 box-shadow: none; 24 color: #F7F7F7; 25 text-shadow: 1px 1px 1px #000000; 26 } 27 .upcast.upcast_box { 28 float: left; 29 text-align: center; 30 margin: 0px 15px 15px 0px; 31 } 32 .upcast.upcast_box img { 33 border: 5px #CCCCCC solid; 34 } 35 .upcast.upcast_box h2 > a:hover { 36 color: #333333; 37 } 38 .upcast.upcast_box img:hover { 39 border: 5px #333333 solid; 40 } 41 4 42 textarea.upcast { width: 100% } 5 43 input[type="text"].upcast-template { width : 300px } -
upcast/trunk/upcast.php
r1204863 r1410982 44 44 function upcast_rss($atts, $content = '') { 45 45 return upcast_feed($atts, $content); 46 } 47 48 function upcast_group($atts, $content = '') { 49 return upcast_feed($atts, $content, 'group'); 46 50 } 47 51 … … 128 132 $default_columns = ''; 129 133 $default_column_names = ''; 134 130 135 foreach (explode(',', UPCAST_FIELD_NAMES) as $field) { 131 136 if (isset($options['column_'.$field]) && $options['column_'.$field] == 'on') { … … 142 147 $default_column_names = implode(',', array_map('ucwords', explode(',', UPCAST_DEFAULT_COLUMNS))); 143 148 } 144 149 150 if (isset($_GET['group'])) 151 $options['group'] = $_GET['group']; 152 153 $filters = array('title','desc','description','pubdate','date','category','subject','author'); 154 if (isset($_GET['search'])) { 155 $options['search'] = true; 156 } 157 $search = isset($options['search']) && $options['search']; 158 foreach ($filters as $f) { 159 if (isset($_GET[$f])) { 160 $options['filter_'.$f] = $_GET[$f]; 161 $search = false; 162 //error_log('option '.$f.' = '.$options[$f]); 163 } 164 } 165 145 166 extract(shortcode_atts(Array( 146 167 'feed' => isset($options['rss_link']) ? $options['rss_link'] : false, … … 155 176 'headers' => $default_column_names, 156 177 'table' => true, 157 'template' => isset($options['template_row']) ? $options['template_row'] : '', 178 'template' => isset($options['template_row']) ? $options['template_row'] : '', 179 'search' => isset($options['search']) ? $options['search'] : false, 180 'group' => isset($options['filter_group']) ? $options['filter_group'] : false, 158 181 'title' => isset($options['filter_title']) ? $options['filter_title'] : false, 159 'description' => isset($options['filter_desc']) ? $options['filter_desc'] : false,182 'description' => isset($options['filter_desc']) ? $options['filter_desc'] : (isset($options['filter_description']) ? $options['filter_description'] : false), 160 183 'pubdate' => isset($options['filter_pubdate']) ? $options['filter_pubdate'] : false, 161 184 'date' => isset($options['filter_date']) ? $options['filter_date'] : false, … … 186 209 $display_columns = explode(',',$columns); 187 210 $display_column_headers = explode(',',$headers); 211 //error_log('display_columns='.count($display_columns)); 212 //error_log('display_column_headers='.count($display_column_headers)); 213 if ($search) { 214 $search_columns = array(); 215 $search_column_headers = array(); 216 for ($c = 0; $c < count($display_columns); $c++) { 217 if (in_array($display_columns[$c], $filters)) { 218 $search_columns[] = $display_columns[$c]; 219 $search_column_headers[] = $display_column_headers[$c]; 220 } 221 } 222 $search_columns[] = 'search'; 223 $search_column_headers[] = ' '; 224 } 225 //error_log('search_columns='.count($search_columns)); 188 226 189 227 # If no feed, return with nothing … … 219 257 //error_log('rss_items='.count($rss_items)); 220 258 $rsscount = 0; 221 259 260 if ($search) 261 $search_content = '<td>['.implode(']</td><td>[',$search_columns).']</td>'; 262 263 $custom = false; 222 264 if ($content == '') { 223 265 if ($template) { 224 266 $content = $template; 267 $custom = true; 225 268 } else { 226 269 $content = '<td>['.implode(']</td><td>[',$display_columns).']</td>'; 227 270 // Substitute any individual column templates 228 foreach ($display_columns as $field) 229 if (isset($options['template_'.$field]) && $options['template_'.$field]) 271 foreach ($display_columns as $field) { 272 if (isset($options['template_'.$field]) && $options['template_'.$field]) { 230 273 $content = str_replace('['.$field.']', $options['template_'.$field], $content); 231 } 274 } 275 } 276 } 277 } else { 278 $custom = true; 232 279 } 233 280 … … 235 282 $matches = array(); 236 283 $thead = ''; 284 $table = !$custom; 237 285 if (preg_match('/\s*<table>\s*(<thead>.*<\/thead>)?\s*(<tbody>)?\s*(<tr>)?\s*(.*?)\s*(<\/tr>)?\s*(<\/tbody>)?\s*<\/table>\s*/mis', $content, $matches)) { 238 286 //error_log('matches='.print_r($matches, true)); … … 241 289 } 242 290 $content = $matches[4]; 243 } 291 $table = true; 292 } 293 294 if ($search) { 295 $output .= '<form name="upcast_search" action="">'; 296 } 244 297 245 298 if ($table) 246 299 $content = '<tr>'.$content.'</tr>'; 247 300 301 $search_content = '<tr>'.$search_content.'</tr>'; 302 248 303 // Display the headers 304 $table_head = ''; 249 305 if ($table) { 250 $ output.= '<table>';306 $table_head .= '<table>'; 251 307 if ($thead) { 252 $ output.= $thead;308 $table_head .= $thead; 253 309 } elseif ($header) { 254 $ output.= '<thead><tr>';310 $table_head .= '<thead><tr>'; 255 311 foreach ($display_column_headers as $header) { 256 $output .= '<th>'.$header.'</th>'; 257 } 258 $output .= '</tr></thead>'; 259 } 260 $output .= '<tbody>'; 261 } 312 $table_head .= '<th>'.$header.'</th>'; 313 } 314 $table_head .= '</tr></thead>'; 315 } 316 $table_head .= '<tbody>'; 317 } 318 if ($search) { 319 $search_head = '<table><thead><tr>'; 320 foreach ($search_column_headers as $header) { 321 $search_head .= '<th>'.$header.'</th>'; 322 } 323 $search_head .= '</tr></thead><tbody>'; 324 325 } 262 326 263 327 if ($offset > 0) { … … 267 331 // Pre-find all the substitutions and locations in the content to be repeated for each row 268 332 $matches = array(); 333 $search_matches = array(); 269 334 preg_match_all('/[\[{]('.str_replace(',','|',UPCAST_FIELD_NAMES).')[\]}]/i', $content, $matches, PREG_OFFSET_CAPTURE); 335 if ($search) { 336 //error_log('search_content='.$search_content); 337 preg_match_all('/[\[{]('.str_replace(',','|',UPCAST_FIELD_NAMES).')[\]}]/i', $search_content, $search_matches, PREG_OFFSET_CAPTURE); 338 //error_log("search_matches[1]=".print_r($search_matches[1],true)); 339 } 270 340 // error_log('content='.print_r($content, true)); 271 341 // error_log(print_r($matches, true)); 342 $searches = array(); 343 $table_body = ''; 272 344 foreach ($rss_items as $item) 273 345 { … … 298 370 if ($selected && $title) $selected = preg_match_simple($title,$item->get_title()); 299 371 if ($selected && $subject && is_array($item_subject) && count($item_subject)) $selected = preg_match_simple($subject,$item_subject[0]['data']); 300 if ($dates) { 301 if ($selected && $pubdate) $selected = preg_match_simple($pubdate,$item->get_gmdate($dates)); 302 if ($selected && $date) $selected = preg_match_simple($date,$item->get_local_date($dates)); 303 } 304 else { 305 if ($selected && $pubdate) $selected = preg_match_simple($pubdate,$item->get_gmdate()); 306 if ($selected && $date) $selected = preg_match_simple($date,$item->get_local_date()); 307 } 308 if ($selected && $author && $item_author) $selected = preg_match_simple($author,$item_author->get_name()); 372 if ($selected && $pubdate) $selected = preg_match_simple($pubdate,$item->get_date('Y')); 373 if ($selected && $date) $selected = preg_match_simple($date,$item->get_local_date('%G')); 374 if ($selected && $author && $item_author) { 375 $selected = preg_match_simple($author,$item_author->get_name()); 376 } 309 377 310 378 if ($selected) … … 316 384 if (isset($matches[1])) { 317 385 $row = $content; 386 $search_val = ''; 318 387 // work through in reverse so substitutions do not affect earlier offsets 319 388 for ($f = count($matches[1]) - 1; $f >= 0; $f--) { 320 389 $text = ' '; 321 switch ($matches[1][$f][0]) { 390 $col = $matches[1][$f][0]; 391 $search_val = ''; 392 switch ($col) { 322 393 case 'count': 323 394 $text = $rsscount; 324 395 break; 325 396 case 'category': 326 if ($item_category) $text = $item_category->get_label(); 397 if ($item_category) { 398 $text = $item_category->get_label(); 399 $search_val = $text; 400 } 327 401 break; 328 402 case 'subject': 329 if (is_array($item_subject) && count($item_subject)) $text = $item_subject[0]['data']; 403 if (is_array($item_subject) && count($item_subject)) { 404 $text = $item_subject[0]['data']; 405 $search_val = $text; 406 } 330 407 break; 331 408 case 'description': 332 $text = $item->get_description(); 409 $text = $item->get_description(); 333 410 break; 334 411 case 'title': … … 338 415 try { 339 416 $t = date_create_from_format('Y-m-d G:i:s', $item->get_local_date('%G-%m-%d %T')); 340 if ($t !== FALSE) 417 if ($t !== FALSE) { 341 418 $text = str_replace(' ', ' ', $t->format($dates)); 419 $search_val = $t->format('Y'); 420 //error_log("search_val=".$search_val); 421 } 342 422 } catch (Exception $e) { 343 423 error_log($e->getMessage()); … … 348 428 try { 349 429 $t = date_create_from_format('Y-m-d G:i:s', $item->get_date('Y-m-d G:i:s')); 350 if ($t !== FALSE) 430 if ($t !== FALSE) { 351 431 $text = str_replace(' ', ' ', $t->format($dates)); 432 $search_val = $t->format('Y'); 433 //error_log("search_val=".$search_val); 434 } 352 435 } catch (Exception $e) { 353 436 error_log($e->getMessage()); … … 356 439 break; 357 440 case 'author': 358 if ($item_author && $item_author->get_name() != $rss_author_name) $text = $item_author->get_name(); 441 if ($item_author && $item_author->get_name() != $rss_author_name) { 442 $text = $item_author->get_name(); 443 $search_val = $text; 444 } 359 445 break; 360 446 case 'url': … … 414 500 break; 415 501 } 416 $row = substr_replace($row, $text, $matches[1][$f][1] - 1, strlen($matches[1][$f][0]) + 2); 502 if ($search) { 503 if ($search_val) { 504 if (!array_key_exists($col, $searches)) 505 $searches[$col] = array(''); 506 if (!in_array($search_val, $searches[$col])) 507 $searches[$col][] = $search_val; 508 } 509 } 510 //error_log('subbing "'.$col.'" as "'.$text.'"'); 511 $row = substr_replace($row, $text, $matches[1][$f][1] - 1, strlen($col) + 2); 417 512 } 418 $ output.= $row;513 $table_body .= $row; 419 514 } else { 420 $output .= $content; 421 } 422 } 423 } 515 $table_body .= $content; 516 } 517 } 518 } 519 520 if ($search) { 521 $output .= $search_head; 522 //error_log('search='.print_r($searches,true)); 523 if (isset($search_matches[1])) { 524 $row = $search_content; 525 for ($f = count($search_matches[1]) - 1; $f >= 0; $f--) { 526 $col = $search_matches[1][$f][0]; 527 //error_log('col='.$col); 528 if (in_array($col, $filters)) { 529 if (array_key_exists($col, $searches)) { 530 sort($searches[$col], SORT_FLAG_CASE); 531 $text = '<select class="upcast upcast_search" name="'.$col.'">'; 532 foreach ($searches[$col] as $opt) { 533 $text .= '<option value="'.$opt.'" '.((isset($_GET[$col]) && $_GET[$col] == $opt) ? 'SELECTED' : '').'>'.htmlspecialchars($opt).'</option>'; 534 } 535 $text .= '</select>'; 536 } else { 537 $text = '<input name="'.$col.'" placeholder="search text" class="upcast upcast_search" type="text" '.((isset($_GET[$col]) && $_GET[$col]) ? 'VALUE='.$_GET[$col] : '').'>'; 538 } 539 $row = substr_replace($row, $text, $search_matches[1][$f][1] - 1, strlen($col) + 2); 540 } elseif ($col == 'search') { 541 $row = substr_replace($row, '<input class="upcast upcast_search" name="search" type="submit" value="Go">', $search_matches[1][$f][1] - 1, strlen($col) + 2); 542 } else { 543 $text = ' '; 544 } 545 } 546 $output .= $row; 547 } else { 548 $output .= $content; 549 } 550 $output .= '</tbody></table></form>'; 551 } elseif ($table && !$rsscount) { 552 $table_body .= '<td span="'.count($display_column_headers).'">No items found</td>'; 553 } 554 555 if ($table) 556 $output .= $table_head; 557 558 $output .= $table_body; 424 559 425 560 if ($table) … … 441 576 add_shortcode('upcast_image', 'upcast_image'); 442 577 add_shortcode('upcast_thumbnail', 'upcast_thumbnail'); 578 add_shortcode('upcast_group', 'upcast_group'); 443 579 function upcast_filter($content) { 444 580 $block = join("|",array("upcast","upcast_rss")); … … 448 584 } 449 585 add_filter("the_content", "upcast_filter"); 450 // register Foo_Widget widget 451 //wp_register_style('upcastStylesheet', plugins_url('style.css', __FILE__) ); 452 //function enqueue_upcast_styles() { 453 // wp_enqueue_style('upcastStylesheet'); 454 //} 586 455 587 function register_upcast_widget() { 456 588 register_widget( 'UpCast_Widget' ); … … 459 591 //add_action( 'wp_enqueue_styles', 'enqueue_upcast_styles'); 460 592 593 //wp_register_style('upcastStylesheet', plugins_url('style.css', __FILE__) ); 594 461 595 ?>
Note: See TracChangeset
for help on using the changeset viewer.