Beispiel #1
0
function draft_save(&$entry, $id = null, $update_index = false, $update_date = false)
{
    if (!$id) {
        $id = bdb_idfromtime('entry', $entry['date']);
    }
    $ed = entry_dir($id);
    $dd = draft_dir($id);
    if (file_exists($ed . EXT)) {
        // move collateral files
        @rename($ed, $dd);
        if ($update_index) {
            // delete normal entry
            fs_delete($ed . EXT);
            // remove from normal flow
            $o =& entry_init();
            $o->delete($id, null);
        }
    }
    $new_entry = entry_prepare($entry);
    if ($new_entry['categories']) {
        $new_entry['categories'] = implode(',', $entry['categories']);
    } else {
        unset($new_entry['categories']);
    }
    $string = utils_kimplode($new_entry);
    if (!io_write_file($dd . EXT, $string)) {
        return false;
    } else {
        return $id;
    }
    return false;
}
Beispiel #2
0
/**
 * function system_save
 * 
 * This function saves a list of variables provided after $file
 * encapsulated in an array where KEY is the var name
 * in a php file.
 *
 * Example usage:
 * <code>
 * <?php
 * // Let's suppose you want to save an array called $my_arr
 *  // in file $my_file
 * $my_file = 'path/to/file'
 * $my_arr = array ('val1', 'val2', 'val3');
 * $save_arr = array('$my_arr' => $my_arr); //same as: $save_arr['$my_arr'] = $my_arr);
 * system_save($my_file, $my_arr);
 * // now the file $my_file will contain the following lines:
 *  // global $my_arr;
 * // $my_arr = array (
 * //           '$my_arr' => val1', 
 * //           '$my_arr' => 'val2', 
 * //           '$my_arr' => 'val3'
 * //           );
 * ?>
 * </code>
 *
 * @param string $file file path where $array contents will be saved
 * @array $var_list list of vars to be saved
 * @return bool
 *
 * @see config_save, config_load
 *
 */
function system_save($file, $array)
{
    //if ( ( $numargs = func_num_args() ) > 1) {
    $string = "<?php\n\n";
    //$arg_list = func_get_args();
    foreach ($array as $key => $arg) {
        //$vname = utils_vname ($arg);
        //var_export($arg);
        $s = "\${$key} = " . var_export($arg, true) . ";\n";
        $string .= $s;
    }
    $string .= "\n?>";
    return io_write_file($file, $string);
    //} else die('Wrong number of parameters!');
}
Beispiel #3
0
 function _lock_acquire($exclusive = true, $cat = 0)
 {
     if (file_exists($this->_lock_file)) {
         trigger_error("Could not acquire write lock on INDEX. " . "Didn't I told you FlatPress is not designed for concurrency, already? ;) " . "Don't worry: your entry has been saved as draft!", E_USER_WARNING);
         return false;
     }
     // simulates atomic write by writing to a file, then moving in place
     $tmp = $this->_lock_file . ".tmp";
     if (io_write_file($tmp, 'dummy')) {
         if (rename($tmp, $this->_lock_file)) {
             return true;
         }
     }
     return false;
 }
Beispiel #4
0
function getstep(&$id)
{
    global $err;
    $STEPS = array('locked', 'step1', 'step2', 'step3');
    $MAXST = count($STEPS) - 1;
    $i = 0;
    $setupid = null;
    if (!file_exists(LOCKFILE)) {
        $setupid = setupid();
        if (!$setupid) {
            die('Setup is running');
        }
        if (!file_exists(SETUPTEMP_FILE)) {
            if (empty($_POST)) {
                $i = 0;
            } else {
                $i = 1;
            }
        } else {
            $x = explode(',', io_load_file(SETUPTEMP_FILE));
            if ($x[0] != $setupid) {
                die('Setup is running: if you are the owner, you can delete ' . SETUPTEMP_FILE . ' to restart');
            }
            $i = intval($x[1]);
        }
        @(include "./setup/lib/{$STEPS[$i]}.lib.php");
        if (!function_exists('check_step')) {
            function check_step()
            {
                return true;
            }
        }
        if (check_step()) {
            ++$i;
            if ($i >= $MAXST) {
                fs_delete(SETUPTEMP_FILE);
                io_write_file(LOCKFILE, "locked");
            } else {
                if ($i > 0 && !@io_write_file(SETUPTEMP_FILE, "{$setupid},{$i}")) {
                    $err[] = 'Write error';
                }
            }
        }
    }
    $id = $STEPS[$i];
    return $i;
}
Beispiel #5
0
function static_save($entry, $id, $oldid = null)
{
    if (!static_isvalid($id)) {
        return false;
    }
    $fname = STATIC_DIR . $id . EXT;
    $entry['content'] = apply_filters('content_save_pre', $entry['content']);
    $entry['subject'] = apply_filters('title_save_pre', $entry['subject']);
    $str = utils_kimplode($entry);
    if (io_write_file($fname, $str)) {
        if ($oldid && $id != $oldid && ($fname = static_exists($oldid))) {
            $succ = static_delete($oldid);
            return $succ !== false && $succ !== 2;
        }
        return true;
    }
    return false;
}
 function onsave()
 {
     $str = stripslashes(@$_POST['content']);
     if (!$str) {
         $this->smarty->assign('success', -1);
         return PANEL_REDIRECT_CURRENT;
     }
     $tmp = $str;
     $tmp = str_replace('<?php', '', $tmp);
     $tmp = str_replace('<?', '', $tmp);
     $tmp = str_replace('?>', '', $tmp);
     if (@eval($tmp) !== false) {
         $success = io_write_file(CONFIG_DIR . 'widgets.conf.php', $str);
     } else {
         $success = false;
     }
     $this->smarty->assign('success', $success ? 1 : -1);
     return PANEL_REDIRECT_CURRENT;
 }
 function onsave()
 {
     $str = stripslashes(trim(@$_POST['content']));
     if ($str) {
         //$success = io_write_file(CONTENT_DIR . 'categories.txt', $str);
         $success = entry_categories_encode($str);
         $ret = 1;
         if ($success <= 0) {
             if ($success == -1) {
                 $ret = -3;
             } elseif ($success == 0) {
                 $ret = -1;
             }
         } else {
             $success = io_write_file(CONTENT_DIR . 'categories.txt', $str) ? -1 : 1;
         }
         $this->smarty->assign('success', $ret);
     } else {
         $this->smarty->assign('success', -1);
     }
     return PANEL_REDIRECT_CURRENT;
 }
function plugin_postviews_calc($id, $calc)
{
    $dir = entry_dir($id);
    if (!$dir) {
        return;
    }
    $f = $dir . '/view_counter' . EXT;
    $v = io_load_file($f);
    if ($v === false) {
        $v = 0;
    } elseif ($v < 0) {
        // file was locked. Do not increase views.
        // actually on file locks system should hang, so
        // this should never happen
        $v = 0;
        $calc = false;
    }
    if ($calc && !user_loggedin()) {
        $v++;
        io_write_file($f, $v);
    }
    return $v;
}
Beispiel #9
0
/**
 * function bdb_save_comment
 *
 * <p>Saves the content of the $comment array, associating it to the entry-ID $id.</p>
 * <p>$comment must be formatted as the one returned by {@link bdb_parse_entry()}.</p>
 * <p>Returns true on success, or false on failure</p>
 *
 * @param string $id string formatted like "prefixYYMMDD-HHMMSS"
 * @param array $comment array formatted as the one returned by {@link bdb_parse_entry()}
 * @return bool
 * 
 * @see bdb_parse_entry()
 */
function comment_save($id, $comment)
{
    comment_clean($comment);
    $comment = array_change_key_case($comment, CASE_UPPER);
    $comment_dir = bdb_idtofile($id, BDB_COMMENT);
    if (!isset($comment['DATE'])) {
        $comment['DATE'] = date_time();
    }
    $id = bdb_idfromtime(BDB_COMMENT, $comment['DATE']);
    $f = $comment_dir . $id . EXT;
    $str = utils_kimplode($comment);
    if (io_write_file($f, $str)) {
        return $id;
    }
    return false;
}
Beispiel #10
0
function fs_copy($source, $dest)
{
    if ($contents = io_load_file($source)) {
        return io_write_file($dest, $contents);
    }
    return false;
}
 function onsubmit()
 {
     global $fp_config;
     if (isset($_POST['saveopt'])) {
         $this->_config['mode'] = (int) $_POST['mode'];
         plugin_addoption('prettyurls', 'mode', $this->_config['mode']);
         if (plugin_saveoptions()) {
             $this->smarty->assign('success', 2);
         } else {
             $this->smarty->assign('success', -2);
         }
     }
     if (isset($_POST['htaccess-submit'])) {
         if (!empty($_POST['htaccess']) && io_write_file(ABS_PATH . '.htaccess', $_POST['htaccess'])) {
             $this->smarty->assign('success', 1);
         } else {
             $this->smarty->assign('success', -1);
         }
     }
     return 2;
 }
Beispiel #12
0
function install_step5()
{
    include 'preconfig.inc';
    install_init_section();
    install_init_authority();
    $function_name = 'preconfig_' . pp('preconfig');
    $function_name();
    widget_init_default(true);
    $title = tt('Happy Ending') . ' : ' . tt('Ximple has been successfully installed');
    $page = '<h2>' . $title . '</h2>';
    $page .= install_finish_message();
    io_write_file(FILES_PATH . 'state/install', "");
    $state_dir = ROOT_PATH . '/files/state/1/';
    if (!is_dir($state_dir)) {
        mkdir($state_dir);
    }
    io_write_file($state_dir . 'product', "");
    return array(tt('Happy Ending'), $page);
}
/**
 * function plugin_lastcomments_cache
 * 
 * comment cache is a reverse queue; we put
 * element on the top, and we delete elements
 * from bottom; this is because the output
 * string is created reading queuing from top to bottom.
 * All this headache stuff just to say that
 * in the end the widget will show up elements ordered
 * from newer to older :P
 * 
 * @param $entryid string entry id i.e. entryNNNNNN-NNNNNN
 * @param $comment array where $comment[0] is $commentid i.e. commentNNNNNN-NNNNNN
 *			 and $comment[1] is the actual content array 
 */
function plugin_lastcomments_cache($entryid, $comment)
{
    // max num of chars per comment
    $CHOP_AT = 30;
    list($id, $content) = $comment;
    comment_clean($content);
    if (false === ($f = io_load_file(LASTCOMMENTS_CACHE_FILE))) {
        // no comments in cache
        $list = array();
    } else {
        // if file exists and its correctly read, we get the stored list
        // (it is stored in encoded form)
        $list = unserialize($f);
        if (count($list) + 1 > LASTCOMMENTS_MAX) {
            // comments are more than allowed maximum:
            // we delete the last in queue.
            array_shift($list);
        }
    }
    if (strlen($content['content']) > $CHOP_AT) {
        $string = substr($content['content'], 0, $CHOP_AT) . '...';
    } else {
        $string = $content['content'];
    }
    array_push($list, array('name' => $content['name'], 'content' => $string, 'id' => $id, 'entry' => $entryid));
    return io_write_file(LASTCOMMENTS_CACHE_FILE, serialize($list));
}