Changeset 4621

Show
Ignore:
Timestamp:
10/27/07 04:01:25 (13 months ago)
Author:
inureyes
Message:

#719

  • 드래프트 핸들링 부분 모두 재작성.
Location:
trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/blog/owner/entry/draft/index.php

    r4599 r4621  
    1818        'acceptTrackback' => array(array('0', '1'), 'default' => '0'), 
    1919        'published' => array('int', 0, 'default' => 0) 
    20         ) 
    21     ); 
     20    ) 
     21); 
    2222require ROOT . '/lib/includeForBlogOwner.php'; 
     23requireModel('blog.entry'); 
     24 
    2325requireStrictRoute(); 
     26 
     27if(empty($suri['id'])) respondResultPage(1); 
    2428$entry['id'] = $suri['id']; 
    2529$entry['draft'] = 1; 
    2630$entry['visibility'] = $_POST['visibility']; 
    27 $entry['category'] = empty($_POST['category']) ? 0 : $_POST['category']; 
     31$entry['category'] = $_POST['category']; 
    2832$entry['title'] = $_POST['title']; 
    2933$entry['content'] = $_POST['content']; 
     
    3236$entry['location'] = empty($_POST['location']) ? '/' : $_POST['location']; 
    3337$entry['tag'] = empty($_POST['tag']) ? '' : $_POST['tag']; 
     38$entry['slogan'] = $_POST['permalink']; 
    3439$entry['acceptComment'] = empty($_POST['acceptComment']) ? 0 : 1; 
    3540$entry['acceptTrackback'] = empty($_POST['acceptTrackback']) ? 0 : 1; 
    3641$entry['published'] = empty($_POST['published']) ? 0 : $_POST['published']; 
    37 if (($id = saveDraftEntry($entry)) !== false) { 
     42$id = saveDraftEntry($blogid, $entry); 
     43if ($id > 0) { 
    3844    setBlogSetting('LatestEditedEntry_user'.getUserId(),$id); 
    3945    $result = array(); 
    40     $result['error'] = (($id !== false) === true ? 0 : 1); 
     46    $result['error'] = ($id > 0) ? 0 : 1; 
    4147    $result['entryId'] = $id; 
     48    $result['suriid'] = $suri['id']; 
    4249    printRespond($result); 
     50} else { 
     51    respondResultPage(1); 
    4352} 
    44 else 
    45     respondResultPage(1); 
    4653?> 
  • trunk/blog/owner/entry/edit/item.php

    r4615 r4621  
    2929    $suri['id'] = 0; 
    3030 
    31 if($_GET['draft']) { 
     31if(isset($_GET['draft'])) { 
    3232    $entry = getEntry(getBlogId(), $suri['id'], true); 
    3333} else { 
     
    7676                                    return true; 
    7777                                } 
    78                                  
    7978                                function setEnclosure(value) { 
    8079                                    var filename = value.substring(0, value.indexOf("|")); 
     
    299298                                            return false; 
    300299                                        } 
    301                                         data = data+"&draft=1"; 
    302300                                        if(entryManager.isSaved == true) { 
    303                                             var request = new HTTPRequest("POST", "<?php echo $blogURL;?>/owner/entry/update/"+entryManager.entryId); 
     301                                            var request = new HTTPRequest("POST", "<?php echo $blogURL;?>/owner/entry/draft/"+entryManager.entryId); 
    304302<?php 
    305303    if($service['useRewriteEngine'] == false) { 
     
    359357                                        if (data == null) 
    360358                                            return false; 
    361                                         data = data+"&draft=0"; 
    362359                                        if(entryManager.isSaved == true) { 
    363360                                            var request = new HTTPRequest("POST", "<?php echo $blogURL;?>/owner/entry/update/"+entryManager.entryId); 
  • trunk/blog/owner/entry/update/item.php

    r4617 r4621  
    1717        'acceptComment' => array(array('0', '1'), 'default' => '0'), 
    1818        'acceptTrackback' => array(array('0', '1'), 'default' => '0'), 
    19         'published' => array('int', 0, 'default' => 1), 
    20         'draft' => array(array('0', '1'), 'default' => '0') 
     19        'published' => array('int', 0, 'default' => 1) 
    2120    ) 
    2221); 
     
    2524 
    2625requireStrictRoute(); 
    27 $entry = array(); 
    28 $isDraft = empty($_POST['draft']) ? 0 : $_POST['draft']; 
    29 if($isDraft) { // Prepare for draft saving. 
    30     $entry['id'] = $suri['id']; 
     26 
     27$updateDraft = 0; 
     28$entry = getEntry($blogid, $suri['id']); 
     29if(empty($entry)) { 
     30    $entry = getEntry($blogid, $suri['id'],true); 
     31    $updateDraft = 1; 
     32} 
     33if (!empty($entry)) { 
    3134    $entry['visibility'] = $_POST['visibility']; 
    3235    $entry['category'] = $_POST['category']; 
     
    4144    $entry['acceptTrackback'] = empty($_POST['acceptTrackback']) ? 0 : 1; 
    4245    $entry['published'] = empty($_POST['published']) ? 0 : $_POST['published']; 
    43     $entry['draft'] = empty($_POST['draft']) ? 0 : $_POST['draft']; 
    44 } else if ($entry = getEntry($blogid, $suri['id'])) { // Non-draft saving. 
    45     $entry['visibility'] = $_POST['visibility']; 
    46     $entry['category'] = $_POST['category']; 
    47     $entry['location'] = empty($_POST['location']) ? '/' : $_POST['location']; 
    48     $entry['tag'] = empty($_POST['tag']) ? '' : $_POST['tag']; 
    49     $entry['title'] = $_POST['title']; 
    50     $entry['content'] = $_POST['content']; 
    51     $entry['contentFormatter'] = $_POST['contentFormatter']; 
    52     $entry['contentEditor'] = $_POST['contentEditor']; 
    53     $entry['slogan'] = $_POST['permalink']; 
    54     $entry['acceptComment'] = empty($_POST['acceptComment']) ? 0 : 1; 
    55     $entry['acceptTrackback'] = empty($_POST['acceptTrackback']) ? 0 : 1; 
    56     $entry['published'] = empty($_POST['published']) ? 0 : $_POST['published']; 
    57     $entry['draft'] = empty($_POST['draft']) ? 0 : $_POST['draft']; 
    58 } 
    59 if(!empty($entry)) { 
    60     setBlogSetting('LatestEditedEntry_user'.getUserId(),$suri['id']); 
    61     if($id = updateEntry($blogid, $entry)) { 
     46 
     47    if($id = updateEntry($blogid, $entry, $updateDraft)) { 
    6248        fireEvent('UpdatePost', $id, $entry); 
     49        setBlogSetting('LatestEditedEntry_user'.getUserId(),$suri['id']); 
    6350        respondResultPage(0); 
    6451    } 
  • trunk/lib/config.php

    r4615 r4621  
    5757 
    5858// Include core components. 
     59// Due to the global variable scope issues, use require here instead of requireComponent. 
     60 
    5961requireComponent('Eolin.PHP.UnifiedEnvironment'); 
    6062requireComponent('Eolin.PHP.Core'); 
  • trunk/lib/includeForBlogOwner.php

    r4605 r4621  
    1212require 'function/image.php'; 
    1313require 'function/mail.php'; 
    14 //require 'function/legacy.php'; 
     14require 'function/legacy.php'; 
    1515require 'functions.php'; 
    1616require 'database.php'; 
  • trunk/lib/model/blog.entry.php

    r4617 r4621  
    8383} 
    8484 
    85 function getUserIdOfEntry($blogid, $id) { 
     85function getUserIdOfEntry($blogid, $id, $draft = false) { 
    8686    global $database; 
    8787    $result = DBQuery::queryCell("SELECT userid  
     
    417417    requireModel("blog.tag"); 
    418418    requireModel("blog.locative"); 
     419 
    419420    $entry['userid'] = getUserId(); 
    420421    $entry['title'] = UTF8::lessenAsEncoding(trim($entry['title']), 255); 
     
    448449    } 
    449450 
    450     $result = DBQuery::queryCount("SELECT slogan FROM {$database['prefix']}Entries WHERE blogid = $blogid AND slogan = '$slogan' AND draft = $isDraft LIMIT 1"); 
     451    $result = DBQuery::queryCount("SELECT slogan FROM {$database['prefix']}Entries WHERE blogid = $blogid AND slogan = '$slogan' AND draft = 0 LIMIT 1"); 
    451452    for ($i = 1; $result > 0; $i++) { 
    452453        if ($i > 1000) 
    453454            return false; 
    454455        $slogan = tc_escape_string(UTF8::lessenAsEncoding($slogan0, 245) . '-' . $i); 
    455         $result = DBQuery::queryCount("SELECT slogan FROM {$database['prefix']}Entries WHERE blogid = $blogid AND slogan = '$slogan' AND draft = $isDraft LIMIT 1"); 
     456        $result = DBQuery::queryCount("SELECT slogan FROM {$database['prefix']}Entries WHERE blogid = $blogid AND slogan = '$slogan' AND draft = 0 LIMIT 1"); 
    456457    } 
    457458    $userid = $entry['userid']; 
     
    468469    } 
    469470     
    470     if(isset($entry['id'])) { // entry id가 있는 경우 (주로 updateEntry에 의하여 draft를 생성하는 경우가 될 것이다) 
    471         if(DBQuery::queryCell("SELECT count(*) FROM {$database['prefix']}Entries WHERE blogid = $blogid AND id = {$entry['id']} AND draft = $isDraft") != 0) { // 이미 원하는 draft에 같은 id가 다 존재한다. 이 경우 저장할 수 없음. 
     471    if(isset($entry['id'])) { // entry id를 지정한 경우 (주로 saveDraftEntry에 의하여 draft를 생성하는 경우가 될 것이다) 
     472        if(DBQuery::queryCell("SELECT count(*)  
     473            FROM {$database['prefix']}Entries  
     474            WHERE blogid = $blogid  
     475                AND id = {$entry['id']}  
     476                AND draft = $isDraft") > 0) { // 이미 원하는 draft에 같은 id가 다 존재한다. 이 경우 저장할 수 없음. 
    472477            return false; 
    473478        } else { 
     
    510515        return false; 
    511516    DBQuery::query("UPDATE {$database['prefix']}Attachments SET parent = $id WHERE blogid = $blogid AND parent = 0"); 
    512     if(!$isDraft) { 
     517    if(!$isDraft) { // draft가 없는 상태에서 저장하고 나가는 경우. 
    513518        DBQuery::query("DELETE FROM {$database['prefix']}Entries WHERE blogid = $blogid AND id = $id AND draft = 1"); 
    514519        updateEntriesOfCategory($blogid, $entry['category']); 
     
    525530} 
    526531 
    527 function updateEntry($blogid, $entry) { 
     532function updateEntry($blogid, $entry, $updateDraft = 0) { 
    528533    global $database; 
    529534    global $blog; 
     
    535540 
    536541    if($entry['id'] == 0) return false; 
    537     $isDraft = empty($entry['draft']) ? 0 : $entry['draft']; 
    538  
    539     // entry가 draft가 없으면서(draft = 1인 글이 없는 경우) 저장하려는 요구사항이 draft인 경우는 addEntry로 글을 더한다. 
    540     $draftCount = DBQuery::queryCell("SELECT count(*) FROM {$database['prefix']}Entries 
    541         WHERE blogid = $blogid 
    542             AND id = ".$entry['id']." 
    543             AND draft = 1"); 
    544     if(($draftCount == 0) && ($isDraft == 1)) { 
    545         return addEntry($blogid, $entry); 
    546     } 
    547     // draft가 없으면서 정상적인 글을 저장하려는 경우, (이 경우는 현재 글을 update한다.) 
    548     // draft가 있으면서 정상적인 글을 저장하려는 경우, (이 경우는 draft를 update한다.) 
    549     // draft가 있으면서 draft를 저장하려는 경우가 남음. (이 경우도 draft를 update한다.) 
    550542     
    551543    if(empty($entry['userid'])) $entry['userid'] = getUserId();  
     
    587579        AND slogan = '$slogan'  
    588580        AND id = {$entry['id']}  
    589         AND draft = $isDraft LIMIT 1"); 
     581        AND draft = 0 
     582        LIMIT 1"); 
    590583    if ($result == 0) { // if changed 
    591         $result = DBQuery::queryCount("SELECT slogan FROM {$database['prefix']}Entries WHERE blogid = $blogid AND slogan = '$slogan' AND draft = $isDraft LIMIT 1"); 
     584        $result = DBQuery::queryCount("SELECT slogan FROM {$database['prefix']}Entries WHERE blogid = $blogid AND slogan = '$slogan' AND draft = 0 LIMIT 1"); 
    592585        for ($i = 1; $result > 0; $i++) { 
    593586            if ($i > 1000) 
    594587                return false; 
    595588            $slogan = tc_escape_string(UTF8::lessenAsEncoding($slogan0, 245) . '-' . $i); 
    596             $result = DBQuery::queryCount("SELECT slogan FROM {$database['prefix']}Entries WHERE blogid = $blogid AND slogan = '$slogan' AND draft = $isDraft LIMIT 1"); 
     589            $result = DBQuery::queryCount("SELECT slogan FROM {$database['prefix']}Entries WHERE blogid = $blogid AND slogan = '$slogan' AND draft = 0 LIMIT 1"); 
    597590        } 
    598591    } 
     
    616609            break; 
    617610    } 
    618      
    619     // draft가 없으면서 정상적인 글을 저장하려는 경우, (이 경우는 현재 글을 update한다.) 
    620     if(($draftCount == 0) && ($isDraft == 0)) $draftSign = 0; 
    621     else $draftSign = 1; 
    622  
    623     // 원래 글이 이미 있으면서 정상적인 글을 저장하려는 경우 원래 글을 날리고 현재 draft를 update한다. 
    624     if(($draftCount > 0) && ($isDraft == 0)) { 
    625         if(!DBQuery::query("DELETE FROM {$database['prefix']}Entries WHERE blogid = $blogid AND id = {$entry['id']} AND draft = 0")) return false; 
    626     } 
     611 
    627612    $result = DBQuery::query("UPDATE {$database['prefix']}Entries 
    628613            SET 
     
    630615                visibility         = {$entry['visibility']}, 
    631616                category           = {$entry['category']}, 
    632                 draft              = $isDraft, 
     617                draft              = 0, 
    633618                location           = '$location', 
    634619                title              = '$title', 
     
    641626                published          = $published, 
    642627                modified           = UNIX_TIMESTAMP() 
    643             WHERE blogid = $blogid AND id = {$entry['id']} AND draft = $draftSign"); 
    644     if($isDraft == 0) {  // Publishing phase. 
    645         if ($result) // 정상적인 글을 저장하려는 경우 draft는 날린다. 
    646             DBQuery::query("DELETE FROM {$database['prefix']}Entries WHERE blogid = $blogid AND id = {$entry['id']} AND draft = 1"); 
    647         updateEntriesOfCategory($blogid, $entry['category']); 
    648         if ($entry['visibility'] == 3) 
    649             syndicateEntry($entry['id'], 'modify'); 
    650         DBQuery::query("UPDATE {$database['prefix']}Attachments SET parent = {$entry['id']} WHERE blogid = $blogid AND parent = 0"); 
    651         if ($entry['visibility'] >= 2) 
    652             clearRSS(); 
     628            WHERE blogid = $blogid AND id = {$entry['id']} AND draft = $updateDraft"); 
     629    if ($result) 
     630        @DBQuery::query("DELETE FROM {$database['prefix']}Entries WHERE blogid = $blogid AND id = {$entry['id']} AND draft = 1"); 
     631    updateEntriesOfCategory($blogid, $entry['category']); 
     632    if ($entry['visibility'] == 3) 
     633        syndicateEntry($entry['id'], 'modify'); 
     634    DBQuery::query("UPDATE {$database['prefix']}Attachments SET parent = {$entry['id']} WHERE blogid = $blogid AND parent = 0"); 
     635    if ($entry['visibility'] >= 2) 
     636        clearRSS(); 
     637    return $result ? $entry['id'] : false; 
     638} 
     639 
     640function saveDraftEntry($blogid, $entry) { 
     641    global $database, $blog; 
     642    requireModel('blog.tag'); 
     643    requireModel('blog.locative'); 
     644    requireModel('blog.attachment'); 
     645    requireModel('blog.category'); 
     646    requireModel('blog.rss'); 
     647 
     648    if($entry['id'] == 0) return -11; 
     649 
     650    $draftCount = DBQuery::queryCell("SELECT count(*) FROM {$database['prefix']}Entries 
     651        WHERE blogid = $blogid 
     652            AND id = ".$entry['id']." 
     653            AND draft = 1"); 
     654 
     655    if($draftCount > 0) { // draft가 없으면 insert를, 있으면 update를. 
     656        $doUpdate = true; 
     657    } else { 
     658        $doUpdate = false; 
     659    } 
     660    // 원 글을 읽어서 몇가지 정보를 보존한다. 원래 글이 없는 경우 draft는 저장될 수 없다. 
     661    $origEntry = DBQuery::queryRow("SELECT created, comments, trackbacks, password 
     662        FROM {$database['prefix']}Entries 
     663        WHERE blogid = $blogid 
     664            AND id = ".$entry['id']." 
     665            AND draft = 0"); 
     666    if(empty($origEntry)) return -12; 
     667     
     668    $created = $origEntry['created']; 
     669    $comments = $origEntry['comments']; 
     670    $trackbacks = $origEntry['trackbacks']; 
     671    $password = $origEntry['password']; 
     672     
     673    if(empty($entry['userid'])) $entry['userid'] = getUserId();  
     674    $entry['title'] = UTF8::lessenAsEncoding(trim($entry['title'])); 
     675    $entry['location'] = UTF8::lessenAsEncoding(trim($entry['location'])); 
     676    $entry['slogan'] = array_key_exists('slogan', $entry) ? trim($entry['slogan']) : ''; 
     677    if(empty($entry['slogan'])) { 
     678        $slogan = $slogan0 = getSlogan($entry['title']); 
     679    } else { 
     680        $slogan = $slogan0 = getSlogan($entry['slogan']); 
     681    } 
     682    $slogan = tc_escape_string(UTF8::lessenAsEncoding($slogan, 255)); 
     683    $title = tc_escape_string($entry['title']); 
     684 
     685    if($entry['category'] == -1) { 
     686        if($entry['visibility'] == 1 || $entry['visibility'] == 3) 
     687            return false; 
     688        if(DBQuery::queryCell("SELECT count(*)  
     689            FROM {$database['prefix']}Entries  
     690            WHERE blogid = $blogid  
     691                AND id <> {$entry['id']}  
     692                AND draft = 0  
     693                AND title = '$title'  
     694                AND category = -1") > 0) 
     695            return -13; 
     696    } 
     697 
     698    if ($entry['category'] < 0) { 
     699        if ($entry['visibility'] == 1) $entry['visibility'] = 0; 
     700        if ($entry['visibility'] == 3) $entry['visibility'] = 2; 
     701    } 
     702    if ($entry['category'] == -4) { 
     703        $entry['visibility'] = 0; 
     704    } 
     705     
     706    $result = DBQuery::queryCount("SELECT slogan  
     707        FROM {$database['prefix']}Entries  
     708        WHERE blogid = $blogid  
     709        AND slogan = '$slogan'  
     710        AND id = {$entry['id']}  
     711        AND draft = 0 LIMIT 1"); 
     712    if ($result == 0) { // if changed 
     713        $result = DBQuery::queryCount("SELECT slogan FROM {$database['prefix']}Entries WHERE blogid = $blogid AND slogan = '$slogan' AND draft = 0 LIMIT 1"); 
     714        for ($i = 1; $result > 0; $i++) { 
     715            if ($i > 1000) 
     716                return false; 
     717            $slogan = tc_escape_string(UTF8::lessenAsEncoding($slogan0, 245) . '-' . $i); 
     718            $result = DBQuery::queryCount("SELECT slogan FROM {$database['prefix']}Entries WHERE blogid = $blogid AND slogan = '$slogan' AND draft = 0 LIMIT 1"); 
     719        } 
     720    } 
     721    $tags = getTagsWithEntryString($entry['tag']); 
     722    modifyTagsWithEntryId($blogid, $entry['id'], $tags); 
     723     
     724    $location = tc_escape_string($entry['location']); 
     725    $content = tc_escape_string($entry['content']); 
     726    $contentFormatter = tc_escape_string($entry['contentFormatter']); 
     727    $contentEditor = tc_escape_string($entry['contentEditor']); 
     728    switch ($entry['published']) { 
     729        case 0: 
     730            $published = 'published'; 
     731            break; 
     732        case 1: 
     733            $published = 'UNIX_TIMESTAMP()'; 
     734            break; 
     735        default: 
     736            $published = $entry['published']; 
     737            $entry['visibility'] = 0 - $entry['visibility']; 
     738            break; 
     739    } 
     740 
     741    if($doUpdate) { 
     742        $result = DBQuery::query("UPDATE {$database['prefix']}Entries 
     743            SET 
     744                userid             = {$entry['userid']}, 
     745                visibility         = {$entry['visibility']}, 
     746                category           = {$entry['category']}, 
     747                draft              = 1, 
     748                location           = '$location', 
     749                title              = '$title', 
     750                content            = '$content', 
     751                contentFormatter   = '$contentFormatter', 
     752                contentEditor      = '$contentEditor', 
     753                slogan             = '$slogan', 
     754                acceptComment      = {$entry['acceptComment']}, 
     755                acceptTrackback    = {$entry['acceptTrackback']}, 
     756                published          = $published, 
     757                modified           = UNIX_TIMESTAMP() 
     758            WHERE blogid = $blogid AND id = {$entry['id']} AND draft = 1"); 
     759    } else { 
     760        $result = DBQuery::query("INSERT INTO {$database['prefix']}Entries  
     761            (blogid, userid, id, draft, visibility, category, title, slogan, content, contentFormatter, 
     762             contentEditor, location, password, acceptComment, acceptTrackback, published, created, modified, 
     763             comments, trackbacks)  
     764            VALUES ( 
     765            $blogid, 
     766            {$entry['userid']}, 
     767            {$entry['id']}, 
     768            1, 
     769            {$entry['visibility']}, 
     770            {$entry['category']}, 
     771            '$title', 
     772            '$slogan', 
     773            '$content', 
     774            '$contentFormatter', 
     775            '$contentEditor', 
     776            '$location', 
     777            '$password', 
     778            {$entry['acceptComment']}, 
     779            {$entry['acceptTrackback']}, 
     780            $published, 
     781            $created, 
     782            UNIX_TIMESTAMP(), 
     783            $comments, 
     784            $trackbacks)"); 
    653785    } 
    654786    return $result ? $entry['id'] : false;