Exemplo n.º 1
0
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
if (!isset($ini)) {
    require_once __DIR__ . '/../Ini.php';
    $ini = new Ini();
}
$path = Ini::$path_data . session_id() . ".Rc";
$sql = sprintf("TRUNCATE TABLE `%s`.`%s`", Ini::$db_master_name, RDoc::get_mysql_table());
mysql_query($sql);
$sql = sprintf("TRUNCATE TABLE `%s`.`%s`", Ini::$db_master_name, RDocLibrary::get_mysql_table());
mysql_query($sql);
$sql = sprintf("TRUNCATE TABLE `%s`.`%s`", Ini::$db_master_name, RDocFunction::get_mysql_table());
mysql_query($sql);
include __DIR__ . "/../SETTINGS.php";
$code = "\r\n        library(RMySQL)\r\n        library(tools)\r\n        unlink('{$path}')\r\n        drv <- dbDriver('MySQL')\r\n        con <- dbConnect(drv, user = '******', password = '******', dbname = '{$db_master_name}', host = '{$db_host}', port = {$db_port}, client.flag=CLIENT_MULTI_STATEMENTS)\r\n        dbSendQuery(con,statement = 'SET NAMES \"utf8\";')\r\n        dbSendQuery(con,statement = 'SET time_zone=\"{$mysql_timezone}\";')\r\n            \r\n        adm <- c()\r\n        for(package in sort(.packages(T))){\r\n\r\n            dbSendQuery(con,paste('INSERT INTO `RDocLibrary` SET `name`=\"',package,'\" ; SELECT last_insert_id();',sep=''))\r\n            rs1 <- dbNextResult(con)\r\n            lid <- fetch(rs1, n=-1)[1,1]\r\n            library(package,character.only=T)\r\n            db <- Rd_db(package)\r\n\r\n            for(doc in db){\r\n                fileConn<-file('{$path}',open='a+')\r\n                tools::Rd2HTML(doc,out=fileConn)\r\n                HTML <- dbEscapeStrings(con,paste(readLines(fileConn),collapse='\n'))\r\n                dbSendQuery(con,paste('INSERT INTO `RDoc` SET `HTML`=\"',HTML,'\"; SELECT last_insert_id();',sep=''))\r\n                rs2 <- dbNextResult(con)\r\n                did <- fetch(rs2, n=-1)[1,1]\r\n                unlink('{$path}')\r\n\r\n                aliases <- tools:::.Rd_get_metadata(x=doc,kind='alias')\r\n                sql <- 'INSERT INTO `RDocFunction` (`name`,`RDocLibrary_id`,`RDoc_id`) VALUES '\r\n                first <- T\r\n                insert <- F\r\n                for(alias in aliases) {\r\n                    if(!grepl('^[a-zA-Z0-9_.]*\$',alias,perl=T) || alias %in% adm || !exists(alias) || !is.function(get(alias))){\r\n                        next\r\n                    }\r\n                    adm <- c(adm,alias)\r\n                    if(!first) {\r\n                        sql <- paste(sql,',',sep='')\r\n                    }\r\n                    alias <- dbEscapeStrings(con,alias)\r\n                    sql <- paste(sql,'(\"',alias,'\", \"',lid,'\", \"',did,'\") ',sep='')\r\n                    first <- F\r\n                    insert <- T\r\n                }\r\n                if(insert){\r\n                    dbSendQuery(con,sql)\r\n                }\r\n            }\r\n        }\r\n        ";
$fh = fopen($path, "w");
fwrite($fh, $code);
fclose($fh);
$rscript_path = Ini::$path_r_script;
`{$rscript_path} {$path}`;
if (file_exists($path)) {
    unlink($path);
}
Exemplo n.º 2
0
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; version 2
 of the License, and not any of the later versions.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
if (!isset($ini)) {
    require_once '../../Ini.php';
    $ini = new Ini();
}
$logged_user = User::get_logged_user();
if ($logged_user == null) {
    echo json_encode(array());
    exit;
}
$result = array();
$result['functions'] = array();
$sql = "SELECT \r\n    `" . Ini::$db_master_name . "`.`" . RDocFunction::get_mysql_table() . "`.`name`, \r\n        `" . Ini::$db_master_name . "`.`" . RDocLibrary::get_mysql_table() . "`.`name`, \r\n            `" . Ini::$db_master_name . "`.`" . RDocFunction::get_mysql_table() . "`.`id` \r\n    FROM `" . Ini::$db_master_name . "`.`" . RDocFunction::get_mysql_table() . "` \r\n    LEFT JOIN `" . Ini::$db_master_name . "`.`" . RDocLibrary::get_mysql_table() . "` ON `" . Ini::$db_master_name . "`.`" . RDocLibrary::get_mysql_table() . "`.`id` = `" . Ini::$db_master_name . "`.`" . RDocFunction::get_mysql_table() . "`.`RDocLibrary_id`\r\n    WHERE `" . Ini::$db_master_name . "`.`" . RDocFunction::get_mysql_table() . "`.`name` LIKE '" . $_POST['string'] . "%' \r\n    ORDER BY `" . Ini::$db_master_name . "`.`" . RDocFunction::get_mysql_table() . "`.`name` ASC";
$z = mysql_query($sql);
while ($r = mysql_fetch_array($z)) {
    array_push($result['functions'], array("id" => $r[2], "name" => $r[0], "pack" => $r[1]));
}
echo json_encode($result);