本文整理汇总了PHP中Annotation::read方法的典型用法代码示例。如果您正苦于以下问题:PHP Annotation::read方法的具体用法?PHP Annotation::read怎么用?PHP Annotation::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Annotation
的用法示例。
在下文中一共展示了Annotation::read方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: punish_comments
function punish_comments($hours = 6)
{
global $globals, $db;
$log = new Annotation('punish-comment');
if ($log->read() && $log->time > time() - 3600 * $hours) {
echo "Comments already verified at: " . get_date_time($log->time) . "\n";
return false;
}
if ($globals['min_karma_for_comments'] > 0) {
$min_karma = $globals['min_karma_for_comments'];
} else {
$min_karma = 4.5;
}
$votes_from = time() - $hours * 3600;
// 'date_sub(now(), interval 6 hour)';
$comments_from = time() - 2 * $hours * 3600;
//'date_sub(now(), interval 12 hour)';
echo "Starting karma_comments...\n";
$users = "SELECT SQL_NO_CACHE distinct comment_user_id as user_id from comments, users where comment_date > from_unixtime({$comments_from}) and comment_karma < -50 and comment_user_id = user_id and user_level != 'disabled' and user_karma >= {$min_karma}";
$result = $db->get_results($users);
$log->store();
if (!$result) {
return;
}
foreach ($result as $dbuser) {
$user = new User();
$user->id = $dbuser->user_id;
$user->read();
printf("%07d %s\n", $user->id, $user->username);
$punish = 0;
$comment_votes_count = (int) $db->get_var("SELECT SQL_NO_CACHE count(*) from votes, comments where comment_user_id = {$user->id} and comment_date > from_unixtime({$comments_from}) and vote_type='comments' and vote_link_id = comment_id and vote_date > from_unixtime({$votes_from}) and vote_user_id != {$user->id}");
if ($comment_votes_count > 5) {
$votes_karma = (int) $db->get_var("SELECT SQL_NO_CACHE sum(vote_value) from votes, comments where comment_user_id = {$user->id} and comment_date > from_unixtime({$comments_from}) and vote_type='comments' and vote_link_id = comment_id and vote_date > from_unixtime({$votes_from}) and vote_user_id != {$user->id}");
if ($votes_karma < 50) {
$distinct_votes_count = (int) $db->get_var("SELECT SQL_NO_CACHE count(distinct comment_id) from votes, comments where comment_user_id = {$user->id} and comment_date > from_unixtime({$comments_from}) and vote_type='comments' and vote_link_id = comment_id and vote_date > from_unixtime({$votes_from}) and vote_user_id != {$user->id}");
$comments_count = (int) $db->get_var("SELECT SQL_NO_CACHE count(*) from comments where comment_user_id = {$user->id} and comment_date > from_unixtime({$comments_from})");
$comment_coeff = min($comments_count / 10, 1) * min($distinct_votes_count / ($comments_count * 0.75), 1);
$punish = max(-2, round($votes_karma * $comment_coeff * 1 / 1000, 2));
}
}
if ($punish < -0.1) {
echo "comments: {$comments_count} votes distinct: {$distinct_votes_count} karma: {$votes_karma} coef: {$comment_coeff} -> {$punish}\n";
$user->karma += $punish;
//$user->store();
$annotation = new Annotation("karma-{$user->id}");
//$annotation->append(_('Penalización por comentarios').": $punish, nuevo karma: $user->karma\n");
echo _('Penalización por comentarios') . ": {$punish}, nuevo karma: {$user->karma}\n";
$log->append(_('Penalización') . " {$user->username}: {$punish}, nuevo karma: {$user->karma}\n");
}
$db->barrier();
}
}
示例2: do_load
function do_load() {
global $db, $current_user;
$annotation = new Annotation('ec2-autoscaler');
if (!$annotation->read()) {
return _('no hay estadísticas disponibles');
}
$group = unserialize($annotation->text);
$str = "web instances: $group->instances, ";
$str .= "cpu average load: ".round($group->load, 2) . "%, ";
$str .= "cpu max average ($group->measures periods): ".round($group->load_max, 2)."%, ";
$str .= "stored at: ". get_date_time($annotation->time);
return $str;
}
示例3: do_load
function do_load()
{
global $db, $current_user;
$annotation = new Annotation('ec2_watch');
if (!$annotation->read()) {
return _('no hay estadísticas disponibles');
}
$group = json_decode($annotation->text);
$str = "web instances: {$group->instances}, ";
$str .= "cpu average load: " . round($group->avg_load, 2) . "%, ";
$str .= "last action: {$group->action} ";
$str .= "last change: " . get_date_time($group->changed_ts) . " ";
$str .= "stored at: " . get_date_time($annotation->time);
return $str;
}
示例4: in
$user_id = guess_user_id($_REQUEST['friends_of']);
$sql = "SELECT link_id FROM links, friends WHERE friend_type='manual' and friend_from = {$user_id} and friend_to=link_author and friend_value > 0 and link_status in ('queued', 'published') ORDER BY link_date DESC limit {$rows}";
$user_login = $db->get_var("select user_login from users where user_id={$user_id}");
$title = $site_info->name . ': ' . sprintf(_('amigos de %s'), $user_login);
} elseif (!empty($_REQUEST['sent_by'])) {
/////
// sent links
/////
$user_id = guess_user_id($_REQUEST['sent_by']);
$sql = "SELECT link_id FROM links WHERE link_author={$user_id} and link_votes > 0 ORDER BY link_id DESC limit {$rows}";
$user_login = $db->get_var("select user_login from users where user_id={$user_id}");
$title = $site_info->name . ': ' . sprintf(_('noticias de %s'), $user_login);
} elseif (isset($_REQUEST['active'])) {
$title = $site_info->name . ': ' . _('más activas');
$top = new Annotation('top-actives-' . $globals['site_shortname']);
if ($top->read()) {
$links = explode(',', $top->text);
}
} elseif (isset($_REQUEST['popular'])) {
$min_date = date("Y-m-d H:i:00", $globals['now'] - 129600);
// 36 hours
// The order is not exactly the votes
// but a time-decreasing function applied to the number of votes
$sql = "select link_id, (link_votes-link_negatives*2)*(1-(unix_timestamp(now())-unix_timestamp(link_date))*0.8/129600) as value from links, sub_statuses where id = " . SitesMgr::my_id() . " AND link_id = link AND status='published' and date > '{$min_date}' order by value desc limit 25";
} elseif (isset($_REQUEST['top_visited'])) {
$min_date = date("Y-m-d H:i:00", $globals['now'] - 172800);
// 48 hours
// The order is not exactly the votes
// but a time-decreasing function applied to the number of votes
$sql = "select link_id, counter*(1-(unix_timestamp(now())-unix_timestamp(link_date))*0.5/172800) as value from links, link_clicks, sub_statuses where sub_statuses.id = " . SitesMgr::my_id() . " AND link_id = link AND status='published' and date > '{$min_date}' and link_clicks.id = link order by value desc limit 25";
} else {
示例5: promote_style
// The source code packaged with this file is Free Software, Copyright (C) 2005 by
// Ricardo Galli <gallir at uib dot es>.
// It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise.
// You can get copies of the licenses here:
// http://www.affero.org/oagpl.html
// AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING".
include 'config.php';
include mnminclude . 'html1.php';
$globals['ads'] = false;
promote_style();
do_header(_('promote') . ' | ' . _('menéame'));
echo '<div id="singlewrap">' . "\n";
$site_id = SitesMgr::my_parent();
$annotation = new Annotation("promote-{$site_id}");
$annotation->text = $output;
if ($annotation->read()) {
echo $annotation->text;
}
echo '</div>' . "\n";
do_footer_menu();
do_footer();
function promote_style()
{
global $globals;
$globals['extra_head'] = '
<style type="text/css">
p {
font-family: Bitstream Vera Sans, Arial, Helvetica, sans-serif;
font-size: 90%;
}
table {
示例6: do_active_stories
function do_active_stories()
{
global $db, $globals, $dblang;
if ($globals['mobile']) {
return;
}
$key = 'active_stories_' . $globals['site_shortname'] . $globals['v'];
if (memcache_mprint($key)) {
return;
}
echo '<!-- Calculating ' . __FUNCTION__ . ' -->';
$title = _('destacadas');
$url = $globals['base_url'] . 'top_active';
$top = new Annotation('top-actives-' . $globals['site_shortname']);
if ($top->read() && ($ids = explode(',', $top->text))) {
$links = array();
$ids = array_slice($ids, 0, 5);
foreach ($ids as $id) {
$link = Link::from_db($id);
$link->url = $link->get_relative_permalink();
$link->thumb = $link->has_thumb();
$link->total_votes = $link->votes + $link->anonymous;
if ($link->thumb) {
$link->thumb_x = round($link->thumb_x / 2);
$link->thumb_y = round($link->thumb_y / 2);
}
$link->check_warn();
$links[] = $link;
}
$subclass = 'red';
$vars = compact('links', 'title', 'url', 'subclass');
$output = Haanga::Load('best_stories.html', $vars, true);
echo $output;
memcache_madd($key, $output, 60);
}
}
示例7: get_extended_properties
public static function get_extended_properties($id = false)
{
static $properties = array(), $last_id = false;
if ($id == false) {
$id = self::my_id();
}
if (!empty($properties) && $last_id == $id) {
return $properties;
}
$last_id = $id;
$properties = self::$extended_properties;
$key = self::PREFERENCES_KEY . $id;
$a = new Annotation($key);
if ($a->read() && !empty($a->text)) {
$res = json_decode($a->text, true);
// We use associative array
if ($res) {
foreach ($res as $k => $v) {
$properties[$k] = $v;
}
}
}
return $properties;
}
示例8: syslog
if (!$my_id > 0) {
syslog(LOG_INFO, "Meneame, " . basename(__FILE__) . " site not found {$site_name}");
echo "No site id found\n";
die;
}
SitesMgr::__init($my_id);
$info = SitesMgr::get_info();
$properties = SitesMgr::get_extended_properties();
$a_tops = new Annotation('top-link-' . $site_name);
echo 'top-link-' . $site_name . "\n";
if (!$a_tops->read()) {
exit;
}
$tops = explode(',', $a_tops->text);
$a_history = new Annotation('top-link-history-' . $site_name);
if ($a_history->read()) {
$history = explode(',', $a_history->text);
} else {
$history = array();
}
if (!in_array($tops[0], $history)) {
if (!($link = Link::from_db($tops[0]))) {
echo "Error reading link " . $tops[0] . "\n";
exit;
}
$url = $link->get_permalink($info->sub);
if ($globals['url_shortener']) {
$short_url = $link->get_short_permalink();
} else {
$short_url = $url;
}
示例9: Annotation
function metas_coef_get() {
$log = new Annotation("metas-coef");
if (!$log->read()) return false;
$dict = unserialize($log->text);
if (!$dict || ! is_array($dict)) return false; // Failed to unserialize
return $dict; // Asked for the whole dict
}
示例10: Annotation
// You can get copies of the licenses here:
// http://www.affero.org/oagpl.html
// AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING".
include 'config.php';
include mnminclude . 'html1.php';
do_header(_('destacadas') . ' | ' . $globals['site_name'], _('destacadas'));
$globals['tag_status'] = 'published';
do_tabs('main', 'active');
/*** SIDEBAR ****/
echo '<div id="sidebar">';
do_banner_right();
do_best_stories();
do_banner_promotions();
do_best_comments();
echo '</div>' . "\n";
/*** END SIDEBAR ***/
echo '<div id="newswrap">' . "\n";
$top = new Annotation('top-actives-' . $globals['site_shortname']);
if ($top->read() && ($links = explode(',', $top->text))) {
$counter = 0;
foreach ($links as $id) {
$link = Link::from_db($id);
$link->show_clicks = true;
$link->print_summary();
$counter++;
Haanga::Safe_Load('private/ad-interlinks.html', compact('counter', 'page_size'));
}
}
echo '</div>' . "\n";
do_footer_menu();
do_footer();
示例11: Annotation
function all_stats()
{
global $db, $globals, $current_user;
if ($this->stats) {
return;
}
if (!$this->read) {
$this->read();
}
$do_cache = $this->date < $globals['now'] - 86400;
// Don't cache for new users
$cache_time = 7200;
$stats = new Annotation("user_stats-{$this->id}");
if ($do_cache && $stats->read() && ($stats->time > $globals['now'] - $cache_time || $globals['bot'] || $current_user->user_id == 0 || $stats->time > intval($db->get_var("select unix_timestamp(max(vote_date)) from votes where vote_user_id = {$this->id} and vote_type in ('links', 'posts', 'comments')")))) {
$obj = unserialize($stats->text);
} else {
if ($globals['bot'] && $current_user->user_id == 0) {
return;
}
// Don't calculate stats por bots
$obj = new stdClass();
$obj->total_votes = (int) $db->get_var("SELECT count(*) FROM votes WHERE vote_type='links' and vote_user_id = {$this->id}");
$obj->total_links = (int) $db->get_var("SELECT count(*) FROM links WHERE link_author = {$this->id} and link_votes > 0");
$obj->published_links = (int) $db->get_var("SELECT count(*) FROM links WHERE link_author = {$this->id} AND link_status = 'published'");
$obj->total_comments = (int) $db->get_var("SELECT count(*) FROM comments WHERE comment_user_id = {$this->id}");
$obj->total_posts = (int) $db->get_var("SELECT count(*) FROM posts WHERE post_user_id = {$this->id}");
$obj->total_friends = (int) $db->get_var("select count(*) from friends where friend_to = {$this->id}");
$obj->total_images = Upload::user_uploads($this->id) - Upload::user_uploads($this->id, false, 'private');
if ($do_cache) {
$stats->text = serialize($obj);
$stats->store($globals['now'] + 86400 * 90);
// Expires in 90 days
}
}
foreach (get_object_vars($obj) as $var => $value) {
$this->{$var} = $value;
}
$this->stats = true;
}
示例12: Annotation
static function get_affinity($id, $from = false) {
global $current_user;
return 100; // remove affinity control
$log = new Annotation("affinity-$id");
if (!$log->read()) return false;
$dict = unserialize($log->text);
if (!$dict || ! is_array($dict)) return false; // Failed to unserialize
if (!$from) return $dict; // Asked for the whole dict
if (abs($dict[$from]) <= 100) return intval($dict[$from]); // Asked just a value;
return false; // Nothing found
}
示例13: Annotation
function subs_coef_get()
{
global $globals;
if (empty($globals['sub_balance_metas']) || !in_array(SitesMgr::my_id(), $globals['sub_balance_metas'])) {
return false;
}
$log = new Annotation("subs-coef-" . SitesMgr::my_id());
if (!$log->read()) {
return false;
}
$dict = unserialize($log->text);
if (!$dict || !is_array($dict)) {
return false;
}
// Failed to unserialize
return $dict;
// Asked for the whole dict
}
示例14: array
$indices = 'posts';
$sort = 'karma';
break;
default:
$indices = 'links';
$sort = 'votes';
}
header('Content-Type: application/json; charset=utf-8');
$series = array();
$min_yymm = PHP_INT_MAX;
$max_yymm = (int) date('Ym');
$sp = new RGDB('', '', '', $globals['sphinx_server']);
$sp->port = 9306;
$sp->connect();
$cache = new Annotation("sphinx-{$indices}");
if ($cache->read()) {
/* If totals' cache is valid, just load the array */
$totals = json_decode($cache->text, true);
} else {
/* Otherwise, query to Sphinx and fills $totals */
$totals = array();
$res = $sp->get_results("select yearmonth(date) as yymm, count(*) as _count from {$indices} group by yymm limit 2000 option ranker = none");
if ($res) {
foreach ($res as $o) {
$a = (array) $o;
$totals[$o->yymm] = intval($a["_count"]);
}
}
$cache->text = json_encode($totals);
$cache->store(time() + 86400);
}