/**
 * Inserts a new entry into the database or updates an existing entry
 *
 * Another central function, that parses, prepares and commits changes to an entry
 *
 * @access public
 * @param   array       The new/modified entry data.
 * @return  mixed       Integer with new entry ID if successfull, a string or array if error(s).
 */
function serendipity_updertEntry($entry)
{
    global $serendipity;
    include_once S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php';
    $errors = array();
    serendipity_plugin_api::hook_event('backend_entry_updertEntry', $errors, $entry);
    if (count($errors) > 0) {
        // Return error message(s)
        return implode("\n", $errors);
    }
    serendipity_plugin_api::hook_event('backend_entry_presave', $entry);
    $categories = $entry['categories'];
    unset($entry['categories']);
    $newEntry = 0;
    $exflag = 0;
    if (isset($entry['properties'])) {
        unset($entry['properties']);
    }
    if (!is_numeric($entry['timestamp'])) {
        $entry['timestamp'] = time();
    }
    /* WYSIWYG-editor inserts empty ' ' for extended body; this is reversed here */
    if (isset($entry['extended']) && (trim($entry['extended']) == '' || trim($entry['extended']) == '<br />' || trim($entry['extended']) == '<p></p>' || str_replace(array("\r", "\n", "\t", "", "<br />", "<p>", "</p>", "<br>"), array('', '', '', '', '', '', '', ''), trim($entry['extended'])) == '')) {
        $entry['extended'] = '';
    }
    if (strlen($entry['extended'])) {
        $exflag = 1;
    }
    $entry['exflag'] = $exflag;
    if (!is_numeric($entry['id'])) {
        /* we need to insert */
        unset($entry['id']);
        $entry['comments'] = 0;
        if (!isset($entry['last_modified']) || !is_numeric($entry['last_modified'])) {
            $entry['last_modified'] = $entry['timestamp'];
        }
        // New entries need an author
        $entry['author'] = $serendipity['user'];
        if (!isset($entry['authorid']) || empty($entry['authorid'])) {
            $entry['authorid'] = $serendipity['authorid'];
        }
        if (!$_SESSION['serendipityRightPublish']) {
            $entry['isdraft'] = 'true';
        }
        if (!isset($entry['allow_comments'])) {
            $entry['allow_comments'] = 'false';
        }
        if (!isset($entry['moderate_comments'])) {
            $entry['moderate_comments'] = 'false';
        }
        $res = serendipity_db_insert('entries', $entry);
        if ($res) {
            $entry['id'] = $serendipity['lastSavedEntry'] = serendipity_db_insert_id('entries', 'id');
            if (is_array($categories)) {
                foreach ($categories as $cat) {
                    if (is_numeric($cat)) {
                        serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entrycat (entryid, categoryid) VALUES ({$entry['id']}, {$cat})");
                    }
                }
            }
            serendipity_insertPermalink($entry);
        } else {
            //Some error message here
            return ENTRIES_NOT_SUCCESSFULLY_INSERTED;
        }
        $newEntry = 1;
    } else {
        /* we need to update */
        // Get settings from entry if already in DB, which should not be alterable with POST methods
        $_entry = serendipity_fetchEntry('id', $entry['id'], 1, 1);
        $entry['authorid'] = $_entry['authorid'];
        if (isset($serendipity['GET']['adminModule']) && $serendipity['GET']['adminModule'] == 'entries' && $entry['authorid'] != $serendipity['authorid'] && !serendipity_checkPermission('adminEntriesMaintainOthers')) {
            // Only chiefs and admins can change other's entry. Else update fails.
            return;
        }
        if (!$_SESSION['serendipityRightPublish']) {
            $entry['isdraft'] = 'true';
        }
        if (is_array($categories)) {
            serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entrycat WHERE entryid={$entry['id']}");
            foreach ($categories as $cat) {
                serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entrycat (entryid, categoryid) VALUES ({$entry['id']}, {$cat})");
            }
        }
        //if (!serendipity_db_bool($entry['isdraft']) && !serendipity_db_bool($_entry['isdraft'])) {
        $entry['last_modified'] = time();
        //}
        $res = serendipity_db_update('entries', array('id' => $entry['id']), $entry);
        $newEntry = 0;
        serendipity_updatePermalink($entry);
    }
    if (is_string($res)) {
        return $res;
    }
    // Reset session data, so that a reload to this frame should not happen!
    $_SESSION['save_entry']['id'] = (int) $entry['id'];
    if (!serendipity_db_bool($entry['isdraft'])) {
        serendipity_plugin_api::hook_event('frontend_display', $entry, array('no_scramble' => true, 'from' => 'functions_entries:updertEntry'));
        $drafted_entry = $entry;
    }
    serendipity_purgeEntry($entry['id'], $entry['timestamp']);
    if (!serendipity_db_bool($entry['isdraft']) && $entry['timestamp'] <= serendipity_serverOffsetHour()) {
        // When saving an entry, first all references need to be gathered. But trackbacks to them
        // shall only be send at the end of the execution flow. However, certain plugins depend on
        // the existance of handled references. Thus we store the current references at this point,
        // execute the plugins and then reset the found references to the original state.
        serendipity_handle_references($entry['id'], $serendipity['blogTitle'], $drafted_entry['title'], $drafted_entry['body'] . $drafted_entry['extended'], true);
    }
    // Send publish tags if either a new article has been inserted from scratch, or if the entry was previously
    // stored as draft and is now published
    $entry['categories'] =& $categories;
    if (!serendipity_db_bool($entry['isdraft']) && ($newEntry || serendipity_db_bool($_entry['isdraft']))) {
        serendipity_plugin_api::hook_event('backend_publish', $entry, $newEntry);
    } else {
        serendipity_plugin_api::hook_event('backend_save', $entry, $newEntry);
    }
    if (!serendipity_db_bool($entry['isdraft']) && $entry['timestamp'] <= serendipity_serverOffsetHour()) {
        // Now that plugins are executed, we go ahead into the Temple of Doom and send possibly failing trackbacks.
        // First, original list of references is restored (inside the function call)
        serendipity_handle_references($entry['id'], $serendipity['blogTitle'], $drafted_entry['title'], $drafted_entry['body'] . $drafted_entry['extended'], false);
    }
    return (int) $entry['id'];
}
Esempio n. 2
0
                // Moved to group administration:
                if ($item['var'] == 'userlevel') {
                    continue;
                }
                if ($item['view'] == 'dangerous') {
                    continue;
                }
                if (serendipity_checkConfigItemFlags($item, 'local')) {
                    serendipity_set_user_var($item['var'], $_POST[$item['var']], $serendipity['authorid'], true);
                }
                if (serendipity_checkConfigItemFlags($item, 'configuration')) {
                    serendipity_set_config_var($item['var'], $_POST[$item['var']], $serendipity['authorid']);
                }
            }
            $pl_data = array('id' => $serendipity['POST']['authorid'], 'authorid' => $serendipity['POST']['authorid'], 'username' => $_POST['username'], 'realname' => $_POST['realname'], 'email' => $_POST['email']);
            serendipity_updatePermalink($pl_data, 'author');
            serendipity_plugin_api::hook_event('backend_users_edit', $pl_data);
        }
        if ($serendipity['authorid'] === $_SESSION['serendipityAuthorid']) {
            if (is_null($serendipity['detected_lang'])) {
                $_SESSION['serendipityLanguage'] = $serendipity['lang'];
            }
        }
        $from = $_POST;
        ?>
    <div class="serendipityAdminMsgSuccess"><img width="22px" height="22px" style="border: 0px; padding-right: 4px; vertical-align: middle" src="<?php 
        echo serendipity_getTemplateFile('admin/img/admin_msg_success.png');
        ?>
" alt="" /><?php 
        echo sprintf(MODIFIED_USER, htmlspecialchars($_POST['realname']));
        ?>
Esempio n. 3
0
/**
 * Update an existing category
 *
 * @access public
 * @param   int     Category ID to update
 * @param   string  The new category name
 * @param   string  The new category description
 * @param   int     The new category owner
 * @param   string  The new category icon
 * @param   int     The new category parent ID
 * @param   int     The new category sort order
 * @param   int     The new category subcat hiding
 * @return null
 */
function serendipity_updateCategory($cid, $name, $desc, $authorid, $icon, $parentid, $sort_order = 0, $hide_sub = 0)
{
    global $serendipity;
    $query = "UPDATE {$serendipity['dbPrefix']}category\n                    SET category_name = '" . serendipity_db_escape_string($name) . "',\n                        category_description = '" . serendipity_db_escape_string($desc) . "',\n                        authorid = " . (int) $authorid . ",\n                        category_icon = '" . serendipity_db_escape_string($icon) . "',\n                        parentid = " . (int) $parentid . ",\n                        sort_order = " . (int) $sort_order . ",\n                        hide_sub = " . (int) $hide_sub . "\n                    WHERE categoryid = " . (int) $cid . "\n                        {$admin_category}";
    serendipity_db_query($query);
    serendipity_plugin_api::hook_event('backend_category_update', $cid);
    $data = array('id' => $cid, 'categoryid' => $cid, 'category_name' => $name, 'category_description' => $desc);
    serendipity_updatePermalink($data, 'category');
}