0, 'version' => $infos['version'], 'title' => $infos['title'], 'installable' => 0, 'installed_version' => 0, 'depends' => $infos['depends'], 'desc' => $infos['desc'], 'author' => $infos['author']); if ( is_file($ddname."/".$file."/install.php") ) { $onfs[$file]['installable'] = 1; } } else { //print "trash directory, not a plugin."; } } else { //print "not a director, skipping"; } } } else { die ("error"); } closedir($plugins_dir); $ondb = array(); global $kdb; $ret = $kdb->query("SELECT * FROM plugins"); while ( ($res = mysql_fetch_array($ret) ) ) { foreach ($onfs as $key => $fs) { if ( $fs[0] == $res['pluginID'] ) { $onfs[$key]['installed'] = $res['installed']; $onfs[$key]['installed_version'] = $res['version']; } } } mysql_free_result($ret); return $onfs; } $plugins = list_plugins(); function is_installed($plid) { $plugins = list_plugins(); if ( !array_key_exists($plid, $plugins) ) { return false; } return $plugins[$plid]['installed']; } function is_available($plid) { if ( !array_key_exists($plid, list_plugins()) ) { return false; } $plugs = list_plugins(); return $plugs[$plid]['installable']; } function get_plugin($plid) { //global $plugins; $plugins = list_plugins(); return $plugins[$plid]; } if ( isset($_GET['plugins']) ) { $onfs = $plugins; print '

List of plugins

'; print ''; foreach ($onfs as $p) { print ''; print ''; // title print ''; print ''; print ''; if ( $p['installed'] ) { print ''; } else { print ''; } if ( $p['installed'] != 1 && $p['installable'] ) { print ''; } else if ( $p['installable']) { print ''; } else { print ""; } print ''; print ""; } print ''; print ''; print ''; print '
'.$p['title'].''.$p['desc'].''.$p['author'].''.$p['version'].''.$p['installed_version'].'INSTALLUNINSTALL'; print $p['depends']; print '
'; print 'Uninstall all'; print ' '; print 'Install all'; print '
'; } function _stringify($ar) { $res = ""; if ( is_array($ar) ) { foreach ( $ar as $rl ) { if ( strlen($res) > 0 ) $res .= ","; $res .= $rl; } } else { $res = $ar; } return $res; } function install_plugin($plid) { global $kdb; // create admin user if (!$kdb->query("SELECT * FROM users WHERE uname='".ADMIN_USERNAME."' ")) { $kdb->query("INSERT INTO users (uname, pwd, roles, approved) VALUES('".ADMIN_USERNAME."', '".ADMIN_PASSWORD."', '111111', True)"); $nui = mysql_insert_id(); $kdb->query("INSERT INTO userinfo (userid, firstname, lastname, email, language, sex, homepage) VALUES (".$nui.",'Krihvel', 'Admin', '', '".DEFAULT_LANGUAGE."', 'boy', '' )"); } $plug = get_plugin($plid); if ( $plug['installed'] ) { return 0; } $ddname = dirname(dirname(__FILE__))."/plugins/".$plid; if ( !is_file($ddname."/install.php") ) { return 0; } include_once($ddname.'/install.php'); $res = call_user_func('install_'.$plid); if ( $res ) { $sql = "INSERT INTO plugins VALUES ('".$plid."', 1, '".$plug['version']."')"; $kdb->query($sql); } $plugins_dir = opendir( $ddname); while (($file = readdir( $plugins_dir ) ) !== false ) { if ( substr($file, 0, 1) == '.' ){ continue; } if ( !strcmp($file, "install.php") ) { continue; } if ( !strcmp(substr($file, -4), ".php") ) { require_once($ddname.'/'.$file); $clname = substr($file, 0, -4); if ( class_exists($clname) ) { $reflection = new ReflectionAnnotatedClass($clname); $is_page = false; $is_ct = false; if ( $reflection->hasAnnotation('Page') || $reflection->hasAnnotation('ContentType') ) { if ( $reflection->hasAnnotation('Page') ) { $is_page = true; $ann = $reflection->getAnnotation('Page'); $rles = _stringify($ann->roles); $sql = "INSERT INTO pages VALUES ( '".$plid."', '".$clname."', '".$ann->title."', '".$ann->group."', '".$rles."', '".$ann->valid."' )"; $kdb->query($sql); } if ( $reflection->hasAnnotation('ContentType') ) { $is_ct = true; $ann = $reflection->getAnnotation('ContentType'); $sql = "INSERT INTO types VALUES ( '".$plid."', '".$clname."', '".$ann->title."', '".$ann->icon."', '".$ann->icon_method."', '".$ann->task."', '".$ann->type."' )"; $kdb->query($sql); } foreach ($reflection->getAllAnnotations('MenuItem') as $mi) { $mrmenu = $mi->menu; if ( !$mrmenu ) { $mrmenu = "leftmenu"; } $sql = "INSERT INTO menus VALUES ( '".$plid."', '".$clname."', '".$mi->title."', '".$mi->group."', '".$mi->page."', '".$mrmenu."', '"._stringify($mi->roles)."', '"._stringify($mi->valid)."' )"; $kdb->query($sql); } foreach ( $reflection->getMethods() as $m ) { if ( $m->hasAnnotation('MenuItem') ) { $mr = $m->getAnnotation('MenuItem'); $mpage = $mr->page; if ( !$mpage ) { if ( $is_ct ) { $mpage = "&mode=".substr($m->getName(), 0, -7); } else { $mpage = "?pid=".$clname."&mode=".substr($m->getName(), 0, -7); } } $mrmenu = $mr->menu; if ( !$mrmenu ) { $mrmenu = "leftmenu"; } $sql = "INSERT INTO menus VALUES ( '".$plid."', '".$clname."', '".$mr->title."', '".$mr->group."', '".$mpage."', '".$mrmenu."', '"._stringify($mr->roles)."', '"._stringify($mr->valid)."' )"; $kdb->query($sql); } } } else { // not a valid class } } } } return $res; } function _do_install($pid) { $plug = get_plugin($pid); $deps = split(",", $plug['depends']); $allok = true; foreach( $deps as $dep ) { if ( strlen(trim($dep)) == 0 ) { continue; } if ( !is_installed(trim($dep)) ) { //print "installing...".$dep."
"; if ( is_available(trim($dep))) { $depres = install_plugin(trim($dep)); if ( !$depres ) { $allok = false; } } else { $allok = false; //print "... but dep not available"; } } } if ( $allok ) { //print "
ok, installing"; $plres = install_plugin($pid); if ( $plres ) { //print "success"; } else { //print "failure"; } } else { //print "
failed to install dependencies"; } } if ( isset($_GET['action']) && $_GET['action'] == 'install' && isset($_GET['pluginid']) ) { $pid = $_GET['pluginid']; _do_install($pid); header('Location: index.php?plugins=1'); } function _do_uninstall($pid) { global $kdb; if ( is_file('../plugins/'.$pid.'/install.php') ) { require_once('../plugins/'.$pid.'/install.php'); $res = call_user_func('uninstall_'.$pid); } $sql = "DELETE FROM plugins where pluginID='".$pid."'"; $kdb->query($sql); } if ( isset($_GET['action']) && $_GET['action'] == 'uninstall' && isset($_GET['pluginid']) ) { $pid = $_GET['pluginid']; _do_uninstall($pid); header('Location: index.php?plugins=1'); } if ( isset($_GET['action']) && $_GET['action'] == 'uninstall_all' ) { foreach ( $plugins as $plugid => $plug ) { if ( $plug['installed'] ) { _do_uninstall($plugid); } } header('Location: index.php?plugins=1'); } if ( isset($_GET['action']) && $_GET['action'] == 'install_all' ) { $c = 0; ob_start(); while (1) { $c++; $found = false; $mstr = ""; foreach ( list_plugins() as $plugid => $plug ) { if ( !$plug['installed'] && $plug['installable']) { try { _do_install($plugid); } catch (Exception $e) { // silently ignore errors. } $mstr = $plugid; $found = true; } } if (!$found) { break; } if ( $c > 1000 ) { break; } } ob_end_clean(); header('Location: index.php?plugins=1'); } ?>