Hi Garvin,garvinhicking wrote:No, the "embed" mechanism is not used/needed. In fact, using Smarty, the whole embed structure of Serendipity is really not needed anymore since you can do everything you need via the Smarty Templating.
And you would only need embedding if you wanted to show Serendipity within Gallery. But you want to do it the other way round, so only Gallery needs to be embedded.
Not really - the point is, that none of them needs to get embedded
Ok Guys, here we go:
- inside gallery/config.php
Code: Select all
$gallery->app->embedded_inside_type = "Serendipity";
$gallery->app->serendipity_dir = "/home/www/html/s9y/";
- in gallery/init.php go to Standalone and include the Serendipity stuff
Code: Select all
/* Standalone */
include_once(dirname(__FILE__) . "/classes/gallery/UserDB.php");
include_once(dirname(__FILE__) . "/classes/gallery/User.php");
/* Load our user database (and user object) */
$gallery->userDB = new Gallery_UserDB;
/* Load their user object with their username as the key */
if (isset($gallery->session->username) && !empty($gallery->session->username)) {
$gallery->user = $gallery->userDB->getUserByUsername($gallery->session->username);
}
/* +++ Include Serendipity stuff start +++ */
$serendipity_directory = $gallery->app->serendipity_dir;
$cwd = getcwd();
chdir($gallery->app->serendipity_dir);
define('S9Y_INCLUDE_PATH', $gallery->app->serendipity_dir);
include_once(S9Y_INCLUDE_PATH . 'serendipity_config.inc.php');
include_once(S9Y_INCLUDE_PATH . 'include/functions.inc.php');
include_once(S9Y_INCLUDE_PATH . 'include/plugin_api.inc.php');
include_once(S9Y_INCLUDE_PATH . 'include/plugin_internal.inc.php');
$serendipity['smarty_file'] = 'index.tpl';
$serendipity['smarty_raw_mode'] = false;
serendipity_smarty_init();
$serendipity['smarty']->assign(
array(
'leftSidebarElements' => serendipity_plugin_api::count_plugins('left'),
'rightSidebarElements' => serendipity_plugin_api::count_plugins('right')
)
);
chdir($cwd);
ob_start();
/* --- include serendipity stuff end --- */
}
Code: Select all
<?php # $Id: functions_smarty.inc.php,v 1.22 2005/03/31 12:10:48 garvinhicking Exp $
# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
# All rights reserved. See LICENSE file for licensing details
if( !function_exists("serendipity_smarty_fetch") ) {
function &serendipity_smarty_fetch($block, $file, $echo = false) {
global $serendipity;
$output = $serendipity['smarty']->fetch('file:'. serendipity_getTemplateFile($file, 'serendipityPath'), null, null, ($echo === true && $serendipity['smarty_raw_mode']));
$serendipity['smarty']->assign($block, $output);
return $output;
}
}
if( !function_exists("serendipity_emptyPrefix") ) {
function serendipity_emptyPrefix($string, $prefix = ': ') {
return (!empty($string) ? $prefix . htmlspecialchars($string) : '');
}
}
if( !function_exists("serendipity_smarty_showPlugin") ) {
function serendipity_smarty_showPlugin($params, &$smarty) {
global $serendipity;
if (!isset($params['class']) && !isset($params['id'])) {
$smarty->trigger_error(__FUNCTION__ .": missing 'class' or 'id' parameter");
return;
}
if (!isset($params['side'])) {
$params['side'] = '*';
}
if (!isset($params['negate'])) {
$params['negate'] = null;
}
return serendipity_plugin_api::generate_plugins($params['side'], null, $params['negate'], $params['class'], $params['id']);
}
}
if( !function_exists("serendipity_smarty_hookPlugin") ) {
function serendipity_smarty_hookPlugin($params, &$smarty) {
global $serendipity;
static $hookable = array('frontend_header',
'entries_header',
'entries_footer',
'frontend_comment');
if (!isset($params['hook'])) {
$smarty->trigger_error(__FUNCTION__ .": missing 'hook' parameter");
return;
}
if (!in_array($params['hook'], $hookable) && $params['hookAll'] != 'true') {
$smarty->trigger_error(__FUNCTION__ .": illegal hook '". $params['hook'] ."'");
return;
}
if (!isset($params['data'])) {
$params['data'] = &$serendipity;
}
if (!isset($params['addData'])) {
$params['addData'] = null;
}
serendipity_plugin_api::hook_event($params['hook'], $params['data'], $params['addData']);
}
}
if( !function_exists("serendipity_smarty_printSidebar") ) {
function serendipity_smarty_printSidebar($params, &$smarty) {
if ( !isset($params['side']) ) {
$smarty->trigger_error(__FUNCTION__ .": missing 'side' parameter");
return;
}
return serendipity_plugin_api::generate_plugins($params['side']);
}
}
if( !function_exists("serendipity_smarty_getFile") ) {
function serendipity_smarty_getFile($params, &$smarty) {
if ( !isset($params['file']) ) {
$smarty->trigger_error(__FUNCTION__ .": missing 'file' parameter");
return;
}
return serendipity_getTemplateFile($params['file']);
}
}
if( !function_exists("serendipity_smarty_formatTime") ) {
function serendipity_smarty_formatTime($timestamp, $format, $useOffset = true) {
if (defined($format)) {
return serendipity_formatTime(constant($format), $timestamp, $useOffset);
} else {
return serendipity_formatTime($format, $timestamp, $useOffset);
}
}
}
if( !function_exists("serendipity_smarty_printComments") ) {
function &serendipity_smarty_printComments($params, &$smarty) {
global $serendipity;
if (!isset($params['entry'])) {
$smarty->trigger_error(__FUNCTION__ .": missing 'entry' parameter");
return;
}
if (!isset($params['mode'])) {
$params['mode'] = VIEWMODE_THREADED;
}
$comments = serendipity_fetchComments($params['entry']);
if (!empty($serendipity['POST']['preview'])) {
$comments[] =
array(
'email' => $serendipity['POST']['email'],
'author' => $serendipity['POST']['name'],
'body' => $serendipity['POST']['comment'],
'url' => $serendipity['POST']['url'],
'parent_id' => $serendipity['POST']['replyTo'],
'timestamp' => time()
);
}
return serendipity_printComments($comments, $params['mode']);
}
}
if( !function_exists("serendipity_smarty_printTrackbacks") ) {
function serendipity_smarty_printTrackbacks($params, &$smarty) {
if ( !isset($params['entry']) ) {
$smarty->trigger_error(__FUNCTION__ .": missing 'entry' parameter");
return;
}
return serendipity_printTrackbacks(serendipity_fetchTrackbacks($params['entry']));
}
}
if( !function_exists("serendipity_smarty_init") ) {
function serendipity_smarty_init() {
global $serendipity;
if (!isset($serendipity['smarty'])) {
@define('SMARTY_DIR', S9Y_INCLUDE_PATH . 'bundled-libs/Smarty/libs/');
require_once SMARTY_DIR . 'Smarty.class.php';
$serendipity['smarty'] = new Smarty;
if ($serendipity['production'] === 'debug') {
$serendipity['smarty']->force_compile = true;
$serendipity['smarty']->debugging = true;
}
$serendipity['smarty']->template_dir = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['template'];
$serendipity['smarty']->compile_dir = $serendipity['serendipityPath'] . PATH_SMARTY_COMPILE;
$serendipity['smarty']->config_dir = &$serendipity['smarty']->template_dir;
$serendipity['smarty']->secure_dir = array($serendipity['serendipityPath'] . $serendipity['templatePath']);
$serendipity['smarty']->security_settings['MODIFIER_FUNCS'] = array('sprintf', 'sizeof', 'count', 'rand');
$serendipity['smarty']->security = true;
$serendipity['smarty']->use_sub_dirs = false;
$serendipity['smarty']->compile_check = true;
$serendipity['smarty']->compile_id = &$serendipity['template'];
$serendipity['smarty']->register_modifier('makeFilename', 'serendipity_makeFilename');
$serendipity['smarty']->register_modifier('xhtml_target', 'serendipity_xhtml_target');
$serendipity['smarty']->register_modifier('emptyPrefix', 'serendipity_emptyPrefix');
$serendipity['smarty']->register_modifier('formatTime', 'serendipity_smarty_formatTime');
$serendipity['smarty']->register_function('serendipity_printSidebar', 'serendipity_smarty_printSidebar');
$serendipity['smarty']->register_function('serendipity_hookPlugin', 'serendipity_smarty_hookPlugin');
$serendipity['smarty']->register_function('serendipity_showPlugin', 'serendipity_smarty_showPlugin');
$serendipity['smarty']->register_function('serendipity_getFile', 'serendipity_smarty_getFile');
$serendipity['smarty']->register_function('serendipity_printComments', 'serendipity_smarty_printComments');
$serendipity['smarty']->register_function('serendipity_printTrackbacks', 'serendipity_smarty_printTrackbacks');
}
if (!isset($serendipity['smarty_raw_mode'])) {
if (file_exists($serendipity['smarty']->template_dir . '/layout.php') && $serendipity['template'] != 'default') {
$serendipity['smarty_raw_mode'] = true;
} else {
$serendipity['smarty_raw_mode'] = false;
}
}
if (!isset($serendipity['smarty_file'])) {
$serendipity['smarty_file'] = 'index.tpl';
}
$serendipity['smarty']->assign(
array(
'head_charset' => LANG_CHARSET,
'head_version' => $serendipity['version'],
'head_title' => $serendipity['head_title'],
'head_subtitle' => $serendipity['head_subtitle'],
'head_link_stylesheet' => serendipity_rewriteURL('serendipity.css'),
'CONST' => get_defined_constants(),
'is_xhtml' => $serendipity['XHTML11'],
'use_popups' => $serendipity['enablePopup'],
'is_embedded' => (!$serendipity['embed'] || $serendipity['embed'] === 'false' || $serendipity['embed'] === false) ? false : true,
'is_raw_mode' => $serendipity['smarty_raw_mode'],
'entry_id' => (isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id'])) ? $serendipity['GET']['id'] : false,
'is_single_entry' => (isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id'])),
'blogTitle' => htmlspecialchars($serendipity['blogTitle']),
'blogSubTitle' => (!empty($serendipity['blogSubTitle']) ? htmlspecialchars($serendipity['blogSubTitle']) : ''),
'blogDescription' => htmlspecialchars($serendipity['blogDescription']),
'serendipityHTTPPath' => $serendipity['serendipityHTTPPath'],
'serendipityBaseURL' => $serendipity['baseURL'],
'serendipityRewritePrefix' => $serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '',
'serendipityIndexFile' => $serendipity['indexFile'],
'serendipityVersion' => $serendipity['version'],
'dateRange' => (!empty($serendipity['range']) ? $serendipity['range'] : array())
)
);
return true;
}
}
/* Nukes all Smarty compiled templates and cache */
if( !function_exists("serendipity_smarty_purge") ) {
function serendipity_smarty_purge() {
global $serendipity;
/* Attempt to init Smarty, brrr */
serendipity_smarty_init();
$files = serendipity_traversePath($serendipity['smarty']->compile_dir, '', false, '/.+\.tpl\.php$/');
if ( !is_array($files) ) {
return false;
}
foreach ( $files as $file ) {
@unlink($serendipity['smarty']->compile_dir . DIRECTORY_SEPARATOR . $file['name']);
}
}
}
if( !function_exists("serendipity_smarty_shutdown") ) {
/* Function can be called from foreign applications. ob_start() needs to
have been called before, and will be parsed into Smarty here */
function serendipity_smarty_shutdown($serendipity_directory = '') {
global $serendipity;
$cwd = getcwd();
chdir($serendipity_directory);
$raw_data = ob_get_contents();
ob_end_clean();
$serendipity['smarty']->assign('content_message', $raw_data);
serendipity_smarty_fetch('CONTENT', 'content.tpl');
if (empty($serendipity['smarty_file'])) {
$serendipity['smarty_file'] = '404.tpl';
}
$serendipity['smarty']->display(serendipity_getTemplateFile($serendipity['smarty_file'], 'serendipityPath'));
}
}
Regards
Ian