本文整理汇总了PHP中user_error函数的典型用法代码示例。如果您正苦于以下问题:PHP user_error函数的具体用法?PHP user_error怎么用?PHP user_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了user_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convert_uudecode
function convert_uudecode($string)
{
// Sanity check
if (!is_scalar($string)) {
user_error('convert_uuencode() expects parameter 1 to be string, ' . gettype($string) . ' given', E_USER_WARNING);
return false;
}
if (strlen($string) < 8) {
user_error('convert_uuencode() The given parameter is not a valid uuencoded string', E_USER_WARNING);
return false;
}
$decoded = '';
foreach (explode("\n", $string) as $line) {
$c = count($bytes = unpack('c*', substr(trim($line), 1)));
while ($c % 4) {
$bytes[++$c] = 0;
}
foreach (array_chunk($bytes, 4) as $b) {
$b0 = $b[0] == 0x60 ? 0 : $b[0] - 0x20;
$b1 = $b[1] == 0x60 ? 0 : $b[1] - 0x20;
$b2 = $b[2] == 0x60 ? 0 : $b[2] - 0x20;
$b3 = $b[3] == 0x60 ? 0 : $b[3] - 0x20;
$b0 <<= 2;
$b0 |= $b1 >> 4 & 0x3;
$b1 <<= 4;
$b1 |= $b2 >> 2 & 0xf;
$b2 <<= 6;
$b2 |= $b3 & 0x3f;
$decoded .= pack('c*', $b0, $b1, $b2);
}
}
return rtrim($decoded, "");
}
示例2: republish
function republish($original)
{
if (self::$disable_realtime) {
return;
}
$urls = array();
if ($this->owner->hasMethod('pagesAffectedByChanges')) {
$urls = $this->owner->pagesAffectedByChanges($original);
} else {
$pages = Versioned::get_by_stage('SiteTree', 'Live', '', '', '', 10);
if ($pages) {
foreach ($pages as $page) {
$urls[] = $page->AbsoluteLink();
}
}
}
// Note: Similiar to RebuildStaticCacheTask->rebuildCache()
foreach ($urls as $i => $url) {
if (!is_string($url)) {
user_error("Bad URL: " . var_export($url, true), E_USER_WARNING);
continue;
}
// Remove leading slashes from all URLs (apart from the homepage)
if (substr($url, -1) == '/' && $url != '/') {
$url = substr($url, 0, -1);
}
$urls[$i] = $url;
}
$urls = array_unique($urls);
$this->publishPages($urls);
}
示例3: convert_uuencode
function convert_uuencode($string)
{
// Sanity check
if (!is_scalar($string)) {
user_error('convert_uuencode() expects parameter 1 to be string, ' . gettype($string) . ' given', E_USER_WARNING);
return false;
}
$u = 0;
$encoded = '';
while ($c = count($bytes = unpack('c*', substr($string, $u, 45)))) {
$u += 45;
$encoded .= pack('c', $c + 0x20);
while ($c % 3) {
$bytes[++$c] = 0;
}
foreach (array_chunk($bytes, 3) as $b) {
$b0 = ($b[0] & 0xfc) >> 2;
$b1 = (($b[0] & 0x3) << 4) + (($b[1] & 0xf0) >> 4);
$b2 = (($b[1] & 0xf) << 2) + (($b[2] & 0xc0) >> 6);
$b3 = $b[2] & 0x3f;
$b0 = $b0 ? $b0 + 0x20 : 0x60;
$b1 = $b1 ? $b1 + 0x20 : 0x60;
$b2 = $b2 ? $b2 + 0x20 : 0x60;
$b3 = $b3 ? $b3 + 0x20 : 0x60;
$encoded .= pack('c*', $b0, $b1, $b2, $b3);
}
$encoded .= "\n";
}
// Add termination characters
$encoded .= "`\n";
return $encoded;
}
示例4: str_word_count
function str_word_count($string, $format = null)
{
if ($format !== 1 && $format !== 2 && $format !== null) {
user_error('str_word_count() The specified format parameter, "' . $format . '" is invalid', E_USER_WARNING);
return false;
}
$word_string = preg_replace('/[0-9]+/', '', $string);
$word_array = preg_split('/[^A-Za-z0-9_\']+/', $word_string, -1, PREG_SPLIT_NO_EMPTY);
switch ($format) {
case null:
$result = count($word_array);
break;
case 1:
$result = $word_array;
break;
case 2:
$lastmatch = 0;
$word_assoc = array();
foreach ($word_array as $word) {
$word_assoc[$lastmatch = strpos($string, $word, $lastmatch)] = $word;
$lastmatch += strlen($word);
}
$result = $word_assoc;
break;
}
return $result;
}
示例5: handleRequest
/**
* @uses ModelAsController::getNestedController()
* @param SS_HTTPRequest $request
* @param DataModel $model
* @return SS_HTTPResponse
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model)
{
$this->setRequest($request);
$this->setDataModel($model);
$this->pushCurrent();
// Create a response just in case init() decides to redirect
$this->response = new SS_HTTPResponse();
$this->init();
// If we had a redirection or something, halt processing.
if ($this->response->isFinished()) {
$this->popCurrent();
return $this->response;
}
// If the database has not yet been created, redirect to the build page.
if (!DB::is_active() || !ClassInfo::hasTable('SiteTree')) {
$this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
$this->popCurrent();
return $this->response;
}
try {
$result = $this->getNestedController();
if ($result instanceof RequestHandler) {
$result = $result->handleRequest($this->getRequest(), $model);
} else {
if (!$result instanceof SS_HTTPResponse) {
user_error("ModelAsController::getNestedController() returned bad object type '" . get_class($result) . "'", E_USER_WARNING);
}
}
} catch (SS_HTTPResponse_Exception $responseException) {
$result = $responseException->getResponse();
}
$this->popCurrent();
return $result;
}
示例6: read
function read($pref_name, $user_id = false, $die_on_error = false)
{
$pref_name = db_escape_string($pref_name);
$profile = false;
if (!$user_id) {
$user_id = $_SESSION["uid"];
@($profile = $_SESSION["profile"]);
} else {
$user_id = sprintf("%d", $user_id);
}
if (isset($this->cache[$pref_name])) {
$tuple = $this->cache[$pref_name];
return $this->convert($tuple["value"], $tuple["type"]);
}
if ($profile) {
$profile_qpart = "profile = '{$profile}' AND";
} else {
$profile_qpart = "profile IS NULL AND";
}
if (get_schema_version() < 63) {
$profile_qpart = "";
}
$result = db_query("SELECT value,ttrss_prefs_types.type_name as type_name\n FROM\n ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types\n WHERE\n {$profile_qpart}\n ttrss_user_prefs.pref_name = '{$pref_name}' AND\n ttrss_prefs_types.id = type_id AND\n owner_uid = '{$user_id}' AND\n ttrss_user_prefs.pref_name = ttrss_prefs.pref_name");
if (db_num_rows($result) > 0) {
$value = db_fetch_result($result, 0, "value");
$type_name = db_fetch_result($result, 0, "type_name");
if ($user_id == $_SESSION["uid"]) {
$this->cache[$pref_name]["type"] = $type_name;
$this->cache[$pref_name]["value"] = $value;
}
return $this->convert($value, $type_name);
}
user_error("Fatal error, unknown preferences key: {$pref_name} (owner: {$user_id})", $die_on_error ? E_USER_ERROR : E_USER_WARNING);
return null;
}
示例7: Factory
public static function Factory(&$source, $conf_file = NULL, $conf_section = NULL, $strict = TRUE)
{
if (!is_array($source)) {
user_error('$source ' . $source . ' is not an array', E_USER_NOTICE);
}
$cage = new Inspekt_Cage_Session();
$cage->_setSource($source);
$cage->_parseAndApplyAutoFilters($conf_file);
if (ini_get('session.use_cookies') || ini_get('session.use_only_cookies')) {
if (isset($_COOKIE) && isset($_COOKIE[session_name()])) {
session_id($_COOKIE[session_name()]);
} elseif ($cookie = Inspekt::makeSessionCage()) {
session_id($cookie->getAlnum(session_name()));
}
} else {
// we're using session ids passed via GET
if (isset($_GET) && isset($_GET[session_name()])) {
session_id($_GET[session_name()]);
} elseif ($cookie = Inspekt::makeSessionCage()) {
session_id($cookie->getAlnum(session_name()));
}
}
if ($strict) {
$source = NULL;
}
return $cage;
register_shutdown_function();
register_shutdown_function(array($this, '_repopulateSession'));
}
示例8: __construct
function __construct($agentData, $sessionLink = '', $POST = true, $formVarname = 'form')
{
if ($agentData) {
if ($formVarname) {
if (isset($agentData->{$formVarname})) {
user_error(__CLASS__ . ": Overwriting existing \$agentData->{$formVarname}! If this is the intended behavior, unset(\$agentData->{$formVarname}) to remove this warning.");
}
$agentData->{$formVarname} = $this;
}
$this->agentData = $agentData;
} else {
$this->agentData = false;
}
$this->POST = (bool) $POST;
if ($this->POST) {
p::canPost();
if (isset($_POST['_POST_BACKUP'])) {
// This should only be used for field persistence, not as valid input
$this->rawValues =& $GLOBALS['_POST_BACKUP'];
// $this->filesValues =& $GLOBALS['_FILES_BACKUP'];
} else {
$this->rawValues =& $_POST;
$this->filesValues =& $_FILES;
}
} else {
$this->rawValues =& $_GET;
}
if ($sessionLink) {
s::bind($sessionLink, $this->sessionLink);
if (!$this->sessionLink) {
$this->sessionLink = array(0);
}
}
}
示例9: __construct
/**
* Most of the code below was copied from ManyManyComplexTableField.
* Painful, but necessary, until PHP supports multiple inheritance.
*/
function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "Created DESC", $sourceJoin = "")
{
parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
$manyManyTable = false;
$classes = array_reverse(ClassInfo::ancestry($this->controllerClass()));
foreach ($classes as $class) {
if ($class != "Object") {
$singleton = singleton($class);
$manyManyRelations = $singleton->uninherited('many_many', true);
if (isset($manyManyRelations) && array_key_exists($this->name, $manyManyRelations)) {
$this->manyManyParentClass = $class;
$manyManyTable = $class . '_' . $this->name;
break;
}
$belongsManyManyRelations = $singleton->uninherited('belongs_many_many', true);
if (isset($belongsManyManyRelations) && array_key_exists($this->name, $belongsManyManyRelations)) {
$this->manyManyParentClass = $class;
$manyManyTable = $belongsManyManyRelations[$this->name] . '_' . $this->name;
break;
}
}
}
if (!$manyManyTable) {
user_error("I could not find the relation {$this}-name in " . $this->controllerClass() . " or any of its ancestors.", E_USER_WARNING);
}
$tableClasses = ClassInfo::dataClassesFor($this->sourceClass);
$source = array_shift($tableClasses);
$sourceField = $this->sourceClass;
if ($this->manyManyParentClass == $sourceField) {
$sourceField = 'Child';
}
$parentID = $this->controller->ID;
$this->sourceJoin .= " LEFT JOIN `{$manyManyTable}` ON (`{$source}`.`ID` = `{$sourceField}ID` AND `{$this->manyManyParentClass}ID` = '{$parentID}')";
$this->joinField = 'Checked';
}
示例10: strripos
function strripos($haystack, $needle, $offset = null)
{
// Sanity check
if (!is_scalar($haystack)) {
user_error('strripos() expects parameter 1 to be scalar, ' . gettype($haystack) . ' given', E_USER_WARNING);
return false;
}
if (!is_scalar($needle)) {
user_error('strripos() expects parameter 2 to be scalar, ' . gettype($needle) . ' given', E_USER_WARNING);
return false;
}
if (!is_int($offset) && !is_bool($offset) && !is_null($offset)) {
user_error('strripos() expects parameter 3 to be long, ' . gettype($offset) . ' given', E_USER_WARNING);
return false;
}
// Initialise variables
$needle = strtolower($needle);
$haystack = strtolower($haystack);
$needle_fc = $needle[0];
$needle_len = strlen($needle);
$haystack_len = strlen($haystack);
$offset = (int) $offset;
$leftlimit = $offset >= 0 ? $offset : 0;
$p = $offset >= 0 ? $haystack_len : $haystack_len + $offset + 1;
// Reverse iterate haystack
while (--$p >= $leftlimit) {
if ($needle_fc === $haystack[$p] && substr($haystack, $p, $needle_len) === $needle) {
return $p;
}
}
return false;
}
示例11: array_diff_assoc
function array_diff_assoc()
{
// Check we have enough arguments
$args = func_get_args();
$count = count($args);
if (count($args) < 2) {
user_error('Wrong parameter count for array_diff_assoc()', E_USER_WARNING);
return;
}
// Check arrays
for ($i = 0; $i < $count; $i++) {
if (!is_array($args[$i])) {
user_error('array_diff_assoc() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING);
return;
}
}
// Get the comparison array
$array_comp = array_shift($args);
--$count;
// Traverse values of the first array
foreach ($array_comp as $key => $value) {
// Loop through the other arrays
for ($i = 0; $i < $count; $i++) {
// Loop through this arrays key/value pairs and compare
foreach ($args[$i] as $comp_key => $comp_value) {
if ((string) $key === (string) $comp_key && (string) $value === (string) $comp_value) {
unset($array_comp[$key]);
}
}
}
}
return $array_comp;
}
示例12: ob_handler
function ob_handler($buffer)
{
$this->releaseLock();
$this->queueNext();
'' !== $buffer && user_error($buffer);
return '';
}
示例13: transform
public function transform(FormField $field)
{
// Look for a performXXTransformation() method on the field itself.
// performReadonlyTransformation() is a pretty commonly applied method.
// Otherwise, look for a transformXXXField() method on this object.
// This is more commonly done in custom transformations
// We iterate through each array simultaneously, looking at [0] of both, then [1] of both.
// This provides a more natural failover scheme.
$transNames = array_reverse(array_values(ClassInfo::ancestry($this->class)));
$fieldClasses = array_reverse(array_values(ClassInfo::ancestry($field->class)));
$len = max(sizeof($transNames), sizeof($fieldClasses));
for ($i = 0; $i < $len; $i++) {
// This is lets fieldClasses be longer than transNames
if ($transName = $transNames[$i]) {
if ($field->hasMethod('perform' . $transName)) {
$funcName = 'perform' . $transName;
//echo "<li>$field->class used $funcName";
return $field->{$funcName}($this);
}
}
// And this one does the reverse.
if ($fieldClass = $fieldClasses[$i]) {
if ($this->hasMethod('transform' . $fieldClass)) {
$funcName = 'transform' . $fieldClass;
//echo "<li>$field->class used $funcName";
return $this->{$funcName}($field);
}
}
}
user_error("FormTransformation:: Can't perform '{$this->class}' on '{$field->class}'", E_USER_ERROR);
}
示例14: array_walk_recursive
function array_walk_recursive(&$input, $funcname)
{
if (!is_callable($funcname)) {
if (is_array($funcname)) {
$funcname = $funcname[0] . '::' . $funcname[1];
}
user_error('array_walk_recursive() Not a valid callback ' . $user_func, E_USER_WARNING);
return;
}
if (!is_array($input)) {
user_error('array_walk_recursive() The argument should be an array', E_USER_WARNING);
return;
}
$args = func_get_args();
foreach ($input as $key => $item) {
if (is_array($item)) {
array_walk_recursive($item, $funcname, $args);
$input[$key] = $item;
} else {
$args[0] =& $item;
$args[1] =& $key;
call_user_func_array($funcname, $args);
$input[$key] = $item;
}
}
}
示例15: update_form
/**
* Add the spam protector field to a form
* @param Form the form that the protecter field added into
* @param string the name of the field that the protecter field will be added in front of
* @param array an associative array
* with the name of the spam web service's field, for example post_title, post_body, author_name
* and a string of field names
* @param String Title for the captcha field
* @param String RightTitle for the captcha field
* @return SpamProtector object on success or null if the spamprotector class is not found
* also null if spamprotectorfield creation fails.
*/
static function update_form($form, $before = null, $fieldsToSpamServiceMapping = array(), $title = null, $rightTitle = null)
{
$protectorClass = self::get_spam_protector();
// Don't update if no protector is set
if (!$protectorClass) {
return false;
}
if (!class_exists($protectorClass)) {
return user_error("Spam Protector class '{$protectorClass}' does not exist. Please define a valid Spam Protector", E_USER_WARNING);
}
try {
$protector = new $protectorClass();
$field = $protector->getFormField("Captcha", $title, null, $form, $rightTitle);
if ($field) {
// update the mapping
$field->setFieldMapping($fieldsToSpamServiceMapping);
// add the form field
if ($before && $form->Fields()->fieldByName($before)) {
$form->Fields()->insertBefore($field, $before);
} else {
$form->Fields()->push($field);
}
}
} catch (Exception $e) {
return user_error("SpamProtectorManager::update_form(): '{$protectorClass}' is not correctly set up. " . $e, E_USER_WARNING);
}
}