예제 #1
0
function addLink($blogid, $link)
{
    global $database;
    $name = UTF8::lessenAsEncoding(trim($link['name']), 255);
    $url = UTF8::lessenAsEncoding(trim($link['url']), 255);
    if (empty($name) || empty($url)) {
        return -1;
    }
    $category = isset($link['category']) ? $link['category'] : 0;
    $name = POD::escapeString($name);
    $url = POD::escapeString($url);
    if (isset($link['newCategory']) && !empty($link['newCategory'])) {
        // Add new category information
        $newCategoryTitle = POD::escapeString(UTF8::lessenAsEncoding(trim($link['newCategory']), 255));
        $newCategoryId = addLinkCategory($blogid, $newCategoryTitle);
        if (!empty($newCategoryId)) {
            $category = $newCategoryId;
        } else {
            return false;
        }
    }
    $id = getMaxIdOfLink() + 1;
    $pid = getMaxPidOfLink() + 1;
    $rss = isset($link['rss']) ? POD::escapeString(UTF8::lessenAsEncoding(trim($link['rss']), 255)) : '';
    if (POD::queryCell("SELECT id FROM {$database['prefix']}Links WHERE blogid = {$blogid} AND url = '{$url}'")) {
        return 1;
    }
    if (POD::execute("INSERT INTO {$database['prefix']}Links (pid, blogid, id,category,name,url,rss,written) VALUES ({$pid}, {$blogid}, {$id}, {$category}, '{$name}', '{$url}', '{$rss}', UNIX_TIMESTAMP())")) {
        return 0;
    } else {
        return -1;
    }
}
예제 #2
0
function addLink($blogid, $link)
{
    $name = Utils_Unicode::lessenAsEncoding(trim($link['name']), 255);
    $url = Utils_Unicode::lessenAsEncoding(trim($link['url']), 255);
    if (empty($name) || empty($url)) {
        return -1;
    }
    $pool = DBModel::getInstance();
    $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;
        } else {
            return false;
        }
    }
    $id = getMaxIdOfLink() + 1;
    $pid = getMaxPidOfLink() + 1;
    $pool->init("Links");
    $pool->setQualifier("blogid", "eq", $blogid);
    $pool->setQualifier("url", "eq", $url, true);
    if ($pool->getCell("id")) {
        return 1;
    }
    $rss = isset($link['rss']) ? Utils_Unicode::lessenAsEncoding(trim($link['rss']), 255) : '';
    $pool->init("Links");
    $pool->setAttribute("pid", $pid);
    $pool->setAttribute("blogid", $blogid);
    $pool->setAttribute("id", $id);
    $pool->setAttribute("category", $category);
    $pool->setAttribute("name", $name, true);
    $pool->setAttribute("url", $url, true);
    $pool->setAttribute("rss", $rss, true);
    $pool->setAttribute("written", Timestamp::getUNIXtime());
    if ($pool->insert()) {
        return 0;
    } else {
        return -1;
    }
}