=')) { add_action('admin_head-edit.php', array($this, 'admin_add_help')); add_action('admin_head-post.php', array($this, 'admin_add_help')); add_action('admin_head-post-new.php', array($this, 'admin_add_help')); } parent::init(); } function enable_custom_menu_order($menu_ord) { return true; } function custom_menu_order( $menu_ord ) { $types_index = array_search('wpcf', $menu_ord); $views_index = array_search('edit.php?post_type=view', $menu_ord); if ($types_index !== false && $views_index !== false) { // put the types menu above the views menu. unset($menu_ord[$types_index]); $menu_ord = array_values($menu_ord); array_splice($menu_ord, $views_index, 0, 'wpcf'); } return $menu_ord; } function is_embedded() { return false; } function wpv_register_type_view() { $labels = array( 'name' => _x('Views', 'post type general name'), 'singular_name' => _x('View', 'post type singular name'), 'add_new' => _x('Add New View', 'book'), 'add_new_item' => __('Add New View', 'wpv-views'), 'edit_item' => __('Edit View', 'wpv-views'), 'new_item' => __('New View', 'wpv-views'), 'view_item' => __('View Views', 'wpv-views'), 'search_items' => __('Search Views', 'wpv-views'), 'not_found' => __('No views found', 'wpv-views'), 'not_found_in_trash' => __('No views found in Trash', 'wpv-views'), 'parent_item_colon' => '', 'menu_name' => 'Views' ); $args = array( 'labels' => $labels, 'public' => false, 'publicly_queryable' => false, 'show_ui' => true, 'show_in_menu' => false, 'query_var' => false, 'rewrite' => false, 'capability_type' => 'post', 'can_export' => false, 'has_archive' => false, 'hierarchical' => false, //'menu_position' => 80, 'menu_icon' => WPV_URL .'/res/img/views-18.png', 'supports' => array('title','editor','author') ); register_post_type('view',$args); } function admin_menu(){ add_utility_page(__('Views', 'wpv-views'), __('Views', 'wpv-views'), 'manage_options', 'edit.php?post_type=view', '', WPV_URL .'/res/img/views-18.png'); // remove the default menus and then add a Help menu remove_submenu_page('edit.php?post_type=view', 'edit.php?post_type=view'); remove_submenu_page('edit.php?post_type=view', 'post-new.php?post_type=view'); // Add the default menus after the Help menu add_submenu_page('edit.php?post_type=view', __('Views', 'wpv-views'), __('Views', 'wpv-views'), 'manage_options', 'edit.php?post_type=view'); add_submenu_page('edit.php?post_type=view', __('New View', 'wpv-views'), __('New View', 'wpv-views'), 'manage_options', 'post-new.php?post_type=view'); // Add the view template menus. add_submenu_page('edit.php?post_type=view', __('View Templates', 'wpv-views'), __('View Templates', 'wpv-views'), 'manage_options', 'edit.php?post_type=view-template'); add_submenu_page('edit.php?post_type=view', __('New View Template', 'wpv-views'), __('New View Template', 'wpv-views'), 'manage_options', 'post-new.php?post_type=view-template'); // add settings menu. add_submenu_page('edit.php?post_type=view', __('Settings', 'wpv-views'), __('Settings', 'wpv-views'), 'manage_options', 'views-settings', array($this, 'views_settings_admin')); // Add import export menu. if (function_exists('wpv_admin_menu_import_export')) { add_submenu_page('edit.php?post_type=view', __('Import/Export', 'wpv-views'), __('Import/Export', 'wpv-views'), 'manage_options', 'views-import-export', 'wpv_admin_menu_import_export'); } add_submenu_page('edit.php?post_type=view', __('Views Subscription','wp-wiews'), __('Views Subscription','wp-wiews'), 'manage_options', WPV_FOLDER . '/menu/main.php', null, WPV_URL . '/res/img/icon16.png'); add_submenu_page('edit.php?post_type=view', __('Help', 'wpv-views'), __('Help', 'wpv-views'), 'manage_options', WPV_FOLDER . '/menu/help.php', null, WPV_URL . '/res/img/icon16.png'); } function settings_box_load(){ add_meta_box('wpv_settings', '  ' . __('View Query - Choose what content to load', 'wpv-views'), array($this, 'settings_box'), 'view', 'normal', 'high'); add_meta_box('wpv_layout', '  ' . __('View Layout - Edit the layout', 'wpv-views'), 'view_layout_box', 'view', 'normal', 'high'); add_meta_box('wpv_views_help', '  ' . __('Views Help', 'wpv-views'), array($this, 'view_help_box'), 'view', 'side', 'high'); //add_meta_box('wpv_css', '  ' . __('CSS for view', 'wpv-views'), array($this, 'css_box'), 'view', 'normal', 'high'); global $pagenow; if ($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'view') { $this->include_admin_css(); } if ($pagenow == 'options-general.php' && isset($_GET['page']) && $_GET['page'] == WPV_FOLDER . '/menu/main.php') { $this->include_admin_css(); } if ($pagenow == 'options-general.php' && isset($_GET['page']) && $_GET['page'] == 'wpv-import-theme') { $this->include_admin_css(); } } function hide_view_body_controls() { global $pagenow, $post; if (($pagenow == 'post-new.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'view') || ($pagenow == 'post.php' && isset($_GET['action']) && $_GET['action'] == 'edit')) { $post_type = $post->post_type; if($pagenow == 'post.php' && $post_type != 'view') { return; } // hide the post body. ?>
'; _e('* Requires WordPress 3.2 or greater for best results.', 'wpv-views'); echo '

'; } $this->include_admin_css(); wp_nonce_field( 'wpv_get_table_row_ui_nonce', 'wpv_get_table_row_ui_nonce'); ?> get_view_settings($post->ID); // $view_settings = (array)get_post_meta($post->ID, '_wpv_settings', true); ?>

', ' »'); ?> get_row("SELECT post_type, post_status FROM {$wpdb->posts} WHERE ID = " . $post_id, ARRAY_N); if ($post_type == 'view') { if(isset($_POST['_wpv_settings'])){ $_POST['_wpv_settings'] = apply_filters('wpv_view_settings_save', $_POST['_wpv_settings']); update_post_meta($post_id, '_wpv_settings', $_POST['_wpv_settings']); } save_view_layout_settings($post_id); if (isset($sitepress)) { if (isset($_POST['icl_trid'])) { // save the post from the edit screen. if (isset($_POST['wpv_duplicate_view'])) { update_post_meta($post_id, '_wpv_view_sync', intval($_POST['wpv_duplicate_view'])); } else { update_post_meta($post_id, '_wpv_view_sync', "0"); } $icl_trid = $_POST['icl_trid']; } else { // get trid from database. $icl_trid = $wpdb->get_var("SELECT trid FROM {$wpdb->prefix}icl_translations WHERE element_id={$post_id} AND element_type = 'post_$post_type'"); } if (isset($_POST['wpv_duplicate_source_id'])) { $source_id = $_POST['wpv_duplicate_source_id']; $target_id = $post_id; } else { // this is the source $source_id = $post_id; $target_id = null; } if ($icl_trid) { $this->duplicate_view($source_id, $target_id, $icl_trid); } } } } function duplicate_view($source_id, $target_id, $icl_trid) { global $wpdb; if ($target_id) { // we're saving a translation // see if we should copy from the original $duplicate = get_post_meta($target_id, '_wpv_view_sync', true); if ($duplicate === "") { // check the original state $duplicate = get_post_meta($source_id, '_wpv_view_sync', true); } if ($duplicate) { $view_settings = get_post_meta($source_id, '_wpv_settings', true); update_post_meta($target_id, '_wpv_settings', $view_settings); $view_layout_settings = get_post_meta($source_id, '_wpv_layout_settings', true); update_post_meta($target_id, '_wpv_layout_settings', $view_layout_settings); } } else { // We're saving the original // see if we should copy to translations. $translations = $wpdb->get_col("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid = {$icl_trid}"); foreach ($translations as $translation_id) { if ($translation_id != $source_id) { $this->duplicate_view($source_id, $translation_id, $icl_trid); } } } } /** * If the post has a view * add an view edit link to post. */ function edit_post_link($link, $post_id) { if ($this->current_view) { remove_filter('edit_post_link', array($this, 'edit_post_link'), 10, 2); ob_start(); edit_post_link(__('Edit view', 'wpv-views'), '', '', $this->current_view); $link = $link . ' ' . ob_get_clean(); add_filter('edit_post_link', array($this, 'edit_post_link'), 10, 2); } return $link; } function admin_add_help() { global $pagenow; $screen = get_current_screen(); $help = $this->admin_plugin_help('', $screen->id, $screen); if ($help) { $screen->add_help_tab(array( 'id' => 'views-help', 'title' => __('Views', 'wpv-views'), 'content' => $help, )); } } /** * Adds help on admin pages. * * @param type $contextual_help * @param type $screen_id * @param type $screen * @return type */ function admin_plugin_help($contextual_help, $screen_id, $screen) { $help = ''; switch ($screen_id) { case 'edit-view-template': $help = '

'.__("Create View Templates and attach them to content types to display content in complex ways. You can read more detail about View Templates on our website:",'wpv-views'); $help .= '
http://wp-types.com/user-guides/view-templates/ »

'; $help .= '

'.__("On this page you have the following options:", 'wpv-views').'

'; $help .= ''; $help .= '

'.__("Hover over the name of your View Template to get additional options:", 'wpv-views').'

'; $help .= ''; $help .= '

'.sprintf(__("If you need additional help with View Templates you can visit our support forum ».", 'wpv-views'), WPV_SUPPORT_LINK).'

'; break; case 'view-template': $help = '

'.__("Use this page to create and edit View Templates. For more information about View Templates visit the user guide on our website:", 'wpv-views'); $help .= '
http://wp-types.com/user-guides/view-templates/ »

'; $help .= '

'.__("To Create a View Template", 'wpv-views').'

'; $help .= '
  1. '.__("Add a Title", 'wpv-views').'
  2. '; $help .= '
  3. '.__("Add shortcodes to the body. You can find these by clicking on the ā€œVā€ icon", 'wpv-views').'
  4. '; $help .= '
  5. '.__("Use HTML mode to style your content (we recommend keeping your styles in style.css or another external stylesheet rather than including them inline)", 'wpv-views').'
  6. '; $help .= '
'; $help .= '

'.sprintf(__("If you need additional help with View Templates you can visit our support forum ».", 'wpv-views'), WPV_SUPPORT_LINK).'

'; break; case 'edit-view': $help = '

'.__("Use Views to filter and display lists in complex and interesting ways. Read more about Views in our user guide:",'wpv-views'); $help .= '
http://wp-types.com/user-guides/views/ »

'; $help .= '

'.__("This page gives you an overview of the Views you have created.", 'wpv-views').'

'; $help .= '

'.__("It has the following options:", 'wpv-views').'

'; $help .= ''; $help .= '

'.__("If you hover over a View's name you also have these options:", 'wpv-views').'

'; $help .= ''; $help .= '

'.sprintf(__("If you need additional help with View Templates you can visit our support forum ».", 'wpv-views'), WPV_SUPPORT_LINK).'

'; break; case 'view': $help = '

'.__("Use this page to create and edit your Views. You can read more about creating Views in our user guide:",'wpv-views'); $help .= '
http://wp-types.com/user-guides/views/ »

'; $help .= '

'.__("To Create a View:", 'wpv-views').'

'; $help .= '
  1. '.__("Add a Title for your View.", 'wpv-views').'
  2. '; $help .= '
  3. '.__("Leave the shortcodes that are in your text area. These are for filtering and displaying your content.", 'wpv-views').'
  4. '; $help .= '
  5. '.__("View Query > Filter: Select how you would like your content to be filtered.", 'wpv-views').'
  6. '; $help .= '
  7. '.__("View Query > Pagination: Turn pagination on or off.", 'wpv-views').'
  8. '; $help .= '
  9. '.__("View Query > View/Edit HTML : fine tune the HTML for your query.", 'wpv-views').'
  10. '; $help .= '
  11. '.__("View Layout: Choose your layout.", 'wpv-views').'
  12. '; $help .= '
  13. '.__("View Layout > View/Edit HTML: use addition CSS and HTML to control how your View is displayed.", 'wpv-views').'
'; $help .= '

'.sprintf(__("If you need additional help with View Templates you can visit our support forum ».", 'wpv-views'), WPV_SUPPORT_LINK).'

'; break; } if ($help != '') { return $help; } else { return $contextual_help; } } // Add WPML sync options. function language_options() { global $sitepress, $post; if ($post->post_type == 'view') { list($translation, $source_id, $translated_id) = $sitepress->icl_get_metabox_states(); echo '

' . __('Views sync', 'wpv-views') . ''; $checked = ''; if ($translation) { if ($translated_id) { $duplicate = get_post_meta($translated_id, '_wpv_view_sync', true); if ($duplicate === "") { // check the original state $duplicate = get_post_meta($source_id, '_wpv_view_sync', true); } } else { // This is a new translation. $duplicate = get_post_meta($source_id, '_wpv_view_sync', true); } if ($duplicate) { $checked = ' checked="checked"'; } echo '
'; echo ''; } else { $duplicate = get_post_meta($source_id, '_wpv_view_sync', true); if ($duplicate) { $checked = ' checked="checked"'; } echo '
'; } } } function views_settings_admin() { global $WPV_templates, $wpdb; $options = $this->get_options(); $defaults = array('views_template_loop_blog' => '0'); $options = wp_parse_args($options, $defaults); if (isset($_POST['submit']) && $_POST['submit'] == __('Save Changes', 'wpv-views') && wp_verify_nonce($_POST['wpv_view_templates'], 'wpv_view_templates')) { $options = $WPV_templates->submit($options); $this->save_options($options); ?>



admin_settings($options); ?>