示例#1
0
 /**
  * POST data validator function used when creating/editing posts
  *
  * @param string    $thing "request"/"reservation"
  * @param array     $array Array to output the checked data into
  * @param Post|null $Post  Optional, exsting post to compare new data against
  */
 static function checkPostDetails($thing, &$array, $Post = null)
 {
     $editing = !empty($Post);
     $label = (new Input('label', 'string', array(Input::IS_OPTIONAL => true, Input::IN_RANGE => [3, 255], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_RANGE => 'The description must be between @min and @max characters'))))->out();
     if (isset($label)) {
         if (!$editing || $label !== $Post->label) {
             CoreUtils::checkStringValidity($label, 'The description', INVERSE_PRINTABLE_ASCII_PATTERN);
             CoreUtils::set($array, 'label', $label);
         }
     } else {
         if (!$editing && $thing !== 'reservation') {
             Response::fail('Description cannot be empty');
         } else {
             CoreUtils::set($array, 'label', null);
         }
     }
     if ($thing === 'request') {
         $type = (new Input('type', function ($value) {
             if (!in_array($value, array('chr', 'obj', 'bg'))) {
                 return Input::ERROR_INVALID;
             }
         }, array(Input::IS_OPTIONAL => true, Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_INVALID => "Request type (@value) is invalid"))))->out();
         if (!isset($type) && !$editing) {
             respnd("Missing request type");
         }
         if (!$editing || isset($type) && $type !== $Post->type) {
             CoreUtils::set($array, 'type', $type);
         }
         if (Permission::sufficient('developer')) {
             $reserved_at = self::validateReservedAt();
             if (isset($reserved_at)) {
                 if ($reserved_at !== strtotime($Post->reserved_at)) {
                     CoreUtils::set($array, 'reserved_at', date('c', $reserved_at));
                 }
             } else {
                 CoreUtils::set($array, 'reserved_at', null);
             }
         }
     }
     if (Permission::sufficient('developer')) {
         $posted = (new Input('posted', 'timestamp', array(Input::IS_OPTIONAL => true, Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_INVALID => '"Posted" timestamp (@value) is invalid'))))->out();
         if (isset($posted) && $posted !== strtotime($Post->posted)) {
             CoreUtils::set($array, 'posted', date('c', $posted));
         }
         $finished_at = self::validateFinishedAt();
         if (isset($finished_at)) {
             if ($finished_at !== strtotime($Post->finished_at)) {
                 CoreUtils::set($array, 'finished_at', date('c', $finished_at));
             }
         } else {
             CoreUtils::set($array, 'finished_at', null);
         }
     }
 }
示例#2
0
                 }
             }
             Response::fail("Unsupported prefix: {$match[1]}. " . (isset($mostSimilar) ? "<em>Did you mean <span class='color-ui'>{$mostSimilar}</span></em>?" : 'Use a backslash if the colon is part of the title (e.g. <code>\\:</code>)'));
         }
         $title = Episodes::removeTitlePrefix($value);
         if (Input::checkStringLength($title, $range, $code)) {
             return $code;
         }
         $value = "{$match[1]}: {$title}";
     } else {
         if (Input::checkStringLength($value, $range, $code)) {
             return $code;
         }
     }
 }, array(Input::IN_RANGE => [5, 35], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => "{$What} title is missing", Input::ERROR_RANGE => "{$What} title must be between @min and @max characters", 'prefix-movieonly' => "Prefixes can only be used for movies"))))->out();
 CoreUtils::checkStringValidity($insert['title'], "{$What} title", INVERSE_EP_TITLE_PATTERN);
 $airs = (new Input('airs', 'timestamp', array(Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'No air date & time specified', Input::ERROR_INVALID => 'Invalid air date and/or time (@value) specified'))))->out();
 if (empty($airs)) {
     Response::fail('Please specify an air date & time');
 }
 $insert['airs'] = date('c', strtotime('this minute', $airs));
 if ($editing) {
     if (!$Database->whereEp($Episode)->update('episodes', $insert)) {
         Response::dbError('Updating episode failed');
     }
 } else {
     if (!$Database->insert('episodes', $insert)) {
         Response::dbError('Episode creation failed');
     }
 }
 if (!$editing || $SeasonChanged || $EpisodeChanged) {
示例#3
0
 $data = array();
 $label = (new Input('label', 'string', array(Input::IN_RANGE => [3, 35], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Link label is missing', Input::ERROR_RANGE => 'Link label must be between @min and @max characters long'))))->out();
 if ($creating || $Link['label'] !== $label) {
     CoreUtils::checkStringValidity($label, 'Link label', INVERSE_PRINTABLE_ASCII_PATTERN);
     $data['label'] = $label;
 }
 $url = (new Input('url', 'url', array(Input::IN_RANGE => [3, 255], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Link URL is missing', Input::ERROR_RANGE => 'Link URL must be between @min and @max characters long'))))->out();
 if ($creating || $Link['url'] !== $url) {
     $data['url'] = $url;
 }
 $title = (new Input('title', 'string', array(Input::IS_OPTIONAL => true, Input::IN_RANGE => [3, 255], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_RANGE => 'Link title must be between @min and @max characters long'))))->out();
 if (!isset($title)) {
     $data['title'] = '';
 } else {
     if ($creating || $Link['title'] !== $title) {
         CoreUtils::checkStringValidity($title, 'Link title', INVERSE_PRINTABLE_ASCII_PATTERN);
         $data['title'] = $title;
     }
 }
 $minrole = (new Input('minrole', function ($value) {
     if (empty(Permission::ROLES_ASSOC[$value]) || !Permission::sufficient('user', $value)) {
         Response::fail();
     }
 }, array(Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Minumum role is missing', Input::ERROR_INVALID => 'Minumum role (@value) is invalid'))))->out();
 if ($creating || $Link['minrole'] !== $minrole) {
     $data['minrole'] = $minrole;
 }
 if (empty($data)) {
     Response::fail('Nothing was changed');
 }
 $query = $creating ? $Database->insert('usefullinks', $data) : $Database->where('id', $Link['id'])->update('usefullinks', $data);
示例#4
0
 function testCheckStringValidity()
 {
     $result = CoreUtils::checkStringValidity('Oh my~!', 'Exclamation', '[^A-Za-z!\\s]', true);
     self::assertEquals("Exclamation (Oh my~!) contains an invalid character: ~", $result);
     $result = CoreUtils::checkStringValidity('A_*cbe>#', 'String', '[^A-Za-z]', true);
     self::assertEquals("String (A_*cbe&gt;#) contains the following invalid characters: _, *, &gt; and #", $result);
 }
示例#5
0
     }
     $Group = array('groupid' => $GroupID);
 } else {
     $CGDb->where('groupid', $Group['groupid'])->update('colorgroups', $data);
 }
 $origColors = $adding ? null : ColorGroups::getColors($Group['groupid']);
 $recvColors = (new Input('Colors', 'json', array(Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => "Missing list of {$color}s", Input::ERROR_INVALID => "List of {$color}s is invalid"))))->out();
 $colors = array();
 foreach ($recvColors as $part => $c) {
     $append = array('order' => $part);
     $index = "(index: {$part})";
     if (empty($c['label'])) {
         Response::fail("You must specify a {$color} name {$index}");
     }
     $label = CoreUtils::trim($c['label']);
     CoreUtils::checkStringValidity($label, "{$Color} {$index} name", INVERSE_PRINTABLE_ASCII_PATTERN);
     $ll = CoreUtils::length($label);
     if ($ll < 3 || $ll > 30) {
         Response::fail("The {$color} name must be between 3 and 30 characters in length {$index}");
     }
     $append['label'] = $label;
     if (empty($c['hex'])) {
         Response::fail("You must specify a {$color} code {$index}");
     }
     $hex = CoreUtils::trim($c['hex']);
     if (!$HEX_COLOR_REGEX->match($hex, $_match)) {
         Response::fail("HEX {$color} is in an invalid format {$index}");
     }
     $append['hex'] = '#' . strtoupper($_match[1]);
     $colors[] = $append;
 }