コード例 #1
0
function tplsadmin_import_data($tplset, $tpl_file, $tpl_source, $lastmodified = 0)
{
    $db =& Database::getInstance();
    // check the file is valid template
    list($count) = $db->fetchRow($db->query("SELECT COUNT(*) FROM " . $db->prefix("tplfile") . " WHERE tpl_tplset='default' AND tpl_file='" . addslashes($tpl_file) . "'"));
    if (!$count) {
        return false;
    }
    // check the template exists in the tplset
    if ($tplset != 'default') {
        list($count) = $db->fetchRow($db->query("SELECT COUNT(*) FROM " . $db->prefix("tplfile") . " WHERE tpl_tplset='" . addslashes($tplset) . "' AND tpl_file='" . addslashes($tpl_file) . "'"));
        if ($count <= 0) {
            // copy from 'default' to the tplset
            $result = $db->query("SELECT * FROM " . $db->prefix("tplfile") . " WHERE tpl_tplset='default' AND tpl_file='" . addslashes($tpl_file) . "'");
            while ($row = $db->fetchArray($result)) {
                $db->queryF("INSERT INTO " . $db->prefix("tplfile") . " SET tpl_refid='" . addslashes($row['tpl_refid']) . "',tpl_module='" . addslashes($row['tpl_module']) . "',tpl_tplset='" . addslashes($tplset) . "',tpl_file='" . addslashes($tpl_file) . "',tpl_desc='" . addslashes($row['tpl_desc']) . "',tpl_type='" . addslashes($row['tpl_type']) . "'");
                $tpl_id = $db->getInsertId();
                $db->queryF("INSERT INTO " . $db->prefix("tplsource") . " SET tpl_id='{$tpl_id}', tpl_source=''");
            }
        }
    }
    // UPDATE just tpl_lastmodified and tpl_source
    $drs = $db->query("SELECT tpl_id FROM " . $db->prefix("tplfile") . " WHERE tpl_tplset='" . addslashes($tplset) . "' AND tpl_file='" . addslashes($tpl_file) . "'");
    while (list($tpl_id) = $db->fetchRow($drs)) {
        $db->queryF("UPDATE " . $db->prefix("tplfile") . " SET tpl_lastmodified='" . addslashes($lastmodified) . "',tpl_lastimported=UNIX_TIMESTAMP() WHERE tpl_id='{$tpl_id}'");
        $db->queryF("UPDATE " . $db->prefix("tplsource") . " SET tpl_source='" . addslashes($tpl_source) . "' WHERE tpl_id='{$tpl_id}'");
        xoops_template_touch($tpl_id);
    }
    return true;
}
コード例 #2
0
function xpress_create_db_template($file_name, $file_path, $mydirname, $mid)
{
    if (is_file($file_path)) {
        $tplfile_handler =& xoops_gethandler('tplfile');
        $tplfile =& $tplfile_handler->create();
        $mtime = intval(@filemtime($file_path));
        $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
        $tplfile->setVar('tpl_refid', $mid);
        $tplfile->setVar('tpl_tplset', 'default');
        $tplfile->setVar('tpl_file', $file_name);
        $tplfile->setVar('tpl_desc', '', true);
        $tplfile->setVar('tpl_module', $mydirname);
        $tplfile->setVar('tpl_lastmodified', $mtime);
        $tplfile->setVar('tpl_lastimported', 0);
        $tplfile->setVar('tpl_type', 'module');
        if (!$tplfile_handler->insert($tplfile)) {
            $msg = '<span style="color:#ff0000;">ERROR: Template Could not added to the database. <b>' . htmlspecialchars($file_name) . '</b> to the database.</span><br />';
        } else {
            $tplid = $tplfile->getVar('tpl_id');
            $msg = 'Template <b>' . htmlspecialchars($file_name) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />';
            // generate compiled file
            include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
            include_once XOOPS_ROOT_PATH . '/class/template.php';
            if (!xoops_template_touch($tplid)) {
                $msg = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($file_name) . '</b>.</span><br />';
            } else {
                $msg = 'Template <b>' . htmlspecialchars($file_name) . '</b> compiled.</span><br />';
            }
        }
    }
    return $msg;
}
コード例 #3
0
ファイル: onupdate.php プロジェクト: nouphet/rata
 function gnavi_onupdate_base($module, $mydirname)
 {
     // transations on module update
     global $msgs;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'gnavi_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     $check_sql = "SELECT arrowhtml FROM " . $db->prefix("{$mydirname}_text");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_text") . " ADD arrowhtml tinyint(1) NOT NULL default '0',ADD addinfo text");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_cat") . " CHANGE icd icd int(5) unsigned NOT NULL default '0'");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " CHANGE icd icd int(5) unsigned NOT NULL default '0'");
     }
     //version 0.13 -> version 0.7
     $check_sql = "SELECT * FROM " . $db->prefix("{$mydirname}_photos") . " USE INDEX(submitter)";
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " ADD INDEX (submitter)");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_cat") . " CHANGE lat tmp_lat double(9,6) NOT NULL default '0'");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_cat") . " CHANGE lng lat double(9,6) NOT NULL default '0'");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_cat") . " CHANGE tmp_lat lng double(9,6) NOT NULL default '0'");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " CHANGE lat tmp_lat double(9,6) NOT NULL default '0'");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " CHANGE lng lat double(9,6) NOT NULL default '0'");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " CHANGE tmp_lat lng double(9,6) NOT NULL default '0'");
     }
     //version 0.8 -> version 0.9
     $check_sql = "SELECT mtype FROM " . $db->prefix("{$mydirname}_photos");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " ADD mtype varchar(30) NOT NULL default ''");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_cat") . " ADD mtype varchar(30) NOT NULL default ''");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_cat") . " ADD   kmlurl varchar(150) NOT NULL default ''");
     }
     //version 0.95 -> version 0.96
     $check_sql = "SELECT rss FROM " . $db->prefix("{$mydirname}_photos");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " ADD rss varchar(255) NOT NULL default ''");
     }
     // TEMPLATES (all templates have been already removed by modulesadmin)
     $tplfile_handler =& xoops_gethandler('tplfile');
     // block templete must alldelete (for update from V2 module)
     $templates =& $tplfile_handler->find(null, 'block', null, $mydirname);
     $tcount = count($templates);
     if ($tcount > 0) {
         $ret[] = 'Deleting templates...';
         for ($i = 0; $i < $tcount; $i++) {
             if (!$tplfile_handler->delete($templates[$i])) {
                 $msgs[] = '<span style="color:#ff0000;">ERROR: Could not delete template ' . $templates[$i]->getVar('tpl_file', 's') . ' from the database. Template ID: <b>' . $templates[$i]->getVar('tpl_id', 's') . '</b></span><br />';
             } else {
                 $msgs[] = 'Template <b>' . $templates[$i]->getVar('tpl_file', 's') . '</b> deleted from the database. Template ID: <b>' . $templates[$i]->getVar('tpl_id', 's') . '</b><br />';
             }
         }
     }
     unset($templates);
     $tpl_path = dirname(__FILE__) . '/templates';
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path)) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                     // generate compiled file
                     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                     include_once XOOPS_ROOT_PATH . '/class/template.php';
                     if (!xoops_template_touch($tplid)) {
                         $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span>';
                     }
                 }
             }
         }
         closedir($handler);
     }
     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
     include_once XOOPS_ROOT_PATH . '/class/template.php';
     xoops_template_clear_module_cache($mid);
     return true;
 }
コード例 #4
0
ファイル: onupdate.php プロジェクト: nunoluciano/uxcl
function bulletin_onupdate_base( $module, $prev_version , $mydirname )
{
	global $msgs, $xoopsDB, $xoopsUser, $xoopsConfig ;

	// for Cube 2.1
	if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
		$isCube = true ;
		$root =& XCube_Root::getSingleton();
		$root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'bulletin_message_append_onupdate' ) ;
		$msgs = array() ;
	} else {
		$isCube = false ;
		if( ! is_array( $msgs ) ) $msgs = array() ;
	}

	$db =& Database::getInstance() ;
	$mid = $module->getVar('mid') ;


	// transations on module update
	// TABLES (write here ALTER TABLE etc. if necessary)
	if( $prev_version < 200 ){

		$msgs[] = 'Executing compatible programs... (ver '. $prev_version / 100 .' to 2.x)';

		$sql = sprintf("SHOW TABLES LIKE '%s'", $xoopsDB->prefix("{$mydirname}_relation") );
		list($result) = $xoopsDB->fetchRow($xoopsDB->query($sql));
		if( empty($result) ){
			$sql = "CREATE TABLE `".$xoopsDB->prefix("{$mydirname}_relation")."` (  `storyid` int(8) NOT NULL default '0',  `linkedid` int(8) NOT NULL default '0',  `dirname` varchar(25) NOT NULL default '') ENGINE=MyISAM;";
			if( $xoopsDB->query($sql) ){
				$msgs[] = '&nbsp;&nbsp;Table <b>'.htmlspecialchars($xoopsDB->prefix("{$mydirname}_relation")).'</b> created.';
			}else{
				$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
			}
		}else{
			$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Table <b>'.htmlspecialchars($result).'</b> already exsits.</span>';
		}

		$sql = sprintf("SHOW COLUMNS FROM %s LIKE 'block'", $xoopsDB->prefix("{$mydirname}_stories") );
		list($result) = $xoopsDB->fetchRow($xoopsDB->query($sql));
		if( empty($result) ){
			$sql = sprintf("ALTER TABLE %s ADD `block` TINYINT( 1 ) DEFAULT '1'", $xoopsDB->prefix("{$mydirname}_stories") );
			if( $xoopsDB->query($sql) ){
				$msgs[] = '&nbsp;&nbsp;Column <b>block</b> added.';
			}else{
				$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
			}
		}else{
			$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Column <b>block</b> already exsits.</span>';
		}

		// This is Duplication V2 compatibility...
		if( preg_match( '/^(\D+)(\d*)$/' , $mydirname , $regs ) ){
			$mydirnumber = $regs[2] === '' ? '' : intval( $regs[2] ) ;

			$sql = sprintf("SHOW TABLES LIKE '%s%%'", str_replace('_','\_',$xoopsDB->prefix("bulletin{$mydirnumber}_")) );
			$result = $xoopsDB->query($sql);
			while(list($table) = $xoopsDB->fetchRow($result)){
				$sql = "SELECT * FROM ".$xoopsDB->prefix('modules')." WHERE dirname = 'bulletin{$mydirnumber}'";

				list($count) = $xoopsDB->fetchRow($xoopsDB->query($sql));
				if($count == 0){
					$renamed = preg_replace('/^' .$xoopsDB->prefix("bulletin{$mydirnumber}"). '/i', $xoopsDB->prefix($mydirname), $table);
					$sql = "ALTER TABLE `".addslashes($table)."` RENAME `".addslashes($renamed)."` ";
					if( $xoopsDB->query($sql) ){
						$msgs[] = '&nbsp;&nbsp;Table <b>'.htmlspecialchars($table).'</b> is renamed into <b>'.htmlspecialchars($renamed).'</b>.';
					}else{
						$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Failed to rename table <b>'.htmlspecialchars($table).'</b></span>';
					}
				}
			}
		}
	}
	// update table structure from 2.04
	$check_rs = $db->query( "SELECT topic_created FROM ".$db->prefix($mydirname.'_topics') ) ;
	if( empty( $check_rs ) ) {
		$db->queryF( "ALTER TABLE ".$db->prefix($mydirname.'_topics')." ADD `topic_created` int(10) unsigned NOT NULL default 0, ADD `topic_modified` int(10) unsigned NOT NULL default 0, MODIFY `topic_imgurl` varchar(255) NOT NULL default '', MODIFY `topic_title` varchar(255) NOT NULL default ''" ) ;
		$db->queryF( "ALTER TABLE ".$db->prefix($mydirname.'_stories')." MODIFY `uid` mediumint(8) unsigned NOT NULL default 0" ) ;
		$db->queryF( "ALTER TABLE ".$db->prefix($mydirname.'_relation')." ADD KEY (`storyid`), ADD PRIMARY KEY (`storyid`,`linkedid`,`dirname`)" ) ;
	}
//ver2.22->ver3.0
	$sql = sprintf("SHOW TABLES LIKE '%s'", $db->prefix("{$mydirname}_topic_access") );
	list($result) = $db->fetchRow($db->query($sql));
	if( empty($result) ){
		$sql ="CREATE TABLE ".$db->prefix("{$mydirname}_topic_access")." (
		topic_id smallint(5) unsigned NOT NULL default 0,
		uid mediumint(8) default NULL,
		groupid smallint(5) default NULL,
		can_post tinyint(1) NOT NULL default 0,
		can_edit tinyint(1) NOT NULL default 0,
		can_delete tinyint(1) NOT NULL default 0,
		post_auto_approved tinyint(1) NOT NULL default 0,
		UNIQUE KEY (topic_id,uid),
		UNIQUE KEY (topic_id,groupid),
		KEY (topic_id),
		KEY (uid),
		KEY (groupid),
		KEY (can_post)
		) ENGINE=MyISAM;
		";
		if( $db->query($sql) ){
			$msgs[] = '&nbsp;&nbsp;Table <b>'.htmlspecialchars($db->prefix("{$mydirname}_topic_access")).'</b> created.';
		}else{
			$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
		}
//ver2.22->ver3.0  creat data to topic_access
		$can_groups = array();
		$can_read_topic_id = array();
		$topic_access_data = "";
		$sql = "SELECT gperm_groupid FROM ".$db->prefix('group_permission');
		$sql .= " WHERE gperm_itemid = ".$mid;
		$sql .= " AND gperm_modid = 1";
		$sql .= " AND gperm_name = 'module_read'";
		$result = $db->query($sql);
		if (empty($result)){
			$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
		}else{
			while ($myrow = $db->fetchArray($result)) {
				$can_groups[$myrow['gperm_groupid']]['can_read'] = 1;
				$can_groups[$myrow['gperm_groupid']]['can_post'] = 0;
				$can_groups[$myrow['gperm_groupid']]['can_edit'] = 0;
				$can_groups[$myrow['gperm_groupid']]['can_delete'] = 0;
				$can_groups[$myrow['gperm_groupid']]['post_auto_approved'] = 0;
			}
			if (!empty($can_groups)){
				//ca_post,post_auto_approved
				$sql = "SELECT * FROM ".$db->prefix('group_permission');
				$sql .= " WHERE gperm_modid = ".$mid;
				$sql .= " AND gperm_name = 'bulletin_permit'";
				$result = $db->query($sql);
				if (empty($result)){
					$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
				}else{
					while ($myrow = $db->fetchArray($result)) {
						if(isset($can_groups[$myrow['gperm_groupid']])){
							switch ($myrow['gperm_itemid']) {
							case 1:
								$can_groups[$myrow['gperm_groupid']]['can_post'] = 1;
								break;
							case 2:
								$can_groups[$myrow['gperm_groupid']]['post_auto_approved'] = 1;
								break;
							}
						}
					}
					$sql = "SELECT gperm_groupid FROM ".$db->prefix('group_permission');
					$sql .= " WHERE gperm_itemid = ".$mid;
					$sql .= " AND gperm_modid = 1";
					$sql .= " AND gperm_name = 'module_admin'";
					$result = $db->query($sql);
					if (empty($result)){
						$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
					}else{
						while ($myrow = $db->fetchArray($result)) {
							if(isset($can_groups[$myrow['gperm_groupid']])){
								$can_groups[$myrow['gperm_groupid']]['can_post'] = 1;
								$can_groups[$myrow['gperm_groupid']]['can_edit'] = 1;
								$can_groups[$myrow['gperm_groupid']]['can_delete'] = 1;
								$can_groups[$myrow['gperm_groupid']]['post_auto_approved'] = 1;
							}
						}
						$sql = "SELECT topic_id FROM ".$db->prefix("{$mydirname}_topics");
						$result = $db->query($sql);
						if (empty($result)){
							$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
						}else{
							while ($myrow = $db->fetchArray($result)) {
								$can_read_topic_id[] = $myrow['topic_id'];
							}
							if (!empty($can_read_topic_id)){
								foreach ($can_read_topic_id as $topic_id) {
									foreach ($can_groups as $groupid => $value) {
										$sql = "INSERT INTO `".$db->prefix("{$mydirname}_topic_access")."`";
										$sql .= " (`topic_id`, `uid`, `groupid`, `can_post`, `can_edit`, `can_delete`, `post_auto_approved`)";
										$sql .= " VALUES (".$topic_id.", NULL, ".$groupid.", ".$value['can_post'].", ".$value['can_edit'].", ".$value['can_delete'].", ".$value['post_auto_approved'].")";
										if ($db->query($sql)){
											$msgs[] = '&nbsp;&nbsp;Table <b>'.htmlspecialchars($db->prefix("{$mydirname}_topic_access")).'</b> add '.$topic_id.' for group '.$groupid ;
										}else{
											$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	// TEMPLATES (all templates have been already removed by modulesadmin)
	$tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
	$tpl_path = dirname(__FILE__).'/templates' ;
	if( $handler = @opendir( $tpl_path . '/' ) ) {
		while( ( $file = readdir( $handler ) ) !== false ) {
			if( substr( $file , 0 , 1 ) == '.' ) continue ;
			$file_path = $tpl_path . '/' . $file ;
			if( is_file( $file_path ) && substr( $file , -5 ) == '.html' ) {
				$mtime = intval( @filemtime( $file_path ) ) ;
				$tplfile =& $tplfile_handler->create() ;
				$tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
				$tplfile->setVar( 'tpl_refid' , $mid ) ;
				$tplfile->setVar( 'tpl_tplset' , 'default' ) ;
				$tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ;
				$tplfile->setVar( 'tpl_desc' , '' , true ) ;
				$tplfile->setVar( 'tpl_module' , $mydirname ) ;
				$tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
				$tplfile->setVar( 'tpl_lastimported' , 0 ) ;
				$tplfile->setVar( 'tpl_type' , 'module' ) ;
				if( ! $tplfile_handler->insert( $tplfile ) ) {
					$msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
				} else {
					$tplid = $tplfile->getVar( 'tpl_id' ) ;
					$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)';
					// generate compiled file
					include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
					include_once XOOPS_ROOT_PATH.'/class/template.php';
					if( ! xoops_template_touch( $tplid ) ) {
						$msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>';
					} else {
						$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>';
					}
				}
			}
		}
		closedir( $handler ) ;
	}
	include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
	include_once XOOPS_ROOT_PATH.'/class/template.php' ;
	xoops_template_clear_module_cache( $mid ) ;

	// BLOCKS
	$tpl_path = dirname(__FILE__).'/templates/blocks' ;
	if( $handler = @opendir( $tpl_path . '/' ) ) {
		while( ( $file = readdir( $handler ) ) !== false ) {
			if( substr( $file , 0 , 1 ) == '.' ) continue ;
			$file_path = $tpl_path . '/' . $file ;
			if( is_file( $file_path ) && substr( $file , -5 ) == '.html' ) {
				$mtime = intval( @filemtime( $file_path ) ) ;
				$tpl_file = $mydirname . '_' . $file;
				$tpl_source = file_get_contents( $file_path );
				$sql = "SELECT tpl_id, tpl_refid FROM ".$db->prefix('tplfile')." WHERE tpl_module='$mydirname' AND tpl_file='".mysql_escape_string($tpl_file)."'";
				list($tpl_id, $block_id) = $db->fetchRow($db->query($sql));
				if( empty($tpl_id) && empty($block_id)){
					$blocks_info = $module->getInfo('blocks');
					$show_func = '';
					foreach($blocks_info as $oneblock){
						if($tpl_file == $oneblock['template']){
							$show_func = $oneblock['show_func'];
							break;
						}
					}
					if( $show_func != ''){
						$sql = sprintf("SELECT bid FROM %s WHERE dirname=%s AND show_func=%s", $db->prefix("newblocks"), $db->quoteString($mydirname), $db->quoteString($show_func) ) ;
						list($block_id) = $xoopsDB->fetchRow($xoopsDB->query($sql));
						if($block_id){
							$tplfile =& $tplfile_handler->create();
							$tplfile->setVar('tpl_module', $mydirname);
							$tplfile->setVar('tpl_refid', $block_id);
							$tplfile->setVar('tpl_source', $tpl_source, true);
							$tplfile->setVar('tpl_tplset', 'default');
							$tplfile->setVar('tpl_file', $tpl_file, true);
							$tplfile->setVar('tpl_type', 'block');
							$tplfile->setVar('tpl_lastimported', 0);
							$tplfile->setVar('tpl_lastmodified', time());
							$tplfile->setVar('tpl_desc', '', true);
							if (!$tplfile_handler->insert($tplfile)) {
								$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>'.$tpl_file.'</b> to the database.</span>';
							} else {
								$newid = $tplfile->getVar('tpl_id');
								$msgs[] = '&nbsp;&nbsp;Template <b>'.$tpl_file.'</b> added to the database.';
								if ($xoopsConfig['template_set'] == 'default') {
									if (!xoops_template_touch($block_id)) {
										$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Template <b>'.$tpl_file.'</b> recompile failed.</span>';
									} else {
										$msgs[] = '&nbsp;&nbsp;Template <b>'.$tpl_file.'</b> recompiled.';
									}
								}
							}
							$sql = "UPDATE ".$db->prefix("newblocks")." SET template='".mysql_escape_string($tpl_file)."', last_modified=".time()." WHERE bid=".$block_id;
							if( !$result = $db->query($sql) ) {
								$msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
							}else{
								$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$newid.'</b>)';
							}
						}
					}
				}
				elseif (!empty($tpl_id) && isset($tpl_source) && $tpl_source != '') {
					$sql = "SELECT COUNT(*) FROM ".$db->prefix('tplsource')." WHERE tpl_id='$tpl_id'";
					list($count) = $xoopsDB->fetchRow($xoopsDB->query($sql));
					if($count==0){
						$sql = sprintf("INSERT INTO %s (tpl_id, tpl_source) VALUES (%u, %s)", $db->prefix('tplsource'), $tpl_id, $db->quoteString($tpl_source));
					}else{
						$sql = "UPDATE ".$db->prefix("tplsource")." SET tpl_source='".mysql_escape_string($tpl_source)."' WHERE tpl_id=".$tpl_id;
					}
					if( !$result = $db->query($sql) ) {
						$msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
					} else {
						$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tpl_id.'</b>)';
						// generate compiled file
						include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
						include_once XOOPS_ROOT_PATH.'/class/template.php';
						if( ! xoops_template_touch( $tpl_id ) ) {
							$msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>';
						} else {
							$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>';
						}
					}
					$sql = "UPDATE ".$db->prefix("newblocks")." SET template='".mysql_escape_string($tpl_file)."', last_modified=".time()." WHERE bid=".$block_id;
					if( !$result = $db->query($sql) ) {
						$msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
					}else{
						$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tpl_id.'</b>)';
					}
				}
			}
		}
		closedir( $handler ) ;
	}

	return true ;
}
コード例 #5
0
ファイル: main.php プロジェクト: BackupTheBerlios/soopa
             } else {
                 $tpl =& $tpltpl_handler->get($old_template[$upload_file]);
             }
             $tpl->setVar('tpl_lastmodified', time());
             $fp = @fopen($uploader->getSavedDestination(), 'r');
             $fsource = @fread($fp, filesize($uploader->getSavedDestination()));
             @fclose($fp);
             $tpl->setVar('tpl_source', $fsource, true);
             @unlink($uploader->getSavedDestination());
             if (!$tpltpl_handler->insert($tpl)) {
                 $msg[] = 'Failed inserting data for ' . $upload_file . ' to database';
             } else {
                 $msg[] = 'Template file <b>' . $upload_file . '</b> updated.';
                 if ($tplset == $xoopsConfig['template_set']) {
                     include_once XOOPS_ROOT_PATH . '/class/template.php';
                     if (xoops_template_touch($tpl, true)) {
                         $msg[] = 'Template file <b>' . $upload_file . '</b> compiled.';
                     }
                 }
             }
         }
     } else {
         if ($uploader->getMediaName() == '') {
             continue;
         } else {
             $msg[] = $uploader->getErrors();
         }
     }
 }
 xoops_cp_header();
 echo '<code>';
コード例 #6
0
ファイル: onupdate.php プロジェクト: naao/attachfile
 function attachfile_onupdate_base($module, $mydirname)
 {
     // transations on module update
     global $msgs;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'attachfile_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // non
     // TEMPLATES (all templates have been already removed by modulesadmin)
     $tplfile_handler =& xoops_gethandler('tplfile');
     $tpl_path = dirname(__FILE__) . '/templates';
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path)) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                     // generate compiled file
                     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                     include_once XOOPS_ROOT_PATH . '/class/template.php';
                     if (!xoops_template_touch($tplid)) {
                         $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span>';
                     }
                 }
             }
         }
         closedir($handler);
     }
     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
     include_once XOOPS_ROOT_PATH . '/class/template.php';
     xoops_template_clear_module_cache($mid);
     return true;
 }
コード例 #7
0
ファイル: oninstall.php プロジェクト: nouphet/rata
function bulletin_oninstall_base($module, $mydirname)
{
    // transations on module install
    global $ret;
    $db =& Database::getInstance();
    $mid = $module->getVar('mid');
    // for Cube 2.1
    if (defined('XOOPS_CUBE_LEGACY')) {
        $isCube = true;
        $root =& XCube_Root::getSingleton();
        $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'bulletin_message_append_oninstall');
        $ret = array();
    } else {
        $isCube = false;
        if (!is_array($ret)) {
            $ret = array();
        }
    }
    // transations on module installation
    $bulletin_posting_permissions = array(1, 2, 3, 7);
    $gperm_handler = xoops_gethandler('groupperm');
    foreach ($bulletin_posting_permissions as $itemid) {
        $gperm =& $gperm_handler->create();
        $gperm->setVar('gperm_groupid', 1);
        $gperm->setVar('gperm_name', 'bulletin_permit');
        $gperm->setVar('gperm_modid', $mid);
        $gperm->setVar('gperm_itemid', $itemid);
        $gperm_handler->insert($gperm);
    }
    // TABLES (loading mysql.sql)
    $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql';
    $prefix_mod = $db->prefix() . '_' . $mydirname;
    if (file_exists($sql_file_path)) {
        $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path) . "</b>.<br  /> Creating tables...<br />";
        if (file_exists(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) {
            include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php';
            $sqlutil = new OldSqlUtility();
        } else {
            include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
            $sqlutil = new SqlUtility();
        }
        $sql_query = trim(file_get_contents($sql_file_path));
        $sqlutil->splitMySqlFile($pieces, $sql_query);
        $created_tables = array();
        foreach ($pieces as $piece) {
            $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod);
            if (!$prefixed_query) {
                $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece) . "</b><br />";
                return false;
            }
            if (!$db->query($prefixed_query[0])) {
                $ret[] = '<b>' . htmlspecialchars($db->error()) . '</b><br />';
                var_dump($db->error());
                return false;
            } else {
                if (!in_array($prefixed_query[4], $created_tables)) {
                    $ret[] = '&nbsp;&nbsp;Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br />';
                    $created_tables[] = $prefixed_query[4];
                } else {
                    $ret[] = '&nbsp;&nbsp;Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b>.</br />';
                }
            }
        }
    }
    // TEMPLATES
    $tplfile_handler =& xoops_gethandler('tplfile');
    $tpl_path = dirname(__FILE__) . '/templates';
    if ($handler = @opendir($tpl_path . '/')) {
        while (($file = readdir($handler)) !== false) {
            if (substr($file, 0, 1) == '.') {
                continue;
            }
            $file_path = $tpl_path . '/' . $file;
            if (is_file($file_path) && substr($file, -5) == '.html') {
                $mtime = intval(@filemtime($file_path));
                $tplfile =& $tplfile_handler->create();
                $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                $tplfile->setVar('tpl_refid', $mid);
                $tplfile->setVar('tpl_tplset', 'default');
                $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                $tplfile->setVar('tpl_desc', '', true);
                $tplfile->setVar('tpl_module', $mydirname);
                $tplfile->setVar('tpl_lastmodified', $mtime);
                $tplfile->setVar('tpl_lastimported', 0);
                $tplfile->setVar('tpl_type', 'module');
                if (!$tplfile_handler->insert($tplfile)) {
                    $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br />';
                } else {
                    $tplid = $tplfile->getVar('tpl_id');
                    $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />';
                    // generate compiled file
                    include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                    include_once XOOPS_ROOT_PATH . '/class/template.php';
                    if (!xoops_template_touch($tplid)) {
                        $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br />';
                    } else {
                        $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br />';
                    }
                }
            }
        }
        closedir($handler);
    }
    include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
    include_once XOOPS_ROOT_PATH . '/class/template.php';
    xoops_template_clear_module_cache($mid);
    // BLOCKS
    $tpl_path = dirname(__FILE__) . '/templates/blocks';
    if ($handler = @opendir($tpl_path . '/')) {
        while (($file = readdir($handler)) !== false) {
            if (substr($file, 0, 1) == '.') {
                continue;
            }
            $file_path = $tpl_path . '/' . $file;
            if (is_file($file_path) && substr($file, -5) == '.html') {
                $mtime = intval(@filemtime($file_path));
                $tpl_file = $mydirname . '_' . $file;
                $sql = "SELECT tpl_id FROM " . $db->prefix('tplfile') . " WHERE tpl_module='{$mydirname}' AND tpl_file='" . mysql_escape_string($tpl_file) . "'";
                list($tpl_id) = $db->fetchRow($db->query($sql));
                $tpl_source = file_get_contents($file_path);
                if (!empty($tpl_id) && isset($tpl_source) && $tpl_source != '') {
                    $sql = sprintf("INSERT INTO %s (tpl_id, tpl_source) VALUES (%u, %s)", $db->prefix('tplsource'), $tpl_id, $db->quoteString($tpl_source));
                    if (!($result = $db->query($sql))) {
                        $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br />';
                    } else {
                        $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tpl_id . '</b>)<br />';
                        // generate compiled file
                        include_once XOOPS_ROOT_PATH . '/class/template.php';
                        if (!xoops_template_touch($tpl_id)) {
                            $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br />';
                        } else {
                            $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br />';
                        }
                    }
                }
            }
        }
        closedir($handler);
    }
    return true;
}
コード例 #8
0
ファイル: module.php プロジェクト: BackupTheBerlios/soopa
 /**
  * Insert blocks from module into the database
  *
  * @return void
  */
 function insertBlocks()
 {
     global $xoopsConfig, $xoopsUser;
     $block_handler =& xoops_gethandler('block');
     $blocks = $this->getInfo('blocks');
     $this->setMessage('Building blocks...');
     if ($blocks != false) {
         $count = count($blocks);
         $showfuncs = array();
         $funcfiles = array();
         foreach (array_keys($blocks) as $i) {
             if (isset($blocks[$i]['show_func']) && $blocks[$i]['show_func'] != '' && isset($blocks[$i]['file']) && $blocks[$i]['file'] != '') {
                 $editfunc = isset($blocks[$i]['edit_func']) ? $blocks[$i]['edit_func'] : '';
                 $showfuncs[] = $blocks[$i]['show_func'];
                 $funcfiles[] = $blocks[$i]['file'];
                 $template = '';
                 if (isset($blocks[$i]['template']) && trim($blocks[$i]['template']) != '') {
                     $content =& $this->gettemplate($blocks[$i]['template'], true);
                 }
                 if (!isset($content) || !$content) {
                     $content = '';
                 } else {
                     $template = $blocks[$i]['template'];
                 }
                 $options = '';
                 if (!empty($blocks[$i]['options'])) {
                     $options = $blocks[$i]['options'];
                 }
                 $myts =& MyTextSanitizer::getInstance();
                 $criteria = new CriteriaCompo(new Criteria('mid', $this->getVar('mid')));
                 $criteria->add(new Criteria('show_func', $myts->addSlashes($blocks[$i]['show_func'])));
                 $criteria->add(new Criteria('func_file', $myts->addSlashes($blocks[$i]['file'])));
                 if (isset($blocks[$i]['template']) && trim($blocks[$i]['template']) != '') {
                     $criteria->add(new Criteria('template', $myts->addSlashes($blocks[$i]['template'])));
                 }
                 $block = $block_handler->getObjects($criteria);
                 if (isset($block[0])) {
                     $block = $block[0];
                     $this->setMessage("Updating existing block");
                 } else {
                     $this->setMessage("Creating new block");
                     $block =& $block_handler->create();
                     $block->setVar('mid', $this->getVar('mid'));
                     $block->setVar('dirname', $this->getVar('dirname'));
                     $block->setVar('show_func', $blocks[$i]['show_func'], true);
                     $block->setVar('func_file', $blocks[$i]['file'], true);
                     $block->setVar('isactive', 1);
                 }
                 $block->setVar('name', $blocks[$i]['name'], true);
                 $block->setVar('edit_func', $editfunc, true);
                 $block->setVar('options', explode('|', $options), true);
                 $block->setVar('template', $template, true);
                 $block->setVar('last_modified', time());
                 if (!$block_handler->insert($block)) {
                     $this->setMessage('&nbsp;&nbsp;ERROR: Could not insert ' . $blocks[$i]['name']);
                 } else {
                     $this->setMessage('&nbsp;&nbsp;Block <b>' . $blocks[$i]['name'] . '</b> inserted. Block ID: <b>' . $block->getVar('bid') . '</b>');
                     if ($template != '') {
                         //Update or insert template
                         $tplfile_handler =& xoops_gethandler('tplfile');
                         $tplfile =& $tplfile_handler->find('default', 'block', $block->getVar('bid'));
                         if (count($tplfile) == 0) {
                             $tplfile_new =& $tplfile_handler->create();
                             $tplfile_new->setVar('tpl_module', $this->getVar('dirname'));
                             $tplfile_new->setVar('tpl_refid', $block->getVar('bid'));
                             $tplfile_new->setVar('tpl_tplset', 'default');
                             $tplfile_new->setVar('tpl_file', $template, true);
                             $tplfile_new->setVar('tpl_type', 'block');
                         } else {
                             $tplfile_new = $tplfile[0];
                         }
                         $tplfile_new->setVar('tpl_source', $content, true);
                         $tplfile_new->setVar('tpl_desc', $blocks[$i]['description'], true);
                         $tplfile_new->setVar('tpl_lastmodified', time());
                         $tplfile_new->setVar('tpl_lastimported', 0);
                         if (!$tplfile_handler->insert($tplfile_new)) {
                             $this->setMessage('&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>' . $blocks[$i]['template'] . '</b>.</span>');
                         } else {
                             $this->setMessage('&nbsp;&nbsp;Template <b>' . $blocks[$i]['template'] . '</b> inserted.');
                             if (isset($xoopsConfig['template_set']) && $xoopsConfig['template_set'] == 'default') {
                                 if (!xoops_template_touch($tplfile_new)) {
                                     $this->setMessage('&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not compile template <b>' . $blocks[$i]['template'] . '</b>.</span>');
                                 } else {
                                     $this->setMessage('&nbsp;&nbsp;Template <b>' . $blocks[$i]['template'] . '</b> compiled.');
                                 }
                             }
                         }
                     }
                 }
                 $blockids[] = $block->getVar('bid');
             }
         }
     }
     $block_arr = $block_handler->getByModule($this->getVar('mid'));
     if (count($block_arr) > 0) {
         foreach ($block_arr as $block) {
             if (!in_array($block->getVar('bid'), $blockids)) {
                 if (!$block_handler->delete($block)) {
                     $this->setMessage('&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete block <b>' . $block->getVar('name') . '</b>. Block ID: <b>' . $block->getVar('bid') . '</b><br />' . implode('<br />', $block->getErrors()) . '</span>');
                 } else {
                     $this->setMessage('&nbsp;&nbsp;Block <b>' . $block->getVar('name') . ' deleted. Block ID: <b>' . $block->getVar('bid') . '</b>');
                 }
             }
         }
     }
 }
コード例 #9
0
ファイル: oninstall.php プロジェクト: nunoluciano/uxcl
function xsns_oninstall($module, $mydirname)
{
	global $ret;
	
	if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
		$root =& XCube_Root::getSingleton();
		$root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success' , 'xsns_message_append_oninstall' ) ;
		$root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Fail' , 'xsns_message_append_oninstall' ) ;
		$ret = array() ;
	}
	else{
		if( !is_array($ret) ){
			$ret = array() ;
		}
	}
	
	$constpref = '_MI_'.strtoupper($mydirname);
	if(strlen($mydirname) > 15){
		$ret[] = constant($constpref.'_INSTERR').'<br />';
	}
	
	$db =& Database::getInstance() ;
	$mid = $module->getVar('mid') ;
	
	// Tables
	$sql_ver = floatval(substr(mysql_get_server_info(), 0, 3));
	if($sql_ver < 4){
		$sql_file = 'mysql3.sql';
	}
	elseif($sql_ver == 4.0){
		$sql_file = 'mysql40.sql';
	}
	else{
		$sql_file = 'mysql.sql';
	}
	$sql_file_path = realpath(dirname(__FILE__).'/sql/'.$sql_file);
	$prefix_mod = $db->prefix() . '_' . $mydirname ;
	if( file_exists( $sql_file_path ) ) {
		$ret[] = "SQL file found at <b>".htmlspecialchars($sql_file_path)."</b>.<br /> Creating tables...";
		
		if( file_exists( XOOPS_ROOT_PATH.'/class/database/oldsqlutility.php' ) ) {
			include_once XOOPS_ROOT_PATH.'/class/database/oldsqlutility.php' ;
			$sqlutil = new OldSqlUtility ;
		} else {
			include_once XOOPS_ROOT_PATH.'/class/database/sqlutility.php' ;
			$sqlutil = new SqlUtility ;
		}

		$sql_query = trim( file_get_contents( $sql_file_path ) ) ;
		$sqlutil->splitMySqlFile( $pieces , $sql_query ) ;
		$created_tables = array() ;
		if( is_array( $pieces ) ) {
			foreach( $pieces as $piece ) {
				$prefixed_query = $sqlutil->prefixQuery( $piece , $prefix_mod ) ;
				if( ! $prefixed_query ) {
					$ret[] = "Invalid SQL <b>".htmlspecialchars($piece)."</b><br />";
					return false ;
				}
				if( ! $db->query( $prefixed_query[0] ) ) {
					$ret[] = '<b>'.htmlspecialchars( $db->error() ).'</b><br />' ;
					return false ;
				}
				else {
					if( ! in_array( $prefixed_query[4] , $created_tables ) ) {
						$ret[] = 'Table <b>'.htmlspecialchars($prefix_mod.'_'.$prefixed_query[4]).'</b> created.<br />';						$created_tables[] = $prefixed_query[4];
					}
					else {
						$ret[] = 'Data inserted to table <b>'.htmlspecialchars($prefix_mod.'_'.$prefixed_query[4]).'</b>.</br />';
					}
				}
			}
		}
	}

	// Templates
	$tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
	$tpl_path = dirname(__FILE__).'/templates' ;
	if( $handler = @opendir( $tpl_path . '/' ) ) {
		while( ( $file = readdir( $handler ) ) !== false ) {
			if( substr( $file , 0 , 1 ) == '.' || !preg_match('/(\.html$)|(\.css$)/i', $file)){
				continue ;
			}
			$file_path = $tpl_path . '/' . $file ;
			if( is_file( $file_path ) ) {
				$mtime = intval( @filemtime( $file_path ) ) ;
				$tplfile =& $tplfile_handler->create() ;
				$tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
				$tplfile->setVar( 'tpl_refid' , $mid ) ;
				$tplfile->setVar( 'tpl_tplset' , 'default' ) ;
				$tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ;
				$tplfile->setVar( 'tpl_desc' , '' , true ) ;
				$tplfile->setVar( 'tpl_module' , $mydirname ) ;
				$tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
				$tplfile->setVar( 'tpl_lastimported' , 0 ) ;
				$tplfile->setVar( 'tpl_type' , 'module' ) ;
				if( ! $tplfile_handler->insert( $tplfile ) ) {
					$ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span><br />';
				} else {
					$tplid = $tplfile->getVar( 'tpl_id' ) ;
					$ret[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)<br />';
					// generate compiled file
					include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
					include_once XOOPS_ROOT_PATH.'/class/template.php' ;
					if( ! xoops_template_touch( $tplid ) ) {
						$ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span><br />';
					} else {
						$ret[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span><br />';
					}
				}
			}
		}
		closedir( $handler ) ;
	}
	include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
	include_once XOOPS_ROOT_PATH.'/class/template.php' ;
	xoops_template_clear_module_cache( $mid ) ;
	
	
	// Set default categories
	$ini_category_list = array(
		// 小カテゴリ名, 表示順, 中カテゴリID
		array(constant($constpref.'_CATEGORY_1'), 1, 1),
		array(constant($constpref.'_CATEGORY_2'), 2, 1),
		array(constant($constpref.'_CATEGORY_3'), 3, 1),
		array(constant($constpref.'_CATEGORY_4'), 50, 1),
	);
	
	$sql_values = array();
	$selector_arr = array();
	$id = 1;
	
	foreach($ini_category_list as $category){
		$values = array();
		foreach($category as $v){
			$values[] = "'".$v."'";
		}
		$sql_values[] = "(".implode(',', $values).")";
		$selector_arr[] = "<a href=\"".XOOPS_URL."/modules/".$mydirname."/?cat_id=".($id++)."\">".$category[0]."<nobr><small>(0)</small></nobr></a>";
	}
	
	if(count($sql_values) > 0 || count($selector_arr) > 0){
		$sql = "INSERT INTO ".$db->prefix($mydirname.'_c_commu_category').
				" (name,sort_order,c_commu_category_parent_id) VALUES ".
				implode(",", $sql_values);
		if($db->query($sql)){
			$sql = "INSERT INTO ".$db->prefix($mydirname.'_c_commu_category_parent').
					" (name,sort_order,selector) VALUES".
					" ('".constant($constpref.'_CATEGORY')."', '1', '".implode("&nbsp;- ", $selector_arr)."')";
			return $db->query($sql);
		}
		else{
			return false;
		}
	}
	return true;
}
コード例 #10
0
/**
 * @param $dirname
 * @return string
 */
function xoops_module_update($dirname)
{
    global $xoopsUser, $xoopsConfig, $xoopsTpl;
    $dirname = trim($dirname);
    $xoopsDB =& $GLOBALS['xoopsDB'];
    $myts = MyTextSanitizer::getInstance();
    $dirname = $myts->htmlspecialchars(trim($dirname));
    $module_handler = xoops_getHandler('module');
    $module = $module_handler->getByDirname($dirname);
    // Save current version for use in the update function
    $prev_version = $module->getVar('version');
    $clearTpl = new XoopsTpl();
    $clearTpl->clearCache($dirname);
    // we don't want to change the module name set by admin
    $temp_name = $module->getVar('name');
    $module->loadInfoAsVar($dirname);
    $module->setVar('name', $temp_name);
    $module->setVar('last_update', time());
    /*
            // Call Header
            // Define main template
            $GLOBALS['xoopsOption']['template_main'] = 'system_header.html';
            // Call Header
            xoops_cp_header();
            // Define Stylesheet
            $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
            // Define Breadcrumb and tips
            $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath'));
            $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_UPDATE);
            $xoBreadCrumb->addHelp(system_adminVersion('modulesadmin', 'help') . '#update');https://www.facebook.com/photo.php?v=10154358806675333
            $xoBreadCrumb->render();
    */
    if (!$module_handler->insert($module)) {
        echo '<p>Could not update ' . $module->getVar('name') . '</p>';
        echo "<br><div class='center'><a href='admin.php?fct=modulesadmin'>" . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
    } else {
        $newmid = $module->getVar('mid');
        $msgs = array();
        $msgs[] = '<div id="xo-module-log"><div class="header">';
        $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UPDATING . $module->getInfo('name', 's') . '</h4>';
        if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
            $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />';
        }
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
        if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
            $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . $myts->htmlspecialchars(trim($module->getInfo('author')));
        }
        $msgs[] = '</div><div class="logger">';
        $update_script = $module->getInfo('onUpdate');
        if (!empty($update_script) && trim($update_script) != '') {
            include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($update_script);
        }
        // execute module specific update script if any
        if (function_exists('xoops_module_pre_update_' . $dirname)) {
            $func = 'xoops_module_pre_update_' . $dirname;
            if (!$func($module, $prev_version)) {
                $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
                $msgs = array_merge($msgs, $module->getErrors());
            } else {
                $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, '<strong>' . $func . '</strong>') . '</p>';
                $msgs += $module->getErrors();
            }
        }
        $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_UPDATE;
        $tplfile_handler = xoops_getHandler('tplfile');
        // irmtfan bug fix: remove codes for delete templates
        /*
        $deltpl          = $tplfile_handler->find('default', 'module', $module->getVar('mid'));
        $delng           = array();
        if (is_array($deltpl)) {
            // delete template file entry in db
            $dcount = count($deltpl);
            for ($i = 0; $i < $dcount; $i++) {
                if (!$tplfile_handler->delete($deltpl[$i])) {
                    $delng[] = $deltpl[$i]->getVar('tpl_file');
                }
            }
        }
        */
        // irmtfan bug fix: remove codes for delete templates
        $templates = $module->getInfo('templates');
        if ($templates != false) {
            $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_UPDATE;
            foreach ($templates as $tpl) {
                $tpl['file'] = trim($tpl['file']);
                // START irmtfan solve templates duplicate issue
                // if (!in_array($tpl['file'], $delng)) { // irmtfan bug fix: remove codes for delete templates
                $type = isset($tpl['type']) ? $tpl['type'] : 'module';
                if (preg_match("/\\.css\$/i", $tpl['file'])) {
                    $type = 'css';
                }
                $criteria = new CriteriaCompo();
                $criteria->add(new Criteria('tpl_refid', $newmid), 'AND');
                $criteria->add(new Criteria('tpl_module', $dirname), 'AND');
                $criteria->add(new Criteria('tpl_tplset', 'default'), 'AND');
                $criteria->add(new Criteria('tpl_file', $tpl['file']), 'AND');
                $criteria->add(new Criteria('tpl_type', $type), 'AND');
                $tplfiles = $tplfile_handler->getObjects($criteria);
                $tpldata =& xoops_module_gettemplate($dirname, $tpl['file'], $type);
                $tplfile = empty($tplfiles) ? $tplfile_handler->create() : $tplfiles[0];
                // END irmtfan solve templates duplicate issue
                $tplfile->setVar('tpl_refid', $newmid);
                $tplfile->setVar('tpl_lastimported', 0);
                $tplfile->setVar('tpl_lastmodified', time());
                $tplfile->setVar('tpl_type', $type);
                $tplfile->setVar('tpl_source', $tpldata, true);
                $tplfile->setVar('tpl_module', $dirname);
                $tplfile->setVar('tpl_tplset', 'default');
                $tplfile->setVar('tpl_file', $tpl['file'], true);
                $tplfile->setVar('tpl_desc', $tpl['description'], true);
                if (!$tplfile_handler->insert($tplfile)) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
                } else {
                    $newid = $tplfile->getVar('tpl_id');
                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_INSERT_DATA, '<strong>' . $tpl['file'] . '</strong>');
                    if ($xoopsConfig['template_set'] === 'default') {
                        if (!xoops_template_touch($newid)) {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
                        } else {
                            $msgs[] = '&nbsp;&nbsp;<span>' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
                        }
                    }
                }
                unset($tpldata);
                // irmtfan bug fix: remove codes for delete templates
                /*
                } else {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_OLD_ERROR, "<strong>".$tpl['file']."</strong>").'</span>';
                }
                */
                // irmtfan bug fix: remove codes for delete templates
            }
        }
        $blocks = $module->getInfo('blocks');
        $msgs[] = _AM_SYSTEM_MODULES_BLOCKS_REBUILD;
        if ($blocks != false) {
            $showfuncs = array();
            $funcfiles = array();
            foreach ($blocks as $i => $block) {
                if (isset($block['show_func']) && $block['show_func'] != '' && isset($block['file']) && $block['file'] != '') {
                    $editfunc = isset($block['edit_func']) ? $block['edit_func'] : '';
                    $showfuncs[] = $block['show_func'];
                    $funcfiles[] = $block['file'];
                    $template = '';
                    if (isset($block['template']) && trim($block['template']) != '') {
                        $content =& xoops_module_gettemplate($dirname, $block['template'], 'blocks');
                    }
                    if (!$content) {
                        $content = '';
                    } else {
                        $template = $block['template'];
                    }
                    $options = '';
                    if (!empty($block['options'])) {
                        $options = $block['options'];
                    }
                    $sql = 'SELECT bid, name FROM ' . $xoopsDB->prefix('newblocks') . ' WHERE mid=' . $module->getVar('mid') . ' AND func_num=' . $i . " AND show_func='" . addslashes($block['show_func']) . "' AND func_file='" . addslashes($block['file']) . "'";
                    $fresult = $xoopsDB->query($sql);
                    $fcount = 0;
                    while ($fblock = $xoopsDB->fetchArray($fresult)) {
                        ++$fcount;
                        $sql = 'UPDATE ' . $xoopsDB->prefix('newblocks') . " SET name='" . addslashes($block['name']) . "', edit_func='" . addslashes($editfunc) . "', content='', template='" . $template . "', last_modified=" . time() . ' WHERE bid=' . $fblock['bid'];
                        $result = $xoopsDB->query($sql);
                        if (!$result) {
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_UPDATE_ERROR, $fblock['name']);
                        } else {
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_UPDATE, $fblock['name']) . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $fblock['bid'] . '</strong>');
                            if ($template != '') {
                                $tplfile = $tplfile_handler->find('default', 'block', $fblock['bid']);
                                if (count($tplfile) == 0) {
                                    $tplfile_new = $tplfile_handler->create();
                                    $tplfile_new->setVar('tpl_module', $dirname);
                                    $tplfile_new->setVar('tpl_refid', $fblock['bid']);
                                    $tplfile_new->setVar('tpl_tplset', 'default');
                                    $tplfile_new->setVar('tpl_file', $block['template'], true);
                                    $tplfile_new->setVar('tpl_type', 'block');
                                } else {
                                    $tplfile_new = $tplfile[0];
                                }
                                $tplfile_new->setVar('tpl_source', $content, true);
                                $tplfile_new->setVar('tpl_desc', $block['description'], true);
                                $tplfile_new->setVar('tpl_lastmodified', time());
                                $tplfile_new->setVar('tpl_lastimported', 0);
                                $tplfile_new->setVar('tpl_file', $block['template'], true);
                                // irmtfan bug fix:  block template file will not updated after update the module
                                if (!$tplfile_handler->insert($tplfile_new)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
                                } else {
                                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE, '<strong>' . $block['template'] . '</strong>');
                                    if ($xoopsConfig['template_set'] === 'default') {
                                        if (!xoops_template_touch($tplfile_new->getVar('tpl_id'))) {
                                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
                                        } else {
                                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $block['template'] . '</strong>');
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if ($fcount == 0) {
                        $newbid = $xoopsDB->genId($xoopsDB->prefix('newblocks') . '_bid_seq');
                        $block_name = addslashes($block['name']);
                        $block_type = $module->getVar('dirname') === 'system' ? 'S' : 'M';
                        $sql = 'INSERT INTO ' . $xoopsDB->prefix('newblocks') . ' (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, isactive, dirname, func_file, show_func, edit_func, template, last_modified) VALUES (' . $newbid . ', ' . $module->getVar('mid') . ', ' . $i . ",'" . addslashes($options) . "','" . $block_name . "', '" . $block_name . "', '', 0, 0, 0, '{$block_type}', 1, '" . addslashes($dirname) . "', '" . addslashes($block['file']) . "', '" . addslashes($block['show_func']) . "', '" . addslashes($editfunc) . "', '" . $template . "', " . time() . ')';
                        $result = $xoopsDB->query($sql);
                        if (!$result) {
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_CREATE, $block['name']);
                            echo $sql;
                        } else {
                            if (empty($newbid)) {
                                $newbid = $xoopsDB->getInsertId();
                            }
                            if ($module->getInfo('hasMain')) {
                                $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS);
                            } else {
                                $groups = array(XOOPS_GROUP_ADMIN);
                            }
                            $gperm_handler = xoops_getHandler('groupperm');
                            foreach ($groups as $mygroup) {
                                $bperm = $gperm_handler->create();
                                $bperm->setVar('gperm_groupid', $mygroup);
                                $bperm->setVar('gperm_itemid', $newbid);
                                $bperm->setVar('gperm_name', 'block_read');
                                $bperm->setVar('gperm_modid', 1);
                                if (!$gperm_handler->insert($bperm)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_ACCESS_ERROR . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>') . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, '<strong>' . $mygroup . '</strong>') . '</span>';
                                } else {
                                    $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_BLOCK_ACCESS . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>') . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, '<strong>' . $mygroup . '</strong>');
                                }
                            }
                            if ($template != '') {
                                $tplfile = $tplfile_handler->create();
                                $tplfile->setVar('tpl_module', $dirname);
                                $tplfile->setVar('tpl_refid', $newbid);
                                $tplfile->setVar('tpl_source', $content, true);
                                $tplfile->setVar('tpl_tplset', 'default');
                                $tplfile->setVar('tpl_file', $block['template'], true);
                                $tplfile->setVar('tpl_type', 'block');
                                $tplfile->setVar('tpl_lastimported', time());
                                $tplfile->setVar('tpl_lastmodified', time());
                                $tplfile->setVar('tpl_desc', $block['description'], true);
                                if (!$tplfile_handler->insert($tplfile)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
                                } else {
                                    $newid = $tplfile->getVar('tpl_id');
                                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, '<strong>' . $block['template'] . '</strong>');
                                    if ($xoopsConfig['template_set'] === 'default') {
                                        if (!xoops_template_touch($newid)) {
                                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_FAILD, '<strong>' . $block['template'] . '</strong>') . '</span>';
                                        } else {
                                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $block['template'] . '</strong>');
                                        }
                                    }
                                }
                            }
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_CREATED, '<strong>' . $block['name'] . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>');
                            $sql = 'INSERT INTO ' . $xoopsDB->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)';
                            $xoopsDB->query($sql);
                        }
                    }
                }
            }
            $block_arr = XoopsBlock::getByModule($module->getVar('mid'));
            foreach ($block_arr as $block) {
                if (!in_array($block->getVar('show_func'), $showfuncs) || !in_array($block->getVar('func_file'), $funcfiles)) {
                    $sql = sprintf('DELETE FROM %s WHERE bid = %u', $xoopsDB->prefix('newblocks'), $block->getVar('bid'));
                    if (!$xoopsDB->query($sql)) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_ERROR, '<strong>' . $block->getVar('name') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $block->getVar('bid') . '</strong>') . '</span>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;Block <strong>' . $block->getVar('name') . ' deleted. Block ID: <strong>' . $block->getVar('bid') . '</strong>';
                        if ($block->getVar('template') != '') {
                            $tplfiles = $tplfile_handler->find(null, 'block', $block->getVar('bid'));
                            if (is_array($tplfiles)) {
                                $btcount = count($tplfiles);
                                for ($k = 0; $k < $btcount; $k++) {
                                    if (!$tplfile_handler->delete($tplfiles[$k])) {
                                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_DEPRECATED_ERROR . '(ID: <strong>' . $tplfiles[$k]->getVar('tpl_id') . '</strong>)</span>';
                                    } else {
                                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DEPRECATED, '<strong>' . $tplfiles[$k]->getVar('tpl_file') . '</strong>');
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // reset compile_id
        //        $xoTheme  =& $xoopsThemeFactory->createInstance(array('contentTemplate' => @$GLOBALS['xoopsOption']['template_main']));
        //        $xoopsTpl =& $xoTheme->template;
        //        $xoopsTpl->setCompileId();
        $template = $clearTpl;
        $template->setCompileId();
        //        $GLOBALS['xoopsTpl']->setCompileId();
        //        $xoopsTpl->setCompileId();
        // first delete all config entries
        $config_handler = xoops_getHandler('config');
        $configs = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
        $confcount = count($configs);
        $config_delng = array();
        if ($confcount > 0) {
            $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_DELETE;
            for ($i = 0; $i < $confcount; $i++) {
                if (!$config_handler->deleteConfig($configs[$i])) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_CONFIG_DATA_DELETE_ERROR . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getvar('conf_id') . '</strong>') . '</span>';
                    // save the name of config failed to delete for later use
                    $config_delng[] = $configs[$i]->getvar('conf_name');
                } else {
                    $config_old[$configs[$i]->getvar('conf_name')]['value'] = $configs[$i]->getvar('conf_value', 'N');
                    $config_old[$configs[$i]->getvar('conf_name')]['formtype'] = $configs[$i]->getvar('conf_formtype');
                    $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype');
                    $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getVar('conf_id') . '</strong>');
                }
            }
        }
        // now reinsert them with the new settings
        $configs = $module->getInfo('config');
        if ($configs != false) {
            if ($module->getVar('hascomments') != 0) {
                include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
                array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)));
                array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0));
            }
        } else {
            if ($module->getVar('hascomments') != 0) {
                $configs = array();
                include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
                $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN));
                $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0);
            }
        }
        // RMV-NOTIFY
        if ($module->getVar('hasnotification') != 0) {
            if (empty($configs)) {
                $configs = array();
            }
            // Main notification options
            include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
            include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
            $options = array();
            $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
            $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
            $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
            $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
            //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
            $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options);
            // Event specific notification options
            // FIXME: for some reason the default doesn't come up properly
            //  initially is ok, but not when 'update' module..
            $options = array();
            $categories =& notificationCategoryInfo('', $module->getVar('mid'));
            foreach ($categories as $category) {
                $events =& notificationEvents($category['name'], false, $module->getVar('mid'));
                foreach ($events as $event) {
                    if (!empty($event['invisible'])) {
                        continue;
                    }
                    $option_name = $category['title'] . ' : ' . $event['title'];
                    $option_value = $category['name'] . '-' . $event['name'];
                    $options[$option_name] = $option_value;
                    //$configs[] = array ('name' => notificationGenerateConfig($category,$event,'name'), 'title' => notificationGenerateConfig($category,$event,'title_constant'), 'description' => notificationGenerateConfig($category,$event,'description_constant'), 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
                }
            }
            $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options);
        }
        if ($configs != false) {
            $msgs[] = 'Adding module config data...';
            $config_handler = xoops_getHandler('config');
            $order = 0;
            foreach ($configs as $config) {
                // only insert ones that have been deleted previously with success
                if (!in_array($config['name'], $config_delng)) {
                    $confobj = $config_handler->createConfig();
                    $confobj->setVar('conf_modid', $newmid);
                    $confobj->setVar('conf_catid', 0);
                    $confobj->setVar('conf_name', $config['name']);
                    $confobj->setVar('conf_title', $config['title'], true);
                    $confobj->setVar('conf_desc', $config['description'], true);
                    $confobj->setVar('conf_formtype', $config['formtype']);
                    if (isset($config['valuetype'])) {
                        $confobj->setVar('conf_valuetype', $config['valuetype']);
                    }
                    if (isset($config_old[$config['name']]['value']) && $config_old[$config['name']]['formtype'] == $config['formtype'] && $config_old[$config['name']]['valuetype'] == $config['valuetype']) {
                        // preserver the old value if any
                        // form type and value type must be the same
                        $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true);
                    } else {
                        $confobj->setConfValueForInput($config['default'], true);
                        //$confobj->setVar('conf_value', $config['default'], true);
                    }
                    $confobj->setVar('conf_order', $order);
                    $confop_msgs = '';
                    if (isset($config['options']) && is_array($config['options'])) {
                        foreach ($config['options'] as $key => $value) {
                            $confop = $config_handler->createConfigOption();
                            $confop->setVar('confop_name', $key, true);
                            $confop->setVar('confop_value', $value, true);
                            $confobj->setConfOptions($confop);
                            $confop_msgs .= '<br>&nbsp;&nbsp;&nbsp;&nbsp; ' . _AM_SYSTEM_MODULES_CONFIG_ADD . _AM_SYSTEM_MODULES_NAME . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . _AM_SYSTEM_MODULES_VALUE . ' <strong>' . $value . '</strong> ';
                            unset($confop);
                        }
                    }
                    $order++;
                    if (false !== $config_handler->insertConfig($confobj)) {
                        //$msgs[] = '&nbsp;&nbsp;Config <strong>'.$config['name'].'</strong> added to the database.'.$confop_msgs;
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD, '<strong>' . $config['name'] . '</strong>') . $confop_msgs;
                    } else {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD_ERROR, '<strong>' . $config['name'] . '</strong>') . '</span>';
                    }
                    unset($confobj);
                }
            }
            unset($configs);
        }
        // execute module specific update script if any
        if (function_exists('xoops_module_update_' . $dirname)) {
            $func = 'xoops_module_update_' . $dirname;
            if (!$func($module, $prev_version)) {
                $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
                $msgs = array_merge($msgs, $module->getErrors());
            } else {
                $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, '<strong>' . $func . '</strong>') . '</p>';
                $msgs += $module->getErrors();
            }
        }
        $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKUPD, '<strong>' . $module->getVar('name', 's') . '</strong>');
        $msgs[] = '</div></div>';
        $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a>  | <a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_ADMIN . '</a></div>';
        //        foreach ($msgs as $msg) {
        //            echo $msg . '<br>';
        //        }
    }
    // Call Footer
    //    xoops_cp_footer();
    // Flush cache files for cpanel GUIs
    //    xoops_load("cpanel", "system");
    //    XoopsSystemCpanel::flush();
    //
    //    require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php';
    //    $maintenance = new SystemMaintenance();
    //    $folder      = array(1, 3);
    //    $maintenance->CleanCache($folder);
    //Set active modules in cache folder
    //    xoops_setActiveModules();
    //    break;
    //-----------------------------------------------
    $ret = implode('<br>', $msgs);
    return $ret;
}
コード例 #11
0
ファイル: mytplsform.php プロジェクト: nunoluciano/uxcl
}

// EDIT UPDATE
$errors = array() ;
if( ! empty( $_POST['do_modifycont'] ) || ! empty( $_POST['do_modify'] ) ) {
	if ( ! $xoopsGTicket->check( true , 'dbcss' ) ) {
		redirect_header(XOOPS_URL.'/modules/'.$mydirname.'/admin/index.php',3,$xoopsGTicket->getErrors());
	}

	$post_source = addslashes($myts->stripSlashesGPC( $_POST['tpl_source'] ) );

	$result = $db->query( "UPDATE ".$db->prefix("tplsource")." SET tpl_source='".$post_source."' WHERE tpl_id=$tpl_id" ) ;
	if( ! $result ) $errors[] = $tpl_id ;
	$result = $db->query( "UPDATE ".$db->prefix("tplfile")." SET tpl_lastmodified=UNIX_TIMESTAMP() WHERE tpl_id=$tpl_id" ) ;
	if( ! $result ) $errors[] = $tpl_id ;
	xoops_template_touch( $tpl_id ) ;

	// CONTINUE OR END ?
	if( ! empty( $_POST['do_modifycont'] ) ) {
		redirect_header(  XOOPS_URL."/modules/$mydirname/admin/index.php?page=mytplsform&tpl_id=".$tpl_id."&#dbcss_tplsform_top." , 2 , $errors ? sprintf( _MD_DBCSS_ERROR_MESSEAGE , implode( ',' , $errors ) ) : _MD_DBCSS_MYTPLSFORM_UPDATED ) ;
	} else {
		if( ! empty( $bid ) ) {
			redirect_header( XOOPS_URL."/modules/$mydirname/admin/index.php?mode=admin&lib=altsys&page=myblocksadmin&op=edit&bid=".$bid , 2 , $errors ? sprintf( _MD_DBCSS_ERROR_MESSEAGE , implode( ',' , $errors ) ) : _MD_DBCSS_MYTPLSFORM_UPDATED ) ;
		} else {
			redirect_header( XOOPS_URL."/modules/$mydirname/admin/index.php?page=export" , 2 , $errors ? sprintf( _MD_DBCSS_ERROR_MESSEAGE , implode( ',' , $errors ) ) : _MD_DBCSS_MYTPLSFORM_UPDATED ) ;
		}
	}
	exit() ;
}

// DISPLAY STAGE
コード例 #12
0
 function dbtheme_oninstall_base($module, $mydirname)
 {
     // transations on module install
     global $ret;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'dbtheme_message_append_oninstall');
         $ret = array();
     } else {
         if (!is_array($ret)) {
             $ret = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (loading mysql.sql)
     $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql';
     $prefix_mod = $db->prefix() . '_' . $mydirname;
     if (file_exists($sql_file_path)) {
         $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path) . "</b>.<br /> Creating tables...";
         if (file_exists(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) {
             include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php';
             $sqlutil =& new OldSqlUtility();
         } else {
             include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
             $sqlutil =& new SqlUtility();
         }
         $sql_query = trim(file_get_contents($sql_file_path));
         $sqlutil->splitMySqlFile($pieces, $sql_query);
         $created_tables = array();
         if (is_array($pieces)) {
             foreach ($pieces as $piece) {
                 $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod);
                 if (!$prefixed_query) {
                     $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece) . "</b><br />";
                     return false;
                 }
                 if (!$db->query($prefixed_query[0])) {
                     $ret[] = '<b>' . htmlspecialchars($db->error()) . '</b><br />';
                     //var_dump( $db->error() ) ;
                     return false;
                 } else {
                     if (!in_array($prefixed_query[4], $created_tables)) {
                         $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br />';
                         $created_tables[] = $prefixed_query[4];
                     } else {
                         $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b>.</br />';
                     }
                 }
             }
         }
     }
     // IMPORT THE SELECTED THEME AS THIS MODULE'S TEMPLATES
     $tplfile_handler =& xoops_gethandler('tplfile');
     /*************** BEGIN DBTHEME SPECIFIC PART ******************/
     // set weight=0
     $db->queryF("UPDATE " . $db->prefix("modules") . " SET weight=0 WHERE mid={$mid}");
     // set tpl_path
     $module_handler =& xoops_gethandler('module');
     $module =& $module_handler->getByDirname($mydirname);
     $config_handler =& xoops_gethandler('config');
     $mod_config =& $config_handler->getConfigsByCat(0, $module->getVar('mid'));
     if (file_exists(dirname(__FILE__) . '/templates/theme.html')) {
         $tpl_path = dirname(__FILE__) . '/templates';
     } else {
         if (!empty($mod_config['base_theme'])) {
             $tpl_path = XOOPS_ROOT_PATH . '/themes/' . $mod_config['base_theme'];
         } else {
             $tpl_path = XOOPS_ROOT_PATH . '/themes/' . $GLOBALS['xoopsConfig']['theme_set'];
         }
     }
     /*************** END DBTHEME SPECIFIC PART ******************/
     // TEMPLATES
     //$tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
     //$tpl_path = dirname(__FILE__).'/templates' ;
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 /*************** BEGIN DBTHEME SPECIFIC PART ******************/
                 // modify the theme/css
                 $tpl_source = file_get_contents($file_path);
                 $searches = array();
                 $replacements = array();
                 if (strrchr($file, '.') == '.html') {
                     // CSS hooking
                     $searches[] = '/\\"\\<\\{\\$xoops_imageurl\\}\\>([0-9a-zA-Z_-]+)\\.(css|html|js)\\"/';
                     $replacements[] = '"<{$xoops_url}>/modules/' . $mydirname . '/?template=$1.$2' . '"';
                 } else {
                     if (strrchr($file, '.') == '.css') {
                         // url() hooking
                         $searches[] = '#url\\(\\s*([\\"\']?)([0-9a-z./]{3})#i';
                         $replacements[] = 'url($1<{$xoops_imageurl}>$2';
                     }
                 }
                 $tplfile->setVar('tpl_source', preg_replace($searches, $replacements, $tpl_source));
                 $mtime = time();
                 /*************** END DBTHEME SPECIFIC PART ******************/
                 //				$tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br />';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />';
                     // generate compiled file
                     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                     include_once XOOPS_ROOT_PATH . '/class/template.php';
                     if (!xoops_template_touch($tplid)) {
                         $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br />';
                     } else {
                         $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br />';
                     }
                 }
             }
         }
         closedir($handler);
     }
     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
     include_once XOOPS_ROOT_PATH . '/class/template.php';
     xoops_template_clear_module_cache($mid);
     return true;
 }
コード例 #13
0
 function pico_onupdate_base($module, $mydirname)
 {
     // transations on module update
     global $msgs;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'pico_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // configs (Though I know it is not a recommended way...)
     $check_sql = "SHOW COLUMNS FROM " . $db->prefix("config") . " LIKE 'conf_title'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] == 'varchar(30)') {
         $db->queryF("ALTER TABLE " . $db->prefix("config") . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
     }
     // 0.1 -> 0.2
     $check_sql = "SELECT COUNT(*) FROM " . $db->prefix($mydirname . "_category_permissions");
     if (!$db->query($check_sql)) {
         $db->queryF("DROP TABLE " . $db->prefix($mydirname . "_category_access"));
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_category_permissions") . " ( cat_id smallint(5) unsigned NOT NULL default 0, uid mediumint(8) default NULL, groupid smallint(5) default NULL, permissions text, UNIQUE KEY (cat_id,uid), UNIQUE KEY (cat_id,groupid), KEY (cat_id), KEY (uid), KEY (groupid)) TYPE=MyISAM");
     }
     // 0.2 -> 0.9
     $check_sql = "SELECT cat_vpath FROM " . $db->prefix($mydirname . "_categories");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " ADD   `cat_vpath` varchar(255) AFTER `cat_id`, ADD UNIQUE KEY (`cat_vpath`)");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_contents") . " ADD   `vpath` varchar(255) AFTER `content_id`, ADD UNIQUE KEY (`vpath`)");
     }
     // 0.9 -> 0.95
     $check_sql = "SELECT cat_vpath_mtime FROM " . $db->prefix($mydirname . "_categories");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " ADD cat_created_time int(10) NOT NULL default 0, ADD cat_modified_time int(10) NOT NULL default 0, ADD cat_vpath_mtime int(10) NOT NULL default 0");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_contents") . " MODIFY weight smallint(5) NOT NULL default 0");
     }
     // 1.0 -> 1.1/1.2
     $check_sql = "SELECT COUNT(*) FROM " . $db->prefix($mydirname . "_content_histories");
     if (!$db->query($check_sql)) {
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_content_histories") . " ( content_history_id int(10) unsigned NOT NULL auto_increment, content_id int(10) unsigned NOT NULL default 0, vpath varchar(255), cat_id smallint(5) unsigned NOT NULL default 0, created_time int(10) NOT NULL default 0, modified_time int(10) NOT NULL default 0, poster_uid mediumint(8) unsigned NOT NULL default 0, poster_ip varchar(15) NOT NULL default '', modifier_uid mediumint(8) unsigned NOT NULL default 0, modifier_ip varchar(15) NOT NULL default '', subject varchar(255) NOT NULL default '', htmlheader mediumtext, body mediumtext, filters text, PRIMARY KEY (content_history_id), KEY (content_id), KEY (created_time), KEY (modified_time), KEY (modifier_uid) ) TYPE=MyISAM");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_contents") . " MODIFY htmlheader mediumtext, MODIFY htmlheader_waiting mediumtext, MODIFY body mediumtext, MODIFY body_waiting mediumtext, MODIFY body_cached mediumtext");
     }
     // 1.1/1.2 -> 1.3/1.4
     $check_sql = "SELECT cat_redundants FROM " . $db->prefix($mydirname . "_categories");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " MODIFY cat_id smallint(5) unsigned NOT NULL, ADD cat_redundants text AFTER cat_vpath_mtime");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_contents") . " ADD comments_count int(10) unsigned NOT NULL default 0 AFTER votes_count");
         $db->queryF("INSERT INTO " . $db->prefix($mydirname . "_categories") . " (cat_id,pid,cat_title) VALUES (0,0xffff,'TOP')");
     }
     // 1.3/1.4 -> 1.5/1.6
     $check_sql = "SELECT COUNT(*) FROM " . $db->prefix($mydirname . "_content_extras");
     if (!$db->query($check_sql)) {
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_content_extras") . " ( content_extra_id int(10) unsigned NOT NULL auto_increment, content_id int(10) unsigned NOT NULL default 0, extra_type varchar(255) NOT NULL default '', created_time int(10) NOT NULL default 0, modified_time int(10) NOT NULL default 0, data mediumtext, PRIMARY KEY (content_extra_id), KEY (content_id), KEY (extra_type), KEY (created_time) ) TYPE=MyISAM");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_contents") . " ADD `locked` tinyint(1) NOT NULL default 0 AFTER subject_waiting, ADD `redundants` text AFTER filters");
     }
     $check_sql = "SHOW CREATE TABLE " . $db->prefix($mydirname . "_content_histories");
     list(, $create_sql) = $db->fetchRow($db->queryF($check_sql));
     if (stristr($create_sql, '`body` text')) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_content_histories") . " MODIFY `htmlheader` mediumtext, MODIFY `body` mediumtext");
     }
     $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " MODIFY `cat_redundants` mediumtext");
     // 1.5/1.6 -> 1.7/1.8
     $check_sql = "SELECT cat_permission_id FROM " . $db->prefix($mydirname . "_categories");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_contents") . " ADD permission_id int(10) unsigned NOT NULL default 0 AFTER `content_id`, ADD expiring_time int(10) NOT NULL default 0x7fffffff AFTER `modified_time`, ADD last_cached_time int(10) NOT NULL default 0 AFTER `modified_time`, ADD `extra_fields` mediumtext AFTER `filters`, ADD `for_search` mediumtext AFTER `redundants`, MODIFY `redundants` mediumtext, ADD `tags` text AFTER `filters`, ADD KEY (`modified_time`), ADD KEY (`expiring_time`), ADD KEY (`permission_id`)");
         $db->queryF("UPDATE " . $db->prefix($mydirname . "_contents") . " SET `expiring_time`=0x7fffffff");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_content_histories") . " ADD tags text, ADD extra_fields mediumtext");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " ADD `cat_permission_id` int(10) unsigned NOT NULL AFTER `cat_id`, ADD KEY (`cat_permission_id`)");
         $db->queryF("UPDATE " . $db->prefix($mydirname . "_categories") . " SET `cat_permission_id`=`cat_id`");
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_tags") . " ( label varchar(255) NOT NULL default '', weight int(10) unsigned NOT NULL default 0, count int(10) unsigned NOT NULL default 0, content_ids mediumtext, created_time int(10) NOT NULL default 0, modified_time int(10) NOT NULL default 0, PRIMARY KEY (label), KEY (count), KEY (weight), KEY (created_time) ) TYPE=MyISAM");
     }
     // 1.7/1.8 -> 1.9/2.0 (1)
     $check_sql = "SELECT * FROM " . $db->prefix($mydirname . "_content_ef_sortables");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " ADD `cat_extra_fields` mediumtext AFTER `cat_vpath_mtime`;");
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_content_ef_sortables") . " ( content_id int(10) unsigned NOT NULL default 0, ef0 char(64) NOT NULL default '', ef1 char(64) NOT NULL default '', ef2 char(64) NOT NULL default '', ef3 char(64) NOT NULL default '', ef4 char(64) NOT NULL default '', ef5 char(64) NOT NULL default '', ef6 char(64) NOT NULL default '', ef7 char(64) NOT NULL default '', ef8 char(64) NOT NULL default '', ef9 char(64) NOT NULL default '', KEY (ef0), KEY (ef1), KEY (ef2), KEY (ef3), KEY (ef4), KEY (ef5), KEY (ef6), KEY (ef7), KEY (ef8), KEY (ef9), PRIMARY KEY (content_id) ) TYPE=MyISAM");
     }
     // 1.7/1.8 -> 1.9/2.0 (2)
     // content_histories ...
     // TEMPLATES (all templates have been already removed by modulesadmin)
     $tplfile_handler =& xoops_gethandler('tplfile');
     $tpl_path = dirname(__FILE__) . '/templates';
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path)) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                     // generate compiled file
                     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                     include_once XOOPS_ROOT_PATH . '/class/template.php';
                     if (!xoops_template_touch($tplid)) {
                         $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span>';
                     }
                 }
             }
         }
         closedir($handler);
     }
     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
     include_once XOOPS_ROOT_PATH . '/class/template.php';
     xoops_template_clear_module_cache($mid);
     return true;
 }
コード例 #14
0
ファイル: main.php プロジェクト: BackupTheBerlios/xoops4-svn
         $xoopsTpl->clear_compiled_tpl();
         // generate compiled files for the new theme
         // block files only for now..
         $tplfile_handler =& xoops_gethandler('tplfile');
         $dtemplates =& $tplfile_handler->find('default', 'block');
         $dcount = count($dtemplates);
         // need to do this to pass to xoops_template_touch function
         $GLOBALS['xoopsConfig']['template_set'] = $newtplset;
         for ($i = 0; $i < $dcount; $i++) {
             $found =& $tplfile_handler->find($newtplset, 'block', $dtemplates[$i]->getVar('tpl_refid'), null);
             if (count($found) > 0) {
                 // template for the new theme found, compile it
                 xoops_template_touch($found[0]);
             } else {
                 // not found, so compile 'default' template file
                 xoops_template_touch($dtemplates[$i]);
             }
         }
         // generate image cache files from image binary data, save them under cache/
         $image_handler =& xoops_gethandler('imagesetimg');
         $imagefiles =& $image_handler->getObjects(new Criteria('tplset_name', $newtplset), true);
         foreach (array_keys($imagefiles) as $i) {
             if (!($fp = fopen(XOOPS_CACHE_PATH . '/' . $newtplset . '_' . $imagefiles[$i]->getVar('imgsetimg_file'), 'wb'))) {
             } else {
                 fwrite($fp, $imagefiles[$i]->getVar('imgsetimg_body'));
                 fclose($fp);
             }
         }
     }
     $tpl_updated = true;
 }
コード例 #15
0
 function dbtheme_onupdate_base($module, $mydirname)
 {
     // transations on module update
     global $msgs;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'dbtheme_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // configs (Though I know it is not a recommended way...)
     $check_sql = "SHOW COLUMNS FROM " . $db->prefix("config") . " LIKE 'conf_title'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] == 'varchar(30)') {
         $db->queryF("ALTER TABLE " . $db->prefix("config") . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
     }
     // IMPORT THE SELECTED THEME AS THIS MODULE'S TEMPLATES
     $tplfile_handler =& xoops_gethandler('tplfile');
     /*************** BEGIN DBTHEME SPECIFIC PART ******************/
     $module_handler =& xoops_gethandler('module');
     $module =& $module_handler->getByDirname($mydirname);
     $config_handler =& xoops_gethandler('config');
     $mod_config =& $config_handler->getConfigsByCat(0, $module->getVar('mid'));
     if (file_exists(dirname(__FILE__) . '/templates/theme.html')) {
         $tpl_path = dirname(__FILE__) . '/templates';
     } else {
         if (!empty($mod_config['base_theme'])) {
             $tpl_path = XOOPS_ROOT_PATH . '/themes/' . $mod_config['base_theme'];
         } else {
             $tpl_path = XOOPS_ROOT_PATH . '/themes/' . $GLOBALS['xoopsConfig']['theme_set'];
         }
     }
     /*************** END DBTHEME SPECIFIC PART ******************/
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 /*************** BEGIN DBTHEME SPECIFIC PART ******************/
                 $tpl_source = file_get_contents($file_path);
                 $searches = array();
                 $replacements = array();
                 if (strrchr($file, '.') == '.html') {
                     // CSS hooking
                     $searches[] = '/\\"\\<\\{\\$xoops_imageurl\\}\\>([0-9a-zA-Z_-]+)\\.(css|html|js)\\"/';
                     $replacements[] = '"<{$xoops_url}>/modules/' . $mydirname . '/?template=$1.$2' . '"';
                 } else {
                     if (strrchr($file, '.') == '.css') {
                         // url() hooking
                         $searches[] = '#url\\(\\s*([\\"\']?)([0-9a-z./]{3})#i';
                         $replacements[] = 'url($1<{$xoops_imageurl}>$2';
                     }
                 }
                 $tplfile->setVar('tpl_source', preg_replace($searches, $replacements, $tpl_source));
                 $mtime = time();
                 /*************** END DBTHEME SPECIFIC PART ******************/
                 //				$tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                     // generate compiled file
                     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                     include_once XOOPS_ROOT_PATH . '/class/template.php';
                     if (!xoops_template_touch($tplid)) {
                         $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span>';
                     }
                 }
             }
         }
         closedir($handler);
     }
     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
     include_once XOOPS_ROOT_PATH . '/class/template.php';
     xoops_template_clear_module_cache($mid);
     return true;
 }
コード例 #16
0
ファイル: onupdate.php プロジェクト: geekwright/XoopsCore25
 /**
  * @param $module
  * @param $mydirname
  *
  * @return bool
  */
 function protector_onupdate_base($module, $mydirname)
 {
     // transations on module update
     global $msgs;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'protector_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db = XoopsDatabaseFactory::getDatabaseConnection();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // configs (Though I know it is not a recommended way...)
     $check_sql = 'SHOW COLUMNS FROM ' . $db->prefix('config') . " LIKE 'conf_title'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] === 'varchar(30)') {
         $db->queryF('ALTER TABLE ' . $db->prefix('config') . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
     }
     list(, $create_string) = $db->fetchRow($db->query('SHOW CREATE TABLE ' . $db->prefix('config')));
     foreach (explode('KEY', $create_string) as $line) {
         if (preg_match('/(\\`conf\\_title_\\d+\\`) \\(\\`conf\\_title\\`\\)/', $line, $regs)) {
             $db->query('ALTER TABLE ' . $db->prefix('config') . ' DROP KEY ' . $regs[1]);
         }
     }
     $db->query('ALTER TABLE ' . $db->prefix('config') . ' ADD KEY `conf_title` (`conf_title`)');
     // 2.x -> 3.0
     list(, $create_string) = $db->fetchRow($db->query('SHOW CREATE TABLE ' . $db->prefix($mydirname . '_log')));
     if (preg_match('/timestamp\\(/i', $create_string)) {
         $db->query('ALTER TABLE ' . $db->prefix($mydirname . '_log') . ' MODIFY `timestamp` DATETIME');
     }
     // TEMPLATES (all templates have been already removed by modulesadmin)
     $tplfile_handler = xoops_getHandler('tplfile');
     $tpl_path = __DIR__ . '/templates';
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) === '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) {
                 $mtime = (int) @filemtime($file_path);
                 $tplfile = $tplfile_handler->create();
                 $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                     // generate compiled file
                     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                     include_once XOOPS_ROOT_PATH . '/class/template.php';
                     if (!xoops_template_touch($tplid)) {
                         $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span>';
                     }
                 }
             }
         }
         closedir($handler);
     }
     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
     include_once XOOPS_ROOT_PATH . '/class/template.php';
     xoops_template_clear_module_cache($mid);
     return true;
 }
コード例 #17
0
 function d3forum_oninstall_base($module, $mydirname)
 {
     // transations on module install
     global $ret;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'd3forum_message_append_oninstall');
         $ret = array();
     } else {
         if (!is_array($ret)) {
             $ret = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (loading mysql.sql)
     $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql';
     $prefix_mod = $db->prefix() . '_' . $mydirname;
     if (file_exists($sql_file_path)) {
         $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path) . "</b>.<br /> Creating tables...";
         if (file_exists(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) {
             include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php';
             $sqlutil =& new OldSqlUtility();
         } else {
             include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
             $sqlutil =& new SqlUtility();
         }
         $sql_query = trim(file_get_contents($sql_file_path));
         $sqlutil->splitMySqlFile($pieces, $sql_query);
         $created_tables = array();
         if (is_array($pieces)) {
             foreach ($pieces as $piece) {
                 $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod);
                 if (!$prefixed_query) {
                     $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece) . "</b><br />";
                     return false;
                 }
                 if (!$db->query($prefixed_query[0])) {
                     $ret[] = '<b>' . htmlspecialchars($db->error()) . '</b><br />';
                     //var_dump( $db->error() ) ;
                     return false;
                 } else {
                     if (!in_array($prefixed_query[4], $created_tables)) {
                         $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br />';
                         $created_tables[] = $prefixed_query[4];
                     } else {
                         $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b>.</br />';
                     }
                 }
             }
         }
     }
     // TEMPLATES
     $tplfile_handler =& xoops_gethandler('tplfile');
     $tpl_path = dirname(__FILE__) . '/templates';
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path)) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br />';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />';
                     // generate compiled file
                     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                     include_once XOOPS_ROOT_PATH . '/class/template.php';
                     if (!xoops_template_touch($tplid)) {
                         $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br />';
                     } else {
                         $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br />';
                     }
                 }
             }
         }
         closedir($handler);
     }
     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
     include_once XOOPS_ROOT_PATH . '/class/template.php';
     xoops_template_clear_module_cache($mid);
     return true;
 }
コード例 #18
0
ファイル: onupdate.php プロジェクト: naao/d3diary
 function d3diary_onupdate_base($module, $mydirname)
 {
     // transations on module update
     global $msgs;
     // TODO :-D
     require dirname(__FILE__) . '/class/d3diaryConf.class.php';
     $d3dConf =& D3diaryConf::getInstance($mydirname, 0, "onupdate");
     $func =& $d3dConf->func;
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'd3diary_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // configs (Though I know it is not a recommended way...)
     $check_sql = "SHOW COLUMNS FROM " . $db->prefix("config") . " LIKE 'conf_title'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] == 'varchar(30)') {
         $db->queryF("ALTER TABLE " . $db->prefix("config") . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
     }
     // 0.01 -> 0.01
     $check_sql = "SELECT blogtype FROM " . $db->prefix($mydirname . "_category");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD blogtype tinyint(3) NOT NULL default '0' AFTER corder");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD blogurl text AFTER blogtype");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD rss text AFTER blogurl");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD openarea tinyint(3) NOT NULL AFTER rss");
     }
     // 0.01 -> 0.01
     $check_sql = "SELECT openarea FROM " . $db->prefix($mydirname . "_diary");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_diary") . " ADD openarea tinyint(3) unsigned NOT NULL AFTER create_time");
     }
     // 0.01 -> 0.01
     $check_sql = "SELECT cid FROM " . $db->prefix($mydirname . "_newentry");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_newentry") . " ADD cid int(10) unsigned NOT NULL default '0' AFTER uid");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_newentry") . " DROP PRIMARY KEY");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_newentry") . " ADD PRIMARY KEY (uid,cid)");
     }
     // 0.01 -> 0.01
     $check_sql = "SELECT tag_id FROM " . $db->prefix($mydirname . "_tag");
     if (!$db->query($check_sql)) {
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_tag") . " ( tag_id int(11) unsigned NOT NULL auto_increment, tag_name varchar(64) NOT NULL default '',\tbid int(11) unsigned NOT NULL default '0', uid mediumint(8) unsigned NOT NULL default '0',\ttag_group int(11) unsigned NOT NULL default '0', reg_unixtime int(11) unsigned NOT NULL default '0', PRIMARY KEY  (tag_id), KEY (tag_name), KEY (bid), KEY (uid) ) ENGINE=MyISAM");
     }
     // 0.01 -> 0.01
     // deleted dayly cout up
     $db->queryF("DELETE FROM " . $db->prefix($mydirname . "_cnt") . " WHERE ymd<>'1111-11-11'");
     // 0.05 -> 0.06
     // add dohtml
     $check_sql = "SELECT dohtml FROM " . $db->prefix($mydirname . "_diary");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_diary") . " ADD dohtml tinyint(1) unsigned NOT NULL AFTER openarea");
     }
     $check_sql = "SELECT dohtml FROM " . $db->prefix($mydirname . "_category");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD dohtml tinyint(1) unsigned NOT NULL AFTER openarea");
     }
     // 0.11a2 -> 0.11a3
     // add subcategory
     $check_sql = "SELECT subcat FROM " . $db->prefix($mydirname . "_category");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD subcat tinyint(1) unsigned NOT NULL default '0' AFTER corder");
     }
     // 0.11a3 -> 0.12
     // add group and personal permissions
     $check_sql = "SELECT vgids FROM " . $db->prefix($mydirname . "_category");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD vgids varchar(255) default NULL AFTER dohtml");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD vpids varchar(255) default NULL AFTER vgids");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_diary") . " ADD vgids varchar(255) default NULL AFTER dohtml");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_diary") . " ADD vpids varchar(255) default NULL AFTER vgids");
     }
     // add page view
     $check_sql = "SELECT view FROM " . $db->prefix($mydirname . "_diary");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_diary") . " ADD view int(10) unsigned NOT NULL default '0' AFTER vpids");
     }
     // 0.12b2 -> 0.12b3
     // add photo info
     $check_sql = "SELECT info FROM " . $db->prefix($mydirname . "_photo");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_photo") . " ADD info text AFTER tstamp");
     }
     // 0.13c -> 0.14
     // cppy tag registered unixtime from each diary's create_time
     $sql = "SELECT t.tag_id, d.create_time FROM " . $db->prefix($mydirname . "_tag") . " t \n\t\t\t\tINNER JOIN " . $db->prefix($mydirname . "_diary") . " d USING(bid) \n\t\t\t\tWHERE t.bid=d.bid AND t.reg_unixtime='0'";
     if ($result = $db->query($sql)) {
         while ($dbdat = $db->fetchArray($result)) {
             $ctime = preg_split("/[-: ]/", $dbdat['create_time']);
             $tstamp = mktime($ctime[3], $ctime[4], $ctime[5], $ctime[1], $ctime[2], $ctime[0]);
             $sql = "UPDATE " . $db->prefix($mydirname . "_tag") . " SET \n\t\t\t\t\treg_unixtime='" . $tstamp . "' WHERE tag_id='" . $dbdat['tag_id'] . "'";
             $irs = $db->query($sql);
         }
     }
     // 0.15 -> 0.16
     // add mail post
     $check_sql = "SELECT mailpost FROM " . $db->prefix($mydirname . "_config");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_config") . " \n\t\t\tADD `mailpost` tinyint(1) unsigned NOT NULL default '0' AFTER openarea");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_config") . " \n\t\t\tADD `address` varchar(255) NOT NULL default '' AFTER mailpost");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_config") . " \n\t\t\tADD `keep` tinyint(1) NOT NULL default '0' AFTER address");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_config") . " \n\t\t\tADD `uptime` int(10) unsigned NOT NULL default '0' AFTER keep");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_config") . " \n\t\t\tADD `updated` int(10) unsigned NOT NULL default '0' AFTER uptime");
     }
     // 0.18
     // modify photo `tstamp` column data type from timestamp to datetime
     $result = $db->query("SELECT `tstamp` FROM " . $db->prefix($mydirname . "_photo"));
     static $link = null;
     if (is_null($link)) {
         //$db = XoopsDatabaseFactory::getDatabaseConnection();
         $link = is_object($db->conn) && get_class($db->conn) === 'mysqli' ? $db->conn : false;
     }
     if ($link) {
         $field_info = mysqli_fetch_field_direct($result, 0);
         $field_type = $field_info->type;
     } else {
         $field_type = mysql_field_type($result, 0);
     }
     if ($field_type == "timestamp") {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_photo") . " modify `tstamp` datetime NOT NULL");
         // for NULL tstamp, copy from diary's create_time
         $sql = "UPDATE " . $db->prefix($mydirname . "_photo") . " p \n\t\t\t\tINNER JOIN " . $db->prefix($mydirname . "_diary") . " d USING(bid) \n\t\t\t\tSET p.tstamp=d.create_time WHERE (p.tstamp IS NULL) OR (p.tstamp = '0000-00-00 00:00:00')";
         $result = $db->queryF($sql);
     }
     // 0.28 -> 0.29
     // add indexes for tables
     $check_sql = "SHOW INDEX FROM " . $db->prefix($mydirname . "_category") . " WHERE Key_name='idx_uid'";
     $result = $db->query($check_sql);
     $dbdat = $db->fetchArray($result);
     if (!$dbdat) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " \n\t\t\tADD KEY idx_uid (`uid`,`cid`,`blogtype`,`openarea`)");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_config") . " \n\t\t\tADD KEY idx_uid (`uid`,`blogtype`,`openarea`)");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_diary") . " \n\t\t\tADD KEY idx_uid (`uid`,`cid`,`openarea`,`create_time`)");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_newentry") . " \n\t\t\tADD KEY idx_uid (`uid`,`cid`,`blogtype`,`create_time`)");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_photo") . " \n\t\t\tADD KEY idx_uid (`uid`)");
     }
     $check_sql = "SHOW INDEX FROM " . $db->prefix($mydirname . "_cnt_ip") . " WHERE Column_name='acctime'";
     $result = $db->query($check_sql);
     $dbdat = $db->fetchArray($result);
     if (!$dbdat) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_cnt_ip") . " \n\t\t\tADD KEY `acctime` (`acctime`)");
     }
     // 0.44 -> 0.45
     // add show whole detail on the index page
     $check_sql = "SELECT showoption FROM " . $db->prefix($mydirname . "_category");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " \n\t\t\tADD `showoption` tinyint(1) unsigned NOT NULL default '0' AFTER openarea");
     }
     // TEMPLATES (all templates have been already removed by modulesadmin)
     $tplfile_handler =& xoops_gethandler('tplfile');
     $tpl_path = dirname(__FILE__) . '/templates';
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path)) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . $func->htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . $func->htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                     // generate compiled file
                     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                     include_once XOOPS_ROOT_PATH . '/class/template.php';
                     if (!xoops_template_touch($tplid)) {
                         $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . $func->htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . $func->htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span>';
                     }
                 }
             }
         }
         closedir($handler);
     }
     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
     include_once XOOPS_ROOT_PATH . '/class/template.php';
     xoops_template_clear_module_cache($mid);
     return true;
 }
コード例 #19
0
ファイル: modules.php プロジェクト: laiello/bitcero-modules
function xoops_module_update($dirname)
{
    global $xoopsConfig, $xoopsDB;
    $dirname = trim($dirname);
    $module_handler =& xoops_gethandler('module');
    $module =& $module_handler->getByDirname($dirname);
    // Save current version for use in the update function
    $prev_version = $module->getVar('version');
    include_once XOOPS_ROOT_PATH . '/class/template.php';
    $xoopsTpl = new XoopsTpl();
    $xoopsTpl->clearCache($dirname);
    //xoops_template_clear_module_cache($module->getVar('mid'));
    // we dont want to change the module name set by admin
    $temp_name = $module->getVar('name');
    $module->loadInfoAsVar($dirname);
    $module->setVar('name', $temp_name);
    $log = '';
    if (!$module_handler->insert($module)) {
        $log .= sprintf(__('Could not update %s', 'rmcommon'), $module->getVar('name'));
    } else {
        $newmid = $module->getVar('mid');
        $msgs = array();
        $msgs[] = sprintf(__('Updating module %s', 'rmcommon'), $module->getVar('name'));
        $tplfile_handler =& xoops_gethandler('tplfile');
        $deltpl = $tplfile_handler->find('default', 'module', $module->getVar('mid'));
        $delng = array();
        if (is_array($deltpl)) {
            // delete template file entry in db
            $dcount = count($deltpl);
            for ($i = 0; $i < $dcount; $i++) {
                if (!$tplfile_handler->delete($deltpl[$i])) {
                    $delng[] = $deltpl[$i]->getVar('tpl_file');
                }
            }
        }
        $templates = $module->getInfo('templates');
        if ($templates != false) {
            $msgs[] = __('Updating templates...', 'rmcommon');
            foreach ($templates as $tpl) {
                $tpl['file'] = trim($tpl['file']);
                if (!in_array($tpl['file'], $delng)) {
                    $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']);
                    $tplfile =& $tplfile_handler->create();
                    $tplfile->setVar('tpl_refid', $newmid);
                    $tplfile->setVar('tpl_lastimported', 0);
                    $tplfile->setVar('tpl_lastmodified', time());
                    if (preg_match("/\\.css\$/i", $tpl['file'])) {
                        $tplfile->setVar('tpl_type', 'css');
                    } else {
                        $tplfile->setVar('tpl_type', 'module');
                    }
                    $tplfile->setVar('tpl_source', $tpldata, true);
                    $tplfile->setVar('tpl_module', $dirname);
                    $tplfile->setVar('tpl_tplset', 'default');
                    $tplfile->setVar('tpl_file', $tpl['file'], true);
                    $tplfile->setVar('tpl_desc', $tpl['description'], true);
                    if (!$tplfile_handler->insert($tplfile)) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(__('Template %s could not be inserted!', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>") . '</span>';
                    } else {
                        $newid = $tplfile->getVar('tpl_id');
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(__('Template %s inserted to the database.', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>");
                        if ($xoopsConfig['template_set'] == 'default') {
                            if (!xoops_template_touch($newid)) {
                                $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(__('ERROR: Could not recompile template %s', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>") . '</span>';
                            } else {
                                $msgs[] = '&nbsp;&nbsp;<span>' . sprintf(__('Template %s recompiled', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>") . '</span>';
                            }
                        }
                    }
                    unset($tpldata);
                } else {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(__('ERROR: Could not delete old template %s. Aborting update of this file.', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>") . '</span>';
                }
            }
        }
        $blocks = $module->getInfo('blocks');
        $msgs[] = __('Rebuilding blocks...', 'rmcommon');
        if ($blocks != false) {
            $showfuncs = array();
            $funcfiles = array();
            foreach ($blocks as $i => $block) {
                if (isset($block['show_func']) && $block['show_func'] != '' && isset($block['file']) && $block['file'] != '') {
                    $editfunc = isset($block['edit_func']) ? $block['edit_func'] : '';
                    $showfuncs[] = $block['show_func'];
                    $funcfiles[] = $block['file'];
                    $template = '';
                    if (isset($block['template']) && trim($block['template']) != '') {
                        $content = xoops_module_gettemplate($dirname, $block['template'], 'blocks');
                    }
                    if (!$content) {
                        $content = '';
                    } else {
                        $template = $block['template'];
                    }
                    $options = '';
                    if (!empty($block['options'])) {
                        $options = $block['options'];
                    }
                    $sql = "SELECT bid, name FROM " . $xoopsDB->prefix('newblocks') . " WHERE mid=" . $module->getVar('mid') . " AND func_num=" . $i . " AND show_func='" . addslashes($block['show_func']) . "' AND func_file='" . addslashes($block['file']) . "'";
                    $fresult = $xoopsDB->query($sql);
                    $fcount = 0;
                    while ($fblock = $xoopsDB->fetchArray($fresult)) {
                        $fcount++;
                        $sql = "UPDATE " . $xoopsDB->prefix("newblocks") . " SET name='" . addslashes($block['name']) . "', edit_func='" . addslashes($editfunc) . "', content='', template='" . $template . "', last_modified=" . time() . " WHERE bid=" . $fblock['bid'];
                        $result = $xoopsDB->query($sql);
                        if (!$result) {
                            $msgs[] = "&nbsp;&nbsp;" . sprintf(__('ERROR: Could not update %s'), $fblock['name']);
                        } else {
                            $msgs[] = "&nbsp;&nbsp;" . sprintf(__('Block %s updated.', 'rmcommon'), $fblock['name']) . sprintf(__('Block ID: %s', 'rmcommon'), "<strong>" . $fblock['bid'] . "</strong>");
                            if ($template != '') {
                                $tplfile = $tplfile_handler->find('default', 'block', $fblock['bid']);
                                if (count($tplfile) == 0) {
                                    $tplfile_new =& $tplfile_handler->create();
                                    $tplfile_new->setVar('tpl_module', $dirname);
                                    $tplfile_new->setVar('tpl_refid', $fblock['bid']);
                                    $tplfile_new->setVar('tpl_tplset', 'default');
                                    $tplfile_new->setVar('tpl_file', $block['template'], true);
                                    $tplfile_new->setVar('tpl_type', 'block');
                                } else {
                                    $tplfile_new = $tplfile[0];
                                }
                                $tplfile_new->setVar('tpl_source', $content, true);
                                $tplfile_new->setVar('tpl_desc', $block['description'], true);
                                $tplfile_new->setVar('tpl_lastmodified', time());
                                $tplfile_new->setVar('tpl_lastimported', 0);
                                if (!$tplfile_handler->insert($tplfile_new)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(__('ERROR: Could not update %s template.', 'rmcommon'), "<strong>" . $block['template'] . "</strong>") . '</span>';
                                } else {
                                    $msgs[] = "&nbsp;&nbsp;" . sprintf(__('Template %s updated.', 'rmcommon'), "<strong>" . $block['template'] . "</strong>");
                                    if ($xoopsConfig['template_set'] == 'default') {
                                        if (!xoops_template_touch($tplfile_new->getVar('tpl_id'))) {
                                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(__('ERROR: Could not recompile template %s', 'rmcommon'), "<strong>" . $block['template'] . "</strong>") . '</span>';
                                        } else {
                                            $msgs[] = "&nbsp;&nbsp;" . sprintf(__('Template %s recompiled', 'rmcommon'), "<strong>" . $block['template'] . "</strong>");
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if ($fcount == 0) {
                        $newbid = $xoopsDB->genId($xoopsDB->prefix('newblocks') . '_bid_seq');
                        $block_name = addslashes($block['name']);
                        $block_type = $module->getVar('dirname') == 'system' ? 'S' : 'M';
                        $sql = "INSERT INTO " . $xoopsDB->prefix("newblocks") . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, isactive, dirname, func_file, show_func, edit_func, template, last_modified) VALUES (" . $newbid . ", " . $module->getVar('mid') . ", " . $i . ",'" . addslashes($options) . "','" . $block_name . "', '" . $block_name . "', '', 0, 0, 0, '{$block_type}', 1, '" . addslashes($dirname) . "', '" . addslashes($block['file']) . "', '" . addslashes($block['show_func']) . "', '" . addslashes($editfunc) . "', '" . $template . "', " . time() . ")";
                        $result = $xoopsDB->query($sql);
                        if (!$result) {
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_('ERROR: Could not create %s', 'rmcommon'), $block['name']);
                            $log .= $sql;
                        } else {
                            if (empty($newbid)) {
                                $newbid = $xoopsDB->getInsertId();
                            }
                            if ($module->getInfo('hasMain')) {
                                $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS);
                            } else {
                                $groups = array(XOOPS_GROUP_ADMIN);
                            }
                            $gperm_handler =& xoops_gethandler('groupperm');
                            foreach ($groups as $mygroup) {
                                $bperm =& $gperm_handler->create();
                                $bperm->setVar('gperm_groupid', $mygroup);
                                $bperm->setVar('gperm_itemid', $newbid);
                                $bperm->setVar('gperm_name', 'block_read');
                                $bperm->setVar('gperm_modid', 1);
                                if (!$gperm_handler->insert($bperm)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . __('ERROR: Could not add block access right', 'rmcommon') . ' ' . sprintf(__("Block ID: %s", 'rmcommon'), "<strong>" . $newbid . "</strong>") . ' ' . sprintf(__('Group ID: %s', 'rmcommon'), "<strong>" . $mygroup . "</strong>") . '</span>';
                                } else {
                                    $msgs[] = '&nbsp;&nbsp;' . __('Added block access right', 'rmcommon') . ' ' . sprintf(__("Block ID: %s", 'rmcommon'), "<strong>" . $newbid . "</strong>") . ' ' . sprintf(__('Group ID: %s', 'rmcommon'), "<strong>" . $mygroup . "</strong>");
                                }
                            }
                            if ($template != '') {
                                $tplfile =& $tplfile_handler->create();
                                $tplfile->setVar('tpl_module', $dirname);
                                $tplfile->setVar('tpl_refid', $newbid);
                                $tplfile->setVar('tpl_source', $content, true);
                                $tplfile->setVar('tpl_tplset', 'default');
                                $tplfile->setVar('tpl_file', $block['template'], true);
                                $tplfile->setVar('tpl_type', 'block');
                                $tplfile->setVar('tpl_lastimported', 0);
                                $tplfile->setVar('tpl_lastmodified', time());
                                $tplfile->setVar('tpl_desc', $block['description'], true);
                                if (!$tplfile_handler->insert($tplfile)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(__('ERROR: Could not insert template %s to the database.', 'rmcommon'), "<strong>" . $block['template'] . "</strong>") . '</span>';
                                } else {
                                    $newid = $tplfile->getVar('tpl_id');
                                    $msgs[] = '&nbsp;&nbsp;' . sprintf(__('Template %s added to the database', 'rmcommon'), "<strong>" . $block['template'] . "</strong>");
                                    if ($xoopsConfig['template_set'] == 'default') {
                                        if (!xoops_template_touch($newid)) {
                                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(__('ERROR: Template %s recompile failed', 'rmcommon'), "<strong>" . $block['template'] . "</strong>") . '</span>';
                                        } else {
                                            $msgs[] = '&nbsp;&nbsp;' . sprintf(__('Template %s recompiled', 'rmcommon'), "<strong>" . $block['template'] . "</strong>");
                                        }
                                    }
                                }
                            }
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(__('Block %s created', 'rmcommon'), "<strong>" . $block['name'] . "</strong>") . sprintf(__("Block ID: %s", 'rmcommon'), "<strong>" . $newbid . "</strong>");
                            $sql = 'INSERT INTO ' . $xoopsDB->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)';
                            $xoopsDB->query($sql);
                        }
                    }
                }
            }
            $block_arr = XoopsBlock::getByModule($module->getVar('mid'));
            foreach ($block_arr as $block) {
                if (!in_array($block->getVar('show_func'), $showfuncs) || !in_array($block->getVar('func_file'), $funcfiles)) {
                    $sql = sprintf("DELETE FROM %s WHERE bid = %u", $xoopsDB->prefix('newblocks'), $block->getVar('bid'));
                    if (!$xoopsDB->query($sql)) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(__('ERROR: Could not delete block %s', 'rmcommon'), "<strong>" . $block->getVar('name') . "</strong>") . sprintf(__("Block ID: %s", 'rmcommon'), "<strong>" . $block->getVar('bid') . "</strong>") . '</span>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;Block <strong>' . $block->getVar('name') . ' deleted. Block ID: <strong>' . $block->getVar('bid') . '</strong>';
                        if ($block->getVar('template') != '') {
                            $tplfiles = $tplfile_handler->find(null, 'block', $block->getVar('bid'));
                            if (is_array($tplfiles)) {
                                $btcount = count($tplfiles);
                                for ($k = 0; $k < $btcount; $k++) {
                                    if (!$tplfile_handler->delete($tplfiles[$k])) {
                                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . __('ERROR: Could not remove deprecated block template.', 'rmcommon') . '(ID: <strong>' . $tplfiles[$k]->getVar('tpl_id') . '</strong>)</span>';
                                    } else {
                                        $msgs[] = '&nbsp;&nbsp;' . sprintf(__('Block template %s deprecated', 'rmcommon'), "<strong>" . $tplfiles[$k]->getVar('tpl_file') . "</strong>");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // reset compile_id
        $xoopsTpl->setCompileId();
        // first delete all config entries
        $config_handler =& xoops_gethandler('config');
        $configs = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
        $confcount = count($configs);
        $config_delng = array();
        if ($confcount > 0) {
            $msgs[] = __('Deleting module config options...', 'rmcommon');
            for ($i = 0; $i < $confcount; $i++) {
                if (!$config_handler->deleteConfig($configs[$i])) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . __('ERROR: Could not delete config data from the database', 'rmcommon') . sprintf(__('Config ID: %s', 'rmcommon'), "<strong>" . $configs[$i]->getvar('conf_id') . "</strong>") . '</span>';
                    // save the name of config failed to delete for later use
                    $config_delng[] = $configs[$i]->getvar('conf_name');
                } else {
                    $config_old[$configs[$i]->getvar('conf_name')]['value'] = $configs[$i]->getvar('conf_value', 'N');
                    $config_old[$configs[$i]->getvar('conf_name')]['formtype'] = $configs[$i]->getvar('conf_formtype');
                    $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype');
                    $msgs[] = "&nbsp;&nbsp;" . __('Config data deleted from the database.', 'rmcommon') . ' ' . sprintf(__('Config ID: %s', 'rmcommon'), "<strong>" . $configs[$i]->getVar('conf_id') . "</strong>");
                }
            }
        }
        // now reinsert them with the new settings
        $configs = $module->getInfo('config');
        // Include
        if ($configs != false) {
            if ($module->getVar('hascomments') != 0) {
                include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
                array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)));
                array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0));
            }
        } else {
            if ($module->getVar('hascomments') != 0) {
                $configs = array();
                include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
                $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN));
                $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0);
            }
        }
        // RMV-NOTIFY
        if ($module->getVar('hasnotification') != 0) {
            if (empty($configs)) {
                $configs = array();
            }
            // Main notification options
            include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
            include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
            $options = array();
            $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
            $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
            $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
            $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
            //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
            $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options);
            // Event specific notification options
            // FIXME: for some reason the default doesn't come up properly
            //  initially is ok, but not when 'update' module..
            $options = array();
            $categories =& notificationCategoryInfo('', $module->getVar('mid'));
            foreach ($categories as $category) {
                $events =& notificationEvents($category['name'], false, $module->getVar('mid'));
                foreach ($events as $event) {
                    if (!empty($event['invisible'])) {
                        continue;
                    }
                    $option_name = $category['title'] . ' : ' . $event['title'];
                    $option_value = $category['name'] . '-' . $event['name'];
                    $options[$option_name] = $option_value;
                    //$configs[] = array ('name' => notificationGenerateConfig($category,$event,'name'), 'title' => notificationGenerateConfig($category,$event,'title_constant'), 'description' => notificationGenerateConfig($category,$event,'description_constant'), 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
                }
            }
            $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options);
        }
        if ($configs != false) {
            $msgs[] = 'Adding module config data...';
            $config_handler =& xoops_gethandler('config');
            $order = 0;
            foreach ($configs as $config) {
                // only insert ones that have been deleted previously with success
                if (!in_array($config['name'], $config_delng)) {
                    $confobj =& $config_handler->createConfig();
                    $confobj->setVar('conf_modid', $newmid);
                    $confobj->setVar('conf_catid', 0);
                    $confobj->setVar('conf_name', $config['name']);
                    $confobj->setVar('conf_title', $config['title'], true);
                    $confobj->setVar('conf_desc', $config['description'], true);
                    $confobj->setVar('conf_formtype', $config['formtype']);
                    $confobj->setVar('conf_valuetype', $config['valuetype']);
                    if (isset($config_old[$config['name']]['value']) && $config_old[$config['name']]['formtype'] == $config['formtype'] && $config_old[$config['name']]['valuetype'] == $config['valuetype']) {
                        // preserver the old value if any
                        // form type and value type must be the same
                        $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true);
                    } else {
                        $confobj->setConfValueForInput($config['default'], true);
                        //$confobj->setVar('conf_value', $config['default'], true);
                    }
                    $confobj->setVar('conf_order', $order);
                    $confop_msgs = '';
                    if (isset($config['options']) && is_array($config['options'])) {
                        foreach ($config['options'] as $key => $value) {
                            $confop =& $config_handler->createConfigOption();
                            $confop->setVar('confop_name', $key, true);
                            $confop->setVar('confop_value', $value, true);
                            $confobj->setConfOptions($confop);
                            $confop_msgs .= '<br />&nbsp;&nbsp;&nbsp;&nbsp; ' . __('Config option added', 'rmcommon') . ' ' . __('Name:', 'rmcommon') . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . __('Value:', 'rmcommon') . ' <strong>' . $value . '</strong> ';
                            unset($confop);
                        }
                    }
                    $order++;
                    if (false != $config_handler->insertConfig($confobj)) {
                        //$msgs[] = '&nbsp;&nbsp;Config <strong>'.$config['name'].'</strong> added to the database.'.$confop_msgs;
                        $msgs[] = "&nbsp;&nbsp;" . sprintf(__('Config %s added to the database', 'rmcommon'), "<strong>" . $config['name'] . "</strong>") . $confop_msgs;
                    } else {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(__('ERROR: Could not insert config %s to the database.', 'rmcommon'), "<strong>" . $config['name'] . "</strong>") . '</span>';
                    }
                    unset($confobj);
                }
            }
            unset($configs);
        }
        // execute module specific update script if any
        $update_script = $module->getInfo('onUpdate');
        if (false != $update_script && trim($update_script) != '') {
            include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($update_script);
            if (function_exists('xoops_module_update_' . $dirname)) {
                $func = 'xoops_module_update_' . $dirname;
                if (!$func($module, $prev_version)) {
                    $msgs[] = "<p>" . sprintf(__('Failed to execute %s', 'rmcommon'), $func) . "</p>";
                } else {
                    $msgs[] = "<p>" . sprintf(__('%s executed successfully.', 'rmcommon'), "<strong>" . $func . "</strong>") . "</p>";
                }
            }
        }
        foreach ($msgs as $msg) {
            $log .= $msg . '<br />';
        }
        $log .= "<p>" . sprintf(__('Module %s updated successfully!', 'rmcommon'), "<strong>" . $module->getVar('name') . "</strong>") . "</p>";
    }
    // Flush cache files for cpanel GUIs
    xoops_load("cpanel", "system");
    XoopsSystemCpanel::flush();
    return $log;
}
コード例 #20
0
ファイル: onupdate.php プロジェクト: nouphet/rata
    function xpwiki_onupdate_base($module, $mydirname)
    {
        // transations on module update
        global $msgs;
        // TODO :-D
        // for Cube 2.1
        if (defined('XOOPS_CUBE_LEGACY')) {
            $root =& XCube_Root::getSingleton();
            $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'xpwiki_message_append_onupdate');
            $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Fail', 'xpwiki_message_append_onupdate');
            $msgs = array();
        } else {
            if (!is_array($msgs)) {
                $msgs = array();
            }
        }
        $db =& Database::getInstance();
        $mid = $module->getVar('mid');
        // DB Check for db non support version
        $query = "SELECT * FROM " . $db->prefix($mydirname . "_pginfo");
        if (!$db->query($query)) {
            // TABLES (loading mysql.sql)
            $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql';
            $prefix_mod = $db->prefix() . '_' . $mydirname;
            if (file_exists($sql_file_path)) {
                $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path) . "</b>.<br /> Creating tables...";
                if (is_file(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) {
                    include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php';
                    $sqlutil =& new OldSqlUtility();
                } else {
                    include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
                    $sqlutil =& new SqlUtility();
                }
                $sql_query = trim(file_get_contents($sql_file_path));
                $sqlutil->splitMySqlFile($pieces, $sql_query);
                $created_tables = array();
                foreach ($pieces as $piece) {
                    $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod);
                    if (!$prefixed_query) {
                        $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece) . "</b><br />";
                        return false;
                    }
                    if (!$db->query($prefixed_query[0])) {
                        $ret[] = '<b>' . htmlspecialchars($db->error()) . '</b><br />';
                        //var_dump( $db->error() ) ;
                        return false;
                    } else {
                        if (!in_array($prefixed_query[4], $created_tables)) {
                            $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br />';
                            $created_tables[] = $prefixed_query[4];
                        } else {
                            $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b>.</br />';
                        }
                    }
                }
            }
        }
        // TABLES (write here ALTER TABLE etc. if necessary)
        $query = "SELECT `reading` FROM " . $db->prefix($mydirname . "_pginfo");
        if (!$db->query($query)) {
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_pginfo") . '` ADD `reading` VARCHAR( 255 ) BINARY NOT NULL');
        }
        $query = "SELECT `name_ci` FROM " . $db->prefix($mydirname . "_pginfo");
        if (!$db->query($query)) {
            $db->query('ALTER TABLE `' . $db->prefix($mydirname . '_pginfo') . '` ADD `name_ci` VARCHAR( 255 ) NOT NULL');
            $db->query('ALTER TABLE `' . $db->prefix($mydirname . '_pginfo') . '` ADD INDEX ( `name_ci` )');
            $db->query('UPDATE `' . $db->prefix($mydirname . '_pginfo') . '` SET `name_ci` = `name`');
        }
        $query = "SELECT `pgorder` FROM " . $db->prefix($mydirname . "_pginfo");
        if (!$db->query($query)) {
            $db->query('ALTER TABLE `' . $db->prefix($mydirname . '_pginfo') . '` ADD `pgorder` FLOAT DEFAULT \'1\' NOT NULL');
        }
        $query = "SELECT count(*) FROM " . $db->prefix($mydirname . "_cache");
        if (!$db->query($query)) {
            $db->query('CREATE TABLE `' . $db->prefix($mydirname . '_cache') . '` (
  `key` varchar(64) NOT NULL default \'\',
  `plugin` varchar(100) NOT NULL default \'\',
  `data` mediumblob NOT NULL,
  `mtime` int(11) NOT NULL default \'0\',
  `ttl` int(11) NOT NULL default \'0\',
  KEY `key` (`key`),
  KEY `plugin` (`plugin`)
)');
        }
        // ADD Keys
        $table = $db->prefix($mydirname . '_attach');
        if ($result = $db->query('SHOW INDEX FROM `' . $table . '`')) {
            $keys = array('name' => '', 'type' => '', 'mode' => '', 'age' => '');
            while ($arr = $db->fetchArray($result)) {
                unset($keys[$arr['Key_name']]);
            }
            foreach ($keys as $_key => $_val) {
                $query = 'ALTER TABLE `' . $table . '` ADD INDEX(`' . $_key . '`' . $_val . ')';
                $db->query($query);
                //$msgs[] = $query;
            }
        }
        $table = $db->prefix($mydirname . '_pginfo');
        if ($result = $db->query('SHOW INDEX FROM `' . $table . '`')) {
            $keys = array('editedtime' => '', 'freeze' => '', 'egids' => '', 'vgids' => '', 'eaids' => '(255)', 'vaids' => '(255)', 'vids' => array('vaids' => '(200)', 'vgids' => '(133)'));
            while ($arr = $db->fetchArray($result)) {
                unset($keys[$arr['Key_name']]);
            }
            foreach ($keys as $_key => $_val) {
                if (is_array($_val)) {
                    $_index = array();
                    foreach ($_val as $__key => $__val) {
                        $_index[] = '`' . $__key . '`' . $__val;
                    }
                    $_index = join(', ', $_index);
                } else {
                    $_index = '`' . $_key . '`' . $_val;
                }
                $query = 'ALTER TABLE `' . $table . '` ADD INDEX `' . $_key . '`(' . $_index . ')';
                $db->query($query);
                //$msgs[] = $query;
            }
        }
        $table = $db->prefix($mydirname . '_rel');
        if ($result = $db->query('SHOW INDEX FROM `' . $table . '`')) {
            $keys = array('PRIMARY' => '');
            while ($arr = $db->fetchArray($result)) {
                unset($keys[$arr['Key_name']]);
            }
            if ($keys) {
                $dels = array();
                $query = 'SELECT CONCAT(pgid, \'_\', relid) as id, (count(*)-1) as count FROM `' . $table . '` GROUP BY id HAVING count >= 1';
                if ($result = $db->query($query)) {
                    while ($arr = $db->fetchRow($result)) {
                        $dels[$arr[0]] = $arr[1];
                    }
                }
                foreach ($dels as $key => $limit) {
                    $arr = explode('_', $key);
                    $query = 'DELETE FROM ' . $table . ' WHERE pgid=' . $arr[0] . ' AND relid=' . $arr[1] . ' LIMIT ' . $limit;
                    $db->query($query);
                    //$msgs[] = $query;
                }
                $query = 'ALTER TABLE `' . $table . '` ADD PRIMARY KEY(`pgid`,`relid`)';
                $db->query($query);
                //$msgs[] = $query;
            }
        }
        $table = $db->prefix($mydirname . '_count');
        if ($result = $db->query('SHOW INDEX FROM `' . $table . '`')) {
            $keys = array('today' => '');
            while ($arr = $db->fetchArray($result)) {
                unset($keys[$arr['Key_name']]);
            }
            foreach ($keys as $_key => $_val) {
                $query = 'ALTER TABLE `' . $table . '` ADD INDEX(`' . $_key . '`' . $_val . ')';
                $db->query($query);
                //$msgs[] = $query;
            }
        }
        // TEMPLATES (all templates have been already removed by modulesadmin)
        $tplfile_handler =& xoops_gethandler('tplfile');
        $tpl_path = dirname(__FILE__) . '/templates';
        if ($handler = @opendir($tpl_path . '/')) {
            while (($file = readdir($handler)) !== false) {
                if (substr($file, 0, 1) == '.') {
                    continue;
                }
                $file_path = $tpl_path . '/' . $file;
                if (is_file($file_path) && substr($file, -5) == '.html') {
                    $mtime = intval(@filemtime($file_path));
                    $tplfile =& $tplfile_handler->create();
                    $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                    $tplfile->setVar('tpl_refid', $mid);
                    $tplfile->setVar('tpl_tplset', 'default');
                    $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                    $tplfile->setVar('tpl_desc', '', true);
                    $tplfile->setVar('tpl_module', $mydirname);
                    $tplfile->setVar('tpl_lastmodified', $mtime);
                    $tplfile->setVar('tpl_lastimported', 0);
                    $tplfile->setVar('tpl_type', 'module');
                    if (!$tplfile_handler->insert($tplfile)) {
                        $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
                    } else {
                        $tplid = $tplfile->getVar('tpl_id');
                        $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                        // generate compiled file
                        include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                        include_once XOOPS_ROOT_PATH . '/class/template.php';
                        if (!xoops_template_touch($tplid)) {
                            $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>';
                        } else {
                            $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span>';
                        }
                    }
                }
            }
            closedir($handler);
        }
        include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
        include_once XOOPS_ROOT_PATH . '/class/template.php';
        xoops_template_clear_module_cache($mid);
        // xpWiki original functions
        include_once dirname(__FILE__) . '/include/check.func.php';
        $_ret = xpwikifunc_permission_check($mydirname);
        if (!$_ret) {
            $msgs = array_merge($msgs, xpwikifunc_defdata_check($mydirname, 'update'));
        } else {
            $msgs = array_merge($msgs, $_ret);
            return false;
        }
        // Delete COUNTER_DIR/*.counter
        $msgs = array_merge($msgs, xpwikifunc_delete_counter($mydirname));
        return true;
    }
コード例 #21
0
ファイル: modulesadmin.php プロジェクト: koki-h/xoops_utf8
function xoops_module_install($dirname)
{
    global $xoopsUser, $xoopsConfig;
    $dirname = trim($dirname);
    $db =& Database::getInstance();
    $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');
    $module_handler =& xoops_gethandler('module');
    if ($module_handler->getCount(new Criteria('dirname', $dirname)) == 0) {
        $module =& $module_handler->create();
        $module->loadInfoAsVar($dirname);
        $module->setVar('weight', 1);
        $error = false;
        $errs = array();
        $sqlfile =& $module->getInfo('sqlfile');
        $msgs = array();
        $msgs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing ' . $module->getInfo('name') . '</h4>';
        if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
            $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />';
        }
        $msgs[] = '<b>Version:</b> ' . $module->getInfo('version');
        if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
            $msgs[] = '<b>Author:</b> ' . trim($module->getInfo('author'));
        }
        $msgs[] = '';
        $errs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing ' . $module->getInfo('name') . '</h4>';
        if ($sqlfile != false && is_array($sqlfile)) {
            $sql_file_path = XOOPS_ROOT_PATH . "/modules/" . $dirname . "/" . $sqlfile[XOOPS_DB_TYPE];
            if (!file_exists($sql_file_path)) {
                $errs[] = "SQL file not found at <b>{$sql_file_path}</b>";
                $error = true;
            } else {
                $msgs[] = "SQL file found at <b>{$sql_file_path}</b>.<br  /> Creating tables...";
                include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
                $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
                $sql_query = trim($sql_query);
                SqlUtility::splitMySqlFile($pieces, $sql_query);
                $created_tables = array();
                foreach ($pieces as $piece) {
                    // [0] contains the prefixed query
                    // [4] contains unprefixed table name
                    $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
                    if (!$prefixed_query) {
                        $errs[] = "<b>{$piece}</b> is not a valid SQL!";
                        $error = true;
                        break;
                    }
                    // check if the table name is reserved
                    if (!in_array($prefixed_query[4], $reservedTables)) {
                        // not reserved, so try to create one
                        if (!$db->query($prefixed_query[0])) {
                            $errs[] = $db->error();
                            $error = true;
                            break;
                        } else {
                            if (!in_array($prefixed_query[4], $created_tables)) {
                                $msgs[] = '&nbsp;&nbsp;Table <b>' . $db->prefix($prefixed_query[4]) . '</b> created.';
                                $created_tables[] = $prefixed_query[4];
                            } else {
                                $msgs[] = '&nbsp;&nbsp;Data inserted to table <b>' . $db->prefix($prefixed_query[4]) . '</b>.';
                            }
                        }
                    } else {
                        // the table name is reserved, so halt the installation
                        $errs[] = '<b>' . $prefixed_query[4] . "</b> is a reserved table!";
                        $error = true;
                        break;
                    }
                }
                // if there was an error, delete the tables created so far, so the next installation will not fail
                if ($error == true) {
                    foreach ($created_tables as $ct) {
                        //echo $ct;
                        $db->query("DROP TABLE " . $db->prefix($ct));
                    }
                }
            }
        }
        // if no error, save the module info and blocks info associated with it
        if ($error == false) {
            if (!$module_handler->insert($module)) {
                $errs[] = 'Could not insert <b>' . $module->getVar('name') . '</b> to database.';
                foreach ($created_tables as $ct) {
                    $db->query("DROP TABLE " . $db->prefix($ct));
                }
                $ret = "<p>" . sprintf(_MD_AM_FAILINS, "<b>" . $module->name() . "</b>") . "&nbsp;" . _MD_AM_ERRORSC . "<br />";
                foreach ($errs as $err) {
                    $ret .= " - " . $err . "<br />";
                }
                $ret .= "</p>";
                unset($module);
                unset($created_tables);
                unset($errs);
                unset($msgs);
                return $ret;
            } else {
                $newmid = $module->getVar('mid');
                unset($created_tables);
                $msgs[] = 'Module data inserted successfully. Module ID: <b>' . $newmid . '</b>';
                $tplfile_handler =& xoops_gethandler('tplfile');
                $templates = $module->getInfo('templates');
                if ($templates != false) {
                    $msgs[] = 'Adding templates...';
                    foreach ($templates as $tpl) {
                        $tplfile =& $tplfile_handler->create();
                        $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']);
                        $tplfile->setVar('tpl_source', $tpldata, true);
                        $tplfile->setVar('tpl_refid', $newmid);
                        $tplfile->setVar('tpl_tplset', 'default');
                        $tplfile->setVar('tpl_file', $tpl['file']);
                        $tplfile->setVar('tpl_desc', $tpl['description'], true);
                        $tplfile->setVar('tpl_module', $dirname);
                        $tplfile->setVar('tpl_lastmodified', time());
                        $tplfile->setVar('tpl_lastimported', 0);
                        $tplfile->setVar('tpl_type', 'module');
                        if (!$tplfile_handler->insert($tplfile)) {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>' . $tpl['file'] . '</b> to the database.</span>';
                        } else {
                            $newtplid = $tplfile->getVar('tpl_id');
                            $msgs[] = '&nbsp;&nbsp;Template <b>' . $tpl['file'] . '</b> added to the database. (ID: <b>' . $newtplid . '</b>)';
                            // generate compiled file
                            include_once XOOPS_ROOT_PATH . '/class/template.php';
                            if (!xoops_template_touch($newtplid)) {
                                $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . $tpl['file'] . '</b>.</span>';
                            } else {
                                $msgs[] = '&nbsp;&nbsp;Template <b>' . $tpl['file'] . '</b> compiled.</span>';
                            }
                        }
                        unset($tpldata);
                    }
                }
                include_once XOOPS_ROOT_PATH . '/class/template.php';
                xoops_template_clear_module_cache($newmid);
                $blocks = $module->getInfo('blocks');
                if ($blocks != false) {
                    $msgs[] = 'Adding blocks...';
                    foreach ($blocks as $blockkey => $block) {
                        // break the loop if missing block config
                        if (!isset($block['file']) || !isset($block['show_func'])) {
                            break;
                        }
                        $options = '';
                        if (!empty($block['options'])) {
                            $options = trim($block['options']);
                        }
                        $newbid = $db->genId($db->prefix('newblocks') . '_bid_seq');
                        $edit_func = isset($block['edit_func']) ? trim($block['edit_func']) : '';
                        $template = '';
                        if (isset($block['template']) && trim($block['template']) != '') {
                            $content =& xoops_module_gettemplate($dirname, $block['template'], true);
                        }
                        if (!isset($content)) {
                            $content = '';
                        } else {
                            $template = trim($block['template']);
                        }
                        $block_name = addslashes(trim($block['name']));
                        $sql = "INSERT INTO " . $db->prefix("newblocks") . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES ({$newbid}, {$newmid}, " . intval($blockkey) . ", '{$options}', '" . $block_name . "','" . $block_name . "', '', 0, 0, 0, 'M', 'H', 1, '" . addslashes($dirname) . "', '" . addslashes(trim($block['file'])) . "', '" . addslashes(trim($block['show_func'])) . "', '" . addslashes($edit_func) . "', '" . $template . "', 0, " . time() . ")";
                        if (!$db->query($sql)) {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add block <b>' . $block['name'] . '</b> to the database! Database error: <b>' . $db->error() . '</b></span>';
                        } else {
                            if (empty($newbid)) {
                                $newbid = $db->getInsertId();
                            }
                            $msgs[] = '&nbsp;&nbsp;Block <b>' . $block['name'] . '</b> added. Block ID: <b>' . $newbid . '</b>';
                            $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)';
                            $db->query($sql);
                            if ($template != '') {
                                $tplfile =& $tplfile_handler->create();
                                $tplfile->setVar('tpl_refid', $newbid);
                                $tplfile->setVar('tpl_source', $content, true);
                                $tplfile->setVar('tpl_tplset', 'default');
                                $tplfile->setVar('tpl_file', $block['template']);
                                $tplfile->setVar('tpl_module', $dirname);
                                $tplfile->setVar('tpl_type', 'block');
                                $tplfile->setVar('tpl_desc', $block['description'], true);
                                $tplfile->setVar('tpl_lastimported', 0);
                                $tplfile->setVar('tpl_lastmodified', time());
                                if (!$tplfile_handler->insert($tplfile)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>' . $block['template'] . '</b> to the database.</span>';
                                } else {
                                    $newtplid = $tplfile->getVar('tpl_id');
                                    $msgs[] = '&nbsp;&nbsp;Template <b>' . $block['template'] . '</b> added to the database. (ID: <b>' . $newtplid . '</b>)';
                                    // generate compiled file
                                    include_once XOOPS_ROOT_PATH . '/class/template.php';
                                    if (!xoops_template_touch($newtplid)) {
                                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . $block['template'] . '</b>.</span>';
                                    } else {
                                        $msgs[] = '&nbsp;&nbsp;Template <b>' . $block['template'] . '</b> compiled.</span>';
                                    }
                                }
                            }
                        }
                        unset($content);
                    }
                    unset($blocks);
                }
                $configs = $module->getInfo('config');
                if ($configs != false) {
                    if ($module->getVar('hascomments') != 0) {
                        include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
                        array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)));
                        array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0));
                    }
                } else {
                    if ($module->getVar('hascomments') != 0) {
                        $configs = array();
                        include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
                        $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN));
                        $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0);
                    }
                }
                // RMV-NOTIFY
                if ($module->getVar('hasnotification') != 0) {
                    if (empty($configs)) {
                        $configs = array();
                    }
                    // Main notification options
                    include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
                    include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
                    $options = array();
                    $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
                    $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
                    $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
                    $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
                    //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
                    $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options);
                    // Event-specific notification options
                    // FIXME: doesn't work when update module... can't read back the array of options properly...  " changing to &quot;
                    $options = array();
                    $categories =& notificationCategoryInfo('', $module->getVar('mid'));
                    foreach ($categories as $category) {
                        $events =& notificationEvents($category['name'], false, $module->getVar('mid'));
                        foreach ($events as $event) {
                            if (!empty($event['invisible'])) {
                                continue;
                            }
                            $option_name = $category['title'] . ' : ' . $event['title'];
                            $option_value = $category['name'] . '-' . $event['name'];
                            $options[$option_name] = $option_value;
                        }
                    }
                    $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options);
                }
                if ($configs != false) {
                    $msgs[] = 'Adding module config data...';
                    $config_handler =& xoops_gethandler('config');
                    $order = 0;
                    foreach ($configs as $config) {
                        $confobj =& $config_handler->createConfig();
                        $confobj->setVar('conf_modid', $newmid);
                        $confobj->setVar('conf_catid', 0);
                        $confobj->setVar('conf_name', $config['name']);
                        $confobj->setVar('conf_title', $config['title'], true);
                        $confobj->setVar('conf_desc', $config['description'], true);
                        $confobj->setVar('conf_formtype', $config['formtype']);
                        $confobj->setVar('conf_valuetype', $config['valuetype']);
                        $confobj->setConfValueForInput($config['default'], true);
                        //$confobj->setVar('conf_value', $config['default'], true);
                        $confobj->setVar('conf_order', $order);
                        $confop_msgs = '';
                        if (isset($config['options']) && is_array($config['options'])) {
                            foreach ($config['options'] as $key => $value) {
                                $confop =& $config_handler->createConfigOption();
                                $confop->setVar('confop_name', $key, true);
                                $confop->setVar('confop_value', $value, true);
                                $confobj->setConfOptions($confop);
                                $confop_msgs .= '<br />&nbsp;&nbsp;&nbsp;&nbsp;Config option added. Name: <b>' . $key . '</b> Value: <b>' . $value . '</b>';
                                unset($confop);
                            }
                        }
                        $order++;
                        if ($config_handler->insertConfig($confobj) != false) {
                            $msgs[] = '&nbsp;&nbsp;Config <b>' . $config['name'] . '</b> added to the database.' . $confop_msgs;
                        } else {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert config <b>' . $config['name'] . '</b> to the database.</span>';
                        }
                        unset($confobj);
                    }
                    unset($configs);
                }
            }
            $groups = $xoopsUser->getGroups();
            // retrieve all block ids for this module
            $blocks =& XoopsBlock::getByModule($newmid, false);
            $msgs[] = 'Setting group rights...';
            $gperm_handler =& xoops_gethandler('groupperm');
            foreach ($groups as $mygroup) {
                if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) {
                    $mperm =& $gperm_handler->create();
                    $mperm->setVar('gperm_groupid', $mygroup);
                    $mperm->setVar('gperm_itemid', $newmid);
                    $mperm->setVar('gperm_name', 'module_admin');
                    $mperm->setVar('gperm_modid', 1);
                    if (!$gperm_handler->insert($mperm)) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add admin access right for Group ID <b>' . $mygroup . '</b></span>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;Added admin access right for Group ID <b>' . $mygroup . '</b>';
                    }
                    unset($mperm);
                }
                $mperm =& $gperm_handler->create();
                $mperm->setVar('gperm_groupid', $mygroup);
                $mperm->setVar('gperm_itemid', $newmid);
                $mperm->setVar('gperm_name', 'module_read');
                $mperm->setVar('gperm_modid', 1);
                if (!$gperm_handler->insert($mperm)) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add user access right for Group ID: <b>' . $mygroup . '</b></span>';
                } else {
                    $msgs[] = '&nbsp;&nbsp;Added user access right for Group ID: <b>' . $mygroup . '</b>';
                }
                unset($mperm);
                foreach ($blocks as $blc) {
                    $bperm =& $gperm_handler->create();
                    $bperm->setVar('gperm_groupid', $mygroup);
                    $bperm->setVar('gperm_itemid', $blc);
                    $bperm->setVar('gperm_name', 'block_read');
                    $bperm->setVar('gperm_modid', 1);
                    if (!$gperm_handler->insert($bperm)) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add block access right. Block ID: <b>' . $blc . '</b> Group ID: <b>' . $mygroup . '</b></span>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;Added block access right. Block ID: <b>' . $blc . '</b> Group ID: <b>' . $mygroup . '</b>';
                    }
                    unset($bperm);
                }
            }
            unset($blocks);
            unset($groups);
            // execute module specific install script if any
            $install_script = $module->getInfo('onInstall');
            if (false != $install_script && trim($install_script) != '') {
                include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($install_script);
                if (function_exists('xoops_module_install_' . $dirname)) {
                    $func = 'xoops_module_install_' . $dirname;
                    if (!$func($module)) {
                        $msgs[] = 'Failed to execute ' . $func;
                    } else {
                        $msgs[] = '<b>' . $func . '</b> executed successfully.';
                    }
                }
            }
            $ret = '<p><code>';
            foreach ($msgs as $m) {
                $ret .= $m . '<br />';
            }
            unset($msgs);
            unset($errs);
            $ret .= '</code><br />' . sprintf(_MD_AM_OKINS, "<b>" . $module->getVar('name') . "</b>") . '</p>';
            unset($module);
            return $ret;
        } else {
            $ret = '<p>';
            foreach ($errs as $er) {
                $ret .= '&nbsp;&nbsp;' . $er . '<br />';
            }
            unset($msgs);
            unset($errs);
            $ret .= '<br />' . sprintf(_MD_AM_FAILINS, '<b>' . $dirname . '</b>') . '&nbsp;' . _MD_AM_ERRORSC . '</p>';
            return $ret;
        }
    } else {
        return "<p>" . sprintf(_MD_AM_FAILINS, "<b>" . $dirname . "</b>") . "&nbsp;" . _MD_AM_ERRORSC . "<br />&nbsp;&nbsp;" . sprintf(_MD_AM_ALEXISTS, $dirname) . "</p>";
    }
}
コード例 #22
0
ファイル: altsys_functions.php プロジェクト: hiro1173/legacy
function altsys_template_touch($tpl_id)
{
    if (in_array(altsys_get_core_type(), array(ALTSYS_CORE_TYPE_X20S, ALTSYS_CORE_TYPE_X23P, ALTSYS_CORE_TYPE_X25))) {
        // need to delete all files under templates_c/
        altsys_clear_templates_c();
    } else {
        // just touch the template
        xoops_template_touch($tpl_id);
    }
}
コード例 #23
0
ファイル: onupdate.php プロジェクト: nunoluciano/uxcl
function dbcss_onupdate_base( $module , $mydirname )
{
	// transations on module update

	global $msgs ; // TODO :-D

	// for Cube 2.1
	if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
		$root =& XCube_Root::getSingleton();
		$root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'dbcss_message_append_onupdate' ) ;
		$msgs = array() ;
	} else {
		if( ! is_array( $msgs ) ) $msgs = array() ;
	}

	$db =& Database::getInstance() ;
	$mid = $module->getVar('mid') ;

	// TABLES (write here ALTER TABLE etc. if necessary)

	// 0.6 -> 0.7
	$check_sql = "SELECT COUNT(*) FROM ".$db->prefix($mydirname."_metalink") ;
	if( ! $db->query( $check_sql ) ) {
		$db->queryF( "CREATE TABLE ".$db->prefix($mydirname."_metalink")." (lid int(10) NOT NULL default '0', metakey text NOT NULL, metadesc text NOT NULL, robots varchar(100) NOT NULL default '', rating varchar(100) NOT NULL default '', author varchar(255) NOT NULL default '', UNIQUE KEY lid (lid)) TYPE=MyISAM" ) ;
	}

	// 0.8 -> 0.9
	$check_sql = "SELECT COUNT(*) FROM ".$db->prefix($mydirname."_scriptbody") ;
	if( ! $db->query( $check_sql ) ) {
		$db->queryF( "CREATE TABLE ".$db->prefix($mydirname."_scriptbody")." (lid mediumint(5) unsigned NOT NULL auto_increment, title varchar(255) NOT NULL default '', created int(10) NOT NULL default '0', body text NOT NULL, css text NOT NULL, UNIQUE KEY lid (lid)) TYPE=MyISAM;" ) ;
	}

	// 0.9 -> 1.0
	$check_sql = "SELECT COUNT(*) FROM ".$db->prefix($mydirname."_cssexport") ;
	if( ! $db->query( $check_sql ) ) {
		$db->queryF( "CREATE TABLE ".$db->prefix($mydirname."_cssexport")." (lid int(10) NOT NULL default '0', exportdir varchar(255) NOT NULL default '', UNIQUE KEY lid (lid)
) TYPE=MyISAM;" ) ;
	}

	// configs (Though I know it is not a recommended way...)
	$check_sql = "SHOW COLUMNS FROM ".$db->prefix("config")." LIKE 'conf_title'" ;
	if( ( $result = $db->query( $check_sql ) ) && ( $myrow = $db->fetchArray( $result ) ) && @$myrow['Type'] == 'varchar(30)' ) {
		$db->queryF( "ALTER TABLE ".$db->prefix("config")." MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''" ) ;
	}

	// configs (Though I know it is not a recommended way...)
	$check_sql = "SHOW COLUMNS FROM ".$db->prefix("config")." LIKE 'conf_title'" ;
	if( ( $result = $db->query( $check_sql ) ) && ( $myrow = $db->fetchArray( $result ) ) && @$myrow['Type'] == 'varchar(30)' ) {
		$db->queryF( "ALTER TABLE ".$db->prefix("config")." MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''" ) ;
	}

	// TEMPLATES (all templates have been already removed by modulesadmin)
	include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
	include_once XOOPS_ROOT_PATH.'/class/template.php' ;

	$tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
	$tpl_path = dirname(__FILE__).'/templates' ;

	if( $handler = @opendir( $tpl_path . '/' ) ) {
		while( ( $file = readdir( $handler ) ) !== false ) {
			if( substr( $file , 0 , 1 ) == '.' ) continue ;
			$file_path = $tpl_path . '/' . $file ;
			if( is_file( $file_path ) ) {
				$mtime = intval( @filemtime( $file_path ) ) ;
				$tplfile =& $tplfile_handler->create() ;
				$tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
				$tplfile->setVar( 'tpl_refid' , $mid ) ;
				$tplfile->setVar( 'tpl_tplset' , 'default' ) ;
				$tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ;
				$tplfile->setVar( 'tpl_desc' , '' , true ) ;
				$tplfile->setVar( 'tpl_module' , $mydirname ) ;
				$tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
				$tplfile->setVar( 'tpl_lastimported' , 0 ) ;
				$tplfile->setVar( 'tpl_type' , 'module' ) ;
				if( ! $tplfile_handler->insert( $tplfile ) ) {
					$msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
				} else {
					$tplid = $tplfile->getVar( 'tpl_id' ) ;
					$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)';
					// generate compiled file
					if( ! xoops_template_touch( $tplid ) ) {
						$msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>';
					} else {
						$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>';
					}
				}
			}
		}
		closedir( $handler ) ;
	}

	/*************** BEGIN DBCSS SPECIFIC PART ******************/
	// CSS TEMPLATES
	if( file_exists( XOOPS_TRUST_PATH.'/uploads/'.$mydirname ) ) {
		$CSS_path = XOOPS_TRUST_PATH.'/uploads/'.$mydirname ;

		if( $handler = @opendir( $CSS_path . '/' ) ) {
			while( ( $file = readdir( $handler ) ) !== false ) {
				if( substr( $file , 0 , 1 ) == '.' ) continue ;
				$file_path = $CSS_path . '/' . $file ;
				if ( is_file( $file_path ) && substr( $file , -4 ) == '.css'){
					$mtime = intval( @filemtime( $file_path ) ) ;
					$tplfile =& $tplfile_handler->create() ;
					$tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
					$tplfile->setVar( 'tpl_refid' , $mid ) ;
					$tplfile->setVar( 'tpl_tplset' , 'default' ) ;
					$tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ;
					$tplfile->setVar( 'tpl_desc' , '' , true ) ;
					$tplfile->setVar( 'tpl_module' , $mydirname ) ;
					$tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
					$tplfile->setVar( 'tpl_lastimported' , 0 ) ;
					$tplfile->setVar( 'tpl_type' , 'module' ) ;
					if( ! $tplfile_handler->insert( $tplfile ) ) {
						$msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
					} else {
						$tplid = $tplfile->getVar( 'tpl_id' ) ;
						$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)';
						// generate compiled file
						if( ! xoops_template_touch( $tplid ) ) {
							$msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>';
						} else {
							$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>';
						}
					}
				}
			}
		}
		closedir( $handler ) ;
	}
	xoops_template_clear_module_cache( $mid ) ;
	/*************** END DBCSS SPECIFIC PART ******************/

	return true ;
}
コード例 #24
0
 function d3forum_onupdate_base($module, $mydirname)
 {
     // transations on module update
     global $msgs;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'd3forum_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // configs (Though I know it is not a recommended way...)
     $check_sql = "SHOW COLUMNS FROM " . $db->prefix("config") . " LIKE 'conf_title'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] == 'varchar(30)') {
         $db->queryF("ALTER TABLE " . $db->prefix("config") . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
     }
     // 0.1x -> 0.2x
     $check_sql = "SELECT cat_unique_path FROM " . $db->prefix($mydirname . "_categories");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " ADD cat_unique_path text NOT NULL default '' AFTER cat_path_in_tree");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_forums") . " ADD forum_external_link_format varchar(255) NOT NULL default '' AFTER cat_id");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_topics") . " ADD topic_external_link_id int(10) unsigned NOT NULL default 0 AFTER forum_id, ADD KEY (`topic_external_link_id`)");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_posts") . " ADD path_in_tree text NOT NULL default '' AFTER order_in_tree , ADD unique_path text NOT NULL default '' AFTER order_in_tree");
     }
     // 0.3x -> 0.4x
     $check_sql = "SELECT subject_waiting FROM " . $db->prefix($mydirname . "_posts");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_posts") . " ADD subject_waiting varchar(255) NOT NULL default '' AFTER `subject`, ADD post_text_waiting text NOT NULL AFTER `post_text`, ADD uid_hidden mediumint(8) unsigned NOT NULL default 0 AFTER `uid`, DROP hide_uid");
     }
     // 0.4x/0.6x -> 0.7x
     $check_sql = "SHOW COLUMNS FROM " . $db->prefix($mydirname . "_topics") . " LIKE 'topic_external_link_id'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && substr(@$myrow['Type'], 0, 3) == 'int') {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_topics") . " MODIFY topic_external_link_id varchar(255) NOT NULL default ''");
     }
     $check_sql = "SELECT COUNT(*) FROM " . $db->prefix($mydirname . "_post_histories");
     if (!$db->query($check_sql)) {
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_post_histories") . " ( history_id int(10) unsigned NOT NULL auto_increment, post_id int(10) unsigned NOT NULL default 0, history_time int(10) NOT NULL default 0, data text, PRIMARY KEY (history_id), KEY (post_id) ) TYPE=MyISAM");
     }
     // TEMPLATES (all templates have been already removed by modulesadmin)
     $tplfile_handler =& xoops_gethandler('tplfile');
     $tpl_path = dirname(__FILE__) . '/templates';
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path)) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                     // generate compiled file
                     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                     include_once XOOPS_ROOT_PATH . '/class/template.php';
                     if (!xoops_template_touch($tplid)) {
                         $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span>';
                     }
                 }
             }
         }
         closedir($handler);
     }
     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
     include_once XOOPS_ROOT_PATH . '/class/template.php';
     xoops_template_clear_module_cache($mid);
     return true;
 }
コード例 #25
0
ファイル: onupdate.php プロジェクト: naao/xelfinder
    function xelfinder_onupdate_base($module, $mydirname)
    {
        // transations on module update
        global $msgs;
        // TODO :-D
        // for Cube 2.1
        if (defined('XOOPS_CUBE_LEGACY')) {
            $root =& XCube_Root::getSingleton();
            $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'xelfinder_message_append_onupdate');
            $msgs = array();
        } else {
            if (!is_array($msgs)) {
                $msgs = array();
            }
        }
        $db =& Database::getInstance();
        $mid = $module->getVar('mid');
        // TABLES (write here ALTER TABLE etc. if necessary)
        $query = "SELECT `gids` FROM " . $db->prefix($mydirname . "_file");
        if (!$db->query($query)) {
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD `gids` VARCHAR( 255 ) NOT NULL');
        }
        // from v 0.10
        $query = "SELECT `mime_filter` FROM " . $db->prefix($mydirname . "_file");
        if (!$db->query($query)) {
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD `mime_filter` VARCHAR( 255 ) NOT NULL');
        }
        // from v 0.13
        $query = "SHOW COLUMNS FROM `" . $db->prefix($mydirname . "_file") . "` LIKE 'mime'";
        $res = $db->query($query);
        $dat = $db->fetchArray($res);
        if ($dat['Type'] !== 'varchar(255)') {
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `mime` `mime` varchar(255) NOT NULL DEFAULT \'unknown\'');
        }
        // from v 0.17
        $query = "SELECT `id` FROM " . $db->prefix($mydirname . "_userdat");
        if (!$db->query($query)) {
            $db->queryF('CREATE TABLE `' . $db->prefix($mydirname . '_userdat') . '`' . '(
				  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
				  `uid` int(10) unsigned NOT NULL,
				  `key` varchar(255) NOT NULL,
				  `data` blob NOT NULL,
				  `mtime` int(10) unsigned NOT NULL,
				  PRIMARY KEY (`id`),
				  KEY `uid_key` (`uid`,`key`)
				) ENGINE=MyISAM');
        }
        //from v0.22
        $query = "SELECT `local_path` FROM " . $db->prefix($mydirname . "_file");
        if (!$db->query($query)) {
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD `local_path` VARCHAR( 255 ) NOT NULL');
        }
        // TEMPLATES (all templates have been already removed by modulesadmin)
        $tplfile_handler =& xoops_gethandler('tplfile');
        $tpl_path = dirname(__FILE__) . '/templates';
        if ($handler = @opendir($tpl_path . '/')) {
            while (($file = readdir($handler)) !== false) {
                if (substr($file, 0, 1) == '.') {
                    continue;
                }
                $file_path = $tpl_path . '/' . $file;
                if (is_file($file_path)) {
                    $mtime = intval(@filemtime($file_path));
                    $tplfile =& $tplfile_handler->create();
                    $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                    $tplfile->setVar('tpl_refid', $mid);
                    $tplfile->setVar('tpl_tplset', 'default');
                    $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                    $tplfile->setVar('tpl_desc', '', true);
                    $tplfile->setVar('tpl_module', $mydirname);
                    $tplfile->setVar('tpl_lastmodified', $mtime);
                    $tplfile->setVar('tpl_lastimported', 0);
                    $tplfile->setVar('tpl_type', 'module');
                    if (!$tplfile_handler->insert($tplfile)) {
                        $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
                    } else {
                        $tplid = $tplfile->getVar('tpl_id');
                        $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                        // generate compiled file
                        include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                        include_once XOOPS_ROOT_PATH . '/class/template.php';
                        if (!xoops_template_touch($tplid)) {
                            $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>';
                        } else {
                            $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span>';
                        }
                    }
                }
            }
            closedir($handler);
        }
        include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
        include_once XOOPS_ROOT_PATH . '/class/template.php';
        xoops_template_clear_module_cache($mid);
        return true;
    }
コード例 #26
0
ファイル: main.php プロジェクト: BackupTheBerlios/haxoo-svn
                     $tplfile->setVar('tpl_module', $dirname);
                     $tplfile->setVar('tpl_refid', $newbid);
                     $tplfile->setVar('tpl_source', $content, true);
                     $tplfile->setVar('tpl_tplset', 'default');
                     $tplfile->setVar('tpl_file', $block['template'], true);
                     $tplfile->setVar('tpl_type', 'block');
                     $tplfile->setVar('tpl_lastimported', time());
                     $tplfile->setVar('tpl_lastmodified', time());
                     $tplfile->setVar('tpl_desc', $block['description'], true);
                     if (!$tplfile_handler->insert($tplfile)) {
                         $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, "<strong>" . $block['template'] . "</strong>") . '</span>';
                     } else {
                         $newid = $tplfile->getVar('tpl_id');
                         $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, "<strong>" . $block['template'] . "</strong>");
                         if ($xoopsConfig['template_set'] == 'default') {
                             if (!xoops_template_touch($newid)) {
                                 $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_FAILD, "<strong>" . $block['template'] . "</strong>") . '</span>';
                             } else {
                                 $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, "<strong>" . $block['template'] . "</strong>");
                             }
                         }
                     }
                 }
                 $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_CREATED, "<strong>" . $block['name'] . "</strong>") . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, "<strong>" . $newbid . "</strong>");
                 $sql = 'INSERT INTO ' . $xoopsDB->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)';
                 $xoopsDB->query($sql);
             }
         }
     }
 }
 $block_arr = XoopsBlock::getByModule($module->getVar('mid'));
コード例 #27
0
         $xoopsTpl->clear_compiled_tpl();
         // generate compiled files for the new theme
         // block files only for now..
         $tplfile_handler =& xoops_gethandler('tplfile');
         $dtemplates =& $tplfile_handler->find('default', 'block');
         $dcount = count($dtemplates);
         // need to do this to pass to xoops_template_touch function
         $GLOBALS['xoopsConfig']['template_set'] = $newtplset;
         for ($i = 0; $i < $dcount; $i++) {
             $found =& $tplfile_handler->find($newtplset, 'block', $dtemplates[$i]->getVar('tpl_refid'), null);
             if (count($found) > 0) {
                 // template for the new theme found, compile it
                 xoops_template_touch($found[0]->getVar('tpl_id'));
             } else {
                 // not found, so compile 'default' template file
                 xoops_template_touch($dtemplates[$i]->getVar('tpl_id'));
             }
         }
         // generate image cache files from image binary data, save them under cache/
         $image_handler =& xoops_gethandler('imagesetimg');
         $imagefiles =& $image_handler->getObjects(new Criteria('tplset_name', $newtplset), true);
         foreach (array_keys($imagefiles) as $i) {
             if (!($fp = fopen(XOOPS_CACHE_PATH . '/' . $newtplset . '_' . $imagefiles[$i]->getVar('imgsetimg_file'), 'wb'))) {
             } else {
                 fwrite($fp, $imagefiles[$i]->getVar('imgsetimg_body'));
                 fclose($fp);
             }
         }
     }
     $tpl_updated = true;
 }
コード例 #28
0
function xoops_module_install($dirname)
{
    global $xoopsUser, $xoopsConfig;
    $dirname = trim($dirname);
    $db =& $GLOBALS["xoopsDB"];
    $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');
    $module_handler =& xoops_gethandler('module');
    if ($module_handler->getCount(new Criteria('dirname', $dirname)) == 0) {
        $module =& $module_handler->create();
        $module->loadInfoAsVar($dirname);
        $module->setVar('weight', 1);
        $error = false;
        $errs = array();
        $msgs = array();
        $msgs[] = '<h4 style="margin-bottom: 0px;border-bottom: dashed 1px #000000;">' . _MD_AM_INSTALLING . $module->getInfo('name') . '</h4>';
        if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
            $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />';
        }
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version');
        if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
            $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . trim($module->getInfo('author'));
        }
        $msgs[] = '';
        $errs[] = '<h4 style="margin-bottom: 0px;border-bottom: dashed 1px #000000;">' . _MD_AM_INSTALLING . $module->getInfo('name') . '</h4>';
        // Load module specific install script if any
        $install_script = $module->getInfo('onInstall');
        if ($install_script && trim($install_script) != '') {
            include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($install_script);
        }
        $func = "xoops_module_pre_install_{$dirname}";
        // If pre install function is defined, execute
        if (function_exists($func)) {
            $result = $func($module);
            if (!$result) {
                $error = true;
                $errs[] = "<p>" . sprintf(_MD_AM_FAILED_EXECUTE, $func) . "</p>";
                $errs = array_merge($errs, $module->getErrors());
            } else {
                $msgs[] = "<p>" . sprintf(_MD_AM_FAILED_SUCESS, "<strong>{$func}</strong>") . "</p>";
                $msgs += $module->getErrors();
            }
        }
        if ($error == false) {
            $sqlfile = $module->getInfo('sqlfile');
            if (is_array($sqlfile) && !empty($sqlfile[XOOPS_DB_TYPE])) {
                $sql_file_path = XOOPS_ROOT_PATH . "/modules/" . $dirname . "/" . $sqlfile[XOOPS_DB_TYPE];
                if (!file_exists($sql_file_path)) {
                    $errs[] = "<p>" . sprintf(_MD_AM_SQL_NOT_FOUND, "<strong>{$sql_file_path}</strong>");
                    $error = true;
                } else {
                    $msgs[] = "<p>" . sprintf(_MD_AM_SQL_FOUND, "<strong>{$sql_file_path}</strong>") . "<br  />" . _MD_AM_CREATE_TABLES;
                    include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
                    $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
                    $sql_query = trim($sql_query);
                    SqlUtility::splitMySqlFile($pieces, $sql_query);
                    $created_tables = array();
                    foreach ($pieces as $piece) {
                        // [0] contains the prefixed query
                        // [4] contains unprefixed table name
                        $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
                        if (!$prefixed_query) {
                            $errs[] = "<p>" . sprintf(_MD_AM_SQL_NOT_VALID, "<strong>" . $piece . "</strong>");
                            $error = true;
                            break;
                        }
                        // check if the table name is reserved
                        if (!in_array($prefixed_query[4], $reservedTables)) {
                            // not reserved, so try to create one
                            if (!$db->query($prefixed_query[0])) {
                                $errs[] = $db->error();
                                $error = true;
                                break;
                            } else {
                                if (!in_array($prefixed_query[4], $created_tables)) {
                                    $msgs[] = "&nbsp;&nbsp;" . sprintf(_MD_AM_TABLE_CREATED, "<strong>" . $db->prefix($prefixed_query[4]) . "</strong>");
                                    $created_tables[] = $prefixed_query[4];
                                } else {
                                    $msgs[] = "&nbsp;&nbsp;" . sprintf(_MD_AM_INSERT_DATA, "<strong>" . $db->prefix($prefixed_query[4]) . "</strong>");
                                }
                            }
                        } else {
                            // the table name is reserved, so halt the installation
                            $errs[] = "&nbsp;&nbsp;" . sprintf(_MD_AM_TABLE_RESERVED, "<strong>" . $prefixed_query[4] . "</strong>");
                            $error = true;
                            break;
                        }
                    }
                    // if there was an error, delete the tables created so far, so the next installation will not fail
                    if ($error == true) {
                        foreach ($created_tables as $ct) {
                            $db->query("DROP TABLE " . $db->prefix($ct));
                        }
                    }
                }
            }
        }
        // if no error, save the module info and blocks info associated with it
        if ($error == false) {
            if (!$module_handler->insert($module)) {
                $errs[] = "<p>" . sprintf(_MD_AM_INSERT_DATA_FAILD, "<strong>" . $module->getVar('name') . "</strong>");
                foreach ($created_tables as $ct) {
                    $db->query("DROP TABLE " . $db->prefix($ct));
                }
                $ret = "<p>" . sprintf(_MD_AM_FAILINS, "<strong>" . $module->name() . "</strong>") . "&nbsp;" . _MD_AM_ERRORSC . "<br />";
                foreach ($errs as $err) {
                    $ret .= " - " . $err . "<br />";
                }
                $ret .= "</p>";
                unset($module);
                unset($created_tables);
                unset($errs);
                unset($msgs);
                return $ret;
            } else {
                $newmid = $module->getVar('mid');
                unset($created_tables);
                $msgs[] = "<p>" . _MD_AM_INSERT_DATA_DONE . sprintf(_MD_AM_MODULEID, "<strong>" . $newmid . "</strong>");
                $tplfile_handler =& xoops_gethandler('tplfile');
                $templates = $module->getInfo('templates');
                if ($templates != false) {
                    $msgs[] = _MD_AM_TEMPLATES_ADD;
                    foreach ($templates as $tpl) {
                        $tplfile =& $tplfile_handler->create();
                        $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']);
                        $tplfile->setVar('tpl_source', $tpldata, true);
                        $tplfile->setVar('tpl_refid', $newmid);
                        $tplfile->setVar('tpl_tplset', 'default');
                        $tplfile->setVar('tpl_file', $tpl['file']);
                        $tplfile->setVar('tpl_desc', $tpl['description'], true);
                        $tplfile->setVar('tpl_module', $dirname);
                        $tplfile->setVar('tpl_lastmodified', time());
                        $tplfile->setVar('tpl_lastimported', 0);
                        $tplfile->setVar('tpl_type', 'module');
                        if (!$tplfile_handler->insert($tplfile)) {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_TEMPLATE_ADD_ERROR, "<strong>" . $tpl['file'] . "</strong>") . "</span>";
                        } else {
                            $newtplid = $tplfile->getVar('tpl_id');
                            $msgs[] = "&nbsp;&nbsp;" . sprintf(_MD_AM_TEMPLATE_ADD_DATA, "<strong>" . $tpl['file'] . "</strong>") . "(ID: <strong>" . $newtplid . "</strong>)";
                            // generate compiled file
                            include_once XOOPS_ROOT_PATH . '/class/template.php';
                            if (!xoops_template_touch($newtplid)) {
                                $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_TEMPLATE_COMPILED_FAILED, "<strong>" . $tpl['file'] . "</strong>") . "</span>";
                            } else {
                                $msgs[] = "&nbsp;&nbsp;" . sprintf(_MD_AM_TEMPLATE_COMPILED, "<strong>" . $tpl['file'] . "</strong>");
                            }
                        }
                        unset($tplfile, $tpldata);
                    }
                }
                include_once XOOPS_ROOT_PATH . '/class/template.php';
                xoops_template_clear_module_cache($newmid);
                $blocks = $module->getInfo('blocks');
                if ($blocks != false) {
                    $msgs[] = _MD_AM_BLOCKS_ADD;
                    foreach ($blocks as $blockkey => $block) {
                        // break the loop if missing block config
                        if (!isset($block['file']) || !isset($block['show_func'])) {
                            break;
                        }
                        $options = '';
                        if (!empty($block['options'])) {
                            $options = trim($block['options']);
                        }
                        $newbid = $db->genId($db->prefix('newblocks') . '_bid_seq');
                        $edit_func = isset($block['edit_func']) ? trim($block['edit_func']) : '';
                        $template = '';
                        if (isset($block['template']) && trim($block['template']) != '') {
                            $content =& xoops_module_gettemplate($dirname, $block['template'], true);
                        }
                        if (empty($content)) {
                            $content = '';
                        } else {
                            $template = trim($block['template']);
                        }
                        $block_name = addslashes(trim($block['name']));
                        $sql = "INSERT INTO " . $db->prefix("newblocks") . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES ({$newbid}, {$newmid}, " . intval($blockkey) . ", '{$options}', '" . $block_name . "','" . $block_name . "', '', 0, 0, 0, 'M', 'H', 1, '" . addslashes($dirname) . "', '" . addslashes(trim($block['file'])) . "', '" . addslashes(trim($block['show_func'])) . "', '" . addslashes($edit_func) . "', '" . $template . "', 0, " . time() . ")";
                        if (!$db->query($sql)) {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_BLOCK_ADD_ERROR, "<strong>" . $block['name'] . "</strong>") . sprintf(_MD_AM_BLOCK_ADD_ERROR_DATABASE, "<strong>" . $db->error() . "</strong>") . "</span>";
                        } else {
                            if (empty($newbid)) {
                                $newbid = $db->getInsertId();
                            }
                            $msgs[] = "&nbsp;&nbsp;" . sprintf(_MD_AM_BLOCK_ADD, "<strong>" . $block['name'] . "</strong>") . sprintf(_MD_AM_BLOCK_ID, "<strong>" . $newbid . "</strong>");
                            $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)';
                            $db->query($sql);
                            if ($template != '') {
                                $tplfile =& $tplfile_handler->create();
                                $tplfile->setVar('tpl_refid', $newbid);
                                $tplfile->setVar('tpl_source', $content, true);
                                $tplfile->setVar('tpl_tplset', 'default');
                                $tplfile->setVar('tpl_file', $block['template']);
                                $tplfile->setVar('tpl_module', $dirname);
                                $tplfile->setVar('tpl_type', 'block');
                                $tplfile->setVar('tpl_desc', $block['description'], true);
                                $tplfile->setVar('tpl_lastimported', 0);
                                $tplfile->setVar('tpl_lastmodified', time());
                                if (!$tplfile_handler->insert($tplfile)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_TEMPLATE_ADD_ERROR, "<strong>" . $block['template'] . "</strong>") . "</span>";
                                } else {
                                    $newtplid = $tplfile->getVar('tpl_id');
                                    $msgs[] = "&nbsp;&nbsp;" . sprintf(_MD_AM_TEMPLATE_ADD_DATA, "<strong>" . $block['template'] . "</strong>") . " (ID: <strong>" . $newtplid . "</strong>)";
                                    // generate compiled file
                                    include_once XOOPS_ROOT_PATH . '/class/template.php';
                                    if (!xoops_template_touch($newtplid)) {
                                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_TEMPLATE_COMPILED_FAILED, "<strong>" . $block['template'] . "</strong>") . "</span>";
                                    } else {
                                        $msgs[] = "&nbsp;&nbsp;" . sprintf(_MD_AM_TEMPLATE_COMPILED, "<strong>" . $block['template'] . "</strong>");
                                    }
                                }
                                unset($tplfile);
                            }
                        }
                        unset($content);
                    }
                    unset($blocks);
                }
                $configs = $module->getInfo('config');
                if ($configs != false) {
                    if ($module->getVar('hascomments') != 0) {
                        include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
                        array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)));
                        array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0));
                    }
                } else {
                    if ($module->getVar('hascomments') != 0) {
                        $configs = array();
                        include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
                        $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN));
                        $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0);
                    }
                }
                // RMV-NOTIFY
                if ($module->getVar('hasnotification') != 0) {
                    if (empty($configs)) {
                        $configs = array();
                    }
                    // Main notification options
                    include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
                    include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
                    $options = array();
                    $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE;
                    $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK;
                    $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
                    $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH;
                    $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options);
                    // Event-specific notification options
                    // FIXME: doesn't work when update module... can't read back the array of options properly...  " changing to &quot;
                    $options = array();
                    $categories =& notificationCategoryInfo('', $module->getVar('mid'));
                    foreach ($categories as $category) {
                        $events =& notificationEvents($category['name'], false, $module->getVar('mid'));
                        foreach ($events as $event) {
                            if (!empty($event['invisible'])) {
                                continue;
                            }
                            $option_name = $category['title'] . ' : ' . $event['title'];
                            $option_value = $category['name'] . '-' . $event['name'];
                            $options[$option_name] = $option_value;
                        }
                        unset($events);
                    }
                    unset($categories);
                    $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options);
                }
                if ($configs != false) {
                    $msgs[] = _MD_AM_MODULE_DATA_ADD;
                    $config_handler =& xoops_gethandler('config');
                    $order = 0;
                    foreach ($configs as $config) {
                        $confobj =& $config_handler->createConfig();
                        $confobj->setVar('conf_modid', $newmid);
                        $confobj->setVar('conf_catid', 0);
                        $confobj->setVar('conf_name', $config['name']);
                        $confobj->setVar('conf_title', $config['title'], true);
                        $confobj->setVar('conf_desc', $config['description'], true);
                        $confobj->setVar('conf_formtype', $config['formtype']);
                        $confobj->setVar('conf_valuetype', $config['valuetype']);
                        $confobj->setConfValueForInput($config['default'], true);
                        $confobj->setVar('conf_order', $order);
                        $confop_msgs = '';
                        if (isset($config['options']) && is_array($config['options'])) {
                            foreach ($config['options'] as $key => $value) {
                                $confop =& $config_handler->createConfigOption();
                                $confop->setVar('confop_name', $key, true);
                                $confop->setVar('confop_value', $value, true);
                                $confobj->setConfOptions($confop);
                                $confop_msgs .= '<br />&nbsp;&nbsp;&nbsp;&nbsp; ' . _MD_AM_CONFIG_ADD . _MD_AM_NAME . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . _MD_AM_VALUE . ' <strong>' . $value . '</strong> ';
                                unset($confop);
                            }
                        }
                        $order++;
                        if ($config_handler->insertConfig($confobj) != false) {
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_MD_AM_CONFIG_DATA_ADD, "<strong>" . $config['name'] . "</strong>") . $confop_msgs;
                        } else {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_CONFIG_DATA_ADD_ERROR, "<strong>" . $config['name'] . "</strong>") . "</span>";
                        }
                        unset($confobj);
                    }
                    unset($configs);
                }
            }
            if ($module->getInfo('hasMain')) {
                $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS);
            } else {
                $groups = array(XOOPS_GROUP_ADMIN);
            }
            // retrieve all block ids for this module
            $blocks = XoopsBlock::getByModule($newmid, false);
            $msgs[] = _MD_AM_GROUP_SETTINGS_ADD;
            $gperm_handler =& xoops_gethandler('groupperm');
            foreach ($groups as $mygroup) {
                if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) {
                    $mperm =& $gperm_handler->create();
                    $mperm->setVar('gperm_groupid', $mygroup);
                    $mperm->setVar('gperm_itemid', $newmid);
                    $mperm->setVar('gperm_name', 'module_admin');
                    $mperm->setVar('gperm_modid', 1);
                    if (!$gperm_handler->insert($mperm)) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_ACCESS_ADMIN_ADD_ERROR, "<strong>" . $mygroup . "</strong>") . "</span>";
                    } else {
                        $msgs[] = "&nbsp;&nbsp;" . sprintf(_MD_AM_ACCESS_ADMIN_ADD, "<strong>" . $mygroup . "</strong>");
                    }
                    unset($mperm);
                }
                $mperm =& $gperm_handler->create();
                $mperm->setVar('gperm_groupid', $mygroup);
                $mperm->setVar('gperm_itemid', $newmid);
                $mperm->setVar('gperm_name', 'module_read');
                $mperm->setVar('gperm_modid', 1);
                if (!$gperm_handler->insert($mperm)) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_MD_AM_ACCESS_USER_ADD_ERROR, "<strong>" . $mygroup . "</strong>") . "</span>";
                } else {
                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_MD_AM_ACCESS_USER_ADD_ERROR, "<strong>" . $mygroup . "</strong>");
                }
                unset($mperm);
                foreach ($blocks as $blc) {
                    $bperm =& $gperm_handler->create();
                    $bperm->setVar('gperm_groupid', $mygroup);
                    $bperm->setVar('gperm_itemid', $blc);
                    $bperm->setVar('gperm_name', 'block_read');
                    $bperm->setVar('gperm_modid', 1);
                    if (!$gperm_handler->insert($bperm)) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_BLOCK_ACCESS_ERROR . ' Block ID: <strong>' . $blc . '</strong> Group ID: <strong>' . $mygroup . '</strong></span>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;' . _MD_AM_BLOCK_ACCESS . sprintf(_MD_AM_BLOCK_ID, "<strong>" . $blc . "</strong>") . sprintf(_MD_AM_GROUP_ID, "<strong>" . $mygroup . "</strong>");
                    }
                    unset($bperm);
                }
            }
            unset($blocks);
            unset($groups);
            // execute module specific install script if any
            $func = "xoops_module_install_{$dirname}";
            if (function_exists($func)) {
                if (!($lastmsg = $func($module))) {
                    $msgs[] = "<p>" . sprintf(_MD_AM_FAILED_EXECUTE, $func) . "</p>";
                } else {
                    $msgs[] = "<p>" . sprintf(_MD_AM_FAILED_SUCESS, "<strong>{$func}</strong>") . "</p>";
                    if (is_string($lastmsg)) {
                        $msgs[] = $lastmsg;
                    }
                }
            }
            $ret = '<div>' . implode("<br />", $msgs) . '</div><br />' . sprintf(_MD_AM_OKINS, "<strong>" . $module->getVar('name') . "</strong>");
            unset($msgs);
            unset($errs);
            unset($module);
            return $ret;
        } else {
            $ret = '<p>' . sprintf(_MD_AM_FAILINS, '<strong>' . $dirname . '</strong>') . '&nbsp;' . _MD_AM_ERRORSC . '<br />' . implode("<br />", $errs) . '</p>';
            unset($msgs);
            unset($errs);
            return $ret;
        }
    } else {
        return "<p>" . sprintf(_MD_AM_FAILINS, "<strong>" . $dirname . "</strong>") . "&nbsp;" . _MD_AM_ERRORSC . "<br />&nbsp;&nbsp;" . sprintf(_MD_AM_ALEXISTS, $dirname) . "</p>";
    }
}
コード例 #29
0
ファイル: main.php プロジェクト: BackupTheBerlios/xoops4-svn
             } else {
                 $tpl =& $tpltpl_handler->get($old_template[$upload_file]);
             }
             $tpl->setVar('tpl_lastmodified', time());
             $fp = @fopen($uploader->getSavedDestination(), 'r');
             $fsource = @fread($fp, filesize($uploader->getSavedDestination()));
             @fclose($fp);
             $tpl->setVar('tpl_source', $fsource, true);
             @unlink($uploader->getSavedDestination());
             if (!$tpltpl_handler->insert($tpl)) {
                 $msg[] = 'Failed inserting data for ' . $upload_file . ' to database';
             } else {
                 $msg[] = 'Template file <b>' . $upload_file . '</b> updated.';
                 if ($tplset == $xoopsConfig['template_set']) {
                     include_once XOOPS_ROOT_PATH . '/class/template.php';
                     if (xoops_template_touch($tpl->getVar('tpl_id'), true)) {
                         $msg[] = 'Template file <b>' . $upload_file . '</b> compiled.';
                     }
                 }
             }
         }
     } else {
         if ($uploader->getMediaName() == '') {
             continue;
         } else {
             $msg[] = $uploader->getErrors();
         }
     }
 }
 xoops_cp_header();
 echo '<code>';
コード例 #30
0
ファイル: onupdate.php プロジェクト: hmoritake/xelfinder
    function xelfinder_onupdate_base($module, $mydirname)
    {
        // transations on module update
        global $msgs;
        // TODO :-D
        // for Cube 2.1
        if (defined('XOOPS_CUBE_LEGACY')) {
            $root =& XCube_Root::getSingleton();
            $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'xelfinder_message_append_onupdate');
            $msgs = array();
        } else {
            if (!is_array($msgs)) {
                $msgs = array();
            }
        }
        $db =& Database::getInstance();
        $mid = $module->getVar('mid');
        // TABLES (write here ALTER TABLE etc. if necessary)
        $query = "SELECT `gids` FROM " . $db->prefix($mydirname . "_file");
        if (!$db->query($query)) {
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD `gids` VARCHAR( 255 ) NOT NULL');
        }
        // check last update version
        $cache_dir = (defined('XOOPS_MODULE_PATH') ? XOOPS_MODULE_PATH : XOOPS_ROOT_PATH . '/modules') . '/' . $mydirname . '/cache';
        $lastupdate = 0;
        if (file_exists($cache_dir . '/lastupdate.dat')) {
            $lastupdate = @unserialize(file_get_contents($cache_dir . '/lastupdate.dat'));
        }
        if (!is_numeric($lastupdate)) {
            $lastupdate = 0;
        }
        file_put_contents($cache_dir . '/lastupdate.dat', serialize($module->getVar('version')));
        // from v 0.10
        if ($lastupdate < 10) {
            $query = "SELECT `mime_filter` FROM " . $db->prefix($mydirname . "_file");
            if (!$db->query($query)) {
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD `mime_filter` VARCHAR( 255 ) NOT NULL');
            }
        }
        // from v 0.13
        if ($lastupdate < 13) {
            $query = "SHOW COLUMNS FROM `" . $db->prefix($mydirname . "_file") . "` LIKE 'mime'";
            $res = $db->query($query);
            $dat = $db->fetchArray($res);
            if ($dat['Type'] !== 'varchar(255)') {
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `mime` `mime` varchar(255) NOT NULL DEFAULT \'unknown\'');
            }
        }
        // from v 0.17
        if ($lastupdate < 17) {
            $query = "SELECT `id` FROM " . $db->prefix($mydirname . "_userdat");
            if (!$db->query($query)) {
                $db->queryF('CREATE TABLE `' . $db->prefix($mydirname . '_userdat') . '`' . '(
				  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
				  `uid` int(10) unsigned NOT NULL,
				  `key` varchar(255) NOT NULL,
				  `data` blob NOT NULL,
				  `mtime` int(10) unsigned NOT NULL,
				  PRIMARY KEY (`id`),
				  KEY `uid_key` (`uid`,`key`)
				) ENGINE=MyISAM');
            }
        }
        //from v0.22
        if ($lastupdate < 22) {
            $query = "SELECT `local_path` FROM " . $db->prefix($mydirname . "_file");
            if (!$db->query($query)) {
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD `local_path` VARCHAR( 255 ) NOT NULL');
            }
        }
        //from v0.66 add default value for strict mode
        if ($lastupdate < 66) {
            $query = "SHOW COLUMNS FROM `" . $db->prefix($mydirname . "_file") . "` LIKE 'parent_id'";
            $res = $db->query($query);
            $dat = $db->fetchArray($res);
            if ($dat['Default'] === NULL) {
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `parent_id` `parent_id` INT( 10 ) UNSIGNED NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `name` `name` varchar(255) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `size` `size` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `ctime` `ctime` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `mtime` `mtime` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `perm` `perm` varchar(3) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `uid` `uid` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `gid` `gid` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `home_of` `home_of` int(10) DEFAULT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `width` `width` int(11) NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `height` `height` int(11) NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `gids` `gids` varchar(255) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `mime_filter` `mime_filter` varchar(255) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `local_path` `local_path` varchar(255) NOT NULL DEFAULT \'\'');
                // link
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_link") . '` CHANGE `file_id` `file_id` int(11) NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_link") . '` CHANGE `mid` `mid` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_link") . '` CHANGE `param` `param` varchar(25) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_link") . '` CHANGE `val` `val` varchar(25) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_link") . '` CHANGE `title` `title` varchar(255) NOT NULL DEFAULT \'\'');
                // userdat
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_userdat") . '` CHANGE `uid` `uid` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_userdat") . '` CHANGE `key` `key` varchar(255) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_userdat") . '` CHANGE `mtime` `mtime` int(10) unsigned NOT NULL DEFAULT \'0\'');
            }
        }
        // for version < 0.99 remove unless tmb file
        if ($lastupdate < 99) {
            $msgs[] = 'checking unless tmbs (Version < 0.99)';
            $tmbdir = $cache_dir . '/tmb';
            $_res = false;
            if ($handle = opendir($tmbdir)) {
                while (false !== ($entry = readdir($handle))) {
                    if (preg_match('/^[a-zA-Z]{1,2}[0-9]{1,3}_.+\\.png$/', $entry)) {
                        //$msgs[] = $tmbdir.'/'.$entry;
                        $_res = @unlink($tmbdir . '/' . $entry);
                    }
                }
            }
            if ($_res) {
                $msgs[] = 'removed unless tmbs';
            }
        }
        if ($lastupdate < 166) {
            $msgs[] = 'ALTER TABLE file `home_of` and fix data (Version < 1.66)';
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `home_of` `home_of` INT(10) NULL DEFAULT NULL');
            $db->queryF('UPDATE `' . $db->prefix($mydirname . "_file") . '` SET `home_of` = NULL WHERE `home_of` = 0 AND `mime` != \'directory\'');
        }
        if ($lastupdate < 182) {
            $msgs[] = 'ALTER TABLE file `home_of` Add Index (Version < 1.82)';
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD INDEX home_of( home_of )');
        }
        // TEMPLATES (all templates have been already removed by modulesadmin)
        $tplfile_handler =& xoops_gethandler('tplfile');
        $tpl_path = dirname(__FILE__) . '/templates';
        if ($handler = @opendir($tpl_path . '/')) {
            while (($file = readdir($handler)) !== false) {
                if (substr($file, 0, 1) == '.') {
                    continue;
                }
                $file_path = $tpl_path . '/' . $file;
                if (is_file($file_path)) {
                    $mtime = intval(@filemtime($file_path));
                    $tplfile =& $tplfile_handler->create();
                    $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                    $tplfile->setVar('tpl_refid', $mid);
                    $tplfile->setVar('tpl_tplset', 'default');
                    $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                    $tplfile->setVar('tpl_desc', '', true);
                    $tplfile->setVar('tpl_module', $mydirname);
                    $tplfile->setVar('tpl_lastmodified', $mtime);
                    $tplfile->setVar('tpl_lastimported', 0);
                    $tplfile->setVar('tpl_type', 'module');
                    if (!$tplfile_handler->insert($tplfile)) {
                        $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> to the database.</span>';
                    } else {
                        $tplid = $tplfile->getVar('tpl_id');
                        $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                        // generate compiled file
                        include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                        include_once XOOPS_ROOT_PATH . '/class/template.php';
                        if (!xoops_template_touch($tplid)) {
                            $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b>.</span>';
                        } else {
                            $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> compiled.</span>';
                        }
                    }
                }
            }
            closedir($handler);
        }
        include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
        include_once XOOPS_ROOT_PATH . '/class/template.php';
        xoops_template_clear_module_cache($mid);
        return true;
    }