示例#1
0
function check_step()
{
    global $err;
    if (check_write(SETUPTEMP_FILE, 2)) {
        $r = fs_mkdir(CACHE_DIR);
        $r &= fs_mkdir(INDEX_DIR);
        $r &= fs_copy(CONFIG_DEFAULT, CONFIG_FILE);
        $r &= fs_copy(FP_DEFAULTS . 'plugins.conf.php', CONFIG_DIR . 'plugins.conf.php');
        $r &= fs_copy(FP_DEFAULTS . 'widgets.conf.php', CONFIG_DIR . 'widgets.conf.php');
        //$r &=	create_content();
        return true;
    }
    $err[] = 'Write error';
    return false;
}
示例#2
0
function io_write_file($filename, $data)
{
    @umask(0);
    $dir = dirname($filename);
    if (fs_mkdir($dir)) {
        $f = fopen($filename, "w");
        if ($f) {
            if (!flock($f, LOCK_EX)) {
                return -1;
            }
            $length = strlen($data);
            $done = fwrite($f, $data);
            flock($f, LOCK_UN);
            fclose($f);
            @chmod($filename, FILE_PERMISSIONS);
            //returns true on success
            return $length == $done;
        }
    }
    return false;
}
示例#3
0
 function onupload()
 {
     $success = false;
     if (!file_exists(IMAGES_DIR)) {
         fs_mkdir(IMAGES_DIR);
     }
     if (!file_exists(ATTACHS_DIR)) {
         fs_mkdir(ATTACHS_DIR);
     }
     $imgs = array('.jpg', '.gif', '.png', '.jpeg');
     //intentionally
     //I've not put BMPs
     $uploaded_files = array();
     foreach ($_FILES["upload"]["error"] as $key => $error) {
         if ($error == UPLOAD_ERR_OK) {
             $tmp_name = $_FILES["upload"]["tmp_name"][$key];
             $name = $_FILES["upload"]["name"][$key];
             $dir = ATTACHS_DIR;
             $ext = strtolower(strrchr($name, '.'));
             if (in_array($ext, $imgs)) {
                 $dir = IMAGES_DIR;
             }
             $name = sanitize_title(substr($name, 0, -strlen($ext))) . $ext;
             $target = "{$dir}/{$name}";
             @umask(022);
             $success = move_uploaded_file($tmp_name, $target);
             @chmod($target, 0766);
             $uploaded_files[] = $name;
             // one failure will make $success == false :)
             $success &= $success;
         }
     }
     if ($uploaded_files) {
         $this->smarty->assign('success', $success ? 1 : -1);
         sess_add('admin_uploader_files', $uploaded_files);
     }
     return 1;
 }
示例#4
0
/**
 *
 * @param array entry 	contents
 * @param string|null 	entry id, null if can be deducted from the date field of $entry; 
 * 						defaults to null
 *
 * @param bool 			updates entry index; defaults to true	
 *
 *
 * @return integer 		-1 failure while storing preliminar draft, abort. Index not touched.
 * 						-2 index updated succesfully, but draft doesn't exist anymore 
 * 						   (should never happen!) OR
 * 						   failure while trying to move draft to entry path, draft does not exist anymore
 * 						   index not touched
 * 						-3 error while moving draft still exists, index written succesfully but rolled back
 * 						-4 failure while saving to index, aborted (draft still exists)
 *
 *
 */
function entry_save($entry, $id = null, $update_index = true)
{
    // PHASE 1 : prepare entry
    if (!$id) {
        if (!@$entry['date']) {
            $entry['date'] = date_time();
        }
        $id = bdb_idfromtime(BDB_ENTRY, $entry['date']);
    }
    // PHASE 2 : Store
    // secure data as DRAFT
    // (entry is also implicitly entry_prepare()'d here)
    $ret = draft_save($entry, $id);
    do_action('publish_post', $id, $entry);
    if ($ret === false) {
        return -1;
        // FAILURE: ABORT
    }
    // PHASE 3 : Update index
    $delete_cats = array();
    $all_cats = @$entry['categories'];
    $update_title = true;
    if ($old_entry = entry_parse($id)) {
        if ($all_cats) {
            $delete_cats = array_diff($old_entry['categories'], $all_cats);
        }
        $all_cats = $all_cats ? array_merge($all_cats, $old_entry['categories']) : $old_entry['categories'];
        $update_title = $entry['subject'] != $old_entry['subject'];
    }
    /*
    echo 'old';
    print_r($old_entry['categories']);
    echo 'new';
    print_r($entry['categories']);
    echo 'del';
    print_r($delete_cats);
    echo 'all';
    print_r($all_cats);
    */
    $INDEX =& entry_init();
    $ok = $update_index ? $INDEX->add($id, $entry, $delete_cats, $update_title) : true;
    // PHASE 4 : index updated; let's move back the entry
    if ($ok) {
        $entryd = entry_dir($id, true);
        $entryf = $entryd . $id . EXT;
        $draftf = draft_exists($id);
        if ($draftf === false) {
            // this should never happen!
            if ($update_index) {
                $INDEX->delete($id, $all_cats);
            }
            return -2;
        }
        fs_delete($entryf);
        fs_mkdir($entryd);
        $ret = rename($draftf, $entryf);
        if (!$ret) {
            if (draft_exists($id)) {
                // rollback changes in the index
                // (keep the draft file)
                if ($update_index) {
                    $INDEX->delete($id, $all_cats);
                }
                return -3;
            } else {
                return -2;
            }
        } else {
            // SUCCESS : delete draft, move comments along
            draft_to_entry($id);
            return $id;
        }
    }
    return -4;
}
示例#5
0
/**
 *
 * plugin_thumb_create
 *
 * creates a thumbnail and caches the thumbnail in IMAGES_DIR/.thumb
 *
 * @param string $fpath string with filepath
 * @param array $infos infos from getimagesize($fpath) function
 * @param int $new_width
 * @param int $new_height
 *
 * @return array array(string $thumbpath, int $thumbwidth, int $thumbheight)
 *
 */
function plugin_thumb_create($fpath, $infos, $new_width, $new_height)
{
    if (!defined('PLUGIN_THUMB_ENABLED')) {
        return array();
    }
    if (!file_exists($fpath)) {
        return array();
    }
    if (!($new_width && $new_height)) {
        trigger_error("Size can't be 0 but got width={$new_width} height={$new_height}\n", E_USER_WARNING);
        return;
    }
    $thumbname = basename($fpath);
    $thumbdir = dirname($fpath) . '/' . THUMB_DIR;
    $thumbpath = $thumbdir . '/' . $thumbname;
    if (file_exists($thumbpath)) {
        $oldthumbinfo = getimagesize($thumbpath);
        if ($new_width == $oldthumbinfo[0]) {
            // already scaled
            return array($thumbpath, $new_width, $new_height);
        }
    }
    @fs_mkdir($thumbdir);
    // we support only jpeg's, png's and gif's
    switch ($infos[2]) {
        case 1:
            $image = imagecreatefromgif($fpath);
            break;
        case 2:
            $image = imagecreatefromjpeg($fpath);
            break;
        case 3:
            $image = imagecreatefrompng($fpath);
    }
    //$image = imagecreatefromgd2 ($fpath);
    // create empty scaled and copy(resized) the picture
    $scaled = imagecreatetruecolor($new_width, $new_height);
    /*
     * If gif or png preserve the alpha channel
     *
     * Added by Piero VDFN
     * Kudos to http://www.php.net/manual/en/function.imagecopyresampled.php#104028
     */
    if ($infos[2] == 1 || $infos[2] == 3) {
        imagecolortransparent($scaled, imagecolorallocatealpha($scaled, 0, 0, 0, 127));
        imagealphablending($scaled, false);
        imagesavealpha($scaled, true);
        $output = $infos[2] == 3 ? 'png' : 'gif';
    } else {
        $output = 'jpg';
    }
    imagecopyresampled($scaled, $image, 0, 0, 0, 0, $new_width, $new_height, $infos[0], $infos[1]);
    if ($output == 'png') {
        imagepng($scaled, $thumbpath);
    } elseif ($output == 'gif') {
        imagegif($scaled, $thumbpath);
    } else {
        imagejpeg($scaled, $thumbpath);
    }
    @chmod($thumbpath, FILE_PERMISSIONS);
    return array($thumbpath, $new_width, $new_height);
}
示例#6
0
 function dodo($do)
 {
     switch ($do) {
         case 'rebuild':
             if (substr(INDEX_DIR, -1) == '/') {
                 $oldidx = substr(INDEX_DIR, 0, -1);
             }
             $movedir = $oldidx . time();
             header('Content-Type: text/plain');
             echo "ENTERING LOWRES MODE\n\n";
             if (file_exists(INDEX_DIR)) {
                 echo "BACKUP INDEX to {$movedir}\n";
                 $ret = @rename($oldidx, $movedir);
                 if (!$ret) {
                     trigger_error('Cannot backup old index. STOP.', E_USER_ERROR);
                 }
             }
             fs_mkdir(INDEX_DIR);
             new s_entry_crawler();
             exit("\nDONE \nPlease, select the back arrow in your browser");
             return PANEL_NOREDIRECT;
         case 'restorechmods':
             $this->smarty->assign('files', fs_chmod_recursive());
             $this->smarty->assign('success', 1);
             return PANEL_NOREDIRECT;
         case 'purgetplcache':
             $tpldel = new tpl_deleter();
             unset($tpldel);
             $this->smarty->cache_dir = CACHE_DIR . 'cache/';
             $this->smarty->caching = 0;
             $this->smarty->clear_all_cache();
             $this->smarty->clear_compiled_tpl();
             $this->smarty->compile_check = true;
             $this->smarty->force_compile = true;
             $this->smarty->assign('success', 1);
             if (!file_exists(CACHE_DIR)) {
                 fs_mkdir(CACHE_DIR);
             }
             return PANEL_NOREDIRECT;
         case 'phpinfo':
             ob_start();
             phpinfo();
             $info = ob_get_contents();
             ob_end_clean();
             $this->smarty->assign('phpinfo', preg_replace('%^.*<body>(.*)</body>.*$%ms', '$1', $info));
             return PANEL_NOREDIRECT;
     }
 }
示例#7
0
/**
 * function fs_mkdir
 *
 * <p>Function from : {@link http://www.php.net/function.mkdir.php}</p>
 * 
 * <p>Recursively creates dirs.</p>
 * <p>Returns true on success, else false</p>
 *
 * @param string $path Directory or directories to create
 * @param int $mode octal mode value; same as UNIX chmod; defaults to 0777 (rwrwrw);
 * @return bool
 *
 * @todo cleanup & check bool return value
 *
 */
function fs_mkdir($dir, $mode = DIR_PERMISSIONS)
{
    if (is_dir($dir) || @mkdir($dir, $mode)) {
        @chmod($dir, $mode);
        return TRUE;
    }
    if (!fs_mkdir(dirname($dir), $mode)) {
        return FALSE;
    }
    return @mkdir($dir, $mode) && @chmod($dir, $mode);
}