Dotclear


Ignore:
Timestamp:
12/10/13 09:00:09 (12 years ago)
Author:
Dsls
Branch:
twig
Parents:
2468:d7fda5a0bd39 (diff), 2608:3365c9df16a6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with default

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.core.php

    r2313 r2609  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    4040     public $log;        ///< <b>dcLog</b>             dcLog object 
    4141     public $tpl;        ///< <b>Twig_Environment</b>  Twig_Environment object 
     42     public $stime;      ///< <b>float</b>             starting time 
    4243      
    4344     private $versions = null; 
     
    6061     public function __construct($driver, $host, $db, $user, $password, $prefix, $persist) 
    6162     { 
     63          if (defined('DC_START_TIME')) { 
     64               $this->stime=DC_START_TIME; 
     65          } else { 
     66               $this->stime = microtime(true); 
     67          } 
     68 
    6269          $this->con = dbLayer::init($driver,$host,$db,$user,$password,$persist); 
    6370           
     
    8895          $this->url = new dcUrlHandlers(); 
    8996           
    90           $this->plugins = new dcModules($this); 
     97          $this->plugins = new dcPlugins($this); 
    9198           
    9299          $this->rest = new dcRestServer($this); 
     
    10191026     private function getBlogCursor($cur) 
    10201027     { 
    1021           if ($cur->blog_id !== null 
    1022           && !preg_match('/^[A-Za-z0-9._-]{2,}$/',$cur->blog_id)) { 
     1028          if (($cur->blog_id !== null 
     1029               && !preg_match('/^[A-Za-z0-9._-]{2,}$/',$cur->blog_id)) || 
     1030               (!$cur->blog_id)) { 
    10231031               throw new Exception(__('Blog ID must contain at least 2 characters using letters, numbers or symbols.'));  
    10241032          } 
    10251033           
    1026           if ($cur->blog_name !== null && $cur->blog_name == '') { 
     1034          if (($cur->blog_name !== null && $cur->blog_name == '') || 
     1035               (!$cur->blog_name)) { 
    10271036               throw new Exception(__('No blog name')); 
    10281037          } 
    10291038           
    1030           if ($cur->blog_url !== null && $cur->blog_url == '') { 
     1039          if (($cur->blog_url !== null && $cur->blog_url == '') || 
     1040               (!$cur->blog_url)) { 
    10311041               throw new Exception(__('No blog URL')); 
    10321042          } 
     
    13431353                    array('media_img_title_pattern','string','Title ;; Date(%b %Y) ;; separator(, )', 
    13441354                    'Pattern to set image title when you insert it in a post'), 
     1355                    array('nb_post_for_home','integer',20, 
     1356                    'Number of entries on first home page'), 
    13451357                    array('nb_post_per_page','integer',20, 
    1346                     'Number of entries on home page and category pages'), 
     1358                    'Number of entries on home pages and category pages'), 
    13471359                    array('nb_post_per_feed','integer',20, 
    13481360                    'Number of entries on feeds'), 
     
    15061518          } 
    15071519     } 
     1520 
     1521     /** 
     1522      Return elapsed time since script has been started 
     1523      @param   $mtime <b>float</b> timestamp (microtime format) to evaluate delta from 
     1524                                     current time is taken if null 
     1525      @return <b>float</b>        elapsed time 
     1526      */ 
     1527     public function getElapsedTime ($mtime=null) { 
     1528          if ($mtime !== null) { 
     1529               return $mtime-$this->stime; 
     1530          } else { 
     1531               return microtime(true)-$this->stime; 
     1532          } 
     1533     } 
    15081534     //@} 
     1535 
     1536 
     1537 
    15091538} 
    1510 ?> 
  • inc/core/class.dc.core.php

    r2596 r2609  
    3939     public $rest;       ///< <b>dcRestServer</b> dcRestServer object 
    4040     public $log;        ///< <b>dcLog</b>             dcLog object 
     41     public $tpl;        ///< <b>Twig_Environment</b>  Twig_Environment object 
    4142     public $stime;      ///< <b>float</b>             starting time 
    42  
     43      
    4344     private $versions = null; 
    4445     private $formaters = array(); 
    4546     private $behaviors = array(); 
    4647     private $post_types = array(); 
    47  
     48      
    4849     /** 
    4950     dcCore constructor inits everything related to Dotclear. It takes arguments 
    5051     to init database connection. 
    51  
     52      
    5253     @param    driver    <b>string</b>  Database driver name 
    5354     @param    host      <b>string</b>  Database hostname 
     
    6768 
    6869          $this->con = dbLayer::init($driver,$host,$db,$user,$password,$persist); 
    69  
     70           
    7071          # define weak_locks for mysql 
    7172          if ($this->con instanceof mysqlConnection) { 
     
    7475               mysqliConnection::$weak_locks = true; 
    7576          } 
    76  
     77           
    7778          # define searchpath for postgresql 
    7879          if ($this->con instanceof pgsqlConnection) 
     
    8687               } 
    8788          } 
    88  
     89           
    8990          $this->prefix = $prefix; 
    90  
     91           
    9192          $this->error = new dcError(); 
    9293          $this->auth = $this->authInstance(); 
    9394          $this->session = new sessionDB($this->con,$this->prefix.'session',DC_SESSION_NAME,'',null,DC_ADMIN_SSL); 
    9495          $this->url = new dcUrlHandlers(); 
    95  
     96           
    9697          $this->plugins = new dcPlugins($this); 
    97  
     98           
    9899          $this->rest = new dcRestServer($this); 
    99  
     100           
    100101          $this->meta = new dcMeta($this); 
    101  
     102           
    102103          $this->log = new dcLog($this); 
    103  
     104           
    104105          $this->addFormater('xhtml', create_function('$s','return $s;')); 
    105106          $this->addFormater('wiki', array($this,'wikiTransform')); 
    106      } 
    107  
     107          $this->loadTemplateEnvironment(); 
     108     } 
     109      
    108110     private function authInstance() 
    109111     { 
     
    115117               $c = DC_AUTH_CLASS; 
    116118          } 
    117  
     119           
    118120          if (!class_exists($c)) { 
    119121               throw new Exception('Authentication class '.$c.' does not exist.'); 
    120122          } 
    121  
     123           
    122124          if ($c != 'dcAuth' && !is_subclass_of($c,'dcAuth')) { 
    123125               throw new Exception('Authentication class '.$c.' does not inherit dcAuth.'); 
    124126          } 
    125  
     127           
    126128          return new $c($this); 
    127129     } 
    128  
    129  
     130      
     131     /** 
     132     Create template environment (Twig_Environment instance) 
     133      
     134     default-templates path must be added from admin|public/prepend.php with: 
     135     $core->tpl->getLoader()->addPath('PATH_TO/default-templates'); 
     136     Selected theme path must be added with: 
     137     $core->tpl->getLoader()->prependPath('PATH_TO/MY_THEME'); 
     138     */ 
     139     public function loadTemplateEnvironment() 
     140     { 
     141          $cache_dir = path::real(DC_TPL_CACHE.'/twtpl',false); 
     142          if (!is_dir($cache_dir)) { 
     143               try { 
     144                    files::makeDir($cache_dir); 
     145               } catch (Exception $e) { 
     146                    $cache_dir = false; 
     147               } 
     148          } 
     149           
     150          $this->tpl = new Twig_Environment( 
     151               new Twig_Loader_Filesystem(dirname(__FILE__).'/../swf'), 
     152               array( 
     153                    'auto_reload' => true, 
     154                    'autoescape' => false, 
     155                    'base_template_class' => 'Twig_Template', 
     156                    'cache' => $cache_dir,  
     157                    'charset' => 'UTF-8', 
     158                    'debug' => DC_DEBUG, 
     159                    'optimizations' => -1, 
     160                    'strict_variables' => 0 //DC_DEBUG // Please fix undefined variables! 
     161               ) 
     162          ); 
     163          $this->tpl->addExtension(new dcFormExtension($this)); 
     164          $this->tpl->addExtension(new dcTabExtension($this)); 
     165     } 
     166      
    130167     /// @name Blog init methods 
    131168     //@{ 
    132169     /** 
    133170     Sets a blog to use in <var>blog</var> property. 
    134  
     171      
    135172     @param    id        <b>string</b>       Blog ID 
    136173     */ 
     
    139176          $this->blog = new dcBlog($this, $id); 
    140177     } 
    141  
     178      
    142179     /** 
    143180     Unsets <var>blog</var> property. 
     
    148185     } 
    149186     //@} 
    150  
    151  
     187      
     188      
    152189     /// @name Blog status methods 
    153190     //@{ 
    154191     /** 
    155192     Returns an array of available blog status codes and names. 
    156  
     193      
    157194     @return   <b>array</b> Simple array with codes in keys and names in value 
    158195     */ 
     
    165202          ); 
    166203     } 
    167  
     204      
    168205     /** 
    169206     Returns a blog status name given to a code. This is intended to be 
    170207     human-readable and will be translated, so never use it for tests. 
    171208     If status code does not exist, returns <i>offline</i>. 
    172  
     209      
    173210     @param    s    <b>integer</b> Status code 
    174211     @return   <b>string</b> Blog status name 
     
    183220     } 
    184221     //@} 
    185  
     222      
    186223     /// @name Admin nonce secret methods 
    187224     //@{ 
    188  
     225      
    189226     public function getNonce() 
    190227     { 
    191228          return crypt::hmac(DC_MASTER_KEY,session_id()); 
    192229     } 
    193  
     230      
    194231     public function checkNonce($secret) 
    195232     { 
     
    197234               return false; 
    198235          } 
    199  
     236           
    200237          return $secret == crypt::hmac(DC_MASTER_KEY,session_id()); 
    201238     } 
    202  
     239      
    203240     public function formNonce() 
    204241     { 
     
    206243               return; 
    207244          } 
    208  
     245           
    209246          return form::hidden(array('xd_check'),$this->getNonce()); 
    210247     } 
    211248     //@} 
    212  
    213  
     249      
     250      
    214251     /// @name Text Formatters methods 
    215252     //@{ 
     
    218255     transform text. The function must be a valid callback and takes one 
    219256     argument: the string to transform. It returns the transformed string. 
    220  
     257      
    221258     @param    name      <b>string</b>       Formater name 
    222259     @param    func      <b>callback</b>     Function to use, must be a valid and callable callback 
     
    228265          } 
    229266     } 
    230  
     267      
    231268     /** 
    232269     Returns formaters list. 
    233  
     270      
    234271     @return   <b>array</b> An array of formaters names in values. 
    235272     */ 
     
    238275          return array_keys($this->formaters); 
    239276     } 
    240  
     277      
    241278     /** 
    242279     If <var>$name</var> is a valid formater, it returns <var>$str</var> 
    243280     transformed using that formater. 
    244  
     281      
    245282     @param    name      <b>string</b>       Formater name 
    246283     @param    str       <b>string</b>       String to transform 
     
    252289               return call_user_func($this->formaters[$name],$str); 
    253290          } 
    254  
     291           
    255292          return $str; 
    256293     } 
    257294     //@} 
    258  
    259  
     295      
     296      
    260297     /// @name Behaviors methods 
    261298     //@{ 
     
    263300     Adds a new behavior to behaviors stack. <var>$func</var> must be a valid 
    264301     and callable callback. 
    265  
     302      
    266303     @param    behavior  <b>string</b>       Behavior name 
    267304     @param    func      <b>callback</b>     Function to call 
     
    273310          } 
    274311     } 
    275  
     312      
    276313     /** 
    277314     Tests if a particular behavior exists in behaviors stack. 
    278  
     315      
    279316     @param    behavior  <b>string</b>  Behavior name 
    280317     @return   <b>boolean</b> 
     
    284321          return isset($this->behaviors[$behavior]); 
    285322     } 
    286  
     323      
    287324     /** 
    288325     Get behaviors stack (or part of). 
    289  
     326      
    290327     @param    behavior  <b>string</b>       Behavior name 
    291328     @return   <b>array</b> 
     
    294331     { 
    295332          if (empty($this->behaviors)) return null; 
    296  
     333           
    297334          if ($behavior == '') { 
    298335               return $this->behaviors; 
     
    300337               return $this->behaviors[$behavior]; 
    301338          } 
    302  
     339           
    303340          return array(); 
    304341     } 
    305  
     342      
    306343     /** 
    307344     Calls every function in behaviors stack for a given behavior and returns 
    308345     concatened result of each function. 
    309  
     346      
    310347     Every parameters added after <var>$behavior</var> will be pass to 
    311348     behavior calls. 
    312  
     349      
    313350     @param    behavior  <b>string</b>  Behavior name 
    314351     @return   <b>string</b> Behavior concatened result 
     
    320357               $args = func_get_args(); 
    321358               array_shift($args); 
    322  
     359                
    323360               $res = ''; 
    324  
     361                
    325362               foreach ($this->behaviors[$behavior] as $f) { 
    326363                    $res .= call_user_func_array($f,$args); 
    327364               } 
    328  
     365                
    329366               return $res; 
    330367          } 
    331368     } 
    332369     //@} 
    333  
     370      
    334371     /// @name Post types URLs management 
    335372     //@{ 
     
    339376               $type = 'post'; 
    340377          } 
    341  
     378           
    342379          $url = sprintf($this->post_types[$type]['admin_url'],$post_id); 
    343380          return $escaped ? html::escapeURL($url) : $url; 
    344381     } 
    345  
     382      
    346383     public function getPostPublicURL($type,$post_url,$escaped=true) 
    347384     { 
     
    349386               $type = 'post'; 
    350387          } 
    351  
     388           
    352389          $url = sprintf($this->post_types[$type]['public_url'],$post_url); 
    353390          return $escaped ? html::escapeURL($url) : $url; 
    354391     } 
    355  
     392      
    356393     public function setPostType($type,$admin_url,$public_url,$label='') 
    357394     { 
     
    362399          ); 
    363400     } 
    364  
     401      
    365402     public function getPostTypes() 
    366403     { 
     
    368405     } 
    369406     //@} 
    370  
     407      
    371408     /// @name Versions management methods 
    372409     //@{ 
    373410     /** 
    374411     Returns a given $module version. 
    375  
     412      
    376413     @param    module    <b>string</b>  Module name 
    377414     @return   <b>string</b>  Module version 
     
    384421               $strReq = 'SELECT module, version FROM '.$this->prefix.'version'; 
    385422               $rs = $this->con->select($strReq); 
    386  
     423                
    387424               while ($rs->fetch()) { 
    388425                    $this->versions[$rs->module] = $rs->version; 
    389426               } 
    390427          } 
    391  
     428           
    392429          if (isset($this->versions[$module])) { 
    393430               return $this->versions[$module]; 
     
    396433          } 
    397434     } 
    398  
     435      
    399436     /** 
    400437     Sets $version to given $module. 
    401  
     438      
    402439     @param    module    <b>string</b>  Module name 
    403440     @param    version   <b>string</b>  Module version 
     
    406443     { 
    407444          $cur_version = $this->getVersion($module); 
    408  
     445           
    409446          $cur = $this->con->openCursor($this->prefix.'version'); 
    410447          $cur->module = (string) $module; 
    411448          $cur->version = (string) $version; 
    412  
     449           
    413450          if ($cur_version === null) { 
    414451               $cur->insert(); 
     
    416453               $cur->update("WHERE module='".$this->con->escape($module)."'"); 
    417454          } 
    418  
     455           
    419456          $this->versions[$module] = $version; 
    420457     } 
    421  
     458      
    422459     /** 
    423460     Removes given $module version entry. 
    424  
     461      
    425462     @param    module    <b>string</b>  Module name 
    426463     */ 
     
    430467          'DELETE FROM '.$this->prefix.'version '. 
    431468          "WHERE module = '".$this->con->escape($module)."' "; 
    432  
     469           
    433470          $this->con->execute($strReq); 
    434  
     471           
    435472          if (is_array($this->versions)) { 
    436473               unset($this->versions[$module]); 
    437474          } 
    438475     } 
    439  
     476      
    440477     //@} 
    441  
     478      
    442479     /// @name Users management methods 
    443480     //@{ 
    444481     /** 
    445482     Returns a user by its ID. 
    446  
     483      
    447484     @param    id        <b>string</b>       User ID 
    448485     @return   <b>record</b> 
     
    451488     { 
    452489          $params['user_id'] = $id; 
    453  
     490           
    454491          return $this->getUsers($params); 
    455492     } 
    456  
     493      
    457494     /** 
    458495     Returns a users list. <b>$params</b> is an array with the following 
    459496     optionnal parameters: 
    460  
     497      
    461498      - <var>q</var>: search string (on user_id, user_name, user_firstname) 
    462499      - <var>user_id</var>: user ID 
    463500      - <var>order</var>: ORDER BY clause (default: user_id ASC) 
    464501      - <var>limit</var>: LIMIT clause (should be an array ![limit,offset]) 
    465  
     502      
    466503     @param    params         <b>array</b>        Parameters 
    467504     @param    count_only     <b>boolean</b>      Only counts results 
     
    488525               'WHERE NULL IS NULL '; 
    489526          } 
    490  
     527           
    491528          if (!empty($params['q'])) { 
    492529               $q = $this->con->escape(str_replace('*','%',strtolower($params['q']))); 
     
    497534                    ') '; 
    498535          } 
    499  
     536           
    500537          if (!empty($params['user_id'])) { 
    501538               $strReq .= "AND U.user_id = '".$this->con->escape($params['user_id'])."' "; 
    502539          } 
    503  
     540           
    504541          if (!$count_only) { 
    505542               $strReq .= 'GROUP BY U.user_id,user_super,user_status,user_pwd,user_change_pwd,'. 
    506543               'user_name,user_firstname,user_displayname,user_email,user_url,'. 
    507544               'user_desc, user_lang,user_tz,user_post_status,user_options '; 
    508  
     545                
    509546               if (!empty($params['order']) && !$count_only) { 
    510547                    $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; 
     
    513550               } 
    514551          } 
    515  
     552           
    516553          if (!$count_only && !empty($params['limit'])) { 
    517554               $strReq .= $this->con->limit($params['limit']); 
    518555          } 
    519  
     556           
    520557          $rs = $this->con->select($strReq); 
    521558          $rs->extend('rsExtUser'); 
    522559          return $rs; 
    523560     } 
    524  
     561      
    525562     /** 
    526563     Create a new user. Takes a cursor as input and returns the new user ID. 
    527  
     564      
    528565     @param    cur       <b>cursor</b>       User cursor 
    529566     @return   <b>string</b> 
     
    534571               throw new Exception(__('You are not an administrator')); 
    535572          } 
    536  
     573           
    537574          if ($cur->user_id == '') { 
    538575               throw new Exception(__('No user ID given')); 
    539576          } 
    540  
     577           
    541578          if ($cur->user_pwd == '') { 
    542579               throw new Exception(__('No password given')); 
    543580          } 
    544  
     581           
    545582          $this->getUserCursor($cur); 
    546  
     583           
    547584          if ($cur->user_creadt === null) { 
    548585               $cur->user_creadt = date('Y-m-d H:i:s'); 
    549586          } 
    550  
     587           
    551588          $cur->insert(); 
    552  
     589           
    553590          $this->auth->afterAddUser($cur); 
    554  
     591           
    555592          return $cur->user_id; 
    556593     } 
    557  
     594      
    558595     /** 
    559596     Updates an existing user. Returns the user ID. 
    560  
     597      
    561598     @param    id        <b>string</b>       User ID 
    562599     @param    cur       <b>cursor</b>       User cursor 
     
    566603     { 
    567604          $this->getUserCursor($cur); 
    568  
     605           
    569606          if (($cur->user_id !== null || $id != $this->auth->userID()) && 
    570607          !$this->auth->isSuperAdmin()) { 
    571608               throw new Exception(__('You are not an administrator')); 
    572609          } 
    573  
     610           
    574611          $cur->update("WHERE user_id = '".$this->con->escape($id)."' "); 
    575  
     612           
    576613          $this->auth->afterUpdUser($id,$cur); 
    577  
     614           
    578615          if ($cur->user_id !== null) { 
    579616               $id = $cur->user_id; 
    580617          } 
    581  
     618           
    582619          # Updating all user's blogs 
    583620          $rs = $this->con->select( 
     
    585622               "WHERE user_id = '".$this->con->escape($id)."' " 
    586623               ); 
    587  
     624           
    588625          while ($rs->fetch()) { 
    589626               $b = new dcBlog($this,$rs->blog_id); 
     
    591628               unset($b); 
    592629          } 
    593  
     630           
    594631          return $id; 
    595632     } 
    596  
     633      
    597634     /** 
    598635     Deletes a user. 
    599  
     636      
    600637     @param    id        <b>string</b>       User ID 
    601638     */ 
     
    605642               throw new Exception(__('You are not an administrator')); 
    606643          } 
    607  
     644           
    608645          if ($id == $this->auth->userID()) { 
    609646               return; 
    610647          } 
    611  
     648           
    612649          $rs = $this->getUser($id); 
    613  
     650           
    614651          if ($rs->nb_post > 0) { 
    615652               return; 
    616653          } 
    617  
     654           
    618655          $strReq = 'DELETE FROM '.$this->prefix.'user '. 
    619656                    "WHERE user_id = '".$this->con->escape($id)."' "; 
    620  
     657           
    621658          $this->con->execute($strReq); 
    622  
     659           
    623660          $this->auth->afterDelUser($id); 
    624661     } 
    625  
     662      
    626663     /** 
    627664     Checks whether a user exists. 
    628  
     665      
    629666     @param    id        <b>string</b>       User ID 
    630667     @return   <b>boolean</b> 
     
    635672                    'FROM '.$this->prefix.'user '. 
    636673                    "WHERE user_id = '".$this->con->escape($id)."' "; 
    637  
     674           
    638675          $rs = $this->con->select($strReq); 
    639  
     676           
    640677          return !$rs->isEmpty(); 
    641678     } 
    642  
     679      
    643680     /** 
    644681     Returns all user permissions as an array which looks like: 
    645  
     682      
    646683      - [blog_id] 
    647684        - [name] => Blog name 
     
    650687          - [permission] => true 
    651688          - ... 
    652  
     689      
    653690     @param    id        <b>string</b>       User ID 
    654691     @return   <b>array</b> 
     
    660697                    'INNER JOIN '.$this->prefix.'blog B ON P.blog_id = B.blog_id '. 
    661698                    "WHERE user_id = '".$this->con->escape($id)."' "; 
    662  
     699           
    663700          $rs = $this->con->select($strReq); 
    664  
     701           
    665702          $res = array(); 
    666  
     703           
    667704          while ($rs->fetch()) 
    668705          { 
     
    673710               ); 
    674711          } 
    675  
     712           
    676713          return $res; 
    677714     } 
    678  
     715      
    679716     /** 
    680717     Sets user permissions. The <var>$perms</var> array looks like: 
    681  
     718      
    682719      - [blog_id] => '|perm1|perm2|' 
    683720      - ... 
    684  
     721      
    685722     @param    id        <b>string</b>       User ID 
    686723     @param    perms     <b>array</b>        Permissions array 
     
    691728               throw new Exception(__('You are not an administrator')); 
    692729          } 
    693  
     730           
    694731          $strReq = 'DELETE FROM '.$this->prefix.'permissions '. 
    695732                    "WHERE user_id = '".$this->con->escape($id)."' "; 
    696  
     733           
    697734          $this->con->execute($strReq); 
    698  
     735           
    699736          foreach ($perms as $blog_id => $p) { 
    700737               $this->setUserBlogPermissions($id, $blog_id, $p, false); 
    701738          } 
    702739     } 
    703  
     740      
    704741     /** 
    705742     Sets user permissions for a given blog. <var>$perms</var> is an array with 
    706743     permissions in values 
    707  
     744      
    708745     @param    id             <b>string</b>       User ID 
    709746     @param    blog_id        <b>string</b>       Blog ID 
     
    716753               throw new Exception(__('You are not an administrator')); 
    717754          } 
    718  
     755           
    719756          $no_perm = empty($perms); 
    720  
     757           
    721758          $perms = '|'.implode('|',array_keys($perms)).'|'; 
    722  
     759           
    723760          $cur = $this->con->openCursor($this->prefix.'permissions'); 
    724  
     761           
    725762          $cur->user_id = (string) $id; 
    726763          $cur->blog_id = (string) $blog_id; 
    727764          $cur->permissions = $perms; 
    728  
     765           
    729766          if ($delete_first || $no_perm) 
    730767          { 
     
    732769                         "WHERE blog_id = '".$this->con->escape($blog_id)."' ". 
    733770                         "AND user_id = '".$this->con->escape($id)."' "; 
    734  
     771                
    735772               $this->con->execute($strReq); 
    736773          } 
    737  
     774           
    738775          if (!$no_perm) { 
    739776               $cur->insert(); 
    740777          } 
    741778     } 
    742  
     779      
    743780     /** 
    744781     Sets a user default blog. This blog will be selected when user log in. 
    745  
     782      
    746783     @param    id             <b>string</b>       User ID 
    747784     @param    blog_id        <b>string</b>       Blog ID 
     
    750787     { 
    751788          $cur = $this->con->openCursor($this->prefix.'user'); 
    752  
     789           
    753790          $cur->user_default_blog = (string) $blog_id; 
    754  
     791           
    755792          $cur->update("WHERE user_id = '".$this->con->escape($id)."'"); 
    756793     } 
    757  
     794      
    758795     private function getUserCursor($cur) 
    759796     { 
     
    762799               throw new Exception(__('User ID must contain at least 2 characters using letters, numbers or symbols.')); 
    763800          } 
    764  
     801           
    765802          if ($cur->user_url !== null && $cur->user_url != '') { 
    766803               if (!preg_match('|^http(s?)://|',$cur->user_url)) { 
     
    768805               } 
    769806          } 
    770  
     807           
    771808          if ($cur->isField('user_pwd')) { 
    772809               if (strlen($cur->user_pwd) < 6) { 
     
    775812               $cur->user_pwd = crypt::hmac(DC_MASTER_KEY,$cur->user_pwd); 
    776813          } 
    777  
     814           
    778815          if ($cur->user_lang !== null && !preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$cur->user_lang)) { 
    779816               throw new Exception(__('Invalid user language code')); 
    780817          } 
    781  
     818           
    782819          if ($cur->user_upddt === null) { 
    783820               $cur->user_upddt = date('Y-m-d H:i:s'); 
    784821          } 
    785  
     822           
    786823          if ($cur->user_options !== null) { 
    787824               $cur->user_options = serialize((array) $cur->user_options); 
    788825          } 
    789826     } 
    790  
     827      
    791828     /** 
    792829     Returns user default settings in an associative array with setting names in 
    793830     keys. 
    794  
     831      
    795832     @return   <b>array</b> 
    796833     */ 
     
    804841     } 
    805842     //@} 
    806  
     843      
    807844     /// @name Blog management methods 
    808845     //@{ 
    809846     /** 
    810847     Returns all blog permissions (users) as an array which looks like: 
    811  
     848      
    812849      - [user_id] 
    813850        - [name] => User name 
     
    818855          - [permission] => true 
    819856          - ... 
    820  
     857      
    821858     @param    id             <b>string</b>       Blog ID 
    822859     @param    with_super     <b>boolean</b>      Includes super admins in result 
     
    831868          'JOIN '.$this->prefix.'permissions P ON U.user_id = P.user_id '. 
    832869          "WHERE blog_id = '".$this->con->escape($id)."' "; 
    833  
     870           
    834871          if ($with_super) { 
    835872               $strReq .= 
     
    840877               'WHERE user_super = 1 '; 
    841878          } 
    842  
     879           
    843880          $rs = $this->con->select($strReq); 
    844  
     881           
    845882          $res = array(); 
    846  
     883           
    847884          while ($rs->fetch()) 
    848885          { 
     
    856893               ); 
    857894          } 
    858  
     895           
    859896          return $res; 
    860897     } 
    861  
     898      
    862899     /** 
    863900     Returns a blog of given ID. 
    864  
     901      
    865902     @param    id        <b>string</b>       Blog ID 
    866903     @return   <b>record</b> 
     
    869906     { 
    870907          $blog = $this->getBlogs(array('blog_id'=>$id)); 
    871  
     908           
    872909          if ($blog->isEmpty()) { 
    873910               return false; 
    874911          } 
    875  
     912           
    876913          return $blog; 
    877914     } 
    878  
     915      
    879916     /** 
    880917     Returns a record of blogs. <b>$params</b> is an array with the following 
    881918     optionnal parameters: 
    882  
     919      
    883920      - <var>blog_id</var>: Blog ID 
    884921      - <var>q</var>: Search string on blog_id, blog_name and blog_url 
    885922      - <var>limit</var>: limit results 
    886  
     923      
    887924     @param    params         <b>array</b>        Parameters 
    888925     @param    count_only     <b>boolean</b>      Count only results 
     
    893930          $join = '';    // %1$s 
    894931          $where = '';   // %2$s 
    895  
     932           
    896933          if ($count_only) 
    897934          { 
     
    911948               'WHERE NULL IS NULL '. 
    912949               '%2$s '; 
    913  
     950                
    914951               if (!empty($params['order'])) { 
    915952                    $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; 
     
    917954                    $strReq .= 'ORDER BY B.blog_id ASC '; 
    918955               } 
    919  
     956                
    920957               if (!empty($params['limit'])) { 
    921958                    $strReq .= $this->con->limit($params['limit']); 
    922959               } 
    923960          } 
    924  
     961           
    925962          if ($this->auth->userID() && !$this->auth->isSuperAdmin()) 
    926963          { 
     
    933970               $where = 'AND blog_status IN (1,0) '; 
    934971          } 
    935  
     972           
    936973          if (!empty($params['blog_id'])) { 
    937974               $where .= "AND B.blog_id = '".$this->con->escape($params['blog_id'])."' "; 
    938975          } 
    939  
     976           
    940977          if (!empty($params['q'])) { 
    941978               $params['q'] = strtolower(str_replace('*','%',$params['q'])); 
     
    947984               ') '; 
    948985          } 
    949  
     986           
    950987          $strReq = sprintf($strReq,$join,$where); 
    951988          return $this->con->select($strReq); 
    952989     } 
    953  
     990      
    954991     /** 
    955992     Creates a new blog. 
    956  
     993      
    957994     @param    cur            <b>cursor</b>       Blog cursor 
    958995     */ 
     
    962999               throw new Exception(__('You are not an administrator')); 
    9631000          } 
    964  
     1001           
    9651002          $this->getBlogCursor($cur); 
    966  
     1003           
    9671004          $cur->blog_creadt = date('Y-m-d H:i:s'); 
    9681005          $cur->blog_upddt = date('Y-m-d H:i:s'); 
    9691006          $cur->blog_uid = md5(uniqid()); 
    970  
     1007           
    9711008          $cur->insert(); 
    9721009     } 
    973  
     1010      
    9741011     /** 
    9751012     Updates a given blog. 
    976  
     1013      
    9771014     @param    id        <b>string</b>       Blog ID 
    9781015     @param    cur       <b>cursor</b>       Blog cursor 
     
    9811018     { 
    9821019          $this->getBlogCursor($cur); 
    983  
     1020           
    9841021          $cur->blog_upddt = date('Y-m-d H:i:s'); 
    985  
     1022           
    9861023          $cur->update("WHERE blog_id = '".$this->con->escape($id)."'"); 
    9871024     } 
    988  
     1025      
    9891026     private function getBlogCursor($cur) 
    9901027     { 
     
    9921029               && !preg_match('/^[A-Za-z0-9._-]{2,}$/',$cur->blog_id)) || 
    9931030               (!$cur->blog_id)) { 
    994                throw new Exception(__('Blog ID must contain at least 2 characters using letters, numbers or symbols.')); 
    995           } 
    996  
     1031               throw new Exception(__('Blog ID must contain at least 2 characters using letters, numbers or symbols.'));  
     1032          } 
     1033           
    9971034          if (($cur->blog_name !== null && $cur->blog_name == '') || 
    9981035               (!$cur->blog_name)) { 
    9991036               throw new Exception(__('No blog name')); 
    10001037          } 
    1001  
     1038           
    10021039          if (($cur->blog_url !== null && $cur->blog_url == '') || 
    10031040               (!$cur->blog_url)) { 
    10041041               throw new Exception(__('No blog URL')); 
    10051042          } 
    1006  
     1043           
    10071044          if ($cur->blog_desc !== null) { 
    10081045               $cur->blog_desc = html::clean($cur->blog_desc); 
    10091046          } 
    10101047     } 
    1011  
     1048      
    10121049     /** 
    10131050     Removes a given blog. 
    10141051     @warning This will remove everything related to the blog (posts, 
    10151052     categories, comments, links...) 
    1016  
     1053      
    10171054     @param    id        <b>string</b>       Blog ID 
    10181055     */ 
     
    10221059               throw new Exception(__('You are not an administrator')); 
    10231060          } 
    1024  
     1061           
    10251062          $strReq = 'DELETE FROM '.$this->prefix.'blog '. 
    10261063                    "WHERE blog_id = '".$this->con->escape($id)."' "; 
    1027  
     1064           
    10281065          $this->con->execute($strReq); 
    10291066     } 
    1030  
     1067      
    10311068     /** 
    10321069     Checks if a blog exist. 
    1033  
     1070      
    10341071     @param    id        <b>string</b>       Blog ID 
    10351072     @return   <b>boolean</b> 
     
    10401077                    'FROM '.$this->prefix.'blog '. 
    10411078                    "WHERE blog_id = '".$this->con->escape($id)."' "; 
    1042  
     1079           
    10431080          $rs = $this->con->select($strReq); 
    1044  
     1081           
    10451082          return !$rs->isEmpty(); 
    10461083     } 
    1047  
     1084      
    10481085     /** 
    10491086     Count posts on a blog 
    1050  
     1087      
    10511088     @param    id        <b>string</b>       Blog ID 
    10521089     @param    type      <b>string</b>       Post type 
     
    10581095                    'FROM '.$this->prefix.'post '. 
    10591096                    "WHERE blog_id = '".$this->con->escape($id)."' "; 
    1060  
     1097           
    10611098          if ($type) { 
    10621099               $strReq .= "AND post_type = '".$this->con->escape($type)."' "; 
    10631100          } 
    1064  
     1101           
    10651102          return $this->con->select($strReq)->f(0); 
    10661103     } 
    10671104     //@} 
    1068  
     1105      
    10691106     /// @name HTML Filter methods 
    10701107     //@{ 
     
    10731110     tidy extension is present). If <b>enable_html_filter</b> blog setting is 
    10741111     false, returns not filtered string. 
    1075  
     1112      
    10761113     @param    str  <b>string</b>       String to filter 
    10771114     @return   <b>string</b> Filtered string. 
     
    10821119               return $str; 
    10831120          } 
    1084  
     1121           
    10851122          $filter = new htmlFilter; 
    10861123          $str = trim($filter->apply($str)); 
     
    10881125     } 
    10891126     //@} 
    1090  
     1127      
    10911128     /// @name wiki2xhtml methods 
    10921129     //@{ 
     
    10951132          $this->wiki2xhtml = new wiki2xhtml; 
    10961133     } 
    1097  
     1134      
    10981135     /** 
    10991136     Returns a transformed string with wiki2xhtml. 
    1100  
     1137      
    11011138     @param    str       <b>string</b>       String to transform 
    11021139     @return   <b>string</b>  Transformed string 
     
    11091146          return $this->wiki2xhtml->transform($str); 
    11101147     } 
    1111  
     1148      
    11121149     /** 
    11131150     Inits <var>wiki2xhtml</var> property for blog post. 
     
    11161153     { 
    11171154          $this->initWiki(); 
    1118  
     1155           
    11191156          $this->wiki2xhtml->setOpts(array( 
    11201157               'active_title' => 1, 
     
    11481185               'note_str' => '<div class="footnotes"><h4>Notes</h4>%s</div>' 
    11491186          )); 
    1150  
     1187           
    11511188          $this->wiki2xhtml->registerFunction('url:post',array($this,'wikiPostLink')); 
    1152  
     1189           
    11531190          # --BEHAVIOR-- coreWikiPostInit 
    11541191          $this->callBehavior('coreInitWikiPost',$this->wiki2xhtml); 
    11551192     } 
    1156  
     1193      
    11571194     /** 
    11581195     Inits <var>wiki2xhtml</var> property for simple blog comment (basic syntax). 
     
    11611198     { 
    11621199          $this->initWiki(); 
    1163  
     1200           
    11641201          $this->wiki2xhtml->setOpts(array( 
    11651202               'active_title' => 0, 
     
    11901227               'active_fr_syntax' => 0 
    11911228          )); 
    1192  
     1229           
    11931230          # --BEHAVIOR-- coreInitWikiSimpleComment 
    11941231          $this->callBehavior('coreInitWikiSimpleComment',$this->wiki2xhtml); 
    11951232     } 
    1196  
     1233      
    11971234     /** 
    11981235     Inits <var>wiki2xhtml</var> property for blog comment. 
     
    12011238     { 
    12021239          $this->initWiki(); 
    1203  
     1240           
    12041241          $this->wiki2xhtml->setOpts(array( 
    12051242               'active_title' => 0, 
     
    12301267               'active_fr_syntax' => 0 
    12311268          )); 
    1232  
     1269           
    12331270          # --BEHAVIOR-- coreInitWikiComment 
    12341271          $this->callBehavior('coreInitWikiComment',$this->wiki2xhtml); 
    12351272     } 
    1236  
     1273      
    12371274     public function wikiPostLink($url,$content) 
    12381275     { 
    1239           if (!($this->blog instanceof dcBlog)) { 
     1276          if (!($this->blog instanceof dcBlog)) {  
    12401277               return array(); 
    12411278          } 
    1242  
     1279           
    12431280          $post_id = abs((integer) substr($url,5)); 
    12441281          if (!$post_id) { 
    12451282               return array(); 
    12461283          } 
    1247  
     1284           
    12481285          $post = $this->blog->getPosts(array('post_id'=>$post_id)); 
    12491286          if ($post->isEmpty()) { 
    12501287               return array(); 
    12511288          } 
    1252  
     1289           
    12531290          $res = array('url' => $post->getURL()); 
    12541291          $post_title = $post->post_title; 
    1255  
     1292           
    12561293          if ($content != $url) { 
    12571294               $res['title'] = html::escapeHTML($post->post_title); 
    12581295          } 
    1259  
     1296           
    12601297          if ($content == '' || $content == $url) { 
    12611298               $res['content'] = html::escapeHTML($post->post_title); 
    12621299          } 
    1263  
     1300           
    12641301          if ($post->post_lang) { 
    12651302               $res['lang'] = $post->post_lang; 
    12661303          } 
    1267  
     1304           
    12681305          return $res; 
    12691306     } 
    12701307     //@} 
    1271  
     1308      
    12721309     /// @name Maintenance methods 
    12731310     //@{ 
     
    12751312     Creates default settings for active blog. Optionnal parameter 
    12761313     <var>defaults</var> replaces default params while needed. 
    1277  
     1314      
    12781315     @param    defaults       <b>array</b>   Default parameters 
    12791316     */ 
     
    13601397               ); 
    13611398          } 
    1362  
     1399           
    13631400          $settings = new dcSettings($this,null); 
    13641401          $settings->addNamespace('system'); 
    1365  
     1402           
    13661403          foreach ($defaults as $v) { 
    13671404               $settings->system->put($v[0],$v[2],$v[1],$v[3],false,true); 
    13681405          } 
    13691406     } 
    1370  
     1407      
    13711408     /** 
    13721409     Recreates entries search engine index. 
    1373  
     1410      
    13741411     @param    start     <b>integer</b>      Start entry index 
    13751412     @param    limit     <b>integer</b>      Number of entry to index 
    1376  
     1413      
    13771414     @return   <b>integer</b>      <var>$start</var> and <var>$limit</var> sum 
    13781415     */ 
     
    13831420          $rs = $this->con->select($strReq); 
    13841421          $count = $rs->f(0); 
    1385  
     1422           
    13861423          $strReq = 'SELECT post_id, post_title, post_excerpt_xhtml, post_content_xhtml '. 
    13871424                    'FROM '.$this->prefix.'post '; 
    1388  
     1425           
    13891426          if ($start !== null && $limit !== null) { 
    13901427               $strReq .= $this->con->limit($start,$limit); 
    13911428          } 
    1392  
     1429           
    13931430          $rs = $this->con->select($strReq,true); 
    1394  
     1431           
    13951432          $cur = $this->con->openCursor($this->prefix.'post'); 
    1396  
     1433           
    13971434          while ($rs->fetch()) 
    13981435          { 
    13991436               $words = $rs->post_title.' '. $rs->post_excerpt_xhtml.' '. 
    14001437               $rs->post_content_xhtml; 
    1401  
     1438                
    14021439               $cur->post_words = implode(' ',text::splitWords($words)); 
    14031440               $cur->update('WHERE post_id = '.(integer) $rs->post_id); 
    14041441               $cur->clean(); 
    14051442          } 
    1406  
     1443           
    14071444          if ($start+$limit > $count) { 
    14081445               return null; 
     
    14101447          return $start+$limit; 
    14111448     } 
    1412  
     1449      
    14131450     /** 
    14141451     Recreates comments search engine index. 
    1415  
     1452      
    14161453     @param    start     <b>integer</b>      Start comment index 
    14171454     @param    limit     <b>integer</b>      Number of comments to index 
    1418  
     1455      
    14191456     @return   <b>integer</b>      <var>$start</var> and <var>$limit</var> sum 
    14201457     */ 
     
    14251462          $rs = $this->con->select($strReq); 
    14261463          $count = $rs->f(0); 
    1427  
     1464           
    14281465          $strReq = 'SELECT comment_id, comment_content '. 
    14291466                    'FROM '.$this->prefix.'comment '; 
    1430  
     1467           
    14311468          if ($start !== null && $limit !== null) { 
    14321469               $strReq .= $this->con->limit($start,$limit); 
    14331470          } 
    1434  
     1471           
    14351472          $rs = $this->con->select($strReq); 
    1436  
     1473           
    14371474          $cur = $this->con->openCursor($this->prefix.'comment'); 
    1438  
     1475           
    14391476          while ($rs->fetch()) 
    14401477          { 
     
    14431480               $cur->clean(); 
    14441481          } 
    1445  
     1482           
    14461483          if ($start+$limit > $count) { 
    14471484               return null; 
     
    14491486          return $start+$limit; 
    14501487     } 
    1451  
     1488      
    14521489     /** 
    14531490     Reinits nb_comment and nb_trackback in post table. 
     
    14551492     public function countAllComments() 
    14561493     { 
    1457  
     1494      
    14581495          $updCommentReq = 'UPDATE '.$this->prefix.'post P '. 
    14591496               'SET nb_comment = ('. 
     
    14711508          $this->con->execute($updTrackbackReq); 
    14721509     } 
    1473  
     1510      
    14741511     /** 
    14751512     Empty templates cache directory 
Note: See TracChangeset for help on using the changeset viewer.

Sites map