From 0c85bcbcc75c1d1653df9b5b8836684bf075b74b Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Wed, 30 May 2007 11:20:53 +0000 Subject: [PATCH] Allow possibility to style the backend (surrounding layout + entry editor so far) --- docs/NEWS | 7 + include/functions_config.inc.php | 37 +- include/functions_entries_admin.inc.php | 59 ++- include/functions_smarty.inc.php | 19 +- serendipity_admin.php | 461 ++++++++++++++---------- templates/default/admin/entries.tpl | 227 ++++++++++++ templates/default/admin/index.tpl | 240 ++++++++++++ 7 files changed, 839 insertions(+), 211 deletions(-) create mode 100644 templates/default/admin/entries.tpl create mode 100644 templates/default/admin/index.tpl diff --git a/docs/NEWS b/docs/NEWS index d09ca2a8..800f5bf4 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,13 @@ Version 1.2 () ------------------------------------------------------------------------ + * Add admin backend templates for main area and the entry editor. + Falls back to default PHP output if Smarty cannot be utilized. + (garvinhicking) + + * Fix properly reinstantiating sessions and properly deleting cookies + when requested (garvinhicking) + * Add support for sqlite3 (http://php-sqlite3.sourceforge.net/), by geekmug diff --git a/include/functions_config.inc.php b/include/functions_config.inc.php index 03972156..d7314543 100644 --- a/include/functions_config.inc.php +++ b/include/functions_config.inc.php @@ -336,8 +336,24 @@ function serendipity_load_configuration($author = null) { */ function serendipity_logout() { $_SESSION['serendipityAuthedUser'] = false; - @session_destroy(); + serendipity_session_destroy(); serendipity_deleteCookie('author_information'); + serendipity_deleteCookie('author_token'); +} + +/** + * Destroys a session, keeps important stuff intact. + * @access public + * @return null + */ +function serendipity_session_destroy() { + $no_smarty = $_SESSION['no_smarty']; + @session_destroy(); + session_regenerate_id(); + session_start(); + + $_SESSION['SERVER_GENERATED_SID'] = true; + $_SESSION['no_smarty'] = $no_smarty; } /** @@ -437,7 +453,7 @@ function serendipity_checkAutologin($ident, $iv) { if ($autologin['name'] < (time()-86400)) { // Issued autologin cookie has been issued more than 1 day ago. Re-Issue new cookie, invalidate old one to prevent abuse - serendipity_header('X-ReIssue-Cookie: +' . (time() - $autologin['name']) . 's'); + if ($serendipity['expose_s9y']) serendipity_header('X-ReIssue-Cookie: +' . (time() - $autologin['name']) . 's'); serendipity_issueAutologin($cookie); } @@ -445,9 +461,9 @@ function serendipity_checkAutologin($ident, $iv) { } function serendipity_setAuthorToken() { - $hash = sha1(uniqid(rand(), true)); - serendipity_setCookie('author_token', $hash); - $_SESSION['author_token'] = $hash; + $hash = sha1(uniqid(rand(), true)); + serendipity_setCookie('author_token', $hash); + $_SESSION['author_token'] = $hash; } /** @@ -516,7 +532,7 @@ function serendipity_authenticate_author($username = '', $password = '', $is_md5 return true; } else { $_SESSION['serendipityAuthedUser'] = false; - @session_destroy(); + serendipity_session_destroy(); } } @@ -613,7 +629,12 @@ function serendipity_setCookie($name, $value, $securebyprot = true) { function serendipity_deleteCookie($name) { global $serendipity; - setcookie("serendipity[$name]", '', time()-4000); + $host = $_SERVER['HTTP_HOST']; + if ($pos = strpos($host, ":")) { + $host = substr($host, 0, $pos); + } + + setcookie("serendipity[$name]", '', time()-4000, $serendipity['serendipityHTTPPath'], $host); unset($_COOKIE[$name]); unset($serendipity['COOKIE'][$name]); } @@ -874,7 +895,7 @@ function serendipity_getSessionLanguage() { return $serendipity['lang']; } else { $_SESSION['serendipityLanguage'] = $lang; - if (! is_null($serendipity['detected_lang'])) { + if (!is_null($serendipity['detected_lang'])) { if ($serendipity['expose_s9y']) serendipity_header('X-Serendipity-InterfaceLang: ' . $lang); } } diff --git a/include/functions_entries_admin.inc.php b/include/functions_entries_admin.inc.php index 6321489d..1d7a1872 100644 --- a/include/functions_entries_admin.inc.php +++ b/include/functions_entries_admin.inc.php @@ -36,31 +36,41 @@ function serendipity_printEntryForm($targetURL, $hiddens = array(), $entry = arr $draftP = ''; $categoryselector_expanded = false; + $template_vars = array(); + serendipity_plugin_api::hook_event('backend_entryform', $entry); if ( (isset($entry['isdraft']) && serendipity_db_bool($entry['isdraft'])) || (!isset($entry['isdraft']) && $serendipity['publishDefault'] == 'draft') ) { $draftD = ' selected="selected"'; + $template_vars['draft_mode'] = 'draft'; } else { $draftP = ' selected="selected"'; + $template_vars['draft_mode'] = 'publish'; } if (isset($entry['moderate_comments']) && (serendipity_db_bool($entry['moderate_comments']))) { + $template_vars['moderate_comments'] = true; $moderate_comments = ' checked="checked"'; } elseif (!isset($entry['moderate_comments']) && ($serendipity['moderateCommentsDefault'] == 'true' || $serendipity['moderateCommentsDefault'] === true)) { // This is the default on creation of a new entry and depends on the "moderateCommentsDefault" variable of the configuration. $moderate_comments = ' checked="checked"'; + $template_vars['moderate_comments'] = true; } else { $moderate_comments = ''; + $template_vars['moderate_comments'] = false; } if (isset($entry['allow_comments']) && (serendipity_db_bool($entry['allow_comments']))) { + $template_vars['allow_comments'] = true; $allow_comments = ' checked="checked"'; } elseif ((!isset($entry['allow_comments']) || $entry['allow_comments'] !== 'false') && (!isset($serendipity['allowCommentsDefault']) || $serendipity['allowCommentsDefault'] == 'true' || $serendipity['allowCommentsDefault'] === true)) { // This is the default on creation of a new entry and depends on the "allowCommentsDefault" variable of the configuration. + $template_vars['allow_comments'] = true; $allow_comments = ' checked="checked"'; } else { + $template_vars['allow_comments'] = false; $allow_comments = ''; } @@ -94,10 +104,19 @@ function serendipity_printEntryForm($targetURL, $hiddens = array(), $entry = arr if (is_array($cats = serendipity_fetchCategories())) { $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED); - foreach ( $cats as $cat ) { - $cat_list .= '' . "\n"; + foreach ($cats as $cat) { + + if (in_array($cat['categoryid'], $selected)) { + $cat['is_selected'] = true; + } + + $cat['depth_pad'] = str_repeat(' ', $cat['depth']); + + $template_vars['category_options'][] = $cat; + $cat_list .= '' . "\n"; } } + $cat_list .= '' . $n; if (!empty($serendipity['GET']['title'])) { @@ -120,6 +139,42 @@ function serendipity_printEntryForm($targetURL, $hiddens = array(), $entry = arr $hidden .= ' ' . $n; $hidden .= ' '; $hidden .= ' ' . serendipity_setFormToken(); + + if (is_object($serendipity['smarty'])) { + if (isset($serendipity['allowDateManipulation']) && $serendipity['allowDateManipulation']) { + $template_vars['allowDateManipulation'] = true; + } + + if ((!empty($entry['extended']) || !empty($serendipity['COOKIE']['toggle_extended'])) && !$serendipity['wysiwyg']) { + $template_vars['show_wysiwyg'] = true; + } + + if (eregi($serendipity['EditorBrowsers'], $_SERVER['HTTP_USER_AGENT']) ) { + $template_vars['wysiwyg_advanced'] = true; + } + + $template_vars['timestamp'] = serendipity_serverOffsetHour(isset($entry['timestamp']) && $entry['timestamp'] > 0 ? $entry['timestamp'] : time()); + $template_vars['reset_timestamp'] = serendipity_serverOffsetHour(time()); + $template_vars['hidden'] = $hidden; + $template_vars['errMsG'] = $errMsg; + $template_vars['entry'] =& $entry; + $template_vars['targetURL'] = $targetURL; + $template_vars['cat_count'] = count($cats)+1; + $template_vars['cat_state'] = $categoryselector_expanded ? 'on' : 'off'; + $template_vars['wysiwyg'] = $serendipity['wysiwyg']; + $template_vars['serendipityRightPublish'] = $_SESSION['serendipityRightPublish']; + $template_vars['wysiwyg_blocks'] = array( + 'body' => 'serendipity[body]', + 'extended' => 'serendipity[extended]' + ); + $serendipity['smarty']->register_modifier('emit_htmlarea_code', 'serendipity_emit_htmlarea_code'); + $serendipity['smarty']->assign('admin_view', 'entryform'); + $serendipity['smarty']->assign_by_ref('entry_vars', $template_vars); + $serendipity['smarty']->display(serendipity_getTemplateFile('admin/entries.tpl', 'serendipityPath')); + return true; + } + + /* HTML CODE BELOW IS FOR FALLBACK PORTABILITY ONLY - MODIFY CODE IN TEMPLATE ADMIN/ENTRIES.TPL INSTEAD! */ if (!empty($errMsg)) { ?>
diff --git a/include/functions_smarty.inc.php b/include/functions_smarty.inc.php index 7469c93d..01fefdf4 100644 --- a/include/functions_smarty.inc.php +++ b/include/functions_smarty.inc.php @@ -695,12 +695,20 @@ function serendipity_smarty_init($vars = array()) { // Beware: Smarty is used in the Admin backend, despite of this. include $template_dir . '/template.inc.php'; } else { - // Default Smarty Engine will be used + // Set a session variable if Smarty fails: + $prev_smarty = $_SESSION['no_smarty']; + $_SESSION['no_smarty'] = true; + // Default Smarty Engine will be used @define('SMARTY_DIR', S9Y_PEAR_PATH . 'Smarty/libs/'); if (!class_exists('Smarty')) { - require SMARTY_DIR . 'Smarty.class.php'; + include SMARTY_DIR . 'Smarty.class.php'; } + + if (!class_exists('Smarty')) { + return false; + } + $serendipity['smarty'] = new Smarty; if ($serendipity['production'] === 'debug') { $serendipity['smarty']->force_compile = true; @@ -714,9 +722,13 @@ function serendipity_smarty_init($vars = array()) { $serendipity['smarty']->compile_dir = $serendipity['serendipityPath'] . PATH_SMARTY_COMPILE; if (!is_dir($serendipity['smarty']->compile_dir) || !is_writable($serendipity['smarty']->compile_dir)) { - serendipity_die(sprintf(DIRECTORY_WRITE_ERROR, $serendipity['smarty']->compile_dir)); + printf(DIRECTORY_WRITE_ERROR, $serendipity['smarty']->compile_dir); + return false; } + // Hooray for Smarty: + $_SESSION['no_smarty'] = $prev_smarty; + $serendipity['smarty']->config_dir = $template_dir; $serendipity['smarty']->secure_dir = array($serendipity['serendipityPath'] . $serendipity['templatePath']); $serendipity['smarty']->security_settings['MODIFIER_FUNCS'] = array('sprintf', 'sizeof', 'count', 'rand', 'print_r', 'str_repeat'); @@ -732,6 +744,7 @@ function serendipity_smarty_init($vars = array()) { $serendipity['smarty']->register_modifier('formatTime', 'serendipity_smarty_formatTime'); $serendipity['smarty']->register_modifier('serendipity_utf8_encode', 'serendipity_utf8_encode'); $serendipity['smarty']->register_modifier('ifRemember', 'serendipity_ifRemember'); + $serendipity['smarty']->register_modifier('checkPermission', 'serendipity_checkPermission'); $serendipity['smarty']->register_function('serendipity_printSidebar', 'serendipity_smarty_printSidebar'); $serendipity['smarty']->register_function('serendipity_hookPlugin', 'serendipity_smarty_hookPlugin'); diff --git a/serendipity_admin.php b/serendipity_admin.php index 783e4871..fa09c6ab 100644 --- a/serendipity_admin.php +++ b/serendipity_admin.php @@ -30,7 +30,7 @@ if (isset($serendipity['GET']['adminModule']) && $serendipity['GET']['adminModul if (!isset($_SESSION['author_token']) || !isset($serendipity['COOKIE']['author_token']) || ($_SESSION['author_token'] !== $serendipity['COOKIE']['author_token'])) { $_SESSION['serendipityAuthedUser'] = false; - @session_destroy(); + serendipity_session_destroy(); } if (!serendipity_userLoggedIn()) { // Try again to log in, this time with enabled external authentication event hook @@ -44,79 +44,41 @@ if (serendipity_is_iframe()) { return true; } -?> - - - <?php echo SERENDIPITY_ADMIN_SUITE; ?> - - - +if (isset($serendipity['GET']['no_smarty']) || isset($serendipity['no_smarty'])) { + $_SESSION['no_smarty'] = true; +} - - - - - - - - - - - - - - - - - -
- -

-

- -

- -
- - - -
- - - -

- -
- -
- -
- - - - - - - - - - - - - - - - - -
-
- - - - -
-
    -
  • - -
  • - -
-
-
    - -
  • - -
  • -
  • - - -
  • - - -
  • - - - - -
- - -
    -
  • - -
  • - - -
  • - - -
  • - - -
  • - - -
- - -
    -
  • - -
  • - - -
  • - - -
- - -
    -
  • - -
  • - - -
  • - - -
  • - - -
  • -
  • - - -
- -
-
    -
  • -
  • -
+ $use_installer = false; +} -
-assign_by_ref('admin_vars', $admin_vars); + $serendipity['smarty']->display(serendipity_getTemplateFile('admin/index.tpl', 'serendipityPath')); +} else { +?> + + + <?php echo SERENDIPITY_ADMIN_SUITE; ?> + + + + + + + + + + + + + + + + + + + + + + @@ -397,5 +463,4 @@ if (!isset($serendipity['serendipityPath']) || IS_installed === false || IS_up2d \ No newline at end of file +} \ No newline at end of file diff --git a/templates/default/admin/entries.tpl b/templates/default/admin/entries.tpl new file mode 100644 index 00000000..27c3ecdd --- /dev/null +++ b/templates/default/admin/entries.tpl @@ -0,0 +1,227 @@ + +{*** POSSIBLE ERROR MESSAGES START ***} +{if $entry_vars.errMsg} +
{$entry_vars.errMsg}
+{/if} +{*** POSSIBLE ERROR MESSAGES END ***} + +{*** MAIN ENTRY FORM START ***} + +{$entry_vars.hidden} + +
+ +

+

+ +

+ +
+ + + +
+ + + +

+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + +
+
+ + + +
+
    +
  • + +
  • + +
+
+
    + +
  • + +
  • +
  • + + +
  • + + +
  • + + + + + +
+ + +
    +
  • + +
  • + + +
  • + + +
  • + + +
  • + + +
+ + +
    +
  • + +
  • + + +
  • + + +
+ + +
    +
  • + +
  • + + +
  • + + +
  • + + +
  • +
  • + + +
+ +
+
    +
  • +
  • +
+ +
+
+ + {*** ENTRY TITLE, DRAFT START ***} + + + + + {*** ENTRY TITLE, DRAFT END ***} + + + + {*** ENTRY DATE,CATEGORY START ***} + {if $entry_vars.allowDateManipulation} + + + + {else} + + + {/if} + + {*** ENTRY TOOLBAR END ***} + + {*** ENTRY BODY START ***} + + + + {*** ENTRY BODY START ***} + + {*** ENTRY OPTIONS START ***} + + + + {*** ENTRY OPTIONS END ***} + + {*** EXTENDED ENTRY TOOLBAR START ***} + + + + + + {*** EXTENDED ENTRY TOOLBAR END ***} + + {*** EXTENDED ENTRY BODY START ***} + + + + {*** EXTENDED ENTRY BODY END ***} + + + + +
+ {$CONST.TITLE}: + + + + + + +
+ +
+
+ {$CONST.DATE}: + + + + {$CONST.RESET_DATE} + + {else} + + {/if} + {$CONST.CATEGORY}: + + + + + {else} + + {/if} + {serendipity_hookPlugin hook="backend_entry_toolbar_extended" data=$entry_data.entry hookAll="true"} + {$CONST.ENTRY_BODY}{serendipity_hookPlugin hook="backend_entry_toolbar_extended" data=$entry_data.entry hookAll="true"}
+ +
+ + + + + +
+
+ +
+
+ +
+
+
+ {if NOT $entry_vars.wysiwyg} + +/- + {/if} + {$CONST.EXTENDED_BODY} + + {if NOT $entry_vars.wysiwyg} + + {else} + {serendipity_hookPlugin hook="backend_entry_toolbar_extended" data=$entry_data.entry hookAll="true"} + {/if} +
+ + {if NOT $entry_vars.wysiwyg} + + {/if} +
+
+
+ {$CONST.ADVANCED_OPTIONS} + {*** EXTERNAL PLUGINS OUTPUT START ***} + {serendipity_hookPlugin hook="backend_display" data=$entry_vars.entry hookAll="true"} + {*** EXTERNAL PLUGINS OUTPUT END ***} +
+
+ +{*** MAIN ENTRY FORM END ***} + +{*** SPAWN WYSIWYG EDITORS START ***} +{if $entry_vars.show_wysiwyg} + +{/if} + +{if $entry_vars.wysiwyg} + {foreach from=$entry_vars.wysiwyg_blocks item="wysiwyg_block_item" key="wysiwyg_block_jsname"} + {$wysiwyg_block_item|emit_htmlarea_code:$wysiwyg_block_jsname} + {/foreach} + {serendipity_hookPlugin hook="backend_wysiwyg_finish" data=$entry_vars.wysiwyg_blocks hookAll="true"} +{/if} +{*** SPAWN WYSIWYG EDITORS END ***} + + + + diff --git a/templates/default/admin/index.tpl b/templates/default/admin/index.tpl new file mode 100644 index 00000000..9061f1ea --- /dev/null +++ b/templates/default/admin/index.tpl @@ -0,0 +1,240 @@ + + + + {$CONST.SERENDIPITY_ADMIN_SUITE} + + + + + + {if $admin_vars.admin_installed} + {serendipity_hookPlugin hook="backend_header" hookAll="true"} + {/if} + + + + + +{*** BANNER START ***} + {if NOT $admin_vars.no_banner} + + + + + + + {/if} +{*** BANNER END ***} + + +{if NOT $admin_vars.is_logged_in} +{*** LOGIN-AREA START ***} + + {serendipity_hookPlugin hook="backend_header" data=$admin_vars.out hookAll="true"} + + {/if} + + +
+ {if $admin_vars.admin_installed} +

{$CONST.SERENDIPITY_ADMIN_SUITE}

+

{$blogTitle}

+ {else} +

{$CONST.SERENDIPITY_INSTALLATION}

+ {/if} +
+ {if $admin_vars.is_logged_in} + {$admin_vars.self_info} + {/if} +
+
{$CONST.WELCOME_TO_ADMIN}
+ {$CONST.PLEASE_ENTER_CREDENTIALS} + {$admin_vars.out.header} +
+
+ + {if $admin_vars.post_action != '' AND NOT $admin_vars.is_logged_in} +
{$CONST.WRONG_USERNAME_OR_PASSWORD}
+ {/if} + +
+ + + + + + + + + + + + + + + + + {$admin_vars.out.table} +
{$CONST.USERNAME}
{$CONST.PASSWORD}
+
+ {$admin_vars.out.footer} + {$CONST.BACK_TO_BLOG} +{*** LOGIN-AREA END ***} +{else} +{*** SIDEBAR-MENU START ***} + {if NOT $admin_vars.no_sidebar} +
+ {*** MAIN LINKS START ***} + + {*** MAIN LINKS END ***} + +
+ + {*** ENTRY LINKS START ***} +
    + {if 'adminEntries'|checkPermission OR 'adminEntriesPlugins'|checkPermission} +
  • {$CONST.ADMIN_ENTRIES}
  • + {if 'adminEntries'|checkPermission} +
  • {$CONST.NEW_ENTRY}
  • +
  • {$CONST.EDIT_ENTRIES}
  • + {/if} + + {if 'adminComments'|checkPermission} +
  • {$CONST.COMMENTS}
  • + {/if} + + {if 'adminCategories'|checkPermission} +
  • {$CONST.CATEGORIES}
  • + {/if} + + {if 'adminEntries'|checkPermission OR 'adminEntriesPlugins'|checkPermission} + {if $admin_vars.no_create !== true} {serendipity_hookPlugin hook="backend_sidebar_entries" hookAll="true"}{/if} + {/if} + {/if} +
+ {*** ENTRY LINKS END ***} + + {*** MEDIA LINKS START ***} + {if 'adminImages'|checkPermission} + + {/if} + {*** MEDIA LINKS END ***} + + {*** APPEARANCE START ***} + {if 'adminTemplates'|checkPermission OR 'adminPlugins'|checkPermission} +
    +
  • {$CONST.APPEARANCE}
  • + {if 'adminTemplates'|checkPermission} +
  • {$CONST.MANAGE_STYLES}
  • + {/if} + {if 'adminPlugins'|checkPermission} +
  • {$CONST.CONFIGURE_PLUGINS}
  • + {/if} + {if $admin_vars.no_create !== true} {serendipity_hookPlugin hook="backend_sidebar_admin_appearance" hookAll="true"}{/if} +
+ {/if} + {*** APPEARANCE END ***} + + {*** USER MANAGEMENT START ***} + {if 'adminUsersGroups'|checkPermission OR 'adminImport'|checkPermission OR 'siteConfiguration'|checkPermission OR 'blogConfiguration'|checkPermission OR 'adminUsers'|checkPermission} + + {/if} + {*** USER MANAGEMENT END ***} + + {*** LOGOUT START ***} +
+ + {*** LOGOUT END ***} + +
+ + {*** MAIN CONTENT OF THE ADMIN INTERFACE START ***} + {$admin_vars.main_content} + {*** MAIN CONTENT OF THE ADMIN INTERFACE END ***} + +{/if} +{*** SIDEBAR-MENU END ***} +
+ +
+
+ {$admin_vars.version_info} +
+ + + \ No newline at end of file