'.sprintf(__('%1$s Provide a %2$s attribute', ATOM), '[form]', 'i/n').'

'; $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); } /** * Create simple forms, or output the register form * usage examples: * [form mailto=maryjane420@gmail.com textinput1="Your Name" textinput2="Your E-mail" textarea="Type your message here"] * [form mailto=johnnywalker@yahoo.com select1="Select a color|Red|Blue|Green" select2="Select a number|4|8|16|20" checkbox="I want to subscribe"] * [form register] * * (a number is required when there are more fields of the same type) * * @since 1.0 * * @param mixed $atts Shortcode attributes * @return string The Form (HTML output) * @todo: add field validation */ function atom_shortcode_form($atts){ extract(shortcode_atts(array( 'mailto' => false ), $atts)); if(isset($atts[0]) && $atts[0] == 'register' && get_option('users_can_register')): // register form $target = 'reg'; $atts = array(); $submit_label = __("Sign up", ATOM); else: // custom form if(!$mailto) return '

'.sprintf(__('%1$s Provide a %2$s attribute', ATOM), '[form]', 'mailto').'

'; $target = esc_attr($mailto); unset($atts['mailto']); $submit_label = __("Send", ATOM); endif; // generate a form ID $form = substr(md5(implode('-',$atts)),0,10); $fields = array(); $output = '
'; foreach($atts as $index => $value): $id = sanitize_title(esc_attr(strip_tags($value))); $index = preg_replace("/[0-9]/", "", $index); switch($index): // input:text case 'textinput': $output .= ''; break; // textarea case 'textarea': $output .= ''; break; // select case 'select': $select = explode('|', esc_attr($value)); $id = sanitize_title(esc_attr(strip_tags($select[0]))); $output .= ''; break; // input:checkbox case 'checkbox': $output .= ''; break; endswitch; $fields[] = $id; endforeach; if($target == 'reg'): $output .= ''; $output .= ''; $output .= '

'.__("(A password will be emailed to you)", ATOM).'

'; endif; $output .= ''; $output .= ''; // disable submit button - we enable it with jquery after we retrieve the nonce $output .= ''; $output .= '
'; set_transient($form, array('target' => $target, 'nonce' => wp_create_nonce($form), 'fields' => $fields), 60*60*6); // cache for 6 hours return $output; } /** * 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) 'align' => false, // float 'title' => true, // show titles? 'sidebar' => '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 = strip_tags(stripslashes($atts[0])); else return; $sidebar = strip_tags(stripslashes($sidebar)); $align = strip_tags(stripslashes($align)); $number = intval($number); $callback = false; $possible_matches = array(); $sidebars_widgets = wp_get_sidebars_widgets(); if(empty($sidebars_widgets[$sidebar]) || empty($wp_registered_widgets)) return '

'.'[Widget] '.sprintf(__("There are no valid active widgets (empty %s area)", ATOM), strip_tags(stripslashes($sidebar))).'

'; // 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']); $widget = $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(!$callback): $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)) $widget = $number ? $valid_matches[$number-1] : $widget = $valid_matches[0]; if($widget && isset($wp_registered_widgets[$widget]['callback'])) $callback = $wp_registered_widgets[$widget]['callback']; endif; // yey. we found it if($callback): ob_start(); // catch the echo output, so we can control where it appears in the text $params = array_merge(array(array_merge($wp_registered_sidebars[$sidebar], array('widget_id' => $widget, 'widget_name' => $wp_registered_widgets[$widget]['name']))), (array)$wp_registered_widgets[$widget]['params']); // align classes? if($align) $params[0]['before_widget'] = str_replace('block', 'block align'.strip_tags(stripslashes(($align))), $params[0]['before_widget']); // Substitute HTML id and class attributes into before_widget $classname_ = ''; foreach ((array)$wp_registered_widgets[$widget]['classname'] as $cn) if (is_string($cn)) $classname_ .= '_'.$cn; elseif (is_object($cn)) $classname_ .= '_'.get_class($cn); $classname_ = ltrim($classname_, '_'); $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $widget, $classname_); $params = apply_filters('dynamic_sidebar_params', $params); if (is_callable($callback)) call_user_func_array($callback, $params); $output = ob_get_clean(); // remove h3 if title = false if(!$title) $output = preg_replace('#

(.*?)

#', '', $output); return $output; else: return '

'.'[Widget] '.sprintf(__("Widget instance not found (%s)", ATOM), strip_tags(stripslashes($atts[0]))).'

'; endif; } /** * Output posts filtered by specific attributes * Examples: * List 5 posts from Uncategorized, ordered by comment count: * [query category="Uncategorized" count=5 order="comment_count"] * * List 9 posts from Uncategorized in thumbnail-only format * [query category="Uncategorized" count=9 show_title=0 show_content=0 show_comment_link=0 show_date=0 show_category=0 show_author=0 show_tags=0] * * @since 1.0 * * @param mixed $atts Shortcode attributes * @return string The Widget (HTML output) * * @todo: add pagination */ function atom_shortcode_query($atts){ extract(shortcode_atts(array( // query 'count' => 5, 'tags' => false, 'order' => 'date', 'author' => false, 'category' => false, 'type' => 'post', 'status' => 'publish', 'day' => false, 'month' => false, 'year' => false, 'featured' => false, // featured posts? 'asides' => false, // asides? // display options 'show_title' => true, 'show_date' => true, 'show_category' => true, 'show_tags' => true, 'show_author' => true, 'show_comment_link' => true, 'show_content' => true, 'show_thumbs' => true, 'content_mode' => atom_get_options('post_content_mode'), 'thumb_mode' => atom_get_options('post_thumbs_mode'), 'mode' => 'normal' // normal/list ), $atts)); $output = ''; $query = array(); $query['posts_per_page'] = intval($count); $query['orderby'] = strip_tags(stripslashes(($order))); $query['post_type'] = strip_tags(stripslashes(($type))); $query['post_status'] = strip_tags(stripslashes(($status))); if($day) $query['day'] = intval(($day)); if($month) $query['month'] = intval(($month)); if($year) $query['year'] = intval(($year)); if($tags) $query['tag'] = strip_tags(stripslashes(($tags))); if($author) $query['author_name'] = strip_tags(stripslashes(($author))); if($category) $query['category_name'] = strip_tags(stripslashes(($category))); $query['caller_get_posts'] = 1; // no sticky posts at the top $query['post__not_in'] = get_option('sticky_posts'); // no sticky posts in the results if($featured && ($featured_ids = get_option('featured_posts'))) $query['post__in'] = explode(',', $featured_ids); // get the featured post IDs $c = get_term_by('slug', 'asides', 'category'); if(!empty($c)) if($asides) $query['cat'] = $c->term_id; // asides category else $query['cat'] = '-'.$c->term_id; // exclude asides $opts = array(); $opts['post_title'] = (bool)$show_title; $opts['post_date'] = (bool)$show_date; $opts['post_category'] = (bool)$show_category; $opts['post_tags'] = (bool)$show_tags; $opts['post_author'] = (bool)$show_author; $opts['post_comments'] = (bool)$show_comment_link; $opts['post_content'] = (bool)$show_content; $opts['post_thumbs'] = (bool)$show_thumbs; $opts['post_content_mode'] = strip_tags(stripslashes($content_mode)); $opts['post_thumbs_mode'] = strip_tags(stripslashes($thumb_mode)); ob_start(); //$override = create_function('$opts', 'return array_merge(atom_get_options(),$opts);'); global $__theme_settings; $bkp = $__theme_settings; $__theme_settings = array_merge($__theme_settings, $opts); $posts = new WP_Query($query); if ($posts->have_posts()) while ($posts->have_posts()): $posts->the_post(); if($mode == 'list') echo "
  • \n"; atom_post(); if($mode == 'list') echo "
  • \n"; endwhile; else return; // no posts found wp_reset_query(); $output = ob_get_contents(); ob_end_clean(); if($mode != 'list') $output = "
    \n".$output."\n
    "; $__theme_settings = $bkp; return $output; } /** * 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: [page-rank 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('pr_'+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 the transient for 24 hours (cache) set_transient('pr_'+md5($url), $pagerank, 60*60*24); endif; // pr green bar $output = '
    '; $output.= sprintf(__("PR %s","mystique"), $pagerank); $output.= '
    '; $output.= '
    '; $output.= '
    '; return $output; } /** * Credit links (Wordpress & digitalnature) * example: [credit] * * @since 1.0 * * @return string Credit links */ function atom_shortcode_credit(){ return sprintf(__('Powered by %1$s | %2$s theme by %3$s', ATOM), 'WordPress', THEME_FULL_NAME, 'digitalnature'); } /** * Copyright info * example: [copyright] * * @since 1.0 * * @return string Copyright info */ function atom_shortcode_copyright() { return sprintf('%1$s %2$s %4$s', __('Copyright ©', ATOM), date('Y'), BLOG_URL, BLOG_NAME); } /** * validate XHTML link * Use this to check your posts for errors * example: [xhtml] * * @since 1.0 * * @return string w3 link */ function atom_shortcode_xhtml(){ return 'XHTML 1.1'; } /** * validate CSS link * Useless; having valid CSS code is not important. The theme uses a lot of CSS3 and browser specific properties, which are marked as invalid anyway... * example: [css] * * @since 1.0 * * @return string w3 link */ function atom_shortcode_css(){ return 'CSS 3.0'; } /** * 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(__('%1$s queries in %2$s seconds', ATOM), get_num_queries(), timer_stop(0)); } /** * 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 [/field] * * @since 1.0 * * @return string Custom field value */ function atom_shortcode_field($atts, $custom_field){ extract(shortcode_atts(array( 'post_id' => '' ), $atts)); global $post; if(!$post_id) $post_id = $post->ID; return get_post_meta($post_id, $custom_field, 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){ ob_start(); if (FALSE === @eval($code.' return true;')) return '

    '.sprintf(__("%s Error while evaluating your code", ATOM), '[PHP]').'

    '; $output = ob_get_contents(); ob_end_clean(); return $output; } /** * RSS Feed link * example: [rss] * * @since 1.0 * * @return string */ function atom_shortcode_rss(){ return ''. __('RSS Feeds', ATOM) .''; } /** * Theme Link/Name * example: [theme] * * @since 1.0 * * @return string */ function atom_shortcode_theme(){ return ''.THEME_FULL_NAME.''; } /** * Theme Author Name/Link * example: [theme-author] * * @since 1.0 * * @return string */ function atom_shortcode_themeauthor(){ return THEME_AUTHOR; } /** * Wordpress Link * example: [wp] * * @since 1.0 * * @return string */ function atom_shortcode_wp(){ return 'WordPress'; } /** * Login/Dashboard Link * example: [login] * * @since 1.0 * * @return string */ function atom_shortcode_login(){ if (is_user_logged_in()) return sprintf('%2$s', admin_url(), __('Site Admin', ATOM)); else return sprintf('%2$s', wp_login_url(), __('Log in', ATOM)); } /** * Blog title * example: [blog-title] * * @since 1.0 * * @return string */ function atom_shortcode_blogtitle(){ return ''.get_bloginfo('name').''; } ?>