Beispiel #1
0
 function save($info, $where, $overwrite)
 {
     $templates = $this->createTemplates($info);
     $package = str_replace('.', '/', $info['package']);
     //First create package hierarchy
     if (!is_dir($where . '/' . $package)) {
         //Create the directory
         $attempt = @makeDirs($where . '/' . $package);
         if ($attempt == FALSE) {
             return "could not create directory {$where}/{$package}";
         }
     }
     chdir($where . '/' . $package);
     //Make standard ARP dirs
     $dirs = array('business', 'control', 'command', 'view', 'vo');
     foreach ($dirs as $dir) {
         if (!is_dir($dir)) {
             //Create the directory
             $attempt = @mkdir($dir);
             if ($attempt == FALSE) {
                 return "Could not create directory {$dir}, permissions set correctly?";
             }
         }
     }
     //Save
     $error = "Could not write file ";
     if ($overwrite || !file_exists('control/Controller.as')) {
         $r = file_put_contents('control/Controller.as', $templates['controller']);
         if ($r === FALSE) {
             return $error . 'Controller.as';
         }
     }
     if ($overwrite || !file_exists('business/ServiceLocator.as')) {
         $r = file_put_contents('business/ServiceLocator.as', $templates['locator']);
         if ($r === FALSE) {
             return $error . 'ServiceLocator.as';
         }
     }
     foreach ($templates['commands'] as $commandName => $command) {
         if ($overwrite || !file_exists('command/' . ucfirst($commandName . 'Command.as'))) {
             $r = file_put_contents('command/' . ucfirst($commandName . 'Command.as'), $command);
             if ($r === FALSE) {
                 return $error . ucfirst($commandName . 'Command.as');
             }
         }
     }
     return true;
 }
Beispiel #2
0
function recursive_copy($source, $destination)
{
    $counter = 0;
    if (substr($source, strlen($source), 1) != "/") {
        $source .= "/";
    }
    if (substr($destination, strlen($destination), 1) != "/") {
        $destination .= "/";
    }
    if (!is_dir($destination)) {
        makeDirs($destination);
    }
    $itens = listFiles($source);
    foreach ($itens as $id => $name) {
        if ($name[0] == "/") {
            $name = substr($name, 1);
        }
        if (is_file($source . $name)) {
            // file
            if ($name != "Thumbs.db") {
                $counter++;
                if (!copy($source . $name, $destination . $name)) {
                    echo "Error: " . $source . $name . " -> " . $destination . $name . "<br/>";
                } else {
                    safe_chmod($destination . $name, 0775);
                }
            } else {
                @unlink($source . $name);
            }
        } else {
            if (is_dir($source . $name)) {
                // dir
                if (!is_dir($destination . $name)) {
                    safe_mkdir($destination . $name);
                }
                $counter += recursive_copy($source . $name, $destination . $name);
            }
        }
    }
    return $counter;
}
Beispiel #3
0
 function save($info, $where, $overwrite)
 {
     //First create package hierarchy
     $package = str_replace('.', '/', $info['package']);
     if (!is_dir($where . '/' . $package)) {
         //Create the directory
         $attempt = makeDirs($where . '/' . $package);
         if ($attempt === FALSE) {
             return "could not create directory {$where}/{$package}";
         }
     }
     chdir($where . '/' . $package);
     //Put content
     $template = $this->format($info);
     if ($overwrite || !file_exists($info['class'] . '.as')) {
         $r = file_put_contents($info['class'] . '.as', $template);
         if ($r === FALSE) {
             return "Could not create file " . $info['class'];
         }
     }
     return TRUE;
 }
Beispiel #4
0
 function generateBackup($echo = false)
 {
     $maxLine = 5000;
     // largest line size
     $bck = CONS_PATH_BACKUP . $_SESSION['CODE'] . "/" . $this->dbname . ".sql";
     if (!is_dir(CONS_PATH_BACKUP . $_SESSION['CODE'] . "/")) {
         makeDirs(CONS_PATH_BACKUP . $_SESSION['CODE'] . "/");
     }
     if (is_file($bck)) {
         @unlink($bck);
     }
     $fd = fopen($bck, "wb");
     if ($fd) {
         $sql = "SELECT * FROM " . $this->dbname;
         $this->parent->dbo->query($sql, $r, $n);
         $baseLine = "INSERT INTO " . $this->dbname . " (";
         foreach ($this->fields as $fn => &$f) {
             $baseLine .= $fn . ",";
         }
         $baseLine = substr($baseLine, 0, strlen($baseLine) - 1) . ") VALUES (";
         $line = $baseLine;
         for ($c = 0; $c < $n; $c++) {
             $data = $this->parent->dbo->fetch_assoc($r);
             foreach ($this->fields as $fn => &$f) {
                 if ($f[CONS_XML_TIPO] == CONS_TIPO_INT || $f[CONS_XML_TIPO] == CONS_TIPO_FLOAT) {
                     // integer
                     $line .= (is_numeric($data[$fn]) ? $data[$fn] : "NULL") . ",";
                 } else {
                     if ($f[CONS_XML_TIPO] == CONS_TIPO_DATE || $f[CONS_XML_TIPO] == CONS_TIPO_DATETIME) {
                         // dates
                         $line .= ($data[$fn] != '' ? $data[$fn] : "NULL") . ",";
                     } else {
                         if ($f[CONS_XML_TIPO] == CONS_TIPO_LINK) {
                             // link, must get the link db type
                             // TODO: format the output for null data as well?
                             if ($this->parent->modules[$f[CONS_XML_MODULE]]->fields[$this->parent->modules[$f[CONS_XML_MODULE]]->keys[0]][CONS_XML_TIPO] == CONS_TIPO_INT) {
                                 $line .= (is_numeric($data[$fn]) ? $data[$fn] : "NULL") . ",";
                             } else {
                                 $line .= "\"" . addslashes_EX($data[$fn], true) . "\",";
                             }
                         } else {
                             // not integer
                             $line .= "\"" . addslashes_EX($data[$fn], true) . "\",";
                         }
                     }
                 }
             }
             $line = substr($line, 0, strlen($line) - 1) . ")";
             // removes ,
             if (strlen($line) > $maxLine) {
                 $line .= ";\n";
                 fwrite($fd, $line);
                 $line = $baseLine;
             } else {
                 $line .= ",(";
             }
         }
         if ($line != $baseLine) {
             $line = substr($line, 0, strlen($line) - 2) . ";\n";
             // removes ,(
             fwrite($fd, $line);
         }
         fclose($fd);
         if ($echo) {
             echo $line;
         }
     }
 }
Beispiel #5
0
function makeDirs($strPath)
{
    return is_dir($strPath) or makeDirs(dirname($strPath)) and mkdir($strPath);
}
function makeDirs($strPath, $mode = 0777)
{
    return is_dir($strPath) or makeDirs(dirname($strPath), $mode) and mkdir($strPath, $mode);
}
Beispiel #7
0
 function save_model()
 {
     # saves all XML data into cached serialized phps
     $ok = true;
     $theModules = array();
     $this->permissionTemplate = array();
     if (!is_dir(CONS_PATH_CACHE . $_SESSION['CODE'] . "/meta/")) {
         makeDirs(CONS_PATH_CACHE . $_SESSION['CODE'] . "/meta/");
     }
     foreach ($this->modules as $nome => $module) {
         $theModules[] = array($nome, $module->dbname, $module->plugins);
         $oModule = array($module->keys, $module->title, $module->fields, $module->order, $module->permissionOverride, $module->freeModule, $module->linker, $module->options);
         $ok = $ok && cWriteFile(CONS_PATH_CACHE . $_SESSION['CODE'] . "/meta/{$nome}.dat", serialize($oModule));
         $p = CONS_TOOLS_DEFAULTPERM;
         if ($module->permissionOverride != "") {
             for ($c = 0; $c < 9; $c++) {
                 if ($module->permissionOverride[$c] == "a") {
                     $p[$c] = "1";
                 } else {
                     if ($module->permissionOverride[$c] == "d") {
                         $p[$c] = "0";
                     }
                 }
             }
         }
         $p .= "00000000000000";
         // some random custom permissions
         $this->permissionTemplate[$nome] = $p;
     }
     // now add plugin templates
     foreach ($this->loadedPlugins as $pname => $plugin) {
         if ($plugin->moduleRelation == '') {
             $p = "000000000";
             // standard
             $pos = 9;
             foreach ($plugin->customPermissions as $ptag => $pi18n) {
                 $p .= "0";
                 $pos++;
             }
         }
         $this->permissionTemplate["plugin_" . $pname] = $p;
     }
     $ok = $ok && cWriteFile(CONS_PATH_CACHE . $_SESSION['CODE'] . "/meta/_modules.dat", serialize($theModules));
     $ok = $ok && cWriteFile(CONS_PATH_CACHE . $_SESSION['CODE'] . "/meta/_permissions.dat", serialize($this->permissionTemplate));
     if (!$ok) {
         $this->errorControl->raise(124);
     }
     return $ok;
 }
Beispiel #8
0
 if (!is_dir($destination)) {
     makeDirs($destination);
 }
 $destination .= "multiple_upload_" . $module->name . ".zip";
 $ok = storefile($_FILES['mup_file'], $destination, 'udef:zip');
 // process upload to this file
 if ($ok == 0) {
     // upload ok
     $zipFile = $destination;
     # prepare and clean up destination folder
     $destination = CONS_FMANAGER . "upload/mpu/";
     recursive_del($destination, true);
     # this will delete mpu!
     if (!is_dir($destination)) {
         # so recreate
         if (!makeDirs($destination)) {
             $ok = 9;
             $core->errorControl->raise(804, $core->langOut("mpu_error_mkdir"));
         }
     }
 }
 if ($ok == 0) {
     // no error in preparing /mpu
     $zHn = zip_open($zipFile);
     if (is_resource($zHn)) {
         $core->errorControl->raise('300', "Unzipping file...");
         $hadFolders = false;
         while ($zHn_file = zip_read($zHn)) {
             $zip_name = zip_entry_name($zHn_file);
             if (strpos($zip_name, '.') !== false) {
                 cWriteFile($destination . $zip_name, zip_entry_read($zHn_file, zip_entry_filesize($zHn_file)), false, true);
function validateAndSave($file)
{
    $result = array();
    $path = $file['name'];
    $ext = pathinfo($path, PATHINFO_EXTENSION);
    $file['name'] = $_POST['profile-code'] . '.' . strtolower($ext);
    if ($file['error'] !== UPLOAD_ERR_OK) {
        // file uploading errors: http://php.net/manual/en/features.file-upload.errors.php
        $exception = new UploadException($file['error']);
        $access = date("[Y/m/d H:i:s]");
        if ($file['error'] === UPLOAD_ERR_INI_SIZE || $file['error'] === UPLOAD_ERR_FORM_SIZE) {
            $result['status'] = 'ERR';
            $result['message'] = 'Please choose a smaller file!';
            error_log("{$access} UPLOAD_ERR({$file['error']}): {$exception->getMessage()}");
        } else {
            if ($file['error'] === UPLOAD_ERR_EXTENSION) {
                $result['status'] = 'ERR';
                $result['message'] = 'Invalid file format!';
                error_log("{$access} UPLOAD_ERR({$file['error']}): {$exception->{$message}}");
            } else {
                throw $exception;
            }
        }
    } else {
        if (!preg_match('/^image\\//', $file['type']) || !preg_match('/\\.(jpe?g|gif|png)$/i', $file['name']) || getimagesize($file['tmp_name']) === FALSE) {
            //then there is an error
            $result['status'] = 'ERR';
            $result['message'] = 'Invalid file format!';
        } else {
            if ($file['size'] > 1100000) {
                // 1Mb
                //if size is larger than what we expect
                $result['status'] = 'ERR';
                $result['message'] = 'Please choose a smaller file!';
            } else {
                if ($file['error'] != 0 || !is_uploaded_file($file['tmp_name'])) {
                    //if there is an unknown error or temporary uploaded file is not what we thought it was
                    $result['status'] = 'ERR';
                    $result['message'] = 'Unspecified error!';
                } else {
                    $upload_dir = PROFILE_PICTURE_UPLOAD_DIR;
                    $small_picture_dir = $upload_dir . DIRECTORY_SEPARATOR . PICTURE_SMALL_DIR;
                    $medium_picture_dir = $upload_dir . DIRECTORY_SEPARATOR . PICTURE_MEDIUM_DIR;
                    $large_picture_dir = $upload_dir . DIRECTORY_SEPARATOR . PICTURE_LARGE_DIR;
                    makeDirs($upload_dir);
                    makeDirs($small_picture_dir);
                    makeDirs($medium_picture_dir);
                    makeDirs($large_picture_dir);
                    //save file inside current directory using a safer version of its name
                    $filename = preg_replace('/[^\\w\\.\\- ]/', '', $file['name']);
                    $filename_jpg = preg_replace('/\\.(.+)$/', '', $filename) . '.jpg';
                    $save_path = $upload_dir . DIRECTORY_SEPARATOR . $filename;
                    //thumbnail name is like filename-thumb.jpg
                    $thumb_path = $upload_dir . DIRECTORY_SEPARATOR . preg_replace('/\\.(.+)$/', '', $filename) . '-cropped.jpg';
                    $small_picture_path = $small_picture_dir . DIRECTORY_SEPARATOR . $filename_jpg;
                    $medium_picture_path = $medium_picture_dir . DIRECTORY_SEPARATOR . $filename_jpg;
                    $large_picture_path = $large_picture_dir . DIRECTORY_SEPARATOR . $filename_jpg;
                    if (!deleteFile($small_picture_path . '.deleted') or !deleteFile($medium_picture_path . '.deleted') or !deleteFile($large_picture_path . '.deleted') or !move_uploaded_file($file['tmp_name'], $save_path) or !crop($save_path, $thumb_path, $_POST['x'], $_POST['y'], $_POST['w'], $_POST['h']) or !resize($thumb_path, $small_picture_path, PICTURE_SMALL_SIZE) or !resize($thumb_path, $medium_picture_path, PICTURE_MEDIUM_SIZE) or !resize($thumb_path, $large_picture_path, PICTURE_LARGE_SIZE)) {
                        $result['status'] = 'ERR';
                        $result['message'] = 'Unable to save file!';
                    } else {
                        //everything seems OK
                        $result['status'] = 'OK';
                        $result['message'] = 'Avatar changed successfully!';
                        //include new thumbnails `url` in our result and send to browser
                        $result['url'] = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/' . $large_picture_path;
                    }
                }
            }
        }
    }
    return $result;
}
     $_REQUEST[$key] = stripslashes($val);
 }
 $pi = pathinfo($_FILES['userfile']['name']);
 if ($_FILES['userfile']['name'] == '') {
     $output .= "\n\t" . '<p class="errors">' . plog_tr('No filename specified') . '!</p>' . "\n";
 } else {
     if (strtolower($pi['extension']) == 'zip') {
         // Let's decompress the zip file into the 'plog-content/uploads/' folder and then redirect the user to plog-import.php
         include PLOGGER_DIR . 'plog-includes/lib/pclzip-2-4/pclzip.lib.php';
         // Zip file to extract
         $archive = new PclZip($_FILES['userfile']['tmp_name']);
         // Create a temporary folder in 'plog-content/uploads/' based on the .zip file name
         $zipname = strtolower(sanitize_filename(substr($_FILES['userfile']['name'], 0, -4)));
         $zipdir = $config['basedir'] . 'plog-content/uploads/' . $zipname;
         $zipdirkey = md5($zipdir);
         $zipresult = makeDirs($zipdir);
         if (is_safe_mode()) {
             chmod_ftp($zipdir, 0777);
         }
         // Extract to 'plog-content/uploads/' folder
         $results = $archive->extract(PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_PATH, $zipdir);
         if (is_safe_mode()) {
             chmod_ftp($zipdir);
         }
         if ($results == 0) {
             // Failed
             $output .= "\n\t" . '<p class="errors">' . plog_tr('Error') . ': ' . $archive->errorInfo(true) . '</p>' . "\n";
         } else {
             // Unzip succeeded - doesn't necessarily mean that saving the images succeeded
             $errors = array();
             foreach ($results as $r) {
function fix_open_perms($dirs, $action = 'rename')
{
    if (!empty($dirs)) {
        foreach ($dirs as $key => $dir) {
            if ($action == 'delete') {
                kill_dir(PLOGGER_DIR . 'plog-content/' . $key);
            } else {
                @rename(PLOGGER_DIR . 'plog-content/' . $key, PLOGGER_DIR . 'plog-content/' . $key . '-old');
            }
            makeDirs(PLOGGER_DIR . 'plog-content/' . $key);
        }
    }
}
Beispiel #12
0
 function addCachedContent($tag, $content, $shared = false)
 {
     if ($content == '' || $content === false) {
         return;
     }
     // we don't take empty caches, sorry
     $tag = removeSimbols($this->cacheuid($shared) . $tag, true, false);
     // feel free to use memcached on the $shared mode instead of files ;)
     if ($shared) {
         $file = CONS_PATH_CACHE . $_SESSION["CODE"] . "/caches/{$tag}.cache";
         $data = array('time' => date("Y-m-d H:i:s"), 'payload' => $content);
         if (!is_dir(CONS_PATH_CACHE . $_SESSION['CODE'] . "/caches/")) {
             makeDirs(CONS_PATH_CACHE . $_SESSION['CODE'] . "/caches/");
         }
         cWriteFile($file, serialize($data));
     } else {
         if (!isset($_SESSION[CONS_SESSION_CACHE])) {
             $_SESSION[CONS_SESSION_CACHE] = array();
         }
         $_SESSION[CONS_SESSION_CACHE][$tag] = array('time' => date("Y-m-d H:i:s"), 'payload' => $content);
     }
 }
Beispiel #13
0
-*/
$domains = cReadFile(CONS_PATH_SETTINGS . "domains");
if (!$domains) {
    $this->errorControl->raise(100);
}
$domains = explode("\n", str_replace("\r", "", preg_replace("/(\t| ){1,}/", " ", $domains)));
$domainList = array();
$gotdomain = false;
foreach ($domains as $dline) {
    if (strlen($dline) > 0 && $dline[0] != "#") {
        $dline = explode(" ", $dline);
        if (count($dline) == 2) {
            $thisdomains = explode(",", $dline[1]);
            foreach ($thisdomains as $td) {
                $td = trim($td);
                if ($td != "") {
                    $domainList[$td] = $dline[0];
                    if (!$gotdomain && ($td == $this->domain || $td == "*")) {
                        $_SESSION["CODE"] = $dline[0];
                        $gotdomain = true;
                    }
                }
            }
        }
    }
}
if (!is_dir(CONS_PATH_CACHE)) {
    makeDirs(CONS_PATH_CACHE);
}
cWriteFile(CONS_PATH_CACHE . "domains.dat", serialize($domainList));
return $domainList;
Beispiel #14
0
        }
    }
    $nb = array();
    if (isset($tree->data['id'])) {
        foreach ($tree->branchs as &$branch) {
            if ($branch !== false && fillInfo($branch, $core, $path . $tree->data['id'] . '/')) {
                $nb[] = $branch;
            }
        }
    }
    $tree->branchs = $nb;
    return true;
}
$newTree = new ttree();
if (!is_dir(CONS_FMANAGER)) {
    makeDirs(CONS_FMANAGER);
}
$newTree->getFolderTree(CONS_FMANAGER, false, $dir, "", array("_thumbs", "_undodata"));
// thumbs is the fckfinder folder
fillInfo($newTree, $core);
$core->template->getTreeTemplate("_dirs", "_subdirs", $newTree, "/", "/");
if ($dir == "") {
    $dir = "/";
}
$canEdit = $this->canEdit($dir);
if (isset($core->storage['error']) || isset($core->storage['dir'])) {
    if (!isset($core->storage['dir'])) {
        $core->storage['dir'] = "";
    }
    $core->template->assign('script', "<script type=\"text/javascript\">alert(\"" . $core->storage['error'] . "\");canChange=" . ($canEdit ? "true" : "false") . ";showFolder(\"" . $core->storage['dir'] . "\");</script>");
} else {
function upgrade_images($num, $list)
{
    $output = array();
    $errors = array();
    $count = 0;
    $list = array_slice($list, 0, $num);
    foreach ($list as $image) {
        if (!empty($image['id'])) {
            // Work on the images - move physical file, create directory if necessary and update path in database
            if (!makeDirs(PLOGGER_DIR . 'plog-content/images/' . dirname($image['new_path'] . '/'))) {
                $errors[] = plog_tr('Could not create directory') . ': ' . PLOGGER_DIR . 'plog-content/images/' . $image['new_path'];
            } else {
                if (!move_this(PLOGGER_DIR . $image['old_path'], PLOGGER_DIR . 'plog-content/images/' . $image['new_path'])) {
                    $errors[] = plog_tr('Could not move file') . ': ' . PLOGGER_DIR . $image['old_path'];
                } else {
                    @chmod(PLOGGER_DIR . $new_path, PLOGGER_CHMOD_DIR);
                    $output[] = sprintf(plog_tr('Moved file %s -> %s'), '<strong>' . $image['old_path'] . '</strong>', '<strong>' . 'plog-content/images/' . $image['new_path'] . '</strong>');
                    // Update database
                    $sql = "UPDATE " . PLOGGER_TABLE_PREFIX . "pictures SET path = '" . mysql_real_escape_string($image['new_path']) . "' WHERE id = '" . $image['id'] . "'";
                    run_query($sql);
                    // Generate a new small thumbnail after database has been updated in case script times out
                    $thumbpath = generate_thumb($image['new_path'], $image['id'], THUMB_SMALL);
                    $count++;
                }
            }
        } else {
            if (!empty($image['uploads'])) {
                // Work on the uploads - move physical file and create directory in the uploads folder if necessary and update path in database
                if (!makeDirs(PLOGGER_DIR . dirname($image['new_path'] . '/'))) {
                    $errors[] = plog_tr('Could not create directory') . ': ' . PLOGGER_DIR . $image['new_path'];
                } else {
                    if (!move_this(PLOGGER_DIR . $image['old_path'], PLOGGER_DIR . $image['new_path'])) {
                        $errors[] = plog_tr('Could not move file') . ': ' . PLOGGER_DIR . $image['old_path'];
                    } else {
                        @chmod(PLOGGER_DIR . $new_path, PLOGGER_CHMOD_DIR);
                        $output[] = sprintf(plog_tr('Moved file %s -> %s'), '<strong>' . $image['old_path'] . '</strong>', '<strong>' . $image['new_path'] . '</strong>');
                        $count++;
                    }
                }
            } else {
                if (!empty($image['container'])) {
                    // Create the collection and album directory structure
                    if (!makeDirs(PLOGGER_DIR . $image['new_path'] . '/')) {
                        $errors[] = plog_tr('Could not create directory') . ': ' . PLOGGER_DIR . $image['new_path'];
                    } else {
                        $output[] = sprintf(plog_tr('Created directory %s'), '<strong>' . $image['new_path'] . '</strong>');
                        $count++;
                    }
                }
            }
        }
    }
    return array('errors' => $errors, 'output' => $output, 'count' => $count);
}
Beispiel #16
0
function generate_thumb($path, $prefix, $type = THUMB_SMALL)
{
    global $config, $thumbnail_config;
    $thumb_config = $thumbnail_config[$type];
    // For relative paths assume that they are relative to 'plog-content/images/' directory,
    // otherwise just use the given path
    if (file_exists($path)) {
        $source_file_name = $path;
        if ($type == THUMB_THEME) {
            $cache_path = 'themes/';
        } else {
            $cache_path = 'uploads/';
        }
    } else {
        $source_file_name = $config['basedir'] . 'plog-content/images/' . SmartStripSlashes($path);
        $cache_path = dirname(SmartStripSlashes($path)) . '/' . $thumb_config['type'] . '/';
    }
    // The file might have been deleted and since phpThumb dies in that case
    // try to do something sensible so that the rest of the images can still be seen
    // There is a problem in safe mode - if the script and picture file are owned by
    // different users, then the file cannot be read.
    if (!is_readable($source_file_name)) {
        return false;
    }
    $imgdata = @getimagesize($source_file_name);
    if (!$imgdata) {
        // Unknown image format, bail out
        // Do we want to have video support in the Plogger core?
        //return 'plog-graphics/thumb-video.gif';
        return false;
    }
    // Attributes of original image
    $orig_width = $imgdata[0];
    $orig_height = $imgdata[1];
    // XXX: food for thought - maybe we can return URL to some kind of error image
    // if this function fails?
    $base_filename = sanitize_filename(basename($path));
    if ($thumb_config['disabled']) {
        return $config['gallery_url'] . 'plog-content/images/' . $path;
    }
    $prefix = $prefix . '-';
    $thumbpath = $config['basedir'] . 'plog-content/thumbs/' . $cache_path . $prefix . $base_filename;
    $thumburl = $config['gallery_url'] . 'plog-content/thumbs/' . $cache_path . $prefix . $base_filename;
    // If thumbnail file already exists and is generated after data for a thumbnail type
    // has been changed, then we assume that the thumbnail is valid.
    if (file_exists($thumbpath)) {
        $thumbnail_timestamp = @filemtime($thumbpath);
        if ($thumb_config['timestamp'] < $thumbnail_timestamp) {
            return $thumburl;
        }
    }
    // Create the same directory structure as the image under plog-content/thumbs/
    include_once PLOGGER_DIR . 'plog-admin/plog-admin-functions.php';
    if (!makeDirs(dirname($thumbpath))) {
        return sprintf(plog_tr('Error creating path %s'), dirname($thumbpath));
    }
    // If dimensions of source image are smaller than those of the requested
    // thumbnail, then use the original image as thumbnail unless fullsize images are disabled
    if ($orig_width <= $thumb_config['size'] && $orig_height <= $thumb_config['size']) {
        // if fullsize image access is disabled, copy the file to the thumbs folder
        if ($config['allow_fullpic'] == 0) {
            copy($source_file_name, $thumbpath);
            return $thumburl;
            // otherwise return the original file path
        } else {
            return $config['gallery_url'] . 'plog-content/images/' . $path;
        }
    }
    // No existing thumbnail found or thumbnail config has changed,
    // generate new thumbnail file
    require_once PLOGGER_DIR . 'plog-includes/lib/phpthumb/phpthumb.class.php';
    $phpThumb = new phpThumb();
    // Set data
    $phpThumb->setSourceFileName($source_file_name);
    switch ($thumb_config['resize_option']) {
        // Resize to width
        case 0:
            $phpThumb->w = $thumb_config['size'];
            break;
            // Resize to height
        // Resize to height
        case 1:
            $phpThumb->h = $thumb_config['size'];
            break;
            // Use square thumbnails
        // Use square thumbnails
        case 3:
            $phpThumb->zc = 1;
            $phpThumb->h = $thumb_config['size'];
            $phpThumb->w = $thumb_config['size'];
            break;
            // Resize to longest side
        // Resize to longest side
        case 2:
        default:
            if ($imgdata[0] > $imgdata[1]) {
                $phpThumb->w = $thumb_config['size'];
            } else {
                $phpThumb->h = $thumb_config['size'];
            }
    }
    $phpThumb->q = $config['compression'];
    if ($type == THUMB_NAV) {
        $phpThumb->zc = 1;
        $phpThumb->h = $thumb_config['size'];
        $phpThumb->w = $thumb_config['size'];
    }
    if ($type == THUMB_THEME) {
        $phpThumb->w = $thumb_config['size'];
    }
    // Set options (see phpThumb.config.php)
    // here you must preface each option with "config_"
    // Disable ImageMagick - set to false for localhost testing
    // ImageMagick seems to cause some issues on localhost using FF or Chrome
    $phpThumb->config_prefer_imagemagick = false;
    // We want to use the original image for thumbnail creation, not the EXIF stored thumbnail
    $phpThumb->config_use_exif_thumbnail_for_speed = false;
    // Set error handling (optional)
    $phpThumb->config_error_die_on_error = false;
    // If safe_mode enabled, open the permissions first
    if (is_safe_mode()) {
        $thumb_path = dirname($thumbpath) . '/';
        chmod_ftp($thumb_path, 0777);
    }
    // Generate & output thumbnail
    if ($phpThumb->GenerateThumbnail()) {
        $phpThumb->RenderToFile($thumbpath);
    } else {
        // do something with debug/error messages
        die('Failed: ' . implode("\n", $phpThumb->debugmessages));
    }
    @chmod($thumbpath, PLOGGER_CHMOD_FILE);
    // If safe_mode enabled, close the permissions back down to the default
    if (is_safe_mode()) {
        chmod_ftp($thumb_path);
    }
    return $thumburl;
}
function makeDirs($path, $mode = PLOGGER_CHMOD_DIR)
{
    // Creates directory tree recursively
    if (is_safe_mode()) {
        return is_dir($path) or makeDirs(dirname($path), $mode) and makeDirs_ftp($path);
    } else {
        return is_dir($path) or makeDirs(dirname($path), $mode) and mkdir($path, $mode) and configure_blank_index($path) and chmod($path, $mode);
    }
}