Created
June 13, 2014 19:53
-
-
Save zllovesuki/b22ed4427c02a5ad033e to your computer and use it in GitHub Desktop.
Cache URL Generator
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 | |
$retina = true; | |
$key = 'kokenwtf'; //ENTER YOUR OWN KEY | |
if ($_GET['key'] != $key) die; | |
$ds = DIRECTORY_SEPARATOR; | |
$root = dirname(__FILE__); | |
$content = $root . $ds . 'storage'; | |
$base = '/storage/cache/images'; | |
require($content . $ds . 'configuration' . $ds . 'database.php'); | |
$interface = $KOKEN_DATABASE['driver']; | |
$query = "SELECT id, filename, file_modified_on FROM {$KOKEN_DATABASE['prefix']}content"; | |
if ($interface == 'mysqli') | |
{ | |
$db_link = mysqli_connect($KOKEN_DATABASE['hostname'], $KOKEN_DATABASE['username'], $KOKEN_DATABASE['password'], null, (int) $KOKEN_DATABASE['port'], $KOKEN_DATABASE['socket']); | |
$db_link->select_db($KOKEN_DATABASE['database']); | |
if ($query) | |
{ | |
$result = $db_link->query($query); | |
if ($result) | |
{ | |
while ($row = $result->fetch_assoc()) { | |
$results[] = $row; | |
} | |
$result->close(); | |
} | |
} | |
$db_link->close(); | |
} | |
else | |
{ | |
mysql_connect($KOKEN_DATABASE['hostname'], $KOKEN_DATABASE['username'], $KOKEN_DATABASE['password']); | |
mysql_select_db($KOKEN_DATABASE['database']); | |
if ($query) | |
{ | |
$result = mysql_query($query); | |
if ($result) | |
{ | |
while ($row = mysql_fetch_assoc($result)) { | |
$results[] = $row; | |
} | |
} | |
} | |
mysql_close(); | |
} | |
$requests = array(); | |
foreach($results as $image) { | |
$full_id = str_pad($image['id'], 6, 0, STR_PAD_LEFT); | |
$parts = str_split($full_id, $split_length = 3); | |
$url = $base.'/'.$parts[0].'/'.$parts[1]; | |
list($name, $ext) = explode('.', $image['filename']); | |
$size = array( | |
'tiny', | |
'small', | |
'medium', | |
'medium_large', | |
'large', | |
'xlarge', | |
'huge' | |
); | |
foreach($size as $s) { | |
$requests[] = $url.'/'.$name.','.$s.'.'.$image['file_modified_on'].'.'.$ext; | |
if ($retina) { | |
$requests[] = $url.'/'.$name.','.$s.'.2x.'.$image['file_modified_on'].'.'.$ext; | |
} | |
} | |
} | |
echo json_encode($requests); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was forced to modify one line to work with the latest version of Koken, which doesn't set $KOKEN_DATABASE in the database.php file. Instead, I changed the line with the require command in cache.url.php as follows:
$KOKEN_DATABASE=require($content . $ds . 'configuration' . $ds . 'database.php');