PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/plussed_old/library/admin/ReduxCore/inc/fields/group/field_group.php

https://gitlab.com/plusplusminus/compassion
PHP | 264 lines | 142 code | 49 blank | 73 comment | 20 complexity | f3bef011ca4f9438b4c96ec0589686f5 MD5 | raw file
  1. <?php
  2. /**
  3. * Redux Framework is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * any later version.
  7. *
  8. * Redux Framework is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with Redux Framework. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * @package ReduxFramework
  17. * @subpackage Field_Info
  18. * @author Daniel J Griffiths (Ghost1227)
  19. * @author Dovy Paukstys
  20. * @author Abdullah Almesbahi
  21. * @author Jesús Mendoza (@vertigo7x)
  22. * @version 3.0.0
  23. */
  24. // Exit if accessed directly
  25. if (!defined('ABSPATH'))
  26. exit;
  27. // Don't duplicate me!
  28. if (!class_exists('ReduxFramework_group')) {
  29. /**
  30. * Main ReduxFramework_info class
  31. *
  32. * @since 1.0.0
  33. */
  34. class ReduxFramework_group extends ReduxFramework {
  35. /**
  36. * Field Constructor.
  37. *
  38. * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
  39. *
  40. * @since 1.0.0
  41. * @access public
  42. * @return void
  43. */
  44. function __construct( $field = array(), $value ='', $parent ) {
  45. //parent::__construct( $parent->sections, $parent->args );
  46. $this->parent = $parent;
  47. $this->field = $field;
  48. $this->value = $value;
  49. }
  50. /**
  51. * Field Render Function.
  52. *
  53. * Takes the vars and outputs the HTML for the field in the settings
  54. *
  55. * @since 1.0.0
  56. * @access public
  57. * @return void
  58. */
  59. public function render() {
  60. if (empty($this->value) || !is_array($this->value)) {
  61. $this->value = array(
  62. array(
  63. 'slide_title' => __('New', 'redux-framework').' '.$this->field['groupname'],
  64. 'slide_sort' => '0',
  65. )
  66. );
  67. }
  68. $groups = $this->value;
  69. echo '<div class="redux-group">';
  70. echo '<input type="hidden" class="redux-dummy-slide-count" id="redux-dummy-' . $this->field['id'] . '-count" name="redux-dummy-' . $this->field['id'] . '-count" value="' . count($groups) . '" />';
  71. echo '<div id="redux-groups-accordion">';
  72. // Create dummy content for the adding new ones
  73. echo '<div class="redux-groups-accordion-group redux-dummy" style="display:none" id="redux-dummy-' . $this->field['id'] . '"><h3><span class="redux-groups-header">' . __("New ", "redux-framework") . $this->field['groupname'] . '</span></h3>';
  74. echo '<div>';//according content open
  75. echo '<table style="margin-top: 0;" class="redux-groups-accordion redux-group form-table no-border">';
  76. echo '<fieldset><input type="hidden" id="' . $this->field['id'] . '_slide-title" data-name="' . $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][@][slide_title]" value="" class="regular-text slide-title" /></fieldset>';
  77. echo '<input type="hidden" class="slide-sort" data-name="' . $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][@][slide_sort]" id="' . $this->field['id'] . '-slide_sort" value="" />';
  78. $field_is_title = true;
  79. foreach ($this->field['subfields'] as $field) {
  80. //we will enqueue all CSS/JS for sub fields if it wasn't enqueued
  81. $this->enqueue_dependencies($field['type']);
  82. echo '<tr><td>';
  83. if(isset($field['class']))
  84. $field['class'] .= " group";
  85. else
  86. $field['class'] = " group";
  87. if (!empty($field['title']))
  88. echo '<h4>' . $field['title'] . '</h4>';
  89. if (!empty($field['subtitle']))
  90. echo '<span class="description">' . $field['subtitle'] . '</span>';
  91. $value = empty($this->options[$field['id']][0]) ? "" : $this->options[$field['id']][0];
  92. ob_start();
  93. $this->_field_input($field, $value);
  94. $content = ob_get_contents();
  95. //adding sorting number to the name of each fields in group
  96. $name = $this->parent->args['opt_name'] . '[' . $field['id'] . ']';
  97. $content = str_replace($name,$this->parent->args['opt_name'] . '[' . $this->field['id'] . '][@]['.$field['id'].']', $content);
  98. // remove the name property. asigned by the controller, create new data-name property for js
  99. $content = str_replace('name', 'data-name', $content);
  100. if(($field['type'] === "text") && ($field_is_title)) {
  101. $content = str_replace('>', 'data-title="true" />', $content);
  102. $field_is_title = false;
  103. }
  104. //we should add $sort to id to fix problem with select field
  105. $content = str_replace(' id="'.$field['id'].'-select"', ' id="'.$field['id'].'-select-'.$sort.'"', $content);
  106. $_field = apply_filters('redux-support-group',$content, $field, 0);
  107. ob_end_clean();
  108. echo $_field;
  109. echo '</td></tr>';
  110. }
  111. echo '</table>';
  112. echo '<a href="javascript:void(0);" class="button deletion redux-groups-remove">' . __('Delete', 'redux-framework').' '. $this->field['groupname']. '</a>';
  113. echo '</div></div>';
  114. // Create real groups
  115. $x = 0;
  116. foreach ($groups as $group) {
  117. echo '<div class="redux-groups-accordion-group"><h3><span class="redux-groups-header">' . $group['slide_title'] . '</span></h3>';
  118. echo '<div>';//according content open
  119. echo '<table style="margin-top: 0;" class="redux-groups-accordion redux-group form-table no-border">';
  120. //echo '<h4>' . __('Group Title', 'redux-framework') . '</h4>';
  121. echo '<fieldset><input type="hidden" id="' . $this->field['id'] . '-slide_title_' . $x . '" name="' . $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][' . $x . '][slide_title]" value="' . esc_attr($group['slide_title']) . '" class="regular-text slide-title" /></fieldset>';
  122. echo '<input type="hidden" class="slide-sort" name="' . $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][' . $x . '][slide_sort]" id="' . $this->field['id'] . '-slide_sort_' . $x . '" value="' . $group['slide_sort'] . '" />';
  123. $field_is_title = true;
  124. foreach ($this->field['subfields'] as $field) {
  125. //we will enqueue all CSS/JS for sub fields if it wasn't enqueued
  126. $this->enqueue_dependencies($field['type']);
  127. echo '<tr><td>';
  128. if(isset($field['class']))
  129. $field['class'] .= " group";
  130. else
  131. $field['class'] = " group";
  132. if (!empty($field['title']))
  133. echo '<h4>' . $field['title'] . '</h4>';
  134. if (!empty($field['subtitle']))
  135. echo '<span class="description">' . $field['subtitle'] . '</span>';
  136. if (isset($group[$field['id']]) && !empty($group[$field['id']])) {
  137. $value = $group[$field['id']];
  138. }
  139. $value = empty($value) ? "" : $value;
  140. ob_start();
  141. $this->_field_input($field, $value);
  142. //if (isset($this->options[$field['id']]) && !empty($this->options[$field['id']]) && is_array($this->options[$field['id']])) {
  143. // $value = next($this->options[$field['id']]);
  144. //}
  145. $content = ob_get_contents();
  146. //adding sorting number to the name of each fields in group
  147. $name = $this->parent->args['opt_name'] . '[' . $field['id'] . ']';
  148. $content = str_replace($name, $this->parent->args['opt_name'] . '[' . $this->field['id'] . ']['.$x.']['.$field['id'].']', $content);
  149. //we should add $sort to id to fix problem with select field
  150. $content = str_replace(' id="'.$field['id'].'-select"', ' id="'.$field['id'].'-select-'.$sort.'"', $content);
  151. if(($field['type'] === "text") && ($field_is_title)) {
  152. $content = str_replace('>', 'data-title="true" />', $content);
  153. $field_is_title = false;
  154. }
  155. $_field = apply_filters('redux-support-group',$content, $field, $x);
  156. ob_end_clean();
  157. echo $_field;
  158. echo '</td></tr>';
  159. }
  160. echo '</table>';
  161. echo '<a href="javascript:void(0);" class="button deletion redux-groups-remove">' . __('Delete', 'redux-framework').' '.$this->field['groupname']. '</a>';
  162. echo '</div></div>';
  163. $x++;
  164. }
  165. echo '</div><a href="javascript:void(0);" class="button redux-groups-add button-primary" rel-id="' . $this->field['id'] . '-ul" rel-name="' . $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][slide_title][]">' . __('Add', 'redux-framework') .' '.$this->field['groupname']. '</a><br/>';
  166. echo '</div>';
  167. }
  168. function support_multi($content, $field, $sort) {
  169. //convert name
  170. $name = $this->parent->args['opt_name'] . '[' . $field['id'] . ']';
  171. $content = str_replace($name, $name . '[' . $sort . ']', $content);
  172. //we should add $sort to id to fix problem with select field
  173. $content = str_replace(' id="'.$field['id'].'-select"', ' id="'.$field['id'].'-select-'.$sort.'"', $content);
  174. return $content;
  175. }
  176. /**
  177. * Enqueue Function.
  178. *
  179. * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
  180. *
  181. * @since 1.0.0
  182. * @access public
  183. * @return void
  184. */
  185. public function enqueue() {
  186. wp_enqueue_script(
  187. 'redux-field-group-js',
  188. ReduxFramework::$_url . 'inc/fields/group/field_group.js',
  189. array('jquery', 'jquery-ui-core', 'jquery-ui-accordion', 'wp-color-picker'),
  190. time(),
  191. true
  192. );
  193. wp_enqueue_style(
  194. 'redux-field-group-css',
  195. ReduxFramework::$_url . 'inc/fields/group/field_group.css',
  196. time(),
  197. true
  198. );
  199. }
  200. public function enqueue_dependencies($field_type) {
  201. $field_class = 'ReduxFramework_' . $field_type;
  202. if (!class_exists($field_class)) {
  203. $class_file = apply_filters('redux-typeclass-load', ReduxFramework::$_dir . 'inc/fields/' . $field_type . '/field_' . $field_type . '.php', $field_class);
  204. if ($class_file) {
  205. /** @noinspection PhpIncludeInspection */
  206. require_once( $class_file );
  207. }
  208. }
  209. if (class_exists($field_class) && method_exists($field_class, 'enqueue')) {
  210. $enqueue = new $field_class('', '', $this);
  211. $enqueue->enqueue();
  212. }
  213. }
  214. }
  215. }