コード例 #1
0
 /**
  * Static function for plugin activation.
  *
  * @return void
  */
 public function do_activate()
 {
     global $wp_version;
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     // Check for capability
     if (!current_user_can('activate_plugins')) {
         wp_die(__('Sorry, you do not have suffient permissions to activate this plugin.', MP_DOMAIN));
     }
     // Get the capabilities for the administrator
     $role = get_role('administrator');
     // Must have admin privileges in order to activate.
     if (empty($role)) {
         wp_die(__('Sorry, you must be an Administrator in order to use Manga+Press', MP_DOMAIN));
     }
     if (version_compare($wp_version, '3.0', '<=')) {
         wp_die('Sorry, only WordPress 3.0 and later are supported.' . ' Please upgrade to WordPress 3.0', 'Wrong Version');
     }
     self::$_version = strval(get_option('mangapress_ver'));
     // version_compare will still evaluate against an empty string
     // so we have to tell it not to.
     if (version_compare(self::$_version, MP_VERSION, '<') && !(self::$_version == '')) {
         add_option('mangapress_upgrade', 'yes', '', 'no');
     } elseif (self::$_version == '') {
         add_option('mangapress_ver', MP_VERSION, '', 'no');
         add_option('mangapress_options', serialize(MangaPress_Options::get_default_options()), '', 'no');
     }
     $this->_bootstrap = MangaPress_Bootstrap::get_instance();
     $this->_bootstrap->init();
     $this->after_plugin_activation();
     flush_rewrite_rules(false);
 }
コード例 #2
0
ファイル: functions.php プロジェクト: jesgs/mangapress
/**
* Create a date-archive permalink for Comics
*
* @param string $daylink Existing link to be modified or replaced
* @param string $year Year
* @param string $month Month
* @param string $day Day
*
* @return string
*/
function mangapress_day_link($daylink, $year = '', $month = '', $day = '')
{
    $posts = MangaPress_Bootstrap::get_instance()->get_helper('posts');
    $slug = $posts->get_slug();
    $relative = "/{$slug}/{$year}/{$month}/{$day}";
    $day_permalink = home_url($relative);
    return $day_permalink;
}
コード例 #3
0
ファイル: mangapress.php プロジェクト: jesgs/mangapress
 /**
  * Get instance of MangaPress_Bootstrap
  *
  * @return MangaPress_Bootstrap
  */
 public static function get_instance()
 {
     if (null == self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
コード例 #4
0
/**
 * mangapress_comic_navigation()
 *
 * Displays navigation for post specified by $post_id.
 *
 * @since 0.1b
 *
 * @global object $wpdb
 *
 * @param array $args Arguments for navigation output
 * @param bool $echo Specifies whether to echo comic navigation or return it as a string
 * @return string Returns navigation string if $echo is set to false.
 */
function mangapress_comic_navigation($args = array(), $echo = true)
{
    global $post;
    $mp_options = MangaPress_Bootstrap::get_instance()->get_options();
    $defaults = array('container' => 'nav', 'container_attr' => array('id' => 'comic-navigation', 'class' => 'comic-nav-hlist-wrapper'), 'items_wrap' => '<ul%1$s>%2$s</ul>', 'items_wrap_attr' => array('class' => 'comic-nav-hlist'), 'link_wrap' => 'li', 'link_before' => '', 'link_after' => '');
    $parsed_args = wp_parse_args($args, $defaults);
    $r = apply_filters('mangapress_comic_navigation_args', $parsed_args);
    $args = (object) $r;
    $group = (bool) $mp_options['basic']['group_comics'];
    $by_parent = (bool) $mp_options['basic']['group_by_parent'];
    $next_post = mangapress_get_adjacent_comic($group, $by_parent, 'mangapress_series', false, false);
    $prev_post = mangapress_get_adjacent_comic($group, $by_parent, 'mangapress_series', false, true);
    add_filter('pre_get_posts', '_mangapress_set_post_type_for_boundary');
    $last_post = mangapress_get_boundary_comic($group, $by_parent, 'mangapress_series', false, false);
    $first_post = mangapress_get_boundary_comic($group, $by_parent, 'mangapress_series', false, true);
    remove_filter('pre_get_posts', '_mangapress_set_post_type_for_boundary');
    $current_page = $post->ID;
    // use post ID this time.
    $next_page = !isset($next_post->ID) ? $current_page : $next_post->ID;
    $prev_page = !isset($prev_post->ID) ? $current_page : $prev_post->ID;
    $last = !isset($last_post[0]->ID) ? $current_page : $last_post[0]->ID;
    $first = !isset($first_post[0]->ID) ? $current_page : $first_post[0]->ID;
    $first_url = get_permalink($first);
    $last_url = get_permalink($last);
    $next_url = get_permalink($next_page);
    $prev_url = get_permalink($prev_page);
    $show_container = false;
    $comic_nav = "";
    if ($args->container) {
        $show_container = true;
        $attr = "";
        if (!empty($args->container_attr)) {
            $attr_arr = array();
            foreach ($args->container_attr as $name => $value) {
                $attr_arr[] = "{$name}=\"" . esc_attr($value) . "\"";
            }
            $attr = " " . implode(" ", $attr_arr);
        }
        $comic_nav .= "<{$args->container}{$attr}>";
    }
    $items_wrap_attr = "";
    if (!empty($args->items_wrap_attr)) {
        $items_attr_arr = array();
        foreach ($args->items_wrap_attr as $name => $value) {
            $items_attr_arr[] = "{$name}=\"" . esc_attr($value) . "\"";
        }
        $items_wrap_attr = " " . implode(" ", $items_attr_arr);
    }
    $items = array();
    // Here, we start processing the urls.
    // Let's do first page first.
    $first_html = "<{$args->link_wrap} class=\"link-first\">" . ($first == $current_page ? '<span class="comic-nav-span">' . __('First', MP_DOMAIN) . '</span>' : '<a href="' . $first_url . '">' . __('First', MP_DOMAIN) . '</a>') . "</{$args->link_wrap}>";
    $last_html = "<{$args->link_wrap} class=\"link-last\">" . ($last == $current_page ? '<span class="comic-nav-span">' . __('Last', MP_DOMAIN) . '</span>' : '<a href="' . $last_url . '">' . __('Last', MP_DOMAIN) . '</a>') . "</{$args->link_wrap}>";
    $next_html = "<{$args->link_wrap} class=\"link-next\">" . ($next_page == $current_page ? '<span class="comic-nav-span">' . __('Next', MP_DOMAIN) . '</span>' : '<a href="' . $next_url . '">' . __('Next', MP_DOMAIN) . '</a>') . "</{$args->link_wrap}>";
    $prev_html = "<{$args->link_wrap} class=\"link-prev\">" . ($prev_page == $current_page ? '<span class="comic-nav-span">' . __('Prev', MP_DOMAIN) . '</span>' : '<a href="' . $prev_url . '">' . __('Prev', MP_DOMAIN) . '</a>') . "</{$args->link_wrap}>";
    $items['first'] = apply_filters('mangapress_comic_navigation_first', $first_html, $args);
    $items['prev'] = apply_filters('mangapress_comic_navigation_prev', $prev_html, $args);
    $items['next'] = apply_filters('mangapress_comic_navigation_next', $next_html, $args);
    $items['last'] = apply_filters('mangapress_comic_navigation_last', $last_html, $args);
    $items_str = implode(" ", apply_filters('mangapress_comic_navigation_items', $items, $args));
    $comic_nav .= sprintf($args->items_wrap, $items_wrap_attr, $items_str);
    if ($show_container) {
        $comic_nav .= "</{$args->container}>";
    }
    if ($echo) {
        echo $comic_nav;
    } else {
        return $comic_nav;
    }
}
コード例 #5
0
 /**
  * Sanitize options
  * 
  * @param array $options
  * @return array
  */
 public function sanitize_options($options)
 {
     if (!$options) {
         return $options;
     }
     $mp_options = MangaPress_Bootstrap::get_instance()->get_options();
     $section = key($options);
     $available_options = $this->options_fields();
     $new_options = $mp_options;
     if ($section == 'nav') {
         $new_options['nav']['insert_nav'] = intval($options['nav']['insert_nav']);
         //
         // if the value of the option doesn't match the correct values in the array, then
         // the value of the option is set to its default.
         $nav_css_values = array_keys($available_options['nav']['nav_css']['value']);
         if (in_array($mp_options['nav']['nav_css'], $nav_css_values)) {
             $new_options['nav']['nav_css'] = strval($options['nav']['nav_css']);
         } else {
             $new_options['nav']['nav_css'] = 'default_css';
         }
     }
     if ($section == 'basic') {
         //
         // Converting the values to their correct data-types should be enough for now...
         $new_options['basic'] = array('group_comics' => $this->_sanitize_integer($options, 'basic', 'group_comics'), 'group_by_parent' => $this->_sanitize_integer($options, 'basic', 'group_by_parent'));
         if ($options['basic']['latestcomic_page'] !== 'no_val') {
             $new_options['basic']['latestcomic_page'] = $options['basic']['latestcomic_page'];
         } else {
             $new_options['basic']['latestcomic_page'] = 0;
         }
         $new_options['basic']['latestcomic_page_template'] = $this->_sanitize_integer($options, 'basic', 'latestcomic_page_template');
         if ($options['basic']['comicarchive_page'] !== 'no_val') {
             $new_options['basic']['comicarchive_page'] = $options['basic']['comicarchive_page'];
         } else {
             $new_options['basic']['comicarchive_page'] = 0;
         }
         // damned checkboxes...fffuuuu
         $new_options['basic']['comicarchive_page_template'] = $this->_sanitize_integer($options, 'basic', 'comicarchive_page_template');
         flush_rewrite_rules(false);
     }
     if ($section == 'comic_page') {
         $new_options['comic_page'] = array('generate_comic_page' => $this->_sanitize_integer($options, 'comic_page', 'generate_comic_page'), 'comic_page_width' => $this->_sanitize_integer($options, 'comic_page', 'comic_page_width'), 'comic_page_height' => $this->_sanitize_integer($options, 'comic_page', 'comic_page_height'));
     }
     return array_merge($mp_options, $new_options);
 }
コード例 #6
0
ファイル: mangapress-admin.php プロジェクト: jesgs/mangapress
 /**
  * Create options page tabs
  *
  * @return string
  */
 public function get_current_tab()
 {
     $options = MangaPress_Bootstrap::get_instance()->get_helper('options');
     $tabs = $options->get_options_sections();
     $current_tab = filter_input(INPUT_GET, 'tab');
     if (in_array($current_tab, $tabs)) {
         return $current_tab;
     } else {
         return 'basic';
     }
 }
コード例 #7
0
 /**
  * Set MangaPress options. This method should run every time
  * MangaPress options are updated.
  *
  * @uses init()
  * @see MangaPress_Bootstrap::init()
  *
  * @return void
  */
 public static function set_options()
 {
     self::$_options = maybe_unserialize(get_option('mangapress_options'));
 }