Пример #1
0
function draft_parse($id)
{
    if ($fname = draft_exists($id)) {
        $entry = io_load_file($fname);
        $entry = utils_kexplode($entry);
        if (!isset($entry['categories'])) {
            $entry['categories'] = array();
        } else {
            $entry['categories'] = explode(',', $entry['categories']);
        }
        return $entry;
    }
    return array();
}
Пример #2
0
 function _makePreview($arr, $id = null)
 {
     if (!$id) {
         $arr['subject'] = apply_filters('title_save_pre', $arr['subject']);
         $arr['content'] = apply_filters('content_save_pre', $arr['content']);
     }
     if ($this->draft || ($this->draft = draft_exists($this->id))) {
         if (isset($arr['categories']) && is_array($arr['categories']) && !in_array('draft', $arr['categories'])) {
             $arr['categories'][] = 'draft';
         } else {
             $arr['categories'][] = 'draft';
         }
     }
     // unfiltered content (for editing)
     $this->smarty->assign('post', $arr);
     if (THEME_LEGACY_MODE) {
         theme_entry_filters($arr, $id);
     }
     // content for preview
     $this->smarty->assign('entry', $arr);
     $this->smarty->assign('preview', true);
 }
Пример #3
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;
}