OSDN Git Service

3.15 taka-san version
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / BLOG.php
1 <?php\r
2 \r
3 /**\r
4   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) \r
5   * Copyright (C) 2002-2004 The Nucleus Group\r
6   *\r
7   * This program is free software; you can redistribute it and/or\r
8   * modify it under the terms of the GNU General Public License\r
9   * as published by the Free Software Foundation; either version 2\r
10   * of the License, or (at your option) any later version.\r
11   * (see nucleus/documentation/index.html#license for more info)\r
12   *\r
13   * A class representing a blog and containing functions to get that blog shown\r
14   * on the screen \r
15   */\r
16 class BLOG {\r
17         \r
18         // blog id\r
19         var $blogid;\r
20         \r
21         // ID of currently selected category\r
22         var $selectedcatid;\r
23         \r
24         // After creating an object of the blog class, contains true if the BLOG object is \r
25         // valid (the blog exists)\r
26         var $isValid;\r
27         \r
28         // associative array, containing all blogsettings (use the get/set functions instead)\r
29         var $settings;\r
30         \r
31         /**\r
32          * Creates a new BLOG object for the given blog\r
33          *\r
34          * @param $id blogid\r
35          */\r
36         function BLOG($id) {\r
37                 $this->blogid = intval($id);\r
38                 $this->readSettings();\r
39 \r
40                 // try to set catid \r
41                 // (the parse functions in SKIN.php will override this, so it's mainly useless)\r
42                 global $catid;\r
43                 $this->setSelectedCategory($catid);\r
44         }\r
45 \r
46         /**\r
47          * Shows the given amount of items for this blog\r
48          *\r
49          * @param $template\r
50          *              String representing the template _NAME_ (!)\r
51          * @param $amountEntries \r
52          *              amount of entries to show\r
53          * @param $startpos\r
54          *              offset from where items should be shown (e.g. 5 = start at fifth item)\r
55          * @returns int\r
56          *              amount of items shown\r
57          */\r
58         function readLog($template, $amountEntries, $offset = 0, $startpos = 0) {\r
59                 return $this->readLogAmount($template,$amountEntries,'','',1,1,$offset, $startpos);\r
60         }\r
61 \r
62         /**\r
63          * Shows an archive for a given month\r
64          *\r
65          * @param $year\r
66          *              year\r
67          * @param $month\r
68          *              month \r
69          * @param $template\r
70          *              String representing the template name to be used\r
71          */\r
72         function showArchive($templatename, $year, $month, $day=0) {\r
73                 \r
74                 // create extra where clause for select query\r
75                 if ($day == 0) {\r
76                         $timestamp_start = mktime(0,0,0,$month,1,$year);\r
77                         $timestamp_end = mktime(0,0,0,$month+1,1,$year);  // also works when $month==12\r
78                 } else {\r
79                         $timestamp_start = mktime(0,0,0,$month,$day,$year);\r
80                         $timestamp_end = mktime(0,0,0,$month,$day+1,$year);  \r
81                 }\r
82                 $extra_query = ' and i.itime>=' . mysqldate($timestamp_start)\r
83                              . ' and i.itime<' . mysqldate($timestamp_end);\r
84                 \r
85         \r
86                 $this->readLogAmount($templatename,0,$extra_query,'',1,1);\r
87 \r
88         }\r
89 \r
90 \r
91         // sets/gets current category (only when category exists)\r
92         function setSelectedCategory($catid) {\r
93                 if ($this->isValidCategory($catid) || (intval($catid) == 0)) \r
94                         $this->selectedcatid = intval($catid);\r
95         }\r
96         \r
97         function setSelectedCategoryByName($catname) {\r
98                 $this->setSelectedCategory($this->getCategoryIdFromName($catname));\r
99         }\r
100 \r
101         function getSelectedCategory() { \r
102                 return $this->selectedcatid; \r
103         }\r
104 \r
105         /**\r
106          * Shows the given amount of items for this blog\r
107          *\r
108          * @param $template\r
109          *              String representing the template _NAME_ (!)\r
110          * @param $amountEntries\r
111          *              amount of entries to show (0 = no limit)\r
112          * @param $extraQuery\r
113          *              extra conditions to be added to the query\r
114          * @param $highlight\r
115          *              contains a query that should be highlighted\r
116          * @param $comments\r
117          *              1=show comments 0=don't show comments\r
118          * @param $dateheads\r
119          *              1=show dateheads 0=don't show dateheads\r
120          * @param $offset\r
121          *              offset\r
122          * @returns int\r
123          *              amount of items shown\r
124          */\r
125         function readLogAmount($template, $amountEntries, $extraQuery, $highlight, $comments, $dateheads, $offset = 0, $startpos = 0) {\r
126 \r
127                 $query = $this->getSqlBlog($extraQuery);\r
128                 \r
129                 if ($amountEntries > 0) {\r
130                         // $offset zou moeten worden:\r
131                         // (($startpos / $amountentries) + 1) * $offset ... later testen ...\r
132                        $query .= ' LIMIT ' . intval($startpos + $offset).',' . intval($amountEntries);\r
133                 }\r
134                 return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads);\r
135         }\r
136 \r
137         function showUsingQuery($templateName, $query, $highlight = '', $comments = 0, $dateheads = 1) {\r
138                 global $CONF, $manager;\r
139 \r
140                 $lastVisit = cookieVar('lastVisit');\r
141                 if ($lastVisit != 0)\r
142                         $lastVisit = $this->getCorrectTime($lastVisit);\r
143 \r
144                 // set templatename as global variable (so plugins can access it)\r
145                 global $currentTemplateName;\r
146                 $currentTemplateName = $templateName;\r
147                 \r
148                 $template = TEMPLATE::read($templateName);\r
149                 \r
150                 // create parser object & action handler\r
151                 $actions = new ITEMACTIONS($this);\r
152                 $parser = new PARSER($actions->getDefinedActions(),$actions);\r
153                 $actions->setTemplate($template);\r
154                 $actions->setHighlight($highlight);\r
155                 $actions->setLastVisit($lastVisit);\r
156                 $actions->setParser($parser);\r
157                 $actions->setShowComments($comments);\r
158 \r
159                 // execute query\r
160                 $items = sql_query($query);\r
161                 \r
162                 // loop over all items\r
163                 while ($item = mysql_fetch_object($items)) {\r
164                         \r
165                         $item->timestamp = strtotime($item->itime);     // string timestamp -> unix timestamp\r
166                 \r
167                         // action handler needs to know the item we're handling\r
168                         $actions->setCurrentItem($item);\r
169                         \r
170                         // add date header if needed\r
171                         if ($dateheads) {\r
172                                 $new_date = date('dFY',$item->timestamp);\r
173                                 if ($new_date != $old_date) {\r
174                                         // unless this is the first time, write date footer\r
175                                         $timestamp = $item->timestamp;\r
176                                         if ($old_date != 0) {\r
177                                                 $oldTS = strtotime($old_date);\r
178                                                 $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));\r
179                                                 $parser->parse(strftime($template['DATE_FOOTER'], $oldTS));\r
180                                                 $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));                                                \r
181                                         }\r
182                                         $manager->notify('PreDateHead',array('blog' => &$this, 'timestamp' => $timestamp));\r
183                                         // note, to use templatvars in the dateheader, the %-characters need to be doubled in\r
184                                         // order to be preserved by strftime\r
185                                         $parser->parse(strftime($template['DATE_HEADER'],$timestamp));\r
186                                         $manager->notify('PostDateHead',array('blog' => &$this, 'timestamp' => $timestamp));                                    \r
187                                 }\r
188                                 $old_date = $new_date;\r
189                         }\r
190                         \r
191                         // parse item \r
192                         $parser->parse($template['ITEM_HEADER']);\r
193                         $manager->notify('PreItem', array('blog' => &$this, 'item' => &$item));                 \r
194                         $parser->parse($template['ITEM']);                      \r
195                         $manager->notify('PostItem', array('blog' => &$this, 'item' => &$item));                        \r
196                         $parser->parse($template['ITEM_FOOTER']);\r
197 \r
198                 }\r
199                 \r
200                 $numrows = mysql_num_rows($items);\r
201                 \r
202                 // add another date footer if there was at least one item\r
203                 if (($numrows > 0) && $dateheads) {\r
204                         $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date)));           \r
205                         $parser->parse($template['DATE_FOOTER']);\r
206                         $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date)));\r
207                 }\r
208                 \r
209                 mysql_free_result($items);      // free memory\r
210                 \r
211                 return $numrows;\r
212                 \r
213         }        \r
214         \r
215         function showOneitem($itemid, $template, $highlight) {\r
216                 $extraQuery = ' and inumber=' . intval($itemid);\r
217                 \r
218                 return $this->readLogAmount($template, 1, $extraQuery, $highlight, 0, 0);\r
219         }\r
220         \r
221 \r
222         /**\r
223           * Adds an item to this blog\r
224           */\r
225         function additem($catid, $title, $body, $more, $blogid, $authorid, $timestamp, $closed, $draft) {\r
226                 global $manager;\r
227 \r
228                 $blogid         = intval($blogid);\r
229                 $authorid       = intval($authorid);\r
230                 $title          = $title;\r
231                 $body           = $body;\r
232                 $more           = $more;\r
233                 $catid          = intval($catid);\r
234 \r
235                 // convert newlines to <br />\r
236                 if ($this->convertBreaks()) {\r
237                         $body = addBreaks($body);\r
238                         $more = addBreaks($more);\r
239                 }\r
240                 \r
241                 if ($closed != '1')     $closed = '0';\r
242                 if ($draft != '0') $draft = '1';\r
243 \r
244                 if (!$this->isValidCategory($catid))\r
245                         $catid = $this->getDefaultCategory();\r
246                 \r
247                 if ($timestamp > $this->getCorrectTime())\r
248                         $isFuture = 1;\r
249 \r
250                 $timestamp = date('Y-m-d H:i:s',$timestamp);\r
251 \r
252                 $manager->notify('PreAddItem',array('title' => &$title, 'body' => &$body, 'more' => &$more, 'blog' => &$this, 'authorid' => &$authorid, 'timestamp' => &$timestamp, 'closed' => &$closed, 'draft' => &$draft, 'catid' => &$catid));\r
253 \r
254                 $title = addslashes($title);\r
255                 $body = addslashes($body);\r
256                 $more = addslashes($more);\r
257 \r
258                 $query = 'INSERT INTO '.sql_table('item').' (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IDRAFT, ICAT) '\r
259                        . "VALUES ('$title', '$body', '$more', $blogid, $authorid, '$timestamp', $closed, $draft, $catid)";\r
260                 sql_query($query);  \r
261                 $itemid = mysql_insert_id();\r
262                 \r
263                 $manager->notify('PostAddItem',array('itemid' => $itemid));\r
264                 \r
265                 if (!$draft) \r
266                         $this->updateUpdateFile();\r
267                 \r
268                 // send notification mail\r
269                 if (!$draft && !$isFuture && $this->getNotifyAddress() && $this->notifyOnNewItem()) \r
270                         $this->sendNewItemNotification($itemid, stripslashes($title), stripslashes($body));\r
271                 \r
272                 return $itemid;\r
273         }\r
274         \r
275         function sendNewItemNotification($itemid, $title, $body) {\r
276                 global $CONF, $member;\r
277                 \r
278                 // create text version of html post\r
279                 $ascii = toAscii($body);\r
280 \r
281                 $mailto_msg = _NOTIFY_NI_MSG . " \n";\r
282                 $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n";\r
283                 $mailto_msg .= _NOTIFY_TITLE . ' ' . strip_tags($title) . "\n";\r
284                 $mailto_msg .= _NOTIFY_CONTENTS . "\n " . $ascii . "\n";\r
285                 $mailto_msg .= getMailFooter();\r
286                 \r
287                 $mailto_title = $this->getName() . ': ' . _NOTIFY_NI_TITLE;\r
288                         \r
289                 $frommail = $member->getNotifyFromMailAddress();\r
290 \r
291                 $notify = new NOTIFICATION($this->getNotifyAddress());\r
292                 $notify->notify($mailto_title, $mailto_msg , $frommail);\r
293                                 \r
294 \r
295 \r
296         }\r
297 \r
298         \r
299         /**\r
300           * Creates a new category for this blog\r
301           *\r
302           * @param $catName\r
303           *             name of the new category. When empty, a name is generated automatically \r
304           *             (starting with newcat)\r
305           * @param $catDescription\r
306           *             description of the new category. Defaults to 'New Category'\r
307           *\r
308           * @returns \r
309           *             the new category-id in case of success. \r
310           *             0 on failure\r
311           */\r
312         function createNewCategory($catName = '', $catDescription = 'New category') {\r
313                 global $member, $manager;\r
314 \r
315                 if ($member->blogAdminRights($this->getID())) {\r
316                         // generate \r
317                         if ($catName == '')\r
318                         {\r
319                                 $catName = 'newcat';\r
320                                 $i = 1;\r
321                                 while(mysql_num_rows(sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID())) > 0) \r
322                                         $i++;\r
323                                 $catName = $catName . $i;\r
324                         }\r
325                         \r
326                         $manager->notify(\r
327                                 'PreAddCategory',\r
328                                 array(\r
329                                         'blog' => &$this,\r
330                                         'name' => &$catName,\r
331                                         'description' => $catDescription\r
332                                 )\r
333                         );\r
334                         \r
335                         $query = 'INSERT INTO '.sql_table('category').' (cblog, cname, cdesc) VALUES (' . $this->getID() . ", '" . addslashes($catName) . "', '" . addslashes($catDescription) . "')";\r
336                         sql_query($query);\r
337                         $catid = mysql_insert_id();\r
338                         \r
339                         $manager->notify(\r
340                                 'PostAddCategory',\r
341                                 array(\r
342                                         'blog' => &$this,\r
343                                         'name' => $catName,\r
344                                         'description' => $catDescription,\r
345                                         'catid' => $catid\r
346                                 )\r
347                         );                      \r
348                         \r
349                         return $catid;\r
350                 } else {\r
351                         return 0;\r
352                 }\r
353         \r
354         }       \r
355 \r
356 \r
357         /**\r
358          * Searches all months of this blog for the given query\r
359          *\r
360          * @param $query\r
361          *              search query\r
362          * @param $template\r
363          *              template to be used (__NAME__ of the template)\r
364          * @param $amountMonths\r
365          *              max amount of months to be search (0 = all)\r
366          * @param $maxresults\r
367          *              max number of results to show\r
368          * @param $startpos\r
369          *              offset\r
370          * @returns\r
371          *              amount of hits found\r
372          */\r
373         function search($query, $template, $amountMonths, $maxresults, $startpos) {\r
374         global $CONF;\r
375 \r
376                 $highlight      = '';\r
377                 $sqlquery       = $this->getSqlSearch($query, $amountMonths, $highlight);\r
378                 \r
379                 if ($sqlquery == '')\r
380                 {\r
381                         // no query -> show everything\r
382             $extraquery = '';\r
383                     $amountfound = $this->readLogAmount($template, $maxresults, $extraQuery, $query, 1, 1);\r
384                 } else {\r
385                 \r
386                         // add LIMIT to query (to split search results into pages)\r
387             if (intval($maxresults > 0)) \r
388                     $sqlquery .= ' LIMIT ' . intval($startpos).',' . intval($maxresults);\r
389 \r
390                         // show results\r
391                     $amountfound = $this->showUsingQuery($template, $sqlquery, $highlight, 1, 1);\r
392                     \r
393                         // when no results were found, show a message \r
394                 if ($amountfound == 0) \r
395                 {\r
396                         $template = TEMPLATE::read($template);\r
397                         $vars = array(\r
398                                 'query'         => htmlspecialchars($query),\r
399                                 'blogid'        => $this->getID()\r
400                         );\r
401                         echo TEMPLATE::fill($template['SEARCH_NOTHINGFOUND'],$vars);\r
402                 }\r
403         }\r
404         \r
405                 return $amountfound;\r
406         }\r
407         \r
408         /**\r
409          * Returns an SQL query to use for a search query\r
410          *\r
411          * @param $query\r
412          *              search query\r
413          * @param $amountMonths\r
414          *              amount of months to search back. Default = 0 = unlimited\r
415          * @param $mode\r
416          *              either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query\r
417          * @returns $highlight\r
418          *              words to highlight (out parameter)\r
419          * @returns \r
420          *              either a full SQL query, or an empty string (if querystring empty)\r
421          * @note\r
422          *              No LIMIT clause is added. (caller should add this if multiple pages are requested)\r
423          */\r
424         function getSqlSearch($query, $amountMonths = 0, &$highlight, $mode = '')\r
425         {\r
426         $searchclass = new SEARCH($query);\r
427         \r
428         $highlight        = $searchclass->inclusive;\r
429         \r
430         // if querystring is empty, return empty string\r
431         if ($searchclass->inclusive == '') \r
432                 return '';\r
433             \r
434            \r
435                 $where  = $searchclass->boolean_sql_where('ititle,ibody,imore');\r
436                 $select = $searchclass->boolean_sql_select('ititle,ibody,imore');\r
437 \r
438                 // get list of blogs to search\r
439                 $blogs          = $searchclass->blogs;          // array containing blogs that always need to be included\r
440                 $blogs[]        = $this->getID();                       // also search current blog (duh)\r
441                 $blogs          = array_unique($blogs);         // remove duplicates\r
442                 $selectblogs = '';\r
443                 if (count($blogs) > 0)\r
444                         $selectblogs = ' and i.iblog in (' . implode(',', $blogs) . ')';\r
445 \r
446                 if ($mode == '') \r
447                 {\r
448                         $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, m.mname as author, m.mrealname as authorname, i.itime, i.imore as more, m.mnumber as authorid, m.memail as authormail, m.murl as authorurl, c.cname as category, i.icat as catid, i.iclosed as closed';\r
449                         if ($select) \r
450                                 $query .= ', '.$select. ' as score ';\r
451                 } else {\r
452                         $query = 'SELECT COUNT(*) as result ';\r
453                 }\r
454                         \r
455                 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'\r
456                            . ' WHERE i.iauthor=m.mnumber'\r
457                            . ' and i.icat=c.catid'\r
458                            . ' and i.idraft=0'  // exclude drafts\r
459                            . $selectblogs\r
460                                         // don't show future items\r
461                            . ' and i.itime<=' . mysqldate($this->getCorrectTime())\r
462                            . ' and '.$where;\r
463 \r
464                 // take into account amount of months to search\r
465                 if ($amountMonths > 0) \r
466                 {\r
467                         $localtime = getdate($this->getCorrectTime());\r
468                         $timestamp_start = mktime(0,0,0,$localtime['mon'] - $amountMonths,1,$localtime['year']);\r
469                         $query .= ' and i.itime>' . mysqldate($timestamp_start);\r
470                 }\r
471 \r
472                 if ($mode == '')\r
473                 {\r
474                         if ($select) \r
475                                 $query .= ' ORDER BY score DESC';\r
476                         else \r
477                                 $query .= ' ORDER BY i.itime DESC ';\r
478                 }\r
479 \r
480                 return $query;          \r
481         }\r
482         \r
483         /**\r
484          * Returns the SQL query that's normally used to display the blog items on the index type skins\r
485          *\r
486          * @param $mode\r
487          *              either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query\r
488          * @returns \r
489          *              either a full SQL query, or an empty string \r
490          * @note\r
491          *              No LIMIT clause is added. (caller should add this if multiple pages are requested)\r
492          */\r
493         function getSqlBlog($extraQuery, $mode = '')\r
494         {\r
495                 if ($mode == '')\r
496                         $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, m.mname as author, m.mrealname as authorname, i.itime, i.imore as more, m.mnumber as authorid, m.memail as authormail, m.murl as authorurl, c.cname as category, i.icat as catid, i.iclosed as closed';\r
497                 else\r
498                         $query = 'SELECT COUNT(*) as result ';\r
499                 \r
500                 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'\r
501                        . ' WHERE i.iblog='.$this->blogid\r
502                        . ' and i.iauthor=m.mnumber'\r
503                        . ' and i.icat=c.catid'\r
504                        . ' and i.idraft=0'      // exclude drafts\r
505                                         // don't show future items\r
506                        . ' and i.itime<=' . mysqldate($this->getCorrectTime());\r
507 \r
508                 if ($this->getSelectedCategory())\r
509                         $query .= ' and i.icat=' . $this->getSelectedCategory() . ' ';\r
510 \r
511 \r
512                 $query .= $extraQuery;\r
513                 \r
514                 if ($mode == '')\r
515                         $query .= ' ORDER BY i.itime DESC';\r
516                        \r
517                 return $query;\r
518         }\r
519 \r
520         /**\r
521           * Shows the archivelist using the given template\r
522           */\r
523         function showArchiveList($template, $mode = 'month', $limit = 0) {\r
524                 global $CONF, $catid;\r
525 \r
526                 if ($catid) \r
527                         $linkparams = array('catid' => $catid);\r
528                 \r
529                 $template = TEMPLATE::read($template);\r
530                 $data['blogid'] = $this->getID();\r
531 \r
532                 echo TEMPLATE::fill($template['ARCHIVELIST_HEADER'],$data);\r
533 \r
534                 $query = 'SELECT itime, SUBSTRING(itime,1,4) AS Year, SUBSTRING(itime,6,2) AS Month, SUBSTRING(itime,9,2) as Day FROM '.sql_table('item')\r
535                 . ' WHERE iblog=' . $this->getID()\r
536                 . ' and itime <=' . mysqldate($this->getCorrectTime())  // don't show future items!\r
537                 . ' and idraft=0'; // don't show draft items\r
538                 \r
539                 if ($catid)\r
540                         $query .= ' and icat=' . intval($catid);\r
541                 \r
542                 $query .= ' GROUP BY Year, Month';\r
543                 if ($mode == 'day')\r
544                         $query .= ', Day';\r
545                 \r
546                         \r
547                 $query .= ' ORDER BY itime DESC';                               \r
548                 \r
549                 if ($limit > 0) \r
550                         $query .= ' LIMIT ' . intval($limit);\r
551                 \r
552                 $res = sql_query($query);\r
553 \r
554                 while ($current = mysql_fetch_object($res)) {\r
555                         $current->itime = strtotime($current->itime);   // string time -> unix timestamp\r
556                 \r
557                         if ($mode == 'day') {\r
558                                 $archivedate = date('Y-m-d',$current->itime);\r
559                                 $archive['day'] = date('d',$current->itime);\r
560                         } else {\r
561                                 $archivedate = date('Y-m',$current->itime);                     \r
562                         }\r
563                         $data['month'] = date('m',$current->itime);\r
564                         $data['year'] = date('Y',$current->itime);\r
565                         $data['archivelink'] = createArchiveLink($this->getID(),$archivedate,$linkparams);\r
566 \r
567                         $temp = TEMPLATE::fill($template['ARCHIVELIST_LISTITEM'],$data);\r
568                         echo strftime($temp,$current->itime);\r
569 \r
570                 }\r
571                 \r
572                 mysql_free_result($res);\r
573 \r
574                 echo TEMPLATE::fill($template['ARCHIVELIST_FOOTER'],$data);\r
575         }\r
576         \r
577 \r
578         /**\r
579           * Shows the list of categories using a given template\r
580           */\r
581         function showCategoryList($template) {\r
582                 global $CONF;\r
583                 \r
584                 // determine arguments next to catids\r
585                 // I guess this can be done in a better way, but it works\r
586                 global $archive, $archivelist;\r
587                 \r
588                 $linkparams = array();\r
589                 if ($archive) {\r
590                         $blogurl = createArchiveLink($this->getID(), $archive, '');\r
591                         $linkparams['blogid'] = $this->getID();\r
592                         $linkparams['archive'] = $archive;\r
593                 } else if ($archivelist) {\r
594                         $blogurl = createArchiveListLink($this->getID(), '');\r
595                         $linkparams['archivelist'] = $archivelist;\r
596                 } else {\r
597                         $blogurl = createBlogidLink($this->getID(), '');\r
598                         $linkparams['blogid'] = $this->getID();\r
599                 } \r
600                         \r
601                 //$blogurl = $this->getURL() . $qargs;\r
602                 $blogurl = createBlogLink($this->getURL(), $linkparams);\r
603 \r
604                 $template = TEMPLATE::read($template);\r
605 \r
606                 echo TEMPLATE::fill($template['CATLIST_HEADER'],\r
607                                                         array(\r
608                                                                 'blogid' => $this->getID(),\r
609                                                                 'blogurl' => $blogurl,\r
610                                                                 'self' => $CONF['Self']\r
611                                                         ));\r
612 \r
613                 $query = 'SELECT catid, cdesc as catdesc, cname as catname FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' ORDER BY cname ASC';\r
614                 $res = sql_query($query);\r
615 \r
616 \r
617                 while ($data = mysql_fetch_assoc($res)) {\r
618                         $data['blogid'] = $this->getID();       \r
619                         $data['blogurl'] = $blogurl;\r
620                         $data['catlink'] = createCategoryLink($data['catid'], $linkparams);\r
621                         $data['self'] = $CONF['Self'];\r
622 \r
623                         $temp = TEMPLATE::fill($template['CATLIST_LISTITEM'],$data);\r
624                         echo strftime($temp,$current->itime);\r
625 \r
626                 }\r
627                 \r
628                 mysql_free_result($res);\r
629 \r
630                 echo TEMPLATE::fill($template['CATLIST_FOOTER'],\r
631                                                         array(\r
632                                                                 'blogid' => $this->getID(),\r
633                                                                 'blogurl' => $blogurl,\r
634                                                                 'self' => $CONF['Self']                                                         \r
635                                                         ));\r
636         }\r
637 \r
638         /**\r
639           * Blogsettings functions\r
640           */\r
641           \r
642         function readSettings() {\r
643                 $query =  'SELECT *'\r
644                        . ' FROM '.sql_table('blog')\r
645                        . ' WHERE bnumber=' . $this->blogid;\r
646                 $res = sql_query($query);\r
647                 \r
648                 $this->isValid = (mysql_num_rows($res) > 0);\r
649                 if (!$this->isValid)\r
650                         return;\r
651                 \r
652                 $this->settings = mysql_fetch_assoc($res);\r
653         }\r
654         \r
655         function writeSettings() {\r
656                 $query =  'UPDATE '.sql_table('blog')\r
657                        . " SET bname='" . addslashes($this->getName()) . "',"\r
658                        . "     bshortname='". addslashes($this->getShortName()) . "',"\r
659                        . "     bcomments=". intval($this->commentsEnabled()) . ","\r
660                        . "     bmaxcomments=" . intval($this->getMaxComments()) . ","\r
661                        . "     btimeoffset=" . floatval($this->getTimeOffset()) . ","\r
662                        . "     bpublic=" . intval($this->isPublic()) . ","\r
663                        . "     bsendping=" . intval($this->pingUserland()) . ","\r
664                        . "     bconvertbreaks=" . intval($this->convertBreaks()) . ","\r
665                        . "     ballowpast=" . intval($this->allowPastPosting()) . ","                      \r
666                        . "     bnotify='" . addslashes($this->getNotifyAddress()) . "',"\r
667                        . "     bnotifytype=" . intval($this->getNotifyType()) . ","                    \r
668                        . "     burl='" . addslashes($this->getURL()) . "',"\r
669                        . "     bupdate='" . addslashes($this->getUpdateFile()) . "',"\r
670                        . "     bdesc='" . addslashes($this->getDescription()) . "',"\r
671                        . "     bdefcat=" . intval($this->getDefaultCategory()) . ","                   \r
672                        . "     bdefskin=" . intval($this->getDefaultSkin()) . ","\r
673                        . "     bincludesearch=" . intval($this->getSearchable())\r
674                        . " WHERE bnumber=" . intval($this->getID());\r
675                 sql_query($query);\r
676 \r
677         }\r
678         \r
679 \r
680                 \r
681         // update update file if requested\r
682         function updateUpdatefile() {\r
683                  if ($this->getUpdateFile()) {\r
684                         $f_update = fopen($this->getUpdateFile(),'w');\r
685                         fputs($f_update,$this->getCorrectTime());\r
686                         fclose($f_update);\r
687                  }\r
688 \r
689         }\r
690         \r
691         /**\r
692           * Sends a XML-RPC ping message to Userland, so the weblog can\r
693           * show up in the weblogs.com updates-list\r
694           */\r
695         function sendUserlandPing() {\r
696                 global $php_errormsg;\r
697                 \r
698                  if ($this->pingUserland()) {\r
699                           // testmessage for adding an item\r
700                           $message = new xmlrpcmsg('weblogUpdates.ping',array(\r
701                                         new xmlrpcval($this->getName(),'string'),       \r
702                                         new xmlrpcval($this->getURL(),'string')\r
703                           ));\r
704                           \r
705                           $c = new xmlrpc_client('/RPC2', 'rpc.weblogs.com', 80);\r
706 \r
707                           // $c->setDebug(1);\r
708 \r
709                           $r = $c->send($message,15); // 15 seconds timeout...\r
710                           \r
711                           if (($r == 0) && ($r->errno || $r->errstring)) {\r
712                                 return 'Error ' . $r->errno . ' : ' . $r->errstring;\r
713                           } elseif (($r == 0) && ($php_errormsg)) {\r
714                                 return 'PHP Error: ' . $php_errormsg;\r
715                           } elseif ($r == 0) {\r
716                                 return 'Error while trying to send ping. Sorry about that.';\r
717                           } elseif ($r->faultCode() != 0) {\r
718                                 return 'Error: ' . $r->faultString();\r
719                           } else {\r
720                                   $r = $r->value();     // get response struct\r
721                                   // get values\r
722                                   $flerror = $r->structmem('flerror');\r
723                                   $flerror = $flerror->scalarval();\r
724  \r
725                                   \r
726                                   $message = $r->structmem('message');\r
727                                   $message = $message->scalarval();\r
728 \r
729                                   if ($flerror != 0)\r
730                                         return 'Error (flerror=1): ' . $message;\r
731                                   else\r
732                                         return 'Success: ' . $message;\r
733                           }                       \r
734                  }\r
735         }\r
736         \r
737         function isValidCategory($catid) {\r
738                 $query = 'SELECT * FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' and catid=' . intval($catid);\r
739                 return (mysql_num_rows(mysql_query($query)) != 0);\r
740         }\r
741         \r
742         function getCategoryName($catid) {\r
743                 $res = mysql_query('SELECT cname FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));\r
744                 $o = mysql_fetch_object($res);\r
745                 return $o->cname;\r
746         }\r
747         \r
748         function getCategoryDesc($catid) {\r
749                 $res = mysql_query('SELECT cdesc FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));\r
750                 $o = mysql_fetch_object($res);\r
751                 return $o->cdesc;\r
752         }\r
753 \r
754         function getCategoryIdFromName($name) {\r
755                 $res = mysql_query('SELECT catid FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and cname="' . addslashes($name) . '"');\r
756                 if (mysql_num_rows($res) > 0) {\r
757                         $o = mysql_fetch_object($res);\r
758                         return $o->catid;       \r
759                 } else {\r
760                         return $this->getDefaultCategory();\r
761                 }\r
762         }\r
763         \r
764         function pingUserland() {\r
765                 return $this->getSetting('bsendping');\r
766         }\r
767         \r
768         function setPingUserland($val) {\r
769                 $this->setSetting('bsendping',$val);\r
770         }\r
771         \r
772         function convertBreaks() {\r
773                 return $this->getSetting('bconvertbreaks');\r
774         }\r
775         \r
776         function insertJavaScriptInfo($authorid = '') {\r
777                 global $member, $CONF;\r
778                 \r
779                 if ($authorid == '')    \r
780                         $authorid = $member->getID();\r
781                         \r
782                 ?>\r
783                 <script type="text/javascript">\r
784                         setConvertBreaks(<?php echo  $this->convertBreaks() ? 'true' : 'false' ?>);\r
785                         setMediaUrl("<?php echo $CONF['MediaURL']?>");\r
786                         setAuthorId(<?php echo $authorid?>);\r
787                 </script><?php  }\r
788         \r
789         function setConvertBreaks($val) {\r
790                 $this->setSetting('bconvertbreaks',$val);\r
791         }\r
792         function setAllowPastPosting($val) {\r
793                 $this->setSetting('ballowpast',$val);\r
794         }               \r
795         function allowPastPosting() {\r
796                 return $this->getSetting('ballowpast');\r
797         }\r
798         \r
799         function getCorrectTime($t=0) {\r
800                 if ($t == 0) $t = time();\r
801                 return ($t + 3600 * $this->getTimeOffset());\r
802         }\r
803         \r
804         function getName() {\r
805                 return $this->getSetting('bname');\r
806         }\r
807         \r
808         function getShortName() {\r
809                 return $this->getSetting('bshortname');\r
810         }\r
811         \r
812         function getMaxComments() {\r
813                 return $this->getSetting('bmaxcomments');\r
814         }\r
815         \r
816         function getNotifyAddress() {\r
817                 return $this->getSetting('bnotify');\r
818         }\r
819         \r
820         function getNotifyType() {\r
821                 return $this->getSetting('bnotifytype');\r
822         }\r
823         \r
824         function notifyOnComment() {\r
825                 $n = $this->getNotifyType();\r
826                 return (($n != 0) && (($n % 3) == 0));\r
827         }\r
828 \r
829         function notifyOnVote() {\r
830                 $n = $this->getNotifyType();\r
831                 return (($n != 0) && (($n % 5) == 0));\r
832         }\r
833 \r
834         function notifyOnNewItem() {\r
835                 $n = $this->getNotifyType();\r
836                 return (($n != 0) && (($n % 7) == 0));\r
837         }\r
838         \r
839         function setNotifyType($val) {\r
840                 $this->setSetting('bnotifytype',$val);  \r
841         }\r
842         \r
843 \r
844         function getTimeOffset() {\r
845                 return $this->getSetting('btimeoffset');\r
846         }\r
847         \r
848         function commentsEnabled() {\r
849                 return $this->getSetting('bcomments');\r
850         }\r
851         \r
852         function getURL() {\r
853                 return $this->getSetting('burl');\r
854         }\r
855         \r
856         function getDefaultSkin() {\r
857                 return $this->getSetting('bdefskin');\r
858         }\r
859         \r
860         function getUpdateFile() {\r
861                 return $this->getSetting('bupdate');\r
862         }\r
863         \r
864         function getDescription() {\r
865                 return $this->getSetting('bdesc');\r
866         }\r
867         \r
868         function isPublic() {\r
869                 return $this->getSetting('bpublic');\r
870         }\r
871         \r
872         function getSearchable() {\r
873                 return $this->getSetting('bincludesearch');\r
874         }\r
875 \r
876         function getDefaultCategory() {\r
877                 return $this->getSetting('bdefcat');\r
878         }\r
879         \r
880         function setPublic($val) {\r
881                 $this->setSetting('bpublic',$val);\r
882         }\r
883 \r
884         function setSearchable($val) {\r
885                 $this->setSetting('bincludesearch',$val);\r
886         }\r
887 \r
888         function setDescription($val) {\r
889                 $this->setSetting('bdesc',$val);\r
890         }\r
891 \r
892         function setUpdateFile($val) {\r
893                 $this->setSetting('bupdate',$val);\r
894         }\r
895         \r
896         function setDefaultSkin($val) {\r
897                 $this->setSetting('bdefskin',$val);\r
898         }\r
899         \r
900         function setURL($val) {\r
901                 $this->setSetting('burl',$val);\r
902         }\r
903         \r
904         function setName($val) {\r
905                 $this->setSetting('bname',$val);\r
906         }\r
907         \r
908         function setShortName($val) {\r
909                 $this->setSetting('bshortname',$val);\r
910         }\r
911         \r
912         function setCommentsEnabled($val) { \r
913                 $this->setSetting('bcomments',$val);\r
914         }\r
915         \r
916         function setMaxComments($val) {\r
917                 $this->setSetting('bmaxcomments',$val);\r
918         }\r
919         \r
920         function setNotifyAddress($val) {\r
921                 $this->setSetting('bnotify',$val);\r
922         }\r
923         \r
924         function setTimeOffset($val) {\r
925                 // check validity of value\r
926                 // 1. replace , by . (common mistake)\r
927                 $val = str_replace(',','.',$val);\r
928                 // 2. cast to float or int\r
929                 if (is_numeric($val) && strstr($val,'.5')) {\r
930                         $val = (float) $val;\r
931                 } else {\r
932                         $val = intval($val);\r
933                 }\r
934         \r
935                 $this->setSetting('btimeoffset',$val);\r
936         }\r
937         \r
938         function setDefaultCategory($val) {\r
939                 $this->setSetting('bdefcat',$val);\r
940         }\r
941 \r
942         function getSetting($key) {\r
943                 return $this->settings[$key];\r
944         }\r
945         \r
946         function setSetting($key,$value) {\r
947                 $this->settings[$key] = $value;\r
948         }\r
949         \r
950         \r
951         // tries to add a member to the team. Returns false if the member was already on\r
952         // the team\r
953         function addTeamMember($memberid, $admin) {\r
954                 global $manager;\r
955                 \r
956                 $memberid = intval($memberid);\r
957                 $admin = intval($admin);\r
958                 \r
959                 // check if member is already a member\r
960                 $tmem = MEMBER::createFromID($memberid);\r
961                 \r
962                 if ($tmem->isTeamMember($this->getID()))\r
963                         return 0;\r
964                 \r
965                 $manager->notify(\r
966                         'PreAddTeamMember',\r
967                         array(\r
968                                 'blog' => &$this,\r
969                                 'member' => &$tmem,\r
970                                 'admin' => &$admin\r
971                         )\r
972                 );\r
973                 \r
974                 // add to team\r
975                 $query = 'INSERT INTO '.sql_table('team').' (TMEMBER, TBLOG, TADMIN) '\r
976                        . 'VALUES (' . $memberid .', '.$this->getID().', "'.$admin.'")';\r
977                 sql_query($query);\r
978                 \r
979                 $manager->notify(\r
980                         'PostAddTeamMember',\r
981                         array(\r
982                                 'blog' => &$this,\r
983                                 'member' => &$tmem,\r
984                                 'admin' => $admin\r
985                         )\r
986                         \r
987                 );\r
988                 \r
989                 ACTIONLOG::add(INFO, 'Added ' . $tmem->getDisplayName() . ' (ID=' .\r
990                                $memberid .') to the team of blog "' . $this->getName() . '"');\r
991                 \r
992                 return 1;\r
993         }\r
994         \r
995         function getID() {\r
996                 return $this->blogid;\r
997         }\r
998         \r
999         // returns true if there is a blog with the given shortname (static)\r
1000         function exists($name) {\r
1001                 $r = sql_query('select * FROM '.sql_table('blog').' WHERE bshortname="'.addslashes($name).'"');\r
1002                 return (mysql_num_rows($r) != 0);\r
1003         }\r
1004 \r
1005         // returns true if there is a blog with the given ID (static)\r
1006         function existsID($id) {\r
1007                 $r = sql_query('select * FROM '.sql_table('blog').' WHERE bnumber='.intval($id));\r
1008                 return (mysql_num_rows($r) != 0);\r
1009         }       \r
1010         \r
1011         \r
1012 }\r
1013 \r
1014 /**\r
1015   * This class is used when parsing item templates\r
1016   */\r
1017 class ITEMACTIONS extends BaseActions {\r
1018 \r
1019         // contains an assoc array with parameters that need to be included when\r
1020         // generating links to items/archives/... (e.g. catid)\r
1021         var $linkparams;\r
1022         \r
1023         // true when the current user is a blog admin (and thus allowed to edit all items)\r
1024         var $allowEditAll;\r
1025         \r
1026         // timestamp of last visit\r
1027         var $lastVisit;\r
1028         \r
1029         // item currently being handled (mysql result object, see BLOG::showUsingQuery)\r
1030         var $currentItem;\r
1031         \r
1032         // reference to the blog currently being displayed\r
1033         var $blog;\r
1034         \r
1035         // associative array with template info (part name => contents)\r
1036         var $template;\r
1037         \r
1038         // true when comments need to be displayed\r
1039         var $showComments;\r
1040         \r
1041         function ITEMACTIONS(&$blog) {\r
1042                 // call constructor of superclass first\r
1043                 $this->BaseActions();   \r
1044                 \r
1045                 // extra parameters for created links\r
1046                 global $catid;\r
1047                 if ($catid)\r
1048                         $this->linkparams = array('catid' => $catid);\r
1049                         \r
1050                 // check if member is blog admin (and thus allowed to edit all items)\r
1051                 global $member;\r
1052                 $this->allowEditAll = ($member->isLoggedIn() && $member->blogAdminRights($blog->getID()));\r
1053                 $this->setBlog($blog);\r
1054         }\r
1055 \r
1056         function getDefinedActions() {\r
1057                 return array(\r
1058                         'blogid',\r
1059                         'title',\r
1060                         'body',\r
1061                         'more',\r
1062                         'smartbody',\r
1063                         'itemid',\r
1064                         'morelink',\r
1065                         'category',\r
1066                         'categorylink',\r
1067                         'author',\r
1068                         'authorid',\r
1069                         'authorlink',\r
1070                         'catid',\r
1071                         'karma',\r
1072                         'date',\r
1073                         'time',\r
1074                         'query',\r
1075                         'itemlink',\r
1076                         'blogurl',\r
1077                         'closed',\r
1078                         'syndicate_title',\r
1079                         'syndicate_description',\r
1080                         'karmaposlink',\r
1081                         'karmaneglink',\r
1082                         'new',\r
1083                         'image',\r
1084                         'popup',\r
1085                         'media',\r
1086                         'daylink',\r
1087                         'query',\r
1088                         'include',\r
1089                         'phpinclude',\r
1090                         'parsedinclude',\r
1091                         'skinfile',\r
1092                         'set',\r
1093                         'plugin',\r
1094                         'edit',\r
1095                         'editlink',\r
1096                         'editpopupcode',\r
1097                         'comments',\r
1098                         'relevance'\r
1099                 );\r
1100         }\r
1101         \r
1102 \r
1103         \r
1104         function setLastVisit($lastVisit) {             $this->lastVisit = $lastVisit; }\r
1105         function setParser(&$parser) {                  $this->parser =& $parser; }\r
1106         function setCurrentItem(&$item) {               $this->currentItem =& $item; }\r
1107         function setBlog(&$blog) {                              $this->blog =& $blog; }\r
1108         function setTemplate($template) {               $this->template =& $template; }\r
1109         function setShowComments($val) {                $this->showComments = $val; }\r
1110         \r
1111         // methods used by parser to insert content\r
1112         \r
1113         function parse_blogid() {               echo $this->blog->getID();      }\r
1114         function parse_body() {                 $this->highlightAndParse($this->currentItem->body); }\r
1115         function parse_title() {                $this->highlightAndParse($this->currentItem->title); }\r
1116         function parse_more() {                 $this->highlightAndParse($this->currentItem->more); }   \r
1117         function parse_itemid() {               echo $this->currentItem->itemid; }              \r
1118         function parse_category() {             echo $this->currentItem->category; }                            \r
1119         function parse_categorylink() { echo createCategoryLink($this->currentItem->catid); }                           \r
1120         function parse_catid() {                echo $this->currentItem->catid; }                                       \r
1121         function parse_authorid() {             echo $this->currentItem->authorid; }\r
1122         function parse_authorlink() {   echo createMemberLink($this->currentItem->authorid, $this->linkparams); }       \r
1123         function parse_query() {                echo $this->strHighlight; }\r
1124         function parse_itemlink() {             echo createItemLink($this->currentItem->itemid, $this->linkparams); }\r
1125         function parse_blogurl() {              echo $this->blog->getURL(); }\r
1126         function parse_closed() {               echo $this->currentItem->closed; }\r
1127         function parse_relevance() {    echo round($this->currentItem->score,2);}\r
1128         \r
1129         function parse_karma($type = 'totalscore') {\r
1130                 global $manager;\r
1131 \r
1132                 // get karma object\r
1133                 $karma =& $manager->getKarma($this->currentItem->itemid);\r
1134                 \r
1135                 switch($type) {\r
1136                         case 'pos':\r
1137                                 echo $karma->getNbPosVotes();\r
1138                                 break;\r
1139                         case 'neg':\r
1140                                 echo $karma->getNbNegVotes();\r
1141                                 break;                          \r
1142                         case 'votes':\r
1143                                 echo $karma->getNbOfVotes();\r
1144                                 break;          \r
1145                         case 'posp':\r
1146                                 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbPosVotes() / $karma->getNbOfVotes()) : 50;\r
1147                                 echo number_format($percentage,2), '%';                         \r
1148                                 break;                          \r
1149                         case 'negp':\r
1150                                 $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbNegVotes() / $karma->getNbOfVotes()) : 50;\r
1151                                 echo number_format($percentage,2), '%';                         \r
1152                                 break;                          \r
1153                         case 'totalscore':\r
1154                         default:\r
1155                                 echo $karma->getTotalScore();\r
1156                                 break;\r
1157                 }\r
1158                 \r
1159         }                                               \r
1160 \r
1161         function parse_author($which = '') {            \r
1162                 switch($which)\r
1163                 {\r
1164                         case 'realname':\r
1165                                 echo $this->currentItem->authorname;\r
1166                                 break;\r
1167                         case 'id':\r
1168                                 echo $this->currentItem->authorid;\r
1169                                 break;\r
1170                         case 'email':\r
1171                                 echo $this->currentItem->authormail;\r
1172                                 break;\r
1173                         case 'url':\r
1174                                 echo $this->currentItem->authorurl;\r
1175                                 break;\r
1176                         case 'name':\r
1177                         default:\r
1178                                 echo $this->currentItem->author;\r
1179                 }\r
1180         }               \r
1181         \r
1182         function parse_smartbody() {\r
1183                 if (!$this->currentItem->more) {\r
1184                         $this->highlightAndParse($this->currentItem->body);\r
1185                 } else {\r
1186                         $this->highlightAndParse($this->currentItem->more);             \r
1187                 }\r
1188         }\r
1189 \r
1190         function parse_morelink() {             \r
1191                 if ($this->currentItem->more)\r
1192                         $this->parser->parse($this->template['MORELINK']);\r
1193         }                       \r
1194         \r
1195         function parse_date($format = '') {\r
1196                 echo formatDate($format, $this->currentItem->timestamp, $this->template['FORMAT_DATE']);\r
1197         }\r
1198         \r
1199         /**\r
1200           * @param format optional strftime format\r
1201           */\r
1202         function parse_time($format = '') {                     \r
1203                 echo strftime($format ? $format : $this->template['FORMAT_TIME'],$this->currentItem->timestamp); \r
1204         }\r
1205         \r
1206         /**\r
1207           * @param maxLength optional maximum length\r
1208           */\r
1209         function parse_syndicate_title($maxLength = 100) { \r
1210                 $syndicated = strip_tags($this->currentItem->title);\r
1211                 echo htmlspecialchars(shorten($syndicated,$maxLength,'...'));\r
1212         }\r
1213         \r
1214         /**\r
1215           * @param maxLength optional maximum length\r
1216           */\r
1217         function parse_syndicate_description($maxLength = 250, $addHighlight = 0) { \r
1218                 $syndicated = strip_tags($this->currentItem->body);\r
1219                 if ($addHighlight) {\r
1220                     echo $this->highlightAndParse(htmlspecialchars(shorten($syndicated,$maxLength,'...')));\r
1221                 } else {\r
1222                 echo htmlspecialchars(shorten($syndicated,$maxLength,'...'));\r
1223                 }\r
1224         }\r
1225         \r
1226         function parse_karmaposlink($text = '') { \r
1227                 global $CONF;\r
1228                 $link = $CONF['ActionURL'] . '?action=votepositive&amp;itemid='.$this->currentItem->itemid; \r
1229                 echo $text ? '<a href="'.$link.'">'.$text.'</a>' : $link;\r
1230         }\r
1231         \r
1232         function parse_karmaneglink($text = '') { \r
1233                 global $CONF;\r
1234                 $link = $CONF['ActionURL'] . '?action=votenegative&amp;itemid='.$this->currentItem->itemid; \r
1235                 echo $text ? '<a href="'.$link.'">'.$text.'</a>' : $link;\r
1236         }\r
1237         \r
1238         function parse_new() {  \r
1239                 if (($this->lastVisit != 0) && ($this->currentItem->timestamp > $this->lastVisit))\r
1240                         echo $this->template['NEW'];\r
1241         }\r
1242         \r
1243         function parse_image() {\r
1244                 // image/popup calls have arguments separated by |\r
1245                 $args = func_get_args();\r
1246                 $args = explode('|',implode($args,', '));\r
1247                 call_user_func_array(array(&$this,'createImageCode'),$args);\r
1248         }\r
1249         function parse_popup() {\r
1250                 // image/popup calls have arguments separated by |\r
1251                 $args = func_get_args();\r
1252                 $args = explode('|',implode($args,', '));\r
1253                 call_user_func_array(array(&$this,'createPopupCode'),$args);\r
1254         }\r
1255         function parse_media() {\r
1256                 // image/popup calls have arguments separated by |\r
1257                 $args = func_get_args();\r
1258                 $args = explode('|',implode($args,', '));\r
1259                 call_user_func_array(array(&$this,'createMediaCode'),$args);\r
1260         }\r
1261         \r
1262         function parse_daylink() {              \r
1263                 echo createArchiveLink($this->blog->getID(), strftime('%Y-%m-%d',$this->currentItem->timestamp), $this->linkparams);\r
1264         }\r
1265         \r
1266         function parse_comments($maxToShow = 0) {\r
1267                 if ($maxToShow == 0)\r
1268                         $maxToShow = $this->blog->getMaxComments();\r
1269                         \r
1270                 // add comments\r
1271                 if ($this->showComments && $this->blog->commentsEnabled()) {\r
1272                         $comments = new COMMENTS($this->currentItem->itemid);\r
1273                         $comments->setItemActions($this);\r
1274                         $comments->showComments($this->template, $maxToShow, $this->currentItem->closed ? 0 : 1, $this->strHighlight); \r
1275                 }\r
1276         }\r
1277 \r
1278         /**\r
1279           * Executes a plugin templatevar\r
1280           *\r
1281           * @param pluginName name of plugin (without the NP_)\r
1282           * \r
1283           * extra parameters can be added\r
1284           */\r
1285         function parse_plugin($pluginName) {\r
1286                 global $manager;\r
1287                 \r
1288                 // only continue when the plugin is really installed\r
1289                 if (!$manager->pluginInstalled('NP_' . $pluginName))\r
1290                         return;\r
1291                 \r
1292                 $plugin =& $manager->getPlugin('NP_' . $pluginName);\r
1293                 if (!$plugin) return;\r
1294 \r
1295                 // get arguments\r
1296                 $params = func_get_args();\r
1297                 \r
1298                 // remove plugin name \r
1299                 array_shift($params);\r
1300                 \r
1301                 // add item reference (array_unshift didn't work)\r
1302                 $params = array_merge(array(&$this->currentItem),$params);\r
1303 \r
1304                 call_user_func_array(array(&$plugin,'doTemplateVar'), $params);\r
1305         }\r
1306         \r
1307         function parse_edit() {\r
1308                 global $member, $CONF;\r
1309                 if ($this->allowEditAll || ($member->isLoggedIn() && ($member->getID() == $this->currentItem->authorid)) ) {\r
1310                         $this->parser->parse($this->template['EDITLINK']);\r
1311                 }\r
1312         }\r
1313         \r
1314         function parse_editlink() {\r
1315                 global $CONF;\r
1316                 echo $CONF['AdminURL'],'bookmarklet.php?action=edit&amp;itemid=',$this->currentItem->itemid;\r
1317         }\r
1318         \r
1319         function parse_editpopupcode() {\r
1320                 echo "if (event &amp;&amp; event.preventDefault) event.preventDefault();winbm=window.open(this.href,'nucleusbm','scrollbars=yes,width=600,height=500,left=10,top=10,status=yes,resizable=yes');winbm.focus();return false;";\r
1321         }\r
1322         \r
1323         // helper functions\r
1324 \r
1325         /**\r
1326           * Parses highlighted text, with limited actions only (to prevent not fully trusted team members\r
1327           * from hacking your weblog. \r
1328           */\r
1329         function highlightAndParse(&$data) {\r
1330                 // allow only a limited subset of actions (do not allow includes etc, they might be evil)\r
1331                 $this->parser->actions = array('image','media','popup');\r
1332                 $this->parser->parse($this->highlight($data));\r
1333                 $this->parser->actions = $this->getDefinedActions();\r
1334         }\r
1335         \r
1336         function createPopupCode($filename, $width, $height, $text = '') {\r
1337                 global $CONF;\r
1338         \r
1339                 // select private collection when no collection given\r
1340                 if (!strstr($filename,'/')) {\r
1341                         $filename = $this->currentItem->authorid . '/' . $filename;\r
1342                 }\r
1343                 \r
1344                 $windowwidth = $width;\r
1345                 $windowheight = $height;\r
1346                 \r
1347                 $vars['rawpopuplink']   = $CONF['Self'] . "?imagepopup=" . htmlspecialchars($filename) . "&amp;width=$width&amp;height=$height&amp;imagetext=" . urlencode(htmlspecialchars($text));\r
1348                 $vars['popupcode']              = "window.open(this.href,'imagepopup','status=no,toolbar=no,scrollbars=no,resizable=yes,width=$windowwidth,height=$windowheight');return false;";\r
1349                 $vars['popuptext']              = htmlspecialchars($text);\r
1350                 $vars['popuplink']              = '<a href="' . $vars['rawpopuplink']. '" onclick="'. $vars['popupcode'].'" >' . $vars['popuptext'] . '</a>';\r
1351                 $vars['width']                  = $width;\r
1352                 $vars['height']                 = $height;\r
1353                 $vars['text']                   = $text;\r
1354                 \r
1355                 echo TEMPLATE::fill($this->template['POPUP_CODE'],$vars);\r
1356         }\r
1357         \r
1358         function createImageCode($filename, $width, $height, $text = '') {\r
1359                 global $CONF;\r
1360                 \r
1361                 // select private collection when no collection given\r
1362                 if (!strstr($filename,'/')) {\r
1363                         $filename = $this->currentItem->authorid . '/' . $filename;\r
1364                 }\r
1365                 \r
1366                 $windowwidth = $width;\r
1367                 $windowheight = $height;\r
1368                 \r
1369                 $vars['link']                   = htmlspecialchars($CONF['MediaURL']. $filename);\r
1370                 $vars['text']                   = htmlspecialchars($text);\r
1371                 $vars['image'] = '<img src="' . $vars['link'] . '" width="' . $width . '" height="' . $height . '" alt="' . $vars['text'] . '" />';\r
1372                 $vars['width']                  = $width;\r
1373                 $vars['height']                 = $height;\r
1374                                 \r
1375                 \r
1376                 \r
1377                 echo TEMPLATE::fill($this->template['IMAGE_CODE'],$vars);;\r
1378 \r
1379         }\r
1380         \r
1381         function createMediaCode($filename, $text = '') {\r
1382                 global $CONF;\r
1383                 \r
1384                 // select private collection when no collection given\r
1385                 if (!strstr($filename,'/')) {\r
1386                         $filename = $this->currentItem->authorid . '/' . $filename;\r
1387                 }               \r
1388 \r
1389                 $vars['link']                   = htmlspecialchars($CONF['MediaURL'] . $filename);\r
1390                 $vars['text']                   = htmlspecialchars($text);\r
1391                 $vars['media']                  = '<a href="' . $vars['link'] . '">' . $vars['text'] . '</a>';\r
1392 \r
1393                 echo TEMPLATE::fill($this->template['MEDIA_CODE'],$vars);;\r
1394         }\r
1395         \r
1396         \r
1397 }\r
1398 \r
1399 \r
1400 // used for mail notification (html -> text)\r
1401 \r
1402 function toAscii($html) {\r
1403         // strip off most tags \r
1404         $html = strip_tags($html,'<a>');\r
1405         $to_replace = "/<a[^>]*href=[\"\']([^\"^']*)[\"\'][^>]*>([^<]*)<\/a>/i"; \r
1406         _links_init(); \r
1407         $ascii = preg_replace_callback ($to_replace, '_links_add', $html); \r
1408         $ascii .= "\n\n" . _links_list(); \r
1409         return strip_tags($ascii);\r
1410 }\r
1411 \r
1412 function _links_init() { \r
1413    global $tmp_links; \r
1414    $tmp_links = array(); \r
1415\r
1416 \r
1417 function _links_add($match) { \r
1418    global $tmp_links; \r
1419    array_push($tmp_links, $match[1]); \r
1420    return $match[2] . ' [' . sizeof($tmp_links) .']'; \r
1421\r
1422 \r
1423 function _links_list() { \r
1424    global $tmp_links; \r
1425    $output = ''; \r
1426    $i = 1; \r
1427    foreach ($tmp_links as $current) { \r
1428       $output .= "[$i] $current\n"; \r
1429       $i++; \r
1430    } \r
1431    return $output; \r
1432\r
1433 \r
1434  \r
1435 ?>\r