示例#1
0
function modifyCategory($blogid, $id, $name, $bodyid)
{
    $ctx = Model_Context::getInstance();
    requireModel('blog.feed');
    if ($id == 0) {
        checkRootCategoryExistence($blogid);
    }
    if (empty($name) && empty($bodyid)) {
        return false;
    }
    $row = POD::queryRow("SELECT p.name, p.id\n\t\tFROM " . $ctx->getProperty('database.prefix') . "Categories c\n\t\tLEFT JOIN " . $ctx->getProperty('database.prefix') . "Categories p ON c.parent = p.id\n\t\tWHERE c.blogid = {$blogid} AND c.id = {$id}");
    $label = $row['name'];
    //	$parentId = $row['id'];
    //	if (!empty($parentId)) {
    //		$parentStr = "AND parent = $parentId";
    //	} else
    //		$parentStr = 'AND parent is null';
    $name = POD::escapeString(Utils_Unicode::lessenAsEncoding($name, 127));
    $bodyid = POD::escapeString(Utils_Unicode::lessenAsEncoding($bodyid, 20));
    if (POD::queryExistence("SELECT name\n\t\tFROM " . $ctx->getProperty('database.prefix') . "Categories\n\t\tWHERE blogid = {$blogid} AND name = '" . $name . "' AND bodyid = '" . $bodyid . "'")) {
        return false;
    }
    $label = POD::escapeString(Utils_Unicode::lessenAsEncoding(empty($label) ? $name : "{$label}/{$name}", 255));
    $sql = "SELECT *\n\t\tFROM " . $ctx->getProperty('database.prefix') . "Categories\n\t\tWHERE blogid = {$blogid}\n\t\t\tAND id = {$id}";
    // $sql = "SELECT count(*) FROM ".$ctx->getProperty('database.prefix')."Categories WHERE blogid = $blogid AND name='$name' $parentStr";
    if (POD::queryExistence($sql) == false) {
        return false;
    }
    $result = POD::query("UPDATE " . $ctx->getProperty('database.prefix') . "Categories\n\t\tSET name = '{$name}',\n\t\t\tlabel = '{$label}',\n\t\t\tbodyid = '{$bodyid}'\n\t\tWHERE blogid = {$blogid}\n\t\t\tAND id = {$id}");
    if ($result) {
        clearFeed();
    }
    updateEntriesOfCategory($blogid, $id);
    CacheControl::flushCategory($id);
    return $result ? true : false;
}
示例#2
0
function modifyCategory($blogid, $id, $name, $bodyid)
{
    $context = Model_Context::getInstance();
    importlib('model.blog.feed');
    if ($id == 0) {
        checkRootCategoryExistence($blogid);
    }
    if (empty($name) && empty($bodyid)) {
        return false;
    }
    $pool = DBModel::getInstance();
    $pool->reset("Categories");
    $pool->setAlias("Categories", "c");
    $pool->extend("Categories p", "left", array(array("c.parent", "eq", "p.id")));
    $pool->setQualifier("c.blogid", "eq", $blogid);
    $pool->setQualifier("c.id", "eq", $id);
    $row = $pool->getRow("p.name,p.id");
    $label = $row['name'];
    //	$parentId = $row['id'];
    //	if (!empty($parentId)) {
    //		$parentStr = "AND parent = $parentId";
    //	} else
    //		$parentStr = 'AND parent is null';
    $name = Utils_Unicode::lessenAsEncoding($name, 127);
    $bodyid = Utils_Unicode::lessenAsEncoding($bodyid, 20);
    $pool->reset("Categories");
    $pool->setQualifier("blogid", "eq", $blogid);
    $pool->setQualifier("name", "eq", $name, true);
    $pool->setQualifier("bodyid", "eq", $bodyid, true);
    if ($pool->doesExist("name")) {
        return false;
    }
    $label = Utils_Unicode::lessenAsEncoding(empty($label) ? $name : "{$label}/{$name}", 255);
    $pool->reset("Categories");
    $pool->setQualifier("blogid", "eq", $blogid);
    $pool->setQualifier("id", "eq", $id);
    if ($pool->doesExist() == false) {
        return false;
    }
    $pool->reset("Categories");
    $pool->setAttribute("name", $name, true);
    $pool->setAttribute("label", $label, true);
    $pool->setAttribute("bodyid", $bodyid, true);
    $pool->setQualifier("blogid", "eq", $blogid);
    $pool->setQualifier("id", "eq", $id);
    $result = $pool->update();
    if ($result) {
        clearFeed();
    }
    updateEntriesOfCategory($blogid, $id);
    CacheControl::flushCategory($id);
    return $result ? true : false;
}