예제 #1
0
 /**
  * Table body
  * @param string $column_name
  * @param int $item_id
  */
 public function td($column_name, $item_id)
 {
     if ('mslscol' == $column_name) {
         $blogs = MslsBlogCollection::instance()->get();
         if ($blogs) {
             $mydata = MslsOptions::create($item_id);
             foreach ($blogs as $blog) {
                 switch_to_blog($blog->userblog_id);
                 $language = $blog->get_language();
                 $icon = MslsAdminIcon::create();
                 $icon->set_language($language);
                 if ($mydata->has_value($language)) {
                     $flag_url = MslsOptions::instance()->get_url('images/link_edit.png');
                     $icon->set_href($mydata->{$language})->set_src($flag_url);
                 } else {
                     $flag_url = MslsOptions::instance()->get_url('images/link_add.png');
                     $icon->set_src($flag_url);
                 }
                 echo $icon;
                 // xss ok
                 restore_current_blog();
             }
         }
     }
 }
예제 #2
0
 /**
  * Creates and gets the output as an array
  * @param int $display
  * @param bool $filter
  * @param bool $exists
  * @uses MslsOptions
  * @uses MslsLink
  * @return array
  */
 public function get($display, $filter = false, $exists = false)
 {
     $arr = array();
     $blogs = MslsBlogCollection::instance()->get_filtered($filter);
     if ($blogs) {
         $mydata = MslsOptions::create();
         $link = MslsLink::create($display);
         foreach ($blogs as $blog) {
             $language = $blog->get_language();
             $url = $mydata->get_current_link();
             $current = $blog->userblog_id == MslsBlogCollection::instance()->get_current_blog_id();
             if ($current) {
                 $link->txt = $blog->get_description();
             } else {
                 switch_to_blog($blog->userblog_id);
                 if ($this->is_requirements_not_fulfilled($mydata, $exists, $language)) {
                     restore_current_blog();
                     continue;
                 } else {
                     $url = $mydata->get_permalink($language);
                     $link->txt = $blog->get_description();
                 }
                 restore_current_blog();
             }
             $link->src = MslsOptions::instance()->get_flag_url($language);
             $link->alt = $language;
             if (has_filter('msls_output_get')) {
                 /**
                  * Returns HTML-link for an item of the output-arr
                  * @since 0.9.8
                  * @param string $url
                  * @param MslsLink $link
                  * @param bool current
                  */
                 $arr[] = (string) apply_filters('msls_output_get', $url, $link, $current);
             } else {
                 $arr[] = sprintf('<a href="%s" title="%s"%s>%s</a>', $url, $link->txt, $current ? ' class="current_language"' : '', $link);
             }
         }
     }
     return $arr;
 }
 /**
  * Execute filter. Exclude translated posts from WP_Query
  * @param WP_Query $query
  * @return false or WP_Query object
  */
 public function execute_filter(WP_Query $query)
 {
     $blogs = MslsBlogCollection::instance()->get();
     if (!filter_has_var(INPUT_GET, 'msls_filter')) {
         return false;
     }
     $id = filter_input(INPUT_GET, 'msls_filter', FILTER_SANITIZE_NUMBER_INT);
     if (isset($blogs[$id])) {
         $cache = MslsSqlCacher::init(__CLASS__)->set_params(__METHOD__);
         // load post we need to exclude (already have translation) from search query
         $posts = $cache->get_results($cache->prepare("SELECT option_id, option_name FROM {$cache->options} WHERE option_name LIKE %s AND option_value LIKE %s", 'msls_%', '%"' . $blogs[$id]->get_language() . '"%'));
         $exclude_ids = array();
         foreach ($posts as $post) {
             $exclude_ids[] = substr($post->option_name, 5);
         }
         $query->query_vars['post__not_in'] = $exclude_ids;
         return $query;
     }
     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)
 {
     $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;
 }
 /**
  * Help searchengines to index and to serve the localized version with
  * rel="alternate"-links in the html-header
  */
 function msls_head()
 {
     $blogs = MslsBlogCollection::instance();
     $mydata = MslsOptions::create();
     foreach ($blogs->get_objects() as $blog) {
         $language = $blog->get_language();
         $url = $mydata->get_current_link();
         $current = $blog->userblog_id == MslsBlogCollection::instance()->get_current_blog_id();
         $title = $blog->get_description();
         if (!$current) {
             switch_to_blog($blog->userblog_id);
             if ('MslsOptions' != get_class($mydata) && (is_null($mydata) || !$mydata->has_value($language))) {
                 restore_current_blog();
                 continue;
             }
             $url = $mydata->get_permalink($language);
             $title = $blog->get_description();
             restore_current_blog();
         }
         if (has_filter('msls_head_hreflang')) {
             /**
              * Overrides the hreflang value
              * @since 0.9.9
              * @param string $language
              */
             $hreflang = (string) apply_filters('msls_head_hreflang', $language);
         } else {
             $hreflang = $blog->get_alpha2();
         }
         printf('<link rel="alternate" hreflang="%s" href="%s" title="%s" />', $hreflang, $url, esc_attr($title));
         echo "\n";
     }
 }
 /**
  * Save
  * @param int $object_id
  * @param string $class
  * @codeCoverageIgnore
  */
 protected function save($object_id, $class)
 {
     if (has_action('msls_main_save')) {
         /**
          * Calls completely customized save-routine
          * @since 0.9.9
          * @param int $object_id
          * @param string Classname
          */
         do_action('msls_main_save', $object_id, $class);
     } else {
         $blogs = MslsBlogCollection::instance();
         $language = $blogs->get_current_blog()->get_language();
         $msla = new MslsLanguageArray($this->get_input_array($object_id));
         $options = new $class($object_id);
         $temp = $options->get_arr();
         if (0 != $msla->get_val($language)) {
             $options->save($msla->get_arr($language));
         } else {
             $options->delete();
         }
         foreach ($blogs->get() as $blog) {
             switch_to_blog($blog->userblog_id);
             $language = $blog->get_language();
             $larr_id = $msla->get_val($language);
             if (0 != $larr_id) {
                 $options = new $class($larr_id);
                 $options->save($msla->get_arr($language));
             } elseif (isset($temp[$language])) {
                 $options = new $class($temp[$language]);
                 $options->delete();
             }
             restore_current_blog();
         }
     }
 }
    /**
     * Render the suggest input-field
     */
    public function render_input()
    {
        $blogs = MslsBlogCollection::instance()->get();
        if ($blogs) {
            global $post;
            $post_type = get_post_type($post->ID);
            $my_data = new MslsOptionsPost($post->ID);
            $temp = $post;
            $items = '';
            wp_nonce_field(MSLS_PLUGIN_PATH, 'msls_noncename');
            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)) {
                    $icon->set_href($my_data->{$language});
                    $value = $my_data->{$language};
                    $title = get_the_title($value);
                }
                $items .= sprintf('<li>
					<label for="msls_title_%1$s">%2$s</label>
					<input type="hidden" id="msls_id_%1$s" name="msls_input_%3$s" value="%4$s"/>
					<input class="msls_title" id="msls_title_%1$s" name="msls_title_%1$s" type="text" value="%5$s"/>
					</li>', $blog->userblog_id, $icon, $language, $value, $title);
                restore_current_blog();
            }
            printf('<ul>%s</ul>
				<input type="hidden" name="msls_post_type" id="msls_post_type" value="%s"/>
				<input type="hidden" name="msls_action" id="msls_action" value="suggest_posts"/>
				<input type="submit" class="button-secondary clear" value="%s"/>', $items, $post_type, __('Update', 'msls'));
            $post = $temp;
        } else {
            printf('<p>%s</p>', __('You should define at least another blog in a different language in order to have some benefit from this plugin!', 'msls'));
        }
    }
 /**
  * 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;
 }
 /**
  * Shows the select-form-field 'reference_user'
  */
 public function reference_user()
 {
     $users = array();
     foreach (MslsBlogCollection::instance()->get_users() as $user) {
         $users[$user->ID] = $user->user_nicename;
     }
     echo $this->render_select('reference_user', $users, MslsOptions::instance()->reference_user);
     // xss ok
 }
 /**
  * Verify the instance-method
  */
 function test_instance_method()
 {
     $obj = MslsBlogCollection::instance();
     $this->assertInstanceOf('MslsBlogCollection', $obj);
     return $obj;
 }
/*
 * Get Prefered language of the browser
 */
if (!isset($lang)) {
    $acceptedLanguages = filter_var($_SERVER['HTTP_ACCEPT_LANGUAGE'], FILTER_SANITIZE_STRING);
    $lang = explode(',', $acceptedLanguages);
    $lang = strtolower(substr(chop($lang[0]), 0, 2));
}
if (!isset($req)) {
    $req = filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_STRING);
}
/**
 * List of the sites URL by languages
 */
$sites = array();
foreach (MslsBlogCollection::instance()->get_objects() as $key => $blog) {
    if (get_blog_details()->blog_id != $key) {
        $lg = $blog->get_alpha2();
        if (isset($sites[$lg])) {
            echo 'Language ' . $lg . ' has multiples solutions, please fix that';
            exit;
        }
        $sites[$lg] = get_blog_details($key)->path;
    }
}
/**
 * Run redirection
 * 
 * @param string $lang		Current language
 * @param string $req		Current path
 * @param array $sites		List of others sites
예제 #12
0
 private static function get_obj_info($obj, $kp)
 {
     $cache = isset(self::$results_cache[$obj->ID]) || array_key_exists($obj->ID, self::$results_cache) ? self::$results_cache[$obj->ID] : false;
     if (!$cache) {
         //if($kp!==0 ){echo "Non cachato".d($obj).d($kp).d(self::$results_cache[$obj->ID]).d(self::$results_cache).'!!!';}
         $result = array();
         $result["title"] = $obj->post_title;
         $result["permalink"] = get_permalink($obj->ID);
         $result["content"] = wpautop($obj->post_content, true);
         $result["thumbnail"] = get_the_post_thumbnail($obj->ID);
         $result["fields"] = get_fields($obj->ID);
         $result["lang"] = array();
         $object2 = new MslsOptionsPost($obj->ID);
         $blogs = MslsBlogCollection::instance();
         foreach ($blogs->get() as $blog) {
             $blog_id = $blog->userblog_id;
             $title = $blog->get_language();
             $langname = $blog->get_description();
             $url = $object2->get_postlink($title);
             $current = $blog_id == MslsBlogCollection::instance()->get_current_blog_id();
             if (!$current) {
                 switch_to_blog($blog_id);
                 $url = $object2->get_postlink($title);
                 restore_current_blog();
             }
             if ('en_GB' == $title) {
                 $url = str_replace('/prodotti/', '/products/', $url);
                 $url = str_replace('/area-skin-care/', '/skin-care-area/', $url);
                 $url = str_replace('/linee/', '/lines/', $url);
             } elseif ('it_IT' == $title) {
                 $url = str_replace('/products/', '/prodotti/', $url);
                 $url = str_replace('/skin-care-area/', '/area-skin-care/', $url);
                 $url = str_replace('/lines/', '/linee/', $url);
             }
             $result["lang"][$langname] = $url;
         }
         /*
             $object  = new MslsOutput();
         $display = 1;
         $exists  = false;
         
         foreach ( $object->get( $display, $exists ) as $link ) {
          $a = new SimpleXMLElement($link);
          $title=(string)$a['title'];
          $href=(string)$a['href'];
         $result["lang"][$title]=$href;
         
         }
         */
         self::$results_cache[$obj->ID] = $result;
         if ($kp === 0) {
             if (!isset(self::$results_cache['linee'])) {
                 self::$results_cache['inverse'] = array();
             }
             self::$results_cache['linee'][$obj->ID] = $obj;
         }
         return $result;
     } else {
         return $cache;
     }
 }