[column] '._a('Please specify the column number / total column count').''; $type = explode('/', $atts[0]); $index = intval($type[0]); $count = intval($type[1]); $classes = array('col'); $classes[] = "c-{$count}"; if($index == 1) $classes[] = 'first'; elseif($index == $count) $classes[] = 'last'; $output = ''; if($index == 1) $output .= '
'; $output .= '
'.$content.'
'; if($index == $count) $output .= '
'; return do_shortcode($output); } /** * Output a link. So far, valid attributes are: * - wp (wordpress.org link) * - login (login/or dashboard) * - rss (feed url) * - xhtml (xhtml validation link) * - css (css validation, useless, css is not seen as valid because of browser-specific properties) * - theme (theme uri from style.css) * * usage examples: * [link rss] * [link login] * [link wp] * * @since 1.2 * * @param mixed $atts Shortcode attributes * @return string The Link (HTML output) */ function atom_shortcode_link($atts){ $links = array( 'wp' => array('url' => 'http://WordPress.org/', 'title' => 'WordPress', 'rel' => 'generator', 'class' => 'wp-link' ), 'rss' => array('url' => get_bloginfo('rss2_url'), 'title' => _a('RSS Feeds'), 'rel' => 'feed', 'class' => 'rss' ), 'login' => array('url' => is_user_logged_in() ? admin_url() : wp_login_url(), 'title' => is_user_logged_in() ? _a('Dashboard') : _a('Log in'), 'rel' => 'login', 'class' => 'login-link' ), 'theme' => array('url' => THEME_URI, 'title' => THEME_NAME, 'rel' => 'theme', 'class' => 'theme-link' ), 'css' => array('url' => 'http://validator.w3.org/check?uri=referer', 'title' => 'XHTML 1.1', 'rel' => 'external', 'class' => 'valid-xhtml' ), 'xhtml' => array('url' => 'http://jigsaw.w3.org/css-validator/check/referer?profile=css3', 'title' => 'CSS 3.0', 'rel' => 'external', 'class' => 'valid-css' ), ); if(!isset($atts[0]) || !array_key_exists($atts[0], $links)) return atom_add_debug_message("[link] Invalid link attribute."); $link = $links[$atts[0]]; return "{$link['title']}\n"; } /** * Allows the user to insert widgets into areas that allow shortcodes * inspired by http://webdesign.anmari.com/shortcode-any-widget by Anna-marie Redpath * usage examples: * [widget "ID"] * [widget "Widget Name"] * [widget "Widget Name" number=4] * * ID should be provided in the Widgets Dashboard page * * @since 1.0 * @global array $wp_registered_widgets * @global array $wp_registered_sidebars * * @param mixed $atts Shortcode attributes * @return string The Widget (HTML output) */ function atom_shortcode_widget($atts){ global $wp_registered_widgets, $wp_registered_sidebars; extract(shortcode_atts(array( 'number' => false, // only taken in consideration if the 1st argument is the "Widget Name" (not the hashed ID) 'title' => true, // show titles? 'area' => 'arbitrary' // sidebar to search, shoud not be changed because it might actually kill puppies ), $atts)); // get 1st parameter (assuming this is the target widget id or name) if (!empty($atts[0])) $widget = esc_attr($atts[0]); else return atom_add_debug_message("[widget {$widget}] No valid widget name/or id provided"); $sidebar = esc_attr($area); $align = esc_attr($align); $number = intval($number); $callback = false; $found = false; $possible_matches = array(); $sidebars_widgets = wp_get_sidebars_widgets(); if((empty($sidebars_widgets[$sidebar]) || empty($wp_registered_widgets)) && (current_user_can('edit_themes'))) return atom_add_debug_message("[widget {$widget}] No active widget in {$sidebar} area"); // assuming we get the md5 hashed ID foreach ($wp_registered_widgets as $i => $w) if($widget == substr(md5($w['id']), 0, 8)): $callback = ($w['callback']); $found = $w['id']; // real widget ID // compare widget names as well, and build a array with the possible widget matches array // (which is used later if ID match fails) elseif($widget == $w['name']): $possible_matches[] = $w['id']; endif; // nothing found, assume it's the "Widget Name". if(!$found): $valid_matches = array(); foreach($sidebars_widgets[$sidebar] as $i => $w) foreach($possible_matches as $id) if($id == $w) $valid_matches[] = $w; if(!empty($valid_matches)) $found = $number ? $valid_matches[$number-1] : $found = $valid_matches[0]; endif; $remove_title = !$title ? 'h3' : false; if($found && $output = atom_get_widget($found, $sidebar, $remove_title)) return $output; //else return current_user_can('edit_themes') ? '

'.'[Widget] '.sprintf(_a("Widget instance not found (%s)"), esc_attr($atts[0])).'

' : false; } /** * Output posts filtered by specific attributes * * Examples: * List 10 most commented posts using the teaser template: * [query posts_per_page=10 order="comment_count" template="teaser"] ... [/query] * * List featured posts using a defined template * [query featured=1 order="comment_count"] {TITLE} ({COMMENT_COUNT} comments) [/query] * * @since 1.0 * * @param mixed $atts Shortcode attributes * @param string $content HTML * * @return string HTML output * * @todo: add pagination * @todo: add more variables for user defined templates * @todo: handle array type arguments (explode commas?) */ function atom_shortcode_query($atts, $content = null){ // theme (non-wpquery) arguments $args = array( 'template' => '', // use custom template, for eg. "teaser" 'content_limit' => 40, 'thumbnail_size' => 'post-thumbnail', 'date_mode' => 'relative', 'featured' => false, ); $all_args = shortcode_atts(array_merge(array( // a few wp_query arguments 'caller_get_posts' => 1, // no sticky posts at the top by default 'post__not_in' => atom_get_options('sticky_posts'), // no sticky posts in the results by default ), $args), $atts); extract($all_args); $query = array_merge($atts, $all_args); foreach($args as $key => $value) unset($query[$key]); // filter out non-wpquery arguments // get the featured post IDs if "featured" argument is true if($featured && ($featured_ids = atom_get_options('featured_posts'))) $query['post__in'] = explode(',', $featured_ids); $output = ''; ob_start(); global $post; $posts = new WP_Query($query); if ($posts->have_posts()) while ($posts->have_posts()): $posts->the_post(); if(!empty($template)): // use internal template atom_post(esc_attr($template)); else: // use shortcode-defined template echo atom_render_template($content, array( 'URL' => atom_get_post_title_url(), 'TITLE' => atom_get_post_title(), 'AUTHOR' => esc_attr(get_the_author()), 'AUTHOR_URL' => get_author_posts_url(get_the_author_meta('ID')), 'DATE' => atom_get_post_date($date_mode), 'THUMBNAIL' => atom_get_post_thumb(NULL, $thumbnail_size), 'TAGS' => implode(', ', atom_get_post_terms()), 'CATEGORIES' => implode(', ', atom_get_post_terms(NULL, 'category')), // @todo: I need to somehow add support for custom taxonomies 'FILTERED_CONTENT' => atom_filter_content(NULL, array('limit' => $content_limit)), 'CONTENT' => get_the_content(), 'COMMENT_COUNT' => $post->comment_count, 'CURRENT_POST' => $posts->current_post+1, )); endif; endwhile; wp_reset_query(); $output = ob_get_clean(); return $output ? "
\n{$output}\n
" : atom_add_debug_message("[query] No matching posts found."); } /** * Member only content * based on: http://justintadlock.com/archives/2009/05/09/using-shortcodes-to-show-members-only-content * example: [member] text [/member] * * @since 1.0 * * @param mixed $atts Shortcode attributes * @param string $content Content to output * @return string content (html) */ function atom_shortcode_member($atts, $content = null){ if (is_user_logged_in() && !is_null($content) && !is_feed()) return do_shortcode($content); return ''; } /** * Visitor only content * based on: http://justintadlock.com/archives/2009/05/09/using-shortcodes-to-show-members-only-content * example: [visitor] text [/visitor] * * @since 1.0 * * @param mixed $atts Shortcode attributes * @param string $content Content to output * @return string content (html) */ function atom_shortcode_visitor($atts, $content = null){ if ((!is_user_logged_in() && !is_null($content)) || is_feed()) return do_shortcode($content); return ''; } /** * Output a TinyURL link * example: [tinyurl url=http://google.com title="Google Homepage" rel=nofollow] * * @since 1.0 * * @param mixed $atts Shortcode attributes * @return string The tinyURL link */ function atom_shortcode_tinyurl($atts){ extract(shortcode_atts(array( 'url' => '', 'title' => '', 'rel' => 'nofollow' ), $atts)); if(!$title) $title = $url; return ''.esc_attr($title).''; } /** * Get the Google PageRank of a URL * Google Toolbar 3.0.x/4.0.x Pagerank Checksum Algorithm by http://pagerank.gamesaga.net * example: [pagerank url=http://digitalnature.ro] * * @since 1.0 * * @param mixed $atts Shortcode attributes * @return string The HTML formatted page rank */ function atom_shortcode_pagerank($atts){ function CheckHash($Hashnum){ $CheckByte = 0; $Flag = 0; $HashStr = sprintf('%u', $Hashnum) ; $length = strlen($HashStr); for ($i = $length - 1; $i >= 0; $i --): $Re = $HashStr{$i}; if (1 === ($Flag % 2)): $Re += $Re; $Re = (int)($Re / 10) + ($Re % 10); endif; $CheckByte += $Re; $Flag ++; endfor; $CheckByte %= 10; if (0 !== $CheckByte): $CheckByte = 10 - $CheckByte; if (1 === ($Flag % 2)): if (1 === ($CheckByte % 2)): $CheckByte += 9; endif; $CheckByte >>= 1; endif; endif; return '7'.$CheckByte.$HashStr; } function HashURL($String){ function StrToNum($Str, $Check, $Magic){ $Int32Unit = 4294967296; // 2^32 $length = strlen($Str); for ($i = 0; $i < $length; $i++): $Check *= $Magic; // If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31), // the result of converting to integer is undefined // refer to http://www.php.net/manual/en/language.types.integer.php if ($Check >= $Int32Unit): $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit)); //if the check less than -2^31 $Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check; endif; $Check += ord($Str{$i}); endfor; return $Check; } $Check1 = StrToNum($String, 0x1505, 0x21); $Check2 = StrToNum($String, 0, 0x1003F); $Check1 >>= 2; $Check1 = (($Check1 >> 4) & 0x3FFFFC0) | ($Check1 & 0x3F); $Check1 = (($Check1 >> 4) & 0x3FFC00) | ($Check1 & 0x3FF); $Check1 = (($Check1 >> 4) & 0x3C000) | ($Check1 & 0x3FFF); $T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2) | ($Check2 & 0xF0F); $T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000); return ($T1 | $T2); } extract(shortcode_atts(array('url' => BLOG_URL), $atts)); $pagerank = 0; // if the transient is not present in the database if (false === ($pagerank = get_transient('pagerank_'.md5($url)))): // get the pr $query = "http://toolbarqueries.google.com/search?client=navclient-auto&ch=".CheckHash(HashURL($url))."&features=Rank&q=info:".$url."&num=100&filter=0"; $request = new WP_Http(); $result = $request->request($query); $pos = strpos($result['body'], "Rank_"); if($pos === false); else $pagerank = substr($result['body'], $pos + 9); set_transient('pagerank_'.md5($url), $pagerank, 60*60*24); // 1 day cache endif; // pr green bar $output = '
'.sprintf(_a("PR %s"), $pagerank); $output.= '
'; return $output; } /** * Get the number of subscribers (subscribers) for a particular social media service * uses Yahoo Query Language - http://developer.yahoo.com/yql/ * based on "Total Media Followers" by Melody Fassino - http://element-80.com/portfolio/plugins/total-social-followers/ * @todo: add more services * * examples: * [subscribers FeedBurner id=ourawesomeplanet] * [subscribers Twitter id=digitalnature] * * @since 1.3 * * @param mixed $atts Shortcode attributes * @return string Subscriber count */ function atom_shortcode_subscribers($atts){ extract(shortcode_atts(array( 'id' => false ), $atts)); $service = (isset($atts[0]) && $id) ? strtolower(esc_attr(strip_tags($atts[0]))) : false; $id = esc_attr(strip_tags($id)); if($service == 'feedburner') $query = YQL.urlencode("SELECT * FROM xml WHERE url='https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri={$id}'").'&format=json&callback='; elseif($service == 'twitter') $query = YQL.urlencode("SELECT * FROM xml WHERE url='http://twitter.com/users/show/{$id}.xml'").'&format=json&callback='; elseif($service == 'facebook') $query = YQL.urlencode("SELECT * FROM facebook.graph WHERE id='{$id}'").'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback='; elseif($service == 'youtube') $query = YQL.urlencode("SELECT * FROM xml WHERE url='http://gdata.youtube.com/feeds/api/users/{$id}'").'&format=json&callback='; else return "
[subscribers] "._a('Please specify a valid service and user ID')."
\n"; // if the transient is not present in the database make a new query if (false === ($data = get_transient("subscribers_{$service}_{$id}"))): $response = wp_remote_retrieve_body(wp_remote_request($query)); //if(is_wp_error($response)) return "
[subscribers] {$response->get_error_message()}
\n"; if($response): $response = json_decode($response, true); if($service == 'feedburner') $data = $response['query']['results']['rsp']['feed']['entry']['circulation']; elseif($service == 'twitter') $data = $response['query']['results']['user']['followers_count']; elseif($service == 'facebook') $data = $response['query']['results']['json']['likes']; elseif($service == 'youtube') $data = $response['query']['results']['entry']['statistics']['subscriberCount']; // cache the result as a transient, for 6 hours set_transient("subscribers_{$service}_{$id}", intval($data), 60*60*6); endif; endif; return intval($data); } /** * Credit links (Wordpress & digitalnature) * example: [credit] * * @since 1.0 * * @return string Credit links */ function atom_shortcode_credit(){ return sprintf(_a('Powered by %1$s | %2$s theme by %3$s'), 'WordPress', THEME_NAME, 'digitalnature'); } /** * Copyright info * example: [copyright start="2001"] * * @since 1.0 * * @return string Copyright info */ function atom_shortcode_copyright($atts){ extract(shortcode_atts(array( 'start' => false ), $atts)); if($start) $start = intval($start).' – '; return sprintf('%1$s '.$start.'%2$s %4$s', _a('Copyright ©'), date('Y'), BLOG_URL, BLOG_NAME); } /** * Show the number of database queries and how much time it takes to load the current page * example: [load] * * @since 1.0 * * @return string */ function atom_shortcode_load(){ return sprintf(_a('%1$s queries in %2$s seconds (%3$s MB)'), get_num_queries(), timer_stop(0, 2), number_format((version_compare(PHP_VERSION, '5.2.0', '<') ? memory_get_usage(): memory_get_peak_usage())/1024/1024, 2)); } /** * Return the value of a custom field. * If used outside the loop (eg. in text widgets), you need to specify the post_id parameter * example: [field "Apples"] * * @since 1.0 * * @return string Custom field value */ function atom_shortcode_field($atts){ extract(shortcode_atts(array( 'post_id' => '' ), $atts)); global $post; $post_id = (NULL === $post_id) ? $post->ID : $post_id; return !isset($atts[0]) ? false : get_post_meta($post_id, esc_attr(strip_tags($atts[0])), true); } /** * Execute PHP code - Really unsecure stuff! Do not enable this shortcode on WP-multiuser! * example: [php] echo "Hello World!"; [/php] * * @since 1.0 * * @return string */ function atom_shortcode_php($atts, $code = null){ // print_r($code); $code = strip_tags(html_entity_decode($code)); ob_start(); if (@eval("") === false): ob_clean(); return '
[PHP] '._a("Error while evaluating your code").$code.'
'; endif; return ob_get_clean(); } /** * Theme Author Name/Link * example: [theme-author] * * @since 1.0 * * @return string */ function atom_shortcode_themeauthor(){ return THEME_AUTHOR; } /** * Blog title * example: [blog-title] * * @since 1.0 * * @return string */ function atom_shortcode_blogtitle(){ return ''.get_bloginfo('name').''; } ?>