Ejemplo n.º 1
0
function create_message($filename, $data)
{
    $sample = file_get_contents($filename);
    if ($sample === FALSE) {
        return 'File not found!<BR>';
    } else {
        foreach ($data as $k => $v) {
            $sample = str_replace('{{' . $k . '}}', $v, $sample);
        }
        return htmlallentities($sample);
    }
}
/**
 * Report potentially problematic characters.
 *
 * @param array $values An array values with atleast one entry containing problematic chars
 *
 * @return string
 */
function listProblematicCharacters($values)
{
    $str = '';
    foreach ($values as $field_name => $value) {
        $entified = htmlallentities($value);
        preg_match_all('/&#([0-9]+);/', $entified, $matches);
        $codes = array_unique($matches[1]);
        $probChars = '';
        foreach ($codes as $code) {
            $probChars .= html_entity_decode('&#' . $code . ';', ENT_COMPAT, 'utf-8') . ' (' . $code . '), ';
        }
        $str .= "\n\t" . $field_name . ": " . preg_replace('/,\\s*$/', '', $probChars);
    }
    return $str;
}
Ejemplo n.º 3
0
/**
 * Parse and Import all link to WordPress
 * @param  integer $parser     Content parser used, 0 for using Readability API, 1 for using Fivefilters API.
 * @param  string  $url        URL list that will be parsed and imported to WordPress
 * @param  array   $categories Category for the imported articles.
 * @param  array   $tags       Tags for the imported articles.
 * @return Void              
 */
function importToWordPress($parser = 0, $url, $categories = array(), $tags = array())
{
    $objXMLRPClientWordPress = new XMLRPClientWordPress(WP_URL, WP_USERNAME, WP_PASSWORD);
    if (!is_null($url) || !empty($url)) {
        for ($i = 0; $i < count($url); $i++) {
            $startItem = $i + 1;
            $totalItem = count($url);
            $progressPecentage = $startItem * 100 / $totalItem;
            try {
                if ($parser == 0) {
                    // USE Readability as Parser
                    $content = file_get_contents(READABILITY_URL . '?url=' . $url[$i] . '&token=' . READABILITY_TOKEN);
                } else {
                    // USE Fivefilters as Parser
                    $content = file_get_contents(FIVEFILTERS_URL . '?url=' . $url[$i] . '&links=preserve&format=json');
                }
                // Check for any error on HTTP request
                if ($content === false) {
                    $allowedExts = array("jpg", "jpeg", "png", "gif");
                    $temp = explode(".", $url[$i]);
                    // Separate file name and it's extension
                    $file_ext = strtolower(end($temp));
                    //If the error url is image, add new post as images (For Readability API).
                    if (in_array($file_ext, $allowedExts) === true) {
                        echo "Image found, added as image to WordPress";
                        $objXMLRPClientWordPress->new_post('Image', '<figure><img src="' . $url[$i] . '" alt="image" /></figure>', array('images'), $tags[$i], array(array("key" => "source_url", "value" => $url[$i])));
                    }
                }
                $json = json_decode($content, true);
                if ($parser == 0) {
                    $article_title = $json['title'];
                    $article_content = $json['content'];
                } else {
                    $article_title = $json['rss']['channel']['item']['title'];
                    $article_content = $json['rss']['channel']['item']['description'];
                }
                // Print progress of succesfully title posted to WP
                echo htmlallentities($article_title) . " &raquo; Added<br>";
                // Post to WP
                $objXMLRPClientWordPress->new_post($article_title, $article_content, $categories, $tags[$i], array(array("key" => "source_url", "value" => $url[$i])));
                showProgressbar($progressPecentage);
            } catch (Exception $ex) {
                echo 'Caught exception: ', $e->getMessage(), "\n";
            }
        }
        deleteAllFiles('uploads');
        //Delete all Pocket HTML file insied uploads
        echo "<br/>Import Complete<br/>";
    }
}