formatting

This commit is contained in:
Shish 2019-11-02 19:57:34 +00:00
parent aabc69033b
commit 55c6854003
29 changed files with 128 additions and 106 deletions

View file

@ -186,7 +186,7 @@ class Database
public function execute(string $query, array $args=[], bool $scoreql = false): PDOStatement public function execute(string $query, array $args=[], bool $scoreql = false): PDOStatement
{ {
try { try {
if($scoreql===true) { if ($scoreql===true) {
$query = $this->scoreql_to_sql($query); $query = $this->scoreql_to_sql($query);
} }
@ -222,7 +222,7 @@ class Database
*/ */
public function get_all(string $query, array $args=[], bool $scoreql = false): array public function get_all(string $query, array $args=[], bool $scoreql = false): array
{ {
if($scoreql===true) { if ($scoreql===true) {
$query = $this->scoreql_to_sql($query); $query = $this->scoreql_to_sql($query);
} }
@ -237,7 +237,7 @@ class Database
*/ */
public function get_all_iterable(string $query, array $args=[], bool $scoreql = false): PDOStatement public function get_all_iterable(string $query, array $args=[], bool $scoreql = false): PDOStatement
{ {
if($scoreql===true) { if ($scoreql===true) {
$query = $this->scoreql_to_sql($query); $query = $this->scoreql_to_sql($query);
} }
$_start = microtime(true); $_start = microtime(true);
@ -251,7 +251,7 @@ class Database
*/ */
public function get_row(string $query, array $args=[], bool $scoreql = false): ?array public function get_row(string $query, array $args=[], bool $scoreql = false): ?array
{ {
if($scoreql===true) { if ($scoreql===true) {
$query = $this->scoreql_to_sql($query); $query = $this->scoreql_to_sql($query);
} }
$_start = microtime(true); $_start = microtime(true);
@ -266,7 +266,7 @@ class Database
*/ */
public function exists(string $query, array $args=[], bool $scoreql = false): bool public function exists(string $query, array $args=[], bool $scoreql = false): bool
{ {
if($scoreql===true) { if ($scoreql===true) {
$query = $this->scoreql_to_sql($query); $query = $this->scoreql_to_sql($query);
} }
$_start = microtime(true); $_start = microtime(true);
@ -280,7 +280,7 @@ class Database
*/ */
public function get_col(string $query, array $args=[], bool $scoreql = false): array public function get_col(string $query, array $args=[], bool $scoreql = false): array
{ {
if($scoreql===true) { if ($scoreql===true) {
$query = $this->scoreql_to_sql($query); $query = $this->scoreql_to_sql($query);
} }
$_start = microtime(true); $_start = microtime(true);
@ -294,7 +294,7 @@ class Database
*/ */
public function get_col_iterable(string $query, array $args=[], bool $scoreql = false): Generator public function get_col_iterable(string $query, array $args=[], bool $scoreql = false): Generator
{ {
if($scoreql===true) { if ($scoreql===true) {
$query = $this->scoreql_to_sql($query); $query = $this->scoreql_to_sql($query);
} }
$_start = microtime(true); $_start = microtime(true);
@ -310,7 +310,7 @@ class Database
*/ */
public function get_pairs(string $query, array $args=[], bool $scoreql = false): array public function get_pairs(string $query, array $args=[], bool $scoreql = false): array
{ {
if($scoreql===true) { if ($scoreql===true) {
$query = $this->scoreql_to_sql($query); $query = $this->scoreql_to_sql($query);
} }
$_start = microtime(true); $_start = microtime(true);
@ -324,7 +324,7 @@ class Database
*/ */
public function get_one(string $query, array $args=[], bool $scoreql = false) public function get_one(string $query, array $args=[], bool $scoreql = false)
{ {
if($scoreql===true) { if ($scoreql===true) {
$query = $this->scoreql_to_sql($query); $query = $this->scoreql_to_sql($query);
} }
$_start = microtime(true); $_start = microtime(true);

View file

@ -34,7 +34,7 @@ abstract class DBEngine
return 'CREATE TABLE '.$name.' ('.$data.')'; return 'CREATE TABLE '.$name.' ('.$data.')';
} }
public abstract function set_timeout(PDO $db, int $time); abstract public function set_timeout(PDO $db, int $time);
} }
class MySQL extends DBEngine class MySQL extends DBEngine
@ -76,7 +76,6 @@ class MySQL extends DBEngine
// These only apply to read-only queries, which appears to be the best we can to mysql-wise // These only apply to read-only queries, which appears to be the best we can to mysql-wise
$db->exec("SET SESSION MAX_EXECUTION_TIME=".$time.";"); $db->exec("SET SESSION MAX_EXECUTION_TIME=".$time.";");
} }
} }
class PostgreSQL extends DBEngine class PostgreSQL extends DBEngine
@ -123,7 +122,6 @@ class PostgreSQL extends DBEngine
{ {
$db->exec("SET statement_timeout TO ".$time.";"); $db->exec("SET statement_timeout TO ".$time.";");
} }
} }
// shimmie functions for export to sqlite // shimmie functions for export to sqlite

View file

@ -151,7 +151,7 @@ class Image
if (!$result) { if (!$result) {
$querylet = Image::build_search_querylet($tag_conditions, $img_conditions); $querylet = Image::build_search_querylet($tag_conditions, $img_conditions);
$querylet->append(new Querylet(" ORDER BY ".(Image::$order_sql ?: "images.".$config->get_string(IndexConfig::ORDER)))); $querylet->append(new Querylet(" ORDER BY ".(Image::$order_sql ?: "images.".$config->get_string(IndexConfig::ORDER))));
if($limit!=null) { if ($limit!=null) {
$querylet->append(new Querylet(" LIMIT :limit ", ["limit" => $limit])); $querylet->append(new Querylet(" LIMIT :limit ", ["limit" => $limit]));
$querylet->append(new Querylet(" OFFSET :offset ", ["offset"=>$start])); $querylet->append(new Querylet(" OFFSET :offset ", ["offset"=>$start]));
} }
@ -730,9 +730,11 @@ class Image
"INSERT INTO tags(tag) VALUES (:tag)", "INSERT INTO tags(tag) VALUES (:tag)",
["tag"=>$tag] ["tag"=>$tag]
); );
$database->execute($database->scoreql_to_sql( $database->execute(
$database->scoreql_to_sql(
"INSERT INTO image_tags(image_id, tag_id) "INSERT INTO image_tags(image_id, tag_id)
VALUES(:id, (SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)))"), VALUES(:id, (SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)))"
),
["id"=>$this->id, "tag"=>$tag] ["id"=>$this->id, "tag"=>$tag]
); );
} else { } else {

View file

@ -101,18 +101,18 @@ class Tag
public static function compare(array $tags1, array $tags2): bool public static function compare(array $tags1, array $tags2): bool
{ {
if(count($tags1)!==count($tags2)) { if (count($tags1)!==count($tags2)) {
return false; return false;
} }
$tags1 = array_map("strtolower",$tags1); $tags1 = array_map("strtolower", $tags1);
$tags2 = array_map("strtolower",$tags2); $tags2 = array_map("strtolower", $tags2);
natcasesort($tags1); natcasesort($tags1);
natcasesort($tags2); natcasesort($tags2);
for($i = 0; $i < count($tags1); $i++) { for ($i = 0; $i < count($tags1); $i++) {
if($tags1[$i]!==$tags2[$i]) { if ($tags1[$i]!==$tags2[$i]) {
var_dump($tags1); var_dump($tags1);
var_dump($tags2); var_dump($tags2);
return false; return false;
@ -140,7 +140,7 @@ class Tag
foreach ($tags as $tag) { foreach ($tags as $tag) {
try { try {
$tag = Tag::sanitize($tag); $tag = Tag::sanitize($tag);
} catch(Exception $e) { } catch (Exception $e) {
flash_message($e->getMessage()); flash_message($e->getMessage());
continue; continue;
} }

View file

@ -83,5 +83,4 @@ abstract class Permissions
public const CRON_ADMIN = "cron_admin"; public const CRON_ADMIN = "cron_admin";
public const APPROVE_IMAGE = "approve_image"; public const APPROVE_IMAGE = "approve_image";
public const APPROVE_COMMENT = "approve_comment"; public const APPROVE_COMMENT = "approve_comment";
} }

View file

@ -352,16 +352,18 @@ function join_url(string $base, string ...$paths)
function get_dir_contents(string $dir): array function get_dir_contents(string $dir): array
{ {
if(empty($dir)) { if (empty($dir)) {
throw new Exception("dir required"); throw new Exception("dir required");
} }
if(!is_dir($dir)) { if (!is_dir($dir)) {
return []; return [];
} }
$results = array_diff( $results = array_diff(
scandir( scandir(
$dir), $dir
['..', '.']); ),
['..', '.']
);
return $results; return $results;
} }
@ -378,7 +380,8 @@ function scan_dir(string $path): array
$path, $path,
FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::KEY_AS_PATHNAME |
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::CURRENT_AS_FILEINFO |
FilesystemIterator::SKIP_DOTS); FilesystemIterator::SKIP_DOTS
);
foreach (new RecursiveIteratorIterator($ite) as $filename => $cur) { foreach (new RecursiveIteratorIterator($ite) as $filename => $cur) {
try { try {
$filesize = $cur->getSize(); $filesize = $cur->getSize();

View file

@ -74,20 +74,23 @@ class Approval extends Extension
$action = $event->action; $action = $event->action;
$event->redirect = true; $event->redirect = true;
if($action==="approval") { if ($action==="approval") {
$approval_action = $_POST["approval_action"]; $approval_action = $_POST["approval_action"];
switch ($approval_action) { switch ($approval_action) {
case "approve_all": case "approve_all":
$database->set_timeout(300000); // These updates can take a little bit $database->set_timeout(300000); // These updates can take a little bit
$database->execute($database->scoreql_to_sql( $database->execute(
"UPDATE images SET approved = SCORE_BOOL_Y, approved_by_id = :approved_by_id WHERE approved = SCORE_BOOL_N"), $database->scoreql_to_sql(
"UPDATE images SET approved = SCORE_BOOL_Y, approved_by_id = :approved_by_id WHERE approved = SCORE_BOOL_N"
),
["approved_by_id"=>$user->id] ["approved_by_id"=>$user->id]
); );
break; break;
case "disapprove_all": case "disapprove_all":
$database->set_timeout(300000); // These updates can take a little bit $database->set_timeout(300000); // These updates can take a little bit
$database->execute($database->scoreql_to_sql( $database->execute($database->scoreql_to_sql(
"UPDATE images SET approved = SCORE_BOOL_N, approved_by_id = NULL WHERE approved = SCORE_BOOL_Y")); "UPDATE images SET approved = SCORE_BOOL_N, approved_by_id = NULL WHERE approved = SCORE_BOOL_Y"
));
break; break;
default: default:
@ -100,7 +103,7 @@ class Approval extends Extension
{ {
global $user, $page, $config; global $user, $page, $config;
if ( $config->get_bool(ApprovalConfig::IMAGES) && $event->image->approved===false && !$user->can(Permissions::APPROVE_IMAGE)) { if ($config->get_bool(ApprovalConfig::IMAGES) && $event->image->approved===false && !$user->can(Permissions::APPROVE_IMAGE)) {
$page->set_mode(PageMode::REDIRECT); $page->set_mode(PageMode::REDIRECT);
$page->set_redirect(make_link("post/list")); $page->set_redirect(make_link("post/list"));
} }
@ -109,9 +112,9 @@ class Approval extends Extension
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) public function onPageSubNavBuilding(PageSubNavBuildingEvent $event)
{ {
global $user; global $user;
if($event->parent=="posts") { if ($event->parent=="posts") {
if($user->can(Permissions::APPROVE_IMAGE)) { if ($user->can(Permissions::APPROVE_IMAGE)) {
$event->add_nav_link("posts_unapproved", new Link('/post/list/approved%3Ano/1'), "Pending Approval",null, 60); $event->add_nav_link("posts_unapproved", new Link('/post/list/approved%3Ano/1'), "Pending Approval", null, 60);
} }
} }
} }
@ -122,7 +125,7 @@ class Approval extends Extension
{ {
global $user, $database, $config; global $user, $database, $config;
if($config->get_bool(ApprovalConfig::IMAGES)) { if ($config->get_bool(ApprovalConfig::IMAGES)) {
$matches = []; $matches = [];
if (is_null($event->term) && $this->no_approval_query($event->context)) { if (is_null($event->term) && $this->no_approval_query($event->context)) {
@ -168,8 +171,10 @@ class Approval extends Extension
{ {
global $database, $user; global $database, $user;
$database->execute($database->scoreql_to_sql( $database->execute(
"UPDATE images SET approved = SCORE_BOOL_Y, approved_by_id = :approved_by_id WHERE id = :id AND approved = SCORE_BOOL_N"), $database->scoreql_to_sql(
"UPDATE images SET approved = SCORE_BOOL_Y, approved_by_id = :approved_by_id WHERE id = :id AND approved = SCORE_BOOL_N"
),
["approved_by_id"=>$user->id, "id"=>$image_id] ["approved_by_id"=>$user->id, "id"=>$image_id]
); );
} }
@ -178,8 +183,10 @@ class Approval extends Extension
{ {
global $database, $user; global $database, $user;
$database->execute($database->scoreql_to_sql( $database->execute(
"UPDATE images SET approved = SCORE_BOOL_N, approved_by_id = NULL WHERE id = :id AND approved = SCORE_BOOL_Y"), $database->scoreql_to_sql(
"UPDATE images SET approved = SCORE_BOOL_N, approved_by_id = NULL WHERE id = :id AND approved = SCORE_BOOL_Y"
),
["id"=>$image_id] ["id"=>$image_id]
); );
} }
@ -187,7 +194,7 @@ class Approval extends Extension
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event)
{ {
global $user, $config; global $user, $config;
if($user->can(Permissions::APPROVE_IMAGE) && $config->get_bool(ApprovalConfig::IMAGES)) { if ($user->can(Permissions::APPROVE_IMAGE) && $config->get_bool(ApprovalConfig::IMAGES)) {
$event->add_part($this->theme->get_image_admin_html($event->image)); $event->add_part($this->theme->get_image_admin_html($event->image));
} }
} }
@ -197,7 +204,7 @@ class Approval extends Extension
global $user, $config; global $user, $config;
if ($user->can(Permissions::APPROVE_IMAGE)&& $config->get_bool(ApprovalConfig::IMAGES)) { if ($user->can(Permissions::APPROVE_IMAGE)&& $config->get_bool(ApprovalConfig::IMAGES)) {
if(in_array("approved:no", $event->search_terms)) { if (in_array("approved:no", $event->search_terms)) {
$event->add_action("bulk_approve_image", "Approve", "a"); $event->add_action("bulk_approve_image", "Approve", "a");
} else { } else {
$event->add_action("bulk_disapprove_image", "Disapprove"); $event->add_action("bulk_disapprove_image", "Disapprove");

View file

@ -4,7 +4,7 @@ class ApprovalTheme extends Themelet
{ {
public function get_image_admin_html(Image $image) public function get_image_admin_html(Image $image)
{ {
if($image->approved===true) { if ($image->approved===true) {
$html = " $html = "
".make_form(make_link('disapprove_image/'.$image->id), 'POST')." ".make_form(make_link('disapprove_image/'.$image->id), 'POST')."
<input type='hidden' name='image_id' value='$image->id'> <input type='hidden' name='image_id' value='$image->id'>

View file

@ -905,7 +905,7 @@ class Artists extends Extension
$pageNumber * $artistsPerPage $pageNumber * $artistsPerPage
, $artistsPerPage , $artistsPerPage
] ]
); );
$number_of_listings = count($listing); $number_of_listings = count($listing);

View file

@ -123,7 +123,7 @@ class BulkRemove extends Extension
$page->add_block(new Block( $page->add_block(new Block(
"Bulk Remove Error", "Bulk Remove Error",
"Please use Board Admin to use bulk remove." "Please use Board Admin to use bulk remove."
)); ));
} }
// //

View file

@ -22,7 +22,6 @@ abstract class CronUploaderConfig
$config->set_string(self::KEY, $upload_key); $config->set_string(self::KEY, $upload_key);
} }
} }
public static function get_user(): int public static function get_user(): int

View file

@ -22,7 +22,7 @@ class CronUploader extends Extension
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) public function onPageSubNavBuilding(PageSubNavBuildingEvent $event)
{ {
if($event->parent=="system") { if ($event->parent=="system") {
$event->add_nav_link("cron_docs", new Link('cron_upload'), "Cron Upload"); $event->add_nav_link("cron_docs", new Link('cron_upload'), "Cron Upload");
} }
} }
@ -58,7 +58,7 @@ class CronUploader extends Extension
$sb->add_int_option(CronUploaderConfig::COUNT, "Upload per run", true); $sb->add_int_option(CronUploaderConfig::COUNT, "Upload per run", true);
$sb->add_text_option(CronUploaderConfig::DIR, "Root dir", true); $sb->add_text_option(CronUploaderConfig::DIR, "Root dir", true);
$sb->add_text_option(CronUploaderConfig::KEY, "Key", true); $sb->add_text_option(CronUploaderConfig::KEY, "Key", true);
$sb->add_choice_option(CronUploaderConfig::USER, $users,"User", true); $sb->add_choice_option(CronUploaderConfig::USER, $users, "User", true);
$sb->end_table(); $sb->end_table();
$sb->add_label("<a href='$documentation_link'>Read the documentation</a> for cron setup instructions."); $sb->add_label("<a href='$documentation_link'>Read the documentation</a> for cron setup instructions.");
@ -130,7 +130,7 @@ class CronUploader extends Extension
$results = get_dir_contents($stage_dir); $results = get_dir_contents($stage_dir);
if (count($results) == 0) { if (count($results) == 0) {
if(rmdir($stage_dir)===false) { if (rmdir($stage_dir)===false) {
flash_message("Nothing to stage from $folder, cannot remove folder"); flash_message("Nothing to stage from $folder, cannot remove folder");
} else { } else {
flash_message("Nothing to stage from $folder, removing folder"); flash_message("Nothing to stage from $folder, removing folder");
@ -203,24 +203,29 @@ class CronUploader extends Extension
} }
$this->theme->display_documentation( $this->theme->display_documentation(
$running, $queue_dirinfo, $uploaded_dirinfo, $failed_dirinfo, $running,
$this->get_cron_cmd(), $this->get_cron_url(), $logs $queue_dirinfo,
$uploaded_dirinfo,
$failed_dirinfo,
$this->get_cron_cmd(),
$this->get_cron_url(),
$logs
); );
} }
function get_queue_dir() public function get_queue_dir()
{ {
$dir = CronUploaderConfig::get_dir(); $dir = CronUploaderConfig::get_dir();
return join_path($dir, self::QUEUE_DIR); return join_path($dir, self::QUEUE_DIR);
} }
function get_uploaded_dir() public function get_uploaded_dir()
{ {
$dir = CronUploaderConfig::get_dir(); $dir = CronUploaderConfig::get_dir();
return join_path($dir, self::UPLOADED_DIR); return join_path($dir, self::UPLOADED_DIR);
} }
function get_failed_dir() public function get_failed_dir()
{ {
$dir = CronUploaderConfig::get_dir(); $dir = CronUploaderConfig::get_dir();
return join_path($dir, self::FAILED_DIR); return join_path($dir, self::FAILED_DIR);
@ -262,7 +267,7 @@ class CronUploader extends Extension
throw new SCoreException("Cron upload key incorrect"); throw new SCoreException("Cron upload key incorrect");
} }
$user_id = CronUploaderConfig::get_user(); $user_id = CronUploaderConfig::get_user();
if(empty($user_id)) { if (empty($user_id)) {
throw new SCoreException("Cron upload user not set"); throw new SCoreException("Cron upload user not set");
} }
$user = User::by_id($user_id); $user = User::by_id($user_id);
@ -329,8 +334,6 @@ class CronUploader extends Extension
$this->move_uploaded($img[0], $img[1], $output_subdir, true); $this->move_uploaded($img[0], $img[1], $output_subdir, true);
$this->log_message(SCORE_LOG_ERROR, "(" . gettype($e) . ") " . $e->getMessage()); $this->log_message(SCORE_LOG_ERROR, "(" . gettype($e) . ") " . $e->getMessage());
$this->log_message(SCORE_LOG_ERROR, $e->getTraceAsString()); $this->log_message(SCORE_LOG_ERROR, $e->getTraceAsString());
} }
} }
@ -348,14 +351,13 @@ class CronUploader extends Extension
flock($lockfile, LOCK_UN); flock($lockfile, LOCK_UN);
fclose($lockfile); fclose($lockfile);
} }
} }
private function move_uploaded(string $path, string $filename, string $output_subdir, bool $corrupt = false) private function move_uploaded(string $path, string $filename, string $output_subdir, bool $corrupt = false)
{ {
$relativeDir = dirname(substr($path, strlen(CronUploaderConfig::get_dir()) + 7)); $relativeDir = dirname(substr($path, strlen(CronUploaderConfig::get_dir()) + 7));
if($relativeDir==".") { if ($relativeDir==".") {
$relativeDir = ""; $relativeDir = "";
} }
@ -424,10 +426,11 @@ class CronUploader extends Extension
private const PARTIAL_DOWNLOAD_EXTENSIONS = ['crdownload','part']; private const PARTIAL_DOWNLOAD_EXTENSIONS = ['crdownload','part'];
private function is_skippable_file(string $path) { private function is_skippable_file(string $path)
{
$info = pathinfo($path); $info = pathinfo($path);
if(in_array(strtolower($info['extension']),self::PARTIAL_DOWNLOAD_EXTENSIONS)) { if (in_array(strtolower($info['extension']), self::PARTIAL_DOWNLOAD_EXTENSIONS)) {
return true; return true;
} }
@ -499,4 +502,3 @@ class CronUploader extends Extension
$page->set_data(implode("\r\n", $this->output_buffer)); $page->set_data(implode("\r\n", $this->output_buffer));
} }
} }

View file

@ -2,9 +2,15 @@
class CronUploaderTheme extends Themelet class CronUploaderTheme extends Themelet
{ {
public function display_documentation(bool $running, array $queue_dirinfo, array $uploaded_dirinfo, array $failed_dirinfo, public function display_documentation(
string $cron_cmd, string $cron_url, ?array $log_entries) bool $running,
{ array $queue_dirinfo,
array $uploaded_dirinfo,
array $failed_dirinfo,
string $cron_cmd,
string $cron_url,
?array $log_entries
) {
global $page; global $page;
@ -51,7 +57,7 @@ class CronUploaderTheme extends Themelet
<br />When you create the cron job, you choose when to upload new images.</li> <br />When you create the cron job, you choose when to upload new images.</li>
</ol>"; </ol>";
$usage_html = "Upload your images you want to be uploaded to the queue directory using your FTP client or other means. $usage_html = "Upload your images you want to be uploaded to the queue directory using your FTP client or other means.
<br />(<b>{$queue_dirinfo['path']}</b>) <br />(<b>{$queue_dirinfo['path']}</b>)
<ol> <ol>
<li>Any sub-folders will be turned into tags.</li> <li>Any sub-folders will be turned into tags.</li>
@ -81,9 +87,9 @@ class CronUploaderTheme extends Themelet
$page->add_block($block_install); $page->add_block($block_install);
$page->add_block($block_usage); $page->add_block($block_usage);
if(!empty($log_entries)) { if (!empty($log_entries)) {
$log_html = "<table class='log'>"; $log_html = "<table class='log'>";
foreach($log_entries as $entry) { foreach ($log_entries as $entry) {
$log_html .= "<tr><th>{$entry["date_sent"]}</th><td>{$entry["message"]}</td></tr>"; $log_html .= "<tr><th>{$entry["date_sent"]}</th><td>{$entry["message"]}</td></tr>";
} }
$log_html .= "</table>"; $log_html .= "</table>";
@ -111,13 +117,13 @@ class CronUploaderTheme extends Themelet
$html .= "<tr><td colspan='2'><input type='submit' value='Re-stage files to queue' /></td></tr>"; $html .= "<tr><td colspan='2'><input type='submit' value='Re-stage files to queue' /></td></tr>";
$html .= "</table></form>"; $html .= "</table></form>";
$html .= make_form(make_link("admin/cron_uploader_clear_queue"), "POST",false,"","return confirm('Are you sure you want to delete everything in the queue folder?');") $html .= make_form(make_link("admin/cron_uploader_clear_queue"), "POST", false, "", "return confirm('Are you sure you want to delete everything in the queue folder?');")
."<table class='form'><tr><td>" ."<table class='form'><tr><td>"
."<input type='submit' value='Clear queue folder'></td></tr></table></form>"; ."<input type='submit' value='Clear queue folder'></td></tr></table></form>";
$html .= make_form(make_link("admin/cron_uploader_clear_uploaded"), "POST",false,"","return confirm('Are you sure you want to delete everything in the uploaded folder?');") $html .= make_form(make_link("admin/cron_uploader_clear_uploaded"), "POST", false, "", "return confirm('Are you sure you want to delete everything in the uploaded folder?');")
."<table class='form'><tr><td>" ."<table class='form'><tr><td>"
."<input type='submit' value='Clear uploaded folder'></td></tr></table></form>"; ."<input type='submit' value='Clear uploaded folder'></td></tr></table></form>";
$html .= make_form(make_link("admin/cron_uploader_clear_failed"), "POST",false,"","return confirm('Are you sure you want to delete everything in the failed folder?');") $html .= make_form(make_link("admin/cron_uploader_clear_failed"), "POST", false, "", "return confirm('Are you sure you want to delete everything in the failed folder?');")
."<table class='form'><tr><td>" ."<table class='form'><tr><td>"
."<input type='submit' value='Clear failed folder'></td></tr></table></form>"; ."<input type='submit' value='Clear failed folder'></td></tr></table></form>";
$html .= "</table>\n"; $html .= "</table>\n";

View file

@ -90,8 +90,10 @@ class DanbooruApi extends Extension
} elseif (isset($_GET['name'])) { } elseif (isset($_GET['name'])) {
$namelist = explode(",", $_GET['name']); $namelist = explode(",", $_GET['name']);
foreach ($namelist as $name) { foreach ($namelist as $name) {
$sqlresult = $database->get_all($database->scoreql_to_sql( $sqlresult = $database->get_all(
"SELECT id,tag,count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)"), $database->scoreql_to_sql(
"SELECT id,tag,count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)"
),
[$name] [$name]
); );
foreach ($sqlresult as $row) { foreach ($sqlresult as $row) {

View file

@ -66,6 +66,6 @@ class DowntimeTheme extends Themelet
</body> </body>
</html> </html>
EOD EOD
); );
} }
} }

View file

@ -242,7 +242,7 @@ class Favorites extends Extension
{ {
global $database; global $database;
if ($do_set) { if ($do_set) {
if(!$database->exists("select 1 from user_favorites where image_id=:image_id and user_id=:user_id",["image_id"=>$image_id, "user_id"=>$user_id])) { if (!$database->exists("select 1 from user_favorites where image_id=:image_id and user_id=:user_id", ["image_id"=>$image_id, "user_id"=>$user_id])) {
$database->Execute( $database->Execute(
"INSERT INTO user_favorites(image_id, user_id, created_at) VALUES(:image_id, :user_id, NOW())", "INSERT INTO user_favorites(image_id, user_id, created_at) VALUES(:image_id, :user_id, NOW())",
["image_id"=>$image_id, "user_id"=>$user_id] ["image_id"=>$image_id, "user_id"=>$user_id]

View file

@ -269,7 +269,7 @@ class Forum extends Extension
"GROUP BY f.id, f.sticky, f.title, f.date, u.name, u.email, u.class ". "GROUP BY f.id, f.sticky, f.title, f.date, u.name, u.email, u.class ".
"ORDER BY f.sticky ASC, f.uptodate DESC LIMIT :limit OFFSET :offset", "ORDER BY f.sticky ASC, f.uptodate DESC LIMIT :limit OFFSET :offset",
["limit"=>$threadsPerPage, "offset"=>$pageNumber * $threadsPerPage] ["limit"=>$threadsPerPage, "offset"=>$pageNumber * $threadsPerPage]
); );
$this->theme->display_thread_list($page, $threads, $showAdminOptions, $pageNumber + 1, $totalPages); $this->theme->display_thread_list($page, $threads, $showAdminOptions, $pageNumber + 1, $totalPages);
} }
@ -302,7 +302,7 @@ class Forum extends Extension
"ORDER BY p.date ASC ". "ORDER BY p.date ASC ".
"LIMIT :limit OFFSET :offset", "LIMIT :limit OFFSET :offset",
["thread_id"=>$threadID, "offset"=>$pageNumber * $postsPerPage, "limit"=>$postsPerPage] ["thread_id"=>$threadID, "offset"=>$pageNumber * $postsPerPage, "limit"=>$postsPerPage]
); );
$this->theme->display_thread($posts, $showAdminOptions, $threadTitle, $threadID, $pageNumber + 1, $totalPages); $this->theme->display_thread($posts, $showAdminOptions, $threadTitle, $threadID, $pageNumber + 1, $totalPages);
} }

View file

@ -37,7 +37,7 @@ class HelpPages extends Extension
private function get_pages(): array private function get_pages(): array
{ {
if($this->pages==null) { if ($this->pages==null) {
$e = new HelpPageListBuildingEvent(); $e = new HelpPageListBuildingEvent();
send_event($e); send_event($e);
$this->pages = $e->pages; $this->pages = $e->pages;
@ -52,8 +52,6 @@ class HelpPages extends Extension
$pages = $this->get_pages(); $pages = $this->get_pages();
if ($event->page_matches("help")) { if ($event->page_matches("help")) {
if ($event->count_args() == 0) { if ($event->count_args() == 0) {
$name = array_key_first($pages); $name = array_key_first($pages);
$page->set_mode(PageMode::REDIRECT); $page->set_mode(PageMode::REDIRECT);
@ -63,7 +61,7 @@ class HelpPages extends Extension
$page->set_mode(PageMode::PAGE); $page->set_mode(PageMode::PAGE);
$name = $event->get_arg(0); $name = $event->get_arg(0);
$title = $name; $title = $name;
if(array_key_exists($name, $pages)) { if (array_key_exists($name, $pages)) {
$title = $pages[$name]; $title = $pages[$name];
} else { } else {
return; return;
@ -97,10 +95,10 @@ class HelpPages extends Extension
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) public function onPageSubNavBuilding(PageSubNavBuildingEvent $event)
{ {
if($event->parent=="help") { if ($event->parent=="help") {
$pages = $this->get_pages(); $pages = $this->get_pages();
foreach ($pages as $key=>$value) { foreach ($pages as $key=>$value) {
$event->add_nav_link("help_".$key, new Link('help/'.$key),$value); $event->add_nav_link("help_".$key, new Link('help/'.$key), $value);
} }
} }
} }

View file

@ -22,7 +22,7 @@ class HomeTheme extends Themelet
</body> </body>
</html> </html>
EOD EOD
); );
} }
public function build_body(string $sitename, string $main_links, string $main_text, string $contact_link, $num_comma, string $counter_text) public function build_body(string $sitename, string $main_links, string $main_text, string $contact_link, $num_comma, string $counter_text)

View file

@ -6,5 +6,4 @@ abstract class MediaConfig
const CONVERT_PATH = "media_convert_path"; const CONVERT_PATH = "media_convert_path";
const VERSION = "ext_media_version"; const VERSION = "ext_media_version";
const MEM_LIMIT = 'media_mem_limit'; const MEM_LIMIT = 'media_mem_limit';
} }

View file

@ -14,14 +14,19 @@ class MediaResizeEvent extends Event
public $ignore_aspect_ratio; public $ignore_aspect_ratio;
public $allow_upscale; public $allow_upscale;
public function __construct(String $engine, string $input_path, string $input_type, string $output_path, public function __construct(
int $target_width, int $target_height, String $engine,
bool $ignore_aspect_ratio = false, string $input_path,
string $target_format = null, string $input_type,
int $target_quality = 80, string $output_path,
bool $minimize = false, int $target_width,
bool $allow_upscale = true) int $target_height,
{ bool $ignore_aspect_ratio = false,
string $target_format = null,
int $target_quality = 80,
bool $minimize = false,
bool $allow_upscale = true
) {
assert(in_array($engine, MediaEngine::ALL)); assert(in_array($engine, MediaEngine::ALL));
$this->engine = $engine; $this->engine = $engine;
$this->input_path = $input_path; $this->input_path = $input_path;
@ -54,5 +59,4 @@ class MediaCheckPropertiesEvent extends Event
$this->file_name = $file_name; $this->file_name = $file_name;
$this->ext = $ext; $this->ext = $ext;
} }
} }

View file

@ -265,7 +265,7 @@ class Media extends Extension
$matches = []; $matches = [];
if (preg_match(self::CONTENT_SEARCH_TERM_REGEX, $event->term, $matches)) { if (preg_match(self::CONTENT_SEARCH_TERM_REGEX, $event->term, $matches)) {
$field = $matches[1]; $field = $matches[1];
if($field==="unknown") { if ($field==="unknown") {
$event->add_querylet(new Querylet($database->scoreql_to_sql("video IS NULL OR audio IS NULL OR image IS NULL"))); $event->add_querylet(new Querylet($database->scoreql_to_sql("video IS NULL OR audio IS NULL OR image IS NULL")));
} else { } else {
$event->add_querylet(new Querylet($database->scoreql_to_sql("$field = SCORE_BOOL_Y"))); $event->add_querylet(new Querylet($database->scoreql_to_sql("$field = SCORE_BOOL_Y")));
@ -814,7 +814,7 @@ class Media extends Extension
$new_height, $new_height,
$width, $width,
$height $height
) === false) { ) === false) {
throw new MediaException("Unable to copy resized image data to new image"); throw new MediaException("Unable to copy resized image data to new image");
} }
@ -1039,7 +1039,7 @@ class Media extends Extension
"ALTER TABLE images ADD COLUMN image SCORE_BOOL NULL" "ALTER TABLE images ADD COLUMN image SCORE_BOOL NULL"
)); ));
switch($database->get_driver_name()) { switch ($database->get_driver_name()) {
case DatabaseDriver::PGSQL: case DatabaseDriver::PGSQL:
case DatabaseDriver::SQLITE: case DatabaseDriver::SQLITE:
$database->execute('CREATE INDEX images_image_idx ON images(image) WHERE image IS NOT NULL'); $database->execute('CREATE INDEX images_image_idx ON images(image) WHERE image IS NOT NULL');
@ -1052,7 +1052,7 @@ class Media extends Extension
$database->set_timeout(300000); // These updates can take a little bit $database->set_timeout(300000); // These updates can take a little bit
if ($database->transaction === true) { if ($database->transaction === true) {
$database->commit(); // Each of these commands could hit a lot of data, combining them into one big transaction would not be a good idea. $database->commit(); // Each of these commands could hit a lot of data, combining them into one big transaction would not be a good idea.
} }
log_info("upgrade", "Setting predictable media values for known file types"); log_info("upgrade", "Setting predictable media values for known file types");
$database->execute($database->scoreql_to_sql("UPDATE images SET image = SCORE_BOOL_N WHERE ext IN ('swf','mp3','ani','flv','mp4','m4v','ogv','webm')")); $database->execute($database->scoreql_to_sql("UPDATE images SET image = SCORE_BOOL_N WHERE ext IN ('swf','mp3','ani','flv','mp4','m4v','ogv','webm')"));

View file

@ -55,7 +55,7 @@ class NotATag extends Extension
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) public function onPageSubNavBuilding(PageSubNavBuildingEvent $event)
{ {
global $user; global $user;
if($event->parent==="tags") { if ($event->parent==="tags") {
if ($user->can(Permissions::BAN_IMAGE)) { if ($user->can(Permissions::BAN_IMAGE)) {
$event->add_nav_link("untags", new Link('untag/list/1'), "UnTags"); $event->add_nav_link("untags", new Link('untag/list/1'), "UnTags");
} }

View file

@ -472,7 +472,7 @@ class OuroborosAPI extends Extension
if (empty($post->file) && !empty($post->file_url) && filter_var( if (empty($post->file) && !empty($post->file_url) && filter_var(
$post->file_url, $post->file_url,
FILTER_VALIDATE_URL FILTER_VALIDATE_URL
) !== false ) !== false
) { ) {
// Transload from source // Transload from source
$meta['file'] = tempnam('/tmp', 'shimmie_transload_' . $config->get_string('transload_engine')); $meta['file'] = tempnam('/tmp', 'shimmie_transload_' . $config->get_string('transload_engine'));

View file

@ -818,7 +818,7 @@ class Pools extends Extension
SELECT COUNT(*) FROM pool_images p SELECT COUNT(*) FROM pool_images p
$query", $query",
["pid" => $poolID] ["pid" => $poolID]
) / $imagesPerPage); ) / $imagesPerPage);

View file

@ -341,7 +341,7 @@ class Ratings extends Extension
$old = $_POST["rating_old"]; $old = $_POST["rating_old"];
$new = $_POST["rating_new"]; $new = $_POST["rating_new"];
if($user->can(Permissions::BULK_EDIT_IMAGE_RATING)) { if ($user->can(Permissions::BULK_EDIT_IMAGE_RATING)) {
$database->execute("UPDATE images SET rating = :new WHERE rating = :old", ["new"=>$new, "old"=>$old ]); $database->execute("UPDATE images SET rating = :new WHERE rating = :old", ["new"=>$new, "old"=>$old ]);
} }

View file

@ -63,9 +63,9 @@ class Trash extends Extension
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) public function onPageSubNavBuilding(PageSubNavBuildingEvent $event)
{ {
global $user; global $user;
if($event->parent=="posts") { if ($event->parent=="posts") {
if($user->can(Permissions::VIEW_TRASH)) { if ($user->can(Permissions::VIEW_TRASH)) {
$event->add_nav_link("posts_trash", new Link('/post/list/in%3Atrash/1'), "Trash",null, 60); $event->add_nav_link("posts_trash", new Link('/post/list/in%3Atrash/1'), "Trash", null, 60);
} }
} }
} }

View file

@ -35,6 +35,9 @@ class DataUploadEvent extends Event
assert(is_array($metadata["tags"])); assert(is_array($metadata["tags"]));
assert(is_string($metadata["source"]) || is_null($metadata["source"])); assert(is_string($metadata["source"]) || is_null($metadata["source"]));
// DB limits to 64 char filenames
$metadata['filename'] = substr($metadata['filename'], 0, 63);
$this->metadata = $metadata; $this->metadata = $metadata;
$this->set_tmpname($tmpname); $this->set_tmpname($tmpname);

View file

@ -25,7 +25,7 @@ class CustomHomeTheme extends HomeTheme
</body> </body>
</html> </html>
EOD EOD
); );
} }
public function build_body(string $sitename, string $main_links, string $main_text, string $contact_link, $num_comma, string $counter_text) public function build_body(string $sitename, string $main_links, string $main_text, string $contact_link, $num_comma, string $counter_text)