Example #1
0
function getEntryFormatterInfo($id)
{
    global $database;
    static $info;
    if (!Validator::id($id)) {
        return NULL;
    } else {
        if (!isset($info[$id])) {
            $query = sprintf('SELECT contentformatter FROM %sEntries WHERE id = %d', $database['prefix'], $id);
            $info[$id] = POD::queryCell($query);
        }
    }
    return $info[$id];
}
Example #2
0
function getEntryFormatterInfo($id)
{
    static $info;
    $context = Model_Context::getInstance();
    $blogid = intval($context->getProperty('blog.id'));
    if (!Validator::id($id)) {
        return NULL;
    } else {
        if (!isset($info[$blogid][$id])) {
            $context = Model_Context::getInstance();
            $pool = DBModel::getInstance();
            $pool->reset('Entries');
            $pool->setQualifier('blogid', 'equals', $blogid);
            $pool->setQualifier('id', 'equals', $id);
            $info[$blogid][$id] = $pool->getCell('contentformatter');
        }
    }
    return $info[$blogid][$id];
}
 function load()
 {
     global $configMappings;
     if (false == Validator::id($this->blogid)) {
         $this->usable = false;
         return false;
     }
     if (!isset($this->pluginName) || empty($this->pluginName)) {
         $this->usable = false;
         return false;
     }
     $plugin = $this->pluginName;
     if (!isset($configMappings[$plugin])) {
         $this->usable = false;
         return false;
     }
     $this->configVal = $this->__getPluginConfig();
     if (false == is_array($this->configVal)) {
         $this->usable = false;
         return false;
     }
     $this->usable = true;
     return true;
 }
Example #4
0
function addCategory($blogid, $parent, $name, $id = null, $priority = null)
{
    $pool = DBModel::getInstance();
    if (empty($name)) {
        return false;
    }
    if (!is_null($parent) && !Validator::id($parent)) {
        return false;
    }
    if (!is_null($id) && !Validator::isInteger($id, 0)) {
        return false;
    }
    if ($priority !== null && !Validator::isInteger($priority, 0)) {
        return false;
    }
    if (!is_null($parent)) {
        $pool->reset('Categories');
        $pool->setQualifier('blogid', 'eq', $blogid);
        $pool->setQualifier('id', 'eq', $parent);
        $label = $pool->getCell('name');
        if ($label === null) {
            return false;
        }
        $label .= '/' . $name;
    } else {
        $parent = 'NULL';
        $label = $name;
    }
    $label = Utils_Unicode::lessenAsEncoding($label, 255);
    $name = Utils_Unicode::lessenAsEncoding($name, 127);
    $pool->reset('Categories');
    $pool->setQualifier('blogid', 'eq', $blogid);
    $pool->setQualifier('name', 'eq', $name, true);
    if ($parent == 'NULL') {
        $pool->setQualifier('parent', 'eq', NULL);
    } else {
        $pool->setQualifier('parent', 'eq', $parent);
    }
    if ($pool->getCount() > 0) {
        return false;
    }
    if (!is_null($priority)) {
        $pool->reset('Categories');
        $pool->setQualifier('blogid', 'eq', $blogid);
        $pool->setQualifier('priority', 'eq', $priority);
        if ($pool->doesExist()) {
            return false;
        } else {
            $newPriority = $priority;
        }
    } else {
        $pool->reset('Categories');
        $pool->setQualifier('blogid', 'eq', $blogid);
        $newPriority = $pool->getCell('MAX(priority)') + 1;
    }
    // Determine ID.
    if (!is_null($id)) {
        $pool->reset('Categories');
        $pool->setQualifier('blogid', 'eq', $blogid);
        $pool->setQualifier('id', 'eq', $id);
        if ($pool->doesExist()) {
            return false;
        } else {
            $newId = $id;
        }
    } else {
        $pool->reset('Categories');
        $pool->setQualifier('blogid', 'eq', $blogid);
        $newId = $pool->getCell('MAX(id)') + 1;
    }
    $pool->reset('Categories');
    $pool->setAttribute('blogid', $blogid);
    $pool->setAttribute('id', $newId);
    if ($parent == 'NULL') {
        $pool->setAttribute('parent', NULL);
    } else {
        $pool->setAttribute('parent', $parent);
    }
    $pool->setAttribute('name', $name, true);
    $pool->setAttribute('priority', $newPriority);
    $pool->setAttribute('entries', 0);
    $pool->setAttribute('entriesinlogin', 0);
    $pool->setAttribute('label', $label, true);
    $pool->setAttribute('visibility', 2);
    $result = $pool->insert();
    updateEntriesOfCategory($blogid, $newId);
    return $result ? true : false;
}
Example #5
0
function addCategory($blogid, $parent, $name, $id = null, $priority = null)
{
    global $database;
    if (empty($name)) {
        return false;
    }
    if (!is_null($parent) && !Validator::id($parent)) {
        return false;
    }
    if (!is_null($id) && !Validator::isInteger($id, 0)) {
        return false;
    }
    if ($priority !== null && !Validator::isInteger($priority, 0)) {
        return false;
    }
    if (!is_null($parent)) {
        $label = POD::queryCell("SELECT name FROM {$database['prefix']}Categories WHERE blogid = {$blogid} AND id = {$parent}");
        if ($label === null) {
            return false;
        }
        $label .= '/' . $name;
    } else {
        $parent = 'NULL';
        $label = $name;
    }
    $label = POD::escapeString(UTF8::lessenAsEncoding($label, 255));
    $name = POD::escapeString(UTF8::lessenAsEncoding($name, 127));
    if ($parent == 'NULL') {
        $parentStr = 'AND parent is null';
    } else {
        $parentStr = "AND parent = {$parent}";
    }
    $sql = "SELECT count(*) FROM {$database['prefix']}Categories WHERE blogid = {$blogid} AND name = '{$name}' {$parentStr}";
    if (POD::queryCell($sql) > 0) {
        return false;
    }
    if (!is_null($priority)) {
        if (POD::queryExistence("SELECT * FROM {$database['prefix']}Categories WHERE blogid = {$blogid} AND priority = {$priority}")) {
            return false;
        } else {
            $newPriority = $priority;
        }
    } else {
        $newPriority = POD::queryCell("SELECT MAX(priority) FROM {$database['prefix']}Categories WHERE blogid = {$blogid}") + 1;
    }
    // Determine ID.
    if (!is_null($id)) {
        $sql = "SELECT * FROM {$database['prefix']}Categories WHERE blogid = {$blogid} AND id = {$id}";
        if (POD::queryExistence($sql)) {
            return false;
        } else {
            $newId = $id;
        }
    } else {
        $newId = POD::queryCell("SELECT MAX(id) FROM {$database['prefix']}Categories WHERE blogid = {$blogid}") + 1;
    }
    $result = POD::query("INSERT INTO {$database['prefix']}Categories (blogid, id, parent, name, priority, entries, entriesinlogin, label, visibility) VALUES ({$blogid}, {$newId}, {$parent}, '{$name}', {$newPriority}, 0, 0, '{$label}', 2)");
    updateEntriesOfCategory($blogid, $newId);
    return $result ? true : false;
}
Example #6
0
 static function validateArray(&$array, &$rules)
 {
     // Workaround for non Fancy-URL user.
     $cropArray = array();
     foreach ($array as $name => $value) {
         $doesHaveRequest = strpos($name, '?');
         if ($doesHaveRequest !== false) {
             $name = substr($name, $doesHaveRequest + 1);
         }
         $cropArray[$name] = $value;
     }
     $array = $cropArray;
     foreach ($rules as $key => $rule) {
         if (!isset($rule[0])) {
             trigger_error("Validator: The type of '{$key}' is not defined", E_USER_WARNING);
             continue;
         }
         if (isset($array[$key]) && ($rule[0] == 'file' || strlen($array[$key]) > 0)) {
             $value =& $array[$key];
             if (isset($rule['min'])) {
                 $rule[1] = $rule['min'];
             }
             if (isset($rule['max'])) {
                 $rule[2] = $rule['max'];
             }
             if (isset($rule['bypass'])) {
                 $rule[3] = $rule['bypass'];
             }
             switch ($rule[0]) {
                 case 'any':
                     if (isset($rule[1]) && strlen($value) < $rule[1]) {
                         return false;
                     }
                     if (isset($rule[2]) && strlen($value) > $rule[2]) {
                         return false;
                     }
                     break;
                 case 'bit':
                     $array[$key] = Validator::getBit($value);
                     break;
                 case 'bool':
                     $array[$key] = Validator::getBool($value);
                     break;
                 case 'number':
                     if (!Validator::number($value, isset($rule[1]) ? $rule[1] : null, isset($rule[2]) ? $rule[2] : null, isset($rule[3]) ? $rule[3] : false)) {
                         return false;
                     }
                     break;
                 case 'int':
                     if (!Validator::isInteger($value, isset($rule[1]) ? $rule[1] : -2147483648.0, isset($rule[2]) ? $rule[2] : 2147483647, isset($rule[3]) ? $rule[3] : false)) {
                         return false;
                     }
                     break;
                 case 'id':
                     if (!Validator::id($value, isset($rule[1]) ? $rule[1] : 1, isset($rule[2]) ? $rule[2] : 2147483647)) {
                         return false;
                     }
                     break;
                 case 'url':
                 case 'string':
                     if (!Utils_Unicode::validate($value)) {
                         $value = Utils_Unicode::bring($value);
                         if (!Utils_Unicode::validate($value)) {
                             return false;
                         }
                     }
                     $value = $array[$key] = Utils_Unicode::correct($value);
                     if (isset($rule[1]) && Utils_Unicode::length($value) < $rule[1]) {
                         return false;
                     }
                     if (isset($rule[2]) && Utils_Unicode::length($value) > $rule[2]) {
                         return false;
                     }
                     break;
                 case 'list':
                     if (!Validator::isList($value)) {
                         return false;
                     }
                     break;
                 case 'timestamp':
                     if (!Validator::timestamp($value)) {
                         return false;
                     }
                     break;
                 case 'period':
                     if (!Validator::period($value)) {
                         return false;
                     }
                     break;
                 case 'ip':
                     if (!Validator::ip($value)) {
                         return false;
                     }
                     break;
                 case 'domain':
                     if (!Validator::domain($value)) {
                         return false;
                     }
                     break;
                 case 'email':
                     if (!Validator::email($value)) {
                         return false;
                     }
                     break;
                 case 'language':
                     if (!Validator::language($value)) {
                         return false;
                     }
                     break;
                 case 'filename':
                     if (!Validator::filename($value)) {
                         return false;
                     }
                     break;
                 case 'directory':
                     if (!Validator::directory($value)) {
                         return false;
                     }
                     break;
                 case 'path':
                     if (!Validator::path($value)) {
                         return false;
                     }
                     break;
                 case 'file':
                     if (!isset($value['name']) || preg_match('@[/\\\\]@', $value['name'])) {
                         return false;
                     }
                     break;
                 default:
                     if (is_array($rule[0])) {
                         if (!in_array($value, $rule[0])) {
                             return false;
                         }
                     } else {
                         trigger_error("Validator: The type of '{$key}' is unknown", E_USER_WARNING);
                     }
                     break;
             }
             if (isset($rule['check'])) {
                 $rule[5] = $rule['check'];
             }
             if (isset($rule[5])) {
                 if (function_exists($rule[5])) {
                     if (!call_user_func($rule[5], $value)) {
                         return false;
                     }
                 } else {
                     trigger_error("Validator: The check function of '{$key}' is not defined", E_USER_WARNING);
                 }
             }
         } else {
             if (array_key_exists(3, $rule)) {
                 $array[$key] = $rule[3];
             } else {
                 if (array_key_exists('default', $rule)) {
                     $array[$key] = $rule['default'];
                 } else {
                     if ((!isset($rule[4]) || $rule[4]) && (!isset($rule['mandatory']) || $rule['mandatory'])) {
                         return false;
                     }
                 }
             }
         }
     }
     return true;
 }
Example #7
0
 public function testId()
 {
     $this->assertFalse(Validator::id()->valid('not an id'));
     $this->assertTrue(Validator::id()->valid(1));
 }
Example #8
0
<?php

/// Copyright (c) 2004-2011, 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';
if (eventExists('AccessFreeSlogan')) {
    $info = fireEvent('AccessFreeSlogan', implode('/', $URLInfo['fragment']), $URLInfo);
    if (Validator::id($info)) {
        $entries = array();
        $objEntry = new Notice();
        if ($objEntry->doesExist($info)) {
            list($entries) = getEntryWithPaging($blogid, $info, true);
        } else {
            $objEntry = new Post();
            if ($objEntry->doesExist($info)) {
                list($entries, $paging) = getEntryWithPaging($blogid, $info);
            }
        }
        fireEvent('OBStart');
        require ROOT . '/interface/common/blog/begin.php';
        if (empty($entries)) {
            header('HTTP/1.1 404 Not Found');
            if (empty($skin->pageError)) {
                dress('article_rep', '<div class="TCwarning">' . _text('존재하지 않는 페이지입니다.') . '</div>', $view);
            } else {
                dress('article_rep', NULL, $view);
                dress('page_error', $skin->pageError, $view);
            }
            unset($paging);
        } else {