Dotclear


Ignore:
Timestamp:
05/20/14 08:39:33 (11 years ago)
Author:
Dsls
Branch:
twig
Parents:
2683:fb8aa74332f1 (diff), 2714:eed2e5727277 (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 (admin/post.php still to update with editor preferences, in twig template)

Files:
2 edited

Legend:

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

    r2683 r2715  
    901901               'edit_size' => 24, 
    902902               'enable_wysiwyg' => true, 
     903            'editor' => 'dcLegacyEditor', 
    903904               'post_format' => 'wiki' 
    904905          ); 
  • inc/core/class.dc.core.php

    r2706 r2715  
    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); 
    103104     } 
    104  
     105      
    105106     private function authInstance() 
    106107     { 
     
    112113               $c = DC_AUTH_CLASS; 
    113114          } 
    114  
     115           
    115116          if (!class_exists($c)) { 
    116117               throw new Exception('Authentication class '.$c.' does not exist.'); 
    117118          } 
    118  
     119           
    119120          if ($c != 'dcAuth' && !is_subclass_of($c,'dcAuth')) { 
    120121               throw new Exception('Authentication class '.$c.' does not inherit dcAuth.'); 
    121122          } 
    122  
     123           
    123124          return new $c($this); 
    124125     } 
    125  
    126  
     126      
     127     /** 
     128     Create template environment (Twig_Environment instance) 
     129      
     130     default-templates path must be added from admin|public/prepend.php with: 
     131     $core->tpl->getLoader()->addPath('PATH_TO/default-templates'); 
     132     Selected theme path must be added with: 
     133     $core->tpl->getLoader()->prependPath('PATH_TO/MY_THEME'); 
     134     */ 
     135     public function loadTemplateEnvironment() 
     136     { 
     137          $cache_dir = path::real(DC_TPL_CACHE.'/twtpl',false); 
     138          if (!is_dir($cache_dir)) { 
     139               try { 
     140                    files::makeDir($cache_dir); 
     141               } catch (Exception $e) { 
     142                    $cache_dir = false; 
     143               } 
     144          } 
     145           
     146          $this->tpl = new Twig_Environment( 
     147               new Twig_Loader_Filesystem(dirname(__FILE__).'/../swf'), 
     148               array( 
     149                    'auto_reload' => true, 
     150                    'autoescape' => false, 
     151                    'base_template_class' => 'Twig_Template', 
     152                    'cache' => $cache_dir,  
     153                    'charset' => 'UTF-8', 
     154                    'debug' => DC_DEBUG, 
     155                    'optimizations' => -1, 
     156                    'strict_variables' => 0 //DC_DEBUG // Please fix undefined variables! 
     157               ) 
     158          ); 
     159          $this->tpl->addExtension(new dcFormExtension($this)); 
     160          $this->tpl->addExtension(new dcTabExtension($this)); 
     161     } 
     162      
    127163     /// @name Blog init methods 
    128164     //@{ 
    129165     /** 
    130166     Sets a blog to use in <var>blog</var> property. 
    131  
     167      
    132168     @param    id        <b>string</b>       Blog ID 
    133169     */ 
     
    136172          $this->blog = new dcBlog($this, $id); 
    137173     } 
    138  
     174      
    139175     /** 
    140176     Unsets <var>blog</var> property. 
     
    145181     } 
    146182     //@} 
    147  
    148  
     183      
     184      
    149185     /// @name Blog status methods 
    150186     //@{ 
    151187     /** 
    152188     Returns an array of available blog status codes and names. 
    153  
     189      
    154190     @return   <b>array</b> Simple array with codes in keys and names in value 
    155191     */ 
     
    162198          ); 
    163199     } 
    164  
     200      
    165201     /** 
    166202     Returns a blog status name given to a code. This is intended to be 
    167203     human-readable and will be translated, so never use it for tests. 
    168204     If status code does not exist, returns <i>offline</i>. 
    169  
     205      
    170206     @param    s    <b>integer</b> Status code 
    171207     @return   <b>string</b> Blog status name 
     
    180216     } 
    181217     //@} 
    182  
     218      
    183219     /// @name Admin nonce secret methods 
    184220     //@{ 
    185  
     221      
    186222     public function getNonce() 
    187223     { 
    188224          return crypt::hmac(DC_MASTER_KEY,session_id()); 
    189225     } 
    190  
     226      
    191227     public function checkNonce($secret) 
    192228     { 
     
    194230               return false; 
    195231          } 
    196  
     232           
    197233          return $secret == crypt::hmac(DC_MASTER_KEY,session_id()); 
    198234     } 
    199  
     235      
    200236     public function formNonce() 
    201237     { 
     
    203239               return; 
    204240          } 
    205  
     241           
    206242          return form::hidden(array('xd_check'),$this->getNonce()); 
    207243     } 
    208244     //@} 
    209  
     245      
    210246     /// @name Text Formatters methods 
    211247     //@{ 
     
    225261          } 
    226262     } 
    227  
     263      
    228264     /// @name Text Formatters methods 
    229265     //@{ 
     
    232268     transform text. The function must be a valid callback and takes one 
    233269     argument: the string to transform. It returns the transformed string. 
    234  
     270      
    235271     @param    name      <b>string</b>       Formater name 
    236272     @param    func      <b>callback</b>     Function to use, must be a valid and callable callback 
     
    256292          return $editors; 
    257293     } 
    258  
     294      
    259295     /** 
    260296     Returns formaters list by editor 
    261  
     297      
    262298     @param    editor_id <b>string</b>  Editor id (dcLegacyEditor, dcCKEditor, ...) 
    263299     @return   <b>array</b> An array of formaters names in values. 
     
    288324          return $formaters_list; 
    289325     } 
    290  
     326      
    291327     /** 
    292328     If <var>$name</var> is a valid formater, it returns <var>$str</var> 
    293329     transformed using that formater. 
    294  
     330      
    295331     @param    editor_id <b>string</b>  Editor id (dcLegacyEditor, dcCKEditor, ...) 
    296332     @param    name      <b>string</b>       Formater name 
     
    303339               return call_user_func($this->formaters[$editor_id][$name],$str); 
    304340          } 
    305  
     341           
    306342          return $str; 
    307343     } 
    308344     //@} 
    309  
     345      
    310346     /** 
    311347     If <var>$name</var> is a valid formater, it returns <var>$str</var> 
     
    322358     //@} 
    323359 
    324  
     360      
    325361     /// @name Behaviors methods 
    326362     //@{ 
     
    328364     Adds a new behavior to behaviors stack. <var>$func</var> must be a valid 
    329365     and callable callback. 
    330  
     366      
    331367     @param    behavior  <b>string</b>       Behavior name 
    332368     @param    func      <b>callback</b>     Function to call 
     
    338374          } 
    339375     } 
    340  
     376      
    341377     /** 
    342378     Tests if a particular behavior exists in behaviors stack. 
    343  
     379      
    344380     @param    behavior  <b>string</b>  Behavior name 
    345381     @return   <b>boolean</b> 
     
    349385          return isset($this->behaviors[$behavior]); 
    350386     } 
    351  
     387      
    352388     /** 
    353389     Get behaviors stack (or part of). 
    354  
     390      
    355391     @param    behavior  <b>string</b>       Behavior name 
    356392     @return   <b>array</b> 
     
    359395     { 
    360396          if (empty($this->behaviors)) return null; 
    361  
     397           
    362398          if ($behavior == '') { 
    363399               return $this->behaviors; 
     
    365401               return $this->behaviors[$behavior]; 
    366402          } 
    367  
     403           
    368404          return array(); 
    369405     } 
    370  
     406      
    371407     /** 
    372408     Calls every function in behaviors stack for a given behavior and returns 
    373409     concatened result of each function. 
    374  
     410      
    375411     Every parameters added after <var>$behavior</var> will be pass to 
    376412     behavior calls. 
    377  
     413      
    378414     @param    behavior  <b>string</b>  Behavior name 
    379415     @return   <b>string</b> Behavior concatened result 
     
    385421               $args = func_get_args(); 
    386422               array_shift($args); 
    387  
     423                
    388424               $res = ''; 
    389  
     425                
    390426               foreach ($this->behaviors[$behavior] as $f) { 
    391427                    $res .= call_user_func_array($f,$args); 
    392428               } 
    393  
     429                
    394430               return $res; 
    395431          } 
    396432     } 
    397433     //@} 
    398  
     434      
    399435     /// @name Post types URLs management 
    400436     //@{ 
     
    404440               $type = 'post'; 
    405441          } 
    406  
     442           
    407443          $url = sprintf($this->post_types[$type]['admin_url'],$post_id); 
    408444          return $escaped ? html::escapeURL($url) : $url; 
    409445     } 
    410  
     446      
    411447     public function getPostPublicURL($type,$post_url,$escaped=true) 
    412448     { 
     
    414450               $type = 'post'; 
    415451          } 
    416  
     452           
    417453          $url = sprintf($this->post_types[$type]['public_url'],$post_url); 
    418454          return $escaped ? html::escapeURL($url) : $url; 
    419455     } 
    420  
     456      
    421457     public function setPostType($type,$admin_url,$public_url,$label='') 
    422458     { 
     
    427463          ); 
    428464     } 
    429  
     465      
    430466     public function getPostTypes() 
    431467     { 
     
    433469     } 
    434470     //@} 
    435  
     471      
    436472     /// @name Versions management methods 
    437473     //@{ 
    438474     /** 
    439475     Returns a given $module version. 
    440  
     476      
    441477     @param    module    <b>string</b>  Module name 
    442478     @return   <b>string</b>  Module version 
     
    449485               $strReq = 'SELECT module, version FROM '.$this->prefix.'version'; 
    450486               $rs = $this->con->select($strReq); 
    451  
     487                
    452488               while ($rs->fetch()) { 
    453489                    $this->versions[$rs->module] = $rs->version; 
    454490               } 
    455491          } 
    456  
     492           
    457493          if (isset($this->versions[$module])) { 
    458494               return $this->versions[$module]; 
     
    461497          } 
    462498     } 
    463  
     499      
    464500     /** 
    465501     Sets $version to given $module. 
    466  
     502      
    467503     @param    module    <b>string</b>  Module name 
    468504     @param    version   <b>string</b>  Module version 
     
    471507     { 
    472508          $cur_version = $this->getVersion($module); 
    473  
     509           
    474510          $cur = $this->con->openCursor($this->prefix.'version'); 
    475511          $cur->module = (string) $module; 
    476512          $cur->version = (string) $version; 
    477  
     513           
    478514          if ($cur_version === null) { 
    479515               $cur->insert(); 
     
    481517               $cur->update("WHERE module='".$this->con->escape($module)."'"); 
    482518          } 
    483  
     519           
    484520          $this->versions[$module] = $version; 
    485521     } 
    486  
     522      
    487523     /** 
    488524     Removes given $module version entry. 
    489  
     525      
    490526     @param    module    <b>string</b>  Module name 
    491527     */ 
     
    495531          'DELETE FROM '.$this->prefix.'version '. 
    496532          "WHERE module = '".$this->con->escape($module)."' "; 
    497  
     533           
    498534          $this->con->execute($strReq); 
    499  
     535           
    500536          if (is_array($this->versions)) { 
    501537               unset($this->versions[$module]); 
    502538          } 
    503539     } 
    504  
     540      
    505541     //@} 
    506  
     542      
    507543     /// @name Users management methods 
    508544     //@{ 
    509545     /** 
    510546     Returns a user by its ID. 
    511  
     547      
    512548     @param    id        <b>string</b>       User ID 
    513549     @return   <b>record</b> 
     
    516552     { 
    517553          $params['user_id'] = $id; 
    518  
     554           
    519555          return $this->getUsers($params); 
    520556     } 
    521  
     557      
    522558     /** 
    523559     Returns a users list. <b>$params</b> is an array with the following 
    524560     optionnal parameters: 
    525  
     561      
    526562      - <var>q</var>: search string (on user_id, user_name, user_firstname) 
    527563      - <var>user_id</var>: user ID 
    528564      - <var>order</var>: ORDER BY clause (default: user_id ASC) 
    529565      - <var>limit</var>: LIMIT clause (should be an array ![limit,offset]) 
    530  
     566      
    531567     @param    params         <b>array</b>        Parameters 
    532568     @param    count_only     <b>boolean</b>      Only counts results 
     
    553589               'WHERE NULL IS NULL '; 
    554590          } 
    555  
     591           
    556592          if (!empty($params['q'])) { 
    557593               $q = $this->con->escape(str_replace('*','%',strtolower($params['q']))); 
     
    562598                    ') '; 
    563599          } 
    564  
     600           
    565601          if (!empty($params['user_id'])) { 
    566602               $strReq .= "AND U.user_id = '".$this->con->escape($params['user_id'])."' "; 
    567603          } 
    568  
     604           
    569605          if (!$count_only) { 
    570606               $strReq .= 'GROUP BY U.user_id,user_super,user_status,user_pwd,user_change_pwd,'. 
    571607               'user_name,user_firstname,user_displayname,user_email,user_url,'. 
    572608               'user_desc, user_lang,user_tz,user_post_status,user_options '; 
    573  
     609                
    574610               if (!empty($params['order']) && !$count_only) { 
    575611                    $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; 
     
    578614               } 
    579615          } 
    580  
     616           
    581617          if (!$count_only && !empty($params['limit'])) { 
    582618               $strReq .= $this->con->limit($params['limit']); 
    583619          } 
    584  
     620           
    585621          $rs = $this->con->select($strReq); 
    586622          $rs->extend('rsExtUser'); 
    587623          return $rs; 
    588624     } 
    589  
     625      
    590626     /** 
    591627     Create a new user. Takes a cursor as input and returns the new user ID. 
    592  
     628      
    593629     @param    cur       <b>cursor</b>       User cursor 
    594630     @return   <b>string</b> 
     
    599635               throw new Exception(__('You are not an administrator')); 
    600636          } 
    601  
     637           
    602638          if ($cur->user_id == '') { 
    603639               throw new Exception(__('No user ID given')); 
    604640          } 
    605  
     641           
    606642          if ($cur->user_pwd == '') { 
    607643               throw new Exception(__('No password given')); 
    608644          } 
    609  
     645           
    610646          $this->getUserCursor($cur); 
    611  
     647           
    612648          if ($cur->user_creadt === null) { 
    613649               $cur->user_creadt = date('Y-m-d H:i:s'); 
    614650          } 
    615  
     651           
    616652          $cur->insert(); 
    617  
     653           
    618654          $this->auth->afterAddUser($cur); 
    619  
     655           
    620656          return $cur->user_id; 
    621657     } 
    622  
     658      
    623659     /** 
    624660     Updates an existing user. Returns the user ID. 
    625  
     661      
    626662     @param    id        <b>string</b>       User ID 
    627663     @param    cur       <b>cursor</b>       User cursor 
     
    631667     { 
    632668          $this->getUserCursor($cur); 
    633  
     669           
    634670          if (($cur->user_id !== null || $id != $this->auth->userID()) && 
    635671          !$this->auth->isSuperAdmin()) { 
    636672               throw new Exception(__('You are not an administrator')); 
    637673          } 
    638  
     674           
    639675          $cur->update("WHERE user_id = '".$this->con->escape($id)."' "); 
    640  
     676           
    641677          $this->auth->afterUpdUser($id,$cur); 
    642  
     678           
    643679          if ($cur->user_id !== null) { 
    644680               $id = $cur->user_id; 
    645681          } 
    646  
     682           
    647683          # Updating all user's blogs 
    648684          $rs = $this->con->select( 
     
    650686               "WHERE user_id = '".$this->con->escape($id)."' " 
    651687               ); 
    652  
     688           
    653689          while ($rs->fetch()) { 
    654690               $b = new dcBlog($this,$rs->blog_id); 
     
    656692               unset($b); 
    657693          } 
    658  
     694           
    659695          return $id; 
    660696     } 
    661  
     697      
    662698     /** 
    663699     Deletes a user. 
    664  
     700      
    665701     @param    id        <b>string</b>       User ID 
    666702     */ 
     
    670706               throw new Exception(__('You are not an administrator')); 
    671707          } 
    672  
     708           
    673709          if ($id == $this->auth->userID()) { 
    674710               return; 
    675711          } 
    676  
     712           
    677713          $rs = $this->getUser($id); 
    678  
     714           
    679715          if ($rs->nb_post > 0) { 
    680716               return; 
    681717          } 
    682  
     718           
    683719          $strReq = 'DELETE FROM '.$this->prefix.'user '. 
    684720                    "WHERE user_id = '".$this->con->escape($id)."' "; 
    685  
     721           
    686722          $this->con->execute($strReq); 
    687  
     723           
    688724          $this->auth->afterDelUser($id); 
    689725     } 
    690  
     726      
    691727     /** 
    692728     Checks whether a user exists. 
    693  
     729      
    694730     @param    id        <b>string</b>       User ID 
    695731     @return   <b>boolean</b> 
     
    700736                    'FROM '.$this->prefix.'user '. 
    701737                    "WHERE user_id = '".$this->con->escape($id)."' "; 
    702  
     738           
    703739          $rs = $this->con->select($strReq); 
    704  
     740           
    705741          return !$rs->isEmpty(); 
    706742     } 
    707  
     743      
    708744     /** 
    709745     Returns all user permissions as an array which looks like: 
    710  
     746      
    711747      - [blog_id] 
    712748        - [name] => Blog name 
    713749        - [url] => Blog URL 
    714750        - [p] 
    715           - [permission] => true 
     751          - [permission] => true 
    716752          - ... 
    717  
     753      
    718754     @param    id        <b>string</b>       User ID 
    719755     @return   <b>array</b> 
     
    725761                    'INNER JOIN '.$this->prefix.'blog B ON P.blog_id = B.blog_id '. 
    726762                    "WHERE user_id = '".$this->con->escape($id)."' "; 
    727  
     763           
    728764          $rs = $this->con->select($strReq); 
    729  
     765           
    730766          $res = array(); 
    731  
     767           
    732768          while ($rs->fetch()) 
    733769          { 
     
    738774               ); 
    739775          } 
    740  
     776           
    741777          return $res; 
    742778     } 
    743  
     779      
    744780     /** 
    745781     Sets user permissions. The <var>$perms</var> array looks like: 
    746  
     782      
    747783      - [blog_id] => '|perm1|perm2|' 
    748784      - ... 
    749  
     785      
    750786     @param    id        <b>string</b>       User ID 
    751787     @param    perms     <b>array</b>        Permissions array 
     
    756792               throw new Exception(__('You are not an administrator')); 
    757793          } 
    758  
     794           
    759795          $strReq = 'DELETE FROM '.$this->prefix.'permissions '. 
    760796                    "WHERE user_id = '".$this->con->escape($id)."' "; 
    761  
     797           
    762798          $this->con->execute($strReq); 
    763  
     799           
    764800          foreach ($perms as $blog_id => $p) { 
    765801               $this->setUserBlogPermissions($id, $blog_id, $p, false); 
    766802          } 
    767803     } 
    768  
     804      
    769805     /** 
    770806     Sets user permissions for a given blog. <var>$perms</var> is an array with 
    771807     permissions in values 
    772  
     808      
    773809     @param    id             <b>string</b>       User ID 
    774810     @param    blog_id        <b>string</b>       Blog ID 
     
    781817               throw new Exception(__('You are not an administrator')); 
    782818          } 
    783  
     819           
    784820          $no_perm = empty($perms); 
    785  
     821           
    786822          $perms = '|'.implode('|',array_keys($perms)).'|'; 
    787  
     823           
    788824          $cur = $this->con->openCursor($this->prefix.'permissions'); 
    789  
     825           
    790826          $cur->user_id = (string) $id; 
    791827          $cur->blog_id = (string) $blog_id; 
    792828          $cur->permissions = $perms; 
    793  
     829           
    794830          if ($delete_first || $no_perm) 
    795831          { 
     
    797833                         "WHERE blog_id = '".$this->con->escape($blog_id)."' ". 
    798834                         "AND user_id = '".$this->con->escape($id)."' "; 
    799  
     835                
    800836               $this->con->execute($strReq); 
    801837          } 
    802  
     838           
    803839          if (!$no_perm) { 
    804840               $cur->insert(); 
    805841          } 
    806842     } 
    807  
     843      
    808844     /** 
    809845     Sets a user default blog. This blog will be selected when user log in. 
    810  
     846      
    811847     @param    id             <b>string</b>       User ID 
    812848     @param    blog_id        <b>string</b>       Blog ID 
     
    815851     { 
    816852          $cur = $this->con->openCursor($this->prefix.'user'); 
    817  
     853           
    818854          $cur->user_default_blog = (string) $blog_id; 
    819  
     855           
    820856          $cur->update("WHERE user_id = '".$this->con->escape($id)."'"); 
    821857     } 
    822  
     858      
    823859     private function getUserCursor($cur) 
    824860     { 
     
    827863               throw new Exception(__('User ID must contain at least 2 characters using letters, numbers or symbols.')); 
    828864          } 
    829  
     865           
    830866          if ($cur->user_url !== null && $cur->user_url != '') { 
    831867               if (!preg_match('|^http(s?)://|',$cur->user_url)) { 
     
    833869               } 
    834870          } 
    835  
     871           
    836872          if ($cur->isField('user_pwd')) { 
    837873               if (strlen($cur->user_pwd) < 6) { 
     
    840876               $cur->user_pwd = crypt::hmac(DC_MASTER_KEY,$cur->user_pwd); 
    841877          } 
    842  
     878           
    843879          if ($cur->user_lang !== null && !preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$cur->user_lang)) { 
    844880               throw new Exception(__('Invalid user language code')); 
    845881          } 
    846  
     882           
    847883          if ($cur->user_upddt === null) { 
    848884               $cur->user_upddt = date('Y-m-d H:i:s'); 
    849885          } 
    850  
     886           
    851887          if ($cur->user_options !== null) { 
    852888               $cur->user_options = serialize((array) $cur->user_options); 
    853889          } 
    854890     } 
    855  
     891      
    856892     /** 
    857893     Returns user default settings in an associative array with setting names in 
    858894     keys. 
    859  
     895      
    860896     @return   <b>array</b> 
    861897     */ 
     
    870906     } 
    871907     //@} 
    872  
     908      
    873909     /// @name Blog management methods 
    874910     //@{ 
    875911     /** 
    876912     Returns all blog permissions (users) as an array which looks like: 
    877  
     913      
    878914      - [user_id] 
    879915        - [name] => User name 
     
    882918        - [super] => (true|false) super admin 
    883919        - [p] 
    884           - [permission] => true 
     920          - [permission] => true 
    885921          - ... 
    886  
     922      
    887923     @param    id             <b>string</b>       Blog ID 
    888924     @param    with_super     <b>boolean</b>      Includes super admins in result 
     
    897933          'JOIN '.$this->prefix.'permissions P ON U.user_id = P.user_id '. 
    898934          "WHERE blog_id = '".$this->con->escape($id)."' "; 
    899  
     935           
    900936          if ($with_super) { 
    901937               $strReq .= 
     
    906942               'WHERE user_super = 1 '; 
    907943          } 
    908  
     944           
    909945          $rs = $this->con->select($strReq); 
    910  
     946           
    911947          $res = array(); 
    912  
     948           
    913949          while ($rs->fetch()) 
    914950          { 
     
    922958               ); 
    923959          } 
    924  
     960           
    925961          return $res; 
    926962     } 
    927  
     963      
    928964     /** 
    929965     Returns a blog of given ID. 
    930  
     966      
    931967     @param    id        <b>string</b>       Blog ID 
    932968     @return   <b>record</b> 
     
    935971     { 
    936972          $blog = $this->getBlogs(array('blog_id'=>$id)); 
    937  
     973           
    938974          if ($blog->isEmpty()) { 
    939975               return false; 
    940976          } 
    941  
     977           
    942978          return $blog; 
    943979     } 
    944  
     980      
    945981     /** 
    946982     Returns a record of blogs. <b>$params</b> is an array with the following 
    947983     optionnal parameters: 
    948  
     984      
    949985      - <var>blog_id</var>: Blog ID 
    950986      - <var>q</var>: Search string on blog_id, blog_name and blog_url 
    951987      - <var>limit</var>: limit results 
    952  
     988      
    953989     @param    params         <b>array</b>        Parameters 
    954990     @param    count_only     <b>boolean</b>      Count only results 
     
    959995          $join = '';    // %1$s 
    960996          $where = '';   // %2$s 
    961  
     997           
    962998          if ($count_only) 
    963999          { 
     
    9771013               'WHERE NULL IS NULL '. 
    9781014               '%2$s '; 
    979  
     1015                
    9801016               if (!empty($params['order'])) { 
    9811017                    $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; 
     
    9831019                    $strReq .= 'ORDER BY B.blog_id ASC '; 
    9841020               } 
    985  
     1021                
    9861022               if (!empty($params['limit'])) { 
    9871023                    $strReq .= $this->con->limit($params['limit']); 
    9881024               } 
    9891025          } 
    990  
     1026           
    9911027          if ($this->auth->userID() && !$this->auth->isSuperAdmin()) 
    9921028          { 
     
    9991035               $where = 'AND blog_status IN (1,0) '; 
    10001036          } 
    1001  
     1037           
    10021038          if (!empty($params['blog_id'])) { 
    10031039               $where .= "AND B.blog_id = '".$this->con->escape($params['blog_id'])."' "; 
    10041040          } 
    1005  
     1041           
    10061042          if (!empty($params['q'])) { 
    10071043               $params['q'] = strtolower(str_replace('*','%',$params['q'])); 
     
    10131049               ') '; 
    10141050          } 
    1015  
     1051           
    10161052          $strReq = sprintf($strReq,$join,$where); 
    10171053          return $this->con->select($strReq); 
    10181054     } 
    1019  
     1055      
    10201056     /** 
    10211057     Creates a new blog. 
    1022  
     1058      
    10231059     @param    cur            <b>cursor</b>       Blog cursor 
    10241060     */ 
     
    10281064               throw new Exception(__('You are not an administrator')); 
    10291065          } 
    1030  
     1066           
    10311067          $this->getBlogCursor($cur); 
    1032  
     1068           
    10331069          $cur->blog_creadt = date('Y-m-d H:i:s'); 
    10341070          $cur->blog_upddt = date('Y-m-d H:i:s'); 
    10351071          $cur->blog_uid = md5(uniqid()); 
    1036  
     1072           
    10371073          $cur->insert(); 
    10381074     } 
    1039  
     1075      
    10401076     /** 
    10411077     Updates a given blog. 
    1042  
     1078      
    10431079     @param    id        <b>string</b>       Blog ID 
    10441080     @param    cur       <b>cursor</b>       Blog cursor 
     
    10471083     { 
    10481084          $this->getBlogCursor($cur); 
    1049  
     1085           
    10501086          $cur->blog_upddt = date('Y-m-d H:i:s'); 
    1051  
     1087           
    10521088          $cur->update("WHERE blog_id = '".$this->con->escape($id)."'"); 
    10531089     } 
    1054  
     1090      
    10551091     private function getBlogCursor($cur) 
    10561092     { 
     
    10581094               && !preg_match('/^[A-Za-z0-9._-]{2,}$/',$cur->blog_id)) || 
    10591095               (!$cur->blog_id)) { 
    1060                throw new Exception(__('Blog ID must contain at least 2 characters using letters, numbers or symbols.')); 
    1061           } 
    1062  
     1096               throw new Exception(__('Blog ID must contain at least 2 characters using letters, numbers or symbols.'));  
     1097          } 
     1098           
    10631099          if (($cur->blog_name !== null && $cur->blog_name == '') || 
    10641100               (!$cur->blog_name)) { 
    10651101               throw new Exception(__('No blog name')); 
    10661102          } 
    1067  
     1103           
    10681104          if (($cur->blog_url !== null && $cur->blog_url == '') || 
    10691105               (!$cur->blog_url)) { 
    10701106               throw new Exception(__('No blog URL')); 
    10711107          } 
    1072  
     1108           
    10731109          if ($cur->blog_desc !== null) { 
    10741110               $cur->blog_desc = html::clean($cur->blog_desc); 
    10751111          } 
    10761112     } 
    1077  
     1113      
    10781114     /** 
    10791115     Removes a given blog. 
    10801116     @warning This will remove everything related to the blog (posts, 
    10811117     categories, comments, links...) 
    1082  
     1118      
    10831119     @param    id        <b>string</b>       Blog ID 
    10841120     */ 
     
    10881124               throw new Exception(__('You are not an administrator')); 
    10891125          } 
    1090  
     1126           
    10911127          $strReq = 'DELETE FROM '.$this->prefix.'blog '. 
    10921128                    "WHERE blog_id = '".$this->con->escape($id)."' "; 
    1093  
     1129           
    10941130          $this->con->execute($strReq); 
    10951131     } 
    1096  
     1132      
    10971133     /** 
    10981134     Checks if a blog exist. 
    1099  
     1135      
    11001136     @param    id        <b>string</b>       Blog ID 
    11011137     @return   <b>boolean</b> 
     
    11061142                    'FROM '.$this->prefix.'blog '. 
    11071143                    "WHERE blog_id = '".$this->con->escape($id)."' "; 
    1108  
     1144           
    11091145          $rs = $this->con->select($strReq); 
    1110  
     1146           
    11111147          return !$rs->isEmpty(); 
    11121148     } 
    1113  
     1149      
    11141150     /** 
    11151151     Count posts on a blog 
    1116  
     1152      
    11171153     @param    id        <b>string</b>       Blog ID 
    11181154     @param    type      <b>string</b>       Post type 
     
    11241160                    'FROM '.$this->prefix.'post '. 
    11251161                    "WHERE blog_id = '".$this->con->escape($id)."' "; 
    1126  
     1162           
    11271163          if ($type) { 
    11281164               $strReq .= "AND post_type = '".$this->con->escape($type)."' "; 
    11291165          } 
    1130  
     1166           
    11311167          return $this->con->select($strReq)->f(0); 
    11321168     } 
    11331169     //@} 
    1134  
     1170      
    11351171     /// @name HTML Filter methods 
    11361172     //@{ 
     
    11391175     tidy extension is present). If <b>enable_html_filter</b> blog setting is 
    11401176     false, returns not filtered string. 
    1141  
     1177      
    11421178     @param    str  <b>string</b>       String to filter 
    11431179     @return   <b>string</b> Filtered string. 
     
    11481184               return $str; 
    11491185          } 
    1150  
     1186           
    11511187          $filter = new htmlFilter; 
    11521188          $str = trim($filter->apply($str)); 
     
    11541190     } 
    11551191     //@} 
    1156  
     1192      
    11571193     /// @name wiki2xhtml methods 
    11581194     //@{ 
     
    11611197          $this->wiki2xhtml = new wiki2xhtml; 
    11621198     } 
    1163  
     1199      
    11641200     /** 
    11651201     Returns a transformed string with wiki2xhtml. 
    1166  
     1202      
    11671203     @param    str       <b>string</b>       String to transform 
    11681204     @return   <b>string</b>  Transformed string 
     
    11751211          return $this->wiki2xhtml->transform($str); 
    11761212     } 
    1177  
     1213      
    11781214     /** 
    11791215     Inits <var>wiki2xhtml</var> property for blog post. 
     
    11821218     { 
    11831219          $this->initWiki(); 
    1184  
     1220           
    11851221          $this->wiki2xhtml->setOpts(array( 
    11861222               'active_title' => 1, 
     
    12141250               'note_str' => '<div class="footnotes"><h4>Notes</h4>%s</div>' 
    12151251          )); 
    1216  
     1252           
    12171253          $this->wiki2xhtml->registerFunction('url:post',array($this,'wikiPostLink')); 
    1218  
     1254           
    12191255          # --BEHAVIOR-- coreWikiPostInit 
    12201256          $this->callBehavior('coreInitWikiPost',$this->wiki2xhtml); 
    12211257     } 
    1222  
     1258      
    12231259     /** 
    12241260     Inits <var>wiki2xhtml</var> property for simple blog comment (basic syntax). 
     
    12271263     { 
    12281264          $this->initWiki(); 
    1229  
     1265           
    12301266          $this->wiki2xhtml->setOpts(array( 
    12311267               'active_title' => 0, 
     
    12561292               'active_fr_syntax' => 0 
    12571293          )); 
    1258  
     1294           
    12591295          # --BEHAVIOR-- coreInitWikiSimpleComment 
    12601296          $this->callBehavior('coreInitWikiSimpleComment',$this->wiki2xhtml); 
    12611297     } 
    1262  
     1298      
    12631299     /** 
    12641300     Inits <var>wiki2xhtml</var> property for blog comment. 
     
    12671303     { 
    12681304          $this->initWiki(); 
    1269  
     1305           
    12701306          $this->wiki2xhtml->setOpts(array( 
    12711307               'active_title' => 0, 
     
    12961332               'active_fr_syntax' => 0 
    12971333          )); 
    1298  
     1334           
    12991335          # --BEHAVIOR-- coreInitWikiComment 
    13001336          $this->callBehavior('coreInitWikiComment',$this->wiki2xhtml); 
    13011337     } 
    1302  
     1338      
    13031339     public function wikiPostLink($url,$content) 
    13041340     { 
    1305           if (!($this->blog instanceof dcBlog)) { 
     1341          if (!($this->blog instanceof dcBlog)) {  
    13061342               return array(); 
    13071343          } 
    1308  
     1344           
    13091345          $post_id = abs((integer) substr($url,5)); 
    13101346          if (!$post_id) { 
    13111347               return array(); 
    13121348          } 
    1313  
     1349           
    13141350          $post = $this->blog->getPosts(array('post_id'=>$post_id)); 
    13151351          if ($post->isEmpty()) { 
    13161352               return array(); 
    13171353          } 
    1318  
     1354           
    13191355          $res = array('url' => $post->getURL()); 
    13201356          $post_title = $post->post_title; 
    1321  
     1357           
    13221358          if ($content != $url) { 
    13231359               $res['title'] = html::escapeHTML($post->post_title); 
    13241360          } 
    1325  
     1361           
    13261362          if ($content == '' || $content == $url) { 
    13271363               $res['content'] = html::escapeHTML($post->post_title); 
    13281364          } 
    1329  
     1365           
    13301366          if ($post->post_lang) { 
    13311367               $res['lang'] = $post->post_lang; 
    13321368          } 
    1333  
     1369           
    13341370          return $res; 
    13351371     } 
    13361372     //@} 
    1337  
     1373      
    13381374     /// @name Maintenance methods 
    13391375     //@{ 
     
    13411377     Creates default settings for active blog. Optionnal parameter 
    13421378     <var>defaults</var> replaces default params while needed. 
    1343  
     1379      
    13441380     @param    defaults       <b>array</b>   Default parameters 
    13451381     */ 
     
    14261462               ); 
    14271463          } 
    1428  
     1464           
    14291465          $settings = new dcSettings($this,null); 
    14301466          $settings->addNamespace('system'); 
    1431  
     1467           
    14321468          foreach ($defaults as $v) { 
    14331469               $settings->system->put($v[0],$v[2],$v[1],$v[3],false,true); 
    14341470          } 
    14351471     } 
    1436  
     1472      
    14371473     /** 
    14381474     Recreates entries search engine index. 
    1439  
     1475      
    14401476     @param    start     <b>integer</b>      Start entry index 
    14411477     @param    limit     <b>integer</b>      Number of entry to index 
    1442  
     1478      
    14431479     @return   <b>integer</b>      <var>$start</var> and <var>$limit</var> sum 
    14441480     */ 
     
    14491485          $rs = $this->con->select($strReq); 
    14501486          $count = $rs->f(0); 
    1451  
     1487           
    14521488          $strReq = 'SELECT post_id, post_title, post_excerpt_xhtml, post_content_xhtml '. 
    14531489                    'FROM '.$this->prefix.'post '; 
    1454  
     1490           
    14551491          if ($start !== null && $limit !== null) { 
    14561492               $strReq .= $this->con->limit($start,$limit); 
    14571493          } 
    1458  
     1494           
    14591495          $rs = $this->con->select($strReq,true); 
    1460  
     1496           
    14611497          $cur = $this->con->openCursor($this->prefix.'post'); 
    1462  
     1498           
    14631499          while ($rs->fetch()) 
    14641500          { 
    14651501               $words = $rs->post_title.' '. $rs->post_excerpt_xhtml.' '. 
    14661502               $rs->post_content_xhtml; 
    1467  
     1503                
    14681504               $cur->post_words = implode(' ',text::splitWords($words)); 
    14691505               $cur->update('WHERE post_id = '.(integer) $rs->post_id); 
    14701506               $cur->clean(); 
    14711507          } 
    1472  
     1508           
    14731509          if ($start+$limit > $count) { 
    14741510               return null; 
     
    14761512          return $start+$limit; 
    14771513     } 
    1478  
     1514      
    14791515     /** 
    14801516     Recreates comments search engine index. 
    1481  
     1517      
    14821518     @param    start     <b>integer</b>      Start comment index 
    14831519     @param    limit     <b>integer</b>      Number of comments to index 
    1484  
     1520      
    14851521     @return   <b>integer</b>      <var>$start</var> and <var>$limit</var> sum 
    14861522     */ 
     
    14911527          $rs = $this->con->select($strReq); 
    14921528          $count = $rs->f(0); 
    1493  
     1529           
    14941530          $strReq = 'SELECT comment_id, comment_content '. 
    14951531                    'FROM '.$this->prefix.'comment '; 
    1496  
     1532           
    14971533          if ($start !== null && $limit !== null) { 
    14981534               $strReq .= $this->con->limit($start,$limit); 
    14991535          } 
    1500  
     1536           
    15011537          $rs = $this->con->select($strReq); 
    1502  
     1538           
    15031539          $cur = $this->con->openCursor($this->prefix.'comment'); 
    1504  
     1540           
    15051541          while ($rs->fetch()) 
    15061542          { 
     
    15091545               $cur->clean(); 
    15101546          } 
    1511  
     1547           
    15121548          if ($start+$limit > $count) { 
    15131549               return null; 
     
    15151551          return $start+$limit; 
    15161552     } 
    1517  
     1553      
    15181554     /** 
    15191555     Reinits nb_comment and nb_trackback in post table. 
     
    15211557     public function countAllComments() 
    15221558     { 
    1523  
     1559      
    15241560          $updCommentReq = 'UPDATE '.$this->prefix.'post P '. 
    15251561               'SET nb_comment = ('. 
     
    15371573          $this->con->execute($updTrackbackReq); 
    15381574     } 
    1539  
     1575      
    15401576     /** 
    15411577     Empty templates cache directory 
     
    15501586     /** 
    15511587      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 
     1588      @param   $mtime <b>float</b> timestamp (microtime format) to evaluate delta from 
     1589                                     current time is taken if null 
     1590      @return <b>float</b>        elapsed time 
    15551591      */ 
    15561592     public function getElapsedTime ($mtime=null) { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map