Changeset 5775

Show
Ignore:
Timestamp:
04/19/08 00:50:05 (9 months ago)
Author:
inureyes
Message:

#759

  • POD framework의 기본인 DBQuery에 sql 호환 함수 추가
    • num_rows, fetch
  • 관련하여 전체 코드 정리
  • mysql_ 계열의 명령을 코드 전체에서 제외
  • User class의 model dependency 제거
  • Blog class 추가
    • TODO : model dependency 제외및 기능 수정
  • 사흘정도 네트워크를 못하고 로컬 수정한거라 좀 변경 사항이 많습니다.
Location:
trunk
Files:
1 removed
53 modified

Legend:

Unmodified
Added
Removed
  • trunk/components/Needlworks.DBMS.MySQL.php

    r5482 r5775  
    44/// See the GNU General Public License for more details. (/doc/LICENSE, /doc/COPYRIGHT) 
    55 
     6// DBQuery version 1.7 for MySQL 
     7 
    68global $cachedResult; 
    79global $fileCachedResult; 
    810global $__gEscapeTag; 
    911global $__dbProperties; 
     12global $__gLastQueryType; 
    1013$cachedResult = $__dbProperties = array(); 
    1114$__gEscapeTag = null; 
     
    6669    /*@static@*/ 
    6770    function queryCount($query) { 
     71        global $__gLastQueryType; 
    6872        $count = 0; 
    6973        $query = trim($query); 
    7074        if ($result = DBQuery::query($query)) { 
    7175            $operation = strtolower(substr($query, 0,6)); 
     76            $__gLastQueryType = $operation; 
    7277            switch ($operation) { 
    7378                case 'select': 
     
    150155    /*@static@*/ 
    151156    function queryAll ($query, $type = MYSQL_BOTH, $count = -1) { 
     157        if($type == 'assoc') $type = MYSQL_ASSOC; 
     158        else if ($type == 'num') $type = MYSQL_NUM; 
    152159        return DBQuery::queryAllWithCache($query, $type, $count); 
    153160        //return DBQuery::queryAllWithoutCache($query, $type, $count);  // Your choice. :) 
     
    202209    /*@static@*/ 
    203210    function query($query) { 
     211        global $__gLastQueryType; 
    204212        if( function_exists( '__tcSqlLogBegin' ) ) { 
    205213            __tcSqlLogBegin($query); 
     
    209217            $result = mysql_query($query); 
    210218        } 
     219        $__gLastQueryType = strtolower(substr($query, 0,6)); 
    211220        if( stristr($query, 'update ') || 
    212221            stristr($query, 'insert ') || 
     
    253262        global $fileCachedResult; 
    254263    } 
     264     
     265    /* Raw functions (to easier adoptation) */ 
     266    /*@static@*/ 
     267    function num_rows($handle = null) { 
     268        global $__gLastQueryType; 
     269        switch($__gLastQueryType) { 
     270            case 'select': 
     271                return mysql_num_rows($handle); 
     272                break; 
     273            default: 
     274                return mysql_affected_rows($handle); 
     275                break; 
     276        } 
     277        return null; 
     278    } 
     279    /*@static@*/ 
     280    function free($handle = null) { 
     281        mysql_free_result($handle); 
     282    } 
     283     
     284    /*@static@*/ 
     285    function fetch($handle = null, $type = 'assoc') { 
     286        if($type == 'array') return mysql_fetch_array($handle); // Can I use mysql_fetch_row instead? 
     287        else if ($type = 'row') return mysql_fetch_row($handle); 
     288        else return mysql_fetch_assoc($handle); 
     289    } 
     290     
     291    /*@static@*/ 
     292    function error($err = null) { 
     293        return mysql_error($err); 
     294    } 
    255295} 
    256296 
  • trunk/components/Textcube.Core.php

    r5774 r5775  
    44/// See the GNU General Public License for more details. (/doc/LICENSE, /doc/COPYRIGHT) 
    55 
    6 /* This component contains 'User' and 'Transaction' class. */ 
    7  
    8 requireComponent( "Textcube.Control.Auth" ); 
     6/* This component contains 'User', 'Blog' and 'Transaction' class.  
     7   NOTE : Classes described below are actually not object. Usually they are static.*/ 
     8 
     9requireComponent('Textcube.Control.Auth'); 
    910 
    1011// for Global Cache 
     
    181182    } 
    182183 
     184    /*@static@*/ 
    183185    function authorName($blogid = null,$entryId){ 
    184186        if( is_null($blogid) ) { 
    185187            $blogid = getBlogId(); 
    186188        } 
    187         global $database, $entry; 
    188189 
    189190        // Read userId of entry from relation table. 
     
    196197    } 
    197198 
     199    /*@static@*/ 
    198200    function changeBlog(){ 
    199201        global $database, $blogURL, $blog, $service; 
     
    216218        return $changeBlogView; 
    217219    } 
    218      
     220 
     221    /*@static@*/ 
    219222    function changeSetting($userid, $email, $nickname) { 
    220223        global $database; 
     
    232235        } 
    233236    } 
    234      
     237 
     238    /*@static@*/ 
    235239    function add($email, $name) { 
    236240        global $database, $service, $user, $blog; 
     
    244248        $loginid = POD::escapeString(UTF8::lessenAsEncoding($email, 64));    
    245249        $name = POD::escapeString(UTF8::lessenAsEncoding($name, 32)); 
    246         $password = generatePassword(); 
    247         $authtoken = md5(generatePassword()); 
     250        $password = User::__generatePassword(); 
     251        $authtoken = md5(User::__generatePassword()); 
    248252     
    249253        if (POD::queryExistence("SELECT * FROM `{$database['prefix']}Users` WHERE loginid = '$loginid'")) { 
     
    262266    } 
    263267     
    264     /* TO DO : library 의존성 없애야 함. 함수를 사용하고 있습니다.  */ 
     268    /*@static@*/ 
    265269    function remove($userid) { 
    266270        global $database; 
     
    273277        POD::execute($sql); 
    274278        foreach ($blogs as $ownedBlog) { 
    275             changeBlogOwner($ownedBlog,1); // 관리자 uid로 변경 
     279            Blog::changeOwner($ownedBlog,1); // 관리자 uid로 변경 
    276280        } 
    277281        $blogs = User::getBlogs($userid); 
    278282        foreach ($blogs as $joinedBlog) { 
    279             deleteTeamblogUser($userid,$joinedBlog); 
     283            Blog::deleteUser($joinedBlog, $userid); 
    280284        } 
    281285        User::removePermanent($userid); 
     
    283287    } 
    284288     
     289    /*@static@*/ 
    285290    function removePermanent($userid) { 
    286291        global $database; 
     
    291296        } 
    292297    } 
     298     
     299    /* private functions */ 
     300    /*@private static@*/ 
     301    function __generatePassword() { 
     302        return strtolower(substr(base64_encode(rand(0x10000000, 0x70000000)), 3, 8)); 
     303    } 
    293304} 
    294305 
     306class Blog { 
     307    /*@static@*/ 
     308    function changeOwner($blogid,$userid) { 
     309        global $database; 
     310        POD::execute("UPDATE `{$database['prefix']}Teamblog` SET acl = 3 WHERE blogid = ".$blogid." and acl = " . BITWISE_OWNER); 
     311     
     312        $acl = POD::queryCell("SELECT acl FROM {$database['prefix']}Teamblog WHERE blogid='$blogid' and userid='$userid'"); 
     313     
     314        if( $acl === null ) { // If there is no ACL, add user into the blog. 
     315            POD::query("INSERT INTO `{$database['prefix']}Teamblog`   
     316                VALUES('$blogid', '$userid', '".BITWISE_OWNER."', UNIX_TIMESTAMP(), '0')"); 
     317        } else { 
     318            POD::execute("UPDATE `{$database['prefix']}Teamblog` SET acl = ".BITWISE_OWNER."  
     319                WHERE blogid = ".$blogid." and userid = " . $userid); 
     320        } 
     321        return true; 
     322    } 
     323     
     324    /*@static@*/ 
     325    /* TODO : remove model dependency (addBlog, sendInvitationMail) */ 
     326    function addUser($email, $name, $comment, $senderName, $senderEmail) { 
     327        requireModel('blog.user'); 
     328        requireModel('blog.blogSetting'); 
     329        global $database,$service,$blogURL,$hostURL,$user,$blog; 
     330     
     331        $blogid = getBlogId(); 
     332        if(empty($email)) 
     333            return 1; 
     334        if(!preg_match('/^[^@]+@([-a-zA-Z0-9]+\.)+[-a-zA-Z0-9]+$/',$email)) 
     335            return array( 2, _t('이메일이 바르지 않습니다.') ); 
     336         
     337        $isUserExists = User::getUserIdByEmail($email); 
     338        if(empty($isUserExists)) { // If user is not exist 
     339            User::add($email,$name); 
     340        } 
     341        $userid = User::getUserIdByEmail($email); 
     342        $result = addBlog(getBlogId(), $userid, null); 
     343        if($result === true) { 
     344            return sendInvitationMail(getBlogId(), $userid, User::getName($userid), $comment, $senderName, $senderEmail); 
     345        } 
     346        return $result; 
     347    } 
     348 
     349    /*@static@*/ 
     350    function deleteUser($blogid = null, $userid, $clean = true) { 
     351        global $database; 
     352        if ($blogid == null) { 
     353            $blogid = getBlogId(); 
     354        } 
     355        POD::execute("UPDATE `{$database['prefix']}Entries`  
     356            SET userid = ".User::getBlogOwner($blogid)."  
     357            WHERE blogid = ".$blogid." AND userid = ".$userid); 
     358     
     359        // Delete ACL relation. 
     360        if(!POD::execute("DELETE FROM `{$database['prefix']}Teamblog` WHERE blogid='$blogid' and userid='$userid'")) 
     361            return false; 
     362        // And if there is no blog related to the specific user, delete user. 
     363        if($clean && !POD::queryAll("SELECT * FROM `{$database['prefix']}Teamblog` WHERE userid = '$userid'")) { 
     364            User::removePermanent($userid); 
     365        } 
     366        return true; 
     367    } 
     368     
     369    /*@static@*/ 
     370    function changeACLofUser($blogid, $userid, $ACLtype, $switch) {  // Change user priviledge on the blog. 
     371        global $database; 
     372        if(empty($ACLtype) || empty($userid)) 
     373            return false; 
     374        $acl = POD::queryCell("SELECT acl 
     375                FROM {$database['prefix']}Teamblog  
     376                WHERE blogid='$blogid' and userid='$userid'"); 
     377        if( $acl === null ) { // If there is no ACL, add user into the blog. 
     378            $name = User::getName($userid); 
     379            POD::query("INSERT INTO `{$database['prefix']}Teamblog`   
     380                    VALUES('$blogid', '$userid', '0', UNIX_TIMESTAMP(), '0')"); 
     381            $acl = 0; 
     382        } 
     383        $bitwise = null; 
     384        switch( $ACLtype ) { 
     385            case 'admin': 
     386                $bitwise = BITWISE_ADMINISTRATOR; 
     387                break; 
     388            case 'editor': 
     389                $bitwise = BITWISE_EDITOR; 
     390                break; 
     391            default: 
     392                return false; 
     393        } 
     394        if( $switch ) { 
     395            $acl |= $bitwise; 
     396        } else { 
     397            $acl &= ~$bitwise; 
     398        } 
     399        return POD::execute("UPDATE `{$database['prefix']}Teamblog`  
     400            SET acl = ".$acl."  
     401            WHERE blogid = ".$blogid." and userid = ".$userid); 
     402    } 
     403} 
    295404 
    296405class Transaction { 
  • trunk/components/Textcube.Data.Attachment.php

    r5285 r5775  
    3131            $sort = 'ORDER BY ' . $sort; 
    3232        $this->close(); 
    33         $this->_result = mysql_query("SELECT $fields FROM {$database['prefix']}Attachments WHERE blogid = $blogid $filter $sort"); 
     33        $this->_result = POD::query("SELECT $fields FROM {$database['prefix']}Attachments WHERE blogid = $blogid $filter $sort"); 
    3434        if ($this->_result) { 
    35             if ($this->_count = mysql_num_rows($this->_result)) 
     35            if ($this->_count = POD::num_rows($this->_result)) 
    3636                return $this->shift(); 
    3737            else 
    38                 mysql_free_result($this->_result); 
     38                POD::free($this->_result); 
    3939        } 
    4040        unset($this->_result); 
     
    4444    function close() { 
    4545        if (isset($this->_result)) { 
    46             mysql_free_result($this->_result); 
     46            POD::free($this->_result); 
    4747            unset($this->_result); 
    4848        } 
     
    5353    function shift() { 
    5454        $this->reset(); 
    55         if ($this->_result && ($row = mysql_fetch_assoc($this->_result))) { 
     55        if ($this->_result && ($row = POD::fetch($this->_result))) { 
    5656            foreach ($row as $name => $value) { 
    5757                if ($name == 'blogid') 
  • trunk/components/Textcube.Data.BlogStatistics.php

    r5285 r5775  
    1717        global $database; 
    1818        $this->reset(); 
    19         if ($result = mysql_query("SELECT visits FROM {$database['prefix']}BlogStatistics WHERE blogid = ".getBlogId())) { 
    20             if ($row = mysql_fetch_assoc($result)) { 
     19        if ($result = POD::query("SELECT visits FROM {$database['prefix']}BlogStatistics WHERE blogid = ".getBlogId())) { 
     20            if ($row = POD::fetch($result)) { 
    2121                foreach ($row as $name => $value) { 
    2222                    if ($name == 'owner') 
     
    2424                    $this->$name = $value; 
    2525                } 
    26                 mysql_free_result($result); 
     26                POD::free($result); 
    2727                return true; 
    2828            } 
    29             mysql_free_result($result); 
     29            POD::free($result); 
    3030        } 
    3131        return false; 
  • trunk/components/Textcube.Data.Category.php

    r5285 r5775  
    3535            $sort = 'ORDER BY ' . $sort; 
    3636        $this->close(); 
    37         $this->_result = mysql_query("SELECT $fields FROM {$database['prefix']}Categories WHERE blogid = ".getBlogId()." $filter $sort"); 
     37        $this->_result = POD::query("SELECT $fields FROM {$database['prefix']}Categories WHERE blogid = ".getBlogId()." $filter $sort"); 
    3838        if ($this->_result) 
    39             $this->_count = mysql_num_rows($this->_result); 
     39            $this->_count = POD::num_rows($this->_result); 
    4040        return $this->shift(); 
    4141    } 
     
    4343    function close() { 
    4444        if (isset($this->_result)) { 
    45             mysql_free_result($this->_result); 
     45            POD::free($this->_result); 
    4646            unset($this->_result); 
    4747        } 
     
    5252    function shift() { 
    5353        $this->reset(); 
    54         if ($this->_result && ($row = mysql_fetch_assoc($this->_result))) { 
     54        if ($this->_result && ($row = POD::fetch($this->_result))) { 
    5555            foreach ($row as $name => $value) { 
    5656                if ($name == 'blogid') 
  • trunk/components/Textcube.Data.Comment.php

    r5285 r5775  
    3535            $sort = 'ORDER BY ' . $sort; 
    3636        $this->close(); 
    37         $this->_result = mysql_query("SELECT $fields FROM {$database['prefix']}Comments WHERE blogid = ".getBlogId()." $filter $sort"); 
     37        $this->_result = POD::query("SELECT $fields FROM {$database['prefix']}Comments WHERE blogid = ".getBlogId()." $filter $sort"); 
    3838        if ($this->_result) { 
    39             if ($this->_count = mysql_num_rows($this->_result)) 
     39            if ($this->_count = POD::num_rows($this->_result)) 
    4040                return $this->shift(); 
    4141            else 
    42                 mysql_free_result($this->_result); 
     42                POD::free($this->_result); 
    4343        } 
    4444        unset($this->_result); 
     
    4848    function close() { 
    4949        if (isset($this->_result)) { 
    50             mysql_free_result($this->_result); 
     50            POD::free($this->_result); 
    5151            unset($this->_result); 
    5252        } 
     
    5757    function shift() { 
    5858        $this->reset(); 
    59         if ($this->_result && ($row = mysql_fetch_assoc($this->_result))) { 
     59        if ($this->_result && ($row = POD::fetch($this->_result))) { 
    6060            foreach ($row as $name => $value) { 
    6161                if ($name == 'blogid') 
  • trunk/components/Textcube.Data.CommentNotified.php

    r5627 r5775  
    4040            $sort = 'ORDER BY ' . $sort; 
    4141        $this->close(); 
    42         $this->_result = mysql_query("SELECT $fields FROM {$database['prefix']}CommentsNotified WHERE blogid = ".getBlogId()." $filter $sort"); 
     42        $this->_result = POD::query("SELECT $fields FROM {$database['prefix']}CommentsNotified WHERE blogid = ".getBlogId()." $filter $sort"); 
    4343        if ($this->_result) { 
    44             if ($this->_count = mysql_num_rows($this->_result)) 
     44            if ($this->_count = POD::num_rows($this->_result)) 
    4545                return $this->shift(); 
    4646            else 
    47                 mysql_free_result($this->_result); 
     47                POD::free($this->_result); 
    4848        } 
    4949        unset($this->_result); 
     
    5353    function close() { 
    5454        if (isset($this->_result)) { 
    55             mysql_free_result($this->_result); 
     55            POD::free($this->_result); 
    5656            unset($this->_result); 
    5757        } 
     
    6262    function shift() { 
    6363        $this->reset(); 
    64         if ($this->_result && ($row = mysql_fetch_assoc($this->_result))) { 
     64        if ($this->_result && ($row = POD::fetch($this->_result))) { 
    6565            foreach ($row as $name => $value) { 
    6666                if ($name == 'blogid') 
  • trunk/components/Textcube.Data.CommentNotifiedSiteInfo.php

    r5285 r5775  
    2525            $sort = 'ORDER BY ' . $sort; 
    2626        $this->close(); 
    27         $this->_result = mysql_query("SELECT $fields FROM {$database['prefix']}CommentsNotifiedSiteInfo WHERE $filter $sort"); 
     27        $this->_result = POD::query("SELECT $fields FROM {$database['prefix']}CommentsNotifiedSiteInfo WHERE $filter $sort"); 
    2828        if ($this->_result) { 
    29             if ($this->_count = mysql_num_rows($this->_result)) 
     29            if ($this->_count = POD::num_rows($this->_result)) 
    3030                return $this->shift(); 
    3131            else 
    32                 mysql_free_result($this->_result); 
     32                POD::free($this->_result); 
    3333        } 
    3434        unset($this->_result); 
     
    3838    function close() { 
    3939        if (isset($this->_result)) { 
    40             mysql_free_result($this->_result); 
     40            POD::free($this->_result); 
    4141            unset($this->_result); 
    4242        } 
     
    4747    function shift() { 
    4848        $this->reset(); 
    49         if ($this->_result && ($row = mysql_fetch_assoc($this->_result))) { 
     49        if ($this->_result && ($row = POD::fetch($this->_result))) { 
    5050            foreach ($row as $name => $value) { 
    5151                $this->$name = $value; 
  • trunk/components/Textcube.Data.DailyStatistics.php

    r5285 r5775  
    2323            $sort = 'ORDER BY ' . $sort; 
    2424        $this->close(); 
    25         $this->_result = mysql_query("SELECT $fields FROM {$database['prefix']}DailyStatistics WHERE blogid = ".getBlogId()." $filter $sort"); 
     25        $this->_result = POD::query("SELECT $fields FROM {$database['prefix']}DailyStatistics WHERE blogid = ".getBlogId()." $filter $sort"); 
    2626        if ($this->_result) { 
    27             if ($this->_count = mysql_num_rows($this->_result)) 
     27            if ($this->_count = POD::num_rows($this->_result)) 
    2828                return $this->shift(); 
    2929            else 
    30                 mysql_free_result($this->_result); 
     30                POD::free($this->_result); 
    3131        } 
    3232        unset($this->_result); 
     
    3636    function close() { 
    3737        if (isset($this->_result)) { 
    38             mysql_free_result($this->_result); 
     38            POD::free($this->_result); 
    3939            unset($this->_result); 
    4040        } 
     
    4545    function shift() { 
    4646