Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.43 KB | None | 0 0
  1. <?php
  2. class T4PSC_Person {
  3.  
  4. public static $args;
  5.  
  6. /**
  7. * Initiate the shortcode
  8. */
  9. public function __construct() {
  10.  
  11. add_filter( 't4p_attr_person-shortcode', array( $this, 'attr' ) );
  12. add_filter( 't4p_attr_person-shortcode-image-container', array( $this, 'image_container_attr' ) );
  13. add_filter( 't4p_attr_person-shortcode-href', array( $this, 'href_attr' ) );
  14. add_filter( 't4p_attr_person-shortcode-img', array( $this, 'img_attr' ) );
  15. add_filter( 't4p_attr_person-shortcode-author', array( $this, 'author_attr' ) );
  16. add_filter( 't4p_attr_person-shortcode-social-networks', array( $this, 'social_networks_attr' ) );
  17. add_filter( 't4p_attr_person-shortcode-icon', array( $this, 'icon_attr' ) );
  18.  
  19. add_shortcode( 'person', array( $this, 'render' ) );
  20.  
  21. }
  22.  
  23. /**
  24. * Render the shortcode
  25. * @param array $args Shortcode paramters
  26. * @param string $content Content between shortcode
  27. * @return string HTML output
  28. */
  29. function render( $args, $content = '') {
  30. global $smof_data;
  31.  
  32. $defaults = T4PCore_Plugin::set_shortcode_defaults(
  33. array(
  34. 'class' => '',
  35. 'id' => '',
  36. 'lightbox' => 'no',
  37. 'linktarget' => '_blank',
  38. 'name' => '',
  39. 'social_icon_boxed' => strtolower( $smof_data['social_links_boxed'] ),
  40. 'social_icon_boxed_colors' => strtolower( $smof_data['social_links_box_color'] ),
  41. 'social_icon_boxed_radius' => strtolower( $smof_data['social_links_boxed_radius'] ),
  42. 'social_icon_colors' => strtolower( $smof_data['social_links_icon_color'] ),
  43. 'social_icon_order' => '',
  44. 'social_icon_tooltip' => strtolower( $smof_data['social_links_tooltip_placement'] ),
  45. 'pic_bordercolor' => strtolower( $smof_data['person_border_color'] ),
  46. 'pic_bordersize' => strtolower( $smof_data['person_border_size'] ),
  47. 'pic_link' => '',
  48. 'pic_style' => 'none',
  49. 'pic_style_color' => strtolower( $smof_data['person_style_color'] ),
  50. 'picture' => '',
  51. 'title' => '',
  52.  
  53. 'facebook' => '', 'twitter' => '', 'linkedin' => '', 'dribbble' => '', 'rss' => '', 'youtube' => '', 'pinterest' => '', 'flickr' => '', 'vimeo' => '',
  54. 'tumblr' => '', 'google' => '', 'googleplus' => '', 'digg' => '', 'blogger' =>'', 'skype' => '', 'myspace' => '', 'deviantart' => '', 'yahoo' => '',
  55. 'reddit' => '', 'forrst' => '', 'paypal' => '', 'dropbox' => '', 'soundcloud' => '', 'vk' => '', 'email' => '',
  56. ), $args
  57. );
  58.  
  59. extract( $defaults );
  60.  
  61. self::$args = $defaults;
  62.  
  63. if( $smof_data['social_icons_new'] ) {
  64. self::$args['linktarget'] == '_blank';
  65. } else {
  66. self::$args['linktarget'] == '_self';
  67. }
  68.  
  69. self::$args['styles'] = '';
  70.  
  71. $rgb = T4PCore_Plugin::hex2rgb( $defaults['pic_style_color'] );
  72.  
  73. if( $pic_style == 'glow' ) {
  74. self::$args['styles'] .= "-moz-box-shadow: 0 0 3px rgba({$rgb[0]},{$rgb[1]},{$rgb[2]},.3);
  75. -webkit-box-shadow: 0 0 3px rgba({$rgb[0]},{$rgb[1]},{$rgb[2]},.3);
  76. box-shadow: 0 0 3px rgba({$rgb[0]},{$rgb[1]},{$rgb[2]},.3);";
  77. }
  78.  
  79. if( $pic_style == 'dropshadow' ) {
  80. self::$args['styles'] .= "
  81. -moz-box-shadow: 2px 3px 7px rgba({$rgb[0]},{$rgb[1]},{$rgb[2]},.3);
  82. -webkit-box-shadow: 2px 3px 7px rgba({$rgb[0]},{$rgb[1]},{$rgb[2]},.3);
  83. box-shadow: 2px 3px 7px rgba({$rgb[0]},{$rgb[1]},{$rgb[2]},.3);";
  84. }
  85.  
  86. $inner_content = '';
  87.  
  88. if( $picture ) {
  89. $picture = sprintf( '<img %s />', T4PCore_Plugin::attributes( 'person-shortcode-img' ) ) ;
  90.  
  91. if ( $pic_link ) {
  92. $picture = sprintf( '<a %s>%s</a>', T4PCore_Plugin::attributes( 'person-shortcode-href' ), $picture ) ;
  93. }
  94.  
  95. $picture = sprintf( '<div %s><div %s>%s</div></div>', T4PCore_Plugin::attributes( 'person-shortcode-image-wrapper' ),
  96. T4PCore_Plugin::attributes( 'person-shortcode-image-container' ), $picture ) ;
  97.  
  98. }
  99.  
  100. $style_radius = '';
  101. $style_radius .= sprintf( 'border-radius:%s;', $args['social_icon_boxed_radius'] );
  102. $print_css_radius = '<style type="text/css">.t4p-person .t4p-icon-holder, .t4p-person .t4p-social-networks.boxed-icons a:after {'.$style_radius.'}</style>';
  103. echo $print_css_radius;
  104.  
  105. if( $name || $title || $content ) {
  106.  
  107. $social_networks = $this->get_social_links_array();
  108.  
  109. if( ! is_array( $social_icon_order ) ) {
  110. $social_icon_order = explode( '|', $social_icon_order );
  111. }
  112. //$social_networks = T4PCore_Plugin::order_array_like_array( $social_networks, $social_icon_order );
  113.  
  114. $social_icon_colors = explode( '|', $social_icon_colors );
  115. $num_of_icon_colors = count( $social_icon_colors );
  116.  
  117. $social_icon_boxed_colors = explode( '|', $social_icon_boxed_colors );
  118. $num_of_box_colors = count( $social_icon_boxed_colors );
  119.  
  120. $icons = '';
  121.  
  122. if( isset( $smof_data['social_sorter'] ) && $smof_data['social_sorter'] ) {
  123. $order = $smof_data['social_sorter'];
  124. $ordered_array = explode(',', $order);
  125.  
  126. if( isset( $ordered_array ) && $ordered_array && is_array( $ordered_array ) ) {
  127. $social_networks_old = $social_networks;
  128. $social_networks = array();
  129. foreach( $ordered_array as $key => $field_order ) {
  130. $field_order_number = str_replace( 'social_sorter_', '', $field_order );
  131. $find_the_field = $smof_data['social_sorter_' . $field_order_number];
  132. $field_name = str_replace( '_link', '', $smof_data['social_sorter_' . $field_order_number] );
  133.  
  134. if( $field_name == 'google' ) {
  135. $field_name = 'googleplus';
  136. } elseif($field_name == 'email' ) {
  137. $field_name = 'mail';
  138. }
  139.  
  140. if( ! isset( $social_networks_old[$field_name] ) ) {
  141. continue;
  142. }
  143.  
  144. $social_networks[$field_name] = $social_networks_old[$field_name];
  145. }
  146. }
  147. }
  148.  
  149. for( $i = 0; $i < count( $social_networks ); $i++ ) {
  150. if( $num_of_icon_colors == 1 ) {
  151. $social_icon_colors[$i] = $social_icon_colors[0];
  152. }
  153.  
  154. if( $num_of_box_colors == 1 ) {
  155. $social_icon_boxed_colors[$i] = $social_icon_boxed_colors[0];
  156. }
  157. }
  158.  
  159. $i = 0;
  160. foreach( $social_networks as $network => $link ) {
  161.  
  162. $icon_options = array(
  163. 'social_network' => $network,
  164. 'social_link' => $link,
  165. 'icon_color' => $i < count( $social_icon_colors ) ? $social_icon_colors[$i] : '',
  166. 'box_color' => $i < count( $social_icon_boxed_colors ) ? $social_icon_boxed_colors[$i] : '',
  167. );
  168.  
  169. $icons .= sprintf( '<span class="t4p-icon-holder"><a %s></a></span>', T4PCore_Plugin::attributes( 'person-shortcode-icon', $icon_options ) );
  170. $i++;
  171. }
  172.  
  173. $inner_content .= sprintf( '<div %s><div %s><div %s><span %s>%s</span><span %s>%s</span></div><div %s>%s</div></div><div %s>%s</div></div>',
  174. T4PCore_Plugin::attributes( 'person-desc' ), T4PCore_Plugin::attributes( 'person-shortcode-author' ),
  175. T4PCore_Plugin::attributes( 'person-author-wrapper' ), T4PCore_Plugin::attributes( 'person-name' ), $name,
  176. T4PCore_Plugin::attributes( 'person-title' ), $title,
  177. T4PCore_Plugin::attributes( 'person-content t4p-clearfix' ), do_shortcode( $content ),
  178. T4PCore_Plugin::attributes( 'person-shortcode-social-networks' ), $icons );
  179.  
  180. }
  181.  
  182. $html = sprintf( '<div %s>%s%s</div>', T4PCore_Plugin::attributes( 'person-shortcode' ), $picture, $inner_content );
  183.  
  184. return $html;
  185.  
  186. }
  187.  
  188. function attr() {
  189.  
  190. $attr = array();
  191.  
  192. $attr['class'] = 't4p-person person';
  193.  
  194. if( self::$args['class'] ) {
  195. $attr['class'] .= ' ' . self::$args['class'];
  196. }
  197.  
  198. if( self::$args['id'] ) {
  199. $attr['id'] = self::$args['id'];
  200. }
  201.  
  202. return $attr;
  203.  
  204. }
  205.  
  206. function image_container_attr() {
  207.  
  208. $attr = array();
  209.  
  210. $attr['class'] = 'person-imgage-container';
  211.  
  212. if( self::$args['pic_style'] == 'glow' ) {
  213. $attr['class'] .= ' glow';
  214. } else if( self::$args['pic_style'] == 'dropshadow' ) {
  215. $attr['class'] .= ' dropshadow';
  216. } else if( self::$args['pic_style'] == 'bottomshadow' ) {
  217. $attr['class'] .= ' element-bottomshadow';
  218. }
  219.  
  220. $attr['style'] = self::$args['styles'];
  221.  
  222. return $attr;
  223.  
  224. }
  225.  
  226. function href_attr() {
  227.  
  228. $attr = array();
  229.  
  230. $attr['href'] = self::$args['pic_link'];
  231.  
  232. if( self::$args['lightbox'] == 'yes' ) {
  233. $attr['class'] = 'lightbox-shortcode';
  234. $attr['href'] = self::$args['picture'];
  235. } else {
  236. $attr['target'] = self::$args['linktarget'];
  237. }
  238.  
  239. return $attr;
  240.  
  241. }
  242.  
  243. function img_attr() {
  244.  
  245. $attr = array();
  246.  
  247. $attr['class'] = 'person-img img-responsive';
  248.  
  249. if( self::$args['pic_bordersize'] ) {
  250. $attr['style'] = sprintf( 'border:%s solid %s;', self::$args['pic_bordersize'], self::$args['pic_bordercolor'] );
  251. }
  252.  
  253. $attr['src'] = self::$args['picture'];
  254.  
  255. $attr['alt'] = self::$args['name'];
  256.  
  257. return $attr;
  258.  
  259. }
  260.  
  261. function author_attr() {
  262.  
  263. $attr = array();
  264.  
  265. $attr['class'] = sprintf( 'person-author' );
  266.  
  267. return $attr;
  268.  
  269. }
  270.  
  271. function social_networks_attr() {
  272.  
  273. $attr['class'] = 't4p-social-networks';
  274.  
  275. if( self::$args['social_icon_boxed'] == 'yes' ) {
  276. $attr['class'] .= ' boxed-icons';
  277. }
  278.  
  279. return $attr;
  280.  
  281. }
  282.  
  283. function icon_attr( $args ) {
  284. global $smof_data;
  285.  
  286. $attr['class'] = sprintf( 't4p-social-network-icon t4p-tooltip t4p-%s t4p-icon-%s', $args['social_network'], $args['social_network'] );
  287.  
  288. $attr['href'] = $args['social_link'];
  289. $attr['target'] = self::$args['linktarget'];
  290.  
  291. if( $smof_data['nofollow_social_links'] ) {
  292. $attr['rel'] = 'nofollow';
  293. }
  294.  
  295. $attr['style'] = '';
  296.  
  297. if( $args['icon_color'] ) {
  298. $attr['style'] = sprintf( 'color:%s;', $args['icon_color'] );
  299. }
  300.  
  301. if( self::$args['social_icon_boxed'] == 'yes' &&
  302. $args['box_color']
  303. ) {
  304. $attr['style'] .= sprintf( 'background-color:%s;border-color:%s;', $args['box_color'], $args['box_color'] );
  305. }
  306.  
  307. if( self::$args['social_icon_boxed'] == 'yes' &&
  308. self::$args['social_icon_boxed_radius'] || self::$args['social_icon_boxed_radius'] === '0'
  309. ) {
  310. if( self::$args['social_icon_boxed_radius'] == 'round' ) {
  311. self::$args['social_icon_boxed_radius'] = '50%';
  312. }
  313.  
  314. $attr['style'] .= sprintf( 'border-radius:%s;', self::$args['social_icon_boxed_radius'] );
  315. }
  316.  
  317. $attr['data-placement'] = self::$args['social_icon_tooltip'];
  318. $attr['data-title'] = ucfirst( $args['social_network'] );
  319.  
  320. if( self::$args['social_icon_tooltip'] != 'none' ) {
  321. $attr['data-toggle'] = 'tooltip';
  322. }
  323.  
  324. return $attr;
  325.  
  326. }
  327.  
  328. function get_social_links_array() {
  329.  
  330. $social_links_array = array();
  331.  
  332. if( self::$args['facebook'] ) {
  333. $social_links_array['facebook'] = self::$args['facebook'];
  334. }
  335. if( self::$args['twitter'] ) {
  336. $social_links_array['twitter'] = self::$args['twitter'];
  337. }
  338. if( self::$args['linkedin'] ) {
  339. $social_links_array['linkedin'] = self::$args['linkedin'];
  340. }
  341. if( self::$args['dribbble'] ) {
  342. $social_links_array['dribbble'] = self::$args['dribbble'];
  343. }
  344. if( self::$args['rss'] ) {
  345. $social_links_array['rss'] = self::$args['rss'];
  346. }
  347. if( self::$args['youtube'] ) {
  348. $social_links_array['youtube'] = self::$args['youtube'];
  349. }
  350. if( self::$args['pinterest'] ) {
  351. $social_links_array['pinterest'] = self::$args['pinterest'];
  352. }
  353. if( self::$args['flickr'] ) {
  354. $social_links_array['flickr'] = self::$args['flickr'];
  355. }
  356. if( self::$args['vimeo'] ) {
  357. $social_links_array['vimeo'] = self::$args['vimeo'];
  358. }
  359. if( self::$args['tumblr'] ) {
  360. $social_links_array['tumblr'] = self::$args['tumblr'];
  361. }
  362. if( self::$args['googleplus'] ) {
  363. $social_links_array['googleplus'] = self::$args['googleplus'];
  364. }
  365. if( self::$args['google'] ) {
  366. $social_links_array['googleplus'] = self::$args['google'];
  367. }
  368. if( self::$args['digg'] ) {
  369. $social_links_array['digg'] = self::$args['digg'];
  370. }
  371. if( self::$args['blogger'] ) {
  372. $social_links_array['blogger'] = self::$args['blogger'];
  373. }
  374. if( self::$args['skype'] ) {
  375. $social_links_array['skype'] = self::$args['skype'];
  376. }
  377. if( self::$args['myspace'] ) {
  378. $social_links_array['myspace'] = self::$args['myspace'];
  379. }
  380. if( self::$args['deviantart'] ) {
  381. $social_links_array['deviantart'] = self::$args['deviantart'];
  382. }
  383. if( self::$args['yahoo'] ) {
  384. $social_links_array['yahoo'] = self::$args['yahoo'];
  385. }
  386. if( self::$args['reddit'] ) {
  387. $social_links_array['reddit'] = self::$args['reddit'];
  388. }
  389. if( self::$args['forrst'] ) {
  390. $social_links_array['forrst'] = self::$args['forrst'];
  391. }
  392. if( self::$args['paypal'] ) {
  393. $social_links_array['paypal'] = self::$args['paypal'];
  394. }
  395. if( self::$args['dropbox'] ) {
  396. $social_links_array['dropbox'] = self::$args['dropbox'];
  397. }
  398. if( self::$args['soundcloud'] ) {
  399. $social_links_array['soundcloud'] = self::$args['soundcloud'];
  400. }
  401. if( self::$args['vk'] ) {
  402. $social_links_array['vk'] = self::$args['vk'];
  403. }
  404. if( self::$args['email'] ) {
  405. $social_links_array['mail'] = "mailto:".self::$args['email'];
  406. }
  407.  
  408. return $social_links_array;
  409.  
  410. }
  411.  
  412. }
  413.  
  414. new T4PSC_Person();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement