Example #1
0
function removeServiceSetting($name, $pruneSimilarEntries = false)
{
    global $database;
    clearServiceSettingCache();
    if ($pruneSimilarEntries) {
        return POD::execute("DELETE FROM {$database['prefix']}ServiceSettings WHERE name like '" . POD::escapeString($name) . "'");
    } else {
        return POD::execute("DELETE FROM {$database['prefix']}ServiceSettings WHERE name = '" . POD::escapeString($name) . "'");
    }
}
 function removeAll($removeAttachments = true)
 {
     global $database;
     $blogid = getBlogId();
     $tags = POD::queryColumn("SELECT DISTINCT tag FROM {$database['prefix']}TagRelations WHERE blogid = {$blogid}");
     POD::query("UPDATE {$database['prefix']}BlogStatistics SET visits = 0 WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}DailyStatistics WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}Categories WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}Attachments WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}Comments WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}CommentsNotified WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}RemoteResponses WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}RemoteResponseLogs WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}TagRelations WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}Entries WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}LinkCategories WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}Links WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}RefererLogs WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}RefererStatistics WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}Plugins WHERE blogid = {$blogid}");
     //POD::query("DELETE FROM {$database['prefix']}UserSettings WHERE user = $blogid");
     POD::query("DELETE FROM {$database['prefix']}Filters WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}FeedStarred WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}FeedReads WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}FeedGroupRelations WHERE blogid = {$blogid}");
     POD::query("DELETE FROM {$database['prefix']}FeedGroups WHERE blogid = {$blogid} AND id <> 0");
     if (count($tags) > 0) {
         $tagliststr = implode(', ', $tags);
         $nottargets = POD::queryColumn("SELECT DISTINCT tag FROM {$database['prefix']}TagRelations WHERE tag in ( {$tagliststr} )");
         if (count($nottargets) > 0) {
             $nottargetstr = implode(', ', $nottargets);
             POD::execute("DELETE FROM {$database['prefix']}Tags WHERE id IN ( {$tagliststr} ) AND id NOT IN ( {$nottargetstr} )");
         } else {
             POD::execute("DELETE FROM {$database['prefix']}Tags WHERE id IN ( {$tagliststr} ) ");
         }
     }
     if (file_exists(__TEXTCUBE_CACHE_DIR__ . "/rss/{$blogid}.xml")) {
         unlink(__TEXTCUBE_CACHE_DIR__ . "/rss/{$blogid}.xml");
     }
     if ($removeAttachments) {
         Path::removeFiles(Path::combine(ROOT, 'attach', $blogid));
         POD::query("UPDATE {$database['prefix']}BlogSettings SET logo = '' WHERE blogid = {$blogid}");
     }
 }
Example #3
0
function clearCache()
{
    global $database, $changed, $errorlog, $memcache;
    static $isCleared = false;
    if ($isCleared == true) {
        return;
    }
    if (!is_null($blogids = POD::queryColumn("SELECT blogid FROM {$database['prefix']}PageCacheLog"))) {
        $changed = true;
        $errorlog = false;
        echo '<li>', _textf('페이지 캐시를 초기화합니다.'), ': ';
        foreach ($blogids as $ids) {
            if (CacheControl::flushAll($ids) == false) {
                $errorlog = true;
            }
        }
        if ($errorlog == false) {
            echo '<span class="result success">', _text('성공'), '</span></li>';
        } else {
            echo '<span class="result fail">', _text('실패'), '</span></li>';
        }
    }
    if (!is_null($memcache)) {
        echo '<li>', _textf('Memcached 캐시를 초기화합니다.'), ': ';
        if ($memcache->flush()) {
            echo '<span class="result success">', _text('성공'), '</span></li>';
        } else {
            echo '<span class="result fail">', _text('실패'), '</span></li>';
        }
    }
    echo '<li>', _textf('공지사항 캐시를 초기화합니다.'), ': ';
    if (POD::execute("DELETE FROM {$database['prefix']}ServiceSettings WHERE name like 'TextcubeNotice%'")) {
        echo '<span class="result success">', _text('성공'), '</span></li>';
    } else {
        echo '<span class="result fail">', _text('실패'), '</span></li>';
    }
    $isCleared = true;
}
Example #4
0
function treatPluginTable($plugin, $name, $fields, $keys, $version)
{
    $context = Model_Context::getInstance();
    //	global $context;
    if (doesExistTable($context->getProperty('database.prefix') . $name)) {
        $keyname = 'Database_' . $name;
        $value = $plugin;
        $result = Setting::getServiceSetting($keyname, null, true);
        if (is_null($result)) {
            $keyname = Utils_Unicode::lessenAsEncoding($keyname, 32);
            $value = Utils_Unicode::lessenAsEncoding($plugin . '/' . $version, 255);
            $query = DBModel::getInstance();
            $query->reset('ServiceSettings');
            $query->setAttribute('name', $keyname, true);
            $query->setAttribute('value', $value, true);
            $query->insert();
        } else {
            $keyname = Utils_Unicode::lessenAsEncoding($keyname, 32);
            $value = Utils_Unicode::lessenAsEncoding($plugin . '/' . $version, 255);
            $values = explode('/', $result, 2);
            if (strcmp($plugin, $values[0]) != 0) {
                // diff plugin
                return false;
                // nothing can be done
            } else {
                if (strcmp($version, $values[1]) != 0) {
                    $query = DBModel::getInstance();
                    $query->reset('ServiceSettings');
                    $query->setQualifier('name', 'equals', $keyname, true);
                    $query->setAttribute('value', $value, true);
                    $query->update();
                    $eventName = 'UpdateDB_' . $name;
                    fireEvent($eventName, $values[1]);
                }
            }
        }
        return true;
    } else {
        $query = "CREATE TABLE " . $context->getProperty('database.prefix') . $name . " (blogid int(11) NOT NULL default 0,";
        $isaiExists = false;
        $index = '';
        foreach ($fields as $field) {
            $ai = '';
            if (strtolower($field['attribute']) == 'int' || strtolower($field['attribute']) == 'mediumint') {
                if ($field['autoincrement'] == 1 && !$isaiExists) {
                    $ai = ' AUTO_INCREMENT ';
                    $isaiExists = true;
                    if (!in_array($field['name'], $keys)) {
                        $index = ", KEY({$field['name']})";
                    }
                }
            }
            $isNull = $field['isnull'] == 0 ? ' NOT NULL ' : ' NULL ';
            $defaultValue = is_null($field['default']) ? '' : " DEFAULT '" . POD::escapeString($field['default']) . "' ";
            $fieldLength = $field['length'] >= 0 ? "(" . $field['length'] . ")" : '';
            $sentence = $field['name'] . " " . $field['attribute'] . $fieldLength . $isNull . $defaultValue . $ai . ",";
            $query .= $sentence;
        }
        array_unshift($keys, 'blogid');
        $query .= " PRIMARY KEY (" . implode(',', $keys) . ")";
        $query .= $index;
        $query .= ") TYPE=MyISAM ";
        $query .= POD::charset() == 'utf8' ? 'DEFAULT CHARSET=utf8' : '';
        if (POD::execute($query)) {
            $keyname = Utils_Unicode::lessenAsEncoding('Database_' . $name, 32);
            $value = Utils_Unicode::lessenAsEncoding($plugin . '/' . $version, 255);
            Setting::setServiceSetting($keyname, $value, true);
            #POD::execute("INSERT INTO {$database['prefix']}ServiceSettings SET name='$keyname', value ='$value'");
            return true;
        } else {
            return false;
        }
    }
    return true;
}
Example #5
0
function clearCache()
{
    global $database, $changed, $errorlog, $memcache;
    static $isCleared = false;
    $context = Model_Context::getInstance();
    if ($isCleared == true) {
        return;
    }
    if (!is_null($blogids = POD::queryColumn("SELECT blogid FROM {$database['prefix']}PageCacheLog"))) {
        $changed = true;
        $errorlog = false;
        echo '<li>', _textf('페이지 캐시를 초기화합니다.'), ': ';
        foreach ($blogids as $ids) {
            if (CacheControl::flushAll($ids) == false) {
                $errorlog = true;
            }
        }
        if ($errorlog == false) {
            echo '<span class="result success">', _text('성공'), '</span></li>';
        } else {
            echo '<span class="result fail">', _text('실패'), '</span></li>';
        }
    }
    if ($context->getProperty('service.codecache', false)) {
        $changed = true;
        $errorlog = false;
        echo '<li>', _textf('코드 캐시를 초기화합니다.'), ': ';
        $code = new CodeCache();
        $code->flush();
        if ($errorlog == false) {
            echo '<span class="result success">', _text('성공'), '</span></li>';
        } else {
            echo '<span class="result fail">', _text('실패'), '</span></li>';
        }
    }
    if (!is_null($memcache)) {
        echo '<li>', _textf('Memcached 캐시를 초기화합니다.'), ': ';
        if ($memcache->flush()) {
            echo '<span class="result success">', _text('성공'), '</span></li>';
        } else {
            echo '<span class="result fail">', _text('실패'), '</span></li>';
        }
    }
    echo '<li>', _textf('공지사항 캐시를 초기화합니다.'), ': ';
    if (POD::execute("DELETE FROM {$database['prefix']}ServiceSettings WHERE name like 'TextcubeNotice%'")) {
        echo '<span class="result success">', _text('성공'), '</span></li>';
    } else {
        echo '<span class="result fail">', _text('실패'), '</span></li>';
    }
    if (!is_null($blogids = POD::queryColumn("SELECT DISTINCT blogid FROM {$database['prefix']}BlogSettings"))) {
        $changed = true;
        $errorlog = false;
        echo '<li>', _textf('댓글 및 트랙백 휴지통을 비웁니다.'), ': ';
        foreach ($blogids as $ids) {
            emptyTrash(true, $ids);
            emptyTrash(false, $ids);
        }
        if ($errorlog == false) {
            echo '<span class="result success">', _text('성공'), '</span></li>';
        } else {
            echo '<span class="result fail">', _text('실패'), '</span></li>';
        }
    }
    $isCleared = true;
}
Example #6
0
<?php

/// Copyright (c) 2004-2015, Needlworks  / Tatter Network Foundation
/// All rights reserved. Licensed under the GPL.
/// See the GNU General Public License for more details. (/documents/LICENSE, /documents/COPYRIGHT)
require ROOT . '/library/preprocessor.php';
requireStrictRoute();
if (!array_key_exists('viewMode', $_REQUEST)) {
    $_REQUEST['viewMode'] = '';
} else {
    $_REQUEST['viewMode'] = '?' . $_REQUEST['viewMode'];
}
POD::execute("DELETE FROM `{$database['prefix']}BlogSettings` WHERE `blogid` = {$blogid} AND `name` = 'coverpageOrder'");
header('Location: ' . $context->getProperty('uri.blog') . '/owner/skin/coverpage' . $_REQUEST['viewMode']);
 function removePageCacheLog()
 {
     global $database;
     if (empty($this->queryHash)) {
         $this->getQueryHash();
     }
     return POD::execute("DELETE FROM {$database['prefix']}PageCacheLog \n\t\t\tWHERE blogid = " . getBlogId() . "\n\t\t\tAND name = '" . POD::escapeString($this->queryHash) . "'");
 }
Example #8
0
function removeBlog($blogid)
{
    $pool = DBModel::getInstance();
    $ctx = Model_Context::getInstance();
    if (Setting::getServiceSetting("defaultBlogId", 1, true) == $blogid) {
        return false;
    }
    $targets = array('Attachments', 'BlogSettings', 'BlogStatistics', 'Categories', 'Comments', 'CommentsNotified', 'CommentsNotifiedQueue', 'DailyStatistics', 'Entries', 'EntriesArchive', 'FeedGroups', 'FeedReads', 'FeedStarred', 'FeedSettings', 'Filters', 'Links', 'LinkCategories', 'PageCacheLog', 'Plugins', 'RefererLogs', 'RefererStatistics', 'RemoteResponses', 'RemoteResponseLogs', 'SkinSettings', 'TagRelations', 'Privileges', 'XMLRPCPingSettings');
    //Clear Tables
    foreach ($targets as $t) {
        $pool->reset($t);
        $pool->setQualifier('blogid', 'eq', $blogid);
        $pool->delete();
    }
    //Delete Tags
    $tags = POD::queryColumn("SELECT DISTINCT tag FROM " . $ctx->getProperty('database.prefix') . "TagRelations WHERE blogid = {$blogid}");
    if (count($tags) > 0) {
        $tagliststr = implode(', ', $tags);
        // Tag id used at deleted blog.
        $nottargets = POD::queryColumn("SELECT DISTINCT tag FROM " . $ctx->getProperty('database.prefix') . "TagRelations WHERE tag in ( {$tagliststr} )");
        // Tag id used at other blogs.
        if (count($nottargets) > 0) {
            $nottargetstr = implode(', ', $nottargets);
            POD::execute("DELETE FROM " . $ctx->getProperty('database.prefix') . "Tags WHERE id IN ( {$tagliststr} ) AND id NOT IN ( {$nottargetstr} )");
        } else {
            POD::execute("DELETE FROM " . $ctx->getProperty('database.prefix') . "Tags WHERE id IN ( {$tagliststr} ) ");
        }
    }
    //Delete Feeds
    $feeds = POD::queryColumn("SELECT DISTINCT feeds FROM " . $ctx->getProperty('database.prefix') . "FeedGroupRelations WHERE blogid = {$blogid}");
    if (count($feeds) > 0) {
        foreach ($feeds as $feedId) {
            deleteFeed($blogid, $feedId);
        }
    }
    //Clear Plugin Database
    // TODO : encapsulate with 'value'
    $query = "SELECT name, value FROM " . $ctx->getProperty('database.prefix') . "ServiceSettings WHERE name like 'Database\\_%'";
    $plugintablesraw = POD::queryAll($query);
    foreach ($plugintablesraw as $table) {
        $dbname = $ctx->getProperty('database.prefix') . substr($table['name'], 9);
        POD::execute("DELETE FROM " . $ctx->getProperty('database.prefix') . "{$dbname} WHERE blogid = {$blogid}");
    }
    //Clear RSS Cache
    if (file_exists(__TEXTCUBE_CACHE_DIR__ . "/rss/{$blogid}.xml")) {
        unlink(__TEXTCUBE_CACHE_DIR__ . "/rss/{$blogid}.xml");
    }
    //Delete Attachments
    Path::removeFiles(Path::combine(ROOT, 'attach', $blogid));
    return true;
}
Example #9
0
 function deleteTagsWithEntryId($blogid, $entry)
 {
     global $database;
     $taglist = POD::queryColumn("SELECT tag FROM {$database['prefix']}TagRelations WHERE blogid = {$blogid} AND entry = {$entry}");
     if (!is_null($taglist)) {
         $tagliststr = implode(',', $taglist);
         foreach ($taglist as $tagid) {
             CacheControl::flushTag($tagid);
         }
         POD::execute("DELETE FROM {$database['prefix']}TagRelations\n\t\t\t\tWHERE blogid = {$blogid} AND entry = {$entry}");
         $nottargets = POD::queryColumn("SELECT DISTINCT tag FROM {$database['prefix']}TagRelations WHERE tag in ( {$tagliststr} )");
         if (count($nottargets) > 0) {
             $nottargetstr = implode(', ', $nottargets);
             POD::execute("DELETE FROM {$database['prefix']}Tags WHERE id IN ( {$tagliststr} ) AND id NOT IN ( {$nottargetstr} )");
         } else {
             POD::execute("DELETE FROM {$database['prefix']}Tags WHERE id IN ( {$tagliststr} )");
         }
     }
 }
 private static function DBQuery($mode = 'query', $sql)
 {
     switch ($mode) {
         case 'cell':
             return POD::queryCell($sql);
         case 'row':
             return POD::queryRow($sql);
         case 'execute':
             return POD::execute($sql);
         case 'count':
             return POD::queryCount($sql);
         case 'all':
             return POD::queryAll($sql);
         case 'query':
         default:
             return POD::query($sql);
     }
     return null;
 }
Example #11
0
        POD::execute($query);
    }
    $result = true;
    foreach ($plugintables as $dbname) {
        $query = "DROP TABLE {$dbname}";
        $result = POD::execute($query) && $result;
    }
    deactivatePlugin($pluginname);
    if ($result == false) {
        Respond::ResultPage(1);
        exit;
    }
} else {
    // type 2, table
    $dbname = $_REQUEST['name'];
    if (strncmp($dbname, $database['prefix'], strlen($database['prefix'])) != 0) {
        Respond::ResultPage(1);
        exit;
    }
    if (in_array($dbname, $definedTables)) {
        Respond::ResultPage(1);
        exit;
    }
    if (!doesExistTable($dbname)) {
        Respond::ResultPage(1);
        exit;
    }
    $query = "DROP TABLE {$dbname}";
    POD::execute($query);
}
Respond::ResultPage(0);
 function add()
 {
     global $database;
     if (!isset($this->id)) {
         $this->id = $this->nextId();
     } else {
         $this->id = $this->nextId($this->id);
     }
     if (!isset($this->entry)) {
         return $this->_error('entry');
     }
     if (!isset($this->commenter) && !isset($this->name)) {
         return $this->_error('commenter');
     }
     if (!isset($this->content)) {
         return $this->_error('content');
     }
     if (!isset($this->ip)) {
         $this->ip = $_SERVER['REMOTE_ADDR'];
     }
     if (!isset($this->isfiltered)) {
         $this->isfiltered = 0;
     }
     // legacy
     if (isset($this->commenter)) {
         $this->replier = $this->commenter;
         /*unset($this->commenter);*/
     }
     if (!($query = $this->_buildQuery())) {
         return false;
     }
     if (!$query->hasAttribute('written')) {
         $query->setAttribute('written', Timestamp::getUNIXtime());
     }
     if (!$query->insert()) {
         return $this->_error('insert');
     }
     if (isset($this->parent)) {
         $this->entry = Comment::getEntry($this->parent);
     }
     if (isset($this->entry) && $this->isfiltered == 0) {
         POD::execute("UPDATE {$database['prefix']}Entries SET comments = comments + 1 WHERE blogid = " . getBlogId() . " AND id = {$this->entry}");
     }
     return true;
 }
Example #13
0
function getDeleteAttachment($filename)
{
    global $database, $serviceURL;
    $tmpImage = POD::queryCell("SELECT image FROM {$database['prefix']}TeamUserSettings WHERE blogid=" . getBlogId() . " and userid=" . getUserId());
    if ($tmpImage) {
        POD::execute("UPDATE {$database['prefix']}TeamUserSettings SET image='', updated=UNIX_TIMESTAMP() WHERE blogid=" . getBlogId() . " and userid=" . getUserId());
        @unlink(__TEXTCUBE_ATTACH_DIR__ . "/" . getBlogId() . "/team/" . $tmpImage);
    }
    $result = "{$serviceURL}/resources/image/spacer.gif";
    return $result;
}
Example #14
0
function removeBlog($blogid)
{
    global $database;
    if (getServiceSetting("defaultBlogId", 1) == $blogid) {
        return false;
    }
    $tags = POD::queryColumn("SELECT DISTINCT tag FROM {$database['prefix']}TagRelations WHERE blogid = {$blogid}");
    $feeds = POD::queryColumn("SELECT DISTINCT feeds FROM {$database['prefix']}FeedGroupRelations WHERE blogid = {$blogid}");
    //Clear Tables
    POD::execute("DELETE FROM {$database['prefix']}Attachments WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}BlogSettings WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}BlogStatistics WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}Categories WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}Comments WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}CommentsNotified WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}CommentsNotifiedQueue WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}DailyStatistics WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}Entries WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}EntriesArchive WHERE blogid = {$blogid}");
    //	POD::execute("DELETE FROM {$database['prefix']}FeedGroupRelations WHERE blogid = $blogid");
    POD::execute("DELETE FROM {$database['prefix']}FeedGroups WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}FeedReads WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}FeedStarred WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}FeedSettings WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}Filters WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}Links WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}LinkCategories WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}PageCacheLog WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}Plugins WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}RefererLogs WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}RefererStatistics WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}RemoteResponses WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}RemoteResponseLogs WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}SkinSettings WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}TagRelations WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}Privileges WHERE blogid = {$blogid}");
    POD::execute("DELETE FROM {$database['prefix']}XMLRPCPingSettings WHERE blogid = {$blogid}");
    //Delete Tags
    if (count($tags) > 0) {
        $tagliststr = implode(', ', $tags);
        // Tag id used at deleted blog.
        $nottargets = POD::queryColumn("SELECT DISTINCT tag FROM {$database['prefix']}TagRelations WHERE tag in ( {$tagliststr} )");
        // Tag id used at other blogs.
        if (count($nottargets) > 0) {
            $nottargetstr = implode(', ', $nottargets);
            POD::execute("DELETE FROM {$database['prefix']}Tags WHERE id IN ( {$tagliststr} ) AND id NOT IN ( {$nottargetstr} )");
        } else {
            POD::execute("DELETE FROM {$database['prefix']}Tags WHERE id IN ( {$tagliststr} ) ");
        }
    }
    //Delete Feeds
    if (count($feeds) > 0) {
        foreach ($feeds as $feedId) {
            deleteFeed($blogid, $feedId);
        }
    }
    //Clear Plugin Database
    // TODO : encapsulate with 'value'
    $query = "SELECT name, value FROM {$database['prefix']}ServiceSettings WHERE name like 'Database\\_%'";
    $plugintablesraw = POD::queryAll($query);
    foreach ($plugintablesraw as $table) {
        $dbname = $database['prefix'] . substr($table['name'], 9);
        POD::execute("DELETE FROM {$database['prefix']}{$dbname} WHERE blogid = {$blogid}");
    }
    //Clear RSS Cache
    if (file_exists(ROOT . "/cache/rss/{$blogid}.xml")) {
        unlink(ROOT . "/cache/rss/{$blogid}.xml");
    }
    //Delete Attachments
    Path::removeFiles(Path::combine(ROOT, 'attach', $blogid));
    return true;
}
Example #15
0
 public function create()
 {
     if (!isset($this->structure) || empty($this->structure) || !is_array($this->structure)) {
         return false;
     }
     /// TO DO : implementing create method by structure
     $this->_called = true;
     $sql = "CREATE TABLE " . $this->_getTableName() . " (" . CRLF;
     $keys = array();
     foreach ($this->structure as $field => $attributes) {
         $type = $length = $isNull = $default = "";
         foreach ($attributes as $attr => $value) {
             if ($attr == "type") {
                 // Type casting
                 $type = POD::fieldType($value);
             }
             if ($attr == "isNull") {
                 $isNull = $value;
             }
             if ($attr == "default") {
                 $default = $value;
             }
             if ($attr == "length") {
                 $length = intval($value);
             }
             if ($attr == "autoincrement") {
                 $ai = $value;
             }
             if ($attr == "index" && $value == true) {
                 array_push($keys, $field);
             }
         }
         $sql .= $field;
         $sql .= ' ' . $type . (!empty($length) ? "(" . $length . ")" : "") . ' ' . ($default ? 'DEFAULT ' . (in_array($type, array("integer", "timestamp", "float")) ? $default : '"' . POD::escapeString($default) . '"') : "") . ' ' . ($isNull ? "NULL" : "NOT NULL") . (isset($ai) && $ai == true ? ' AUTO INCREMENT' : '') . ',';
     }
     $sql = rtrim($sql, ",");
     if (is_array($this->option) && array_key_exists('primary', $this->option)) {
         $sql .= ', PRIMARY KEY (' . implode(',', $this->option['primary']) . ')';
     }
     foreach ($keys as $key) {
         $sql .= ', KEY (' . POD::escapeString($key) . ')';
     }
     $sql .= ")";
     $result = POD::execute($sql);
     $this->_manage_pool_stack();
     return $result;
 }
Example #16
0
function emptyTrash($comment = true)
{
    global $database;
    requireModel('common.setting');
    $blogid = getBlogId();
    if ($comment == true) {
        POD::execute("DELETE FROM {$database['prefix']}Comments where blogid = " . $blogid . " and isfiltered > 0");
    } else {
        POD::execute("DELETE FROM {$database['prefix']}RemoteResponses where blogid = " . $blogid . " and isfiltered > 0");
    }
}
Example #17
0
function defensio_clear_comments($comment_TYPE, $IDs = array())
{
    global $database;
    $table = $comment_TYPE == 'C' ? "Comments" : "Trackbacks";
    $blogid = getBlogId();
    $sql = "SELECT D.* from {$database['prefix']}{$table} C RIGHT OUTER JOIN {$database['prefix']}defensio D\n\t\tON C.blogid = D.blog_ID and C.id = D.comment_ID WHERE D.blog_ID = '{$blogid}' and D.comment_TYPE = '{$comment_TYPE}' and C.id IS NULL";
    $r = POD::queryAll($sql);
    if (is_array($r) && count($r) > 0) {
        foreach ($r as $c) {
            $a[] = $c['comment_ID'];
        }
        $string_id = implode(',', $a);
        $sql = "DELETE FROM {$database['prefix']}defensio WHERE blog_ID = '{$blogid}' and comment_TYPE = '{$comment_TYPE}' and comment_ID in ({$string_id})";
        POD::execute($sql);
    }
    /*
    	// remove old comments from defensio table for better performance.
    	$olds = defensio_get_all_comments_id( $comment_TYPE, strtotime('-3 month'));
    	if ( count($olds) > 0 ) $IDs = array_unique(array_merge($IDs, $olds));
    */
    if (is_array($IDs) && count($IDs) > 0) {
        $string_id = implode(',', $IDs);
        $sql = "DELETE FROM {$database['prefix']}defensio WHERE blog_ID = '{$blogid}' and comment_TYPE = '{$comment_TYPE}' and comment_ID in ({$string_id})";
        POD::execute($sql);
    }
}
Example #18
0
function deleteCategory($blogid, $id)
{
    global $database;
    if (!is_numeric($id)) {
        return false;
    }
    CacheControl::flushCategory($id);
    POD::execute("DELETE FROM {$database['prefix']}Categories WHERE blogid = {$blogid} AND id = {$id}");
    updateEntriesOfCategory($blogid);
    return true;
}
Example #19
0
function changeAuthorOfEntries($blogid, $entries, $userid)
{
    global $database;
    requireModel("blog.feed");
    $targets = array_unique(preg_split('/,/', $entries, -1, PREG_SPLIT_NO_EMPTY));
    foreach ($targets as $entryId) {
        POD::execute("UPDATE {$database['prefix']}Entries SET userid = {$userid} WHERE blogid = {$blogid} AND id = {$entryId}");
    }
    clearFeed();
    CacheControl::flushAuthor();
    return true;
}
Example #20
0
 function authenticate($blogid, $loginid, $password, $blogapi = false)
 {
     global $database;
     $session = array();
     Acl::clearAcl();
     $loginid = POD::escapeString($loginid);
     $blogApiPassword = Setting::getBlogSettingGlobal("blogApiPassword", "");
     if (strlen($password) == 32 && preg_match('/[0-9a-f]{32}/i', $password)) {
         // Raw login. ( with/without auth token)
         $userid = User::getUserIdByEmail($loginid);
         if (!empty($userid) && !is_null($userid)) {
             $query = DBModel::getInstance();
             $query->reset('UserSettings');
             $query->setQualifier('userid', 'equals', intval($userid));
             $query->setQualifier('name', 'equals', 'AuthToken', true);
             $authtoken = $query->getCell('value');
             if (!empty($authtoken) && $authtoken === $password) {
                 // If user requested auth token, use it to confirm.
                 $session['userid'] = $userid;
             } else {
                 // login with md5 hash
                 $secret = 'password = \'' . md5($password) . '\'';
             }
         } else {
             return false;
         }
     } else {
         if ($blogapi && !empty($blogApiPassword)) {
             // BlogAPI login
             $password = POD::escapeString($password);
             $secret = '(password = \'' . md5($password) . '\' OR \'' . $password . '\' = \'' . $blogApiPassword . '\')';
         } else {
             // Normal login
             $secret = 'password = \'' . md5($password) . '\'';
         }
     }
     if (empty($session)) {
         $session = POD::queryRow("SELECT userid, loginid, name FROM {$database['prefix']}Users WHERE loginid = '{$loginid}' AND {$secret}");
     }
     if (empty($session)) {
         /* You should compare return value with '=== false' which checks with variable types*/
         return false;
     }
     $userid = $session['userid'];
     Acl::authorize('textcube', $userid);
     POD::execute("UPDATE {$database['prefix']}Users SET lastlogin = "******" WHERE loginid = '{$loginid}'");
     //		POD::execute("DELETE FROM {$database['prefix']}UserSettings WHERE userid = '$userid' AND name = 'AuthToken' LIMIT 1");
     return $userid;
 }
function revertRemoteResponse($blogid, $id)
{
    global $database;
    requireModel('blog.entry');
    if (!is_numeric($id)) {
        return null;
    }
    $entry = POD::queryCell("SELECT entry FROM {$database['prefix']}RemoteResponses WHERE blogid = {$blogid} AND id = {$id}");
    if ($entry === null) {
        return false;
    }
    if (!POD::execute("UPDATE {$database['prefix']}RemoteResponses SET isfiltered = 0 WHERE blogid = {$blogid} AND id = {$id}")) {
        return false;
    }
    CacheControl::flushDBCache('trackback');
    CacheControl::flushDBCache('remoteResponse');
    if (updateRemoteResponsesOfEntry($blogid, $entry)) {
        return $entry;
    }
    return false;
}
Example #22
0
function deleteTagById($blogid, $id)
{
    global $database;
    /// delete relation
    $result = POD::execute('DELETE FROM ' . $database['prefix'] . 'TagRelations WHERE blogid = ' . $blogid . ' AND tag = ' . $id);
    if (!$result) {
        return false;
    }
    $count = POD::queryCell('SELECT COUNT(*) FROM ' . $database['prefix'] . 'TagRelations WHERE tag = ' . $id);
    if (intval($count) == 0) {
        POD::execute('DELETE FROM ' . $database['prefix'] . 'Tags WHERE id = ' . $id);
    }
    return true;
}
Example #23
0
 function changeACLofUser($blogid, $userid, $ACLtype, $switch)
 {
     // Change user priviledge on the blog.
     global $database;
     if (empty($ACLtype) || empty($userid)) {
         return false;
     }
     $acl = POD::queryCell("SELECT acl\n\t\t\t\tFROM {$database['prefix']}Privileges\n\t\t\t\tWHERE blogid={$blogid} and userid={$userid}");
     if ($acl === null) {
         // If there is no ACL, add user into the blog.
         $name = User::getName($userid);
         POD::query("INSERT INTO {$database['prefix']}Privileges\n\t\t\t\t\tVALUES({$blogid}, {$userid}, 0, UNIX_TIMESTAMP(), 0)");
         $acl = 0;
     }
     $bitwise = null;
     switch ($ACLtype) {
         case 'admin':
             $bitwise = BITWISE_ADMINISTRATOR;
             break;
         case 'editor':
             $bitwise = BITWISE_EDITOR;
             break;
         default:
             return false;
     }
     if ($switch) {
         $acl |= $bitwise;
     } else {
         $acl &= ~$bitwise;
     }
     return POD::execute("UPDATE {$database['prefix']}Privileges\n\t\t\tSET acl = " . $acl . "\n\t\t\tWHERE blogid = " . $blogid . " and userid = " . $userid);
 }
Example #24
0
function receiveNotifiedComment($post)
{
    if (empty($post['mode']) || $post['mode'] != 'fb') {
        return 1;
    }
    global $database;
    CacheControl::flushCommentNotifyRSS();
    $post = fireEvent('ReceiveNotifiedComment', $post);
    if ($post === false) {
        return 7;
    }
    $blogid = getBlogId();
    $title = POD::escapeString(UTF8::lessenAsEncoding($post['s_home_title'], 255));
    $name = POD::escapeString(UTF8::lessenAsEncoding($post['s_name'], 255));
    $entryId = POD::escapeString($post['s_no']);
    $homepage = POD::escapeString(UTF8::lessenAsEncoding($post['url'], 255));
    $entryurl = POD::escapeString($post['s_url']);
    $entrytitle = POD::escapeString($post['s_post_title']);
    $parent_id = $post['r1_no'];
    $parent_name = POD::escapeString(UTF8::lessenAsEncoding($post['r1_name'], 80));
    $parent_parent = $post['r1_rno'];
    $parent_homepage = POD::escapeString(UTF8::lessenAsEncoding($post['r1_homepage'], 80));
    $parent_written = $post['r1_regdate'];
    $parent_comment = POD::escapeString($post['r1_body']);
    $parent_url = POD::escapeString(UTF8::lessenAsEncoding($post['r1_url'], 255));
    $child_id = $post['r2_no'];
    $child_name = POD::escapeString(UTF8::lessenAsEncoding($post['r2_name'], 80));
    $child_parent = $post['r2_rno'];
    $child_homepage = POD::escapeString(UTF8::lessenAsEncoding($post['r2_homepage'], 80));
    $child_written = $post['r2_regdate'];
    $child_comment = POD::escapeString($post['r2_body']);
    $child_url = POD::escapeString(UTF8::lessenAsEncoding($post['r2_url'], 255));
    $siteid = POD::queryCell("SELECT id FROM {$database['prefix']}CommentsNotifiedSiteInfo WHERE url = '{$homepage}'");
    if (empty($siteid)) {
        $insertId = getCommentsNotifiedSiteInfoMaxId() + 1;
        if (POD::execute("INSERT INTO {$database['prefix']}CommentsNotifiedSiteInfo\n\t\t\t( id, title, name, url, modified)\n\t\t\tVALUES ({$insertId}, '{$title}', '{$name}', '{$homepage}', UNIX_TIMESTAMP());")) {
            $siteid = $insertId;
        } else {
            return 2;
        }
    }
    $parentId = POD::queryCell("SELECT id\n\t\tFROM {$database['prefix']}CommentsNotified\n\t\tWHERE entry = {$entryId}\n\t\t\tAND siteid = {$siteid}\n\t\t\tAND blogid = {$blogid}\n\t\t\tAND remoteid = {$parent_id}");
    if (empty($parentId)) {
        $insertId = getCommentsNotifiedMaxId() + 1;
        $sql = "INSERT INTO {$database['prefix']}CommentsNotified\n\t\t\t( blogid , replier , id , entry , parent , name , password , homepage , secret , comment , ip , written, modified , siteid , isnew , url , remoteid ,entrytitle , entryurl )\n\t\t\tVALUES (\n\t\t\t\t{$blogid}, NULL , {$insertId}, " . $entryId . ", " . (empty($parent_parent) ? 'null' : $parent_parent) . ", '" . $parent_name . "', '', '" . $parent_homepage . "', '', '" . $parent_comment . "', '', " . $parent_written . ",UNIX_TIMESTAMP(), " . $siteid . ", 1, '" . $parent_url . "'," . $parent_id . ", '" . $entrytitle . "', '" . $entryurl . "'\n)";
        if (!POD::execute($sql)) {
            return 3;
        }
        $parentId = $insertId;
    }
    if (POD::queryCell("SELECT count(*) FROM {$database['prefix']}CommentsNotified WHERE siteid={$siteid} AND remoteid={$child_id}") > 0) {
        return 4;
    }
    $insertId = getCommentsNotifiedMaxId() + 1;
    $sql = "INSERT INTO {$database['prefix']}CommentsNotified\n\t\t( blogid , replier , id , entry , parent , name , password , homepage , secret , comment , ip , written, modified , siteid , isnew , url , remoteid ,entrytitle , entryurl )\n\t\tVALUES (\n\t\t\t{$blogid}, NULL , {$insertId}, " . $entryId . ", {$parentId}, '{$child_name}', '', '{$child_homepage}', '', '{$child_comment}', '', {$child_written}, UNIX_TIMESTAMP(), {$siteid}, 1, '{$child_url}', {$child_id}, '{$entrytitle}', '{$entryurl}')";
    if (!POD::execute($sql)) {
        return 5;
    }
    $sql = "UPDATE {$database['prefix']}CommentsNotified SET modified = UNIX_TIMESTAMP() WHERE blogid = {$blogid} AND id = {$parentId}";
    if (!POD::execute($sql)) {
        return 6;
    }
    return 0;
}
Example #25
0
function GoogleMap_Cache()
{
    $ctx = Model_Context::getInstance();
    $dbPrefix = $ctx->getProperty('database.prefix');
    $blogId = $ctx->getProperty('blog.id');
    $IV = array('POST' => array('original_path' => array('string', 'default' => ''), 'path' => array('string', 'default' => ''), 'lat' => array('number', 'default' => null), 'lng' => array('number', 'default' => null)));
    Validator::validate($IV);
    if (empty($_POST['path']) || empty($_POST['original_path'])) {
        echo 'error: empty path';
        return;
    }
    $original_path_e = POD::escapeString($_POST['original_path']);
    $path_e = POD::escapeString($_POST['path']);
    $row = POD::queryRow("SELECT * FROM {$dbPrefix}GMapLocations WHERE blogid = {$blogId} AND original_address = '{$original_path_e}'");
    if ($row == null || empty($row)) {
        if (POD::execute("INSERT INTO {$dbPrefix}GMapLocations VALUES ({$blogId}, '{$original_path_e}', '{$path_e}', {$_POST['lng']}, {$_POST['lat']}, " . time() . ")")) {
            echo 'ok';
        } else {
            echo 'error: cache failed';
        }
    } else {
        echo 'duplicate';
    }
}
Example #26
0
function deleteLinkCategory($blogid, $id)
{
    global $database;
    if (POD::query("DELETE FROM {$database['prefix']}LinkCategories\n\t\tWHERE blogid = {$blogid} AND id = {$id}")) {
        POD::execute("UPDATE {$database['prefix']}Links\n\t\t\tSET category = 0\n\t\t\tWHERE blogid = {$blogid} AND category = {$id}");
        return true;
    } else {
        return false;
    }
}
Example #27
0
 public function create()
 {
     if (!isset($this->structure) || empty($this->structure) || !is_array($this->structure)) {
         return false;
     }
     /// TO DO : implementing create method by structure
     $sql = "CREATE " . $this->table . " (" . CRLF;
     foreach ($this->structure as $field => $attributes) {
         $sql .= $field;
         $type = $length = $isNull = $default = "";
         foreach ($attributes as $attr => $value) {
             if ($attr == "type") {
                 // Type casting
                 $type = POD::fieldType($type);
             }
             if ($attr == "isNull") {
                 $isNull = $value;
             }
             if ($attr == "default") {
                 $default = $value;
             }
         }
         $sql .= ' ' . $type . (!empty($length) ? "(" . $length . ")" : "") . ' ' . ($default ? 'DEFAULT ' . (in_array($type, array("integer", "timestamp", "float")) ? $default : '"' . $default . '"') : "") . ' ' . ($isNull ? "NULL" : "NOT NULL") . CRLF;
     }
     $sql .= ")";
     return POD::execute($sql);
 }
Example #28
0
function updateFeed($feedRow)
{
    global $database;
    if ($feedRow['modified'] > gmmktime() - 300) {
        return true;
    }
    list($status, $feed, $xml) = getRemoteFeed($feedRow['xmlurl']);
    if ($status > 0) {
        POD::execute("UPDATE {$database['prefix']}Feeds SET modified = 0 WHERE xmlurl = '{$feedRow['xmlurl']}'");
        return $status;
    } else {
        POD::execute("UPDATE {$database['prefix']}Feeds SET blogURL = '{$feed['blogURL']}', title = '{$feed['title']}', description = '{$feed['description']}', language = '{$feed['language']}', modified = " . gmmktime() . " WHERE xmlurl = '{$feedRow['xmlurl']}'");
        return saveFeedItems($feedRow['id'], $xml) ? 0 : 1;
    }
}
 static function setTotalStatistics($blogid)
 {
     global $database;
     POD::execute("DELETE FROM {$database['prefix']}DailyStatistics WHERE blogid = {$blogid}");
     $prevCount = POD::queryCell("SELECT visits FROM {$database['prefix']}BlogStatistics WHERE blogid = {$blogid}");
     if (!is_null($prevCount) && $prevCount == 0) {
         return true;
     }
     if (POD::execute("UPDATE {$database['prefix']}BlogStatistics SET visits = 0 WHERE blogid = {$blogid}")) {
         return true;
     } else {
         $result = POD::execute("INSERT INTO {$database['prefix']}BlogStatistics values({$blogid}, 0)");
         return $result;
     }
 }
Example #30
0
function notifyComment()
{
    $ctx = Model_Context::getInstance();
    $blogid = getBlogId();
    $sql = "SELECT\n\t\t\t\tCN.*,\n\t\t\t\tCNQ.id AS queueId,\n\t\t\t\tCNQ.commentid AS commentid,\n\t\t\t\tCNQ.sendstatus AS sendstatus,\n\t\t\t\tCNQ.checkdate AS checkdate,\n\t\t\t\tCNQ.written  AS queueWritten\n\t\t\tFROM\n\t\t\t\t" . $ctx->getProperty('database.prefix') . "CommentsNotifiedQueue AS CNQ\n\t\t\tLEFT JOIN\n\t\t\t\t" . $ctx->getProperty('database.prefix') . "Comments AS CN ON CNQ.commentid = CN.id\n\t\t\tWHERE\n\t\t\t\tCNQ.sendstatus = 0\n\t\t\t\tand CN.parent is not null\n\t\t\tORDER BY CNQ.id ASC LIMIT 1 OFFSET 0";
    $queue = POD::queryRow($sql);
    if (empty($queue) && empty($queue['queueId'])) {
        return false;
    }
    $comments = POD::queryRow("SELECT * FROM " . $ctx->getProperty('database.prefix') . "Comments WHERE blogid = {$blogid} AND id = {$queue['commentid']}");
    if (empty($comments['parent']) || $comments['secret'] == 1) {
        POD::execute("DELETE FROM " . $ctx->getProperty('database.prefix') . "CommentsNotifiedQueue WHERE id={$queue['queueId']}");
        return false;
    }
    $parentComments = POD::queryRow("SELECT * FROM " . $ctx->getProperty('database.prefix') . "Comments WHERE blogid = {$blogid} AND id = {$comments['parent']}");
    if (empty($parentComments['homepage'])) {
        POD::execute("DELETE FROM " . $ctx->getProperty('database.prefix') . "CommentsNotifiedQueue WHERE id={$queue['queueId']}");
        return false;
    }
    $entry = POD::queryRow("SELECT * FROM " . $ctx->getProperty('database.prefix') . "Entries WHERE blogid = {$blogid} AND id={$comments['entry']}");
    if (is_null($entry)) {
        $r1_comment_check_url = rawurlencode($ctx->getProperty('uri.default') . "/guestbook/" . $parentComments['id'] . "#guestbook" . $parentComments['id']);
        $r2_comment_check_url = rawurlencode($ctx->getProperty('uri.default') . "/guestbook/" . $comments['id'] . "#guestbook" . $comments['id']);
        $entry['title'] = _textf('%1 블로그의 방명록', $ctx->getProperty('blog.title'));
        $entryPermaLink = $ctx->getProperty('uri.default') . "/guestbook/";
        $entry['id'] = 0;
    } else {
        $r1_comment_check_url = rawurlencode($ctx->getProperty('uri.default') . "/" . ($ctx->getProperty('blog.useSloganOnPost') ? "entry/{$entry['slogan']}" : $entry['id']) . "#comment" . $parentComments['id']);
        $r2_comment_check_url = rawurlencode($ctx->getProperty('uri.default') . "/" . ($ctx->getProperty('blog.useSloganOnPost') ? "entry/{$entry['slogan']}" : $entry['id']) . "#comment" . $comments['id']);
        $entryPermaLink = $ctx->getProperty('uri.default') . "/" . ($ctx->getProperty('blog.useSloganOnPost') ? "entry/{$entry['slogan']}" : $entry['id']);
    }
    $data = "url=" . rawurlencode($ctx->getProperty('uri.default')) . "&mode=fb" . "&s_home_title=" . rawurlencode($ctx->getProperty('blog.title')) . "&s_post_title=" . rawurlencode($entry['title']) . "&s_name=" . rawurlencode($comments['name']) . "&s_no=" . rawurlencode($comments['entry']) . "&s_url=" . rawurlencode($entryPermaLink) . "&r1_name=" . rawurlencode($parentComments['name']) . "&r1_no=" . rawurlencode($parentComments['id']) . "&r1_pno=" . rawurlencode($comments['entry']) . "&r1_rno=0" . "&r1_homepage=" . rawurlencode($parentComments['homepage']) . "&r1_regdate=" . rawurlencode($parentComments['written']) . "&r1_url=" . $r1_comment_check_url . "&r2_name=" . rawurlencode($comments['name']) . "&r2_no=" . rawurlencode($comments['id']) . "&r2_pno=" . rawurlencode($comments['entry']) . "&r2_rno=" . rawurlencode($comments['parent']) . "&r2_homepage=" . rawurlencode($comments['homepage']) . "&r2_regdate=" . rawurlencode($comments['written']) . "&r2_url=" . $r2_comment_check_url . "&r1_body=" . rawurlencode($parentComments['comment']) . "&r2_body=" . rawurlencode($comments['comment']);
    if (strpos($parentComments['homepage'], "http://") === false) {
        $homepage = 'http://' . $parentComments['homepage'];
    } else {
        $homepage = $parentComments['homepage'];
    }
    $request = new HTTPRequest('POST', $homepage);
    $request->contentType = 'application/x-www-form-urlencoded; charset=utf-8';
    $request->content = $data;
    if ($request->send()) {
        $xmls = new XMLStruct();
        if ($xmls->open($request->responseText)) {
            $result = $xmls->selectNode('/response/error/');
            if ($result['.value'] != '1' && $result['.value'] != '0') {
                $homepage = rtrim($homepage, '/') . '/index.php';
                $request = new HTTPRequest('POST', $homepage);
                $request->contentType = 'application/x-www-form-urlencoded; charset=utf-8';
                $request->content = $data;
                if ($request->send()) {
                }
            }
        }
    }
    POD::execute("DELETE FROM " . $ctx->getProperty('database.prefix') . "CommentsNotifiedQueue WHERE id={$queue['queueId']}");
}