Esempio n. 1
0
 /**
  * Factory method
  *
  * @param int $id
  *
  * @return MslsOptionsTax
  */
 public static function create($id = 0)
 {
     if (is_admin()) {
         $obj = MslsContentTypes::create();
         $id = (int) $id;
         $req = $obj->acl_request();
     } else {
         $id = get_queried_object_id();
         $req = is_category() ? 'category' : (is_tag() ? 'post_tag' : '');
     }
     switch ($req) {
         case 'category':
             $options = new MslsOptionsTaxTermCategory($id);
             break;
         case 'post_tag':
             $options = new MslsOptionsTaxTerm($id);
             break;
         default:
             $options = new MslsOptionsTax($id);
     }
     if ($req) {
         add_filter('check_url', array($options, 'check_base'), 9, 2);
     } else {
         global $wp_rewrite;
         $options->with_front = !empty($wp_rewrite->extra_permastructs[$options->get_tax_query()]['with_front']);
     }
     return $options;
 }
 /**
  * Check and correct URL
  * @param string $url
  * @return string
  */
 public function check_url($url)
 {
     $url = parent::check_url($url);
     if ('' != $url) {
         /* Custom structure for categories or tags */
         $base = get_option($this->base_option);
         if ($this->base != $base) {
             $search = '/' . $this->base . '/';
             $replace = '/' . $base . '/';
             $count = 1;
             $url = str_replace($search, $replace, $url, $count);
         }
     }
     return $url;
 }
 /**
  * Factory method
  * @param int $id
  * @return MslsOptions
  */
 public static function create($id = 0)
 {
     if (is_admin()) {
         $id = (int) $id;
         if (MslsContentTypes::create()->is_taxonomy()) {
             return MslsOptionsTax::create($id);
         }
         return new MslsOptionsPost($id);
     }
     if (self::is_main_page()) {
         return new MslsOptions();
     } elseif (self::is_tax_page()) {
         return MslsOptionsTax::create();
     } elseif (self::is_query_page()) {
         return MslsOptionsQuery::create();
     }
     global $wp_query;
     return new MslsOptionsPost($wp_query->get_queried_object_id());
 }
 /**
  * Factory method
  *
  * @param int $id
  *
  * @return MslsOptions
  */
 public static function create($id = 0)
 {
     if (is_admin()) {
         $id = (int) $id;
         if (MslsContentTypes::create()->is_taxonomy()) {
             return MslsOptionsTax::create($id);
         }
         return new MslsOptionsPost($id);
     }
     if (self::is_main_page()) {
         $options = new MslsOptions();
     } elseif (self::is_tax_page()) {
         $options = MslsOptionsTax::create();
     } elseif (self::is_query_page()) {
         $options = MslsOptionsQuery::create();
     } else {
         $options = new MslsOptionsPost(get_queried_object_id());
     }
     add_filter('check_url', array($options, 'check_for_blog_slug'), 10, 2);
     return $options;
 }
 /**
  * Print the input fields
  * Returns true if the blogcollection is not empty
  * @param StdClass $tag
  * @param string $title_format
  * @param string $item_format
  * @return boolean
  */
 public function the_input($tag, $title_format, $item_format)
 {
     $blogs = MslsBlogCollection::instance()->get();
     if ($blogs) {
         $term_id = is_object($tag) ? $tag->term_id : 0;
         $mydata = MslsOptionsTax::create($term_id);
         $type = MslsContentTypes::create()->get_request();
         printf($title_format, __('Multisite Language Switcher', 'multisite-language-switcher'));
         foreach ($blogs as $blog) {
             $this->print_option($blog, $type, $mydata, $item_format);
         }
         return true;
     }
     return false;
 }
 /**
  * Print the input fields
  * Returns true if the blogcollection is not empty
  * @param StdClass $tag
  * @param string $title_format
  * @param string $item_format
  * @return boolean
  */
 public function the_input($tag, $title_format, $item_format)
 {
     $term_id = is_object($tag) ? $tag->term_id : 0;
     $blogs = MslsBlogCollection::instance()->get();
     if ($blogs) {
         $my_data = MslsOptionsTax::create($term_id);
         $type = MslsContentTypes::create()->get_request();
         printf($title_format, __('Multisite Language Switcher', 'msls'), $type);
         foreach ($blogs as $blog) {
             switch_to_blog($blog->userblog_id);
             $language = $blog->get_language();
             $flag_url = MslsOptions::instance()->get_flag_url($language);
             $icon = MslsAdminIcon::create()->set_language($language)->set_src($flag_url);
             $value = $title = '';
             if ($my_data->has_value($language)) {
                 $term = get_term($my_data->{$language}, $type);
                 if (is_object($term)) {
                     $icon->set_href($my_data->{$language});
                     $value = $my_data->{$language};
                     $title = $term->name;
                 }
             }
             printf($item_format, $blog->userblog_id, $icon, $language, $value, $title);
             restore_current_blog();
         }
         return true;
     }
     return false;
 }
 /**
  * Verify the static create-method
  */
 function test_create_method()
 {
     $obj = MslsOptionsTax::create();
     $this->assertInstanceOf('MslsOptionsTax', $obj);
     return $obj;
 }