function _buildQuery()
 {
     $query = DBModel::getInstance();
     $query->reset('ServiceSettings');
     $query->setQualifier('name', 'equals', Utils_Unicode::lessenAsEncoding($this->name, 32), false);
     if (isset($this->value)) {
         $query->setAttribute('value', Utils_Unicode::lessenAsEncoding($this->value, 255), true);
     }
     return $query;
 }
Esempio n. 2
0
function updateLink($blogid, $link)
{
    $id = $link['id'];
    $name = Utils_Unicode::lessenAsEncoding(trim($link['name']), 255);
    $url = Utils_Unicode::lessenAsEncoding(trim($link['url']), 255);
    if (empty($name) || empty($url)) {
        return false;
    }
    $category = isset($link['category']) ? $link['category'] : 0;
    if (isset($link['newCategory']) && !empty($link['newCategory'])) {
        // Add new category information
        $newCategoryTitle = Utils_Unicode::lessenAsEncoding(trim($link['newCategory']), 255);
        $newCategoryId = addLinkCategory($blogid, $newCategoryTitle);
        if (!empty($newCategoryId)) {
            $category = $newCategoryId;
        }
    }
    $rss = isset($link['rss']) ? Utils_Unicode::lessenAsEncoding(trim($link['rss']), 255) : '';
    $pool = DBModel::getInstance();
    $pool->init("Links");
    $pool->setAttribute("category", $category);
    $pool->setAttribute("name", $name, true);
    $pool->setAttribute("url", $url, true);
    $pool->setAttribute("rss", $rss, true);
    $pool->setAttribute("written", Timestamp::getUNIXtime());
    $pool->setQualifier("blogid", "eq", $blogid);
    $pool->setQualifier("id", "eq", $link['id']);
    $result = $pool->update();
    // Garbage correction
    $pool->init("Links");
    $pool->setQualifier("blogid", "eq", $blogid);
    $existCategories = $pool->getColumn("category", array("filter" => "distinct"));
    $pool->init("LinkCategories");
    $pool->setQualifier("blogid", "eq", $blogid);
    $pool->setQualifier("id", "hasnoneof", $existCategories);
    $pool->delete();
    return $result;
}
 function _buildQuery()
 {
     global $database;
     $query = DBModel::getInstance();
     $query->reset('Comments');
     $query->setQualifier('blogid', 'equals', getBlogId());
     $query->setQualifier('entry', 'equals', 0);
     if (isset($this->id)) {
         if (!Validator::number($this->id, 1)) {
             return $this->_error('id');
         }
         $query->setQualifier('id', 'equals', $this->id);
     }
     if (isset($this->parent)) {
         if (!Validator::number($this->parent, 1)) {
             return $this->_error('parent');
         }
     }
     $query->setAttribute('parent', $this->parent);
     if (isset($this->commenter)) {
         if (!Validator::number($this->commenter, 1)) {
             return $this->_error('commenter');
         }
         if (!($this->name = User::getName($this->commenter))) {
             return $this->_error('commenter');
         }
         $query->setAttribute('replier', $this->commenter);
     }
     if (isset($this->name)) {
         $this->name = Utils_Unicode::lessenAsEncoding(trim($this->name), 80);
         if (empty($this->name)) {
             return $this->_error('name');
         }
         $query->setAttribute('name', $this->name, true);
     }
     if (isset($this->openid)) {
         $this->openid = Utils_Unicode::lessenAsEncoding(trim($this->openid), 128);
         if (empty($this->openid)) {
             return $this->_error('openid');
         }
         $query->setAttribute('openid', $this->openid, true);
     }
     if (isset($this->homepage)) {
         $this->homepage = Utils_Unicode::lessenAsEncoding(trim($this->homepage), 80);
         if (empty($this->homepage)) {
             return $this->_error('homepage');
         }
         $query->setAttribute('homepage', $this->homepage, true);
     }
     if (isset($this->ip)) {
         if (!Validator::ip($this->ip)) {
             return $this->_error('ip');
         }
         $query->setAttribute('ip', $this->ip, true);
     }
     if (isset($this->secret)) {
         $query->setAttribute('secret', Validator::getBit($this->secret));
     }
     if (isset($this->content)) {
         $this->content = trim($this->content);
         if (empty($this->content)) {
             return $this->_error('content');
         }
         $query->setAttribute('comment', $this->content, true);
     }
     if (isset($this->written)) {
         if (!Validator::timestamp($this->written)) {
             return $this->_error('written');
         }
         $query->setAttribute('written', $this->written);
     }
     if (isset($this->isfiltered)) {
         $query->setAttribute('isfiltered', Validator::getBit($this->isfiltered));
     }
     if (isset($this->password)) {
         $this->password = Utils_Unicode::lessenAsEncoding($this->password, 32);
         $query->setAttribute('password', $this->password, true);
         $this->password = null;
     }
     return $query;
 }
Esempio n. 4
0
 static function add($email, $name)
 {
     global $database, $service, $user, $blog;
     if (empty($email)) {
         return 1;
     }
     if (!preg_match('/^[^@]+@([-a-zA-Z0-9]+\\.)+[-a-zA-Z0-9]+$/', $email)) {
         return 2;
     }
     if (strcmp($email, Utils_Unicode::lessenAsEncoding($email, 64)) != 0) {
         return 11;
     }
     $loginid = POD::escapeString(Utils_Unicode::lessenAsEncoding($email, 64));
     $name = POD::escapeString(Utils_Unicode::lessenAsEncoding($name, 32));
     $password = User::__generatePassword();
     $authtoken = md5(User::__generatePassword());
     if (POD::queryExistence("SELECT * FROM {$database['prefix']}Users WHERE loginid = '{$loginid}'")) {
         return 9;
         // User already exists.
     }
     if (POD::queryCell("SELECT COUNT(*) FROM {$database['prefix']}Users WHERE name = '{$name}'")) {
         $name = $name . '.' . time();
     }
     $result = POD::query("INSERT INTO {$database['prefix']}Users (userid, loginid, password, name, created, lastlogin, host) VALUES (" . (User::__getMaxUserId() + 1) . ", '{$loginid}', '" . md5($password) . "', '{$name}', UNIX_TIMESTAMP(), 0, " . getUserId() . ")");
     if (empty($result)) {
         return 11;
     }
     $result = POD::query("INSERT INTO {$database['prefix']}UserSettings (userid, name, value) VALUES ('" . User::getUserIdByEmail($loginid) . "', 'AuthToken', '{$authtoken}')");
     if (empty($result)) {
         return 11;
     }
     return true;
 }
 function _buildQuery()
 {
     $query = DBModel::getInstance();
     $query->reset('RemoteResponses');
     $query->setQualifier('blogid', getBlogId());
     $query->setQualifier('responsetype', 'pingback');
     if (isset($this->id)) {
         if (!Validator::number($this->id, 1)) {
             return $this->_error('id');
         }
         $query->setQualifier('id', $this->id);
     }
     if (isset($this->entry)) {
         if (!Validator::number($this->entry, 1)) {
             return $this->_error('entry');
         }
         $query->setQualifier('entry', $this->entry);
     }
     if (isset($this->url)) {
         $this->url = Utils_Unicode::lessenAsEncoding(trim($this->url), 255);
         if (empty($this->url)) {
             return $this->_error('url');
         }
         $query->setQualifier('url', $this->url, true);
     }
     if (isset($this->ip)) {
         if (!Validator::ip($this->ip)) {
             return $this->_error('ip');
         }
         $query->setAttribute('ip', $this->ip, true);
     }
     if (isset($this->received)) {
         if (!Validator::timestamp($this->received)) {
             return $this->_error('received');
         }
         $query->setAttribute('written', $this->received);
     }
     if (isset($this->isFiltered)) {
         if ($this->isFiltered) {
             $query->setAttribute('isFiltered', 'UNIX_TIMESTAMP()');
         } else {
             $query->setAttribute('isFiltered', Validator::getBit($this->isFiltered));
         }
     }
     return $query;
 }
Esempio n. 6
0
 function add()
 {
     global $database;
     $this->id = null;
     $this->link = Utils_Unicode::lessenAsEncoding(trim($this->link), 255);
     if (empty($this->link)) {
         return false;
     }
     if (isset($this->group)) {
         if (is_numeric($this->group) && $this->group > 0) {
             FeedGroup::getName($this->group);
         }
     }
     if (!is_numeric($this->feed)) {
         return false;
     }
     if (!is_numeric($this->published)) {
         return false;
     }
     $query = DBModel::getInstance();
     $query->reset('FeedItems');
     $query->setQualifier('feed', 'equals', $this->feed);
     $query->setQualifier('permalink', 'equals', $this->link, true);
     $this->id = $query->getCell('id');
     if (is_null($this->id)) {
         $query->setAttribute('id', $this->_getMaxId() + 1);
         $query->setAttribute('title', Utils_Unicode::lessenAsEncoding($this->title, 255), true);
         $query->setAttribute('description', $this->description, true);
         $query->setAttribute('tags', Utils_Unicode::lessenAsEncoding($this->tags, 255), true);
         $query->setAttribute('enclosure', Utils_Unicode::lessenAsEncoding($this->enclosure, 255), true);
         $query->setAttribute('author', Utils_Unicode::lessenAsEncoding($this->author, 255), true);
         $query->setAttribute('written', $this->published);
         $this->id = $query->insert();
         //echo mysql_error(), '<br />';
         if ($this->id === false) {
             return false;
         }
     }
     return true;
 }
 function _buildQuery()
 {
     $query = DBModel::getInstance();
     $query->reset('Users');
     $query->setQualifier('userid', getUserId());
     if (isset($this->userid)) {
         if (!Validator::number($this->userid, 1)) {
             return $this->_error('userid');
         }
         $query->setQualifier('userid', $this->userid);
     }
     if (isset($this->loginid)) {
         $this->loginid = Utils_Unicode::lessenAsEncoding(trim($this->loginid), 64);
         if (empty($this->loginid)) {
             return $this->_error('loginid');
         }
         $query->setAttribute('loginid', $this->loginid, true);
     }
     if (isset($this->password)) {
         $this->password = trim($this->password);
         if (empty($this->password)) {
             return $this->_error('password');
         }
         $query->setAttribute('password', $this->password, true);
     }
     if (isset($this->name)) {
         $this->name = Utils_Unicode::lessenAsEncoding(trim($this->name), 32);
         if (empty($this->name)) {
             return $this->_error('name');
         }
         $query->setAttribute('name', $this->name, true);
     }
     if (isset($this->created)) {
         if (!Validator::number($this->created, 0)) {
             return $this->_error('created');
         }
         $query->setAttribute('created', $this->created);
     }
     if (isset($this->lastLogin)) {
         if (!Validator::number($this->lastLogin, 1)) {
             return $this->_error('lastLogin');
         }
         $query->setAttribute('lastLogin', $this->lastLogin);
     }
     if (isset($this->host)) {
         if (!Validator::number($this->host, 0)) {
             return $this->_error('host');
         }
         $query->setAttribute('host', $this->host);
     }
     return $query;
 }
 function add()
 {
     if ($this->id != 0) {
         $this->id = null;
     }
     if (isset($this->parent) && !is_numeric($this->parent)) {
         return $this->_error('parent');
     }
     $this->name = Utils_Unicode::lessenAsEncoding(trim($this->name), 127);
     if (empty($this->name)) {
         return $this->_error('name');
     }
     $query = DBModel::getInstance();
     $query->reset('Categories');
     $query->setQualifier('blogid', 'equals', getBlogId());
     if (isset($this->parent)) {
         if (is_null($parentLabel = Category::getLabel($this->parent))) {
             return $this->_error('parent');
         }
         $query->setQualifier('parent', 'equals', $this->parent);
         $query->setAttribute('label', Utils_Unicode::lessenAsEncoding($parentLabel . '/' . $this->name, 255), true);
     } else {
         $query->setQualifier('parent', null);
         $query->setAttribute('label', $this->name, true);
     }
     $query->setQualifier('name', 'equals', $this->name, true);
     if (isset($this->priority)) {
         if (!is_numeric($this->priority)) {
             return $this->_error('priority');
         }
         $query->setAttribute('priority', $this->priority);
     }
     if ($query->doesExist()) {
         $this->id = $query->getCell('id');
         if ($query->update()) {
             return true;
         } else {
             return $this->_error('update');
         }
     }
     if (!isset($this->id)) {
         $this->id = $this->getNextCategoryId();
         $query->setQualifier('id', 'equals', $this->id);
     }
     if (!$query->insert()) {
         return $this->_error('insert');
     }
     return true;
 }
 function _buildQuery()
 {
     if (!Validator::directory($this->name)) {
         return $this->_error('name');
     }
     $query = DBModel::getInstance();
     $query->reset('Plugins');
     $query->setQualifier('blogid', 'equals', getBlogId());
     $query->setQualifier('name', 'equals', Utils_Unicode::lessenAsEncoding($this->name, 255), true);
     if (isset($this->setting)) {
         $query->setAttribute('settings', $this->setting, true);
     }
     return $query;
 }
Esempio n. 10
0
function sendTrackback($blogid, $entryId, $url)
{
    importlib('model.blog.entry');
    importlib('model.blog.keyword');
    $context = Model_Context::getInstance();
    $entry = getEntry($blogid, $entryId);
    if (is_null($entry)) {
        return false;
    }
    $link = $context->getProperty('uri.default') . "/" . $entryId;
    $title = htmlspecialchars($entry['title']);
    $entry['content'] = getEntryContentView($blogid, $entryId, $entry['content'], $entry['contentformatter'], getKeywordNames($blogid));
    $excerpt = str_tag_on(Utils_Unicode::lessen(removeAllTags(stripHTML($entry['content'])), 255));
    $blogTitle = $context->getProperty('blog.title');
    $isNeedConvert = strpos($url, '/rserver.php?') !== false || strpos($url, 'blog.naver.com/tb') !== false || strpos($url, 'news.naver.com/tb/') !== false || strpos($url, 'blog.empas.com') !== false || strpos($url, 'blog.yahoo.com') !== false || strpos($url, 'www.blogin.com/tb/') !== false || strpos($url, 'cytb.cyworld.nate.com') !== false || strpos($url, 'www.cine21.com/Movies/tb.php') !== false;
    if ($isNeedConvert) {
        $title = Utils_Unicode::convert($title, 'EUC-KR');
        $excerpt = Utils_Unicode::convert($excerpt, 'EUC-KR');
        $blogTitle = Utils_Unicode::convert($blogTitle, 'EUC-KR');
        $content = "url=" . rawurlencode($link) . "&title=" . rawurlencode($title) . "&blog_name=" . rawurlencode($blogTitle) . "&excerpt=" . rawurlencode($excerpt);
        $request = new HTTPRequest('POST', $url);
        $request->contentType = 'application/x-www-form-urlencoded; charset=euc-kr';
        $isSuccess = $request->send($content);
    } else {
        $content = "url=" . rawurlencode($link) . "&title=" . rawurlencode($title) . "&blog_name=" . rawurlencode($blogTitle) . "&excerpt=" . rawurlencode($excerpt);
        $request = new HTTPRequest('POST', $url);
        $request->contentType = 'application/x-www-form-urlencoded; charset=utf-8';
        $isSuccess = $request->send($content);
    }
    if ($isSuccess && checkResponseXML($request->responseText) === 0) {
        $trackbacklog = new TrackbackLog();
        $trackbacklog->entry = $entryId;
        $trackbacklog->url = Utils_Unicode::lessenAsEncoding($url, 255);
        $trackbacklog->add();
        return true;
    }
    return false;
}
Esempio n. 11
0
 static function add($email, $name)
 {
     $context = Model_Context::getInstance();
     $pool = DBModel::getInstance();
     if (empty($email)) {
         return 1;
     }
     if (!preg_match('/^[^@]+@([-a-zA-Z0-9]+\\.)+[-a-zA-Z0-9]+$/', $email)) {
         return 2;
     }
     if (strcmp($email, Utils_Unicode::lessenAsEncoding($email, 64)) != 0) {
         return 11;
     }
     $loginid = Utils_Unicode::lessenAsEncoding($email, 64);
     $name = Utils_Unicode::lessenAsEncoding($name, 32);
     $password = User::__generatePassword();
     $authtoken = md5(User::__generatePassword());
     $pool->reset("Users");
     $pool->setQualifier("loginid", "eq", $loginid, true);
     if ($pool->doesExist()) {
         return 9;
         // User already exists.
     }
     $pool->reset("Users");
     $pool->setQualifier("name", "eq", $name, true);
     if ($pool->getCount()) {
         $name = $name . '.' . time();
     }
     $pool->reset("Users");
     $pool->setAttribute("userid", User::__getMaxUserId() + 1);
     $pool->setAttribute("loginid", $loginid, true);
     $pool->setAttribute("password", md5($password), true);
     $pool->setAttribute("name", $name, true);
     $pool->setAttribute("created", Timestamp::getUNIXtime());
     $pool->setAttribute("lastlogin", 0);
     $pool->setAttribute("host", getUserId());
     $result = $pool->insert();
     if (empty($result)) {
         return 11;
     }
     $pool->reset("UserSettings");
     $pool->setAttribute("userid", User::getUserIdByEmail($loginid));
     $pool->setAttribute("name", 'AuthToken', true);
     $pool->setAttribute("value", $authtoken, true);
     $result = $pool->insert();
     if (empty($result)) {
         return 11;
     }
     return true;
 }
Esempio n. 12
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;
}
 function _buildQuery()
 {
     $query = DBModel::getInstance();
     $query->reset('CommentsNotifiedSiteInfo');
     if (isset($this->id)) {
         if (!Validator::number($this->id, 1)) {
             return $this->_error('id');
         }
         $query->setQualifier('id', 'equals', $this->id);
     }
     if (isset($this->title)) {
         $this->title = Utils_Unicode::lessenAsEncoding(trim($this->title), 255);
         $query->setAttribute('title', $this->title, true);
     }
     if (isset($this->name)) {
         $this->name = Utils_Unicode::lessenAsEncoding(trim($this->name), 255);
         $query->setAttribute('name', $this->name, true);
     }
     if (isset($this->url)) {
         $this->url = Utils_Unicode::lessenAsEncoding(trim($this->url), 255);
         if (empty($this->url)) {
             return $this->_error('url');
         }
         $query->setAttribute('url', $this->url, true);
     }
     if (isset($this->modified)) {
         if (!Validator::timestamp($this->modified)) {
             return $this->_error('modified');
         }
         $query->setAttribute('modified', $this->modified);
     }
     return $query;
 }
Esempio n. 14
0
 function _buildQuery()
 {
     global $database;
     $query = DBModel::getInstance();
     $query->reset('Links');
     $query->setQualifier('blogid', 'equals', getBlogId());
     if (isset($this->id)) {
         if (!Validator::number($this->id, 1)) {
             return $this->_error('id');
         }
         $query->setQualifier('id', 'equals', $this->id);
     }
     if (isset($this->pid)) {
         if (!Validator::number($this->pid, 1)) {
             return $this->_error('pid');
         }
         $query->setQualifier('pid', 'equals', $this->pid);
     }
     if (isset($this->category)) {
         if (intval($this->category) < 0) {
             return $this->_error('category');
         }
         $query->setQualifier('category', 'equals', $this->category);
     }
     if (isset($this->url)) {
         $this->url = Utils_Unicode::lessenAsEncoding(trim($this->url), 255);
         if (empty($this->url)) {
             return $this->_error('url');
         }
         $query->setQualifier('url', 'equals', $this->url, true);
     }
     if (isset($this->title)) {
         $this->title = Utils_Unicode::lessenAsEncoding(trim($this->title), 255);
         if (empty($this->title)) {
             return $this->_error('title');
         }
         $query->setAttribute('name', $this->title, true);
     }
     if (isset($this->feed)) {
         $this->feed = Utils_Unicode::lessenAsEncoding(trim($this->feed), 255);
         if (empty($this->feed)) {
             return $this->_error('feed');
         }
         $query->setAttribute('rss', $this->feed, true);
     }
     if (isset($this->registered)) {
         if (!Validator::number($this->registered, 1)) {
             return $this->_error('registered');
         }
         $query->setAttribute('written', $this->registered);
     }
     if (isset($this->xfn)) {
         $this->xfn = Utils_Unicode::lessenAsEncoding(trim($this->xfn), 255);
         if (empty($this->xfn)) {
             return $this->_error('xfn');
         }
         $query->setAttribute('xfn', $this->xfn, true);
     }
     $this->_count = 0;
     $this->reset();
     return $query;
 }
Esempio n. 15
0
 function _buildQuery()
 {
     global $database;
     $query = DBModel::getInstance();
     $query->reset('Comments');
     $query->setQualifier('blogid', 'equals', getBlogId());
     if (isset($this->id)) {
         if (!Validator::number($this->id, 1)) {
             return $this->_error('id');
         }
         $query->setQualifier('id', 'equals', $this->id);
     }
     if (isset($this->entry)) {
         if (!Validator::number($this->entry, 1)) {
             return $this->_error('entry');
         }
         $query->setAttribute('entry', $this->entry);
     }
     if (isset($this->parent)) {
         if (!Validator::number($this->parent, 1)) {
             return $this->_error('parent');
         }
     }
     $query->setAttribute('parent', $this->parent);
     if (isset($this->commenter)) {
         if (!Validator::number($this->commenter, 1)) {
             return $this->_error('commenter');
         }
         if (!isset($this->name)) {
             if (!($this->name = User::getName($this->commenter))) {
                 return $this->_error('commenter');
             }
         } else {
             // name information exists. however, replier maybe different from services.
             // It is a limitation of spec.
             if ($this->name == User::getName($this->commenter)) {
                 // If name == commenter, it is same service (maybe).
                 $query->setAttribute('replier', $this->commenter);
             }
         }
         //			$query->setAttribute('replier', $this->commenter);
     }
     if (isset($this->name)) {
         $this->name = Utils_Unicode::lessenAsEncoding(trim($this->name), 80);
         if (empty($this->name)) {
             return $this->_error('name');
         }
         $query->setAttribute('name', $this->name, true);
     }
     if (isset($this->openid)) {
         $this->openid = Utils_Unicode::lessenAsEncoding(trim($this->openid), 128);
         if (empty($this->openid)) {
             return $this->_error('openid');
         }
         $query->setAttribute('openid', $this->openid, true);
     }
     if (isset($this->homepage)) {
         $this->homepage = Utils_Unicode::lessenAsEncoding(trim($this->homepage), 80);
         if (empty($this->homepage)) {
             return $this->_error('homepage');
         }
         $query->setAttribute('homepage', $this->homepage, true);
     }
     if (isset($this->ip)) {
         if (!Validator::ip($this->ip)) {
             return $this->_error('ip');
         }
         $query->setAttribute('ip', $this->ip, true);
     }
     if (isset($this->secret)) {
         $query->setAttribute('secret', Validator::getBit($this->secret));
     }
     if (isset($this->content)) {
         $this->content = trim($this->content);
         if (empty($this->content)) {
             return $this->_error('content');
         }
         $query->setAttribute('comment', $this->content, true);
     }
     if (isset($this->longitude) && Validator::number($this->longitude)) {
         $query->setAttribute('longitude', $this->longitude, false);
     } else {
         $query->setAttribute('longitude', null);
     }
     if (isset($this->latitude) && Validator::number($this->latitude)) {
         $query->setAttribute('latitude', $this->latitude, false);
     } else {
         $query->setAttribute('latitude', null);
     }
     if (isset($this->written)) {
         if (!Validator::timestamp($this->written)) {
             return $this->_error('written');
         }
         $query->setAttribute('written', $this->written);
     }
     if (isset($this->isfiltered)) {
         $query->setAttribute('isfiltered', Validator::getBit($this->isfiltered));
     }
     if (isset($this->password)) {
         $this->password = Utils_Unicode::lessenAsEncoding($this->password, 32);
         $query->setAttribute('password', $this->password, true);
         $this->password = null;
     }
     return $query;
 }
 function setServiceSetting($name, $value, $global = null)
 {
     global $__serviceSetting;
     if (is_null($global)) {
         $name = 'plugin_' . $name;
     }
     $name = Utils_Unicode::lessenAsEncoding($name, 32);
     $query = DBModel::getInstance();
     $query->reset('ServiceSettings');
     $query->setQualifier('name', 'equals', $name, true);
     $query->setAttribute('name', $name, true);
     $query->setAttribute('value', $value, true);
     if (!empty($__serviceSetting)) {
         $__serviceSetting[$name] = $value;
     }
     return $query->replace();
 }
Esempio n. 17
0
 function saveSlogan($slogan = null)
 {
     global $database;
     $this->init();
     if (!Validator::number($this->id, 1)) {
         return $this->_error('id');
     }
     if (!Validator::number($this->userid, 1)) {
         return $this->_error('userid');
     }
     if (isset($slogan)) {
         $this->slogan = $slogan;
     }
     $query = new DBModel();
     $query->reset('Entries');
     $query->setQualifier('blogid', $this->blogid);
     if (isset($this->userid)) {
         $query->setQualifier('userid', $this->userid);
     }
     $query->setQualifier('id', $this->id);
     if (!$query->doesExist()) {
         return $this->_error('id');
     }
     if (isset($this->slogan) && $this->validateSlogan($this->slogan)) {
         $slogan0 = $this->slogan;
     } else {
         $slogan0 = $this->slogan = $this->makeSlogan($this->title);
     }
     $slogan0 = Utils_Unicode::lessenAsEncoding($slogan0, 255);
     for ($i = 1; $i < 1000; $i++) {
         //			$checkSlogan = POD::escapeString($this->slogan);
         $checkSlogan = $this->slogan;
         $query->setAttribute('slogan', $checkSlogan, true);
         if (!POD::queryExistence("SELECT id FROM {$database['prefix']}Entries " . "WHERE blogid = " . $this->blogid . " AND id <> {$this->id} AND slogan ='{$checkSlogan}'")) {
             if (!$query->update()) {
                 return $this->_error('update');
             }
             return true;
         }
         $this->slogan = Utils_Unicode::lessenAsEncoding($slogan0, 245) . '-' . $i;
     }
     // if try saveSlogan again, slogan string has more $i
     return $this->_error('limit');
 }
 function _buildQuery()
 {
     global $database;
     $query = DBModel::getInstance();
     $query->reset('RefererLogs');
     $query->setQualifier('blogid', 'equals', getBlogId());
     if (isset($this->host)) {
         $this->host = Utils_Unicode::lessenAsEncoding(trim($url['host']), 64);
         if (empty($this->host)) {
             return $this->_error('host');
         }
         $query->setAttribute('host', $this->host, true);
     }
     if (isset($this->url)) {
         $this->url = Utils_Unicode::lessenAsEncoding(trim($this->url), 255);
         if (empty($this->url)) {
             return $this->_error('url');
         }
         $url = parse_url($this->url);
         if (empty($url['host'])) {
             return $this->_error('url');
         }
         $this->host = Utils_Unicode::lessenAsEncoding(trim($url['host']), 64);
         $query->setAttribute('host', $this->host, true);
         if (empty($url['scheme'])) {
             $this->url = 'http://' . $this->url;
         }
         $query->setAttribute('url', $this->url, true);
     }
     if (isset($this->referred)) {
         if (!Validator::number($this->referred, 1)) {
             return $this->_error('referred');
         }
         $query->setAttribute('referred', $this->referred);
     }
     return $query;
 }
 function _buildQuery()
 {
     global $database;
     $query = DBModel::getInstance();
     $query->reset('LinkCategories');
     $query->setQualifier('blogid', 'equals', getBlogId());
     if (isset($this->id)) {
         if (!Validator::number($this->id, 1)) {
             return $this->_error('id');
         }
         $query->setQualifier('id', 'equals', $this->id);
     }
     if (isset($this->pid)) {
         if (!Validator::number($this->pid, 1)) {
             return $this->_error('pid');
         }
         $query->setQualifier('pid', 'equals', $this->pid);
     }
     if (isset($this->priority)) {
         if (intval($this->priority) < 0) {
             return $this->_error('category');
         }
         $query->setQualifier('priority', 'equals', $this->priority);
     }
     if (isset($this->name)) {
         $this->url = Utils_Unicode::lessenAsEncoding(trim($this->name), 255);
         if (empty($this->name)) {
             return $this->_error('name');
         }
         $query->setQualifier('name', 'equals', $this->name, true);
     }
     if (isset($this->visibility)) {
         if (intval($this->visibility) < 0) {
             return $this->_error('visibility');
         }
         $query->setQualifier('visibility', 'equals', $this->visibility);
     }
     return $query;
 }
Esempio n. 20
0
function getTeamContentsSave($target)
{
    global $database;
    $flag = isset($_POST['flag']) ? $_POST['flag'] : '';
    $style = isset($_POST['fontstyle']) ? $_POST['fontstyle'] : '';
    $profile = isset($_POST['profile']) ? $_POST['profile'] : '';
    if (doesHaveOwnership() && doesHaveMembership()) {
        if ($flag == "style") {
            if (POD::execute("UPDATE {$database['prefix']}TeamUserSettings SET style=\"{$style}\", updated=UNIX_TIMESTAMP() WHERE blogid=" . getBlogId() . " and userid=" . getUserId())) {
                Respond::ResultPage(0);
            }
        } else {
            if ($flag == "profile") {
                $profile = POD::escapeString(Utils_Unicode::lessenAsEncoding($profile, 65535));
                if (POD::execute("UPDATE {$database['prefix']}TeamUserSettings SET profile=\"{$profile}\", updated=UNIX_TIMESTAMP() WHERE blogid=" . getBlogId() . " and userid=" . getUserId())) {
                    Respond::ResultPage(0);
                }
            }
        }
        Respond::ResultPage(-1);
    }
}
Esempio n. 21
0
function updateEntriesOfCategory($blogid, $categoryId = -1)
{
    $ctx = Model_Context::getInstance();
    clearCategoryCache();
    if ($categoryId == -1) {
        $result = POD::queryAll("SELECT * FROM " . $ctx->getProperty('database.prefix') . "Categories WHERE blogid = {$blogid} AND parent IS NULL");
    } else {
        $parent = getParentCategoryId($blogid, $categoryId);
        if (empty($parent)) {
            // It is parent.
            $lookup = $categoryId;
        } else {
            $lookup = $parent;
        }
        $result = POD::queryAll("SELECT * FROM " . $ctx->getProperty('database.prefix') . "Categories WHERE blogid = {$blogid} AND id = {$lookup}");
    }
    foreach ($result as $row) {
        $parent = $row['id'];
        $parentName = Utils_Unicode::lessenAsEncoding($row['name'], 127);
        $row['name'] = POD::escapeString($parentName);
        $countParent = POD::queryCell("SELECT COUNT(id) FROM " . $ctx->getProperty('database.prefix') . "Entries WHERE blogid = {$blogid} AND draft = 0 AND visibility > 0 AND category = {$parent}");
        $countInLoginParent = POD::queryCell("SELECT COUNT(id) FROM " . $ctx->getProperty('database.prefix') . "Entries WHERE blogid = {$blogid} AND draft = 0 AND category = {$parent}");
        $result2 = POD::queryAll("SELECT * FROM " . $ctx->getProperty('database.prefix') . "Categories WHERE blogid = {$blogid} AND parent = {$parent}");
        foreach ($result2 as $rowChild) {
            $label = POD::escapeString(Utils_Unicode::lessenAsEncoding($parentName . '/' . $rowChild['name'], 255));
            $rowChild['name'] = POD::escapeString(Utils_Unicode::lessenAsEncoding($rowChild['name'], 127));
            $countChild = POD::queryCell("SELECT COUNT(id) FROM " . $ctx->getProperty('database.prefix') . "Entries WHERE blogid = {$blogid} AND draft = 0 AND visibility > 0 AND category = {$rowChild['id']}");
            $countInLogInChild = POD::queryCell("SELECT COUNT(id) FROM " . $ctx->getProperty('database.prefix') . "Entries WHERE blogid = {$blogid} AND draft = 0 AND category = {$rowChild['id']}");
            POD::query("UPDATE " . $ctx->getProperty('database.prefix') . "Categories SET entries = {$countChild}, entriesinlogin = {$countInLogInChild}, label = '{$label}' WHERE blogid = {$blogid} AND id = {$rowChild['id']}");
            $countParent += $countChild;
            $countInLoginParent += $countInLogInChild;
        }
        POD::query("UPDATE " . $ctx->getProperty('database.prefix') . "Categories SET entries = {$countParent}, entriesinlogin = {$countInLoginParent}, label = '{$row['name']}' WHERE blogid = {$blogid} AND id = {$parent}");
    }
    if ($categoryId >= 0) {
        CacheControl::flushCategory($categoryId);
    }
    return true;
}
Esempio n. 22
0
function receiveNotifiedComment($post)
{
    if (empty($post['mode']) || $post['mode'] != 'fb') {
        return 1;
    }
    $context = Model_Context::getInstance();
    CacheControl::flushCommentNotifyRSS();
    $post = fireEvent('ReceiveNotifiedComment', $post);
    if ($post === false) {
        return 7;
    }
    $pool = DBModel::getInstance();
    $blogid = getBlogId();
    $title = Utils_Unicode::lessenAsEncoding($post['s_home_title'], 255);
    $name = Utils_Unicode::lessenAsEncoding($post['s_name'], 255);
    $entryId = $post['s_no'];
    $homepage = Utils_Unicode::lessenAsEncoding($post['url'], 255);
    $entryurl = $post['s_url'];
    $entrytitle = $post['s_post_title'];
    $parent_id = $post['r1_no'];
    $parent_name = Utils_Unicode::lessenAsEncoding($post['r1_name'], 80);
    $parent_parent = $post['r1_rno'];
    $parent_homepage = Utils_Unicode::lessenAsEncoding($post['r1_homepage'], 80);
    $parent_written = $post['r1_regdate'];
    $parent_comment = $post['r1_body'];
    $parent_url = Utils_Unicode::lessenAsEncoding($post['r1_url'], 255);
    $child_id = $post['r2_no'];
    $child_name = Utils_Unicode::lessenAsEncoding($post['r2_name'], 80);
    $child_parent = $post['r2_rno'];
    $child_homepage = Utils_Unicode::lessenAsEncoding($post['r2_homepage'], 80);
    $child_written = $post['r2_regdate'];
    $child_comment = $post['r2_body'];
    $child_url = Utils_Unicode::lessenAsEncoding($post['r2_url'], 255);
    $pool->reset('CommentsNotifiedSiteInfo');
    $pool->setQualifier('url', 'eq', $homepage);
    $siteid = $pool->getCell('id');
    if (empty($siteid)) {
        $insertId = getCommentsNotifiedSiteInfoMaxId() + 1;
        $pool->reset('CommentsNotifiedSiteInfo');
        $pool->setAttribute('id', $insertId);
        $pool->setAttribute('title', $title, true);
        $pool->setAttribute('name', $name, true);
        $pool->setAttribute('url', $homepage, true);
        $pool->setAttribute('modified', Timestamp::getUNIXtime());
        if ($pool->insert()) {
            $siteid = $insertId;
        } else {
            return 2;
        }
    }
    $pool->reset('CommentsNotified');
    $pool->setQualifier('entry', 'eq', $entryId);
    $pool->setQualifier('siteid', 'eq', $siteid);
    $pool->setQualifier('blogid', 'eq', $blogid);
    $pool->setQualifier('remoteid', 'eq', $parent_id);
    $parentId = $pool->getCell('id');
    if (empty($parentId)) {
        $insertId = getCommentsNotifiedMaxId() + 1;
        $pool->reset('CommentsNotified');
        $pool->setAttribute('blogid', $blogid);
        $pool->setAttribute('replier', NULL);
        $pool->setAttribute('id', $insertId);
        $pool->setAttribute('entry', $entryId);
        $pool->setAttribute('parent', empty($parent_parent) ? NULL : $parent_parent);
        $pool->setAttribute('name', $parent_name, true);
        $pool->setAttribute('password', '', true);
        $pool->setAttribute('homepage', $parent_homepage, true);
        $pool->setAttribute('secret', '', true);
        $pool->setAttribute('comment', $parent_comment, true);
        $pool->setAttribute('ip', '', true);
        $pool->setAttribute('written', $parent_written, true);
        $pool->setAttribute('modified', Timestamp::getUNIXtime());
        $pool->setAttribute('siteid', $siteid);
        $pool->setAttribute('isnew', 1);
        $pool->setAttribute('url', $parent_url, true);
        $pool->setAttribute('remoteid', $parent_id);
        $pool->setAttribute('entrytitle', $entrytitle, true);
        $pool->setAttribute('entryurl', $entryurl, true);
        if (!$pool->insert()) {
            return 3;
        }
        $parentId = $insertId;
    }
    $pool->reset('CommentsNotified');
    $pool->setQualifier('siteid', 'eq', $siteid);
    $pool->setQualifier('remoteid', 'eq', $child_id);
    if ($pool->getCount() > 0) {
        return 4;
    }
    $insertId = getCommentsNotifiedMaxId() + 1;
    $pool->reset('CommentsNotified');
    $pool->setAttribute('blogid', $blogid);
    $pool->setAttribute('replier', NULL);
    $pool->setAttribute('id', $insertId);
    $pool->setAttribute('entry', $entryId);
    $pool->setAttribute('parent', $parentId);
    $pool->setAttribute('name', $child_name, true);
    $pool->setAttribute('password', '', true);
    $pool->setAttribute('homepage', $child_homepage, true);
    $pool->setAttribute('secret', '', true);
    $pool->setAttribute('comment', $child_comment, true);
    $pool->setAttribute('ip', '', true);
    $pool->setAttribute('written', $child_written, true);
    $pool->setAttribute('modified', Timestamp::getUNIXtime());
    $pool->setAttribute('siteid', $siteid);
    $pool->setAttribute('isnew', 1);
    $pool->setAttribute('url', $child_url, true);
    $pool->setAttribute('remoteid', $child_id);
    $pool->setAttribute('entrytitle', $entrytitle, true);
    $pool->setAttribute('entryurl', $entryurl, true);
    if (!$pool->insert()) {
        return 5;
    }
    $pool->reset('CommentsNotified');
    $pool->setAttribute('modified', Timestamp::getUNIXtime());
    $pool->setQualifier('blogid', 'eq', $blogid);
    $pool->setQualifier('id', 'eq', $parentId);
    if (!$pool->update()) {
        return 6;
    }
    return 0;
}
 function _buildQuery()
 {
     global $database;
     $this->host = Utils_Unicode::lessenAsEncoding(trim($this->host), 64);
     if (empty($this->host)) {
         return $this->_error('host');
     }
     $query = DBModel::getInstance();
     $query->reset('RefererStatistics');
     $query->setQualifier('blogid', 'equals', getBlogId());
     $query->setQualifier('host', 'equals', $this->host, true);
     if (isset($this->count)) {
         if (!Validator::number($this->count, 1)) {
             return $this->_error('count');
         }
         $query->setAttribute('count', $this->count);
     }
     return $query;
 }
 static function updateVisitorStatistics($blogid)
 {
     global $database, $blogURL;
     if (!fireEvent('UpdatingVisitorStatistics', true)) {
         return;
     }
     if (doesHaveOwnership()) {
         return;
     }
     $id = session_id();
     if (POD::queryCount("SELECT blogid FROM {$database['prefix']}SessionVisits WHERE id = '{$id}' AND address = '{$_SERVER['REMOTE_ADDR']}' AND blogid = {$blogid}") > 0) {
         return;
     }
     if (POD::queryCount("INSERT INTO {$database['prefix']}SessionVisits values('{$id}', '{$_SERVER['REMOTE_ADDR']}', {$blogid})") > 0) {
         if (POD::queryCount("UPDATE {$database['prefix']}BlogStatistics SET visits = visits + 1 WHERE blogid = {$blogid}") < 1) {
             POD::execute("INSERT into {$database['prefix']}BlogStatistics values({$blogid}, 1)");
         }
         $period = Timestamp::getDate();
         if (POD::queryCount("UPDATE {$database['prefix']}DailyStatistics SET visits = visits + 1 WHERE blogid = {$blogid} AND datemark = {$period}") < 1) {
             POD::execute("INSERT INTO {$database['prefix']}DailyStatistics VALUES ({$blogid}, {$period}, 1)");
         }
         if (!empty($_SERVER['HTTP_REFERER'])) {
             $referer = parse_url($_SERVER['HTTP_REFERER']);
             if (!empty($referer['host']) && ($referer['host'] != $_SERVER['HTTP_HOST'] || strncmp($referer['path'], $blogURL, strlen($blogURL)) != 0)) {
                 if (Filter::isFiltered('ip', $_SERVER['REMOTE_ADDR']) || Filter::isFiltered('url', $_SERVER['HTTP_REFERER'])) {
                     return;
                 }
                 if (!fireEvent('AddingRefererLog', true, array('host' => $referer['host'], 'url' => $_SERVER['HTTP_REFERER']))) {
                     return;
                 }
                 $host = POD::escapeString(Utils_Unicode::lessenAsEncoding($referer['host'], 64));
                 $url = POD::escapeString(Utils_Unicode::lessenAsEncoding($_SERVER['HTTP_REFERER'], 255));
                 POD::query("INSERT INTO {$database['prefix']}RefererLogs values({$blogid}, '{$host}', '{$url}', UNIX_TIMESTAMP())");
                 //					POD::query("DELETE FROM {$database['prefix']}RefererLogs WHERE referred < UNIX_TIMESTAMP() - 604800");	// Moved to trashVan
                 if (!POD::queryCount("UPDATE {$database['prefix']}RefererStatistics SET count = count + 1 WHERE blogid = {$blogid} AND host = '{$host}' LIMIT 1")) {
                     POD::execute("INSERT into {$database['prefix']}RefererStatistics values({$blogid}, '{$host}', 1)");
                 }
             }
         }
     }
 }
Esempio n. 25
0
function sendInvitationMail($blogid, $userid, $name, $comment, $senderName, $senderEmail)
{
    $ctx = Model_Context::getInstance();
    $pool = DBModel::getInstance();
    if (empty($blogid)) {
        $pool->reset('BlogSettings');
        $blogid = $pool->getCell('max(blogid)');
        // If no blogid, get the latest created blogid.
    }
    $email = User::getEmail($userid);
    $pool->reset('Users');
    $pool->setQualifier('userid', 'eq', $userid);
    $password = getCell('password');
    $authtoken = getAuthToken($userid);
    $blogName = getBlogName($blogid);
    if (empty($email)) {
        return 1;
    }
    if (!preg_match('/^[^@]+@([-a-zA-Z0-9]+\\.)+[-a-zA-Z0-9]+$/', $email)) {
        return 2;
    }
    if (empty($name)) {
        $name = User::getName($userid);
    }
    if (strcmp($email, Utils_Unicode::lessenAsEncoding($email, 64)) != 0) {
        return 11;
    }
    //$loginid = POD::escapeString(Utils_Unicode::lessenAsEncoding($email, 64));
    $name = POD::escapeString(Utils_Unicode::lessenAsEncoding($name, 32));
    //$headers = 'From: ' . encodeMail($senderName) . '<' . $senderEmail . ">\n" . 'X-Mailer: ' . TEXTCUBE_NAME . "\n" . "MIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n";
    if (empty($name)) {
        $subject = _textf('귀하를 %1님이 초대합니다', $senderName);
    } else {
        $subject = _textf('%1님을 %2님이 초대합니다', $name, $senderName);
    }
    $message = file_get_contents(ROOT . "/resources/style/letter/letter.html");
    $message = str_replace('[##_title_##]', _text('초대장'), $message);
    $message = str_replace('[##_content_##]', $comment, $message);
    $message = str_replace('[##_images_##]', $ctx->getProperty('uri.service') . "/resources/style/letter", $message);
    $message = str_replace('[##_link_##]', getInvitationLink(getBlogURL($blogName), $email, $password, $authtoken), $message);
    $message = str_replace('[##_go_blog_##]', getBlogURL($blogName), $message);
    $message = str_replace('[##_link_title_##]', _text('블로그 바로가기'), $message);
    if (empty($name)) {
        $message = str_replace('[##_to_##]', '', $message);
    } else {
        $message = str_replace('[##_to_##]', _text('받는 사람') . ': ' . $name, $message);
    }
    $message = str_replace('[##_sender_##]', _text('보내는 사람') . ': ' . $senderName, $message);
    $ret = sendEmail($senderName, $senderEmail, $name, $email, $subject, $message);
    if ($ret !== true) {
        return array(14, $ret[1]);
    }
    return true;
}
Esempio n. 26
0
function saveFeedItem($feedId, $item)
{
    global $database;
    $item = fireEvent('SaveFeedItem', $item);
    $item['permalink'] = POD::escapeString(Utils_Unicode::lessenAsEncoding(Utils_Unicode::correct($item['permalink'])));
    $item['author'] = POD::escapeString(Utils_Unicode::lessenAsEncoding(Utils_Unicode::correct($item['author'])));
    $item['title'] = POD::escapeString(Utils_Unicode::lessenAsEncoding(Utils_Unicode::correct($item['title'])));
    $item['description'] = POD::escapeString(Utils_Unicode::lessenAsEncoding(Utils_Unicode::correct($item['description']), 65535));
    $tagString = POD::escapeString(Utils_Unicode::lessenAsEncoding(Utils_Unicode::correct(implode(', ', $item['tags']))));
    $enclosureString = POD::escapeString(Utils_Unicode::lessenAsEncoding(Utils_Unicode::correct(implode('|', $item['enclosures']))));
    if ($item['written'] > gmmktime() + 86400) {
        return false;
    }
    $deadLine = 0;
    $feedlife = POD::queryCell("SELECT feedlife FROM {$database['prefix']}FeedSettings");
    if ($feedlife > 0) {
        $deadLine = gmmktime() - $feedlife * 86400;
    }
    if ($id = POD::queryCell("SELECT id FROM {$database['prefix']}FeedItems WHERE permalink='{$item['permalink']}'") && $item['written'] != 0) {
        $result = POD::query("UPDATE {$database['prefix']}FeedItems SET author = '{$item['author']}', title = '{$item['title']}', description = '{$item['description']}', tags = '{$tagString}', enclosure = '{$enclosureString}', written = {$item['written']} WHERE id = {$id}");
        /*
        TODO : 읽은글이 읽지않은 글로 표시되는 문제 원인이 찾아질때 까지 막아둠
        if (POD::num_rows($result) > 0)
            POD::query("DELETE FROM {$database['prefix']}FeedReads WHERE item = $id");
        */
    } else {
        if ($id != null) {
            return false;
        } else {
            if ($item['written'] == 0) {
                $item['written'] = gmmktime();
            }
            if ($item['written'] > $deadLine) {
                $id = POD::queryCell("SELECT max(id) FROM {$database['prefix']}FeedItems");
                if (!$id) {
                    $id = 0;
                }
                $id++;
                POD::query("INSERT INTO {$database['prefix']}FeedItems VALUES({$id}, {$feedId}, '{$item['author']}', '{$item['permalink']}', '{$item['title']}', '{$item['description']}', '{$tagString}', '{$enclosureString}', {$item['written']})");
            }
        }
    }
    return true;
}
Esempio n. 27
0
 function modifyTagsWithEntryId($blogid, $entry, $taglist)
 {
     global $database;
     if (empty($taglist)) {
         $taglist = array();
     }
     $tmptaglist = array_filter($taglist, 'Tag_removeEmptyTagHelper');
     $taglist = array();
     foreach ($tmptaglist as $tag) {
         $tag = POD::escapeString(trim($tag));
         array_push($taglist, $tag);
     }
     // step 1. Get deleted Tag
     $tmpoldtaglist = POD::queryColumn("SELECT name FROM {$database['prefix']}Tags\n\t\t\tLEFT JOIN {$database['prefix']}TagRelations ON tag = id \n\t\t\tWHERE blogid = {$blogid} AND entry = {$entry}");
     if ($tmpoldtaglist === null) {
         $tmpoldtaglist = array();
     }
     $oldtaglist = array();
     foreach ($tmpoldtaglist as $tag) {
         $tag = POD::escapeString(Utils_Unicode::lessenAsEncoding(trim($tag), 255));
         array_push($oldtaglist, $tag);
     }
     $deletedTagList = array_diff($oldtaglist, $taglist);
     $insertedTagList = array_diff($taglist, $oldtaglist);
     // step 2. Insert Tag
     if (count($insertedTagList) > 0) {
         foreach ($insertedTagList as $tg) {
             if (!Tag::doesExist($tg)) {
                 @POD::execute("INSERT INTO {$database['prefix']}Tags (id, name) VALUES (" . (Tag::_getMaxId() + 1) . ",'" . $tg . "')");
             }
         }
         //			$tagliststr = '(\'' . implode('\') , (\'', $insertedTagList) . '\')';
         //			POD::execute("INSERT IGNORE INTO {$database['prefix']}Tags (name) VALUES $tagliststr ");
         // step 3. Insert Relation
         $tagliststr = '\'' . implode('\' , \'', $insertedTagList) . '\'';
         /*
         POD::execute("INSERT INTO {$database['prefix']}TagRelations
             (SELECT $blogid, t.id, $entry FROM {$database['prefix']}Tags as t
                 WHERE
                 name in ( $tagliststr ) AND
                 t.id NOT IN
                     ( SELECT tag FROM {$database['prefix']}TagRelations WHERE
                         (tag = t.id) AND (entry = $entry) AND (blogid = $blogid)
                     )
                 )");
         */
         // For MySQL 3, Simple Query Version
         $tagIDs = POD::queryColumn("SELECT id FROM {$database['prefix']}Tags WHERE name in ( {$tagliststr} )");
         $tagrelations = array();
         foreach ($tagIDs as $tagid) {
             array_push($tagrelations, " ({$blogid}, {$tagid}, {$entry}) ");
         }
         foreach ($tagrelations as $tr) {
             @POD::execute("INSERT INTO {$database['prefix']}TagRelations VALUES {$tr}");
         }
         //$tagRelationStr = implode(', ', $tagrelations);
         //POD::execute("INSERT IGNORE INTO {$database['prefix']}TagRelations VALUES $tagRelationStr");
     }
     // step 4. Delete Tag
     if (count($deletedTagList) > 0) {
         // small step, get tag id list
         $tagliststr = '\'' . implode('\' , \'', $deletedTagList) . '\'';
         $t1list = POD::queryColumn("SELECT id FROM {$database['prefix']}Tags WHERE name in ( {$tagliststr} )");
         if (is_null($t1list)) {
             return;
         }
         // What?
         // Flushing pageCache
         foreach ($t1list as $tagids) {
             CacheControl::flushTag($tagids);
         }
         // Make string
         $t1liststr = implode(', ', $t1list);
         $taglist = POD::queryColumn("SELECT tag FROM {$database['prefix']}TagRelations\n\t\t\t\t\t\tWHERE blogid = {$blogid} AND entry = {$entry} AND tag in ( {$t1liststr} )");
         if (is_null($taglist)) {
             return;
         }
         // What?
         // now delete tag
         $tagliststr = implode(', ', $taglist);
         // step 5. Delete Relation
         POD::execute("DELETE FROM {$database['prefix']}TagRelations WHERE blogid = {$blogid} AND entry = {$entry} AND tag in ( {$tagliststr} )");
         // step 6. Delete Tag
         $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} )");
         }
     }
 }
Esempio n. 28
0
function treatPluginTable($plugin, $name, $fields, $keys, $version)
{
    $context = Model_Context::getInstance();
    $query = DBModel::getInstance();
    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->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->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->init($name);
        $query->structure = array("blogid" => array("type" => 'integer', "isNull" => false, "default" => 0, "index" => true));
        $isaiExists = false;
        foreach ($fields as $field) {
            $branch = array();
            $ai = '';
            if (strtolower($field['attribute']) == 'int' || strtolower($field['attribute']) == 'mediumint') {
                if ($field['autoincrement'] == 1 && !$isaiExists) {
                    $branch['autoincrement'] = true;
                    //$branch['index'] = true;
                    $isaiExists = true;
                    if (!in_array($field['name'], $keys)) {
                        $branch['index'] = true;
                    }
                }
            }
            $branch['type'] = strtolower($field['attribute']);
            if ($field['isnull'] == 0) {
                $branch['isNull'] = false;
            } else {
                $branch['isNull'] = true;
            }
            if (!is_null($field['default'])) {
                $branch['default'] = $field['default'];
            }
            if ($field['length'] >= 0) {
                $branch['length'] = $field['length'];
            }
            $query->structure[$field['name']] = $branch;
        }
        array_unshift($keys, 'blogid');
        $query->option['primary'] = $keys;
        if ($query->create()) {
            $keyname = Utils_Unicode::lessenAsEncoding('Database_' . $name, 32);
            $value = Utils_Unicode::lessenAsEncoding($plugin . '/' . $version, 255);
            Setting::setServiceSetting($keyname, $value, true);
            return true;
        } else {
            return false;
        }
    }
    return true;
}
Esempio n. 29
0
function api_update_attaches_with_replace($entryId)
{
    $pool = DBModel::getInstance();
    $pool->reset('Attachments');
    $pool->setQualifier('blogid', 'eq', getBlogId());
    $pool->setQualifier('parent', 'eq', 0);
    $newFiles = $pool->getAll('name,label');
    if ($newFiles) {
        foreach ($newFiles as $newfile) {
            $newfile['label'] = Utils_Unicode::lessenAsEncoding($newfile['label'], 64);
            $pool->reset('Attachments');
            $pool->setQualifier('blogid', 'eq', getBlogId());
            $pool->setQualifier('parent', 'eq', $entryId);
            $pool->setQualifier('label', 'eq', $newfile['label'], true);
            $oldFile = $pool->getCell('name');
            if (!is_null($oldFile)) {
                deleteAttachment(getBlogId(), $entryId, $oldFile);
            }
        }
    }
    api_update_attaches($entryId);
}
Esempio n. 30
0
function getTagsWithEntryString($entryTag)
{
    $tags = explode(',', $entryTag);
    $ret = array();
    foreach ($tags as $tag) {
        $tag = Utils_Unicode::lessenAsEncoding($tag, 255, '');
        $tag = str_replace('&quot;', '"', $tag);
        $tag = str_replace('&#39;', '\'', $tag);
        $tag = preg_replace('/ +/', ' ', $tag);
        $tag = preg_replace('/[\\x00-\\x1f]|[\\x7f]/', '', $tag);
        $tag = preg_replace('/^(-|\\s)+/', '', $tag);
        $tag = preg_replace('/(-|\\s)+$/', '', $tag);
        $tag = trim($tag);
        array_push($ret, $tag);
    }
    return $ret;
}