Skip to content

Commit

Permalink
refs #1067 : modified - Blog class is rewritten.
Browse files Browse the repository at this point in the history
 -
  • Loading branch information
inureyes committed Jan 9, 2015
1 parent 2809ce3 commit 385c6c1
Showing 1 changed file with 58 additions and 23 deletions.
81 changes: 58 additions & 23 deletions framework/legacy/Textcube.Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,17 +358,33 @@ function __getMaxUserId() {
class Blog {
/*@static@*/
function changeOwner($blogid,$userid) {
global $database;
POD::execute("UPDATE {$database['prefix']}Privileges SET acl = 3 WHERE blogid = ".$blogid." and acl = " . BITWISE_OWNER);
$context = Model_Context::getInstance();
$pool = DBModel::getInstance();
$pool->reset("Privileges");
$pool->setAttribute("acl",3);
$pool->setQualifier("blogid","eq",$blogid);
$pool->setQualifier("acl","eq", BITWISE_OWNER);
$pool->update();

$acl = POD::queryCell("SELECT acl FROM {$database['prefix']}Privileges WHERE blogid = $blogid and userid = $userid");
$pool->reset("Privileges");
$pool->setQualifier("blogid","eq",$blogid);
$pool->setQualifier("userid","eq",$userid);
$acl = $pool->getCell("acl");

if( $acl === null ) { // If there is no ACL, add user into the blog.
POD::query("INSERT INTO {$database['prefix']}Privileges
VALUES($blogid, $userid, '".BITWISE_OWNER."', UNIX_TIMESTAMP(), 0)");
$pool->reset("Privileges");
$pool->setAttribute("blogid",$blogid);
$pool->setAttribute("userid",$userid);
$pool->setAttribute("acl",BITWISE_OWNER);
$pool->setAttribute("created",Timestamp::getUNIXtime());
$pool->setAttribute("lastlogin",0);
$pool->insert();
} else {
POD::execute("UPDATE {$database['prefix']}Privileges SET acl = ".BITWISE_OWNER."
WHERE blogid = ".$blogid." and userid = " . $userid);
$pool->reset("Privileges");
$pool->setAttribute("acl",BITWISE_OWNER);
$pool->setQualifier("blogid","eq",$blogid);
$pool->setQualifier("userid","eq",$userid);
$pool->update();
}
return true;
}
Expand All @@ -378,7 +394,6 @@ function changeOwner($blogid,$userid) {
function addUser($email, $name, $comment, $senderName, $senderEmail) {
requireModel('blog.user');
requireModel('blog.blogSetting');
global $database,$service,$blogURL,$hostURL,$user,$blog;

$blogid = getBlogId();
if(empty($email))
Expand All @@ -400,36 +415,54 @@ function addUser($email, $name, $comment, $senderName, $senderEmail) {

/*@static@*/
function deleteUser($blogid = null, $userid, $clean = true) {
global $database;
$context = Model_Context::getInstance();
$pool = DBModel::getInstance();

if ($blogid == null) {
$blogid = getBlogId();
}
POD::execute("UPDATE {$database['prefix']}Entries
SET userid = ".User::getBlogOwner($blogid)."
WHERE blogid = ".$blogid." AND userid = ".$userid);
$pool->reset("Entries");
$pool->setAttribute("userid",User::getBlogOwner($blogid));
$pool->setQualifier("blogid","eq",$blogid);
$pool->setQualifier("userid","eq",$userid);
$pool->update();

// Delete ACL relation.
if(!POD::execute("DELETE FROM {$database['prefix']}Privileges WHERE blogid='$blogid' and userid='$userid'"))
$pool->reset("Privileges");
$pool->setQualifier("blogid","eq",$blogid);
$pool->setQualifier("userid","eq",$userid);
if(!$pool->delete())
return false;
// And if there is no blog related to the specific user, delete user.
if($clean && !POD::queryAll("SELECT * FROM {$database['prefix']}Privileges WHERE userid = '$userid'")) {
$pool->reset("Privileges");
$pool->setQualifier("userid","eq",$userid);

if($clean && !$pool->getAll()) {
User::removePermanent($userid);
}
return true;
}

/*@static@*/
function changeACLofUser($blogid, $userid, $ACLtype, $switch) { // Change user priviledge on the blog.
global $database;
$context = Model_Context::getInstance();
$pool = DBModel::getInstance();

if(empty($ACLtype) || empty($userid))
return false;
$acl = POD::queryCell("SELECT acl
FROM {$database['prefix']}Privileges
WHERE blogid=$blogid and userid=$userid");
$pool->reset("Privileges");
$pool->setQualifier("blogid","eq",$blogid);
$pool->setQualifier("userid","eq",$userid);
$acl = $pool->getCell("acl");
if( $acl === null ) { // If there is no ACL, add user into the blog.
$name = User::getName($userid);
POD::query("INSERT INTO {$database['prefix']}Privileges
VALUES($blogid, $userid, 0, UNIX_TIMESTAMP(), 0)");
$pool->reset("Privileges");
$pool->setAttribute("blogid",$blogid);
$pool->setAttribute("userid",$userid);
$pool->setAttribute("acl",0);
$pool->setAttribute("created",Timestamp::getUNIXtime());
$pool->setAttribute("lastlogin",0);
$pool->insert();
$acl = 0;
}
$bitwise = null;
Expand All @@ -448,9 +481,11 @@ function changeACLofUser($blogid, $userid, $ACLtype, $switch) { // Change user
} else {
$acl &= ~$bitwise;
}
return POD::execute("UPDATE {$database['prefix']}Privileges
SET acl = ".$acl."
WHERE blogid = ".$blogid." and userid = ".$userid);
$pool->reset("Privileges");
$pool->setAttribute("acl",$acl);
$pool->setQualifier("blogid","eq",$blogid);
$pool->setQualifier("userid","eq",$userid);
return $pool->update();
}
}

Expand Down

0 comments on commit 385c6c1

Please sign in to comment.