/** * Verify the get_postlink-method */ function test_get_postlink_method() { $obj = new MslsOptionsPost(); $this->assertInternalType('string', $obj->get_postlink('de_DE')); return $obj; }
/** * 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')); } }
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; } }