本文整理汇总了PHP中common_sql_date函数的典型用法代码示例。如果您正苦于以下问题:PHP common_sql_date函数的具体用法?PHP common_sql_date怎么用?PHP common_sql_date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了common_sql_date函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUsers
function getUsers($y, $m, $d, $i)
{
$u = User::cacheGet("sitemap:user:{$y}:{$m}:{$d}:{$i}");
if ($u === false) {
$user = new User();
$begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
// XXX: estimates 1d == 24h, which screws up days
// with leap seconds (1d == 24h + 1s). Thankfully they're
// few and far between.
$theend = strtotime($begindt) + 24 * 60 * 60;
$enddt = common_sql_date($theend);
$user->selectAdd();
$user->selectAdd('nickname');
$user->whereAdd("created >= '{$begindt}'");
$user->whereAdd("created < '{$enddt}'");
$user->orderBy('created');
$offset = ($i - 1) * SitemapPlugin::USERS_PER_MAP;
$limit = SitemapPlugin::USERS_PER_MAP;
$user->limit($offset, $limit);
$user->find();
while ($user->fetch()) {
$u[] = $user->nickname;
}
$c = Cache::instance();
if (!empty($c)) {
$c->set(Cache::key("sitemap:user:{$y}:{$m}:{$d}:{$i}"), $u, Cache::COMPRESSED, time() > $theend ? time() + 90 * 24 * 60 * 60 : time() + 5 * 60);
}
}
return $u;
}
示例2: getNotices
function getNotices($y, $m, $d, $i)
{
$n = Notice::cacheGet("sitemap:notice:{$y}:{$m}:{$d}:{$i}");
if ($n === false) {
$notice = new Notice();
$begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
// XXX: estimates 1d == 24h, which screws up days
// with leap seconds (1d == 24h + 1s). Thankfully they're
// few and far between.
$theend = strtotime($begindt) + 24 * 60 * 60;
$enddt = common_sql_date($theend);
$notice->selectAdd();
$notice->selectAdd('id, created');
$notice->whereAdd("created >= '{$begindt}'");
$notice->whereAdd("created < '{$enddt}'");
$notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
$notice->orderBy('created');
$offset = ($i - 1) * SitemapPlugin::NOTICES_PER_MAP;
$limit = SitemapPlugin::NOTICES_PER_MAP;
$notice->limit($offset, $limit);
$notice->find();
$n = array();
while ($notice->fetch()) {
$n[] = array($notice->id, $notice->created);
}
$c = Cache::instance();
if (!empty($c)) {
$c->set(Cache::key("sitemap:notice:{$y}:{$m}:{$d}:{$i}"), $n, Cache::COMPRESSED, time() > $theend ? time() + 90 * 24 * 60 * 60 : time() + 5 * 60);
}
}
return $n;
}
示例3: addNew
/**
* Save a favorite record.
* @fixme post-author notification should be moved here
*
* @param Profile $actor the local or remote Profile who favorites
* @param Notice $target the notice that is favorited
* @return Fave record on success
* @throws Exception on failure
*/
static function addNew(Profile $actor, Notice $target)
{
if (self::existsForProfile($target, $actor)) {
// TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
throw new AlreadyFulfilledException(_('You have already favorited this!'));
}
$act = new Activity();
$act->type = ActivityObject::ACTIVITY;
$act->verb = ActivityVerb::FAVORITE;
$act->time = time();
$act->id = self::newUri($actor, $target, common_sql_date($act->time));
$act->title = _("Favor");
// TRANS: Message that is the "content" of a favorite (%1$s is the actor's nickname, %2$ is the favorited
// notice's nickname and %3$s is the content of the favorited notice.)
$act->content = sprintf(_('%1$s favorited something by %2$s: %3$s'), $actor->getNickname(), $target->getProfile()->getNickname(), $target->rendered ?: $target->content);
$act->actor = $actor->asActivityObject();
$act->target = $target->asActivityObject();
$act->objects = array(clone $act->target);
$url = common_local_url('AtomPubShowFavorite', array('profile' => $actor->id, 'notice' => $target->id));
$act->selfLink = $url;
$act->editLink = $url;
// saveActivity will in turn also call Fave::saveActivityObject which does
// what this function used to do before this commit.
$stored = Notice::saveActivity($act, $actor);
return $stored;
}
示例4: getNotices
function getNotices()
{
// @fixme there should be a common func for this
if (common_config('db', 'type') == 'pgsql') {
if (!empty($this->out->tag)) {
$tag = pg_escape_string($this->out->tag);
}
} else {
if (!empty($this->out->tag)) {
$tag = mysql_escape_string($this->out->tag);
}
}
$weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
$cutoff = sprintf("fave.modified > '%s'", common_sql_date(time() - common_config('popular', 'cutoff')));
$qry = "SELECT notice.*, {$weightexpr} as weight ";
if (isset($tag)) {
$qry .= 'FROM notice_tag, notice JOIN fave ON notice.id = fave.notice_id ' . "WHERE {$cutoff} and notice.id = notice_tag.notice_id and '{$tag}' = notice_tag.tag";
} else {
$qry .= 'FROM notice JOIN fave ON notice.id = fave.notice_id ' . "WHERE {$cutoff}";
}
$qry .= ' GROUP BY notice.id,notice.profile_id,notice.content,notice.uri,' . 'notice.rendered,notice.url,notice.created,notice.modified,' . 'notice.reply_to,notice.is_local,notice.source,notice.conversation, ' . 'notice.lat,notice.lon,location_id,location_ns,notice.repeat_of' . ' ORDER BY weight DESC';
$offset = 0;
$limit = NOTICES_PER_SECTION + 1;
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
$notice = Memcached_DataObject::cachedQuery('Notice', $qry, 1200);
return $notice;
}
示例5: setupFeedSub
public function setupFeedSub(FeedSub $feedsub, $interval = 300)
{
$orig = clone $feedsub;
$feedsub->sub_state = 'nohub';
$feedsub->sub_start = common_sql_date(time());
$feedsub->sub_end = '';
$feedsub->last_update = common_sql_date(time() - $interval);
// force polling as soon as we can
$feedsub->update($orig);
}
示例6: getUpdates
function getUpdates($seconds)
{
$notice = new Notice();
# XXX: cache this. Depends on how big this protocol becomes;
# Re-doing this query every 15 seconds isn't the end of the world.
$divider = common_sql_date(time() - $seconds);
$notice->query('SELECT profile_id, max(id) AS max_id ' . 'FROM ( ' . 'SELECT profile_id, id FROM notice ' . (common_config('db', 'type') == 'pgsql' ? 'WHERE extract(epoch from created) > (extract(epoch from now()) - ' . $seconds . ') ' : 'WHERE created > "' . $divider . '" ') . ') AS latest ' . 'GROUP BY profile_id');
$updates = array();
while ($notice->fetch()) {
$updates[] = array($notice->profile_id, $notice->max_id);
}
return $updates;
}
示例7: lookup_nonce
function lookup_nonce($consumer, $token, $nonce, $timestamp)
{
$n = new Nonce();
$n->consumer_key = $consumer->key;
$n->ts = common_sql_date($timestamp);
$n->nonce = $nonce;
if ($n->find(true)) {
return true;
} else {
$n->created = DB_DataObject_Cast::dateTime();
$n->insert();
return false;
}
}
示例8: cleanupChannels
function cleanupChannels()
{
$rc = new Realtime_channel();
$rc->selectAdd();
$rc->selectAdd('channel_key');
$rc->whereAdd('modified < "' . common_sql_date(time() - Realtime_channel::TIMEOUT) . '"');
if ($rc->find()) {
$keys = $rc->fetchAll();
foreach ($keys as $key) {
$rc = Realtime_channel::staticGet('channel_key', $key);
if (!empty($rc)) {
printfv("Deleting realtime channel '{$key}'\n");
$rc->delete();
}
}
}
}
示例9: importActivityStream
function importActivityStream($user, $doc)
{
$feed = $doc->documentElement;
$entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry');
for ($i = $entries->length - 1; $i >= 0; $i--) {
$entry = $entries->item($i);
$activity = new Activity($entry, $feed);
$object = $activity->objects[0];
if (!have_option('q', 'quiet')) {
print $activity->content . "\n";
}
$html = getTweetHtml($object->link);
$config = array('safe' => 1, 'deny_attribute' => 'class,rel,id,style,on*');
$html = htmLawed($html, $config);
$content = html_entity_decode(strip_tags($html), ENT_QUOTES, 'UTF-8');
$notice = Notice::saveNew($user->id, $content, 'importtwitter', array('uri' => $object->id, 'url' => $object->link, 'rendered' => $html, 'created' => common_sql_date($activity->time), 'replies' => array(), 'groups' => array()));
}
}
示例10: setLease
/**
* Validates a requested lease length, sets length plus
* subscription start & end dates.
*
* Does not save to database -- use before insert() or update().
*
* @param int $length in seconds
*/
function setLease($length)
{
assert(is_int($length));
$min = 86400;
$max = 86400 * 30;
if ($length == 0) {
// We want to garbage collect dead subscriptions!
$length = $max;
} elseif ($length < $min) {
$length = $min;
} else {
if ($length > $max) {
$length = $max;
}
}
$this->lease = $length;
$this->start_sub = common_sql_now();
$this->end_sub = common_sql_date(time() + $length);
}
示例11: showContent
/**
* Content area
*
* Shows the list of popular notices
*
* @return void
*/
function showContent()
{
$groupId = intval($this->group->id);
$weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
$cutoff = sprintf("fave.modified > '%s'", common_sql_date(time() - common_config('popular', 'cutoff')));
$qry = 'SELECT notice.*, ' . $weightexpr . ' as weight ' . 'FROM notice ' . "JOIN group_inbox ON notice.id = group_inbox.notice_id " . 'JOIN fave ON notice.id = fave.notice_id ' . "WHERE {$cutoff} AND group_id = {$groupId} " . 'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source,notice.conversation ' . 'ORDER BY weight DESC';
$offset = ($this->page - 1) * NOTICES_PER_PAGE;
$limit = NOTICES_PER_PAGE + 1;
if (common_config('db', 'type') == 'pgsql') {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} else {
$qry .= ' LIMIT ' . $offset . ', ' . $limit;
}
$notice = Memcached_DataObject::cachedQuery('Notice', $qry, 600);
$nl = new NoticeList($notice, $this);
$cnt = $nl->show();
if ($cnt == 0) {
//$this->showEmptyList();
}
$this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, $this->page, 'groupfavorited', array('nickname' => $this->group->nickname));
}
示例12: getNoticeIds
function getNoticeIds($offset, $limit, $since_id, $max_id)
{
$weightexpr = common_sql_weight('modified', common_config('popular', 'dropoff'));
$cutoff = sprintf("modified > '%s'", common_sql_date(time() - common_config('popular', 'cutoff')));
$fave = new Fave();
$fave->selectAdd();
$fave->selectAdd('notice_id');
$fave->selectAdd("{$weightexpr} as weight");
$fave->whereAdd($cutoff);
$fave->orderBy('weight DESC');
$fave->groupBy('notice_id');
if (!is_null($offset)) {
$fave->limit($offset, $limit);
}
// FIXME: $since_id, $max_id are ignored
$ids = array();
if ($fave->find()) {
while ($fave->fetch()) {
$ids[] = $fave->notice_id;
}
}
return $ids;
}
示例13: onAppendUserActivityStreamObjects
public function onAppendUserActivityStreamObjects(UserActivityStream $uas, array &$objs)
{
$fave = new Fave();
$fave->user_id = $uas->getUser()->id;
if (!empty($uas->after)) {
$fave->whereAdd("modified > '" . common_sql_date($uas->after) . "'");
}
if ($fave->find()) {
while ($fave->fetch()) {
$objs[] = clone $fave;
}
}
return true;
}
示例14: confirmSubscribe
/**
* Save PuSH subscription confirmation.
* Sets approximate lease start and end times and finalizes state.
*
* @param int $lease_seconds provided hub.lease_seconds parameter, if given
*/
public function confirmSubscribe($lease_seconds)
{
$original = clone $this;
$this->sub_state = 'active';
$this->sub_start = common_sql_date(time());
if ($lease_seconds > 0) {
$this->sub_end = common_sql_date(time() + $lease_seconds);
} else {
$this->sub_end = null;
// Backwards compatibility to StatusNet (PuSH <0.4 supported permanent subs)
}
$this->modified = common_sql_now();
return $this->update($original);
}
示例15: postNote
function postNote($activity)
{
$note = $activity->objects[0];
// Use summary as fallback for content
if (!empty($note->content)) {
$sourceContent = $note->content;
} else {
if (!empty($note->summary)) {
$sourceContent = $note->summary;
} else {
if (!empty($note->title)) {
$sourceContent = $note->title;
} else {
// @fixme fetch from $sourceUrl?
// TRANS: Client error displayed when posting a notice without content through the API.
// TRANS: %d is the notice ID (number).
$this->clientError(sprintf(_('No content for notice %d.'), $note->id));
}
}
}
// Get (safe!) HTML and text versions of the content
$rendered = common_purify($sourceContent);
$content = common_strip_html($rendered);
$shortened = $this->auth_user->shortenLinks($content);
$options = array('is_local' => Notice::LOCAL_PUBLIC, 'rendered' => $rendered, 'replies' => array(), 'groups' => array(), 'tags' => array(), 'urls' => array());
// accept remote URI (not necessarily a good idea)
common_debug("Note ID is {$note->id}");
if (!empty($note->id)) {
$notice = Notice::getKV('uri', trim($note->id));
if (!empty($notice)) {
// TRANS: Client error displayed when using another format than AtomPub.
// TRANS: %s is the notice URI.
$this->clientError(sprintf(_('Notice with URI "%s" already exists.'), $note->id));
}
common_log(LOG_NOTICE, "Saving client-supplied notice URI '{$note->id}'");
$options['uri'] = $note->id;
}
// accept remote create time (also maybe not such a good idea)
if (!empty($activity->time)) {
common_log(LOG_NOTICE, "Saving client-supplied create time {$activity->time}");
$options['created'] = common_sql_date($activity->time);
}
// Check for optional attributes...
if ($activity->context instanceof ActivityContext) {
foreach ($activity->context->attention as $uri => $type) {
try {
$profile = Profile::fromUri($uri);
if ($profile->isGroup()) {
$options['groups'][] = $profile->id;
} else {
$options['replies'][] = $uri;
}
} catch (UnknownUriException $e) {
common_log(LOG_WARNING, sprintf('AtomPub post with unknown attention URI %s', $uri));
}
}
// Maintain direct reply associations
// @fixme what about conversation ID?
if (!empty($activity->context->replyToID)) {
$orig = Notice::getKV('uri', $activity->context->replyToID);
if (!empty($orig)) {
$options['reply_to'] = $orig->id;
}
}
$location = $activity->context->location;
if ($location) {
$options['lat'] = $location->lat;
$options['lon'] = $location->lon;
if ($location->location_id) {
$options['location_ns'] = $location->location_ns;
$options['location_id'] = $location->location_id;
}
}
}
// Atom categories <-> hashtags
foreach ($activity->categories as $cat) {
if ($cat->term) {
$term = common_canonical_tag($cat->term);
if ($term) {
$options['tags'][] = $term;
}
}
}
// Atom enclosures -> attachment URLs
foreach ($activity->enclosures as $href) {
// @fixme save these locally or....?
$options['urls'][] = $href;
}
$saved = Notice::saveNew($this->target->id, $content, 'atompub', $options);
return $saved;
}