Dotclear


Ignore:
Timestamp:
01/10/11 21:27:04 (13 years ago)
Author:
kemar
Message:

Réorganisation code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/subscription/_public.php

    r2842 r2851  
    1616# ***** END LICENSE BLOCK ***** 
    1717 
     18 
    1819$core->url->register('subscription','subscribe','^subscribe(/(.*))?$',array('urlSubscription','create')); 
    1920 
     21$core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); 
     22 
    2023$core->tpl->addBlock('SubscriptionIf',array('tplSubscription','SubscriptionIf')); 
     24 
    2125$core->tpl->addValue('SubscriptionURL',array('tplSubscription','SubscriptionURL')); 
    2226$core->tpl->addValue('SubscriptionMsgSuccess',array('tplSubscription','SubscriptionMsgSuccess')); 
     
    7983               } 
    8084                
    81            
    8285               try 
    8386               { 
     87                    # Checks provided fields 
     88                    if (empty($_POST['s_name'])) { 
     89                         throw new Exception(__('You must provide a name.')); 
     90                    } 
     91                     
     92                    if (!text::isEmail($_POST['s_mail'])) { 
     93                         throw new Exception(__('You must provide a valid email address.')); 
     94                    } 
     95                     
     96                    if (empty($_POST['s_login'])) { 
     97                         throw new Exception(__('You must provide a login.')); 
     98                    } 
     99                     
     100                    if (empty($_POST['s_password'])) { 
     101                         throw new Exception(__('You must provide a password.')); 
     102                    } 
     103                     
     104                    if ($_POST['s_password_confirm'] !== $_POST['s_password']) { 
     105                         throw new Exception(__("Passwords don't match")); 
     106                    } 
     107                     
     108                    if (empty($_POST['s_blog_name'])) { 
     109                         throw new Exception(__('You must provide a name for you blog.')); 
     110                    } 
     111                     
     112                    if (empty($_POST['s_blog_url'])) { 
     113                         throw new Exception(__('You must provide an url for your blog.')); 
     114                    } 
     115                     
    84116                    $_ctx->subscription['name'] = preg_replace('/[\n\r]/','',$_POST['s_name']); 
    85117                    $_ctx->subscription['mail'] = preg_replace('/[\n\r]/','',$_POST['s_mail']); 
     
    89121                    $_ctx->subscription['blog_name'] = preg_replace('/[\n\r]/','',$_POST['s_blog_name']); 
    90122                    $_ctx->subscription['blog_url'] = preg_replace('/[\n\r]/','',$_POST['s_blog_url']); 
    91                                     
    92                     # Checks provided fields 
    93                     if (empty($_POST['s_name'])) { 
    94                          throw new Exception(__('You must provide a name.')); 
    95                     } 
    96                      
    97                     if (!text::isEmail($_POST['s_mail'])) { 
    98                          throw new Exception(__('You must provide a valid email address.')); 
    99                     } 
    100                      
    101                     if (empty($_POST['s_login'])) { 
    102                          throw new Exception(__('You must provide a login.')); 
    103                     } 
    104                      
    105                     if (empty($_POST['s_password'])) { 
    106                          throw new Exception(__('You must provide a password.')); 
    107                     } 
    108                      
    109                     if ($_POST['s_password_confirm'] !== $_POST['s_password']) { 
    110                          throw new Exception(__("Passwords don't match")); 
    111                     } 
    112                      
    113                     if (empty($_POST['s_blog_name'])) { 
    114                          throw new Exception(__('You must provide a name for you blog.')); 
    115                     } 
    116                      
    117                     if (empty($_POST['s_blog_url'])) { 
    118                          throw new Exception(__('You must provide an url for your blog.')); 
    119                     } 
    120                      
    121                     //creating user and blog 
    122                     $core->blog->settings->setNamespace('subscription2'); 
    123                     $blogs_folder_path = $core->blog->settings->get('blogs_folder_path');  
    124                     $dotclear_folder_path = $core->blog->settings->get('dotclear_folder_path');      
    125                      
    126                      
    127                     if($core->userExists($_ctx->subscription['login'])) { 
    128                          throw new Exception(__('User already exists')); 
    129                     } 
    130                      
    131                     if($core->blogExists($_ctx->subscription['blog_url'])) { 
    132                          throw new Exception(__('A blog already exists at this URL')); 
    133                     } 
    134                      
    135                      
    136                     //augmentation des droits TODO : changer admin par un recuperation de login 
    137                     $core->auth->checkUser('marc'); 
    138                      
    139                     //user 
    140                     $cur = $core->con->openCursor($core->prefix.'user'); 
    141  
    142                     $cur->user_id = $_ctx->subscription['login']; 
    143                     $cur->user_super = 0;   
    144                     $cur->user_email = $_ctx->subscription['mail']; 
    145                     $cur->user_pwd = $_ctx->subscription['password']; 
    146                      
    147                     if (!preg_match('/^[A-Za-z0-9._-]{2,}$/',$cur->user_id)) { 
    148                          throw new Exception(__('User ID must contain at least 2 characters using letters, numbers or symbols.')); 
    149                     } 
    150                     if ($cur->user_creadt === null) { 
    151                          $cur->user_creadt = array('NOW()'); 
    152                     } 
    153                 
    154                     //$cur->insert(); 
    155                     $core->addUser($cur); 
    156                      
    157                      
    158                     //blog 
    159                      
    160                     $root_url = 'http://'.$_ctx->subscription['blog_url'].'.'.self::getDomainName().'/'; 
    161                      
    162                     $cur = $core->con->openCursor($core->prefix.'blog'); 
    163                 
    164                     $cur->blog_id = $_ctx->subscription['blog_url']; 
    165                     $cur->blog_url = $root_url.'index.php/'; 
    166                     $cur->blog_name = $_ctx->subscription['blog_name']; 
    167                      
    168                     $core->addBlog($cur); 
    169       
    170                     //permissions du blog 
    171                      
    172                     $core->setUserBlogPermissions($_ctx->subscription['login'], $_ctx->subscription['blog_url'],  array('admin'=>1, 'blogroll'=>1), true); 
    173       
    174                     $core->blogDefaults($cur->blog_id); 
    175  
    176                     $blog_settings = new dcSettings($core,$_ctx->subscription['blog_url']); 
    177                     $blog_settings->setNameSpace('system'); 
    178                     $blog_settings->put('lang',http::getAcceptLanguage()); 
    179                      
    180                     $blog_settings->put('themes_path',$core->blog->themes_path); 
    181                     $blog_settings->put('themes_url',$core->blog->themes_path); //TODO : injection via la config 
    182                      
    183                     //creating blog folder and index.php file 
    184                     $path = $blogs_folder_path.$_ctx->subscription['blog_url']; 
    185                     if(!file_exists($path)){ 
    186                          mkdir ($path); 
    187                          chmod ($path, 0755); 
    188                          mkdir ($path."/public"); 
    189                          chmod ($path."/public", 0755); 
    190                     } 
    191                      
    192                     file_put_contents($path.'/index.php',"<?php\n\n". 
    193                          "define('DC_BLOG_ID','".$_ctx->subscription['blog_url']."'); # identifiant du blog\n". 
    194                          "require '".realpath($dotclear_folder_path.'/inc/public/prepend.php')."';\n\n?>");   //TODO : param dans la conf pour le path de dotclear 
    195                      
    196                      
    197                                          
     123                     
     124                    Subscription::subscribe($_ctx->subscription); 
     125                     
    198126                    http::redirect($core->blog->url.$core->url->getBase('subscription2').'/created'); 
    199127               } 
     
    206134          } 
    207135                
    208           $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); 
    209136          self::serveDocument('new_blog.html'); 
    210137          exit; 
     
    241168     { 
    242169          $f = $GLOBALS['core']->tpl->getFilters($attr); 
    243           return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getBase("subscription2")').'; ?>'; 
     170          return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getBase("subscription")').'; ?>'; 
    244171     } 
    245172      
     
    259186     public static function SubscriptionDomainName() { 
    260187          $domain_name = urlSubscription::getDomainName();   
    261           return "<?php echo $domain_name; ?>"; 
     188          return "<?php echo '$domain_name'; ?>"; 
    262189     } 
    263190      
Note: See TracChangeset for help on using the changeset viewer.

Sites map