コード例 #1
0
ファイル: DeuxTitres.php プロジェクト: WhiteFangs/DeuxTitres
function getHeadline($topic)
{
    $headlines = array();
    $topicPage = getCURLOutput($topic->url);
    $topicPage = str_replace("<b>", "", $topicPage);
    $topicPage = str_replace("</b>", "", $topicPage);
    $topicXpath = getDOMXPath($topicPage);
    $headlinesNodes = $topicXpath->query('//*[@class="titletext"]/text()');
    for ($i = 0; $i < $headlinesNodes->length; $i++) {
        $titletext = $headlinesNodes->item($i)->nodeValue;
        if (strstr($titletext, " ...") === false && strstr($titletext, $topic->name) !== false) {
            $headlines[] = $titletext;
        }
    }
    $headline = $headlines[array_rand($headlines)];
    return $headline;
}
コード例 #2
0
function getPosts($topicUrl)
{
    $posts = array();
    $pageCount = 0;
    while ($topicUrl != "" && $pageCount < 5) {
        $topicPage = getCURLOutput($topicUrl);
        $topicPage = cleanHTML($topicPage);
        $topicXpath = getDOMXPath($topicPage);
        $textNodes = $topicXpath->query('//*[contains(@class, "txt-msg") and contains(@class ,"text-enrichi-forum")]');
        $userNodes = $topicXpath->query('//*[contains(@class, "bloc-pseudo-msg") and contains(@class, "text-user")]/text()');
        for ($i = 0; $i < $textNodes->length; $i++) {
            $post = (object) array('user' => $userNodes->item($i)->nodeValue, 'text' => $textNodes->item($i)->nodeValue);
            $posts[] = $post;
        }
        if (strstr($topicPage, $pageCount + 1 . "-0-1-0") != false && strstr($topicPage, "Page suivante") != false) {
            $topicUrl = str_replace($pageCount . "-0-1-0", $pageCount + 1 . "-0-1-0", $topicUrl);
            $pageCount++;
        } else {
            $topicUrl = "";
        }
    }
    return $posts;
}
コード例 #3
0
ファイル: getSong.php プロジェクト: Orsucciu/PoetifyJS
<?php

include "helpers.php";
header('Content-Type: text/html; charset=utf-8');
$lyricsLink = $_POST["songUrl"];
// Get the lyrics and credits
$lyricsPage = getCURLOutput($lyricsLink);
$lyricsPage = str_replace('<br />', '###', $lyricsPage);
$lyricsXpath = getDOMXPath($lyricsPage);
$lyricsQuery = $lyricsXpath->query('//div[@class="lyricbox"]/text()');
$creditsQuery = $lyricsXpath->query('//div[@class="song-credit-box"]/text()');
$metaQuery = $lyricsXpath->query('//div[@class="header-column header-title"]/h1/text()');
$songAttrTitle = $metaQuery->item(0)->nodeValue;
$songAttrTitle = str_replace(" Lyrics", "", $songAttrTitle);
$artistName = substr($songAttrTitle, 0, strrpos($songAttrTitle, ":"));
$songName = substr($songAttrTitle, strrpos($songAttrTitle, ":") + 1);
$lyrics = $lyricsQuery->item($i)->nodeValue;
$lyrics = delete_all_between("(", ")", $lyrics);
$lyrics = str_replace("'", "’", $lyrics);
if (isset($lyricsLink) && isset($songName) && isset($artistName) && isset($lyrics)) {
    $arr = array('url' => $lyricsLink, 'titre' => $songName, 'auteur' => $artistName, 'lyrics' => $lyrics);
    echo json_encode($arr);
} else {
    echo "Erreur";
}