Created
November 4, 2013 21:20
-
-
Save timw4mail/7309356 to your computer and use it in GitHub Desktop.
mal-api script for theme images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function do_curl($url, $options=array()) | |
{ | |
$cookie = tempnam ("/tmp", "CURLCOOKIE"); | |
$ch = curl_init($url); | |
//Use the user's User Agent and Cookies | |
$opts= array( | |
CURLOPT_USERAGENT => "Tim's List Image Updater", | |
CURLOPT_COOKIEJAR => $cookie, | |
CURLOPT_FOLLOWLOCATION => TRUE, | |
CURLOPT_ENCODING => "", | |
CURLOPT_RETURNTRANSFER => TRUE, | |
CURLOPT_AUTOREFERER => TRUE, | |
CURLOPT_SSL_VERIFYPEER => FALSE, | |
CURLOPT_CONNECTTIMEOUT => 10, | |
CURLOPT_TIMEOUT => 10, | |
CURLOPT_MAXREDIRS => 10, | |
CURLOPT_PROTOCOLS => array(CURLPROTO_HTTP,CURLPROTO_HTTPS) | |
); | |
//Set default options | |
curl_setopt_array($ch, $opts); | |
//Set additional options | |
curl_setopt_array($ch, $options); | |
return curl_exec($ch); | |
} | |
/** | |
* Takes the object, builds the array | |
* | |
* @param string type | |
* @return array | |
*/ | |
function build_css($type) | |
{ | |
$json = do_curl("http://mal-api.com/{$type}list/timw4mail"); | |
$obj = json_decode($json); | |
$css = array(); | |
foreach ($obj->$type as $$type) | |
{ | |
$css[] = "#more{$$type->id}{background:url({$$type->image_url})no-repeat}"; | |
} | |
return $css; | |
} | |
// ! Manga | |
$css = build_css("manga"); | |
$css_string = implode("\n", $css); | |
file_put_contents("/htdocs/static.timshomepage.net/css/mal_manga_imgs.css", $css_string); | |
?><pre><?= print_r($css, TRUE) ?></pre><?php | |
// ! Anime | |
$css = build_css("anime"); | |
$css_string = implode("\n", $css); | |
file_put_contents("/htdocs/static.timshomepage.net/css/mal_imgs.css", $css_string); | |
?><pre><?= print_r($css, TRUE) ?></pre> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment