Example #1
0
function mkpath($path)
{
    if (@mkdir($path) or file_exists($path)) {
        return true;
    }
    return mkpath(dirname($path)) and mkdir($path);
}
Example #2
0
function write_file($path, $data = '')
{
    $dir = dirname($path);
    if (!is_dir($dir)) {
        mkpath($dir);
    }
    return file_put_contents($path, $data);
}
Example #3
0
 function mkpath($path)
 {
     # Via Zingus J. Rinkle
     if (@mkdir($path) or file_exists($path)) {
         return true;
     }
     return mkpath(dirname($path)) and mkdir($path);
 }
Example #4
0
/**
 * @brief create course directories
 * @global type $webDir
 * @param type $code
 * @return boolean
 */
function create_course_dirs($code)
{
    global $webDir;
    $base = $webDir . "/courses/{$code}";
    umask(0);
    if (!(mkpath("{$base}") and mkpath("{$base}/image") and mkpath("{$base}/document") and mkpath("{$base}/dropbox") and mkpath("{$base}/page") and mkpath("{$base}/work") and mkpath("{$base}/group") and mkpath("{$base}/temp") and mkpath("{$base}/scormPackages") and mkpath($webDir . "/video/{$code}"))) {
        return false;
    }
    return true;
}
Example #5
0
 public function build()
 {
     if (!file_exists($this->mPath)) {
         mkpath($this->mPath);
     }
     $filename = date("Ymdhis") . ".sql";
     /*echo "mysqldump -h "._DB_HOST." -u "._DB_USER." -p"._DB_PASS." "._DB_NAME." > ".$this->mPath.$filename;
     		die();*/
     system("mysqldump -h " . _DB_HOST . " -u " . _DB_USER . " -p" . _DB_PASS . " " . _DB_NAME . " --skip-lock-tables > " . $this->mPath . "/" . $filename);
     $sql = "INSERT INTO " . get_table("backuplist") . " SET filename='{$filename}',path='" . $this->mPath . "'";
     $this->mDb->execute($sql);
     return $filename;
 }
Example #6
0
function mkpath($dir, $basepath)
{
    global $switches;
    $output = '';
    if ($dh = opendir($dir)) {
        $dirlist = array();
        $cdok = false;
        while (($file = readdir($dh)) !== false) {
            if ($file == '.svn') {
                continue;
            }
            $type = filetype($dir . '/' . $file);
            if ($type == 'dir') {
                if ($file != '.' && $file != '..') {
                    $dirlist[] = $file;
                }
            } else {
                if (!$cdok) {
                    $output .= "cd " . $basepath . "\n";
                    $cdok = true;
                }
                $output .= "  " . $file . "\n";
            }
        }
        closedir($dh);
        if (!$cdok && count($dirlist) == 0 && isset($switches['-e'])) {
            $output .= "cd " . $basepath . "\n";
        }
        foreach ($dirlist as $d) {
            $output .= mkpath($dir . '/' . $d, $basepath . '/' . $d);
        }
    } else {
        echo "error opening directory {$dir}\n";
        exit(1);
    }
    return $output;
}
/**
 * Do the main task of archiving a course.
 * 
 * @param int $course_id
 * @param string $course_code
 * @return boolean $success
 */
function doArchive($course_id, $course_code)
{
    global $webDir, $urlServer, $urlAppend, $siteName;
    if (extension_loaded('zlib')) {
        include 'include/pclzip/pclzip.lib.php';
    }
    $basedir = "{$webDir}/courses/archive/{$course_code}";
    mkpath($basedir);
    // Remove previous back-ups older than 10 minutes
    cleanup("{$webDir}/courses/archive", 600);
    $backup_date = date('Ymd-His');
    $backup_date_short = date('Ymd');
    $archivedir = $basedir . '/' . $backup_date;
    mkpath($archivedir);
    $zipfile = $basedir . "/{$course_code}-{$backup_date_short}.zip";
    // backup subsystems from main db
    $sql_course = "course_id = {$course_id}";
    $archive_conditions = array('course' => "id = {$course_id}", 'user' => "id IN (SELECT user_id FROM course_user\n                                          WHERE course_id = {$course_id})", 'course_user' => "course_id = {$course_id}", 'course_settings' => "course_id = {$course_id}", 'course_department' => "course = {$course_id}", 'course_module' => $sql_course, 'hierarchy' => "id IN (SELECT department FROM course_department\n                                          WHERE course = {$course_id})", 'announcement' => $sql_course, 'group_properties' => $sql_course, 'group' => $sql_course, 'group_members' => "group_id IN (SELECT id FROM `group`\n                                                    WHERE course_id = {$course_id})", 'document' => $sql_course, 'link_category' => $sql_course, 'link' => $sql_course, 'ebook' => $sql_course, 'ebook_section' => "ebook_id IN (SELECT id FROM ebook\n                                                    WHERE course_id = {$course_id})", 'ebook_subsection' => "section_id IN (SELECT ebook_section.id\n                                                         FROM ebook, ebook_section\n                                                         WHERE ebook.id = ebook_id AND\n                                                               course_id = {$course_id})", 'course_units' => $sql_course, 'unit_resources' => "unit_id IN (SELECT id FROM course_units\n                                                    WHERE course_id = {$course_id})", 'forum' => $sql_course, 'forum_category' => $sql_course, 'forum_topic' => "forum_id IN (SELECT id FROM forum\n                                                  WHERE course_id = {$course_id})", 'forum_post' => "topic_id IN (SELECT forum_topic.id\n                                                 FROM forum, forum_topic\n                                                 WHERE forum.id = forum_id AND\n                                                       course_id = {$course_id})", 'forum_notify' => $sql_course, 'forum_user_stats' => $sql_course, 'course_description' => $sql_course, 'glossary' => $sql_course, 'glossary_category' => $sql_course, 'video_category' => $sql_course, 'video' => $sql_course, 'videolink' => $sql_course, 'dropbox_msg' => $sql_course, 'dropbox_attachment' => "msg_id IN (SELECT id from dropbox_msg WHERE course_id = {$course_id})", 'dropbox_index' => "msg_id IN (SELECT id from dropbox_msg WHERE course_id = {$course_id})", 'lp_learnPath' => $sql_course, 'lp_module' => $sql_course, 'lp_asset' => "module_id IN (SELECT module_id FROM lp_module WHERE course_id = {$course_id})", 'lp_rel_learnPath_module' => "learnPath_id IN (SELECT learnPath_id FROM lp_learnPath WHERE course_id = {$course_id})", 'lp_user_module_progress' => "learnPath_id IN (SELECT learnPath_id FROM lp_learnPath WHERE course_id = {$course_id})", 'wiki_properties' => $sql_course, 'wiki_acls' => "wiki_id IN (SELECT id FROM wiki_properties WHERE course_id = {$course_id})", 'wiki_pages' => "wiki_id IN (SELECT id FROM wiki_properties WHERE course_id = {$course_id})", 'wiki_pages_content' => "pid IN (SELECT id FROM wiki_pages\n                                                    WHERE wiki_id IN (SELECT id FROM wiki_properties\n                                                                             WHERE course_id = {$course_id}))", 'poll' => $sql_course, 'poll_question' => "pid IN (SELECT pid FROM poll WHERE course_id = {$course_id})", 'poll_answer_record' => "pid IN (SELECT pid FROM poll WHERE course_id = {$course_id})", 'poll_question_answer' => "pqid IN (SELECT pqid FROM poll_question\n                                                       WHERE pid IN (SELECT pid FROM poll\n                                                                            WHERE course_id = {$course_id}))", 'assignment' => $sql_course, 'assignment_submit' => "assignment_id IN (SELECT id FROM assignment\n                                                             WHERE course_id = {$course_id})", 'gradebook' => $sql_course, 'gradebook_activities' => "gradebook_id IN (SELECT id FROM gradebook\n                                                             WHERE course_id = {$course_id})", 'gradebook_book' => "gradebook_activity_id IN (SELECT gradebook_activities.id FROM gradebook_activities, gradebook\n                                                             WHERE gradebook.course_id = {$course_id} AND gradebook_activities.gradebook_id = gradebook.id)", 'gradebook_users' => "gradebook_id IN (SELECT id FROM gradebook WHERE course_id = {$course_id})", 'attendance' => $sql_course, 'attendance_activities' => "attendance_id IN (SELECT id FROM attendance\n                                                             WHERE course_id = {$course_id})", 'attendance_book' => "attendance_activity_id IN (SELECT attendance_activities.id FROM attendance_activities, attendance\n                                                             WHERE attendance.course_id = {$course_id} AND attendance_activities.attendance_id = attendance.id)", 'attendance_users' => "attendance_id IN (SELECT id FROM attendance WHERE course_id = {$course_id})", 'agenda' => $sql_course, 'exercise' => $sql_course, 'exercise_question' => $sql_course, 'exercise_answer' => "question_id IN (SELECT id FROM exercise_question\n                                                         WHERE course_id = {$course_id})", 'exercise_user_record' => "eid IN (SELECT id FROM exercise WHERE course_id = {$course_id})", 'exercise_with_questions' => "question_id IN (SELECT id FROM exercise_question\n                                                                 WHERE course_id = {$course_id}) OR\n                                          exercise_id IN (SELECT id FROM exercise\n                                                                 WHERE course_id = {$course_id})", 'bbb_session' => "course_id IN (SELECT id FROM bbb_session WHERE course_id = {$course_id})", 'blog_post' => "id IN (SELECT id FROM blog_post WHERE course_id = {$course_id})", 'comments' => "(rtype = 'blogpost' AND rid IN (SELECT id FROM blog_post WHERE course_id = {$course_id})) OR (rtype = 'course' AND rid = {$course_id})", 'rating' => "(rtype = 'blogpost' AND rid IN (SELECT id FROM blog_post WHERE course_id = {$course_id})) OR (rtype = 'course' AND rid = {$course_id})", 'rating_cache' => "(rtype = 'blogpost' AND rid IN (SELECT id FROM blog_post WHERE course_id = {$course_id})) OR (rtype = 'course' AND rid = {$course_id})", 'note' => "(reference_obj_course IS NOT NULL AND reference_obj_course = {$course_id})");
    foreach ($archive_conditions as $table => $condition) {
        backup_table($archivedir, $table, $condition);
    }
    file_put_contents("{$archivedir}/config_vars", serialize(array('urlServer' => $urlServer, 'urlAppend' => $urlAppend, 'siteName' => $siteName, 'version' => get_config('version'))));
    // $htmldir is not needed anywhere
    //$htmldir = $archivedir . '/html';
    // create zip file
    $zipCourse = new PclZip($zipfile);
    $result1 = $zipCourse->create($archivedir, PCLZIP_OPT_REMOVE_PATH, "{$webDir}/courses/archive");
    $result2 = $zipCourse->add("{$webDir}/courses/{$course_code}", PCLZIP_OPT_REMOVE_PATH, "{$webDir}/courses/{$course_code}", PCLZIP_OPT_ADD_PATH, "{$course_code}/{$backup_date}/html");
    $result3 = $zipCourse->add("{$webDir}/video/{$course_code}", PCLZIP_OPT_REMOVE_PATH, "{$webDir}/video/{$course_code}", PCLZIP_OPT_ADD_PATH, "{$course_code}/{$backup_date}/video_files");
    $success = true;
    if ($result1 === 0 || $result2 === 0 || $result3 === 0) {
        $success = false;
    }
    removeDir($archivedir);
    return $success;
}
/**
 * Crea un path.
 *
 * @param string $path ruta a crear
 * @return boolean
 */
function mkpath($path)
{
    $path = join_path(func_get_args());
    if (@mkdir($path) or file_exists($path)) {
        return true;
    }
    return mkpath(dirname($path)) and mkdir($path);
}
Example #9
0
<?php

/*ini_set('error_reporting', E_ALL); //打开所有的错误级别
	ini_set('display_errors', 1); //显示错误*/
require_once "../../configs/initdb.php";
$root = "/data/wwwroot/vhost/";
//$db->debug=1;
$data = unserialize($_POST["data"]);
if ($data["domain"]) {
    $path = $root . $data["domain"] . ".feidaoyu.com";
    mkpath($path . "/htdocs");
    $user = $data["domain"] . random(2);
    $password = random(6);
    $start = date("Y-m-d");
    $end = date("Y-m-d", strtotime($data["year"] . "year"));
    $vpsid = $data["vpsid"];
    $sql = "INSERT INTO `ftpuser` VALUES (null, '{$user}','{$vpsid}', '{$password}', 5500, 5500, '{$path}', '/sbin/nologin', 10, '{$start} 00:00:00', '{$end} 00:00:00');";
    $db->execute($sql);
    $fp = fopen("{$path}/htdocs/index.html", "a+");
    fwrite($fp, "Hello world! by feidaoyu.com");
    fclose($fp);
    system("chmod -R 777 {$path}");
    $sql = "CREATE DATABASE `{$user}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;";
    $db->execute($sql);
    $sql = "GRANT ALL PRIVILEGES ON {$user}.* TO {$user}@localhost IDENTIFIED BY '{$password}';";
    $db->execute($sql);
    $rs["domain"] = $data["domain"] . ".feidaoyu.com";
    $rs["user"] = $user;
    $rs["password"] = $password;
    $rs["dbhost"] = "localhost";
    $rs["dbname"] = $user;
Example #10
0
function writeBigOrderSkuLog($file, $data)
{
    $tmp_dir = dirname($file);
    if (!is_dir($tmp_dir)) {
        mkpath($tmp_dir);
    }
    if (!($handle = fopen($file, 'a'))) {
        return false;
    }
    if (flock($handle, LOCK_EX)) {
        if (fwrite($handle, $data) === FALSE) {
            return false;
        }
        flock($handle, LOCK_UN);
    }
    fclose($handle);
    return true;
}
function download_images_for_page($target)
{
    echo "target = {$target}\n";
    # Download the web page
    $web_page = http_get($target, $referer = "");
    # Update the target in case there was a redirection
    $target = $web_page['STATUS']['url'];
    # Strip file name off target for use as page base
    $page_base = get_base_page_address($target);
    # Identify the directory where iamges are to be saved
    $save_image_directory = "saved_images_" . str_replace("http://", "", $page_base);
    # Parse the image tags
    $img_tag_array = parse_array($web_page['FILE'], "<img", ">");
    if (count($img_tag_array) == 0) {
        echo "No images found at {$target}\n";
        exit;
    }
    # Echo the image source attribute from each image tag
    for ($xx = 0; $xx < count($img_tag_array); $xx++) {
        $image_path = get_attribute($img_tag_array[$xx], $attribute = "src");
        echo " image: " . $image_path;
        $image_url = resolve_address($image_path, $page_base);
        if (get_base_domain_address($page_base) == get_base_domain_address($image_url)) {
            # Make image storage directory for image, if one doesn't exist
            $directory = substr($image_path, 0, strrpos($image_path, "/"));
            $directory = str_replace(":", "-", $directory);
            $image_path = str_replace(":", "-", $image_path);
            clearstatcache();
            // clear cache to get accurate directory status
            if (!is_dir($save_image_directory . "/" . $directory)) {
                mkpath($save_image_directory . "/" . $directory);
            }
            # Download the image, report image size
            $this_image_file = download_binary_file($image_url, $ref = "");
            echo " size: " . strlen($this_image_file);
            # Save the image
            if (stristr($image_url, ".jpg") || stristr($image_url, ".gif") || stristr($image_url, ".png")) {
                $fp = fopen($save_image_directory . "/" . $image_path, "w");
                fputs($fp, $this_image_file);
                fclose($fp);
                echo "\n";
            }
        } else {
            echo "\nSkipping off-domain image.\n";
        }
    }
}
Example #12
0
/**
 *  创建一条路径(递归地创建文件夹)
 *  @param  string $path
 *  @param  int    $mode
 *  @return bool
 */
function mkpath($path, $mode = 0777)
{
    if (is_dir($path)) {
        return true;
    }
    if (@mkdir($path, $mode)) {
        @touch($path . '/index.html');
        return true;
    }
    /* 递归的创建父亲文件夹 */
    if (!mkpath(dirname($path), $mode)) {
        return false;
    }
    /* 创建自身 */
    $result = @mkdir($path, $mode);
    if ($result) {
        @touch($path . '/index.html');
    }
    return $result;
}
function jikes_compile($src_path, $target_path, $verbose, $extra_classpath = '')
{
    // Initialize path to jikes. First assume jikes is in the same directory as this script
    $jikes_pp = explode('/', __FILE__);
    $jikes_pp[count($jikes_pp) - 1] = 'jikes';
    $jikes_cmd = implode('/', $jikes_pp);
    if (!file_exists($jikes_cmd)) {
        $jikes_cmd = $jikes_cmd . '.exe';
        if (!file_exists($jikes_cmd)) {
            $jikes_cmd = 'jikes';
            // Try path
        }
    }
    $src_path = realpath($src_path);
    mkpath($target_path, 0750);
    $target_path = realpath($target_path);
    $System = new JavaClass("java.lang.System");
    $Properties = $System->getProperties();
    $java_home = $Properties->get("java.home");
    $classpath = $Properties->get("java.class.path");
    if ($extra_classpath != '') {
        $classpath .= ":{$extra_classpath}";
    }
    $bootclasspath = $Properties->get("sun.boot.class.path");
    $target_version = $Properties->get("java.specification.version");
    clearstatcache();
    // Neccessary, otherwise file modification dates and calls to "file_exists" get cached.
    $files = dir_pattern_scan($src_path, "\\.java\$", '/', 6);
    $files = filter_unmodified($files, $src_path, $target_path);
    if (count($files) == 0) {
        return 0;
    }
    $filearg = implode(' ', $files);
    $output = array();
    if ($verbose) {
        $command = "{$jikes_cmd} -Xstdout -verbose ";
    } else {
        $command = "{$jikes_cmd} -Xstdout ";
    }
    $command .= "-bootclasspath {$bootclasspath} -classpath {$classpath}:{$target_path} -target {$target_version} -source {$target_version} ";
    $command .= "-sourcepath {$src_path} -d {$target_path} {$filearg}";
    $retval = -99999;
    exec($command, $output, $retval);
    if ($retval == 126) {
        throw new JavaCompilationException($command, "No execute permission for '{$jikes_cmd}'", $retval);
    }
    if ($retval == 127) {
        throw new JavaCompilationException($command, "Jikes Executable '{$jikes_cmd}' not found", $retval);
    }
    if ($retval != 0) {
        throw new JavaCompilationException($command, implode("\n", $output), $retval);
    }
    return count($files);
}
Example #14
0
     $newTag->execute();
 }
 $file->setType(issetOrBlank($_POST['file-type']));
 $file->setUploadDate(date('Y-m-d H:i:s'));
 $file->setActive(1);
 $file->setAliasID(0);
 //echo UPLOADS_DIR;
 $DATEPATH = date('Y') . DIRECTORY_SEPARATOR . date('m') . DIRECTORY_SEPARATOR;
 $uploadTo = $DATEPATH . $file->getCampus() . DIRECTORY_SEPARATOR . $file->getFaculty() . DIRECTORY_SEPARATOR . $file->getCategory() . DIRECTORY_SEPARATOR;
 $uploadTo = issetOrBlank($uploadTo);
 //$uploadTo = "";
 //echo $uploadTo;
 //Ensure that the directory path exists
 //echo UPLOADS_DIR;
 //exit;
 mkpath(UPLOADS_DIR . $uploadTo);
 //echo UPLOADS_DIR.$uploadTo;
 $uploaded = 0;
 if (!file_exists(UPLOADS_DIR . $uploadTo)) {
     //could not create directory
     echo '<h1 class="error">Could not create directory for upload</h1>';
 } else {
     if (isset($_FILES["file-file"])) {
         //file uploaded
         $targetFile = UPLOADS_DIR . $uploadTo . $_FILES["file-file"]['name'];
         if (!file_exists($targetFile)) {
             if (move_uploaded_file($_FILES["file-file"]["tmp_name"], issetOrBlank($targetFile))) {
                 $uploaded = 1;
             }
         } else {
             echo '<h1 class="error">File already Exists!</h1>';
 function get_thumbnail(&$dest, &$width, &$height, $id, $scale = 0, $format = '%f-thumb-%wx%h-%i%x', $dest_type = 'auto', $square = false)
 {
     if (empty($this->src_file)) {
         return false;
     }
     if (!file_exists($this->src_file)) {
         return false;
     }
     if (!$this->is_available()) {
         global $mt;
         $mt->warning_log($mt->translate('GD support has not been available. Please install GD support.'));
         return false;
     }
     # Get source image information
     list($this->src_w, $this->src_h, $this->src_type, $src_attr) = getimagesize($this->src_file);
     # Load source image
     $src_img;
     switch ($this->src_type) {
         case 1:
             #GIF
             $src_img = @imagecreatefromgif($this->src_file);
             break;
         case 2:
             #JPEG
             $src_img = @imagecreatefromjpeg($this->src_file);
             break;
         case 3:
             #PNG
             $src_img = @imagecreatefrompng($this->src_file);
             break;
         default:
             #Unsupported format
             return false;
     }
     if (empty($src_img)) {
         return false;
     }
     # Calculate thumbnail size
     list($thumb_w, $thumb_h, $thumb_w_name, $thumb_h_name) = $this->_calculate_size($width, $height, $scale, $square);
     $width = $thumb_w;
     $height = $thumb_h;
     # Decide a destination file name
     if (empty($dest)) {
         $dest = $this->_make_dest_name($thumb_w_name, $thumb_h_name, $format, $dest_type, $id);
     }
     # Generate
     if (!file_exists($dest)) {
         $dir_name = dirname($dest);
         if (!file_exists($dir_name)) {
             mkpath($dir_name, 0777);
         }
         if (!is_writable($dir_name)) {
             imagedestroy($src_img);
             return false;
         }
         # if square modifier is enable, crop & resize
         $src_x = 0;
         $src_y = 0;
         $target_w = $this->src_w;
         $target_h = $this->src_h;
         if ($square) {
             if ($this->src_w > $this->src_h) {
                 $src_x = (int) ($this->src_w - $this->src_h) / 2;
                 $src_y = 0;
                 $target_w = $this->src_h;
             } else {
                 $src_x = 0;
                 $src_y = (int) ($this->src_h - $this->src_w) / 2;
                 $target_h = $this->src_w;
             }
         }
         # Create thumbnail
         $dst_img = imagecreatetruecolor($thumb_w, $thumb_h);
         $result = imagecopyresampled($dst_img, $src_img, 0, 0, $src_x, $src_y, $thumb_w, $thumb_h, $target_w, $target_h);
         $output = $this->src_type;
         if ($dest_type != 'auto') {
             $output = strtolower($dest_type) == 'gif' ? 1 : strtolower($dest_type) == 'jpeg' ? 2 : strtolower($dest_type) == 'png' ? 3 : $src_type;
         }
         switch ($output) {
             case 1:
                 #GIF
                 imagegif($dst_img, $dest);
                 break;
             case 2:
                 #JPEG
                 imagejpeg($dst_img, $dest);
                 break;
             case 3:
                 #PNG
                 imagepng($dst_img, $dest);
                 break;
         }
         imagedestroy($dst_img);
     }
     imagedestroy($src_img);
     return true;
 }
Example #16
0
    //文件保存目录URL
    $root_url .= $forder;
}
//图片扩展名
$ext_arr = array('gif', 'jpg', 'jpeg', 'png', 'bmp');
//目录名
$dir_name = empty($_GET['dir']) ? '' : trim($_GET['dir']);
if (!in_array($dir_name, array('', 'image', 'flash', 'media', 'file'))) {
    echo "Invalid Directory name.";
    exit;
}
if ($dir_name !== '') {
    $root_path .= $dir_name . "/";
    $root_url .= $dir_name . "/";
    if (!file_exists($root_path)) {
        mkpath($root_path);
    }
}
//根据path参数,设置各路径和URL
if (empty($_GET['path'])) {
    $current_path = realpath($root_path) . '/';
    $current_url = $root_url;
    $current_dir_path = '';
    $moveup_dir_path = '';
} else {
    $current_path = realpath($root_path) . '/' . $_GET['path'];
    $current_url = $root_url . $_GET['path'];
    $current_dir_path = $_GET['path'];
    $moveup_dir_path = preg_replace('/(.*?)[^\\/]+\\/$/', '$1', $current_dir_path);
}
echo realpath($root_path);
Example #17
0
 function moveTestFiles()
 {
     if (!$this->conf['TEST_BASE_PATH'] || $this->conf['TEST_BASE_PATH'] == $this->conf['TEST_PHP_SRCDIR']) {
         return;
     }
     $this->writemsg("moving files from {$this->conf['TEST_PHP_SRCDIR']} to {$this->conf['TEST_BASE_PATH']}\n");
     $l = strlen($this->conf['TEST_PHP_SRCDIR']);
     $files = array();
     $dirs = array();
     foreach ($this->test_files as $file) {
         if (strpos($file, $this->conf['TEST_PHP_SRCDIR']) == 0) {
             $newlocation = $this->conf['TEST_BASE_PATH'] . substr($file, $l);
             $files[] = $newlocation;
             $dirs[dirname($file)] = dirname($newlocation);
         } else {
             // XXX what to do with test files outside the
             // php source directory?  Need to map them into
             // the new directory somehow.
         }
     }
     foreach ($dirs as $src => $new) {
         mkpath($new);
         copyfiles($src, $new);
     }
     $this->test_files = $files;
 }
Example #18
0
 public function BuildStyle($id, $str)
 {
     mkpath(dirname(_CSS_PATH . $id . ".css"));
     $fp = fopen(_CSS_PATH . $id . ".css", "wb");
     $str = str_replace("‘", "'", $str);
     $str = str_replace("\\'", "'", $str);
     fwrite($fp, $str);
     fclose($fp);
 }
Example #19
0
$web_page = http_get($target, $referer);
$books = array();
$bookCount = 0;
# Parse all the tables on the web page into an array
$divs = parse_array($web_page['FILE'], "<div", "</div>");
foreach ($divs as $div) {
    $divClass = 'views-field-field-image-cache-fid';
    if (stristr($div, $divClass)) {
        $imgTag = parse_array($div, '<img', '/>');
        if ($cloudflare == 1) {
            $books[$bookCount]['imageUrl'] = resolve_address(str_replace("www", "ftp", get_attribute($imgTag[0], $attribute = "src")), $page_base);
        } else {
            $books[$bookCount]['imageUrl'] = resolve_address(get_attribute($imgTag[0], $attribute = "src"), $page_base);
        }
        if (!is_dir($save_image_directory)) {
            mkpath($save_image_directory);
        }
        $this_image_file = download_binary_file($books[$bookCount]['imageUrl'], $ref = "");
        if (stristr($books[$bookCount]['imageUrl'], ".jpg") || stristr($books[$bookCount]['imageUrl'], ".gif") || stristr($books[$bookCount]['imageUrl'], ".png")) {
            file_put_contents($save_image_directory . basename($books[$bookCount]['imageUrl']), $this_image_file);
        }
    }
    $divClass = 'views-field-title';
    if (stristr($div, $divClass)) {
        $books[$bookCount]['title'] = trim(strip_tags($div));
        $aTag = parse_array($div, '<a', '</a>');
        if ($cloudflare == 1) {
            $books[$bookCount]['bookUrl'] = resolve_address(str_replace("www", "ftp", get_attribute($aTag[0], $attribute = "href")), $page_base);
        } else {
            $books[$bookCount]['bookUrl'] = resolve_address(get_attribute($aTag[0], $attribute = "href"), $page_base);
        }
 public function get_thumbnail($args = null)
 {
     # Parse args
     if (!empty($args)) {
         if (!empty($args['dest'])) {
             $this->dest_file = $args['dest'];
         }
         if (!empty($args['width'])) {
             $this->dest_w = $args['width'];
         }
         if (!empty($args['height'])) {
             $this->dest_h = $args['height'];
         }
         if (!empty($args['id'])) {
             $this->dest_id = $args['id'];
         }
         if (!empty($args['scale'])) {
             $this->dest_scale = $args['scale'];
         }
         if (!empty($args['format'])) {
             $this->dest_format = $args['format'];
         }
         if (!empty($args['dest_type'])) {
             $this->dest_type = $args['dest_type'];
         }
         if (!empty($args['square'])) {
             $this->dest_square = $args['square'];
         }
     }
     # Load source image
     if (!$this->load_image()) {
         return false;
     }
     # Calculate thumbnail size
     list($thumb_w, $thumb_h, $thumb_w_name, $thumb_h_name) = $this->_calculate_size();
     $this->dest_w = $thumb_w;
     $this->dest_h = $thumb_h;
     # Decide a destination file name
     if (empty($this->dest_file)) {
         $this->dest_file($this->_make_dest_name($thumb_w_name, $thumb_h_name));
     }
     # Generate
     $dest_file = $this->dest_file();
     if (file_exists($dest_file)) {
         if ($this->src_w == $this->src_h) {
             $compulsive_resize = 0;
         } else {
             list($tmp_w, $tmp_h) = getimagesize($dest_file);
             $ds = $this->dest_square;
             $compulsive_resize = $ds && $tmp_w != $tmp_h || !$ds && $tmp_w == $tmp_h ? 1 : 0;
         }
     } else {
         $compulsive_resize = 1;
     }
     if ($compulsive_resize) {
         $dir_name = dirname($dest_file);
         if (!file_exists($dir_name)) {
             mkpath($dir_name, 0777);
         }
         if (!is_writable($dir_name)) {
             return false;
         }
         # if square modifier is enable, crop & resize
         $src_x = 0;
         $src_y = 0;
         $target_w = $this->src_w;
         $target_h = $this->src_h;
         if ($this->dest_square) {
             if ($this->src_w > $this->src_h) {
                 $src_x = (int) ($this->src_w - $this->src_h) / 2;
                 $src_y = 0;
                 $target_w = $this->src_h;
             } else {
                 $src_x = 0;
                 $src_y = (int) ($this->src_h - $this->src_w) / 2;
                 $target_h = $this->src_w;
             }
         }
         # Create dest image
         $this->dest_img = imagecreatetruecolor($thumb_w, $thumb_h);
         # Check transparent color support
         # Code from https://github.com/maxim/smart_resize_image/blob/master/smart_resize_image.function.php
         if ($this->src_type == 1 || $this->src_type == 3) {
             $trnprt_indx = imagecolortransparent($this->src_img);
             // If we have a specific transparent color
             if ($trnprt_indx >= 0) {
                 // Get the original image's transparent color's RGB values
                 $trnprt_color = imagecolorsforindex($this->src_img, $trnprt_indx);
                 // Allocate the same color in the new image resource
                 $trnprt_indx = imagecolorallocate($this->dest_img, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
                 // Completely fill the background of the new image with allocated color.
                 imagefill($this->dest_img, 0, 0, $trnprt_indx);
                 // Set the background color for new image to transparent
                 imagecolortransparent($this->dest_img, $trnprt_indx);
             } elseif ($this->src_type == 3) {
                 // Always make a transparent background color for PNGs that don't have one allocated already
                 // Turn off transparency blending (temporarily)
                 imagealphablending($this->dest_img, false);
                 // Create a new transparent color for image
                 $color = imagecolorallocatealpha($this->dest_img, 0, 0, 0, 127);
                 // Completely fill the background of the new image with allocated color.
                 imagefill($this->dest_img, 0, 0, $color);
                 // Restore transparency blending
                 imagesavealpha($this->dest_img, true);
             }
         }
         # Create thumbnail
         $result = imagecopyresampled($this->dest_img, $this->src_img, 0, 0, $src_x, $src_y, $thumb_w, $thumb_h, $target_w, $target_h);
         $output = $this->src_type;
         if ($this->dest_type != 'auto') {
             if (strtolower($this->dest_type) == 'gif') {
                 $output = 1;
             } elseif (strtolower($this->dest_type) == 'jpeg') {
                 $output = 2;
             } elseif (strtolower($this->dest_type) == 'png') {
                 $output = 3;
             } else {
                 $output = $this->src_type;
             }
         }
         switch ($output) {
             case 1:
                 #GIF
                 imagegif($this->dest_img, $dest_file);
                 break;
             case 2:
                 #JPEG
                 imagejpeg($this->dest_img, $dest_file);
                 break;
             case 3:
                 #PNG
                 imagepng($this->dest_img, $dest_file);
                 break;
         }
         @imagedestroy($this->dest_img);
     }
     @imagedestroy($this->src_img);
     return true;
 }
Example #21
0
 /**
  * Crea un path.
  *
  * @param string $path ruta a crear
  * @return boolean
  */
 public static function mkpath($path)
 {
     if (@mkdir($path) or file_exists($path)) {
         return TRUE;
     }
     return mkpath(dirname($path)) and mkdir($path);
 }
Example #22
0
function mkpath($path, $mode = 0777)
{
    // PHP5 supports recursive param
    if (version_compare(PHP_VERSION, '5.0.0', ">=")) {
        return mkdir($path, $mode, true);
    }
    // for php4
    is_dir(dirname($path)) || mkpath(dirname($path), $mode);
    return is_dir($path) || @mkdir($path, $mode);
}
Example #23
0
         case 2:
             $simage = imagecreatefromjpeg($file[tmp_name]);
             break;
         case 3:
             $simage = imagecreatefrompng($file[tmp_name]);
             break;
         case 6:
             $simage = imagecreatefromwbmp($file[tmp_name]);
             break;
     }
 }
 if ($_SERVER['REQUEST_METHOD'] == 'POST' && is_uploaded_file($_FILES["pic"][tmp_name])) {
     $file = $_FILES["pic"];
     $filepath = wrzc_net . "up/wzphoto/" . date("Ym") . "/";
     $dbpath = date("Ym") . "/";
     mkpath($filepath);
     $savename = $cook_userid . "_" . cdstr(20) . ".";
     $filename = $file["tmp_name"];
     $image_size = getimagesize($filename);
     $pinfo = pathinfo($file["name"]);
     $ftype = $pinfo['extension'];
     $destination = $filepath . "b_" . $savename . $ftype;
     if (!move_uploaded_file($filename, $destination)) {
         callmsg("移动照片出错", "-1");
     }
     $path_b = $dbpath . "b_" . $savename . $ftype;
     // 略
     $RESIZEWIDTH2 = 700;
     $RESIZEHEIGHT2 = 700;
     if ($ftype == "jpg" || $ftype == "JPG") {
         $im = imagecreatefromjpeg($destination);
Example #24
0
/**
 * Creates the given directory and creates all
 * dependant directories if necessary.
 * 
 * @param $path path of directory.
 */
function mkpath($path)
{
    if (@mkdir($path) || file_exists($path)) {
        return true;
    }
    return mkpath(dirname($path)) && mkdir($path);
}
function smarty_function_mtinclude($args, &$ctx)
{
    // status: partial
    // parameters: module, file
    // notes: file case needs work -- search through blog site archive path, etc...
    // push to ctx->vars
    $ext_args = array();
    while (list($key, $val) = each($args)) {
        if (!preg_match('/(^file$|^module$|^widget$|^blog_id$|^identifier$|^type$)/', $key)) {
            require_once "function.mtsetvar.php";
            smarty_function_mtsetvar(array('name' => $key, 'value' => $val), $ctx);
            $ext_args[] = $key;
        }
    }
    $blog_id = $args['blog_id'];
    $blog_id or $blog_id = $ctx->stash('blog_id');
    if ($args['local']) {
        $blog_id = $ctx->stash('local_blog_id');
    }
    $blog = $ctx->mt->db()->fetch_blog($blog_id);
    // When the module name starts by 'Widget', it converts to 'Widget' from 'Module'.
    if (isset($args['module']) && $args['module']) {
        $module = $args['module'];
        if (preg_match('/^Widget:/', $module)) {
            $args['widget'] = preg_replace('/^Widget: ?/', '', $module);
            unset($args['module']);
        }
    }
    // Fetch template meta data
    $load_type = null;
    $load_name = null;
    if (isset($args['module'])) {
        $load_type = 'custom';
        $load_name = $args['module'];
    } elseif (isset($args['widget'])) {
        $load_type = 'widget';
        $load_name = $args['widget'];
    } elseif (isset($args['identifier'])) {
        $load_type = 'identifier';
        $load_name = $args['identifier'];
    }
    $tmpl_meta = null;
    if (!empty($load_type)) {
        $is_global = isset($args['global']) && $args['global'] ? 1 : 0;
        if (isset($args['parent']) && $args['parent']) {
            if (isset($args['global']) && $args['global']) {
                return $ctx->error($ctx->mt->translate("'parent' modifier cannot be used with '[_1]'", 'global'));
            }
            if (isset($args['local']) && $args['local']) {
                return $ctx->error($ctx->mt->translate("'parent' modifier cannot be used with '[_1]'", 'global'));
            }
            $local_blog = $ctx->mt->db()->fetch_blog($ctx->stash('local_blog_id'));
            if ($local_blog->is_blog()) {
                $website = $local_blog->website();
                $blog_id = $website->id;
            } else {
                $blog_id = $local_blog->id;
            }
        }
        $tmpl_meta = $ctx->mt->db()->fetch_template_meta($load_type, $load_name, $blog_id, $is_global);
    }
    # Convert to phrase of PHP Include
    require_once 'MTUtil.php';
    $ssi_enable = false;
    $include_file = '';
    if (!empty($load_type) && isset($blog) && $blog->blog_include_system == 'php' && (isset($args['ssi']) && $args['ssi'] || $tmpl_meta->include_with_ssi)) {
        $ssi_enable = true;
        // Generates include path using Key
        $base_path = '';
        if (isset($args['key'])) {
            $base_path = $args['key'];
        } elseif (isset($args['cache_key'])) {
            $base_path or $base_path = $args['cache_key'];
        }
        $include_path_array = _include_path($base_path);
        $filename = dirify($tmpl_meta->template_name);
        $filename or $filename = 'template_' . $tmpl_meta->template_id;
        $filename .= '.' . $blog->blog_file_extension;
        $include_path = $blog->site_path();
        if (substr($include_path, strlen($include_path) - 1, 1) != DIRECTORY_SEPARATOR) {
            $include_path .= DIRECTORY_SEPARATOR;
        }
        foreach ($include_path_array as $p) {
            $include_path .= $p . DIRECTORY_SEPARATOR;
        }
        $include_file = $include_path . $filename;
    }
    # Try to read from cache
    $cache_enable = false;
    $cache_id = '';
    $cache_key = '';
    $cache_ttl = 0;
    $cache_expire_type = $tmpl_meta->cache_expire_type;
    if (!empty($load_type) && isset($blog) && $blog->blog_include_cache == 1 && ($cache_expire_type == '1' || $cache_expire_type == '2') || (isset($args['cache']) && $args['cache'] == '1' || isset($args['key']) || isset($args['cache_key']) || isset($args['ttl']))) {
        $cache_blog_id = isset($args['global']) && $args['global'] == 1 ? 0 : $blog_id;
        $mt = MT::get_instance();
        $cache_enable = true;
        $cache_key = isset($args['key']) ? $args['key'] : (isset($args['cache_key']) ? $args['cache_key'] : md5('blog::' . $cache_blog_id . '::template_' . $load_type . '::' . $load_name));
        if (isset($args['ttl'])) {
            $cache_ttl = $args['ttl'];
        } elseif (isset($cache_expire_type) && $cache_expire_type == '1') {
            $cache_ttl = $tmpl_meta->cache_expire_interval;
        } else {
            $cache_ttl = 60 * 60;
        }
        # default 60 min.
        if (isset($cache_expire_type) && $cache_expire_type == '2') {
            $expire_types = preg_split('/,/', $tmpl_meta->cache_expire_event, -1, PREG_SPLIT_NO_EMPTY);
            if (!empty($expire_types)) {
                $latest = $ctx->mt->db()->get_latest_touch($blog_id, $expire_types);
                if ($latest) {
                    $latest_touch = $latest->modified_on;
                    if ($ssi_enable) {
                        $file_stat = stat($include_file);
                        if ($file_stat) {
                            $file_stamp = gmdate("Y-m-d H:i:s", $file_stat[9]);
                            if (datetime_to_timestamp($latest_touch) > datetime_to_timestamp($file_stamp)) {
                                $cache_ttl = 1;
                            }
                        }
                    } else {
                        $cache_ttl = time() - datetime_to_timestamp($latest_touch, 'gmt');
                    }
                }
            }
        }
        $elapsed_time = time() - offset_time(datetime_to_timestamp($tmpl_meta->template_modified_on, 'gmt'), $blog, '-');
        if ($cache_ttl == 0 || $elapsed_time < $cache_ttl) {
            $cache_ttl = $elapsed_time;
        }
        $cache_driver = $mt->cache_driver($cache_ttl);
        $cached_val = $cache_driver->get($cache_key, $cache_ttl);
        if (!empty($cached_val)) {
            _clear_vars($ctx, $ext_args);
            if ($ssi_enable) {
                if (file_exists($include_file) && is_readable($include_file)) {
                    $content = file_get_contents($include_file);
                    if ($content) {
                        return $content;
                    }
                }
            } else {
                return $cached_val;
            }
        }
    }
    if ($ssi_enable && !$cache_enable) {
        if (file_exists($include_file) && is_readable($include_file)) {
            $content = file_get_contents($include_file);
            if ($content) {
                return $content;
            }
        }
    }
    # Compile template
    static $_include_cache = array();
    $_var_compiled = '';
    if (!empty($load_type)) {
        $cache_blog_id = isset($args['global']) && $args['global'] == 1 ? 0 : $blog_id;
        $cache_id = $load_type . '::' . $cache_blog_id . '::' . $load_name;
        if (isset($_include_cache[$cache_id])) {
            $_var_compiled = $_include_cache[$cache_id];
        } else {
            $tmpl = $ctx->mt->db()->get_template_text($ctx, $load_name, $blog_id, $load_type, $args['global']);
            if (!$ctx->_compile_source('evaluated template', $tmpl, $_var_compiled)) {
                _clear_vars($ctx, $ext_args);
                return $ctx->error("Error compiling template module '{$module}'");
            }
            $_include_cache[$cache_id] = $_var_compiled;
        }
    } elseif (isset($args['file']) && $args['file']) {
        $mt = MT::get_instance();
        if (!$mt->config('AllowFileInclude')) {
            return $ctx->error('File include is disabled by "AllowFileInclude" config directive.');
        }
        $file = $args['file'];
        $cache_id = 'file::' . $blog_id . '::' . $file;
        if (isset($_include_cache[$cache_id])) {
            $_var_compiled = $_include_cache[$cache_id];
        } else {
            $tmpl = _get_template_from_file($ctx, $file, $blog_id);
            if (!$ctx->_compile_source('evaluated template', $tmpl, $_var_compiled)) {
                _clear_vars($ctx, $ext_args);
                return $ctx->error("Error compiling template file '{$file}'");
            }
            $_include_cache[$cache_id] = $_var_compiled;
        }
    } elseif (isset($args['type']) && $args['type']) {
        $type = $args['type'];
        $cache_id = 'type::' . $blog_id . '::' . $type;
        if (isset($_include_cache[$cache_id])) {
            $_var_compiled = $_include_cache[$cache_id];
        } else {
            $tmpl = $ctx->mt->db()->load_special_template($ctx, null, $type, $blog_id);
            if ($tmpl) {
                if ($ctx->_compile_source('evaluated template', $tmpl->template_text, $_var_compiled)) {
                    $_include_cache[$cache_id] = $_var_compiled;
                } else {
                    if ($type != 'dynamic_error') {
                        _clear_vars($ctx, $ext_args);
                        return $ctx->error("Error compiling template module '{$module}'");
                    } else {
                        _clear_vars($ctx, $ext_args);
                        return null;
                    }
                }
            } else {
                _clear_vars($ctx, $ext_args);
                return null;
            }
        }
    }
    ob_start();
    $ctx->_eval('?>' . $_var_compiled);
    $_contents = ob_get_contents();
    ob_end_clean();
    _clear_vars($ctx, $ext_args);
    if ($cache_enable) {
        $cache_driver = $mt->cache_driver($cache_ttl);
        $cache_driver->set($cache_key, $_contents, $cache_ttl);
    }
    if ($ssi_enable) {
        $include_dir = dirname($include_file);
        if (!file_exists($include_dir) && !is_dir($include_dir)) {
            mkpath($include_dir, 0777);
        }
        if (is_writable($include_dir)) {
            if ($h_file = fopen($include_file, 'w')) {
                fwrite($h_file, $_contents);
                fclose($h_file);
            }
        }
    }
    return $_contents;
}
Example #26
0
$save_path = _FILE_PATH . "/";
//文件保存目录URL
$save_url = IMG_HOST . "/";
if ($_SESSION["login_user"]) {
    $hash = md5($_SESSION["login_user"]["id"]);
    $forder = "users/" . substr($hash, 0, 2) . "/" . $_SESSION["login_user"]["id"] . "/";
    //文件保存目录路径
    $save_path .= $forder;
    //文件保存目录URL
    $save_url .= $forder;
}
//定义允许上传的文件扩展名
$ext_arr = array('image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'), 'flash' => array('swf', 'flv'), 'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'), 'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2'));
//最大文件大小
$max_size = 30000000;
mkpath($save_path);
$save_path = realpath($save_path) . '/';
//PHP上传失败
if (!empty($_FILES['imgFile']['error'])) {
    switch ($_FILES['imgFile']['error']) {
        case '1':
            $error = '超过php.ini允许的大小。';
            break;
        case '2':
            $error = '超过表单允许的大小。';
            break;
        case '3':
            $error = '图片只有部分被上传。';
            break;
        case '4':
            $error = '请选择图片。';