Advertisement
Guest User

functions

a guest
Oct 25th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.99 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 1);
  3. define('THEME_INCLUDE',TEMPLATEPATH.'/include/');
  4. define('THUMB',get_template_directory_uri().'/include/thumbnailer.php');
  5.  
  6. $themename = "Hasmi";  
  7. $shortname = "hasmi";
  8.  
  9. add_theme_support('menus');
  10. add_theme_support('automatic-feed-links');
  11. add_editor_style('editor-style.css');
  12. add_theme_support('post-thumbnails');
  13.  
  14. /* Requiring Files */
  15. require_once(THEME_INCLUDE.'shortcodes.php');
  16. require_once(THEME_INCLUDE.'hijri.php');
  17. require_once(THEME_INCLUDE.'social-widget.php');
  18. require_once(THEME_INCLUDE.'BFI_Thumb.php');
  19. // require_once(THEME_INCLUDE.'facebook-widget.php');
  20. // require_once(THEME_INCLUDE.'instagram-widget.php');
  21. // require_once(THEME_INCLUDE.'flickr-widget.php');
  22. // require_once(THEME_INCLUDE.'twitter-widget.php');
  23. // require_once(THEME_INCLUDE.'twitteroauth/twitteroauth.php'); // grab twitteroauth from correct place
  24.  
  25. if(is_admin()){
  26.   require_once(THEME_INCLUDE.'generate-metabox.php');
  27.   require_once(THEME_INCLUDE.'generate-metabox2.php');
  28.   require_once(THEME_INCLUDE.'theme-options.php');
  29.   require_once(THEME_INCLUDE.'settings/metabox-settings.php');
  30.   require_once(THEME_INCLUDE.'settings/theme-settings.php');
  31. }
  32. // Registering Widget
  33. register_widget('social_icons');
  34. // register_widget('facebook_like');
  35. // register_widget('instagram_images');
  36. // register_widget('flickr_images');
  37. // register_widget('tweet_widget');
  38.  
  39. add_theme_support('menus');
  40. add_theme_support('automatic-feed-links');
  41. add_editor_style('editor-style.css');
  42. add_theme_support('post-thumbnails');
  43.  
  44. /* Registering Sidebars */
  45. if (function_exists('register_sidebar')){
  46.     register_sidebar(
  47.         array(
  48.             'id'=>'sidebar',
  49.             'name'=>'Sidebar',
  50.             'before_widget' => '<div id="%1$s" class="group style1 widget %2$s"><div class="group-content">',
  51.             'after_widget' => '</div></div>',
  52.             'before_title' => '<div class="group-title"><h2 class="widgettitle">',
  53.             'after_title' => '</h2></div>'
  54.         )
  55.     );
  56.     register_sidebar(
  57.         array(
  58.             'id'=>'footer1',
  59.             'name'=>'Footer 1',
  60.             'before_widget' => '<div id="%1$s" class="widget %2$s">',
  61.             'after_widget' => '</div>',
  62.             'before_title' => '<h2 class="widgettitle">',
  63.             'after_title' => '</h2>'
  64.         )
  65.     );
  66.     register_sidebar(
  67.         array(
  68.             'id'=>'footer2',
  69.             'name'=>'Footer 2',
  70.             'before_widget' => '<div id="%1$s" class="widget %2$s">',
  71.             'after_widget' => '</div>',
  72.             'before_title' => '<h2 class="widgettitle">',
  73.             'after_title' => '</h2>'
  74.         )
  75.     );
  76.     register_sidebar(
  77.         array(
  78.             'id'=>'footer3',
  79.             'name'=>'Footer 3',
  80.             'before_widget' => '<div id="%1$s" class="widget %2$s">',
  81.             'after_widget' => '</div>',
  82.             'before_title' => '<h2 class="widgettitle">',
  83.             'after_title' => '</h2>'
  84.         )
  85.     );
  86.     register_sidebar(
  87.         array(
  88.             'id'=>'floatingbanner',
  89.             'name'=>'Floating Banner',
  90.             'before_widget' => '<span>',
  91.             'after_widget' => '</span>'
  92.         )
  93.     );
  94. };
  95.  
  96.  
  97. /**********************************
  98.  *   Theme Menu
  99.  **********************************/
  100. function theme_menu($loc='',$id='',$class=''){
  101.   if (function_exists('wp_nav_menu') && has_nav_menu($loc))
  102.   wp_nav_menu(array(
  103.       'theme_location' => $loc,
  104.       'container' => '',
  105.       'menu_class' => $class,
  106.       'menu_id' => $id
  107.   ));
  108. }
  109. if (function_exists('register_nav_menu'))
  110.   register_nav_menus(array(
  111.       'primary_menu'=>'Primary Menu',
  112.       'secondary_menu'=>'Secondary Menu',
  113.       'footer_menu'=>'Footer Menu'
  114.   )
  115. );
  116.  
  117. /*******************************
  118.  * pagination
  119.  ********************************/
  120. function theme_pagination($pages = '', $range = 2){  
  121.     global $paged;
  122.  
  123.     $showitems = ($range * 2)+1;
  124.  
  125.     if(empty($paged)) $paged = 1;
  126.  
  127.     if($pages == ''){
  128.         global $wp_query;
  129.         $pages = $wp_query->max_num_pages;
  130.         if(!$pages) { $pages = 1; }
  131.     }  
  132.  
  133.     if(1 != $pages){
  134.         echo "<div id='pagination'>";
  135.         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
  136.         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";
  137.  
  138.         for ($i=1; $i <= $pages; $i++){
  139.             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){
  140.                 echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
  141.             }
  142.         }
  143.  
  144.         if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";  
  145.         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
  146.         echo "</div>\n";
  147.     }
  148. }
  149.  
  150.  
  151. /****************************************
  152.  *  Get Real Image Path, needed on WPMU
  153.  ****************************************/
  154. function get_image_path ($theImageSrc) {
  155.     if (isset($blog_id) && $blog_id > 0) {
  156.         $imageParts = explode('/files/', $theImageSrc);
  157.         if (isset($imageParts[1])) {
  158.             $theImageSrc = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
  159.         }
  160.     }
  161.     return $theImageSrc;
  162. }
  163.  
  164. /***************************************
  165.  * Smart Post Image  
  166.  ***************************************/
  167. function post_image($first=true){
  168.     global $post;
  169.  
  170.     $image='';
  171.     $image_id = get_post_thumbnail_id($post->ID);
  172.     $image = get_image_path(wp_get_attachment_image_src($image_id,"full"));
  173.     $firstimage=get_first_image();
  174.  
  175.     $image = $image[0];
  176.  
  177.     // if(get_option('hasmi_video_thumb') && get_post_meta( $post->ID, "video_link") ) {
  178.     //     $link = get_post_meta( $post->ID, "video_link");
  179.     //     $image = video_image($link[0]);
  180.     // }
  181.     if ($image) {
  182.         return $image;
  183.     } elseif(!empty($firstimage) && $first != false) {
  184.         return $firstimage;
  185.     } else{
  186.       return false;
  187.     }
  188.  
  189. }
  190. /*************************************
  191.  * Get first image from post
  192.  *************************************/
  193. function get_first_image(){
  194.   global $post, $posts;
  195.  
  196.   $first_img = '';
  197.  
  198.   ob_start();
  199.   ob_end_clean();
  200.  
  201.   $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  202.   $first_img="";
  203.  
  204.   if(isset($matches[1][0])) $first_img = $matches[1][0];
  205.  
  206.   return $first_img;
  207. }
  208.  
  209. /***************************************
  210.  * Comment list callback function
  211.  ***************************************/
  212.  
  213. function theme_comments($comment, $args, $depth) {
  214.     $GLOBALS['comment'] = $comment; ?>
  215.     <li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
  216.         <article class="comment-inner">
  217.               <?php echo get_avatar($comment,$size='68'); ?>
  218.  
  219.           <footer class="comment-meta">
  220.             <div class="comment-author vcard clearfix">
  221.               <span class="fn"><?php comment_author_link()?></span>
  222.               <a href=""><time><?php comment_date('j M Y'); ?></time></a>
  223.             </div>
  224.             <div class="reply">
  225.               <?php comment_reply_link( array_merge( $args, array('reply_text' => 'Reply', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  226.             </div>
  227.           </footer>
  228.           <div class="comment-content">
  229.             <?php if ($comment->comment_approved == '0') : ?>
  230.                 <p><em>Your comment will appear here once it moderated by Administrator</em></p>
  231.             <?php endif; ?>
  232.             <?php echo get_comment_text(); ?>
  233.           </div>
  234.        </article>
  235.  
  236. <?php
  237. }
  238.  
  239. /* Limit generated words */
  240. function string_limit_words($string, $word_limit)
  241. {
  242.   $words = explode(' ', $string, ($word_limit + 1));
  243.   if(count($words) > $word_limit) array_pop($words);
  244.  
  245.   return implode(' ', $words);
  246. }
  247.  
  248.  
  249. /* Custom Excerpt Length */
  250. function custom_excerpt_length( $length ) { return 20; }
  251. add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
  252.  
  253. /* Custom Exceprt More text */
  254. function new_excerpt_more( $more ) { return '...'; }
  255. add_filter('excerpt_more', 'new_excerpt_more');
  256.  
  257. // add_filter('widget_text', 'do_shortcode');
  258.  
  259. function remove_silly_dot($title){
  260.   return str_replace(array(".::","."), "", $title);
  261. }
  262. add_filter("the_title",'remove_silly_dot');
  263.  
  264. /* tinyMCE Custom Button */
  265. function tiny_button( $hook ) {
  266.   if( $hook == 'post.php' || $hook == 'post-new.php' ) {
  267.     wp_register_script( 'tinymce_scripts', get_template_directory_uri().'/include/tinymce/js/scripts.js', "",false, true );
  268.     wp_enqueue_script('tinymce_scripts');
  269.   }
  270. }
  271. add_action('admin_enqueue_scripts', 'tiny_button');
  272. /* Including scripts safely */
  273. function js_theme() {
  274.     wp_register_script( 'bootstrap', get_template_directory_uri().'/js/bootstrap.js', "", null, true);
  275.     // wp_register_script( 'google-map',"http://maps.google.com/maps/api/js?sensor=false&amp;language=en", "", null, true);
  276.     wp_register_script( 'fancy', get_template_directory_uri()."/js/jquery.fancybox.pack.js", "", null, true );
  277.     wp_register_script( 'fancymedia', get_template_directory_uri()."/js/jquery.fancybox-media.js", "", null, true );
  278.    
  279.     wp_register_script('theme_plugins', get_template_directory_uri().'/js/plugins.js', "", null, true);
  280.     wp_enqueue_script( array('jquery','bootstrap','theme_plugins','fancy','fancymedia' ));
  281. }
  282. add_action('wp_enqueue_scripts', 'js_theme');
  283.  
  284.  
  285. function quoteslider(){
  286.   $i=1;
  287.   while($i<=5){
  288.     $quote = get_option("hasmi_quote$i");
  289.     if(!empty($quote)){
  290.       $quotes[]=array(
  291.               "quote"=>get_option("hasmi_quote$i"),
  292.               "cite"=>get_option("hasmi_cite$i")
  293.           );
  294.     }
  295.     $i++;
  296.   }
  297.   echo "<div id='quote-container'>";
  298.   echo '<ul id="quote-list" class="bjqs">';
  299.   foreach($quotes as $quote): ?>
  300.      <li>
  301.        <blockquote>
  302.          <p><?php echo $quote["quote"] ?></p>
  303.          <cite>- <?php echo $quote["cite"] ?></cite>
  304.        </blockquote>
  305.      </li>
  306.   <?php endforeach;
  307.   echo '</ul>';
  308.   echo '</div>';
  309. }
  310.  
  311. function hot_news(){
  312.   query_posts(array("post_type"=>"post","posts_per_page"=>5));
  313.   while(have_posts()) : the_post(); ?>
  314.     <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  315.   <?php
  316.   endwhile;
  317.   wp_reset_query();
  318. }
  319.  
  320. function fbfan($pageid) {
  321.   $data = file_get_contents('http://graph.facebook.com/' . $pageid);
  322.   if($data){
  323.     $info = json_decode($data);
  324.     return $info->likes;
  325.   }else{
  326.     return false;
  327.   }
  328. }
  329.  
  330.  
  331. function twitterCounts($username){
  332.  
  333.   // WordPress Transient API Caching
  334.   $cacheKey = $username . '-cache';
  335.   $cached = get_transient($cacheKey);
  336.   if (false !== $cached)
  337.     {return $cached;}
  338.  
  339.   // Call and instantiate twitterOAuth. Modify the path to where you uploaded twitteroauth
  340.   require_once (THEME_INCLUDE.'/twitteroauth/twitteroauth.php');
  341.  
  342.   // Replace the four parameters below with the information from your Twitter developer application.
  343.   $twitterConnection = new TwitterOAuth(get_option("hasmi_twitter_consumer_key"),get_option("hasmi_twitter_consumer_secret"),get_option("hasmi_twitter_access_token"), get_option("hasmi_twitter_access_token_secret"));
  344.  
  345.   // Send the API request
  346.   $twitterData = $twitterConnection->get('users/show', array('screen_name' => $username));
  347.  
  348.   // Extract the follower and tweet counts
  349.   $followerCount = $twitterData->followers_count;
  350.   $tweetCount = $twitterData->statuses_count;
  351.  
  352.   $output = $followerCount . " followers, " . $tweetCount . " tweets";
  353.   set_transient($cacheKey,$output,3600);
  354.   return $output;
  355. }
  356.  
  357. function localize_day($date){
  358.     $hari = array(1=>"Senin","Selasa","Rabu","Kamis","Jum'at","Sabtu","Ahad");
  359.     $day = date("N",$date);
  360.     return $hari[$day];
  361. }
  362.  
  363. function get_latest_youtube ($channel,$limit) {
  364.         // error_reporting(E_ALL);
  365.         $feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $channel . '/uploads?max-results='.$limit.'&v=2&alt=jsonc';
  366.        // $sxml = simplexml_load_file($feedURL);
  367.     $json = file_get_contents($feedURL,0,null,null);
  368.         $json_output = json_decode($json,true);
  369.         if($json_output ){
  370.         foreach ($json_output["data"]["items"] as $entry) {
  371.            
  372.  
  373.             $data[]=array(
  374.                 "id"=>$entry["id"],
  375.                 "url"=>$entry["player"]["default"],
  376.                 "thumbnail"=>"http://i1.ytimg.com/vi/".$entry["id"]."/0.jpg",
  377.                 "title"=>$entry["title"],
  378.                 "desc"=>$entry["description"],
  379.                 "watch"=>"http://www.youtube.com/watch?v=".$entry["id"]
  380.               );
  381.  
  382.              
  383.         }
  384.  
  385.         return $data;
  386.         }else{return false;}
  387. }
  388.  
  389. function resize_image($url,$w,$h){
  390.     $params = array( 'width' => $w,'height'=>$h, 'crop'=>true );
  391.     $image = bfi_thumb( $url, $params );
  392.     return $image;
  393.   // return THUMB."?src=".$url."&w=".$w."&h=".$h."&zc=1";
  394. }
  395. // function test(){
  396. //     return "http://www.hasmi.org/wp-content/uploads/2013/11/Mar%E2%80%99atush-Shalihah.jpg";
  397. // }
  398. // $test = test();
  399. // echo resize_image($test,20,20);
  400.  
  401. /* Background pattern */
  402. function custom_background(){
  403.   global $shortname;
  404.     $backgroundsrc=get_template_directory_uri()."/images/patterns/";
  405.     $backgroundpattern=get_option($shortname.'_backgroundpattern');
  406.     $backgroundcolor=get_option($shortname.'_backgroundcolor');
  407.  
  408.     if($backgroundpattern && $backgroundpattern !== "no-pattern"){
  409.         $bodyback='background-image:url("'.$backgroundsrc.$backgroundpattern.'.png") !important;';
  410.     }else{
  411.       $bodyback='background-image:none !important;';
  412.     }
  413.     if($backgroundcolor){
  414.         $bodycolr='background-color:'.$backgroundcolor.' !important;';
  415.     }
  416.  
  417.     echo "<style>";
  418.     echo "body{";
  419.     echo $bodyback;
  420.     echo $bodycolr;
  421.     echo "}";
  422.     echo $headercolr;
  423.     echo "</style>";
  424.  
  425. }
  426.  
  427. function get_tweet($user_name="",$limit=5){
  428.  
  429.  
  430.     $screen_name = $user_name; // my twitter username
  431.     $number_of_tweets = $limit; // how many do I want?
  432.      
  433.     $consumerkey = get_option("hasmi_twitter_consumer_key");//"THHJbiXcFZn5JszuH6kSLQ";
  434.     $consumersecret = get_option("hasmi_twitter_consumer_secret");//"7uuxDcEyGDYHMzndRP3pLlcCUEU1I6TDSmGINBhCJY";
  435.     $accesstoken = get_option("hasmi_twitter_access_token");//"275397346-xcq8qLgdRU4Gte2RisTv2ivxyEl5H4WHUoa7x8ux";
  436.     $accesstokensecret = get_option("hasmi_twitter_access_token_secret");//"lUzdmDGZ8nnsWd743LNlIEhXZq7AtMAkKL8nsIs7xqoe2";
  437.      
  438.     $twitterconn = new TwitterOAuth($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
  439.      
  440.     $latesttweets = $twitterconn->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$screen_name."&count=".$number_of_tweets);
  441.      
  442.      
  443.     echo "<ul>";
  444.     foreach($latesttweets as $tweet){ ?>
  445.         <li><p><?php echo preg_replace('/http:\/\/([a-z0-9_\.\-\+\&\!\#\~\/\,]+)/i', '<a href="http://$1" target="_blank">http://$1</a>', $tweet->text);  ?></p></li>
  446.     <?php    
  447.     }
  448.      echo "</ul>";
  449. }
  450.  
  451. add_filter('widget_text', 'do_shortcode');
  452.  
  453. // wp_list_bookmarks();
  454. // if(function_exists("wp_list_bookmarks")){
  455. //   $args = array(
  456. //       "category_name"=>"sponsor",
  457. //       "categorize"=>0,
  458. //       "title_li"=>null,
  459. //       "show_images"=>true
  460. //   );
  461. //   wp_list_bookmarks($args);
  462. // }
  463.  
  464. function get_partner_links($args){
  465.  
  466.   ob_start();
  467.   wp_list_bookmarks($args);
  468.   return $ouput = ob_get_clean();  
  469. }
  470.  
  471. /*function insert_fb_in_head()
  472. {
  473.  
  474.         if (is_singular()) {
  475.             $image = resize_image(post_image(true),200,200);
  476.             $title = get_the_title();
  477.             $type = 'article';
  478.         }
  479.         else {
  480.             $image = get_template_directory_uri()."/images/logo.png";
  481.             $title = bloginfo('name');
  482.             $type = 'blog';
  483.         }
  484.         echo '<meta property="og:image" content="' . $image . '"/>';
  485. }
  486. add_action( 'wp_head', 'insert_fb_in_head', 5 );*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement