File: Images.php

package info (click to toggle)
icinga-web 1.7.1%2Bdfsg2-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 83,496 kB
  • sloc: php: 252,926; xml: 142,251; sql: 8,190; sh: 1,039; makefile: 575; perl: 215; python: 194
file content (104 lines) | stat: -rw-r--r-- 4,007 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
class Images {
    function load($data){
        $db = new SQLiteDatabase("sql/imgorg.db");
        $tags = $data->tags;
        $album = $data->album;
        $qry = 'select i.filename as filename, i.url as url, i.id as id from Images i';
        $where = array();
        if ($tags) {
            for ($i = 0;$i < sizeof($tags);$i++) {
                $qry .= ' INNER JOIN Images_Tags it'.$i.' ON i.id = it'.$i.'.image_id';
                array_push($where,' it'.$i.'.tag_id = "'.$tags[$i].'"');
            }
        }
        if ($album) {
            $qry .= ' INNER JOIN Albums a ON i.album_id = a.id';
            array_push($where, ' a.id ="'.$album.'"');
        }
        if ($where) {
            $qry .= ' WHERE'.join(" AND", $where);
        }
        $res = $db->query($qry);
        return $res->fetchAll();
//        return $qry;
    }

    function upload($data, $files){
        $name = $files["Filedata"]["name"];
        $db = new SQLiteDatabase("sql/imgorg.db");
        $db->queryExec('INSERT INTO Images (filename, url) VALUES("'.$name.'","images/'.$name.'")');
        $q = $db->query('SELECT * FROM Images WHERE filename = "'.$name.'"');
        move_uploaded_file($files["Filedata"]["tmp_name"],"../images/".$name);

        return array(
            'data' => $files["Filedata"],
            'res'  => $q->fetchObject()
            //,
            //'test' => $phm->getImageQuality()
            );
    }

    function addToAlbum($data) {
        $images = $data->images;
        $album = $data->album;
        $db = new SQLiteDatabase("sql/imgorg.db");
        for ($i = 0;$i < sizeof($images);$i++) {
//            $db->queryExec('INSERT INTO Albums_Images (image_id, album_id) VALUES ("'.$images[$i].'","'.$album.'")');
            $db->queryExec('UPDATE Images SET album_id = "'.$album.'" WHERE id ="'.$images[$i].'"');
        }
        return array('success' => true, 'images' => $images, 'album' => $album);
    }

    function tagImage($data) {
        $images = $data->images;
        $tag = $data->tag;
        $db = new SQLiteDatabase("sql/imgorg.db");
        // if it is a known tag the id is sent, otherwise a new string is, so we need to insert
        if (!is_numeric($tag)) {
            $db->queryExec('INSERT INTO Tags (text) VALUES ("'.$tag.'")');
            $q = $db->query('SELECT id FROM Tags WHERE text = "'.$tag.'"');
            $tag = $q->fetchObject()->id;
        }
        for ($i = 0;$i < sizeof($images);$i++) {
            $db->queryExec('INSERT INTO Images_Tags (image_id, tag_id) VALUES ("'.$images[$i].'","'.$tag.'")');
        }
        return array('success' => true, 'images' => $images, 'tag' => $tag);
    }

    function rename($data) {
        $db = new SQLiteDatabase("sql/imgorg.db");
        $image = $data->image;
        $name = $data->name;
        $url = $data->url;
        $urls = split('/',$url);
        array_pop($urls);
        $newUrl = (join('/',$urls)).'/'.$name;

        $db->queryExec('UPDATE Images SET url = "'.$newUrl.'", filename = "'.$name.'" WHERE id = "'.$image.'"');
        rename('../'.$url, '../'.$newUrl);

        return array('image' => $image, 'name' => $name, 'url' => $newUrl);
    }

    function remove($data) {
        $db = new SQLiteDatabase("sql/imgorg.db");
        $images = $data->images;
        for ($i = 0;$i < sizeof($images);$i++) {
            $res = $db->query('SELECT url FROM Images where id ="'.$images[$i].'"');
            $url = $res->fetchObject()->url;
            unlink('../'.$url);
            $db->queryExec('DELETE FROM Images WHERE id ="'.$images[$i].'"');
            $db->queryExec('DELETE FROM Images_Tags WHERE image_id ="'.$images[$i].'"');
        }
    }

    function getInfo($data) {
        $db = new SQLiteDatabase("sql/imgorg.db");
        $image = $data->image;
        $q = $db->query('SELECT url FROM Images WHERE id = "'.$image.'"');
        $path = $q->fetchObject()->url;
        $ret = exif_read_data('../'.$path);
        return $ret;
    }
}