Commit c036ae43 authored by lrargerich's avatar lrargerich

Factorization of tikilib continues

parent fa0f7fde
......@@ -1003,7 +1003,9 @@ tiki/lib/diff.php -text
tiki/lib/directory/dirlib.php -text
tiki/lib/faqs/faqlib.php -text
tiki/lib/filegals/filegallib.php -text
tiki/lib/games/gamelib.php -text
tiki/lib/htmlpages/htmlpageslib.php -text
tiki/lib/imagegals/imagegallib.php -text
tiki/lib/jHotDraw/ATEXT1.gif -text
tiki/lib/jHotDraw/ATEXT2.gif -text
tiki/lib/jHotDraw/ATEXT3.gif -text
......@@ -1074,10 +1076,14 @@ tiki/lib/pclzip-trace.lib.php -text
tiki/lib/pclzip.lib.php -text
tiki/lib/phplot.php -text
tiki/lib/quizzes/quizlib.php -text
tiki/lib/refererstats/refererlib.php -text
tiki/lib/registration/registrationlib.php -text
tiki/lib/search/searchstatslib.php -text
tiki/lib/searchlib.php -text
tiki/lib/stats/statslib.php -text
tiki/lib/structures/structlib.php -text
tiki/lib/surveys/surveylib.php -text
tiki/lib/taglines/taglinelib.php -text
tiki/lib/tar.class.php -text
tiki/lib/tasks/tasklib.php -text
tiki/lib/templates/templateslib.php -text
......@@ -1085,6 +1091,7 @@ tiki/lib/tiki-js.js -text
tiki/lib/tikilib.php -text
tiki/lib/trackers/trackerlib.php -text
tiki/lib/usermodules/usermoduleslib.php -text
tiki/lib/userprefs/userprefslib.php -text
tiki/lib/userslib.php -text
tiki/lib/webmail/API.txt -text
tiki/lib/webmail/class.rc4crypt.php -text
......@@ -1111,6 +1118,7 @@ tiki/lib/wiki-plugins/wikiplugin_example.php -text
tiki/lib/wiki-plugins/wikiplugin_gauge.php -text
tiki/lib/wiki-plugins/wikiplugin_split.php -text
tiki/lib/wiki-plugins/wikiplugin_sql.php -text
tiki/lib/wiki/exportlib.php -text
tiki/lib/wiki/wikilib.php -text
tiki/lib/xmlrpc.inc -text
tiki/lib/xmlrpcs.inc -text
......
......@@ -153,6 +153,67 @@ class FileGalLib extends TikiLib {
$galleryId=$this->getOne("select max(galleryId) from tiki_file_galleries where name='$name' and lastModif=$now");
}
return $galleryId;
}
function process_batch_file_upload($galleryId,$file,$user,$description)
{
global $fgal_match_regex;
global $fgal_nmatch_regex;
global $fgal_use_db;
global $fgal_use_dir;
$description = addslashes($description);
include_once('lib/pclzip.lib.php');
$archive = new PclZip($file);
$archive->extract('temp');
$files=Array();
$h = opendir("temp");
$gal_info = $this->get_gallery($galleryId);
while (($file = readdir($h)) !== false) {
if( $file!='.' && $file!='..' && is_file("temp/$file") && $file!='license.txt' ) {
$files[]=$file;
// check filters
$upl=1;
if(!empty($fgal_match_regex)) {
if(!preg_match("/$gal_match_regex/",$file,$reqs)) $upl=0;
}
if(!empty($fgal_nmatch_regex)) {
if(preg_match("/$gal_nmatch_regex/",$file,$reqs)) $upl=0;
}
$fp = fopen('temp/'.$file,"rb");
$data = '';
$fhash='';
if($fgal_use_db == 'n') {
$fhash = md5($name = $file);
@$fw = fopen($fgal_use_dir.$fhash,"w");
if(!$fw) {
$smarty->assign('msg',tra('Cannot write to this file:').$fhash);
$smarty->display("styles/$style_base/error.tpl");
die;
}
}
while(!feof($fp)) {
if($fgal_use_db == 'y') {
$data .= fread($fp,8192*16);
} else {
$data = fread($fp,8192*16);
fwrite($fw,$data);
}
}
fclose($fp);
if($fgal_use_db == 'n') {
fclose($fw);
$data='';
}
$size = filesize('temp/'.$file);
$name = $file;
$type = '';
$fileId = $this->insert_file($galleryId,$name,$description,$name, $data, $size, '', $user,$fhash);
unlink('temp/'.$file);
}
}
closedir($h);
}
}
......
<?php
class GameLib extends TikiLib {
function GameLib($db)
{
# this is probably uneeded now
if(!$db) {
die("Invalid db object passed to UsersLib constructor");
}
$this->db = $db;
}
function add_game_hit($game)
{
$cant = $this->getOne("select count(*) from tiki_games where gameName='$game'");
if($cant) {
$query = "update tiki_games set hits = hits+1 where gameName='$game'";
} else {
$query = "insert into tiki_games(gameName,hits,points,votes) values('$game',1,0,0)";
}
$result = $this->query($query);
}
function get_game_hits($game)
{
$cant = $this->getOne("select count(*) from tiki_games where gameName='$game'");
if($cant) {
$hits = $this->getOne("select hits from tiki_games where gameName='$game'");
} else {
$hits =0;
}
return $hits;
}
}
$gamelib= new GameLib($dbTiki);
?>
\ No newline at end of file
<?php
class ImageGalsLib extends TikiLib {
function ImageGalsLib($db)
{
# this is probably uneeded now
if(!$db) {
die("Invalid db object passed to UsersLib constructor");
}
$this->db = $db;
}
// Batch image uploads ////
// Batch image uploads ////
// Fixed by FLO
function process_batch_image_upload($galleryId,$file,$user)
{
global $gal_match_regex;
global $gal_nmatch_regex;
global $gal_use_db;
global $gal_use_dir;
global $tmpDir;
$numimages=0;
include_once('lib/pclzip.lib.php');
$archive = new PclZip($file);
// Read Archive contents
$ziplist=$archive->listContent();
if (!$ziplist) return(false); // Archive invalid
for ($i=0; $i<sizeof($ziplist); $i++) {
$file=$ziplist["$i"]["filename"];
if (!$ziplist["$i"]["folder"]) {
//copied
$gal_info = $this->get_gallery($galleryId);
$upl=1;
if(!empty($gal_match_regex)) {
if(!preg_match("/$gal_match_regex/",$file,$reqs)) $upl=0;
}
if(!empty($gal_nmatch_regex)) {
if(preg_match("/$gal_nmatch_regex/",$file,$reqs)) $upl=0;
}
//extract file
$archive->extractByIndex($ziplist["$i"]["index"],$tmpDir,dirname($file)); //extract and remove (dangerous) pathname
$file=basename($file);
//determine filetype and dimensions
$imageinfo=getimagesize($tmpDir."/".$file);
if ($imageinfo["0"] > 0 && $imageinfo["1"] > 0 && $imageinfo["2"] > 0 ) {
if (chkgd2()) {
$type = $imageinfo["mime"];
} else {
$mimetypes=array("1" => "gif", "2" => "jpg", "3" => "png",
"4" => "swf", "5" => "psd", "6" => "bmp",
"7" => "tiff", "8" => "tiff", "9" => "jpc",
"10" => "jp2", "11" => "jpx", "12" => "jb2",
"13" => "swc", "14" => "iff");
$type="image/".$mimetypes[$imageinfo["2"]];
}
$exp=substr($file,strlen($file)-3,3);
$fp = fopen($tmpDir."/".$file,"rb");
$size=filesize($tmpDir."/".$file);
$data = fread($fp,$size);
fclose($fp);
if(function_exists("ImageCreateFromString")&&(!strstr($type,"gif"))) {
$img = imagecreatefromstring($data);
$size_x = imagesx($img);
$size_y = imagesy($img);
if ($size_x > $size_y)
$tscale = ((int)$size_x / $gal_info["thumbSizeX"]);
else
$tscale = ((int)$size_y / $gal_info["thumbSizeY"]);
$tw = ((int)($size_x / $tscale));
$ty = ((int)($size_y / $tscale));
if (chkgd2()) {
$t = imagecreatetruecolor($tw,$ty);
imagecopyresampled($t, $img, 0,0,0,0, $tw,$ty, $size_x, $size_y);
} else {
$t = imagecreate($tw,$ty);
$this->ImageCopyResampleBicubic( $t, $img, 0,0,0,0, $tw,$ty, $size_x, $size_y);
}
// CHECK IF THIS TEMP IS WRITEABLE OR CHANGE THE PATH TO A WRITEABLE DIRECTORY
//$tmpfname = 'temp.jpg';
$tmpfname = tempnam ($tmpDir , "FOO").'.jpg';
imagejpeg($t,$tmpfname);
// Now read the information
$fp = fopen($tmpfname,"rb");
$t_data = fread($fp, filesize($tmpfname));
fclose($fp);
unlink($tmpfname);
$t_pinfo = pathinfo($tmpfname);
$t_type = $t_pinfo["extension"];
$t_type='image/'.$t_type;
$imageId = $this->insert_image($galleryId,$file,'',$file, $type, $data, $size, $size_x, $size_y, $user,$t_data,$t_type);
$numimages++;
unlink($tmpDir."/".$file);
} else {
$tmpfname='';
$imageId = $this->insert_image($galleryId,$file,'',$file, $type, $data, $size, 0, 0, $user,'','');
$numimages++;
unlink($tmpDir."/".$file);
}
}
}
}
return $numimages;
}
}
$imagegallib= new ImageGalsLib($dbTiki);
?>
\ No newline at end of file
<?php
class RefererLib extends TikiLib {
function RefererLib($db)
{
# this is probably uneeded now
if(!$db) {
die("Invalid db object passed to UsersLib constructor");
}
$this->db = $db;
}
function clear_referer_stats()
{
$query = "delete from tiki_referer_stats";
$result = $this->query($query);
}
function list_referer_stats($offset,$maxRecords,$sort_mode,$find)
{
$sort_mode = str_replace("_"," ",$sort_mode);
if($find) {
$mid=" where (referer like '%".$find."%')";
} else {
$mid="";
}
$query = "select * from tiki_referer_stats $mid order by $sort_mode limit $offset,$maxRecords";
$query_cant = "select count(*) from tiki_referer_stats $mid";
$result = $this->query($query);
$cant = $this->getOne($query_cant);
$ret = Array();
while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$ret[] = $res;
}
$retval = Array();
$retval["data"] = $ret;
$retval["cant"] = $cant;
return $retval;
}
}
$refererlib= new RefererLib($dbTiki);
?>
\ No newline at end of file
<?php
class RegistrationLib extends TikiLib {
function RegistrationLib($db)
{
# this is probably uneeded now
if(!$db) {
die("Invalid db object passed to UsersLib constructor");
}
$this->db = $db;
}
// Validate emails...
function SnowCheckMail($Email,$Debug=false)
{
$HTTP_HOST=$_SERVER['HTTP_HOST'];
$Return =array();
// Variable for return.
// $Return[0] : [true|false]
// $Return[1] : Processing result save.
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)) {
$Return[0]=false;
$Return[1]="${Email} is E-Mail form that is not right.";
if ($Debug) echo "Error : {$Email} is E-Mail form that is not right.<br>";
return $Return;
}
else if ($Debug) echo "Confirmation : {$Email} is E-Mail form that is not right.<br>";
// E-Mail @ by 2 by standard divide. if it is $Email this "[email protected]"..
// $Username : lsm
// $Domain : ebeecomm.com
// list function reference : http://www.php.net/manual/en/function.list.php
// split function reference : http://www.php.net/manual/en/function.split.php
list ( $Username, $Domain ) = split ("@",$Email);
// That MX(mail exchanger) record exists in domain check .
// checkdnsrr function reference : http://www.php.net/manual/en/function.checkdnsrr.php
if ( checkdnsrr ( $Domain, "MX" ) ) {
if($Debug) echo "Confirmation : MX record about {$Domain} exists.<br>";
// If MX record exists, save MX record address.
// getmxrr function reference : http://www.php.net/manual/en/function.getmxrr.php
if ( getmxrr ($Domain, $MXHost)) {
if($Debug) {
echo "Confirmation : Is confirming address by MX LOOKUP.<br>";
for ( $i = 0,$j = 1; $i < count ( $MXHost ); $i++,$j++ ) {
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result($j) - $MXHost[$i]<BR>";
}
}
}
// Getmxrr function does to store MX record address about $Domain in arrangement form to $MXHost.
// $ConnectAddress socket connection address.
$ConnectAddress = $MXHost[0];
}
else {
// If there is no MX record simply @ to next time address socket connection do .
$ConnectAddress = $Domain;
if ($Debug) echo "Confirmation : MX record about {$Domain} does not exist.<br>";
}
// fsockopen function reference : http://www.php.net/manual/en/function.fsockopen.php
$Connect = fsockopen ( $ConnectAddress, 25 );
// Success in socket connection
if ($Connect)
{
if ($Debug) echo "Connection succeeded to {$ConnectAddress} SMTP.<br>";
// Judgment is that service is preparing though begin by 220 getting string after connection .
// fgets function reference : http://www.php.net/manual/en/function.fgets.php
if ( ereg ( "^220", $Out = fgets ( $Connect, 1024 ) ) ) {
// Inform client's reaching to server who connect.
fputs ( $Connect, "HELO $HTTP_HOST\r\n" );
if ($Debug) echo "Run : HELO $HTTP_HOST<br>";
$Out = fgets ( $Connect, 1024 ); // Receive server's answering cord.
// Inform sender's address to server.
fputs ( $Connect, "MAIL FROM: <{$Email}>\r\n" );
if ($Debug) echo "Run : MAIL FROM: &lt;{$Email}&gt;<br>";
$From = fgets ( $Connect, 1024 ); // Receive server's answering cord.
// Inform listener's address to server.
fputs ( $Connect, "RCPT TO: <{$Email}>\r\n" );
if ($Debug) echo "Run : RCPT TO: &lt;{$Email}&gt;<br>";
$To = fgets ( $Connect, 1024 ); // Receive server's answering cord.
// Finish connection.
fputs ( $Connect, "QUIT\r\n");
if ($Debug) echo "Run : QUIT<br>";
fclose($Connect);
// Server's answering cord about MAIL and TO command checks.
// Server about listener's address reacts to 550 codes if there does not exist
// checking that mailbox is in own E-Mail account.
if ( !ereg ( "^250", $From ) || !ereg ( "^250", $To )) {
$Return[0]=false;
$Return[1]="${Email} is address done not admit in E-Mail server.";
if ($Debug) echo "{$Email} is address done not admit in E-Mail server.<br>";
return $Return;
}
}
}
// Failure in socket connection
else {
$Return[0]=false;
$Return[1]="Can not connect E-Mail server ({$ConnectAddress}).";
if ($Debug) echo "Can not connect E-Mail server ({$ConnectAddress}).<br>";
return $Return;
}
$Return[0]=true;
$Return[1]="{$Email} is E-Mail address that there is no any problem.";
return $Return;
}
}
$registrationlib= new RegistrationLib($dbTiki);
?>
<?php
class SearchStatsLib extends TikiLib {
function SearchStatsLib($db)
{
# this is probably uneeded now
if(!$db) {
die("Invalid db object passed to UsersLib constructor");
}
$this->db = $db;
}
function clear_search_stats()
{
$query = "delete from tiki_search_stats";
$result = $this->query($query);
}
function list_search_stats($offset,$maxRecords,$sort_mode,$find)
{
$sort_mode = str_replace("_"," ",$sort_mode);
if($find) {
$mid=" where (term like '%".$find."%')";
} else {
$mid="";
}
$query = "select * from tiki_search_stats $mid order by $sort_mode limit $offset,$maxRecords";
$query_cant = "select count(*) from tiki_search_stats $mid";
$result = $this->query($query);
$cant = $this->getOne($query_cant);
$ret = Array();
while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$ret[] = $res;
}
$retval = Array();
$retval["data"] = $ret;
$retval["cant"] = $cant;
return $retval;
}
}
$searchstatslib= new SearchStatsLib($dbTiki);
?>
\ No newline at end of file
......@@ -10,6 +10,23 @@ class SearchLib Extends TikiLib {
}
$this->db = $db;
}
function register_search($words)
{
$words=addslashes($words);
$words = preg_split("/\s/",$words);
foreach($words as $word) {
$word=trim($word);
$cant = $this->getOne("select count(*) from tiki_search_stats where term='$word'");
if($cant) {
$query = "update tiki_search_stats set hits=hits+1 where term='$word'";
} else {
$query = "insert into tiki_search_stats(term,hits) values('$word',1)";
}
$result = $this->query($query);
}
}
function _find($h, $words = '', $offset = 0, $maxRecords = -1, $fulltext = false) {
$words = trim($words);
......
<?php
class TagLineLib extends TikiLib {
function TagLineLib($db)
{
# this is probably uneeded now
if(!$db) {
die("Invalid db object passed to UsersLib constructor");
}
$this->db = $db;
}
function list_cookies($offset,$maxRecords,$sort_mode,$find)
{
$sort_mode = str_replace("_"," ",$sort_mode);
if($find) {
$mid=" where (cookie like '%".$find."%')";
} else {
$mid="";
}
$query = "select * from tiki_cookies $mid order by $sort_mode limit $offset,$maxRecords";
$query_cant = "select count(*) from tiki_cookies $mid";
$result = $this->query($query);
$cant = $this->getOne($query_cant);
$ret = Array();
while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$ret[] = $res;
}
$retval = Array();
$retval["data"] = $ret;
$retval["cant"] = $cant;
return $retval;
}
function replace_cookie($cookieId, $cookie)
{
$cookie=addslashes($cookie);
// Check the name
if($cookieId) {
$query = "update tiki_cookies set cookie='$cookie' where cookieId=$cookieId";
} else {
$query = "replace into tiki_cookies(cookie)
values('$cookie')";
}
$result = $this->query($query);
return true;
}
function remove_cookie($cookieId)
{
$query = "delete from tiki_cookies where cookieId=$cookieId";
$result = $this->query($query);
return true;
}
function get_cookie($cookieId)
{
$query = "select * from tiki_cookies where cookieId=$cookieId";
$result = $this->query($query);
if(!$result->numRows()) return false;
$res = $result->fetchRow(DB_FETCHMODE_ASSOC);
return $res;
}
function remove_all_cookies()
{
$query = "delete from tiki_cookies";
$result = $this->query($query);
}
}
$taglinelib= new TagLineLib($dbTiki);
?>
\ No newline at end of file
This diff is collapsed.
<?php
class UserPrefsLib extends TikiLib {
function UserPrefsLib($db)
{
# this is probably uneeded now
if(!$db) {
die("Invalid db object passed to UsersLib constructor");
}
$this->db = $db;
}
function set_user_avatar($user,$type,$avatarLibName,$avatarName,$avatarSize,$avatarType,$avatarData)
{
$avatarData = addslashes($avatarData);
$avatarName = addslashes($avatarName);
$query = "update users_users set
avatarType = '$type',
avatarLibName = '$avatarLibName',
avatarName = '$avatarName',
avatarSize = '$avatarSize',
avatarFileType = '$avatarType',
avatarData = '$avatarData'
where login='$user'";
$result = $this->query($query);
}
function get_user_avatar_img($user)
{
$query = "select * from users_users where login='$user'";
$result = $this->query($query);
if(!$result->numRows()) return false;
$res = $result->fetchRow(DB_FETCHMODE_ASSOC);
return $res;
}
}
$userprefslib= new UserPrefsLib($dbTiki);
?>
\ No newline at end of file
<?php
class ExportLib extends TikiLib {
function ExportLib($db)
{
# this is probably uneeded now
if(!$db) {
die("Invalid db object passed to UsersLib constructor");
}
$this->db = $db;
}
function MakeWikiZip()
{
$zipname = "wikidb.zip";
include_once("tar.class.php");
$tar = new tar();
$query = "select pageName from tiki_pages order by pageName asc";
$result = $this->query($query);
while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$page = $res["pageName"];
$content = $this->export_wiki_page($page, 0);
$tar->addData($page,$content,date("U"));
}
$tar->toTar("dump/export.tar",FALSE);