Dotclear


Ignore:
Timestamp:
03/08/18 17:58:39 (8 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Code formatting (PSR-2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin/services.php

    r3614 r3730  
    1212 
    1313#if (isset($_GET['dcxd'])) { 
    14 #    $_COOKIE['dcxd'] = $_GET['dcxd']; 
     14#    $_COOKIE['dcxd'] = $_GET['dcxd']; 
    1515#} 
    1616 
    17 require dirname(__FILE__).'/../inc/admin/prepend.php'; 
    18  
    19 $core->rest->addFunction('checkNewsUpdate',array('dcRestMethods','checkNewsUpdate')); 
    20 $core->rest->addFunction('checkCoreUpdate',array('dcRestMethods','checkCoreUpdate')); 
    21 $core->rest->addFunction('getPostById',array('dcRestMethods','getPostById')); 
    22 $core->rest->addFunction('getCommentById',array('dcRestMethods','getCommentById')); 
    23 $core->rest->addFunction('quickPost',array('dcRestMethods','quickPost')); 
    24 $core->rest->addFunction('validatePostMarkup',array('dcRestMethods','validatePostMarkup')); 
    25 $core->rest->addFunction('getZipMediaContent',array('dcRestMethods','getZipMediaContent')); 
    26 $core->rest->addFunction('getMeta',array('dcRestMethods','getMeta')); 
    27 $core->rest->addFunction('delMeta',array('dcRestMethods','delMeta')); 
    28 $core->rest->addFunction('setPostMeta',array('dcRestMethods','setPostMeta')); 
    29 $core->rest->addFunction('searchMeta',array('dcRestMethods','searchMeta')); 
    30 $core->rest->addFunction('setSectionFold',array('dcRestMethods','setSectionFold')); 
    31 $core->rest->addFunction('getModuleById',array('dcRestMethods','getModuleById')); 
     17require dirname(__FILE__) . '/../inc/admin/prepend.php'; 
     18 
     19$core->rest->addFunction('checkNewsUpdate', array('dcRestMethods', 'checkNewsUpdate')); 
     20$core->rest->addFunction('checkCoreUpdate', array('dcRestMethods', 'checkCoreUpdate')); 
     21$core->rest->addFunction('getPostById', array('dcRestMethods', 'getPostById')); 
     22$core->rest->addFunction('getCommentById', array('dcRestMethods', 'getCommentById')); 
     23$core->rest->addFunction('quickPost', array('dcRestMethods', 'quickPost')); 
     24$core->rest->addFunction('validatePostMarkup', array('dcRestMethods', 'validatePostMarkup')); 
     25$core->rest->addFunction('getZipMediaContent', array('dcRestMethods', 'getZipMediaContent')); 
     26$core->rest->addFunction('getMeta', array('dcRestMethods', 'getMeta')); 
     27$core->rest->addFunction('delMeta', array('dcRestMethods', 'delMeta')); 
     28$core->rest->addFunction('setPostMeta', array('dcRestMethods', 'setPostMeta')); 
     29$core->rest->addFunction('searchMeta', array('dcRestMethods', 'searchMeta')); 
     30$core->rest->addFunction('setSectionFold', array('dcRestMethods', 'setSectionFold')); 
     31$core->rest->addFunction('getModuleById', array('dcRestMethods', 'getModuleById')); 
    3232 
    3333$core->rest->serve(); 
     
    3636class dcRestMethods 
    3737{ 
    38      public static function checkNewsUpdate($core,$get) 
    39      { 
    40           # Dotclear news 
    41  
    42           $rsp = new xmlTag('news'); 
    43           $rsp->check = false; 
    44           $ret = __('Dotclear news not available'); 
    45  
    46           if ($core->auth->user_prefs->dashboard->dcnews) { 
    47                try 
    48                { 
    49  
    50                     if (empty($GLOBALS['__resources']['rss_news'])) { 
    51                          throw new Exception(); 
    52                     } 
    53                     $feed_reader = new feedReader; 
    54                     $feed_reader->setCacheDir(DC_TPL_CACHE); 
    55                     $feed_reader->setTimeout(2); 
    56                     $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/'); 
    57                     $feed = $feed_reader->parse($GLOBALS['__resources']['rss_news']); 
    58                     if ($feed) 
    59                     { 
    60                          $ret = '<div class="box medium dc-box"><h3>'.__('Dotclear news').'</h3><dl id="news">'; 
    61                          $i = 1; 
    62                          foreach ($feed->items as $item) 
    63                          { 
    64                               $dt = isset($item->link) ? '<a href="'.$item->link.'" class="outgoing" title="'.$item->title.'">'. 
    65                                    $item->title.' <img src="images/outgoing-blue.png" alt="" /></a>' : $item->title; 
    66  
    67                               if ($i < 3) { 
    68                                    $ret .= 
    69                                    '<dt>'.$dt.'</dt>'. 
    70                                    '<dd><p><strong>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</strong> '. 
    71                                    '<em>'.text::cutString(html::clean($item->content),120).'...</em></p></dd>'; 
    72                               } else { 
    73                                    $ret .= 
    74                                    '<dt>'.$dt.'</dt>'. 
    75                                    '<dd>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</dd>'; 
    76                               } 
    77                               $i++; 
    78                               if ($i > 2) { break; } 
    79                          } 
    80                          $ret .= '</dl></div>'; 
    81                          $rsp->check = true; 
    82                     } 
    83                } 
    84                catch (Exception $e) {} 
    85           } 
    86           $rsp->ret = $ret; 
    87           return $rsp; 
    88      } 
    89  
    90      public static function checkCoreUpdate($core,$get) 
    91      { 
    92           # Dotclear updates notifications 
    93  
    94           $rsp = new xmlTag('update'); 
    95           $rsp->check = false; 
    96           $ret = __('Dotclear update not available'); 
    97  
    98           if ($core->auth->isSuperAdmin() && !DC_NOT_UPDATE && is_readable(DC_DIGESTS) && 
    99                !$core->auth->user_prefs->dashboard->nodcupdate) 
    100           { 
    101                $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions'); 
    102                $new_v = $updater->check(DC_VERSION); 
    103                $version_info = $new_v ? $updater->getInfoURL() : ''; 
    104  
    105                if ($updater->getNotify() && $new_v) { 
    106                     // Check PHP version required 
    107                     if (version_compare(phpversion(),$updater->getPHPVersion()) >= 0) { 
    108                          $ret = 
    109                          '<div class="dc-update"><h3>'.sprintf(__('Dotclear %s is available!'),$new_v).'</h3> '. 
    110                          '<p><a class="button submit" href="'.$core->adminurl->get("admin.update").'">'.sprintf(__('Upgrade now'),$new_v).'</a> '. 
    111                          '<a class="button" href="'.$core->adminurl->get("admin.update", array('hide_msg' => 1)).'">'.__('Remind me later').'</a>'. 
    112                          ($version_info ? ' </p>'. 
    113                          '<p class="updt-info"><a href="'.$version_info.'">'.__('Information about this version').'</a>' : '').'</p>'. 
    114                          '</div>'; 
    115                     } else { 
    116                          $ret = '<p class="info">'. 
    117                               sprintf(__('A new version of Dotclear is available but needs PHP version ≥ %s, your\'s is currently %s'), 
    118                                    $updater->getPHPVersion(),phpversion()). 
    119                               '</p>'; 
    120                     } 
    121                     $rsp->check = true; 
    122                } else { 
    123                     if (version_compare(phpversion(),DC_NEXT_REQUIRED_PHP,'<')) { 
    124                          $ret = '<p class="info">'. 
    125                               sprintf(__('The next versions of Dotclear will not support PHP version < %s, your\'s is currently %s'), 
    126                                    DC_NEXT_REQUIRED_PHP,phpversion()). 
    127                               '</p>'; 
    128                          $rsp->check = true; 
    129                     } 
    130                } 
    131           } 
    132           $rsp->ret = $ret; 
    133           return $rsp; 
    134      } 
    135  
    136      public static function getPostById($core,$get) 
    137      { 
    138           if (empty($get['id'])) { 
    139                throw new Exception('No post ID'); 
    140           } 
    141  
    142           $params = array('post_id' => (integer) $get['id']); 
    143  
    144           if (isset($get['post_type'])) { 
    145                $params['post_type'] = $get['post_type']; 
    146           } 
    147  
    148           $rs = $core->blog->getPosts($params); 
    149  
    150           if ($rs->isEmpty()) { 
    151                throw new Exception('No post for this ID'); 
    152           } 
    153  
    154           $rsp = new xmlTag('post'); 
    155           $rsp->id = $rs->post_id; 
    156  
    157           $rsp->blog_id($rs->blog_id); 
    158           $rsp->user_id($rs->user_id); 
    159           $rsp->cat_id($rs->cat_id); 
    160           $rsp->post_dt($rs->post_dt); 
    161           $rsp->post_creadt($rs->post_creadt); 
    162           $rsp->post_upddt($rs->post_upddt); 
    163           $rsp->post_format($rs->post_format); 
    164           $rsp->post_url($rs->post_url); 
    165           $rsp->post_lang($rs->post_lang); 
    166           $rsp->post_title($rs->post_title); 
    167           $rsp->post_excerpt($rs->post_excerpt); 
    168           $rsp->post_excerpt_xhtml($rs->post_excerpt_xhtml); 
    169           $rsp->post_content($rs->post_content); 
    170           $rsp->post_content_xhtml($rs->post_content_xhtml); 
    171           $rsp->post_notes($rs->post_notes); 
    172           $rsp->post_status($rs->post_status); 
    173           $rsp->post_selected($rs->post_selected); 
    174           $rsp->post_open_comment($rs->post_open_comment); 
    175           $rsp->post_open_tb($rs->post_open_tb); 
    176           $rsp->nb_comment($rs->nb_comment); 
    177           $rsp->nb_trackback($rs->nb_trackback); 
    178           $rsp->user_name($rs->user_name); 
    179           $rsp->user_firstname($rs->user_firstname); 
    180           $rsp->user_displayname($rs->user_displayname); 
    181           $rsp->user_email($rs->user_email); 
    182           $rsp->user_url($rs->user_url); 
    183           $rsp->cat_title($rs->cat_title); 
    184           $rsp->cat_url($rs->cat_url); 
    185  
    186           $rsp->post_display_content($rs->getContent(true)); 
    187           $rsp->post_display_excerpt($rs->getExcerpt(true)); 
    188  
    189           $metaTag = new xmlTag('meta'); 
    190           if (($meta = @unserialize($rs->post_meta)) !== false) 
    191           { 
    192                foreach ($meta as $K => $V) 
    193                { 
    194                     foreach ($V as $v) { 
    195                          $metaTag->$K($v); 
    196                     } 
    197                } 
    198           } 
    199           $rsp->post_meta($metaTag); 
    200  
    201           return $rsp; 
    202      } 
    203  
    204      public static function getCommentById($core,$get) 
    205      { 
    206           if (empty($get['id'])) { 
    207                throw new Exception('No comment ID'); 
    208           } 
    209  
    210           $rs = $core->blog->getComments(array('comment_id' => (integer) $get['id'])); 
    211  
    212           if ($rs->isEmpty()) { 
    213                throw new Exception('No comment for this ID'); 
    214           } 
    215  
    216           $rsp = new xmlTag('post'); 
    217           $rsp->id = $rs->comment_id; 
    218  
    219           $rsp->comment_dt($rs->comment_dt); 
    220           $rsp->comment_upddt($rs->comment_upddt); 
    221           $rsp->comment_author($rs->comment_author); 
    222           $rsp->comment_site($rs->comment_site); 
    223           $rsp->comment_content($rs->comment_content); 
    224           $rsp->comment_trackback($rs->comment_trackback); 
    225           $rsp->comment_status($rs->comment_status); 
    226           $rsp->post_title($rs->post_title); 
    227           $rsp->post_url($rs->post_url); 
    228           $rsp->post_id($rs->post_id); 
    229           $rsp->post_dt($rs->post_dt); 
    230           $rsp->user_id($rs->user_id); 
    231  
    232           $rsp->comment_display_content($rs->getContent(true)); 
    233  
    234           if ($core->auth->userID()) { 
    235                $rsp->comment_ip($rs->comment_ip); 
    236                $rsp->comment_email($rs->comment_email); 
    237                $rsp->comment_spam_disp(dcAntispam::statusMessage($rs)); 
    238           } 
    239  
    240           return $rsp; 
    241      } 
    242  
    243      public static function quickPost($core,$get,$post) 
    244      { 
    245           # Create category 
    246           if (!empty($post['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) { 
    247  
    248                $cur_cat = $core->con->openCursor($core->prefix.'category'); 
    249                $cur_cat->cat_title = $post['new_cat_title']; 
    250                $cur_cat->cat_url = ''; 
    251  
    252                $parent_cat = !empty($post['new_cat_parent']) ? $post['new_cat_parent'] : ''; 
    253  
    254                # --BEHAVIOR-- adminBeforeCategoryCreate 
    255                $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); 
    256  
    257                $post['cat_id'] = $core->blog->addCategory($cur_cat, (integer) $parent_cat); 
    258  
    259                # --BEHAVIOR-- adminAfterCategoryCreate 
    260                $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $post['cat_id']); 
    261           } 
    262  
    263           $cur = $core->con->openCursor($core->prefix.'post'); 
    264  
    265           $cur->post_title = !empty($post['post_title']) ? $post['post_title'] : ''; 
    266           $cur->user_id = $core->auth->userID(); 
    267           $cur->post_content = !empty($post['post_content']) ? $post['post_content'] : ''; 
    268           $cur->cat_id = !empty($post['cat_id']) ? (integer) $post['cat_id'] : null; 
    269           $cur->post_format = !empty($post['post_format']) ? $post['post_format'] : 'xhtml'; 
    270           $cur->post_lang = !empty($post['post_lang']) ? $post['post_lang'] : ''; 
    271           $cur->post_status = !empty($post['post_status']) ? (integer) $post['post_status'] : 0; 
    272           $cur->post_open_comment = (integer) $core->blog->settings->system->allow_comments; 
    273           $cur->post_open_tb = (integer) $core->blog->settings->system->allow_trackbacks; 
    274  
    275           # --BEHAVIOR-- adminBeforePostCreate 
    276           $core->callBehavior('adminBeforePostCreate',$cur); 
    277  
    278           $return_id = $core->blog->addPost($cur); 
    279  
    280           # --BEHAVIOR-- adminAfterPostCreate 
    281           $core->callBehavior('adminAfterPostCreate',$cur,$return_id); 
    282  
    283           $rsp = new xmlTag('post'); 
    284           $rsp->id = $return_id; 
    285  
    286           $post = $core->blog->getPosts(array('post_id' => $return_id)); 
    287  
    288           $rsp->post_status = $post->post_status; 
    289           $rsp->post_url = $post->getURL(); 
    290           return $rsp; 
    291      } 
    292  
    293      public static function validatePostMarkup($core,$get,$post) 
    294      { 
    295           if (!isset($post['excerpt'])) { 
    296                throw new Exception('No entry excerpt'); 
    297           } 
    298  
    299           if (!isset($post['content'])) { 
    300                throw new Exception('No entry content'); 
    301           } 
    302  
    303           if (empty($post['format'])) { 
    304                throw new Exception('No entry format'); 
    305           } 
    306  
    307           if (!isset($post['lang'])) { 
    308                throw new Exception('No entry lang'); 
    309           } 
    310  
    311           $excerpt = $post['excerpt']; 
    312           $excerpt_xhtml = ''; 
    313           $content = $post['content']; 
    314           $content_xhtml = ''; 
    315           $format = $post['format']; 
    316           $lang = $post['lang']; 
    317  
    318           $core->blog->setPostContent(0,$format,$lang,$excerpt,$excerpt_xhtml,$content,$content_xhtml); 
    319  
    320           $rsp = new xmlTag('result'); 
    321  
    322           $v = htmlValidator::validate($excerpt_xhtml.$content_xhtml); 
    323  
    324           $rsp->valid($v['valid']); 
    325           $rsp->errors($v['errors']); 
    326  
    327           return $rsp; 
    328      } 
    329  
    330      public static function getZipMediaContent($core,$get,$post) 
    331      { 
    332           if (empty($get['id'])) { 
    333                throw new Exception('No media ID'); 
    334           } 
    335  
    336           $id = (integer) $get['id']; 
    337  
    338           if (!$core->auth->check('media,media_admin',$core->blog)) { 
    339                throw new Exception('Permission denied'); 
    340           } 
    341  
    342           try { 
    343                $core->media = new dcMedia($core); 
    344                $file = $core->media->getFile($id); 
    345           } catch (Exception $e) {} 
    346  
    347           if ($file === null || $file->type != 'application/zip' || !$file->editable) { 
    348                throw new Exception('Not a valid file'); 
    349           } 
    350  
    351           $rsp = new xmlTag('result'); 
    352           $content = $core->media->getZipContent($file); 
    353  
    354           foreach ($content as $k => $v) { 
    355                $rsp->file($k); 
    356           } 
    357  
    358           return $rsp; 
    359      } 
    360  
    361      public static function getMeta($core,$get) 
    362      { 
    363           $postid = !empty($get['postId']) ? $get['postId'] : null; 
    364           $limit = !empty($get['limit']) ? $get['limit'] : null; 
    365           $metaId = !empty($get['metaId']) ? $get['metaId'] : null; 
    366           $metaType = !empty($get['metaType']) ? $get['metaType'] : null; 
    367  
    368           $sortby = !empty($get['sortby']) ? $get['sortby'] : 'meta_type,asc'; 
    369  
    370           $rs = $core->meta->getMetadata(array( 
    371                'meta_type' => $metaType, 
    372                'limit' => $limit, 
    373                'meta_id' => $metaId, 
    374                'post_id' => $postid)); 
    375           $rs = $core->meta->computeMetaStats($rs); 
    376  
    377           $sortby = explode(',',$sortby); 
    378           $sort = $sortby[0]; 
    379           $order = isset($sortby[1]) ? $sortby[1] : 'asc'; 
    380  
    381           switch ($sort) { 
    382                case 'metaId': 
    383                     $sort = 'meta_id_lower'; 
    384                     break; 
    385                case 'count': 
    386                     $sort = 'count'; 
    387                     break; 
    388                case 'metaType': 
    389                     $sort = 'meta_type'; 
    390                     break; 
    391                default: 
    392                     $sort = 'meta_type'; 
    393           } 
    394  
    395           $rs->sort($sort,$order); 
    396  
    397           $rsp = new xmlTag(); 
    398  
    399           while ($rs->fetch()) 
    400           { 
    401                $metaTag = new xmlTag('meta'); 
    402                $metaTag->type = $rs->meta_type; 
    403                $metaTag->uri = rawurlencode($rs->meta_id); 
    404                $metaTag->count = $rs->count; 
    405                $metaTag->percent = $rs->percent; 
    406                $metaTag->roundpercent = $rs->roundpercent; 
    407                $metaTag->CDATA($rs->meta_id); 
    408  
    409                $rsp->insertNode($metaTag); 
    410           } 
    411  
    412           return $rsp; 
    413      } 
    414  
    415      public static function setPostMeta($core,$get,$post) 
    416      { 
    417           if (empty($post['postId'])) { 
    418                throw new Exception('No post ID'); 
    419           } 
    420  
    421           if (empty($post['meta']) && $post['meta'] != '0') { 
    422                throw new Exception('No meta'); 
    423           } 
    424  
    425           if (empty($post['metaType'])) { 
    426                throw new Exception('No meta type'); 
    427           } 
    428  
    429           # Get previous meta for post 
    430           $post_meta = $core->meta->getMetadata(array( 
    431                'meta_type' => $post['metaType'], 
    432                'post_id' => $post['postId'])); 
    433           $pm = array(); 
    434           while ($post_meta->fetch()) { 
    435                $pm[] = $post_meta->meta_id; 
    436           } 
    437  
    438           foreach ($core->meta->splitMetaValues($post['meta']) as $m) 
    439           { 
    440                if (!in_array($m,$pm)) { 
    441                     $core->meta->setPostMeta($post['postId'],$post['metaType'],$m); 
    442                } 
    443           } 
    444  
    445           return true; 
    446      } 
    447  
    448      public static function delMeta($core,$get,$post) 
    449      { 
    450           if (empty($post['postId'])) { 
    451                throw new Exception('No post ID'); 
    452           } 
    453  
    454           if (empty($post['metaId']) && $post['metaId'] != '0') { 
    455                throw new Exception('No meta ID'); 
    456           } 
    457  
    458           if (empty($post['metaType'])) { 
    459                throw new Exception('No meta type'); 
    460           } 
    461  
    462           $core->meta->delPostMeta($post['postId'],$post['metaType'],$post['metaId']); 
    463  
    464           return true; 
    465      } 
    466  
    467      public static function searchMeta($core,$get) 
    468      { 
    469           $q = !empty($get['q']) ? $get['q'] : null; 
    470           $metaType = !empty($get['metaType']) ? $get['metaType'] : null; 
    471  
    472           $sortby = !empty($get['sortby']) ? $get['sortby'] : 'meta_type,asc'; 
    473  
    474           $rs = $core->meta->getMetadata(array('meta_type' => $metaType)); 
    475           $rs = $core->meta->computeMetaStats($rs); 
    476  
    477           $sortby = explode(',',$sortby); 
    478           $sort = $sortby[0]; 
    479           $order = isset($sortby[1]) ? $sortby[1] : 'asc'; 
    480  
    481           switch ($sort) { 
    482                case 'metaId': 
    483                     $sort = 'meta_id_lower'; 
    484                     break; 
    485                case 'count': 
    486                     $sort = 'count'; 
    487                     break; 
    488                case 'metaType': 
    489                     $sort = 'meta_type'; 
    490                     break; 
    491                default: 
    492                     $sort = 'meta_type'; 
    493           } 
    494  
    495           $rs->sort($sort,$order); 
    496  
    497           $rsp = new xmlTag(); 
    498  
    499           while ($rs->fetch()) 
    500           { 
    501                if (stripos($rs->meta_id,$q) === 0) { 
    502                     $metaTag = new xmlTag('meta'); 
    503                     $metaTag->type = $rs->meta_type; 
    504                     $metaTag->uri = rawurlencode($rs->meta_id); 
    505                     $metaTag->count = $rs->count; 
    506                     $metaTag->percent = $rs->percent; 
    507                     $metaTag->roundpercent = $rs->roundpercent; 
    508                     $metaTag->CDATA($rs->meta_id); 
    509  
    510                     $rsp->insertNode($metaTag); 
    511                } 
    512           } 
    513  
    514           return $rsp; 
    515      } 
    516  
    517      public static function setSectionFold($core,$get,$post) 
    518      { 
    519           if (empty($post['section'])) { 
    520                throw new Exception('No section name'); 
    521           } 
    522           if ($core->auth->user_prefs->toggles === null) { 
    523                $core->auth->user_prefs->addWorkspace('toggles'); 
    524           } 
    525           $section = $post['section']; 
    526           $status = isset($post['value']) && ($post['value'] != 0); 
    527           if ($core->auth->user_prefs->toggles->prefExists('unfolded_sections')) { 
    528                $toggles = explode(',',trim($core->auth->user_prefs->toggles->unfolded_sections)); 
    529           } else { 
    530                $toggles = array(); 
    531           } 
    532           $k = array_search($section,$toggles); 
    533           if ($status) { // true == Fold section ==> remove it from unfolded list 
    534                if ($k !== false) { 
    535                     unset($toggles[$k]); 
    536                } 
    537           } else { // false == unfold section ==> add it to unfolded list 
    538                if ($k === false) { 
    539                     $toggles[]=$section; 
    540                }; 
    541           } 
    542           $core->auth->user_prefs->toggles->put('unfolded_sections',join(',',$toggles)); 
    543           return true; 
    544      } 
    545  
    546      public static function getModuleById($core, $get, $post) 
    547      { 
    548           if (empty($get['id'])) { 
    549                throw new Exception('No module ID'); 
    550           } 
    551           if (empty($get['list'])) { 
    552                throw new Exception('No list ID'); 
    553           } 
    554  
    555           $id = $get['id']; 
    556           $list = $get['list']; 
    557           $module = array(); 
    558  
    559           if ($list == 'plugin-activate') { 
    560                $modules = $core->plugins->getModules(); 
    561                if (empty($modules) || !isset($modules[$id])) { 
    562                     throw new Exception('Unknow module ID'); 
    563                } 
    564                $module = $modules[$id]; 
    565           } 
    566           elseif ($list == 'plugin-new') { 
    567                $store = new dcStore( 
    568                     $core->plugins, 
    569                     $core->blog->settings->system->store_plugin_url 
    570                ); 
    571                $store->check(); 
    572  
    573                $modules = $store->get(); 
    574                if (empty($modules) || !isset($modules[$id])) { 
    575                     throw new Exception('Unknow module ID'); 
    576                } 
    577                $module = $modules[$id]; 
    578           } 
    579           else { 
    580                // behavior not implemented yet 
    581           } 
    582  
    583           if (empty($module)) { 
    584                throw new Exception('Unknow module ID'); 
    585           } 
    586  
    587           $module = adminModulesList::sanitizeModule($id, $module); 
    588  
    589           $rsp = new xmlTag('module'); 
    590           $rsp->id = $id; 
    591  
    592           foreach($module as $k => $v) { 
    593                $rsp->{$k}((string) $v); 
    594           } 
    595  
    596           return $rsp; 
    597      } 
     38    public static function checkNewsUpdate($core, $get) 
     39    { 
     40        # Dotclear news 
     41 
     42        $rsp        = new xmlTag('news'); 
     43        $rsp->check = false; 
     44        $ret        = __('Dotclear news not available'); 
     45 
     46        if ($core->auth->user_prefs->dashboard->dcnews) { 
     47            try 
     48            { 
     49 
     50                if (empty($GLOBALS['__resources']['rss_news'])) { 
     51                    throw new Exception(); 
     52                } 
     53                $feed_reader = new feedReader; 
     54                $feed_reader->setCacheDir(DC_TPL_CACHE); 
     55                $feed_reader->setTimeout(2); 
     56                $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/'); 
     57                $feed = $feed_reader->parse($GLOBALS['__resources']['rss_news']); 
     58                if ($feed) { 
     59                    $ret = '<div class="box medium dc-box"><h3>' . __('Dotclear news') . '</h3><dl id="news">'; 
     60                    $i   = 1; 
     61                    foreach ($feed->items as $item) { 
     62                        $dt = isset($item->link) ? '<a href="' . $item->link . '" class="outgoing" title="' . $item->title . '">' . 
     63                        $item->title . ' <img src="images/outgoing-blue.png" alt="" /></a>' : $item->title; 
     64 
     65                        if ($i < 3) { 
     66                            $ret .= 
     67                            '<dt>' . $dt . '</dt>' . 
     68                            '<dd><p><strong>' . dt::dt2str(__('%d %B %Y:'), $item->pubdate, 'Europe/Paris') . '</strong> ' . 
     69                            '<em>' . text::cutString(html::clean($item->content), 120) . '...</em></p></dd>'; 
     70                        } else { 
     71                            $ret .= 
     72                            '<dt>' . $dt . '</dt>' . 
     73                            '<dd>' . dt::dt2str(__('%d %B %Y:'), $item->pubdate, 'Europe/Paris') . '</dd>'; 
     74                        } 
     75                        $i++; 
     76                        if ($i > 2) {break;} 
     77                    } 
     78                    $ret .= '</dl></div>'; 
     79                    $rsp->check = true; 
     80                } 
     81            } catch (Exception $e) {} 
     82        } 
     83        $rsp->ret = $ret; 
     84        return $rsp; 
     85    } 
     86 
     87    public static function checkCoreUpdate($core, $get) 
     88    { 
     89        # Dotclear updates notifications 
     90 
     91        $rsp        = new xmlTag('update'); 
     92        $rsp->check = false; 
     93        $ret        = __('Dotclear update not available'); 
     94 
     95        if ($core->auth->isSuperAdmin() && !DC_NOT_UPDATE && is_readable(DC_DIGESTS) && 
     96            !$core->auth->user_prefs->dashboard->nodcupdate) { 
     97            $updater      = new dcUpdate(DC_UPDATE_URL, 'dotclear', DC_UPDATE_VERSION, DC_TPL_CACHE . '/versions'); 
     98            $new_v        = $updater->check(DC_VERSION); 
     99            $version_info = $new_v ? $updater->getInfoURL() : ''; 
     100 
     101            if ($updater->getNotify() && $new_v) { 
     102                // Check PHP version required 
     103                if (version_compare(phpversion(), $updater->getPHPVersion()) >= 0) { 
     104                    $ret = 
     105                    '<div class="dc-update"><h3>' . sprintf(__('Dotclear %s is available!'), $new_v) . '</h3> ' . 
     106                    '<p><a class="button submit" href="' . $core->adminurl->get("admin.update") . '">' . sprintf(__('Upgrade now'), $new_v) . '</a> ' . 
     107                    '<a class="button" href="' . $core->adminurl->get("admin.update", array('hide_msg' => 1)) . '">' . __('Remind me later') . '</a>' . 
     108                        ($version_info ? ' </p>' . 
     109                        '<p class="updt-info"><a href="' . $version_info . '">' . __('Information about this version') . '</a>' : '') . '</p>' . 
     110                        '</div>'; 
     111                } else { 
     112                    $ret = '<p class="info">' . 
     113                    sprintf(__('A new version of Dotclear is available but needs PHP version ≥ %s, your\'s is currently %s'), 
     114                        $updater->getPHPVersion(), phpversion()) . 
     115                        '</p>'; 
     116                } 
     117                $rsp->check = true; 
     118            } else { 
     119                if (version_compare(phpversion(), DC_NEXT_REQUIRED_PHP, '<')) { 
     120                    $ret = '<p class="info">' . 
     121                    sprintf(__('The next versions of Dotclear will not support PHP version < %s, your\'s is currently %s'), 
     122                        DC_NEXT_REQUIRED_PHP, phpversion()) . 
     123                        '</p>'; 
     124                    $rsp->check = true; 
     125                } 
     126            } 
     127        } 
     128        $rsp->ret = $ret; 
     129        return $rsp; 
     130    } 
     131 
     132    public static function getPostById($core, $get) 
     133    { 
     134        if (empty($get['id'])) { 
     135            throw new Exception('No post ID'); 
     136        } 
     137 
     138        $params = array('post_id' => (integer) $get['id']); 
     139 
     140        if (isset($get['post_type'])) { 
     141            $params['post_type'] = $get['post_type']; 
     142        } 
     143 
     144        $rs = $core->blog->getPosts($params); 
     145 
     146        if ($rs->isEmpty()) { 
     147            throw new Exception('No post for this ID'); 
     148        } 
     149 
     150        $rsp     = new xmlTag('post'); 
     151        $rsp->id = $rs->post_id; 
     152 
     153        $rsp->blog_id($rs->blog_id); 
     154        $rsp->user_id($rs->user_id); 
     155        $rsp->cat_id($rs->cat_id); 
     156        $rsp->post_dt($rs->post_dt); 
     157        $rsp->post_creadt($rs->post_creadt); 
     158        $rsp->post_upddt($rs->post_upddt); 
     159        $rsp->post_format($rs->post_format); 
     160        $rsp->post_url($rs->post_url); 
     161        $rsp->post_lang($rs->post_lang); 
     162        $rsp->post_title($rs->post_title); 
     163        $rsp->post_excerpt($rs->post_excerpt); 
     164        $rsp->post_excerpt_xhtml($rs->post_excerpt_xhtml); 
     165        $rsp->post_content($rs->post_content); 
     166        $rsp->post_content_xhtml($rs->post_content_xhtml); 
     167        $rsp->post_notes($rs->post_notes); 
     168        $rsp->post_status($rs->post_status); 
     169        $rsp->post_selected($rs->post_selected); 
     170        $rsp->post_open_comment($rs->post_open_comment); 
     171        $rsp->post_open_tb($rs->post_open_tb); 
     172        $rsp->nb_comment($rs->nb_comment); 
     173        $rsp->nb_trackback($rs->nb_trackback); 
     174        $rsp->user_name($rs->user_name); 
     175        $rsp->user_firstname($rs->user_firstname); 
     176        $rsp->user_displayname($rs->user_displayname); 
     177        $rsp->user_email($rs->user_email); 
     178        $rsp->user_url($rs->user_url); 
     179        $rsp->cat_title($rs->cat_title); 
     180        $rsp->cat_url($rs->cat_url); 
     181 
     182        $rsp->post_display_content($rs->getContent(true)); 
     183        $rsp->post_display_excerpt($rs->getExcerpt(true)); 
     184 
     185        $metaTag = new xmlTag('meta'); 
     186        if (($meta = @unserialize($rs->post_meta)) !== false) { 
     187            foreach ($meta as $K => $V) { 
     188                foreach ($V as $v) { 
     189                    $metaTag->$K($v); 
     190                } 
     191            } 
     192        } 
     193        $rsp->post_meta($metaTag); 
     194 
     195        return $rsp; 
     196    } 
     197 
     198    public static function getCommentById($core, $get) 
     199    { 
     200        if (empty($get['id'])) { 
     201            throw new Exception('No comment ID'); 
     202        } 
     203 
     204        $rs = $core->blog->getComments(array('comment_id' => (integer) $get['id'])); 
     205 
     206        if ($rs->isEmpty()) { 
     207            throw new Exception('No comment for this ID'); 
     208        } 
     209 
     210        $rsp     = new xmlTag('post'); 
     211        $rsp->id = $rs->comment_id; 
     212 
     213        $rsp->comment_dt($rs->comment_dt); 
     214        $rsp->comment_upddt($rs->comment_upddt); 
     215        $rsp->comment_author($rs->comment_author); 
     216        $rsp->comment_site($rs->comment_site); 
     217        $rsp->comment_content($rs->comment_content); 
     218        $rsp->comment_trackback($rs->comment_trackback); 
     219        $rsp->comment_status($rs->comment_status); 
     220        $rsp->post_title($rs->post_title); 
     221        $rsp->post_url($rs->post_url); 
     222        $rsp->post_id($rs->post_id); 
     223        $rsp->post_dt($rs->post_dt); 
     224        $rsp->user_id($rs->user_id); 
     225 
     226        $rsp->comment_display_content($rs->getContent(true)); 
     227 
     228        if ($core->auth->userID()) { 
     229            $rsp->comment_ip($rs->comment_ip); 
     230            $rsp->comment_email($rs->comment_email); 
     231            $rsp->comment_spam_disp(dcAntispam::statusMessage($rs)); 
     232        } 
     233 
     234        return $rsp; 
     235    } 
     236 
     237    public static function quickPost($core, $get, $post) 
     238    { 
     239        # Create category 
     240        if (!empty($post['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) { 
     241 
     242            $cur_cat            = $core->con->openCursor($core->prefix . 'category'); 
     243            $cur_cat->cat_title = $post['new_cat_title']; 
     244            $cur_cat->cat_url   = ''; 
     245 
     246            $parent_cat = !empty($post['new_cat_parent']) ? $post['new_cat_parent'] : ''; 
     247 
     248            # --BEHAVIOR-- adminBeforeCategoryCreate 
     249            $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); 
     250 
     251            $post['cat_id'] = $core->blog->addCategory($cur_cat, (integer) $parent_cat); 
     252 
     253            # --BEHAVIOR-- adminAfterCategoryCreate 
     254            $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $post['cat_id']); 
     255        } 
     256 
     257        $cur = $core->con->openCursor($core->prefix . 'post'); 
     258 
     259        $cur->post_title        = !empty($post['post_title']) ? $post['post_title'] : ''; 
     260        $cur->user_id           = $core->auth->userID(); 
     261        $cur->post_content      = !empty($post['post_content']) ? $post['post_content'] : ''; 
     262        $cur->cat_id            = !empty($post['cat_id']) ? (integer) $post['cat_id'] : null; 
     263        $cur->post_format       = !empty($post['post_format']) ? $post['post_format'] : 'xhtml'; 
     264        $cur->post_lang         = !empty($post['post_lang']) ? $post['post_lang'] : ''; 
     265        $cur->post_status       = !empty($post['post_status']) ? (integer) $post['post_status'] : 0; 
     266        $cur->post_open_comment = (integer) $core->blog->settings->system->allow_comments; 
     267        $cur->post_open_tb      = (integer) $core->blog->settings->system->allow_trackbacks; 
     268 
     269        # --BEHAVIOR-- adminBeforePostCreate 
     270        $core->callBehavior('adminBeforePostCreate', $cur); 
     271 
     272        $return_id = $core->blog->addPost($cur); 
     273 
     274        # --BEHAVIOR-- adminAfterPostCreate 
     275        $core->callBehavior('adminAfterPostCreate', $cur, $return_id); 
     276 
     277        $rsp     = new xmlTag('post'); 
     278        $rsp->id = $return_id; 
     279 
     280        $post = $core->blog->getPosts(array('post_id' => $return_id)); 
     281 
     282        $rsp->post_status = $post->post_status; 
     283        $rsp->post_url    = $post->getURL(); 
     284        return $rsp; 
     285    } 
     286 
     287    public static function validatePostMarkup($core, $get, $post) 
     288    { 
     289        if (!isset($post['excerpt'])) { 
     290            throw new Exception('No entry excerpt'); 
     291        } 
     292 
     293        if (!isset($post['content'])) { 
     294            throw new Exception('No entry content'); 
     295        } 
     296 
     297        if (empty($post['format'])) { 
     298            throw new Exception('No entry format'); 
     299        } 
     300 
     301        if (!isset($post['lang'])) { 
     302            throw new Exception('No entry lang'); 
     303        } 
     304 
     305        $excerpt       = $post['excerpt']; 
     306        $excerpt_xhtml = ''; 
     307        $content       = $post['content']; 
     308        $content_xhtml = ''; 
     309        $format        = $post['format']; 
     310        $lang          = $post['lang']; 
     311 
     312        $core->blog->setPostContent(0, $format, $lang, $excerpt, $excerpt_xhtml, $content, $content_xhtml); 
     313 
     314        $rsp = new xmlTag('result'); 
     315 
     316        $v = htmlValidator::validate($excerpt_xhtml . $content_xhtml); 
     317 
     318        $rsp->valid($v['valid']); 
     319        $rsp->errors($v['errors']); 
     320 
     321        return $rsp; 
     322    } 
     323 
     324    public static function getZipMediaContent($core, $get, $post) 
     325    { 
     326        if (empty($get['id'])) { 
     327            throw new Exception('No media ID'); 
     328        } 
     329 
     330        $id = (integer) $get['id']; 
     331 
     332        if (!$core->auth->check('media,media_admin', $core->blog)) { 
     333            throw new Exception('Permission denied'); 
     334        } 
     335 
     336        try { 
     337            $core->media = new dcMedia($core); 
     338            $file        = $core->media->getFile($id); 
     339        } catch (Exception $e) {} 
     340 
     341        if ($file === null || $file->type != 'application/zip' || !$file->editable) { 
     342            throw new Exception('Not a valid file'); 
     343        } 
     344 
     345        $rsp     = new xmlTag('result'); 
     346        $content = $core->media->getZipContent($file); 
     347 
     348        foreach ($content as $k => $v) { 
     349            $rsp->file($k); 
     350        } 
     351 
     352        return $rsp; 
     353    } 
     354 
     355    public static function getMeta($core, $get) 
     356    { 
     357        $postid   = !empty($get['postId']) ? $get['postId'] : null; 
     358        $limit    = !empty($get['limit']) ? $get['limit'] : null; 
     359        $metaId   = !empty($get['metaId']) ? $get['metaId'] : null; 
     360        $metaType = !empty($get['metaType']) ? $get['metaType'] : null; 
     361 
     362        $sortby = !empty($get['sortby']) ? $get['sortby'] : 'meta_type,asc'; 
     363 
     364        $rs = $core->meta->getMetadata(array( 
     365            'meta_type' => $metaType, 
     366            'limit'     => $limit, 
     367            'meta_id'   => $metaId, 
     368            'post_id'   => $postid)); 
     369        $rs = $core->meta->computeMetaStats($rs); 
     370 
     371        $sortby = explode(',', $sortby); 
     372        $sort   = $sortby[0]; 
     373        $order  = isset($sortby[1]) ? $sortby[1] : 'asc'; 
     374 
     375        switch ($sort) { 
     376            case 'metaId': 
     377                $sort = 'meta_id_lower'; 
     378                break; 
     379            case 'count': 
     380                $sort = 'count'; 
     381                break; 
     382            case 'metaType': 
     383                $sort = 'meta_type'; 
     384                break; 
     385            default: 
     386                $sort = 'meta_type'; 
     387        } 
     388 
     389        $rs->sort($sort, $order); 
     390 
     391        $rsp = new xmlTag(); 
     392 
     393        while ($rs->fetch()) { 
     394            $metaTag               = new xmlTag('meta'); 
     395            $metaTag->type         = $rs->meta_type; 
     396            $metaTag->uri          = rawurlencode($rs->meta_id); 
     397            $metaTag->count        = $rs->count; 
     398            $metaTag->percent      = $rs->percent; 
     399            $metaTag->roundpercent = $rs->roundpercent; 
     400            $metaTag->CDATA($rs->meta_id); 
     401 
     402            $rsp->insertNode($metaTag); 
     403        } 
     404 
     405        return $rsp; 
     406    } 
     407 
     408    public static function setPostMeta($core, $get, $post) 
     409    { 
     410        if (empty($post['postId'])) { 
     411            throw new Exception('No post ID'); 
     412        } 
     413 
     414        if (empty($post['meta']) && $post['meta'] != '0') { 
     415            throw new Exception('No meta'); 
     416        } 
     417 
     418        if (empty($post['metaType'])) { 
     419            throw new Exception('No meta type'); 
     420        } 
     421 
     422        # Get previous meta for post 
     423        $post_meta = $core->meta->getMetadata(array( 
     424            'meta_type' => $post['metaType'], 
     425            'post_id'   => $post['postId'])); 
     426        $pm = array(); 
     427        while ($post_meta->fetch()) { 
     428            $pm[] = $post_meta->meta_id; 
     429        } 
     430 
     431        foreach ($core->meta->splitMetaValues($post['meta']) as $m) { 
     432            if (!in_array($m, $pm)) { 
     433                $core->meta->setPostMeta($post['postId'], $post['metaType'], $m); 
     434            } 
     435        } 
     436 
     437        return true; 
     438    } 
     439 
     440    public static function delMeta($core, $get, $post) 
     441    { 
     442        if (empty($post['postId'])) { 
     443            throw new Exception('No post ID'); 
     444        } 
     445 
     446        if (empty($post['metaId']) && $post['metaId'] != '0') { 
     447            throw new Exception('No meta ID'); 
     448        } 
     449 
     450        if (empty($post['metaType'])) { 
     451            throw new Exception('No meta type'); 
     452        } 
     453 
     454        $core->meta->delPostMeta($post['postId'], $post['metaType'], $post['metaId']); 
     455 
     456        return true; 
     457    } 
     458 
     459    public static function searchMeta($core, $get) 
     460    { 
     461        $q        = !empty($get['q']) ? $get['q'] : null; 
     462        $metaType = !empty($get['metaType']) ? $get['metaType'] : null; 
     463 
     464        $sortby = !empty($get['sortby']) ? $get['sortby'] : 'meta_type,asc'; 
     465 
     466        $rs = $core->meta->getMetadata(array('meta_type' => $metaType)); 
     467        $rs = $core->meta->computeMetaStats($rs); 
     468 
     469        $sortby = explode(',', $sortby); 
     470        $sort   = $sortby[0]; 
     471        $order  = isset($sortby[1]) ? $sortby[1] : 'asc'; 
     472 
     473        switch ($sort) { 
     474            case 'metaId': 
     475                $sort = 'meta_id_lower'; 
     476                break; 
     477            case 'count': 
     478                $sort = 'count'; 
     479                break; 
     480            case 'metaType': 
     481                $sort = 'meta_type'; 
     482                break; 
     483            default: 
     484                $sort = 'meta_type'; 
     485        } 
     486 
     487        $rs->sort($sort, $order); 
     488 
     489        $rsp = new xmlTag(); 
     490 
     491        while ($rs->fetch()) { 
     492            if (stripos($rs->meta_id, $q) === 0) { 
     493                $metaTag               = new xmlTag('meta'); 
     494                $metaTag->type         = $rs->meta_type; 
     495                $metaTag->uri          = rawurlencode($rs->meta_id); 
     496                $metaTag->count        = $rs->count; 
     497                $metaTag->percent      = $rs->percent; 
     498                $metaTag->roundpercent = $rs->roundpercent; 
     499                $metaTag->CDATA($rs->meta_id); 
     500 
     501                $rsp->insertNode($metaTag); 
     502            } 
     503        } 
     504 
     505        return $rsp; 
     506    } 
     507 
     508    public static function setSectionFold($core, $get, $post) 
     509    { 
     510        if (empty($post['section'])) { 
     511            throw new Exception('No section name'); 
     512        } 
     513        if ($core->auth->user_prefs->toggles === null) { 
     514            $core->auth->user_prefs->addWorkspace('toggles'); 
     515        } 
     516        $section = $post['section']; 
     517        $status  = isset($post['value']) && ($post['value'] != 0); 
     518        if ($core->auth->user_prefs->toggles->prefExists('unfolded_sections')) { 
     519            $toggles = explode(',', trim($core->auth->user_prefs->toggles->unfolded_sections)); 
     520        } else { 
     521            $toggles = array(); 
     522        } 
     523        $k = array_search($section, $toggles); 
     524        if ($status) { 
     525            // true == Fold section ==> remove it from unfolded list 
     526            if ($k !== false) { 
     527                unset($toggles[$k]); 
     528            } 
     529        } else { 
     530            // false == unfold section ==> add it to unfolded list 
     531            if ($k === false) { 
     532                $toggles[] = $section; 
     533            }; 
     534        } 
     535        $core->auth->user_prefs->toggles->put('unfolded_sections', join(',', $toggles)); 
     536        return true; 
     537    } 
     538 
     539    public static function getModuleById($core, $get, $post) 
     540    { 
     541        if (empty($get['id'])) { 
     542            throw new Exception('No module ID'); 
     543        } 
     544        if (empty($get['list'])) { 
     545            throw new Exception('No list ID'); 
     546        } 
     547 
     548        $id     = $get['id']; 
     549        $list   = $get['list']; 
     550        $module = array(); 
     551 
     552        if ($list == 'plugin-activate') { 
     553            $modules = $core->plugins->getModules(); 
     554            if (empty($modules) || !isset($modules[$id])) { 
     555                throw new Exception('Unknow module ID'); 
     556            } 
     557            $module = $modules[$id]; 
     558        } elseif ($list == 'plugin-new') { 
     559            $store = new dcStore( 
     560                $core->plugins, 
     561                $core->blog->settings->system->store_plugin_url 
     562            ); 
     563            $store->check(); 
     564 
     565            $modules = $store->get(); 
     566            if (empty($modules) || !isset($modules[$id])) { 
     567                throw new Exception('Unknow module ID'); 
     568            } 
     569            $module = $modules[$id]; 
     570        } else { 
     571            // behavior not implemented yet 
     572        } 
     573 
     574        if (empty($module)) { 
     575            throw new Exception('Unknow module ID'); 
     576        } 
     577 
     578        $module = adminModulesList::sanitizeModule($id, $module); 
     579 
     580        $rsp     = new xmlTag('module'); 
     581        $rsp->id = $id; 
     582 
     583        foreach ($module as $k => $v) { 
     584            $rsp->{$k}((string) $v); 
     585        } 
     586 
     587        return $rsp; 
     588    } 
    598589} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map