예제 #1
0
    public function doGET()
    {
        global $entry;
        // FIXME: ew
        $id = intval($entry);
        $_SESSION['verify.' . $id] = sha1(time() . $id);
        $sql = sprintf("select title,width,height,size,date,views,ip,safe,hash,\n\t\t\t\t\tchild,type,user from entries where id=%d", $id);
        if (!($result = $this->db->query($sql))) {
            die("Query Error");
        }
        $entry = $result->fetch_assoc();
        if ($entry['width'] > 800) {
            $ratio = $entry['width'] / $entry['height'];
            $width = 800;
            $height = $width / $ratio;
        } else {
            $width = $entry['width'];
            $height = $entry['height'];
        }
        // check for custom thumbnail
        $sql = sprintf('select id from thumbs where entry=%d && custom=1', $id);
        $result = $this->db->query($sql);
        $custom = $result->num_rows == 1;
        $display_id = $entry['child'] ? $entry['child'] : $id;
        $filename = $id . '.' . imgtypetoext($entry['type']);
        if ($entry['user'] > 0) {
            $sql = sprintf('select alias,username from users where id=%d', $entry['user']);
            if ($info = $this->db->select($sql)) {
                $user = '******' . DB_URL . DB_LOC . '/user/' . $info['username'] . '/">' . $info['alias'] . '</a>';
            }
        } else {
            $user = $entry['ip'];
        }
        $sql = sprintf('select t.name from tags t, tagmap m where m.entry=%d && 
									t.id=m.tag', $id);
        if (!($tags = $this->db->query($sql))) {
            die("Query Error");
        }
        include DB_PATH . '/core/themes/' . DB_THEME . '/view.php';
    }
예제 #2
0
function imgtypetomime($type)
{
    return 'image/' . imgtypetoext($type);
}
예제 #3
0
    public function doGET()
    {
        // If there are tags
        if ($this->request->tags) {
			$taglist = split(' ', $this->request->tags);
			foreach ($taglist as $k => $value) {
				$tag = $this->db->real_escape_string(strval($value));
				switch ($value{0}) {
					case '-': # don't show entries with these tags
						$tag = substr($tag, 1);
						$joins .= " left outer join tagmap t{$k} on t{$k}.entry=entries.id && t{$k}.tag=(SELECT id FROM tags WHERE name='$tag') ";
						$where[] = " t{$k}.tag is null ";
						break;
					case '~':
						# not implemented yet
						break;
					case 's': # sorting
						if ((strlen($value) > 2) && $value{1} == ':') {
							switch (substr($value, 2)) {
								case 's':
								case 'size':
									$sort = 'size';
									break;
								case 'v':
								case 'views':
									$sort = 'views';
									break;
								case 'd':
								case 'date':
								default:
									$sort = 'date';
									break;
							}
							break;
						}
					default: # show entries with these tags
						if (substr($value, -1, 1) == '*') {
							$joins .= " inner join tagmap t{$k} on t{$k}.entry=entries.id && t{$k}.tag in (SELECT id FROM tags WHERE name like '" .
									substr($tag, 0, -1) . "%') ";
						} else {
							$joins .= " inner join tagmap t{$k} on t{$k}.entry=entries.id && t{$k}.tag=(SELECT id FROM tags WHERE name='$tag') ";
						}
						break;
				}
			}
			if ($where) 
				$where = ' && ' . implode(' && ', $where);
        }

        if (isset($_SESSION['hide']))
            $where .= ' && safe=1 ';
		$nsid = ($_SESSION['namespace_id']) ? $_SESSION['namespace_id'] : DB_PUBNS;
		$where .= sprintf(' && namespace=%d', $nsid);

        $page = ($this->request->entry) ? $this->request->entry : 1;

        if (!$sort)
            $sort = 'date';
        $direction = 'desc';
        $count = 50;
        $offset = $count * ($page - 1);

        $sql = sprintf("select SQL_CALC_FOUND_ROWS id,title,type from entries %s where parent is null %s order by %s %s limit %d offset %d",
                                $joins, $where, $sort, $direction, $count, $offset);
        $result = $this->db->query($sql);
        $num = array_pop($this->db->query("SELECT FOUND_ROWS()")->fetch_row());
        if (!$result) die("Failed Query");

        ?>
            <?php tagField($this->db, 50); ?>
            <div id="search">
            <form action="/search/" method="post">
            search <input type="text" name="search" value="<?=$this->request->tags;?>" />
            </form>
            </div>
            <div id="images">
            <? for($i = 1; $row = $result->fetch_assoc(); ++$i) { ?>	
                <a title="<?=$row['title'];?>" href="<?=DB_LOC;?>/view/<?=$row['id'];?>/">
                    <img src="<?=DB_LOC;?>/thumb/<?=$row['id'];?>/<?=$row['id'];?>.<?=imgtypetoext($row['type']);?>" alt="<?=$row['title'];?>" />
                </a>
            <? } ?>
            </div>
        <?
        $pages = ceil($num / $count);
        $tagurl = ($this->request->tags) ? DB_LOC . "/tags/$this->request->tags" : DB_LOC;
        if ($pages > 1 && $page > 1)
            echo "<a href=\"$tagurl/page/" . ($page-1) . "/\">&lt;prev</a>";
        if ($pages > 1) {
            for ($i = 1; $i <= $pages; ++$i) {
                if ($i != $page)
                    echo " <a href=\"$tagurl/page/$i/\">$i</a> ";
                else
                    echo " $i ";
            }
            if ($page < $pages)
                echo "<a href=\"$tagurl/page/" . ($page+1) . "/\">next&gt;</a>";
        }
    }