コード例 #1
0
ファイル: podcastfunctions.php プロジェクト: cyrilix/rompr
function getNewPodcast($url)
{
    debuglog("Getting podcast " . $url, "PODCASTS");
    // iTunes links normally link to the same XML feed as the RSS link, so fixup the protocol and hope
    $url = preg_replace('#^itpc://#', 'http://', $url);
    $fname = md5($url);
    if (!is_dir('prefs/podcasts/' . $fname)) {
        mkdir('prefs/podcasts/' . $fname);
    }
    $fp = fopen('prefs/podcasts/' . $fname . '/feed.xml', 'w');
    if (!$fp) {
        debuglog("COULD NOT OPEN FILE FOR FEED!", "PODCASTS");
        header('HTTP/1.0 404 Not Found');
        debuglog("Failed to get " . $url, "PODCASTS");
        fclose($fp);
        if (file_exists('prefs/podcasts/' . $fname . '/feed.xml')) {
            unlink('prefs/podcasts/' . $fname . '/feed.xml');
        }
        exit;
    }
    $result = url_get_contents($url, 'RompR Music Player/0.41', false, true, false, $fp);
    fclose($fp);
    if ($result['status'] != "200") {
        header('HTTP/1.0 404 Not Found');
        debuglog("Failed to get " . $url, "PODCASTS");
        if (file_exists('prefs/podcasts/' . $fname . '/feed.xml')) {
            unlink('prefs/podcasts/' . $fname . '/feed.xml');
        }
        exit;
    }
    debuglog("Feed retrieved from " . $url, "PODCASTS");
    $feed = simplexml_load_file('prefs/podcasts/' . $fname . '/feed.xml');
    $lastupdated = 0;
    $oldinfo = null;
    if (file_exists('prefs/podcasts/' . $fname . '/info.xml')) {
        $oldinfo = simplexml_load_file('prefs/podcasts/' . $fname . '/info.xml');
        $lastupdated = $oldinfo->lastupdate;
    }
    $domain = preg_replace('#^(http://.*?)/.*$#', '$1', $url);
    // <ppg:seriesDetails typicalDuration="PT28M" active="true" public="true" region="all" launchDate="2009-01-21" frequency="weekly" daysLive="60" liveItems="2" />
    $ppg = $feed->channel->children('ppg', TRUE);
    $refreshoption = "never";
    $displaymode = "all";
    $autodownload = "false";
    $keepdownloaded = "false";
    $sortmode = "newestfirst";
    $hidedescriptions = "false";
    $daystokeep = 0;
    $numtokeep = 0;
    $daysLive = -1;
    if ($oldinfo) {
        $refreshoption = $oldinfo->refreshoption;
        $displaymode = $oldinfo->displaymode;
        $autodownload = $oldinfo->autodownload;
        $daystokeep = $oldinfo->daystokeep;
        $numtokeep = $oldinfo->numtokeep;
        $keepdownloaded = $oldinfo->keepdownloaded;
        $sortmode = $oldinfo->sortmode;
        $hidedescriptions = $oldinfo->hidedescriptions;
    } else {
        if ($ppg && $ppg->seriesDetails) {
            $refreshoption = $ppg->seriesDetails[0]->attributes()->frequency;
            if ($refreshoption != "hourly" && $refreshoption != "daily" && $refreshoption != "weekly" && $refreshoption != "monthly") {
                $refreshoption = "never";
            }
        }
    }
    if ($ppg && $ppg->seriesDetails && $ppg->seriesDetails[0]->attributes()->daysLive) {
        $daysLive = $ppg->seriesDetails[0]->attributes()->daysLive;
    }
    $image = "newimages/podcast-logo.png";
    $m = $feed->channel->children('itunes', TRUE);
    if ($feed->channel->image) {
        $image = $feed->channel->image->url;
    } else {
        if ($m && $m->image) {
            $image = $m->image[0]->attributes()->href;
        }
    }
    if (preg_match('#^/#', $image)) {
        // Image link with a relative URL. Duh.
        $image = $domain . $image;
    }
    $i = getDomain($image);
    if ($i == "http" || $i == "https") {
        $imgname = 'prefs/podcasts/' . $fname . '/' . preg_replace('/\\?.*$/', '', basename($image));
        $fp = fopen($imgname, 'w');
        debuglog("Downloading Image " . $image . " to " . $imgname, "PODCASTS");
        $result = url_get_contents($image, 'RompR Music Player/0.60', false, true, false, $fp);
        if ($result['status'] == '200') {
            debuglog("Image download Success", "PODCASTS");
            $image = $imgname;
        } else {
            debuglog("Failed to download Image", "PODCASTS");
        }
        fclose($fp);
    }
    $albumartist = "";
    if ($m && $m->author) {
        $albumartist = (string) $m->author;
    }
    $album = (string) $feed->channel->title;
    $x = new SimpleXMLElement('<podcast></podcast>');
    $x->addChild('feedurl', htmlspecialchars($url));
    $x->addChild('lastupdate', time());
    $x->addChild('image', $image);
    $x->addChild('album', htmlspecialchars($album));
    $x->addChild('refreshoption', $refreshoption);
    $x->addChild('sortmode', $sortmode);
    $x->addChild('hidedescriptions', $hidedescriptions);
    $x->addChild('displaymode', $displaymode);
    $x->addChild('daystokeep', $daystokeep);
    $x->addChild('numtokeep', $numtokeep);
    $x->addChild('keepdownloaded', $keepdownloaded);
    $x->addChild('autodownload', $autodownload);
    $x->addChild('description', htmlspecialchars((string) $feed->channel->description));
    $x->addChild('albumartist', htmlspecialchars($albumartist));
    $x->addChild('daysLive', $daysLive);
    $tracklist = $x->addChild('trackList');
    $count = 0;
    foreach ($feed->channel->item as $item) {
        $link = "";
        $duration = 0;
        $m = $item->children('media', TRUE);
        if ($m && $m->content) {
            $link = (string) $m->content[0]->attributes()->url;
        } else {
            if ($item->enclosure) {
                $link = (string) $item->enclosure->attributes()->url;
            }
        }
        if ($m && $m->content) {
            if ($m->content[0]->attributes()->duration) {
                $duration = (string) $m->content[0]->attributes()->duration;
            }
        }
        $m = $item->children('itunes', TRUE);
        if ($duration == 0 && $m && $m->duration) {
            $duration = (string) $m->duration;
        }
        // Always store time values in seconds
        if ($duration != 0 && preg_match('/:/', $duration)) {
            if (strlen($duration) == 5) {
                // Make sure we have a HH:MM:SS time string. strtotime doesn't cope with MM:SS
                $duration = "00:" . $duration;
            }
            $duration = strtotime($duration) - strtotime('TODAY');
        }
        if ($m && $m->author) {
            $artist = (string) $m->author;
        } else {
            $artist = $albumartist;
        }
        $pubdate = (string) $item->pubDate;
        if ($item->enclosure && $item->enclosure->attributes()) {
            $filesize = $item->enclosure->attributes()->length;
        }
        $description = (string) $item->description;
        if ($description == "" && $m && $m->summary) {
            $description = (string) $m->summary;
        }
        $key = md5((string) $item->guid);
        $listened = "no";
        $new = "yes";
        $deleted = "no";
        $link = htmlspecialchars($link);
        $origlink = null;
        if ($oldinfo) {
            // debuglog("Checking previous download for ".$key,"PODCASTS");
            $axp = $oldinfo->xpath('//track/key[.="' . $key . '"]/parent::*');
            if ($axp) {
                // debuglog("... Found ".$key,"PODCASTS");
                $listened = $axp[0]->{'listened'};
                $link = $axp[0]->{'link'};
                $deleted = $axp[0]->{'deleted'};
                if ($axp[0]->{'origlink'}) {
                    $origlink = $axp[0]->{'origlink'};
                }
                $new = "no";
                $axp[0]->{'found'} = "yes";
                if ($deleted == "no") {
                    $count++;
                }
            } else {
                $count++;
            }
        } else {
            $count++;
        }
        if ($numtokeep > 0 && $count > $numtokeep || checkExpiry($pubdate, $daystokeep)) {
            $od = $deleted;
            $deleted = "yes";
            if (is_dir('prefs/podcasts/' . $fname . '/' . $key)) {
                if ($keepdownloaded == "false") {
                    system('rm -fR prefs/podcasts/' . $fname . '/' . $key);
                } else {
                    $deleted = $od;
                }
            }
        }
        $track = $tracklist->addChild('track');
        $track->addChild('title', htmlspecialchars($item->title));
        $track->addChild('duration', $duration);
        $track->addChild('artist', htmlspecialchars($artist));
        $track->addChild('pubdate', $pubdate);
        $track->addChild('filesize', $filesize);
        $track->addChild('description', htmlspecialchars($description));
        $track->addChild('key', $key);
        debuglog("Track Link Is " . $link, "PODCASTS");
        $track->addChild('link', htmlspecialchars($link));
        $track->addChild('listened', $listened);
        $track->addChild('new', $new);
        $track->addChild('deleted', $deleted);
        if ($origlink) {
            $track->addChild('origlink', $origlink);
        }
    }
    // Now add any remaining ones from the old list that have been downloaded but not
    // found in the new list
    if ($oldinfo) {
        foreach ($oldinfo->trackList->track as $track) {
            if ($track->found && $track->found == "yes") {
            } else {
                if (is_dir('prefs/podcasts/' . $fname . '/' . $track->key)) {
                    // This is messy but simplexml sucks big fat donkey shit and it's late and I'm tired.
                    if ($track->deleted == "no") {
                        $count++;
                        if ($keepdownloaded == "false" && ($numtokeep > 0 && $count > $numtokeep || checkExpiry($track->pubdate, $daystokeep))) {
                            system('rm -fR prefs/podcasts/' . $fname . '/' . $track->key);
                        } else {
                            $item = $tracklist->addChild('track');
                            $item->addChild('deleted', $track->deleted);
                            $item->addChild('title', $track->title);
                            $item->addChild('duration', $track->duration);
                            $item->addChild('artist', $track->artist);
                            $item->addChild('pubdate', $track->pubdate);
                            $item->addChild('filesize', $track->filesize);
                            $item->addChild('description', $track->description);
                            $item->addChild('key', $track->key);
                            $item->addChild('link', $track->link);
                            $item->addChild('listened', $track->listened);
                            $item->addChild('new', $track->new);
                        }
                    }
                }
            }
        }
    }
    saveFormattedXML($x, 'prefs/podcasts/' . $fname . '/info.xml');
}
コード例 #2
0
// Register an error array - just in case!
$_SESSION["ccErrors"] = array();
// Set up a formVars array for the POST variables
$_SESSION["ccFormVars"] = array();
foreach ($_POST as $varname => $value) {
    $_SESSION["ccFormVars"]["{$varname}"] = pearclean($_POST, $varname, 128, $connection);
}
// Check if mandatory credit card entered
if (checkMandatory("creditcard", "SurchargeCard", "ccErrors", "ccFormVars")) {
    // Validate credit card using Luhn algorithm
    checkCard("creditcard", "ccErrors", "ccFormVars");
}
// Check if mandatory credit card expiry entered
if (checkMandatory("expirydate", "expiry date", "ccErrors", "ccFormVars")) {
    // Validate credit card expiry date
    checkExpiry("expirydate", "ccErrors", "ccFormVars");
}
// Now the script has finished the validation,
// check if there were any errors
if (count($_SESSION["ccErrors"]) > 0) {
    // There are errors.  Relocate back to step #1
    header("Location: " . S_ORDER_1);
    exit;
}
// OK to update the order
$query = "UPDATE orders SET \n          creditcard = '{$_SESSION["ccFormVars"]["creditcard"]}',\n          expirydate = '{$_SESSION["ccFormVars"]["expirydate"]}',\n          instructions = '{$_SESSION["ccFormVars"]["instructions"]}'\n          WHERE cust_id = -1 AND\n                order_id = {$_SESSION["order_no"]}";
$result = $connection->query($query);
if (DB::isError($result)) {
    trigger_error($result->getMessage(), E_USER_ERROR);
}
// Clear the formVars so a future <form> is blank
コード例 #3
0
 }
 $errMsg .= checkPostcode($bstate, $bpostcode);
 // Checks if the expiration date of the card is earlier than today's date
 function checkExpiry($date)
 {
     $cmm = substr($date, 0, 2);
     $cyy = substr($date, 3, 5);
     $expires = \DateTime::createFromFormat('my', $cmm . $cyy);
     $now = new \DateTime();
     if ($expires < $now) {
         return "<p>This creditcard has expired</p>";
     } else {
         return "";
     }
 }
 $errMsg .= checkExpiry($cardexpiry);
 // checks card number against the card type
 function checkCardNumber($cardtype, $number)
 {
     $errMsg = "";
     switch ($cardtype) {
         case "Visa":
             if (!preg_match("/4[0-9]{15}/", $number)) {
                 $errMsg = "<p>Visa cards have 16 digits and start with a 4</p>";
             }
             break;
         case "Mastercard":
             if (!preg_match("/5[1-5][0-9]{14}/", $number)) {
                 $errMsg = "<p>MasterCard have 16 digits and start with digits 51 through to 55</p>";
             }
             break;