Changeset 5076
- Timestamp:
- 02/11/2006 02:55:57 AM (21 years ago)
- File:
-
- 1 edited
-
cricket-moods/branches/2.x/cricket-moods.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cricket-moods/branches/2.x/cricket-moods.php
r4191 r5076 10 10 11 11 /** 12 Copyright (c) 200 5Keith Constable12 Copyright (c) 2006 Keith Constable 13 13 14 14 Permission is hereby granted, free of charge, to any person obtaining a copy of … … 34 34 ************************************************** !! **/ 35 35 36 define('CM_VERSION', '2.1'); 36 37 // The name of the option key that contains the available moods. 37 38 define('CM_OPTION_MOODS', 'cricketmoods_moods'); … … 43 44 define('CM_OPTION_AUTOPRINT', 'cricketmoods_autoprint'); 44 45 45 /* Removing presentation options. I need to think this through. 46 define('CM_OPTION_BEFORE', 'cricketmoods_before'); 47 define('CM_OPTION_SEPARATOR', 'cricketmoods_separator'); 48 define('CM_OPTION_AFTER', 'cricketmoods_after'); 49 */ 46 define('CM_OPTION_VERSION', 'cricketmoods_version'); 50 47 51 48 define('CM_IMAGE_DIR', get_option(CM_OPTION_DIR) ); 52 49 define('CM_META_KEY', 'mood'); 53 50 54 55 // These are used for writing various debug information to a file. They are56 // currently unused. So don't bother uncommenting them.57 //define('CM_DEBUG_FILE', $_SERVER['DOCUMENT_ROOT'].'/wp-content/plugins/cricket-moods/debug.txt');58 //$cm_debug = fopen(CM_DEBUG_FILE, 'a');59 51 60 52 … … 72 64 called from within The Loop. 73 65 */ 74 function cm_the_moods($separator=' & ', $before = null, $after = null ) {75 global $ wpdb;66 function cm_the_moods($separator=' & ', $before = null, $after = null, $return = false) { 67 global $post_ID, $wpdb; 76 68 77 69 // Get the moods for the current post. 78 $post_moods = get_post_ custom_values(CM_META_KEY);70 $post_moods = get_post_meta($post_ID, CM_META_KEY); 79 71 80 72 if( !empty($post_moods) ) { … … 84 76 $mood_list = cm_process_moods(); 85 77 78 $output = ''; 79 86 80 foreach( $post_moods as $i => $mood_id ) { 87 $mood_name = wptexturize($mood_list[$mood_id]['mood_name']);88 81 if( $i == 0 ) { 89 echo $before; 90 } 91 92 // Only print the img tag if the mood has an associated image. 93 if( !empty( $mood_list[$mood_id]['mood_image'] ) ) { 94 echo '<img src="http://'. $_SERVER['HTTP_HOST'] . CM_IMAGE_DIR . wptexturize($mood_list[$mood_id]['mood_image']) .'" alt="'. $mood_name .' emoticon" /> '; 95 } 96 97 echo $mood_name; 82 $output .= $before; 83 } 84 85 // Failsafe in case that mood ID doesn't actually exist. 86 if( !empty($mood_list[$mood_id]) ) { 87 $mood_name = wptexturize($mood_list[$mood_id]['mood_name']); 88 89 // Only print the img tag if the mood has an associated image. 90 if( !empty( $mood_list[$mood_id]['mood_image'] ) ) { 91 $output .= '<img src="'. CM_IMAGE_DIR . wptexturize($mood_list[$mood_id]['mood_image']) .'" alt="'. $mood_name .' emoticon" /> '; 92 } 93 94 $output .= $mood_name; 95 96 if( $i != $count ) { 97 $output .= $separator; 98 } 99 } 98 100 99 101 // Determine if this is the last mood. 100 if( $i != $count ) { 101 echo $separator; 102 } else { 103 echo $after; 104 } 102 if( $i == $count ) { 103 $output .= $after; 104 } 105 } 106 107 if ($return) { 108 return $output; 109 } else { 110 echo $output; 105 111 } 106 112 } … … 203 209 204 210 // If no $mood, pull from $_POST. 205 if( !$moods) {211 if( !isset($moods) ) { 206 212 $moods = cm_get_posted_moods(); 207 213 } … … 240 246 } // cm_update_moods 241 247 242 243 // Update the moods whenever a post is saved or edited. 244 add_action('save_post', 'cm_update_moods'); 245 add_action('edit_post', 'cm_update_moods'); 246 247 248 249 /** 250 cm_update_option 251 252 A slight modification of WP's update_option(). 253 Sometimes, you *don't* want to trim. 254 */ 255 /* Removing presentation options. 256 function cm_update_option($option_name, $newvalue) { 257 global $wpdb, $cache_settings; 258 if ( is_array($newvalue) || is_object($newvalue) ) 259 $newvalue = serialize($newvalue); 260 261 // $newvalue = trim($newvalue); // I can't think of any situation we wouldn't want to trim 262 // kccricket says: Good for you, I can. 263 264 // If the new and old values are the same, no need to update. 265 if ($newvalue == get_option($option_name)) { 266 return true; 267 } 268 269 // If it's not there add it 270 if ( !$wpdb->get_var("SELECT option_name FROM $wpdb->options WHERE option_name = '$option_name'") ) 271 add_option($option_name); 272 273 $newvalue = $wpdb->escape($newvalue); 274 $wpdb->query("UPDATE $wpdb->options SET option_value = '$newvalue' WHERE option_name = '$option_name'"); 275 $cache_settings = get_alloptions(); // Re cache settings 276 return true; 277 } 278 */ 248 add_action('save_post', 'cm_update_post_moods'); 249 add_action('edit_post', 'cm_update_post_moods'); 279 250 280 251 … … 335 306 336 307 /** 308 cm_mood_sort 309 310 **/ 311 function cm_mood_sort( $row1,$row2 ) { 312 if ( $first = strnatcasecmp($row1['mood_name'], $row2['mood_name']) ) { 313 return $first; 314 } else { 315 return strnatcasecmp($row1['mood_image'], $row2['mood_image']); 316 } 317 } 318 319 320 321 /** 337 322 cm_auto_moods 338 323 339 324 Used if the AutoPrint option is enabled. 340 325 */ 341 function cm_auto_moods($time) { 342 echo $time; 343 cm_the_moods(' & ', '<br/>Current Mood: '); 326 function cm_auto_moods($content) { 327 return cm_the_moods(' & ', '<p class="moods">Current Mood: ', '</p>', true) . $content; 344 328 } 345 329 … … 348 332 // is_admin() didn't work here... 349 333 if ( strpos($_SERVER['PHP_SELF'], 'wp-admin/') === false && get_option(CM_OPTION_AUTOPRINT) == "on" ) { 350 add_filter('the_ time', 'cm_auto_moods');334 add_filter('the_content', 'cm_auto_moods'); 351 335 } 352 336 … … 472 456 473 457 <?php 458 459 $mood_list = cm_process_moods(); 460 474 461 // If the user pushed the update button. 475 462 if ( isset($_POST['cm_options_update']) ) { … … 496 483 */ 497 484 498 // Get the pre-modified list of moods.499 $mood_list = cm_process_moods();500 501 485 // Parse the $_POST for the CM options we want. 502 486 foreach ($_POST as $name => $value) { … … 531 515 532 516 // Finally, update the mood list. 517 uasort($mood_list, 'cm_mood_sort'); 533 518 update_option(CM_OPTION_MOODS, $mood_list); 534 519 … … 549 534 Directory containing the images associated with the moods. Should be relative to the root of your domain.</li> 550 535 <li><input type="checkbox" id="cm_auto_print" name="cm_auto_print" <?php if ( get_option(CM_OPTION_AUTOPRINT) == "on" ) echo 'checked="true"' ?>/> <label for="cm_auto_print">Automatically print moods</label><br/> 551 Causes Cricket Moods to automatically display moods directly after each post's time without the need to modify the active template. Works best with the default WordPress theme. Uncheckif you've manually added <code>cm_the_moods()</code> to your template(s).</li>536 Causes Cricket Moods to automatically display moods just before each post's content without the need to modify the active template. Deselect if you've manually added <code>cm_the_moods()</code> to your template(s).</li> 552 537 <ul> 553 538 </fieldset> 554 <?php /* Removing presentation options. 555 <fieldset class="options"> 556 <legend>Presentation</legend> 557 <strong>Leave these options blank to use the default values.</strong> 558 <ul> 559 <li><label for="cm_before">Text to place before the first mood:</label><br/> 560 <input type="text" id="cm_before" name="cm_before" value="<?php echo htmlspecialchars(get_option(CM_OPTION_BEFORE) ) ?>"/><br/> 561 Default: <code>'Current Mood: '</code></li> 562 <li><label for="cm_separator">Text to place in between multiple moods:</label><br/> 563 <input type="text" id="cm_separator" name="cm_separator" value="<?php echo htmlspecialchars(get_option(CM_OPTION_SEPARATOR) ) ?>"/><br/> 564 Will only display if the current post has two or more moods.<br/> 565 Default: <code>' &amp; '</code></li> 566 <li><label for="cm_after">Text to place after the last mood:</label><br/> 567 <input type="text" id="cm_after" name="cm_after" value="<?php echo htmlspecialchars(get_option(CM_OPTION_AFTER) ) ?>"/><br/> 568 Default: <em>(blank)</em></li> 569 </ul> 570 </fieldset> 571 */ ?> 539 572 540 <fieldset class="options"> 573 541 <legend>Moods</legend> … … 581 549 <?php 582 550 // List the existing moods. 583 foreach ( cm_process_moods() as $id => $mood ) { 551 ksort($mood_list); 552 foreach ( $mood_list as $id => $mood ) { 584 553 ?> 585 554 <tr<?php if ($alt == true) { echo ' class="alternate"'; $alt = false; } else { $alt = true; } ?> valign="middle"> … … 683 652 } 684 653 654 if ( get_option(CM_OPTION_VERSION) != CM_VERSION ) { 655 update_option(CM_OPTION_VERSION, CM_VERSION); 656 } 685 657 } 686 658
Note:
See TracChangeset
for help on using the changeset viewer.