Exemple #1
0
<?php

required_params('post');
if (User::is('<=20') && Post::count(array('conditions' => array("user_id = ? AND created_at > ? ", User::$current->id, gmd_math('sub', '1D')))) >= CONFIG::member_post_limit) {
    respond_to_error("Daily limit exceeded", "#error", array('status' => 421));
}
auto_set_params(array('md5'));
$status = User::is('>=30') ? 'active' : 'pending';
Request::$params->post = array_merge(Request::$params->post, array('updater_user_id' => User::$current->id, 'updater_ip_addr' => Request::$remote_ip, 'user_id' => User::$current->id, 'ip_addr' => Request::$remote_ip, 'status' => $status, 'tempfile_path' => $_FILES['post']['tmp_name']['file'], 'tempfile_name' => $_FILES['post']['name']['file'], 'is_upload' => true));
$post = Post::create(Request::$params->post);
if ($post->record_errors->blank()) {
    if (Request::$params->md5 && $post->md5 != strtolower(Request::$params->md5)) {
        $post->destroy();
        respond_to_error("MD5 mismatch", '#error', array('status' => 420));
    } else {
        $api_data = array('post_id' => $post->id, 'location' => url_for('post#show', array('id' => $post->id)));
        if (CONFIG::dupe_check_on_upload && $post->is_image() && empty($post->parent_id)) {
            // if (Request::$format == "xml" || Request::$format == "json") {
            // $options = array('services' => SimilarImages::get_services('local'), 'type' => 'post', 'source' => $post);
            // $res = SimilarImages::similar_images($options);
            // if (!empty($res['posts'])) {
            // $post->tags .= " possible_duplicate";
            // $post->save();
            // $api_data['has_similar_hits'] = true;
            // }
            // }
            $api_data['similar_location'] = url_for('post#similar', array('id' => $post->id, 'initial' => 1));
            respond_to_success("Post uploaded", array('#similar', array('id' => $post->id, 'initial' => 1)), array('api' => $api_data));
        } else {
            respond_to_success("Post uploaded", array('#show', array('id' => $post->id, 'tag_title' => $post->tag_title())), array('api' => $api_data));
        }
Exemple #2
0
 function related()
 {
     if (gmd() > $this->cached_related_expires_on) {
         $length = ceil($this->post_count / 3);
         $length < 12 && ($length = 12);
         $length > 8760 && ($length = 8760);
         DB::update("tags SET cached_related = ?, cached_related_expires_on = ? WHERE id = ?", implode(",", array_flat($this->calculate_related($this->name))), gmd_math('add', 'T' . $length . 'H'), $this->id);
         $this->reload();
     }
     $related = explode(',', $this->cached_related);
     $i = 0;
     $groups = array();
     foreach ($related as $rel) {
         $group[] = $rel;
         if ($i & 1) {
             $groups[] = $group;
             $group = array();
         }
         $i++;
     }
     return $groups;
 }
Exemple #3
0
    }
    // @preload = @preload.delete_if { |post| not post.can_be_seen_by?(@current_user) }
}
if ($from_api and isset(Request::$params->api_version) && Request::$params->api_version == "2" and Request::$format != "json") {
    respond_to_error("V2 API is JSON-only", array(), array('status' => 424));
}
// @posts.replace(results)
$posts = $results;
unset($results);
switch (Request::$format) {
    case 'json':
        if (empty(Request::$params->api_version) || Request::$params->api_version != "2") {
            render('json', to_json(array_map(function ($p) {
                return $p->api_attributes();
            }, (array) $posts)));
            return;
        }
        $api_data = Post::batch_api_data($posts, array('exclude_tags' => !empty(Request::$params->include_tags) ? false : true, 'exclude_votes' => !empty(Request::$params->include_votes) ? false : true, 'exclude_pools' => !empty(Request::$params->include_pools) ? false : true));
        render('json', to_json($api_data));
        break;
    case 'xml':
        ActionView::$layout = false;
        return;
        break;
}
if (!empty($split_tags)) {
    $tags = Tag::parse_query($tags);
} else {
    $tags['include'] = Tag::count_by_period(gmd_math('sub', '1D'), gmd(), array('limit' => 25, 'exclude_types' => CONFIG::$exclude_from_tag_sidebar));
}
calc_pages();
Exemple #4
0
<?php

if (User::is('<=20') && Request::$params->commit == "Post" && Comment::count(array('conditions' => array("user_id = ? AND created_at > ?", User::$current->id, gmd_math('sub', '1H'))) >= CONFIG::member_comment_limit)) {
    # TODO: move this to the model
    respond_to_error("Hourly limit exceeded", "#index", array('status' => 421));
}
$user_id = User::$current->id;
Request::$params->comment = array_merge(Request::$params->comment, array('ip_addr' => Request::$remote_ip, 'user_id' => $user_id));
// $comment = new Comment('empty', Request::$params->comment);
$comment = Comment::blank(Request::$params->comment);
// vde(Request::$params->comment);
// vde($comment);
if (Request::$params->commit == "Post without bumping") {
    $comment->do_not_bump_post = true;
}
if ($comment->save()) {
    respond_to_success("Comment created", "#index");
} else {
    respond_to_error($comment, "#index");
}
Exemple #5
0
<?php

if (!($forum_post = ForumPost::find(request::$params->id))) {
    return 404;
}
include_model('comment');
create_page_params();
set_title($forum_post->title);
$children = ForumPost::find_all(array('order' => "id", 'per_page' => 30, 'conditions' => array("parent_id = ?", request::$params->id), 'page' => request::$params->page));
if (!User::$current->is_anonymous && User::$current->last_forum_topic_read_at < $forum_post->updated_at && $forum_post->updated_at < gmd_math('sub', 'T3S')) {
    User::$current->update_attribute('last_forum_topic_read_at', $forum_post->updated_at);
}
calc_pages();
respond_to_list($forum_post);