예제 #1
0
 /**
  * Checks if route info is valid and performs any required sanitation
  *
  * @param array $data
  * @return bool Returns TRUE iff data is valid
  */
 protected static function validInput(array &$data)
 {
     //if we have nothing we set actions to create, settings
     //if we have a channelid and no action1 or 2 we set actions to create, settings.
     //if we have no channelid and anything but create, settings then we throw an exception
     // if no action is defined, use index
     if (empty($data[self::$actionKey])) {
         $data[self::$actionKey] = 'create';
     }
     if (empty($data['action2'])) {
         $data['action2'] = 'settings';
     }
     if (!isset($data['guid']) or empty($data['guid'])) {
         $data['guid'] = vB_Xml_Export_Route::createGUID($data);
     }
     if ($data[self::$actionKey] == 'admin') {
         return isset($data['nodeid']) and in_array($data['action2'], self::$adminActions);
     }
     if ($data[self::$actionKey] == 'create') {
         return in_array($data['action2'], self::$createActions);
     }
     return false;
 }
예제 #2
0
 /**
  * Checks if route info is valid and performs any required sanitation
  *
  * @param array $data
  * @return bool Returns TRUE iff data is valid
  */
 protected static function validInput(array &$data)
 {
     if (!isset($data['guid']) or empty($data['guid'])) {
         $data['guid'] = vB_Xml_Export_Route::createGUID($data);
     }
     $prefixLength = strlen($data['prefix']);
     if (!isset($data['prefix']) or $prefixLength > self::PREFIX_MAXSIZE) {
         if (defined('VB_AREA') and in_array(VB_AREA, array('Install', 'Upgrade'))) {
             // We need to automatically shorten the URL
             $parts = array_reverse(explode('/', $data['prefix']));
             $newPath[] = $part = array_shift($parts);
             $length = strlen($part);
             if ($length > self::PREFIX_MAXSIZE) {
                 // the last element is itself too long
                 $newPrefix = substr($part, 0, self::PREFIX_MAXSIZE);
             } else {
                 // prepend parts until we reach the limit
                 while ($part = array_shift($parts) and $length + 1 + strlen($part) <= self::PREFIX_MAXSIZE) {
                     array_unshift($newPath, $part);
                     $length += 1 + strlen($part);
                 }
                 $newPrefix = implode('/', $newPath);
             }
             // replace in regex
             $data['regex'] = preg_replace("#^{$data['prefix']}#", $newPrefix, $data['regex']);
             $data['prefix'] = $newPrefix;
         } else {
             throw new vB_Exception_Api('url_too_long', array($prefixLength, self::PREFIX_MAXSIZE));
         }
     }
     if (!isset($data['regex']) or strlen($data['regex']) > self::REGEX_MAXSIZE) {
         return false;
     }
     return true;
 }