Exemple #1
0
function saveDraftEntry($blogid, $entry)
{
    global $database, $blog;
    requireModel('blog.tag');
    requireModel('blog.locative');
    requireModel('blog.attachment');
    requireModel('blog.category');
    requireModel('blog.feed');
    requireComponent('Textcube.Data.Tag');
    if ($entry['id'] == 0) {
        return -11;
    }
    $draftCount = POD::queryCell("SELECT count(*) FROM {$database['prefix']}Entries\n\t\tWHERE blogid = {$blogid}\n\t\t\tAND id = " . $entry['id'] . "\n\t\t\tAND draft = 1");
    if ($draftCount > 0) {
        // draft가 없으면 insert를, 있으면 update를.
        $doUpdate = true;
    } else {
        $doUpdate = false;
    }
    // 원 글을 읽어서 몇가지 정보를 보존한다. 원래 글이 없는 경우 draft는 저장될 수 없다.
    $origEntry = POD::queryRow("SELECT created, comments, trackbacks, pingbacks, password\n\t\tFROM {$database['prefix']}Entries\n\t\tWHERE blogid = {$blogid}\n\t\t\tAND id = " . $entry['id'] . "\n\t\t\tAND draft = 0");
    if (empty($origEntry)) {
        return -12;
    }
    $created = $origEntry['created'];
    $comments = $origEntry['comments'];
    $trackbacks = $origEntry['trackbacks'];
    $pingbacks = $origEntry['pingbacks'];
    $password = $origEntry['password'];
    if (empty($entry['userid'])) {
        $entry['userid'] = getUserId();
    }
    $entry['title'] = UTF8::lessenAsEncoding(trim($entry['title']));
    $entry['location'] = UTF8::lessenAsEncoding(trim($entry['location']));
    $entry['slogan'] = array_key_exists('slogan', $entry) ? trim($entry['slogan']) : '';
    if (empty($entry['slogan'])) {
        $slogan = $slogan0 = getSlogan($entry['title']);
    } else {
        $slogan = $slogan0 = getSlogan($entry['slogan']);
    }
    $slogan = POD::escapeString(UTF8::lessenAsEncoding($slogan, 255));
    $title = POD::escapeString($entry['title']);
    if ($entry['category'] == -1) {
        if ($entry['visibility'] == 1 || $entry['visibility'] == 3) {
            return false;
        }
        if (POD::queryCell("SELECT count(*) \n\t\t\tFROM {$database['prefix']}Entries \n\t\t\tWHERE blogid = {$blogid} \n\t\t\t\tAND id <> {$entry['id']} \n\t\t\t\tAND draft = 0 \n\t\t\t\tAND title = '{$title}' \n\t\t\t\tAND category = -1") > 0) {
            return -13;
        }
    }
    if ($entry['category'] < 0) {
        if ($entry['visibility'] == 1) {
            $entry['visibility'] = 0;
        }
        if ($entry['visibility'] == 3) {
            $entry['visibility'] = 2;
        }
    }
    if ($entry['category'] == -4) {
        $entry['visibility'] = 0;
    }
    $result = POD::queryCount("SELECT slogan \n\t\tFROM {$database['prefix']}Entries \n\t\tWHERE blogid = {$blogid} \n\t\tAND slogan = '{$slogan}' \n\t\tAND id = {$entry['id']} \n\t\tAND draft = 0 LIMIT 1");
    if ($result == 0) {
        // if changed
        $result = POD::queryExistence("SELECT slogan FROM {$database['prefix']}Entries WHERE blogid = {$blogid} AND slogan = '{$slogan}' AND draft = 0 LIMIT 1");
        for ($i = 1; $result != false; $i++) {
            if ($i > 1000) {
                return false;
            }
            $slogan = POD::escapeString(UTF8::lessenAsEncoding($slogan0, 245) . '-' . $i);
            $result = POD::queryExistence("SELECT slogan FROM {$database['prefix']}Entries WHERE blogid = {$blogid} AND slogan = '{$slogan}' AND draft = 0 LIMIT 1");
        }
    }
    $tags = getTagsWithEntryString($entry['tag']);
    Tag::modifyTagsWithEntryId($blogid, $entry['id'], $tags);
    $location = POD::escapeString($entry['location']);
    $latitude = isset($entry['latitude']) && !is_null($entry['latitude']) ? $entry['latitude'] : 'NULL';
    $longitude = isset($entry['longitude']) && !is_null($entry['longitude']) ? $entry['longitude'] : 'NULL';
    $content = POD::escapeString($entry['content']);
    $contentformatter = POD::escapeString($entry['contentformatter']);
    $contenteditor = POD::escapeString($entry['contenteditor']);
    switch ($entry['published']) {
        case 0:
            $published = 'published';
            break;
        case 1:
            $published = 'UNIX_TIMESTAMP()';
            break;
        default:
            $published = $entry['published'];
            $entry['visibility'] = 0 - $entry['visibility'];
            break;
    }
    if ($doUpdate) {
        $result = POD::query("UPDATE {$database['prefix']}Entries\n\t\t\tSET\n\t\t\t\tuserid             = {$entry['userid']},\n\t\t\t\tvisibility         = {$entry['visibility']},\n\t\t\t\tstarred            = {$entry['starred']},\n\t\t\t\tcategory           = {$entry['category']},\n\t\t\t\tdraft              = 1,\n\t\t\t\tlocation           = '{$location}',\n\t\t\t\tlatitude           = {$latitude},\n\t\t\t\tlongitude          = {$longitude},\n\t\t\t\ttitle              = '{$title}',\n\t\t\t\tcontent            = '{$content}',\n\t\t\t\tcontentformatter   = '{$contentformatter}',\n\t\t\t\tcontenteditor      = '{$contenteditor}',\n\t\t\t\tslogan             = '{$slogan}',\n\t\t\t\tacceptcomment      = {$entry['acceptcomment']},\n\t\t\t\taccepttrackback    = {$entry['accepttrackback']},\n\t\t\t\tpublished          = {$published},\n\t\t\t\tmodified           = UNIX_TIMESTAMP()\n\t\t\tWHERE blogid = {$blogid} AND id = {$entry['id']} AND draft = 1");
    } else {
        $result = POD::query("INSERT INTO {$database['prefix']}Entries \n\t\t\t(blogid, userid, id, draft, visibility, starred, category, title, slogan, content, contentformatter,\n\t\t\t contenteditor, location, password, acceptcomment, accepttrackback, published, created, modified,\n\t\t\t comments, trackbacks, pingbacks) \n\t\t\tVALUES (\n\t\t\t{$blogid},\n\t\t\t{$entry['userid']},\n\t\t\t{$entry['id']},\n\t\t\t1,\n\t\t\t{$entry['visibility']},\n\t\t\t{$entry['starred']},\n\t\t\t{$entry['category']},\n\t\t\t'{$title}',\n\t\t\t'{$slogan}',\n\t\t\t'{$content}',\n\t\t\t'{$contentformatter}',\n\t\t\t'{$contenteditor}',\n\t\t\t'{$location}',\n\t\t\t'{$password}',\n\t\t\t{$entry['acceptcomment']},\n\t\t\t{$entry['accepttrackback']},\n\t\t\t{$published},\n\t\t\t{$created},\n\t\t\tUNIX_TIMESTAMP(),\n\t\t\t{$comments},\n\t\t\t{$trackbacks},\n\t\t\t{$pingbacks})");
    }
    return $result ? $entry['id'] : false;
}
Exemple #2
0
function saveDraftEntry($blogid, $entry)
{
    $ctx = Model_Context::getInstance();
    $pool = DBModel::getInstance();
    importlib('model.blog.tag');
    importlib('model.blog.locative');
    importlib('model.blog.attachment');
    importlib('model.blog.category');
    importlib('model.blog.feed');
    if ($entry['id'] == 0) {
        return -11;
    }
    $pool->init("Entries");
    $pool->setQualifier("blogid", "eq", $blogid);
    $pool->setQualifier("id", "eq", $entry['id']);
    $pool->setQualifier("draft", "eq", 1);
    $draftCount = $pool->getCount();
    if ($draftCount > 0) {
        // draft가 없으면 insert를, 있으면 update를.
        $doUpdate = true;
    } else {
        $doUpdate = false;
    }
    // 원 글을 읽어서 몇가지 정보를 보존한다. 원래 글이 없는 경우 draft는 저장될 수 없다.
    $pool->init("Entries");
    $pool->setQualifier("blogid", "eq", $blogid);
    $pool->setQualifier("id", "eq", $entry['id']);
    $pool->setQualifier("draft", "eq", 0);
    $origEntry = $pool->getRow("created, comments, trackbacks, pingbacks, password, published");
    if (empty($origEntry)) {
        return -12;
    }
    $created = $origEntry['created'];
    $comments = $origEntry['comments'];
    $trackbacks = $origEntry['trackbacks'];
    $pingbacks = $origEntry['pingbacks'];
    $password = $origEntry['password'];
    if (empty($entry['userid'])) {
        $entry['userid'] = getUserId();
    }
    $entry['title'] = Utils_Unicode::lessenAsEncoding(trim($entry['title']));
    $entry['location'] = Utils_Unicode::lessenAsEncoding(trim($entry['location']));
    $entry['slogan'] = array_key_exists('slogan', $entry) ? trim($entry['slogan']) : '';
    if (empty($entry['slogan'])) {
        $slogan = $slogan0 = getSlogan($entry['title']);
    } else {
        $slogan = $slogan0 = getSlogan($entry['slogan']);
    }
    $slogan = Utils_Unicode::lessenAsEncoding($slogan, 255);
    $title = $entry['title'];
    if ($entry['category'] == -1) {
        if ($entry['visibility'] == 1 || $entry['visibility'] == 3) {
            return false;
        }
        $pool->init("Entries");
        $pool->setQualifier("blogid", "eq", $blogid);
        $pool->setQualifier("id", "neq", $entry['id']);
        $pool->setQualifier("draft", "eq", 0);
        $pool->setQualifier("title", "eq", $entry['title'], true);
        $pool->setQualifier("category", "eq", -1);
        if ($pool->getCount() > 0) {
            return -13;
        }
    }
    if ($entry['category'] < 0) {
        if ($entry['visibility'] == 1) {
            $entry['visibility'] = 0;
        }
        if ($entry['visibility'] == 3) {
            $entry['visibility'] = 2;
        }
    }
    if ($entry['category'] == -4) {
        $entry['visibility'] = 0;
    }
    $slogan = getUniqueSlogan($blogid, $slogan, $entry['id']);
    $tags = getTagsWithEntryString($entry['tag']);
    Tag::modifyTagsWithEntryId($blogid, $entry['id'], $tags);
    $location = $entry['location'];
    $latitude = isset($entry['latitude']) && !is_null($entry['latitude']) ? $entry['latitude'] : null;
    $longitude = isset($entry['longitude']) && !is_null($entry['longitude']) ? $entry['longitude'] : null;
    $content = $entry['content'];
    $contentformatter = $entry['contentformatter'];
    $contenteditor = $entry['contenteditor'];
    switch ($entry['published']) {
        case 0:
            $published = $origEntry['published'];
            break;
        case 1:
            $published = Timestamp::getUNIXtime();
            break;
        default:
            $published = $entry['published'];
            $entry['visibility'] = 0 - $entry['visibility'];
            break;
    }
    if ($doUpdate) {
        $pool->reset("Entries");
        $pool->setAttribute("userid", $entry['userid']);
        $pool->setAttribute("draft", 1);
        $pool->setAttribute("visibility", $entry['visibility']);
        $pool->setAttribute("starred", $entry['starred']);
        $pool->setAttribute("category", $entry['category']);
        $pool->setAttribute("title", $title, true);
        $pool->setAttribute("slogan", $slogan, true);
        $pool->setAttribute("content", $entry['content'], true);
        $pool->setAttribute("contentformatter", $entry['contentformatter'], true);
        $pool->setAttribute("contenteditor", $entry['contenteditor'], true);
        $pool->setAttribute("location", $entry['location'], true);
        $pool->setAttribute("latitude", $latitude);
        $pool->setAttribute("longitude", $longitude);
        $pool->setAttribute("acceptcomment", $entry['acceptcomment']);
        $pool->setAttribute("accepttrackback", $entry['accepttrackback']);
        $pool->setAttribute("published", $published);
        $pool->setAttribute("modified", Timestamp::getUNIXtime());
        $pool->setQualifier("blogid", "eq", $blogid);
        $pool->setQualifier("id", "eq", $entry['id']);
        $pool->setQualifier("draft", "eq", 1);
        $result = $pool->update();
    } else {
        $pool->reset("Entries");
        $pool->setAttribute("blogid", $blogid);
        $pool->setAttribute("userid", $entry['userid']);
        $pool->setAttribute("id", $entry['id']);
        $pool->setAttribute("draft", 1);
        $pool->setAttribute("visibility", $entry['visibility']);
        $pool->setAttribute("starred", $entry['starred']);
        $pool->setAttribute("category", $entry['category']);
        $pool->setAttribute("title", $title, true);
        $pool->setAttribute("slogan", $slogan, true);
        $pool->setAttribute("content", $entry['content'], true);
        $pool->setAttribute("contentformatter", $entry['contentformatter'], true);
        $pool->setAttribute("contenteditor", $entry['contenteditor'], true);
        $pool->setAttribute("location", $entry['location'], true);
        $pool->setAttribute("latitude", $latitude);
        $pool->setAttribute("longitude", $longitude);
        $pool->setAttribute("password", $password, true);
        $pool->setAttribute("acceptcomment", $entry['acceptcomment']);
        $pool->setAttribute("accepttrackback", $entry['accepttrackback']);
        $pool->setAttribute("published", $published);
        $pool->setAttribute("created", $created);
        $pool->setAttribute("modified", Timestamp::getUNIXtime());
        $pool->setAttribute("comments", $comments);
        $pool->setAttribute("trackbacks", $trackbacks);
        $pool->setAttribute("pingbacks", $pingbacks);
        $result = $pool->insert();
    }
    return $result ? $entry['id'] : false;
}