PageRenderTime 68ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/content-web-clean/plugins/types/vendor/toolset/toolset-common/toolset-forms/classes/class.skype.php

https://bitbucket.org/Salmendrote/wordpress-clean
PHP | 276 lines | 232 code | 30 blank | 14 comment | 3 complexity | 2480125f6837cc592f0f9708eb690d87 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, GPL-2.0, BSD-3-Clause, MIT
  1. <?php
  2. /**
  3. *
  4. *
  5. */
  6. require_once 'class.textfield.php';
  7. class WPToolset_Field_Skype extends WPToolset_Field_Textfield {
  8. protected $_defaults = array(
  9. 'skypename' => '',
  10. 'action' => 'chat',
  11. 'color' => 'blue',
  12. 'size' => 32,
  13. );
  14. public function init() {
  15. add_action( 'admin_footer', array( $this, 'editButtonTemplate' ) );
  16. add_action( 'wp_footer', array( $this, 'editButtonTemplate' ) );
  17. // In related content meta boxes, 'admin_footer' is executed before this class, so this hook is needed.
  18. add_action( 'toolset_related_content_footer', array( $this, 'editButtonTemplate' ) );
  19. wp_register_script(
  20. 'skype-uri-buttom', '//www.skypeassets.com/i/scom/js/skype-uri.js'
  21. );
  22. wp_register_script(
  23. 'wptoolset-field-skype', WPTOOLSET_FORMS_RELPATH . '/js/skype.js', array(
  24. 'jquery',
  25. 'skype-uri-buttom',
  26. ), WPTOOLSET_FORMS_VERSION, true
  27. );
  28. wp_enqueue_script( 'wptoolset-field-skype' );
  29. add_thickbox();
  30. $translation = array( 'title' => esc_js( __( 'Edit Skype button', 'wpv-views' ) ) );
  31. wp_localize_script( 'wptoolset-field-skype', 'wptSkypeData', $translation );
  32. $this->set_placeholder_as_attribute();
  33. }
  34. public function enqueueStyles() {
  35. }
  36. public function metaform() {
  37. $value = wp_parse_args( $this->getValue(), $this->_defaults );
  38. $attributes = $this->getAttr();
  39. $shortcode_class = array_key_exists( 'class', $attributes ) ? $attributes['class'] : "";
  40. $attributes['class'] = "js-wpt-skypename js-wpt-cond-trigger regular-text {$shortcode_class}"; // What is this js-wpt-cond-trigger classname for?
  41. $wpml_action = $this->getWPMLAction();
  42. $form = array();
  43. $form[] = array(
  44. '#type' => 'textfield',
  45. '#title' => $this->getTitle(),
  46. '#description' => $this->getDescription(),
  47. '#name' => $this->getName() . "[skypename]",
  48. '#attributes' => array(),
  49. '#value' => $value['skypename'],
  50. '#validate' => $this->getValidationData(),
  51. '#attributes' => $attributes,
  52. '#repetitive' => $this->isRepetitive(),
  53. 'wpml_action' => $wpml_action,
  54. );
  55. /**
  56. * action
  57. */
  58. $form[] = array(
  59. '#type' => 'hidden',
  60. '#value' => $value['action'],
  61. '#name' => $this->getName() . '[action]',
  62. '#attributes' => array( 'class' => 'js-wpt-skype-action' ),
  63. );
  64. /**
  65. * color
  66. */
  67. $form[] = array(
  68. '#type' => 'hidden',
  69. '#value' => $value['color'],
  70. '#name' => $this->getName() . '[color]',
  71. '#attributes' => array( 'class' => 'js-wpt-skype-color' ),
  72. );
  73. /**
  74. * size
  75. */
  76. $form[] = array(
  77. '#type' => 'hidden',
  78. '#value' => $value['size'],
  79. '#name' => $this->getName() . '[size]',
  80. '#attributes' => array( 'class' => 'js-wpt-skype-size' ),
  81. );
  82. if ( ! Toolset_Utils::is_real_admin() ) {
  83. return $form;
  84. }
  85. $button_element = array(
  86. '#name' => '',
  87. '#type' => 'button',
  88. '#value' => esc_attr( __( 'Edit Skype', 'wpv-views' ) ),
  89. '#attributes' => array(
  90. 'class' => 'js-wpt-skype-edit-button button button-small button-secondary',
  91. ),
  92. );
  93. $wpcf_wpml_condition = defined( 'WPML_TM_VERSION' ) &&
  94. intval( $wpml_action ) === 1 &&
  95. function_exists( 'wpcf_wpml_post_is_original' ) &&
  96. function_exists( 'wpcf_wpml_have_original' ) &&
  97. ! wpcf_wpml_post_is_original() &&
  98. wpcf_wpml_have_original();
  99. if (
  100. Toolset_Utils::is_real_admin() &&
  101. $wpcf_wpml_condition
  102. ) {
  103. $button_element['#attributes']['disabled'] = 'disabled';
  104. }
  105. foreach ( $value as $key => $val ) {
  106. $button_element['#attributes'][ 'data-' . esc_attr( $key ) ] = $val;
  107. }
  108. $form[] = $button_element;
  109. return $form;
  110. }
  111. public function editButtonTemplate() {
  112. static $edit_button_template_template_already_loaded;
  113. if ( $edit_button_template_template_already_loaded ) {
  114. return;
  115. }
  116. $edit_button_template_template_already_loaded = true;
  117. $form = array();
  118. $form['full-open'] = array(
  119. '#type' => 'markup',
  120. '#markup' => '<div id="tpl-wpt-skype-edit-button" style="display:none;"><div id="wpt-skype-edit-button-popup">',
  121. );
  122. $form['preview'] = array(
  123. '#type' => 'markup',
  124. '#markup' => sprintf(
  125. '<div id="wpt-skype-edit-button-popup-preview"><p class="bold">%s</p><div id="wpt-skype-edit-button-popup-preview-button"><div id="wpt-skype-preview"></div><small style="display:none">%s</small></div><p class="description"><strong>%s</strong>: %s</p></div>', __( 'Preview of your Skype button', 'wpv-views' ), __( '*Hover over to see the menu', 'wpv-views' ), __( 'Note', 'wpv-views' ), __( 'Skype button background is transparent and will work on any colour backgrounds.', 'wpv-views' )
  126. ),
  127. );
  128. $form['options-open'] = array(
  129. '#type' => 'markup',
  130. '#markup' => '<div class="main">',
  131. );
  132. $form['skypename'] = array(
  133. '#type' => 'textfield',
  134. '#name' => 'skype[name]',
  135. '#attributes' => array(
  136. 'class' => 'js-wpt-skypename-popup js-wpt-skype',
  137. 'data-skype-field-name' => 'skypename',
  138. ),
  139. '#before' => sprintf( '<h3>%s</h2>', __( 'Enter your Skype Name', 'wpv-views' ) ),
  140. );
  141. $form['skype-action'] = array(
  142. '#type' => 'checkboxes',
  143. '#name' => 'skype[action]',
  144. '#options' => array(
  145. 'call' => array(
  146. '#name' => 'skype[action][call]',
  147. '#value' => 'call',
  148. '#title' => __( 'Call', 'wpv-views' ),
  149. '#description' => __( 'Start a call with just a click.', 'wpv-views' ),
  150. '#default_value' => 'call',
  151. '#attributes' => array(
  152. 'class' => 'js-wpt-skype js-wpt-skype-action js-wpt-skype-action-call',
  153. 'data-skype-field-name' => 'action',
  154. ),
  155. ),
  156. 'chat' => array(
  157. '#name' => 'skype[action][chat]',
  158. '#title' => __( 'Chat', 'wpv-views' ),
  159. '#value' => 'chat',
  160. '#description' => __( 'Start the conversation with an instant message.', 'wpv-views' ),
  161. '#attributes' => array(
  162. 'class' => 'js-wpt-skype js-wpt-skype-action js-wpt-skype-action-chat',
  163. 'data-skype-field-name' => 'action',
  164. ),
  165. ),
  166. ),
  167. '#before' => sprintf( '<h3>%s</h3>', __( "Choose what you'd like your button to do", 'wpv-views' ) ),
  168. );
  169. $form['skype-color-header'] = array(
  170. '#type' => 'markup',
  171. '#markup' => sprintf( '<h3>%s</h3>', __( 'Choose how you want your button to look', 'wpv-views' ) ),
  172. );
  173. $form['skype-color'] = array(
  174. '#type' => 'select',
  175. '#name' => 'skype[color]',
  176. '#options' => array(
  177. array(
  178. '#value' => 'blue',
  179. '#title' => __( 'Blue', 'wpv-views' ),
  180. '#attributes' => array(
  181. 'data-skype-field-name' => 'color',
  182. 'class' => 'js-wpt-skype',
  183. ),
  184. ),
  185. array(
  186. '#value' => 'white',
  187. '#title' => __( 'White', 'wpv-views' ),
  188. '#attributes' => array(
  189. 'data-skype-field-name' => 'color',
  190. 'class' => 'js-wpt-skype',
  191. ),
  192. ),
  193. ),
  194. '#default_value' => 'blue',
  195. '#attributes' => array(
  196. 'class' => 'js-wpt-skype js-wpt-skype-color',
  197. ),
  198. '#inline' => true,
  199. );
  200. $form['skype-size'] = array(
  201. '#type' => 'select',
  202. '#name' => 'skype[size]',
  203. '#options' => array(),
  204. '#default_value' => 32,
  205. '#attributes' => array(
  206. 'class' => 'js-wpt-skype js-wpt-skype-size',
  207. ),
  208. '#inline' => true,
  209. );
  210. foreach ( array( 10, 12, 14, 16, 24, 32 ) as $size ) {
  211. $form['skype-size']['#options'][] = array(
  212. '#value' => $size,
  213. '#title' => sprintf( '%dpx', $size ),
  214. '#attributes' => array(
  215. 'data-skype-field-name' => 'size',
  216. 'class' => 'js-wpt-skype',
  217. ),
  218. );
  219. }
  220. $form['options-close'] = array(
  221. '#type' => 'markup',
  222. '#markup' => '</div>',
  223. );
  224. $form['submit'] = array(
  225. '#type' => 'button',
  226. '#name' => 'skype[submit]',
  227. '#attributes' => array(
  228. 'class' => 'button-secondary js-wpt-close-thickbox',
  229. ),
  230. '#value' => __( 'Save', 'wpv-views' ),
  231. );
  232. $form['full-close'] = array(
  233. '#type' => 'markup',
  234. '#markup' => '</div></div>',
  235. );
  236. $theForm = new Enlimbo_Forms( __FUNCTION__ );
  237. $theForm->autoHandle( __FUNCTION__, $form );
  238. echo $theForm->renderElements( $form );
  239. }
  240. public function editform( $config = null ) {
  241. }
  242. public function mediaEditor() {
  243. return array();
  244. }
  245. }