resolved merge conflict

This commit is contained in:
following
2013-02-16 23:50:55 +01:00
23 changed files with 1123 additions and 245 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
<?
<?php
/*
*------------------------------------------------------------
* BMP Image functions
+339
View File
@@ -42,6 +42,8 @@ class user
function __construct($nNewUserId=ID_NEW)
{
global $opt;
$this->reUser = new rowEditor('user');
$this->reUser->addPKInt('user_id', null, false, RE_INSERT_AUTOINCREMENT);
$this->reUser->addString('username', '', false);
@@ -71,6 +73,7 @@ class user
$this->reUser->addBoolean('no_htmledit_flag', false, false);
$this->reUser->addInt('notify_radius', 0, false);
$this->reUser->addInt('admin', 0, false);
$this->reUser->addInt('data_license', $opt['logic']['license'], false);
$this->reUser->addInt('node', 0, false);
$this->reUserStat = new rowEditor('stat_user');
@@ -722,6 +725,342 @@ class user
return true;
}
function canDisableDueLicense()
{
global $login;
$login->verify();
if ($login->userid != $this->nUserId && ($login->admin & ADMIN_USER) != ADMIN_USER)
return false;
else
return true;
}
/**
* disables user (if not disabled), removes all licensed content from db and
* replaces every picture with a dummy one
*
* @return bool false, if anything went wrong, true otherwise
*/
function disduelicense() {
// get translation-object
global $translate;
// check if disabled, disable if not
if (!$this->canDisableDueLicense())
return 'this user must not be disabled';
if ($this->canDisable())
if (!$this->disable())
return 'disable user failed';
// remember that data license was declined
sql("UPDATE user SET data_license=1 WHERE user_id='&1'", $this->getUserId());
/*
* set all cache_desc and hint to ''
*/
// check if there are caches
$num_caches = sql_value("SELECT COUNT(*) FROM `caches` WHERE `user_id`='&1'",
0, $this->getUserId());
if ($num_caches > 0) {
$cache_descs = array();
$rs = sql("SELECT `cache_desc`.`id`,`cache_desc`.`language` " .
"FROM `cache_desc`,`caches` " .
"WHERE `caches`.`cache_id`=`cache_desc`.`cache_id` " .
"AND `caches`.`user_id`='&1'",
$this->getUserId()
);
while ($cache_desc = sql_fetch_array($rs,MYSQL_ASSOC))
$cache_descs[] = $cache_desc;
sql_free_result($rs);
// walk through cache_descs and set message for each language
foreach ($cache_descs as $desc)
{
sql("UPDATE `cache_desc` " .
"SET `desc`='&1',`hint`='&2' " .
"WHERE `id`='&3'",
"<em>" . $translate->t('cache description was removed because owner declined content license', '', basename(__FILE__), __LINE__, '', 1, $desc['language']) . "</em>",
'',
$desc['id']
);
}
// replace pictures
$errmesg = $this->replace_pictures(OBJECT_CACHE);
if ($errmesg !== true)
return "removing cache pictures: $errmesg";
}
/*
* set all cache_logs ''
*/
// check if there are cache_logs
$num_cache_logs = sql_value("SELECT COUNT(*) " .
"FROM `cache_logs` " .
"WHERE `user_id`='&1'",
0,
$this->getUserId()
);
if ($num_cache_logs > 0) {
// set text ''
sql("UPDATE `cache_logs` " .
"SET `text`='&1' WHERE `user_id`='&2'",
"<em>Dieser Logtext wurde entfernt, weil der Benutzer die Opencaching.de-Datenlizenz abgelehnt hat." .
"<br /><br />" .
"This text has been deleted because the used declined the Opencaching.de data license.</em>",
$this->getUserId());
// replace pictures
$errmesg = $this->replace_pictures(OBJECT_CACHELOG);
if ($errmesg !== true)
return "removing log pictures: $errmesg";
}
// success
return true;
}
/**
* replaces all pictures of $this-user with a dummy for the given object-type
* @param int $object_type object_types-id from table object_types
* @return bool true, if replacement worked, false otherwise
*/
function replace_pictures($object_type) {
// get optionsarray
global $opt;
// load bmp-support
require_once($opt['rootpath'] . 'lib2/imagebmp.inc.php');
// paths cleared by trailing '/'
if (substr($opt['logic']['pictures']['dir'],-1) != '/')
$picpath = $opt['logic']['pictures']['dir'];
else
$picpath = substr($opt['logic']['pictures']['dir'],0,-1);
$thumbpath = "$picpath/thumbs";
$pdummy = isset($opt['logic']['pictures']['dummy']);
if ($pdummy && isset($opt['logic']['pictures']['dummy']['bgcolor']) && is_array($opt['logic']['pictures']['dummy']['bgcolor']))
$dummybg = $opt['logic']['pictures']['dummy']['bgcolor'];
else
$dummybg = array(255,255,255);
if ($pdummy && isset($opt['logic']['pictures']['dummy']['text']))
$dummytext = $opt['logic']['pictures']['dummy']['text'];
else
$dummytext = '';
if ($pdummy && isset($opt['logic']['pictures']['dummy']['textcolor']) && is_array($opt['logic']['pictures']['dummy']['textcolor']))
$dummytextcolor = $opt['logic']['pictures']['dummy']['textcolor'];
else
$dummytextcolor = array(0,0,0);
$tmh = 0;
$tmw = 0;
/*
* check log or cache
*/
if ($object_type == OBJECT_CACHE)
// get filenames of the pictures of $this' caches
$rs = sql("SELECT `pictures`.`url` " .
"FROM `pictures`,`caches` " .
"WHERE `caches`.`cache_id`=`pictures`.`object_id`" .
"AND `caches`.`user_id`='&1'",
$this->getUserId()
);
elseif ($object_type == OBJECT_CACHELOG)
// get filenames of the pictures of $this' logs
$rs = sql("SELECT `pictures`.`url` " .
"FROM `pictures`,`cache_logs` " .
"WHERE `cache_logs`.`id`=`pictures`.`object_id`" .
"AND `cache_logs`.`user_id`='&1'",
$this->getUserId()
);
// set thumb-dimensions
$tmh = $opt['logic']['pictures']['thumb_max_height'];
$tmw = $opt['logic']['pictures']['thumb_max_width'];
$filenames = array();
while ($url = sql_fetch_array($rs,MYSQL_NUM))
$filenames[] = substr($url['url'],-40);
// free result
sql_free_result($rs);
/*
* walk through filenames and replace original
*/
// check if there is something to replace
if (count($filenames) > 0) {
foreach ($filenames as $fn) {
// get uuid and extension
$uuid = substr($fn,0,36);
$ext = substr($fn,-3);
$thumb_dir1 = substr($uuid,0,1);
$thumb_dir2 = substr($uuid,1,1);
// read original size
if (file_exists("$picpath/$fn")) {
list($w,$h,$t,$attr) = getimagesize("$picpath/$fn");
} else {
$w = 600;
$h = 480;
}
// create new image
$im = imagecreatetruecolor($w,$h);
// allocate colors
$col_bg = imagecolorallocate($im,$dummybg[0],$dummybg[1],$dummybg[2]);
$col_text = imagecolorallocate($im,$dummytextcolor[0],$dummytextcolor[1],$dummytextcolor[2]);
// fill bg
imagefill($im,0,0,$col_bg);
// check for replacement-image
if ($pdummy && isset($opt['logic']['pictures']['dummy']['replacepic'])
&& $opt['logic']['pictures']['dummy']['replacepic'] != $opt['rootpath'] . 'images/'
&& file_exists($opt['logic']['pictures']['dummy']['replacepic'])) {
// get dimensions of the replacement
list($rw,$rh,$rt,$rattr) = getimagesize($opt['logic']['pictures']['dummy']['replacepic']);
$rwh = 0;
if($rw > $rh) {
$rwh = $rh;
} else {
$rwh = $rw;
}
// check dimensions of original and set replacement size
$rsize = 0;
if ($w > $h) {
if(($h * 0.85) > $rwh) {
$rsize = $rwh;
} else {
$rsize = $h * 0.9;
}
} else {
if(($w * 0.85) > $rwh) {
$rsize = $rwh;
} else {
$rsize = $w * 0.9;
}
}
$dx = ($w-$rsize)/2;
$dy = ($h-$rsize)/2;
// get replacement image
$rext = substr($opt['logic']['pictures']['dummy']['replacepic'],-3);
$rim = null;
if ($rext == 'jpg') {
$rim = imagecreatefromjpeg($opt['logic']['pictures']['dummy']['replacepic']);
} elseif ($rext == 'png') {
$rim = imagecreatefrompng($opt['logic']['pictures']['dummy']['replacepic']);
} elseif ($rext == 'gif') {
$rim = imagecreatefromgif($opt['logic']['pictures']['dummy']['replacepic']);
} elseif ($rext == 'bmp') {
$rim = imagecreatefrombmp($opt['logic']['pictures']['dummy']['replacepic']);
}
// copy image
if (!is_null($rim))
imagecopyresampled($im, $rim, $dx, $dy, 0, 0, $rsize, $rsize, $rw, $rh);
} else {
// set text
if ($dummytext != '')
imagestring($im,1,10,$h/2,$dummytext,$col_text);
else {
imageline($im,0,0,$w,$h,0xff0000);
imageline($im,0,$h,$w,0,0xff0000);
}
}
// save dummy
if ($ext == 'jpg') {
if (!imagejpeg($im,"$picpath/$fn",75))
return "save dummy failed [$ext]";
} elseif ($ext == 'png') {
if (!imagepng($im,"$picpath/$fn",4))
return "save dummy failed [$ext]";
} elseif ($ext == 'gif') {
if (!imagegif($im,"$picpath/$fn"))
return "save dummy failed [$ext]";
} elseif ($ext == 'bmp') {
if (!imagebmp($im,"$picpath/$fn"))
return "save dummy failed [$ext]";
} else {
return "save dummy failed [$ext], unknown extension";
}
// set thumb-dimensions
if (($h > $tmh) || ($w > $tmw))
{
if ($h > $w)
{
$th = $tmh;
$tw = $w * ($th / $h);
}
else
{
$tw = $tmw;
$th = $h * ($tw / $w);
}
}
else
{
$tw = $w;
$th = $h;
}
// copy dummy
$tim = imagecreatetruecolor($tw, $th);
imagecopyresampled($tim, $im, 0, 0, 0, 0, $tw, $th, $w, $h);
// check directories or create them
if (!file_exists("$thumbpath/$thumb_dir1"))
if (!mkdir("$thumbpath/$thumb_dir1")) {
return 'mkdir in thumbpath failed';
}
if (!file_exists("$thumbpath/$thumb_dir1/$thumb_dir2")){
if (!mkdir("$thumbpath/$thumb_dir1/$thumb_dir2"))
return 'mkdir in thumbpath failed';
}
// save thumb
if ($ext == 'jpg') {
if (!imagejpeg($tim,"$thumbpath/$thumb_dir1/$thumb_dir2/$fn",75))
return "save thumb failed [$ext]";
} elseif ($ext == 'png') {
if (!imagepng($tim,"$thumbpath/$thumb_dir1/$thumb_dir2/$fn",4))
return "save thumb failed [$ext]";
} elseif($ext == 'gif') {
if (!imagegif($tim,"$thumbpath/$thumb_dir1/$thumb_dir2/$fn"))
return "save thumb failed [$ext]";
} elseif($ext == 'bmp') {
if (!imagebmp($tim,"$thumbpath/$thumb_dir1/$thumb_dir2/$fn"))
return "save thumb failed [$ext]";
} else {
return "save thumb failed [$ext], unknown extension";
}
}
}
// success
return true;
}
function canDelete()
{