forked from 4ducky/4ducky
Move the original PHP site into legacy/
The PHP sources, templates and old jQuery-based scripts move unchanged into legacy/ for reference. Shared assets (media/, images/, favicon.ico, the default avatar) stay at the repository root. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
The ImageUploader class handles the insertion of images into the system -
|
||||
whether they were uploaded or should be copied from a remote URL
|
||||
*/
|
||||
|
||||
require_once( 'lib/config.php' );
|
||||
require_once( 'lib/db.php' );
|
||||
require_once( 'lib/filesystem.php' );
|
||||
require_once( 'lib/images.php' );
|
||||
require_once( 'lib/users.php' );
|
||||
require_once( 'lib/keyword.php' );
|
||||
|
||||
class ImageUploader {
|
||||
|
||||
public static function copyFromUrl( $url, $tags, $referer, &$errors ) {
|
||||
if( stripos( $url, 'http://' ) !== 0 ) {
|
||||
$url = 'http://'.$url;
|
||||
}
|
||||
// no recursion, no non-images
|
||||
if(
|
||||
stripos( $url, Config::$frontendPath ) !== false ||
|
||||
!preg_match( '/([^\/]*?)\.(gif|jpg|jpeg|png)$/i', $url, $fileMatch )
|
||||
) {
|
||||
$errors['downloadFailed'] = 'The Image could not be downloaded!';
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$fileName = $fileMatch[1];
|
||||
// use the domain name as part of the keyword
|
||||
$urlParts = parse_url( $url );
|
||||
if( preg_match( '/(^|\.)([\w\-]+)\.\w+$/', $urlParts['host'], $m ) ) {
|
||||
$fileName = strtolower($m[2]).'-'.$fileName;
|
||||
}
|
||||
$fileName = Keyword::get( $fileName ).'.'.$fileMatch[2];
|
||||
$targetPath = './import/'.$fileName;
|
||||
|
||||
if( !Filesystem::download( $url, $targetPath, Config::$images['maxDownload'], $referer ) ) {
|
||||
$errors['downloadFailed'] = 'The Image could not be downloaded!';
|
||||
return false;
|
||||
}
|
||||
|
||||
if( self::process( $fileName, $targetPath, $tags, false, $errors, $url ) ) {
|
||||
return true;
|
||||
} else {
|
||||
@unlink( $targePath );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function process( $name, $localPath, $tags, $uploaded = true, &$errors, $source = '',$commentUpload = false,$cid=0 ) {
|
||||
echo("hallo");
|
||||
$user = new User();
|
||||
$user->login();
|
||||
|
||||
if( !$user->id ) {
|
||||
$errors['notLoggedIn'] = 'You are not logged in!';
|
||||
return false;
|
||||
}
|
||||
|
||||
// no non-images
|
||||
if(
|
||||
!preg_match( '/([^\/]*?)\.(gif|jpg|jpeg|png)$/i', $name, $fileMatch )
|
||||
) {
|
||||
$errors['wrongExtension'] = 'Your file has not the right extension (gif, jpg or png)!';
|
||||
return false;
|
||||
}
|
||||
|
||||
$time = time();
|
||||
$keyword = Keyword::get( $fileMatch[1] );
|
||||
|
||||
// Iterate over all keywords, if this one is allready taken
|
||||
$taken = array();
|
||||
$r = DB::query( 'SELECT keyword FROM '.TABLE_IMAGES.' WHERE keyword LIKE :1', date('Y/m/',$time).$keyword.'%' );
|
||||
foreach( $r as $v ) {
|
||||
$taken[] = substr($v['keyword'],8); // Keyword without date!
|
||||
}
|
||||
$keyword = Keyword::iterate( $keyword, $taken );
|
||||
|
||||
list( $srcWidth, $srcHeight, $type ) = getimagesize( $localPath );
|
||||
if( $type == IMAGETYPE_JPEG ) {
|
||||
$extension = 'jpg';
|
||||
} else if( $type == IMAGETYPE_GIF ) {
|
||||
$extension = 'gif';
|
||||
} else if( $type == IMAGETYPE_PNG ) {
|
||||
$extension = 'png';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$thumbName = $keyword.".jpg"; // all thumbs are jpegs!
|
||||
$name = $keyword.".".$extension;
|
||||
$imageDir = Config::$images['imagePath'] . date('Y/m', $time);
|
||||
$thumbDir = Config::$images['thumbPath'] . date('Y/m', $time);
|
||||
$imagePath = $imageDir.'/'.$name;
|
||||
|
||||
if( !Filesystem::mkdirr($imageDir) || !Filesystem::mkdirr($thumbDir) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( $uploaded ) {
|
||||
if( !@move_uploaded_file( $localPath, $imagePath ) ) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if( !@rename( $localPath, $imagePath ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$hash = md5_file( $imagePath );
|
||||
$c = DB::query('SELECT id FROM '.TABLE_IMAGES.' WHERE hash = :1', $hash);
|
||||
if( !empty( $c ) ) {
|
||||
unlink( $imagePath );
|
||||
$errors['duplicate'] = 'This image is already in our database!';
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//watermark
|
||||
function watermark($SourceFile, $WatermarkFile, $SaveToFile = NULL)
|
||||
|
||||
{
|
||||
|
||||
list( $srcWidth, $srcHeight, $type ) = getimagesize( $SourceFile );
|
||||
if( $type != IMAGETYPE_GIF ) {
|
||||
|
||||
|
||||
|
||||
|
||||
$watermark = @imagecreatefrompng($WatermarkFile)
|
||||
|
||||
|
||||
or exit('Cannot open the watermark file.');
|
||||
|
||||
imageAlphaBlending($watermark, false);
|
||||
|
||||
imageSaveAlpha($watermark, true);
|
||||
|
||||
$image_string = @file_get_contents($SourceFile)
|
||||
|
||||
|
||||
or exit('Cannot open image file.');
|
||||
|
||||
$image = @imagecreatefromstring($image_string)
|
||||
|
||||
or exit('Not a valid image format.');
|
||||
|
||||
$imageWidth=imageSX($image);
|
||||
|
||||
$imageHeight=imageSY($image);
|
||||
|
||||
|
||||
$watermarkWidth=imageSX($watermark);
|
||||
|
||||
$watermarkHeight=imageSY($watermark);
|
||||
|
||||
$coordinate_X = ( $imageWidth) - ( $watermarkWidth);
|
||||
|
||||
|
||||
$coordinate_Y = ( $imageHeight) - ( $watermarkHeight);
|
||||
|
||||
imagecopy($image, $watermark, $coordinate_X, $coordinate_Y,
|
||||
|
||||
|
||||
0, 0, $watermarkWidth, $watermarkHeight);
|
||||
|
||||
if(!($SaveToFile)) header('Content-Type: image/jpeg');
|
||||
|
||||
imagejpeg ($image, $SaveToFile, 100);
|
||||
|
||||
|
||||
imagedestroy($image);
|
||||
|
||||
imagedestroy($watermark);
|
||||
|
||||
if(!($SaveToFile)) exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// make thumbs
|
||||
foreach( Config::$gridView['classes'] as $gc ) {
|
||||
$thumbPath = $thumbDir.'/'.$gc['dir'].'/'.$thumbName;
|
||||
Filesystem::mkdirr($thumbDir.'/'.$gc['dir']);
|
||||
if( !Image::createThumb( $imagePath, $thumbPath,
|
||||
$gc['width'] * Config::$gridView['gridSize'] - Config::$gridView['borderWidth'],
|
||||
$gc['height'] * Config::$gridView['gridSize'] - Config::$gridView['borderWidth']
|
||||
)) {
|
||||
unlink( $imagePath );
|
||||
$errors['internalError'] = 'Internal error processing the image!';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
///watermark
|
||||
watermark($imagePath,"watermark.png",$imagePath);
|
||||
///watermark
|
||||
|
||||
$user->increaseScore( Config::$postScore );
|
||||
|
||||
DB::query( 'UPDATE '.TABLE_USERS.' SET images = images + 1 WHERE id = :1', $user->id );
|
||||
|
||||
|
||||
if ($commentUpload && $cid != 0){
|
||||
DB::insertRow( "pl_commentuploads",array('c_id' => $cid,"image_link" =>$imagePath,"thumb_link" => "data/thumbs/".date('Y/m/', $time)."/128x128/".$name));
|
||||
|
||||
}else{
|
||||
DB::insertRow( TABLE_IMAGES,
|
||||
array(
|
||||
'logged' => date('Y-m-d H:i:s', $time),
|
||||
'user' => $user->id,
|
||||
'score' => 3,
|
||||
'votes' => 0,
|
||||
'keyword' => date('Y/m/', $time).$keyword,
|
||||
'tags' => $tags,
|
||||
'image' => $name,
|
||||
'thumb' => $thumbName,
|
||||
'hash' => $hash,
|
||||
'source' => $source
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$imageId = DB::insertId();
|
||||
|
||||
$colors = Image::getColors( $imagePath, 4 );
|
||||
foreach( $colors as $c ) {
|
||||
DB::insertRow( TABLE_IMAGECOLORS,
|
||||
array(
|
||||
'imageId' => $imageId,
|
||||
'r' => $c['r'],
|
||||
'g' => $c['g'],
|
||||
'b' => $c['b']
|
||||
)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Vendored
+4
File diff suppressed because one or more lines are too long
@@ -0,0 +1,490 @@
|
||||
function $(id){return document.getElementById(id)}
|
||||
function gridView(id){ gridSolve(id); gridSolve(id); window.setInterval("gridSolve('"+id+"')",250); }
|
||||
function swap(e, c1, c2) { e.className = e.className == c1 ? c2 : c1; };
|
||||
|
||||
// GridSolver ------------------------------------------------------------
|
||||
var gridSize = 64;
|
||||
var gridMinWidth = 6;
|
||||
var gridWidth = 0;
|
||||
var grid = null;
|
||||
var boxDef = {
|
||||
'b0': {'width': 3, 'height': 3},
|
||||
'b1': {'width': 2, 'height': 2},
|
||||
'b2': {'width': 1, 'height': 1}
|
||||
};
|
||||
|
||||
function gridSolve( cid ) {
|
||||
var container = $(cid);
|
||||
var newWidth = parseInt( container.offsetWidth );
|
||||
var newGridWidth = parseInt( newWidth / gridSize );
|
||||
newGridWidth = newGridWidth < gridMinWidth ? gridMinWidth : newGridWidth;
|
||||
|
||||
if( gridWidth == newGridWidth )
|
||||
return;
|
||||
else
|
||||
gridWidth = newGridWidth;
|
||||
|
||||
boxes = new Array();
|
||||
while( container.hasChildNodes() ) {
|
||||
e = container.removeChild( container.firstChild );
|
||||
if( e.tagName == 'DIV' ) {
|
||||
boxes.push( e );
|
||||
}
|
||||
}
|
||||
|
||||
grid = new Array( gridWidth );
|
||||
for( var i = 0; i < grid.length; i++ ) {
|
||||
grid[i] = 0;
|
||||
}
|
||||
|
||||
for(var i = 0; i < boxes.length; i++) {
|
||||
insertThumb( boxes[i], cid )
|
||||
}
|
||||
|
||||
var maxHeight = 0;
|
||||
for( var i = 0; i < grid.length; i++) {
|
||||
maxHeight = Math.max( maxHeight,grid[i] );
|
||||
}
|
||||
container.style.height = (maxHeight * gridSize) + 'px';
|
||||
$('images').style.height = (maxHeight * gridSize) + 'px';
|
||||
}
|
||||
|
||||
function insertThumb( box, cid ) {
|
||||
var boxWidth = boxDef[box.className]['width'];
|
||||
var boxHeight = boxDef[box.className]['height'];
|
||||
var maxHeight = 0;
|
||||
var currentHeight = -1;
|
||||
var spotWidth = 0;
|
||||
var spotLeft = 0;
|
||||
var freeSpots = new Array();
|
||||
for( var i = 0; i < grid.length; i++) {
|
||||
if( currentHeight == grid[i] ) {
|
||||
spotWidth++;
|
||||
}
|
||||
|
||||
if( (currentHeight != grid[i] || i+1 == grid.length) && spotWidth > 0) {
|
||||
freeSpots.push({'width': spotWidth, 'left': spotLeft, 'height': currentHeight});
|
||||
|
||||
spotWidth = 1;
|
||||
spotLeft = i;
|
||||
if(currentHeight != grid[i] && i+1 == grid.length) {
|
||||
freeSpots.push({'width': spotWidth, 'left': spotLeft, 'height': grid[i]});
|
||||
}
|
||||
}
|
||||
|
||||
else if( spotWidth == 0 ) {
|
||||
spotWidth = 1;
|
||||
}
|
||||
|
||||
currentHeight = grid[i];
|
||||
if( grid[i] > maxHeight ) {
|
||||
maxHeight = grid[i];
|
||||
}
|
||||
}
|
||||
|
||||
var targetHeight = 0;
|
||||
var targetLeft = 0;
|
||||
var bestScore = -1;
|
||||
for( var j = 0; j < boxWidth; j++ ) {
|
||||
if( grid[j] > targetHeight ) {
|
||||
targetHeight = grid[j];
|
||||
}
|
||||
}
|
||||
var newHeight = targetHeight + boxHeight;
|
||||
|
||||
for( var i = 0; i < freeSpots.length; i++ ) {
|
||||
var heightScore = ( maxHeight - freeSpots[i]['height'] );
|
||||
var widthScore = boxWidth / freeSpots[i]['width'];
|
||||
var score = heightScore * heightScore + widthScore * 2;
|
||||
|
||||
if( freeSpots[i]['width'] >= boxWidth && score > bestScore ) {
|
||||
targetHeight = freeSpots[i]['height'];
|
||||
targetLeft = freeSpots[i]['left'];
|
||||
newHeight = freeSpots[i]['height'] + boxHeight;
|
||||
bestScore = score;
|
||||
}
|
||||
}
|
||||
|
||||
for( var j = 0; j < boxWidth; j++ ) {
|
||||
grid[targetLeft + j] = newHeight;
|
||||
}
|
||||
|
||||
var container = $( cid );
|
||||
container.appendChild( box );
|
||||
box.style.left = (targetLeft * gridSize) + 'px';
|
||||
box.style.top = (targetHeight * gridSize) + 'px';
|
||||
return true;
|
||||
}
|
||||
|
||||
// Colorpicker -----------------------------------------------------------
|
||||
function colorpicker( id, size, onchange, onshow ) {
|
||||
var that = this;
|
||||
this.size = size;
|
||||
this.onchange = onchange;
|
||||
this.onshow = onshow;
|
||||
|
||||
this.mode = 'none';
|
||||
|
||||
this.sv = $(id+'SV');
|
||||
this.svselect = $(id+'SVSelect');
|
||||
this.h = $(id+'H');
|
||||
this.hselect = $(id+'HSelect');
|
||||
this.value = $(id+'Value');
|
||||
this.current = $(id+'Current');
|
||||
|
||||
this.cap = function( v, min, max ) {
|
||||
return Math.min(Math.max(min,v),max);
|
||||
}
|
||||
|
||||
this.getMousPos = function( event ) {
|
||||
if(event.pageX || event.pageY){
|
||||
return {
|
||||
'x': event.pageX,
|
||||
'y': event.pageY
|
||||
};
|
||||
}
|
||||
return {
|
||||
'x': event.clientX + document.body.scrollLeft - document.body.clientLeft,
|
||||
'y': event.clientY + document.body.scrollTop - document.body.clientTop
|
||||
};
|
||||
}
|
||||
|
||||
this.getObjPos = function( obj ) {
|
||||
var curleft = curtop = 0;
|
||||
if (obj.offsetParent) {
|
||||
curleft = obj.offsetLeft;
|
||||
curtop = obj.offsetTop;
|
||||
while (obj = obj.offsetParent) {
|
||||
curleft += obj.offsetLeft;
|
||||
curtop += obj.offsetTop;
|
||||
}
|
||||
}
|
||||
return {
|
||||
'x':curleft,
|
||||
'y':curtop
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
this.release = function() {
|
||||
document.onmousemove = '';
|
||||
this.mode = 'none';
|
||||
}
|
||||
|
||||
this.move = function( event ) {
|
||||
if (!event) var event = window.event;
|
||||
if(event.pageX || event.pageY) {
|
||||
var mx = event.pageX;
|
||||
var my = event.pageY;
|
||||
} else {
|
||||
var mx = event.clientX + document.body.scrollLeft - document.body.clientLeft;
|
||||
var my = event.clientY + document.body.scrollTop - document.body.clientTop;
|
||||
}
|
||||
if( this.mode == 'sv' ) {
|
||||
var obj = this.getObjPos( this.sv );
|
||||
var x = this.cap(mx - obj.x - 3, -4, this.size - 4);
|
||||
var y = this.cap(my - obj.y - 3, -4, this.size - 4);
|
||||
this.svselect.style.left = x + "px";
|
||||
this.svselect.style.top = y + "px";
|
||||
}
|
||||
else if ( this.mode == 'h' ) {
|
||||
var obj = this.getObjPos( this.sv );
|
||||
var y = this.cap(my - obj.y - 2, -2, this.size - 3);
|
||||
this.hselect.style.top = y + "px";
|
||||
this.sv.style.backgroundColor = '#' + this.rgb2hex(this.hsv2rgb( {'h':1-((y+3)/this.size), 's':1, 'v':1} ));
|
||||
}
|
||||
else return false;
|
||||
|
||||
var hex = this.getHex();
|
||||
this.current.style.backgroundColor = '#' + hex;
|
||||
this.value.innerHTML = '#' + hex;
|
||||
this.onchange( this );
|
||||
return false;
|
||||
}
|
||||
|
||||
this.sv.onmousedown = function() {
|
||||
that.mode = 'sv';
|
||||
document.onmousemove = function( event ) { that.move( event ) };
|
||||
document.onmouseup = that.release;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.h.onmousedown = function() {
|
||||
that.mode = 'h';
|
||||
document.onmousemove = function( event ) { that.move( event ) };
|
||||
document.onmouseup = that.release;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
this.getHSV = function() {
|
||||
var svpos = this.getObjPos( this.sv );
|
||||
var svselectpos = this.getObjPos( this.svselect );
|
||||
|
||||
var hpos = this.getObjPos( this.h );
|
||||
var hselectpos = this.getObjPos( this.hselect );
|
||||
|
||||
return {
|
||||
'h': 1 - (this.cap(hselectpos.y - hpos.y + 3, 0, this.size) / this.size),
|
||||
's': this.cap(svselectpos.x - svpos.x + 2, 0, this.size) / this.size,
|
||||
'v': 1 - (this.cap(svselectpos.y - svpos.y + 4, 0, this.size) / this.size)
|
||||
}
|
||||
}
|
||||
|
||||
this.getRGB = function() {
|
||||
return this.hsv2rgb( this.getHSV() );
|
||||
}
|
||||
|
||||
this.getHex = function() {
|
||||
return this.rgb2hex( this.getRGB() );
|
||||
}
|
||||
|
||||
this.toHex = function(v) { v=Math.round(Math.min(Math.max(0,v),255)); return("0123456789ABCDEF".charAt((v-v%16)/16)+"0123456789ABCDEF".charAt(v%16)); }
|
||||
this.rgb2hex = function(c) { return this.toHex(c.r)+this.toHex(c.g)+this.toHex(c.b); }
|
||||
|
||||
this.hsv2rgb = function( c ) {
|
||||
var R, B, G, H = c.h, S = c.s, V = c.v;
|
||||
if( S>0 ) {
|
||||
if(H>=1) H=0;
|
||||
|
||||
H=6*H; F=H-Math.floor(H);
|
||||
A=Math.round(255*V*(1.0-S));
|
||||
B=Math.round(255*V*(1.0-(S*F)));
|
||||
C=Math.round(255*V*(1.0-(S*(1.0-F))));
|
||||
V=Math.round(255*V);
|
||||
|
||||
switch(Math.floor(H)) {
|
||||
case 0: R=V; G=C; B=A; break;
|
||||
case 1: R=B; G=V; B=A; break;
|
||||
case 2: R=A; G=V; B=C; break;
|
||||
case 3: R=A; G=B; B=V; break;
|
||||
case 4: R=C; G=A; B=V; break;
|
||||
case 5: R=V; G=A; B=B; break;
|
||||
}
|
||||
return {'r': (R?R:0), 'g': (G?G:0), 'b': (B?B:0)};
|
||||
}
|
||||
else {
|
||||
return {'r': (Math.round(V*255)), 'g': (Math.round(V*255)), 'b': (Math.round(V*255))};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Adjust height of prev/next bars in IE ---------------------------------
|
||||
var ieAdjustCount = 0;
|
||||
function ieAdjustHeight( oldHeight ) {
|
||||
var pe = ($('viewer') ? $('viewer') : $('images'));
|
||||
if(
|
||||
!document.all || // IE
|
||||
!( pe ) ||
|
||||
(
|
||||
pe.scrollHeight < oldHeight + 50 &&
|
||||
ieAdjustCount > 10
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
ieAdjustCount++;
|
||||
var newHeight = pe.scrollHeight;
|
||||
$('prevBar').style.height = pe.scrollHeight + 'px';
|
||||
$('nextBar').style.height = pe.scrollHeight + 'px';
|
||||
setTimeout( 'ieAdjustHeight(' + newHeight + ')', 100 );
|
||||
}
|
||||
|
||||
//GET
|
||||
|
||||
function getUrlVars() {
|
||||
var vars = {};
|
||||
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
|
||||
vars[key] = value;
|
||||
});
|
||||
return vars;
|
||||
}
|
||||
|
||||
|
||||
// JSON functions for tagging, rating, deleting... -----------------------
|
||||
function post( url, params, callback ) {
|
||||
if (window.ActiveXObject) { // ie
|
||||
try {
|
||||
req = new ActiveXObject( 'Msxml2.XMLHTTP' );
|
||||
}
|
||||
catch (e) {
|
||||
try {
|
||||
req = new ActiveXObject( 'Microsoft.XMLHTTP' );
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
}
|
||||
else if (window.XMLHttpRequest) { // moz
|
||||
req = new XMLHttpRequest();
|
||||
req.overrideMimeType( 'text/plain' );
|
||||
}
|
||||
req.onreadystatechange = function(){
|
||||
if (req.readyState == 4 && req.status == 200) {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
if( !req ) return false;
|
||||
req.open( 'POST', url, true );
|
||||
req.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded; charset=UTF-8' );
|
||||
req.setRequestHeader( 'Content-length', params.length );
|
||||
req.setRequestHeader( 'Connection', 'close' );
|
||||
req.send( params );
|
||||
}
|
||||
|
||||
function addTags( imageId, inputField, admin ) {
|
||||
$( 'loadTags' ).style.display = 'block';
|
||||
var tags = encodeURIComponent(inputField.value);
|
||||
if( !admin ) {
|
||||
inputField.value = '';
|
||||
}
|
||||
post(
|
||||
location.protocol + "//" + location.host + '/json.php?addTags',
|
||||
'id='+imageId+'&tags='+tags,
|
||||
function(){
|
||||
q = ( eval('('+req.responseText+')') );
|
||||
if( q.tags ) {
|
||||
$('tags').innerHTML = q.tags;
|
||||
}
|
||||
$('addTag').className='hidden';
|
||||
$( 'loadTags' ).style.display = 'none';
|
||||
}
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
function del( imageId ) {
|
||||
try {
|
||||
if( !confirm( 'Delete this image: ' + imageId +' ?' ) ) return false;
|
||||
//$( 'loadDelete' ).style.display = 'block';
|
||||
|
||||
post(
|
||||
location.protocol + "//" + location.host + '/json.php?delete','id='+imageId);
|
||||
LoadData("comments","cmts",imageId);
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
alert("Fehler: "+e);
|
||||
return false;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function movehof( imageId ) {
|
||||
try {
|
||||
if( !confirm( 'Move to Hall of Fame?' ) ) return false;
|
||||
//$( 'loadhof' ).style.display = 'block';
|
||||
|
||||
post(
|
||||
location.protocol + "//" + location.host + '/json.php?fame',
|
||||
'id='+imageId);
|
||||
//function(){
|
||||
//$( 'loadhof' ).style.display = 'none';
|
||||
// //$( 'hof' ).style.display = 'none';
|
||||
//}
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
alert("Fehler: "+e);
|
||||
return false;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function CloseThread( imageId ) {
|
||||
try {
|
||||
if( !confirm( 'Close Thread?' ) ) return false;
|
||||
//$( 'loadhof' ).style.display = 'block';
|
||||
|
||||
post(
|
||||
location.protocol + "//" + location.host + '/json.php?CloseThread',
|
||||
'id='+imageId);
|
||||
//function(){
|
||||
//$( 'loadhof' ).style.display = 'none';
|
||||
// //$( 'hof' ).style.display = 'none';
|
||||
//}
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
alert("Fehler: "+e);
|
||||
return false;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function banUser( userId ) {
|
||||
|
||||
if( !confirm( 'Ban this User?' ) ) return false;
|
||||
var rsn = prompt("Why?");
|
||||
//$( 'loadDelete' ).style.display = 'block';
|
||||
post(
|
||||
location.protocol + "//" + location.host + '/json.php?banUser',
|
||||
'id='+userId+'&rsn='+rsn);
|
||||
return false;
|
||||
}
|
||||
|
||||
function TimeUser( userId ) {
|
||||
|
||||
if( !confirm( 'Spamlock this user?' ) ) return false;
|
||||
var tm = prompt("How long? (in hours)");
|
||||
var rsn = prompt("Why?");
|
||||
//$( 'loadDelete' ).style.display = 'block';
|
||||
var now = parseInt(Math.round((new Date()).getTime() / 1000));
|
||||
now = now + (3600 * parseInt(tm));
|
||||
alert(now);
|
||||
post(
|
||||
location.protocol + "//" + location.host + '/json.php?TimeUser',
|
||||
'id='+userId+'&time='+now+'&rsn='+rsn);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function delComment( commentId, e ) {
|
||||
if( !confirm( 'Delete this comment?' ) ) return false;
|
||||
var cdiv = e.parentNode.parentNode.parentNode;
|
||||
post(
|
||||
location.protocol + "//" + location.host + '/json.php?deleteComment',
|
||||
'id='+commentId);
|
||||
return false;
|
||||
}
|
||||
|
||||
function addfav( imageId, e ) {
|
||||
post(
|
||||
location.protocol + "//" + location.host + '/json.php?addfav',
|
||||
'id='+imageId);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// mouseover for rating stars
|
||||
function sr( id, scale ) {
|
||||
$( id ).style.backgroundPosition = ( (20 * scale) - 100 ) + 'px 0';
|
||||
}
|
||||
|
||||
function rate( imageId, score ) {
|
||||
$( 'loadRating' ).style.display = 'block';
|
||||
post(
|
||||
$('home').href + 'json.php?rate',
|
||||
'id='+imageId+'&score='+score,
|
||||
function() {
|
||||
q = ( eval('('+req.responseText+')') );
|
||||
$( 'loadRating' ).style.display = 'none';
|
||||
$( 'currentRating' ).style.width = 20 * parseFloat(q.score) + 'px';
|
||||
$( 'ratingDescription' ).innerHTML = q.score + ' after ' + q.votes + ' Vote' + ( q.votes > 1 ? 's' : '' );
|
||||
}
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
function s() {
|
||||
var q = $( 'q' );
|
||||
if( q && q.value ) {
|
||||
window.location = $('home').href + 'search/' + encodeURI( q.value );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
require_once( '../lib/config.php' );
|
||||
header( 'Content-type: text/javascript; charset=utf-8' );
|
||||
?>
|
||||
function RP_RemotePost( postURL, stylesheet ) {
|
||||
this.postURL = postURL;
|
||||
this.stylesheet = stylesheet;
|
||||
|
||||
this.visible = false;
|
||||
this.menu = null;
|
||||
this.dialog = null;
|
||||
this.iframe = null;
|
||||
this.checkSuccessInterval = 0;
|
||||
this.minImageSize = 32;
|
||||
|
||||
|
||||
this.create = function(){
|
||||
var that = this;
|
||||
var css = document.createElement('link');
|
||||
css.type = 'text/css';
|
||||
css.rel = 'stylesheet';
|
||||
css.href = this.stylesheet;
|
||||
if( document.getElementsByTagName("head").item(0) ) {
|
||||
document.getElementsByTagName("head").item(0).appendChild( css );
|
||||
} else {
|
||||
document.getElementsByTagName("body").item(0).appendChild( css );
|
||||
}
|
||||
|
||||
var closeButton = document.createElement('a');
|
||||
closeButton.appendChild( document.createTextNode("x") );
|
||||
closeButton.className = 'close';
|
||||
closeButton.onclick = function() { return that.toggle(); }
|
||||
closeButton.href = '#';
|
||||
|
||||
|
||||
this.dialog = document.createElement('div');
|
||||
this.dialog.id = 'RP_Dialog';
|
||||
this.iframe = document.createElement('iframe');
|
||||
this.iframe.src = 'about:blank';
|
||||
this.dialog.appendChild( this.iframe );
|
||||
this.dialog.appendChild( closeButton );
|
||||
document.body.appendChild( this.dialog );
|
||||
|
||||
this.loadIFrame( {} );
|
||||
}
|
||||
|
||||
|
||||
this.loadIFrame = function( params ) {
|
||||
var reqUrl = this.postURL + '?nocache=' + parseInt(Math.random()*10000);
|
||||
for( p in params ) {
|
||||
reqUrl += '&' + p + '=' + encodeURIComponent( params[p] );
|
||||
}
|
||||
this.iframe.src = reqUrl;
|
||||
}
|
||||
|
||||
|
||||
this.selectImage = function( image ) {
|
||||
var title = image.title ? image.title : ( image.alt ? image.alt : document.title );
|
||||
var imageSrc = image.src;
|
||||
if(
|
||||
image.parentNode.tagName.match(/^a$/i) &&
|
||||
image.parentNode.href &&
|
||||
image.parentNode.href.match(/\.(jpe?g|gif|png)$/i)
|
||||
) {
|
||||
imageSrc = image.parentNode.href;
|
||||
}
|
||||
this.loadIFrame( {
|
||||
'url': imageSrc,
|
||||
'xhrLocation': document.location.href.replace(/#.*$/,'')
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
this.checkSuccess = function() {
|
||||
if( document.location.href.match(/#RP_Success/) ) {
|
||||
var that = this;
|
||||
document.location.href = document.location.href.replace(/#.*$/, '#');
|
||||
setTimeout( function() { that.hide() }, 500 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.show = function() {
|
||||
this.visible = true;
|
||||
var that = this;
|
||||
|
||||
this.checkSuccessInterval = setInterval( function() { that.checkSuccess(); }, 500 );
|
||||
this.dialog.style.display = 'block';
|
||||
|
||||
var images = document.getElementsByTagName('img');
|
||||
for( var i=0; i<images.length; i++ ) {
|
||||
var img = images[i];
|
||||
if( img && img.src && img.src.match(/(space|blank)[^\/]*\.gif$/i) ) {
|
||||
img.style.display = 'none';
|
||||
}
|
||||
else if( img && img.src && img.width > this.minImageSize && img.height > this.minImageSize) {
|
||||
img.onclick = function( ev ) {
|
||||
if( ev && ev.stopPropagation ) {
|
||||
ev.stopPropagation();
|
||||
}
|
||||
return that.selectImage(this);
|
||||
};
|
||||
img.className = img.className ? img.className + ' RP_PostImage' : 'RP_PostImage';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.hide = function() {
|
||||
this.visible = false;
|
||||
|
||||
clearInterval( this.checkSuccessInterval );
|
||||
this.dialog.style.display = 'none';
|
||||
|
||||
var images = document.getElementsByTagName('img');
|
||||
for( var i=0; i<images.length; i++ ) {
|
||||
var img = images[i];
|
||||
if( img && img.src && img.width > this.minImageSize && img.height > this.minImageSize) {
|
||||
img.onclick = null;
|
||||
img.className = img.className.replace(/\s*RP_PostImage/, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.toggle = function() {
|
||||
if( !this.visible ) {
|
||||
this.show();
|
||||
} else {
|
||||
this.hide();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
this.create();
|
||||
}
|
||||
|
||||
if( typeof(RP_Instance) == 'undefined' ) {
|
||||
var RP_Instance = new RP_RemotePost(
|
||||
'<?php echo Config::$frontendPath; ?>remotepost.php',
|
||||
'<?php echo Config::$frontendPath; ?>media/remotepost.css'
|
||||
);
|
||||
}
|
||||
RP_Instance.toggle();
|
||||
@@ -0,0 +1,44 @@
|
||||
var nextImage = {};
|
||||
var preload = null;
|
||||
function quickTag( logId, imageId, inputField ) {
|
||||
var tags = encodeURIComponent(inputField.value);
|
||||
|
||||
// swap nextImage
|
||||
$('imageLocation').href = nextImage['link'];
|
||||
$('imageLocation').innerHTML = nextImage['link'];
|
||||
$('imageId').value = nextImage['id'];
|
||||
$('logId').value = nextImage['logId'];
|
||||
$('image').src = nextImage['image'];
|
||||
$('tags').innerHTML = nextImage['tags'];
|
||||
$('tagText').value = '';
|
||||
$('tagText').focus();
|
||||
|
||||
if( !nextImage['link'] ) {
|
||||
$('imageInfo').innerHTML = 'No more Images found';
|
||||
}
|
||||
|
||||
post(
|
||||
$('home').href + 'json.php?quickTag',
|
||||
'logId='+logId+'&id='+imageId+'&tags='+tags,
|
||||
function(){
|
||||
nextImage = ( eval('('+req.responseText+')') );
|
||||
preload = new Image(1,1)
|
||||
preload.src=nextImage['image'];
|
||||
}
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
function quickTagInit() {
|
||||
swap($('quickTagIntro'), 'article', 'hidden');
|
||||
swap($('viewer'), 'hidden', 'visible');
|
||||
post(
|
||||
$('home').href + 'json.php?quickTag',
|
||||
'',
|
||||
function(){
|
||||
nextImage = ( eval('('+req.responseText+')') );
|
||||
quickTag( 0, 0, $('tagText') );
|
||||
}
|
||||
);
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user