public function __construct() { parent::__construct(); global $cb_post_id; $this->settings = clearbase_get_folder_settings(); $this->is_parent_settings = $cb_post_id != clearbase_get_value('_folder_id', 0, $this->settings); $this->show_folders = clearbase_get_value($this->is_parent_settings ? 'allow_child_nesting' : 'allow_nesting', true, $this->settings); $this->show_add_folders = !$this->show_folders ? false : apply_filters("clearbase_allow_new_folders", true, $cb_post_id); $this->show_media = !clearbase_is_root() || clearbase_is_root() && clearbase_get_value('allow_root_media', true, $this->settings); $this->show_media = apply_filters('clearbase_show_media', $this->show_media, $cb_post_id); $this->show_add_media = !$this->show_media ? false : apply_filters("clearbase_allow_new_media", true, $cb_post_id); $this->is_trash = false; //TODO if (clearbase_is_root(false)) { //enforce Clearbase root rules $this->show_folders = $this->show_add_folders = true; $this->show_media = $this->show_add_media = false; } $modes = array('grid', 'list'); if (isset($_GET['mode']) && in_array($_GET['mode'], $modes)) { $this->mode = clearbase_empty_default($_GET, 'mode', ''); update_user_option(get_current_user_id(), 'clearbase_media_mode', $this->mode); } else { $this->mode = get_user_option('clearbase_media_mode', get_current_user_id()); if (!in_array($this->mode, $modes)) { $this->mode = 'list'; } } if ($this->show_media && 'list' == $this->mode) { require_once CLEARBASE_DIR . '/includes/class-cb-media-list-table.php'; $this->media_table = new CB_Media_List_Table(); } }
function clearbase_ajax_move_to_folder() { check_ajax_referer('clearbase_ajax', 'cbnonce'); //move posts to another folder $folder_id = absint($_REQUEST['folderid']); $posts = clearbase_empty_default($_REQUEST, 'posts', array()); $result = clearbase_move_to_folder($folder_id, $posts); echo wp_json_encode(array('success' => false == is_wp_error($result), 'data' => array('message' => is_wp_error($result) ? $result->get_error_message() : __('Move to folder complete.', 'clearbase')))); wp_die(); }
function clearbase_current_url($encode = false) { $pageURL = 'http'; if ("on" == clearbase_empty_default($_SERVER, 'HTTPS', '')) { $pageURL .= "s"; } $pageURL .= "://"; if ('80' != clearbase_empty_default($_SERVER, 'SERVER_PORT', '')) { $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; } return $encode ? urlencode($pageURL) : $pageURL; }
function clearbase_init_menus() { $page = clearbase_empty_default($_GET, 'page', ''); $folder_id = 0; if (0 === strrpos($page, 'cbfolder')) { $folder_id = absint(substr(strrchr($page, "_"), 1)); $page = 'cbfolder'; } global $cb_admin_view; switch ($page) { case 'clearbase': case 'cbfolder': require_once CLEARBASE_DIR . '/views/class-view-workspace.php'; $cb_admin_view = new Clearbase_View_Workspace($folder_id); break; case 'clearbase-settings': require_once CLEARBASE_DIR . '/views/class-view-admin-settings.php'; $cb_admin_view = new Clearbase_View_Admin_Settings(); break; } /* Render the main Clearbase menus */ add_menu_page(__('Clearbase', 'clearbase'), __('Clearbase', 'clearbase'), 'manage_options', 'clearbase', '_clearbase_admin_render_view', 'dashicons-screenoptions'); //now add the sub menus add_submenu_page('clearbase', __('Clearbase Framework', 'clearbase'), __('Folders', 'clearbase'), 'manage_options', 'clearbase', '_clearbase_admin_render_view'); add_submenu_page('clearbase', __('Clearbase Settings', 'clearbase'), __('Settings', 'clearbase'), 'manage_options', 'clearbase-settings', '_clearbase_admin_render_view'); //now loop through all of the root clearbase folders that have menus specified $query = new WP_Query(array('post_type' => 'clearbase_folder', 'post_parent' => 0, 'meta_query' => array(array('key' => 'menu', 'compare' => 'EXISTS')))); global $post; while ($query->have_posts()) { $query->the_post(); $meta = clearbase_get_value('postmeta.menu', array()); if ('yes' != clearbase_empty_default($meta, 'show', 'no')) { continue; } $menu_slug = 'cbfolder_' . get_the_ID(); add_menu_page(clearbase_empty_default($meta, 'page_title', get_the_title()), clearbase_empty_default($meta, 'title', get_the_title()), clearbase_empty_default($meta, 'capability', 'manage_options'), $menu_slug, '_clearbase_admin_render_view', clearbase_empty_default($meta, 'icon', 'dashicons-screenoptions'), clearbase_empty_default($meta, 'position', 21)); //fire the parent menu do_action('clearbase_folder_menu', $menu_slug); } }
public function __construct($subviews = array()) { parent::__construct(); global $cb_post_id, $cb_post; $this->subviews = $subviews; $this->subviews = apply_filters("clearbase_{$this->ID()}_subviews", $this->subviews, $cb_post); // $subview_id = clearbase_empty_default($_REQUEST, 'subview', ''); //handle the scenario where no subview is specified... if (empty($subview_id)) { $this->current_view = reset($this->subviews); } else { foreach ($this->subviews as $subview) { if ($subview->ID() == $subview_id) { $this->current_view = $subview; break; } } } if (isset($this->current_view)) { $this->current_view->InitEditor(); } }
public function manage_media_columns($columns) { //remove the "Uploaded To" column. All media items in our table are //uploaded to the current folder unset($columns['parent']); //if the attachment-filter is not set... if (!clearbase_empty_default($_REQUEST, 'attachment-filter', false)) { //add the dragsort column at the first position $columns = array('dragsort' => '') + $columns; } //return the updated columns return $columns; }
public function __construct($folder_root = 0) { parent::__construct(); global $cb_folder_root, $cb_post_id, $cb_post, $cb_post_type_obj, $view_id, $cb_action, $cb_workspace_saving; $cb_folder_root = $folder_root; clearbase_folder_set_global(clearbase_empty_default($_GET, 'id', 0)); add_action('post_updated', array(&$this, '_updated'), 10, 1); add_action('edit_attachment', array(&$this, '_updated'), 10, 1); $cb_action = isset($_REQUEST['cbaction']) && -1 != $_REQUEST['cbaction'] ? $_REQUEST['cbaction'] : ''; $cb_workspace_saving = isset($_POST['save-changes']); // do_action('clearbase_workspace_start'); add_filter('clearbase_workspace_view', array($this, 'view'), 10, 3); $this->view = apply_filters('clearbase_workspace_view', null, $cb_post->post_type, $cb_action); if ($this->view instanceof Clearbase_View) { $this->view->InitEditor(); } do_action('clearbase_workspace_loaded'); //allow the loaded views to save any editor changes if (isset($_REQUEST['save-editor'])) { do_action('clearbase_view_save_editor', 'save-editor'); } $args = apply_filters('clearbase_workspace_action', array('action' => $cb_action, 'nonce_action' => $cb_action, 'nonce_field' => isset($_REQUEST['cbnonce']) ? 'cbnonce' : '_wpnonce', 'posts' => clearbase_empty_default($_REQUEST, 'posts', array($cb_post_id)), 'handled' => false)); // Process any Clearbase actions, if the action has not already been handled if (isset($args) && is_array($args) && !$args['handled']) { switch ($args['action']) { case 'add-folder': check_admin_referer($args['nonce_action'], $args['nonce_field']); $result = clearbase_add_folder($cb_post_id); if (is_wp_error($result)) { die($result->get_error_message()); } wp_redirect(clearbase_workspace_url(array('id' => $result, 'cbaction' => 'edit', 'back' => urlencode(clearbase_workspace_url(array('id' => $cb_post_id)))))); exit; break; case 'move': check_admin_referer($args['nonce_action'], $args['nonce_field']); $folder_id = clearbase_empty_default($_REQUEST, 'folderid', ''); if (!is_numeric($folder_id)) { die('Folder ID is invalid.'); } $result = clearbase_move_to_folder($folder_id, $args['posts']); if (is_wp_error($result)) { die($result->get_error_message()); } wp_redirect(clearbase_workspace_url(array('id' => $folder_id))); exit; break; case 'trash': case 'delete': check_admin_referer($args['nonce_action'], $args['nonce_field']); $parent_id; $posts = $args['posts']; for ($i = count($posts) - 1; $i > -1; $i--) { if (!isset($parent_id) && ($p = get_post($posts[$i]))) { $parent_id = $p->post_parent; } wp_delete_post($posts[$i], 'delete' == $args['action']); } wp_redirect(clearbase_workspace_url(array('id' => $parent_id))); exit; break; } } }