function test_extract_jpeg_images_with_redirection() { $html = '<html><body><img src="http://ocafe.appspot.com/?redirect=true"/></body></html>'; $images = p2mixi_extract_jpeg_images($html, 1); // Assert::equals( count ($images['images']), 1, ''); Assert::equals(strlen($images['images'][0]), 5221, ''); }
/** * Publishes the wordpress entry to mixi. * * @param number $postId * @return postId */ function p2mixi_publish_handler($postId) { global $p2mixi_debug; $p2mixi_username = get_option('p2mixi_username'); $p2mixi_password = get_option('p2mixi_password'); $p2mixi_id = get_option('p2mixi_id'); $p2mixi_default = get_option('p2mixi_default'); $p2mixi_header_default = get_option('p2mixi_header_default'); $p2mixi_footer_default = get_option('p2mixi_footer_default'); $header = ""; $footer = ""; // If the post was published from the wordpress admin page. if (p2mixi_is_submitted_from_wp_admin($_POST) == true) { // verify this came from the our screen and with proper authorization, // because publish_post can be triggered at other times if (!wp_verify_nonce($_POST['p2mixi_noncename'], plugin_basename(__FILE__))) { return $post_id; } if ($_POST['p2mixi_publishcheckbox'] == null || $_POST['p2mixi_publishcheckbox'] == 'false') { return $postId; } $header = trim($_POST['p2mixi_headertext']); $footer = trim($_POST['p2mixi_footertext']); } else { // If the post was published not from the wordpress admin page // such as iphone application, user doesn't see the publishToMixi option. // If that's the case, publishToMixi just follows the default configuration. if ($p2mixi_default == false) { return $postId; } $header = $p2mixi_header_default; $footer = $p2mixi_footer_default; } // Get the post detail from wordpress. $post = get_post($postId); if ($post->post_status != 'publish' || $post->post_type != 'post') { return $postId; } // Extracting images from the post content. $images = p2mixi_extract_jpeg_images($post->post_content); // Header if ($header != '') { $header = str_replace('%%URL%%', get_permalink($postId), $header); $header = p2mixi_sanitize_html($header . "\r\n\r\n"); } // Body $body = $post->post_content; $movies = p2mixi_parse_movie_links($body); $body = p2mixi_replace_hyperlinks($body, array($images['urls'][0])); $body = p2mixi_sanitize_html($body); $body .= $movies; // Footer if ($footer != '') { $footer = str_replace('%%URL%%', get_permalink($postId), $footer); $footer = p2mixi_sanitize_html("\r\n\r\n" . $footer); } // Chop the body if it is too big. // The max length for the mixi diary body is 10k letters. // Actually it is 10k 'Japanese' letters (20k bytes) so it could be more // if you use ASCII letters, but here just say 10k letters to make it safer. // // Not sure mb_ functions are available in any php env. if (function_exists('mb_strlen') && function_exists('mb_substr')) { $max_body_len = 10000 - mb_strlen($header, 'utf-8') - mb_strlen($footer, 'utf-8'); if ($max_body_len < mb_strlen($body)) { $body = mb_substr($body, 0, $max_body_len, 'utf-8'); } } // content = header + body + footer $content = $header . $body . $footer; // Publish to Mixi p2mixi_publish_to_mixi($p2mixi_username, $p2mixi_password, $p2mixi_id, $post->post_title, $content, $images['images']); return $postId; }