PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/xoops_trust_path/modules/d3blog/oninstall.php

http://xoopscube-modules.googlecode.com/
PHP | 141 lines | 112 code | 17 blank | 12 comment | 26 complexity | ba78c4ce04d107e974a81e289d0a4b48 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * @version $Id: oninstall.php 442 2008-05-24 02:12:53Z hodaka $
  4. */
  5. eval( ' function xoops_module_install_'.$mydirname.'( $module ) { return d3blog_oninstall_base( $module , "'.$mydirname.'" ) ; } ' ) ;
  6. if( ! function_exists( 'd3blog_oninstall_base' ) ) {
  7. function d3blog_oninstall_base( $module , $mydirname )
  8. {
  9. // transations on module install
  10. global $ret ; // TODO :-D
  11. // for Cube 2.1
  12. if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
  13. $root =& XCube_Root::getSingleton();
  14. $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success' , 'd3blog_message_append_oninstall' ) ;
  15. $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Fail' , 'd3blog_message_append_oninstall' ) ;
  16. $ret = array() ;
  17. } else {
  18. if( ! is_array( $ret ) ) $ret = array() ;
  19. }
  20. $db =& Database::getInstance() ;
  21. $mid = $module->getVar('mid') ;
  22. // to keep config setting more stable.
  23. // xoops config_title is too short, especially for d3-modules.
  24. $sql = "SHOW COLUMNS FROM ".$db->prefix("config")." LIKE 'conf_title'" ;
  25. if($result = $db->query($sql)) {
  26. if($row = $db->fetchArray($result)) {
  27. $sql = "ALTER TABLE ".$db->prefix("config")." MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''";
  28. if(!$res = $db->queryF($sql)) {
  29. $ret[] = '<span style="color:#FC0;font-weight:bold">FAILED TO ALTER AND MODIFY XOOPS CONFIG TABLE.</span><br />';
  30. return false ;
  31. }
  32. else {
  33. $ret[] = 'Database table <strong>xoops config</strong> was successfully altered and modified.';
  34. }
  35. }
  36. }
  37. // TABLES (loading mysql.sql)
  38. $sql_file_path = dirname(__FILE__).'/sql/mysql.sql' ;
  39. $prefix_mod = $db->prefix() . '_' . $mydirname ;
  40. if( file_exists( $sql_file_path ) ) {
  41. $ret[] = "SQL file found at <b>".htmlspecialchars($sql_file_path)."</b>.<br /> Creating tables...";
  42. if( file_exists( XOOPS_ROOT_PATH.'/class/database/oldsqlutility.php' ) ) {
  43. include_once XOOPS_ROOT_PATH.'/class/database/oldsqlutility.php' ;
  44. $sqlutil = new OldSqlUtility ;
  45. } else {
  46. include_once XOOPS_ROOT_PATH.'/class/database/sqlutility.php' ;
  47. $sqlutil = new SqlUtility ;
  48. }
  49. $sql_query = trim( file_get_contents( $sql_file_path ) ) ;
  50. $sqlutil->splitMySqlFile( $pieces , $sql_query ) ;
  51. $created_tables = array() ;
  52. foreach( $pieces as $piece ) {
  53. $prefixed_query = $sqlutil->prefixQuery( $piece , $prefix_mod ) ;
  54. if( ! $prefixed_query ) {
  55. $ret[] = "Invalid SQL <b>".htmlspecialchars($piece)."</b><br />";
  56. return false ;
  57. }
  58. if( ! $db->query( $prefixed_query[0] ) ) {
  59. $ret[] = '<strong>'.htmlspecialchars( $db->error() ).'</strong><br />' ;
  60. //var_dump( $db->error() ) ;
  61. return false ;
  62. } else {
  63. if( ! in_array( $prefixed_query[4] , $created_tables ) ) {
  64. $ret[] = 'Table <strong>'.htmlspecialchars($prefix_mod.'_'.$prefixed_query[4]).'</strong> created.<br />';
  65. $created_tables[] = $prefixed_query[4];
  66. } else {
  67. $ret[] = 'Data inserted to table <strong>'.htmlspecialchars($prefix_mod.'_'.$prefixed_query[4]).'</strong>.</br />';
  68. }
  69. }
  70. }
  71. }
  72. // TEMPLATES
  73. $tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
  74. $tpl_path = dirname(__FILE__).'/templates' ;
  75. if( $handler = @opendir( $tpl_path . '/' ) ) {
  76. while( ( $file = readdir( $handler ) ) !== false ) {
  77. if( substr( $file , 0 , 1 ) == '.' ) continue ;
  78. $file_path = $tpl_path . '/' . $file ;
  79. if( is_file( $file_path ) && in_array( strrchr( $file , '.' ) , array( '.xml', '.html' , '.css' , '.js' ) ) ) {
  80. $mtime = intval( @filemtime( $file_path ) ) ;
  81. $tplfile =& $tplfile_handler->create() ;
  82. $tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
  83. $tplfile->setVar( 'tpl_refid' , $mid ) ;
  84. $tplfile->setVar( 'tpl_tplset' , 'default' ) ;
  85. $tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ;
  86. $tplfile->setVar( 'tpl_desc' , '' , true ) ;
  87. $tplfile->setVar( 'tpl_module' , $mydirname ) ;
  88. $tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
  89. $tplfile->setVar( 'tpl_lastimported' , 0 ) ;
  90. $tplfile->setVar( 'tpl_type' , 'module' ) ;
  91. if( ! $tplfile_handler->insert( $tplfile ) ) {
  92. $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span><br />';
  93. } else {
  94. $tplid = $tplfile->getVar( 'tpl_id' ) ;
  95. $ret[] = 'Template <strong>'.htmlspecialchars($mydirname.'_'.$file).'</strong> added to the database. (ID: <b>'.$tplid.'</b>)<br />';
  96. // generate compiled file
  97. include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
  98. include_once XOOPS_ROOT_PATH.'/class/template.php' ;
  99. if( ! xoops_template_touch( $tplid ) ) {
  100. $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span><br />';
  101. } else {
  102. $ret[] = 'Template <strong>'.htmlspecialchars($mydirname.'_'.$file).'</strong> compiled.</span><br />';
  103. }
  104. }
  105. }
  106. }
  107. closedir( $handler ) ;
  108. }
  109. include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
  110. include_once XOOPS_ROOT_PATH.'/class/template.php' ;
  111. xoops_template_clear_module_cache( $mid ) ;
  112. return true ;
  113. }
  114. function d3blog_message_append_oninstall( &$module_obj , &$log )
  115. {
  116. if( is_array( @$GLOBALS['ret'] ) ) {
  117. foreach( $GLOBALS['ret'] as $message ) {
  118. $log->add( strip_tags( $message ) ) ;
  119. }
  120. }
  121. // use mLog->addWarning() or mLog->addError() if necessary
  122. }
  123. }
  124. ?>