Advertisement
Guest User

Untitled

a guest
Jun 15th, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.08 KB | None | 0 0
  1. <?php
  2. /**
  3. * 2 classes to manage social media icons and share entry links
  4. * ============================================================
  5. *
  6. */
  7. if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly
  8.  
  9.  
  10. if( ! class_exists( 'avia_social_media_icons' ) )
  11. {
  12. /**
  13. * Social Media Icon builder
  14. *
  15. * @since ???
  16. */
  17. class avia_social_media_icons
  18. {
  19. /**
  20. * @since < 4.0
  21. * @var array
  22. */
  23. protected $args;
  24.  
  25. /**
  26. * @since < 4.0
  27. * @var array
  28. */
  29. protected $post_data;
  30.  
  31. /**
  32. * @since < 4.0
  33. * @var array
  34. */
  35. protected $icons;
  36.  
  37. /**
  38. * @since < 4.0
  39. * @var string
  40. */
  41. protected $html;
  42.  
  43. /**
  44. * @since < 4.0
  45. * @var int
  46. */
  47. protected $counter;
  48.  
  49.  
  50. /**
  51. * Initialize the variables necessary for all social media links
  52. *
  53. * @since < 4.0
  54. * @param array $args
  55. * @param array $post_data
  56. */
  57. public function __construct( $args = array(), $post_data = array() )
  58. {
  59. $default_arguments = array(
  60. 'outside' => 'ul',
  61. 'inside' => 'li',
  62. 'class' => 'social_bookmarks',
  63. 'append' => ''
  64. );
  65.  
  66. $this->args = array_merge( $default_arguments, $args );
  67.  
  68. $this->post_data = $post_data;
  69. $this->icons = apply_filters( 'avia_filter_social_icons', avia_get_option( 'social_icons' ) );
  70. $this->html = '';
  71. $this->counter = 1;
  72.  
  73. $this->validate_urls();
  74. }
  75.  
  76. /**
  77. * @since 4.5.6
  78. */
  79. public function __destruct()
  80. {
  81. unset( $this->args );
  82. unset( $this->post_data );
  83. unset( $this->icons );
  84. }
  85.  
  86. /**
  87. * Returns the array of social icons defined in theme options (or filtered on creating class)
  88. *
  89. * @since 4.8.3
  90. * @return array
  91. */
  92. public function get_icons()
  93. {
  94. return $this->icons;
  95. }
  96.  
  97. /**
  98. * Returns the social profile info from theme options settings
  99. *
  100. * @since 4.8.3
  101. * @param string $key
  102. * @return array|false
  103. */
  104. public function get_icon( $key )
  105. {
  106. foreach( $this->icons as $icon )
  107. {
  108. if( isset( $icon['social_icon'] ) && $key == $icon['social_icon'] )
  109. {
  110. return $icon;
  111. }
  112. }
  113.  
  114. return false;
  115. }
  116.  
  117. /**
  118. * Handle special URL cases
  119. *
  120. * @since 4.8.3
  121. */
  122. protected function validate_urls()
  123. {
  124. foreach ( $this->icons as &$icon )
  125. {
  126. switch( $icon['social_icon'] )
  127. {
  128. case 'rss':
  129. if( empty( $icon['social_icon_link'] ) )
  130. {
  131. $icon['social_icon_link'] = get_bloginfo( 'rss2_url' );
  132. }
  133. break;
  134. case 'twitter':
  135. case 'dribbble':
  136. case 'vimeo':
  137. case 'behance':
  138. if( strpos( $icon['social_icon_link'], 'http' ) === false && ! empty( $icon['social_icon_link'] ) )
  139. {
  140. /**
  141. * Protocoll changed with 4.5.6 to https. Allow to filter in case http is needed
  142. *
  143. * @since 4.5.6
  144. * @return string
  145. */
  146. $protocol = apply_filters( 'avf_social_media_icon_protocol', 'https', $icon );
  147. $icon['social_icon_link'] = "{$protocol}://{$icon['social_icon']}.com/{$icon['social_icon_link']}/";
  148. }
  149. break;
  150. }
  151. }
  152.  
  153. unset( $icon );
  154. }
  155.  
  156. /**
  157. * Builds the html string for a single item, with a few options for special items like rss feeds
  158. *
  159. * @since < 4.0
  160. * @param array $icon
  161. * @return string
  162. */
  163. protected function build_icon( $icon )
  164. {
  165. global $avia_config;
  166.  
  167. $display_name = ucfirst( $icon['social_icon'] );
  168. if( ! empty( $avia_config['font_icons'][ $icon['social_icon'] ]['display_name'] ) )
  169. {
  170. $display_name = $avia_config['font_icons'][ $icon['social_icon'] ]['display_name'];
  171. }
  172.  
  173. $aria_label = sprintf( __( 'Link to %s', 'avia_framework' ), $display_name );
  174.  
  175. if( 'rss' == $icon['social_icon'] )
  176. {
  177. $aria_label .= ' ' . __( ' this site', 'avia_framework' );
  178. }
  179.  
  180. if( empty( $icon['social_icon_link'] ) )
  181. {
  182. $icon['social_icon_link'] = '#';
  183. }
  184.  
  185. //dont add target blank to relative urls or urls to the same domain
  186. $blank = ( strpos( $icon['social_icon_link'], 'http') === false || strpos( $icon['social_icon_link'], home_url() ) === 0 ) ? '' : ' target="_blank"';
  187.  
  188. /**
  189. * @since 4.5.6
  190. * @return string
  191. */
  192. $aria_label = apply_filters( 'avf_social_media_icon_aria_label_value', $aria_label, $icon );
  193. if( ! empty( $aria_label ) )
  194. {
  195. $aria_label = 'aria-label="' . esc_attr( $aria_label ) . '"';
  196. }
  197.  
  198. $html = '';
  199. $html .= "<{$this->args['inside']} class='{$this->args['class']}_{$icon['social_icon']} av-social-link-{$icon['social_icon']} social_icon_{$this->counter}'>";
  200. $html .= "<a {$blank} {$aria_label} href='" . esc_url( $icon['social_icon_link'] ) . "' " . av_icon_string( $icon['social_icon'], false ) . " title='{$display_name}'>";
  201. $html .= "<span class='avia_hidden_link_text'>{$display_name}</span>";
  202. $html .= '</a>';
  203.  
  204. $html .= "</{$this->args['inside']}>";
  205.  
  206. $html = avia_targeted_link_rel( $html );
  207. return $html;
  208. }
  209.  
  210. /**
  211. * Builds the html, based on the available icons
  212. *
  213. * @since < 4.0
  214. * @return string
  215. */
  216. public function html()
  217. {
  218. $this->html = '';
  219.  
  220. if( ! empty( $this->icons ) )
  221. {
  222. $this->html .= "<{$this->args['outside']} class='noLightbox {$this->args['class']} icon_count_" . count( $this->icons ) . "'>";
  223.  
  224. foreach ( $this->icons as $icon )
  225. {
  226. if( ! empty( $icon['social_icon'] ) )
  227. {
  228. $this->html .= $this->build_icon( $icon );
  229. $this->counter ++;
  230. }
  231. }
  232.  
  233. $this->html .= $this->args['append'];
  234. $this->html .= "</{$this->args['outside']}>";
  235. }
  236.  
  237. return $this->html;
  238. }
  239. }
  240. }
  241.  
  242. if( ! function_exists( 'avia_social_media_icons' ) )
  243. {
  244. /**
  245. * Wrapper function for social media icons
  246. *
  247. * @since < 4.0
  248. * @param array $args
  249. * @param boolean $echo
  250. * @param array $post_data
  251. * @return string
  252. */
  253. function avia_social_media_icons( $args = array(), $echo = true, $post_data = array() )
  254. {
  255. $icons = new avia_social_media_icons( $args, $post_data );
  256.  
  257. $html = $icons->html();
  258. if( $echo )
  259. {
  260. echo $html;
  261. }
  262.  
  263. return $html;
  264. }
  265. }
  266.  
  267.  
  268.  
  269.  
  270. if( ! class_exists( 'avia_social_share_links' ) )
  271. {
  272. /**
  273. * Share link builder class
  274. *
  275. * @since ???
  276. * @since 4.8.3 extended to support link to social profiles and custom profile link set in ALB element "Social Buttons"
  277. */
  278. class avia_social_share_links
  279. {
  280. /**
  281. * @since < 4.0
  282. * @var array
  283. */
  284. protected $args;
  285.  
  286. /**
  287. * @since < 4.0
  288. * @var array
  289. */
  290. protected $options;
  291.  
  292. /**
  293. * @since < 4.0
  294. * @var string
  295. */
  296. protected $title;
  297.  
  298. /**
  299. * @since < 4.0
  300. * @var array
  301. */
  302. protected $links;
  303.  
  304. /**
  305. * @since < 4.0
  306. * @var string
  307. */
  308. protected $html;
  309.  
  310. /**
  311. * @since < 4.0
  312. * @var int
  313. */
  314. protected $counter;
  315.  
  316. /**
  317. *
  318. * @since 4.5.7.1
  319. * @var array
  320. */
  321. protected $post_data;
  322.  
  323. /**
  324. *
  325. * @since 4.8.3
  326. * @var avia_social_media_icons
  327. */
  328. protected $social_media_icons;
  329.  
  330.  
  331. /**
  332. * Initialize the variables necessary for all social media links
  333. *
  334. * @since < 4.0
  335. * @param array $args
  336. * @param array|false $options
  337. * @param string|false $title
  338. */
  339. public function __construct( $args = array(), $options = false, $title = false )
  340. {
  341.  
  342. $default_arguments = array(
  343.  
  344. 'facebook' => array(
  345. 'encode' => true,
  346. 'encode_urls' => false,
  347. 'pattern' => 'https://www.facebook.com/sharer.php?u=[permalink]&amp;t=[title]'
  348. ),
  349. 'twitter' => array(
  350. 'encode' => true,
  351. 'encode_urls' => false,
  352. 'pattern' => 'https://twitter.com/share?text=[title]&url=[shortlink]'
  353. ),
  354. 'whatsapp' => array(
  355. 'encode' => true,
  356. 'encode_urls' => false,
  357. 'pattern' => 'https://api.whatsapp.com/send?text=[permalink]',
  358. 'label' => __( 'Share on WhatsApp', 'avia_framework' ),
  359. 'label_profile' => __( 'Link to WhatsApp', 'avia_framework' )
  360. ),
  361. 'pinterest' => array(
  362. 'encode' => true,
  363. 'encode_urls' => true,
  364. 'pattern' => 'https://pinterest.com/pin/create/button/?url=[permalink]&amp;description=[title]&amp;media=[thumbnail]'
  365. ),
  366. 'linkedin' => array(
  367. 'encode' => true,
  368. 'encode_urls' => false,
  369. 'pattern' => 'https://linkedin.com/shareArticle?mini=true&amp;title=[title]&amp;url=[permalink]'
  370. ),
  371. 'tumblr' => array(
  372. 'encode' => true,
  373. 'encode_urls' => true,
  374. 'pattern' => 'https://www.tumblr.com/share/link?url=[permalink]&amp;name=[title]&amp;description=[excerpt]'
  375. ),
  376. 'vk' => array(
  377. 'encode' => true,
  378. 'encode_urls' => false,
  379. 'pattern' => 'https://vk.com/share.php?url=[permalink]'
  380. ),
  381. 'reddit' => array(
  382. 'encode' => true,
  383. 'encode_urls' => false,
  384. 'pattern' => 'https://reddit.com/submit?url=[permalink]&amp;title=[title]'
  385. ),
  386. 'mail' => array(
  387. 'encode' => true,
  388. 'encode_urls' => false,
  389. 'pattern' => 'mailto:?subject=[title]&amp;body=[permalink]',
  390. 'label' => __( 'Share by Mail', 'avia_framework' )
  391. ),
  392. 'yelp' => $this->default_yelp_link( $args, $options, $title ),
  393.  
  394. 'five_100_px' => array(
  395. 'encode' => false,
  396. 'encode_urls' => false,
  397. 'profile_only' => true,
  398. 'label_profile' => __( 'Link to 500px', 'avia_framework' )
  399. ),
  400. 'behance' => array(
  401. 'encode' => false,
  402. 'encode_urls' => false,
  403. 'profile_only' => true
  404. ),
  405. 'dribbble' => array(
  406. 'encode' => false,
  407. 'encode_urls' => false,
  408. 'profile_only' => true
  409. ),
  410. 'flickr' => array(
  411. 'encode' => false,
  412. 'encode_urls' => false,
  413. 'profile_only' => true
  414. ),
  415. 'instagram' => array(
  416. 'encode' => false,
  417. 'encode_urls' => false,
  418. 'profile_only' => true
  419. ),
  420. 'skype' => array(
  421. 'encode' => false,
  422. 'encode_urls' => false,
  423. 'profile_only' => true
  424. ),
  425. 'soundcloud' => array(
  426. 'encode' => false,
  427. 'encode_urls' => false,
  428. 'profile_only' => true
  429. ),
  430. 'vimeo' => array(
  431. 'encode' => false,
  432. 'encode_urls' => false,
  433. 'profile_only' => true
  434. ),
  435. 'xing' => array(
  436. 'encode' => false,
  437. 'encode_urls' => false,
  438. 'profile_only' => true
  439. ),
  440. 'youtube' => array(
  441. 'encode' => false,
  442. 'encode_urls' => false,
  443. 'profile_only' => true
  444. )
  445. );
  446.  
  447. $this->args = apply_filters( 'avia_social_share_link_arguments', array_merge( $default_arguments, $args ) );
  448.  
  449. $this->options = ( empty( $options ) ) ? avia_get_option() : $options;
  450. $this->title = $title !== false ? $title : __( 'Share this entry', 'avia_framework' );
  451. $this->links = array();
  452. $this->html = '';
  453. $this->counter = 0;
  454. $this->post_data = array();
  455. $this->social_media_icons = new avia_social_media_icons();
  456.  
  457. /**
  458. * Create a valid options entry for theme icons in case a new checkbox option for an icon has been created and
  459. * options have not been saved - in this case we hide it.
  460. * Was introduced with adding yelp 4.7.2.1, can be removed in a future release.
  461. *
  462. * This allows to add icons via filter and show them
  463. */
  464. if( ! isset( $this->options['share_yelp'] ) )
  465. {
  466. $this->options['share_yelp'] = 'disabled';
  467. }
  468.  
  469. $this->build_share_links();
  470. }
  471.  
  472. /**
  473. * @since 4.5.6
  474. */
  475. public function __destruct()
  476. {
  477. unset( $this->args );
  478. unset( $this->options );
  479. unset( $this->links );
  480. unset( $this->post_data );
  481. unset( $this->social_media_icons );
  482. }
  483.  
  484.  
  485. /**
  486. * Initialize and filter the default yelp array.
  487. * If $options = false or no link provided in $options fallback to
  488. * link in theme options or yelp homepage
  489. *
  490. * @since 4.6.4
  491. * @param array $args
  492. * @param array|false $options
  493. * @param string|false $title
  494. * @return array
  495. */
  496. protected function default_yelp_link( $args, $options, $title )
  497. {
  498. /**
  499. * Fallback URL used if no url specified in theme options "Social Profiles" or in custom social share button
  500. *
  501. * @since 4.7.1.1
  502. * @param string
  503. * @return string
  504. */
  505. $pattern = apply_filters( 'avf_default_yelp_url', 'https://www.yelp.com' );
  506.  
  507. $icons = apply_filters( 'avia_filter_social_icons', avia_get_option( 'social_icons' ) );
  508. foreach( $icons as $icon )
  509. {
  510. if( 'yelp' == $icon['social_icon'] )
  511. {
  512. if( ! empty( $icon['social_icon_link'] ) )
  513. {
  514. $pattern = esc_url( $icon['social_icon_link'] );
  515. }
  516.  
  517. break;
  518. }
  519. }
  520.  
  521. if( is_array( $options ) && ( 'disabled' != $options['share_yelp'] ) && ( 'disabled' != $options['yelp_link'] ) )
  522. {
  523. $pattern = esc_url( $options['yelp_link'] );
  524. }
  525.  
  526. $default = array(
  527. 'encode' => false,
  528. 'encode_urls' => false,
  529. 'pattern' => $pattern,
  530. 'label' => __( 'Visit us on Yelp','avia_framework' )
  531. );
  532.  
  533. /**
  534. * Filter the default yelp array
  535. * e.g. allow on blogposts is_single() to change link to post specific yelp page
  536. *
  537. * @since 4.6.4
  538. * @param array $default
  539. * @param array $args
  540. * @param array|false $options
  541. * @param string|false $title
  542. * @return array
  543. */
  544. $default = apply_filters( 'avf_default_yelp_link', $default, $args, $options, $title );
  545.  
  546. return $default;
  547. }
  548.  
  549. /**
  550. * Filter social icons that are disabled in the backend. everything that is left will be displayed.
  551. * That way the user can hook into the 'avia_social_share_link_arguments' filter above and add new social icons
  552. * without the need to add a new backend option
  553. *
  554. * @since < 4.0
  555. */
  556. protected function build_share_links()
  557. {
  558. $replace = array();
  559. $thumb = wp_get_attachment_image_src( get_post_thumbnail_id(), 'masonry' );
  560.  
  561. $replace['permalink'] = ! isset( $this->post_data['permalink'] ) ? get_permalink() : $this->post_data['permalink'];
  562. $replace['title'] = ! isset( $this->post_data['title'] ) ? get_the_title() : $this->post_data['title'];
  563. $replace['excerpt'] = ! isset( $this->post_data['excerpt'] ) ? get_the_excerpt() : $this->post_data['excerpt'];
  564. $replace['shortlink'] = ! isset( $this->post_data['shortlink'] ) ? wp_get_shortlink() : $this->post_data['shortlink'];
  565.  
  566. $replace['thumbnail'] = is_array( $thumb ) && isset( $thumb[0] ) ? $thumb[0] : '';
  567. $replace['thumbnail'] = ! isset( $this->post_data['thumbnail'] ) ? $replace['thumbnail'] : $this->post_data['thumbnail'];
  568.  
  569. $replace = apply_filters( 'avia_social_share_link_replace_values', $replace );
  570. $charset = get_bloginfo( 'charset' );
  571.  
  572. foreach( $this->args as $key => $share )
  573. {
  574. $share_key = 'share_' . $key;
  575. $profile_key = $key . '_profile';
  576.  
  577. $this->args[ $key ]['url'] = false;
  578. $this->args[ $key ]['profile'] = false;
  579.  
  580. /*
  581. * 'avia_social_share_link_arguments' filter might add share links that do not exist in "Blog Layout" section as checkbox.
  582. * Therefore we only check for unchecked if the checkbox exists.
  583. */
  584. if( isset( $this->options[ $share_key ] ) && $this->options[ $share_key ] == 'disabled' )
  585. {
  586. continue;
  587. }
  588.  
  589. $url = isset( $share['pattern'] ) ? $share['pattern'] : '';
  590.  
  591. if( ! empty( $url ) )
  592. {
  593. foreach( $replace as $replace_key => $replace_value )
  594. {
  595. if( ! empty( $share['encode'] ) && $replace_key != 'shortlink' && $replace_key != 'permalink' )
  596. {
  597. $replace_value = rawurlencode( html_entity_decode( $replace_value, ENT_QUOTES, $charset ) );
  598. }
  599.  
  600. if( ! empty( $share['encode_urls'] ) && ( $replace_key == 'shortlink' || $replace_key == 'permalink') )
  601. {
  602. $replace_value = rawurlencode( html_entity_decode( $replace_value, ENT_QUOTES, $charset ) );
  603. }
  604.  
  605. $url = str_replace( "[{$replace_key}]", $replace_value, $url );
  606. }
  607.  
  608. $this->args[ $key ]['url'] = ! empty( $url ) ? $url : false;
  609. }
  610.  
  611. // set profile link
  612. if( isset( $this->options[ $profile_key ] ) && ! empty( $this->options[ $profile_key ] ) )
  613. {
  614. $this->args[ $key ]['profile'] = trim( $this->options[ $profile_key ] );
  615. }
  616. else
  617. {
  618. $icon = $this->social_media_icons->get_icon( $key );
  619. if( false !== $icon )
  620. {
  621. $this->args[ $key ]['profile'] = $icon['social_icon_link'];
  622. }
  623. }
  624.  
  625. $this->counter ++;
  626. }
  627. }
  628.  
  629. /**
  630. * Builds the html, based on the available urls
  631. *
  632. * @since < 4.0
  633. * @return string
  634. */
  635. public function html()
  636. {
  637. global $avia_config;
  638.  
  639. $this->html = '';
  640.  
  641. if( $this->counter == 0 )
  642. {
  643. return $this->html;
  644. }
  645.  
  646. $this->html .= '<div class="av-share-box">';
  647. if( $this->title )
  648. {
  649.  
  650. $default_heading = 'h5';
  651. $args = array(
  652. 'heading' => $default_heading,
  653. 'extra_class' => ''
  654. );
  655.  
  656. $extra_args = array( $this, 'title' );
  657.  
  658. /**
  659. * @since 4.5.7.1
  660. * @return array
  661. */
  662. $args = apply_filters( 'avf_customize_heading_settings', $args, __CLASS__, $extra_args );
  663.  
  664. $heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  665. $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
  666.  
  667. $this->html .= "<{$heading} class='av-share-link-description av-no-toc {$css}'>";
  668. $this->html .= apply_filters( 'avia_social_share_title', $this->title , $this->args );
  669. $this->html .= "</{$heading}>";
  670. }
  671.  
  672. $this->html .= '<ul class="av-share-box-list noLightbox">';
  673.  
  674.  
  675. $buttons = $this->sort_buttons( $this->args );
  676.  
  677. foreach( $buttons as $key => $share )
  678. {
  679. $select_profile = false;
  680. if( isset( $this->options['btn_action'] ) && 'profile' == $this->options['btn_action'] )
  681. {
  682. $select_profile = true;
  683. }
  684. else if( isset( $share['profile_only'] ) && true === $share['profile_only'] )
  685. {
  686. $select_profile = true;
  687. }
  688.  
  689. if( $select_profile )
  690. {
  691. $url = isset( $share['profile'] ) ? $share['profile'] : false;
  692. }
  693. else
  694. {
  695. $url = isset( $share['url'] ) ? $share['url'] : false;
  696. }
  697.  
  698. if( empty( $url ) )
  699. {
  700. continue;
  701. }
  702.  
  703. $icon = isset( $share['icon'] ) ? $share['icon'] : $key;
  704.  
  705. $source = ucfirst( $key );
  706. if( ! empty( $avia_config['font_icons'][ $key ]['display_name'] ) )
  707. {
  708. $source = $avia_config['font_icons'][ $key ]['display_name'];
  709. }
  710.  
  711.  
  712. $label_key = $select_profile ? 'label_profile' : 'label';
  713.  
  714. if( isset( $share[ $label_key ] ) && ! empty( $share[ $label_key ] ) )
  715. {
  716. $name = $share[ $label_key ];
  717. }
  718. else if( $select_profile )
  719. {
  720. $name = __( 'Link to','avia_framework') . ' ' . $source;
  721. }
  722. else
  723. {
  724. $name = __( 'Share on','avia_framework') . ' ' . $source;
  725. }
  726.  
  727. $name = esc_attr( $name );
  728.  
  729. $blank = strpos( $share['url'], 'mailto' ) !== false ? '' : 'target="_blank"';
  730.  
  731. /**
  732. * @since 4.5.6
  733. * @return string
  734. */
  735. $aria_label = apply_filters( 'avf_social_share_links_aria_label_value', $name, $key, $share, $this );
  736. if( ! empty( $aria_label ) )
  737. {
  738. $aria_label = 'aria-label="' . esc_attr( $aria_label ) . '"';
  739. }
  740.  
  741. $this->html .= "<li class='av-share-link av-social-link-{$key}' >";
  742. $this->html .= "<a {$blank} {$aria_label} href='" . esc_url( $url ) . "' " . av_icon_string( $icon, false ) . " title='' data-avia-related-tooltip='{$name}'>";
  743. $this->html .= "<span class='avia_hidden_link_text'>{$name}</span>";
  744. $this->html .= '</a>';
  745. $this->html .= '</li>';
  746. }
  747.  
  748. $this->html .= '</ul>';
  749. $this->html .= '</div>';
  750.  
  751. $this->html = avia_targeted_link_rel( $this->html );
  752. return $this->html;
  753. }
  754.  
  755. /**
  756. * Sort buttons using a filter
  757. *
  758. * @since 4.8.3
  759. * @param array $buttons
  760. * @return array
  761. */
  762. protected function sort_buttons( array $buttons )
  763. {
  764. /**
  765. * Return an array with button keys in the desired order. These buttons are placed first, then the other follow as defined in $this->args
  766. *
  767. * @since 4.8.3
  768. * @param array $sort_array
  769. * @param array $this->options
  770. * @param avia_social_share_links $this
  771. * @return array|false
  772. */
  773. $sort_buttons = apply_filters( 'avf_social_share_buttons_order', [], $this->options, $this );
  774.  
  775. if( ! is_array( $sort_buttons ) || empty( $sort_buttons ) )
  776. {
  777. return $buttons;
  778. }
  779.  
  780. $new_array = [];
  781.  
  782. foreach( $sort_buttons as $key )
  783. {
  784. if( ! isset( $buttons[ $key ] ) )
  785. {
  786. continue;
  787. }
  788.  
  789. $new_array[ $key ] = $buttons[ $key ];
  790. unset( $buttons[ $key ] );
  791. }
  792.  
  793. return array_merge( $new_array, $buttons );
  794. }
  795.  
  796. }
  797. }
  798.  
  799. if( ! function_exists( 'avia_social_share_links' ) )
  800. {
  801. /**
  802. * Wrapper function for social share links
  803. *
  804. * @param array $args
  805. * @param array|false $options
  806. * @param string|false $title
  807. * @param boolean $echo
  808. * @return string
  809. */
  810. function avia_social_share_links( $args = array(), $options = false, $title = false, $echo = true )
  811. {
  812. $icons = new avia_social_share_links( $args, $options, $title );
  813.  
  814. $html = $icons->html();
  815. if( $echo )
  816. {
  817. echo $html;
  818. }
  819.  
  820. return $html;
  821. }
  822. }
  823.  
  824. if( ! function_exists( 'avia_social_share_links_blog' ) )
  825. {
  826. /**
  827. * Wrapper function for social share links on a single post page
  828. *
  829. * @since 4.8.3
  830. * @return string
  831. */
  832. function avia_social_share_links_single_post( $echo = true )
  833. {
  834. $custom_class = array();
  835.  
  836. $style = avia_get_option( 'single_post_share_buttons_style' );
  837. $alignment = avia_get_option( 'single_post_share_buttons_alignment' );
  838.  
  839. if( '' == $style )
  840. {
  841. $style = 'av-social-sharing-box-default';
  842. }
  843. else if( 'minimal' == $style )
  844. {
  845. $style = 'av-social-sharing-box-minimal';
  846. }
  847.  
  848. $custom_class[] = $style;
  849.  
  850. if( ! in_array( $style, array( 'av-social-sharing-box-default', 'av-social-sharing-box-minimal', 'av-social-sharing-box-icon', 'av-social-sharing-box-icon-simple' ) ) )
  851. {
  852. $custom_class[] = 'av-social-sharing-box-color-bg';
  853. }
  854.  
  855. if( in_array( $style, array( 'av-social-sharing-box-square', 'av-social-sharing-box-circle', 'av-social-sharing-box-icon', 'av-social-sharing-box-icon-simple' ) ) )
  856. {
  857. $custom_class[] = 'av-social-sharing-box-same-width';
  858. $custom_class[] = $alignment;
  859. }
  860. else
  861. {
  862. $custom_class[] = 'av-social-sharing-box-fullwidth';
  863. }
  864.  
  865. $custom_class = implode( ' ', $custom_class );
  866.  
  867.  
  868.  
  869. $html = "<div class='av-social-sharing-box {$custom_class}'>";
  870. $html .= avia_social_share_links( array(), false, false, false );
  871. $html .= '</div>';
  872.  
  873. if( $echo )
  874. {
  875. echo $html;
  876. }
  877.  
  878. return $html;
  879. }
  880. }
  881.  
  882.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement