当前位置: 首页>>代码示例>>PHP>>正文


PHP System::varValidate方法代码示例

本文整理汇总了PHP中System::varValidate方法的典型用法代码示例。如果您正苦于以下问题:PHP System::varValidate方法的具体用法?PHP System::varValidate怎么用?PHP System::varValidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System的用法示例。


在下文中一共展示了System::varValidate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * Validates the input.
  *
  * @param Zikula_Form_View $view Reference to Zikula_Form_View object.
  *
  * @return void
  */
 public function validate(Zikula_Form_View $view)
 {
     parent::validate($view);
     if (!$this->isValid) {
         return;
     }
     if (!empty($this->text)) {
         if (!System::varValidate($this->text, 'email')) {
             $this->setError(__('Error! Invalid e-mail address.'));
         }
     }
 }
开发者ID:Silwereth,项目名称:core,代码行数:19,代码来源:EmailInput.php

示例2: validateField

 /**
  * Validate a specific field using the supplied control parameters
  *
  * @param string   $objectType The string object type.
  * @param array    $object     The object to validate.
  * @param string   $field      The field to validate.
  * @param boolean  $required   Whether or not the field is required.
  * @param string   $cmp_op     The compare operation to perform.
  * @param string   $cmp_value  The value to compare the supplied field value to. If the value starts with a ':', the argument is used as an object access key.
  * @param string   $err_msg    The error message to use if the validation fails.
  * @param callable $callback   Callback, any PHP callable.
  *
  * @return boolean A true/false value indicating whether the field validation passed or failed.
  */
 public static function validateField($objectType, $object, $field, $required, $cmp_op, $cmp_value, $err_msg, $callback = null)
 {
     if (!is_array($object)) {
         return z_exit(__f('%1s: %2s is not an array.', array('ValidationUtil::validateField', 'object')));
     }
     if (!$field) {
         return z_exit(__f('%1s: empty %2s supplied.', array('ValidationUtil::validateField', 'field')));
     }
     if (!$err_msg) {
         return z_exit(__f('%1s: empty %2s supplied.', array('ValidationUtil::validateField', 'error message')));
     }
     $rc = true;
     // if this field already has an error, don't perform further checks
     if (isset($_SESSION['validationErrors'][$objectType][$field])) {
         return $rc;
     }
     if ($required) {
         if (!isset($object[$field]) || $object[$field] === '' || $object[$field] === '0') {
             $rc = false;
         }
     }
     if ($rc && $object[$field]) {
         $postval = $object[$field];
         $testval = $cmp_value;
         if (substr($testval, 0, 1) == ':') {
             // denotes an object access key
             $v2 = substr($testval, 1);
             $testval = $object[$v2];
         }
         if ($callback) {
             $postval = call_user_func($callback, $postval);
         }
         switch ($cmp_op) {
             case 'eq ':
                 $rc = $postval === $testval;
                 break;
             case 'neq':
                 $rc = $postval != $testval;
                 break;
             case 'gt':
                 $rc = $postval !== '' && is_numeric($postval) && $postval > $testval;
                 break;
             case 'gte':
                 $rc = $postval !== '' && is_numeric($postval) && $postval >= $testval;
                 break;
             case 'lt':
                 $rc = $postval !== '' && is_numeric($postval) && $postval < $testval;
                 break;
             case 'lte':
                 $rc = $postval !== '' && is_numeric($postval) && $postval <= $testval;
                 break;
             case 'in':
                 $rc = $postval !== '' && is_array($testval) && in_array($postval, $testval);
                 break;
             case 'notin':
                 $rc = $postval !== '' && is_array($testval) && !in_array($postval, $testval);
                 break;
             case 'regexp':
                 $rc = $postval !== '' && preg_match($testval, $postval);
                 break;
             case 'url':
                 $rc = System::varValidate($postval, 'url');
                 break;
             case 'email':
                 $rc = System::varValidate($postval, 'email');
                 break;
             case 'noop':
             case '':
                 if (!$required) {
                     return z_exit(__f('%1$s: invalid cmp_op [%2$s] supplied for non-required field [%3$s].', array('ValidationUtil::validateField', $cmp_op, $field)));
                 }
                 $rc = true;
                 break;
             default:
                 return z_exit(__f('%1$s: invalid cmp_op [%2$s] supplied for field [%3$s].', array('ValidationUtil::validateField', $cmp_op, $field)));
         }
     }
     if ($rc === false) {
         if (!isset($_SESSION['validationErrors'][$objectType][$field])) {
             $_SESSION['validationErrors'][$objectType][$field] = $err_msg;
         }
     }
     return $rc;
 }
开发者ID:planetenkiller,项目名称:core,代码行数:98,代码来源:ValidationUtil.php

示例3: isHooked

 /**
  * Determine if a module is hooked by another module.
  *
  * @param string $tmodule The target module.
  * @param string $smodule The source module - default the current top most module.
  *
  * @deprecated since 1.3.0
  *
  * @return boolean True if the current module is hooked by the target module, false otherwise.
  */
 public static function isHooked($tmodule, $smodule)
 {
     if (!isset(self::$cache['ishooked'])) {
         self::$cache['ishooked'] = array();
     }
     if (isset(self::$cache['ishooked'][$tmodule][$smodule])) {
         return self::$cache['ishooked'][$tmodule][$smodule];
     }
     // define input, all numbers and booleans to strings
     $tmodule = isset($tmodule) ? (string) $tmodule : '';
     $smodule = isset($smodule) ? (string) $smodule : '';
     // validate
     if (!System::varValidate($tmodule, 'mod') || !System::varValidate($smodule, 'mod')) {
         return false;
     }
     // Get database info
     $tables = DBUtil::getTables();
     $hookscolumn = $tables['hooks_column'];
     // Get applicable hooks
     $where = "WHERE {$hookscolumn['smodule']} = '" . DataUtil::formatForStore($smodule) . "'\n                    AND {$hookscolumn['tmodule']} = '" . DataUtil::formatForStore($tmodule) . "'";
     self::$cache['ishooked'][$tmodule][$smodule] = $numitems = DBUtil::selectObjectCount('hooks', $where);
     self::$cache['ishooked'][$tmodule][$smodule] = $numitems > 0;
     return self::$cache['ishooked'][$tmodule][$smodule];
 }
开发者ID:projectesIF,项目名称:Sirius,代码行数:34,代码来源:ModUtil.php

示例4: getIDFromName

 /**
  * Get themeID given its name.
  *
  * @param string $theme The name of the theme.
  *
  * @return integer Theme ID.
  */
 public static function getIDFromName($theme)
 {
     // define input, all numbers and booleans to strings
     $theme = preg_match('/\\w+Theme$/', $theme) || !$theme ? $theme : $theme . 'Theme';
     $theme = isset($theme) ? strtolower((string) $theme) : '';
     // validate
     if (!System::varValidate($theme, 'theme')) {
         return false;
     }
     static $themeid;
     if (!is_array($themeid) || !isset($themeid[$theme])) {
         $themes = self::getThemesTable();
         if (!$themes) {
             return;
         }
         foreach ($themes as $themeinfo) {
             $tName = strtolower($themeinfo['name']);
             $themeid[$tName] = $themeinfo['id'];
             if (isset($themeinfo['displayname']) && $themeinfo['displayname']) {
                 $tdName = strtolower($themeinfo['displayname']);
                 $themeid[$tdName] = $themeinfo['id'];
             }
         }
         if (!isset($themeid[$theme])) {
             $themeid[$theme] = false;
             return false;
         }
     }
     if (isset($themeid[$theme])) {
         return $themeid[$theme];
     }
     return false;
 }
开发者ID:rtznprmpftl,项目名称:Zikulacore,代码行数:40,代码来源:ThemeUtil.php

示例5: uploadImport


//.........这里部分代码省略.........
                    }
                }
                $counter++;
                continue;
            }
            // get and check the second and following lines
            $lineArray = array();
            $lineArray = DataUtil::formatForOS(explode($delimiterChar, $line));

            // check if the line have all the needed values
            if (count($lineArray) != count($firstLineArray)) {
                return $this->__f('Error! The number of parameters in line %s is not correct. Please check your import file.', $counter);
            }
            $importValues[] = array_combine($firstLineArray, $lineArray);

            // check all the obtained values
            // check user name
            $uname = trim($importValues[$counter - 1]['uname']);
            if ($uname == '' || strlen($uname) > 25) {
                return $this->__f('Sorry! The user name is not valid in line %s. The user name is mandatory and the maximum length is 25 characters. Please check your import file.',
                    $counter);
            }

            // check if it is a valid user name
            // admins are allowed to add any usernames, even those defined as being illegal
            if (!$is_admin && $pregcondition != '') {
                // check for illegal usernames
                if (preg_match($pregcondition, $uname)) {
                    return $this->__f('Sorry! The user name %1$s is reserved and cannot be registered in line %2$s. Please check your import file.', array($uname, $counter));
                }
            }

            // check if the user name is valid because spaces or invalid characters
            if (preg_match("/[[:space:]]/", $uname) || !System::varValidate($uname, 'uname')) {
                return $this->__f('Sorry! The user name %1$s cannot contain spaces in line %2$s. Please check your import file.', array($uname, $counter));
            }

            // check if the user name is repeated
            if (in_array($uname, $usersArray)) {
                return $this->__f('Sorry! The user name %1$s is repeated in line %2$s, and it cannot be used twice for creating accounts. Please check your import file.',
                    array($uname, $counter));
            }
            $usersArray[] = $uname;

            // check password
            $pass = (string)trim($importValues[$counter - 1]['pass']);
            if ($pass == '') {
                return $this->__f('Sorry! You did not provide a password in line %s. Please check your import file.', $counter);
            }

            // check password length
            if (strlen($pass) <  $minpass) {
                return $this->__f('Sorry! The password must be at least %1$s characters long in line %2$s. Please check your import file.', array($minpass, $counter));
            }

            // check email
            $email = trim($importValues[$counter - 1]['email']);
            if ($email == '') {
                return $this->__f('Sorry! You did not provide a email in line %s. Please check your import file.', $counter);
            }

            // check email format
            if (!System::varValidate($email, 'email')) {
                return $this->__f('Sorry! The e-mail address you entered was incorrectly formatted or is unacceptable for other reasons in line %s. Please check your import file.', $counter);
            }
开发者ID:projectesIF,项目名称:Sirius,代码行数:66,代码来源:Admin.php

示例6: available

 /**
  * Check if a module is available.
  *
  * @param string  $modname The name of the module.
  * @param boolean $force   Force.
  *
  * @return boolean True if the module is available, false if not.
  */
 public static function available($modname = null, $force = false)
 {
     // define input, all numbers and booleans to strings
     $modname = preg_match('/\\w+Module$/i', $modname) || !$modname ? $modname : $modname . 'Module';
     $modname = isset($modname) ? strtolower((string) $modname) : '';
     // validate
     if (!System::varValidate($modname, 'mod')) {
         return false;
     }
     if (!isset(self::$cache['modstate'])) {
         self::$cache['modstate'] = array();
     }
     if (!isset(self::$cache['modstate'][$modname]) || $force == true) {
         $modinfo = self::getInfo(self::getIDFromName($modname));
         if (isset($modinfo['state'])) {
             self::$cache['modstate'][$modname] = $modinfo['state'];
         }
     }
     if ($force == true) {
         self::$cache['modstate'][$modname] = self::STATE_ACTIVE;
     }
     if (isset(self::$cache['modstate'][$modname]) && self::$cache['modstate'][$modname] == self::STATE_ACTIVE || preg_match('/^(extensionsmodule|adminmodule|thememodule|blockmodule|groupsmodule|permissionsmodule|usersmodule)$/i', $modname) && (isset(self::$cache['modstate'][$modname]) && (self::$cache['modstate'][$modname] == self::STATE_UPGRADED || self::$cache['modstate'][$modname] == self::STATE_INACTIVE))) {
         self::$cache['modstate'][$modname] = self::STATE_ACTIVE;
         return true;
     }
     return false;
 }
开发者ID:rtznprmpftl,项目名称:Zikulacore,代码行数:35,代码来源:ModUtil.php

示例7: getRegistrationErrors

    /**
     * Validate new user information entered by the user.
     *
     * Parameters passed in the $args array:
     * -------------------------------------
     * array  $args['reginfo']        The core registration or user information collected from the user.
     * string $args['emailagain']     The e-mail address repeated for verification.
     * string $args['passagain']      The passsword repeated for verification.
     * string $args['antispamanswer'] The answer to the antispam question provided by the user.
     * string $args['checkmode']      The "mode" that should be used when checking errors. Either 'new' or 'modify'
     *                                      The checks that are performed depend on whether the record being checked is
     *                                      for a new record or a record being modified.
     * bool   $args['setpass']        A flag indicating whether the password is to be set on the new
     *                                      or modified record, affecting error checking.
     *
     * @param array $args All parameters passed to this function.
     *
     * @return array An array containing errors organized by field.
     *
     * @throws Zikula_Exception_Forbidden Thrown if the user does not have read access.
     *
     * @throws Zikula_Exception_Fatal If a required parameter is missing from $args.
     */
    public function getRegistrationErrors($args)
    {
        $registrationErrors = array();

        if (!SecurityUtil::checkPermission('Users::', '::', ACCESS_READ)) {
            throw new Zikula_Exception_Forbidden();
        }

        $isAdmin = $this->currentUserIsAdmin();
        $isAdminOrSubAdmin = $this->currentUserIsAdminOrSubAdmin();

        if (!isset($args['reginfo']) || !is_array($args['reginfo'])) {
            throw new Zikula_Exception_Fatal($this->__('Internal Error! Missing required parameter.'));
        }
        $reginfo = $args['reginfo'];

        // Easier to to these here....
        if (isset($reginfo['uname'])) {
            $reginfo['uname'] = mb_strtolower($reginfo['uname']);
        }
        if (isset($reginfo['email'])) {
            $reginfo['email'] = mb_strtolower($reginfo['email']);
        }

        $setPassword = ($isAdminOrSubAdmin && isset($args['setpass'])) ? $args['setpass'] : true;

        $checkMode                  = isset($args['checkmode'])     ? $args['checkmode']        : 'new';
        $emailAgain                 = isset($args['emailagain'])    ? $args['emailagain']       : '';
        $passwordAgain              = isset($args['passagain'])     ? $args['passagain']        : '';
        $spamProtectionUserAnswer   = isset($args['antispamanswer'])? $args['antispamanswer']   : '';

        if (!isset($reginfo['uname']) || empty($reginfo['uname'])) {
            $registrationErrors['uname'] = $this->__('You must provide a user name.');
        } elseif (!System::varValidate($reginfo['uname'], 'uname')) {
            $registrationErrors['uname'] = $this->__('The user name you entered contains unacceptable characters. A valid user name consists of lowercase letters, numbers, underscores, periods, and/or dashes.');
        } elseif (mb_strlen($reginfo['uname']) > Users_Constant::UNAME_VALIDATION_MAX_LENGTH) {
            $registrationErrors['uname'] = $this->__f('The user name you entered is too long. The maximum length is %1$d characters.', array(Users_Constant::UNAME_VALIDATION_MAX_LENGTH));
        } else {
            $tempValid = true;
            if (!$isAdmin) {
                $illegalUserNames = $this->getVar(Users_Constant::MODVAR_REGISTRATION_ILLEGAL_UNAMES, '');
                if (!empty($illegalUserNames)) {
                    $pattern = array('/^(\s*,\s*|\s+)+/D', '/\b(\s*,\s*|\s+)+\b/D', '/(\s*,\s*|\s+)+$/D');
                    $replace = array('', '|', '');
                    $illegalUserNames = preg_replace($pattern, $replace, preg_quote($illegalUserNames, '/'));
                    if (preg_match("/^({$illegalUserNames})/iD", $reginfo['uname'])) {
                        $registrationErrors['uname'] = $this->__('The user name you entered is reserved. It cannot be used.');
                        $tempValid = false;
                    }
                }
            }

            if ($tempValid) {
                if ($checkMode == 'modify') {
                    $unameUsageCount = UserUtil::getUnameUsageCount($reginfo['uname'], $reginfo['uid']);
                } else {
                    $unameUsageCount = UserUtil::getUnameUsageCount($reginfo['uname']);
                }

                if ($unameUsageCount) {
                    $registrationErrors['uname'] = $this->__('The user name you entered has already been registered.');
                    $tempValid = false;
                }
            }
            unset($tempValid);
        }

        $emailErrors = ModUtil::apiFunc($this->name, 'registration', 'getEmailErrors', array(
            'uid'        => isset($reginfo['uid'])        ? $reginfo['uid']        : null,
            'email'      => isset($reginfo['email'])      ? $reginfo['email']      : null,
            'emailagain' => isset($emailAgain)            ? $emailAgain            : null,
            'checkmode'  => isset($checkMode)             ? $checkMode             : null,
        ));
        if (!empty($emailErrors)) {
            $registrationErrors = array_merge($registrationErrors, $emailErrors);
        }

//.........这里部分代码省略.........
开发者ID:projectesIF,项目名称:Sirius,代码行数:101,代码来源:Registration.php

示例8: handleCommand

 function handleCommand(Zikula_Form_View $view, &$args)
 {
     // Security check
     $securityCheck = ModUtil::apiFunc('EZComments', 'user', 'checkPermission', array('module' => '', 'objectid' => '', 'commentid' => $this->id, 'level' => ACCESS_EDIT));
     if (!$securityCheck) {
         return LogUtil::registerPermissionError(ModUtil::url('EZComments', 'admin', 'main'));
     }
     $ok = $view->isValid();
     $data = $view->getValues();
     $comment = ModUtil::apiFunc('EZComments', 'user', 'get', array('id' => $this->id));
     switch ($args['commandName']) {
         case 'cancel':
             // nothing to do
             break;
         case 'delete':
             // delete the comment
             // The API function is called.
             // note: the api call is a little different here since we'll really calling a hook function that will
             // normally be executed when a module is deleted. The extra nesting of the modname inside an extrainfo
             // array reflects this
             if (ModUtil::apiFunc('EZComments', 'admin', 'delete', array('id' => $this->id))) {
                 // Success
                 LogUtil::registerStatus($this->__('Done! Comment deleted.'));
                 // clear respective cache
                 ModUtil::apiFunc('EZComments', 'user', 'clearItemCache', $comment);
             }
             break;
         case 'submit':
             if (!empty($comment['anonname'])) {
                 // poster is anonymous
                 // check anon fields
                 if (empty($data['ezcomments_anonname'])) {
                     $ifield = $view->getPluginById('ezcomments_anonname');
                     $ifield->setError(DataUtil::formatForDisplay($this->__('Name for anonymous user is missing.')));
                     $ok = false;
                 }
                 // anonmail must be valid - really necessary if an admin changes this?
                 if (empty($data['ezcomments_anonmail']) || !System::varValidate($data['ezcomments_anonmail'], 'email')) {
                     $ifield = $view->getPluginById('ezcomments_anonmail');
                     $ifield->setError(DataUtil::formatForDisplay($this->__('Email address of anonymous user is missing or invalid.')));
                     $ok = false;
                 }
                 // anonwebsite must be valid
                 if (!empty($data['ezcomments_anonwebsite']) && !System::varValidate($data['ezcomments_anonmail'], 'url')) {
                     $ifield = $view->getPluginById('ezcomments_anonwebsite');
                     $ifield->setError(DataUtil::formatForDisplay($this->__('Website of anonymous user is invalid.')));
                     $ok = false;
                 }
             } else {
                 // user has not posted as anonymous, continue normally
             }
             // no check on ezcomments_subject as this may be empty
             if (empty($data['ezcomments_comment'])) {
                 $ifield = $view->getPluginById('ezcomments_comment');
                 $ifield->setError(DataUtil::formatForDisplay($this->__('Error! The comment contains no text.')));
                 $ok = false;
             }
             if (!$ok) {
                 return false;
             }
             // Call the API to update the item.
             if (ModUtil::apiFunc('EZComments', 'admin', 'update', array('id' => $this->id, 'subject' => $data['ezcomments_subject'], 'comment' => $data['ezcomments_comment'], 'status' => (int) $data['ezcomments_status'], 'anonname' => $data['ezcomments_anonname'], 'anonmail' => $data['ezcomments_anonmail'], 'anonwebsite' => $data['ezcomments_anonwebsite']))) {
                 // Success
                 LogUtil::registerStatus($this->__('Done! Comment updated.'));
                 // clear respective cache
                 ModUtil::apiFunc('EZComments', 'user', 'clearItemCache', $comment);
             }
             break;
     }
     if ($data['ezcomments_sendmeback'] == true) {
         return System::redirect($comment['url'] . "#comments_{$comment['modname']}_{$comment['objectid']}");
     }
     return System::redirect(ModUtil::url('EZComments', 'admin', 'main'));
 }
开发者ID:rmaiwald,项目名称:EZComments,代码行数:74,代码来源:Modify.php

示例9: pnVarValidate

/**
 * validate a zikula variable
 *
 * @deprecated Deprecated since version 1.3.0.
 * @see System::varValidate()
 *
 * @param $var   the variable to validate
 * @param $type  the type of the validation to perform (email, url etc.)
 * @param $args  optional array with validation-specific settings (never used...)
 * @return bool true if the validation was successful, false otherwise
 */
function pnVarValidate($var, $type, $args = 0)
{
    LogUtil::log(__f('Warning! Function %1$s is deprecated. Please use %2$s instead.', array(__FUNCTION__, 'System::varValidate')), E_USER_DEPRECATED);
    return System::varValidate($var, $type, $args);
}
开发者ID:projectesIF,项目名称:Sirius,代码行数:16,代码来源:Api.php


注:本文中的System::varValidate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。