Changeset 35

Show
Ignore:
Timestamp:
09/26/07 17:45:24 (1 year ago)
Author:
bermi
Message:

Finishing form behaviour implementation

Closing ticket #8. Changing the language of an existing Page is not allowed not. If allowed it will break pages nested set integrity.

Reffactoring setup an login message.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/includes/editam/behaviours/form_behaviour.php

    r2 r35  
    3434// +----------------------------------------------------------------------+ 
    3535 
     36defined('AK_EMAIL_REGULAR_EXPRESSION') ? null : define('AK_EMAIL_REGULAR_EXPRESSION',"/^([a-z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-z0-9\-]+\.)+))([a-z]{2,4}|[0-9]{1,3})(\]?)$/i"); 
     37 
    3638class FormBehaviour extends BaseBehaviour 
    3739{ 
     
    4446    function isPageVirtual() 
    4547    { 
    46         return true; 
     48        return false; 
    4749    } 
    4850 
     
    6668        $errors = array(); 
    6769        if(count($post)){ 
    68             define('AK_EMAIL_REGULAR_EXPRESSION',"/^([a-z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-z0-9\-]+\.)+))([a-z]{2,4}|[0-9]{1,3})(\]?)$/i"); 
    69             if(empty($post['email']) || !preg_match(AK_EMAIL_REGULAR_EXPRESSION,$post['email'])){ 
     70            $email = $this->getSenderEmail(); 
     71            if(empty($email) || !preg_match(AK_EMAIL_REGULAR_EXPRESSION,$email)){ 
    7072                $errors['email'] = Ak::t("Please insert a valid email.", array(), 'form_behaviour'); 
    7173            } 
    7274        } 
    73  
    7475        if(count($post) && count($errors) == 0){ 
    7576            $message = ''; 
     
    7879                $message .= ucfirst(str_replace("_"," ",$k)).": ".stripslashes($v)."\r\n"; 
    7980            } 
    80             $this->Controller->form_sent = Ak::mail($this->getSender(), $this->getDestinationEmail(), $this->getSubject(), $message); 
    81             $this->Controller->form_message_contents = $this->getSender().' >> '.$this->getDestinationEmail()."\n". 
    82             $this->getSubject()."\n-------------------\n".$message; 
     81            $this->Controller->form_sent = mail($this->getDestinationEmail(), $this->getSubject(),  $message, $this->getFromHeader()."\r\nContent-Type: text/plain;charset=UTF-8;\r\n"); 
     82 
     83            $this->Controller->form_message_contents = $email.' >> '.$this->getDestinationEmail()."\n".$this->getSubject()."\n-------------------\n".$message; 
    8384        } 
    84         $this->Controller->form_errors = $errors;  
     85        $this->Controller->form_errors = $errors; 
    8586    } 
    8687 
     
    9798    } 
    9899 
    99     function getSender() 
     100    function getSenderEmail() 
    100101    { 
    101         return $this->Controller->params['form']['email'].'<'.$this->Controller->params['form']['email'].'>'; 
     102        return empty($this->Controller->params['form']['email']) ? '' : $this->Controller->params['form']['email']; 
     103    } 
     104 
     105    function getSenderName() 
     106    { 
     107        return empty($this->Controller->params['form']['name']) ? '' : $this->Controller->params['form']['name']; 
     108    } 
     109 
     110    function getFromHeader() 
     111    { 
     112        $sender_name = $this->getSenderName(); 
     113        $email = $this->getSenderEmail(); 
     114        return preg_replace('/(\n|\r)*/','', 'From: '.(empty($sender_name) ? $email : $sender_name)." <{$email}>"); 
    102115    } 
    103116 
  • trunk/src/includes/editam/helpers/editags_helper.php

    r26 r35  
    3535 
    3636defined('EDITAM_CSS_MEDIA_TYPES') ? null : define('EDITAM_CSS_MEDIA_TYPES', 'screen|print|handheld|tv|projection|all|aural|braille|embossed|tty'); 
     37defined('AK_ACTION_CONTROLLER_AVAILABLE_HELPERS') ? null : define('AK_ACTION_CONTROLLER_AVAILABLE_HELPERS', 'url_helper,text_helper,tag_helper,scriptaculous_helper,prototype_helper,pagination_helper,number_helper,menu_helper,javascript_macros_helper,javascript_helper,form_tag_helper,form_options_helper,form_helper,file_upload_helper,date_helper,capture_helper,asset_tag_helper,active_record_helper,editags_helper,layout_helper'); 
     38 
    3739 
    3840require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'AkActionViewHelper.php'); 
     
    103105 
    104106 
    105     function snippet($name
     107    function snippet($name, $local_assigns = array()
    106108    { 
    107109        if($Snippet =& $this->_controller->Snippet->findFirstBy('name',$name)){ 
    108             return $Snippet->render($this->_controller); 
     110            return $Snippet->render($this->_controller, $local_assigns); 
    109111        } 
    110112    } 
     
    251253    { 
    252254        $args = func_get_args(); 
    253         return preg_replace('/^('.str_replace('/','\/',AK_ASSET_URL_PREFIX).')/', '', call_user_func_array(array(&$this->_controller->asset_tag_helper,'_compute_public_path'), $args)); 
     255        $computed_path = call_user_func_array(array(&$this->_controller->asset_tag_helper,'_compute_public_path'), $args); 
     256        return strlen(AK_ASSET_URL_PREFIX) > 1 ? preg_replace('/^('.str_replace('/','\/',AK_ASSET_URL_PREFIX).')/', '', $computed_path) : $computed_path; 
    254257    } 
    255258 
  • trunk/src/includes/editam/models/editam_setup.php

    r29 r35  
    4343    var $available_locales = array('en', 'es'); 
    4444    var $locales = array('en'); 
    45     var $stylesheets = array('akelos','content_layout','default', 
    46     'editam-ie','editam','login','modalbox','page','permission','role', 
    47     'snippet','tab_canvas','tree'); 
    4845 
    4946    function __construct() 
     
    290287    } 
    291288 
    292     function relativizeStylesheetsUrls() 
     289    function relativizeStylesheetPaths() 
    293290    { 
    294291        $suffix = $this->getUrlSuffix(); 
     
    303300        return true; 
    304301    } 
    305  
     302     
    306303    function getUrlSuffix() 
    307304    { 
     
    780777        return 'localhost'; 
    781778    } 
    782      
    783     function relativizeStylesheetPaths() 
    784     { 
    785         if($this->hasUrlSuffix()){ 
    786             $url_suffix = trim($this->getUrlSuffix(),'/'); 
    787             foreach ($this->stylesheets as $stylesheet) { 
    788                 $filename = AK_PUBLIC_DIR.DS.'stylesheets'.DS.$stylesheet.'.css'; 
    789                 $relativized_css = preg_replace("/url\((\'|\")?\/images/","url($1/$url_suffix/images", @Ak::file_get_contents($filename)); 
    790                 empty($relativized_css) ? null : @Ak::file_put_contents($filename, $relativized_css); 
    791             } 
    792         } 
    793     } 
    794779} 
    795780 
  • trunk/src/includes/editam/models/page.php

    r2 r35  
    5555    ); 
    5656 
     57    var $acts_as = array('nested_set' => array('order' => 'virtual DESC, title ASC','scope' => "locale = ?")); 
     58 
     59/* 
    5760    function __construct() 
    5861    { 
    59         if(empty($this->__testing_mode)){ 
    60             $this->acts_as = array('nested_set' => array('order' => 'virtual DESC, title ASC','scope' => "locale = '". 
    61             $this->getLang(@$attributes['locale']). 
    62             "'")); 
    63         } 
    64  
    6562        $attributes = (array)func_get_args(); 
    66         return $this->init($attributes); 
    67     } 
    68  
    69     function getLang($proposed_lang = null) 
     63        $Page = $this->init($attributes); 
     64        $Page->_fixed_locale = $Page->get('locale'); 
     65    } 
     66*/     
     67 
     68    function getLocale() 
    7069    { 
    7170        $default_lang = Ak::lang(); 
    72         $lang = empty($proposed_lang) ? (empty($this->locale) ? $default_lang : $this->locale) : $proposed_lang; 
    73         return in_array($lang, Ak::langs()) ? $lang : $default_lang; 
     71        $lang = empty($this->locale) ? $default_lang : $this->locale; 
     72        $locale = in_array($lang, Ak::langs()) ? $lang : $default_lang; 
     73        $this->_original_locale = empty($this->_original_locale) ? $locale : $this->_original_locale; 
     74        return $locale; 
    7475    } 
    7576 
     
    163164 
    164165        $this->validatesInclusionOf('locale', Ak::langs()); 
     166         
     167        if(isset($this->_original_locale) && $this->_original_locale != $this->get('locale')){ 
     168            $this->addError('locale', $this->t('Page locale can\'t be changed once it has been set.')); 
     169        } 
    165170    } 
    166171 
  • trunk/src/includes/editam/test/unit/app/models/page.php

    r28 r35  
    1818Mock::generate('EditagsHelper'); 
    1919 
     20 
    2021// Page without nested for creating initial pages from yaml data 
    2122class TestingPage extends Page 
     
    3132 
    3233 
    33 class PageTestCase extends AkUnitTest   
     34class PageTestCase extends AkUnitTest 
    3435{ 
    3536    function setup() 
     
    4041            $installer->do_not_create_sample_data = true; 
    4142            $installer->uninstall(); 
    42              
     43 
    4344            $installer->install(); 
    4445 
    4546            $Pages = Ak::convert('yaml','array', Ak::file_get_contents(AK_TEST_DIR.DS.'fixtures'.DS.'db'.DS.'pages.yaml')); 
    4647            $this->_loadPage(); 
    47          
     48 
    4849            $Layouts = Ak::convert('yaml','array', Ak::file_get_contents(AK_TEST_DIR.DS.'fixtures'.DS.'db'.DS.'content_layouts.yaml')); 
    4950            $this->Layout =& new ContentLayout(); 
     
    5152                $this->Layout->create($Layout); 
    5253            } 
    53              
     54 
    5455            $this->Page =& new TestingPage(); 
    5556            foreach ($Pages as $Page){ 
     
    6566 
    6667        } 
    67          
     68 
    6869        $this->_loadPage(); 
    6970    } 
    70      
     71 
    7172    function _loadPage() 
    7273    { 
     
    7475        $this->_loadPageDependencies($this->Page); 
    7576    } 
    76      
     77 
    7778    function _loadPageDependencies(&$Page) 
    7879    { 
     
    9596            $this->assertNoPattern('/is invalid/',$Page->getErrorsOn('slug')); 
    9697        } 
    97          
     98 
    9899        return; 
    99100 
     
    235236 
    236237    } 
    237      
     238 
    238239    function test_published_at_not_updated_on_save_because_already_published() 
    239240    { 
     
    258259 
    259260    } 
    260      
     261 
    261262 
    262263    function test_page_should_return_current_layout() 
     
    264265        $Page =& $this->Page->findByUrl('/'); 
    265266        $this->assertPattern('/base_template/',$Page->getLayout()); 
    266                  
     267 
    267268        $Page =& $this->Page->findByUrl('/docs'); 
    268269        $this->assertPattern('/docs_template/',$Page->getLayout()); 
     
    275276        $Layout =& $Page->getLayoutInstance(); 
    276277        $this->assertPattern('/base_template/',$Layout->get('content')); 
    277          
     278 
    278279        $Page =& $this->Page->findByUrl('/docs/tutorials'); 
    279280        $Layout =& $Page->getLayoutInstance(); 
    280281        $this->assertPattern('/docs_template/',$Layout->get('content')); 
    281282    } 
    282      
    283      
     283 
     284 
    284285    function test_should_return_part_instance() 
    285286    { 
     
    302303        $this->_loadPageDependencies($Page); 
    303304        $this->assertEqual($Page->getFilteredPart('body'), 'Documentation body'); 
    304          
    305     } 
    306      
     305 
     306    } 
     307 
    307308 
    308309 
     
    312313        $Page->part->load(); 
    313314 
    314         $part_id = $Page->parts[0]->getId();         
     315        $part_id = $Page->parts[0]->getId(); 
    315316        $this->assertTrue($Page->destroy()); 
    316317        $this->assertFalse($this->PagePart->find($part_id)); 
    317318    } 
    318      
     319 
    319320 
    320321    function test_destroy_nested_elements_and_their_dependent_parts() 
    321322    { 
    322          
     323 
    323324        $Page =& $this->Page->findByUrl('/docs/tutorials/creating-a-bookstore/introduction', true); 
    324325        $outermost_page_id = $Page->getId(); 
    325326        $Page->part->load(); 
    326327        $outermost_part_id = $Page->parts[0]->getId(); 
    327          
     328 
    328329        $Page =& $this->Page->findByUrl('/docs/tutorials/creating-a-bookstore', true); 
    329330        $child_page_id = $Page->getId(); 
    330331        $Page->part->load(); 
    331         $child_part_id = $Page->parts[0]->getId();   
    332          
     332        $child_part_id = $Page->parts[0]->getId(); 
     333 
    333334        $Page =& $this->Page->findByUrl('docs/tutorials'); 
    334335        $Page->part->load(); 
    335336        $part_id = $Page->parts[0]->getId(); 
    336               
     337 
    337338        $this->assertTrue($Page->destroy()); 
    338          
     339 
    339340        $this->assertFalse($this->PagePart->find($part_id)); 
    340341        $this->assertFalse($this->PagePart->find($child_part_id)); 
    341342        $this->assertFalse($this->PagePart->find($outermost_part_id)); 
    342          
     343 
    343344        $this->assertFalse($this->Page->find($child_page_id)); 
    344345        $this->assertFalse($this->Page->find($outermost_page_id)); 
    345346    } 
    346347 
     348    function test_should_not_allow_changing_page_locale() 
     349    { 
     350        $Page =& $this->Page->findByUrl('/about/our-team/bermi',true); 
     351        $this->assertEqual($Page->get('locale'), 'en'); 
     352 
     353        $Page->set('locale','es'); 
     354 
     355        $this->assertFalse($Page->save()); 
     356 
     357        $this->assertPattern('/change/', $Page->getErrorsOn('locale')); 
     358 
     359        $Page =& $this->Page->findByUrl('/about/our-team/bermi',true); 
     360        $this->assertEqual($Page->get('locale'), 'en'); 
     361 
     362    } 
    347363} 
    348364 
  • trunk/src/includes/editam/views/login/authenticate.tpl

    r2 r35  
    1616            <? if($controller->Request->isPost()) : ?> 
    1717            <p id="forgot_password_block" class="form_field_block"> 
    18                     <%= link_to translate('I have forgotten my account'), :controller => 'login', :action => 'account_recovery' %> 
     18                    <%= link_to translate('I forgot my password'), :controller => 'login', :action => 'account_recovery' %> 
    1919            </p> 
    2020            <? endif; ?> 
    2121        </div> 
    22         <div class="form_operations"> 
    23             <input type="submit" value="_{Sign in}" class="primary" /> _{or} <a href="/" title="_{Go to the public website}">_{Go to the public website}</a> 
    24         </div> 
    2522    </form> 
    2623</div>