Esempio n. 1
0
 public static function find_all_by_url($url)
 {
     $url = ArtistUrl::normalize($url);
     $artists = new Rails\ActiveRecord\Collection();
     while ($artists->blank() && strlen($url) > 10) {
         $u = str_replace('*', '%', $url) . '%';
         $artists->merge(Artist::where("artists.alias_id IS NULL AND artists_urls.normalized_url LIKE ?", $u)->joins("JOIN artists_urls ON artists_urls.artist_id = artists.id")->order("artists.name")->take());
         # Remove duplicates based on name
         $artists->unique('name');
         $url = dirname($url);
     }
     return $artists->slice(0, 20);
 }
Esempio n. 2
0
 public function moderate()
 {
     $this->set_title('Moderation Queue');
     if ($this->request()->isPost()) {
         $posts = new Rails\ActiveRecord\Collection();
         if ($this->params()->ids) {
             foreach (array_keys($this->params()->ids) as $post_id) {
                 $post = Post::find($post_id);
                 if ($this->params()->commit == "Approve") {
                     $post->approve(current_user()->id);
                 } elseif ($this->params()->commit == "Delete") {
                     $post->destroy_with_reason($this->params()->reason ? $this->params()->reason : $this->params()->reason2, current_user());
                     # Include post data for the parent: deleted posts aren't counted as children, so
                     # their has_children attribute may change.
                     if ($post->parent_id) {
                         $posts[] = $post->get_parent();
                     }
                 }
                 # Post may have been permanently deleted.
                 if (!CONFIG()->delete_posts_permanently) {
                     $post->reload();
                 }
                 $posts[] = $post;
             }
         }
         $posts->unique();
         if ($this->request()->format() == "json" || $this->request()->format() == "xml") {
             $api_data = Post::batch_api_data($posts->members());
         } else {
             $api_data = array();
         }
         if ($this->params()->commit == "Approve") {
             $this->respond_to_success("Post approved", "#moderate", array('api' => $api_data));
         } elseif ($this->params()->commit == "Delete") {
             $this->respond_to_success("Post deleted", "#moderate", array('api' => $api_data));
         }
     } else {
         if ($this->params()->query) {
             list($sql, $params) = Post::generate_sql($this->params()->query, array('pending' => true, 'order' => "id desc"));
             $this->pending_posts = Post::findBySql($sql, $params);
             list($sql, $params) = Post::generate_sql($this->params()->query, array('flagged' => true, 'order' => "id desc"));
             $this->flagged_posts = Post::findBySql($sql, $params);
         } else {
             $this->pending_posts = Post::where("status = 'pending'")->order("id desc")->take();
             $this->flagged_posts = Post::where("status = 'flagged'")->order("id desc")->take();
         }
     }
 }