Commit fa0f7fde authored by lrargerich's avatar lrargerich

Tikilib factorization continues

parent 33df86ef
......@@ -991,15 +991,18 @@ tiki/lib/Date/TimeZoneWindows.php -text
tiki/lib/NNTP.php -text
tiki/lib/bablotron.php -text
tiki/lib/backups/backupslib.php -text
tiki/lib/blogs/bloglib.php -text
tiki/lib/categories/categlib.php -text
tiki/lib/class.ezpdf.php.exe -text
tiki/lib/class_calendar.php -text
tiki/lib/class_rdf_parser.php -text
tiki/lib/class_rss_parser.php -text
tiki/lib/commcenter/commlib.php -text
tiki/lib/commentslib.php -text
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/htmlpages/htmlpageslib.php -text
tiki/lib/jHotDraw/ATEXT1.gif -text
tiki/lib/jHotDraw/ATEXT2.gif -text
......@@ -1059,6 +1062,7 @@ tiki/lib/jHotDraw/example.map -text
tiki/lib/jHotDraw/twikidraw.jar -text
tiki/lib/mailin/mailinlib.php -text
tiki/lib/md5.js -text
tiki/lib/menubuilder/menulib.php -text
tiki/lib/messu/messulib.php -text
tiki/lib/newsletters/nllib.php -text
tiki/lib/newsreader/newslib.php -text
......
<?php # $Header: /cvsroot/tikiwiki/tiki/commxmlrpc.php,v 1.6 2003-01-04 19:34:15 rossta Exp $
<?php # $Header: /cvsroot/tikiwiki/tiki/commxmlrpc.php,v 1.7 2003-03-21 14:42:42 lrargerich Exp $
include_once('db/tiki-db.php');
include_once('lib/tikilib.php');
include_once('lib/userslib.php');
include_once("lib/xmlrpc.inc");
include_once("lib/xmlrpcs.inc");
include_once('lib/commcenter/commlib.php');
......@@ -47,7 +48,7 @@ function sendPage($params) {
// Store the page in the tiki_received_pages_table
$data = base64_decode($data);
$tikilib->receive_page($pageName,$data,$comment,$site,$username,$description);
$commlib->receive_page($pageName,$data,$comment,$site,$username,$description);
/*
if () {
return new xmlrpcresp(new xmlrpcval(1,"boolean"));
......@@ -98,7 +99,7 @@ function sendArticle($params) {
$heading = base64_decode($heading);
$body = base64_decode($body);
$tikilib->receive_article($site,$username,$title,$authorName,$size,$use_image,$image_name,$image_type,$image_size,$image_x,$image_y,$image_data,$publishDate,$created,$heading,$body,$hash,$author,$type,$rating);
$commlib->receive_article($site,$username,$title,$authorName,$size,$use_image,$image_name,$image_type,$image_size,$image_x,$image_y,$image_data,$publishDate,$created,$heading,$body,$hash,$author,$type,$rating);
return new xmlrpcresp(new xmlrpcval(1,"boolean"));
}
......
<?php
class BlogLib extends TikiLib {
function BlogLib($db)
{
# this is probably uneeded now
if(!$db) {
die("Invalid db object passed to UsersLib constructor");
}
$this->db = $db;
}
function add_blog_hit($blogId)
{
$query = "update tiki_blogs set hits = hits+1 where blogId=$blogId";
$result = $this->query($query);
return true;
}
function replace_blog($title,$description,$user,$public,$maxPosts,$blogId)
{
$title = addslashes($title);
$description = addslashes($description);
$now = date("U");
if($blogId) {
$query = "update tiki_blogs set title='$title',description='$description',user='$user',public='$public',lastModif=$now,maxPosts=$maxPosts where blogId=$blogId";
$result = $this->query($query);
} else {
$query = "insert into tiki_blogs(created,lastModif,title,description,user,public,posts,maxPosts,hits)
values($now,$now,'$title','$description','$user','$public',0,$maxPosts,0)";
$result = $this->query($query);
$query2 = "select max(blogId) from tiki_blogs where lastModif=$now";
$blogId=$this->getOne($query2);
}
return $blogId;
}
function list_blog_posts($blogId, $offset = 0,$maxRecords = -1,$sort_mode = 'created_desc', $find='', $date='')
{
$sort_mode = str_replace("_"," ",$sort_mode);
if($find) {
$mid=" where blogId=$blogId and (data like '%".$find."%') ";
} else {
$mid=" where blogId=$blogId ";
}
if($date) {
$mid.=" and created<=$date ";
}
$query = "select * from tiki_blog_posts $mid order by $sort_mode limit $offset,$maxRecords";
$query_cant = "select count(*) from tiki_blog_posts $mid";
$result = $this->query($query);
$cant = $this->getOne($query_cant);
$ret = Array();
while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$hash=md5('post'.$res["postId"]);
$cant_com = $this->getOne("select count(*) from tiki_comments where object='$hash'");
$res["comments"]=$cant_com;
$ret[] = $res;
}
$retval = Array();
$retval["data"] = $ret;
$retval["cant"] = $cant;
return $retval;
}
function list_all_blog_posts($offset = 0,$maxRecords = -1,$sort_mode = 'created_desc', $find='', $date='')
{
$sort_mode = str_replace("_"," ",$sort_mode);
if($find) {
$mid=" where (data like '%".$find."%') ";
} else {
$mid="";
}
if($date) {
if($mid) {
$mid.=" and created<=$date ";
} else {
$mid.=" where created<=$date ";
}
}
$query = "select * from tiki_blog_posts $mid order by $sort_mode limit $offset,$maxRecords";
$query_cant = "select count(*) from tiki_blog_posts $mid";
$result = $this->query($query);
$cant = $this->getOne($query_cant);
$ret = Array();
while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$query2 = "select title from tiki_blogs where blogId=".$res["blogId"];
$title = $this->getOne($query2);
$res["blogtitle"]=$title;
$ret[] = $res;
}
$retval = Array();
$retval["data"] = $ret;
$retval["cant"] = $cant;
return $retval;
}
function blog_post($blogId,$data,$user)
{
// update tiki_blogs and call activity functions
$data = strip_tags($data, '<a><b><i><h1><h2><h3><h4><h5><h6><ul><li><ol><br><p><table><tr><td><img><pre>');
$data=addslashes($data);
$now = date("U");
$query = "insert into tiki_blog_posts(blogId,data,created,user) values($blogId,'$data',$now,'$user')";
$result = $this->query($query);
$query = "select max(postId) from tiki_blog_posts where created=$now and user='$user'";
$id = $this->getOne($query);
$query = "update tiki_blogs set lastModif=$now,posts=posts+1 where blogId=$blogId";
$result = $this->query($query);
$this->add_blog_activity($blogId);
return $id;
}
function remove_blog($blogId)
{
$query = "delete from tiki_blogs where blogId=$blogId";
$result = $this->query($query);
$query = "delete from tiki_blog_posts where blogId=$blogId";
$result = $this->query($query);
$this->remove_object('blog',$blogId);
return true;
}
function remove_post($postId)
{
$query = "select blogId from tiki_blog_posts where postId=$postId";
$blogId = $this->getOne($query);
if($blogId) {
$query = "delete from tiki_blog_posts where postId=$postId";
$result = $this->query($query);
$query = "update tiki_blogs set posts=posts-1 where blogId=$blogId";
$result = $this->query($query);
}
return true;
}
function get_post($postId)
{
$query = "select * from tiki_blog_posts where postId=$postId";
$result = $this->query($query);
if($result->numRows()) {
$res = $result->fetchRow(DB_FETCHMODE_ASSOC);
} else {
return false;
}
return $res;
}
function update_post($postId,$data,$user)
{
$data = addslashes($data);
$query = "update tiki_blog_posts set data='$data',user='$user' where postId=$postId";
$result = $this->query($query);
}
function list_user_posts($user,$offset = 0,$maxRecords = -1,$sort_mode = 'created_desc', $find='')
{
$sort_mode = str_replace("_"," ",$sort_mode);
if($find) {
$mid=" where user=$user and (data like '%".$find."%') ";
} else {
$mid=' where user=$user ';
}
$query = "select * from tiki_blog_posts $mid order by $sort_mode limit $offset,$maxRecords";
$query_cant = "select count(*) from tiki_blog_posts $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 add_blog_activity($blogId)
{
//Caclulate activity, update tiki_blogs and purge activity table
$today = mktime(0,0,0,date("m"),date("d"),date("Y"));
$day0 = $today - (24*60*60);
$day1 = $today - (2*24*60*60);
$day2 = $today - (3*24*60*60);
// Purge old activity
$query="delete from tiki_blog_activity where day<$day2";
$result = $this->query($query);
// Register new activity
$query = "select * from tiki_blog_activity where blogId=$blogId and day=$today";
$result = $this->query($query);
if($result->numRows()) {
$query = "update tiki_blog_activity set posts=posts+1 where blogId=$blogId and day=$today";
} else {
$query = "insert into tiki_blog_activity(blogId,day,posts) values($blogId,$today,1)";
}
$result = $this->query($query);
// Calculate activity
$query = "select posts from tiki_blog_activity where blogId=$blogId and day=$today";
$vtoday = $this->getOne($query);
$query = "select posts from tiki_blog_activity where blogId=$blogId and day=$day0";
$day0 = $this->getOne($query);
$query = "select posts from tiki_blog_activity where blogId=$blogId and day=$day1";
$day1 = $this->getOne($query);
$query = "select posts from tiki_blog_activity where blogId=$blogId and day=$day2";
$day2 = $this->getOne($query);
$activity = (2 * $vtoday) + ($day0) + (0.5 * $day1) + (0.25 * $day2);
// Update tiki_blogs with activity information
$query = "update tiki_blogs set activity=$activity where blogId=$blogId";
$result = $this->query($query);
}
}
$bloglib= new BlogLib($dbTiki);
?>
\ No newline at end of file
<?php
class CommLib extends TikiLib {
function CommLib($db)
{
# this is probably uneeded now
if(!$db) {
die("Invalid db object passed to UsersLib constructor");
}
$this->db = $db;
}
function accept_page($receivedPageId)
{
//create_page($name, $hits, $data, $lastModif, $comment, $user='system', $ip='0.0.0.0')
// CODE HERE
$info = $this->get_received_page($receivedPageId);
if($this->page_exists($info["pageName"])) return false;
$now=date("U");
$this->create_page($info["pageName"],0,$info["data"],$now,$info["comment"],$info["receivedFromUser"],$info["receivedFromSite"],$info["description"]);
$query = "delete from tiki_received_pages where receivedPageId = $receivedPageId";
$result = $this->query($query);
return true;
}
function accept_article($receivedArticleId,$topic)
{
$info = $this->get_received_article($receivedArticleId);
$this->replace_article ($info["title"],$info["authorName"],$topic,$info["useImage"],$info["image_name"],$info["image_size"],$info["image_type"],$info["image_data"],$info["heading"],$info["body"],$info["publishDate"],$info["author"],0,$info["image_x"],$info["image_y"],$info["type"],$info["rating"]);
$query = "delete from tiki_received_articles where receivedArticleId = $receivedArticleId";
$result = $this->query($query);
return true;
}
function list_received_articles($offset,$maxRecords,$sort_mode='publishDate_desc',$find)
{
$sort_mode = str_replace("_"," ",$sort_mode);
if($find) {
$mid=" where (heading like '%".$find."%' or title like '%".$find."%' or body like '%".$find."% ')";
} else {
$mid="";
}
$query = "select * from tiki_received_articles $mid order by $sort_mode limit $offset,$maxRecords";
$query_cant = "select count(*) from tiki_received_articles $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 remove_received_page($receivedPageId)
{
$query = "delete from tiki_received_pages where receivedPageId=$receivedPageId";
$result = $this->query($query);
}
function remove_received_article($receivedArticleId)
{
$query = "delete from tiki_received_articles where receivedArticleId=$receivedArticleId";
$result = $this->query($query);
}
function rename_received_page($receivedPageId,$name)
{
$query = "update tiki_received_pages set pageName='$name' where receivedPageId=$receivedPageId";
$result = $this->query($query);
}
function get_received_page($receivedPageId)
{
$query = "select * from tiki_received_pages where receivedPageId=$receivedPageId";
$result = $this->query($query);
if(!$result->numRows()) return false;
$res = $result->fetchRow(DB_FETCHMODE_ASSOC);
return $res;
}
function get_received_article($receivedArticleId)
{
$query = "select * from tiki_received_articles where receivedArticleId=$receivedArticleId";
$result = $this->query($query);
if(!$result->numRows()) return false;
$res = $result->fetchRow(DB_FETCHMODE_ASSOC);
return $res;
}
function update_received_article($receivedArticleId,$title,$authorName,$useImage,$image_x,$image_y,$publishDate,$heading,$body,$type,$rating)
{
$title = addslashes($title);
$authorName = addslashes($authorName);
$heading = addslashes($heading);
$body = addslashes($body);
$size = strlen($body);
$hash = md5($title.$heading.$body);
$query = "update tiki_received_articles set
title = '$title',
authorName = '$authorName',
heading = '$heading',
body = '$body',
size = $size,
hash = '$hash',
useImage = '$useImage',
image_x = $image_x,
image_y = $image_y,
publishDate = $publishDate,
type = '$type',
rating = $rating
where receivedArticleId=$receivedArticleId";
$result = $this->query($query);
}
function update_received_page($receivedPageId, $pageName, $data, $comment)
{
$data = addslashes($data);
$pageName = addslashes($pageName);
$comment = addslashes($comment);
$query = "update tiki_received_pages set pageName='$pageName', data='$data', comment='$comment' where receivedPageId=$receivedPageId";
$result = $this->query($query);
}
function receive_article($site,$user,$title,$authorName,$size,$use_image,$image_name,$image_type,$image_size,$image_x,$image_y,$image_data,$publishDate,$created,$heading,$body,$hash,$author,$type,$rating)
{
$title = addslashes($title);
$authorName = addslashes($authorName);
$image_data = addslashes($image_data);
$heading = addslashes($heading);
$body = addslashes($body);
$now = date("U");
$query = "delete from tiki_received_articles where title='$title' and receivedFromsite='$site' and receivedFromUser='$user'";
$result = $this->query($query);
$query = "insert into tiki_received_articles(receivedDate,receivedFromSite,receivedFromUser,title,authorName,size,useImage,image_name,image_type,image_size,image_x,image_y,image_data,publishDate,created,heading,body,hash,author,type,rating)
values($now,'$site','$user','$title','$authorName',$size,'$use_image','$image_name','$image_type',$image_size,$image_x,$image_y,'$image_data',$publishDate,$created,'$heading','$body','$hash','$author','$type',$rating)";
$result = $this->query($query);
}
function receive_page($pageName,$data,$comment,$site,$user,$description)
{
$data = addslashes($data);
$pageNAme = addslashes($pageName);
$comment = addslashes($comment);
$description = addslashes($description);
$now = date("U");
// Remove previous page sent from the same site-user (an update)
$query = "delete from tiki_received_pages where pageName='$pageName' and receivedFromsite='$site' and receivedFromUser='$user'";
$result = $this->query($query);
// Now insert the page
$query = "insert into tiki_received_pages(pageName,data,comment,receivedFromSite, receivedFromUser, receivedDate,description)
values('$pageName','$data','$comment','$site','$user',$now,'$description')";
$result = $this->query($query);
}
// Functions for the communication center end ////
}
$commlib= new CommLib($dbTiki);
?>
\ No newline at end of file
<?php
class FileGalLib extends TikiLib {
function FileGalLib($db)
{
# this is probably uneeded now
if(!$db) {
die("Invalid db object passed to UsersLib constructor");
}
$this->db = $db;
}
function remove_file($id)
{
global $fgal_use_dir;
$path = $this->getOne("select path from tiki_files where fileId=$id");
if($path) {
unlink($fgal_use_dir.$path);
}
$query = "delete from tiki_files where fileId=$id";
$result = $this->query($query);
return true;
}
function insert_file($galleryId,$name,$description,$filename, $data, $size,$type ,$user,$path)
{
$name = addslashes(strip_tags($name));
$path = addslashes($path);
$description = addslashes(strip_tags($description));
$data = addslashes($data);
$now = date("U");
$query = "insert into tiki_files(galleryId,name,description,filename,filesize,filetype,data,user,created,downloads,path)
values($galleryId,'$name','$description','$filename',$size,'$type','$data','$user',$now,0,'$path')";
$result = $this->query($query);
$query = "update tiki_file_galleries set lastModif=$now where galleryId=$galleryId";
$result = $this->query($query);
$query = "select max(fileId) from tiki_files where created=$now";
$fileId = $this->getOne($query);
return $fileId;
}
function list_file_galleries($offset = 0, $maxRecords = -1, $sort_mode = 'name_desc', $user, $find)
{
global $tiki_p_admin_file_galleries;
// If $user is admin then get ALL galleries, if not only user galleries are shown
$sort_mode = str_replace("_"," ",$sort_mode);
$old_sort_mode ='';
if(in_array($sort_mode,Array('files desc','files asc'))) {
$old_offset = $offset;
$old_maxRecords = $maxRecords;
$old_sort_mode = $sort_mode;
$sort_mode ='user desc';
$offset = 0;
$maxRecords = -1;
}
// If the user is not admin then select it's own galleries or public galleries
if (($tiki_p_admin_file_galleries == 'y') or ($user == 'admin')) {
$whuser = "";
} else {
$whuser = "where user='$user' or public='y'";
}
if($find) {
if(empty($whuser)) {
$whuser = "where name like '%".$find."%' or description like '%".$find.".%'";
} else {
$whuser .= " and name like '%".$find."%' or description like '%".$find.".%'";
}
}
$query = "select * from tiki_file_galleries $whuser order by $sort_mode limit $offset,$maxRecords";
$query_cant = "select count(*) from tiki_file_galleries $whuser";
$result = $this->query($query);
$result_cant = $this->query($query_cant);
$res2 = $result_cant->fetchRow();
$cant = $res2[0];
$ret = Array();
while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$aux = Array();
$aux["name"] = $res["name"];
$gid = $res["galleryId"];
$aux["id"] = $gid;
$aux["visible"] = $res["visible"];
$aux["galleryId"] = $res["galleryId"];
$aux["description"] = $res["description"];
$aux["created"] = $res["created"];
$aux["lastModif"] = $res["lastModif"];
$aux["user"] = $res["user"];
$aux["hits"] = $res["hits"];
$aux["public"] = $res["public"];
$aux["files"] = $this->getOne("select count(*) from tiki_files where galleryId='$gid'");
$ret[] = $aux;
}
if($old_sort_mode == 'files asc') {
usort($ret,'compare_files');
}
if($old_sort_mode == 'files desc') {
usort($ret,'r_compare_files');
}
if(in_array($old_sort_mode,Array('files desc','files asc'))) {
$ret = array_slice($ret, $old_offset, $old_maxRecords);
}
$retval = Array();
$retval["data"] = $ret;
$retval["cant"] = $cant;
return $retval;
}
function remove_file_gallery($id)
{
global $fgal_use_dir;
$query = "select path from tiki_files where galleryId='$id'";
$result = $this->query($query);
while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$path = $res["path"];
if($path) {
@unlink($fgal_use_dir.$path);
}
}
$query = "delete from tiki_file_galleries where galleryId='$id'";
$result = $this->query($query);
$query = "delete from tiki_files where galleryId='$id'";
$result = $this->query($query);
$this->remove_object('file gallery',$id);
return true;
}
function get_file_gallery_info($id)
{
$query = "select * from tiki_file_galleries where galleryId='$id'";
$result = $this->query($query);
$res = $result->fetchRow(DB_FETCHMODE_ASSOC);
return $res;
}
function replace_file_gallery($galleryId, $name, $description, $user,$maxRows,$public,$visible='y')
{
// if the user is admin or the user is the same user and the gallery exists then replace if not then
// create the gallary if the name is unused.
$name = addslashes(strip_tags($name));
$description = addslashes(strip_tags($description));
$now = date("U");
if($galleryId>0) {
$query = "update tiki_file_galleries set name='$name', maxRows=$maxRows, description='$description',lastModif=$now, public='$public', visible='$visible' where galleryId=$galleryId";
$result = $this->query($query);
} else {
// Create a new record
$query = "insert into tiki_file_galleries(name,description,created,user,lastModif,maxRows,public,hits,visible)
values ('$name','$description',$now,'$user',$now,$maxRows,'$public',0,'$visible')";
$result = $this->query($query);
$galleryId=$this->getOne("select max(galleryId) from tiki_file_galleries where name='$name' and lastModif=$now");
}
return $galleryId;
}
}
$filegallib= new FileGalLib($dbTiki);
?>
\ No newline at end of file
<?php
class MenuLib extends TikiLib {
function MenuLib($db)
{
# this is probably uneeded now
if(!$db) {
die("Invalid db object passed to UsersLib constructor");
}
$this->db = $db;
}
function list_menus($offset,$maxRecords,$sort_mode,$find)
{
$sort_mode = str_replace("_"," ",$sort_mode);
if($find) {
$mid=" where (name like '%".$find."%' or description like '%".$find."%')";
} else {
$mid="";
}
$query = "select * from tiki_menus $mid order by $sort_mode limit $offset,$maxRecords";
$query_cant = "select count(*) from tiki_menus $mid";
$result = $this->query($query);
$cant = $this->getOne($query_cant);
$ret = Array();
while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$query = "select count(*) from tiki_menu_options where menuId=".$res["menuId"];
$res["options"]=$this->getOne($query);
$ret[] = $res;
}
$retval = Array();
$retval["data"] = $ret;