Update of /cvsroot/php-blog/serendipity/include
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9042/include
Modified Files:
functions.inc.php functions_config.inc.php
functions_entries.inc.php
Log Message:
moved around functions so that they can be used within the installer module.
fresh installations will now no longer fail
Index: functions_config.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/functions_config.inc.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- functions_config.inc.php 19 Nov 2004 11:05:29 -0000 1.2
+++ functions_config.inc.php 30 Nov 2004 13:28:02 -0000 1.3
@@ -119,5 +119,219 @@
}
}
+function serendipity_logout() {
+ $_SESSION['serendipityAuthedUser'] = false;
+ @session_destroy();
+ serendipity_deleteCookie('author_information');
+}
+
+function serendipity_login() {
+ global $serendipity;
+
+ if (serendipity_authenticate_author()) {
+ #The session has this data already
+ #we previously just checked the value of $_SESSION['serendipityAuthedUser'] but
+ #we need the authorid still, so call serendipity_authenticate_author with blank
+ #params
+ return true;
+ }
+
+ if (serendipity_authenticate_author($serendipity['POST']['user'], $serendipity['POST']['pass'])) {
+ if (empty($serendipity['POST']['auto'])) {
+ serendipity_deleteCookie('author_information');
+ return false;
+ } else {
+ $package = serialize(array('username' => $serendipity['POST']['user'],
+ 'password' => $serendipity['POST']['pass']));
+ serendipity_setCookie('author_information', base64_encode($package));
+ return true;
+ }
+ } elseif ( isset($serendipity['COOKIE']['author_information']) ) {
+ $cookie = unserialize(base64_decode($serendipity['COOKIE']['author_information']));
+ if (serendipity_authenticate_author($cookie['username'], $cookie['password'])) {
+ return true;
+ } else {
+ serendipity_deleteCookie('author_information');
+ return false;
+ }
+ }
+}
+
+function serendipity_userLoggedIn() {
+ if ($_SESSION['serendipityAuthedUser'] === true && IS_installed) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+function serendipity_setCookie($name,$value) {
+ global $serendipity;
+
+ setcookie("serendipity[$name]", $value, time()+60*60*24*30, $serendipity['serendipityHTTPPath']);
+ $_COOKIE[$name] = $value;
+ $serendipity['COOKIE'][$name] = $value;
+}
+
+function serendipity_deleteCookie($name) {
+ global $serendipity;
+
+ setcookie("serendipity[$name]", '', time()-4000);
+ unset($_COOKIE[$name]);
+ unset($serendipity['COOKIE'][$name]);
+}
+
+function serendipity_authenticate_author($username = '', $password = '', $is_md5 = false) {
+ global $serendipity;
+
+ if (isset($_SESSION['serendipityUser']) && isset($_SESSION['serendipityPassword']) && isset($_SESSION['serendipityAuthedUser']) && $_SESSION['serendipityAuthedUser'] == true) {
+ $username = $_SESSION['serendipityUser'];
+ $password = $_SESSION['serendipityPassword'];
+ // For safety reasons when multiple blogs are installed on the same host, we need to check the current author each time to not let him log into a different blog with the same sessiondata
+ $is_md5 = true;
+ }
+
+ if ($username != '') {
+ if ($is_md5 === false && !empty($password)) {
+ $password = md5($password);
+ }
+
+ $query = "SELECT DISTINCT
+ email, authorid, userlevel, right_publish
+ FROM
+ $serendipity[dbPrefix]authors
+ WHERE
+ username = '" . serendipity_db_escape_string($username) . "'
+ AND password = '" . serendipity_db_escape_string($password) . "'";
+ $row = serendipity_db_query($query, true, 'assoc');
+
+ if (is_array($row)) {
+ $_SESSION['serendipityUser'] = $serendipity['serendipityUser'] = $username;
+ $_SESSION['serendipityPassword'] = $serendipity['serendipityPassword'] = $password;
+ $_SESSION['serendipityEmail'] = $serendipity['serendipityEmail'] = $row['email'];
+ $_SESSION['serendipityAuthorid'] = $serendipity['authorid'] = $row['authorid'];
+ $_SESSION['serendipityUserlevel'] = $serendipity['serendipityUserlevel'] = $row['userlevel'];
+ $_SESSION['serendipityAuthedUser'] = $serendipity['serendipityAuthedUser'] = true;
+ $_SESSION['serendipityRightPublish']= $serendipity['serendipityRightPublish'] = $row['right_publish'];
+ serendipity_load_configuration($serendipity['authorid']);
+ return true;
+ } else {
+ $_SESSION['serendipityAuthedUser'] = false;
+ @session_destroy();
+ }
+ }
+
+ return false;
+}
+
+function serendipity_is_iframe() {
+ global $serendipity;
+
+ if ($serendipity['GET']['is_iframe'] && is_array($_SESSION['save_entry'])) {
+ // An iframe may NOT contain <html> and </html> tags, that's why we emit different headers here than on serendipity_admin.php
+?>
+ <head>
+ <title><?php echo SERENDIPITY_ADMIN_SUITE; ?></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=<?php echo LANG_CHARSET; ?>" />
+ <link rel="stylesheet" type="text/css" href="<?php echo (isset($serendipity['serendipityHTTPPath']) ? $serendipity['serendipityHTTPPath'] : ''); ?>serendipity.css.php" />
+<?php
+ if (!empty($serendipity['extCSS']) && strtolower($serendipity['extCSS']) != 'none') {
+?>
+ <link rel="stylesheet" type="text/css" href="<?php echo $serendipity['extCSS']; ?>" />
+<?php
+ }
+?>
+ </head>
+
+ <body style="padding: 0px; margin: 0px;">
+ <div id="mainpane" style="padding: 0px; margin: 5px auto 5px auto; width: 98%;">
+ <div id="content" style="padding: 5px; margin: 0px;">
+<?php
+ // We need to restore GET/POST variables to that depending plugins inside the iframe
+ // can still fetch all that variables; and we also tighten security by not allowing
+ // to pass any different GET/POST variables to our iframe.
+ $iframe_mode = $serendipity['GET']['iframe_mode'];
+ $serendipity['POST'] = &$_SESSION['save_entry_POST'];
+ $serendipity['GET'] = &$_SESSION['save_entry_POST']; // GET-Vars are the same as POST to ensure compatibility.
+ ignore_user_abort(true);
+ serendipity_iframe($_SESSION['save_entry'], $iframe_mode);
+?>
+ </div>
+ </div>
+ </body>
+<?php
+ return true;
+ }
+ return false;
+}
+
+function serendipity_iframe(&$entry, $mode = null) {
+ global $serendipity;
+
+ if (empty($mode) || !is_array($entry)) {
+ return false;
+ }
+
+ switch ($mode) {
+ case 'save':
+ echo '<div style="float: left; height: 75px"></div>';
+ $res = serendipity_updertEntry($entry);
+ if (is_string($res)) {
+ echo '<div class="serendipity_msg_error">' . ERROR . ': <b>' . $res . '</b></div>';
+ } else {
+ if (!empty($serendipity['lastSavedEntry'])) {
+ // Last saved entry must be propagated to entry form so that if the user re-edits it,
+ // it needs to be stored with the new ID.
+ echo '<script type="text/javascript">parent.document.forms[\'serendipityEntry\'][\'serendipity[id]\'].value = "' . $serendipity['lastSavedEntry'] . '";</script>';
+ }
+ echo '<div class="serendipityAdminMsgSuccess">' . ENTRY_SAVED . '</div>';
+ }
+ echo '<br style="clear: both" />';
+
+ return true;
+ break;
+
+ case 'preview':
+ echo '<div style="float: left; height: 225px"></div>';
+ $serendipity['smarty_raw_mode'] = true; // Force output of Smarty stuff in the backend
+ serendipity_smarty_init();
+ $serendipity['smarty']->assign('is_preview', true);
+
+ serendipity_printEntries(array($entry), ($entry['extended'] != '' ? 1 : 0), true);
+ echo '<br style="clear: both" />';
+
+ return true;
+ break;
+ }
+
+ return false;
+}
+
+function serendipity_iframe_create($mode, &$entry) {
+ global $serendipity;
+
+ $_SESSION['save_entry'] = $entry;
+ $_SESSION['save_entry_POST'] = $serendipity['POST'];
+
+ // TODO: Use a language constant for those strings
+
+ $attr = '';
+ switch($mode) {
+ case 'save':
+ $attr = ' height="100" ';
+ echo '<div class="serendipityAdminMsgSuccess">' . IFRAME_PREVIEW . '</div><br />';
+ break;
+
+ case 'preview':
+ $attr = ' height="300" ';
+ echo '<div class="serendipityAdminMsgSuccess">' . IFRAME_SAVE . '</div><br />';
+ break;
+ }
+
+ echo '<iframe src="serendipity_admin.php?serendipity[is_iframe]=true&serendipity[iframe_mode]=' . $mode . '" id="serendipity_iframe" name="serendipity_iframe" ' . $attr . ' width="100%" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto" title="Serendipity">'
+ . IFRAME_WARNING
+ . '</iframe><br /><br />';
+}
+
/* vim: set sts=4 ts=4 expandtab : */
?>
\ No newline at end of file
Index: functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/functions.inc.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- functions.inc.php 30 Nov 2004 11:27:55 -0000 1.6
+++ functions.inc.php 30 Nov 2004 13:28:01 -0000 1.7
@@ -68,53 +68,6 @@
return ucfirst(serendipity_strftime($cache[$format], (int)$time, $useOffset));
}
-
-function serendipity_logout() {
- $_SESSION['serendipityAuthedUser'] = false;
- @session_destroy();
- serendipity_deleteCookie('author_information');
-}
-
-function serendipity_login() {
- global $serendipity;
-
- if (serendipity_authenticate_author()) {
- #The session has this data already
- #we previously just checked the value of $_SESSION['serendipityAuthedUser'] but
- #we need the authorid still, so call serendipity_authenticate_author with blank
- #params
- return true;
- }
-
- if (serendipity_authenticate_author($serendipity['POST']['user'], $serendipity['POST']['pass'])) {
- if (empty($serendipity['POST']['auto'])) {
- serendipity_deleteCookie('author_information');
- return false;
- } else {
- $package = serialize(array('username' => $serendipity['POST']['user'],
- 'password' => $serendipity['POST']['pass']));
- serendipity_setCookie('author_information', base64_encode($package));
- return true;
- }
- } elseif ( isset($serendipity['COOKIE']['author_information']) ) {
- $cookie = unserialize(base64_decode($serendipity['COOKIE']['author_information']));
- if (serendipity_authenticate_author($cookie['username'], $cookie['password'])) {
- return true;
- } else {
- serendipity_deleteCookie('author_information');
- return false;
- }
- }
-}
-
-function serendipity_userLoggedIn() {
- if ($_SESSION['serendipityAuthedUser'] === true && IS_installed) {
- return true;
- } else {
- return false;
- }
-}
-
function serendipity_fetchTemplates() {
global $serendipity;
$dir = opendir($serendipity['serendipityPath'] . $serendipity['templatePath']);
@@ -149,22 +102,6 @@
return $data;
}
-function serendipity_setCookie($name,$value) {
- global $serendipity;
-
- setcookie("serendipity[$name]", $value, time()+60*60*24*30, $serendipity['serendipityHTTPPath']);
- $_COOKIE[$name] = $value;
- $serendipity['COOKIE'][$name] = $value;
-}
-
-function serendipity_deleteCookie($name) {
- global $serendipity;
-
- setcookie("serendipity[$name]", '', time()-4000);
- unset($_COOKIE[$name]);
- unset($serendipity['COOKIE'][$name]);
-}
-
function serendipity_fetchUsers($user = '') {
global $serendipity;
@@ -394,49 +331,6 @@
return array($f, $suf);
}
-function serendipity_authenticate_author($username = '', $password = '', $is_md5 = false) {
- global $serendipity;
-
- if (isset($_SESSION['serendipityUser']) && isset($_SESSION['serendipityPassword']) && isset($_SESSION['serendipityAuthedUser']) && $_SESSION['serendipityAuthedUser'] == true) {
- $username = $_SESSION['serendipityUser'];
- $password = $_SESSION['serendipityPassword'];
- // For safety reasons when multiple blogs are installed on the same host, we need to check the current author each time to not let him log into a different blog with the same sessiondata
- $is_md5 = true;
- }
-
- if ($username != '') {
- if ($is_md5 === false && !empty($password)) {
- $password = md5($password);
- }
-
- $query = "SELECT DISTINCT
- email, authorid, userlevel, right_publish
- FROM
- $serendipity[dbPrefix]authors
- WHERE
- username = '" . serendipity_db_escape_string($username) . "'
- AND password = '" . serendipity_db_escape_string($password) . "'";
- $row = serendipity_db_query($query, true, 'assoc');
-
- if (is_array($row)) {
- $_SESSION['serendipityUser'] = $serendipity['serendipityUser'] = $username;
- $_SESSION['serendipityPassword'] = $serendipity['serendipityPassword'] = $password;
- $_SESSION['serendipityEmail'] = $serendipity['serendipityEmail'] = $row['email'];
- $_SESSION['serendipityAuthorid'] = $serendipity['authorid'] = $row['authorid'];
- $_SESSION['serendipityUserlevel'] = $serendipity['serendipityUserlevel'] = $row['userlevel'];
- $_SESSION['serendipityAuthedUser'] = $serendipity['serendipityAuthedUser'] = true;
- $_SESSION['serendipityRightPublish']= $serendipity['serendipityRightPublish'] = $row['right_publish'];
- serendipity_load_configuration($serendipity['authorid']);
- return true;
- } else {
- $_SESSION['serendipityAuthedUser'] = false;
- @session_destroy();
- }
- }
-
- return false;
-}
-
function serendipity_track_referrer($entry = 0) {
global $serendipity;
@@ -682,4 +576,4 @@
define("serendipity_FUNCTIONS_LOADED", true);
/* vim: set sts=4 ts=4 expandtab : */
-?>
+?>
\ No newline at end of file
Index: functions_entries.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/functions_entries.inc.php,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- functions_entries.inc.php 30 Nov 2004 11:27:56 -0000 1.15
+++ functions_entries.inc.php 30 Nov 2004 13:28:02 -0000 1.16
@@ -1582,111 +1582,3 @@
serendipity_smarty_fetch('ARCHIVES', 'entries_archives.tpl', true);
}
-function serendipity_is_iframe() {
- global $serendipity;
-
- if ($serendipity['GET']['is_iframe'] && is_array($_SESSION['save_entry'])) {
- // An iframe may NOT contain <html> and </html> tags, that's why we emit different headers here than on serendipity_admin.php
-?>
- <head>
- <title><?php echo SERENDIPITY_ADMIN_SUITE; ?></title>
- <meta http-equiv="Content-Type" content="text/html; charset=<?php echo LANG_CHARSET; ?>" />
- <link rel="stylesheet" type="text/css" href="<?php echo (isset($serendipity['serendipityHTTPPath']) ? $serendipity['serendipityHTTPPath'] : ''); ?>serendipity.css.php" />
-<?php
- if (!empty($serendipity['extCSS']) && strtolower($serendipity['extCSS']) != 'none') {
-?>
- <link rel="stylesheet" type="text/css" href="<?php echo $serendipity['extCSS']; ?>" />
-<?php
- }
-?>
- </head>
-
- <body style="padding: 0px; margin: 0px;">
- <div id="mainpane" style="padding: 0px; margin: 5px auto 5px auto; width: 98%;">
- <div id="content" style="padding: 5px; margin: 0px;">
-<?php
- // We need to restore GET/POST variables to that depending plugins inside the iframe
- // can still fetch all that variables; and we also tighten security by not allowing
- // to pass any different GET/POST variables to our iframe.
- $iframe_mode = $serendipity['GET']['iframe_mode'];
- $serendipity['POST'] = &$_SESSION['save_entry_POST'];
- $serendipity['GET'] = &$_SESSION['save_entry_POST']; // GET-Vars are the same as POST to ensure compatibility.
- ignore_user_abort(true);
- serendipity_iframe($_SESSION['save_entry'], $iframe_mode);
-?>
- </div>
- </div>
- </body>
-<?php
- return true;
- }
- return false;
-}
-
-function serendipity_iframe(&$entry, $mode = null) {
- global $serendipity;
-
- if (empty($mode) || !is_array($entry)) {
- return false;
- }
-
- switch ($mode) {
- case 'save':
- echo '<div style="float: left; height: 75px"></div>';
- $res = serendipity_updertEntry($entry);
- if (is_string($res)) {
- echo '<div class="serendipity_msg_error">' . ERROR . ': <b>' . $res . '</b></div>';
- } else {
- if (!empty($serendipity['lastSavedEntry'])) {
- // Last saved entry must be propagated to entry form so that if the user re-edits it,
- // it needs to be stored with the new ID.
- echo '<script type="text/javascript">parent.document.forms[\'serendipityEntry\'][\'serendipity[id]\'].value = "' . $serendipity['lastSavedEntry'] . '";</script>';
- }
- echo '<div class="serendipityAdminMsgSuccess">' . ENTRY_SAVED . '</div>';
- }
- echo '<br style="clear: both" />';
-
- return true;
- break;
-
- case 'preview':
- echo '<div style="float: left; height: 225px"></div>';
- $serendipity['smarty_raw_mode'] = true; // Force output of Smarty stuff in the backend
- serendipity_smarty_init();
- $serendipity['smarty']->assign('is_preview', true);
-
- serendipity_printEntries(array($entry), ($entry['extended'] != '' ? 1 : 0), true);
- echo '<br style="clear: both" />';
-
- return true;
- break;
- }
-
- return false;
-}
-
-function serendipity_iframe_create($mode, &$entry) {
- global $serendipity;
-
- $_SESSION['save_entry'] = $entry;
- $_SESSION['save_entry_POST'] = $serendipity['POST'];
-
- // TODO: Use a language constant for those strings
-
- $attr = '';
- switch($mode) {
- case 'save':
- $attr = ' height="100" ';
- echo '<div class="serendipityAdminMsgSuccess">' . IFRAME_PREVIEW . '</div><br />';
- break;
-
- case 'preview':
- $attr = ' height="300" ';
- echo '<div class="serendipityAdminMsgSuccess">' . IFRAME_SAVE . '</div><br />';
- break;
- }
-
- echo '<iframe src="serendipity_admin.php?serendipity[is_iframe]=true&serendipity[iframe_mode]=' . $mode . '" id="serendipity_iframe" name="serendipity_iframe" ' . $attr . ' width="100%" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto" title="Serendipity">'
- . IFRAME_WARNING
- . '</iframe><br /><br />';
-}
|