<?php
include("includes/theme_options.php");
//主题检测新版本升级
require_once(TEMPLATEPATH . '/includes/theme-update-checker.php');
$wpdaxue_update_checker = new ThemeUpdateChecker(
'Nocower-Metro',
'http://api.nocower.com/metro-theme-update/metro.json'
);
//友情链接
if ( function_exists('register_nav_menus') ) {
register_nav_menus(array('foot' => '友情链接'));
}
//移除顶部
function hide_admin_bar($flag) {
return false;
}
add_filter('show_admin_bar','hide_admin_bar');
//禁用Google Open Sans字体,加速网站
add_filter( 'gettext_with_context', 'wpdx_disable_open_sans', 888, 4 );
function wpdx_disable_open_sans( $translations, $text, $context, $domain ) {
if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}
return $translations;
}
//获得热评文章
function simple_get_most_viewed($posts_num=11, $days=30){
global $wpdb;
$sql = "SELECT ID , post_title , comment_count
FROM $wpdb->posts
WHERE post_type = 'post' AND TO_DAYS(now()) - TO_DAYS(post_date) < $days
AND ($wpdb->posts.`post_status` = 'publish' OR $wpdb->posts.`post_status` = 'inherit')
ORDER BY comment_count DESC LIMIT 0 , $posts_num ";
$posts = $wpdb->get_results($sql);
$output = "";
foreach ($posts as $post){
$output .= "\n<li><a href= \"".get_permalink($post->ID)."\" target=\"_blank\" rel=\"bookmark\" title=\"".$post->post_title." (".$post->comment_count."条评论)\" >".
cut_str($post->post_title,137,"utf-8")."</a></li>";
}
echo $output;
}
//标题文字截断
function cut_str($src_str,$cut_length)
{
$return_str='';
$i=0;
$n=0;
$str_length=strlen($src_str);
while (($n<$cut_length) && ($i<=$str_length))
{
$tmp_str=substr($src_str,$i,1);
$ascnum=ord($tmp_str);
if ($ascnum>=224)
{
$return_str=$return_str.substr($src_str,$i,3);
$i=$i+3;
$n=$n+2;
}
elseif ($ascnum>=192)
{
$return_str=$return_str.substr($src_str,$i,2);
$i=$i+2;
$n=$n+2;
}
elseif ($ascnum>=65 && $ascnum<=90)
{
$return_str=$return_str.substr($src_str,$i,1);
$i=$i+1;
$n=$n+2;
}
else
{
$return_str=$return_str.substr($src_str,$i,1);
$i=$i+1;
$n=$n+1;
}
}
if ($i<$str_length)
{
$return_str = $return_str . '';
}
if (get_post_status() == 'private')
{
$return_str = $return_str . '(private)';
}
return $return_str;
}
//cuttitle
function title($max_length) {
$title_str = get_the_title();
if (mb_strlen($title_str,'utf-8') > $max_length ) {
$title_str = mb_substr($title_str,0,$max_length,'utf-8').'...';
}
return $title_str;
}
//分页
function pagenavi( $before = '', $after = '', $p = 2 ) {
if ( is_singular() ) return;
global $wp_query, $paged;
$max_page = $wp_query->max_num_pages;
if ( $max_page == 1 ) return;
if ( empty( $paged ) ) $paged = 1;
echo $before.'<div id="pagenavi">'."\n";
echo '<span class="pages">第' . $paged . '页 共' . $max_page . '页 </span>';
if ( $paged > 1 ) p_link( $paged - 1, '上一页', '«' );
if ( $paged > $p + 1 ) p_link( 1, '第一页' );
if ( $paged > $p + 2 ) echo '... ';
for( $i = $paged - $p; $i <= $paged + $p; $i++ ) {
if ( $i > 0 && $i <= $max_page ) $i == $paged ? print "<span class='page-numbers current'>{$i}</span>" : p_link( $i );
}
if ( $paged < $max_page - $p - 1 ) echo '... ';
if ( $paged < $max_page - $p ) p_link( $max_page, '最后一页' );
if ( $paged < $max_page ) p_link( $paged + 1,'下一页', '»' );
echo '</div>'.$after."\n";
}
function p_link( $i, $title = '', $linktype = '' ) {
if ( $title == '' ) $title = "第{$i}页";
if ( $linktype == '' ) { $linktext = $i; } else { $linktext = $linktype; }
echo "<a class='page-numbers' href='", esc_html( get_pagenum_link( $i ) ), "' title='{$title}'>{$linktext}</a>";
}
//密码保护提示
function password_hint( $c ){
global $post, $user_ID, $user_identity;
if ( empty($post->post_password) )
return $c;
if ( isset($_COOKIE['wp-postpass_'.COOKIEHASH]) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) == $post->post_password )
return $c;
if($hint = get_post_meta($post->ID, 'password_hint', true)){
$url = get_option('siteurl').'/wp-pass.php';
if($hint)
$hint = '密码提示:'.$hint;
else
$hint = "请输入您的密码";
if($user_ID)
$hint .= sprintf('欢迎进入,您的密码是:', $user_identity, $post->post_password);
$out = <<<END
<form method="post" action="$url">
<p>这篇文章是受保护的文章,请输入密码继续阅读:</p>
<div>
<label>$hint<br/>
<input type="password" name="post_password"/></label>
<input type="submit" value="输入密码" name="Submit"/>
</div>
</form>
END;
return $out;
}else{
return $c;
}
}
add_filter('the_content', 'password_hint');
//支持外链缩略图
if ( function_exists('add_theme_support') )
add_theme_support('post-thumbnails');
add_image_size('thumbnail', 450, 250, true);//分类页面的大图
add_image_size('medium', 140, 100, true);
// add_image_size('large', 110, 110, true);//分类页面的小图
add_image_size('largephoto', 230, 400, true);//photo页面的图片
add_image_size('bigphoto', 156, 156, true);//相关推荐的大图
add_image_size('largevideo', 230, 173, true);//video页面的图片
function catch_first_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){
$random = mt_rand(1, 20);
echo get_bloginfo ( 'stylesheet_directory' );
echo '/images/random/tb'.$random.'.jpg';
}
return $first_img;
}
//---------------缩略图----------------//
//----------获取优酷视频的图片URl-----------//
include("VideoUrlParser/VideoUrlParser.class.php");
class videclass{
const CHECK_URL_VALID = '/\[youku|tudou|56 id=\"(.*)\"|w=\"([0-9]*)\"\|h=\"([0-9]*)"\]/i';
//--------获取图片地址----------//
static public function parseimgurl($content){
$info = self::_video($content);
return $info['img'];
}
//---------获取数组-----------//
static public function parseinfo($content){
$info = self::_video($content);
return $info;
}
private function _video($content){
preg_match_all('/\[(youku|tudou|56|flash) (id=\"(.*)\"|url=\"(.*)\"|w=\"([0-9]*)\"|h=\"([0-9]*)\")\]/i',$content,$videconarr);
$vvideotype = $videconarr[1][0];//视频类型
$ykid = $videconarr[3][0];//播放id
$vidswf = $videconarr[4][0];//播放swf的url
// echo $vvideotype;
switch($vvideotype){
case 'youku':
$data = self::_youkuv($ykid);
break;
case 'tudou':
$data = self::_tudouv($ykid);
break;
case '56':
$data = self::_56video($ykid);
break;
case 'flash':
$data = self::_flashurl($vidswf);
break;
default:
$data = false;
}
return $data;
}
private function _youkuv($ykid){
$video_url = 'http://v.youku.com/v_show/id_'.$ykid.'.html';//优酷播放地址
$info = VideoUrlParser::parse($video_url);
return $info;
}
private function _tudouv($ykid){
$video_url = 'http://www.tudou.com/programs/view/'.$ykid.'/';//土豆播放地址
$info = VideoUrlParser::parse($video_url);
return $info;
}
private function _56video($ykid){
$video_url = 'http://www.56.com/u77/'.$ykid.'.html';//56视频播放地址
$info = VideoUrlParser::parse($video_url);
return $info;
}
//----如果直接输入swf地址的话不能获取图片在这里设置默认图片-----//
private function _flashurl($vidswf){
$info['swf'] = $vidswf;
$rand = rand(1,6);
$info['img'] = '/wp-content/themes/Nocower-Metro/ima
评论0
最新资源