| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | |
|---|
| 4 | =>> Visit the plugin's homepage for more information and latest updates <<= |
|---|
| 5 | http://www.coffee2code.com/wp-plugins/ |
|---|
| 6 | |
|---|
| 7 | 2. Optional: Add filters for 'the_meta' to filter custom field data (see the end of the file for |
|---|
| 8 | commented out samples you may wish to include). *NEW*: Add per-meta filters by hooking 'the_meta_$field' |
|---|
| 9 | |
|---|
| 10 | 4. Give a post a custom field with a value. |
|---|
| 11 | |
|---|
| 12 | 5. Use the function freshout somewhere inside "the loop" and/or use the function c2c_get_recent_custom |
|---|
| 13 | outside "the loop"; use 'echo' to display the contents of the custom field; or use as an argument to |
|---|
| 14 | another function |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | Function arguments: |
|---|
| 18 | $field : This is the name of the custom field you wish to display |
|---|
| 19 | $before : The text to display before all field value(s) |
|---|
| 20 | $after : The text to display after all field value(s) |
|---|
| 21 | $none : The text to display in place of the field value should no field value exists; if defined as '' |
|---|
| 22 | and no field value exists, then nothing (including no $before and $after) gets displayed |
|---|
| 23 | $between : The text to display between multiple occurrences of the custom field; if defined as '', then |
|---|
| 24 | only the first instance will be used |
|---|
| 25 | $before_last: The text to display between the next-to-last and last items listed when multiple occurrences of |
|---|
| 26 | the custom field; $between MUST be set to something other than '' for this to take effect |
|---|
| 27 | |
|---|
| 28 | Additional arguments used by c2c_get_recent_custom(): |
|---|
| 29 | $limit : The limit to the number of |
|---|
| 30 | $unique : Boolean ('true' or 'false') to indicate if each custom field value in the results should be unique |
|---|
| 31 | $order : Indicates if the results should be sorted in chronological order ('ASC') (the earliest custom field value |
|---|
| 32 | listed first), or reverse chronological order ('DESC') (the most recent custom field value listed first) |
|---|
| 33 | $include_static : Boolean ('true' or 'false') to indicate if static posts (i.e. "pages) should be included when |
|---|
| 34 | retrieving recent custom values; default is 'true' |
|---|
| 35 | $show_pass_post : Boolean ('true' or 'false') to indicate if password protected posts should be included when |
|---|
| 36 | retrieving recent custom values; default is 'false' |
|---|
| 37 | |
|---|
| 38 | Examples: (visit the plugin's homepage for more examples) |
|---|
| 39 | |
|---|
| 40 | <?php echo freshout('mymood'); ?> // with this simple invocation, you can echo the value of any metadata field |
|---|
| 41 | |
|---|
| 42 | <?php echo freshout('mymood', 'Today's moods: ', '', ', '); ?> |
|---|
| 43 | |
|---|
| 44 | <?php echo c2c_get_recent_custom('mymood', 'Most recent mood: '); ?> |
|---|
| 45 | |
|---|
| 46 | <?php echo freshout('mymood', '(Current mood: ', ')', ''); ?> |
|---|
| 47 | |
|---|
| 48 | <?php echo freshout('mylisten', 'Listening to : ', '', 'No one at the moment.'); ?> |
|---|
| 49 | |
|---|
| 50 | <?php echo freshout('myread', 'I\'ve been reading ', ', if you must know.', 'nothing'); ?> |
|---|
| 51 | |
|---|
| 52 | <?php echo freshout('todays_link', '<a class="tlink" href="', '" >Today\'s Link</a>'); ?> |
|---|
| 53 | |
|---|
| 54 | <?php echo freshout('related_offsite_links', |
|---|
| 55 | 'Here\'s a list of offsite links related to this post:<ol><li><a href="', |
|---|
| 56 | '">Related</a></li></ol>', |
|---|
| 57 | '', |
|---|
| 58 | '">Related</a></li><li><a href="'); ?> |
|---|
| 59 | |
|---|
| 60 | <?php echo freshout('more_pictures', |
|---|
| 61 | 'Pictures I\'ve taken today:<br /><div class="more_pictures"><img alt="[photo]" src="', |
|---|
| 62 | '" /></div>', |
|---|
| 63 | '', |
|---|
| 64 | '" /> : <img alt="[photo]" src="'); ?> |
|---|
| 65 | |
|---|
| 66 | Custom 'more...' link text, by replacing <?php the_content(); ?> in index.php with this: |
|---|
| 67 | <?php the_content(freshout('more', '<span class="morelink">', '</span>', '(more...)')); ?> |
|---|
| 68 | |
|---|
| 69 | */ |
|---|
| 70 | |
|---|
| 71 | /* |
|---|
| 72 | Copyright (c) 2004-2005 by Scott Reilly (aka coffee2code) |
|---|
| 73 | |
|---|
| 74 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation |
|---|
| 75 | files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, |
|---|
| 76 | modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
|---|
| 77 | Software is furnished to do so, subject to the following conditions: |
|---|
| 78 | |
|---|
| 79 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
|---|
| 80 | |
|---|
| 81 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|---|
| 82 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
|---|
| 83 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR |
|---|
| 84 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|---|
| 85 | */ |
|---|
| 86 | |
|---|
| 87 | if (!isset($wpdb->posts)) { // For WP 1.2 compatibility |
|---|
| 88 | global $tableposts, $tablepostmeta; |
|---|
| 89 | $wpdb->posts = $tableposts; |
|---|
| 90 | $wpdb->postmeta = $tablepostmeta; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | // Get Variable |
|---|
| 94 | function get ($field, $before='', $after='', $none='', $between='', $before_last='') { |
|---|
| 95 | return c2c__format_custom($field, (array)get_post_custom_values($field), $before, $after, $none, $between, $before_last); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | // Get Image. |
|---|
| 99 | function get_image ($field, $before='', $after='', $none='', $between='', $before_last='') { |
|---|
| 100 | global $wpdb; |
|---|
| 101 | $fieldValue = c2c__format_custom($field, (array)get_post_custom_values($field), $before, $after, $none, $between, $before_last); |
|---|
| 102 | $cssClass = $wpdb->get_results("SELECT CSS FROM wp_rc_cwp_panel_custom_field WHERE name='".$field."'"); |
|---|
| 103 | $finalString = stripslashes(trim("\<img src=\'".$fieldValue."\' class=\"".$cssClass[0]->CSS."\" \/\>")); |
|---|
| 104 | return $finalString; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | // Get Audio. |
|---|
| 108 | function get_audio ($field, $before='', $after='', $none='', $between='', $before_last='') { |
|---|
| 109 | $fieldValue = c2c__format_custom($field, (array)get_post_custom_values($field), $before, $after, $none, $between, $before_last); |
|---|
| 110 | $finalString = stripslashes(trim("\<div style=\'padding-top:3px;\'\>\<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' codebase='\http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\' width=\'95%\' height=\'20\' wmode=\'transparent\' \>\<param name=\'movie\' value=\'http://www.freshoutmedia.com/singlemp3player.swf?file=".$fieldValue."\' wmode=\'transparent\' /\>\<param name=\'quality\' value=\'high\' wmode=\'transparent\' /\>\<embed src=\'http://www.freshoutmedia.com/singlemp3player.swf?file=".$fieldValue."' width=\'50\%\' height=\'20\' quality=\'high\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\' type=\'application/x-shockwave-flash\' wmode=\'transparent\' \>\</embed\>\</object\>\</div\>")); |
|---|
| 111 | return $finalString; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | // This works outside "the loop" |
|---|
| 115 | function c2c_get_recent_custom ($field, $before='', $after='', $none='', $between=', ', $before_last='', $limit=1, $unique=false, $order='DESC', $include_static=true, $show_pass_post=false) { |
|---|
| 116 | global $wpdb; |
|---|
| 117 | if (empty($between)) $limit = 1; |
|---|
| 118 | if ($order != 'ASC') $order = 'DESC'; |
|---|
| 119 | $now = current_time('mysql'); |
|---|
| 120 | |
|---|
| 121 | $sql = "SELECT "; |
|---|
| 122 | if ($unique) $sql .= "DISTINCT "; |
|---|
| 123 | $sql .= "meta_value FROM $wpdb->posts AS posts, $wpdb->postmeta AS postmeta "; |
|---|
| 124 | $sql .= "WHERE posts.ID = postmeta.post_id AND postmeta.meta_key = '$field' "; |
|---|
| 125 | $sql .= "AND ( posts.post_status = 'publish' "; |
|---|
| 126 | if ($include_static) $sql .= " OR posts.post_status = 'static' "; |
|---|
| 127 | $sql .= " ) AND posts.post_date < '$now' "; |
|---|
| 128 | if (!$show_pass_post) $sql .= "AND posts.post_password = '' "; |
|---|
| 129 | $sql .= "AND postmeta.meta_value != '' "; |
|---|
| 130 | $sql .= "ORDER BY posts.post_date $order LIMIT $limit"; |
|---|
| 131 | $results = array(); $values = array(); |
|---|
| 132 | $results = $wpdb->get_results($sql); |
|---|
| 133 | if (!empty($results)) |
|---|
| 134 | foreach ($results as $result) { $values[] = $result->meta_value; }; |
|---|
| 135 | return c2c__format_custom($field, $values, $before, $after, $none, $between, $before_last); |
|---|
| 136 | } //end c2c_get_recent_custom() |
|---|
| 137 | |
|---|
| 138 | /* Helper function */ |
|---|
| 139 | function c2c__format_custom ($field, $meta_values, $before='', $after='', $none='', $between='', $before_last='') { |
|---|
| 140 | $values = array(); |
|---|
| 141 | if (empty($between)) $meta_values = array_slice($meta_values,0,1); |
|---|
| 142 | if (!empty($meta_values)) |
|---|
| 143 | foreach ($meta_values as $meta) { |
|---|
| 144 | $meta = apply_filters("the_meta_$field", $meta); |
|---|
| 145 | $values[] = apply_filters('the_meta', $meta); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | if (empty($values)) $value = ''; |
|---|
| 149 | else { |
|---|
| 150 | $values = array_map('trim', $values); |
|---|
| 151 | if (empty($before_last)) $value = implode($values, $between); |
|---|
| 152 | else { |
|---|
| 153 | switch ($size = sizeof($values)) { |
|---|
| 154 | case 1: |
|---|
| 155 | $value = $values[0]; |
|---|
| 156 | break; |
|---|
| 157 | case 2: |
|---|
| 158 | $value = $values[0] . $before_last . $values[1]; |
|---|
| 159 | break; |
|---|
| 160 | default: |
|---|
| 161 | $value = implode(array_slice($values,0,$size-1), $between) . $before_last . $values[$size-1]; |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | } |
|---|
| 165 | if (empty($value)) { |
|---|
| 166 | if (empty($none)) return; |
|---|
| 167 | $value = $none; |
|---|
| 168 | } |
|---|
| 169 | return $before . $value . $after; |
|---|
| 170 | } //end c2c__format_custom() |
|---|
| 171 | |
|---|
| 172 | // Some filters you may wish to perform: (these are filters typically done to 'the_content' (post content)) |
|---|
| 173 | //add_filter('the_meta', 'convert_chars'); |
|---|
| 174 | //add_filter('the_meta', 'wptexturize'); |
|---|
| 175 | |
|---|
| 176 | // Other optional filters (you would need to obtain and activate these plugins before trying to use these) |
|---|
| 177 | //add_filter('the_meta', 'c2c_hyperlink_urls', 9); |
|---|
| 178 | //add_filter('the_meta', 'text_replace', 2); |
|---|
| 179 | //add_filter('the_meta', 'textile', 6); |
|---|
| 180 | |
|---|
| 181 | ?> |
|---|