'upsidebar',
'before_widget' => '
',
'after_widget' => '',
'before_title' => '',
));
if (function_exists('register_sidebar'))
register_sidebar(array(
'name' => 'lowsidebar',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '
',
));
function se(){
$ref = $_SERVER['HTTP_REFERER'];
$SE = array('.google.','.bing.','.yahoo.','.baidu.','.soso.','youdao.','sogou.','ask.','blogbus.','chinablogs.','renren.','qq.');
foreach ($SE as $source) {
if (strpos($ref,$source)!==false) return true;
}
return false;
}
function cut_str($str, $len) {
if (!isset($str[$len])) {
} else {
if (seems_utf8($str[$len-1]))
$str = substr($str, 0, $len);
else {
if(seems_utf8($str[$len-3].$str[$len-2].$str[$len-1]))
$str = substr($str, 0, $len-3) . $str[$len-3] . $str[$len-2] . $str[$len-1];
elseif(seems_utf8($str[$len-2].$str[$len-1].$str[$len]))
$str = substr($str, 0, $len-2) . $str[$len-2].$str[$len-1].$str[$len];
elseif(seems_utf8($str[$len-1].$str[$len].$str[$len+1]))
$str = substr($str, 0, $len-1) . $str[$len-1].$str[$len].$str[$len+1];
else
$str = substr($str, 0, $len);
}
}
return $str;
}
function bluepaled_get_related_posts($before_title="",$after_title="") {
//$options = QiqiboyOptions::getOptions();
global $wpdb, $post,$table_prefix;
if ( $exclude != '' ) {
$q = 'SELECT tt.term_id FROM '. $table_prefix .'term_taxonomy tt, ' . $table_prefix . 'term_relationships tr WHERE tt.taxonomy = \'category\' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id = '.$post->ID;
$cats = $wpdb->get_results($q);
foreach(($cats) as $cat) {
if (in_array($cat->term_id, $exclude) != false){
return;
}
}
}
if(!$post->ID){return;}
$now = current_time('mysql', 1);
$tags = wp_get_post_tags($post->ID);
$taglist = "'" . $tags[0]->term_id. "'";
$tagcount = count($tags);
if ($tagcount > 1) {
for ($i = 1; $i < $tagcount; $i++) {
$taglist = $taglist . ", '" . $tags[$i]->term_id . "'";
}
}
$limitclause = "LIMIT 5";
$q = "SELECT p.ID, p.post_title, p.post_content,p.post_excerpt, p.post_date, p.comment_count, count(t_r.object_id) as cnt FROM $wpdb->term_taxonomy t_t, $wpdb->term_relationships t_r, $wpdb->posts p WHERE t_t.taxonomy ='post_tag' AND t_t.term_taxonomy_id = t_r.term_taxonomy_id AND t_r.object_id = p.ID AND (t_t.term_id IN ($taglist)) AND p.ID != $post->ID AND p.post_status = 'publish' AND p.post_date_gmt < '$now' GROUP BY t_r.object_id ORDER BY cnt DESC, p.post_date_gmt DESC $limitclause;";
$related_posts = $wpdb->get_results($q);
$output = "";
$wp_rl_title= __("Related Posts",'bluepaled');
if (!$related_posts){
$wp_rl_title= __("Most Commented Posts",'bluepaled');
$related_posts = bluepaled_get_most_commented_posts($limitclause);
}
foreach ($related_posts as $related_post ){
$output .= '';
$output .= ''.wptexturize($related_post->post_title).'';
$output .= " (" . $related_post->comment_count . ")";
$wp_rp_except_number = 240;
if($related_post->post_excerpt && strlen(strip_tags($related_post->post_excerpt)) > 150){
$output .= '
'.(cut_str(strip_tags($related_post->post_excerpt),$wp_rp_except_number)).'...';
}else{
$output .= '
'.(cut_str(strip_tags($related_post->post_content),$wp_rp_except_number)).'...';
}
$output .= '';
}
$output = '';
$output = ''.$wp_rl_title.'
'. $output;
return $output;
}
function bluepaled12_related_posts(){
$output = bluepaled_get_related_posts() ;
echo $output;
}
function bluepaled_related_posts() {
bluepaled12_related_posts();
}
function bluepaled_get_random_posts ($limitclause="") {
global $wpdb, $tableposts, $post;
$q = "SELECT ID, post_title, post_content,post_excerpt, post_date, comment_count FROM $tableposts WHERE post_status = 'publish' AND post_type = 'post' AND ID != $post->ID ORDER BY RAND() $limitclause";
return $wpdb->get_results($q);
}
function bluepaled_random_posts ($number = 10){
$limitclause="LIMIT " . $number;
$random_posts = bluepaled_get_random_posts ($limitclause);
foreach ($random_posts as $random_post ){
$output .= '';
$output .= ''.wptexturize($random_post->post_title).'';
}
$output = '';
echo $output;
}
function head_random_posts ($number = 1){
$limitclause="LIMIT " . $number;
$random_posts = bluepaled_get_random_posts ($limitclause);
foreach ($random_posts as $random_post ){
$output .= '';
}
echo $output;
}
function bluepaled_get_most_commented_posts($limitclause="") {
global $wpdb;
$q = "SELECT ID, post_title, post_content, post_excerpt, post_date, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts, $wpdb->comments WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish' GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC $limitclause";
return $wpdb->get_results($q);
}
function bluepaled_most_commented_posts ($number = 10){
$limitclause="LIMIT " . $number;
$most_commented_posts = bluepaled_get_most_commented_posts ($limitclause);
foreach ($most_commented_posts as $most_commented_post ){
$output .= '';
$output .= ''.wptexturize($most_commented_post->post_title).'('.wptexturize($most_commented_post->comment_count).')';
}
$output = '';
echo $output;
}
function wp_bluepaled_comments_get ($limitclause=""){
global $wpdb;
$q = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved,comment_author_email, comment_type,comment_author_url, SUBSTRING(comment_content,1,19) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND comment_author != 'Your name' AND post_password = '' ORDER BY comment_date_gmt DESC $limitclause";
return $wpdb->get_results($q);
}
function wp_bluepaled_comments ($number = 8){
$limitclause="LIMIT " . $number;
$comments = wp_bluepaled_comments_get ($limitclause);
$output = $pre_HTML;
foreach ($comments as $comment) {
$output .= "".get_avatar($comment->comment_author_email, 16)."ID) . "#comment-" . $comment->comment_ID . "\" title=\"comments on [" . $comment->post_title . " ]\">". strip_tags($comment->comment_author) .": ". strip_tags($comment->com_excerpt) ."...";
}
$output .= $post_HTML;
$output = convert_smilies($output);
echo $output;
}