Exemplo n.º 1
0
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;
}
Exemplo n.º 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;
}
Exemplo n.º 3
0
<?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";
}
Exemplo n.º 4
0
// Get Twitter config
$twitterConfigURL = 'https://api.twitter.com/1.1/help/configuration.json';
$requestMethod = 'GET';
$twitterConfig = $twitter->setGetfield('')->buildOauth($twitterConfigURL, $requestMethod)->performRequest();
$twitterConfig = json_decode($twitterConfig);
// Twitter Media Upload URL
$mediaUploadURL = 'https://upload.twitter.com/1.1/media/upload.json';
// Get number of total hits available for works with image and title
$requestURL = 'http://api.art.rmngp.fr:80/v1/works?exists=images%2Ctitle.fr&per_page=0';
$result = getCURLOutput($requestURL, $RmnAPIKey);
if (isset($result->hits)) {
    $totalHits = $result->hits->total;
    // Get a random work with image and title
    $randomPage = rand(1, $totalHits);
    $requestURL = 'http://api.art.rmngp.fr:80/v1/works?exists=images%2Ctitle.fr&per_page=1&page=' . $randomPage;
    $result = getCURLOutput($requestURL, $RmnAPIKey);
    if (isset($result->hits) && count($result->hits->hits) > 0) {
        $work = $result->hits->hits[0]->_source;
        // Upload image of the work
        foreach ($work->images as $image) {
            if ($image->default) {
                $photographerCredit = $image->photographer->name;
                if (isset($image->permalink)) {
                    $permalink = $image->permalink;
                }
                $imageContent = file_get_contents($image->urls->original);
                $imageData = base64_encode($imageContent);
                $postfields = array('media_data' => $imageData);
                $requestMethod = "POST";
                $response = $twitter->resetFields()->buildOauth($mediaUploadURL, $requestMethod)->setPostfields($postfields)->performRequest();
                $response = json_decode($response);