Advertisement
Guest User

helper

a guest
Jan 18th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.98 KB | None | 0 0
  1. <?php
  2.  
  3. ######################################################################
  4. # social icon builder
  5. ######################################################################
  6.  
  7. if(!function_exists('avia_social_media_icons'))
  8. {
  9.     function avia_social_media_icons($args = array(), $echo = true, $post_data = array())
  10.     {
  11.         $icons = new avia_social_media_icons($args, $post_data);
  12.         if($echo)
  13.         {  
  14.             echo $icons->html();
  15.         }
  16.         else
  17.         {
  18.             return $icons->html();
  19.         }
  20.     }
  21. }
  22.  
  23.  
  24.  
  25. if(!class_exists('avia_social_media_icons'))
  26. {
  27.     class avia_social_media_icons
  28.     {
  29.         var $args;
  30.         var $post_data;
  31.         var $icons = array();
  32.         var $html  = "";
  33.         var $counter = 1;
  34.  
  35.         /*
  36.          * constructor
  37.          * initialize the variables necessary for all social media links
  38.          */
  39.  
  40.         function __construct($args = array(), $post_data = array())
  41.         {
  42.             $default_arguments = array('outside'=>'ul', 'inside'=>'li', 'class' => 'social_bookmarks', 'append' => '');
  43.             $this->args = array_merge($default_arguments, $args);
  44.  
  45.             $this->post_data = $post_data;
  46.  
  47.             $this->icons = apply_filters( 'avia_filter_social_icons', avia_get_option('social_icons') );
  48.         }
  49.  
  50.         /*
  51.          * function build_icon
  52.          * builds the html string for a single item, with a few options for special items like rss feeds
  53.          */
  54.  
  55.         function build_icon($icon)
  56.         {
  57.             global $avia_config;
  58.  
  59.             //special cases
  60.             switch($icon['social_icon'])
  61.             {
  62.                 case 'rss':  if(empty($icon['social_icon_link'])) $icon['social_icon_link'] = get_bloginfo('rss2_url'); break;
  63.                 case 'twitter':
  64.                 case 'dribbble':
  65.                 case 'vimeo':
  66.                 case 'behance':
  67.  
  68.                 if(strpos($icon['social_icon_link'], 'http') === false && !empty($icon['social_icon_link']))
  69.                 {
  70.                     $icon['social_icon_link'] = "http://".$icon['social_icon'].".com/".$icon['social_icon_link']."/";
  71.                 }
  72.                 break;
  73.             }
  74.  
  75.             if(empty($icon['social_icon_link'])) $icon['social_icon_link'] = "#";
  76.             $blank = "target='_blank'";
  77.            
  78.             //dont add target blank to relative urls or urls to the same dmoain
  79.             if(strpos($icon['social_icon_link'], 'http') === false || strpos($icon['social_icon_link'], home_url()) === 0) $blank = "";
  80.            
  81.             $html  = "";
  82.             $html .= "<".$this->args['inside']." class='".$this->args['class']."_".$icon['social_icon']." av-social-link-".$icon['social_icon']." social_icon_".$this->counter."'>";
  83.             $html .= "<a {$blank} href='".$icon['social_icon_link']."' ".av_icon_string($icon['social_icon'])." title='".ucfirst($icon['social_icon'])."'><span class='avia_hidden_link_text'>".ucfirst($icon['social_icon'])."</span></a>";
  84.             $html .= "</".$this->args['inside'].">";
  85.  
  86.             return $html;
  87.         }
  88.  
  89.         /*
  90.          * function html
  91.          * builds the html, based on the available icons
  92.          */
  93.  
  94.         function html()
  95.         {
  96.             if(!empty($this->icons))
  97.             {
  98.                 $this->html = "<".$this->args['outside']." class='noLightbox ".$this->args['class']." icon_count_".count($this->icons)."'>";
  99.  
  100.                 foreach ($this->icons as $icon)
  101.                 {
  102.                     if(!empty($icon['social_icon']))
  103.                     {
  104.                         $this->html .= $this->build_icon($icon);
  105.                         $this->counter ++;
  106.                     }
  107.                 }
  108.  
  109.                 $this->html .= $this->args['append'];
  110.                 $this->html .= "</".$this->args['outside'].">";
  111.             }
  112.  
  113.  
  114.             return $this->html;
  115.         }
  116.     }
  117. }
  118.  
  119.  
  120.  
  121.  
  122. ######################################################################
  123. # share link builder
  124. ######################################################################
  125.  
  126.  
  127. if(!class_exists('avia_social_share_links'))
  128. {
  129.     class avia_social_share_links
  130.     {
  131.         var $args;
  132.         var $options;
  133.         var $links = array();
  134.         var $html  = "";
  135.         var $counter = 0;
  136.        
  137.         /*
  138.          * constructor
  139.          * initialize the variables necessary for all social media links
  140.          */
  141.  
  142.         function __construct($args = array(), $options = false)
  143.         {
  144.             $default_arguments = array
  145.             (
  146.                 'facebook'  => array("encode"=>true, "encode_urls"=>false, "pattern" => "http://www.facebook.com/sharer.php?u=[permalink]&amp;t=[title]"),
  147.                 'twitter'   => array("encode"=>true, "encode_urls"=>false, "pattern" => "https://twitter.com/share?text=[title]&url=[shortlink]"),
  148.                 'gplus'     => array("encode"=>true, "encode_urls"=>false, "pattern" => "https://plus.google.com/share?url=[permalink]" , 'label' => __("Share on Google+",'avia_framework')),
  149.                 'pinterest' => array("encode"=>true, "encode_urls"=>true, "pattern" => "http://pinterest.com/pin/create/button/?url=[permalink]&amp;description=[title]&amp;media=[thumbnail]"),
  150.                 'linkedin'  => array("encode"=>true, "encode_urls"=>false, "pattern" => "http://linkedin.com/shareArticle?mini=true&amp;title=[title]&amp;url=[permalink]"),
  151.                 'tumblr'    => array("encode"=>true, "encode_urls"=>true, "pattern" => "http://www.tumblr.com/share/link?url=[permalink]&amp;name=[title]&amp;description=[excerpt]"),
  152.                 'vk'        => array("encode"=>true, "encode_urls"=>false, "pattern" => "http://vk.com/share.php?url=[permalink]"),
  153.                 'reddit'    => array("encode"=>true, "encode_urls"=>false, "pattern" => "http://reddit.com/submit?url=[permalink]&amp;title=[title]"),
  154.                 'mail'      => array("encode"=>true, "encode_urls"=>false, "pattern" => "mailto:?subject=[title]&amp;body=[permalink]", 'label' => __("Share by Mail",'avia_framework') ),
  155.             );
  156.            
  157.             $this->args = array_merge($default_arguments, apply_filters( 'avia_social_share_link_arguments', $args));
  158.            
  159.             if(empty($options)) $options = avia_get_option();
  160.             $this->options = $options;
  161.             $this->build_share_links();
  162.         }
  163.        
  164.         /*
  165.          * filter social icons that are disabled in the backend. everything that is left will be displayed.
  166.          * that way the user can hook into the "avia_social_share_link_arguments" filter above and add new social icons without the need to add a new backend option
  167.          */
  168.         function build_share_links()
  169.         {
  170.             $thumb                  = wp_get_attachment_image_src( get_post_thumbnail_id(), 'masonry' );
  171.             $replace['permalink']   = !isset($this->post_data['permalink']) ? get_permalink() : $this->post_data['permalink'];
  172.             $replace['title']       = !isset($this->post_data['title']) ? get_the_title() : $this->post_data['title'];
  173.             $replace['excerpt']     = !isset($this->post_data['excerpt']) ? get_the_excerpt() : $this->post_data['excerpt'];
  174.             $replace['shortlink']   = !isset($this->post_data['shortlink']) ? wp_get_shortlink() : $this->post_data['shortlink'];
  175.             $replace['thumbnail']   = is_array($thumb) && isset($thumb[0]) ? $thumb[0] : "";
  176.             $replace['thumbnail']   = !isset($this->post_data['thumbnail']) ? $replace['thumbnail'] : $this->post_data['thumbnail'];
  177.            
  178.             $replace = apply_filters('avia_social_share_link_replace_values', $replace);
  179.             $charset = get_bloginfo('charset');
  180.            
  181.             foreach($this->args as $key => $share)
  182.             {
  183.                 $share_key  = 'share_'.$key;
  184.                 $url        = $share['pattern'];
  185.                
  186.                 //if the backend option is disabled skip to the next link. in any other case generate the share link
  187.                 if(isset($this->options[$share_key]) && $this->options[$share_key] == 'disabled' ) continue;
  188.                
  189.                 foreach($replace as $replace_key => $replace_value)
  190.                 {
  191.                     if(!empty($share['encode']) && $replace_key != 'shortlink' && $replace_key != 'permalink') $replace_value = rawurlencode(html_entity_decode($replace_value, ENT_QUOTES, $charset));
  192.                     if(!empty($share['encode_urls']) && ($replace_key == 'shortlink' || $replace_key == 'permalink')) $replace_value = rawurlencode(html_entity_decode($replace_value, ENT_QUOTES, $charset));
  193.                    
  194.                     $url = str_replace("[{$replace_key}]", $replace_value, $url);
  195.                 }
  196.                
  197.                 $this->args[$key]['url'] = $url;
  198.                 $this->counter ++;
  199.             }
  200.         }
  201.        
  202.        
  203.        
  204.         /*
  205.          * function html
  206.          * builds the html, based on the available urls
  207.          */
  208.  
  209.         function html()
  210.         {
  211.             global $avia_config;
  212.            
  213.             if($this->counter == 0) return;
  214.            
  215.             $this->html .= "<div class='av-share-box'>";
  216.             $this->html .=      "<h5 class='av-share-link-description'>";
  217.             $this->html .=  apply_filters('avia_social_share_title', __("Share this entry",'avia_framework'), $this->args);
  218.             $this->html .=      "</h5>";
  219.             $this->html .=      "<ul class='av-share-box-list noLightbox'>";
  220.            
  221.             foreach($this->args as $key => $share)
  222.             {
  223.                 if(empty($share['url'])) continue;
  224.            
  225.                 $icon = isset($share['icon']) ? $share['icon'] : $key;
  226.                 $name = isset($share['label'])? $share['label']: __("Share on",'avia_framework'). " " .ucfirst($key);
  227.                
  228.                 $blank = strpos($share['url'], 'mailto') !== false ? "" : "target='_blank'";
  229.                
  230.                 $this->html .= "<li class='av-share-link av-social-link-{$key}' >";
  231.                 $this->html .=      "<a {$blank} href='".$share['url']."' ".av_icon_string($icon)." title='' data-avia-related-tooltip='{$name}'><span class='avia_hidden_link_text'>{$name}</span></a>";
  232.                 $this->html .= "</li>";
  233.             }
  234.            
  235.             $this->html .=      "</ul>";
  236.             $this->html .= "</div>";
  237.            
  238.             return $this->html;
  239.         }
  240.        
  241.        
  242.        
  243.        
  244.     }
  245. }
  246.  
  247.  
  248.  
  249.  
  250.  
  251. if(!function_exists('avia_social_share_links'))
  252. {
  253.     function avia_social_share_links($args = array(), $echo = true)
  254.     {
  255.         $icons = new avia_social_share_links($args);
  256.        
  257.         if($echo)
  258.         {  
  259.             echo $icons->html();
  260.         }
  261.         else
  262.         {
  263.             return $icons->html();
  264.         }
  265.     }
  266. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement