Source for file deviantart.php
Documentation is available at deviantart.php
* Scrapes a recent deviations feed together from deviantart.
* Uses a json formatted string from deviantart which works currently, however
* any changes will most likley break this. Hopefully only the xsl would need to
* be updated in such an event.
* I am not personally affiliated with DeviantART in any way. Use of the
* DeviantART website by its Terms Of Service. I am not responsible for the way
* you use this script. The use of this script to scrape your DeviantART user
* gallery may be in breach of your agreement with DeviantART.
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
* @author Stephen Ingram <code@jixor.com>
* @copyright Copyright (c) 2008, Stephen Ingram
* @package deviantartfeed
* @category deviantartfeed
* @todo The title and date regex is quick and dirty, it could easily be tripped
* @todo Investigate further what sort of output the DeviantART "DiFi" script
* Location of config file
* If you move or rename the deviantart.ini file you must edit this path.
const config_file = 'deviantart.ini';
* Holds loaded config array
* Filesystem path to cache file.
* Constructor does all the work
. $this->conf['cache']['file'];
* Set url, broken into multiple lines for readability. Well...
$url = "http://{$this->conf[feed][user]}artist.deviantart.com/global/difi/ "
. "?c%5B%5D=Resources;htmlFromQuery;gallery%3A{$this->conf[feed][user]}"
. "%20sort%3Atime,{$this->conf[feed][start]},{ $this->conf[feed][request]}"
. ",thumb150,artist%3A0&t=json";
* Spoof user agent, not really necessary.
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1)'
* Define xml file, includes attributes on channel that are used by the
imageurl=\"{$this->conf[imagecache][url]}\"
imagecache=\"{$this->conf[imagecache][path]}\"
<title>{$this->conf[feed][user]}'s deviantART gallery</title>
<link>http://{$this->conf[feed][user]}.deviantart.com</link> ";
* Add any additional channel elements as defined in ini
if (isset ($this->conf['channel'])
&& !empty($this->conf['channel'])
foreach ($this->conf['channel'] as $name => $value)
$xml .= "<{$name}>{$value}</{$name}>";
* Add xml entry for each item in the response object.
foreach($result_object->DiFi->response->calls[0]->response->content->resources as $item)
$xml .= '<item>' . $item[2] . '</item>';
* Initialize the dom object and load the xml file from the string.
$dom->loadXML($xml . '</items></channel>');
* Initialize the xsl dom object and load the xsl file form the
$xsl->load($this->conf['xsl']['path']);
* Initialize the XSLT processor and enable php function calls
$proc = new XSLTProcessor();
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsl);
* Process the xml translation and save to the cache file.
* Call deviantart::output_cahce() to send the rss feed to the user,
* Return or send cache depenging on setting
* If not in cron mode sends the contents of the cache file to the user,
* otherwise simply returns void.
if($this->conf['general']['cron'])
/* or redirect to the feed.
. $this->conf['general']['url']
. $this->conf['cache']['url']
. $this->conf['cache']['file']
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla')) {
header('Content-type: text/xml');
header('Content-Type: application/rss+xml');
* Downloads a local cache of specified file.
* @param string $base URL base to apply to output URL
* @param string $path Path base for local filesystem path.
* @return string URL to local cache.
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/Firefox/3.0.1'
* Gets the artwork title from the proviced string
* @param string $string Vale of title attribute from input xml
* @return string Artwork title
* Gets the artwork date in RFC 2822 format from the proviced string
* I'm assuming that deviantart records dates in UTC time, however I could
* @param string $string Vale of title attribute from input xml
* @return string Artwork date
* I'm assuming that you can't have a , in your artork title.
|