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

/wp-content/plugins/wp-types/embedded/common/visual-editor/editor-addon.class.php

https://bitbucket.org/acipriani/madeinapulia.com
PHP | 803 lines | 580 code | 109 blank | 114 comment | 174 complexity | b159204c39c11e5d962319611a5af203 MD5 | raw file
Possible License(s): GPL-3.0, MIT, BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0
  1. <?php
  2. if ( file_exists( dirname(__FILE__) . '/editor-addon-generic.class.php') && !class_exists( 'Editor_addon' ) ) {
  3. require_once( dirname(__FILE__) . '/editor-addon-generic.class.php' );
  4. class Editor_addon extends Editor_addon_generic
  5. {
  6. function get_fields_list() {
  7. return apply_filters( 'toolset_editor_addon_post_fields_list', $this->items );
  8. }
  9. /**
  10. * Adding a "V" button to the menu
  11. * @param string $context
  12. * @param string $text_area
  13. * @param boolean $standard_v is this a standard V button
  14. */
  15. function add_form_button( $context, $text_area = 'textarea#content', $standard_v = true, $add_views = false, $codemirror_button = false ) {
  16. global $wp_version;
  17. // WP 3.3 changes ($context arg is actually a editor ID now)
  18. if ( version_compare( $wp_version, '3.1.4', '>' ) && !empty( $context ) ) {
  19. $text_area = $context;
  20. }
  21. // Apply filters
  22. $this->items = apply_filters( 'editor_addon_items_' . $this->name,
  23. $this->items );
  24. // add_filter('editor_addon_parent_items', array($this, 'wpv_add_parent_items'), 10, $this->items);
  25. // Apply filter parent items
  26. //apply_filters('editor_addon_parent_items', $this->items);
  27. // sort the items into menu levels.
  28. $menus = array();
  29. $sub_menus = array();
  30. if( $this->items )
  31. foreach ( $this->items as $item ) {
  32. $parts = explode( '-!-', $item[2] );
  33. $menu_level = &$menus;
  34. foreach ( $parts as $part ) {
  35. if ( $part != '' ) {
  36. if ( !array_key_exists( $part, $menu_level ) ) {
  37. $menu_level[$part] = array();
  38. }
  39. $menu_level = &$menu_level[$part];
  40. }
  41. }
  42. $menu_level[$item[0]] = $item;
  43. }
  44. // Apply filters
  45. $menus = apply_filters( 'editor_addon_menus_' . $this->name, $menus );
  46. // add View Template links to the "Add Field" button
  47. if ( !$standard_v ) {
  48. $this->add_view_type( $menus, 'view-template',
  49. __( 'View templates', 'wpv-views' ) );
  50. $this->add_view_type( $menus, 'view',
  51. __( 'Post View', 'wpv-views' ) );
  52. $this->add_view_type( $menus, 'view',
  53. __( 'Taxonomy View', 'wpv-views' ) );
  54. $this->add_view_type( $menus, 'view',
  55. __( 'User View', 'wpv-views' ) );
  56. }
  57. if ( $standard_v && $add_views ) {
  58. $this->add_view_type( $menus, 'view',
  59. __( 'Post View', 'wpv-views' ) );
  60. $this->add_view_type( $menus, 'view',
  61. __( 'Taxonomy View', 'wpv-views' ) );
  62. $this->add_view_type( $menus, 'view',
  63. __( 'User View', 'wpv-views' ) );
  64. }
  65. // Sort menus
  66. if ( is_array( $menus ) ) {
  67. $menus = $this->sort_menus_alphabetically( $menus );
  68. }
  69. $this->_media_menu_direct_links = array();
  70. $menus_output = $this->_output_media_menu( $menus, $text_area,
  71. $standard_v );
  72. $direct_links = implode( ' ', $this->_media_menu_direct_links );
  73. $dropdown_class = 'js-editor_addon_dropdown-'.$this->name;
  74. $icon_class = 'js-wpv-shortcode-post-icon-'.$this->name;
  75. if ( $this->name == 'wpv-views' ) {
  76. $button_label = __( 'Views', 'wpv-views' );
  77. } else if ( $this->name == 'types' ) {
  78. $button_label = __( 'Types', 'wpv-views' );
  79. } else {
  80. $button_label = '';
  81. }
  82. if( '' !== $this->media_button_image )
  83. {
  84. $addon_button = '<span class="button wpv-shortcode-post-icon '. $icon_class .'"><img src="' . $this->media_button_image . '" />' . $button_label . '</span>';
  85. }
  86. else if( '' !== $this->icon_class ){
  87. $addon_button = '<span class="button wpv-shortcode-post-icon '. $icon_class .'"><i class="'.$this->icon_class.'"></i><span class="button-label">' . $button_label . '</span></span>';
  88. }
  89. if ( !$standard_v ) {
  90. if( '' !== $this->media_button_image )
  91. {
  92. $addon_button = '<span class="button vicon wpv-shortcode-post-icon '. $icon_class .'"><img src="' . $this->media_button_image . '" />' . $button_label . '</span>';
  93. }
  94. else if( '' !== $this->icon_class )
  95. {
  96. $addon_button = '<span class="button vicon wpv-shortcode-post-icon '. $icon_class .'"><i class="'.$this->icon_class.'"></i><span class="button-label">' . $button_label . '</span></span>';
  97. }
  98. }
  99. // Codemirror (new layout) button
  100. if ( $codemirror_button ){
  101. $addon_button = '<button class="js-code-editor-toolbar-button js-code-editor-toolbar-button-v-icon button-secondary">'.
  102. '<i class="icon-views-logo ont-icon-18"></i><span class="button-label">'. __('Fields', 'wpv-views') .'</span></button>';
  103. }
  104. // add search box
  105. $searchbar = $this->get_search_bar();
  106. // generate output content
  107. $out = '' .
  108. $addon_button . '
  109. <div class="editor_addon_dropdown '. $dropdown_class .'" id="editor_addon_dropdown_' . rand() . '">
  110. <h3 class="title">' . $this->button_text . '</h3>
  111. <div class="close">&nbsp;</div>
  112. <div class="editor_addon_dropdown_content">
  113. ' . apply_filters( 'editor_addon_dropdown_top_message_' . $this->name,
  114. '' ) . '
  115. <p class="direct-links-desc">'. __('Go to','wpv-views') .': </p>
  116. <ul class="direct-links">' . $direct_links . '</ul>
  117. ' . $searchbar . '
  118. ' . $menus_output . '
  119. ' . apply_filters( 'editor_addon_dropdown_bottom_message' . $this->name,
  120. '' ) .
  121. '
  122. </div>
  123. </div>';
  124. // WP 3.3 changes
  125. if ( version_compare( $wp_version, '3.1.4', '>' ) ) {
  126. echo apply_filters( 'wpv_add_media_buttons', $out );
  127. } else {
  128. return apply_filters( 'wpv_add_media_buttons', $context . $out );
  129. }
  130. }
  131. /**
  132. * Adding a "V" button to the menu (for user fields)
  133. * @param string $context
  134. * @param string $text_area
  135. * @param boolean $standard_v is this a standard V button
  136. */
  137. function add_users_form_button( $context, $text_area = 'textarea#content', $codemirror_button = false ) {
  138. global $wp_version, $sitepress, $wpdb, $WP_Views;
  139. $standard_v = true;
  140. // WP 3.3 changes ($context arg is actually a editor ID now)
  141. if ( version_compare( $wp_version, '3.1.4', '>' ) && !empty( $context ) ) {
  142. $text_area = $context;
  143. }
  144. //print_r($this->items);exit;
  145. $this->items = array();
  146. $unused_field = array('comment_shortcuts','managenav-menuscolumnshidden','dismissed_wp_pointers','meta-box-order_dashboard','nav_menu_recently_edited',
  147. 'primary_blog','rich_editing','source_domain','use_ssl','user_level','user-settings-time'
  148. ,'user-settings','dashboard_quick_press_last_post_id','capabilities','new_date','show_admin_bar_front','show_welcome_panel','show_highlight','admin_color'
  149. ,'language_pairs','first_name','last_name','name','nickname','description','yim','jabber','aim');
  150. $exclude_these_hidden_var = '/('.implode('|', $unused_field).')/';
  151. $this->items = array(
  152. array(__('User ID', 'wpv-views'), 'wpv-user field="ID"',__('Basic', 'wpv-views'),''),
  153. array(__('User Email', 'wpv-views'), 'wpv-user field="user_email"',__('Basic', 'wpv-views'),''),
  154. array(__('User Login', 'wpv-views'), 'wpv-user field="user_login"',__('Basic', 'wpv-views'),''),
  155. array(__('First Name', 'wpv-views'), 'wpv-user field="user_firstname"',__('Basic', 'wpv-views'),''),
  156. array(__('Last Name', 'wpv-views'), 'wpv-user field="user_lastname"',__('Basic', 'wpv-views'),''),
  157. array(__('Nickname', 'wpv-views'), 'wpv-user field="nickname"',__('Basic', 'wpv-views'),''),
  158. array(__('Display Name', 'wpv-views'), 'wpv-user field="display_name"',__('Basic', 'wpv-views'),''),
  159. array(__('Description', 'wpv-views'), 'wpv-user field="description"',__('Basic', 'wpv-views'),''),
  160. array(__('Yahoo IM', 'wpv-views'), 'wpv-user field="yim"',__('Basic', 'wpv-views'),''),
  161. array(__('Jabber', 'wpv-views'), 'wpv-user field="jabber"',__('Basic', 'wpv-views'),''),
  162. array(__('AIM', 'wpv-views'), 'wpv-user field="aim"',__('Basic', 'wpv-views'),''),
  163. array(__('User Url', 'wpv-views'), 'wpv-user field="user_url"',__('Basic', 'wpv-views'),''),
  164. array(__('Registration Date', 'wpv-views'), 'wpv-user field="user_registered"',__('Basic', 'wpv-views'),''),
  165. array(__('User Status', 'wpv-views'), 'wpv-user field="user_status"',__('Basic', 'wpv-views'),''),
  166. array(__('User Spam Status', 'wpv-views'), 'wpv-user field="spam"',__('Basic', 'wpv-views'),'')
  167. );
  168. if ( isset( $sitepress ) && function_exists( 'wpml_string_shortcode' ) ) {
  169. $this->items[] = array(__('Translatable string', 'wpv-views'), 'wpml-string',__('Basic', 'wpv-views'),'wpv_insert_translatable_string_popup()');
  170. }
  171. $meta_keys = get_user_meta_keys();
  172. $all_types_fields = get_option( 'wpcf-fields', array() );
  173. foreach ($meta_keys as $key) {
  174. $key_nicename = '';
  175. if ( function_exists('wpcf_init') ){
  176. if (stripos($key, 'wpcf-') === 0) {
  177. //
  178. }
  179. else {
  180. if ( preg_match($exclude_these_hidden_var , $key) ){
  181. continue;
  182. }
  183. $this->items[] = array($key,
  184. 'wpv-user field="'.$key.'"',
  185. __('Users fields', 'wpv-views'),'');
  186. }
  187. }
  188. else{
  189. if ( preg_match($exclude_these_hidden_var , $key) ){
  190. continue;
  191. }
  192. $this->items[] = array($key,
  193. 'wpv-user field="'.$key.'"',
  194. __('User fields', 'wpv-views'),'');
  195. }
  196. }
  197. if ( function_exists('wpcf_init') ){
  198. //Get types groups and fields
  199. $groups = wpcf_admin_fields_get_groups( 'wp-types-user-group' );
  200. $user_id = wpcf_usermeta_get_user();
  201. $add = array();
  202. if ( !empty( $groups ) ) {
  203. foreach ( $groups as $group_id => $group ) {
  204. if ( empty( $group['is_active'] ) ) {
  205. continue;
  206. }
  207. $fields = wpcf_admin_fields_get_fields_by_group( $group['id'],
  208. 'slug', true, false, true, 'wp-types-user-group',
  209. 'wpcf-usermeta' );
  210. if ( !empty( $fields ) ) {
  211. foreach ( $fields as $field_id => $field ) {
  212. $add[] = $field['meta_key'];
  213. $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'views-usermeta\', -1)';
  214. $this->items[] = array($field['name'],
  215. 'types usermeta="'.$field['meta_key'].'"][/types',
  216. $group['name'],$callback);
  217. }
  218. }
  219. }
  220. }
  221. //Get unused types fields
  222. $cf_types = wpcf_admin_fields_get_fields( true, true, false, 'wpcf-usermeta' );
  223. foreach ( $cf_types as $cf_id => $cf ) {
  224. if ( !in_array( $cf['meta_key'], $add) ){
  225. $callback = 'wpcfFieldsEditorCallback(\'' . $cf['id'] . '\', \'views-usermeta\', -1)';
  226. $this->items[] = array($cf['name'],
  227. 'types usermeta="'.$cf['meta_key'].'"][/types',
  228. __('Types fields', 'wpv-views'),$callback);
  229. }
  230. }
  231. }
  232. $view_available = $wpdb->get_results("SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type='view' AND post_status in ('publish')");
  233. foreach($view_available as $view) {
  234. $view_settings = get_post_meta($view->ID, '_wpv_settings', true);
  235. if (isset($view_settings['query_type'][0]) && $view_settings['query_type'][0] == 'posts' && !$WP_Views->is_archive_view($view->ID)) {
  236. $this->items[] = array($view->post_title,
  237. $view->post_title,
  238. __('Post View', 'wpv-views'),
  239. ''
  240. );
  241. }
  242. }
  243. $out = array();
  244. $menus = array();
  245. $sub_menus = array();
  246. if( $this->items )
  247. foreach ( $this->items as $item ) {
  248. $parts = explode( '-!-', $item[2] );
  249. $menu_level = &$menus;
  250. foreach ( $parts as $part ) {
  251. if ( $part != '' ) {
  252. if ( !array_key_exists( $part, $menu_level ) ) {
  253. $menu_level[$part] = array();
  254. }
  255. $menu_level = &$menu_level[$part];
  256. }
  257. }
  258. $menu_level[$item[0]] = $item;
  259. }
  260. // Sort menus
  261. if ( is_array( $menus ) ) {
  262. $menus = $this->sort_menus_alphabetically( $menus );
  263. }
  264. $this->_media_menu_direct_links = array();
  265. $menus_output = $this->_output_media_menu( $menus, $text_area,
  266. $standard_v );
  267. $direct_links = implode( ' ', $this->_media_menu_direct_links );
  268. $dropdown_class = 'js-editor_addon_dropdown-'.$this->name;
  269. $icon_class = 'js-wpv-shortcode-post-icon-'.$this->name;
  270. if ( $this->name == 'wpv-views' ) {
  271. $button_label = __( 'Views', 'wpv-views' );
  272. } else if ( $this->name == 'types' ) {
  273. $button_label = __( 'Types', 'wpv-views' );
  274. } else {
  275. $button_label = '';
  276. }
  277. $addon_button = '<span class="button wpv-shortcode-post-icon '. $icon_class .'"><img src="' . $this->media_button_image . '" />' . $button_label . '</span>';
  278. if ( !$standard_v ) {
  279. $addon_button = '<span class="button vicon wpv-shortcode-post-icon '. $icon_class .'"><img src="' . $this->media_button_image . '" />' . $button_label . '</span>';
  280. // $addon_button = '<input id="addingbutton" alt="#TB_inline?inlineId=add_field_popup" class="thickbox wpv_add_fields_button button-primary field_adder" type="button" value="'. __('Add field', 'wpv-views') .'" name="" />';
  281. //$addon_button = '<span class="wpv_add_fields_button button-primary field_adder">'. __('Add field', 'wpv-views') .'</span>';
  282. }
  283. // Codemirrir (new layout) button
  284. if ( $codemirror_button ){
  285. $addon_button = '<button class="js-code-editor-toolbar-button js-code-editor-toolbar-button-v-icon button-secondary">'.
  286. '<i class="icon-views-logo ont-icon-18"></i><span class="button-label">'. __('Fields', 'wpv-views') .'</span></button>';
  287. }
  288. // add search box
  289. $searchbar = $this->get_search_bar();
  290. // generate output content
  291. $out = '' .
  292. $addon_button . '
  293. <div class="editor_addon_dropdown '. $dropdown_class .'" id="editor_addon_dropdown_' . rand() . '">
  294. <h3 class="title">' . $this->button_text . '</h3>
  295. <div class="close">&nbsp;</div>
  296. <div class="editor_addon_dropdown_content">
  297. ' . apply_filters( 'editor_addon_dropdown_top_message_' . $this->name,
  298. '' ) . '
  299. <p class="direct-links-desc">'. __('Go to','wpv-views') .': </p>
  300. <ul class="direct-links">' . $direct_links . '</ul>
  301. ' . $searchbar . '
  302. ' . $menus_output . '
  303. ' . apply_filters( 'editor_addon_dropdown_bottom_message' . $this->name,
  304. '' ) .
  305. '
  306. </div>
  307. </div>';
  308. // WP 3.3 changes
  309. if ( version_compare( $wp_version, '3.1.4', '>' ) ) {
  310. echo apply_filters( 'wpv_add_media_buttons', $out );
  311. } else {
  312. return apply_filters( 'wpv_add_media_buttons', $context . $out );
  313. }
  314. }
  315. /**
  316. * Output a single menu item
  317. * @param string $menu
  318. * @param string $text_area
  319. * @param boolean $standard_v
  320. * @return string media menu
  321. */
  322. function _output_media_menu( $menu, $text_area, $standard_v ) {
  323. $all_post_types = implode( ' ',
  324. get_post_types( array('public' => true) ) );
  325. $out = '';
  326. if ( is_array( $menu ) ) {
  327. foreach ( $menu as $key => $menu_item ) {
  328. if ( isset( $menu_item[0] ) && !is_array( $menu_item[0] ) ) {
  329. if ( !isset( $menu_item[3] ) ) {
  330. break;
  331. }
  332. if ( $menu_item[3] != '' ) {
  333. if ( !($key == 'css') ) { // hide unnecessary elements from the V popup
  334. if ( !$standard_v && (strpos( $menu_item[3],
  335. 'wpcfFieldsEditorCallback' ) !== false ||
  336. strpos( $menu_item[3],
  337. 'wpcfFieldsEmailEditorCallback' ) !== false ||
  338. strpos( $menu_item[3],
  339. 'wpv_insert_view_form_popup' ) !== false) ) {
  340. $out .= $this->wpv_parse_menu_item_from_addfield( $menu_item );
  341. } else {
  342. $out .= '<li class="item" onclick="' . $menu_item[3] . '; return false;">' . $menu_item[0] . "</li>\n";
  343. }
  344. }
  345. } else {
  346. if ( $standard_v ) {
  347. $short_code = $menu_item[1];
  348. $link_text = $menu_item[0];
  349. if ( $menu_item[2] == __( 'Post View',
  350. 'wpv-views' ) || $menu_item[2] == __( 'Taxonomy View',
  351. 'wpv-views' ) || $menu_item[2] == __( 'User View',
  352. 'wpv-views' ) ) {
  353. $short_code = 'wpv-view name="' . $short_code . '"';
  354. $link_text = str_replace( ' - ' . __( 'Post View' ),
  355. '', $link_text );
  356. $link_text = str_replace( ' - ' . __( 'Taxonomy View' ),
  357. '', $link_text );
  358. $link_text = str_replace( ' - ' . __( 'User View' ),
  359. '', $link_text );
  360. }
  361. $short_code = '[' . $short_code . ']';
  362. $short_code = base64_encode( $short_code );
  363. $out .= '<li class="item" onclick="insert_b64_shortcode_to_editor(\'' . $short_code . '\', \'' . $text_area . '\'); return false;">' . $link_text . "</li>\n";
  364. } else {
  365. $out .= $this->wpv_parse_menu_item_from_addfield( $menu_item );
  366. }
  367. }
  368. } else {
  369. if ( 'wpcf' != $key && 'views' != $key ) { // for some reason it displays a group wpcf on sites with WPLANG different from ''
  370. // a sum menu.
  371. /*
  372. * SRDJAN
  373. * Avoid using all classes.
  374. * It will add generic classes that can messup our code.
  375. */
  376. $css_classes = '';
  377. // $css_classes = isset($menu_item['css']) ? $menu_item['css'] : '';
  378. // if($key == __('Taxonomy', 'wpv-views') || $key == __('Basic', 'wpv-views')) {
  379. // $css_classes = $all_post_types;
  380. // }
  381. $this->_media_menu_direct_links[] = '<li data-id="' . md5( $key ) .'" class="editor-addon-top-link" data-editor_addon_target="editor-addon-link-' . md5( $key ) . '">' . $key . ' </li>';
  382. /*
  383. * SRDJAN
  384. * Hmmmm, multiple IDs
  385. * Changed ID to class
  386. */
  387. // $out .= '<div class="group '. $css_classes .'"><div class="group-title" id="editor-addon-link-' . md5($key) . '-target">' . $key . "&nbsp;&nbsp;\n</div>\n";
  388. $out .= '<div class="group ' . $css_classes . '"><h4 data-id="'.md5( $key ).'" class="group-title editor-addon-link-' . md5( $key ) . '-target">' . $key . "</h4>";
  389. $out .= '<ul>';
  390. $out .= $this->_output_media_menu( $menu_item, $text_area, $standard_v );
  391. $out .= "</ul>";
  392. $out .= "</div>";
  393. }
  394. }
  395. }
  396. }
  397. return $out;
  398. }
  399. /**
  400. * Parser for menu items in the add-field
  401. * @param unknown_type $key
  402. * @param unknown_type $menu_item
  403. * @return string
  404. */
  405. function wpv_parse_menu_item_from_addfield( $menu_item ) {
  406. $param1 = '';
  407. $slug = $menu_item[1];
  408. // search for wpv- starting fields first
  409. if ( strpos( $slug, 'wpv-' ) !== false ) {
  410. $menuitem_parts = explode( ' ', $slug );
  411. $slug = $menuitem_parts[0];
  412. }
  413. // find types fields
  414. else if ( (strpos( $menu_item[3], 'wpcfFieldsEditorCallback' ) !== false)
  415. || (strpos( $menu_item[3], 'wpcfFieldsEmailEditorCallback' ) !== false)
  416. || (strpos( $menu_item[3], 'wpv_insert_view_form_popup' ) !== false) ) {
  417. return '<li class="item" onclick="on_add_field_wpv_types_callback(\'' . esc_js( $menu_item[3] ) . '\', \'' . esc_js( $menu_item[0] ) . '\'); return false;">' . $menu_item[0] . "</li>\n";
  418. } else if ( (preg_match( '/types field="(.+)"/', $slug, $matches ) > 0)
  419. || (preg_match( '/type="(.+)"/', $slug, $matches ) > 0) ) {
  420. $types_slug = $matches[1];
  421. $types_slug = str_replace( '" class="" style="', '', $types_slug );
  422. // convert Types fields to Views fields
  423. $slug = $types_slug;
  424. $param1 = 'Types-!-wpcf';
  425. } else if ( preg_match( '/type="(.+)"/', $slug, $matches ) > 0 ) {
  426. $types_slug = $matches[1];
  427. $types_slug = str_replace( '" class="" style="', '', $types_slug );
  428. // convert field to Views field
  429. $slug = $types_slug;
  430. $param1 = 'Types-!-wpcf';
  431. // apply_filters() for Types shortcodes
  432. }
  433. // for Basic group fields
  434. if ( $menu_item[2] == __( 'Basic', 'wpv-views' ) ) {
  435. // don't use slug here, just field name.
  436. $slug = $menu_item[0];
  437. }
  438. // View Templates here
  439. if ( $menu_item[2] == __( 'View templates', 'wpv-views' ) ) {
  440. $param1 = 'View template';
  441. }
  442. if ( $menu_item[2] == __( 'Post View', 'wpv-views' ) || $menu_item[2] == __( 'Taxonomy View',
  443. 'wpv-views' ) || $menu_item[2] == __( 'User View', 'wpv-views' ) ) {
  444. $param1 = 'Child View';
  445. }
  446. if ( strpos( $slug, 'wpv-post-field' ) !== false ) {
  447. $param1 = __('Field', 'wpv-views');
  448. $slug = $menu_item[0];
  449. }
  450. // Taxonomies
  451. if ( strpos( $menu_item[1], 'wpv-post-taxonomy' ) !== false ) {
  452. $slug = $menu_item[1];
  453. $param1 = 'Taxonomy';
  454. if ( preg_match( '/wpv-post-taxonomy type="([^"]*)"/', $slug,
  455. $matches ) > 0 ) {
  456. $slug = 'wpvtax-' . $matches[1]; // split up and pass text only
  457. } else {
  458. $slug = esc_html( $menu_item[1] );
  459. $slug = str_replace( 'wpv-post-taxonomy', 'wpv-taxonomy',
  460. $slug );
  461. }
  462. /* $slug = esc_html($menu_item[1]);
  463. $slug = str_replace('wpv-post-taxonomy', 'wpv-taxonomy', $slug); */
  464. }
  465. $link_text = $menu_item[0];
  466. if ( $param1 == 'Child View' ) {
  467. $link_text = str_replace( ' - ' . __( 'Post View' ), '',
  468. $link_text );
  469. $link_text = str_replace( ' - ' . __( 'Taxonomy View' ), '',
  470. $link_text );
  471. $link_text = str_replace( ' - ' . __( 'User View' ), '',
  472. $link_text );
  473. }
  474. return '<li class="item" onclick="on_add_field_wpv(\'' . $param1 . '\', \'' . esc_js( $slug ) . '\', \'' . base64_encode( $menu_item[0] ) . '\')">' . $link_text . "</li>\n";
  475. }
  476. // add parent items for Views and View Templates
  477. function wpv_add_parent_items( $items ) {
  478. global $post, $pagenow;
  479. if ( $pagenow == 'post-new.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'view-template' ) {
  480. $this->add_view_template_parent_groups( $items );
  481. }
  482. if ( $pagenow == 'post-new.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'view' ) {
  483. } else if ( $pagenow == 'post.php' && isset( $_GET['action'] ) && $_GET['action'] == 'edit' ) {
  484. $post_type = $post->post_type;
  485. if ( $post_type == 'view' ) {
  486. $items = $this->add_view_parent_groups( $items );
  487. } else if ( $post_type == 'view-template' ) {
  488. $items = $this->add_view_template_parent_groups( $items );
  489. }
  490. }
  491. return $items;
  492. }
  493. function add_view_parent_groups( $items ) {
  494. }
  495. // add parent groups for vew templates
  496. function add_view_template_parent_groups( $items ) {
  497. global $post;
  498. // get current View ID
  499. $view_template_id = $post->ID;
  500. // get all view templates attached in the Settings page for single view
  501. $view_template_relations = $this->get_view_template_settings();
  502. // find view template groups and get their parents
  503. $current_types = array();
  504. $parent_types = array();
  505. foreach ( $view_template_relations as $relation => $value ) {
  506. if ( $value == $view_template_id ) {
  507. $current_types[] = $relation;
  508. if ( function_exists( 'wpcf_pr_get_belongs' ) ) {
  509. $parent_types[] = wpcf_pr_get_belongs( $relation );
  510. }
  511. }
  512. }
  513. // get parent groups
  514. $all_parent_groups = array();
  515. foreach ( $parent_types as $type ) {
  516. foreach ( $type as $typename => $typeval ) {
  517. $parent_groups = wpcf_admin_get_groups_by_post_type( $typename );
  518. }
  519. }
  520. }
  521. /**
  522. *
  523. * Sort menus (and menu content) in an alphabetical order
  524. *
  525. * Still, keep Basic and Taxonomy on the top and Other Fields at the bottom
  526. *
  527. * @param array $menu menu reference
  528. */
  529. function sort_menus_alphabetically( $menus ) {
  530. // keep main references if set (not set on every screen)
  531. $menu_temp = array();
  532. $menu_names = array(
  533. __( 'Taxonomy View', 'wpv-views' ),
  534. __( 'User View', 'wpv-views' ),
  535. __( 'Post View', 'wpv-views' ),
  536. __( 'View', 'wpv-views' ),
  537. __( 'View templates', 'wpv-views' ),
  538. __( 'Taxonomy', 'wpv-views' ),
  539. __( 'Basic', 'wpv-views' ),
  540. __( 'Other Fields', 'wpv-views' )
  541. );
  542. foreach ( $menu_names as $name ) {
  543. $menu_temp[$name] = isset( $menus[$name] ) ? $menus[$name] : array();
  544. }
  545. // remove them to preserve correct listing
  546. foreach ( $menu_names as $name ) {
  547. unset( $menus[$name] );
  548. }
  549. // sort all elements by key
  550. ksort( $menus );
  551. // add main elements in the correct order
  552. foreach ( $menu_names as $name ) {
  553. $menus = !empty( $menu_temp[$name] ) ? array_merge( array($name => $menu_temp[$name]),
  554. $menus ) : $menus;
  555. }
  556. // sort inner elements in the submenus
  557. foreach ( $menus as $key => $menu_group ) {
  558. if ( is_array( $menu_group ) ) {
  559. ksort( $menu_group );
  560. }
  561. }
  562. return $menus;
  563. }
  564. function get_search_bar() {
  565. $searchbar = '<p class="searchbar">';
  566. $searchbar .= '<label for="searchbar-input">' . __( 'Search', 'wpv-views' ) . ': </label>';
  567. $searchbar .= '<input id="searchbar-input" type="text" class="search_field" onkeyup="wpv_on_search_filter(this)" />';
  568. $searchbar .= '<input type="button" class="button-secondary search_clear" value="' . __( 'Clear','wpv-views' ) . '" onclick="wpv_search_clear(this)" style="display: none;" />';
  569. $searchbar .= '</p>';
  570. return $searchbar;
  571. }
  572. function add_view_type( &$menus, $post_type, $post_name ) {
  573. global $wpdb;
  574. $all_post_types = implode( ' ',
  575. get_post_types( array('public' => true) ) );
  576. $view_templates_available = $wpdb->get_results( "SELECT ID, post_title, post_name FROM {$wpdb->posts} WHERE
  577. post_type='{$post_type}' AND post_status in ('publish')" );
  578. $menus[$post_name] = array();
  579. $menus[$post_name]['css'] = $all_post_types;
  580. $vtemplate_index = 0;
  581. foreach ( $view_templates_available as $vtemplate ) {
  582. $title = $vtemplate->post_title;
  583. if ( $post_type == 'view' ) {
  584. $view_settings = get_post_meta( $vtemplate->ID,
  585. '_wpv_settings', true );
  586. $title = $vtemplate->post_title . ' - ' . __( 'Post View',
  587. 'wpv-views' );
  588. if ( isset( $view_settings['query_type'][0] ) && $view_settings['query_type'][0] == 'taxonomy' ) {
  589. $title = $vtemplate->post_title . ' - ' . __( 'Taxonomy View',
  590. 'wpv-views' );
  591. if ( $post_name == __( 'Post View', 'wpv-views' ) || $post_name == __( 'User View', 'wpv-views' ) ) {
  592. continue;
  593. }
  594. } elseif ( isset( $view_settings['query_type'][0] ) && $view_settings['query_type'][0] == 'users' ) {
  595. $title = $vtemplate->post_title . ' - ' . __( 'User View',
  596. 'wpv-views' );
  597. if ( $post_name == __( 'Post View', 'wpv-views' ) || $post_name == __( 'Taxonomy View', 'wpv-views' ) ) {
  598. continue;
  599. }
  600. } else {
  601. if ( $post_name == __( 'Taxonomy View', 'wpv-views' ) || $post_name == __( 'User View', 'wpv-views' ) ) {
  602. continue;
  603. }
  604. }
  605. if ( isset( $view_settings['view-query-mode'] ) && $view_settings['view-query-mode'] =='archive' ){
  606. continue;
  607. }
  608. }
  609. $menus[$post_name][$vtemplate_index] = array();
  610. $menus[$post_name][$vtemplate_index][] = $title;
  611. $menus[$post_name][$vtemplate_index][] = $vtemplate->post_name;
  612. $menus[$post_name][$vtemplate_index][] = $post_name;
  613. $menus[$post_name][$vtemplate_index][] = '';
  614. $vtemplate_index++;
  615. }
  616. }
  617. function get_view_template_settings() {
  618. $post_types = get_post_types();
  619. $options = array();
  620. $wpv_options = get_option( 'wpv_options' );
  621. foreach ( $post_types as $type ) {
  622. if ( isset( $wpv_options['views_template_for_' . $type] ) && !empty( $wpv_options['views_template_for_' . $type] ) ) {
  623. $options[$type] = $wpv_options['views_template_for_' . $type];
  624. }
  625. }
  626. return $options;
  627. }
  628. }
  629. /*
  630. Add the wpv_views button to the toolbar.
  631. */
  632. function wpv_mce_add_button( $buttons )
  633. {
  634. array_push( $buttons, "separator",
  635. str_replace( '-', '_', $this->name ) );
  636. return $buttons;
  637. }
  638. /*
  639. Register this plugin as a mce 'addon'
  640. Tell the mce editor the url of the javascript file.
  641. */
  642. if( !function_exists('wpv_mce_register') )
  643. {
  644. function wpv_mce_register( $plugin_array )
  645. {
  646. $plugin_array[str_replace( '-', '_', $this->name )] = $this->plugin_js_url;
  647. return $plugin_array;
  648. }
  649. }
  650. if( !function_exists('editor_add_js') )
  651. {
  652. function editor_add_js() {
  653. global $pagenow;
  654. if (
  655. $pagenow == 'post.php' ||
  656. $pagenow == 'post-new.php' ||
  657. ( $pagenow == 'admin.php' && ( isset( $_GET['page'] ) &&
  658. ( $_GET['page'] == 'views-editor' ||
  659. $_GET['page'] == 'view-archives-editor' ||
  660. $_GET['page'] == 'dd_layouts_edit') ) ) // add the new Views edit screens
  661. ) {
  662. wp_enqueue_script( 'icl_editor-script',
  663. EDITOR_ADDON_RELPATH . '/res/js/icl_editor_addon_plugin.js',
  664. array() );
  665. }
  666. }
  667. }
  668. /**
  669. * Renders JS for inserting shortcode from thickbox popup to editor.
  670. *
  671. * @param type $shortcode
  672. */
  673. if( !function_exists('editor_admin_popup_insert_shortcode_js') )
  674. {
  675. function editor_admin_popup_insert_shortcode_js( $shortcode ) { // Types now uses ColorBox, it's not used in Views anymore. Maybe DEPRECATED
  676. ?>
  677. <script type="text/javascript">
  678. //<![CDATA[
  679. // Close popup
  680. window.parent.jQuery('#TB_closeWindowButton').trigger('click');
  681. // Check if there is custom handler
  682. if (window.parent.wpcfFieldsEditorCallback_redirect) {
  683. eval(window.parent.wpcfFieldsEditorCallback_redirect['function'] + '(\'<?php echo esc_js( $shortcode ); ?>\', window.parent.wpcfFieldsEditorCallback_redirect[\'params\'])');
  684. } else {
  685. // Use default handler
  686. window.parent.icl_editor.insert('<?php echo $shortcode; ?>');
  687. }
  688. //]]>
  689. </script>
  690. <?php
  691. }
  692. }
  693. }