Esempio n. 1
0
function getSQLByFileName($filename)
{
    global $dbn, $botmaster_name, $dbh;
    $curPath = dirname(__FILE__);
    chdir($curPath);
    $dbFilename = $filename;
    $filename = str_ireplace('.aiml', '.sql', $filename);
    // change to sql extension for clarity
    $categoryTemplate = "    ([id],[bot_id],'[aiml]','[pattern]','[thatpattern]','[template]','[topic]','[filename]','[php_code]'),";
    $dbconn = db_open();
    $phpVer = phpversion();
    $cleanedFilename = mysql_real_escape_string($dbFilename, $dbconn);
    # Get all topics within the file
    $topicArray = array();
    $sql = "select * from aiml where filename like '{$cleanedFilename}' order by id asc;";
    $fileContent = file_get_contents('SQL_Header.dat');
    $fileContent = str_replace('[botmaster_name]', $botmaster_name, $fileContent);
    $fileContent = str_replace('[host]', $dbh, $fileContent);
    $fileContent = str_replace('[dbn]', $dbn, $fileContent);
    $fileContent = str_replace('[sql]', $sql, $fileContent);
    $fileContent = str_replace('[phpVer]', $phpVer, $fileContent);
    $curDate = date('m-d-Y h:j:s A', time());
    $fileContent = str_replace('[curDate]', $curDate, $fileContent);
    $fileContent = str_replace('[fileName]', $cleanedFilename, $fileContent);
    $result = mysql_query($sql, $dbconn) or die(mysql_error());
    while ($row = mysql_fetch_assoc($result)) {
        $aiml = str_replace("\r\n", '', $row['aiml']);
        $aiml = str_replace("\n", '', $aiml);
        $aiml = mysql_real_escape_string($aiml, $dbconn);
        $template = str_replace("\r\n", '', $row['template']);
        $template = str_replace("\n", '', $template);
        $template = mysql_real_escape_string($template, $dbconn);
        $newLine = str_replace('[id]', $row['id'], $categoryTemplate);
        $newLine = str_replace('[bot_id]', $row['bot_id'], $newLine);
        $newLine = str_replace('[aiml]', $aiml, $newLine);
        $newLine = str_replace('[pattern]', $row['pattern'], $newLine);
        $newLine = str_replace('[thatpattern]', $row['thatpattern'], $newLine);
        $newLine = str_replace('[template]', $template, $newLine);
        $newLine = str_replace('[topic]', $row['topic'], $newLine);
        $newLine = str_replace('[filename]', $row['filename'], $newLine);
        $newLine = str_replace('[php_code]', $row['php_code'], $newLine);
        $fileContent .= "{$newLine}\r\n";
    }
    $fileContent = trim($fileContent, ",\r\n");
    // remove the comma from the last row
    $fileContent .= "\n";
    $x = file_put_contents("./downloads/{$filename}", trim($fileContent));
    mysql_close($dbconn);
    $msg = "Your file, <strong>{$filename}</strong>, is being prepaired. If it doesn't start, please <a href=\"file.php?file={$filename}&send_file=yes\">Click Here</a>.<br />\n";
    return serveFile($filename, $msg);
}
Esempio n. 2
0
/**
 * Function getSQLByFileName
 *
 * * @param $filename
 * @return string
 */
function getSQLByFileName($filename)
{
    global $dbn, $botmaster_name, $dbh, $dbConn;
    $curPath = dirname(__FILE__);
    chdir($curPath);
    $dbFilename = $filename;
    $filename = str_ireplace('.aiml', '.sql', $filename);
    $categoryTemplate = "    ([id],[bot_id],'[aiml]','[pattern]','[thatpattern]','[template]','[topic]','[filename]'),";
    $phpVer = phpversion();
    $cleanedFilename = $dbFilename;
    $topicArray = array();
    $sql = "select * from aiml where filename like '{$cleanedFilename}' order by id asc;";
    $fileContent = file_get_contents('SQL_Header.dat');
    $fileContent = str_replace('[botmaster_name]', $botmaster_name, $fileContent);
    $fileContent = str_replace('[host]', $dbh, $fileContent);
    $fileContent = str_replace('[dbn]', $dbn, $fileContent);
    $fileContent = str_replace('[sql]', $sql, $fileContent);
    $fileContent = str_replace('[phpVer]', $phpVer, $fileContent);
    $curDate = date('m-d-Y h:j:s A', time());
    $fileContent = str_replace('[curDate]', $curDate, $fileContent);
    $fileContent = str_replace('[fileName]', $cleanedFilename, $fileContent);
    $sth = $dbConn->prepare($sql);
    $sth->execute();
    $result = $sth->fetchAll();
    foreach ($result as $row) {
        $aiml = str_replace("\r\n", '', $row['aiml']);
        $aiml = str_replace("\n", '', $aiml);
        $template = str_replace("\r\n", '', $row['template']);
        $template = str_replace("\n", '', $template);
        $newLine = str_replace('[id]', $row['id'], $categoryTemplate);
        $newLine = str_replace('[bot_id]', $row['bot_id'], $newLine);
        $newLine = str_replace('[aiml]', $aiml, $newLine);
        $newLine = str_replace('[pattern]', $row['pattern'], $newLine);
        $newLine = str_replace('[thatpattern]', $row['thatpattern'], $newLine);
        $newLine = str_replace('[template]', $template, $newLine);
        $newLine = str_replace('[topic]', $row['topic'], $newLine);
        $newLine = str_replace('[filename]', $row['filename'], $newLine);
        $fileContent .= "{$newLine}\r\n";
    }
    $fileContent = trim($fileContent, ",\r\n");
    $fileContent .= "\n";
    $x = file_put_contents("./downloads/{$filename}", trim($fileContent));
    $msg = "Your file, <strong>{$filename}</strong>, is being prepaired. If it doesn't start, please <a href=\"file.php?file={$filename}&send_file=yes\">Click Here</a>.<br />\n";
    return serveFile($filename, $msg);
}
Esempio n. 3
0
function renderImage($data)
{
    $hash = $data['hash'];
    if ($data['changecode']) {
        $changecode = $data['changecode'];
        unset($data['changecode']);
    }
    $pm = new PictshareModel();
    $base_path = ROOT . DS . 'upload' . DS . $hash . DS;
    $path = $base_path . $hash;
    $type = $pm->isTypeAllowed($pm->getTypeOfFile($path));
    $cached = false;
    $cachename = $pm->getCacheName($data);
    $cachepath = $base_path . $cachename;
    if (file_exists($cachepath)) {
        $path = $cachepath;
        $cached = true;
    } else {
        if (MAX_RESIZED_IMAGES > -1 && $pm->countResizedImages($hash) > MAX_RESIZED_IMAGES) {
            //if the number of max resized images is reached, just show the real one
            $path = ROOT . DS . 'upload' . DS . $hash . DS . $hash;
        }
    }
    switch ($type) {
        case 'jpg':
            header("Content-type: image/jpeg");
            $im = imagecreatefromjpeg($path);
            if (!$cached) {
                if ($pm->changeCodeExists($changecode)) {
                    changeImage($im, $data);
                    imagejpeg($im, $cachepath, 95);
                }
            }
            imagejpeg($im);
            break;
        case 'png':
            header("Content-type: image/png");
            $im = imagecreatefrompng($path);
            if (!$cached) {
                if ($pm->changeCodeExists($changecode)) {
                    changeImage($im, $data);
                    imagepng($im, $cachepath, 1);
                }
            }
            imageAlphaBlending($im, true);
            imageSaveAlpha($im, true);
            imagepng($im);
            break;
        case 'gif':
            if ($data['mp4'] || $data['webm']) {
                $gifpath = $path;
                $mp4path = $base_path . 'mp4_1.' . $hash;
                //workaround.. find a better solution!
                $webmpath = $base_path . 'webm_1.' . $hash;
                if (!file_exists($mp4path) && !$data['preview']) {
                    //if mp4 does not exist, create it
                    $pm->gifToMP4($gifpath, $mp4path);
                }
                if (!file_exists($webmpath) && $data['webm'] && !$data['preview']) {
                    $pm->saveAsWebm($gifpath, $webmpath);
                }
                if ($data['raw']) {
                    if ($data['webm']) {
                        serveFile($webmpath, $hash . '.webm', 'video/webm');
                    } else {
                        serveFile($mp4path, $hash . '.mp4', 'video/mp4');
                    }
                } else {
                    if ($data['preview']) {
                        $file = $mp4path;
                        if (!file_exists($cachepath)) {
                            $pm->saveFirstFrameOfMP4($mp4path, $cachepath);
                        }
                        header("Content-type: image/jpeg");
                        readfile($cachepath);
                    } else {
                        renderMP4($mp4path, $data);
                    }
                }
            } else {
                if (!$cached && $data['size']) {
                    $pm->resizeFFMPEG($data, $cachepath, 'gif');
                }
                header("Content-type: image/gif");
                if (file_exists($cachepath)) {
                    readfile($cachepath);
                } else {
                    readfile($path);
                }
            }
            break;
        case 'mp4':
            if (!$cached && !$data['preview']) {
                $pm->resizeFFMPEG($data, $cachepath, 'mp4');
                $path = $cachepath;
            }
            if (file_exists($cachepath) && filesize($cachepath) == 0) {
                //if there was an error and the file is 0 bytes, use the original
                $cachepath = ROOT . DS . 'upload' . DS . $hash . DS . $hash;
            }
            if ($data['webm']) {
                $pm->saveAsWebm(ROOT . DS . 'upload' . DS . $hash . DS . $hash, $cachepath);
            }
            if ($data['raw']) {
                serveFile($cachepath, $hash, 'video/mp4');
            } else {
                if ($data['preview']) {
                    if (!file_exists($cachepath)) {
                        $pm->saveFirstFrameOfMP4($path, $cachepath);
                    }
                    header("Content-type: image/jpeg");
                    readfile($cachepath);
                } else {
                    renderMP4($path, $data);
                }
            }
            break;
    }
    exit;
}
Esempio n. 4
0
            flush();
        }
        fclose($fp);
    } else {
        header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
        print "File not found";
    }
}
$file = "../" . str_replace(array("{$dpath}/", "?f=", "../"), "", trim(urldecode($_SERVER['REQUEST_URI'])));
// If the last character of the URL is & then trigger for Download
if (substr($_SERVER['REQUEST_URI'], -1) == "&") {
    $download = true;
    // Strip off & from the end of the $file variable
    $file = substr_replace($file, '', strlen($file) - 1, 1);
} else {
    $download = false;
}
if (isset($_GET['f']) && $download == false) {
    if (file_exists($file)) {
        $size = number_format(trim(`stat -c%s "{$file}"`));
        $path_parts = pathinfo($file);
        $url_path = str_replace(array(" ", "../"), array("%20", ""), $file);
        print "Click to download <a href=\"{$dpath}/?f=" . $url_path . "&\">" . $path_parts['basename'] . "</a>";
        print " (" . $size . " bytes)";
    } else {
        header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
        print "File not found";
    }
} else {
    serveFile($file);
}