Dotclear

source: inc/core/class.dc.core.php @ 2753:b9cc2b150f13

Revision 2753:b9cc2b150f13, 38.3 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

For new installation :

  • activate CKEditor by default
  • change default user options and make ckeditor default editor for xhtml
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2014 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14/**
15@defgroup DC_CORE Dotclear Core Classes
16*/
17
18/**
19@ingroup DC_CORE
20@nosubgrouping
21@brief Dotclear core class
22
23True to its name dcCore is the core of Dotclear. It handles everything related
24to blogs, database connection, plugins...
25*/
26class dcCore
27{
28     public $con;        ///< <b>connection</b>        Database connection object
29     public $prefix;          ///< <b>string</b>            Database tables prefix
30     public $blog;       ///< <b>dcBlog</b>            dcBlog object
31     public $error;      ///< <b>dcError</b>           dcError object
32     public $auth;       ///< <b>dcAuth</b>            dcAuth object
33     public $session;    ///< <b>sessionDB</b>         sessionDB object
34     public $url;        ///< <b>urlHandler</b>        urlHandler object
35     public $wiki2xhtml; ///< <b>wiki2xhtml</b>        wiki2xhtml object
36     public $plugins;    ///< <b>dcModules</b>         dcModules object
37     public $media;      ///< <b>dcMedia</b>           dcMedia object
38     public $postmedia;  ///< <b>dcPostMedia</b>       dcPostMedia object
39     public $rest;       ///< <b>dcRestServer</b> dcRestServer object
40     public $log;        ///< <b>dcLog</b>             dcLog object
41     public $stime;      ///< <b>float</b>             starting time
42
43     private $versions = null;
44     private $formaters = array();
45     private $behaviors = array();
46     private $post_types = array();
47
48     /**
49     dcCore constructor inits everything related to Dotclear. It takes arguments
50     to init database connection.
51
52     @param    driver    <b>string</b>  Database driver name
53     @param    host      <b>string</b>  Database hostname
54     @param    db        <b>string</b>  Database name
55     @param    user      <b>string</b>  Database username
56     @param    password  <b>string</b>  Database password
57     @param    prefix    <b>string</b>  DotClear tables prefix
58     @param    persist   <b>boolean</b> Persistent database connection
59     */
60     public function __construct($driver, $host, $db, $user, $password, $prefix, $persist)
61     {
62          if (defined('DC_START_TIME')) {
63               $this->stime=DC_START_TIME;
64          } else {
65               $this->stime = microtime(true);
66          }
67
68          $this->con = dbLayer::init($driver,$host,$db,$user,$password,$persist);
69
70          # define weak_locks for mysql
71          if ($this->con instanceof mysqlConnection) {
72               mysqlConnection::$weak_locks = true;
73          } elseif ($this->con instanceof mysqliConnection) {
74               mysqliConnection::$weak_locks = true;
75          }
76
77          # define searchpath for postgresql
78          if ($this->con instanceof pgsqlConnection)
79          {
80               $searchpath = explode ('.',$prefix,2);
81               if (count($searchpath) > 1)
82               {
83                    $prefix = $searchpath[1];
84                    $sql = 'SET search_path TO '.$searchpath[0].',public;';
85                    $this->con->execute($sql);
86               }
87          }
88
89          $this->prefix = $prefix;
90
91          $this->error = new dcError();
92          $this->auth = $this->authInstance();
93          $this->session = new sessionDB($this->con,$this->prefix.'session',DC_SESSION_NAME,'',null,DC_ADMIN_SSL);
94          $this->url = new dcUrlHandlers();
95
96          $this->plugins = new dcPlugins($this);
97
98          $this->rest = new dcRestServer($this);
99
100          $this->meta = new dcMeta($this);
101
102          $this->log = new dcLog($this);
103     }
104
105     private function authInstance()
106     {
107          # You can set DC_AUTH_CLASS to whatever you want.
108          # Your new class *should* inherits dcAuth.
109          if (!defined('DC_AUTH_CLASS')) {
110               $c = 'dcAuth';
111          } else {
112               $c = DC_AUTH_CLASS;
113          }
114
115          if (!class_exists($c)) {
116               throw new Exception('Authentication class '.$c.' does not exist.');
117          }
118
119          if ($c != 'dcAuth' && !is_subclass_of($c,'dcAuth')) {
120               throw new Exception('Authentication class '.$c.' does not inherit dcAuth.');
121          }
122
123          return new $c($this);
124     }
125
126
127     /// @name Blog init methods
128     //@{
129     /**
130     Sets a blog to use in <var>blog</var> property.
131
132     @param    id        <b>string</b>       Blog ID
133     */
134     public function setBlog($id)
135     {
136          $this->blog = new dcBlog($this, $id);
137     }
138
139     /**
140     Unsets <var>blog</var> property.
141     */
142     public function unsetBlog()
143     {
144          $this->blog = null;
145     }
146     //@}
147
148
149     /// @name Blog status methods
150     //@{
151     /**
152     Returns an array of available blog status codes and names.
153
154     @return   <b>array</b> Simple array with codes in keys and names in value
155     */
156     public function getAllBlogStatus()
157     {
158          return array(
159               1 => __('online'),
160               0 => __('offline'),
161               -1 => __('removed')
162          );
163     }
164
165     /**
166     Returns a blog status name given to a code. This is intended to be
167     human-readable and will be translated, so never use it for tests.
168     If status code does not exist, returns <i>offline</i>.
169
170     @param    s    <b>integer</b> Status code
171     @return   <b>string</b> Blog status name
172     */
173     public function getBlogStatus($s)
174     {
175          $r = $this->getAllBlogStatus();
176          if (isset($r[$s])) {
177               return $r[$s];
178          }
179          return $r[0];
180     }
181     //@}
182
183     /// @name Admin nonce secret methods
184     //@{
185
186     public function getNonce()
187     {
188          return crypt::hmac(DC_MASTER_KEY,session_id());
189     }
190
191     public function checkNonce($secret)
192     {
193          if (!preg_match('/^([0-9a-f]{40,})$/i',$secret)) {
194               return false;
195          }
196
197          return $secret == crypt::hmac(DC_MASTER_KEY,session_id());
198     }
199
200     public function formNonce()
201     {
202          if (!session_id()) {
203               return;
204          }
205
206          return form::hidden(array('xd_check'),$this->getNonce());
207     }
208     //@}
209
210     /// @name Text Formatters methods
211     //@{
212     /**
213     Adds a new text formater which will call the function <var>$func</var> to
214     transform text. The function must be a valid callback and takes one
215     argument: the string to transform. It returns the transformed string.
216
217     @param    editor_id <b>string</b>  Editor id (dcLegacyEditor, dcCKEditor, ...)
218     @param    name      <b>string</b>  Formater name
219     @param    func      <b>callback</b>     Function to use, must be a valid and callable callback
220     */
221     public function addEditorFormater($editor_id,$name,$func)
222     {
223          if (is_callable($func)) {
224               $this->formaters[$editor_id][$name] = $func;
225          }
226     }
227
228     /// @name Text Formatters methods
229     //@{
230     /**
231     Adds a new text formater which will call the function <var>$func</var> to
232     transform text. The function must be a valid callback and takes one
233     argument: the string to transform. It returns the transformed string.
234
235     @param    name      <b>string</b>       Formater name
236     @param    func      <b>callback</b>     Function to use, must be a valid and callable callback
237     */
238     public function addFormater($name,$func)
239     {
240          $this->addEditorFormater('dcLegacyEditor',$name,$func);
241     }
242
243     /**
244     Returns editors list
245
246     @return   <b>array</b> An array of editors values.
247     */
248     public function getEditors()
249     {
250          $editors = array();
251
252          foreach (array_keys($this->formaters) as $editor_id) {
253               $editors[$editor_id] = $this->plugins->moduleInfo($editor_id,'name');
254          }
255
256          return $editors;
257     }
258
259     /**
260     Returns formaters list by editor
261
262     @param    editor_id <b>string</b>  Editor id (dcLegacyEditor, dcCKEditor, ...)
263     @return   <b>array</b> An array of formaters names in values.
264
265     /**
266     if @param editor_id is empty:
267     return all formaters sorted by actives editors
268
269     if @param editor_id is not empty
270     return formaters for an editor if editor is active
271     return empty() array if editor is not active.
272     It can happens when a user choose an editor and admin deactivate that editor later
273     */
274     public function getFormaters($editor_id='')
275     {
276          $formaters_list = array();
277
278          if (!empty($editor_id)) {
279            if (isset($this->formaters[$editor_id])) {
280                $formaters_list = array_keys($this->formaters[$editor_id]);
281            }
282          } else {
283               foreach ($this->formaters as $editor => $formaters) {
284                    $formaters_list[$editor] = array_keys($formaters);
285               }
286          }
287
288          return $formaters_list;
289     }
290
291     /**
292     If <var>$name</var> is a valid formater, it returns <var>$str</var>
293     transformed using that formater.
294
295     @param    editor_id <b>string</b>  Editor id (dcLegacyEditor, dcCKEditor, ...)
296     @param    name      <b>string</b>  Formater name
297     @param    str            <b>string</b>  String to transform
298     @return   <b>string</b>  String transformed
299     */
300     public function callEditorFormater($editor_id,$name,$str)
301     {
302          if (isset($this->formaters[$editor_id]) && isset($this->formaters[$editor_id][$name])) {
303               return call_user_func($this->formaters[$editor_id][$name],$str);
304          }
305
306          return $str;
307     }
308     //@}
309
310     /**
311     If <var>$name</var> is a valid formater, it returns <var>$str</var>
312     transformed using that formater.
313
314     @param    name      <b>string</b>       Formater name
315     @param    str           <b>string</b>        String to transform
316     @return   <b>string</b>  String transformed
317     */
318     public function callFormater($name,$str)
319     {
320          return $this->callEditorFormater('dcLegacyEditor',$name,$str);
321     }
322     //@}
323
324
325     /// @name Behaviors methods
326     //@{
327     /**
328     Adds a new behavior to behaviors stack. <var>$func</var> must be a valid
329     and callable callback.
330
331     @param    behavior  <b>string</b>       Behavior name
332     @param    func      <b>callback</b>     Function to call
333     */
334     public function addBehavior($behavior,$func)
335     {
336          if (is_callable($func)) {
337               $this->behaviors[$behavior][] = $func;
338          }
339     }
340
341     /**
342     Tests if a particular behavior exists in behaviors stack.
343
344     @param    behavior  <b>string</b>  Behavior name
345     @return   <b>boolean</b>
346     */
347     public function hasBehavior($behavior)
348     {
349          return isset($this->behaviors[$behavior]);
350     }
351
352     /**
353     Get behaviors stack (or part of).
354
355     @param    behavior  <b>string</b>       Behavior name
356     @return   <b>array</b>
357     */
358     public function getBehaviors($behavior='')
359     {
360          if (empty($this->behaviors)) return null;
361
362          if ($behavior == '') {
363               return $this->behaviors;
364          } elseif (isset($this->behaviors[$behavior])) {
365               return $this->behaviors[$behavior];
366          }
367
368          return array();
369     }
370
371     /**
372     Calls every function in behaviors stack for a given behavior and returns
373     concatened result of each function.
374
375     Every parameters added after <var>$behavior</var> will be pass to
376     behavior calls.
377
378     @param    behavior  <b>string</b>  Behavior name
379     @return   <b>string</b> Behavior concatened result
380     */
381     public function callBehavior($behavior)
382     {
383          if (isset($this->behaviors[$behavior]))
384          {
385               $args = func_get_args();
386               array_shift($args);
387
388               $res = '';
389
390               foreach ($this->behaviors[$behavior] as $f) {
391                    $res .= call_user_func_array($f,$args);
392               }
393
394               return $res;
395          }
396     }
397     //@}
398
399     /// @name Post types URLs management
400     //@{
401     public function getPostAdminURL($type,$post_id,$escaped=true)
402     {
403          if (!isset($this->post_types[$type])) {
404               $type = 'post';
405          }
406
407          $url = sprintf($this->post_types[$type]['admin_url'],$post_id);
408          return $escaped ? html::escapeURL($url) : $url;
409     }
410
411     public function getPostPublicURL($type,$post_url,$escaped=true)
412     {
413          if (!isset($this->post_types[$type])) {
414               $type = 'post';
415          }
416
417          $url = sprintf($this->post_types[$type]['public_url'],$post_url);
418          return $escaped ? html::escapeURL($url) : $url;
419     }
420
421     public function setPostType($type,$admin_url,$public_url,$label='')
422     {
423          $this->post_types[$type] = array(
424               'admin_url' => $admin_url,
425               'public_url' => $public_url,
426               'label' => ($label != '' ? $label : $type)
427          );
428     }
429
430     public function getPostTypes()
431     {
432          return $this->post_types;
433     }
434     //@}
435
436     /// @name Versions management methods
437     //@{
438     /**
439     Returns a given $module version.
440
441     @param    module    <b>string</b>  Module name
442     @return   <b>string</b>  Module version
443     */
444     public function getVersion($module='core')
445     {
446          # Fetch versions if needed
447          if (!is_array($this->versions))
448          {
449               $strReq = 'SELECT module, version FROM '.$this->prefix.'version';
450               $rs = $this->con->select($strReq);
451
452               while ($rs->fetch()) {
453                    $this->versions[$rs->module] = $rs->version;
454               }
455          }
456
457          if (isset($this->versions[$module])) {
458               return $this->versions[$module];
459          } else {
460               return null;
461          }
462     }
463
464     /**
465     Sets $version to given $module.
466
467     @param    module    <b>string</b>  Module name
468     @param    version   <b>string</b>  Module version
469     */
470     public function setVersion($module,$version)
471     {
472          $cur_version = $this->getVersion($module);
473
474          $cur = $this->con->openCursor($this->prefix.'version');
475          $cur->module = (string) $module;
476          $cur->version = (string) $version;
477
478          if ($cur_version === null) {
479               $cur->insert();
480          } else {
481               $cur->update("WHERE module='".$this->con->escape($module)."'");
482          }
483
484          $this->versions[$module] = $version;
485     }
486
487     /**
488     Removes given $module version entry.
489
490     @param    module    <b>string</b>  Module name
491     */
492     public function delVersion($module)
493     {
494          $strReq =
495          'DELETE FROM '.$this->prefix.'version '.
496          "WHERE module = '".$this->con->escape($module)."' ";
497
498          $this->con->execute($strReq);
499
500          if (is_array($this->versions)) {
501               unset($this->versions[$module]);
502          }
503     }
504
505     //@}
506
507     /// @name Users management methods
508     //@{
509     /**
510     Returns a user by its ID.
511
512     @param    id        <b>string</b>       User ID
513     @return   <b>record</b>
514     */
515     public function getUser($id)
516     {
517          $params['user_id'] = $id;
518
519          return $this->getUsers($params);
520     }
521
522     /**
523     Returns a users list. <b>$params</b> is an array with the following
524     optionnal parameters:
525
526      - <var>q</var>: search string (on user_id, user_name, user_firstname)
527      - <var>user_id</var>: user ID
528      - <var>order</var>: ORDER BY clause (default: user_id ASC)
529      - <var>limit</var>: LIMIT clause (should be an array ![limit,offset])
530
531     @param    params         <b>array</b>        Parameters
532     @param    count_only     <b>boolean</b>      Only counts results
533     @return   <b>record</b>
534     */
535     public function getUsers($params=array(),$count_only=false)
536     {
537          if ($count_only)
538          {
539               $strReq =
540               'SELECT count(U.user_id) '.
541               'FROM '.$this->prefix.'user U '.
542               'WHERE NULL IS NULL ';
543          }
544          else
545          {
546               $strReq =
547               'SELECT U.user_id,user_super,user_status,user_pwd,user_change_pwd,'.
548               'user_name,user_firstname,user_displayname,user_email,user_url,'.
549               'user_desc, user_lang,user_tz, user_post_status,user_options, '.
550               'count(P.post_id) AS nb_post '.
551               'FROM '.$this->prefix.'user U '.
552                    'LEFT JOIN '.$this->prefix.'post P ON U.user_id = P.user_id '.
553               'WHERE NULL IS NULL ';
554          }
555
556          if (!empty($params['q'])) {
557               $q = $this->con->escape(str_replace('*','%',strtolower($params['q'])));
558               $strReq .= 'AND ('.
559                    "LOWER(U.user_id) LIKE '".$q."' ".
560                    "OR LOWER(user_name) LIKE '".$q."' ".
561                    "OR LOWER(user_firstname) LIKE '".$q."' ".
562                    ') ';
563          }
564
565          if (!empty($params['user_id'])) {
566               $strReq .= "AND U.user_id = '".$this->con->escape($params['user_id'])."' ";
567          }
568
569          if (!$count_only) {
570               $strReq .= 'GROUP BY U.user_id,user_super,user_status,user_pwd,user_change_pwd,'.
571               'user_name,user_firstname,user_displayname,user_email,user_url,'.
572               'user_desc, user_lang,user_tz,user_post_status,user_options ';
573
574               if (!empty($params['order']) && !$count_only) {
575                    $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' ';
576               } else {
577                    $strReq .= 'ORDER BY U.user_id ASC ';
578               }
579          }
580
581          if (!$count_only && !empty($params['limit'])) {
582               $strReq .= $this->con->limit($params['limit']);
583          }
584
585          $rs = $this->con->select($strReq);
586          $rs->extend('rsExtUser');
587          return $rs;
588     }
589
590     /**
591     Create a new user. Takes a cursor as input and returns the new user ID.
592
593     @param    cur       <b>cursor</b>       User cursor
594     @return   <b>string</b>
595     */
596     public function addUser($cur)
597     {
598          if (!$this->auth->isSuperAdmin()) {
599               throw new Exception(__('You are not an administrator'));
600          }
601
602          if ($cur->user_id == '') {
603               throw new Exception(__('No user ID given'));
604          }
605
606          if ($cur->user_pwd == '') {
607               throw new Exception(__('No password given'));
608          }
609
610          $this->getUserCursor($cur);
611
612          if ($cur->user_creadt === null) {
613               $cur->user_creadt = date('Y-m-d H:i:s');
614          }
615
616          $cur->insert();
617
618          $this->auth->afterAddUser($cur);
619
620          return $cur->user_id;
621     }
622
623     /**
624     Updates an existing user. Returns the user ID.
625
626     @param    id        <b>string</b>       User ID
627     @param    cur       <b>cursor</b>       User cursor
628     @return   <b>string</b>
629     */
630     public function updUser($id,$cur)
631     {
632          $this->getUserCursor($cur);
633
634          if (($cur->user_id !== null || $id != $this->auth->userID()) &&
635          !$this->auth->isSuperAdmin()) {
636               throw new Exception(__('You are not an administrator'));
637          }
638
639          $cur->update("WHERE user_id = '".$this->con->escape($id)."' ");
640
641          $this->auth->afterUpdUser($id,$cur);
642
643          if ($cur->user_id !== null) {
644               $id = $cur->user_id;
645          }
646
647          # Updating all user's blogs
648          $rs = $this->con->select(
649               'SELECT DISTINCT(blog_id) FROM '.$this->prefix.'post '.
650               "WHERE user_id = '".$this->con->escape($id)."' "
651               );
652
653          while ($rs->fetch()) {
654               $b = new dcBlog($this,$rs->blog_id);
655               $b->triggerBlog();
656               unset($b);
657          }
658
659          return $id;
660     }
661
662     /**
663     Deletes a user.
664
665     @param    id        <b>string</b>       User ID
666     */
667     public function delUser($id)
668     {
669          if (!$this->auth->isSuperAdmin()) {
670               throw new Exception(__('You are not an administrator'));
671          }
672
673          if ($id == $this->auth->userID()) {
674               return;
675          }
676
677          $rs = $this->getUser($id);
678
679          if ($rs->nb_post > 0) {
680               return;
681          }
682
683          $strReq = 'DELETE FROM '.$this->prefix.'user '.
684                    "WHERE user_id = '".$this->con->escape($id)."' ";
685
686          $this->con->execute($strReq);
687
688          $this->auth->afterDelUser($id);
689     }
690
691     /**
692     Checks whether a user exists.
693
694     @param    id        <b>string</b>       User ID
695     @return   <b>boolean</b>
696     */
697     public function userExists($id)
698     {
699          $strReq = 'SELECT user_id '.
700                    'FROM '.$this->prefix.'user '.
701                    "WHERE user_id = '".$this->con->escape($id)."' ";
702
703          $rs = $this->con->select($strReq);
704
705          return !$rs->isEmpty();
706     }
707
708     /**
709     Returns all user permissions as an array which looks like:
710
711      - [blog_id]
712        - [name] => Blog name
713        - [url] => Blog URL
714        - [p]
715          - [permission] => true
716          - ...
717
718     @param    id        <b>string</b>       User ID
719     @return   <b>array</b>
720     */
721     public function getUserPermissions($id)
722     {
723          $strReq = 'SELECT B.blog_id, blog_name, blog_url, permissions '.
724                    'FROM '.$this->prefix.'permissions P '.
725                    'INNER JOIN '.$this->prefix.'blog B ON P.blog_id = B.blog_id '.
726                    "WHERE user_id = '".$this->con->escape($id)."' ";
727
728          $rs = $this->con->select($strReq);
729
730          $res = array();
731
732          while ($rs->fetch())
733          {
734               $res[$rs->blog_id] = array(
735                    'name' => $rs->blog_name,
736                    'url' => $rs->blog_url,
737                    'p' => $this->auth->parsePermissions($rs->permissions)
738               );
739          }
740
741          return $res;
742     }
743
744     /**
745     Sets user permissions. The <var>$perms</var> array looks like:
746
747      - [blog_id] => '|perm1|perm2|'
748      - ...
749
750     @param    id        <b>string</b>       User ID
751     @param    perms     <b>array</b>        Permissions array
752     */
753     public function setUserPermissions($id,$perms)
754     {
755          if (!$this->auth->isSuperAdmin()) {
756               throw new Exception(__('You are not an administrator'));
757          }
758
759          $strReq = 'DELETE FROM '.$this->prefix.'permissions '.
760                    "WHERE user_id = '".$this->con->escape($id)."' ";
761
762          $this->con->execute($strReq);
763
764          foreach ($perms as $blog_id => $p) {
765               $this->setUserBlogPermissions($id, $blog_id, $p, false);
766          }
767     }
768
769     /**
770     Sets user permissions for a given blog. <var>$perms</var> is an array with
771     permissions in values
772
773     @param    id             <b>string</b>       User ID
774     @param    blog_id        <b>string</b>       Blog ID
775     @param    perms          <b>array</b>        Permissions
776     @param    delete_first   <b>boolean</b>      Delete permissions before
777     */
778     public function setUserBlogPermissions($id, $blog_id, $perms, $delete_first=true)
779     {
780          if (!$this->auth->isSuperAdmin()) {
781               throw new Exception(__('You are not an administrator'));
782          }
783
784          $no_perm = empty($perms);
785
786          $perms = '|'.implode('|',array_keys($perms)).'|';
787
788          $cur = $this->con->openCursor($this->prefix.'permissions');
789
790          $cur->user_id = (string) $id;
791          $cur->blog_id = (string) $blog_id;
792          $cur->permissions = $perms;
793
794          if ($delete_first || $no_perm)
795          {
796               $strReq = 'DELETE FROM '.$this->prefix.'permissions '.
797                         "WHERE blog_id = '".$this->con->escape($blog_id)."' ".
798                         "AND user_id = '".$this->con->escape($id)."' ";
799
800               $this->con->execute($strReq);
801          }
802
803          if (!$no_perm) {
804               $cur->insert();
805          }
806     }
807
808     /**
809     Sets a user default blog. This blog will be selected when user log in.
810
811     @param    id             <b>string</b>       User ID
812     @param    blog_id        <b>string</b>       Blog ID
813     */
814     public function setUserDefaultBlog($id, $blog_id)
815     {
816          $cur = $this->con->openCursor($this->prefix.'user');
817
818          $cur->user_default_blog = (string) $blog_id;
819
820          $cur->update("WHERE user_id = '".$this->con->escape($id)."'");
821     }
822
823     private function getUserCursor($cur)
824     {
825          if ($cur->isField('user_id')
826          && !preg_match('/^[A-Za-z0-9@._-]{2,}$/',$cur->user_id)) {
827               throw new Exception(__('User ID must contain at least 2 characters using letters, numbers or symbols.'));
828          }
829
830          if ($cur->user_url !== null && $cur->user_url != '') {
831               if (!preg_match('|^http(s?)://|',$cur->user_url)) {
832                    $cur->user_url = 'http://'.$cur->user_url;
833               }
834          }
835
836          if ($cur->isField('user_pwd')) {
837               if (strlen($cur->user_pwd) < 6) {
838                    throw new Exception(__('Password must contain at least 6 characters.'));
839               }
840               $cur->user_pwd = crypt::hmac(DC_MASTER_KEY,$cur->user_pwd);
841          }
842
843          if ($cur->user_lang !== null && !preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$cur->user_lang)) {
844               throw new Exception(__('Invalid user language code'));
845          }
846
847          if ($cur->user_upddt === null) {
848               $cur->user_upddt = date('Y-m-d H:i:s');
849          }
850
851          if ($cur->user_options !== null) {
852               $cur->user_options = serialize((array) $cur->user_options);
853          }
854     }
855
856     /**
857     Returns user default settings in an associative array with setting names in
858     keys.
859
860     @return   <b>array</b>
861     */
862     public function userDefaults()
863     {
864          return array(
865               'edit_size' => 24,
866               'enable_wysiwyg' => true,
867               'editor' => array('xhtml' => 'dcCKEditor', 'wiki' => 'dcLegacyEditor'),
868               'post_format' => 'wiki'
869          );
870     }
871     //@}
872
873     /// @name Blog management methods
874     //@{
875     /**
876     Returns all blog permissions (users) as an array which looks like:
877
878      - [user_id]
879        - [name] => User name
880        - [firstname] => User firstname
881        - [displayname] => User displayname
882        - [super] => (true|false) super admin
883        - [p]
884          - [permission] => true
885          - ...
886
887     @param    id             <b>string</b>       Blog ID
888     @param    with_super     <b>boolean</b>      Includes super admins in result
889     @return   <b>array</b>
890     */
891     public function getBlogPermissions($id,$with_super=true)
892     {
893          $strReq =
894          'SELECT U.user_id AS user_id, user_super, user_name, user_firstname, '.
895          'user_displayname, user_email, permissions '.
896          'FROM '.$this->prefix.'user U '.
897          'JOIN '.$this->prefix.'permissions P ON U.user_id = P.user_id '.
898          "WHERE blog_id = '".$this->con->escape($id)."' ";
899
900          if ($with_super) {
901               $strReq .=
902               'UNION '.
903               'SELECT U.user_id AS user_id, user_super, user_name, user_firstname, '.
904               "user_displayname, user_email, NULL AS permissions ".
905               'FROM '.$this->prefix.'user U '.
906               'WHERE user_super = 1 ';
907          }
908
909          $rs = $this->con->select($strReq);
910
911          $res = array();
912
913          while ($rs->fetch())
914          {
915               $res[$rs->user_id] = array(
916                    'name' => $rs->user_name,
917                    'firstname' => $rs->user_firstname,
918                    'displayname' => $rs->user_displayname,
919                    'email' => $rs->user_email,
920                    'super' => (boolean) $rs->user_super,
921                    'p' => $this->auth->parsePermissions($rs->permissions)
922               );
923          }
924
925          return $res;
926     }
927
928     /**
929     Returns a blog of given ID.
930
931     @param    id        <b>string</b>       Blog ID
932     @return   <b>record</b>
933     */
934     public function getBlog($id)
935     {
936          $blog = $this->getBlogs(array('blog_id'=>$id));
937
938          if ($blog->isEmpty()) {
939               return false;
940          }
941
942          return $blog;
943     }
944
945     /**
946     Returns a record of blogs. <b>$params</b> is an array with the following
947     optionnal parameters:
948
949      - <var>blog_id</var>: Blog ID
950      - <var>q</var>: Search string on blog_id, blog_name and blog_url
951      - <var>limit</var>: limit results
952
953     @param    params         <b>array</b>        Parameters
954     @param    count_only     <b>boolean</b>      Count only results
955     @return   <b>record</b>
956     */
957     public function getBlogs($params=array(),$count_only=false)
958     {
959          $join = '';    // %1$s
960          $where = '';   // %2$s
961
962          if ($count_only)
963          {
964               $strReq = 'SELECT count(B.blog_id) '.
965                         'FROM '.$this->prefix.'blog B '.
966                         '%1$s '.
967                         'WHERE NULL IS NULL '.
968                         '%2$s ';
969          }
970          else
971          {
972               $strReq =
973               'SELECT B.blog_id, blog_uid, blog_url, blog_name, blog_desc, blog_creadt, '.
974               'blog_upddt, blog_status '.
975               'FROM '.$this->prefix.'blog B '.
976               '%1$s '.
977               'WHERE NULL IS NULL '.
978               '%2$s ';
979
980               if (!empty($params['order'])) {
981                    $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' ';
982               } else {
983                    $strReq .= 'ORDER BY B.blog_id ASC ';
984               }
985
986               if (!empty($params['limit'])) {
987                    $strReq .= $this->con->limit($params['limit']);
988               }
989          }
990
991          if ($this->auth->userID() && !$this->auth->isSuperAdmin())
992          {
993               $join = 'INNER JOIN '.$this->prefix.'permissions PE ON B.blog_id = PE.blog_id ';
994               $where =
995               "AND PE.user_id = '".$this->con->escape($this->auth->userID())."' ".
996               "AND (permissions LIKE '%|usage|%' OR permissions LIKE '%|admin|%' OR permissions LIKE '%|contentadmin|%') ".
997               "AND blog_status IN (1,0) ";
998          } elseif (!$this->auth->userID()) {
999               $where = 'AND blog_status IN (1,0) ';
1000          }
1001
1002          if (!empty($params['blog_id'])) {
1003               $where .= "AND B.blog_id = '".$this->con->escape($params['blog_id'])."' ";
1004          }
1005
1006          if (!empty($params['q'])) {
1007               $params['q'] = strtolower(str_replace('*','%',$params['q']));
1008               $where .=
1009               'AND ('.
1010               "LOWER(B.blog_id) LIKE '".$this->con->escape($params['q'])."' ".
1011               "OR LOWER(B.blog_name) LIKE '".$this->con->escape($params['q'])."' ".
1012               "OR LOWER(B.blog_url) LIKE '".$this->con->escape($params['q'])."' ".
1013               ') ';
1014          }
1015
1016          $strReq = sprintf($strReq,$join,$where);
1017          return $this->con->select($strReq);
1018     }
1019
1020     /**
1021     Creates a new blog.
1022
1023     @param    cur            <b>cursor</b>       Blog cursor
1024     */
1025     public function addBlog($cur)
1026     {
1027          if (!$this->auth->isSuperAdmin()) {
1028               throw new Exception(__('You are not an administrator'));
1029          }
1030
1031          $this->getBlogCursor($cur);
1032
1033          $cur->blog_creadt = date('Y-m-d H:i:s');
1034          $cur->blog_upddt = date('Y-m-d H:i:s');
1035          $cur->blog_uid = md5(uniqid());
1036
1037          $cur->insert();
1038     }
1039
1040     /**
1041     Updates a given blog.
1042
1043     @param    id        <b>string</b>       Blog ID
1044     @param    cur       <b>cursor</b>       Blog cursor
1045     */
1046     public function updBlog($id,$cur)
1047     {
1048          $this->getBlogCursor($cur);
1049
1050          $cur->blog_upddt = date('Y-m-d H:i:s');
1051
1052          $cur->update("WHERE blog_id = '".$this->con->escape($id)."'");
1053     }
1054
1055     private function getBlogCursor($cur)
1056     {
1057          if (($cur->blog_id !== null
1058               && !preg_match('/^[A-Za-z0-9._-]{2,}$/',$cur->blog_id)) ||
1059               (!$cur->blog_id)) {
1060               throw new Exception(__('Blog ID must contain at least 2 characters using letters, numbers or symbols.'));
1061          }
1062
1063          if (($cur->blog_name !== null && $cur->blog_name == '') ||
1064               (!$cur->blog_name)) {
1065               throw new Exception(__('No blog name'));
1066          }
1067
1068          if (($cur->blog_url !== null && $cur->blog_url == '') ||
1069               (!$cur->blog_url)) {
1070               throw new Exception(__('No blog URL'));
1071          }
1072
1073          if ($cur->blog_desc !== null) {
1074               $cur->blog_desc = html::clean($cur->blog_desc);
1075          }
1076     }
1077
1078     /**
1079     Removes a given blog.
1080     @warning This will remove everything related to the blog (posts,
1081     categories, comments, links...)
1082
1083     @param    id        <b>string</b>       Blog ID
1084     */
1085     public function delBlog($id)
1086     {
1087          if (!$this->auth->isSuperAdmin()) {
1088               throw new Exception(__('You are not an administrator'));
1089          }
1090
1091          $strReq = 'DELETE FROM '.$this->prefix.'blog '.
1092                    "WHERE blog_id = '".$this->con->escape($id)."' ";
1093
1094          $this->con->execute($strReq);
1095     }
1096
1097     /**
1098     Checks if a blog exist.
1099
1100     @param    id        <b>string</b>       Blog ID
1101     @return   <b>boolean</b>
1102     */
1103     public function blogExists($id)
1104     {
1105          $strReq = 'SELECT blog_id '.
1106                    'FROM '.$this->prefix.'blog '.
1107                    "WHERE blog_id = '".$this->con->escape($id)."' ";
1108
1109          $rs = $this->con->select($strReq);
1110
1111          return !$rs->isEmpty();
1112     }
1113
1114     /**
1115     Count posts on a blog
1116
1117     @param    id        <b>string</b>       Blog ID
1118     @param    type      <b>string</b>       Post type
1119     @return   <b>boolean</b>
1120     */
1121     public function countBlogPosts($id,$type=null)
1122     {
1123          $strReq = 'SELECT COUNT(post_id) '.
1124                    'FROM '.$this->prefix.'post '.
1125                    "WHERE blog_id = '".$this->con->escape($id)."' ";
1126
1127          if ($type) {
1128               $strReq .= "AND post_type = '".$this->con->escape($type)."' ";
1129          }
1130
1131          return $this->con->select($strReq)->f(0);
1132     }
1133     //@}
1134
1135     /// @name HTML Filter methods
1136     //@{
1137     /**
1138     Calls HTML filter to drop bad tags and produce valid XHTML output (if
1139     tidy extension is present). If <b>enable_html_filter</b> blog setting is
1140     false, returns not filtered string.
1141
1142     @param    str  <b>string</b>       String to filter
1143     @return   <b>string</b> Filtered string.
1144     */
1145     public function HTMLfilter($str)
1146     {
1147          if ($this->blog instanceof dcBlog && !$this->blog->settings->system->enable_html_filter) {
1148               return $str;
1149          }
1150
1151          $filter = new htmlFilter;
1152          $str = trim($filter->apply($str));
1153          return $str;
1154     }
1155     //@}
1156
1157     /// @name wiki2xhtml methods
1158     //@{
1159     private function initWiki()
1160     {
1161          $this->wiki2xhtml = new wiki2xhtml;
1162     }
1163
1164     /**
1165     Returns a transformed string with wiki2xhtml.
1166
1167     @param    str       <b>string</b>       String to transform
1168     @return   <b>string</b>  Transformed string
1169     */
1170     public function wikiTransform($str)
1171     {
1172          if (!($this->wiki2xhtml instanceof wiki2xhtml)) {
1173               $this->initWiki();
1174          }
1175          return $this->wiki2xhtml->transform($str);
1176     }
1177
1178     /**
1179     Inits <var>wiki2xhtml</var> property for blog post.
1180     */
1181     public function initWikiPost()
1182     {
1183          $this->initWiki();
1184
1185          $this->wiki2xhtml->setOpts(array(
1186               'active_title' => 1,
1187               'active_setext_title' => 0,
1188               'active_hr' => 1,
1189               'active_lists' => 1,
1190               'active_quote' => 1,
1191               'active_pre' => 1,
1192               'active_empty' => 1,
1193               'active_auto_br' => 0,
1194               'active_auto_urls' => 0,
1195               'active_urls' => 1,
1196               'active_auto_img' => 0,
1197               'active_img' => 1,
1198               'active_anchor' => 1,
1199               'active_em' => 1,
1200               'active_strong' => 1,
1201               'active_br' => 1,
1202               'active_q' => 1,
1203               'active_code' => 1,
1204               'active_acronym' => 1,
1205               'active_ins' => 1,
1206               'active_del' => 1,
1207               'active_footnotes' => 1,
1208               'active_wikiwords' => 0,
1209               'active_macros' => 1,
1210               'parse_pre' => 1,
1211               'active_fr_syntax' => 0,
1212               'first_title_level' => 3,
1213               'note_prefix' => 'wiki-footnote',
1214               'note_str' => '<div class="footnotes"><h4>Notes</h4>%s</div>'
1215          ));
1216
1217          $this->wiki2xhtml->registerFunction('url:post',array($this,'wikiPostLink'));
1218
1219          # --BEHAVIOR-- coreWikiPostInit
1220          $this->callBehavior('coreInitWikiPost',$this->wiki2xhtml);
1221     }
1222
1223     /**
1224     Inits <var>wiki2xhtml</var> property for simple blog comment (basic syntax).
1225     */
1226     public function initWikiSimpleComment()
1227     {
1228          $this->initWiki();
1229
1230          $this->wiki2xhtml->setOpts(array(
1231               'active_title' => 0,
1232               'active_setext_title' => 0,
1233               'active_hr' => 0,
1234               'active_lists' => 0,
1235               'active_quote' => 0,
1236               'active_pre' => 0,
1237               'active_empty' => 0,
1238               'active_auto_br' => 1,
1239               'active_auto_urls' => 1,
1240               'active_urls' => 0,
1241               'active_auto_img' => 0,
1242               'active_img' => 0,
1243               'active_anchor' => 0,
1244               'active_em' => 0,
1245               'active_strong' => 0,
1246               'active_br' => 0,
1247               'active_q' => 0,
1248               'active_code' => 0,
1249               'active_acronym' => 0,
1250               'active_ins' => 0,
1251               'active_del' => 0,
1252               'active_footnotes' => 0,
1253               'active_wikiwords' => 0,
1254               'active_macros' => 0,
1255               'parse_pre' => 0,
1256               'active_fr_syntax' => 0
1257          ));
1258
1259          # --BEHAVIOR-- coreInitWikiSimpleComment
1260          $this->callBehavior('coreInitWikiSimpleComment',$this->wiki2xhtml);
1261     }
1262
1263     /**
1264     Inits <var>wiki2xhtml</var> property for blog comment.
1265     */
1266     public function initWikiComment()
1267     {
1268          $this->initWiki();
1269
1270          $this->wiki2xhtml->setOpts(array(
1271               'active_title' => 0,
1272               'active_setext_title' => 0,
1273               'active_hr' => 0,
1274               'active_lists' => 1,
1275               'active_quote' => 0,
1276               'active_pre' => 1,
1277               'active_empty' => 0,
1278               'active_auto_br' => 1,
1279               'active_auto_urls' => 1,
1280               'active_urls' => 1,
1281               'active_auto_img' => 0,
1282               'active_img' => 0,
1283               'active_anchor' => 0,
1284               'active_em' => 1,
1285               'active_strong' => 1,
1286               'active_br' => 1,
1287               'active_q' => 1,
1288               'active_code' => 1,
1289               'active_acronym' => 1,
1290               'active_ins' => 1,
1291               'active_del' => 1,
1292               'active_footnotes' => 0,
1293               'active_wikiwords' => 0,
1294               'active_macros' => 0,
1295               'parse_pre' => 0,
1296               'active_fr_syntax' => 0
1297          ));
1298
1299          # --BEHAVIOR-- coreInitWikiComment
1300          $this->callBehavior('coreInitWikiComment',$this->wiki2xhtml);
1301     }
1302
1303     public function wikiPostLink($url,$content)
1304     {
1305          if (!($this->blog instanceof dcBlog)) {
1306               return array();
1307          }
1308
1309          $post_id = abs((integer) substr($url,5));
1310          if (!$post_id) {
1311               return array();
1312          }
1313
1314          $post = $this->blog->getPosts(array('post_id'=>$post_id));
1315          if ($post->isEmpty()) {
1316               return array();
1317          }
1318
1319          $res = array('url' => $post->getURL());
1320          $post_title = $post->post_title;
1321
1322          if ($content != $url) {
1323               $res['title'] = html::escapeHTML($post->post_title);
1324          }
1325
1326          if ($content == '' || $content == $url) {
1327               $res['content'] = html::escapeHTML($post->post_title);
1328          }
1329
1330          if ($post->post_lang) {
1331               $res['lang'] = $post->post_lang;
1332          }
1333
1334          return $res;
1335     }
1336     //@}
1337
1338     /// @name Maintenance methods
1339     //@{
1340     /**
1341     Creates default settings for active blog. Optionnal parameter
1342     <var>defaults</var> replaces default params while needed.
1343
1344     @param    defaults       <b>array</b>   Default parameters
1345     */
1346     public function blogDefaults($defaults=null)
1347     {
1348          if (!is_array($defaults))
1349          {
1350               $defaults = array(
1351                    array('allow_comments','boolean',true,
1352                    'Allow comments on blog'),
1353                    array('allow_trackbacks','boolean',true,
1354                    'Allow trackbacks on blog'),
1355                    array('blog_timezone','string','Europe/London',
1356                    'Blog timezone'),
1357                    array('comments_nofollow','boolean',true,
1358                    'Add rel="nofollow" to comments URLs'),
1359                    array('comments_pub','boolean',true,
1360                    'Publish comments immediately'),
1361                    array('comments_ttl','integer',0,
1362                    'Number of days to keep comments open (0 means no ttl)'),
1363                    array('copyright_notice','string','','Copyright notice (simple text)'),
1364                    array('date_format','string','%A, %B %e %Y',
1365                    'Date format. See PHP strftime function for patterns'),
1366                    array('editor','string','',
1367                    'Person responsible of the content'),
1368                    array('enable_html_filter','boolean',0,
1369                    'Enable HTML filter'),
1370                    array('enable_xmlrpc','boolean',0,
1371                    'Enable XML/RPC interface'),
1372                    array('lang','string','en',
1373                    'Default blog language'),
1374                    array('media_exclusion','string','/\.php$/i',
1375                    'File name exclusion pattern in media manager. (PCRE value)'),
1376                    array('media_img_m_size','integer',448,
1377                    'Image medium size in media manager'),
1378                    array('media_img_s_size','integer',240,
1379                    'Image small size in media manager'),
1380                    array('media_img_t_size','integer',100,
1381                    'Image thumbnail size in media manager'),
1382                    array('media_img_title_pattern','string','Title ;; Date(%b %Y) ;; separator(, )',
1383                    'Pattern to set image title when you insert it in a post'),
1384                    array('nb_post_for_home','integer',20,
1385                    'Number of entries on first home page'),
1386                    array('nb_post_per_page','integer',20,
1387                    'Number of entries on home pages and category pages'),
1388                    array('nb_post_per_feed','integer',20,
1389                    'Number of entries on feeds'),
1390                    array('nb_comment_per_feed','integer',20,
1391                    'Number of comments on feeds'),
1392                    array('post_url_format','string','{y}/{m}/{d}/{t}',
1393                    'Post URL format. {y}: year, {m}: month, {d}: day, {id}: post id, {t}: entry title'),
1394                    array('public_path','string','public',
1395                    'Path to public directory, begins with a / for a full system path'),
1396                    array('public_url','string','/public',
1397                    'URL to public directory'),
1398                    array('robots_policy','string','INDEX,FOLLOW',
1399                    'Search engines robots policy'),
1400                    array('short_feed_items','boolean',false,
1401                    'Display short feed items'),
1402                    array('theme','string','berlin',
1403                    'Blog theme'),
1404                    array('themes_path','string','themes',
1405                    'Themes root path'),
1406                    array('themes_url','string','/themes',
1407                    'Themes root URL'),
1408                    array('time_format','string','%H:%M',
1409                    'Time format. See PHP strftime function for patterns'),
1410                    array('tpl_allow_php','boolean',false,
1411                    'Allow PHP code in templates'),
1412                    array('tpl_use_cache','boolean',true,
1413                    'Use template caching'),
1414                    array('trackbacks_pub','boolean',true,
1415                    'Publish trackbacks immediately'),
1416                    array('trackbacks_ttl','integer',0,
1417                    'Number of days to keep trackbacks open (0 means no ttl)'),
1418                    array('url_scan','string','query_string',
1419                    'URL handle mode (path_info or query_string)'),
1420                    array('use_smilies','boolean',false,
1421                    'Show smilies on entries and comments'),
1422                    array('inc_subcats','boolean',false,
1423                    'Include sub-categories in category page and category posts feed'),
1424                    array('wiki_comments','boolean',false,
1425                    'Allow commenters to use a subset of wiki syntax')
1426               );
1427          }
1428
1429          $settings = new dcSettings($this,null);
1430          $settings->addNamespace('system');
1431
1432          foreach ($defaults as $v) {
1433               $settings->system->put($v[0],$v[2],$v[1],$v[3],false,true);
1434          }
1435     }
1436
1437     /**
1438     Recreates entries search engine index.
1439
1440     @param    start     <b>integer</b>      Start entry index
1441     @param    limit     <b>integer</b>      Number of entry to index
1442
1443     @return   <b>integer</b>      <var>$start</var> and <var>$limit</var> sum
1444     */
1445     public function indexAllPosts($start=null,$limit=null)
1446     {
1447          $strReq = 'SELECT COUNT(post_id) '.
1448                    'FROM '.$this->prefix.'post';
1449          $rs = $this->con->select($strReq);
1450          $count = $rs->f(0);
1451
1452          $strReq = 'SELECT post_id, post_title, post_excerpt_xhtml, post_content_xhtml '.
1453                    'FROM '.$this->prefix.'post ';
1454
1455          if ($start !== null && $limit !== null) {
1456               $strReq .= $this->con->limit($start,$limit);
1457          }
1458
1459          $rs = $this->con->select($strReq,true);
1460
1461          $cur = $this->con->openCursor($this->prefix.'post');
1462
1463          while ($rs->fetch())
1464          {
1465               $words = $rs->post_title.' '. $rs->post_excerpt_xhtml.' '.
1466               $rs->post_content_xhtml;
1467
1468               $cur->post_words = implode(' ',text::splitWords($words));
1469               $cur->update('WHERE post_id = '.(integer) $rs->post_id);
1470               $cur->clean();
1471          }
1472
1473          if ($start+$limit > $count) {
1474               return null;
1475          }
1476          return $start+$limit;
1477     }
1478
1479     /**
1480     Recreates comments search engine index.
1481
1482     @param    start     <b>integer</b>      Start comment index
1483     @param    limit     <b>integer</b>      Number of comments to index
1484
1485     @return   <b>integer</b>      <var>$start</var> and <var>$limit</var> sum
1486     */
1487     public function indexAllComments($start=null,$limit=null)
1488     {
1489          $strReq = 'SELECT COUNT(comment_id) '.
1490                    'FROM '.$this->prefix.'comment';
1491          $rs = $this->con->select($strReq);
1492          $count = $rs->f(0);
1493
1494          $strReq = 'SELECT comment_id, comment_content '.
1495                    'FROM '.$this->prefix.'comment ';
1496
1497          if ($start !== null && $limit !== null) {
1498               $strReq .= $this->con->limit($start,$limit);
1499          }
1500
1501          $rs = $this->con->select($strReq);
1502
1503          $cur = $this->con->openCursor($this->prefix.'comment');
1504
1505          while ($rs->fetch())
1506          {
1507               $cur->comment_words = implode(' ',text::splitWords($rs->comment_content));
1508               $cur->update('WHERE comment_id = '.(integer) $rs->comment_id);
1509               $cur->clean();
1510          }
1511
1512          if ($start+$limit > $count) {
1513               return null;
1514          }
1515          return $start+$limit;
1516     }
1517
1518     /**
1519     Reinits nb_comment and nb_trackback in post table.
1520     */
1521     public function countAllComments()
1522     {
1523
1524          $updCommentReq = 'UPDATE '.$this->prefix.'post P '.
1525               'SET nb_comment = ('.
1526                    'SELECT COUNT(C.comment_id) from '.$this->prefix.'comment C '.
1527                    'WHERE C.post_id = P.post_id AND C.comment_trackback <> 1 '.
1528                    'AND C.comment_status = 1 '.
1529               ')';
1530          $updTrackbackReq = 'UPDATE '.$this->prefix.'post P '.
1531               'SET nb_trackback = ('.
1532                    'SELECT COUNT(C.comment_id) from '.$this->prefix.'comment C '.
1533                    'WHERE C.post_id = P.post_id AND C.comment_trackback = 1 '.
1534                    'AND C.comment_status = 1 '.
1535               ')';
1536          $this->con->execute($updCommentReq);
1537          $this->con->execute($updTrackbackReq);
1538     }
1539
1540     /**
1541     Empty templates cache directory
1542     */
1543     public function emptyTemplatesCache()
1544     {
1545          if (is_dir(DC_TPL_CACHE.'/cbtpl')) {
1546               files::deltree(DC_TPL_CACHE.'/cbtpl');
1547          }
1548     }
1549
1550     /**
1551      Return elapsed time since script has been started
1552      @param     $mtime <b>float</b> timestamp (microtime format) to evaluate delta from
1553                                          current time is taken if null
1554      @return <b>float</b>          elapsed time
1555      */
1556     public function getElapsedTime ($mtime=null) {
1557          if ($mtime !== null) {
1558               return $mtime-$this->stime;
1559          } else {
1560               return microtime(true)-$this->stime;
1561          }
1562     }
1563     //@}
1564
1565
1566
1567}
Note: See TracBrowser for help on using the repository browser.

Sites map