PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/xoops_trust_path/modules/coupons/include/onupdate.php

http://xoopscube-modules.googlecode.com/
PHP | 89 lines | 65 code | 18 blank | 6 comment | 14 complexity | 590f99e919ef068599f73eb333d2d3a0 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. eval( ' function xoops_module_update_'.$mydirname.'( $module ) { return coupons_onupdate_base( $module , "'.$mydirname.'" ) ; } ' ) ;
  3. if( ! function_exists( 'coupons_onupdate_base' ) ) {
  4. function coupons_onupdate_base( $module , $mydirname )
  5. {
  6. // transations on module update
  7. global $msgs ; // TODO :-D
  8. // for Cube 2.1
  9. if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
  10. $root =& XCube_Root::getSingleton();
  11. $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'coupons_message_append_onupdate' ) ;
  12. $msgs = array() ;
  13. } else {
  14. if( ! is_array( $msgs ) ) $msgs = array() ;
  15. }
  16. $db =& Database::getInstance() ;
  17. $mid = $module->getVar('mid') ;
  18. //DB TABLES (write here ALTER TABLE etc. if necessary)
  19. // TEMPLATES (all templates have been already removed by modulesadmin)
  20. $tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
  21. $tpl_path = dirname(dirname(__FILE__)).'/templates' ;
  22. if( $handler = @opendir( $tpl_path . '/' ) ) {
  23. while( ( $file = readdir( $handler ) ) !== false ) {
  24. if( substr( $file , 0 , 1 ) == '.' ) continue ;
  25. $file_path = $tpl_path . '/' . $file ;
  26. if( is_file( $file_path ) && in_array( strrchr( $file , '.' ) , array( '.html' , '.css' , '.js' ) ) ) {
  27. $mtime = intval( @filemtime( $file_path ) ) ;
  28. $tplfile =& $tplfile_handler->create() ;
  29. $tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
  30. $tplfile->setVar( 'tpl_refid' , $mid ) ;
  31. $tplfile->setVar( 'tpl_tplset' , 'default' ) ;
  32. $tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ;
  33. $tplfile->setVar( 'tpl_desc' , '' , true ) ;
  34. $tplfile->setVar( 'tpl_module' , $mydirname ) ;
  35. $tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
  36. $tplfile->setVar( 'tpl_lastimported' , 0 ) ;
  37. $tplfile->setVar( 'tpl_type' , 'module' ) ;
  38. if( ! $tplfile_handler->insert( $tplfile ) ) {
  39. $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
  40. } else {
  41. $tplid = $tplfile->getVar( 'tpl_id' ) ;
  42. $msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)';
  43. // generate compiled file
  44. include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
  45. include_once XOOPS_ROOT_PATH.'/class/template.php' ;
  46. if( ! xoops_template_touch( $tplid ) ) {
  47. $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>';
  48. } else {
  49. $msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>';
  50. }
  51. }
  52. }
  53. }
  54. closedir( $handler ) ;
  55. }
  56. include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
  57. include_once XOOPS_ROOT_PATH.'/class/template.php' ;
  58. xoops_template_clear_module_cache( $mid ) ;
  59. return true ;
  60. }
  61. function coupons_message_append_onupdate( &$module_obj , &$log )
  62. {
  63. if( is_array( @$GLOBALS['msgs'] ) ) {
  64. foreach( $GLOBALS['msgs'] as $message ) {
  65. $log->add( strip_tags( $message ) ) ;
  66. }
  67. }
  68. // use mLog->addWarning() or mLog->addError() if necessary
  69. }
  70. }
  71. ?>