PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/xoops_trust_path/libs/altsys/onupdate.php

http://xoopscube-modules.googlecode.com/
PHP | 101 lines | 68 code | 19 blank | 14 comment | 16 complexity | d4fada9d7a30a244a1aa9749f3838c14 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 altsys_onupdate_base( $module , "'.$mydirname.'" ) ; } ' ) ;
  3. if( ! function_exists( 'altsys_onupdate_base' ) ) {
  4. function altsys_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', 'altsys_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. // TABLES (write here ALTER TABLE etc. if necessary)
  19. // configs (Though I know it is not a recommended way...)
  20. $check_sql = "SHOW COLUMNS FROM ".$db->prefix("config")." LIKE 'conf_title'" ;
  21. if( ( $result = $db->query( $check_sql ) ) && ( $myrow = $db->fetchArray( $result ) ) && @$myrow['Type'] == 'varchar(30)' ) {
  22. $db->queryF( "ALTER TABLE ".$db->prefix("config")." MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''" ) ;
  23. }
  24. // 0.4 -> 0.5
  25. $check_sql = "SELECT COUNT(*) FROM ".$db->prefix($mydirname."_language_constants") ;
  26. if( ! $db->query( $check_sql ) ) {
  27. $db->queryF( "CREATE TABLE ".$db->prefix($mydirname."_language_constants")." (mid smallint(5) unsigned NOT NULL default 0,language varchar(32) NOT NULL default '',name varchar(255) NOT NULL default '',value text,PRIMARY KEY (mid,language,name)) TYPE=MyISAM" ) ;
  28. }
  29. // TEMPLATES (all templates have been already removed by modulesadmin)
  30. $tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
  31. $tpl_path = dirname(__FILE__).'/templates' ;
  32. if( $handler = @opendir( $tpl_path . '/' ) ) {
  33. while( ( $file = readdir( $handler ) ) !== false ) {
  34. if( substr( $file , 0 , 1 ) == '.' ) continue ;
  35. $file_path = $tpl_path . '/' . $file ;
  36. if( is_file( $file_path ) ) {
  37. $mtime = intval( @filemtime( $file_path ) ) ;
  38. $tplfile =& $tplfile_handler->create() ;
  39. $tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
  40. $tplfile->setVar( 'tpl_refid' , $mid ) ;
  41. $tplfile->setVar( 'tpl_tplset' , 'default' ) ;
  42. $tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ;
  43. $tplfile->setVar( 'tpl_desc' , '' , true ) ;
  44. $tplfile->setVar( 'tpl_module' , $mydirname ) ;
  45. $tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
  46. $tplfile->setVar( 'tpl_lastimported' , 0 ) ;
  47. $tplfile->setVar( 'tpl_type' , 'module' ) ;
  48. if( ! $tplfile_handler->insert( $tplfile ) ) {
  49. $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
  50. } else {
  51. $tplid = $tplfile->getVar( 'tpl_id' ) ;
  52. $msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)';
  53. // generate compiled file
  54. require_once XOOPS_TRUST_PATH.'/libs/altsys/include/altsys_functions.php' ;
  55. altsys_clear_templates_c() ;
  56. /*include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
  57. if( ! xoops_template_touch( $tplid ) ) {
  58. $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>';
  59. } else {
  60. $msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>';
  61. }*/
  62. }
  63. }
  64. }
  65. closedir( $handler ) ;
  66. }
  67. include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
  68. include_once XOOPS_ROOT_PATH.'/class/template.php' ;
  69. xoops_template_clear_module_cache( $mid ) ;
  70. return true ;
  71. }
  72. function altsys_message_append_onupdate( &$module_obj , &$log )
  73. {
  74. if( is_array( @$GLOBALS['msgs'] ) ) {
  75. foreach( $GLOBALS['msgs'] as $message ) {
  76. $log->add( strip_tags( $message ) ) ;
  77. }
  78. }
  79. // use mLog->addWarning() or mLog->addError() if necessary
  80. }
  81. }
  82. ?>