PageRenderTime 37ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/xoops_trust_path/modules/pico/class/PicoControllerGetHtmlwrapped.class.php

http://xoopscube-modules.googlecode.com/
PHP | 137 lines | 94 code | 22 blank | 21 comment | 17 complexity | 777f0f966c3ddc961168448cd2906278 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. require_once dirname(__FILE__).'/PicoControllerAbstract.class.php' ;
  3. require_once dirname(__FILE__).'/PicoModelCategory.class.php' ;
  4. require_once dirname(__FILE__).'/PicoModelContent.class.php' ;
  5. // HTML wrapping without DB
  6. class PicoControllerGetHtmlwrapped extends PicoControllerAbstract {
  7. //var $mydirname = '' ;
  8. //var $mydirname = '' ;
  9. //var $mytrustdirname = '' ;
  10. //var $assign = array() ;
  11. //var $mod_config = array() ;
  12. //var $uid = 0 ;
  13. //var $currentCategoryObj = null ;
  14. //var $permissions = array() ;
  15. //var $is_need_header_footer = true ;
  16. //var $template_name = '' ;
  17. //var $html_header = '' ;
  18. function execute( $request )
  19. {
  20. parent::execute( $request ) ;
  21. $this->assign['content'] = $this->readWrappedFile( $request ) ;
  22. // check existence
  23. if( empty( $this->assign['content'] ) ) {
  24. redirect_header( XOOPS_URL."/modules/$this->mydirname/index.php" , 2 , _MD_PICO_ERR_READCONTENT ) ;
  25. exit ;
  26. }
  27. $cat_data = $this->currentCategoryObj->getData() ;
  28. $this->assign['category'] = $this->currentCategoryObj->getData4html() ;
  29. // permission check
  30. if( empty( $this->assign['content']['can_read'] ) || empty( $this->assign['content']['can_readfull'] ) ) {
  31. if( $this->uid > 0 ) {
  32. redirect_header( XOOPS_URL.'/' , 2 , _MD_PICO_ERR_PERMREADFULL ) ;
  33. } else {
  34. redirect_header( XOOPS_URL.'/user.php' , 2 , _MD_PICO_ERR_LOGINTOREADFULL ) ;
  35. }
  36. exit ;
  37. }
  38. // auto-register
  39. if( ! empty( $this->mod_config['wraps_auto_register'] ) && @$cat_data['cat_vpath']{0} == '/' ) {
  40. $register_class = empty( $this->mod_config['auto_register_class'] ) ? 'PicoAutoRegisterWraps' : $this->mod_config['auto_register_class'] ;
  41. require_once dirname(__FILE__).'/'.$register_class.'.class.php' ;
  42. $register_obj = new $register_class( $this->mydirname , $this->mod_config ) ;
  43. $affected_rows = $register_obj->registerByCatvpath( $cat_data ) ;
  44. if( $affected_rows > 0 ) {
  45. // reload if the content is updated
  46. header( 'Location: '.pico_common_unhtmlspecialchars($this->assign['mod_url']).'/'.pico_common_unhtmlspecialchars($this->assign['content']['link']) ) ;
  47. exit ;
  48. }
  49. }
  50. // link for "tell to friends"
  51. // (TODO?)
  52. if( $this->mod_config['use_taf_module'] ) {
  53. $this->assign['content']['tellafriend_uri'] = XOOPS_URL.'/modules/tellafriend/index.php?target_uri='.rawurlencode( pico_common_unhtmlspecialchars( $this->assign['mod_url'] . '/' . $this->assign['content']['link'] ) ).'&amp;subject='.rawurlencode(sprintf(_MD_PICO_FMT_TELLAFRIENDSUBJECT,@$GLOBALS['xoopsConfig']['sitename'])) ;
  54. } else {
  55. $this->assign['content']['tellafriend_uri'] = 'mailto:?subject='.pico_main_escape4mailto(sprintf(_MD_PICO_FMT_TELLAFRIENDSUBJECT,@$GLOBALS['xoopsConfig']['sitename'])).'&amp;body='.pico_main_escape4mailto(sprintf(_MD_PICO_FMT_TELLAFRIENDBODY, $this->assign['content']['subject'])).'%0A'.rawurlencode( pico_common_unhtmlspecialchars( $this->assign['mod_url'] . '/' . $this->assign['content']['link'] ) ) ;
  56. }
  57. // breadcrumbs
  58. $breadcrumbsObj =& AltsysBreadcrumbs::getInstance() ;
  59. $breadcrumbsObj->appendPath( '' , $this->assign['content']['subject'] ) ;
  60. $this->assign['xoops_breadcrumbs'] = $breadcrumbsObj->getXoopsbreadcrumbs() ;
  61. $this->assign['xoops_pagetitle'] = $this->assign['content']['subject'] ;
  62. // views
  63. switch( $request['view'] ) {
  64. case 'singlecontent' :
  65. $this->template_name = 'db:'.$this->mydirname.'_independent_singlecontent.html' ;
  66. $this->is_need_header_footer = false ;
  67. break ;
  68. case 'print' :
  69. $this->template_name = 'db:'.$this->mydirname.'_independent_print.html' ;
  70. $this->is_need_header_footer = false ;
  71. break ;
  72. default :
  73. $this->template_name = $this->mydirname.'_main_viewcontent.html' ;
  74. $this->is_need_header_footer = true ;
  75. break ;
  76. }
  77. }
  78. function readWrappedFile( $request )
  79. {
  80. $wrap_full_path = XOOPS_TRUST_PATH._MD_PICO_WRAPBASE.'/'.$this->mydirname.$request['path_info'] ;
  81. ob_start() ;
  82. include $wrap_full_path ;
  83. $full_content = pico_convert_encoding_to_ie( ob_get_contents() ) ;
  84. ob_end_clean() ;
  85. // parse full_content (get subject, body etc.)
  86. $file = substr( strrchr( $wrap_full_path , '/' ) , 1 ) ;
  87. $mtime = intval( @filemtime( $wrap_full_path ) ) ;
  88. if( preg_match( '/\<title\>([^<>]+)\<\/title\>/is' , $full_content , $regs ) ) {
  89. $subject = $regs[1] ;
  90. } else {
  91. $subject = $file ;
  92. }
  93. if( preg_match( '/\<body[^<>]*\>(.*)\<\/body\>/is' , $full_content , $regs ) ) {
  94. $body = $regs[1] ;
  95. } else {
  96. $body = $full_content ;
  97. }
  98. $cat_data = $this->currentCategoryObj->getData() ;
  99. $link = empty( $this->mod_config['use_rewrite'] ) ? 'index.php'.$request['path_info'] : substr( $request['path_info'] , 1 ) ;
  100. return array(
  101. 'id' => 0 ,
  102. 'link' => $link ,
  103. 'created_time' => $mtime ,
  104. 'created_time_formatted' => formatTimestamp( $mtime ) ,
  105. 'subject_raw' => pico_common_unhtmlspecialchars( $subject ) ,
  106. 'subject' => $subject ,
  107. 'body' => $body ,
  108. 'can_read' => $cat_data['isadminormod'] || $cat_data['can_read'] ,
  109. 'can_readfull' => $cat_data['isadminormod'] || $cat_data['can_readfull'] ,
  110. 'can_edit' => false ,
  111. 'can_vote' => false ,
  112. ) ;
  113. }
  114. }
  115. ?>