forked from Cavemanon/cavepaintings
Merge branch 'master' of https://github.com/shish/shimmie2
This commit is contained in:
@@ -6,11 +6,13 @@
|
||||
* Description: Bulk add server-side images with metadata from CSV file
|
||||
* Documentation:
|
||||
* Modification of "Bulk Add" by Shish.<br><br>
|
||||
* Adds images from a CSV with the four following values: <br>
|
||||
* "/path/to/image.jpg","space separated tags","source","rating (s, q, or e)" <br>
|
||||
* <b>e.g.</b> "/tmp/cat.png","shish oekaki","shimmie.shishnet.org/v2/post/view/3051","s" <br><br>
|
||||
* Any value but the first may be omitted, but there must be four values per line.<br>
|
||||
* <b>e.g.</b> "/why/not/try/bulk_add.jpg","","",""<br><br>
|
||||
* Adds images from a CSV with the five following values: <br>
|
||||
* "/path/to/image.jpg","spaced tags","source","rating s/q/e","/path/thumbnail.jpg" <br>
|
||||
* <b>e.g.</b> "/tmp/cat.png","shish oekaki","shimmie.shishnet.org","s","tmp/custom.jpg" <br><br>
|
||||
* Any value but the first may be omitted, but there must be five values per line.<br>
|
||||
* <b>e.g.</b> "/why/not/try/bulk_add.jpg","","","",""<br><br>
|
||||
* Image thumbnails will be displayed at the AR of the full image. Thumbnails that are
|
||||
* normally static (e.g. SWF) will be displayed at the board's max thumbnail size<br><br>
|
||||
* Useful for importing tagged images without having to do database manipulation.<br>
|
||||
* <p><b>Note:</b> requires "Admin Controls" and optionally "Image Ratings" to be enabled<br><br>
|
||||
*
|
||||
@@ -53,7 +55,7 @@ class BulkAddCSV extends Extension {
|
||||
/**
|
||||
* Generate the necessary DataUploadEvent for a given image and tags.
|
||||
*/
|
||||
private function add_image($tmpname, $filename, $tags, $source, $rating) {
|
||||
private function add_image($tmpname, $filename, $tags, $source, $rating, $thumbfile) {
|
||||
assert(file_exists($tmpname));
|
||||
|
||||
$pathinfo = pathinfo($filename);
|
||||
@@ -68,9 +70,14 @@ class BulkAddCSV extends Extension {
|
||||
send_event($event);
|
||||
if($event->image_id == -1) {
|
||||
throw new UploadException("File type not recognised");
|
||||
} elseif(class_exists("RatingSetEvent") && in_array($rating, array("s", "q", "e"))) {
|
||||
$ratingevent = new RatingSetEvent(Image::by_id($event->image_id), $rating);
|
||||
send_event($ratingevent);
|
||||
} else {
|
||||
if(class_exists("RatingSetEvent") && in_array($rating, array("s", "q", "e"))) {
|
||||
$ratingevent = new RatingSetEvent(Image::by_id($event->image_id), $rating);
|
||||
send_event($ratingevent);
|
||||
}
|
||||
if (file_exists($thumbfile)) {
|
||||
copy($thumbfile, warehouse_path("thumbs", $event->hash));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +98,7 @@ class BulkAddCSV extends Extension {
|
||||
$csvhandle = fopen($csvfile, "r");
|
||||
|
||||
while (($csvdata = fgetcsv($csvhandle, 0, ",")) !== FALSE) {
|
||||
if(count($csvdata) != 4) {
|
||||
if(count($csvdata) != 5) {
|
||||
if(strlen($list) > 0) {
|
||||
$this->theme->add_status("Error", "<b>Encountered malformed data. Line $linenum $csvfile</b><br>".$list);
|
||||
fclose($csvhandle);
|
||||
@@ -106,12 +113,13 @@ class BulkAddCSV extends Extension {
|
||||
$tags = trim($csvdata[1]);
|
||||
$source = $csvdata[2];
|
||||
$rating = $csvdata[3];
|
||||
$thumbfile = $csvdata[4];
|
||||
$pathinfo = pathinfo($fullpath);
|
||||
$shortpath = $pathinfo["basename"];
|
||||
$list .= "<br>".html_escape("$shortpath (".str_replace(" ", ", ", $tags).")... ");
|
||||
if (file_exists($csvdata[0]) && is_file($csvdata[0])) {
|
||||
try{
|
||||
$this->add_image($fullpath, $pathinfo["basename"], $tags, $source, $rating);
|
||||
$this->add_image($fullpath, $pathinfo["basename"], $tags, $source, $rating, $thumbfile);
|
||||
$list .= "ok\n";
|
||||
}
|
||||
catch(Exception $ex) {
|
||||
|
@@ -178,13 +178,16 @@ class CommentList extends Extension {
|
||||
$this->build_page($page_num);
|
||||
}
|
||||
else if($event->get_arg(0) === "beta-search") {
|
||||
$i_comment_count = Comment::count_comments_by_user($user);
|
||||
$com_per_page = 50;
|
||||
$total_pages = ceil($i_comment_count/$com_per_page);
|
||||
$search = $event->get_arg(1);
|
||||
$page_num = int_escape($event->get_arg(2));
|
||||
|
||||
$page_num = $this->sanity_check_pagenumber($page_num, $total_pages);
|
||||
$duser = User::by_name($search);
|
||||
|
||||
$comments = $this->get_user_comments($duser->id, 50, ($page_num-1) * 50);
|
||||
$this->theme->display_all_user_comments($comments, $page_num, 10);
|
||||
$comments = $this->get_user_comments($duser->id, $com_per_page, ($page_num-1) * $com_per_page);
|
||||
$this->theme->display_all_user_comments($comments, $page_num, $total_pages);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -289,11 +292,11 @@ class CommentList extends Extension {
|
||||
if(class_exists("Ratings")) {
|
||||
$user_ratings = Ratings::get_user_privs($user);
|
||||
}
|
||||
|
||||
$total_pages = $database->cache->get("comment_pages");
|
||||
if(is_null($current_page) || $current_page <= 0) {
|
||||
$current_page = 1;
|
||||
}
|
||||
|
||||
$current_page = $this->sanity_check_pagenumber($current_page, $total_pages);
|
||||
$threads_per_page = 10;
|
||||
$start = $threads_per_page * ($current_page - 1);
|
||||
|
||||
@@ -307,7 +310,6 @@ class CommentList extends Extension {
|
||||
";
|
||||
$result = $database->Execute($get_threads, array("limit"=>$threads_per_page, "offset"=>$start));
|
||||
|
||||
$total_pages = $database->cache->get("comment_pages");
|
||||
if(empty($total_pages)) {
|
||||
$total_pages = (int)($database->get_one("SELECT COUNT(c1) FROM (SELECT COUNT(image_id) AS c1 FROM comments $where GROUP BY image_id) AS s1") / 10);
|
||||
$database->cache->set("comment_pages", $total_pages, 600);
|
||||
@@ -363,7 +365,7 @@ class CommentList extends Extension {
|
||||
LEFT JOIN users ON comments.owner_id=users.id
|
||||
WHERE users.id = :user_id
|
||||
ORDER BY comments.id DESC
|
||||
OFFSET :offset LIMIT :limit
|
||||
LIMIT :limit OFFSET :offset
|
||||
", array("user_id"=>$user_id, "offset"=>$offset, "limit"=>$count));
|
||||
$comments = array();
|
||||
foreach($rows as $row) {
|
||||
@@ -474,7 +476,19 @@ class CommentList extends Extension {
|
||||
global $database;
|
||||
return ($database->get_row("SELECT * FROM comments WHERE image_id=:image_id AND comment=:comment", array("image_id"=>$image_id, "comment"=>$comment)));
|
||||
}
|
||||
|
||||
// do some checks
|
||||
private function sanity_check_pagenumber($pagenum, $maxpage){
|
||||
if (!is_numeric($pagenum)){
|
||||
$pagenum=1;
|
||||
}
|
||||
if ($pagenum>$maxpage){
|
||||
$pagenum=$maxpage;
|
||||
}
|
||||
if ($pagenum<=0){
|
||||
$pagenum=1;
|
||||
}
|
||||
return $pagenum;
|
||||
}
|
||||
private function add_comment_wrapper(/*int*/ $image_id, User $user, /*string*/ $comment) {
|
||||
global $database;
|
||||
global $config;
|
||||
|
@@ -36,7 +36,7 @@ class CommentListTheme extends Themelet {
|
||||
|
||||
$h_prev = ($page_number <= 1) ? "Prev" :
|
||||
'<a href="'.make_link('comment/list/'.$prev).'">Prev</a>';
|
||||
$h_index = "<a href='".make_link("comment/list")."'>Index</a>";
|
||||
$h_index = "<a href='".make_link("post/list")."'>Index</a>";
|
||||
$h_next = ($page_number >= $total_pages) ? "Next" :
|
||||
'<a href="'.make_link('comment/list/'.$next).'">Next</a>';
|
||||
|
||||
@@ -171,7 +171,11 @@ class CommentListTheme extends Themelet {
|
||||
}
|
||||
|
||||
public function display_all_user_comments($comments, $page_number, $total_pages) {
|
||||
global $page;
|
||||
global $page, $user;
|
||||
|
||||
assert(is_numeric($page_number));
|
||||
assert(is_numeric($total_pages));
|
||||
|
||||
$html = "";
|
||||
foreach($comments as $comment) {
|
||||
$html .= $this->comment_to_html($comment, true);
|
||||
@@ -184,19 +188,20 @@ class CommentListTheme extends Themelet {
|
||||
|
||||
$prev = $page_number - 1;
|
||||
$next = $page_number + 1;
|
||||
|
||||
$u_tags = url_escape(implode(" ", $search_terms));
|
||||
$query = empty($u_tags) ? "" : '/'.$u_tags;
|
||||
|
||||
//$search_terms = array('I','have','no','idea','what','this','does!');
|
||||
//$u_tags = url_escape(implode(" ", $search_terms));
|
||||
//$query = empty($u_tags) ? "" : '/'.$u_tags;
|
||||
|
||||
|
||||
$h_prev = ($page_number <= 1) ? "Prev" : "<a href='$prev'>Prev</a>";
|
||||
$h_index = "<a href='".make_link("post/list")."'>Index</a>";
|
||||
$h_next = ($page_number >= $total_pages) ? "Next" : "<a href='$next'>Next</a>";
|
||||
|
||||
$page->add_block(new Block("Navigation", $h_prev.' | '.$h_next, "left", 0));
|
||||
$page->add_block(new Block("Navigation", $h_prev.' | '.$h_index.' | '.$h_next, "left", 0));
|
||||
$this->display_paginator($page, 'comment/beta-search/'.$user->name, null, $page_number, $total_pages);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function comment_to_html($comment, $trim=false) {
|
||||
global $config, $user;
|
||||
|
||||
|
@@ -26,7 +26,20 @@ class MP3FileHandler extends DataHandlerExtension {
|
||||
|
||||
$image->filesize = $metadata['size'];
|
||||
$image->hash = $metadata['hash'];
|
||||
$image->filename = $metadata['filename'];
|
||||
|
||||
//Cheat by using the filename to store artist/title if available
|
||||
require_once('lib/getid3/getid3/getid3.php');
|
||||
$getID3 = new getID3;
|
||||
$ThisFileInfo = $getID3->analyze($filename, TRUE);
|
||||
|
||||
if (isset($ThisFileInfo['tags']['id3v2']['artist'][0]) && isset($ThisFileInfo['tags']['id3v2']['title'][0])) {
|
||||
$image->filename = $ThisFileInfo['tags']['id3v2']['artist'][0]." - ".$ThisFileInfo['tags']['id3v2']['title'][0].".mp3";
|
||||
} else if (isset($ThisFileInfo['tags']['id3v1']['artist'][0]) && isset($ThisFileInfo['tags']['id3v1']['title'][0])) {
|
||||
$image->filename = $ThisFileInfo['tags']['id3v1']['artist'][0]." - ".$ThisFileInfo['tags']['id3v1']['title'][0].".mp3";
|
||||
} else {
|
||||
$image->filename = $metadata['filename'];
|
||||
}
|
||||
|
||||
$image->ext = $metadata['extension'];
|
||||
$image->tag_array = Tag::explode($metadata['tags']);
|
||||
$image->source = $metadata['source'];
|
||||
@@ -35,8 +48,15 @@ class MP3FileHandler extends DataHandlerExtension {
|
||||
}
|
||||
|
||||
protected function check_contents($file) {
|
||||
// FIXME: mp3 magic header?
|
||||
return (file_exists($file));
|
||||
if (file_exists($file)) {
|
||||
require_once('lib/getid3/getid3/getid3.php');
|
||||
$getID3 = new getID3;
|
||||
$ThisFileInfo = $getID3->analyze($file, TRUE);
|
||||
if (isset($ThisFileInfo['fileformat']) && $ThisFileInfo['fileformat'] == "mp3") {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
82
ext/handle_video/main.php
Normal file
82
ext/handle_video/main.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/*
|
||||
* Name: Handle Video
|
||||
* Author: velocity37 <velocity37@gmail.com>
|
||||
* License: GPLv2
|
||||
* Description: Handle FLV, MP4, OGV and WEBM video files.
|
||||
* Documentation:
|
||||
* Based heavily on "Handle MP3" by Shish.<br><br>
|
||||
* FLV: Flash player<br>
|
||||
* MP4: HTML5 with Flash fallback<br>
|
||||
* OGV, WEBM: HTML5<br>
|
||||
* MP4's flash fallback is forced with a bit of Javascript as some browsers won't fallback if they can't play H.264.
|
||||
* In the future, it may be necessary to change the user agent checks to reflect the current state of H.264 support.<br><br>
|
||||
* Made possible by:<br>
|
||||
* <a href='http://getid3.sourceforge.net/'>getID3()</a> - Gets media information with PHP (no bulky FFMPEG API required).<br>
|
||||
* <a href='http://jarisflvplayer.org/'>Jaris FLV Player</a> - GPLv3 flash multimedia player.
|
||||
*/
|
||||
|
||||
class VideoFileHandler extends DataHandlerExtension {
|
||||
protected function create_thumb($hash) {
|
||||
copy("ext/handle_video/thumb.jpg", warehouse_path("thumbs", $hash));
|
||||
}
|
||||
|
||||
protected function supported_ext($ext) {
|
||||
$exts = array("flv", "mp4", "m4v", "ogv", "webm");
|
||||
return in_array(strtolower($ext), $exts);
|
||||
}
|
||||
|
||||
protected function create_image_from_data($filename, $metadata) {
|
||||
global $config;
|
||||
|
||||
$image = new Image();
|
||||
|
||||
require_once('lib/getid3/getid3/getid3.php');
|
||||
$getID3 = new getID3;
|
||||
$ThisFileInfo = $getID3->analyze($filename);
|
||||
|
||||
if (isset($ThisFileInfo['video']['resolution_x']) && isset($ThisFileInfo['video']['resolution_y'])) {
|
||||
$image->width = $ThisFileInfo['video']['resolution_x'];
|
||||
$image->height = $ThisFileInfo['video']['resolution_y'];
|
||||
} else {
|
||||
$image->width = 0;
|
||||
$image->height = 0;
|
||||
}
|
||||
|
||||
switch ($ThisFileInfo['mime_type']) {
|
||||
case "video/webm":
|
||||
$image->ext = "webm";
|
||||
break;
|
||||
case "video/quicktime":
|
||||
$image->ext = "mp4";
|
||||
break;
|
||||
case "application/ogg":
|
||||
$image->ext = "ogv";
|
||||
break;
|
||||
case "video/x-flv":
|
||||
$image->ext = "flv";
|
||||
break;
|
||||
}
|
||||
|
||||
$image->filesize = $metadata['size'];
|
||||
$image->hash = $metadata['hash'];
|
||||
$image->filename = $metadata['filename'];
|
||||
$image->tag_array = Tag::explode($metadata['tags']);
|
||||
$image->source = $metadata['source'];
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
protected function check_contents($file) {
|
||||
if (file_exists($file)) {
|
||||
require_once('lib/getid3/getid3/getid3.php');
|
||||
$getID3 = new getID3;
|
||||
$ThisFileInfo = $getID3->analyze($file);
|
||||
if (isset($ThisFileInfo['mime_type']) && ($ThisFileInfo['mime_type'] == "video/webm" || $ThisFileInfo['mime_type'] == "video/quicktime" || $ThisFileInfo['mime_type'] == "application/ogg" || $ThisFileInfo['mime_type'] == 'video/x-flv')) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
?>
|
37
ext/handle_video/theme.php
Normal file
37
ext/handle_video/theme.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
class VideoFileHandlerTheme extends Themelet {
|
||||
public function display_image(Page $page, Image $image) {
|
||||
$data_href = get_base_href();
|
||||
$ilink = $image->get_image_link();
|
||||
$ext = strtolower($image->get_ext());
|
||||
|
||||
if ($ext == "mp4") {
|
||||
$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><script language='JavaScript' type='text/javascript'>
|
||||
if( navigator.userAgent.match(/Firefox/i) ||
|
||||
navigator.userAgent.match(/Opera/i) ||
|
||||
(navigator.userAgent.match(/MSIE/i) && parseFloat(navigator.appVersion.split('MSIE')[1]) < 9)){
|
||||
document.write(\"<object data='$data_href/lib/Jaris/bin/JarisFLVPlayer.swf' id='VideoPlayer' type='application/x-shockwave-flash' height='" . strval($image->height + 1). "px' width='" . strval($image->width) . "px'><param value='#000000' name='bgcolor'><param name='allowFullScreen' value='true'><param value='high' name='quality'><param value='opaque' name='wmode'><param value='source=$ilink&type=video&streamtype=file&controltype=0' name='flashvars'></object>\");
|
||||
}
|
||||
else {
|
||||
document.write(\"<video controls='controls' autoplay='autoplay'>\");
|
||||
document.write(\"<source src='" . make_link("/image/" . $image->id) . "' type='video/mp4' />\");
|
||||
document.write(\"<object data='$data_href/lib/Jaris/bin/JarisFLVPlayer.swf' id='VideoPlayer' type='application/x-shockwave-flash' height='" . strval($image->height + 1). "px' width='" . strval($image->width) . "px'><param value='#000000' name='bgcolor'><param name='allowFullScreen' value='true'><param value='high' name='quality'><param value='opaque' name='wmode'><param value='source=$ilink&type=video&streamtype=file&controltype=0' name='flashvars'></object>\");
|
||||
}
|
||||
</script>
|
||||
<noscript>Javascript appears to be disabled. Please enable it and try again.</noscript>";
|
||||
} elseif ($ext == "flv") {
|
||||
$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><object data='$data_href/lib/Jaris/bin/JarisFLVPlayer.swf' id='VideoPlayer' type='application/x-shockwave-flash' height='" . strval($image->height + 1). "px' width='" . strval($image->width) . "px'><param value='#000000' name='bgcolor'><param name='allowFullScreen' value='true'><param value='high' name='quality'><param value='opaque' name='wmode'><param value='source=$ilink&type=video&streamtype=file&controltype=0' name='flashvars'></object>";
|
||||
} elseif ($ext == "ogv") {
|
||||
$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><video controls='controls' autoplay='autoplay'>
|
||||
<source src='" . make_link("/image/" . $image->id) . "' type='video/ogg' />
|
||||
</video>";
|
||||
} elseif ($ext == "webm") {
|
||||
$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><video controls='controls' autoplay='autoplay'>
|
||||
<source src='" . make_link("/image/" . $image->id) . "' type='video/webm' />
|
||||
</video>";
|
||||
}
|
||||
$page->add_block(new Block("Video", $html, "main", 10));
|
||||
}
|
||||
}
|
||||
?>
|
BIN
ext/handle_video/thumb.jpg
Normal file
BIN
ext/handle_video/thumb.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
Reference in New Issue
Block a user