/** * Function that starts the add-on * @param CUAR_Plugin $cuar_plugin */ public function run($cuar_plugin) { $this->plugin = $cuar_plugin; $cuar_plugin->register_addon($this); $this->run_addon($cuar_plugin); if (is_admin() && $cuar_plugin->has_commercial_addons()) { // Settings add_filter('cuar/core/settings/settings-tabs', array(&$this, 'add_settings_tab'), 900, 1); add_action('cuar/core/settings/print-settings?tab=cuar_licenses', array(&$this, 'print_license_settings'), 10, 2); add_filter('cuar/core/settings/validate-settings?tab=cuar_licenses', array(&$this, 'validate_license_options'), 10, 3); } }
/** * Get the display name of the owner of a post * * @param int $post_id * @return mixed */ function cuar_get_the_owner($post_id = 0) { $cuar_plugin = CUAR_Plugin::get_instance(); $po_addon = $cuar_plugin->get_addon('post-owner'); $post_id = $post_id == 0 ? get_the_ID() : $post_id; $owner_name = $po_addon->get_post_owner_displayname($post_id); return apply_filters('cuar/private-content/the-owner', $owner_name, $post_id); }
/** * Add the full width body class to our private post types */ function cuar_body_class($classes) { if (!class_exists('CUAR_Plugin')) { return $classes; } $post_type = get_post_type(); $private_post_types = CUAR_Plugin::get_instance()->get_private_post_types(); if (in_array($post_type, $private_post_types)) { $classes[] = 'full-width'; } return $classes; }
protected function get_form_field_input($id, $value) { if ($this->enable_rich_editor && !$this->readonly) { ob_start(); $editor_settings = CUAR_Plugin::get_instance()->get_default_wp_editor_settings(); $editor_settings['textarea_name'] = $id; wp_editor($value, $id, $editor_settings); $out = ob_get_contents(); ob_end_clean(); return $out; } else { return sprintf('<textarea rows="5" cols="40" id="%1$s" name="%2$s" class="%4$s" %5$s>%3$s</textarea>', $id, $id, $value, 'form-control', $this->readonly ? 'readonly="readonly"' : ''); } }
/** * Actually process the shortcode (output stuff, ...) * * @param array $params The parameters * @param string $content The content between the shortcode tags * * @return string The shortcode final output */ public function process_shortcode($params, $content) { // Do not consider guests if (!is_user_logged_in()) { return ''; } $plugin = CUAR_Plugin::get_instance(); $current_user_id = get_current_user_id(); $layout = $params['layout']; $type = $params['type']; // Build the query $args = array('post_type' => $type, 'posts_per_page' => $params['max_items']); // Ownership / authorship switch ($params['show']) { case 'owned': /** @var CUAR_PostOwnerAddOn $po_addon */ $po_addon = $plugin->get_addon('post-owner'); $args['meta_query'] = $po_addon->get_meta_query_post_owned_by($current_user_id); break; case 'authored': $args['author'] = $current_user_id; break; default: return sprintf(__('The parameter %2$s of shortcode <code>[%1$s]</code> has an invalid value: <code>%3$s</code>', 'cuar'), $this->name, 'show', $params['mode']); } // Taxonomy $terms = explode(',', $params['terms']); if (!empty($params['taxonomy']) && !empty($terms)) { $args['tax_query'] = array(array('taxonomy' => $params['taxonomy'], 'field' => $params['terms_field'], 'terms' => $terms, 'operator' => $params['terms_operator'])); } $query = new WP_Query(apply_filters('cuar/shortcodes/protected-content/query-args', $args, $params)); // Determine the template files to use $template_root = CUAR_INCLUDES_DIR . '/core-addons/shortcodes'; if ($query->have_posts()) { $loop_template = $plugin->get_template_file_path($template_root, array('protected-content-shortcode-loop-' . $layout . '-' . $type . '.template.php', 'protected-content-shortcode-loop-' . $layout . '.template.php', 'protected-content-shortcode-loop-' . $type . '.template.php', 'protected-content-shortcode-loop-default.template.php')); } else { $loop_template = $plugin->get_template_file_path($template_root, array('protected-content-shortcode-empty-' . $layout . '-' . $type . '.template.php', 'protected-content-shortcode-empty-' . $layout . '.template.php', 'protected-content-shortcode-empty-' . $type . '.template.php', 'protected-content-shortcode-empty-default.template.php')); } $before_items_template = $plugin->get_template_file_path($template_root, array('protected-content-shortcode-layout-' . $layout . '-' . $type . '-before.template.php', 'protected-content-shortcode-layout-' . $layout . '-before.template.php', 'protected-content-shortcode-layout-' . $type . '-before.template.php', 'protected-content-shortcode-layout-default-before.template.php')); $after_items_template = $plugin->get_template_file_path($template_root, array('protected-content-shortcode-layout-' . $layout . '-' . $type . '-after.template.php', 'protected-content-shortcode-layout-' . $layout . '-after.template.php', 'protected-content-shortcode-layout-' . $type . '-after.template.php', 'protected-content-shortcode-layout-default-after.template.php')); $item_template = $plugin->get_template_file_path($template_root, array('protected-content-shortcode-layout-' . $layout . '-' . $type . '-item.template.php', 'protected-content-shortcode-layout-' . $layout . '-item.template.php', 'protected-content-shortcode-layout-' . $type . '-item.template.php', 'protected-content-shortcode-layout-default-item.template.php')); ob_start(); include $loop_template; $out = ob_get_contents(); ob_end_clean(); return $out; }
/** * Display a form to move files from the local FTP upload folder */ public function render_ftp_folder_form($post_id) { /** @var CUAR_PrivateFileAddOn $pf_addon */ $pf_addon = $this->plugin->get_addon('private-files'); $ftp_dir = trailingslashit($pf_addon->get_ftp_path()); $ftp_files = array(); if (@file_exists($ftp_dir)) { $file_filter = apply_filters('cuar/private-content/files/ftp-folder-exclusions', array('.htaccess')); $ftp_files = @scandir($ftp_dir); foreach ($ftp_files as $key => $filename) { $file_path = $ftp_dir . '/' . $filename; if (!is_file($file_path) || in_array($filename, $file_filter)) { unset($ftp_files[$key]); } } } $template_suffix = is_admin() ? '-admin' : '-frontend'; $template = $this->plugin->get_template_file_path(CUAR_INCLUDES_DIR . '/core-addons/private-file', array('private-attachments-add-ftp-folder' . $template_suffix . '.template.php', 'private-attachments-add-ftp-folder.template.php'), 'templates'); include $template; }
/** * Get all submenu items corresponding to private content type listing * @return array */ private function get_private_types_menu_items() { if ($this->private_types_items == null) { $this->private_types_items = array(); $types = array('content' => $this->plugin->get_content_types(), 'container' => $this->plugin->get_container_types()); foreach ($types as $t => $private_types) { foreach ($private_types as $type => $desc) { if (!$this->plugin->is_type_managed($type, $private_types)) { continue; } $post_type = get_post_type_object($type); $taxonomies = get_object_taxonomies($post_type->name, 'object'); if (current_user_can($post_type->cap->edit_post) || current_user_can($post_type->cap->read_post)) { $item = array('page_title' => $desc['label-plural'], 'title' => $desc['label-plural'], 'slug' => 'wpca-list,' . $t . ',' . $type, 'capability' => 'view-customer-area-menu'); if (current_user_can($post_type->cap->read_post)) { $item['children'] = array(); $item['children'][] = array('title' => sprintf(__('All %s', 'cuar'), strtolower($desc['label-plural'])), 'slug' => 'list-' . $type, 'href' => admin_url('admin.php?page=wpca-list,' . $t . ',' . $type)); } if (current_user_can($post_type->cap->edit_post)) { $item['children'][] = array('title' => sprintf(__('New %s', 'cuar'), strtolower($desc['label-singular'])), 'slug' => 'new-' . $type, 'href' => admin_url('post-new.php?post_type=' . $type)); } foreach ($taxonomies as $tax_slug => $tax) { if (current_user_can($tax->cap->manage_terms)) { $item['children'][] = array('title' => sprintf(__('Manage %s', 'cuar'), strtolower(__($tax->labels->name, 'cuar'))), 'slug' => 'manage-' . $tax_slug, 'href' => admin_url('edit-tags.php?taxonomy=' . $tax_slug)); } } $this->private_types_items[] = $item; } } } $this->private_types_items = apply_filters('cuar/core/admin/submenu-items?group=private-types', $this->private_types_items); // Sort alphabetically usort($this->private_types_items, function ($a, $b) { return strcmp($a['title'], $b['title']); }); } return $this->private_types_items; }
include_once CUAR_INCLUDES_DIR . '/core-addons/capabilities/capabilities-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/customer-pages/customer-pages-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/status/status-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/user-profile/user-profile-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/shortcodes/shortcodes-addon.class.php'; // Core content types include_once CUAR_INCLUDES_DIR . '/core-addons/private-page/private-page-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/private-file/private-file-addon.class.php'; // Core pages include_once CUAR_INCLUDES_DIR . '/core-addons/customer-home/customer-home-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/customer-dashboard/customer-dashboard-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/customer-account-home/customer-account-home-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/customer-account-edit/customer-account-edit-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/customer-account/customer-account-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/customer-logout/customer-logout-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/customer-private-files-home/customer-private-files-home-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/customer-private-files/customer-private-files-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/customer-private-pages-home/customer-private-pages-home-addon.class.php'; include_once CUAR_INCLUDES_DIR . '/core-addons/customer-private-pages/customer-private-pages-addon.class.php'; // Template functions include_once CUAR_INCLUDES_DIR . '/functions/functions-general.php'; include_once CUAR_INCLUDES_DIR . '/functions/functions-private-content.php'; include_once CUAR_INCLUDES_DIR . '/functions/functions-private-files.php'; // Some hooks for activation, deactivation, ... CUAR_PluginActivationManager::set_delegate(new CUAR_PluginActivation()); register_activation_hook(__FILE__, array('CUAR_PluginActivationManager', 'on_activate')); register_deactivation_hook(__FILE__, array('CUAR_PluginActivationManager', 'on_deactivate')); // Start the plugin! global $cuar_plugin; $cuar_plugin = new CUAR_Plugin(); $cuar_plugin->run();
protected function get_link($author_id) { $cuar_plugin = CUAR_Plugin::get_instance(); $cfp_addon = $cuar_plugin->get_addon('customer-private-files'); return $cfp_addon->get_author_archive_url($author_id); }
</h2> <form method="GET" action="<?php echo admin_url('admin.php'); ?> "> <input type="hidden" name="cuar-do-logs-action" value="1"/> <input type="hidden" name="page" value="<?php echo $_REQUEST['page']; ?> "/> <?php $start_date = isset($_POST['start-date']) ? sanitize_text_field($_POST['start-date']) : ''; $end_date = isset($_POST['end-date']) ? sanitize_text_field($_POST['end-date']) : ''; $logger = CUAR_Plugin::get_instance()->get_logger(); $type_filter = isset($_POST['filter-by-type']) ? $_POST['filter-by-type'] : 0; ?> <?php $logs_table->views(); ?> <br/> <div class="cuar-list-table-filter"> <a class="cuar-filter-toggle"><?php _e('Toggle advanced filters', 'cuar'); ?> </a> <?php $collapse_panel = $logs_table->is_search_active() ? '' : 'display: none;';
/** * Get the type of the file associated to the given post * * @param int $post_id * * @return string|mixed */ function cuar_get_the_file_size($post_id = null, $human = true) { if (!$post_id) { $post_id = get_the_ID(); } if (!$post_id) { return ''; } $cuar_plugin = CUAR_Plugin::get_instance(); $pf_addon = $cuar_plugin->get_addon('private-files'); $size = $pf_addon->get_file_size($post_id); if (false === $size) { return ''; } if ($human) { $size = cuar_format_human_file_size($size); } return apply_filters('cuar/private-content/files/the-size', $size, $post_id); }
/** * Load theme particular scripts */ function cuar_load_theme_scripts() { $cuar_plugin = CUAR_Plugin::get_instance(); $cuar_plugin->enable_library('bootstrap.dropdown'); $cuar_plugin->enable_library('bootstrap.collapse'); }
protected function get_link($term) { $cuar_plugin = CUAR_Plugin::get_instance(); $cfp_addon = $cuar_plugin->get_addon('customer-private-pages'); return $cfp_addon->get_category_archive_url($term); }
protected function get_link($year, $month = 0) { $cuar_plugin = CUAR_Plugin::get_instance(); $cfp_addon = $cuar_plugin->get_addon('customer-private-files'); return $cfp_addon->get_date_archive_url($year, $month); }
/** * Handles remote requests to validate a license */ public static function ajax_validate_license() { $cuar_plugin = CUAR_Plugin::get_instance(); $addon_id = $_POST["addon_id"]; $license = $_POST["license"]; /** @var CUAR_AddOn $addon */ $addon = $cuar_plugin->get_addon($addon_id); $license_key_option_id = $addon->get_license_key_option_name(); $cuar_plugin->update_option($license_key_option_id, $license); $licensing = $cuar_plugin->get_licensing(); $result = $licensing->validate_license($license, $addon); $today = new DateTime(); $license_check_option_id = $addon->get_license_check_option_name(); $cuar_plugin->update_option($license_check_option_id, $today->format('Y-m-d')); $license_status_option_id = $addon->get_license_status_option_name(); $cuar_plugin->update_option($license_status_option_id, $result); echo json_encode($result); exit; }
/** * Returns true if the type of the given post is a private post type of Customer Area * * @param WP_Post|int $post The post/post ID to test * * @return boolean */ function cuar_is_customer_area_private_content($post = null) { $cuar_plugin = CUAR_Plugin::get_instance(); $private_types = array_merge($cuar_plugin->get_content_post_types(), $cuar_plugin->get_container_post_types()); return in_array(get_post_type($post), $private_types); }
/** * Print a list of posts * * @param array $posts The posts */ protected function print_content_list($posts) { $template = CUAR_Plugin::get_instance()->get_template_file_path(CUAR_INCLUDES_DIR . '/core-classes', "widget-content-list-" . $this->id_base . ".template.php", 'templates', "widget-content-list.template.php"); include $template; }
/** * Print the list of terms * * @param array $terms The terms * @param boolean $hide_empty Shall we hide empty terms? */ protected function print_term_list($terms, $hide_empty) { $template = CUAR_Plugin::get_instance()->get_template_file_path(CUAR_INCLUDES_DIR . '/core-classes', "widget-terms-" . $this->id_base . ".template.php", 'templates', "widget-terms.template.php"); include $template; }