<?php
/*******************************
MENUS SUPPORT
********************************/
if ( function_exists( 'wp_nav_menu' ) ){
if (function_exists('add_theme_support')) {
add_theme_support('nav-menus');
add_action( 'init', 'register_my_menus' );
function register_my_menus() {
register_nav_menus(
array(
'primary-menu' => __( 'Primary Menu' ),
'secondary-menu' => __( 'Secondary Menu' )
)
);
}
}
}
/*******************************
TOP COMMENTERS
********************************/
function top_comment_authors($amount = 5){
global $wpdb;
$results = $wpdb->get_results('
SELECT
COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url
FROM
'.$wpdb->comments.'
WHERE
comment_author_email != "" AND comment_type = "" AND comment_approved = 1
GROUP BY
comment_author_email
ORDER BY
comments_count DESC, comment_author ASC
LIMIT '.$amount
);
$output = "<ul>";
foreach($results as $result){
$output .= "<li>".$result->comment_author. $result->comments_count. $result->comment_author_url."</li>";
}
$output .= "</ul>";
echo $output;
}
/*******************************
JQUERY ENQUEUE
********************************/
add_action('wp_enqueue_scripts', 'get_my_scripts');
function get_my_scripts() {
if (!is_admin())
wp_deregister_script('jquery');
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false, '');
wp_enqueue_script('jquery');
wp_enqueue_script('custom', get_template_directory_uri() . '/js/custom.js', array('jquery'));
wp_enqueue_script('jquerytools', get_template_directory_uri() . '/js/jquery.tools.min.js', array('jquery'));
wp_enqueue_script('jquery-ui-person', get_template_directory_uri() . '/js/jquery-ui-personalized-1.5.2.packed.js', array('jquery'));
wp_enqueue_script('jquery-ui-person', get_template_directory_uri() . '/js/jquery.form.js', array('jquery'));
wp_enqueue_script('sprinkle', get_template_directory_uri() . '/js/sprinkle.js', array('jquery', 'jquery-ui-person', 'jquery-ui-tabs'));
}
/*******************************
TWITTER COUNTER
********************************/
function rarst_twitter_user( $username, $field, $display = false ) {
$interval = 3600;
$cache = get_option('rarst_twitter_user');
$url = 'http://api.twitter.com/1/users/show.json?screen_name='.urlencode($username);
if ( false == $cache )
$cache = array();
// if first time request add placeholder and force update
if ( !isset( $cache[$username][$field] ) ) {
$cache[$username][$field] = NULL;
$cache[$username]['lastcheck'] = 0;
}
// if outdated
if( $cache[$username]['lastcheck'] < (time()-$interval) ) {
// holds decoded JSON data in memory
static $memorycache;
if ( isset($memorycache[$username]) ) {
$data = $memorycache[$username];
}
else {
$result = wp_remote_retrieve_body(wp_remote_request($url));
$data = json_decode( $result );
if ( is_object($data) )
$memorycache[$username] = $data;
}
if ( is_object($data) ) {
// update all fields, known to be requested
foreach ($cache[$username] as $key => $value)
if( isset($data->$key) )
$cache[$username][$key] = $data->$key;
$cache[$username]['lastcheck'] = time();
}
else {
$cache[$username]['lastcheck'] = time()+60;
}
update_option( 'rarst_twitter_user', $cache );
}
if ( false != $display )
echo $cache[$username][$field];
return $cache[$username][$field];
}
/*******************************
THUMBNAIL SUPPORT
********************************/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 250, 165, true );
add_image_size( 'homepage-thumb', 198, 132, true );
add_image_size( 'latestpost-thumb', 584, 197, true );
/*******************************
EXCERPT LENGTH ADJUST
********************************/
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).' (...)';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).' (...)';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
/*******************************
TOP NAVIGATION MENU WALKER
********************************/
class description_walker extends Walker_Nav_Menu
{
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$prepend = '<strong>';
$append = '</strong>';
$description = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';
if($depth != 0)
{
$description = $append = $prepend = "";
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
$item_output .= $description.$args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
/*******************************
WIDGETS AREAS
********************************/
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'sidebar',
'before_widget' => '<div class="rightBox">
<div class="rightBoxTop"></div>
<div class="rightBoxMid">',
'after_widget' => '</div>
<div class="rightBoxBottom"></div>
</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'footer',
'before_widget' => '<div class="boxFooter">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
/*******************************
PAGINATION
********************************
* Retrieve or display pagination code.
*
* The defaults for overwriting are:
* 'page' - Default is null (int). The current page. This function will
* automatically determine the value.
* 'pages' - Default is null (int). The total number of pages. This function will
* automatically determine the value.
* 'range' - Default is 3 (int). The number of page links to show before and after
* the current page.
* 'gap' - Default is 3 (int). The minimum number of pages before a gap is
* replaced with ellipses (...).
* 'anchor' - Default is 1 (int). The number of links to always show at begining
* and end of pagination
* 'before' - Default is '<div class="emm-paginate">' (string). The html or text
* to add before the pagination links.
* 'after' - Default is '</div>' (string). The html or text to add after the
* pagination links.
* 'title' - Default is '__('Pages:')' (string). The text to display before the
* pagination links.
* 'next_page' - Default is '__('»')' (string). The text to use for the
* next page link.
* 'previous_page' - Default is '__('«')' (string). The text to use for the
* previous page link.
* 'echo' - Default is 1 (int). To return the code instead of echo'ing, set this
* to 0 (zero).
*
* @author Eric Martin <eric@ericmmartin.com>
* @copyright Copyright (c) 2009, Eric Martin
* @version 1.0
*
* @param array|string $args Optional. Override default arguments.
* @return string HTML content, if not displaying.
*/
function emm_paginate($args = null) {
$defaults = array(
'page' => null, 'pages' => null,
'range' => 3, 'gap' => 3, 'anchor' => 1,
'before' => '<div class="emm-paginate">', 'after' => '</div>',
'title' => __('Pages:'),
'nextpage' => __('»'), 'previouspage' => __('«'),
'echo' => 1
);
$r = wp_parse_args($args, $defaults);
extract($r, EXTR_SKIP);
if (!$page && !$pages) {
global $wp_query;
$page = get_query_var('paged');
$page = !empty($page) ? intval($page) : 1;
$posts_per_page = intval(get_query_var('posts_per_page'));
$pages = intval(ceil($wp_query->found_posts / $posts_per_page));
}
$output = "";
if ($pages > 1) {
$output .= "$before<span class='emm-title'>$title</span>";
$ellipsis = "<span class='emm-gap'>...</span>";
if ($page > 1 && !empty($previouspage)) {
$output .= "<a href='" . get_pagenum_link($page - 1) . "' class='emm-prev'>$previouspage</a>";
}
$min_links = $range * 2 + 1;
$block_min = min($page - $range, $pages - $min_links);
$block_high = max($page + $range, $min_links);
$left_gap = (($block_min - $anchor - $gap) > 0) ? true : false;
$right_gap = (($block_high + $anchor + $gap) < $pages) ? true : false;
if ($left_gap && !$right_gap) {
$output .= sprintf('%s%s%s',
emm_paginate_loop(1, $anchor),
$ellipsis,
emm_paginate_loop($block_min, $pages, $page)
);
}
else if ($left_gap && $right_gap) {
$output .= sprintf('%s%s%s%s%s',
emm_paginate_loop(1, $anchor),
$ellipsis,
emm_paginate_loop($block_min, $block_high, $page),
$ellipsis,
emm_paginate_loop(($pages - $anchor + 1), $pages)
);
}
else if ($right_gap && !$left_gap) {
$output .= sprintf('%s%s%s',
emm_paginate_loop(1, $block_high, $page),
$ellipsis,
emm_paginate_loop(($pages - $anchor + 1), $pages)
);
}
else {
$output .= emm_paginate_loop(1, $pages, $page);
}
if ($page < $pages && !empty($nextpage)) {
$output .= "<a href='" . get_pagenum_link($page + 1) . "' class='emm-next'>$nextpage</a>";
}
$output .= $after;
}
if ($echo) {
echo $output;
}
return $output;
}
/**
* Helper function for pagination which builds the page links.
*
* @access private
*
* @author Eric Martin <eric@ericmmartin.com>
* @copyright Copyright (c) 2009, Eric Martin
* @version 1.0
*
* @param int $start The first link page.
* @param int $max The last link page.
* @return int $page Optional, default is 0. The current page.
*/
function emm_paginate_loop($start, $max, $page = 0) {
$output = "";
for ($i = $start; $i <= $max; $i++) {
$output .= ($page === intval($i))
? "<span class='emm-page emm-current'>$i</span>"
: "<a href='" . get_pagenum_link($i) . "' class='emm-page'>$i</a>";
}
return $output;
}
/*******************************
CUSTOM COMMENTS
********************************/
function mytheme_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class('clearfix'); ?> id="li-comment-<?php comment_ID() ?>">
<?php echo get_avatar($comment,$size='63'); ?>
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-meta commentmetadata clearfix">
<?php printf(__('<strong>%s</strong>'), get_comment_author_link()) ?><?php edit_comment_link(__('<img src="http://www.zoomingjapan.com/wp-content/themes/alltuts/images/edit.gif">'),' ','') ?> <span><?php printf(__('%1$s @ %2$s'), get_comment_date('Y/n/j'), get_comment_time('G:i')) ?>
</span>
<div class="text">
<?php comment_text() ?>
</div>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<em><?php _e('Your comment is awaiting moderation.') ?></em>
<br />
<?php endif; ?>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</div>
<?php }
/*******************************
THEME OPTIONS PAGE
********************************/
add_action('admin_menu', 'alltuts_theme_page');
function alltuts_theme_page ()
{
if ( count($_POST) > 0 && isset($_POST['alltuts_settings']) )
{
$options = array ('logo_img', 'logo_alt','ads','advertise','contact_email','contact_text','cufon','linkedin_link','twitter_user','latest_tweet','number_tweets','facebook_link','keywords','description','analytics','popular_posts', 'copyright');
foreach ( $options as $opt )
{
delete_option ( 'alltuts_'.$opt, $_POST[$opt] );
add_option ( 'alltuts_'.$opt, $_POST[$opt] );
}
}
add_menu_page(__('Alltuts Options'), __('Alltuts Options'), 'edit_themes', basename(__FILE__), 'alltuts_settings');
add_submenu_page(__('Alltuts Options'), __('Alltuts Options'), 'edit_themes', basename(__FILE__), 'alltuts_settings');
}
function alltuts_settings()
{?>
<div class="wrap">
<h2>AllTuts Options Panel</h2>
<form method="post" action="">
<fieldset style="border:1px solid #ddd; padding-bottom:20px; margin-top:20px;">
<legend style="margin-left:5px; padding:0 5px;color:#2481C6; text-transform:uppercase;"><strong>General Settings</strong></legend>
<table class="form-table">
<!-- General settings -->
<tr valign="top">
<th scope="row"><label for="logo_img">Change logo (full path to logo image)</label></th>
<td>
<input name="logo_img" type="text" id="logo_img" value="<?php echo get_option('alltuts_logo_img'); ?>" class="regular-text" /><br />
<em>current logo:</em> <br /> <img src="<?php echo get_option('alltuts_logo_img'); ?>" alt="<?php echo get_option('alltuts_logo_alt'); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="logo_alt">Logo ALT Text</label></th>
<td>
<input name="logo_alt" type="text" id="logo_alt" value="<?php echo get_option('alltuts_logo_alt'); ?>" class="regular-text" />
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="logo_alt">Ads Section Enabled</label></th>
<td>
<select name="ads" id="ads">
<option value="no" <?php if(get_option('alltuts_ads') == 'no'){?>selected="selected"<?php }?>>No</option>
<option value="yes" <?php if(get_option('alltuts_ads') == 'yes'){?>selected="selected"<?php }?>>Yes</option>
</select> <br />
<em>You need "WP125" plugin installed and activated for this option to make a difference</em>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="logo_alt">Advertise page</label></th>
<td>
<?php wp_dropdown_pages("name=advertise&show_option_none=".__('- Select -')."&selected=" .get_option('alltuts_advertise')); ?>
<br />
<em>You need to create a page for advertising details and selectit here</em>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cufon">Cufon Font Replacement</label></th>
<td>
<select name="cufon" id="cufon">
<option value="yes" <?php if(get_option('alltuts_cufon') == 'yes'){?>selected="selected"<?php }?>>Yes</option>
<option value="no" <?php if(get_option('alltuts_cufon') == 'no'){?>selected="selected"<?php }?>>No</option>
</select>
</td>
</tr>
</table>
</fieldset>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="Save Changes" />
<input type="hidden" name="alltuts_settings" value="save" style="display:none;" />
</p>
<fieldset style="border:1px solid #ddd; padding-bottom:20px; margin-top:20px;">
<legend style="margin-left:5px; padding:0 5px; color:#2481C6;text-transform:uppercase;"><strong>Social Links</strong></legend>
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="twitter_user">Twitter Username</label></th>
<td>
<input name="twitter_user" type="text" id="twitter_user" value="<?php echo get_option('alltuts_twitter_user'); ?>" class="regular-text" />
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="latest_tweet">Display Latest Tweet</label></th>
<td>
<select name="latest_tweet" id="latest_tweet">
<option value="yes" <?php if(get_option('alltuts_latest_tweet') == 'yes'){?>selected="selected"<?php }?>>Yes</option>
<option value="no" <?php if(get_option('alltuts_latest_tweet') == 'no'){?>selected="selected"<?php }?>>No</option>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="number_tweets">Number of Tweets Displayed</label></th>
<td>
<input name="number_tweets" type="text" id="number_tweets" value="<?php echo get_option('alltuts_number_tweets'); ?>" class="regular-text" />
<br />
<em>Default is 1</em>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="facebook_link">Facebook link</label></th>
<td>
<input name="facebook_link" type="text" id="facebook_link" value="<?php echo get_option('alltuts_facebook_link'); ?>" class="regular-text" />
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="flickr_link">LinknedIn link</label></th>
<td>
<input name="linkedin_link" type="text" id="linkedin_link" value="<?php echo get_option('alltuts_linkedin_link'); ?>" class="regular-text" />
</td>
</tr>
</table>
</fieldset>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="Save Changes" />
<input type="hidden" name="alltuts_settings" value="save" style="display:none;" />
</p>
<fieldset style="border:1px solid #ddd; padding-bottom:20px; margin-top:20px;">
<legend style="margin-left:5px; padding:0 5px; color:#2481C6;text-transform:uppercase;"><strong>Contact Page Settings</strong></legend>
<table class="form-table">
<tr>
<td colspan="2"></td>
</tr>
<tr valign="top">
<th scope="row"><label for="contact_text">Contact Page Text</label></th>
<td>
<textarea name="contact_text" id="contact_text" rows="7" cols="70" style="font-size:11px;"><?php echo stripslashes(get_option('alltuts_contact_text')); ?></textarea>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="contact_email">Email Address for Contact Form</label></th>
<td>
<input name="contact_email" type="text" id="contact_email" value="<?php echo get_option('alltuts_contact_email'); ?>" class="regular-text" />
</td>
</tr>
</table>
</fieldset>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="Save Changes" />
<input type="hidden" name="alltuts_settings" value="save" style="display:none;" />
</p>
<fieldset style="border:1px solid #ddd; padding-bottom:20px; margin-top:20px;">
<legend style="margin-left:5px; padding:0 5px; color:#2481C6;text-transform:uppercase;"><strong>Footer</strong></legend>
<table class="form-table">
<tr>
<th><label for="popular_posts">Display Popular Posts</label></th>
<td>
<select name="popular_posts" id="popular_posts">
<option value="yes" <?php if(get_option('alltuts_popular_posts') == 'yes'){?>selected="selected"<?php }?>>Yes</option>
<option value="no" <?php if(get_option('alltuts_popular_posts') == 'no'){?>selected="selected"<?php }?>>No</option>
</select><br />
<em>You need "WP-Popular Posts Tool" plugin installed and activated for this option to make a difference</em>
</td>
</tr>
<tr>
<th><label for="copyright">Copyright Text</label></th>
<td>
<textarea name="copyright" id="copyright" rows="4" cols="70" style="font-size:11px;"><?php echo stripslashes(get_option('alltuts_copyright')); ?></textarea><br />
<em>You can use HTML for links etc.</em>
</td>
</tr>
</table>
</fieldset>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="Save Changes" />
<input type="hidden" name="alltuts_settings" value="save" style="display:none;" />
</p>
<fieldset style="border:1px solid #ddd; padding-bottom:20px; margin-top:20px;">
<legend style="margin-left:5px; padding:0 5px; color:#2481C6;text-transform:uppercase;"><strong>SEO</strong></legend>
<table class="form-table">
<tr>
<th><label for="keywords">Meta Keywords</label></th>
<td>
<textarea name="keywords" id="keywords" rows="7" cols="70" style="font-size:11px;"><?php echo get_option('alltuts_keywords'); ?></textarea><br />
<em>Keywords comma separated</em>
</td>
</tr>
<tr>
<th><label for="description">Meta Description</label></th>
<td>
<textarea name="description" id="description" rows="7" cols="70" style="font-size:11px;"><?php echo get_option('alltuts_description'); ?></textarea>
</td>
</tr>
<tr>
<th><label for="ads">Google Analytics code:</label></th>
<td>
<textarea name="analytics" id="analytics" rows="7" cols="70" style="font-size:11px;"><?php echo stripslashes(get_option('alltuts_analytics')); ?></textarea>
</td>
</tr>
</table>
</fieldset>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="Save Changes" />
<input type="hidden" name="alltuts_settings" value="save" style="display:none;" />
</p>
</form>
</div>
<?php }
/*******************************
CONTACT FORM
********************************/
function hexstr($hexstr) {
$hexstr = str_replace(' ', '', $hexstr);
$hexstr = str_replace('\x', '', $hexstr);
$retstr = pack('H*', $hexstr);
return $retstr;
}
function strhex($string) {
$hexstr = unpack('H*', $string);
return array_shift($hexstr);
}
?>