/** * 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(); } } } }
/** * Prints options inputs * @uses selected * @param MslsBlog $blog * @param string $type * @param MslsOptionsTax $mydata * @param string $item_format */ public function print_option(MslsBlog $blog, $type, MslsOptionsTax $mydata, $item_format) { 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); $options = ''; $terms = get_terms($type, array('hide_empty' => 0)); if ($mydata->has_value($language)) { $icon->set_href($mydata->{$language}); } if (!empty($terms)) { foreach ($terms as $term) { $options .= sprintf('<option value="%s" %s>%s</option>', $term->term_id, selected($term->term_id, $mydata->{$language}, false), $term->name); } } printf($item_format, $language, $icon, $options); 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; }
/** * Verify the create-method */ function test_create_method() { $obj = MslsAdminIcon::create(); $this->assertInstanceOf('MslsAdminIcon', $obj); return $obj; }