Skip to content

Instantly share code, notes, and snippets.

@fvoges
Forked from zllovesuki/cache.url.php
Last active August 29, 2015 14:17
Show Gist options
  • Save fvoges/4e29efb98c50e3a0630e to your computer and use it in GitHub Desktop.
Save fvoges/4e29efb98c50e3a0630e to your computer and use it in GitHub Desktop.
<?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);
#!/usr/bin/env ruby2.0
require 'rubygems'
require 'net/https'
require 'uri'
require 'json'
require 'pp'
host = 'localhost'
port = 443
key = 'kokenwtf'
list_uri = "https://#{host}/cache.url.php?key=#{key}"
pp list_uri
http = Net::HTTP.new(host, port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(URI.parse(list_uri))
response = http.request(request)
images = JSON.parse(response.body)
i = 1
images.each do |image|
uri = "https://#{host}#{image}"
request = Net::HTTP::Get.new(URI.parse(uri))
response = http.request(request)
print "#{i}/#{images.length} - Status: #{response.code} - URL: #{uri}\n"
i += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment