Guest User

Untitled

a guest
Jun 22nd, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 78.60 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Central Template builder class
  5. */
  6.  
  7. // Don't load directly
  8. if (!defined('ABSPATH')) {
  9. die('-1');
  10. }
  11.  
  12. if (!class_exists('AviaHtmlHelper')) {
  13.  
  14. class AviaHtmlHelper
  15. {
  16. static $metaData = array(); //required for meta key storing when creating a metabox. necessary to set already stored std values
  17. static $elementValues = array(); //all element values in an id=>value array so we can check dependencies
  18. static $elementHidden = array(); //all elements that didnt pass the dependency test and are hidden
  19. static $imageCount = 0; //count all image elements to assign the right attachment id
  20. static $cache = array(); //cache for entries that are already fetched
  21.  
  22. static public function render_metabox($element)
  23. {
  24. //query the metadata of the current post and check if a key is set, if not set the default value to the standard value, otherwise to the key value
  25. if (!isset(self::$metaData[$element['current_post']])) {
  26. self::$metaData[$element['current_post']] = get_post_custom($element['current_post']);
  27. }
  28.  
  29. if (isset(self::$metaData[$element['current_post']][$element['id']])) {
  30. $element['std'] = self::$metaData[$element['current_post']][$element['id']][0];
  31. }
  32.  
  33. return self::render_element($element);
  34. }
  35.  
  36.  
  37. /**
  38. *
  39. * @param array $elements
  40. * @param string $parent_class
  41. * @return string
  42. */
  43. static public function render_multiple_elements($elements, $parent_class = false)
  44. {
  45. $output = '';
  46.  
  47. foreach ($elements as $element) {
  48. $output .= self::render_element($element, $parent_class);
  49. }
  50.  
  51. return $output;
  52. }
  53.  
  54. static public function ajax_modify_id($element)
  55. {
  56. // check if its an ajax request. if so prepend a string to ensure that the ids are unique.
  57. // If there are multiple modal windows called prepend the string multiple times
  58. if (isset($_POST['ajax_fetch'])) {
  59. $prepends = isset($_POST['instance']) ? $_POST['instance'] : 0;
  60. $element['ajax'] = true;
  61.  
  62. for ($i = 0; $i < $prepends; $i++) {
  63. $element['id'] = "aviaTB" . $element['id'];
  64. }
  65. }
  66. return $element;
  67. }
  68.  
  69. /**
  70. * Returns an element with all needed default keys
  71. *
  72. * @since 4.5.7.2
  73. * @param array $element
  74. * @return array
  75. */
  76. static public function validate_element(array $element = array())
  77. {
  78. $defaults = array(
  79. 'id' => '',
  80. 'name' => '',
  81. 'label' => '',
  82. 'std' => '',
  83. 'class' => '',
  84. 'container_class' => '',
  85. 'desc' => '',
  86. 'required' => array(),
  87. 'target' => array(),
  88. 'shortcode_data' => array(),
  89. 'builder_active' => ''
  90. );
  91.  
  92. $element = array_merge($defaults, $element);
  93.  
  94. return $element;
  95. }
  96.  
  97. /**
  98. *
  99. * @since < 4.0
  100. * @param array $element
  101. * @param aviaShortcodeTemplate|mixed $parent_class
  102. * @return string
  103. */
  104. static public function render_element($element, $parent_class = false)
  105. {
  106. $element = AviaHtmlHelper::validate_element($element);
  107. $output = '';
  108.  
  109. if ($element['builder_active']) {
  110. $output .= "<div class='avia-conditional-elements avia-conditional-elements-builder-active'>";
  111. }
  112.  
  113. self::$elementValues[$element['id']] = $element['std']; //save the values into a unique array in case we need it for dependencies
  114.  
  115. //create default data und class string and checks the dependencies of an object
  116. $dependency = self::check_dependencies($element);
  117. extract($dependency);
  118.  
  119.  
  120. // check if its an ajax request. if so prepend a string to ensure that the ids are unique.
  121. // If there are multiple modal windows called prepend the string multiple times
  122. $element = self::ajax_modify_id($element);
  123.  
  124.  
  125. $id_string = empty($element['id']) ? '' : "id='" . $element['id'] . "-form-container'";
  126. $class_string .= empty($element['container_class']) ? '' : $element['container_class'];
  127. $description_class = empty($element['description_class']) ? '' : $element['description_class'];
  128.  
  129. $target_string = '';
  130. if (!empty($element['target'])) {
  131. $data['target-element'] = $element['target'][0];
  132. $data['target-property'] = $element['target'][1];
  133. $target_string = AviaHelper::create_data_string($data);
  134. $class_string .= " avia-attach-targeting ";
  135. }
  136.  
  137. if (!empty($element['fetchTMPL'])) $class_string .= " avia-attach-templating ";
  138.  
  139.  
  140. if (empty($element['nodescription'])) {
  141. $output .= "<div class='avia_clearfix avia-form-element-container " . $class_string . " avia-element-" . $element['type'] . "' " . $id_string . " " . $data_string . " " . $target_string . ">";
  142.  
  143. if (!empty($element['name']) || !empty($element['desc'])) {
  144. $output .= "<div class='avia-name-description {$description_class}'>";
  145. if (!empty($element['name'])) $output .= "<strong>" . $element['name'] . "</strong>";
  146. if (!empty($element['desc'])) {
  147. if (!empty($element['type']) && $element['type'] != 'checkbox') {
  148. $output .= "<div>" . $element['desc'] . "</div>";
  149. } else {
  150. $output .= "<label for='" . $element['id'] . "'>" . $element['desc'] . "</label>";
  151. }
  152. }
  153.  
  154. $output .= "</div>";
  155. }
  156.  
  157. $output .= "<div class='avia-form-element " . $element['class'] . "'>";
  158. //$output .= self::{$element['type']}($element, $parent_class);
  159.  
  160. if (method_exists(__CLASS__, $element['type'])) {
  161. $output .= call_user_func(array('self', $element['type']), $element, $parent_class, $dependency);
  162. }
  163.  
  164. if (!empty($element['fetchTMPL'])) {
  165. $output .= "<div class='template-container'></div>";
  166. }
  167.  
  168. $output .= "</div>";
  169.  
  170.  
  171.  
  172. $output .= "</div>";
  173. } else {
  174. //$output .= self::{$element['type']}($element, $parent_class);
  175. if (method_exists(__CLASS__, $element['type'])) {
  176. $output .= call_user_func(array('self', $element['type']), $element, $parent_class, $dependency);
  177. }
  178. }
  179.  
  180. if ($element['builder_active']) {
  181. $output .= "<div class='av-builder-active-overlay'></div>";
  182. $output .= "<div class='av-builder-active-overlay-content'>";
  183. $output .= __('This element only works with activated advanced layout builder', 'avia_framework') . "</div>";
  184. $output .= "</div>";
  185. }
  186.  
  187. return $output;
  188. }
  189.  
  190.  
  191. /*
  192. * Helper function that checks dependencies between objects based on the $element['required'] array
  193. *
  194. * If the array is set it needs to have exactly 3 entries.
  195. * The first entry describes which element should be monitored by the current element. eg: "content"
  196. * The second entry describes the comparison parameter. eg: "equals, not, is_larger, is_smaller ,contains"
  197. * The third entry describes the value that we are comparing against.
  198. *
  199. * Example: if the required array is set to array('content','equals','Hello World'); then the current
  200. * element will only be displayed if the element with id "content" has exactly the value "Hello World"
  201. *
  202. */
  203. static public function check_dependencies($element)
  204. {
  205. $params = array('data_string' => '', 'class_string' => '');
  206.  
  207. if (!empty($element['required'])) {
  208. $data['check-element'] = $element['required'][0];
  209. $data['check-comparison'] = $element['required'][1];
  210. $data['check-value'] = $element['required'][2];
  211. $params['data_string'] = AviaHelper::create_data_string($data);
  212. $return = false;
  213.  
  214. //required element must not be hidden. otherwise hide this one by default
  215. if (!isset(self::$elementHidden[$data['check-element']])) {
  216. if (isset(self::$elementValues[$data['check-element']])) {
  217. $value1 = self::$elementValues[$data['check-element']];
  218. $value2 = $data['check-value'];
  219.  
  220. switch ($data['check-comparison']) {
  221. case 'equals':
  222. if ($value1 == $value2) $return = true;
  223. break;
  224. case 'not':
  225. if ($value1 != $value2) $return = true;
  226. break;
  227. case 'is_larger':
  228. if ($value1 > $value2) $return = true;
  229. break;
  230. case 'is_smaller':
  231. if ($value1 < $value2) $return = true;
  232. break;
  233. case 'contains':
  234. if (strpos($value1, $value2) !== false) $return = true;
  235. break;
  236. case 'doesnt_contain':
  237. if (strpos($value1, $value2) === false) $return = true;
  238. break;
  239. case 'is_empty_or':
  240. if (empty($value1) || $value1 == $value2) $return = true;
  241. break;
  242. case 'not_empty_and':
  243. if (!empty($value1) && $value1 != $value2) $return = true;
  244. break;
  245. case 'parent_in_array': // $value1 = "value,id" or "value"
  246. $sep = strpos($value1, ',');
  247. $val = (false !== $sep) ? substr($value1, 0, $sep) : $value1;
  248. if (!empty($val)) {
  249. $return = in_array($val, explode(' ', $value2));
  250. }
  251. break;
  252. case 'parent_not_in_array'; // $value1 = "value,id" or "value"
  253. $sep = strpos($value1, ',');
  254. $val = (false !== $sep) ? substr($value1, 0, $sep) : $value1;
  255. if (!empty($val)) {
  256. $return = !in_array($val, explode(' ', $value2));
  257. }
  258. break;
  259. }
  260. }
  261. }
  262.  
  263. if (!$return) {
  264. $params['class_string'] = ' avia-hidden ';
  265. self::$elementHidden[$element['id']] = true;
  266. }
  267. }
  268.  
  269. return $params;
  270. }
  271.  
  272.  
  273.  
  274.  
  275. /**
  276. * Creates a wrapper around a set of elements. This set can be cloned with javascript
  277. * @param array $element the array holds data like id, class and some js settings
  278. * @return string $output the string returned contains the html code generated within the method
  279. */
  280.  
  281. static public function modal_group($element, $parent_class)
  282. {
  283. $iterations = count($element['std']);
  284. $class = isset($element['class']) ? $element['class'] : '';
  285.  
  286. $output = '';
  287. $output .= "<div class='avia-modal-group-wrapper {$class}' >";
  288.  
  289. if (!empty($element['creator'])) $output .= self::render_element($element['creator']);
  290.  
  291. $output .= "<div class='avia-modal-group' id='" . $element['id'] . "' >";
  292.  
  293. for ($i = 0; $i < $iterations; $i++) {
  294. if (isset($_POST['extracted_shortcode']) && isset($_POST['extracted_shortcode'][$i])) {
  295. $element['shortcode_data'] = $_POST['extracted_shortcode'][$i]['attr'];
  296. }
  297.  
  298. $output .= self::modal_group_sub($element, $parent_class, $i);
  299. }
  300.  
  301.  
  302. $label = isset($element['add_label']) ? $element['add_label'] : __('Add', 'avia_framework');
  303.  
  304.  
  305. //since adding the clone event we display only custom labels and not only the "+" symbol
  306. //$label_class = isset($element['add_label']) ? "avia-custom-label" : '';
  307. $label_class = "avia-custom-label";
  308.  
  309.  
  310. $output .= "</div>";
  311.  
  312. if (!isset($element['disable_manual'])) {
  313. $output .= "<a class='avia-attach-modal-element-add avia-add {$label_class}'>" . $label . "</a>";
  314.  
  315.  
  316. if (!isset($element['disable_cloning'])) {
  317. $clone_label = isset($element['clone_label']) ? $element['clone_label'] : __('Copy and add last entry', 'avia_framework');
  318.  
  319. $output .= "<a class='avia-attach-modal-element-clone avia-clone {$label_class}'>" . $clone_label . "</a>";
  320. }
  321. }
  322.  
  323. //go the new wordpress way and instead of ajax-loading new items, prepare an empty js template
  324. $output .= ' <script type="text/html" class="avia-tmpl-modal-element">';
  325. $output .= self::modal_group_sub($element, $parent_class);
  326. $output .= ' </script>';
  327. $output .= "</div>";
  328.  
  329. return $output;
  330. }
  331.  
  332. /**
  333. *
  334. * @param array $element
  335. * @param aviaShortcodeTemplate $parent_class
  336. * @param int|false $i false, if we need a new empty template to clone if user clicks "Add New"
  337. * @return string
  338. */
  339. static public function modal_group_sub($element, $parent_class, $i = false)
  340. {
  341. $output = '';
  342.  
  343. $args = array();
  344. $content = null;
  345.  
  346. //iterate over the subelements and set user selected values or leave the predefined default values
  347. foreach ($element['subelements'] as $key => $subelement) {
  348. /**
  349. * New WP way: we add an "empty" template filled with predefined default values that we can clone if user wants to add a new item,
  350. * if we have already existing items overwrite default values with user selected values
  351. */
  352. if (false !== $i) {
  353. if (isset($element['std']) && isset($subelement['id']) && is_array($element['std']) && isset($element['std'][$i][$subelement['id']])) {
  354. $subelement['std'] = $element['std'][$i][$subelement['id']];
  355. }
  356. }
  357.  
  358. if (isset($subelement['id'])) {
  359. if ($subelement['id'] == 'content') {
  360. $content = $subelement['std'];
  361. } else {
  362. $args[$subelement['id']] = $subelement['std'];
  363. }
  364. }
  365. }
  366.  
  367. if ($i !== false && is_array($element['shortcode_data'])) {
  368. $args = array_merge($element['shortcode_data'], $args);
  369. }
  370.  
  371.  
  372. $params['args'] = $args;
  373. $params['content'] = $content;
  374.  
  375.  
  376. $defaults = array('class' => '', 'innerHtml' => '');
  377. $params = array_merge($defaults, $params);
  378. $params = $parent_class->editor_sub_element($params);
  379. extract($params);
  380.  
  381. $data['modal_title'] = $element['modal_title'];
  382. $data['modal_open'] = isset($element['modal_open']) ? $element['modal_open'] : 'yes';
  383. $data['trigger_button'] = isset($element['trigger_button']) ? $element['trigger_button'] : '';
  384. $data['shortcodehandler'] = $parent_class->config['shortcode_nested'][0];
  385. $data['closing_tag'] = $parent_class->is_nested_self_closing($parent_class->config['shortcode_nested'][0]) ? 'no' : 'yes';
  386. $data['modal_ajax_hook'] = $parent_class->config['shortcode_nested'][0];
  387. $data['modal_on_load'] = array();
  388.  
  389. if (!empty($element['modal_on_load'])) {
  390. $data['modal_on_load'] = array_merge($data['modal_on_load'], $element['modal_on_load']);
  391. }
  392.  
  393. if (!empty($parent_class->config['modal_on_load'])) {
  394. $data['modal_on_load'] = array_merge($data['modal_on_load'], $parent_class->config['modal_on_load']);
  395. }
  396.  
  397. $dataString = AviaHelper::create_data_string($data);
  398.  
  399.  
  400. $output .= "<div class='avia-modal-group-element ' {$dataString}>";
  401. $output .= "<a class='avia-attach-modal-element-move avia-move-handle'>" . __('Move', 'avia_framework') . "</a>";
  402. $output .= "<a class='avia-attach-modal-element-delete avia-delete'>" . __('Delete', 'avia_framework') . "</a>";
  403. $output .= "<div class='avia-modal-group-element-inner'>";
  404. $output .= $params['innerHtml'];
  405. $output .= "</div>";
  406.  
  407. $output .= "<textarea data-name='text-shortcode' cols='20' rows='4' name='{$element['id']}'>" . ShortcodeHelper::create_shortcode_by_array($parent_class->config['shortcode_nested'][0], $content, $args) . "</textarea>";
  408. $output .= "</div>";
  409. return $output;
  410. }
  411.  
  412.  
  413.  
  414.  
  415.  
  416. /**
  417. *
  418. * Empty Element - The heading method renders a text and description only that might allow to describe some following functionallity
  419. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  420. * @return string $output the string returned contains the html code generated within the method
  421. */
  422. static public function heading($element)
  423. {
  424. return;
  425. }
  426.  
  427. /**
  428. * Returns a single </div> tag
  429. *
  430. * @since < 4.0
  431. * @param array $element
  432. * @return string
  433. */
  434. static public function close_div($element)
  435. {
  436. $output = '</div>';
  437. return $output;
  438. }
  439.  
  440. /**
  441. * Starts a tab container
  442. *
  443. * @since < 4.0
  444. * @param array $element
  445. * @return string
  446. */
  447. static public function tab_container($element)
  448. {
  449. $class = !empty($element['class']) ? $element['class'] : '';
  450.  
  451. $output = "<div class='avia-modal-tab-container {$class}'>";
  452. return $output;
  453. }
  454.  
  455. /**
  456. * Wrapper for better readability
  457. *
  458. * @since 4.6.4
  459. * @param array $element
  460. * @return string
  461. */
  462. static public function tab_container_close($element)
  463. {
  464. return AviaHtmlHelper::close_div($element);
  465. }
  466.  
  467. /**
  468. * Defines a single tab
  469. *
  470. * @since < 4.0
  471. * @param array $element
  472. * @return string
  473. */
  474. static public function tab($element)
  475. {
  476. $output = '';
  477.  
  478. $output .= "<div class='avia-modal-tab-container-inner' data-tab-name='{$element['name']}'>";
  479. return $output;
  480. }
  481.  
  482. /**
  483. * Wrapper for better readability
  484. *
  485. * @since 4.6.4
  486. * @param array $element
  487. * @return string
  488. */
  489. static public function tab_close($element)
  490. {
  491. return AviaHtmlHelper::close_div($element);
  492. }
  493.  
  494.  
  495. /**
  496. * Starts a Toggle Container Element
  497. *
  498. * @since 4.6.4
  499. * @param array $element
  500. * @return string
  501. */
  502. static public function toggle_container($element)
  503. {
  504. $all_closed = empty($element['all_closed']) ? 'no' : 'yes';
  505. $alb_options_toggles = avia_get_option('alb_options_toggles', '');
  506. $alb_options_toggles_class = !empty($alb_options_toggles) ? 'avia-modal-' . $alb_options_toggles : '';
  507.  
  508. $output = "<div class='avia-modal-toggle-container {$alb_options_toggles_class}' data-toggles-closed='{$all_closed}' data-toggles-layout={$alb_options_toggles}>";
  509.  
  510. return $output;
  511. }
  512.  
  513. /**
  514. * Wrapper for better readability
  515. *
  516. * @since 4.6.4
  517. * @param array $element
  518. * @return string
  519. */
  520. static public function toggle_container_close($element)
  521. {
  522. return AviaHtmlHelper::close_div($element);
  523. }
  524.  
  525. /**
  526. * Defines a single toggle element
  527. *
  528. * @since 4.6.4
  529. * @param array $element
  530. * @return string
  531. */
  532. static public function toggle($element)
  533. {
  534. $output = '';
  535.  
  536. $class = !empty($element['container_class']) ? $element['container_class'] : '';
  537.  
  538. $output .= "<div class='avia-modal-toggle-visibility-wrap {$class}'>";
  539. $output .= "<div class='avia-modal-toggle-container-inner' data-toggle-name='{$element['name']}' data-toggle-desc='{$element['desc']}'>";
  540. $output .= '<div class="avia-toggle-description avia-name-description av-builder-note av-neutral">';
  541. $output .= "<strong>{$element['name']}</strong>";
  542. $output .= "<div>{$element['desc']}</div>";
  543. $output .= '</div>';
  544.  
  545. return $output;
  546. }
  547.  
  548. /**
  549. * Wrapper also for better readability
  550. *
  551. * @since 4.6.4
  552. * @param array $element
  553. * @return string
  554. */
  555. static public function toggle_close($element)
  556. {
  557. $output = '';
  558.  
  559. $output .= AviaHtmlHelper::close_div($element);
  560. $output .= AviaHtmlHelper::close_div($element);
  561. return $output;
  562. }
  563.  
  564. /**
  565. * Switcher Container Element
  566. *
  567. * @since 4.6.4
  568. * @param array $element
  569. * @param string $parent_class
  570. * @param array $dependency
  571. * @return string
  572. */
  573. static public function icon_switcher_container($element, $parent_class, $dependency)
  574. {
  575. $data_string = '';
  576. $class_string = '';
  577.  
  578. if (isset($element['nodescription']) && (false !== $element['nodescription'])) {
  579. extract($dependency);
  580. }
  581.  
  582. $output = "<div class='avia-modal-iconswitcher-container avia-form-element-container {$class_string}' {$data_string}>";
  583.  
  584. if (empty($element['name']) && empty($element['desc'])) {
  585. return $output;
  586. }
  587.  
  588. $output .= '<div class="avia-name-description avia-iconswitcher-name-description">';
  589.  
  590. if (!empty($element['name'])) {
  591. $output .= '<strong>' . esc_html($element['name']) . '</strong>';
  592. }
  593. if (!empty($element['desc'])) {
  594. $output .= '<div>' . esc_html($element['desc']) . '</div>';
  595. }
  596.  
  597. $output .= '</div>';
  598.  
  599. return $output;
  600. }
  601.  
  602. /**
  603. * Wrapper for better readability
  604. *
  605. * @since 4.6.4
  606. * @param array $element
  607. * @return string
  608. */
  609. static public function icon_switcher_container_close($element)
  610. {
  611. return AviaHtmlHelper::close_div($element);
  612. }
  613.  
  614.  
  615. /**
  616. *
  617. *
  618. * @since 4.6.4
  619. * @param array $element
  620. * @return string
  621. */
  622. static public function icon_switcher($element)
  623. {
  624. $output = '';
  625. $output .= "<div class='avia-modal-iconswitcher-container-inner' data-switcher-name='{$element['name']}' data-switcher-icon='" . AVIA_BASE_URL . "config-templatebuilder/avia-template-builder/images/iconswitcher/{$element['icon']}.png'>";
  626.  
  627. return $output;
  628. }
  629.  
  630. /**
  631. * Wrapper for better readability
  632. *
  633. * @since 4.6.4
  634. * @param array $element
  635. * @return string
  636. */
  637. static public function icon_switcher_close($element)
  638. {
  639. return AviaHtmlHelper::close_div($element);
  640. }
  641.  
  642.  
  643. /**
  644. *
  645. * Empty Element - The heading method renders a text and description only that might allow to describe some following functionallity
  646. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  647. * @return string $output the string returned contains the html code generated within the method
  648. */
  649. static public function hr($element)
  650. {
  651. $output = "<div class='avia-builder-hr'></div>";
  652. return $output;
  653. }
  654.  
  655. /**
  656. *
  657. * Checks if a certain option has a required value and if not shows a message and makes options within unclickable
  658. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  659. * @return string $output the string returned contains the html code generated within the method
  660. */
  661. static public function condition($element)
  662. {
  663. //array('option' => 'header_position', 'compare' => "equal_or_empty", "value"=>"header_top")
  664.  
  665. if (isset($element['condition']['option'])) {
  666. $option = avia_get_option($element['condition']['option']);
  667. } else {
  668. $key = $element['condition']['element'];
  669. $option = isset($element['shortcode_data'][$key]) ? $element['shortcode_data'][$key] : '';
  670. }
  671.  
  672. $value = $element['condition']['value'];
  673.  
  674. $result = false;
  675. $class = "av_option_hidden";
  676. $overlay = "<div class='av_conditional_overlay_content'>" . $element['notice'] . "</div>";
  677. switch ($element['condition']['compare']) {
  678. case "equals":
  679. if ($option === $value) $result = true;
  680. break;
  681. case "equal_or_empty":
  682. if ($option === $value || $option == '') $result = true;
  683. break;
  684. case "contains":
  685. if (strpos($option, $value) === false) $result = true;
  686. break;
  687. case "not":
  688. if ($option !== $value) $result = true;
  689. break;
  690. }
  691.  
  692.  
  693. if ($result) {
  694. $class = "av_option_visible";
  695. $overlay = '';
  696. }
  697.  
  698. $output = "<div class='avia-conditional-elements {$class}'><div class='av_conditional_overlay'></div>{$overlay}";
  699. return $output;
  700. }
  701.  
  702. static public function condition_end($element)
  703. {
  704. $output = "</div>";
  705. return $output;
  706. }
  707.  
  708.  
  709.  
  710. /**
  711. *
  712. * The tiny_mce method renders a tiny mce text field, also known as the wordpress visual editor
  713. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  714. * @return string $output the string returned contains the html code generated within the method
  715. */
  716. static public function tiny_mce($element)
  717. {
  718. //tinymce only allows ids in the range of [a-z] so we need to filter them.
  719. $element['id'] = preg_replace('![^a-zA-Z_]!', '', $element['id']);
  720.  
  721.  
  722. /* monitor this: seems only ajax elements need the replacement */
  723. $user_ID = get_current_user_id();
  724.  
  725. if (get_user_meta($user_ID, 'rich_editing', true) == "true" && isset($element['ajax'])) {
  726. global $wp_version;
  727.  
  728. //replace new lines with brs, otherwise the editor will mess up. this was fixed with wp 4.3 so only do that in old versions
  729. if (version_compare($wp_version, "4.3", '<')) {
  730. $element['std'] = str_replace("\n", '<br>', $element['std']);
  731. }
  732. }
  733.  
  734.  
  735. ob_start();
  736. wp_editor($element['std'], $element['id'], array('editor_class' => 'avia_advanced_textarea avia_tinymce', 'media_buttons' => true));
  737. $output = ob_get_clean();
  738.  
  739. return $output;
  740. }
  741.  
  742.  
  743.  
  744. /**
  745. *
  746. * The input method renders one or more input type:text elements, based on the definition of the $elements array
  747. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  748. * @return string $output the string returned contains the html code generated within the method
  749. */
  750. static public function input($element)
  751. {
  752. $output = '<input type="text" class="' . $element['class'] . '" value="' . nl2br($element['std']) . '" id="' . $element['id'] . '" name="' . $element['id'] . '"/>';
  753.  
  754. return $output;
  755. }
  756.  
  757. /**
  758. * Return an input field of type number
  759. *
  760. * @since 4.7.3.1
  761. * @param array $element
  762. * @return string
  763. */
  764. static public function input_number($element)
  765. {
  766. $min = isset($element['min']) ? ' min="' . $element['min'] . '"' : '';
  767. $max = isset($element['max']) ? ' max="' . $element['max'] . '"' : '';
  768. $placeholder = isset($element['placeholder']) ? ' placeholder="' . $element['placeholder'] . '"' : '';
  769. $readonly = isset($element['readonly']) ? ' readonly="' . $element['readonly'] . '"' : '';
  770. $step = isset($element['step']) ? ' step="' . $element['step'] . '"' : '';
  771.  
  772. $output = '<input type="number" class="' . $element['class'] . '" value="' . nl2br($element['std']) . '" id="' . $element['id'] . '" name="' . $element['id'] . '" ' . $min . $max . $placeholder . $readonly . $step . '/>';
  773.  
  774. return $output;
  775. }
  776.  
  777.  
  778. /**
  779. *
  780. * The input method renders one or more input type:text elements, based on the definition of the $elements array
  781. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  782. * @return string $output the string returned contains the html code generated within the method
  783. */
  784. static public function multi_input($element)
  785. {
  786. $output = '';
  787. $count = 0;
  788. $element['std'] = explode(",", $element['std']);
  789. $value = '';
  790. $checked = count(array_unique($element['std'], SORT_STRING));
  791.  
  792.  
  793. $output .= "<div class='av-multi-input-table'>";
  794. foreach ($element['multi'] as $multi => $label) {
  795. $output .= "<div class='av-multi-input-cell'>";
  796. $value = isset($element['std'][$count]) ? $element['std'][$count] : $value;
  797. $disable = ($checked === 1 && $count !== 0 && !empty($element['sync'])) ? 'disabled' : '';
  798.  
  799. $output .= !empty($label) ? "<div class='av-multi-input-label'>{$label}</div>" : '';
  800. $output .= '<input ' . $disable . ' type="text" class="' . $element['class'] . '" value="' . nl2br($value) . '" id="' . $element['id'] . '_' . $multi . '" name="' . $element['id'] . '"/>';
  801. $output .= "</div>";
  802.  
  803. $count++;
  804. }
  805. $output .= "</div>";
  806.  
  807. if (isset($element['sync'])) {
  808. $checked = $checked === 1 ? "checked='checked'" : '';
  809. $label = __('Apply the same value to all?', 'avia_framework');
  810. $output .= "<label class='av-multi-input-label-sync'>";
  811. $output .= '<input ' . $checked . ' type="checkbox" class="' . $element['class'] . '_sync" value="true" id="' . $element['id'] . '_sync" name="' . $element['id'] . '_sync"/>';
  812. $output .= $label . "</label>";
  813. }
  814.  
  815.  
  816. return $output;
  817. }
  818.  
  819.  
  820. /**
  821. *
  822. * The hidden method renders a single input type:hidden element
  823. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  824. * @return string $output the string returned contains the html code generated within the method
  825. */
  826. static public function hidden($element)
  827. {
  828. $output = '<input type="hidden" value="' . $element['std'] . '" id="' . $element['id'] . '" name="' . $element['id'] . '"/>';
  829. return $output;
  830. }
  831.  
  832. /**
  833. *
  834. * The checkbox method renders a single input type:checkbox element
  835. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  836. * @return string $output the string returned contains the html code generated within the method
  837. * @todo: fix: checkboxes at metaboxes currently dont work
  838. */
  839. static public function checkbox($element)
  840. {
  841.  
  842. $checked = '';
  843. if ($element['std'] != '') {
  844. $checked = 'checked = "checked"';
  845. }
  846.  
  847. $output = '<input ' . $checked . ' type="checkbox" class="' . $element['class'] . '" ';
  848. $output .= 'value="' . $element['id'] . '" id="' . $element['id'] . '" name="' . $element['id'] . '"/>';
  849.  
  850. return $output;
  851. }
  852.  
  853. /**
  854. *
  855. * The textarea method renders a single textarea element
  856. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  857. * @return string $output the string returned contains the html code generated within the method
  858. */
  859. static public function textarea($element)
  860. {
  861. $output = '<textarea rows="5" cols="30" class="' . $element['class'] . '" id="' . $element['id'] . '" name="' . $element['id'] . '">';
  862. $output .= rtrim($element['std']) . '</textarea>';
  863. return $output;
  864. }
  865.  
  866.  
  867. /**
  868. *
  869. * The iconfont method renders a single icon-select element based on a font
  870. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  871. * @return string $output the string returned contains the html code generated within the method
  872. */
  873. static public function iconfont($element)
  874. {
  875. $output = '';
  876.  
  877. if (!empty($element['chars']) && is_array($element['chars'])) {
  878. $chars = $element['chars'];
  879. } else {
  880. $chars = avia_font_manager::load_charlist();
  881. }
  882.  
  883. //get either the passed font or the default font
  884. $std_font = isset($element['shortcode_data']['font']) ? $element['shortcode_data']['font'] : key(AviaBuilder::$default_iconfont);
  885.  
  886. $output .= "<div class='avia_icon_select_container avia-attach-element-container'>";
  887.  
  888. $run = 0;
  889. $active_font = '';
  890. foreach ($chars as $font => $charset) {
  891. $run++;
  892. asort($charset);
  893.  
  894. if ($run === 1) {
  895. //if the el value is empty set it to the first char
  896. if (empty($element['std'])) $element['std'] = key($charset);
  897. $standard = avia_font_manager::get_display_char($element['std'], $std_font);
  898. }
  899.  
  900. $output .= "<div class='av-iconselect-heading'>Font: {$font}</div>";
  901. foreach ($charset as $key => $char) {
  902. $char = avia_font_manager::try_decode_icon($char);
  903. $charcode_prefix = "Charcode: \\";
  904. $active_char = '';
  905.  
  906. if ($char == $standard && !empty($std_font) && $std_font == $font) {
  907. $active_char = "avia-active-element";
  908. $active_font = $font;
  909. }
  910.  
  911. $output .= "<span title='{$charcode_prefix}{$key}' data-element-nr='{$key}' data-element-font='{$font}' class='avia-attach-element-select avia_icon_preview avia-font-{$font} {$active_char}'>{$char}</span>";
  912. }
  913. }
  914.  
  915. //default icon value
  916. $output .= self::hidden($element);
  917.  
  918. //fake character value needed for backend editor
  919. $element['id'] = $element['id'] . "_fakeArg";
  920. $element['std'] = empty($standard) ? '' : $standard;
  921. $output .= self::hidden($element);
  922.  
  923. //font value needed for backend and editor
  924. $element['id'] = "font";
  925. $element['std'] = $active_font;
  926. $element = self::ajax_modify_id($element);
  927. $output .= self::hidden($element);
  928.  
  929.  
  930. $output .= "</div>";
  931.  
  932. return $output;
  933. }
  934.  
  935.  
  936.  
  937.  
  938.  
  939. /**
  940. *
  941. * The colorpicker method renders a colorpicker element that allows you to select a color of your choice
  942. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  943. * @return string $output the string returned contains the html code generated within the method
  944. */
  945. static public function colorpicker($element)
  946. {
  947. $data = '';
  948. if (!empty($element['rgba'])) {
  949. $data = "data-av-rgba='1'";
  950. }
  951.  
  952. $output = '<input type="text" class="av-colorpicker ' . $element['class'] . '" value="' . $element['std'] . '" id="' . $element['id'] . '" name="' . $element['id'] . '" ' . $data . ' />';
  953.  
  954. return $output;
  955. }
  956.  
  957. /**
  958. * The datepicker method renders a datepicker element that allows you to select a date of your choice.
  959. * See http://api.jqueryui.com/datepicker/ for possible parameters and values. If you want to extend parmeters also adjust list in
  960. * enfold\config-templatebuilder\avia-template-builder\assets\js\avia-modal.js function $.AviaModal.register_callback.modal_load_datepicker.
  961. *
  962. * Add parameters to modify to array 'dp_params' when defining the datepicker in popup editor.
  963. * Values are rendered 1:1 with js. Arrays must be defined as array.
  964. * Default parameters do not need to be set.
  965. *
  966. * @since < 4.0
  967. * @modified 4.5.6.1 by Günter
  968. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  969. * @return string $output the string returned contains the html code generated within the method
  970. */
  971. static public function datepicker(array $element)
  972. {
  973. global $wp_locale;
  974.  
  975. /**
  976. * Default values are set to be backwards comp. befor
  977. */
  978. $args = array(
  979. 'showButtonPanel' => false,
  980. 'closeText' => __('Close', 'avia_framework'),
  981. 'currentText' => __('Today', 'avia_framework'),
  982. 'nextText' => __('Next', 'avia_framework'),
  983. 'prevText' => __('Prev', 'avia_framework'),
  984. 'monthNames' => array_values($wp_locale->month),
  985. 'monthNamesShort' => array_values($wp_locale->month_abbrev),
  986. 'dayNames' => array_values($wp_locale->weekday),
  987. 'dayNamesShort' => array_values($wp_locale->weekday_abbrev),
  988. 'dayNamesMin' => array_values($wp_locale->weekday_initial),
  989. 'dateFormat' => 'mm / dd / yy',
  990. 'firstDay' => get_option('start_of_week'),
  991. 'isRTL' => $wp_locale->is_rtl(),
  992. 'changeMonth' => false,
  993. 'changeYear' => false,
  994. // 'minDate' => -0, // 'mm / dd / yy' | number
  995. // 'maxDate' => '', //
  996. // 'yearRange' => "c-80:c+10",
  997. // 'container_class' => '' // 'select_dates_30' | ''
  998. );
  999.  
  1000. if (is_array($element['dp_params'])) {
  1001. $args = array_merge($args, $element['dp_params']);
  1002. }
  1003.  
  1004. $data_params = AviaHelper::create_data_string($args);
  1005.  
  1006. $output = '<input type="text" class="av-datepicker av-no-autoselect ' . $element['class'] . '" value="' . $element['std'] . '" id="' . $element['id'] . '" name="' . $element['id'] . '" ' . $data_params . ' />';
  1007.  
  1008. return $output;
  1009. }
  1010.  
  1011.  
  1012. /**
  1013. *
  1014. * The linkpicker method renders a linkpicker element that allows you to select a link to a post type or taxonomy type of your choice
  1015. *
  1016. * Supported:
  1017. * '' | 'manually' | 'single' | 'taxonomy' | 'lightbox'
  1018. *
  1019. * @since < 4.0
  1020. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  1021. * @return string $output the string returned contains the html code generated within the method
  1022. *
  1023. * @todo: currently only one linkpicker per modal window possible
  1024. */
  1025. static public function linkpicker($element)
  1026. {
  1027. //fallback for previous default input link elements: convert a https://kriesi.at value to a manually entry
  1028. if (strpos($element['std'], 'http://') === 0) $element['std'] = 'manually,' . $element['std'];
  1029.  
  1030.  
  1031. //necessary for installations with thousands of posts
  1032. @ini_set("memory_limit", "256M");
  1033.  
  1034. $original = $element;
  1035. $new_std = explode(',', $element['std'], 2);
  1036.  
  1037. $pt = array_flip(AviaHelper::public_post_types());
  1038. $ta = array_flip(AviaHelper::public_taxonomies(false, true));
  1039.  
  1040. if (isset($new_std[1])) $original['std'] = $new_std[1];
  1041.  
  1042. $allowed_pts = isset($original['posttype']) ? $original['posttype'] : $pt;
  1043. $allowed_tas = isset($original['taxtype']) ? $original['taxtype'] : $ta;
  1044.  
  1045. if (in_array('single', $element['subtype'])) {
  1046. foreach ($pt as $key => $type) {
  1047. if (in_array($type, $allowed_pts)) {
  1048. $html = AviaHtmlHelper::select_hierarchical_post_types($element, $type);
  1049.  
  1050. if (false === $html) {
  1051. $original['subtype'] = $type;
  1052. $html = self::select($original);
  1053. }
  1054.  
  1055. if (!empty($html)) {
  1056. AviaHelper::register_template($original['id'] . '-' . $type, $html);
  1057. } else {
  1058. unset($pt[$key]);
  1059. }
  1060. } else {
  1061. unset($pt[$key]);
  1062. }
  1063. }
  1064. }
  1065.  
  1066. if (in_array('taxonomy', $element['subtype'])) {
  1067. foreach ($ta as $key => $type) {
  1068. if (in_array($type, $allowed_tas)) {
  1069. $html = AviaHtmlHelper::select_hierarchical_taxonomy($element, $type);
  1070.  
  1071. if (false === $html) {
  1072. $original['subtype'] = 'cat';
  1073. $original['taxonomy'] = $type;
  1074.  
  1075. $html = self::select($original);
  1076. }
  1077.  
  1078. if (!empty($html)) {
  1079. AviaHelper::register_template($original['id'] . '-' . $type, $html);
  1080. } else {
  1081. unset($ta[$key]);
  1082. }
  1083. } else {
  1084. unset($ta[$key]);
  1085. }
  1086. }
  1087. }
  1088.  
  1089. if (isset($new_std[1])) $element['std'] = $new_std[1];
  1090.  
  1091. $original['subtype'] = array();
  1092. foreach ($element['subtype'] as $value => $key) //register templates
  1093. {
  1094. switch ($key) {
  1095. case "manually":
  1096.  
  1097. if ($new_std[0] != $key) $element['std'] = "http://";
  1098.  
  1099. $original['subtype'][$value] = $key;
  1100. $html = self::input($element);
  1101. AviaHelper::register_template($original['id'] . '-' . $key, $html);
  1102. break;
  1103.  
  1104. case "single":
  1105. $original['subtype'][$value] = $pt;
  1106. break;
  1107.  
  1108. case "taxonomy":
  1109. $original['subtype'][$value] = $ta;
  1110. break;
  1111.  
  1112. default:
  1113. $original['subtype'][$value] = $key;
  1114. break;
  1115. }
  1116. }
  1117.  
  1118. if (!empty($element['ajax'])) // if we got an ajax request we also need to call the printing since the default wordpress hook is already executed
  1119. {
  1120. AviaHelper::print_templates();
  1121. }
  1122.  
  1123. $original['std'] = $new_std[0];
  1124. unset($original['multiple']);
  1125. $output = self::select($original);
  1126. return $output;
  1127. }
  1128.  
  1129.  
  1130. /**
  1131. *
  1132. * The image method renders an image upload button that allows the user to select an image from the media uploader and insert it
  1133. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  1134. * @return string $output the string returned contains the html code generated within the method
  1135. */
  1136. static public function image($element)
  1137. {
  1138. if (empty($element['data'])) {
  1139. $fetch = isset($element['fetch']) ? $element['fetch'] : "url";
  1140. $state = isset($element['state']) ? $element['state'] : "avia_insert_single";
  1141.  
  1142. if (empty($element['show_options'])) {
  1143. $class = $fetch == "id" ? "avia-media-img-only-no-sidebars" : "avia-media-img-only";
  1144. } else if ($element['show_options'] == true) {
  1145. $class = "avia-media-img-only";
  1146. }
  1147.  
  1148.  
  1149. $element['data'] = array(
  1150. 'target' => $element['id'],
  1151. 'title' => $element['title'],
  1152. 'type' => $element['type'],
  1153. 'button' => $element['button'],
  1154. 'class' => 'media-frame ' . $class . ' ' . $element['container_class'],
  1155. 'frame' => 'select',
  1156. 'state' => $state,
  1157. 'fetch' => $fetch,
  1158. 'save_to' => 'hidden'
  1159. );
  1160. }
  1161.  
  1162. if (isset($element['modal_class'])) $element['data']['class'] .= " " . $element['modal_class'];
  1163.  
  1164.  
  1165. $data = AviaHelper::create_data_string($element['data']);
  1166. $class = 'button aviabuilder-image-upload avia-builder-image-insert ' . $element['class'];
  1167. $output = ' <a href="#" class="' . $class . '" ' . $data . ' title="' . esc_attr($element['title']) . '">' . $element['title'] . '</a>';
  1168.  
  1169. if (isset($element['delete'])) $output .= '<a href="#" class="button avia-delete-gallery-button" title="' . esc_attr($element['delete']) . '">' . $element['delete'] . '</a>';
  1170.  
  1171.  
  1172. $attachmentids = !empty($element['shortcode_data']['attachment']) ? explode(',', $element['shortcode_data']['attachment']) : array();
  1173. $attachmentid = !empty($attachmentids[self::$imageCount]) ? $attachmentids[self::$imageCount] : '';
  1174.  
  1175. $attachmentsizes = !empty($element['shortcode_data']['attachment_size']) ? explode(',', $element['shortcode_data']['attachment_size']) : array();
  1176. $attachmentsize = !empty($attachmentsizes[self::$imageCount]) ? $attachmentsizes[self::$imageCount] : '';
  1177.  
  1178. //get image based on id if possible - use the force_id_fetch param in conjunction with the secondary_img when you need a secondary image based on id and not on url like pattern overlay. size of a secondary image can not be stored. tab section element is a working example
  1179. if (!empty($attachmentid) && !empty($attachmentsize) && empty($element['force_id_fetch'])) {
  1180. $fake_img = wp_get_attachment_image($attachmentid, $attachmentsize);
  1181. $url = wp_get_attachment_image_src($attachmentid, $attachmentsize);
  1182. $url = !empty($url[0]) ? $url[0] : '';
  1183. } else if (isset($fetch) && $fetch == "id") {
  1184. $fake_img = wp_get_attachment_image($element['std'], 'thumbnail');
  1185. $url = wp_get_attachment_image_src($element['std'], 'thumbnail');
  1186. $url = !empty($url[0]) ? $url[0] : '';
  1187. } else {
  1188. $fake_img = '<img src="' . $element['std'] . '" />';
  1189. $url = $element['std'];
  1190. }
  1191.  
  1192.  
  1193. if ($element['type'] != 'video') {
  1194. $output .= self::display_image($url);
  1195. }
  1196.  
  1197. //$output .= self::$element['data']['save_to']($element);
  1198. $output .= call_user_func(array('self', $element['data']['save_to']), $element);
  1199.  
  1200. //fake img for multi_image element
  1201. if (isset($fetch)) {
  1202.  
  1203. $fake_img_id = str_replace(str_replace('aviaTB', '', $element['id']), 'img_fakeArg', $element['id']);
  1204. $img_id_field = str_replace(str_replace('aviaTB', '', $element['id']), 'attachment', $element['id']);
  1205. $img_size_field = str_replace(str_replace('aviaTB', '', $element['id']), 'attachment_size', $element['id']);
  1206.  
  1207. $output .= '<input type="hidden" class="hidden-image-url ' . $element['class'] . '" value="' . htmlentities($fake_img, ENT_QUOTES, get_bloginfo('charset')) . '" id="' . $fake_img_id . '" name="' . $fake_img_id . '"/>';
  1208.  
  1209. if ($fetch == 'url' && empty($element['secondary_img'])) {
  1210.  
  1211. $output .= '<input type="hidden" class="hidden-attachment-id ' . $element['class'] . '" value="' . $attachmentid . '" id="' . $img_id_field . '" name="' . $img_id_field . '"/>';
  1212. $output .= '<input type="hidden" class="hidden-attachment-size ' . $element['class'] . '" value="' . $attachmentsize . '" id="' . $img_size_field . '" name="' . $img_size_field . '"/>';
  1213. }
  1214. }
  1215.  
  1216. if (empty($element['force_id_fetch'])) {
  1217. if ($element['type'] != 'video') self::$imageCount++;
  1218. }
  1219. return $output;
  1220. }
  1221.  
  1222. /**
  1223. *
  1224. * The gallery method renders an image upload button that allows the user to select an image from the media uploader and insert it
  1225. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  1226. * @return string $output the string returned contains the html code generated within the method
  1227. */
  1228. static public function gallery($element)
  1229. {
  1230. if (empty($element['data'])) {
  1231. $element['data'] = array(
  1232. 'target' => $element['id'],
  1233. 'title' => $element['title'],
  1234. 'type' => $element['type'],
  1235. 'button' => $element['button'],
  1236. 'class' => 'media-frame avia-media-gallery-insert ' . $element['container_class'],
  1237. 'frame' => 'post',
  1238. 'state' => 'gallery-library',
  1239. 'state_edit' => 'gallery-edit',
  1240. 'fetch' => 'id',
  1241. 'save_to' => 'hidden'
  1242. );
  1243. }
  1244.  
  1245. return AviaHtmlHelper::image($element);
  1246. }
  1247.  
  1248. /**
  1249. *
  1250. * The video method renders a video upload button that allows the user to select an video from the media uploader and insert it
  1251. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  1252. * @return string $output the string returned contains the html code generated within the method
  1253. */
  1254. static public function video($element)
  1255. {
  1256. if (empty($element['data'])) {
  1257. $element['data'] = array(
  1258. 'target' => $element['id'],
  1259. 'title' => $element['title'],
  1260. 'type' => $element['type'],
  1261. 'button' => $element['button'],
  1262. 'class' => 'media-frame avia-blank-insert ' . $element['container_class'],
  1263. 'state' => 'avia_insert_video',
  1264. 'frame' => 'select',
  1265. 'fetch' => 'url',
  1266. 'save_to' => 'input'
  1267. );
  1268. }
  1269.  
  1270. return AviaHtmlHelper::image($element);
  1271. }
  1272.  
  1273. /**
  1274. * The audio method renders an audio upload button that allows the user to select one or more audio files from the media uploader
  1275. * and insert it
  1276. *
  1277. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  1278. * @return string the string returned contains the html code generated within the method
  1279. */
  1280. public static function audio_player($element)
  1281. {
  1282. if (empty($element['data'])) {
  1283. $fetch = isset($element['fetch']) ? $element['fetch'] : "template_audio";
  1284. $state = isset($element['state']) ? $element['state'] : "avia_insert_multi_audio";
  1285.  
  1286. $class = $fetch == "template" ? "avia-media-img-only-no-sidebars" : "avia-media-img-only";
  1287.  
  1288. $element['data'] = array(
  1289. 'target' => $element['id'],
  1290. 'title' => $element['title'],
  1291. 'type' => $element['type'],
  1292. 'button' => $element['button'],
  1293. 'class' => 'media-frame avia-media-audio-insert ' . $element['container_class'],
  1294. 'frame' => 'post',
  1295. 'state' => 'playlist-library',
  1296. 'state_edit' => 'playlist-edit',
  1297. 'fetch' => $fetch,
  1298. 'save_to' => 'html',
  1299. 'media_type' => 'audio'
  1300. );
  1301. }
  1302.  
  1303. $data = AviaHelper::create_data_string($element['data']);
  1304. $class = 'button aviabuilder-image-upload avia-builder-image-insert avia-builder-audio-edit ' . $element['class'];
  1305. $output = ' <a href="#" class="' . $class . '" ' . $data . ' title="' . esc_attr($element['title']) . '">
  1306. <span class="wp-media-buttons-icon"></span>' . $element['title'] . '</a>';
  1307.  
  1308. return $output;
  1309. }
  1310.  
  1311.  
  1312.  
  1313.  
  1314. /**
  1315. *
  1316. * The multi_image method allows us to insert many images into a modal template at once
  1317. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  1318. * @return string $output the string returned contains the html code generated within the method
  1319. */
  1320. static public function multi_image($element)
  1321. {
  1322. if (empty($element['data'])) {
  1323. $fetch = isset($element['fetch']) ? $element['fetch'] : "template";
  1324. $state = isset($element['state']) ? $element['state'] : "avia_insert_multi";
  1325.  
  1326. if (empty($element['show_options'])) {
  1327. $class = $fetch == "template" ? "avia-media-img-only-no-sidebars" : "avia-media-img-only";
  1328. } else if ($element['show_options'] == true) {
  1329. $class = "avia-media-img-only";
  1330. }
  1331.  
  1332. $element['data'] = array(
  1333. 'target' => $element['id'],
  1334. 'title' => $element['title'],
  1335. 'type' => $element['type'],
  1336. 'button' => $element['button'],
  1337. 'class' => 'media-frame ' . $class . ' ' . $element['container_class'],
  1338. 'frame' => 'select',
  1339. 'state' => $state,
  1340. 'fetch' => $fetch,
  1341. );
  1342. }
  1343.  
  1344. $data = AviaHelper::create_data_string($element['data']);
  1345. $class = 'button aviabuilder-image-upload avia-builder-image-insert ' . $element['class'];
  1346. $output = ' <a href="#" class="' . $class . '" ' . $data . ' title="' . esc_attr($element['title']) . '">
  1347. <span class="wp-media-buttons-icon"></span>' . $element['title'] . '</a>';
  1348.  
  1349.  
  1350. return $output;
  1351. }
  1352.  
  1353.  
  1354. /**
  1355. * Return an indented dropdown list for hierarchical post types
  1356. *
  1357. * @since 4.2.7
  1358. * @added_by Günter
  1359. * @param array $element
  1360. * @param string $post_type
  1361. * @return string|false
  1362. */
  1363. static public function select_hierarchical_post_types(array $element, $post_type = 'page')
  1364. {
  1365. $defaults = array(
  1366. 'id' => '',
  1367. 'std' => array('', 0),
  1368. 'label' => false, // for option group
  1369. 'class' => '',
  1370. 'hierarchical' => 'yes', // 'yes' | 'no'
  1371. 'post_status' => 'publish', // array or seperated by comma
  1372. 'option_none_text' => '', // text to display for "Nothing selected"
  1373. 'option_none_value' => '', // value for 'option_none_text'
  1374. 'option_no_change' => '' // value for 'no change' - set to -1 by WP default
  1375. );
  1376.  
  1377. $element = array_merge($defaults, $element);
  1378.  
  1379.  
  1380. /**
  1381. * return, if element should not display a hierarchical structure
  1382. */
  1383. if ('no' == $element['hierarchical']) {
  1384. return false;
  1385. }
  1386.  
  1387. /**
  1388. * wp_dropdown_pages() does not support multiple selection by default.
  1389. * Would need to overwrite Walker_PageDropdown to add this feature.
  1390. *
  1391. * Can be done in future if necessary.
  1392. */
  1393. if (isset($element['multiple'])) {
  1394. return false;
  1395. }
  1396.  
  1397. $post_type_object = get_post_type_object($post_type);
  1398.  
  1399. if (!($post_type_object instanceof WP_Post_Type && $post_type_object->hierarchical)) {
  1400. return false;
  1401. }
  1402.  
  1403. /**
  1404. * If too many entries limit output and only show non hierarchical
  1405. *
  1406. * @since 4.2.7
  1407. */
  1408. $limit = apply_filters('avf_dropdown_post_number', 4000, $post_type, $element, 'alb_select_hierarchical');
  1409. $count = wp_count_posts($post_type);
  1410. if (!isset($count->publish) || ($count->publish > $limit)) {
  1411. return false;
  1412. }
  1413.  
  1414. /**
  1415. * Make sure we have no spaces
  1416. */
  1417. $post_status = is_array($element['post_status']) ? $element['post_status'] : explode(',', (string) $element['post_status']);
  1418. $element['post_status'] = array_map(function ($value) {
  1419. $value = trim($value);
  1420. return $value;
  1421. }, $post_status);
  1422.  
  1423.  
  1424. $new_std = explode(',', $element['std'], 2);
  1425. $selected = (($new_std[0] == $post_type) && isset($new_std[1])) ? $new_std[1] : 0;
  1426. $selected = apply_filters('wpml_object_id', $selected, $new_std[0], true );
  1427. /**
  1428. * @used_by config-wpml\config.php avia_wpml_alb_options_select_hierarchical_post_type_id() 10
  1429. *
  1430. * @since 4.5.7.2
  1431. * @param int $selected
  1432. * @param string $post_type
  1433. * @param array $new_std
  1434. * @param array $element
  1435. * @return int
  1436. */
  1437. $selected = apply_filters('avf_alb_options_select_hierarchical_post_type_id', $selected, $post_type, $new_std, $element);
  1438.  
  1439. $data_string = '';
  1440. if (isset($element['data'])) {
  1441. foreach ($element['data'] as $key => $data) {
  1442. $data_string .= " data-" . $key . "='" . $data . "'";
  1443. }
  1444. }
  1445.  
  1446. $multi = $multi_class = '';
  1447. if (isset($element['multiple'])) {
  1448. $multi_class = " avia_multiple_select";
  1449. $multi = ' multiple="multiple" size="' . $element['multiple'] . '" ';
  1450. }
  1451.  
  1452. $dropdown_args = array(
  1453. 'post_type' => $post_type,
  1454. 'exclude_tree' => false,
  1455. 'selected' => $selected,
  1456. 'name' => $element['id'],
  1457. 'id' => $element['id'],
  1458. 'show_option_none' => $element['option_none_text'],
  1459. 'option_none_value' => $element['option_none_value'],
  1460. 'show_option_no_change' => $element['option_no_change'],
  1461. 'sort_column' => 'post_title',
  1462. 'echo' => 0,
  1463. 'class' => $element['class'] . $multi_class,
  1464. 'post_status' => $element['post_status']
  1465. // 'depth' => 0,
  1466. // 'child_of' => 0,
  1467. // 'value_field' => 'ID',
  1468. );
  1469.  
  1470. /**
  1471. * Allow to add info for non public post status
  1472. */
  1473. add_filter('list_pages', __CLASS__ . '::handler_wp_list_pages', 99, 2);
  1474.  
  1475. $html = wp_dropdown_pages($dropdown_args);
  1476.  
  1477. remove_filter('list_pages', __CLASS__ . '::handler_wp_list_pages', 99, 2);
  1478.  
  1479. $html = str_replace('<select', '<select ' . $multi . $data_string, $html);
  1480.  
  1481. return $html;
  1482. }
  1483.  
  1484.  
  1485. /**
  1486. * Add post status in case of non public
  1487. * WP hooks into this filter with _wp_privacy_settings_filter_draft_page_titles since 4.9.8 with WP_Post as $page
  1488. * and adds (Draft)
  1489. *
  1490. * @since 4.2.7
  1491. * @added_by Günter
  1492. * @param string $title
  1493. * @param WP_Post $page
  1494. * @return string
  1495. */
  1496. static public function handler_wp_list_pages($title, $page)
  1497. {
  1498. if (!$page instanceof WP_Post) {
  1499. return $title;
  1500. }
  1501.  
  1502. if (!in_array($page->post_status, array('publish'))) {
  1503. $title .= ' (' . ucfirst($page->post_status) . ')';
  1504. }
  1505.  
  1506. return $title;
  1507. }
  1508.  
  1509. /**
  1510. * Return an indented dropdown list of terms for hierarchical $taxonomy
  1511. *
  1512. * @since 4.2.7
  1513. * @added_by Günter
  1514. * @param array $element
  1515. * @param string $taxonomy
  1516. * @return string|false
  1517. */
  1518. static public function select_hierarchical_taxonomy(array $element, $taxonomy = 'category')
  1519. {
  1520. $defaults = array(
  1521. 'id' => '',
  1522. 'std' => array('', 0),
  1523. 'label' => false, // for option group
  1524. 'class' => '',
  1525. 'hierarchical' => 'yes', // 'yes' | 'no'
  1526. 'option_none_text' => '', // text to display for "Nothing selected"
  1527. 'option_none_value' => '', // value for 'option_none_text'
  1528. 'option_no_change' => '' // value for 'no change' - set to -1 by WP default
  1529. );
  1530.  
  1531. $element = array_merge($defaults, $element);
  1532.  
  1533. /**
  1534. * return, if element should not display a hierarchical structure
  1535. */
  1536. if ('no' == $element['hierarchical']) {
  1537. return false;
  1538. }
  1539.  
  1540. /**
  1541. * wp_dropdown_pages() does not support multiple selection by default.
  1542. * Would need to overwrite Walker_CategoryDropdown to add this feature.
  1543. *
  1544. * Can be done in future if necessary.
  1545. */
  1546. if (isset($element['multiple'])) {
  1547. return false;
  1548. }
  1549.  
  1550. $obj_ta = get_taxonomy($taxonomy);
  1551.  
  1552. if (!$obj_ta instanceof WP_Taxonomy) {
  1553. return false;
  1554. }
  1555.  
  1556. $new_std = explode(',', $element['std'], 2);
  1557. $selected = (($new_std[0] == $taxonomy) && isset($new_std[1])) ? $new_std[1] : 0;
  1558.  
  1559. /**
  1560. * @used_by config-wpml\config.php avia_wpml_alb_options_select_hierarchical_post_type_id() 10
  1561. *
  1562. * @since 4.5.7.2
  1563. * @param int $selected
  1564. * @param string $post_type
  1565. * @param array $new_std
  1566. * @param array $element
  1567. * @return int
  1568. */
  1569. $selected = apply_filters('avf_alb_options_select_hierarchical_post_type_id', $selected, $taxonomy, $new_std, $element);
  1570.  
  1571. $data_string = '';
  1572. if (isset($element['data'])) {
  1573. foreach ($element['data'] as $key => $data) {
  1574. $data_string .= " data-" . $key . "='" . $data . "'";
  1575. }
  1576. }
  1577.  
  1578. $multi = $multi_class = '';
  1579. if (isset($element['multiple'])) {
  1580. $multi_class = " avia_multiple_select";
  1581. $multi = ' multiple="multiple" size="' . $element['multiple'] . '" ';
  1582. }
  1583.  
  1584. $args = array(
  1585. 'taxonomy' => $taxonomy,
  1586. 'hierarchical' => true,
  1587. 'depth' => 20,
  1588. 'selected' => $selected,
  1589. 'name' => $element['id'],
  1590. 'id' => $element['id'],
  1591. 'show_option_none' => $element['option_none_text'],
  1592. 'option_none_value' => $element['option_none_value'],
  1593. 'show_option_no_change' => $element['option_no_change'],
  1594. 'orderby' => 'name',
  1595. 'order' => 'ASC',
  1596. 'echo' => false,
  1597. 'class' => $element['class'] . $multi_class,
  1598. 'hide_empty' => false,
  1599. 'show_count' => true,
  1600. 'hide_if_empty' => false,
  1601. // 'child_of' => 0,
  1602. // 'exclude' => '',
  1603. // 'include' => '',
  1604. // 'tab_index' => 0,
  1605. // 'value_field' => 'term_id',
  1606. );
  1607.  
  1608. $html = wp_dropdown_categories($args);
  1609.  
  1610. $html = str_replace('<select', '<select ' . $multi . $data_string, $html);
  1611.  
  1612. return $html;
  1613. }
  1614.  
  1615.  
  1616. /**
  1617. *
  1618. * The select method renders a single select element: it either lists custom values, all wordpress pages or all wordpress categories
  1619. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  1620. * @return string $output the string returned contains the html code generated within the method
  1621. */
  1622.  
  1623. static public function select($element)
  1624. {
  1625. $select = __('Select', 'avia_framework');
  1626. $parents = array();
  1627. $fake_val = '';
  1628. $entries = array();
  1629.  
  1630. if ($element['subtype'] == 'cat') {
  1631. $add_taxonomy = '';
  1632.  
  1633. if (!empty($element['taxonomy'])) $add_taxonomy = "&taxonomy=" . $element['taxonomy'];
  1634.  
  1635. $entries = get_categories('title_li=&orderby=name&hide_empty=0' . $add_taxonomy);
  1636.  
  1637. //sort entries so subentries are displayed with indentation
  1638.  
  1639. foreach ($entries as $key => $entry) {
  1640. if (!empty($entry->parent)) {
  1641. $parents[$entry->parent][$entry->term_id] = $entry;
  1642. unset($entries[$key]);
  1643. }
  1644. }
  1645. } else if (!is_array($element['subtype'])) {
  1646. global $wpdb;
  1647. $table_name = $wpdb->prefix . "posts";
  1648. $limit = apply_filters('avf_dropdown_post_number', 4000, $element['subtype'], $element, 'alb_select');
  1649.  
  1650. if (isset(AviaHtmlHelper::$cache['entry_' . $limit]) && isset(AviaHtmlHelper::$cache['entry_' . $limit][$element['subtype']])) {
  1651. $entries = AviaHtmlHelper::$cache['entry_' . $limit][$element['subtype']];
  1652. } else {
  1653. $post_status = (!empty($element['post_status'])) ? $element['post_status'] : 'publish';
  1654. $post_status = explode(',', $post_status);
  1655. $post_status = array_map(function ($value) {
  1656. $value = trim($value);
  1657. return "'{$value}'";
  1658. }, $post_status);
  1659. $post_status = implode(', ', $post_status);
  1660.  
  1661. $prepare_sql = "SELECT distinct ID, post_title, post_status FROM {$table_name} WHERE post_status IN ( {$post_status} ) AND post_type = '" . $element['subtype'] . "' ORDER BY post_title ASC LIMIT {$limit}";
  1662. $prepare_sql = apply_filters('avf_dropdown_post_query', $prepare_sql, $table_name, $limit, $element);
  1663. $entries = $wpdb->get_results($prepare_sql);
  1664.  
  1665. /**
  1666. * Allow to filter the page titles
  1667. *
  1668. * @since 4.2.7
  1669. */
  1670. add_filter('list_pages', __CLASS__ . '::handler_wp_list_pages', 99, 2);
  1671.  
  1672. foreach ($entries as &$entry) {
  1673. $p = get_post($entry->ID);
  1674. if ($p instanceof WP_Post && ($p->ID == $entry->ID)) {
  1675. $entry->post_title = apply_filters('list_pages', avia_wp_get_the_title($entry), $p);
  1676. }
  1677. }
  1678.  
  1679. unset($entry);
  1680.  
  1681. remove_filter('list_pages', __CLASS__ . '::handler_wp_list_pages', 99, 2);
  1682.  
  1683. AviaHtmlHelper::$cache['entry_' . $limit][$element['subtype']] = $entries;
  1684. }
  1685. //$entries = $wpdb->get_results( "SELECT ID, post_title FROM {$table_name} WHERE post_status = 'publish' AND post_type = '".$element['subtype']."' ORDER BY post_title ASC LIMIT {$limit}" );
  1686. //$entries = get_posts(array('numberposts' => apply_filters( 'avf_dropdown_post_number', 200 ), 'post_type' => $element['subtype'], 'post_status'=> 'publish', 'orderby'=> 'post_date', 'order'=> 'ASC'));
  1687. } else {
  1688. $select = 'Select...';
  1689. $entries = $element['subtype'];
  1690. $add_entries = array();
  1691.  
  1692. if (isset($element['folder'])) {
  1693. $add_file_array = avia_backend_load_scripts_by_folder(AVIA_BASE . $element['folder']);
  1694.  
  1695. if (is_array($add_file_array)) {
  1696. foreach ($add_file_array as $file) {
  1697. $skip = false;
  1698.  
  1699. if (!empty($element['exclude'])) {
  1700. foreach ($element['exclude'] as $exclude) {
  1701. if (stripos($file, $exclude) !== false) $skip = true;
  1702. }
  1703. }
  1704.  
  1705. if (strpos($file, '.') !== 0 && $skip == false) {
  1706. $add_entries[$element['folderlabel'] . $file] = "{{AVIA_BASE_URL}}" . $element['folder'] . $file;
  1707. }
  1708. }
  1709.  
  1710.  
  1711. if (isset($element['group'])) {
  1712. $entries[$element['group']] = $add_entries;
  1713. } else {
  1714. $entries = array_merge($entries, $add_entries);
  1715. }
  1716. }
  1717. }
  1718. }
  1719.  
  1720. if (empty($entries)) {
  1721. return;
  1722. }
  1723.  
  1724. $data_string = '';
  1725. if (isset($element['data'])) {
  1726. foreach ($element['data'] as $key => $data) {
  1727. $data_string .= "data-" . $key . "='" . $data . "'";
  1728. }
  1729. }
  1730.  
  1731. $multi = $multi_class = '';
  1732. if (isset($element['multiple'])) {
  1733. $multi_class = " avia_multiple_select";
  1734. $multi = 'multiple="multiple" size="' . $element['multiple'] . '"';
  1735. $element['std'] = explode(',', $element['std']);
  1736. }
  1737.  
  1738. $id_string = empty($element['id']) ? '' : "id='" . $element['id'] . "'";
  1739. $name_string = empty($element['id']) ? '' : "name='" . $element['id'] . "'";
  1740.  
  1741. $output = '<select ' . $multi . ' class="' . $element['class'] . '" ' . $id_string . ' ' . $name_string . ' ' . $data_string . '> ';
  1742.  
  1743.  
  1744. if (isset($element['with_first'])) {
  1745. $output .= '<option value="">' . $select . '</option> ';
  1746. $fake_val = $select;
  1747. }
  1748.  
  1749. $real_entries = array();
  1750. foreach ($entries as $key => $entry) {
  1751. if (!is_array($entry)) {
  1752. $real_entries[$key] = $entry;
  1753. } else {
  1754. $real_entries['option_group_' . $key] = $key;
  1755.  
  1756. foreach ($entry as $subkey => $subentry) {
  1757. $real_entries[$subkey] = $subentry;
  1758. }
  1759.  
  1760. $real_entries['close_option_group_' . $key] = "close";
  1761. }
  1762. }
  1763.  
  1764. $entries = $real_entries;
  1765. $output .= AviaHtmlHelper::create_select_option($element, $entries, $fake_val, $parents, 0);
  1766.  
  1767.  
  1768.  
  1769. $output .= '</select>';
  1770.  
  1771.  
  1772. return $output;
  1773. }
  1774.  
  1775.  
  1776. /**
  1777. * Returns the options part of a select box
  1778. *
  1779. * @since < 4.0
  1780. * @param array $element
  1781. * @param array $entries
  1782. * @param string $fake_val
  1783. * @param array $parents
  1784. * @param int $level
  1785. * @return string
  1786. */
  1787. static protected function create_select_option($element, $entries, $fake_val, $parents, $level)
  1788. {
  1789. $output = '';
  1790.  
  1791. foreach ($entries as $key => $entry) {
  1792. if ($element['subtype'] == 'cat') {
  1793. if (isset($entry->term_id)) {
  1794. $id = $entry->term_id;
  1795. $title = $entry->name;
  1796. }
  1797. } else if (!is_array($element['subtype'])) {
  1798. $id = $entry->ID;
  1799. $title = avia_wp_get_the_title($id);
  1800. } else {
  1801. $id = $entry;
  1802. $title = $key;
  1803. }
  1804.  
  1805. if (!empty($title) || (isset($title) && $title === 0)) {
  1806. if (empty($fake_val)) $fake_val = $title;
  1807. $selected = '';
  1808. if ($element['std'] == $id || (is_array($element['std']) && in_array($id, $element['std']))) {
  1809. $selected = "selected='selected'";
  1810. $fake_val = $title;
  1811. }
  1812.  
  1813. $indent = '';
  1814. for ($i = 0; $i < $level; $i++) {
  1815. $indent .= "- ";
  1816. }
  1817.  
  1818. if (strpos($title, 'option_group_') === 0) {
  1819. $output .= "<optgroup label='" . $id . "'>";
  1820. } else if (strpos($title, 'close_option_group_') === 0) {
  1821. $output .= "</optgroup>";
  1822. } else {
  1823. $output .= "<option $selected value='" . $id . "'>" . $indent . $title . "</option>";
  1824. }
  1825.  
  1826. if (!empty($parents) && !empty($parents[$id])) {
  1827. $level++;
  1828. $output .= AviaHtmlHelper::create_select_option($element, $parents[$id], $fake_val, $parents, $level);
  1829. $level--;
  1830. }
  1831. }
  1832. }
  1833. return $output;
  1834. }
  1835.  
  1836. /**
  1837. * Based on wp_timezone_override_offset() and get_timezone_info()
  1838. * Returns the timezone offset from UTC. Defaults to UTC if not available
  1839. *
  1840. * @since 4.5.6
  1841. * @param string $timezone_string
  1842. * @return float UTC offset in hours
  1843. */
  1844. static public function get_timezone_offset($timezone_string = '')
  1845. {
  1846. $timezone_string = AviaHtmlHelper::default_wp_timezone_string($timezone_string);
  1847.  
  1848. if (false !== stripos($timezone_string, 'UTC')) {
  1849. $tz = trim(str_ireplace('UTC', '', $timezone_string));
  1850. if (empty($tz) || !is_numeric($tz)) {
  1851. $tz = 0;
  1852. }
  1853. return (float) $tz;
  1854. }
  1855.  
  1856. $timezone_object = timezone_open($timezone_string);
  1857. $datetime_object = date_create();
  1858. if (false === $timezone_object || false === $datetime_object) {
  1859. return 0.0;
  1860. }
  1861.  
  1862. return round(timezone_offset_get($timezone_object, $datetime_object) / HOUR_IN_SECONDS, 2);
  1863. }
  1864.  
  1865. /**
  1866. * Returns a valid timezone_string for the selectbox.
  1867. * Checks for WP default setting if empty.
  1868. *
  1869. * @since 4.5.6
  1870. * @param string $timezone_string
  1871. * @return string
  1872. */
  1873. static public function default_wp_timezone_string($timezone_string = '')
  1874. {
  1875. if (!empty($timezone_string)) {
  1876. return $timezone_string;
  1877. }
  1878.  
  1879. $timezone_string = get_option('timezone_string', '');
  1880. if (!empty($timezone_string)) {
  1881. return $timezone_string;
  1882. }
  1883.  
  1884. $offset = get_option('gmt_offset', '');
  1885. if ('' == trim($offset) || !is_numeric($offset) || 0 == $offset) {
  1886. return 'UTC';
  1887. }
  1888.  
  1889. return $offset <= 0 ? 'UTC' . $offset : 'UTC+' . $offset;
  1890. }
  1891.  
  1892.  
  1893. /**
  1894. * Returns a timezone selectbox and preselects the default WP timezone
  1895. *
  1896. * @since 4.5.6
  1897. * @param array $element
  1898. * @return string
  1899. */
  1900. static public function timezone_choice(array $element)
  1901. {
  1902. $html = '';
  1903.  
  1904. $id_string = empty($element['id']) ? '' : "id='{$element['id']}'";
  1905. $name_string = empty($element['id']) ? '' : "name='{$element['id']}'";
  1906. $timezone_string = AviaHtmlHelper::default_wp_timezone_string($element['std']);
  1907.  
  1908. $html .= '<select class="' . $element['class'] . '" ' . $id_string . ' ' . $name_string . '>';
  1909. $html .= wp_timezone_choice($timezone_string);
  1910. $html .= '</select>';
  1911.  
  1912. return $html;
  1913. }
  1914.  
  1915.  
  1916. /**
  1917. *
  1918. * The gmap_adress method renders an address input field that allows to fetch long/lat coordinates via google api
  1919. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  1920. * @return string $output the string returned contains the html code generated within the method
  1921. */
  1922. static public function gmap_adress($element)
  1923. {
  1924. $defaults = array(
  1925. 'address' => '',
  1926. 'postcode' => '',
  1927. 'city' => '',
  1928. 'state' => '',
  1929. 'country' => '',
  1930. 'long' => '',
  1931. 'lat' => ''
  1932. );
  1933.  
  1934. $subvalues = isset($element['shortcode_data']) ? $element['shortcode_data'] : array();
  1935. $values = array_merge($defaults, $subvalues);
  1936. $visibility = '';
  1937.  
  1938. if (!empty($subvalues['long']) || !empty($subvalues['lat'])) {
  1939. $visibility = "av-visible";
  1940. }
  1941.  
  1942. $output = '';
  1943. $output .= '<label class="av-gmap-field av-gmap-addres">' . __('Street address', 'avia_framework') . ' <input type="text" class="' . $element['class'] . '" value="' . nl2br($values['address']) . '" id="address" name="address"/></label>';
  1944.  
  1945. $output .= '<label class="av-gmap-field av-gmap-addres av_half av_first">' . __('Postcode', 'avia_framework') . ' <input type="text" class="' . $element['class'] . '" value="' . nl2br($values['postcode']) . '" id="postcode" name="postcode"/></label>';
  1946. $output .= '<label class="av-gmap-field av-gmap-addres av_half">' . __('City', 'avia_framework') . ' <input type="text" class="' . $element['class'] . '" value="' . nl2br($values['city']) . '" id="city" name="city"/></label>';
  1947.  
  1948. $output .= '<label class="av-gmap-field av-gmap-addres av_half av_first">' . __('State', 'avia_framework') . ' <input type="text" class="' . $element['class'] . '" value="' . nl2br($values['state']) . '" id="state" name="state"/></label>';
  1949. $output .= '<label class="av-gmap-field av-gmap-addres av_half">' . __('Country', 'avia_framework') . ' <input type="text" class="' . $element['class'] . '" value="' . nl2br($values['country']) . '" id="country" name="country"/></label>';
  1950.  
  1951. $class = 'button button-primary avia-js-google-coordinates av-google-fetch-button' . $element['class'];
  1952. $output .= '<a href="#" class="' . $class . '" title="">' . __('Enter Address, then fetch coordinates', 'avia_framework') . '</a>';
  1953. $output .= '<div class="av-gmap-coordinates ' . $visibility . '">';
  1954.  
  1955. $output .= '<label class="av-gmap-field av_half av_first">' . __('Longitude', 'avia_framework') . ' <input type="text" class="' . $element['class'] . '" value="' . nl2br($values['long']) . '" id="long" name="long"/></label>';
  1956.  
  1957. $output .= '<label class="av-gmap-field av_half">' . __('Latitude', 'avia_framework') . ' <input type="text" class="' . $element['class'] . '" value="' . nl2br($values['lat']) . '" id="lat" name="lat"/></label>';
  1958.  
  1959.  
  1960. $output .= '</div>';
  1961.  
  1962. return $output;
  1963. }
  1964.  
  1965.  
  1966.  
  1967. /**
  1968. *
  1969. * The radio method renders one or more input type:radio elements, based on the definition of the $elements array
  1970. * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section
  1971. * @return string $output the string returned contains the html code generated within the method
  1972. */
  1973. static public function radio($element)
  1974. {
  1975. $output = '';
  1976.  
  1977. $counter = 1;
  1978. foreach ($element['options'] as $key => $radiobutton) {
  1979. $checked = '';
  1980. $extra_class = '';
  1981. if ($element['std'] == $key) {
  1982. $checked = 'checked = "checked"';
  1983. }
  1984.  
  1985. $fields = '<input ' . $checked . ' type="radio" class="radio_' . $key . '" ';
  1986. $fields .= 'value="' . $key . '" id="' . $element['id'] . $counter . '" name="' . $element['id'] . '"/>';
  1987.  
  1988. $fields .= '<label for="' . $element['id'] . $counter . '">';
  1989.  
  1990. if (isset($element['images']) && !empty($element['images'][$key])) {
  1991. $fields .= "<img class='radio_image' src='" . $element['images'][$key] . "' />";
  1992. $extra_class = 'avia-image-radio';
  1993. }
  1994.  
  1995. $fields .= '<span class="labeltext">' . $radiobutton . '</span>';
  1996. $fields .= '</label>';
  1997.  
  1998. $output .= '<span class="avia_radio_wrap ' . $extra_class . '">';
  1999. $output .= $fields;
  2000. $output .= '</span>';
  2001.  
  2002. $counter++;
  2003. }
  2004.  
  2005. return $output;
  2006. }
  2007.  
  2008.  
  2009.  
  2010. static public function mailchimp_list($element)
  2011. {
  2012. $api = $element['api'];
  2013. $new_list = array();
  2014.  
  2015. foreach ($api->fields as $list_id => $fields) {
  2016. foreach ($fields as $field) {
  2017. $list_item = array();
  2018. $list_item['id'] = $field->merge_id;
  2019. $list_item['label'] = $field->name;
  2020. $list_item['type'] = $field->type;
  2021. $list_item['value'] = $field->default_value;
  2022. $list_item['disabled'] = empty($field->show) ? "true" : '';
  2023. $list_item['check'] = '';
  2024.  
  2025.  
  2026. if ($field->required == 1) {
  2027. $list_item['check'] = "is_empty";
  2028. if ($field->type == 'email') {
  2029. $list_item['check'] = "is_email";
  2030. $list_item['type'] = "text";
  2031. }
  2032. if ($field->type == 'number') $list_item['check'] = "is_number";
  2033. }
  2034.  
  2035. if (isset($field->options)) {
  2036. $list_item['options'] = implode(",", $field->options->choices);
  2037. }
  2038.  
  2039. $new_list[$list_id][$field->merge_id] = $list_item;
  2040. }
  2041.  
  2042. //add the default subscribe button
  2043. if (!empty($new_list[$list_id])) {
  2044. $new_list[$list_id]['av-button'] = array(
  2045. 'id' => "av-button",
  2046. 'label' => __("Subscribe", "avia_framework"),
  2047. 'type' => "button",
  2048. 'value' => '',
  2049. 'check' => '',
  2050. );
  2051. }
  2052. }
  2053.  
  2054. $output = '';
  2055. $output .= self::select($element);
  2056. $output .= "<script type='text/javascript' > var av_mailchimp_list = " . json_encode($new_list) . "; ";
  2057. $output .= "</script>";
  2058.  
  2059. return $output;
  2060. }
  2061.  
  2062.  
  2063.  
  2064.  
  2065.  
  2066.  
  2067.  
  2068.  
  2069. static public function table($element, $parent)
  2070. {
  2071. $values = !empty($_POST['extracted_shortcode']) ? $_POST['extracted_shortcode'] : false;
  2072.  
  2073. $prepared = array();
  2074. $rows = $columns = 3;
  2075.  
  2076. //prepare values based on the sc array
  2077. if ($values) {
  2078. foreach ($values as $value) {
  2079. switch ($value['tag']) {
  2080. case 'av_cell':
  2081. $prepared['cells'][] = array('content' => stripslashes($value['content']), 'col_style' => $value['attr']['col_style']);
  2082. break;
  2083. case 'av_row':
  2084. $prepared['rows'][] = array('row_style' => $value['attr']['row_style']);
  2085. break;
  2086. }
  2087. }
  2088. }
  2089.  
  2090. if ($prepared) {
  2091. $rows = count($prepared['rows']);
  2092. $columns = count($prepared['cells']) / $rows;
  2093. }
  2094.  
  2095. $params = array('class' => '', 'parent_class' => $parent);
  2096.  
  2097. $output = '';
  2098. $output .= "<div class='avia-table-builder-wrapper'>";
  2099.  
  2100. $output .= " <div class='avia-table-builder-add-buttons'>";
  2101. $output .= " <a class='avia-attach-table-row button button-primary button-large'>" . __('Add Table Row', 'avia_framework') . "</a>";
  2102. $output .= " <a class='avia-attach-table-col button button-primary button-large'>" . __('Add Table Column', 'avia_framework') . "</a>";
  2103. $output .= " </div>";
  2104.  
  2105. $output .= " <div class='avia-table'>";
  2106.  
  2107.  
  2108. $output .= self::table_row(false, $columns, array('class' => 'avia-table-col-style avia-attach-table-col-style avia-noselect', 'col_option' => true, 'no-edit' => true), $element, $prepared);
  2109.  
  2110. for ($i = 1; $i <= $rows; $i++) {
  2111. if ($prepared) {
  2112. $params['row_style'] = $prepared['rows'][$i - 1]['row_style'];
  2113. }
  2114.  
  2115. $output .= self::table_row($i, $columns, $params, $element, $prepared);
  2116. }
  2117.  
  2118. $output .= self::table_row(false, $columns, array('class' => 'avia-template-row'), $element, $prepared);
  2119. $output .= self::table_row(false, $columns, array('class' => 'avia-delete-row avia-noselect', 'no-edit' => true), $element);
  2120.  
  2121. $output .= " </div>";
  2122. $output .= "</div>";
  2123. return $output;
  2124. }
  2125.  
  2126. static public function table_row($row, $columns, $params, $element, $prepared = array())
  2127. {
  2128. $up = __('move up', 'avia_framework');
  2129. $down = __('move down', 'avia_framework');
  2130. $left = __('move left', 'avia_framework');
  2131. $right = __('move right', 'avia_framework');
  2132.  
  2133.  
  2134. $defaults = array('class' => '', 'content' => '', 'row_style' => '');
  2135. $params = array_merge($defaults, $params);
  2136. $extraclass = '';
  2137. $output = '';
  2138. $output .= " <div class='avia-table-row {$params['class']} {$params['row_style']}'>";
  2139.  
  2140. $output .= " <div class='avia-table-cell avia-table-cell-style avia-attach-table-row-style avia-noselect'>";
  2141.  
  2142. if (empty($params['no-edit'])) {
  2143. $output .= "<div class='avia-move-table-row-container'>
  2144. <div class='avia-move-table-row'>
  2145. <a href='#' class='av-table-pos-button av-table-up' data-direction='up' title='{$up}'>{$up}</a>
  2146. <a href='#' class='av-table-pos-button av-table-down' data-direction='down' title='{$down}'>{$down}</a>
  2147. </div></div>";
  2148. }
  2149.  
  2150. $output .= self::select(array('std' => $params['row_style'], 'subtype' => $element['row_style'], 'id' => 'row_style', 'class' => ''));
  2151. $output .= " </div>";
  2152.  
  2153. for ($j = 1; $j <= $columns; $j++) {
  2154. if ($prepared) {
  2155. if (!$row) $row = 1;
  2156.  
  2157. $rows = count($prepared['rows']);
  2158. $columns = count($prepared['cells']) / $rows;
  2159. $key = (($row - 1) * $columns) + ($j - 1);
  2160.  
  2161. if ($params['class'] == 'avia-template-row') {
  2162. $params['content'] = '';
  2163. } else {
  2164. $params['content'] = $prepared['cells'][$key]['content'];
  2165. }
  2166. $extraclass = $prepared['cells'][$key]['col_style'];
  2167. }
  2168.  
  2169. if (isset($params['col_option'])) {
  2170. $params['content'] = "<div class='avia-move-table-col'>
  2171. <a href='#' class='av-table-pos-button av-table-left' data-direction='left' title='{$left}'>{$left}</a>
  2172. <a href='#' class='av-table-pos-button av-table-right' data-direction='right' title='{$right}'>{$right}</a>
  2173. </div>";
  2174.  
  2175. $params['content'] .= self::select(array('std' => $extraclass, 'subtype' => $element['column_style'], 'id' => 'column_style', 'class' => ''));
  2176. }
  2177.  
  2178. if (isset($params['parent_class']) && $params['row_style'] == "avia-button-row" && strpos($params['content'], "[") !== false) {
  2179.  
  2180. $params['parent_class']->builder->text_to_interface($params['content']);
  2181. $values = end($_POST['extracted_shortcode']);
  2182. $params['content'] = $params['parent_class']->builder->shortcode_class[$params['parent_class']->builder->shortcode[$values['tag']]]->prepare_editor_element($values['content'], $values['attr']);
  2183. }
  2184.  
  2185. $output .= " <div class='avia-table-cell " . $extraclass . "'>";
  2186. $output .= " <div class='avia-table-content'>";
  2187. $output .= stripslashes($params['content']);
  2188. $output .= " </div>";
  2189.  
  2190. if (empty($params['no-edit']) && empty($values)) {
  2191. $output .= " <textarea class='avia-table-data-container' name='content'>";
  2192. $output .= stripslashes($params['content']);;
  2193. $output .= "</textarea>";
  2194. }
  2195. $output .= " </div>";
  2196. }
  2197.  
  2198. $output .= " <div class='avia-table-cell avia-table-cell-delete avia-attach-delete-table-row avia-noselect'>";
  2199. $output .= " </div>";
  2200.  
  2201.  
  2202.  
  2203. $output .= " </div>";
  2204. return $output;
  2205. }
  2206.  
  2207.  
  2208. static public function display_image($img = '')
  2209. {
  2210. $final = array();
  2211.  
  2212. if (preg_match('/^.*\.(jpg|jpeg|png|gif)$/i', $img)) {
  2213. $final[] = '<img src="' . $img . '" />';
  2214. } else if (!empty($img)) {
  2215. $args = array('post_type' => 'attachment', 'numberposts' => -1, 'include' => $img, 'orderby' => 'post__in');
  2216. $attachments = get_posts($args);
  2217.  
  2218. foreach ($attachments as $attachment) {
  2219. $final[] = wp_get_attachment_link($attachment->ID, 'thumbnail', false, false);
  2220. }
  2221. }
  2222.  
  2223. $output = '';
  2224. $hidden = "avia-hidden";
  2225.  
  2226. $output .= "<div class='avia-builder-prev-img-container-wrap'>";
  2227. $output .= "<div class='avia-builder-prev-img-container'>";
  2228. if (!empty($final)) {
  2229. if (count($final) == 1) $hidden = '';
  2230.  
  2231. foreach ($final as $img) {
  2232. $output .= "<span class='avia-builder-prev-img'>{$img}</span>";
  2233. }
  2234. }
  2235.  
  2236. $output .= "</div>";
  2237. $output .= "</div>";
  2238. $output .= "<a href='#delete' class='avia-delete-image {$hidden}'>" . __('Remove Image', 'avia_framework') . "</a>";
  2239. return $output;
  2240. }
  2241.  
  2242.  
  2243.  
  2244.  
  2245. static public function number_array($from = 0, $to = 100, $steps = 1, $array = array(), $label = '', $value_prefix = '', $value_postfix = '')
  2246. {
  2247. for ($i = $from; $i <= $to; $i += $steps) {
  2248. $array[$i . $label] = $value_prefix . $i . $value_postfix;
  2249. }
  2250.  
  2251. return $array;
  2252. }
  2253.  
  2254.  
  2255.  
  2256.  
  2257. static public function linking_options()
  2258. {
  2259. if (current_theme_supports('avia_rel_nofollow_for_links')) {
  2260. $linkoptions = array(
  2261. __('Open in same window', 'avia_framework') => '',
  2262. __('Open in same window and use rel=nofollow', 'avia_framework') => 'nofollow',
  2263. __('Open in new window', 'avia_framework') => '_blank',
  2264. __('Open in new window and use rel=nofollow', 'avia_framework') => '_blank nofollow'
  2265. );
  2266. } else {
  2267. $linkoptions = array(
  2268. __('Open in same window', 'avia_framework') => '',
  2269. __('Open in new window', 'avia_framework') => '_blank'
  2270. );
  2271. }
  2272.  
  2273. return $linkoptions;
  2274. }
  2275.  
  2276. /**
  2277. * Returns an option array of all registered post types
  2278. *
  2279. * @param array $args
  2280. * @return array
  2281. */
  2282. static public function get_registered_post_type_array($args = array())
  2283. {
  2284. $post_types = get_post_types($args, 'objects');
  2285. $post_type_option = array();
  2286.  
  2287. if (!empty($post_types)) {
  2288. foreach ($post_types as $post_type) {
  2289. /**
  2290. * Fixes a bug with non unique labels
  2291. */
  2292. if (!isset($post_type_option[$post_type->label])) {
  2293. $post_type_option[$post_type->label] = $post_type->name;
  2294. } else {
  2295. $post_type_option["{$post_type->label} ({$post_type->name})"] = $post_type->name;
  2296. }
  2297. }
  2298. }
  2299.  
  2300. $post_type_option = apply_filters('avf_registered_post_type_array', $post_type_option, $args);
  2301.  
  2302. return $post_type_option;
  2303. }
  2304. } // end class
  2305.  
  2306. } // end if !class_exists
Advertisement
Add Comment
Please, Sign In to add comment