本文整理汇总了PHP中Notice::checkDupes方法的典型用法代码示例。如果您正苦于以下问题:PHP Notice::checkDupes方法的具体用法?PHP Notice::checkDupes怎么用?PHP Notice::checkDupes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Notice
的用法示例。
在下文中一共展示了Notice::checkDupes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveNew
/**
* Save a new notice and push it out to subscribers' inboxes.
* Poster's permissions are checked before sending.
*
* @param int $profile_id Profile ID of the poster
* @param string $content source message text; links may be shortened
* per current user's preference
* @param string $source source key ('web', 'api', etc)
* @param array $options Associative array of optional properties:
* string 'created' timestamp of notice; defaults to now
* int 'is_local' source/gateway ID, one of:
* Notice::LOCAL_PUBLIC - Local, ok to appear in public timeline
* Notice::REMOTE - Sent from a remote service;
* hide from public timeline but show in
* local "and friends" timelines
* Notice::LOCAL_NONPUBLIC - Local, but hide from public timeline
* Notice::GATEWAY - From another non-OStatus service;
* will not appear in public views
* float 'lat' decimal latitude for geolocation
* float 'lon' decimal longitude for geolocation
* int 'location_id' geoname identifier
* int 'location_ns' geoname namespace to interpret location_id
* int 'reply_to'; notice ID this is a reply to
* int 'repeat_of'; notice ID this is a repeat of
* string 'uri' unique ID for notice; a unique tag uri (can be url or anything too)
* string 'url' permalink to notice; defaults to local notice URL
* string 'rendered' rendered HTML version of content
* array 'replies' list of profile URIs for reply delivery in
* place of extracting @-replies from content.
* array 'groups' list of group IDs to deliver to, in place of
* extracting ! tags from content
* array 'tags' list of hashtag strings to save with the notice
* in place of extracting # tags from content
* array 'urls' list of attached/referred URLs to save with the
* notice in place of extracting links from content
* boolean 'distribute' whether to distribute the notice, default true
* string 'object_type' URL of the associated object type (default ActivityObject::NOTE)
* string 'verb' URL of the associated verb (default ActivityVerb::POST)
* int 'scope' Scope bitmask; default to SITE_SCOPE on private sites, 0 otherwise
*
* @fixme tag override
*
* @return Notice
* @throws ClientException
*/
static function saveNew($profile_id, $content, $source, array $options = null)
{
$defaults = array('uri' => null, 'url' => null, 'conversation' => null, 'reply_to' => null, 'repeat_of' => null, 'scope' => null, 'distribute' => true, 'object_type' => null, 'verb' => null);
if (!empty($options) && is_array($options)) {
$options = array_merge($defaults, $options);
extract($options);
} else {
extract($defaults);
}
if (!isset($is_local)) {
$is_local = Notice::LOCAL_PUBLIC;
}
$profile = Profile::getKV('id', $profile_id);
if (!$profile instanceof Profile) {
// TRANS: Client exception thrown when trying to save a notice for an unknown user.
throw new ClientException(_('Problem saving notice. Unknown user.'));
}
$user = User::getKV('id', $profile_id);
if ($user instanceof User) {
// Use the local user's shortening preferences, if applicable.
$final = $user->shortenLinks($content);
} else {
$final = common_shorten_links($content);
}
if (Notice::contentTooLong($final)) {
// TRANS: Client exception thrown if a notice contains too many characters.
throw new ClientException(_('Problem saving notice. Too long.'));
}
if (common_config('throttle', 'enabled') && !Notice::checkEditThrottle($profile_id)) {
common_log(LOG_WARNING, 'Excessive posting by profile #' . $profile_id . '; throttled.');
// TRANS: Client exception thrown when a user tries to post too many notices in a given time frame.
throw new ClientException(_('Too many notices too fast; take a breather ' . 'and post again in a few minutes.'));
}
if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) {
common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.');
// TRANS: Client exception thrown when a user tries to post too many duplicate notices in a given time frame.
throw new ClientException(_('Too many duplicate messages too quickly;' . ' take a breather and post again in a few minutes.'));
}
if (!$profile->hasRight(Right::NEWNOTICE)) {
common_log(LOG_WARNING, "Attempted post from user disallowed to post: " . $profile->nickname);
// TRANS: Client exception thrown when a user tries to post while being banned.
throw new ClientException(_('You are banned from posting notices on this site.'), 403);
}
$notice = new Notice();
$notice->profile_id = $profile_id;
$autosource = common_config('public', 'autosource');
// Sandboxed are non-false, but not 1, either
if (!$profile->hasRight(Right::PUBLICNOTICE) || $source && $autosource && in_array($source, $autosource)) {
$notice->is_local = Notice::LOCAL_NONPUBLIC;
} else {
$notice->is_local = $is_local;
}
if (!empty($created)) {
$notice->created = $created;
} else {
//.........这里部分代码省略.........
示例2: saveNew
/**
* Save a new notice and push it out to subscribers' inboxes.
* Poster's permissions are checked before sending.
*
* @param int $profile_id Profile ID of the poster
* @param string $content source message text; links may be shortened
* per current user's preference
* @param string $source source key ('web', 'api', etc)
* @param array $options Associative array of optional properties:
* string 'created' timestamp of notice; defaults to now
* int 'is_local' source/gateway ID, one of:
* Notice::LOCAL_PUBLIC - Local, ok to appear in public timeline
* Notice::REMOTE - Sent from a remote service;
* hide from public timeline but show in
* local "and friends" timelines
* Notice::LOCAL_NONPUBLIC - Local, but hide from public timeline
* Notice::GATEWAY - From another non-OStatus service;
* will not appear in public views
* float 'lat' decimal latitude for geolocation
* float 'lon' decimal longitude for geolocation
* int 'location_id' geoname identifier
* int 'location_ns' geoname namespace to interpret location_id
* int 'reply_to'; notice ID this is a reply to
* int 'repeat_of'; notice ID this is a repeat of
* string 'uri' unique ID for notice; defaults to local notice URL
* string 'url' permalink to notice; defaults to local notice URL
* string 'rendered' rendered HTML version of content
* array 'replies' list of profile URIs for reply delivery in
* place of extracting @-replies from content.
* array 'groups' list of group IDs to deliver to, in place of
* extracting ! tags from content
* array 'tags' list of hashtag strings to save with the notice
* in place of extracting # tags from content
* array 'urls' list of attached/referred URLs to save with the
* notice in place of extracting links from content
* boolean 'distribute' whether to distribute the notice, default true
* string 'object_type' URL of the associated object type (default ActivityObject::NOTE)
* string 'verb' URL of the associated verb (default ActivityVerb::POST)
* int 'scope' Scope bitmask; default to SITE_SCOPE on private sites, 0 otherwise
*
* @fixme tag override
*
* @return Notice
* @throws ClientException
*/
static function saveNew($profile_id, $content, $source, $options = null)
{
$defaults = array('uri' => null, 'url' => null, 'reply_to' => null, 'repeat_of' => null, 'scope' => null, 'distribute' => true, 'object_type' => null, 'verb' => null);
if (!empty($options) && is_array($options)) {
$options = array_merge($defaults, $options);
extract($options);
} else {
extract($defaults);
}
if (!isset($is_local)) {
$is_local = Notice::LOCAL_PUBLIC;
}
$profile = Profile::staticGet('id', $profile_id);
$user = User::staticGet('id', $profile_id);
if ($user) {
// Use the local user's shortening preferences, if applicable.
$final = $user->shortenLinks($content);
} else {
$final = common_shorten_links($content);
}
if ($source != 'activity' && $source != 'event') {
if (Notice::contentTooLong($final)) {
// TRANS: Client exception thrown if a notice contains too many characters.
throw new ClientException(_('Problem saving notice. Too long.'));
}
}
if (empty($profile)) {
// TRANS: Client exception thrown when trying to save a notice for an unknown user.
throw new ClientException(_('Problem saving notice. Unknown user.'));
}
if (common_config('throttle', 'enabled') && !Notice::checkEditThrottle($profile_id)) {
common_log(LOG_WARNING, 'Excessive posting by profile #' . $profile_id . '; throttled.');
// TRANS: Client exception thrown when a user tries to post too many notices in a given time frame.
throw new ClientException(_('Too many notices too fast; take a breather ' . 'and post again in a few minutes.'));
}
if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) {
common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.');
// TRANS: Client exception thrown when a user tries to post too many duplicate notices in a given time frame.
throw new ClientException(_('Too many duplicate messages too quickly;' . ' take a breather and post again in a few minutes.'));
}
if (!$profile->hasRight(Right::NEWNOTICE)) {
common_log(LOG_WARNING, "Attempted post from user disallowed to post: " . $profile->nickname);
// TRANS: Client exception thrown when a user tries to post while being banned.
throw new ClientException(_('You are banned from posting notices on this site.'), 403);
}
$notice = new Notice();
$notice->profile_id = $profile_id;
$autosource = common_config('public', 'autosource');
// Sandboxed are non-false, but not 1, either
if (!$profile->hasRight(Right::PUBLICNOTICE) || $source && $autosource && in_array($source, $autosource)) {
$notice->is_local = Notice::LOCAL_NONPUBLIC;
} else {
$notice->is_local = $is_local;
}
if (!empty($created)) {
//.........这里部分代码省略.........
示例3: saveNew
/**
* Save a new notice and push it out to subscribers' inboxes.
* Poster's permissions are checked before sending.
*
* @param int $profile_id Profile ID of the poster
* @param string $content source message text; links may be shortened
* per current user's preference
* @param string $source source key ('web', 'api', etc)
* @param array $options Associative array of optional properties:
* string 'created' timestamp of notice; defaults to now
* int 'is_local' source/gateway ID, one of:
* Notice::LOCAL_PUBLIC - Local, ok to appear in public timeline
* Notice::REMOTE_OMB - Sent from a remote OMB service;
* hide from public timeline but show in
* local "and friends" timelines
* Notice::LOCAL_NONPUBLIC - Local, but hide from public timeline
* Notice::GATEWAY - From another non-OMB service;
* will not appear in public views
* float 'lat' decimal latitude for geolocation
* float 'lon' decimal longitude for geolocation
* int 'location_id' geoname identifier
* int 'location_ns' geoname namespace to interpret location_id
* int 'reply_to'; notice ID this is a reply to
* int 'repeat_of'; notice ID this is a repeat of
* string 'uri' unique ID for notice; defaults to local notice URL
* string 'url' permalink to notice; defaults to local notice URL
* string 'rendered' rendered HTML version of content
* array 'replies' list of profile URIs for reply delivery in
* place of extracting @-replies from content.
* array 'groups' list of group IDs to deliver to, in place of
* extracting ! tags from content
* array 'tags' list of hashtag strings to save with the notice
* in place of extracting # tags from content
* array 'urls' list of attached/referred URLs to save with the
* notice in place of extracting links from content
* @fixme tag override
*
* @return Notice
* @throws ClientException
*/
static function saveNew($profile_id, $content, $source, $options = null)
{
$defaults = array('uri' => null, 'url' => null, 'reply_to' => null, 'repeat_of' => null);
if (!empty($options)) {
$options = $options + $defaults;
extract($options);
} else {
extract($defaults);
}
if (!isset($is_local)) {
$is_local = Notice::LOCAL_PUBLIC;
}
$profile = Profile::staticGet($profile_id);
$final = common_shorten_links($content);
if (Notice::contentTooLong($final)) {
// TRANS: Client exception thrown if a notice contains too many characters.
throw new ClientException(_('Problem saving notice. Too long.'));
}
if (empty($profile)) {
// TRANS: Client exception thrown when trying to save a notice for an unknown user.
throw new ClientException(_('Problem saving notice. Unknown user.'));
}
if (common_config('throttle', 'enabled') && !Notice::checkEditThrottle($profile_id)) {
common_log(LOG_WARNING, 'Excessive posting by profile #' . $profile_id . '; throttled.');
// TRANS: Client exception thrown when a user tries to post too many notices in a given time frame.
throw new ClientException(_('Too many notices too fast; take a breather ' . 'and post again in a few minutes.'));
}
if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) {
common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.');
// TRANS: Client exception thrown when a user tries to post too many duplicate notices in a given time frame.
throw new ClientException(_('Too many duplicate messages too quickly;' . ' take a breather and post again in a few minutes.'));
}
if (!$profile->hasRight(Right::NEWNOTICE)) {
common_log(LOG_WARNING, "Attempted post from user disallowed to post: " . $profile->nickname);
// TRANS: Client exception thrown when a user tries to post while being banned.
throw new ClientException(_('You are banned from posting notices on this site.'), 403);
}
$notice = new Notice();
$notice->profile_id = $profile_id;
$autosource = common_config('public', 'autosource');
# Sandboxed are non-false, but not 1, either
if (!$profile->hasRight(Right::PUBLICNOTICE) || $source && $autosource && in_array($source, $autosource)) {
$notice->is_local = Notice::LOCAL_NONPUBLIC;
} else {
$notice->is_local = $is_local;
}
if (!empty($created)) {
$notice->created = $created;
} else {
$notice->created = common_sql_now();
}
$notice->content = $final;
$notice->source = $source;
$notice->uri = $uri;
$notice->url = $url;
// Handle repeat case
if (isset($repeat_of)) {
$notice->repeat_of = $repeat_of;
} else {
$notice->reply_to = self::getReplyTo($reply_to, $profile_id, $source, $final);
//.........这里部分代码省略.........
示例4: saveNew
static function saveNew($profile_id, $content, $source = null, $is_local = 1, $reply_to = null, $uri = null)
{
$profile = Profile::staticGet($profile_id);
$final = common_shorten_links($content);
if (!$profile) {
common_log(LOG_ERR, 'Problem saving notice. Unknown user.');
return _('Problem saving notice. Unknown user.');
}
if (common_config('throttle', 'enabled') && !Notice::checkEditThrottle($profile_id)) {
common_log(LOG_WARNING, 'Excessive posting by profile #' . $profile_id . '; throttled.');
return _('Too many notices too fast; take a breather and post again in a few minutes.');
}
if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) {
common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.');
return _('Too many duplicate messages too quickly; take a breather and post again in a few minutes.');
}
$banned = common_config('profile', 'banned');
if (in_array($profile_id, $banned) || in_array($profile->nickname, $banned)) {
common_log(LOG_WARNING, "Attempted post from banned user: {$profile->nickname} (user id = {$profile_id}).");
return _('You are banned from posting notices on this site.');
}
$notice = new Notice();
$notice->profile_id = $profile_id;
$blacklist = common_config('public', 'blacklist');
$autosource = common_config('public', 'autosource');
# Blacklisted are non-false, but not 1, either
if ($blacklist && in_array($profile_id, $blacklist) || $source && $autosource && in_array($source, $autosource)) {
$notice->is_local = -1;
} else {
$notice->is_local = $is_local;
}
$notice->query('BEGIN');
$notice->reply_to = $reply_to;
$notice->created = common_sql_now();
$notice->content = $final;
$notice->rendered = common_render_content($final, $notice);
$notice->source = $source;
$notice->uri = $uri;
if (Event::handle('StartNoticeSave', array(&$notice))) {
$id = $notice->insert();
if (!$id) {
common_log_db_error($notice, 'INSERT', __FILE__);
return _('Problem saving notice.');
}
# Update the URI after the notice is in the database
if (!$uri) {
$orig = clone $notice;
$notice->uri = common_notice_uri($notice);
if (!$notice->update($orig)) {
common_log_db_error($notice, 'UPDATE', __FILE__);
return _('Problem saving notice.');
}
}
# XXX: do we need to change this for remote users?
$notice->saveReplies();
$notice->saveTags();
$notice->saveGroups();
$notice->addToInboxes();
$notice->query('COMMIT');
Event::handle('EndNoticeSave', array($notice));
}
# Clear the cache for subscribed users, so they'll update at next request
# XXX: someone clever could prepend instead of clearing the cache
if (common_config('memcached', 'enabled')) {
$notice->blowCaches();
}
return $notice;
}