本文整理汇总了PHP中Link::from_db方法的典型用法代码示例。如果您正苦于以下问题:PHP Link::from_db方法的具体用法?PHP Link::from_db怎么用?PHP Link::from_db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Link
的用法示例。
在下文中一共展示了Link::from_db方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: print_result
function print_result()
{
global $response, $page_size;
if ($response['ids']) {
$rows = min($response['rows'], 1000);
foreach ($response['ids'] as $id) {
switch ($_REQUEST['w']) {
case 'posts':
$obj = Post::from_db($id);
break;
case 'comments':
$obj = Comment::from_db($id);
break;
case 'links':
default:
$obj = Link::from_db($id);
}
if (!$obj) {
continue;
}
$obj->basic_summary = true;
switch ($_REQUEST['w']) {
case 'posts':
$obj->print_summary(800);
break;
case 'comments':
if ($obj->type == 'admin' && !$current_user->admin) {
continue;
}
// link_object
$obj->print_summary(800);
break;
case 'links':
default:
$obj->print_summary();
}
}
}
do_pages($rows, $page_size);
}
示例2: addcslashes
}
}
$url_db = $url;
if (!$unique) {
$url_db = addcslashes($url, '%_');
$url_db = preg_replace('/\\/$/', '', $url_db);
$links = $db->get_col("select SQL_NO_CACHE link_id from links where link_url like '{$url_db}%' order by link_date DESC limit 100");
} else {
$url_db = preg_replace('/\\/$/', '', $url_db);
$links = $db->get_col("select SQL_NO_CACHE link_id from links where link_url in ('{$url_db}', '{$url_db}/')");
}
if ($links) {
$dict['status'] = 'OK';
$dict['data'] = array();
foreach ($links as $link_id) {
$link = Link::from_db($link_id, null, false);
if ($json) {
$data = array();
$data['id'] = $link_id;
$data['url'] = $link->get_canonical_permalink();
$data['status'] = $link->status;
$data['votes'] = intval($link->votes);
$data['anonymous'] = intval($link->anonymous);
$data['karma'] = intval($link->karma);
array_push($dict['data'], $data);
} else {
$response = 'OK ' . $link->get_canonical_permalink() . " {$link->total_votes} {$link->status} {$link_id}\n";
}
}
} else {
if ($json) {
示例3: promote
function promote($site_id)
{
global $db, $globals, $output;
SitesMgr::__init($site_id);
$output = '';
$min_karma_coef = $globals['min_karma_coef'];
$links_queue = $db->get_var("SELECT SQL_NO_CACHE count(*) from sub_statuses WHERE id = {$site_id} and date > date_sub(now(), interval 24 hour) and status in ('published', 'queued')");
$links_queue_all = $db->get_var("SELECT SQL_NO_CACHE count(*) from sub_statuses, links WHERE id = {$site_id} and date > date_sub(now(), interval 24 hour) and link_id = link and link_votes > 0");
$pub_estimation = intval(max(min($links_queue * PUB_PERC, PUB_MAX), PUB_MIN));
$interval = intval(86400 / $pub_estimation);
$now = time();
echo "BEGIN\n";
$output .= "<p><b>BEGIN</b>: " . get_date_time($now) . "<br/>\n";
$hours = intval($globals['time_enabled_votes'] / 3600);
$from_time = "date_sub(now(), interval {$hours} hour)";
$last_published = $db->get_var("SELECT SQL_NO_CACHE UNIX_TIMESTAMP(max(date)) from sub_statuses WHERE id = {$site_id} and status='published'");
if (!$last_published) {
$last_published = $now - 24 * 3600 * 30;
}
$links_published = (int) $db->get_var("select SQL_NO_CACHE count(*) from sub_statuses where id = {$site_id} and status = 'published' and date > date_sub(now(), interval 24 hour)");
$links_published_projection = 4 * (int) $db->get_var("select SQL_NO_CACHE count(*) from sub_statuses where id = {$site_id} and status = 'published' and date > date_sub(now(), interval 6 hour)");
$diff = $now - $last_published;
// If published and estimation are lower than projection then
// fasten decay
if ($diff < $interval && ($links_published_projection < $pub_estimation * 0.9 && $links_published < $pub_estimation * 0.9)) {
$diff = max($diff * 2, $interval);
}
$decay = min(MAX, MAX - $diff / $interval * (MAX - MIN));
$decay = max($min_karma_coef, $decay);
if ($diff > $interval * 2) {
$must_publish = true;
$output .= "Delayed! <br/>";
}
$output .= "Last published at: " . get_date_time($last_published) . "<br/>\n";
$output .= "24hs queue: {$links_queue}/{$links_queue_all}, Published: {$links_published} -> {$links_published_projection} Published goal: {$pub_estimation}, Interval: {$interval} secs, difference: " . intval($now - $last_published) . " secs, Decay: {$decay}<br/>\n";
$continue = true;
$published = 0;
$past_karma_long = intval($db->get_var("SELECT SQL_NO_CACHE avg(karma) from sub_statuses WHERE id = {$site_id} and date >= date_sub(now(), interval 7 day) and status='published'"));
$past_karma_short = intval($db->get_var("SELECT SQL_NO_CACHE avg(karma) from sub_statuses WHERE id = {$site_id} and date >= date_sub(now(), interval 12 hour) and status='published'"));
$past_karma = 0.5 * max(40, $past_karma_long) + 0.5 * max(20, $past_karma_short);
$min_past_karma = (int) ($past_karma * $min_karma_coef);
$last_resort_karma = (int) $past_karma * 0.8;
//////////////
$min_karma = round(max($past_karma * $decay, 20));
if ($decay >= 1) {
$max_to_publish = 3;
} else {
$max_to_publish = 1;
}
$min_votes = 3;
/////////////
$limit_karma = round(min($past_karma, $min_karma) * 0.4);
$bonus_karma = round(min($past_karma, $min_karma) * 0.35);
/// Get common votes links' averages
$days = 7;
// Balance metas
if (empty($globals['sub_balance_metas']) || !in_array(SitesMgr::my_id(), $globals['sub_balance_metas'])) {
$db_metas = array();
} else {
$db_metas = $db->get_results("select category, category_name, calculated_coef from sub_categories, categories where id = {$site_id} and category_id = category and category_parent = 0 and category_id in (select category_parent from sub_categories, categories where id = {$site_id} and category_id = category and category_parent > 0)");
}
$subs_coef = get_subs_coef($site_id, 2);
$globals['users_karma_avg'] = (double) $db->get_var("select SQL_NO_CACHE avg(link_votes_avg) from links, sub_statuses where id = {$site_id} and status = 'published' and date > date_sub(now(), interval 72 hour) and link_id = link");
$output .= "Karma average for each link: " . $globals['users_karma_avg'] . ", Past karma. Long term: {$past_karma_long}, Short term: {$past_karma_short}, Average: <b>{$past_karma}</b><br/>\n";
$output .= "<b>Current MIN karma: {$min_karma}</b>, absolute min karma: {$min_past_karma}, analizing from {$limit_karma}<br/>\n";
$output .= "</p>\n";
$where = "id = {$site_id} AND date > {$from_time} AND status = 'queued' AND link_id = link AND link_votes>={$min_votes} AND (link_karma > {$limit_karma} or (date > date_sub(now(), interval 2 hour) and link_karma > {$bonus_karma})) and user_id = link_author ";
$sort = "ORDER BY link_karma DESC, link_votes DESC";
$thumbs_queue = array();
$links = $db->get_results("SELECT SQL_NO_CACHE link_id, link_karma as karma from sub_statuses, links, users where {$where} {$sort} LIMIT 30");
$rows = $db->affected_rows;
echo "SELECTED {$rows} ARTICLES\n";
if (!$rows) {
$output .= "There are no articles<br/>\n";
$output .= "--------------------------<br/>\n";
echo strip_tags($output) . "\n";
if (!DEBUG) {
$annotation = new Annotation("promote-{$site_id}");
$annotation->text = $output;
$annotation->store();
} else {
echo "OUTPUT:\n. " . strip_tags($output) . "\n";
}
return;
}
$max_karma_found = 0;
$best_link = 0;
$best_karma = 0;
$output .= "<table>\n";
if ($links) {
$output .= "<tr class='thead'><th>votes</th><th>anon</th><th>neg.</th><th>coef</th><th>karma</th><th>sub</th><th>title</th><th>changes</th></tr>\n";
$i = 0;
foreach ($links as $dblink) {
$link = Link::from_db($dblink->link_id);
$changes = update_link_karma($site_id, $link);
if (!DEBUG && $link->thumb_status == 'unknown' && $link->karma > $limit_karma) {
echo "Adding {$link->id} to thumb queue\n";
array_push($thumbs_queue, $link->id);
}
if (!empty($link->coef) && $link->coef > 1) {
//.........这里部分代码省略.........
示例4: get_user_uri
case 'friends':
$url = get_user_uri($current_user->user_login, 'friends_new');
do_redirection($url);
exit(0);
case 'post':
$url = $globals['scheme'] . '//' . get_server_name() . post_get_base_url($id);
do_redirection($url);
exit(0);
case 'comment':
$c = new Comment();
$c->id = $id;
$url = $globals['scheme'] . '//' . get_server_name() . $c->get_relative_individual_permalink();
do_redirection($url);
exit(0);
default:
$l = Link::from_db($id, null, false);
if (!$l) {
exit(0);
}
if (!$globals['mobile'] && !$globals['mobile_version'] && !empty($l->url) && $current_user->user_id > 0 && (empty($globals['https']) || preg_match('/^https:/', $l->url)) && User::get_pref($current_user->user_id, 'use_bar') && $db->get_var("select blog_type from blogs where blog_id = {$l->blog}") != 'noiframe') {
$url = $globals['scheme'] . '//' . get_server_name() . $globals['base_url'] . 'b/' . $id;
// we use always http to load no https pages
do_redirection($url, 307);
} else {
if (empty($l->url)) {
$url = $l->get_permalink();
} else {
$url = $l->url;
}
do_redirection($url);
}
示例5: depublish
function depublish($site_id)
{
// send back to queue links with too many negatives
global $db, $globals;
$days = 4;
echo "STARTING depublish for {$site_id}\n";
$site_info = SitesMgr::get_info($site_id);
$links = $db->get_col("select SQL_NO_CACHE link_id as id from links, sub_statuses where id = {$site_id} and status = 'published' and date > date_sub(now(), interval {$days} day) and date < date_sub(now(), interval 14 minute) and link = link_id and link_negatives > link_votes / 5");
if ($links) {
$votes_clicks = $db->get_col("select SQL_NO_CACHE link_votes/counter from links, sub_statuses, link_clicks where sub_statuses.id = {$site_id} and status = 'published' and date > date_sub(now(), interval {$days} day) and link = link_id and link_clicks.id = link");
sort($votes_clicks);
foreach ($links as $link) {
$l = Link::from_db($link);
$vc = $l->votes / $l->clicks;
$prob = cdf($votes_clicks, $vc);
// Count only those votes with karma > 6 to avoid abuses with new accounts with new accounts
$negatives = (int) $db->get_var("select SQL_NO_CACHE sum(user_karma) from votes, users where vote_type='links' and vote_link_id={$l->id} and vote_date > from_unixtime({$l->date}) and vote_date > date_sub(now(), interval 24 hour) and vote_value < 0 and vote_user_id > 0 and user_id = vote_user_id and user_karma > " . $globals['depublish_negative_karma']);
$positives = (int) $db->get_var("select SQL_NO_CACHE sum(user_karma) from votes, users where vote_type='links' and vote_link_id={$l->id} and vote_date > from_unixtime({$l->date}) and vote_value > 0 and vote_date > date_sub(now(), interval 24 hour) and vote_user_id > 0 and user_id = vote_user_id and user_karma > " . $globals['depublish_positive_karma']);
echo "Candidate {$l->uri}\n karma: {$l->sub_karma} ({$l->karma}) negative karma: {$negatives} positive karma: {$positives}\n";
// Adjust positives to the probability of votes/clicks
$c = 1 + (1 - $prob) * 0.5;
$positives = $positives * $c;
echo " probability: {$prob} New positives: {$positives} ({$c})\n";
if ($negatives > 10 && $negatives > $c * $l->sub_karma / 6 && $l->negatives > $c * $l->votes / 6 && $l->negatives > 5 && ($negatives > $positives || $negatives > $c * $l->sub_karma / 2 && $negatives > $positives / 2)) {
echo "Queued again: {$l->id} negative karma: {$negatives} positive karma: {$positives}\n";
$karma_old = $l->sub_karma;
$karma_new = intval($l->sub_karma / $globals['depublish_karma_divisor']);
$l->status = 'queued';
$l->sub_karma = $l->karma = $karma_new;
$db->query("update links set link_status='queued', link_date = link_sent_date, link_karma={$karma_new} where link_id = {$l->id}");
SitesMgr::deploy($l);
// Add an annotation to show it in the logs
$l->karma_old = $karma_old;
$l->karma = $karma_new;
$l->annotation = _('Retirada de portada');
$l->save_annotation('link-karma');
Log::insert('link_depublished', $l->id, $l->author);
if (!$site_info->sub) {
// Add the discard to log/event
$user = new User($l->author);
if ($user->read) {
echo "{$user->username}: {$user->karma}\n";
$user->add_karma(-$globals['instant_karma_per_depublished'], _('Retirada de portada'));
}
// Increase karma to users that voted negative
$ids = $db->get_col("select vote_user_id from votes where vote_type = 'links' and vote_link_id = {$l->id} and vote_user_id > 0 and vote_value < 0");
foreach ($ids as $id) {
$u = new User($id);
if ($u->read) {
// Avoid abuse of users voting negative just to get more karma
$voted = $db->get_var("select count(*) from logs where log_type = 'user_depublished_vote' and log_user_id = {$id} and log_date > date_sub(now(), interval 48 hour)");
if ($voted < 5) {
$u->add_karma(0.2, _('Negativo a retirada de portada'));
Log::insert('user_depublished_vote', $l->id, $id);
}
}
}
}
/***********
* TODO: call for every site (as in promote)
if ($globals['twitter_token'] || $globals['jaiku_user']) {
if ($globals['url_shortener']) {
$short_url = $l->get_short_permalink();
} else {
$short_url = fon_gs($l->get_permalink());
}
$text = _('Retirada de portada') . ': ' . $l->title;
if ($globals['twitter_user'] && $globals['twitter_token']) {
twitter_post($text, $short_url);
}
if ($globals['jaiku_user'] && $globals['jaiku_key']) {
jaiku_post($text, $short_url);
}
}
*******/
}
}
}
}
示例6: intval
// The first element is always a "/"
$comment->id = intval($url_args[0]);
} else {
$url_args = preg_split('/\\/+/', $_REQUEST['id']);
$comment->id = intval($url_args[0]);
if ($comment->id > 0 && $globals['base_comment_url']) {
// Redirect to the right URL if the link has a "semantic" uri
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $comment->get_relative_individual_permalink());
die;
}
}
if (!$comment->read()) {
do_error(_('comentario no encontrado'), 404);
}
$link = Link::from_db($comment->link, null, false);
if ($link->is_discarded()) {
$globals['ads'] = false;
$globals['noindex'] = true;
}
$globals['link'] = $link;
$globals['permalink'] = 'http://' . get_server_name() . $comment->get_relative_individual_permalink();
// Change to a min_value is times is changed for the current link_status
if ($globals['time_enabled_comments_status'][$link->status]) {
$globals['time_enabled_comments'] = min($globals['time_enabled_comments_status'][$link->status], $globals['time_enabled_comments']);
}
// Check for comment post
if ($_POST['process'] == 'newcomment') {
$new = new Comment();
$new_comment_error = $new->save_from_post($link);
}
示例7: print_comment_list
function print_comment_list($comments, $user)
{
global $globals, $current_user;
$comment = new Comment();
$timestamp_read = 0;
$last_link = 0;
$ids = array();
foreach ($comments as $dbcomment) {
$comment = Comment::from_db($dbcomment->comment_id);
// Don't show admin comment if it's her own profile.
if ($comment->type == 'admin' && !$current_user->admin && $user->id == $comment->author) {
continue;
}
if ($last_link != $dbcomment->link_id) {
$link = Link::from_db($dbcomment->link_id, null, false);
// Read basic
echo '<h4>';
echo '<a href="' . $link->get_permalink() . '">' . $link->title . '</a>';
echo ' [' . $link->comments . ']';
echo '</h4>';
$last_link = $link->id;
}
if ($comment->date > $timestamp_read) {
$timestamp_read = $comment->date;
}
echo '<ol class="comments-list">';
echo '<li>';
$comment->link_object = $link;
$comment->print_summary(2000, false);
echo '</li>';
echo "</ol>\n";
$ids[] = $comment->id;
}
Haanga::Load('get_total_answers_by_ids.html', array('type' => 'comment', 'ids' => implode(',', $ids)));
// Return the timestamp of the most recent comment
return $timestamp_read;
}
示例8: intval
<?php
// The source code packaged with this file is Free Software, Copyright (C) 2011 by
// Ricardo Galli <gallir at gmail dot com>.
// 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';
$globals['force_ssl'] = False;
// We open the bar always as http to allow loading no https pages
include mnminclude . 'html1.php';
$url_args = $globals['path'];
$id = intval($globals['path'][1]);
if (!$id > 0 || !($link = Link::from_db($id))) {
do_error(_('enlace no encontrado'), 404);
}
// Mark as read, add click if necessary
$link->add_click();
if ($globals['https'] && !preg_match('/^https:/', $link->url)) {
redirect($link->url);
die;
}
$link->title = text_to_summary($link->title, 80);
// From libs/html1.php do_header()
header('Content-Type: text/html; charset=utf-8');
$globals['security_key'] = get_security_key();
setcookie('k', $globals['security_key'], 0, $globals['base_url']);
// From libks/link.php print_summary()
$link->is_votable();
$link->permalink = $link->get_permalink();
示例9: header
if ($media->create_thumbs($parts[0])) {
header("HTTP/1.0 200 OK");
header('Content-Type: image/jpeg');
$media->thumb->output();
$globals['access_log'] = false;
die;
}
$errn = 404;
break;
case "thumb":
case "thumb_2x":
case "thumb_medium":
// Links' thumbnails
$base = $parts[0];
if (count($parts) == 2 && $parts[1] > 0) {
$link = Link::from_db($parts[1]);
if ($link && ($pathname = $link->try_thumb($base))) {
header("HTTP/1.0 200 OK");
header('Content-Type: image/jpeg');
readfile($pathname);
$globals['access_log'] = false;
die;
}
}
$errn = 404;
break;
case "tmp_thumb":
// Temporal filenames
$name = preg_replace('/^tmp_thumb\\-/', '', $filename);
$path = Upload::get_cache_dir() . '/tmp/';
$pathname = $path . $name;
示例10: do_best_stories
do_best_stories();
do_best_comments();
do_vertical_tags('published');
echo '</div>' . "\n";
/*** END SIDEBAR ***/
echo '<div id="newswrap">' . "\n";
echo '<div class="topheading"><h2>' . _('comentarios más valorados 24 horas') . '</h2></div>';
$last_link = 0;
$counter = 0;
echo '<div class="comments">';
$min_date = date("Y-m-d H:00:00", time() - 86000);
// about 24 hours
$comments = $db->get_results("SELECT comment_id, link_id FROM comments, links WHERE comment_date > '{$min_date}' and link_id=comment_link_id ORDER BY comment_karma desc, link_id asc limit 25");
if ($comments) {
foreach ($comments as $dbcomment) {
$link = Link::from_db($dbcomment->link_id, null, false);
$comment = Comment::from_db($dbcomment->comment_id);
if ($last_link != $link->id) {
echo '<h3>';
echo '<a href="' . $link->get_relative_permalink() . '">' . $link->title . '</a>';
echo '</h3>';
}
echo '<ol class="comments-list">';
echo '<li>';
$comment->print_summary($link, 2000, false);
echo '</li>';
if ($last_link != $link->id) {
$last_link = $link->id;
$counter++;
}
echo "</ol>\n";
示例11: do_most_clicked_stories
function do_most_clicked_stories()
{
global $db, $globals, $dblang;
if ($globals['mobile']) {
return;
}
$key = 'most_clicked_' . $globals['site_shortname'] . $globals['v'] . '_' . $globals['meta_current'];
if (memcache_mprint($key)) {
return;
}
echo '<!-- Calculating ' . __FUNCTION__ . ' -->';
if ($globals['meta_current'] && $globals['meta_categories']) {
$category_list = 'and link_category in (' . $globals['meta_categories'] . ')';
$title = sprintf(_('más visitadas «%s»'), $globals['meta_current_name']);
} else {
$category_list = '';
$title = _('más visitadas');
}
$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
$res = $db->get_results("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' {$category_list} and date > '{$min_date}' and link_clicks.id = link order by value desc limit 5");
if ($res) {
$links = array();
$url = $globals['base_url'] . 'topclicked.php';
$link = new Link();
foreach ($res as $l) {
$link = Link::from_db($l->link_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);
}
if ($link->negatives >= $link->votes / 10) {
$link->warn = true;
}
$links[] = $link;
}
$vars = compact('links', 'title', 'url');
$output = Haanga::Load('most_clicked_stories.html', $vars, true);
echo $output;
memcache_madd($key, $output, 180);
}
}
示例12: intval
if (empty($_GET['id']) || empty($_GET['fields'])) {
die;
}
$id = intval($_GET['id']);
$fields = clean_input_string($_GET['fields']);
// It has to remove parenthesis
if (empty($_GET['what'])) {
$what = 'link';
} else {
$what = $_GET['what'];
}
$object = false;
switch ($what) {
case 'link':
case 'links':
$object = Link::from_db($id, null, false);
break;
case 'comment':
case 'comments':
$object = Comment::from_db($id);
break;
case 'post':
case 'posts':
$object = Post::from_db($id);
break;
}
if (!$object) {
die;
}
$output = new stdClass();
foreach (preg_split('/,/', $fields, 10, PREG_SPLIT_NO_EMPTY) as $f) {
示例13: get_related
//.........这里部分代码省略.........
foreach ($a as $w) {
$w = trim($w);
$wlower = mb_strtolower(unaccent($w));
$len = mb_strlen($w);
if (isset($words[$wlower])) {
continue;
}
if (preg_match('/\\s/', $w)) {
$wlower = "\"{$wlower}\"";
$phrases++;
}
$h = sphinx_doc_hits($wlower);
$hits[$wlower] = $h;
if ($h < 1 || $h > $maxid / 10) {
continue;
}
// If 0 or 1 it won't help to the search, too frequents neither
// Store the frequency
$freq = $h / $maxid;
if (!isset($freqs[$wlower]) || $freqs[$wlower] > $freq) {
$freqs[$wlower] = $freq;
}
if ($freq < $freq_min) {
$freq_min = max(0.0001, $freq);
}
$words[$wlower] = intval($h / 2);
}
// Filter content, check length and that it's begin con capital
$a = preg_split('/[\\s,\\.;:“”–\\"\'\\-\\(\\)\\[\\]«»<>\\/\\?¿¡!]+/u', preg_replace('/https{0,1}:\\/\\/\\S+|[\\[\\(] *\\w{1,6} *[\\)\\]]/i', '', $this->sanitize($this->content)), -1, PREG_SPLIT_NO_EMPTY);
foreach ($a as $w) {
$wlower = mb_strtolower(unaccent($w));
if (!preg_match('/^[A-Z][a-zA-Z]{2,}/', $w)) {
continue;
}
$len = mb_strlen($w);
if (!isset($words[$wlower]) && ($len > 2 || preg_match('/^[A-Z]{2,}$/', $w)) && !preg_match('/^\\d{1,3}\\D{0,1}$/', $w)) {
$h = sphinx_doc_hits($wlower);
$hits[$wlower] = $h;
if ($h < 1 || $h > $maxid / 50) {
continue;
}
// If 0 or 1 it won't help to the search, too frequents neither
if (preg_match('/^[A-Z]/', $w) && $h < $maxid / 1000) {
$coef = max(log10($maxid / $h) - 1, 1);
} else {
$coef = 1;
}
$words[$wlower] = intval($h / $coef);
}
}
// Increase "hits" proportional to word's lenght
// because longer words tends to appear less
foreach ($words as $w => $v) {
$len = mb_strlen($w);
if ($len > 6 && !preg_match('/ /', $w)) {
$words[$w] = $v * $len / 6;
}
}
asort($words);
$i = 0;
$text = '';
foreach ($words as $w => $v) {
// Filter words if we got good candidates
// echo "<!-- $w: ".$freqs[$w]." coef: ".$words[$w]."-->\n";
if ($i > 4 && $freq_min < 0.005 && strlen($w) > 3 && (empty($freqs[$w]) || $freqs[$w] > 0.01 || $freqs[$w] > $freq_min * 100)) {
continue;
}
$i++;
if ($i > 14 or $i > 8 && $v > $maxid / 2000) {
break;
}
$text .= "{$w} ";
}
echo "\n<!-- Search terms: {$text} Phrases: {$phrases} -->\n";
$_REQUEST['q'] = $text;
// Center the date about the the link's date
$_REQUEST['root_time'] = $this->date;
if ($globals['now'] - $this->date > 86400 * 5) {
$this->old = true;
} else {
$this->old = false;
}
$response = do_search(false, 0, $max + 1, false);
if ($response && isset($response['ids'])) {
foreach ($response['ids'] as $id) {
if ($id == $this->id) {
continue;
}
$l = Link::from_db($id);
if (!$l) {
continue;
}
if (empty($l->permalink)) {
$l->permalink = $l->get_permalink();
}
$related[] = $l;
}
}
return $related;
}
示例14: preg_split
if (!isset($_REQUEST['id']) && $globals['base_bar_url'] && $_SERVER['PATH_INFO']) {
$url_args = preg_split('/\\/+/', $_SERVER['PATH_INFO']);
array_shift($url_args);
// The first element is always a "/"
$id = intval($url_args[0]);
} else {
$url_args = preg_split('/\\/+/', $_REQUEST['id']);
$id = intval($url_args[0]);
if ($id > 0 && $globals['base_bar_url']) {
// Redirect to the right URL if the link has a "semantic" uri
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $globals['base_url'] . $globals['base_bar_url'] . $id);
die;
}
}
if (!($link = Link::from_db($id))) {
do_error(_('enlace no encontrado'), 404);
}
// Mark as read, add click if necessary
$link->add_click();
$link->title = text_to_summary($link->title, 80);
// From libs/html1.php do_header()
header('Content-Type: text/html; charset=utf-8');
$globals['security_key'] = get_security_key();
setcookie('k', $globals['security_key'], 0, $globals['base_url']);
// From libks/link.php print_summary()
$link->is_votable();
$link->permalink = $link->get_permalink();
$link->can_vote_negative = !$link->voted && $link->votes_enabled && $link->negatives_allowed(true);
$link->get_box_class();
$vars = compact('type');
示例15: Annotation
$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;
}
$intro = '#' . _('destacada');
$text = "{$intro} {$link->title}";
// Save the history
array_push($history, intval($tops[0]));
while (count($history) > 10) {
array_shift($history);