File: class.tags.php

package info (click to toggle)
collabtive 2.0%2Bdfsg-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,708 kB
  • ctags: 27,425
  • sloc: php: 100,872; sh: 72; makefile: 50
file content (357 lines) | stat: -rw-r--r-- 12,079 bytes parent folder | download | duplicates (2)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?php

class tags {
    public $cloudlimit;
    /**
     * Constructor
     *
     * @access protected
     */
    function __construct()
    {
        $this->cloudlimit = 0;
    }

    /**
     * Formats the an input string to be stored as tags.
     * Possible format: word1,word2,word / word1, word2, word3 / word1 word2 word3
     * OR a mix of the preceding
     *
     * Extracts the words from the string, makes the first character uppercase, and reassembles the tagstring
     *
     * @param string $ tags Tagstring to be formatted
     * @return string worktags Formatted tags
     */
    public function formatInputTags($tags)
    {
        // Trim string
        $tags = trim($tags);
        // Compress string internal spaces:
        $count = 1;
        while ($count) {
            $tags = str_replace("  ", " ", $tags, $count);
        }
        // String liegt jetzt als "txt1, txt2, txt3" / "txt1,txt2,txt3" / "txt1 txt2 txt3" vor,
        // bei entsprechender Usereingabe auch als "txt1 txt2,txt3, txt4"
        $tags = str_replace(" ", "," , $tags);
        // String liegt jetzt als "txt1,,txt2,,txt3" /txt1,txt2,txt3" / "txt1,txt2,txt3" vor,
        // bei entsprechender Usereingabe auch als "txt1,txt2,txt3,,txt4
        $tags = str_replace(",,", "," , $tags);
        // String liegt jetzt als "txt1,txt2,txt3" /txt1,txt2,txt3" / "txt1,txt2,txt3" vor,
        // bei entsprechender Usereingabe auch als "txt1,txt2,txt3,txt4"
        $tags = strtolower($tags);

        if (!empty($tags)) {
            $tags = explode(",", $tags);
            $worktags = "";
            foreach($tags as $tag) {
                if ($tag != "" and $tag != ",") {
                    $tag = trim($tag);
                    $tag = ucfirst($tag);
                    $worktags .= $tag . ",";
                }
            }
            $worktags = substr($worktags, 0, strlen($worktags)-1);
        } else {
            $worktags = "";
        }

        if (!empty($worktags)) {
            return $worktags;
        } else {
            return false;
        }
    }

    /**
     * Splits a tag string into an array
     *
     * @param tagstr $ Tagstring to be split
     * @return array tags Array with the t ags
     */
    public function splitTagStr($tagstr)
    {
        $tags = explode(",", $tagstr);

        if (!empty($tags)) {
            return $tags;
        } else {
            return false;
        }
    }

    /**
     * Gets all the content for a given tag in a given project
     *
     * @param string $ tag The wanted tag
     * @param int $ project The project
     * @return array content The content for the tag
     */
    public function getTagContent($tag, $project)
    {
        $files = $this->getFiles($tag, $project);
        $messages = $this->getMessages($tag, $project);
        $user = $this->getUser($tag);

        $content = array_merge($files, $messages, $user);
        if (!empty($content)) {
            return $content;
        } else {
            return false;
        }
    }
    /**
     * Builds a tagcloud
     *
     * @param string $ tag The wanted tag
     * @param int $ project The project
     * @return array content The content for the tag
     */
    public function getTagcloud($project)
    {
        global $conn;
        $project = (int) $project;

        $sel1 = $conn->query("SELECT tags FROM files WHERE tags != '' AND project = $project");
        $sel2 = $conn->query("SELECT tags FROM messages WHERE tags != '' AND project = $project");

        $tags1 = array();
        $worktags = "";

        while ($sel1 and $dat = $sel1->fetch()) {
            $tag = $dat[0];
            $tag = ucfirst($tag);
            if ($tag != "" and $tag != ",") {
                $worktags .= $tag . ",";
            }
        } while ($sel2 and $dat = $sel2->fetch()) {
            $tag = $dat[0];
            $tag = ucfirst($tag);
            if ($tag != "" and $tag != ",") {
                $worktags .= $tag . ",";
            }
        }

        $worktags = substr($worktags, 0, strlen($worktags)-1);

        $tags1 = explode(",", $worktags);
        $tagsnum = array_count_values($tags1);

        $tagsnum = array_filter($tagsnum, array($this, "limitcloud"));

        $thecloud = new tagcloud($tagsnum);
        $thecloud->itemsPerRow = 3;
        $thecloud->rows = ceil(count($tagsnum) / 3);
        $thecloud->padding = 3;
        $thecloud->maxFontSize = 16;
        $thecloud->minFontSize = 10;
        $thecloud->linkUrlPrefix = "managetags.php?action=gettag&id=$project&tag=";

        return $thecloud->getCloud();
    }
    // SELECT * FROM `files` WHERE tags REGEXP ',{0,1}Wort1,{0,1}'
    private function limitcloud($arr)
    {
        if ($arr > $this->cloudlimit) {
            return true;
        } else {
            return false;
        }
    }
    private function getFiles($query, $project = 0)
    {
        global $conn;
        $project = (int) $project;

        if ($project > 0) {
            $sel = $conn->query("SELECT `ID`,`name`,`desc`,`type`,`datei`,`title`,`project`,`tags` FROM `files` WHERE `tags` LIKE " . $conn->quote("%{$query}%") . " AND project = $project");
        } else {
            $sel = $conn->query("SELECT `ID`,`name`,`desc`,`type`,`datei`,`title`,`project`,`tags` FROM `files` WHERE `tags` LIKE " . $conn->quote("%{$query}%"));
        }

        $files = array();
        while ($sel and $result = $sel->fetch()) {
            if (!empty($result)) {
  	        $qry = $conn->query("SELECT name FROM projekte WHERE ID = $result[project]");
		if ($qry) {
		    $project = $qry->fetch();
		    $project = $project[0];
		}

                $result["pname"] = $project;
                $result["ftype"] = str_replace("/", "-", $result["type"]);
                $set = new settings();
                $settings = $set->getSettings();
                $myfile = CL_ROOT . "/templates/" . $settings["template"] . "/images/symbols/files/" . $result["ftype"] . ".png";
                if (stristr($result["type"], "image")) {
                    $result["imgfile"] = 1;
                } elseif (stristr($result['type'], "text")) {
                    $result["imgfile"] = 2;
                } else {
                    $result["imgfile"] = 0;
                }

                if (!file_exists($myfile)) {
                    $result["ftype"] = "none";
                }
                $result["title"] = stripslashes($result["title"]);
                $result["desc"] = stripslashes($result["desc"]);
                $result["tags"] = stripslashes($result["tags"]);
                $thetags = $this->splitTagStr($result["tags"]);
                $result["tagsarr"] = $thetags;
                $result["tagnum"] = count($result["tagsarr"]);
                $result["type"] = "file";
                $result[3] = "file";
                $result["icon"] = "files.png";
                array_push($files, $result);
            }
        }

        if (!empty($files)) {
            return $files;
        } else {
            return array();
        }
    }

    private function getMessages($query, $project = 0)
    {
        global $conn;
        $project = (int) $project;

        if ($project > 0) {
            $sel = $conn->query("SELECT `ID`,`title`,`text`,`posted`,`user`,`username`,`project`,`tags` FROM messages WHERE `tags` LIKE " . $conn->quote("%{$query}%") . " AND project = $project ");
        } else {
            $sel = $conn->query("SELECT `ID`,`title`,`text`,`posted`,`user`,`username`,`project`,`tags` FROM messages WHERE `tags` LIKE " . $conn->quote("%{$query}%"));
        }

        $messages = array();
        while ($sel and $result = $sel->fetch()) {
            if (!empty($result)) {
	        $qry = $conn->query("SELECT name FROM projekte WHERE ID = $result[project]");
		if ($qry) {
		    $project = $qry->fetch();
		    $project = $project[0];
		}

                $result["pname"] = $project;
                $result["type"] = "message";
                $result["icon"] = "msgs.png";

                $result["tagsarr"] = $this->splitTagStr($result["tags"]);
                $result["tagnum"] = count($result["tagsarr"]);

                $result["title"] = stripslashes($result["title"]);
                $result["text"] = stripslashes($result["text"]);
                $result["username"] = stripslashes($result["username"]);
                $posted = date("d.m.y - H:i", $result["posted"]);
                $result["endstring"] = $posted;
                $result["url"] = "managemessage.php?action=showmessage&amp;mid=$result[ID]&id=$result[project]";
                array_push($messages, $result);
            }
        }

        if (!empty($messages)) {
            return $messages;
        } else {
            return array();
        }
    }

    private function getUser($query)
    {
        global $conn;

        $sel = $conn->query("SELECT `ID`,`email`,`name`,`avatar`,`lastlogin`,`tags`, `gender` FROM user WHERE tags LIKE " . $conn->quote("%{$query}%"));

        $user = array();
        while ($sel and $result = $sel->fetch()) {
            if (!empty($result)) {
                $result["type"] = "user";
                $result["name"] = stripslashes($result["name"]);
                $result["url"] = "manageuser.php?action=profile&amp;id=$result[ID]";
                $result["type"] = "user";
                $result["tagsarr"] = $this->splitTagStr($result["tags"]);
                $result["tagnum"] = count($result["tagsarr"]);
                $result[3] = "user";
                $result["icon"] = ($result['gender'] == "m" ? "user-marker-male.png" : "user-marker-female.png");
                array_push($user, $result);
            }
        }

        if (!empty($user)) {
            return $user;
        } else {
            return array();
        }
    }
}
// end class tags
class tagcloud extends tags {
    public $rows;
    public $itemsPerRow;
    public $minFontSize;
    public $maxFontSize;
    public $padding;
    public $linkUrlPrefix;

    private $keywordsArray;
    private $minTagValue;
    private $maxTagValue;
    private $fontRatio;
    private $fontOffset;

    function __construct ($keys, $rows = 3, $rowitems = 3, $minfont = 10, $maxfont = 20)
    {
        // init default values
        $this->keywordsArray = $keys;

        $this->Rows = $rows;
        $this->itemsPerRow = $rowitems;
        $this->minFontSize = $minfont;
        $this->maxFontSize = $maxfont;
        if (!empty($this->keywordsArray)) {
            $this->minTagValue = min($this->keywordsArray);
            $this->maxTagValue = max($this->keywordsArray);
        }
    }

    function getCloud()
    {
        if (isset($this->maxTagValue) and isset($this->minTagValue) and $this->minTagValue > 0 and $this) {
            $fsize = $this->maxFontSize - $this->minFontSize;
            $tval = $this->maxTagValue - $this->minTagValue;
            if ($fsize > 0 and $tval > 0) {
                $this->fontRatio = $fsize / $tval;
            } else {
                $this->fontRatio = 1;
            }
            $this->fontOffset = $this->maxFontSize - ($this->fontRatio * $this->maxTagValue);
        }
        $htmlCode = "";
        $AbsoluteIndex = 0;

        reset($this->keywordsArray);

        for ($NumofRows = 1;$NumofRows <= $this->rows;$NumofRows++) {
            for ($itemsPerRow = 1;$itemsPerRow <= $this->itemsPerRow;$itemsPerRow++) {
                $AbsoluteIndex++;
                $currentKey = key($this->keywordsArray);
                if (!empty($currentKey)) {
                    $currentValue = $this->keywordsArray[$currentKey];
                }
                $TagSize = floor(($this->fontRatio * $currentValue) + $this->fontOffset);

                $htmlCode .= "<a href=\"" . $this->linkUrlPrefix . $currentKey . "\"style=\"font-size:" . $TagSize . "pt;padding:" . $this->padding . "px;\">" . $currentKey . "</a>";

                next($this->keywordsArray);
            }

            $htmlCode .= "<br />";
        }

        return $htmlCode;
    }
}

?>