Posted By

daisuke103 on 01/27/09


Tagged

php textmate html cake brita component purifier


Versions (?)

PHP CAKE コンポーネントの利用とBrita


 / Published in: Other
 

  1. app/controllers/components/message.php
  2. <?php
  3. class MessageComponent extends Object {
  4.  
  5. var $controller = null;
  6. function startup(& $controller) {
  7. $this->controller =& $controller;
  8. }
  9.  
  10. function errormsg($message=null, $url=null)
  11. {
  12. if(!$url){
  13. $url = "javascript:history.Back()";
  14. }
  15. // $this->controller->Brita->testbrita($controller);
  16. $message = $this->controller->brita->purify( $message );
  17. $this->controller->set('message', $message);
  18. $this->controller->set('url', $url);
  19. //$this->controller->render('errormsg','messages');
  20. $this->controller->render(null, null, VIEWS.'messages'.DS.'errormsg.ctp');
  21. }
  22. }
  23. ?>
  24.  
  25.  
  26. ----------------------------------------
  27. app/controllers/test_controller.php
  28. <?php
  29. class TestsController extends AppController {
  30.  
  31. var $uses = array();
  32. var $autoRender = false;
  33. var $components = array('Test2Action','Message','Brita');
  34.  
  35. function index() {
  36.  
  37. // コンポーネント+Britaよりエラーコントローラのビューを使ったエラーページを作成。
  38. $this->Message->errormsg('test test あああああ', '');
  39. }
  40. ?>
  41.  
  42.  
  43.  
  44. ----------------------------------------
  45. app/controllers/components/brita.php
  46. ※HTML Purifierとしてダウンロード
  47. http://htmlpurifier.org/
  48. http://bakery.cakephp.org/articles/view/brita-component-with-html-purifier
  49.  
  50. <?php
  51. //cake's version of a require_once() call
  52. //vendor('htmlpurifier'.DS.'library'.DS.'HTMLPurifier.auto'); //use this with the 1.1 core
  53. App::import('Vendor','HTMLPurifier' ,array('file'=>'htmlpurifier'.DS.'library'.DS.'HTMLPurifier.auto.php')); //use this with the 1.2 core
  54.  
  55. class BritaComponent extends Object {
  56.  
  57. var $controller;
  58.  
  59. function startup( &$controller ) {
  60. //the next few lines allow the config settings to be cached
  61. $config = HTMLPurifier_Config::createDefault();
  62. $config->set('HTML', 'DefinitionID', 'made by debugged interactive designs');
  63. $config->set('HTML', 'DefinitionRev', 1);
  64. //levels describe how aggressive the Tidy module should be when cleaning up html
  65. //four levels: none, light, medium, heavy
  66. $config->set('HTML', 'TidyLevel', 'heavy');
  67. //check the top of your html file for the next two
  68. $config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional');
  69. $config->set('Core', 'Encoding', 'UTF-8');
  70.  
  71. //BritaComponent instance of controller is replaced by a htmlpurifier instance
  72. $controller->brita =& new HTMLPurifier($config);
  73. $controller->set('brita',$controller->brita);
  74. }
  75.  
  76. }
  77. ?>

Report this snippet  

You need to login to post a comment.