Update of /cvsroot/php-blog/serendipity/include/admin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23806/include/admin
Added Files:
Tag: branch-smarty
category.inc.php comments.inc.php entries.inc.php
entries_overview.inc.php images.inc.php installer.inc.php
interop.inc.php overview.inc.php plugins.inc.php
rss_exchange.inc.php templates.inc.php upgrader.inc.php
users.inc.php
Log Message:
* renamed files as announced on the list. upgrader will take care of moving
old files to a 'backup' directory for upgrading (non-CVS) users.
* MFH'ed some parts
* Fixed quicksave button display
* Fixed footer
* Fixed entry preview properly
* Fixed printing categories where no categories appeard in entry view
--- NEW FILE: templates.inc.php ---
<?php # $Id: templates.inc.php,v 1.1.2.1 2004/11/06 11:22:49 garvinhicking Exp $
if (IN_serendipity !== true) {
die ("Don't hack!");
}
if ($serendipity['serendipityUserlevel'] < USERLEVEL_CHIEF) {
return;
}
if ($serendipity['GET']['adminAction'] == 'save' ) {
serendipity_set_config_var('template', $serendipity['POST']['theme']);
}
?>
<?php echo SELECT_TEMPLATE; ?>
<div>
<form method="post" action="<?php echo $serendipity['serendipityHTTPPath']; ?>serendipity_admin.php?serendipity[adminModule]=templates&serendipity[adminAction]=save">
<?php
foreach (serendipity_fetchTemplates() as $theme) {
$info = serendipity_fetchTemplateInfo($theme);
if (file_exists($serendipity['serendipityPath'] . $serendipity['templatePath'] . $theme . '/preview.png')) {
$preview = '<img src="templates/' . $theme . '/preview.png" width="100" style="border: 1px #000000 solid" />';
} else {
$preview = ' ';
}
if (serendipity_get_config_var('template', $serendipity['defaultTemplate']) == $theme) {
$is_active = 'checked="checked"';
} else {
$is_active = '';
}
$jsLine = " onmousedown=\"document.getElementById('serendipity_theme_radio_". $theme ."').checked = true;\"";
$jsLine .= " onmouseout=\"document.getElementById('serendipity_theme_". $theme ."').className='';\"";
$jsLine .= " onmouseover=\"document.getElementById('serendipity_theme_". $theme ."').className='serendipity_admin_list_item_uneven'; style.cursor = 'pointer';\"";
?>
<table width="100%" id="serendipity_theme_<?php echo $theme; ?>">
<tr>
<td colspan="3" <?php echo $jsLine ?>><strong><?php echo $info['name']; ?></strong></td>
</tr>
<tr>
<td width="100" <?php echo $jsLine ?> style="padding-left: 10px"><?php echo $preview; ?></td>
<td valign="top" <?php echo $jsLine ?>>
<?php echo AUTHOR; ?> : <?php echo $info['author'];?><br />
<?php echo LAST_UPDATED; ?>: <?php echo $info['date']; ?>
</td>
<td valign="middle" align="center" width="70" <?php echo $jsLine ?>>
<div><input type="radio" name="serendipity[theme]" value="<?php echo $theme; ?>" id="serendipity_theme_radio_<?php echo $theme; ?>" <?php echo $is_active; ?> /></div>
</td>
</tr>
</table>
<br />
<?php
}
?>
<div align="right"><input type="submit" name="submit" value="<?php echo SET_AS_TEMPLATE; ?>" /></div>
</form>
</div>
<?php
/* vim: set sts=4 ts=4 expandtab : */
?>
--- NEW FILE: users.inc.php ---
<?php # $Id: users.inc.php,v 1.1.2.1 2004/11/06 11:22:49 garvinhicking Exp $
if (IN_serendipity !== true) {
die ('Don\'t hack!');
}
session_start();
if ($serendipity['serendipityUserlevel'] < USERLEVEL_CHIEF) {
return;
}
require_once(S9Y_INCLUDE_PATH . 'include/functions_installer.inc.php');
/*
* User actions
*/
if (!empty($_POST['DELETE_YES'])) {
$user = serendipity_fetchUsers($serendipity['POST']['user']);
if ($user[0]['userlevel'] >= $serendipity['serendipityUserlevel'] && $serendipity['serendipityUserlevel'] < USERLEVEL_ADMIN) {
echo '<strong>' . CREATE_NOT_AUTHORIZED . '</strong>';
} elseif ($_POST['userlevel'] > $serendipity['serendipityUserlevel']) {
echo '<strong>' . CREATE_NOT_AUTHORIZED_USERLEVEL . '</strong>';
} else {
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}authors WHERE authorid=" . (int)$serendipity['POST']['user']);
printf('<strong>' . DELETED_USER . '</strong>', $serendipity['POST']['user'], $user[0]['username']);
}
}
if (!empty($_POST['SAVE_NEW'])) {
if ($serendipity['POST']['userlevel'] >= $serendipity['serendipityUserlevel'] && $serendipity['serendipityUserlevel'] < USERLEVEL_ADMIN) {
echo '<strong>' . CREATE_NOT_AUTHORIZED . '</strong>';
} else {
$enc_pass = md5($_POST['pass']);
$query = "INSERT INTO {$serendipity['dbPrefix']}authors (
username,
password
)
VALUES (
'" . serendipity_db_escape_string($_POST['username']) . "',
'" . serendipity_db_escape_String($enc_pass) . "'
)";
serendipity_db_query($query);
$serendipity['POST']['user'] = serendipity_db_insert_id('authors', 'authorid');
printf('<strong>' . CREATED_USER . '</strong>', '#' . $serendipity['POST']['user'] . ', ' . $_POST['username']);
}
echo '<br />';
}
if (!empty($_POST['SAVE']) || !empty($_POST['SAVE_NEW'])) {
$user = serendipity_fetchUsers($serendipity['POST']['authorid']);
if ($user[0]['userlevel'] >= $serendipity['serendipityUserlevel'] && $serendipity['serendipityUserlevel'] < USERLEVEL_ADMIN) {
echo '<strong>' . CREATE_NOT_AUTHORIZED . '</strong>';
} elseif ($_POST['userlevel'] > $serendipity['serendipityUserlevel']) {
echo '<strong>' . CREATE_NOT_AUTHORIZED_USERLEVEL . '</strong>';
} else {
$u = serendipity_parseTemplate(S9Y_CONFIG_USERTEMPLATE, true);
foreach($u AS $key => $entry) {
serendipity_set_user_var(
$entry['name'],
$_POST[$entry['name']],
$serendipity['POST']['user'],
($serendipity['authorid'] == $serendipity['POST']['authorid'] ? true : false)
);
}
printf('<strong>' . MODIFIED_USER . '</strong>', $_POST['username']);
echo '<br />';
}
}
/*
* User chooser
*/
?>
<strong><?php echo EDIT_USERS; ?></strong>
<hr noshade="noshade" />
<table width="100%">
<tr>
<td><strong><?php echo USER; ?></strong></td>
<td><strong><?php echo USER_LEVEL ?></strong></td>
<td> </td>
</tr>
<?php
$users = serendipity_fetchUsers();
foreach($users AS $user) {
if ($user['userlevel'] < $serendipity['serendipityUserlevel'] || $user['authorid'] == $serendipity['authorid'] || $serendipity['serendipityUserlevel'] >= USERLEVEL_ADMIN ) {
?>
<tr>
<td><?php echo htmlspecialchars($user['username']); ?></td>
<td width="200"><?php echo $user['userlevel']; ?></td>
<td align="right">
<form action="?serendipity[adminModule]=users" method="post">
<input type="hidden" name="serendipity[user]" value="<?php echo $user['authorid']; ?>" />
<input type="submit" name="EDIT" value="<?php echo EDIT; ?>" />
<input type="submit" name="DELETE" value="<?php echo DELETE; ?>" />
</form>
</td>
</tr>
<?php
}
}
?>
<tr>
<th colspan="3"><br />- <?php echo WORD_OR; ?> -<br /><br /></th>
</tr>
<tr>
<td><strong><?php echo CREATE_USERS; ?>:</strong></td>
<td> </td>
<td>
<form action="?serendipity[adminModule]=users" method="post">
<input type="submit" name="NEW" value="<?php echo CREATE_NEW_USER; ?>" />
</form>
</td>
</tr>
</table>
<hr noshade="noshade" />
<?php
/*
* User editing/creation
*/
if (!empty($_POST['NEW']) || !empty($_POST['EDIT'])) {
?>
<form action="?serendipity[adminModule]=users" method="post">
<div>
<h3>
<?php
if (!empty($_POST['EDIT'])) {
$user = serendipity_fetchUsers($serendipity['POST']['user']);
if ($user[0]['userlevel'] >= $serendipity['serendipityUserlevel'] && $user[0]['authorid'] != $serendipity['authorid'] && $serendipity['serendipityUserlevel'] < USERLEVEL_ADMIN) {
echo '<strong>' . CREATE_NOT_AUTHORIZED . '</strong><br />';
echo CREATE;
$from = array();
} else {
echo EDIT;
$from = &$user[0];
unset($from['password']);
echo '<input type="hidden" name="serendipity[user]" value="' . $from['authorid'] . '" />';
}
} else {
echo CREATE;
$from = array();
}
?>
</h3>
<?php
$t = array();
$t = serendipity_parseTemplate(S9Y_CONFIG_USERTEMPLATE, false, $t, false);
serendipity_printConfigTemplate($t, $from, true, false);
if (!empty($_POST['EDIT'])) { ?>
<input type="submit" name="SAVE" value="<?php echo SAVE; ?>" />
<?php } else { ?>
<input type="submit" name="SAVE_NEW" value="<?php echo CREATE_NEW_USER; ?>" />
<?php } ?>
</div>
</form>
<?php
} elseif (!empty($_POST['DELETE'])) {
$user = serendipity_fetchUsers($serendipity['POST']['user']);
?>
<form action="?serendipity[adminModule]=users" method="post">
<div>
<?php printf(DELETE_USER, $serendipity['POST']['user'], $user[0]['username']); ?>
<br /><br />
<input type="hidden" name="serendipity[user]" value="<?php echo $serendipity['POST']['user']; ?>" />
<input type="submit" name="DELETE_YES" value="<?php echo DUMP_IT; ?>" />
<input type="submit" name="NO" value="<?php echo NOT_REALLY; ?>" />
</div>
</form>
<?php
}
/* vim: set sts=4 ts=4 expandtab : */
?>
--- NEW FILE: upgrader.inc.php ---
<?php
require_once(S9Y_INCLUDE_PATH . 'include/functions_installer.inc.php');
// Setting this value to 'FALSE' is recommended only for SHARED BLOG INSTALLATIONS. This enforces all shared blogs with a common
// codebase to only allow upgrading, no bypassing and thus causing instabilities.
// This variable can also be set as $serendipity['UpgraderShowAbort'] inside serendipity_config_local.inc.php to prevent
// your setting being changed when updating serendipity in first place.
$showAbort = (isset($serendipity['UpgraderShowAbort']) ? $serendipity['UpgraderShowAbort'] : true);
$abortLoc = $serendipity['serendipityHTTPPath'] . 'serendipity_admin.php?serendipity[action]=ignore';
$upgradeLoc = $serendipity['serendipityHTTPPath'] . 'serendipity_admin.php?serendipity[action]=upgrade';
/* A list of files which got obsoleted in 0.8 */
$obsolete_files = array(
'serendipity.inc.php',
'serendipity_layout.inc.php',
'serendipity_layout_table.inc.php',
'serendipity_entries_overview.inc.php',
'serendipity_rss_exchange.inc.php',
'serendipity_admin_category.inc.php',
'serendipity_admin_comments.inc.php',
'serendipity_admin_entries.inc.php',
'serendipity_admin_images.inc.php',
'serendipity_admin_installer.inc.php',
'serendipity_admin_interop.inc.php',
'serendipity_admin_overview.inc.php',
'serendipity_admin_plugins.inc.php',
'serendipity_admin_templates.inc.php',
'serendipity_admin_upgrader.inc.php',
'serendipity_admin_users.inc.php',
'compat.php',
'serendipity_functions_config.inc.php',
'serendipity_functions_images.inc.php',
'serendipity_functions_installer.inc.php',
'serendipity_genpage.inc.php',
'serendipity_lang.inc.php',
'serendipity_plugin_api.php',
'serendipity_sidebar_items.php',
'serendipity_db.inc.php',
'serendipity_db_mysql.inc.php',
'serendipity_db_mysqli.inc.php',
'serendipity_db_postgres.inc.php',
'serendipity_db_sqlite.inc.php',
'htaccess.cgi.errordocs.tpl',
'htaccess.cgi.normal.tpl',
'htaccess.cgi.rewrite.tpl',
'htaccess.errordocs.tpl',
'htaccess.normal.tpl',
'htaccess.rewrite.tpl',
'serendipity_config_local.tpl',
'serendipity_config_user.tpl',
'INSTALL',
'LICENSE',
'NEWS',
'README',
'TODO',
'upgrade.sh',
'templates/default/layout.php'
);
/* Functions which needs to be run if installed version is equal or lower */
$tasks = array('0.5.1' => array('function' => 'serendipity_syncThumbs',
'title' => 'Image Sync',
'desc' => 'Version 0.5.1 introduces image sync with the database'. "\n" .
'With your permission I would like to perform the image sync'),
'0.6.5' => array('function' => 'serendipity_rebuildCategoryTree',
'title' => 'Nested subcategories, post to multiple categories',
'desc' => 'This update will update the categories table of your database and update the relations from entries to categories.'. "\n" .
'This is a possibly dangerous task to perform, so <strong style="color: red">make sure you have a backup of your database!</strong>'),
'0.6.8' => array('function' => 'serendipity_installFiles',
'title' => 'Update of .htaccess file',
'desc' => 'Changes were made to the .htaccess file, you need to regenerate it'),
'0.6.10' => array('functon' => 'serendipity_installFiles',
'title' => 'Update of .htaccess file',
'desc' => 'Changes were made to the .htaccess file, you need to regenerate it'),
'0.6.12' => array('function' => 'serendipity_installFiles',
'title' => 'Update of .htaccess file',
'desc' => 'Changes were made to the .htaccess file, you need to regenerate it'),
'0.8-alpha3' => array('function' => 'serendipity_removeFiles',
'title' => 'Removal of obsolete files',
'arguments' => $obsolete_files,
'desc' => 'The directory structure has been reworked. The following files will be moved to a folder called "backup". If you made manual changes to those files, be sure to read the file docs/CHANGED_FILES to re-implement your changes.<br /><div style="font-size: x-small; margin: 15px">' . implode(', ', $obsolete_files) . '</div>')
);
/* Fetch SQL files which needs to be run */
$dir = opendir(S9Y_INCLUDE_PATH . 'sql/');
$tmpfiles = array();
while (($file = readdir($dir)) !== false ) {
if (preg_match('@db_update_(.*)_(.*)_(.*).sql@', $file, $res)) {
list(, $verFrom, $verTo, $dbType) = $res;
if (version_compare($verFrom, serendipity_version($serendipity['versionInstalled'])) >= 0) {
$tmpFiles[$verFrom][$dbType] = $file;
}
}
}
$sqlfiles = array();
if (is_array($tmpFiles)) {
foreach ($tmpFiles as $version => $db) {
if (array_key_exists($serendipity['dbType'], $db) === false ) {
$sqlfiles[$version] = $db['mysql'];
} else {
$sqlfiles[$version] = $db[$serendipity['dbType']];
}
}
}
@uksort($sqlfiles, "strnatcasecmp");
if ($serendipity['GET']['action'] == 'ignore') {
/* Todo: Don't know what to put here? */
} elseif ($serendipity['GET']['action'] == 'upgrade') {
/* Install SQL files */
foreach ($sqlfiles as $sqlfile) {
$sql = file_get_contents(S9Y_INCLUDE_PATH .'sql/'. $sqlfile);
$sql = str_replace('{PREFIX}', $serendipity['dbPrefix'], $sql);
preg_match_all("@(.*);@iUs", $sql, $res);
foreach ($res[0] as $sql) {
$r = serendipity_db_schema_import($sql);
if (is_string($r)) {
$errors[] = $r;
}
}
}
/* Call functions */
$errors = array();
foreach ($tasks as $version => $task) {
if (version_compare(serendipity_version($serendipity['versionInstalled']), $version, '<') ) {
if (is_callable($task['function'])) {
echo 'Calling ' . $task['function'] . '...<br />';
if (empty($task['arguments']) || !is_array($task['arguments'])) {
$task['arguments'] = array();
}
call_user_func($task['function'], $task['arguments']);
} else {
$errors[] = 'Unable to call '. $task['function'];
}
}
}
if (sizeof($errors)) {
echo DIAGNOSTIC_ERROR . '<br /><br />';
echo '<span class="serendipity_msg_important">- ' . implode('<br />', $errors) . '</span><br /><br />';
}
}
if (($showAbort && $serendipity['GET']['action'] == 'ignore') || $serendipity['GET']['action'] == 'upgrade') {
$privateVariables = array();
if (isset($serendipity['UpgraderShowAbort'])) {
$privateVariables['UpgraderShowAbort'] = $serendipity['UpgraderShowAbort'];
}
$r = serendipity_updateLocalConfig(
$serendipity['dbName'],
$serendipity['dbPrefix'],
$serendipity['dbHost'],
$serendipity['dbUser'],
$serendipity['dbPass'],
$serendipity['dbType'],
'serendipity_config_local.inc.php',
null,
$privateVariables
);
if ($serendipity['GET']['action'] == 'ignore') {
echo SERENDIPITY_UPGRADER_YOU_HAVE_IGNORED;
} elseif ($serendipity['GET']['action'] == 'upgrade') {
printf(SERENDIPITY_UPGRADER_NOW_UPGRADED, $serendipity['version']);
}
echo '<br />';
printf(SERENDIPITY_UPGRADER_RETURN_HERE, '<a href="'. $serendipity['serendipityHTTPPath'] .'">', '</a>');
$_SESSION['serendipityAuthedUser'] = false;
@session_destroy();
} else {
echo SERENDIPITY_UPGRADER_WELCOME . '<br />';
printf(SERENDIPITY_UPGRADER_PURPOSE . '<br />', $serendipity['versionInstalled']);
printf(SERENDIPITY_UPGRADER_WHY, $serendipity['version']);
if (sizeof($sqlfiles) > 0) {
?>
<br />
<h3><?php printf(SERENDIPITY_UPGRADER_DATABASE_UPDATES, $serendipity['dbType']) ?>:</h3>
<?php echo SERENDIPITY_UPGRADER_FOUND_SQL_FILES ?>:<br />
<?php
foreach ($sqlfiles as $sqlfile) {
echo '<div style="padding-left: 5px"><strong>'. $sqlfile .'</strong></div>';
}
}
?>
<br />
<h3><?php echo SERENDIPITY_UPGRADER_VERSION_SPECIFIC ?>:</h3>
<?php
$taskCount = 0;
foreach ( $tasks as $version => $task ) {
if (version_compare(serendipity_version($serendipity['versionInstalled']), $version, '<')) {
echo '<div><strong>'. $version .' - '. $task['title'] .'</strong></div>';
echo '<div style="padding-left: 5px">'. nl2br($task['desc']) .'</div><br />';
$taskCount++;
}
}
if ($taskCount == 0) {
echo SERENDIPITY_UPGRADER_NO_VERSION_SPECIFIC;
}
?>
<br /><br />
<hr noshade="noshade">
<?php if ($taskCount > 0 || sizeof($sqlfiles) > 0) { ?>
<strong><?php echo SERENDIPITY_UPGRADER_PROCEED_QUESTION ?></strong>
<br /><input type="button" value="<?php echo SERENDIPITY_UPGRADER_PROCEED_DOIT ?>" onclick="location.href='<?php echo $upgradeLoc ?>'"> <?php if ($showAbort) { ?><input type="button" value="<?php echo SERENDIPITY_UPGRADER_PROCEED_ABORT ?>" onclick="location.href='<?php echo $abortLoc ?>'"> <?php } ?>
<?php } else { ?>
<strong><?php echo SERENDIPITY_UPGRADER_NO_UPGRADES ?></strong>
<br /><input type="button" value="<?php echo SERENDIPITY_UPGRADER_CONSIDER_DONE ?>" onclick="location.href='<?php echo $abortLoc ?>'">
<?php }
}
?>
--- NEW FILE: overview.inc.php ---
<?php # $Id: overview.inc.php,v 1.1.2.1 2004/11/06 11:22:49 garvinhicking Exp $
##########################################################################
# serendipity - another blogger... #
##########################################################################
# #
# (c) 2003 Jannis Hermanns <J...@ha...> #
# http://www.jannis.to/programming/serendipity.html #
# #
##########################################################################
if (IN_serendipity !== true) {
die ("Don't hack!");
}
echo WELCOME_BACK . ' ' . $_SESSION['serendipityUser'] . '.';
echo '<br /><br />'. RUNNING . $serendipity['version'];
/* vim: set sts=4 ts=4 expandtab : */
?>
--- NEW FILE: rss_exchange.inc.php ---
<?php # $Id: rss_exchange.inc.php,v 1.1.2.1 2004/11/06 11:22:49 garvinhicking Exp $
require_once 'bundled-libs/Onyx/RSS.php';
function serendipity_rss_buildEntry($item, &$entry)
{
global $serendipity;
$entry = array();
$bodyonly = (isset($serendipity['POST']['bodyonly']) && $serendipity['POST']['bodyonly'] == 'true' ? true : false);
if ($item['description']) {
$entry['body'] = utf8_decode($item['description']);
}
if ($item['content:encoded']) {
if (!isset($entry['body']) || $bodyonly) {
$data = &$entry['body'];
} else {
$data = &$entry['extended'];
}
// See if the 'description' element is a substring of the 'content:encoded' part. If it is,
// we will only fetch the full 'content:encoded' part. If it's not a substring, we append
// the 'content:encoded' part to either body or extended entry (respecting the 'bodyonly'
// switch). We substract 4 letters because of possible '...' additions to an entry.
$testbody = substr(trim(strip_tags($entry['body'])), 0, -4);
if ($testbody != substr(trim(strip_tags($item['content:encoded'])), 0, strlen($testbody))) {
$data .= utf8_decode($item['content:encoded']);
} else {
$data = utf8_decode($item['content:encoded']);
}
}
$entry['title'] = utf8_decode($item['title']);
$entry['timestamp'] = utf8_decode(strtotime(isset($item['pubdate']) ? $item['pubdate'] : $item['dc:date']));
if ($entry['timestamp'] == -1) {
$entry['timestamp'] = time();
}
if ($serendipity['POST']['type'] == 'draft') {
$entry['isdraft'] = 'true';
} else {
$entry['isdraft'] = 'false';
}
if (!empty($item['category'])) {
$cat = serendipity_fetchCategoryInfo(0, trim(utf8_decode($item['category'])));
if (is_array($cat) && isset($cat['categoryid'])) {
$entry['categories'][] = $cat['categoryid'];
}
}
if (!is_array($entry['categories'])) {
$entry['categories'][] = $serendipity['POST']['category'];
}
if (!isset($entry['extended'])) {
$entry['extended'] = '';
}
$entry['allow_comments'] = true;
return true;
}
function serendipity_rss_import($url)
{
global $serendipity;
$c = &new Onyx_RSS();
$c->parse($url);
$serendipity['noautodiscovery'] = 1;
while ($item = $c->getNextItem()) {
if (serendipity_rss_buildEntry($item, $entry)) {
serendipity_updertEntry($entry);
}
}
return true;
}
/**
* Import from Movable Type's format.
**/
function serendipity_importMT($contents, $force = false) {
global $serendipity;
if ( $serendipity['serendipityUserlevel'] != USERLEVEL_ADMIN ) {
return array(MUST_BE_ADMIN);
}
$authors = array();
$categories = serendipity_fetchCategories();
$tasks = array();
$entries = array();
$n = 0;
foreach ( preg_split('/\r?\n--------\r?\n/', $contents) as $entry ) {
if ( preg_match_all('/([A-Z ]+):( |\r?\n)(.*)\r?\n(-----)?/', $entry, $res) ) {
$entries[$n]['categories'] = array();
for ( $x=0 ; $x<sizeof($res[1]) ; $x++ ) {
switch ( $res[1][$x] ) {
case 'AUTHOR':
if ( !isset($authors[$res[3][$x]]) ) {
$au_inf = serendipity_fetchAuthor($res[3][$x]);
if ( !is_array($au_inf) ) {
$tasks[] = sprintf(CREATE_AUTHOR, htmlspecialchars($res[3][$x]));
$au_inf = serendipity_fetchAuthor($serendipity['authorid']);
}
$authors[$res[3][$x]] = $au_inf[0];
}
$entries[$n]['authorid'] = $authors[$res[3][$x]]['authorid'];
$entries[$n]['author'] = $authors[$res[3][$x]]['username'];
break;
case 'TITLE':
$entries[$n]['title'] = $res[3][$x];
break;
case 'STATUS':
$entries[$n]['isdraft'] = ($res[3][$x] == 'Publish') ? 'false' : 'true';
break;
case 'ALLOW COMMENTS':
$entries[$n]['allow_comments'] = ($res[3][$x] == '1') ? 'true' : 'false';
break;
case 'DATE':
$entries[$n]['timestamp'] = strtotime($res[3][$x]);
if ( $entries[$n]['timestamp'] == 0 ) {
$entries[$n]['timestamp'] = time();
}
break;
case 'BODY':
$entries[$n]['body'] = $res[3][$x];
break;
case 'EXTENDED BODY':
$entries[$n]['extended'] = $res[3][$x];
break;
case 'PRIMARY CATEGORY':
case 'CATEGORY':
$cat_found = false;
if ( is_array($categories) ) {
for ( $y=0 ; $y<sizeof($categories) ; $y++ ) {
if ( $categories[$y]['category_name'] == $res[3][$x] ) {
$cat_found = true;
break;
}
}
}
if ( $cat_found && !in_array($categories[$y]['categoryid'], $entries[$n]['categories']) ) {
$entries[$n]['categories'][] = $categories[$y]['categoryid'];
$entries[$n]['categories'][] = $categories[$y]['categoryid'];
}
else {
$tasks[] = sprintf(CREATE_CATEGORY, htmlspecialchars($res[3][$x]));
}
break;
}
}
}
$n++;
}
if ( !sizeof($tasks) || $force == true ) {
foreach ( $entries as $entry ) {
if ( !is_int($r = serendipity_updertEntry($entry)) ) {
echo '<div class="important">' . $r . '</div>';
}
}
return true;
}
else {
return array_unique($tasks);
}
}
/**
* Import from a WordPress installation.
**/
function serendipity_importWP($wp) {
global $serendipity;
$wp['prefix'] = serendipity_db_escape_string($wp['prefix']);
$users = array();
$categories = array();
$entries = array();
if ( $serendipity['serendipityUserlevel'] < USERLEVEL_ADMIN ) {
return MUST_BE_ADMIN;
}
if ( !extension_loaded('mysql') ) {
return MYSQL_REQUIRED;;
}
$wpdb = @mysql_connect($wp['host'], $wp['user'], $wp['pass']);
if ( !$wpdb ) {
return sprintf(COULDNT_CONNECT, mysql_error($wpdb));
}
if ( !@mysql_select_db($wp['name']) ) {
return sprintf(COULDNT_SELECT_DB, mysql_error($wpdb));
}
/* Users */
$res = @mysql_query("SELECT ID, user_login, user_pass, user_email, user_level FROM {$wp['prefix']}users;", $wpdb);
if ( !$res ) {
return sprintf(COULDNT_COULDNT_SELECT_USER_INFO, mysql_error($wpdb));
}
for ( $x=0 ; $x<mysql_num_rows($res) ; $x++ ) {
$users[$x] = mysql_fetch_assoc($res);
$data = array('right_publish' => ($users[$x]['user_level'] >= 1) ? 1 : 0,
'username' => $users[$x]['user_login'],
'password' => $users[$x]['user_pass']); // WP uses md5, too.
if ( $users[$x]['user_level'] <= 1 ) {
$data['userlevel'] = USERLEVEL_EDITOR;
} elseif ( $users[$x]['user_level'] < 5 ) {
$data['userlevel'] = USERLEVEL_CHIEF;
} else {
$data['userlevel'] = USERLEVEL_ADMIN;
}
serendipity_db_insert('authors', $data);
$users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
}
/* Categories */
$res = @mysql_query("SELECT cat_ID, cat_name, category_description, category_parent FROM {$wp['prefix']}categories ORDER BY category_parent, cat_ID;", $wpdb);
if ( !$res ) {
return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($wpdb));
}
// Get all the info we need
for ( $x=0 ; $x<mysql_num_rows($res) ; $x++ )
$categories[] = mysql_fetch_assoc($res);
// Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
for ( $x=0 ; $x<sizeof($categories) ; $x++ ) {
$cat = array('category_name' => $categories[$x]['cat_name'],
'category_description' => $categories[$x]['category_description'],
'parentid' => 0, // <---
'category_left' => 0,
'category_right' => 0);
serendipity_db_insert('category', $cat);
$categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
}
// There has to be a more efficient way of doing this...
foreach ( $categories as $cat ) {
if ( $cat['category_parent'] != 0 ) {
// Find the parent
$par_id = 0;
foreach ( $categories as $possible_par ) {
if ( $possible_par['cat_ID'] == $cat['category_parent'] ) {
$par_id = $possible_par['categoryid'];
break;
}
}
if ( $par_id != 0 ) {
serendipity_db_query("UPDATE {$serendipity['dbPrefix']}category SET parentid={$par_id} WHERE categoryid={$cat['categoryid']};");
} // else { echo "D'oh! " . random_string_of_profanity(); }
}
}
serendipity_rebuildCategoryTree();
/* Entries */
$res = @mysql_query("SELECT * FROM {$wp['prefix']}posts ORDER BY post_date;", $wpdb);
if ( !$res ) {
return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($wpdb));
}
for ( $x=0 ; $x<mysql_num_rows($res) ; $x++ ) {
$entries[$x] = mysql_fetch_assoc($res);
$entry = array('title' => $entries[$x]['post_title'],
'isdraft' => ($entries[$x]['post_status'] == 'publish') ? 'false' : 'true',
'allow_comments' => ($entries[$x]['comment_status '] == 'open ') ? 'true' : 'false',
'timestamp' => strtotime($entries[$x]['post_date']),
'body' => $entries[$x]['post_content']);
foreach ( $users as $user ) {
if ( $user['ID'] == $entries[$x]['post_author'] ) {
$entry['authorid'] = $user['authorid'];
break;
}
}
if ( !is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry)) ) {
return $entries[$x]['entryid'];
}
}
/* Entry/category */
$res = @mysql_query("SELECT * FROM {$wp['prefix']}post2cat;", $wpdb);
if ( !$res ) {
return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($wpdb));
}
while ( $a = mysql_fetch_assoc($res) ) {
foreach ( $categories as $category ) {
if ( $category['cat_ID'] == $a['category_id'] ) {
foreach ( $entries as $entry ) {
if ( $a['post_id'] == $entry['ID'] ) {
$data = array('entryid' => $entry['entryid'],
'categoryid' => $category['categoryid']);
serendipity_db_insert('entrycat', $data);
break;
}
}
break;
}
}
}
/* Comments */
$res = @mysql_query("SELECT * FROM {$wp['prefix']}comments;", $wpdb);
if ( !$res ) {
return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($wpdb));
}
while ( $a = mysql_fetch_assoc($res) ) {
foreach ( $entries as $entry ) {
if ( $entry['ID'] == $a['comment_post_ID'] ) {
$comment = array('entry_id ' => $entry['entryid'],
'parent_id' => 0,
'timestamp' => strtotime($a['comment_date']),
'author' => $a['comment_author'],
'email' => $a['comment_author_email'],
'url' => $a['comment_author_url'],
'ip' => $a['comment_author_IP'],
'status' => 'approved',
'body' => $a['comment_content'],
'type' => 'NORMAL');
serendipity_db_insert('comments', $comment);
serendipity_approveComment($cid, $id, true);
}
}
}
// That was fun.
return false;
}
/* vim: set sts=4 ts=4 expandtab : */
?>
--- NEW FILE: installer.inc.php ---
<?php # $Id: installer.inc.php,v 1.1.2.1 2004/11/06 11:22:49 garvinhicking Exp $
umask(0000);
$umask = 0775;
@define('IN_installer', true);
require_once('serendipity_config.inc.php');
require_once(S9Y_INCLUDE_PATH . 'include/functions_installer.inc.php');
require_once S9Y_INCLUDE_PATH . 'include/functions_config.inc.php';
if (!isset($_POST['installAction'])) {
$_POST['installAction'] = '';
}
/* Check where to deploy .htaccess files. For shared installation, first guess is submitted directory name.
If that is not existant we autodetect using current directory. */
if (IS_installed !== true) {
if (!empty($_POST['serendipityPath'])) {
$serendipity_core = $_POST['serendipityPath'];
} else {
$serendipity_core = serendipity_httpCoreDir();
}
} else {
$serendipity_core = $serendipity['serendipityPath'];
}
switch ($_POST['installAction']) {
case 'check':
/* If we already have serendipity installed, all we need to do is write the configuration again */
if (!defined('IN_serendipity') || IN_serendipity !== true) {
$res = serendipity_checkInstallation();
if (is_array($res)) {
echo DIAGNOSTIC_ERROR . '<br /><br />';
echo '<span class="serendipity_msg_important">- ' . implode('<br />', $res) . '</span><br /><br />';
serendipity_printConfigTemplate(serendipity_parseTemplate(S9Y_CONFIG_TEMPLATE), $_POST, false, true, true);
die();
}
echo '<br />';
/* We are good to go, lets install databases etc. */
echo ATTEMPT_SETUP_DATABASE . "<br />";
$res = serendipity_installDatabase();
if ($res !== false) {
echo ' ' . DATABASE_DONE . '<br />';
} else {
echo '<span class="serendipity_msg_important">- ' . DATABASE_ALREADY_INSTALLED . '</span><br />';
}
/* Next are the files, .htaccess */
printf(ATTEMPT_WRITE_FILE, $serendipity_core . '.htaccess');
$res = serendipity_installFiles($serendipity_core);
if (is_array($res)) {
echo '<span class="serendipity_msg_important">- ' . implode('<br />', $res) . '</span><br /><br />';
die();
} else {
echo DONE . '<br />';
}
/* We are now installed */
define('IN_serendipity', true);
/* register default plugins */
$GLOBALS['serendipity']['dbPrefix'] = $_POST['dbPrefix'];
$GLOBALS['serendipity']['dbName'] = $_POST['dbName'];
$GLOBALS['serendipity']['serendipityHTTPPath'] = $_POST['serendipityHTTPPath'];
if (!isset($serendipity['lang'])) {
$serendipity['lang'] = 'en';
}
include_once S9Y_INCLUDE_PATH . 'include/plugin_api.inc.php';
serendipity_plugin_api::register_default_plugins();
printf(
SERENDIPITY_INSTALLED . '<br />',
'<p><strong>',
'</strong></p>',
$_POST['pass'],
$_POST['user'],
'<br /><br />',
$_POST['serendipityHTTPPath']
);
@session_destroy();
}
$oldRewrite = $serendipity['rewrite']; // We save the rewrite method, because we run a check after $serendipity has been updated
$res = serendipity_updateConfiguration();
if (is_array($res)) {
echo DIAGNOSTIC_ERROR;
echo '<span class="serendipity_msg_important">- ' . implode('<br />', $res) . '</span><br /><br />';
} else {
/* If we have new rewrite rules, then install them */
if (isset($_POST['rewrite']) && $serendipity['serendipityUserlevel'] >= USERLEVEL_ADMIN && $oldRewrite != $_POST['rewrite']) {
printf(ATTEMPT_WRITE_FILE, $serendipity_core . '.htaccess');
$res = serendipity_installFiles($serendipity_core);
if (is_array($res)) {
echo implode('<br />', $res);
} else {
echo DONE . '<br />';
}
}
echo '<br /><strong>'. WRITTEN_N_SAVED .'</strong>';
}
break;
default:
/* Is serendipity already installed= */
if (file_exists('./serendipity_config_local.inc.php')) {
$from = &$serendipity;
} else {
define('VERSION_REQUIRED', '4.2.1');
/* Do check for required PHP version */
if (version_compare(PHP_VERSION, VERSION_REQUIRED) == -1) {
echo '<br /><span class="serendipity_msg_important">WARNING!<br />You are using PHP version ' . PHP_VERSION . '! Serendipity requires version ' . VERSION_REQUIRED . '</span>';
}
$from = false;
}
$t = serendipity_parseTemplate(S9Y_CONFIG_TEMPLATE);
// If s9y is installed, append the current userconfiguration
if (IS_installed === true) {
$t = serendipity_parseTemplate(S9Y_CONFIG_USERTEMPLATE, false, $t);
}
serendipity_printConfigTemplate($t, $from, false, true, IS_installed);
}
/* vim: set sts=4 ts=4 expandtab : */
?>
--- NEW FILE: interop.inc.php ---
<?php # $Id: interop.inc.php,v 1.1.2.1 2004/11/06 11:22:49 garvinhicking Exp $
include_once S9Y_INCLUDE_PATH . 'include/admin/rss_exchange.inc.php';
if (IN_serendipity !== true) {
die ("Don't hack!");
}
session_start();
if (!empty($serendipity['POST']['url'])) {
if (serendipity_rss_import($serendipity['POST']['url'])) {
echo ENTRIES_SUCCESSFULLY_INSERTED . "\n<br />\n";
} else {
echo ENTRIES_NOT_SUCCESSFULLY_INSERTED . "\n<br />\n";
}
} else if (!empty($serendipity['POST']['export'])) {
?>
<a href="<?php echo $serendipity['serendipityHTTPPath']; ?>rss.php?version=2.0&all=1"><?php echo VIEW_FEED_EXPORT; ?></a>
<?php
exit;
} else if (isset($serendipity['POST']['import_mt'])) {
$tasks = serendipity_importMT(file_get_contents($_FILES['serendipity']['tmp_name']['mt_dat']), isset($serendipity['POST']['mt_force']));
if ( is_array($tasks) ) {
echo MAX_COMPAT_OLD_BLOG . "\n<ul>\n";
foreach ( array_unique($tasks) as $task ) {
echo " <li>$task</li>\n";
}
echo "</ul>\n" . IMPORT_AGAIN_FORCE;
}
else {
echo ENTRIES_SUCCESSFULLY_INSERTED . "\n<br />\n";
}
} else if (isset($serendipity['POST']['wp']['submit'])) {
if ( $wp_err = serendipity_importWP($serendipity['POST']['wp']) ) {
echo '<div class="serendipity_msg_important">' . var_dump($wp_err) . '</div>';
}
}
?>
<p>
<h3><?php echo IMPORT; ?> RSS</h3>
<form method="POST">
<div>
<?php echo RSS_IMPORT_DESC; ?><br /><br />
RSS URL: <input type="text" name="serendipity[url]" size="30" /> <?php echo TYPE . ': '; ?><select name="type">
<option value="draft"><?php echo DRAFT; ?></option>
<option value="publish"><?php echo PUBLISH; ?></option>
</select><br />
<?php
$cats = serendipity_fetchCategories('all');
echo RSS_IMPORT_CATEGORY . ': ';
?>
<select name="serendipity[category]">
<option value="0">[ <?php echo NO_CATEGORY; ?> ]</option>
<?php echo serendipity_generateCategoryList($cats, array(), 1); ?>
</select><br />
<input type="checkbox" name="serendipity[bodyonly]" id="bodyonly" value="true" /><label for="bodylonly"><?php echo RSS_IMPORT_BODYONLY; ?></label><br />
<input type="submit" value="<?php echo IMPORT; ?> RSS" />
</div>
</form>
</p>
<p>
<h3><?php echo IMPORT . ' ' . MT_DATA_FILE; ?></h3>
<form method="post" enctype="multipart/form-data">
<?php if (serendipity_maxFileUploadSize()) { ?>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo serendipity_maxFileUploadSize(); ?>" />
<?php } ?>
<div>
<label for="serendipity[mt_dat]"><?php echo MT_DATA_FILE; ?></label>
<input id="serendipity[mt_dat]" type="file" name="serendipity[mt_dat]" size="30" />
</div>
<div>
<label for="serendipity[mt_force]"><?php echo FORCE; ?></label>
<input id="serendipity[mt_force]" type="checkbox" name="serendipity[mt_force]" size="30" />
</div>
<div>
<input type="submit" name="serendipity[import_mt]" value="<?php echo IMPORT . ' ' . MT_DATA_FILE; ?>" />
</div>
</form>
</p>
<p>
<h3><?php echo IMPORT . ' ' . WORDPRESS_DATA; ?></h3>
<form method="post">
<div>
<label for="serendipity_wp_host"><?php echo INSTALL_DBHOST; ?>:</label>
<input type="text" name="serendipity[wp][host]" value="<?php echo isset($serendipity['POST']['wp']['host']) ? $serendipity['POST']['wp']['host'] : $serendipity['dbHost']; ?>" id="serendipity_wp_host"/>
</div>
<div>
<label for="serendipity_wp_user"><?php echo INSTALL_DBUSER; ?>:</label>
<input type="text" name="serendipity[wp][user]" value="<?php echo isset($serendipity['POST']['wp']['user']) ? $serendipity['POST']['wp']['user'] : $serendipity['dbUser']; ?>" id="serendipity_wp_user"/>
</div>
<div>
<label for="serendipity_wp_pass"><?php echo INSTALL_DBPASS; ?>:</label>
<input type="password" name="serendipity[wp][pass]" <?php echo isset($serendipity['POST']['wp']['pass']) ? 'value="' . $serendipity['POST']['wp']['pass'] . '" ' : ($serendipity['serendipityUserlevel'] >= USERLEVEL_ADMIN ? 'value="' . $serendipity['dbPass'] . '" ' : '') ?>id="serendipity_wp_pass"/>
</div>
<div>
<label for="serendipity_wp_name"><?php echo INSTALL_DBNAME; ?>:</label>
<input type="text" name="serendipity[wp][name]" value="<?php echo isset($serendipity['POST']['wp']['name']) ? $serendipity['POST']['wp']['name'] : $serendipity['dbName']; ?>" id="serendipity_wp_name"/>
</div>
<div>
<label for="serendipity_wp_prefix"><?php echo INSTALL_DBPREFIX; ?>:</label>
<input type="text" name="serendipity[wp][prefix]" value="<?php echo isset($serendipity['POST']['wp']['prefix']) ? $serendipity['POST']['wp']['prefix'] : 'wp_'; ?>" id="serendipity_wp_prefix"/>
</div>
<div>
<input type="submit" name="serendipity[wp][submit]" value="<?php echo IMPORT . ' ' . WORDPRESS_DATA; ?>" />
</div>
</form>
</p>
<p>
<h3><?php echo EXPORT; ?></h3>
<form method="POST">
<div>
<input type="submit" name="serendipity[export]" value="<?php echo EXPORT; ?> RSS" />
</div>
</form>
</p>
<?php
/* vim: set sts=4 ts=4 expandtab : */
?>
--- NEW FILE: entries.inc.php ---
<?php # $Id: entries.inc.php,v 1.1.2.1 2004/11/06 11:22:49 garvinhicking Exp $
##########################################################################
# serendipity - another blogger... #
##########################################################################
# #
# (c) 2003 Jannis Hermanns <J...@ha...> #
# http://www.jannis.to/programming/serendipity.html #
# #
##########################################################################
if (IN_serendipity !== true) {
die ("Don't hack!");
}
$sort_order = array('timestamp' => DATE,
'username' => AUTHOR,
'category_name' => CATEGORY,
'last_modified' => LAST_UPDATED,
'title' => TITLE);
$per_page = array('12', '16', '50', '100');
// A little helper we don't want in _functions.inc.php
function serendipity_drawList() {
global $serendipity, $sort_order, $per_page;
$perPage = (!empty($serendipity['GET']['sort']['perPage']) ? $serendipity['GET']['sort']['perPage'] : $per_page[0]);
$page = (int)$serendipity['GET']['page'];
$offSet = $perPage*$page;
if (empty($serendipity['GET']['sort']['ordermode'])) {
$serendipity['GET']['sort']['ordermode'] = 'DESC';
}
if (!empty($serendipity['GET']['sort']['order'])) {
$orderby = serendipity_db_escape_string($serendipity['GET']['sort']['order'] . ' ' . $serendipity['GET']['sort']['ordermode']);
} else {
$orderby = 'timestamp ' . serendipity_db_escape_string($serendipity['GET']['sort']['ordermode']);
}
$filter = array();
if (!empty($serendipity['GET']['filter']['author'])) {
$filter[] = "e.authorid = '" . serendipity_db_escape_string($serendipity['GET']['filter']['author']) . "'";
}
if (!empty($serendipity['GET']['filter']['category'])) {
$filter[] = "ec.categoryid = '" . serendipity_db_escape_string($serendipity['GET']['filter']['category']) . "'";
}
if (!empty($serendipity['GET']['filter']['body'])) {
if ($serendipity['dbType'] == 'mysql') {
$filter[] = "MATCH (title,body,extended) AGAINST ('" . serendipity_db_escape_string($serendipity['GET']['filter']['body']) . "')";
$full = true;
}
}
$filter_sql = implode(' AND ', $filter);
// Fetch the entries
$entries = serendipity_fetchEntries(
false,
false,
serendipity_db_limit(
$offSet,
$perPage
),
true,
false,
$orderby,
$filter_sql
);
?>
<form action="?" method="get">
<div class="serendipity_admin_list">
<input type="hidden" name="serendipity[action]" value="admin" />
<input type="hidden" name="serendipity[adminModule]" value="entries" />
<input type="hidden" name="serendipity[adminAction]" value="editSelect" />
<table width="100%" class="serendipity_admin_filters">
<tr>
<td class="serendipity_admin_filters_headline" colspan="6"><strong><?php echo FILTERS ?></strong> - <?php echo FIND_ENTRIES ?></td>
</tr>
<tr>
<td width="80"><?php echo AUTHOR ?></td>
<td>
<select name="serendipity[filter][author]">
<option value="">--</option>
<?php
$users = serendipity_fetchUsers();
if (is_array($users)) {
foreach ($users AS $user) {
echo '<option value="' . $user['authorid'] . '" ' . (isset($serendipity['GET']['filter']['author']) && $serendipity['GET']['filter']['author'] == $user['authorid'] ? 'selected="selected"' : '') . '>' . $user['username'] . '</option>' . "\n";
}
}
?> </select>
</td>
<td width="80"><?php echo CATEGORY ?></td>
<td>
<select name="serendipity[filter][category]">
<option value="">--</option>
<?php
$categories = serendipity_fetchCategories();
if (is_array($categories)) {
echo serendipity_generateCategoryList($categories, (isset($serendipity['GET']['filter']['category']) ? array($serendipity['GET']['filter']['category']) : array(0)), 2);
}
?> </select>
</td>
<td width="80"><?php echo CONTENT ?></td>
<td><input size="10" type="text" name="serendipity[filter][body]" value="<?php echo (isset($serendipity['GET']['filter']['body']) ? htmlspecialchars($serendipity['GET']['filter']['body']) : '') ?>" /></td>
</tr>
<tr>
<td class="serendipity_admin_filters_headline" colspan="6"><strong><?php echo SORT_ORDER ?></strong></td>
</tr>
<tr>
<td><?php echo SORT_BY ?></td>
<td>
<select name="serendipity[sort][order]">
<?php
foreach($sort_order as $so_key => $so_val) {
echo '<option value="' . $so_key . '" ' . (isset($serendipity['GET']['sort']['order']) && $serendipity['GET']['sort']['order'] == $so_key ? 'selected="selected"': '') . '>' . $so_val . '</option>' . "\n";
}
?> </select>
</td>
<td><?php echo SORT_ORDER ?></td>
<td>
<select name="serendipity[sort][ordermode]">
<option value="DESC" <?php echo (isset($serendipity['GET']['sort']['ordermode']) && $serendipity['GET']['sort']['ordermode'] == 'DESC' ? 'selected="selected"' : '') ?>><?php echo SORT_ORDER_DESC ?></option>
<option value="ASC" <?php echo (isset($serendipity['GET']['sort']['ordermode']) && $serendipity['GET']['sort']['ordermode'] == 'ASC' ? 'selected="selected"' : '') ?>><?php echo SORT_ORDER_ASC ?></option>
</select>
</td>
<td><?php echo ENTRIES_PER_PAGE ?></td>
<td>
<select name="serendipity[sort][perPage]">
<?php
foreach($per_page AS $per_page_nr) {
echo '<option value="' . $per_page_nr . '" ' . (isset($serendipity['GET']['sort']['perPage']) && $serendipity['GET']['sort']['perPage'] == $per_page_nr ? 'selected="selected"' : '') . '>' . $per_page_nr . '</option>' . "\n";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right" colspan="6"><input type="submit" name="go" value="<?php echo GO ?>" /></td>
</tr>
</table>
<table class="serendipity_admin_list" cellpadding="5" width="100%">
<?php
if (is_array($entries)) {
$count = count($entries);
$qString = '?serendipity[adminModule]=entries&serendipity[adminAction]=editSelect';
foreach ((array)$serendipity['GET']['sort'] as $k => $v) {
$qString .= '&serendipity[sort]['. $k .']='. $v;
}
foreach ((array)$serendipity['GET']['filter'] as $k => $v) {
$qString .= '&serendipity[filter]['. $k .']='. $v;
}
$linkPrevious = $qString . '&serendipity[page]=' . ($page-1);
$linkNext = $qString . '&serendipity[page]=' . ($page+1);
?>
<tr>
<td>
<input type="button" name="serendipity[prevpage]" value="<<<" onclick="location.href='<?php echo $linkPrevious ?>'" <?php if ($offSet <= 0) echo ' disabled="disabled"' ?> />
</td>
<td align="right">
<input type="button" name="serendipity[nextpage]" value=">>>" onclick="location.href='<?php echo $linkNext ?>'" <?php if ($count != $perPage) echo ' disabled="disabled"'; ?> />
</td>
</tr>
</table>
<table class="serendipity_admin_list" cellpadding="5" width="100%">
<?php
// Print the entries
$rows = 0;
foreach ( $entries as $entry ) {
$rows++;
// Find out if the entry has been modified later than 30 minutes after creation
if ($entry['timestamp'] <= ($entry['last_modified'] - 60*30)) {
$lm = '<a href="#" title="' . LAST_UPDATED . ': ' . serendipity_formatTime(DATE_FORMAT_SHORT, $entry['last_modified']) . '" onclick="alert(this.title)">*</a>';
} else {
$lm = '';
}
?>
<tr>
<td class="serendipity_admin_list_item serendipity_admin_list_item_<?php echo ($rows % 2 ? 'even' : 'uneven'); ?>">
<table width="100%">
<tr>
<td>
<strong><?php if ($entry['isdraft'] == 'true') echo DRAFT . ': '; ?><a href="?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=edit&serendipity[id]=<?php echo $entry['id']; ?>" title="#<?php echo $entry['id']; ?>"><?php echo serendipity_truncateString($entry['title'],50) ?></a></strong>
</td>
<td align="right">
<?php echo serendipity_formatTime(DATE_FORMAT_SHORT, $entry['timestamp']) . ' ' .$lm; ?>
</td>
</tr>
<tr>
<td>
<?php
echo POSTED_BY . ' ' . $entry['username'];
if (count($entry['categories'])) {
echo ' ' . IN . ' ';
$cats = array();
foreach ($entry['categories'] as $cat) {
$cats[] = '<a href="' . $serendipity['serendipityHTTPPath'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'categories/' . $cat['categoryid'] . '_' . serendipity_makeFilename($cat['category_name']) . '">' . $cat['category_name'] . '</a>';
}
echo implode(', ', $cats);
}
?>
</td>
<td align="right">
[<a href="?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=edit&serendipity[id]=<?php echo $entry['id']; ?>" title="#<?php echo $entry['id']; ?>"><?php echo EDIT ?></a>]
- [<a href="?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=delete&serendipity[id]=<?php echo $entry['id']; ?>" title="#<?php echo $entry['id']; ?>"><?php echo DELETE ?></a>]
</td>
</tr>
</table>
</td>
</tr>
<?php
} // end entries output
?>
<tr>
<td class="serendipity_admin_list_item serendipity_admin_list_item_<?php echo (($rows+1) % 2 ? 'even' : 'uneven'); ?>">
<br />
<?php echo EDIT_ENTRY . ': #<input type="text" size="3" name="serendipity[id]" /> <input type="submit" name="serendipity[editSubmit]" value="' . GO . '" />'; ?>
</td>
</tr>
<?php
} else {
// We've got nothing
?>
<tr>
<td align="center">
- <?php echo NO_ENTRIES_TO_PRINT ?> -
</td>
</tr>
<?php
}
?>
</table>
</div>
</form>
<?php
} // End function serendipity_drawList()
if (!empty($serendipity['GET']['editSubmit'])) {
$serendipity['GET']['adminAction'] = 'edit';
}
switch($serendipity['GET']['adminAction']) {
case 'save':
$entry = array(
'id' => $serendipity['POST']['id'],
'title' => $serendipity['POST']['title'],
'timestamp' => $serendipity['POST']['timestamp'],
'body' => $serendipity['POST']['body'],
'extended' => $serendipity['POST']['extended'],
'categories' => $serendipity['POST']['categories'],
'isdraft' => $serendipity['POST']['isdraft'],
'allow_comments' => $serendipity['POST']['allow_comments'],
'moderate_comments' => $serendipity['POST']['moderate_comments'],
'exflag' => (!empty($serendipity['POST']['extended']) ? true : false)
);
if ($entry['allow_comments'] != 'true' && $entry['allow_comments'] !== true) {
$entry['allow_comments'] = 'false';
}
if ($entry['moderate_comments'] != 'true' && $entry['moderate_comments'] !== true) {
$entry['moderate_comments'] = 'false';
}
// Check if the user changed the timestamp.
if (isset($serendipity['allowDateManipulation']) && $serendipity['allowDateManipulation'] && isset($serendipity['POST']['new_timestamp']) && $serendipity['POST']['new_timestamp'] != date(DATE_FORMAT_2, $serendipity['POST']['chk_timestamp'])) {
// The user changed the timestamp, now set the DB-timestamp to the user's date
$entry['timestamp'] = strtotime($serendipity['POST']['new_timestamp']);
if ($entry['timestamp'] == -1) {
echo DATE_INVALID . '<br />';
// The date given by the user is not convertable. Reset the timestamp.
$entry['timestamp'] = $serendipity['POST']['timestamp'];
}
}
if ($serendipity['POST']['quicksave'] == 'true') {
// When quicksaving a new entry, set it to 'draft'
if (!is_numeric($entry['id'])) {
$entry['isdraft'] = 'true';
}
$serendipity['POST']['preview'] = 'true';
$res = serendipity_updertEntry($entry);
if (is_string($res)) {
echo '<div class="serendipity_msg_error">' . QUICKSAVE . ': <b>' . $res . '</b></div><br />';
} else {
// serendipity_updertEntry sets this global variable to store the entry id. Couldn't pass this
// by reference or as return value because it affects too many places inside our API and dependant
// function calls.
if (!empty($serendipity['lastSavedEntry'])) {
$entry['id'] = $serendipity['lastSavedEntry'];
}
echo '<div class="serendipity_msg_notice">' . QUICKSAVE . ': ' . ENTRY_SAVED . '</div><br />';
}
}
// Save the entry, or just display a preview
if ($serendipity['POST']['preview'] != 'true') {
$res = serendipity_updertEntry($entry);
if (is_string($res)) {
serendipity_printEntryForm(
'?',
array(
'serendipity[action]' => 'admin',
'serendipity[adminModule]' => 'entries',
'serendipity[adminAction]' => 'save'
),
$entry,
ERROR . ': <b>' . $res . '</b>');
} else {
echo '<div class="serendipity_msg_notice">' . ENTRY_SAVED . '</div>';
}
} else {
// Only display the preview
$serendipity['hidefooter'] = true;
if (!is_numeric($entry['timestamp'])) $entry['timestamp'] = time();
if (!isset($entry['trackbacks']) || !$entry['trackbacks']) $entry['trackbacks'] = 0;
if (!isset($entry['comments']) || !$entry['comments']) $entry['comments'] = 0;
if (!isset($entry['username']) || !$entry['username']) $entry['username'] = $serendipity['serendipityUser'];
$categories ...
[truncated message content] |