/** * Constructor */ public function __construct() { // default themes path and URL $this->default_themes_path = fa_get_path('themes'); $this->default_themes_url = fa_get_uri('themes'); // extra themes path and URL $option = fa_get_options('settings'); $rel_path = isset($option['themes_dir']) ? $option['themes_dir'] : false; if ($rel_path) { $path = wp_normalize_path(path_join(WP_CONTENT_DIR, $rel_path)); if ($path != $this->default_themes_path && is_dir($path)) { $this->extra_themes_path = $path; $this->extra_themes_url = (is_ssl() ? str_replace('http://', 'https://', WP_CONTENT_URL) : WP_CONTENT_URL) . '/' . $rel_path; } } }
/** * Displays the slider. If $echo, it will output the contents * * @param bool $echo */ public function display($echo = true) { if (!$this->slider || !$this->slides && fa_is_preview()) { return; } $theme = $this->options['theme']; $theme_file = $theme['details']['display']; if (!file_exists($theme_file)) { // trigger error just for admins if (current_user_can('manage_options')) { trigger_error(sprintf(__('Slider theme <strong>%s</strong> display file could not be found.', 'fapro'), $theme['details']['theme_config']['name'])); } return; } // make ssl friendly theme URL if (is_ssl()) { $theme['details']['url'] = str_replace('http://', 'https://', $theme['details']['url']); } // load minified stylesheet $suffix = defined('FA_CSS_DEBUG') && FA_CSS_DEBUG ? '' : '.min'; wp_enqueue_style('fa-theme-' . $theme['active'], path_join($theme['details']['url'], 'stylesheet' . $suffix . '.css'), false, FA_VERSION); if (isset($theme['details']['theme_config']['stylesheets'])) { $extra_styles = (array) $theme['details']['theme_config']['stylesheets']; /** * Filter that can be used in themes to prevent FontAwesome from being loaded * if the theme already uses it. * @var bool */ $allow_fa = apply_filters('fa-load-font-awesome-css', true); // prevent Font Awesome to be loaded if set by the user in admin area $options = fa_get_options('settings'); if (isset($options['load_font_awesome']) && !$options['load_font_awesome']) { $allow_fa = false; } // enqueue font awesome if specified by the theme settings if ($allow_fa && isset($extra_styles['font-awesome']) && $extra_styles['font-awesome']) { // enqueue font awesome only if specified by the theme settings wp_enqueue_style('font-awesome', (is_ssl() ? 'https://' : 'http://') . 'maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css', array(), FA_VERSION); } } if (!empty($this->options['theme']['color'])) { wp_enqueue_style('fa-theme-' . $theme['active'] . '-' . $theme['color'], path_join($theme['details']['url'], 'colors/' . str_replace('.min', '', $theme['color']) . '.css'), array('fa-theme-' . $theme['active']), FA_VERSION); } /** * Theme starter dependencies */ $dependencies = array('jquery'); // when debug is on, load each individual .dev file if (defined('FA_SCRIPT_DEBUG') && FA_SCRIPT_DEBUG) { $dependencies[] = fa_load_script('slider'); $dependencies[] = fa_load_script('jquery-mobile'); $dependencies[] = fa_load_script('jquery-transit'); } else { // load only the minified file containing all scripts $dependencies[] = fa_load_script('_scripts.min'); } // load theme starter $suffix = defined('FA_SCRIPT_DEBUG') && FA_SCRIPT_DEBUG ? '.dev' : '.min'; wp_enqueue_script('fa-theme-' . $theme['active'] . '-starter', path_join($theme['details']['url'], 'starter' . $suffix . '.js'), $dependencies, FA_VERSION, true); global $slider_id, $fa_slider; // global $post $slider_id = $this->slider->ID; /** * Set the global $fa_slider variable that will be used * in templating functions and other functions. * * @var object - the post object of the current slider */ $fa_slider = $this->slider; // store the posts on the slider global variable $fa_slider->slides = $this->slides; // set the current to 0 $fa_slider->current_slide = -1; // set the number of slides $fa_slider->slide_count = count($this->slides); // include the templating functions include_once fa_get_path('includes/templating.php'); // capture the output ob_start(); include $theme_file; $output = ob_get_clean(); // include some cache stats on previews if (fa_is_preview() || current_user_can('manage_options')) { $output .= '<!-- Slider generated in ' . number_format(microtime(true) - $this->timer_start, 5) . ' seconds -->'; } // show the edit link on slider output if (current_user_can('edit_fa_items', $this->slider->ID)) { $settings = fa_get_options('settings'); $show = (bool) $settings['edit_links']; /** * Show slider edit link in front-end output. * * @var bool - if callback returns false, edit link will be hidden * @var slider_id - id of slider */ $show = apply_filters('fa_show_slider_edit_link', $show, $this->slider->ID); if ($show) { $edit_link = get_edit_post_link($this->slider->ID); $output .= sprintf('<a href="%s" title="%s">%s</a>', $edit_link, esc_attr(__('Edit slider', 'fapro')), __('Edit slider', 'fapro')); } } if ($echo) { echo $output; } return $output; }
/** * Retrieves the images attached to a slider that are used to * create the slides. Used when slides are made of manually * selected images * * @param $post_id - slider ID */ function fa_get_slider_images($post_id) { $settings = fa_get_options('settings'); $slider_options = fa_get_slider_options($post_id, 'slides'); $image_ids = (array) $slider_options['images']; if (!$image_ids) { return; } $args = array('posts_per_page' => -1, 'nopaging' => true, 'ignore_sticky_posts' => true, 'offset' => 0, 'post__in' => $image_ids, 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => 'image'); $query = new WP_Query($args); $images = $query->get_posts(); $result = array(); foreach ($image_ids as $image_id) { foreach ($images as $image) { if ($image_id == $image->ID) { $result[] = $image; break; } } } return $result; }
/** * Outputs styling of current slider * @param bool $echo */ function the_slider_styles($echo = true) { $output = the_slider_margin(false); $output .= the_slider_horizontal_align(false); $output .= the_slider_font_size(false); $settings = fa_get_options('settings'); if ($settings['preload_sliders']) { $output .= the_slider_width(); $output .= the_slider_height(); } if ($echo) { echo $output; } return $output; }
/** * Assign sliders to dynamic areas */ public function slider_to_area() { $action = $this->get_action_data('assign_to_area'); check_ajax_referer($action['nonce']['action'], $action['nonce']['name']); if (!current_user_can('edit_fa_items')) { wp_die(-1); } if (!isset($_POST['areas'])) { wp_die(-1); } $settings = fa_get_options('hooks'); foreach ($_POST['areas'] as $area => $sliders) { // if area isn't found in stored areas, skip it if (!array_key_exists($area, $settings)) { continue; } $result = array(); // empty the area if nothing is set if (empty($sliders)) { $settigs[$area]['sliders'] = $result; } $sliders = explode(',', $sliders); foreach ($sliders as $slider) { $slider_id = absint(str_replace('fa_slider-', '', $slider)); $result[] = $slider_id; } $settings[$area]['sliders'] = $result; } fa_update_options('hooks', $settings); die; }
/** * Check if user has set the external directory for slider themes. */ function fa_is_extra_dir_set() { $options = fa_get_options('settings'); if (isset($options['themes_dir']) && !empty($options['themes_dir'])) { return true; } return false; }
/** * Set sliders that should auto display on hooks */ private function store_auto_displays() { if ($this->auto_display) { $option = fa_get_options('hooks'); foreach ($this->auto_display as $hook => $sliders) { if (array_key_exists($hook, $option)) { $option[$hook]['sliders'] = $sliders; } } fa_update_options('hooks', $option); } }
/** * Plugin activation hook callback function */ public function on_activation() { // give full access to administrators on plugin activation parent::set_capabilities(); $this->allow_admins(); // get the current option $option = fa_get_options('plugin_details'); // set the current plugin details $plugin_details = array('version' => FA_VERSION, 'wp_version' => get_bloginfo('version'), 'activated_on' => current_time('mysql')); /** * Action on plugin activation that allows maintenance related actions. * * @param $option - current option stored in plugin settings * @param $plugin_details - the new option that is going to be saved */ do_action('fa_pro_activation', $option, $plugin_details); // update the option fa_update_options('plugin_details', $plugin_details); // pre 3.0 plugin options verification $old_options = get_option('fa_plugin_details', array()); $updated = fa_get_options('updated'); if ($old_options && !version_compare($updated['to'], '3.0', '>=')) { $this->on_init(); include_once fa_get_path('includes/libs/class-fa-update.php'); new FA_Update(); // flag plugin as updated to prevent update from running again if previous plugin version reactivated fa_update_options('updated', array('from' => $old_options['version'], 'to' => FA_VERSION)); } }
/** * Plugin settings admin page */ public function page_settings() { // get user roles global $wp_roles; $roles = $wp_roles->get_names(); // remove administrator and subscriber unset($roles['administrator'], $roles['subscriber']); // get the plugin settings $settings = fa_get_options('settings'); // load the template $template = fa_template_path('settings'); include_once $template; }