Guest User

Untitled

a guest
Oct 22nd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.03 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Class td_single_author_box
  5. */
  6. class tdb_single_author_box extends td_block {
  7.  
  8. public function get_custom_css() {
  9. // $unique_block_class - the unique class that is on the block. use this to target the specific instance via css
  10. $unique_block_class = $this->block_uid . '_rand';
  11.  
  12. $compiled_css = '';
  13.  
  14. $raw_css =
  15. "<style>
  16.  
  17. /* @box_padding */
  18. .$unique_block_class {
  19. padding: @box_padding;
  20. }
  21. /* @all_border_width */
  22. .$unique_block_class {
  23. border: @all_border_width @all_border_style @all_border_color;
  24. }
  25.  
  26. /* @display_columns */
  27. .$unique_block_class .tdb-author-photo,
  28. .$unique_block_class .tdb-author-info {
  29. display: table-cell;
  30. }
  31. .$unique_block_class .tdb-author-info {
  32. width: auto;
  33. }
  34. /* @display_row */
  35. .$unique_block_class .tdb-author-photo,
  36. .$unique_block_class .tdb-author-info {
  37. display: inline-block;
  38. }
  39. .$unique_block_class .tdb-author-info {
  40. width: 100%;
  41. }
  42. /* @align_vert_center */
  43. .$unique_block_class .tdb-author-photo,
  44. .$unique_block_class .tdb-author-info {
  45. vertical-align: middle;
  46. }
  47. /* @align_vert_bottom */
  48. .$unique_block_class .tdb-author-photo,
  49. .$unique_block_class .tdb-author-info {
  50. vertical-align: bottom;
  51. }
  52. /* @align_horiz_center */
  53. .$unique_block_class .tdb-block-inner {
  54. text-align: center;
  55. }
  56. /* @align_horiz_right */
  57. .$unique_block_class .tdb-block-inner {
  58. text-align: right;
  59. }
  60.  
  61.  
  62.  
  63. /* @photo_size */
  64. .$unique_block_class .tdb-author-photo {
  65. width: @photo_size;
  66. }
  67. /* @photo_space_right */
  68. .$unique_block_class .tdb-author-photo {
  69. padding-bottom: 0;
  70. padding-right: @photo_space_right;
  71. }
  72. /* @photo_space_bottom */
  73. .$unique_block_class .tdb-author-photo {
  74. padding-bottom: @photo_space_bottom;
  75. padding-right: 0;
  76. }
  77. /* @photo_radius */
  78. .$unique_block_class .tdb-author-photo img {
  79. border-radius: @photo_radius;
  80. }
  81.  
  82.  
  83.  
  84. /* @auth_color */
  85. .$unique_block_class .tdb-author-name {
  86. color: @auth_color;
  87. }
  88. /* @add_name_margin */
  89. .$unique_block_class .tdb-author-name {
  90. margin: @add_name_margin;
  91. }
  92. /* @auth_h_color */
  93. .$unique_block_class .tdb-author-name:hover {
  94. color: @auth_h_color;
  95. }
  96. /* @url_color */
  97. .$unique_block_class .tdb-author-url {
  98. color: @url_color;
  99. }
  100. /* @url_h_color */
  101. .$unique_block_class .tdb-author-url:hover {
  102. color: @url_h_color;
  103. }
  104. /* @descr_color */
  105. .$unique_block_class .tdb-author-descr {
  106. color: @descr_color;
  107. }
  108. /* @add_description_margin */
  109. .$unique_block_class .tdb-author-descr {
  110. margin: @add_description_margin;
  111. }
  112.  
  113.  
  114.  
  115.  
  116. /* @icons_size */
  117. .$unique_block_class .tdb-social-item i {
  118. font-size: @icons_size;
  119. vertical-align: middle;
  120. }
  121. .$unique_block_class .tdb-social-item i.td-icon-twitter,
  122. .$unique_block_class .tdb-social-item i.td-icon-linkedin,
  123. .$unique_block_class .tdb-social-item i.td-icon-pinterest,
  124. .$unique_block_class .tdb-social-item i.td-icon-blogger,
  125. .$unique_block_class .tdb-social-item i.td-icon-vimeo {
  126. font-size: @icons_size_fix;
  127. }
  128. /* @icons_padding */
  129. .$unique_block_class .tdb-social-item {
  130. min-width: @icons_padding;
  131. height: @icons_padding;
  132. }
  133. .$unique_block_class .tdb-social-item i {
  134. line-height: @icons_padding;
  135. }
  136. /* @icons_margin_right */
  137. .$unique_block_class .tdb-social-item {
  138. margin: @icons_margin_top_bottom @icons_margin_right @icons_margin_top_bottom 0;
  139. }
  140.  
  141. /* @icons_color */
  142. .$unique_block_class .tdb-social-item i {
  143. color: @icons_color;
  144. }
  145. /* @icons_h_color */
  146. .$unique_block_class .tdb-social-item:hover i {
  147. color: @icons_h_color;
  148. }
  149. /* @icons_bg */
  150. .$unique_block_class .tdb-social-item {
  151. background-color: @icons_bg;
  152. }
  153. /* @icons_h_bg */
  154. .$unique_block_class .tdb-social-item:hover {
  155. background-color: @icons_h_bg;
  156. }
  157.  
  158. /* @icons_border_radius */
  159. .$unique_block_class .tdb-social-item {
  160. border-radius: @icons_border_radius;
  161. }
  162.  
  163.  
  164.  
  165. /* @f_auth */
  166. .$unique_block_class .tdb-author-name {
  167. @f_auth
  168. }
  169. /* @f_url */
  170. .$unique_block_class .tdb-author-url {
  171. @f_url
  172. }
  173. /* @f_descr */
  174. .$unique_block_class .tdb-author-descr {
  175. @f_descr
  176. }
  177.  
  178. </style>";
  179.  
  180.  
  181. $td_css_res_compiler = new td_css_res_compiler( $raw_css );
  182. $td_css_res_compiler->load_settings( __CLASS__ . '::cssMedia', $this->get_all_atts() );
  183.  
  184. $compiled_css .= $td_css_res_compiler->compile_css();
  185. return $compiled_css;
  186. }
  187.  
  188. static function cssMedia( $res_ctx ) {
  189.  
  190. // box padding
  191. $box_padding = $res_ctx->get_shortcode_att( 'box_padding' );
  192. $res_ctx->load_settings_raw( 'box_padding', $box_padding );
  193. if( $box_padding != '' && is_numeric( $box_padding ) ) {
  194. $res_ctx->load_settings_raw( 'box_padding', $box_padding . 'px' );
  195. } else {
  196. $res_ctx->load_settings_raw( 'box_padding', '21px' );
  197. }
  198.  
  199. // border width
  200. $border_width = $res_ctx->get_shortcode_att( 'all_border_width' );
  201. $res_ctx->load_settings_raw( 'all_border_width', '1px' );
  202. if( $border_width != '' && is_numeric( $border_width ) ) {
  203. $res_ctx->load_settings_raw( 'all_border_width', $border_width . 'px' );
  204. }
  205. // border style
  206. $border_style = $res_ctx->get_shortcode_att( 'all_border_style' );
  207. $res_ctx->load_settings_raw( 'all_border_style', 'solid' );
  208. if( $border_style != '' ) {
  209. $res_ctx->load_settings_raw( 'all_border_style', $border_style );
  210. }
  211.  
  212. // display
  213. $display = $res_ctx->get_shortcode_att( 'display' );
  214. // vertical align
  215. $align_vert = $res_ctx->get_shortcode_att('align_vert');
  216. // horizontal align
  217. $align_horiz = $res_ctx->get_shortcode_att('align_horiz');
  218. if( $display == '' ) {
  219. $res_ctx->load_settings_raw( 'display_columns', 1 );
  220.  
  221. if( $align_vert == 'content-vert-center' ) {
  222. $res_ctx->load_settings_raw( 'align_vert_center', 1 );
  223. } else if ( $align_vert == 'content-vert-bottom' ) {
  224. $res_ctx->load_settings_raw( 'align_vert_bottom', 1 );
  225. }
  226. } else if( $display == 'row' ) {
  227. $res_ctx->load_settings_raw( 'display_row', 1 );
  228.  
  229. if( $align_horiz == 'content-horiz-center' ) {
  230. $res_ctx->load_settings_raw( 'align_horiz_center', 1 );
  231. } else if ( $align_horiz == 'content-horiz-right' ) {
  232. $res_ctx->load_settings_raw( 'align_horiz_right', 1 );
  233. }
  234. }
  235.  
  236.  
  237.  
  238. /*-- AUTHOR PHOTO -- */
  239. // author photo size
  240. $photo_size = $res_ctx->get_shortcode_att( 'photo_size' );
  241. $res_ctx->load_settings_raw( 'photo_size', '96px' );
  242. if( $photo_size != '' && is_numeric( $photo_size ) ) {
  243. $res_ctx->load_settings_raw( 'photo_size', $photo_size . 'px' );
  244. }
  245.  
  246. // author photo space
  247. $photo_space = $res_ctx->get_shortcode_att( 'photo_space' );
  248. if( $display == '' ) {
  249. $res_ctx->load_settings_raw( 'photo_space_right', '21px' );
  250. if( $photo_space != '' && is_numeric( $photo_space ) ) {
  251. $res_ctx->load_settings_raw('photo_space_right', $photo_space . 'px');
  252. }
  253. } else if ( $display == 'row' ) {
  254. $res_ctx->load_settings_raw( 'photo_space_bottom', '21px' );
  255. if( $photo_space != '' && is_numeric( $photo_space ) ) {
  256. $res_ctx->load_settings_raw('photo_space_bottom', $photo_space . 'px');
  257. }
  258. }
  259.  
  260. //author photo border radius
  261. $photo_radius = $res_ctx->get_shortcode_att( 'photo_radius' );
  262. $res_ctx->load_settings_raw( 'photo_radius', $photo_radius );
  263. if( $photo_radius != '' && is_numeric( $photo_radius ) ) {
  264. $res_ctx->load_settings_raw( 'photo_radius', $photo_radius . 'px' );
  265. }
  266.  
  267.  
  268. // border color
  269. $border_color = $res_ctx->get_shortcode_att( 'all_border_color' );
  270. $res_ctx->load_settings_raw( 'all_border_color', '#ededed' );
  271. if( $border_color != '' ) {
  272. $res_ctx->load_settings_raw( 'all_border_color', $border_color );
  273. }
  274.  
  275.  
  276.  
  277. /*-- META INFO -- */
  278. // add name margin
  279. $add_name_margin = $res_ctx->get_shortcode_att( 'add_name_margin' );
  280. $res_ctx->load_settings_raw( 'add_name_margin', $add_name_margin );
  281. if( $add_name_margin != '' && is_numeric( $add_name_margin ) ) {
  282. $res_ctx->load_settings_raw( 'add_name_margin', $add_name_margin . 'px' );
  283. }
  284.  
  285. // add description margin
  286. $add_description_margin = $res_ctx->get_shortcode_att( 'add_description_margin' );
  287. $res_ctx->load_settings_raw( 'add_description_margin', $add_description_margin );
  288. if( $add_description_margin != '' && is_numeric( $add_description_margin ) ) {
  289. $res_ctx->load_settings_raw( 'add_description_margin', $add_description_margin . 'px' );
  290. }
  291.  
  292.  
  293.  
  294. /*-- SOCIAL ICONS -- */
  295. // icons size
  296. $icons_size = $res_ctx->get_shortcode_att( 'icons_size' );
  297. $res_ctx->load_settings_raw( 'icons_size', $icons_size . 'px' );
  298. $res_ctx->load_settings_raw( 'icons_size_fix', $icons_size * 0.8 . 'px');
  299.  
  300. // icons padding
  301. $res_ctx->load_settings_raw( 'icons_padding', $icons_size * $res_ctx->get_shortcode_att( 'icons_padding' ) . 'px' );
  302.  
  303. // icons spacing
  304. $icons_spacing = $res_ctx->get_shortcode_att( 'icons_spacing' );
  305. if( $icons_spacing != '' ) {
  306. if ( is_numeric( $icons_spacing ) ) {
  307. $res_ctx->load_settings_raw( 'icons_margin_right', $icons_spacing . 'px' );
  308. $res_ctx->load_settings_raw( 'icons_margin_top_bottom', $icons_spacing / 2 . 'px' );
  309. }
  310. } else {
  311. $res_ctx->load_settings_raw( 'icons_margin_right', '14px' );
  312. $res_ctx->load_settings_raw( 'icons_margin_top_bottom', '7px' );
  313. }
  314.  
  315. //icons border radius
  316. $icons_border_radius = $res_ctx->get_shortcode_att( 'icons_border_radius' );
  317. $res_ctx->load_settings_raw( 'icons_border_radius', $icons_border_radius );
  318. if( $icons_border_radius != '' && is_numeric( $icons_border_radius ) ) {
  319. $res_ctx->load_settings_raw( 'icons_border_radius', $icons_border_radius . 'px' );
  320. }
  321.  
  322.  
  323.  
  324. /*-- COLORS -- */
  325. $res_ctx->load_settings_raw( 'auth_color', $res_ctx->get_shortcode_att( 'auth_color' ) );
  326. $res_ctx->load_settings_raw( 'auth_h_color', $res_ctx->get_shortcode_att( 'auth_h_color' ) );
  327. $res_ctx->load_settings_raw( 'url_color', $res_ctx->get_shortcode_att( 'url_color' ) );
  328. $res_ctx->load_settings_raw( 'url_h_color', $res_ctx->get_shortcode_att( 'url_h_color' ) );
  329. $res_ctx->load_settings_raw( 'descr_color', $res_ctx->get_shortcode_att( 'descr_color' ) );
  330.  
  331. $res_ctx->load_settings_raw( 'icons_color', $res_ctx->get_shortcode_att( 'icons_color' ) );
  332. $res_ctx->load_settings_raw( 'icons_bg', $res_ctx->get_shortcode_att( 'icons_bg' ) );
  333. $res_ctx->load_settings_raw( 'icons_h_color', $res_ctx->get_shortcode_att( 'icons_h_color' ) );
  334. $res_ctx->load_settings_raw( 'icons_h_bg', $res_ctx->get_shortcode_att( 'icons_h_bg' ) );
  335.  
  336.  
  337.  
  338. /*-- FONTS -- */
  339. $res_ctx->load_font_settings( 'f_auth' );
  340. $res_ctx->load_font_settings( 'f_url' );
  341. $res_ctx->load_font_settings( 'f_descr' );
  342.  
  343. }
  344.  
  345. /**
  346. * Disable loop block features. This block does not use a loop and it doesn't need to run a query.
  347. */
  348. function __construct() {
  349. parent::disable_loop_block_features();
  350. }
  351.  
  352.  
  353. function render( $atts, $content = null ) {
  354. parent::render( $atts ); // sets the live atts, $this->atts, $this->block_uid, $this->td_query (it runs the query)
  355.  
  356. global $tdb_state_single;
  357.  
  358. $author_box_data = $tdb_state_single->post_author_box->__invoke($atts);
  359.  
  360. $additional_classes = array();
  361.  
  362. // add target attribute if the block configuration is set to open in new window
  363. $td_target = '';
  364. $open_in_new_window = $this->get_att( 'open_in_new_window' );
  365. if ( !empty( $open_in_new_window ) ) {
  366. $td_target = ' target="_blank" ';
  367. }
  368.  
  369. $content_align_vertical = $this->get_att('align_vert');
  370. if( !empty( $content_align_vertical ) ) {
  371. $additional_classes[] = 'tdb-' . $content_align_vertical;
  372. }
  373.  
  374.  
  375. $buffy = ''; //output buffer
  376.  
  377. $buffy .= '<div class="tdb-author-box ' . $this->get_block_classes($additional_classes) . '" ' . $this->get_block_html_atts() . '>';
  378.  
  379. //get the block css
  380. $buffy .= $this->get_block_css();
  381.  
  382. //get the js for this block
  383. $buffy .= $this->get_block_js();
  384.  
  385.  
  386. $buffy .= '<div class="tdb-block-inner td-fix-index">';
  387. $buffy .= '<a href="' . $author_box_data['author_url'] . '" class="tdb-author-photo">' . $author_box_data['author_avatar'] . '</a>';
  388.  
  389. $buffy .= '<div class="tdb-author-info">';
  390. $buffy .= '<a href="' . $author_box_data['author_url'] . '" class="tdb-author-name">' . $author_box_data['author_name'] . '</a>' ;
  391.  
  392. $buffy .= '<a href="' . $author_box_data['user_url'] . '" ' . $td_target . ' class="tdb-author-url">' . $author_box_data['user_url'] . '</a>';
  393.  
  394. $buffy .= '<div class="tdb-author-descr">' . $author_box_data['description'] . '</div>';
  395.  
  396. $buffy .= '<div class="tdb-author-social">';
  397. if ( !empty( $author_box_data['author_social_icons'] ) ) {
  398. foreach ( $author_box_data['author_social_icons'] as $td_social_icon ) {
  399. $buffy .= '<a href="' . $td_social_icon['social_link'] . '" target="_blank" title="' . $td_social_icon['social_id'] . '" class="tdb-social-item">';
  400. $buffy .= '<i class="td-icon-font td-icon-' . $td_social_icon['social_id'] . '"></i>';
  401. $buffy .= '</a>';
  402. }
  403. }
  404. $buffy .= '</div>';
  405. $buffy .= '</div>';
  406. $buffy .= '</div>';
  407.  
  408. $buffy .= '</div>';
  409.  
  410. return $buffy;
  411. }
  412. }
Advertisement
Add Comment
Please, Sign In to add comment