Merge branch 'develop' of https://github.com/shish/shimmie2 into develop
This commit is contained in:
commit
860e828c3e
@ -10,6 +10,7 @@ require_once "core/sys_config.inc.php";
|
|||||||
require_once "core/util.inc.php";
|
require_once "core/util.inc.php";
|
||||||
require_once "lib/context.php";
|
require_once "lib/context.php";
|
||||||
require_once "vendor/autoload.php";
|
require_once "vendor/autoload.php";
|
||||||
|
require_once "core/imageboard.pack.php";
|
||||||
|
|
||||||
// set up and purify the environment
|
// set up and purify the environment
|
||||||
_version_check();
|
_version_check();
|
||||||
|
@ -44,6 +44,14 @@ class Block {
|
|||||||
*/
|
*/
|
||||||
public $id;
|
public $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should this block count as content for the sake of
|
||||||
|
* the 404 handler
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
public $is_content = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a block.
|
* Construct a block.
|
||||||
*
|
*
|
||||||
@ -58,7 +66,11 @@ class Block {
|
|||||||
$this->body = $body;
|
$this->body = $body;
|
||||||
$this->section = $section;
|
$this->section = $section;
|
||||||
$this->position = $position;
|
$this->position = $position;
|
||||||
$this->id = preg_replace('/[^\w]/', '',str_replace(' ', '_', is_null($id) ? (is_null($header) ? md5($body) : $header) . $section : $id));
|
|
||||||
|
if(is_null($id)) {
|
||||||
|
$id = (empty($header) ? md5($body) : $header) . $section;
|
||||||
|
}
|
||||||
|
$this->id = preg_replace('/[^\w]/', '',str_replace(' ', '_', $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -314,13 +314,8 @@ class MemcacheCache implements CacheEngine {
|
|||||||
*/
|
*/
|
||||||
public function __construct($args) {
|
public function __construct($args) {
|
||||||
$hp = explode(":", $args);
|
$hp = explode(":", $args);
|
||||||
if(class_exists("Memcache")) {
|
$this->memcache = new Memcache;
|
||||||
$this->memcache = new Memcache;
|
@$this->memcache->pconnect($hp[0], $hp[1]);
|
||||||
@$this->memcache->pconnect($hp[0], $hp[1]);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
print "no memcache"; exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -378,6 +373,100 @@ class MemcacheCache implements CacheEngine {
|
|||||||
*/
|
*/
|
||||||
public function get_misses() {return $this->misses;}
|
public function get_misses() {return $this->misses;}
|
||||||
}
|
}
|
||||||
|
class MemcachedCache implements CacheEngine {
|
||||||
|
/** @var \Memcached|null */
|
||||||
|
public $memcache=null;
|
||||||
|
/** @var int */
|
||||||
|
private $hits=0;
|
||||||
|
/** @var int */
|
||||||
|
private $misses=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $args
|
||||||
|
*/
|
||||||
|
public function __construct($args) {
|
||||||
|
$hp = explode(":", $args);
|
||||||
|
$this->memcache = new Memcached;
|
||||||
|
#$this->memcache->setOption(Memcached::OPT_COMPRESSION, False);
|
||||||
|
#$this->memcache->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_PHP);
|
||||||
|
#$this->memcache->setOption(Memcached::OPT_PREFIX_KEY, phpversion());
|
||||||
|
$this->memcache->addServer($hp[0], $hp[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $key
|
||||||
|
* @return array|bool|string
|
||||||
|
*/
|
||||||
|
public function get($key) {
|
||||||
|
assert('!is_null($key)');
|
||||||
|
$key = urlencode($key);
|
||||||
|
|
||||||
|
$val = $this->memcache->get($key);
|
||||||
|
$res = $this->memcache->getResultCode();
|
||||||
|
|
||||||
|
if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) {
|
||||||
|
$hit = $res == Memcached::RES_SUCCESS ? "hit" : "miss";
|
||||||
|
file_put_contents("data/cache.log", "Cache $hit: $key\n", FILE_APPEND);
|
||||||
|
}
|
||||||
|
if($res == Memcached::RES_SUCCESS) {
|
||||||
|
$this->hits++;
|
||||||
|
return $val;
|
||||||
|
}
|
||||||
|
else if($res == Memcached::RES_NOTFOUND) {
|
||||||
|
$this->misses++;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error_log("Memcached error during get($key): $res");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $key
|
||||||
|
* @param mixed $val
|
||||||
|
* @param int $time
|
||||||
|
*/
|
||||||
|
public function set($key, $val, $time=0) {
|
||||||
|
assert('!is_null($key)');
|
||||||
|
$key = urlencode($key);
|
||||||
|
|
||||||
|
$this->memcache->set($key, $val, $time);
|
||||||
|
$res = $this->memcache->getResultCode();
|
||||||
|
if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) {
|
||||||
|
file_put_contents("data/cache.log", "Cache set: $key ($time)\n", FILE_APPEND);
|
||||||
|
}
|
||||||
|
if($res != Memcached::RES_SUCCESS) {
|
||||||
|
error_log("Memcached error during set($key): $res");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $key
|
||||||
|
*/
|
||||||
|
public function delete($key) {
|
||||||
|
assert('!is_null($key)');
|
||||||
|
$key = urlencode($key);
|
||||||
|
|
||||||
|
$this->memcache->delete($key);
|
||||||
|
$res = $this->memcache->getResultCode();
|
||||||
|
if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) {
|
||||||
|
file_put_contents("data/cache.log", "Cache delete: $key\n", FILE_APPEND);
|
||||||
|
}
|
||||||
|
if($res != Memcached::RES_SUCCESS && $res != Memcached::RES_NOTFOUND) {
|
||||||
|
error_log("Memcached error during delete($key): $res");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function get_hits() {return $this->hits;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function get_misses() {return $this->misses;}
|
||||||
|
}
|
||||||
|
|
||||||
class APCCache implements CacheEngine {
|
class APCCache implements CacheEngine {
|
||||||
public $hits=0, $misses=0;
|
public $hits=0, $misses=0;
|
||||||
@ -466,10 +555,13 @@ class Database {
|
|||||||
|
|
||||||
private function connect_cache() {
|
private function connect_cache() {
|
||||||
$matches = array();
|
$matches = array();
|
||||||
if(defined("CACHE_DSN") && CACHE_DSN && preg_match("#(memcache|apc)://(.*)#", CACHE_DSN, $matches)) {
|
if(defined("CACHE_DSN") && CACHE_DSN && preg_match("#(memcache|memcached|apc)://(.*)#", CACHE_DSN, $matches)) {
|
||||||
if($matches[1] == "memcache") {
|
if($matches[1] == "memcache") {
|
||||||
$this->cache = new MemcacheCache($matches[2]);
|
$this->cache = new MemcacheCache($matches[2]);
|
||||||
}
|
}
|
||||||
|
else if($matches[1] == "memcached") {
|
||||||
|
$this->cache = new MemcachedCache($matches[2]);
|
||||||
|
}
|
||||||
else if($matches[1] == "apc") {
|
else if($matches[1] == "apc") {
|
||||||
$this->cache = new APCCache($matches[2]);
|
$this->cache = new APCCache($matches[2]);
|
||||||
}
|
}
|
||||||
@ -598,18 +690,15 @@ class Database {
|
|||||||
* @param string $sql
|
* @param string $sql
|
||||||
*/
|
*/
|
||||||
private function count_execs($db, $sql, $inputarray) {
|
private function count_execs($db, $sql, $inputarray) {
|
||||||
if ((defined('DEBUG_SQL') && DEBUG_SQL === true) || (!defined('DEBUG_SQL') && @$_GET['DEBUG_SQL'])) {
|
if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) {
|
||||||
$fp = @fopen("data/sql.log", "a");
|
$sql = trim(preg_replace('/\s+/msi', ' ', $sql));
|
||||||
if($fp) {
|
if(isset($inputarray) && is_array($inputarray) && !empty($inputarray)) {
|
||||||
$sql = trim(preg_replace('/\s+/msi', ' ', $sql));
|
$text = $sql." -- ".join(", ", $inputarray)."\n";
|
||||||
if(isset($inputarray) && is_array($inputarray) && !empty($inputarray)) {
|
|
||||||
fwrite($fp, $sql." -- ".join(", ", $inputarray)."\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fwrite($fp, $sql."\n");
|
|
||||||
}
|
|
||||||
fclose($fp);
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$text = $sql."\n";
|
||||||
|
}
|
||||||
|
file_put_contents("data/sql.log", $text, FILE_APPEND);
|
||||||
}
|
}
|
||||||
if(!is_array($inputarray)) $this->query_count++;
|
if(!is_array($inputarray)) $this->query_count++;
|
||||||
# handle 2-dimensional input arrays
|
# handle 2-dimensional input arrays
|
||||||
@ -617,6 +706,14 @@ class Database {
|
|||||||
else $this->query_count++;
|
else $this->query_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function count_time($method, $start) {
|
||||||
|
if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) {
|
||||||
|
$text = $method.":".(microtime(true) - $start)."\n";
|
||||||
|
file_put_contents("data/sql.log", $text, FILE_APPEND);
|
||||||
|
}
|
||||||
|
$this->dbtime += microtime(true) - $start;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute an SQL query and return an PDO result-set.
|
* Execute an SQL query and return an PDO result-set.
|
||||||
*
|
*
|
||||||
@ -661,7 +758,7 @@ class Database {
|
|||||||
public function get_all($query, $args=array()) {
|
public function get_all($query, $args=array()) {
|
||||||
$_start = microtime(true);
|
$_start = microtime(true);
|
||||||
$data = $this->execute($query, $args)->fetchAll();
|
$data = $this->execute($query, $args)->fetchAll();
|
||||||
$this->dbtime += microtime(true) - $_start;
|
$this->count_time("get_all", $_start);
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -675,7 +772,7 @@ class Database {
|
|||||||
public function get_row($query, $args=array()) {
|
public function get_row($query, $args=array()) {
|
||||||
$_start = microtime(true);
|
$_start = microtime(true);
|
||||||
$row = $this->execute($query, $args)->fetch();
|
$row = $this->execute($query, $args)->fetch();
|
||||||
$this->dbtime += microtime(true) - $_start;
|
$this->count_time("get_row", $_start);
|
||||||
return $row ? $row : null;
|
return $row ? $row : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -693,7 +790,7 @@ class Database {
|
|||||||
foreach($stmt as $row) {
|
foreach($stmt as $row) {
|
||||||
$res[] = $row[0];
|
$res[] = $row[0];
|
||||||
}
|
}
|
||||||
$this->dbtime += microtime(true) - $_start;
|
$this->count_time("get_col", $_start);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -711,7 +808,7 @@ class Database {
|
|||||||
foreach($stmt as $row) {
|
foreach($stmt as $row) {
|
||||||
$res[$row[0]] = $row[1];
|
$res[$row[0]] = $row[1];
|
||||||
}
|
}
|
||||||
$this->dbtime += microtime(true) - $_start;
|
$this->count_time("get_pairs", $_start);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -725,7 +822,7 @@ class Database {
|
|||||||
public function get_one($query, $args=array()) {
|
public function get_one($query, $args=array()) {
|
||||||
$_start = microtime(true);
|
$_start = microtime(true);
|
||||||
$row = $this->execute($query, $args)->fetch();
|
$row = $this->execute($query, $args)->fetch();
|
||||||
$this->dbtime += microtime(true) - $_start;
|
$this->count_time("get_one", $_start);
|
||||||
return $row[0];
|
return $row[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ class Image {
|
|||||||
* @param string[] $tags
|
* @param string[] $tags
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function validate_accel($tags) {
|
public static function validate_accel($tags) {
|
||||||
$yays = 0;
|
$yays = 0;
|
||||||
$nays = 0;
|
$nays = 0;
|
||||||
foreach($tags as $tag) {
|
foreach($tags as $tag) {
|
||||||
@ -209,7 +209,7 @@ class Image {
|
|||||||
* @return null|PDOStatement
|
* @return null|PDOStatement
|
||||||
* @throws SCoreException
|
* @throws SCoreException
|
||||||
*/
|
*/
|
||||||
public function get_accelerated_result($tags, $offset, $limit) {
|
public static function get_accelerated_result($tags, $offset, $limit) {
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
if(!Image::validate_accel($tags)) {
|
if(!Image::validate_accel($tags)) {
|
||||||
@ -282,8 +282,7 @@ class Image {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$querylet = Image::build_search_querylet($tags);
|
$querylet = Image::build_search_querylet($tags);
|
||||||
$result = $database->execute($querylet->sql, $querylet->variables);
|
return $database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables);
|
||||||
return $result->rowCount();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -967,7 +966,7 @@ class Image {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert('$positive_tag_id_array || $negative_tag_id_array');
|
assert('$positive_tag_id_array || $negative_tag_id_array', @$_GET['q']);
|
||||||
$wheres = array();
|
$wheres = array();
|
||||||
if (!empty($positive_tag_id_array)) {
|
if (!empty($positive_tag_id_array)) {
|
||||||
$positive_tag_id_list = join(', ', $positive_tag_id_array);
|
$positive_tag_id_list = join(', ', $positive_tag_id_array);
|
||||||
@ -1210,7 +1209,7 @@ function move_upload_to_archive(DataUploadEvent $event) {
|
|||||||
* Add a directory full of images
|
* Add a directory full of images
|
||||||
*
|
*
|
||||||
* @param $base string
|
* @param $base string
|
||||||
* @return array
|
* @return array|string[]
|
||||||
*/
|
*/
|
||||||
function add_dir($base) {
|
function add_dir($base) {
|
||||||
$results = array();
|
$results = array();
|
||||||
@ -1250,7 +1249,7 @@ function add_image($tmpname, $filename, $tags) {
|
|||||||
$metadata = array();
|
$metadata = array();
|
||||||
$metadata['filename'] = $pathinfo['basename'];
|
$metadata['filename'] = $pathinfo['basename'];
|
||||||
$metadata['extension'] = $pathinfo['extension'];
|
$metadata['extension'] = $pathinfo['extension'];
|
||||||
$metadata['tags'] = $tags;
|
$metadata['tags'] = Tag::explode($tags);
|
||||||
$metadata['source'] = null;
|
$metadata['source'] = null;
|
||||||
$event = new DataUploadEvent($tmpname, $metadata);
|
$event = new DataUploadEvent($tmpname, $metadata);
|
||||||
send_event($event);
|
send_event($event);
|
||||||
|
@ -966,6 +966,17 @@ function data_path($filename) {
|
|||||||
return $filename;
|
return $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!function_exists('mb_strlen')) {
|
||||||
|
// TODO: we should warn the admin that they are missing multibyte support
|
||||||
|
function mb_strlen($str, $encoding) {
|
||||||
|
return strlen($str);
|
||||||
|
}
|
||||||
|
function mb_internal_encoding($encoding) {}
|
||||||
|
function mb_strtolower($str) {
|
||||||
|
return strtolower($str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param string $mfile
|
* @param string $mfile
|
||||||
|
@ -42,7 +42,9 @@ class Blocks extends Extension {
|
|||||||
foreach($blocks as $block) {
|
foreach($blocks as $block) {
|
||||||
$path = implode("/", $event->args);
|
$path = implode("/", $event->args);
|
||||||
if(strlen($path) < 4000 && fnmatch($block['pages'], $path)) {
|
if(strlen($path) < 4000 && fnmatch($block['pages'], $path)) {
|
||||||
$page->add_block(new Block($block['title'], $block['content'], $block['area'], $block['priority']));
|
$b = new Block($block['title'], $block['content'], $block['area'], $block['priority']);
|
||||||
|
$b->is_content = false;
|
||||||
|
$page->add_block($b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ class BulkAddCSV extends Extension {
|
|||||||
$metadata = array();
|
$metadata = array();
|
||||||
$metadata['filename'] = $pathinfo['basename'];
|
$metadata['filename'] = $pathinfo['basename'];
|
||||||
$metadata['extension'] = $pathinfo['extension'];
|
$metadata['extension'] = $pathinfo['extension'];
|
||||||
$metadata['tags'] = $tags;
|
$metadata['tags'] = Tag::explode($tags);
|
||||||
$metadata['source'] = $source;
|
$metadata['source'] = $source;
|
||||||
$event = new DataUploadEvent($tmpname, $metadata);
|
$event = new DataUploadEvent($tmpname, $metadata);
|
||||||
send_event($event);
|
send_event($event);
|
||||||
|
@ -30,6 +30,7 @@ class Chatbox extends Extension {
|
|||||||
// loads the chatbox at the set location
|
// loads the chatbox at the set location
|
||||||
$html = "<div id=\"yshout\"></div>";
|
$html = "<div id=\"yshout\"></div>";
|
||||||
$chatblock = new Block("Chatbox", $html, "main", 97);
|
$chatblock = new Block("Chatbox", $html, "main", 97);
|
||||||
|
$chatblock->is_content = false;
|
||||||
$page->add_block($chatblock);
|
$page->add_block($chatblock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,9 +304,14 @@ class CronUploader extends Extension {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the necessary DataUploadEvent for a given image and tags.
|
* Generate the necessary DataUploadEvent for a given image and tags.
|
||||||
|
*
|
||||||
|
* @param string $tmpname
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $tags
|
||||||
*/
|
*/
|
||||||
private function add_image($tmpname, $filename, $tags) {
|
private function add_image($tmpname, $filename, $tags) {
|
||||||
assert ( file_exists ( $tmpname ) );
|
assert ( file_exists ( $tmpname ) );
|
||||||
|
assert('is_string($tags)');
|
||||||
|
|
||||||
$pathinfo = pathinfo ( $filename );
|
$pathinfo = pathinfo ( $filename );
|
||||||
if (! array_key_exists ( 'extension', $pathinfo )) {
|
if (! array_key_exists ( 'extension', $pathinfo )) {
|
||||||
@ -315,7 +320,7 @@ class CronUploader extends Extension {
|
|||||||
$metadata = array();
|
$metadata = array();
|
||||||
$metadata ['filename'] = $pathinfo ['basename'];
|
$metadata ['filename'] = $pathinfo ['basename'];
|
||||||
$metadata ['extension'] = $pathinfo ['extension'];
|
$metadata ['extension'] = $pathinfo ['extension'];
|
||||||
$metadata ['tags'] = ""; // = $tags; doesn't work when not logged in here
|
$metadata ['tags'] = array(); // = $tags; doesn't work when not logged in here
|
||||||
$metadata ['source'] = null;
|
$metadata ['source'] = null;
|
||||||
$event = new DataUploadEvent ( $tmpname, $metadata );
|
$event = new DataUploadEvent ( $tmpname, $metadata );
|
||||||
send_event ( $event );
|
send_event ( $event );
|
||||||
@ -329,7 +334,7 @@ class CronUploader extends Extension {
|
|||||||
|
|
||||||
// Set tags
|
// Set tags
|
||||||
$img = Image::by_id($event->image_id);
|
$img = Image::by_id($event->image_id);
|
||||||
$img->set_tags($tags);
|
$img->set_tags(Tag::explode($tags));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generate_image_queue($base = "", $subdir = "") {
|
private function generate_image_queue($base = "", $subdir = "") {
|
||||||
|
@ -43,10 +43,7 @@ class Handle404 extends Extension {
|
|||||||
private function count_main($blocks) {
|
private function count_main($blocks) {
|
||||||
$n = 0;
|
$n = 0;
|
||||||
foreach($blocks as $block) {
|
foreach($blocks as $block) {
|
||||||
if($block->section == "main") $n++; // more hax.
|
if($block->section == "main" && $block->is_content) $n++; // more hax.
|
||||||
}
|
|
||||||
if(ext_is_live("Chatbox")) {
|
|
||||||
$n--; // even more hax.
|
|
||||||
}
|
}
|
||||||
return $n;
|
return $n;
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,10 @@ class ArchiveFileHandler extends Extension {
|
|||||||
exec($cmd);
|
exec($cmd);
|
||||||
$results = add_dir($tmpdir);
|
$results = add_dir($tmpdir);
|
||||||
if(count($results) > 0) {
|
if(count($results) > 0) {
|
||||||
// FIXME no theme?
|
// Not all themes have the add_status() method, so need to check before calling.
|
||||||
$this->theme->add_status("Adding files", $results);
|
if (method_exists($this->theme, "add_status")) {
|
||||||
|
$this->theme->add_status("Adding files", $results);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
deltree($tmpdir);
|
deltree($tmpdir);
|
||||||
$event->image_id = -2; // default -1 = upload wasn't handled
|
$event->image_id = -2; // default -1 = upload wasn't handled
|
||||||
|
@ -37,7 +37,7 @@ class FlashFileHandler extends DataHandlerExtension {
|
|||||||
$image->hash = $metadata['hash'];
|
$image->hash = $metadata['hash'];
|
||||||
$image->filename = $metadata['filename'];
|
$image->filename = $metadata['filename'];
|
||||||
$image->ext = $metadata['extension'];
|
$image->ext = $metadata['extension'];
|
||||||
$image->tag_array = $metadata['tags'];
|
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
|
||||||
$image->source = $metadata['source'];
|
$image->source = $metadata['source'];
|
||||||
|
|
||||||
$info = getimagesize($filename);
|
$info = getimagesize($filename);
|
||||||
|
@ -67,7 +67,7 @@ class IcoFileHandler extends Extension {
|
|||||||
$image->hash = $metadata['hash'];
|
$image->hash = $metadata['hash'];
|
||||||
$image->filename = $metadata['filename'];
|
$image->filename = $metadata['filename'];
|
||||||
$image->ext = $metadata['extension'];
|
$image->ext = $metadata['extension'];
|
||||||
$image->tag_array = $metadata['tags'];
|
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
|
||||||
$image->source = $metadata['source'];
|
$image->source = $metadata['source'];
|
||||||
|
|
||||||
return $image;
|
return $image;
|
||||||
|
@ -43,7 +43,7 @@ class MP3FileHandler extends DataHandlerExtension {
|
|||||||
$image->filename = $metadata['filename'];
|
$image->filename = $metadata['filename'];
|
||||||
|
|
||||||
$image->ext = $metadata['extension'];
|
$image->ext = $metadata['extension'];
|
||||||
$image->tag_array = $metadata['tags'];
|
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
|
||||||
$image->source = $metadata['source'];
|
$image->source = $metadata['source'];
|
||||||
|
|
||||||
return $image;
|
return $image;
|
||||||
|
@ -35,7 +35,7 @@ class PixelFileHandler extends DataHandlerExtension {
|
|||||||
$image->hash = $metadata['hash'];
|
$image->hash = $metadata['hash'];
|
||||||
$image->filename = (($pos = strpos($metadata['filename'],'?')) !== false) ? substr($metadata['filename'],0,$pos) : $metadata['filename'];
|
$image->filename = (($pos = strpos($metadata['filename'],'?')) !== false) ? substr($metadata['filename'],0,$pos) : $metadata['filename'];
|
||||||
$image->ext = (($pos = strpos($metadata['extension'],'?')) !== false) ? substr($metadata['extension'],0,$pos) : $metadata['extension'];
|
$image->ext = (($pos = strpos($metadata['extension'],'?')) !== false) ? substr($metadata['extension'],0,$pos) : $metadata['extension'];
|
||||||
$image->tag_array = $metadata['tags'];
|
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
|
||||||
$image->source = $metadata['source'];
|
$image->source = $metadata['source'];
|
||||||
|
|
||||||
return $image;
|
return $image;
|
||||||
|
@ -75,7 +75,7 @@ class SVGFileHandler extends Extension {
|
|||||||
$image->hash = $metadata['hash'];
|
$image->hash = $metadata['hash'];
|
||||||
$image->filename = $metadata['filename'];
|
$image->filename = $metadata['filename'];
|
||||||
$image->ext = $metadata['extension'];
|
$image->ext = $metadata['extension'];
|
||||||
$image->tag_array = $metadata['tags'];
|
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
|
||||||
$image->source = $metadata['source'];
|
$image->source = $metadata['source'];
|
||||||
|
|
||||||
return $image;
|
return $image;
|
||||||
|
@ -170,7 +170,7 @@ class VideoFileHandler extends DataHandlerExtension {
|
|||||||
$image->filesize = $metadata['size'];
|
$image->filesize = $metadata['size'];
|
||||||
$image->hash = $metadata['hash'];
|
$image->hash = $metadata['hash'];
|
||||||
$image->filename = $metadata['filename'];
|
$image->filename = $metadata['filename'];
|
||||||
$image->tag_array = $metadata['tags'];
|
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
|
||||||
$image->source = $metadata['source'];
|
$image->source = $metadata['source'];
|
||||||
|
|
||||||
return $image;
|
return $image;
|
||||||
|
@ -9,8 +9,9 @@ class VideoFileHandlerTheme extends Themelet {
|
|||||||
$full_url = make_http($ilink);
|
$full_url = make_http($ilink);
|
||||||
$autoplay = $config->get_bool("video_playback_autoplay");
|
$autoplay = $config->get_bool("video_playback_autoplay");
|
||||||
$loop = $config->get_bool("video_playback_loop");
|
$loop = $config->get_bool("video_playback_loop");
|
||||||
|
$player = make_link('lib/vendor/swf/flashmediaelement.swf');
|
||||||
|
|
||||||
$html = "Video not playing? <a href='" . $image->parse_link_template(make_link('image/$id/$id%20-%20$tags.$ext')) . "'>Click here</a> to download the file.<br/>";
|
$html = "Video not playing? <a href='$ilink'>Click here</a> to download the file.<br/>";
|
||||||
|
|
||||||
//Browser media format support: https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats
|
//Browser media format support: https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats
|
||||||
$supportedExts = ['mp4' => 'video/mp4', 'm4v' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm', 'flv' => 'video/flv'];
|
$supportedExts = ['mp4' => 'video/mp4', 'm4v' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm', 'flv' => 'video/flv'];
|
||||||
@ -22,8 +23,8 @@ class VideoFileHandlerTheme extends Themelet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$html_fallback = "
|
$html_fallback = "
|
||||||
<object width=\"100%\" height=\"480px\" type=\"application/x-shockwave-flash\" data=\"lib/vendor/swf/flashmediaelement.swf\">
|
<object width=\"100%\" height=\"480px\" type=\"application/x-shockwave-flash\" data=\"$player\">
|
||||||
<param name=\"movie\" value=\"lib/vendor/swf/flashmediaelement.swf\" />
|
<param name=\"movie\" value=\"$player\" />
|
||||||
|
|
||||||
<param name=\"allowFullScreen\" value=\"true\" />
|
<param name=\"allowFullScreen\" value=\"true\" />
|
||||||
<param name=\"wmode\" value=\"opaque\" />
|
<param name=\"wmode\" value=\"opaque\" />
|
||||||
|
@ -265,7 +265,7 @@ class Index extends Extension {
|
|||||||
$images = $database->cache->get("post-list:$page_number");
|
$images = $database->cache->get("post-list:$page_number");
|
||||||
if(!$images) {
|
if(!$images) {
|
||||||
$images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms);
|
$images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms);
|
||||||
$database->cache->set("post-list:$page_number", $images, 600);
|
$database->cache->set("post-list:$page_number", $images, 60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -31,7 +31,7 @@ class Oekaki extends Extension {
|
|||||||
$metadata = array();
|
$metadata = array();
|
||||||
$metadata['filename'] = 'oekaki.png';
|
$metadata['filename'] = 'oekaki.png';
|
||||||
$metadata['extension'] = $pathinfo['extension'];
|
$metadata['extension'] = $pathinfo['extension'];
|
||||||
$metadata['tags'] = 'oekaki tagme';
|
$metadata['tags'] = Tag::explode('oekaki tagme');
|
||||||
$metadata['source'] = null;
|
$metadata['source'] = null;
|
||||||
$duev = new DataUploadEvent($tmpname, $metadata);
|
$duev = new DataUploadEvent($tmpname, $metadata);
|
||||||
send_event($duev);
|
send_event($duev);
|
||||||
|
@ -500,7 +500,7 @@ class OuroborosAPI extends Extension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$meta = array();
|
$meta = array();
|
||||||
$meta['tags'] = $post->tags;
|
$meta['tags'] = is_array($post->tags) ? $post->tags : Tag::explode($post->tags);
|
||||||
$meta['source'] = $post->source;
|
$meta['source'] = $post->source;
|
||||||
if (defined('ENABLED_EXTS')) {
|
if (defined('ENABLED_EXTS')) {
|
||||||
if (strstr(ENABLED_EXTS, 'rating') !== false) {
|
if (strstr(ENABLED_EXTS, 'rating') !== false) {
|
||||||
@ -536,7 +536,8 @@ class OuroborosAPI extends Extension
|
|||||||
if (!is_null($img)) {
|
if (!is_null($img)) {
|
||||||
$handler = $config->get_string("upload_collision_handler");
|
$handler = $config->get_string("upload_collision_handler");
|
||||||
if($handler == "merge") {
|
if($handler == "merge") {
|
||||||
$merged = array_merge(Tag::explode($post->tags), $img->get_tag_array());
|
$postTags = is_array($post->tags) ? $post->tags : Tag::explode($post->tags);
|
||||||
|
$merged = array_merge($postTags, $img->get_tag_array());
|
||||||
send_event(new TagSetEvent($img, $merged));
|
send_event(new TagSetEvent($img, $merged));
|
||||||
|
|
||||||
// This is really the only thing besides tags we should care
|
// This is really the only thing besides tags we should care
|
||||||
|
@ -15,13 +15,24 @@
|
|||||||
|
|
||||||
class RegenThumb extends Extension {
|
class RegenThumb extends Extension {
|
||||||
public function onPageRequest(PageRequestEvent $event) {
|
public function onPageRequest(PageRequestEvent $event) {
|
||||||
global $page, $user;
|
global $database, $page, $user;
|
||||||
|
|
||||||
if($event->page_matches("regen_thumb") && $user->can("delete_image") && isset($_POST['image_id'])) {
|
if($event->page_matches("regen_thumb/one") && $user->can("delete_image") && isset($_POST['image_id'])) {
|
||||||
$image = Image::by_id(int_escape($_POST['image_id']));
|
$image = Image::by_id(int_escape($_POST['image_id']));
|
||||||
send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true));
|
send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true));
|
||||||
$this->theme->display_results($page, $image);
|
$this->theme->display_results($page, $image);
|
||||||
}
|
}
|
||||||
|
if($event->page_matches("regen_thumb/mass") && $user->can("delete_image") && isset($_POST['tags'])) {
|
||||||
|
$tags = Tag::explode(strtolower($_POST['tags']), false);
|
||||||
|
$images = Image::find_images(0, 10000, $tags);
|
||||||
|
|
||||||
|
foreach($images as $image) {
|
||||||
|
send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("post/list"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) {
|
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) {
|
||||||
@ -30,5 +41,12 @@ class RegenThumb extends Extension {
|
|||||||
$event->add_part($this->theme->get_buttons_html($event->image->id));
|
$event->add_part($this->theme->get_buttons_html($event->image->id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onPostListBuilding(PostListBuildingEvent $event) {
|
||||||
|
global $user;
|
||||||
|
if($user->can("delete_image") && !empty($event->search_terms)) {
|
||||||
|
$event->add_control($this->theme->mtr_html(implode(" ", $event->search_terms)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ class RegenThumbTheme extends Themelet {
|
|||||||
*/
|
*/
|
||||||
public function get_buttons_html($image_id) {
|
public function get_buttons_html($image_id) {
|
||||||
return "
|
return "
|
||||||
".make_form(make_link("regen_thumb"))."
|
".make_form(make_link("regen_thumb/one"))."
|
||||||
<input type='hidden' name='image_id' value='$image_id'>
|
<input type='hidden' name='image_id' value='$image_id'>
|
||||||
<input type='submit' value='Regenerate Thumbnail'>
|
<input type='submit' value='Regenerate Thumbnail'>
|
||||||
</form>
|
</form>
|
||||||
@ -29,5 +29,15 @@ class RegenThumbTheme extends Themelet {
|
|||||||
$page->add_block(new NavBlock());
|
$page->add_block(new NavBlock());
|
||||||
$page->add_block(new Block("Thumbnail", $this->build_thumb_html($image)));
|
$page->add_block(new Block("Thumbnail", $this->build_thumb_html($image)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function mtr_html($terms) {
|
||||||
|
$h_terms = html_escape($terms);
|
||||||
|
$html = make_form(make_link("regen_thumb/mass"), "POST") . "
|
||||||
|
<input type='hidden' name='tags' value='$h_terms'>
|
||||||
|
<input type='submit' value='Regen all thumbs' onclick='return confirm(\"This can use a lot of CPU time.\\nAre you sure you want to do this?\")'>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class TagList extends Extension {
|
|||||||
$this->theme->display_page($page);
|
$this->theme->display_page($page);
|
||||||
}
|
}
|
||||||
else if($event->page_matches("api/internal/tag_list/complete")) {
|
else if($event->page_matches("api/internal/tag_list/complete")) {
|
||||||
if(!isset($_GET["s"])) return;
|
if(!isset($_GET["s"]) || $_GET["s"] == "" || $_GET["s"] == "_") return;
|
||||||
|
|
||||||
//$limit = 0;
|
//$limit = 0;
|
||||||
$cache_key = "autocomplete-" . strtolower($_GET["s"]);
|
$cache_key = "autocomplete-" . strtolower($_GET["s"]);
|
||||||
@ -269,7 +269,7 @@ class TagList extends Extension {
|
|||||||
$cache_key = data_path("cache/tag_alpha-" . md5("ta" . $tags_min . $starts_with) . ".html");
|
$cache_key = data_path("cache/tag_alpha-" . md5("ta" . $tags_min . $starts_with) . ".html");
|
||||||
if(file_exists($cache_key)) {return file_get_contents($cache_key);}
|
if(file_exists($cache_key)) {return file_get_contents($cache_key);}
|
||||||
|
|
||||||
$tag_data = $database->get_all($database->scoreql_to_sql("
|
$tag_data = $database->get_pairs($database->scoreql_to_sql("
|
||||||
SELECT tag, count
|
SELECT tag, count
|
||||||
FROM tags
|
FROM tags
|
||||||
WHERE count >= :tags_min
|
WHERE count >= :tags_min
|
||||||
@ -296,8 +296,10 @@ class TagList extends Extension {
|
|||||||
mb_internal_encoding('UTF-8');
|
mb_internal_encoding('UTF-8');
|
||||||
|
|
||||||
$lastLetter = "";
|
$lastLetter = "";
|
||||||
foreach($tag_data as $row) {
|
# postres utf8 string sort ignores punctuation, so we get "aza, a-zb, azc"
|
||||||
$tag = $row['tag'];
|
# which breaks down into "az, a-, az" :(
|
||||||
|
ksort($tag_data, SORT_STRING | SORT_FLAG_CASE);
|
||||||
|
foreach($tag_data as $tag => $count) {
|
||||||
if($lastLetter != mb_strtolower(substr($tag, 0, count($starts_with)+1))) {
|
if($lastLetter != mb_strtolower(substr($tag, 0, count($starts_with)+1))) {
|
||||||
$lastLetter = mb_strtolower(substr($tag, 0, count($starts_with)+1));
|
$lastLetter = mb_strtolower(substr($tag, 0, count($starts_with)+1));
|
||||||
$h_lastLetter = html_escape($lastLetter);
|
$h_lastLetter = html_escape($lastLetter);
|
||||||
@ -305,7 +307,6 @@ class TagList extends Extension {
|
|||||||
}
|
}
|
||||||
$link = $this->tag_link($tag);
|
$link = $this->tag_link($tag);
|
||||||
$h_tag = html_escape($tag);
|
$h_tag = html_escape($tag);
|
||||||
$count = $row['count'];
|
|
||||||
$html .= "<a href='$link'>$h_tag ($count)</a>\n";
|
$html .= "<a href='$link'>$h_tag ($count)</a>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,11 +30,9 @@ class ViewImageTheme extends Themelet {
|
|||||||
|
|
||||||
protected function build_pin(Image $image) {
|
protected function build_pin(Image $image) {
|
||||||
if(isset($_GET['search'])) {
|
if(isset($_GET['search'])) {
|
||||||
$search_terms = explode(' ', $_GET['search']);
|
|
||||||
$query = "search=".url_escape($_GET['search']);
|
$query = "search=".url_escape($_GET['search']);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$search_terms = array();
|
|
||||||
$query = null;
|
$query = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit_Framework_TestCase {
|
|||||||
// post things
|
// post things
|
||||||
/**
|
/**
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @param string|string[] $tags
|
* @param string $tags
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function post_image($filename, $tags) {
|
protected function post_image($filename, $tags) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user