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; }
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 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; }
function plugin_aaspam_comment_form() { // we get a random arithmetic operation // between sum, subtraction and multiplication; // we intentionally left out division because // it can lead to situations like division by zero // or floating point numbers $myop = array_rand($ops = array('+', '-', '*')); $op = $ops[$myop]; // we get two random integers between 1 and 10 $v1 = mt_rand(1, 10); // we rand $v2 until it differs from $v1 // (otherwise result for subtractions is zero) while (($v2 = mt_rand(1, 10)) == $v1) { } // if operation is subtraction // the higher number must always come first // or you'll get a negative integer if ($v2 > $v1 && $op == '-') { $tmp = $v1; $v1 = $v2; $v2 = $tmp; } // execute the operation switch ($op) { case '+': $v = $v1 + $v2; break; case '-': $v = $v1 - $v2; break; case '*': $v = $v1 * $v2; break; } sess_add('aaspam', $v); // load plugin strings // they're located under plugin.PLUGINNAME/lang/LANGID/ $lang = lang_load('plugin:accessibleantispam'); $langstrings =& $lang['plugin']['accessibleantispam']; // get the correct question depending on the operation switch ($op) { case '+': $question = $langstrings['sum']; break; case '-': $question = $langstrings['sub']; break; case '*': $question = $langstrings['prod']; break; } // format the question with numbers at the proper positions $question = sprintf($question, $v1, $v2); if (AASPAM_DEBUG && ($f = @fopen(AASPAM_LOG, 'a'))) { $arr['aaspam-q'] = $v; @fwrite($f, date('r') . '|' . session_id() . '|' . utils_kimplode($arr) . "\r\n"); @fclose($f); } // echoes the question and the form part echo <<<STR \t<p><label class="textlabel" for="aaspam">{$lang['plugin']['accessibleantispam']['prefix']} <strong>{$question} (*)</strong></label><br /> \t\t<input type="text" name="aaspam" id="aaspam" /></p> STR; }