예제 #1
0
 public function edit($permalink = null)
 {
     $news = self::load_news($permalink, false);
     if ($this->post) {
         $news->title = $this->PostData('title');
         $news->permalink = $this->PostData('permalink');
         $news->summary = $this->PostData('summary');
         $news->body = $this->PostData('body');
         $news->fullbody = $this->PostData('fullbody');
         $news->published = $this->PostData('published');
         $news->tag_id = $this->PostData('tag_id');
         $news->ipb_id = $this->PostData('ipb_id');
         $news->image = $this->PostData('image');
         if ($this->PostData('publish_now') == 1) {
             $news->publish_at = time();
         } else {
             $news->set_publish_at($this->PostData('publish_at'));
         }
         if ($news->save()) {
             $news->update_tags($this->PostData('tags'));
             $news->forumSync();
             Site::Flash("notice", "The news has been edited");
             Redirect("admin/news");
         }
     }
     $this->assign("news", $news);
     $tags = array('' => 'None');
     $allTags = Tag::find_all("tags.system = TRUE", "tags.tag ASC");
     foreach ($allTags as $tag) {
         $tags[$tag->id] = $tag->tag;
     }
     $this->assign("tags", $tags);
     $this->tinymce = true;
     $this->title = "Edit News";
     $this->render("news/edit.tpl");
 }
예제 #2
0
 static function parse_query($query, $options = array())
 {
     $q = array();
     foreach (self::scan_query($query) as $token) {
         if (preg_match('/^([qse])$/', $token, $m)) {
             $q['rating'] = $m[1];
             continue;
         }
         if (preg_match('/^(unlocked|deleted|ext|user|sub|vote|-vote|fav|md5|-rating|rating|width|height|mpixels|score|source|id|date|pool|-pool|parent|order|change|holds|pending|shown|limit):(.+)$/', $token, $m)) {
             if ($m[1] == "user") {
                 $q['user'] = $m[2];
             } elseif ($m[1] == "vote") {
                 list($vote, $user) = explode(':', $m[2]);
                 if ($user = User::find_by_name($user)) {
                     $user_id = $user->id;
                 } else {
                     $user_id = null;
                 }
                 $q['vote'] = array(self::parse_helper($vote), $user_id);
             } elseif ($m[1] == "-vote") {
                 if ($user = User::find_by_name($m[2])) {
                     $user_id = $user->id;
                 } else {
                     $user_id = null;
                 }
                 $q['vote_negated'] = $user_id;
                 // $q['vote_negated'] = User.find_by_name_nocase($m[2]).id rescue nil
                 if (!$q['vote_negated']) {
                     $q['error'] = "no user named " . $m[2];
                 }
             } elseif ($m[1] == "fav") {
                 $q['fav'] = $m[2];
             } elseif ($m[1] == "sub") {
                 $q['subscriptions'] = $m[2];
             } elseif ($m[1] == "md5") {
                 $q['md5'] = $m[2];
             } elseif ($m[1] == "-rating") {
                 $q['rating_negated'] = $m[2];
             } elseif ($m[1] == "rating") {
                 $q['rating'] = $m[2];
             } elseif ($m[1] == "id") {
                 $q['post_id'] = self::parse_helper($m[2]);
             } elseif ($m[1] == "width") {
                 $q['width'] = self::parse_helper($m[2]);
             } elseif ($m[1] == "height") {
                 $q['height'] = self::parse_helper($m[2]);
             } elseif ($m[1] == "mpixels") {
                 $q['mpixels'] = self::parse_helper($m[2], 'float');
             } elseif ($m[1] == "score") {
                 $q['score'] = self::parse_helper($m[2]);
             } elseif ($m[1] == "source") {
                 $q['source'] = $m[2] . '%';
             } elseif ($m[1] == "date") {
                 $q['date'] = self::parse_helper($m[2], 'date');
             } elseif ($m[1] == "pool") {
                 $q['pool'] = $m[2];
                 if (preg_match('/^(\\d+)$/', $q['pool'])) {
                     $q['pool'] = (int) $q['pool'];
                 }
             } elseif ($m[1] == "-pool") {
                 $pool = $m[2];
                 if (preg_match('/^(\\d+)$/', $pool)) {
                     $pool = (int) $pool;
                 }
                 $q['exclude_pools'][] = $pool;
             } elseif ($m[1] == "parent") {
                 $q['parent_id'] = $m[2] == "none" ? false : (int) $m[2];
             } elseif ($m[1] == "order") {
                 $q['order'] = $m[2];
             } elseif ($m[1] == "unlocked") {
                 $m[2] == "rating" && ($q['unlocked_rating'] = true);
             } elseif ($m[1] == "deleted") {
                 # This naming is slightly odd, to retain API compatibility with Danbooru's "deleted:true"
                 # search flag.
                 if ($m[2] == "true") {
                     $q['show_deleted_only'] = true;
                 } elseif ($m[2] == "all") {
                     $q['show_deleted_only'] = false;
                 }
                 # all posts, deleted or not
             } elseif ($m[1] == "ext") {
                 $q['ext'] = $m[2];
             } elseif ($m[1] == "change") {
                 $q['change'] = self::parse_helper($m[2]);
             } elseif ($m[1] == "shown") {
                 $q['shown_in_index'] = $m[2] == "true";
             } elseif ($m[1] == "holds") {
                 if ($m[2] == "true" or $m[2] == "only") {
                     $q['show_holds'] = 'only';
                 } elseif ($m[2] == "all") {
                     $q['show_holds'] = 'yes';
                 } elseif ($m[2] == "false") {
                     $q['show_holds'] = 'hide';
                 }
             } elseif ($m[1] == "pending") {
                 if ($m[2] == "true" or $m[2] == "only") {
                     $q['show_pending'] = 'only';
                 } elseif ($m[2] == "all") {
                     $q['show_pending'] = 'yes';
                 } elseif ($m[2] == "false") {
                     $q['show_pending'] = 'hide';
                 }
             } elseif ($m[1] == "limit") {
                 $q['limit'] = $m[2];
             }
         } elseif ($token[0] == '-' && strlen($token) > 1) {
             $q['exclude'][] = substr($token, 1);
         } elseif ($token[0] == '~' && count($token) > 1) {
             $q['include'][] = substr($token, 1);
         } elseif (strstr('*', $token)) {
             $tags = Tag::find_all(array('conditions' => array("name LIKE ?", $token), 'select' => "name, post_count", 'limit' => 25, 'order' => "post_count DESC"));
             foreach ($tags as $i) {
                 $matches = $i->name;
             }
             !$matches && ($matches = array('~no_matches~'));
             $q['include'] += $matches;
         } else {
             $q['related'][] = $token;
         }
     }
     if (!isset($options['skip_aliasing'])) {
         isset($q['exclude']) && ($q['exclude'] = TagAlias::to_aliased($q['exclude']));
         isset($q['include']) && ($q['include'] = TagAlias::to_aliased($q['include']));
         isset($q['related']) && ($q['related'] = TagAlias::to_aliased($q['related']));
     }
     return $q;
 }
예제 #3
0
    $cond_params[] = Request::$params->after_id;
}
if (!empty(Request::$params->id)) {
    $conds[] = 'id = ?';
    $cond_params[] = Request::$params->id;
}
switch (Request::$format) {
    case 'json':
        $tags = Tag::find_all(array('order' => $order, 'limit' => $limit, 'conditions' => array(implode(" AND ", $conds), $cond_params)));
        render('json', to_json($tags));
        break;
    case 'xml':
        if (empty(request::$params->order)) {
            $order = null;
        }
        $conds = implode(' AND ', $conds);
        // if conds == "true" && CONFIG["web_server"] == "nginx" && File.exists?("#{RAILS_ROOT}/public/tags.xml")
        // # Special case: instead of rebuilding a list of every tag every time, cache it locally and tell the web
        // # server to stream it directly. This only works on Nginx.
        // response.headers["X-Accel-Redirect"] = "#{RAILS_ROOT}/public/tags.xml"
        // render :nothing => true
        // else
        $tags = Tag::find('all', array('order' => $order, 'limit' => $limit, 'conditions' => array($conds, $cond_params)));
        render('xml', $tags->to_xml(), array('root', "tags"));
        // end
        break;
}
array_unshift($cond_params, implode(" AND ", $conds));
$params = array('order' => $order, 'per_page' => 50, 'page' => Request::$params->page, 'conditions' => $cond_params, 'calc_rows' => 'found_posts');
$tags = Tag::find_all($params);
calc_pages();
예제 #4
0
 /**
  *	@fn diario_post_add
  *	@short Action method to save a newly composed article.
  */
 public function diario_post_add()
 {
     if (isset($_POST)) {
         $conn = Db::get_connection();
         $post = new DiarioPost($_POST);
         $post->author = $_COOKIE['_u'];
         $post->save();
         // Delete old tags (if any)
         $conn->prepare('DELETE FROM `diario_posts_tags` ' . "WHERE `post_id` = '{1}'", $post->id);
         $conn->exec();
         // Save tags
         $tag_tokens = explode(',', $_POST['tag']);
         $tag_tokens = array_map('trim', $tag_tokens);
         $tag_factory = new Tag();
         foreach ($tag_tokens as $tag_token) {
             if (empty($tag_token)) {
                 continue;
             }
             $tag_results = $tag_factory->find_all(array('where_clause' => "`tag` = '{$tag_token}'"));
             if (count($tag_results) > 0) {
                 $tag = $tag_results[0];
             } else {
                 $tag = new Tag();
                 $tag->tag = $tag_token;
                 $tag->save();
             }
             $conn->prepare('INSERT IGNORE INTO `diario_posts_tags` ' . '(`post_id`, `tag_id`) ' . "VALUES ('{1}', '{2}')", $post->id, $tag->id);
             $conn->exec();
             Db::close_connection($conn);
         }
         // Expires the cache of Diario
         $this->expire_cached_page(array('controller' => 'diario', 'action' => 'index'));
         $this->expire_cached_page(array('controller' => 'diario', 'action' => 'last_posts'));
         $this->expire_cached_page(array('controller' => 'diario', 'action' => 'read', 'id' => $post->id));
         // Expires the cache of Diario feed
         $this->expire_cached_page(array('controller' => 'feed', 'action' => 'diario'));
     }
     $this->redirect_to(array('action' => 'diario_post_list'));
 }
예제 #5
0
<h3><?php 
echo l("Tag cloud");
?>
</h3>
<div id="tag-cloud">
<?php 
$tag_factory = new Tag();
$tags = $tag_factory->find_all(array('order_by' => '`tag` ASC'));
$max = 0;
if (count($tags) > 0) {
    foreach ($tags as $tag) {
        $tag->has_and_belongs_to_many('diario_posts');
        //print_r($tag);
        $max = max($max, count($tag->diario_posts));
    }
    foreach ($tags as $tag) {
        if (($weight = count($tag->diario_posts)) > 0) {
            $style = 'font-size:' . round($weight / $max * 16 + 10) . 'px';
            ?>
	<?php 
            echo $this->link_to($tag->tag, array('action' => 'tag', 'id' => $tag->id, 'style' => $style));
        }
    }
} else {
    echo em(l('No items'), NULL);
}
?>
</div>