static function fetchTemplate($filename, $oembed, $url)
 {
     global $serendipity;
     if (!is_object($serendipity['smarty'])) {
         serendipity_smarty_init();
     }
     // Declare the oembed to smarty
     $serendipity['smarty']->assign('oembedurl', $url);
     $serendipity['smarty']->assign('oembed', (array) $oembed);
     $tfile = serendipity_getTemplateFile($filename, 'serendipityPath');
     if (!$tfile || $filename == $tfile) {
         $tfile = dirname(__FILE__) . '/' . $filename;
     }
     $inclusion = $serendipity['smarty']->security_settings[@INCLUDE_ANY];
     $serendipity['smarty']->security_settings[@INCLUDE_ANY] = true;
     if (version_compare($serendipity['version'], '1.7-alpha1') >= 0) {
         $serendipity['smarty']->disableSecurity();
     }
     /* in earlier versions this is not needed.
        else {
            $serendipity['smarty']->security = false;
        }
        */
     // be smarty 3 compat including the serendipity_smarty class wrappers ->fetch and ->display methods and remove changed parameter number 4
     $content = @$serendipity['smarty']->fetch('file:' . $tfile);
     //, false
     $serendipity['smarty']->security_settings[@INCLUDE_ANY] = $inclusion;
     return $content;
 }
 function show()
 {
     global $serendipity;
     if ($serendipity['GET']['page'] == 'thumbs') {
         $title = '';
         if (!is_object($serendipity['smarty'])) {
             serendipity_smarty_init();
         }
         $_ENV['staticpage_pagetitle'] = 'thumbs';
         $serendipity['smarty']->assign('staticpage_pagetitle', 'thumbs');
         $this->generate_content($title);
     }
 }
 function smartymarkup($input, &$eventData)
 {
     global $serendipity;
     if (!isset($serendipity['smarty'])) {
         serendipity_smarty_init();
     }
     if (!isset($serendipity['plugindata']['smartymarkupplugin'])) {
         $serendipity['smarty']->registerResource("smartymarkupplugin", array(array($this, "smarty_resource_smartymarkupplugin_template"), array($this, "smarty_resource_smartymarkupplugin_timestamp"), array($this, "smarty_resource_smartymarkupplugin_secure"), array($this, "smarty_resource_smartymarkupplugin_trusted")));
     }
     $serendipity['plugindata']['smartymarkupplugin'] =& $input;
     $serendipity['smarty']->assign('smartymarkup_eventData', $eventData);
     // avoid non existing or empty template fetch calls
     if (isset($serendipity['plugindata']['smartymarkupplugin']) && !empty($serendipity['plugindata']['smartymarkupplugin'])) {
         return $serendipity['smarty']->fetch('smartymarkupplugin:' . crc32($serendipity['plugindata']['smartymarkupplugin']));
     }
 }
 function show()
 {
     global $serendipity;
     if ($this->selected()) {
         if (!headers_sent()) {
             header('HTTP/1.0 200');
             header('Status: 200');
         }
         if (!is_object($serendipity['smarty'])) {
             serendipity_smarty_init();
         }
         $_ENV['staticpage_pagetitle'] = preg_replace('@[^a-z0-9]@i', '_', $this->get_config('pagetitle'));
         $serendipity['smarty']->assign('staticpage_pagetitle', $_ENV['staticpage_pagetitle']);
         echo '<div class="serendipity_poll">';
         if (serendipity_db_bool($this->get_config('articleformat'))) {
             echo '<div class="serendipity_Entry_Date">
                      <h3 class="serendipity_date">' . $this->get_config('articleformattitle') . '</h3>';
         }
         echo '<h4 class="serendipity_title"><a href="#">' . $this->get_polldata('title') . '</a></h4>';
         if (serendipity_db_bool($this->get_config('articleformat'))) {
             echo '<div class="serendipity_entry"><div class="serendipity_entry_body">';
         }
         echo '<div class="serendipity_poll_body">';
         if (isset($serendipity['GET']['voteId'])) {
             serendipity_common_pollbox::poll($serendipity['GET']['voteId']);
         } else {
             serendipity_common_pollbox::poll();
         }
         echo '</div>';
         echo '<br /><div class="serendipity_poll_archive">';
         PLUGIN_POLL_ARCHIVE . '<br />';
         $polls =& $this->fetchPolls();
         if (is_array($polls)) {
             foreach ($polls as $poll) {
                 echo '<a href="' . $serendipity['baseURL'] . $serendipity['indexFile'] . '?serendipity[subpage]=' . $this->get_config('pagetitle') . '&amp;serendipity[voteId]=' . $poll['id'] . '">' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($poll['title']) : htmlspecialchars($poll['title'], ENT_COMPAT, LANG_CHARSET)) . '</a>, ' . serendipity_strftime(DATE_FORMAT_ENTRY, $poll['timestamp']) . '<br />';
             }
         }
         echo '</div>';
         if (serendipity_db_bool($this->get_config('articleformat'))) {
             echo '</div></div></div>';
         }
         echo '</div>';
     }
 }
 function show()
 {
     global $serendipity;
     if ($this->selected()) {
         if (!headers_sent()) {
             header('HTTP/1.0 200');
             header('Status: 200 OK');
         }
         if (!is_object($serendipity['smarty'])) {
             serendipity_smarty_init();
         }
         $_ENV['staticpage_pagetitle'] = preg_replace('@[^a-z0-9]@i', '_', $this->get_config('pagetitle'));
         $serendipity['smarty']->assign('staticpage_pagetitle', $_ENV['staticpage_pagetitle']);
         if ($this->get_config('articleformat') == TRUE) {
             echo '<div class="serendipity_Entry_Date">
                      <h3 class="serendipity_date">' . $this->get_config('pagetitle') . '</h3>';
         }
         echo '<h4 class="serendipity_title"><a href="#">' . $this->get_config('headline') . '</a></h4>';
         if ($this->get_config('articleformat') == TRUE) {
             echo '<div class="serendipity_entry"><div class="serendipity_entry_body">';
         }
         $include_file = realpath($this->get_config('include'));
         ob_start();
         include $include_file;
         $content = ob_get_contents();
         ob_end_clean();
         if ($this->get_config('markup') == TRUE) {
             $entry = array('body' => $content);
             serendipity_plugin_api::hook_event('frontend_display', $entry);
             echo $entry['body'];
         } else {
             echo $content;
         }
         if ($this->get_config('articleformat') == TRUE) {
             echo '</div></div></div>';
         }
     }
 }
Example #6
0
# All rights reserved.  See LICENSE file for licensing details
if (IN_serendipity !== true) {
    die("Don't hack!");
}
include_once 'serendipity_config.inc.php';
include_once S9Y_INCLUDE_PATH . 'include/plugin_api.inc.php';
$uri = $_SERVER['REQUEST_URI'];
// need to define this again here, as index.php no longer includes this file
$uri_addData = array('startpage' => false, 'uriargs' => implode('/', serendipity_getUriArguments($uri, true)), 'view' => $serendipity['view'], 'viewtype' => isset($serendipity['viewtype']) ? $serendipity['viewtype'] : '');
if ((empty($uri_addData['uriargs']) || trim($uri_addData['uriargs']) == $serendipity['indexFile']) && empty($serendipity['GET']['subpage'])) {
    $uri_addData['startpage'] = true;
}
$serendipity['plugindata']['smartyvars'] = $uri_addData;
// Plugins can change this global variable
serendipity_plugin_api::hook_event('genpage', $uri, $uri_addData);
serendipity_smarty_init($serendipity['plugindata']['smartyvars']);
$leftSidebarElements = serendipity_plugin_api::count_plugins('left');
$rightSidebarElements = serendipity_plugin_api::count_plugins('right');
$serendipity['smarty']->assignByRef('leftSidebarElements', $leftSidebarElements);
$serendipity['smarty']->assignByRef('rightSidebarElements', $rightSidebarElements);
switch ($serendipity['GET']['action']) {
    // User wants to read the diary
    case 'read':
        if (isset($serendipity['GET']['id'])) {
            $entry = array(serendipity_fetchEntry('id', $serendipity['GET']['id']));
            if (!is_array($entry) || count($entry) < 1 || !is_array($entry[0])) {
                unset($serendipity['GET']['id']);
                $entry = array(array());
                $serendipity['head_title'] = serendipity_specialchars($serendipity['blogTitle']);
                $serendipity['head_subtitle'] = '';
                $serendipity['smarty']->assign('head_title', $serendipity['head_title']);
}
if ($ajax) {
    // if that is an ajax request we can stop here, since we by convention don't want to wrap the content in the usual backend code
    echo $main_content;
} elseif (!$use_installer) {
    $poll_admin_vars = array('main_content', 'no_banner', 'no_sidebar', 'no_footer', 'post_action', 'is_logged_in', 'admin_installed', 'self_info', 'use_installer', 'title');
    $admin_vars = array();
    foreach ($poll_admin_vars as $poll_admin_var) {
        $admin_vars[$poll_admin_var] =& ${$poll_admin_var};
    }
    $admin_vars['out'] = array();
    $admin_vars['no_create'] = $serendipity['no_create'];
    $admin_vars['title'] = $admin_section;
    if ($serendipity['expose_s9y']) {
        $admin_vars['version_info'] = sprintf(ADMIN_FOOTER_POWERED_BY, $serendipity['versionInstalled'], phpversion());
    } else {
        $admin_vars['version_info'] = sprintf(ADMIN_FOOTER_POWERED_BY, '', '');
    }
    if (!is_object($serendipity['smarty'])) {
        serendipity_smarty_init();
    }
    $serendipity['smarty']->assignByRef('admin_vars', $admin_vars);
    $serendipity['smarty']->display(serendipity_getTemplateFile('admin/index.tpl', 'serendipityPath'));
} else {
    if (IS_installed === false) {
        $file = 'include/admin/installer.inc.php';
    } elseif (IS_up2date === false) {
        $file = 'include/admin/upgrader.inc.php';
    }
    require S9Y_INCLUDE_PATH . $file;
}
 function event_hook($event, &$bag, &$eventData, $addData = null)
 {
     global $serendipity;
     static $login_url = null;
     if ($login_url === null) {
         $login_url = $serendipity['baseURL'] . $serendipity['indexFile'] . '?/plugin/loginbox';
     }
     $hooks =& $bag->get('event_hooks');
     if (isset($hooks[$event])) {
         switch ($event) {
             case 'frontend_saveComment':
                 if (!isset($serendipity['csuccess'])) {
                     $serendipity['csuccess'] = 'true';
                 }
                 if (serendipity_db_bool($this->get_config('registered_only')) && !serendipity_userLoggedIn() && $addData['source2'] != 'adduser') {
                     $eventData = array('allow_comments' => false);
                     $serendipity['messagestack']['comments'][] = PLUGIN_ADDUSER_REGISTERED_ONLY_REASON;
                     return false;
                 }
                 if (serendipity_db_bool($this->get_config('registered_only')) && !$this->inGroup() && $addData['source2'] != 'adduser') {
                     $eventData = array('allow_comments' => false);
                     $serendipity['messagestack']['comments'][] = PLUGIN_ADDUSER_REGISTERED_ONLY_REASON;
                     return false;
                 }
                 if (serendipity_db_bool($this->get_config('true_identities')) && !serendipity_userLoggedIn()) {
                     $user = str_replace(" b", '', $addData['name']);
                     $user = serendipity_db_escape_string(preg_replace('@\\s+@', ' ', trim($user)));
                     $user = trim($user);
                     $authors = serendipity_db_query("SELECT authorid FROM {$serendipity['dbPrefix']}authors WHERE realname = '" . $user . "'");
                     if (is_array($authors) && isset($authors[0]['authorid'])) {
                         $eventData = array('allow_comments' => false);
                         $serendipity['messagestack']['comments'][] = sprintf(PLUGIN_ADDUSER_REGISTERED_CHECK_REASON, $login_url, 'onclick="javascript:loginbox = window.open(this.href, \'loginbox\', \'width=300,height=300,locationbar=no,menubar=no,personalbar=no,statusbar=yes,status=yes,toolbar=no\'); return false;"');
                     }
                 }
                 break;
             case 'external_plugin':
                 if ($eventData != 'loginbox') {
                     return true;
                 }
                 $out = array();
                 serendipity_plugin_api::hook_event('backend_login_page', $out);
                 serendipity_smarty_init();
                 $serendipity['smarty']->assign(array('loginform_add' => $out, 'loginform_url' => $login_url, 'loginform_user' => $_SESSION['serendipityUser'], 'loginform_mail' => $_SESSION['serendipityEmail'], 'close_window' => defined('LOGIN_ACTION'), 'is_logged_in' => serendipity_userLoggedIn(), 'is_error' => defined('LOGIN_ERROR')));
                 $filename = 'loginbox.tpl';
                 $tfile = serendipity_getTemplateFile($filename, 'serendipityPath');
                 if (!$tfile || $tfile == $filename) {
                     $tfile = dirname(__FILE__) . '/' . $filename;
                 }
                 $inclusion = $serendipity['smarty']->security_settings[INCLUDE_ANY];
                 $serendipity['smarty']->security_settings[INCLUDE_ANY] = true;
                 $serendipity['smarty']->display($tfile);
                 break;
             case 'frontend_display':
                 if (serendipity_db_bool($this->get_config('registered_only')) && !serendipity_userLoggedIn()) {
                     $serendipity['messagestack']['comments'][] = sprintf(PLUGIN_ADDUSER_REGISTERED_ONLY_REASON, $serendipity['baseURL'] . $serendipity['indexFile'] . '?serendipity[subpage]=adduser', $serendipity['baseURL'] . 'serendipity_admin.php');
                     $eventData['allow_comments'] = false;
                 }
                 break;
             case 'frontend_configure':
                 if (isset($serendipity['POST']['action']) && isset($serendipity['POST']['user']) && isset($serendipity['POST']['pass'])) {
                     serendipity_login();
                     if (serendipity_userLoggedIn()) {
                         define('LOGIN_ACTION', 'login');
                         header('X-s9y-auth: Login');
                     } else {
                         define('LOGIN_ERROR', true);
                     }
                 } elseif (isset($serendipity['POST']['action']) && isset($serendipity['POST']['logout'])) {
                     serendipity_logout();
                     if (!serendipity_userLoggedIn()) {
                         header('X-s9y-auth: Logout');
                         define('LOGIN_ACTION', 'logout');
                     }
                 }
                 if ((serendipity_db_bool($this->get_config('registered_only')) || serendipity_db_bool($this->get_config('true_identities'))) && $_SESSION['serendipityAuthedUser']) {
                     if (defined('IN_serendipity_admin') && $serendipity['GET']['adminAction'] == 'doEdit') {
                         // void
                     } else {
                         $serendipity['COOKIE']['name'] = isset($_SESSION['serendipityRealname']) ? $_SESSION['serendipityRealname'] : $_SESSION['serendipityUser'];
                         $serendipity['COOKIE']['email'] = $_SESSION['serendipityEmail'];
                         if ($serendipity['POST']['comment']) {
                             $serendipity['POST']['name'] = $serendipity['COOKIE']['name'];
                             $serendipity['POST']['email'] = $serendipity['COOKIE']['email'];
                         }
                     }
                 }
                 return true;
                 break;
             case 'entry_display':
                 if ($serendipity['GET']['subpage'] == 'adduser' || $serendipity['POST']['subpage'] == 'adduser' || !empty($serendipity['GET']['adduser_activation']) || !empty($this->clean_page)) {
                     if (is_array($eventData)) {
                         $eventData['clean_page'] = true;
                     }
                 }
                 break;
             case 'entries_header':
                 if ($serendipity['GET']['subpage'] == 'adduser' || $serendipity['POST']['subpage'] == 'adduser' || !empty($serendipity['GET']['adduser_activation'])) {
                     $this->clean_page = true;
                     $url = $serendipity['baseURL'] . $serendipity['indexFile'];
                     $hidden['subpage'] = 'adduser';
                     $username = substr($serendipity['POST']['adduser_user'], 0, 40);
                     $password = substr($serendipity['POST']['adduser_pass'], 0, 32);
                     $email = $serendipity['POST']['adduser_email'];
                     echo '<div id="adduser_form" style="padding-left: 4px; padding-right: 10px"><a id="adduser"></a>';
                     // Get the config from the sidebar plugin
                     $pair_config = array('userlevel' => USERLEVEL_EDITOR, 'no_create' => false, 'right_publish' => false, 'instructions' => $this->get_config('instructions', ''), 'usergroups' => array(), 'straight_insert' => false, 'approve' => false, 'use_captcha' => false);
                     $config = serendipity_db_query("SELECT name, value FROM {$serendipity['dbPrefix']}config WHERE name LIKE 'serendipity_plugin_adduser:%'");
                     if (is_array($config)) {
                         foreach ($config as $conf) {
                             $names = explode('/', $conf['name']);
                             if ($names[1] == 'instructions' && !empty($pair_config['instructions'])) {
                                 continue;
                             }
                             if ($names[1] == 'usergroups') {
                                 $ug = (array) explode(',', $conf['value']);
                                 foreach ($ug as $cid) {
                                     if ($cid === false || empty($cid)) {
                                         continue;
                                     }
                                     $pair_config[$names[1]][$cid] = $cid;
                                 }
                             } else {
                                 $pair_config[$names[1]] = serendipity_get_bool($conf['value']);
                             }
                         }
                     }
                     if (!serendipity_common_adduser::adduser($username, $password, $email, $pair_config['userlevel'], $pair_config['usergroups'], $pair_config['no_create'], $pair_config['right_publish'], $pair_config['straight_insert'], $pair_config['approve'], $pair_config['use_captcha'])) {
                         serendipity_common_adduser::loginform($url, $hidden, $pair_config['instructions'], $username, $password, $email, $pair_config['use_captcha']);
                     }
                     echo '</div>';
                 }
                 return true;
                 break;
             default:
                 return false;
         }
     } else {
         return false;
     }
 }
function serveCSS($css_mode)
{
    global $serendipity;
    serendipity_smarty_init();
    $serendipity['view'] = 'css';
    include S9Y_INCLUDE_PATH . 'serendipity.css.php';
}
/**
 * Performs a check whether an iframe for the admin section shall be emitted
 *
 * The iframe is used for previewing an entry with the stylesheet of the frontend.
 * It fetches its data from the session input data.
 *
 * @access private
 * @return boolean  True, if iframe was requested, false if not.
 */
function serendipity_is_iframe()
{
    global $serendipity;
    if ($serendipity['GET']['is_iframe'] && is_array($_SESSION['save_entry'])) {
        if (!is_object($serendipity['smarty'])) {
            // We need smarty also in the iframe to load a template's config.inc.php and register possible event hooks.
            serendipity_smarty_init();
        }
        return true;
    }
    return false;
}
 function media_insert($text, &$eventData)
 {
     global $serendipity;
     // find in text parts which are mediainsert
     $entry_parts = preg_split('@(<mediainsert>[\\S\\s]*?</mediainsert>)@', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
     // parse mediainserts
     // (if xml parser is present at php installation
     //         - SimpleXMLElement in PHP > 5.0, users of older version could have troubles )
     // text is splitted into parts
     if (class_exists('SimpleXMLElement')) {
         for ($i = 0, $pcount = count($entry_parts); $i < $pcount; $i++) {
             if (!(strpos($entry_parts[$i], "<mediainsert>") === false)) {
                 // There was a problem with wysiwyg-ckeditor: which removes linebreaks and sometimes inserts ending tags
                 // To not error, we remove at least the ending tags and possibly single-tags missing trailing slashes
                 $epart = str_replace(array('</media>', '</gallery>', '">'), array('', '', '" />'), $entry_parts[$i]);
                 $xml = new SimpleXMLElement($epart);
                 $gallery = $xml->gallery['name'];
                 $medias = array();
                 $whole_gallery = false;
                 foreach ($xml->media as $medium) {
                     switch ((string) $medium['type']) {
                         // Get attributes as element indices
                         case 'single':
                             $medias[] = serendipity_db_escape_string($medium['name']);
                             break;
                         case 'range':
                             for ($j = intval($medium['start']); $j <= intval($medium['stop']); $j++) {
                                 $medias[] = serendipity_db_escape_string($medium['prefix']) . $j;
                             }
                             break;
                         case 'gallery':
                             $whole_gallery = true;
                             break;
                         case 'hideafter':
                             $hideafter = intval($medium['nr']);
                             break;
                         case 'picperrow':
                             $picperrow = intval($medium['pr']);
                             break;
                         default:
                             break;
                     }
                 }
                 // here we have desired gallery and desired pictures
                 // now read available ones from database
                 if ($whole_gallery) {
                     $q = "SELECT id,name,extension,thumbnail_name,realname,path,value as comment1,dimensions_width as width, dimensions_height as height\n                              FROM {$serendipity['dbPrefix']}images as i \n                              LEFT JOIN {$serendipity['dbPrefix']}mediaproperties as p ON (p.mediaid = i.id AND p.property='COMMENT1') \n                              WHERE i.path = '" . serendipity_db_escape_string($gallery) . "' ";
                 } else {
                     $images_suggestions = "'" . implode("','", $medias) . "'";
                     $q = "SELECT id,name,extension,thumbnail_name,realname,path,value as comment1,dimensions_width as width, dimensions_height as height\n                              FROM {$serendipity['dbPrefix']}images as i \n                              LEFT JOIN {$serendipity['dbPrefix']}mediaproperties as p ON (p.mediaid = i.id AND p.property='COMMENT1') \n                              WHERE i.path = '" . serendipity_db_escape_string($gallery) . "' AND i.name IN ({$images_suggestions})";
                 }
                 $t = serendipity_db_query($q, false, 'assoc');
                 // here we have to order the results from database to respect
                 // the order of pictures in xml entry
                 // and at the same time we calculate thumbs size
                 $thumb_size = $serendipity['thumbSize'];
                 $order = array();
                 if (is_array($t)) {
                     for ($j = 0, $tcount = count($t); $j < $tcount; $j++) {
                         $h = intval($t[$j]['height']);
                         $w = intval($t[$j]['width']);
                         $h = $h == 0 ? 1 : $h;
                         // avoid 'Division by zero' errors for height
                         $w = $w == 0 ? 1 : $w;
                         // dito for width
                         if ($w > $h) {
                             $t[$j]['thumbheight'] = round($thumb_size * $h / $w);
                             $t[$j]['thumbwidth'] = round($thumb_size);
                         } else {
                             $t[$j]['thumbheight'] = round($thumb_size);
                             $t[$j]['thumbwidth'] = round($thumb_size * $w / $h);
                         }
                         if (strlen($t[$j]['comment1']) == 0) {
                             #$t[$j][6] = $t[$j]['name'];// add missing new num key if not using assoc select
                             $t[$j]['comment1'] = $t[$j]['name'];
                         }
                         $order[$j] = array_search($t[$j]['name'], $medias);
                         if (strlen($t[$j]['thumbnail_name']) == 0) {
                             array_splice($t, $j, 1);
                             $j--;
                             $tcount--;
                         }
                     }
                     if (count($t) + 1 == count($order)) {
                         // remove last $order array element, since else we might get a Fatal error:  Uncaught exception 'ErrorException' with message 'Warning: array_multisort(): Array sizes are inconsistent'
                         array_pop($order);
                     }
                     array_multisort($order, SORT_ASC, SORT_NUMERIC, $t);
                     // now make an output using template
                     if (!is_object($serendipity['smarty'])) {
                         serendipity_smarty_init();
                     }
                     $serendipity['smarty']->assign(array('plugin_mediainsert_media' => $t, 'plugin_mediainsert_entry' => $eventData, 'plugin_mediainsert_hideafter' => $hideafter, 'plugin_mediainsert_picperrow' => $picperrow));
                     $content = $this->parseTemplate('plugin_mediainsert.tpl');
                 } else {
                     // if there are no available images, do no output
                     $content = '';
                 }
                 // fetch the output
                 $entry_parts[$i] = $content;
             }
         }
     }
     return implode('', $entry_parts);
 }
/**
 * Render a smarty-template
 * $template: path to the template-file
 * $data: map with the variables to assign
 * $debugtype: If set, debug string is prepended. Can be set to HTML or JS.
 * $debug: Possible debug string that is prepended to output
 */
function serendipity_smarty_show($template, $data = null, $debugtype = null, $debug = null)
{
    global $serendipity;
    if (!is_object($serendipity['smarty'])) {
        serendipity_smarty_init();
    }
    $serendipity['smarty']->assign($data);
    $tplfile = $template == 'preview_iframe.tpl' ? serendipity_getTemplateFile($template, 'serendipityPath', true) : serendipity_getTemplateFile($template, 'serendipityPath');
    if ($debug !== null) {
        if ($debugtype == "HTML") {
            $debug = "<!-- Dynamically fetched " . htmlspecialchars(str_replace($serendipity['serendipityPath'], '', $tplfile)) . " on " . date('Y-m-d H:i') . ", called from: " . $debug . " -->\n";
        } else {
            $debug = "/* Dynamically fetched " . htmlspecialchars(str_replace($serendipity['serendipityPath'], '', $tplfile)) . " on " . date('Y-m-d H:i') . ", called from: " . $debug . " */\n";
        }
    }
    return $debug . $serendipity['smarty']->fetch('file:' . $tplfile);
}
 function admin_save()
 {
     global $serendipity;
     global $template_vars;
     serendipity_smarty_init();
     if (isset($template_vars['sidebars'])) {
         $sidebars = explode(',', $template_vars['sidebars']);
     } elseif (isset($serendipity['sidebars'])) {
         $sidebars = $serendipity['sidebars'];
     } else {
         $sidebars = array('left', 'hide', 'right');
     }
     $plugin_list = array();
     $view_list = array();
     $category_view_list = array();
     $usergroups_view_list = array();
     foreach ($sidebars as $sidebar) {
         $plugins = serendipity_plugin_api::enum_plugins($sidebar);
         $i = 0;
         if (is_array($plugins)) {
             if ($sidebar == 'left') {
                 $pside = 0;
             } elseif ($sidebar == 'right') {
                 $pside = 1;
             } else {
                 $pside = $sidebar;
             }
             foreach ($plugins as $plugin) {
                 if (isset($_REQUEST['plugin_' . $pside . '_' . $i])) {
                     $plugin_list[$pside][$i] = 0;
                 } else {
                     $plugin_list[$pside][$i] = 1;
                 }
                 $i++;
             }
         }
     }
     $this->set_config('plugin_list', serialize($plugin_list));
     foreach ((array) $_REQUEST['plugin_view'] as $instance => $prop) {
         if ($prop == 'myself') {
             $view_list[base64_decode($instance)] = $serendipity['authorid'];
         } elseif ($prop == 'member') {
             $view_list[base64_decode($instance)] = 'member';
         } elseif ($prop == 'everyone') {
             //--JAM: 2005-10-18
             $view_list[base64_decode($instance)] = 'everyone';
         }
     }
     $this->set_config('view_list', serialize($view_list));
     foreach ((array) $_REQUEST['plugin_category_view'] as $instance => $prop) {
         $category_view_list[base64_decode($instance)] = implode(',', $prop);
     }
     $this->set_config('category_view_list', serialize($category_view_list));
     foreach ((array) $_REQUEST['plugin_usergroups_view'] as $instance => $prop) {
         $usergroups_view_list[base64_decode($instance)] = implode(',', $prop);
     }
     $this->set_config('usergroups_view_list', serialize($usergroups_view_list));
     echo '<div class="serendipityAdminMsgSuccess"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . sprintf(SETTINGS_SAVED_AT, serendipity_strftime('%T')) . "<br /><br />\n</div>";
 }
 function event_hook($event, &$bag, &$eventData, $addData = null)
 {
     global $serendipity;
     $hooks =& $bag->get('event_hooks');
     if (isset($hooks[$event])) {
         switch ($event) {
             case 'genpage':
                 $args = implode('/', serendipity_getUriArguments($eventData, true));
                 if ($serendipity['rewrite'] != 'none') {
                     $nice_url = $serendipity['serendipityHTTPPath'] . $args;
                 } else {
                     $nice_url = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?/' . $args;
                 }
                 if ($this->selected()) {
                     $serendipity['head_title'] = $this->get_config('pagetitle');
                     $serendipity['head_subtitle'] = $serendipity['blogTitle'];
                 }
                 if (empty($serendipity['GET']['subpage'])) {
                     $serendipity['GET']['subpage'] = $nice_url;
                 }
                 serendipity_smarty_init();
                 $serendipity['smarty']->register_function('customArchive', array($this, 'smarty_customArchive'));
                 break;
             case 'entry_display':
                 if ($this->selected()) {
                     if (is_array($eventData)) {
                         $eventData['clean_page'] = true;
                         // This is important to not display an entry list!
                     } else {
                         $eventData = array('clean_page' => true);
                     }
                 }
                 if (version_compare($serendipity['version'], '0.7.1', '<=')) {
                     $this->show();
                 }
                 return true;
                 break;
             case 'entries_header':
                 $this->show();
                 return true;
                 break;
             default:
                 return false;
                 break;
         }
     } else {
         return false;
     }
 }
/**
 * Passes the list of fetched entries from serendipity_fetchEntries() on to the Smarty layer
 *
 * This function contains all the core logic to group and prepare entries to be shown in your
 * $entries.tpl template. It groups them by date, so that you can easily loop on the set of
 * entries.
 * This function is not only used for printing all entries, but also for printing individual
 * entries.
 * Several central Event hooks are executed here for the whole page flow, like header+footer data.
 *
 * @see serendipity_fetchEntries()
 * @see serendipity_searchEntries()
 * @access public
 * @param   array       The array of entries with all of its data
 * @param   boolean     Toggle whether the extended portion of an entry is requested (via $serendipity['GET']['id'] single entry view)
 * @param   boolean     Indicates if this is a preview
 * @param   string      The name of the SMARTY block that this gets parsed into
 * @param   boolean     Indicates whether the assigned smarty variables should be parsed. When set to "return", no smarty parsing is done.
 * @param   boolean     Indicates whether to apply footer/header event hooks
 * @param   boolean     Indicates whether the pagination footer should be displayed
 * @param   mixed       Indicates whether the input $entries array is already grouped in preparation for the smarty $entries output array [TRUE], or if it shall be grouped by date [FALSE] or if a plugin hook shall be executed to modify data ['plugin']. This setting can also be superseded by a 'entry_display' hook.
 * @return
 */
function serendipity_printEntries($entries, $extended = 0, $preview = false, $smarty_block = 'ENTRIES', $smarty_fetch = true, $use_hooks = true, $use_footer = true, $use_grouped_array = false)
{
    global $serendipity;
    if (!is_object($serendipity['smarty'])) {
        serendipity_smarty_init();
        // if not set, start Smarty templating to avoid member function "method()" on a non-object errors (was draft preview error, now at line 1239)
    }
    if ($use_hooks) {
        $addData = array('extended' => $extended, 'preview' => $preview);
        serendipity_plugin_api::hook_event('entry_display', $entries, $addData);
        if (isset($entries['clean_page']) && $entries['clean_page'] === true) {
            if ($serendipity['view'] == '404') {
                $serendipity['view'] = 'plugin';
            }
            $serendipity['smarty']->assign(array('plugin_clean_page' => true, 'view' => $serendipity['view']));
            serendipity_smarty_fetch($smarty_block, 'entries.tpl', true);
            return;
            // no display of this item
        }
    }
    // We shouldn't return here, because we want Smarty to handle the output
    if (!is_array($entries) || $entries[0] == false || !isset($entries[0]['timestamp'])) {
        $entries = array();
    }
    // A plugin executed in entry_display should be able to change the way of ordering entries. Forward-Thinking. ;)
    if (isset($entries['use_grouped_array'])) {
        $use_grouped_array = $entries['use_grouped_array'];
    }
    if ($use_grouped_array === false) {
        // Use grouping by date (default)
        $dategroup = array();
        for ($x = 0, $num_entries = count($entries); $x < $num_entries; $x++) {
            if (!empty($entries[$x]['properties']['ep_is_sticky']) && serendipity_db_bool($entries[$x]['properties']['ep_is_sticky'])) {
                $entries[$x]['is_sticky'] = true;
                $key = 'sticky';
            } else {
                $key = date('Ymd', serendipity_serverOffsetHour($entries[$x]['timestamp']));
            }
            $dategroup[$key]['date'] = $entries[$x]['timestamp'];
            $dategroup[$key]['is_sticky'] = isset($entries[$x]['is_sticky']) && (serendipity_db_bool($entries[$x]['is_sticky']) ? true : false);
            $dategroup[$key]['entries'][] =& $entries[$x];
        }
    } elseif ($use_grouped_array === 'plugin') {
        // Let a plugin do the grouping
        serendipity_plugin_api::hook_event('entry_groupdata', $entries);
        $dategroup =& $entries;
    } else {
        $dategroup =& $entries;
    }
    foreach ($dategroup as $dategroup_idx => $properties) {
        foreach ($properties['entries'] as $x => $_entry) {
            if ($smarty_fetch === 'return') {
                $entry =& $dategroup[$dategroup_idx]['entries'][$x];
                // PHP4 Compat
            } else {
                // DISABLED - made problems with custom plugins
                // $entry = &$properties['entries'][$x]; // PHP4 Compat
                $entry =& $dategroup[$dategroup_idx]['entries'][$x];
                // PHP4 Compat
            }
            if (!empty($entry['properties']['ep_cache_body'])) {
                $entry['pre_body'] = $entry['body'];
                $entry['body'] =& $entry['properties']['ep_cache_body'];
                $entry['is_cached'] = true;
            }
            //--JAM: Highlight-span search terms
            if ($serendipity['action'] == 'search') {
                $searchterms = str_replace('"', '', $serendipity['GET']['searchterms']);
                $searchterms = explode($searchterms, ' ');
                foreach ($searchterms as $searchdx => $searchterm) {
                    $searchclass = "foundterm foundterm" . $searchdx;
                    $entry['body'] = str_replace($searchterm, '<span class="' . $searchclass . '">' . $searchterm . '</span>', $entry['body']);
                }
            }
            if (!empty($entry['properties']['ep_cache_extended'])) {
                $entry['pre_extended'] = $entry['extended'];
                $entry['extended'] =& $entry['properties']['ep_cache_extended'];
                $entry['is_cached'] = true;
            }
            if ($preview) {
                $entry['author'] = $entry['realname'];
                $entry['authorid'] = $serendipity['authorid'];
            }
            $addData = array('from' => 'functions_entries:printEntries');
            if ($entry['is_cached']) {
                $addData['no_scramble'] = true;
            }
            serendipity_plugin_api::hook_event('frontend_display', $entry, $addData);
            if ($preview) {
                $entry['author'] = $entry['realname'];
                $entry['authorid'] = $serendipity['authorid'];
            }
            $entry['author'] = serendipity_specialchars($entry['author']);
            $authorData = array('authorid' => $entry['authorid'], 'username' => $entry['loginname'], 'email' => $entry['email'], 'realname' => $entry['author']);
            $entry['link'] = serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp']));
            $entry['commURL'] = serendipity_archiveURL($entry['id'], $entry['title'], 'baseURL', false, array('timestamp' => $entry['timestamp']));
            $entry['html_title'] = $entry['title'];
            $entry['title'] = serendipity_specialchars($entry['title']);
            $entry['title_rdf'] = preg_replace('@-{2,}@', '-', $entry['html_title']);
            $entry['rdf_ident'] = serendipity_archiveURL($entry['id'], $entry['title_rdf'], 'baseURL', true, array('timestamp' => $entry['timestamp']));
            $entry['link_rdf'] = serendipity_rewriteURL(PATH_FEEDS . '/ei_' . $entry['id'] . '.rdf');
            $entry['title_rdf'] = serendipity_specialchars($entry['title_rdf']);
            $entry['link_allow_comments'] = $serendipity['baseURL'] . 'comment.php?serendipity[switch]=enable&amp;serendipity[entry]=' . $entry['id'];
            $entry['link_deny_comments'] = $serendipity['baseURL'] . 'comment.php?serendipity[switch]=disable&amp;serendipity[entry]=' . $entry['id'];
            $entry['allow_comments'] = serendipity_db_bool($entry['allow_comments']);
            $entry['moderate_comments'] = serendipity_db_bool($entry['moderate_comments']);
            $entry['viewmode'] = $serendipity['GET']['cview'] == VIEWMODE_LINEAR ? VIEWMODE_LINEAR : VIEWMODE_THREADED;
            $entry['link_popup_comments'] = $serendipity['serendipityHTTPPath'] . 'comment.php?serendipity[entry_id]=' . $entry['id'] . '&amp;serendipity[type]=comments';
            $entry['link_popup_trackbacks'] = $serendipity['serendipityHTTPPath'] . 'comment.php?serendipity[entry_id]=' . $entry['id'] . '&amp;serendipity[type]=trackbacks';
            $entry['link_edit'] = $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[action]=admin&amp;serendipity[adminModule]=entries&amp;serendipity[adminAction]=edit&amp;serendipity[id]=' . $entry['id'];
            $entry['link_trackback'] = $serendipity['baseURL'] . 'comment.php?type=trackback&amp;entry_id=' . $entry['id'];
            $entry['link_viewmode_threaded'] = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?url=' . $entry['commURL'] . '&amp;serendipity[cview]=' . VIEWMODE_THREADED;
            $entry['link_viewmode_linear'] = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?url=' . $entry['commURL'] . '&amp;serendipity[cview]=' . VIEWMODE_LINEAR;
            $entry['link_author'] = serendipity_authorURL($authorData);
            if (is_array($entry['categories'])) {
                foreach ($entry['categories'] as $k => $v) {
                    if (!isset($entry['categories'][$k]['category_link'])) {
                        $entry['categories'][$k]['category_link'] = serendipity_categoryURL($entry['categories'][$k]);
                    }
                }
            }
            if (strlen($entry['extended'])) {
                $entry['has_extended'] = true;
            }
            if (isset($entry['exflag']) && $entry['exflag'] && ($extended || $preview)) {
                $entry['is_extended'] = true;
            }
            if (serendipity_db_bool($entry['allow_comments']) || !isset($entry['allow_comments']) || $entry['comments'] > 0) {
                $entry['has_comments'] = true;
                $entry['label_comments'] = $entry['comments'] == 1 ? COMMENT : COMMENTS;
            }
            if (serendipity_db_bool($entry['allow_comments']) || !isset($entry['allow_comments']) || $entry['trackbacks'] > 0) {
                $entry['has_trackbacks'] = true;
                $entry['label_trackbacks'] = $entry['trackbacks'] == 1 ? TRACKBACK : TRACKBACKS;
            }
            if ($_SESSION['serendipityAuthedUser'] === true && ($_SESSION['serendipityAuthorid'] == $entry['authorid'] || serendipity_checkPermission('adminEntriesMaintainOthers'))) {
                $entry['is_entry_owner'] = true;
            }
            $entry['display_dat'] = '';
            serendipity_plugin_api::hook_event('frontend_display:html:per_entry', $entry);
            $entry['plugin_display_dat'] =& $entry['display_dat'];
            if ($preview) {
                ob_start();
                serendipity_plugin_api::hook_event('backend_preview', $entry);
                $entry['backend_preview'] = ob_get_contents();
                ob_end_clean();
            }
            /* IF WE ARE DISPLAYING A FULL ENTRY */
            if (isset($serendipity['GET']['id'])) {
                $comment_add_data = array('comments_messagestack' => isset($serendipity['messagestack']['comments']) ? (array) $serendipity['messagestack']['comments'] : array(), 'is_comment_added' => isset($serendipity['GET']['csuccess']) && $serendipity['GET']['csuccess'] == 'true' ? true : false, 'is_comment_moderate' => isset($serendipity['GET']['csuccess']) && $serendipity['GET']['csuccess'] == 'moderate' ? true : false);
                if ($serendipity['serendipityAuthedUser'] === true) {
                    $userData = array();
                    $userData['name'] = $serendipity['realname'];
                    $userData['email'] = $serendipity['email'];
                    $userData['url'] = '';
                } else {
                    $userData = $serendipity['POST'];
                }
                $serendipity['smarty']->assign($comment_add_data);
                serendipity_displayCommentForm($entry['id'], $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?url=' . $entry['commURL'], true, $userData, true, serendipity_db_bool($entry['moderate_comments']), $entry);
            }
            // END FULL ENTRY LOGIC
        }
        // end foreach-loop (entries)
    }
    // end foreach-loop (dates)
    if (!isset($serendipity['GET']['id']) && (!isset($serendipity['hidefooter']) || $serendipity['hidefooter'] == false) && $num_entries <= $serendipity['fetchLimit'] && $use_footer) {
        serendipity_printEntryFooter();
    }
    if ($smarty_fetch === 'return') {
        return $dategroup;
    }
    $serendipity['smarty']->assignByRef('entries', $dategroup);
    if ($serendipity['useInternalCache']) {
        $cache = serendipity_setupCache();
        $args = func_get_args();
        $args = array_values($args);
        $key = md5(serialize($args));
        $cache->save(serialize($dategroup), $key, "printEntries");
    }
    unset($entries, $dategroup);
    $serendipity['smarty']->assign(array('is_preview' => $preview));
    if (isset($serendipity['short_archives']) && $serendipity['short_archives']) {
        return serendipity_smarty_fetch($smarty_block, 'entries_summary.tpl', true);
    } elseif ($smarty_fetch == true) {
        return serendipity_smarty_fetch($smarty_block, 'entries.tpl', true, $preview);
    }
}
 /**
  * event hook: external_plugin
  *
  * @param   array   GET parameters
  * @param   boolean config var
  */
 function displayExternalTaglist($param, $ctaglist = false)
 {
     global $serendipity;
     $tagged_as_list = false;
     // Manually added (last) parameter 'taglist' to view tags by list for certain taglinks eg.: example.org/plugin/tag/Serendipity/Blog/Plums/taglist - both need a modified entries.tpl
     if ($ctaglist && in_array('taglist', $serendipity['uriArguments'])) {
         $param = array_map('urldecode', $param);
         $param = array_map('urldecode', $param);
         // for doubled encoded tag umlauts via searchengine backlinks
         $param = is_array($param) ? array_map('strip_tags', $param) : strip_tags($param);
         $param = array_filter($param);
         // filter out all left BOOL, NULL and EMPTY elements, which still are possible by removing XSS with strip_tags
         if (!is_object($serendipity['smarty'])) {
             serendipity_smarty_init();
         }
         if (false === serendipity_db_bool($this->get_config('show_tagcloud', 'true'))) {
             // Since this is extra stuff, we need to regular assign the subtitle header and not use $serendipity['head_subtitle'] !
             if (count($param) > 1) {
                 if (function_exists('serendipity_specialchars')) {
                     $serendipity['smarty']->assign('head_subtitle', sprintf(PLUGIN_EVENT_FREETAG_USING, implode(', ', array_map('serendipity_specialchars', $param))));
                 } else {
                     $serendipity['smarty']->assign('head_subtitle', sprintf(PLUGIN_EVENT_FREETAG_USING, implode(', ', array_map('self::callback_map', $param))));
                 }
             } else {
                 $serendipity['smarty']->assign('head_subtitle', sprintf(PLUGIN_EVENT_FREETAG_USING, self::specialchars_mapper($param[0])));
             }
         }
         $serendipity['smarty']->assign('taglist', true);
         foreach ($serendipity['uriArguments'] as $uak => $uav) {
             if ($uav == 'taglist') {
                 unset($serendipity['uriArguments'][$uak]);
             }
         }
         $tagged_as_list = true;
     }
     /* Attempt to locate hidden variables within the URI */
     foreach ($serendipity['uriArguments'] as $k => $v) {
         if ($v[0] == 'P') {
             /* Page */
             $page = substr($v, 1);
             if (is_numeric($page)) {
                 $serendipity['GET']['page'] = $page;
                 unset($serendipity['uriArguments'][$k]);
                 if ($param[count($param) - 1] == "P{$page}.html") {
                     array_pop($param);
                     // knock it off of the param array as well
                 }
             }
         }
     }
     if (count($param) == 0 || empty($param[0])) {
         $serendipity['head_subtitle'] = PLUGIN_EVENT_FREETAG_ALLTAGS;
         $this->displayTag = true;
         $param = null;
     } else {
         if (count($param) == 1) {
             $param = urldecode($param[0]);
             $param = urldecode($param);
             // for doubled encoded tag umlauts via searchengine backlinks
             $param = strip_tags($param);
             $serendipity['head_subtitle'] = sprintf(PLUGIN_EVENT_FREETAG_USING, self::specialchars_mapper($param));
             $emit_404 = true;
         } else {
             if (!$tagged_as_list) {
                 $param = array_map('urldecode', $param);
                 $param = array_map('urldecode', $param);
                 // for doubled encoded tag umlauts via searchengine backlinks in sprintf
             }
             $param = array_map('strip_tags', $param);
             $param = array_filter($param);
             // filter out all left BOOL, NULL and EMPTY elements, which still are possible by removing XSS with strip_tags
             if (function_exists('serendipity_specialchars')) {
                 $serendipity['head_subtitle'] = sprintf(PLUGIN_EVENT_FREETAG_USING, implode(', ', array_map('serendipity_specialchars', $param)));
             } else {
                 $serendipity['head_subtitle'] = sprintf(PLUGIN_EVENT_FREETAG_USING, implode(', ', array_map('self::callback_map', $param)));
             }
             $emit_404 = true;
         }
     }
     // for XSS secureness, while using doubled decode
     $param = is_array($param) ? array_map('strip_tags', $param) : strip_tags($param);
     if (is_array($param)) {
         array_filter($param);
         // filter out all left BOOL, NULL and EMPTY elements, which still are possible by removing XSS with strip_tags
     }
     if (function_exists('serendipity_specialchars')) {
         $param = is_array($param) ? array_map('serendipity_specialchars', $param) : serendipity_specialchars($param);
     } else {
         $param = is_array($param) ? array_map('self::callback_map', $param) : htmlspecialchars($param, ENT_COMPAT, LANG_CHARSET);
     }
     $this->tags['show'] = $param;
     $serendipity['plugin_vars']['tag'] = $param;
     if (is_array($param)) {
         @define('PLUGIN_VARS_TAG', implode(',', $param));
     } else {
         @define('PLUGIN_VARS_TAG', $param);
     }
     $serendipity['GET']['subpage'] = $eventData;
     unset($serendipity['GET']['category']);
     // No restriction should be enforced here.
     if ($tagged_as_list) {
         $serendipity['fetchLimit'] = 99;
         // do not use frontend entries pagination if count < 100 entries
     }
     include_once S9Y_INCLUDE_PATH . 'include/genpage.inc.php';
     if ($emit_404 && $this->taggedEntries !== null && $this->taggedEntries < 1) {
         @header('HTTP/1.0 404 Not found');
         @header('Status: 404 Not found');
         if (serendipity_db_bool($this->get_config('send_http_header', 'true'))) {
             @header('X-FreeTag: not found');
         }
     } else {
         if (serendipity_db_bool($this->get_config('send_http_header', 'true'))) {
             @header('X-FreeTag: ' . $this->taggedEntries);
         }
     }
     $raw_data = ob_get_contents();
     ob_end_clean();
     // the "missing" ob_start() is defined in serendipity roots index.php file
     $serendipity['smarty']->assign('raw_data', $raw_data);
     if (serendipity_db_bool($this->get_config('show_tagcloud', 'true'))) {
         $serendipity['smarty']->assign('istagcloud', true);
         // allows to remove a sidebar with a tag cloud, when using an entry cloud
         // @see changeLog - needs to change your template index.tpl sidebar condition(s), eg. {if !$istagcloud}
     }
     serendipity_gzCompression();
     $serendipity['smarty']->display(serendipity_getTemplateFile($serendipity['smarty_file'], 'serendipityPath'));
     @define('NO_EXIT', true);
     // RQ: Why did or do we (still) need this? (see index.php file change in 2.1-alpha2) - with 2.1 obsolet!
 }
 function smarty_show($template, $data = null)
 {
     global $serendipity;
     if (!is_object($serendipity['smarty'])) {
         serendipity_smarty_init();
     }
     $serendipity['smarty']->assign($data);
     $tfile = serendipity_getTemplateFile($template, 'serendipityPath');
     if ($tfile == $template) {
         $tfile = dirname(__FILE__) . "/{$template}";
     }
     $inclusion = $serendipity['smarty']->security_settings[INCLUDE_ANY];
     $serendipity['smarty']->security_settings[INCLUDE_ANY] = true;
     $content = $serendipity['smarty']->fetch('file:' . $tfile);
     $serendipity['smarty']->security_settings[INCLUDE_ANY] = $inclusion;
     echo $content;
 }
 function template_options($template, $catid)
 {
     global $serendipity, $template_config;
     if (!serendipity_checkPermission('adminTemplates')) {
         return;
     }
     $template = str_replace('.', '', urldecode($template));
     $catid = (int) $catid;
     $tpl_path = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $template;
     if (!is_dir($tpl_path)) {
         return false;
     }
     $serendipity['GET']['adminModule'] == 'templates';
     $serendipity['smarty_vars']['template_option'] = $template . '_' . $catid;
     echo '<h3>' . STYLE_OPTIONS . '</h3>';
     if (file_exists($tpl_path . '/config.inc.php')) {
         serendipity_smarty_init();
         include_once $tpl_path . '/config.inc.php';
     }
     if (is_array($template_config)) {
         serendipity_plugin_api::hook_event('backend_templates_configuration_top', $template_config);
         if ($serendipity['POST']['adminSubAction'] == 'configure') {
             foreach ($serendipity['POST']['template'] as $option => $value) {
                 categorytemplate_option::set_config($option, $value, $serendipity['smarty_vars']['template_option']);
             }
             echo '<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . DONE . ': ' . sprintf(SETTINGS_SAVED_AT, serendipity_strftime('%H:%M:%S')) . '</div>';
         }
         echo '<form method="post" action="serendipity_admin.php">';
         echo '<input type="hidden" name="serendipity[adminModule]" value="templates" />';
         echo '<input type="hidden" name="serendipity[adminSubAction]" value="configure" />';
         echo '<input type="hidden" name="serendipity[adminAction]" value="cattemplate" />';
         echo '<input type="hidden" name="serendipity[adminModule]" value="event_display" />';
         echo '<input type="hidden" name="serendipity[catid]" value="' . $catid . '" />';
         echo '<input type="hidden" name="serendipity[cat_template]" value="' . urlencode($template) . '" />';
         include S9Y_INCLUDE_PATH . 'include/functions_plugins_admin.inc.php';
         $template_vars =& serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option']);
         $template_options = new categorytemplate_option();
         $template_options->import($template_config);
         $template_options->values =& $template_vars;
         serendipity_plugin_config($template_options, $template_vars, $serendipity['template'], $serendipity['template'], $template_options->keys, true, true, true, true, 'template');
         echo '</form><br />';
         serendipity_plugin_api::hook_event('backend_templates_configuration_bottom', $template_config);
     } else {
         echo '<p>' . STYLE_OPTIONS_NONE . '</p>';
         serendipity_plugin_api::hook_event('backend_templates_configuration_none', $template_config);
     }
 }
    function showForm(&$form_values, &$form_container, $introspec_func = 'introspect_item', $value_func = 'get_static', $submit_name = 'staticSubmit')
    {
        global $serendipity;
        $this->htmlnugget = array();
        $GLOBALS['staticpage_htmlnugget'] =& $this->htmlnugget;
        $serendipity['EditorBrowsers'] = '@(IE|Mozilla|Safari)@i';
        if (file_exists(S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php')) {
            include_once S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php';
        }
        // Code copied from include/admin/plugins.inc.php. Sue me. ;-)
        if ($value_func == 'get_static' && $serendipity['POST']['backend_template'] != 'internal') {
            serendipity_smarty_init();
            $serendipity['smarty']->register_modifier('in_array', 'in_array');
            $serendipity['smarty']->register_function('staticpage_input', array($this, 'SmartyInspectConfig'));
            $serendipity['smarty']->register_function('staticpage_input_finish', array($this, 'SmartyInspectConfigFinish'));
            if (isset($serendipity['wysiwyg'])) {
                $serendipity['smarty']->assign('is_wysiwyg', $serendipity['wysiwyg']);
            }
            $filename = preg_replace('@[^a-z0-9\\._-]@i', '', $serendipity['POST']['backend_template']);
            if ($filename == 'external' || empty($filename)) {
                $filename = 'default_staticpage_backend.tpl';
            }
            if ($serendipity['version'][0] < 2) {
                $tfile = serendipity_getTemplateFile('backend_templates/' . $filename, 'serendipityPath');
                // old API
            } else {
                $tfile = serendipity_getTemplateFile('backend_templates/' . $filename, 'serendipityPath', true);
                // force fallback
            }
            if (!$tfile || $tfile == 'backend_templates/' . $filename) {
                $tfile = serendipity_getTemplateFile($filename, 'serendipityPath');
                if (!$tfile || $tfile == $filename) {
                    $tfile = dirname(__FILE__) . '/backend_templates/' . $filename;
                }
            }
            $inclusion = $serendipity['smarty']->security_settings[INCLUDE_ANY];
            $serendipity['smarty']->security_settings[INCLUDE_ANY] = true;
            $serendipity['smarty']->assign(array('showmeta' => serendipity_db_bool($this->get_config('showmeta')), 'form_keys' => $form_values, 'form_container' => $this->staticpage, 'form_post' => $serendipity['POST']['plugin'], 'form_values' => is_array($serendipity['POST']['plugin']) ? $serendipity['POST']['plugin'] : $this->staticpage));
            $content = $serendipity['smarty']->fetch('file:' . $tfile);
            $serendipity['smarty']->security_settings[INCLUDE_ANY] = $inclusion;
            echo $content;
            return true;
        }
        ?>
<br /><hr />
    <table border="0" cellspacing="0" cellpadding="3" width="100%">
<?php 
        $elcount = 0;
        $this->htmlnugget = array();
        foreach ($form_values as $config_item) {
            $elcount++;
            $config_value = $form_container[$config_item];
            $cbag = new serendipity_property_bag();
            $this->{$introspec_func}($config_item, $cbag);
            $cname = function_exists('serendipity_specialchars') ? serendipity_specialchars($cbag->get('name')) : htmlspecialchars($cbag->get('name'), ENT_COMPAT, LANG_CHARSET);
            $cdesc = function_exists('serendipity_specialchars') ? serendipity_specialchars($cbag->get('description')) : htmlspecialchars($cbag->get('description'), ENT_COMPAT, LANG_CHARSET);
            $value = $this->{$value_func}($config_item, 'unset');
            $lang_direction = function_exists('serendipity_specialchars') ? serendipity_specialchars($cbag->get('lang_direction')) : htmlspecialchars($cbag->get('lang_direction'), ENT_COMPAT, LANG_CHARSET);
            if (empty($lang_direction)) {
                $lang_direction = LANG_DIRECTION;
            }
            /* Apparently no value was set for this config item */
            if ($value === 'unset') {
                /* Try and the default value for the config item */
                $value = $cbag->get('default');
            }
            $hvalue = (!isset($serendipity['POST'][$submit_name]) || is_array($serendipity['GET']['pre'])) && isset($serendipity['POST']['plugin'][$config_item]) ? function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['plugin'][$config_item]) : htmlspecialchars($serendipity['POST']['plugin'][$config_item], ENT_COMPAT, LANG_CHARSET) : (function_exists('serendipity_specialchars') ? serendipity_specialchars($value) : htmlspecialchars($value, ENT_COMPAT, LANG_CHARSET));
            $radio = array();
            $select = array();
            $per_row = null;
            $type = $cbag->get('type');
            $select = $cbag->get('select_values');
            $radio2 = $cbag->get('radio');
            $per_row2 = $cbag->get('radio_per_row');
            $default = $cbag->get('default');
            $this->inspectConfig(false, 'input', $elcount, $config_item, $config_value, $type, $cname, $cdesc, $value, $default, $lang_direction, $hvalue, $radio, $radio2, $select, $per_row, $per_row2);
        }
        if (isset($serendipity['wysiwyg']) && $serendipity['wysiwyg'] && count($this->htmlnugget) > 0) {
            $ev = array('nuggets' => $this->htmlnugget, 'skip_nuggets' => false);
            serendipity_plugin_api::hook_event('backend_wysiwyg_nuggets', $ev);
            if ($ev['skip_nuggets'] === false) {
                ?>
    <script type="text/javascript">
    function Spawnnugget() {
        <?php 
                foreach ($this->htmlnugget as $htmlnuggetid) {
                    if (version_compare(preg_replace('@[^0-9\\.]@', '', $serendipity['version']), '0.9', '<')) {
                        ?>
        if (window.Spawnnuggets) Spawnnuggets<?php 
                        echo $htmlnuggetid;
                        ?>
();
                    <?php 
                    } else {
                        ?>

        if (window.Spawnnuggets) Spawnnuggets('<?php 
                        echo $htmlnuggetid;
                        ?>
');
                    <?php 
                    }
                    ?>
        <?php 
                }
                ?>
    }
    </script>
<?php 
            }
        }
        serendipity_plugin_api::hook_event('backend_staticpages_showform', $this->staticpage);
        ?>
    </table>
<br />
    <div style="padding-left: 20px">
        <input type="submit" name="serendipity[SAVECONF]" value="<?php 
        echo SAVE;
        ?>
" class="serendipityPrettyButton input_button" />
    </div>
<?php 
    }
                foreach ($badsums as $rpath => $calcsum) {
                    echo '<li class="serendipityAdminMsgError">' . sprintf(CHECKSUM_FAILED, $rpath) . '</li>';
                }
                echo '</ul>';
            }
            $admin_section = INTEGRITY;
            break;
        default:
            include S9Y_INCLUDE_PATH . 'include/admin/overview.inc.php';
            $admin_section = ADMIN_FRONTPAGE;
            break;
    }
    $main_content = ob_get_contents();
    ob_end_clean();
}
if (!$use_installer && !$_SESSION['no_smarty'] && serendipity_smarty_init()) {
    $poll_admin_vars = array('css_file', 'admin_css_file', 'main_content', 'no_banner', 'no_sidebar', 'post_action', 'is_logged_in', 'admin_installed', 'self_info', 'use_installer', 'title');
    $admin_vars = array();
    foreach ($poll_admin_vars as $poll_admin_var) {
        $admin_vars[$poll_admin_var] =& ${$poll_admin_var};
    }
    $admin_vars['out'] = array();
    $admin_vars['no_create'] = $serendipity['no_create'];
    $admin_vars['title'] = $admin_section;
    if ($serendipity['expose_s9y']) {
        $admin_vars['version_info'] = sprintf(ADMIN_FOOTER_POWERED_BY, $serendipity['versionInstalled'], phpversion());
    } else {
        $admin_vars['version_info'] = sprintf(ADMIN_FOOTER_POWERED_BY, '', '');
    }
    $serendipity['smarty']->assign_by_ref('admin_vars', $admin_vars);
    $serendipity['smarty']->display(serendipity_getTemplateFile('admin/index.tpl', 'serendipityPath'));
Example #21
0
 /**
  * Get a list of Sidebar plugins and pass them to Smarty
  *
  * @access public
  * @param   string      The side of plugins to show (left/right/hide/event/eventh)
  * @param   string      deprecated: Indicated which wrapping HTML element to use for plugins
  * @param   boolean     Indicates whether only all plugins should be shown that are not in the $side list
  * @param   string      Only show plugins of this plugin class
  * @param   string      Only show a plugin with this instance ID
  * @return  string      Smarty HTML output
  */
 function generate_plugins($side, $tag = '', $negate = false, $class = null, $id = null, $tpl = 'sidebar.tpl')
 {
     global $serendipity;
     /* $tag parameter is deprecated and used in Smarty templates instead. Only use it in function
      * header for layout.php BC.
      */
     $plugins = serendipity_plugin_api::enum_plugins($side, $negate, $class, $id);
     if (!is_array($plugins)) {
         return;
     }
     if (!isset($serendipity['smarty'])) {
         $serendipity['smarty_raw_mode'] = true;
         serendipity_smarty_init();
     }
     $pluginData = array();
     $addData = func_get_args();
     serendipity_plugin_api::hook_event('frontend_generate_plugins', $plugins, $addData);
     if (count($plugins) == 0) {
         $serendipity['prevent_sidebar_plugins_' . $side] = true;
     }
     $loggedin = false;
     if (serendipity_userLoggedIn() && serendipity_checkPermission('adminPlugins')) {
         $loggedin = true;
     }
     foreach ($plugins as $plugin_data) {
         $plugin =& serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid'], $plugin_data['path']);
         if (is_object($plugin)) {
             $class = get_class($plugin);
             $title = '';
             /* TODO: make generate_content NOT echo its output */
             ob_start();
             $show_plugin = $plugin->generate_content($title);
             $content = ob_get_contents();
             ob_end_clean();
             if ($loggedin) {
                 $content .= '<div class="serendipity_edit_nugget"><a href="' . $serendipity['serendipityHTTPPath'] . 'serendipity_admin.php?serendipity[adminModule]=plugins&amp;serendipity[plugin_to_conf]=' . htmlentities($plugin->instance) . '">' . EDIT . '</a></div>';
             }
             if ($show_plugin !== false) {
                 $pluginData[] = array('side' => $side, 'class' => $class, 'title' => $title, 'content' => $content, 'id' => $plugin->instance);
             }
         } else {
             $pluginData[] = array('side' => $side, 'title' => ERROR, 'class' => $class, 'content' => sprintf(INCLUDE_ERROR, $plugin_data['name']));
         }
     }
     serendipity_plugin_api::hook_event('frontend_sidebar_plugins', $pluginData, $addData);
     $serendipity['smarty']->assign_by_ref('plugindata', $pluginData);
     $serendipity['smarty']->assign('pluginside', ucfirst($side));
     return serendipity_smarty_fetch('sidebar_' . $side, $tpl, true);
 }
    function event_hook($event, &$bag, &$eventData, $addlData = null)
    {
        global $serendipity;
        $hooks =& $bag->get('event_hooks');
        // I'm not really certain why this is here (since we only get called
        // for the events we hooked), but Garvin uses it, so it must be
        // important.
        if (isset($hooks[$event])) {
            $content_type = $this->get_config('content_type', 'categories');
            $placement = $this->get_config('placement', 'entry top');
            $news_cats = $this->get_config('news_cats');
            switch ($event) {
                case 'genpage':
                    // Is this the frontpage? (Garvin's algorythm; works
                    // for all cases except index.html, on my server)
                    if ($addlData['startpage']) {
                        $this->isFrontPage = true;
                    } else {
                        $this->isFrontPage = false;
                        return true;
                    }
                    // Get this newsbox's entries
                    //
                    // Hidden newsboxes don't need to waste time doing this.
                    if ($placement == 'hidden') {
                        return true;
                    }
                    // If I don't contain categories, I don't generate HTML from categories.
                    if ($content_type != 'categories') {
                        return true;
                    }
                    // If this newsbox is empty, we'd get an SQL error.
                    if (empty($news_cats)) {
                        $this->html = '<div class="newsbox"><i>No ' . $this->get_config('title', PLUGIN_EVENT_NEWSBOX_DEFAULT_TITLE) . ' today.</i></div>';
                        return true;
                    }
                    // Smarty isn't initialized yet.
                    serendipity_smarty_init();
                    // Create the SQL to fetch my entries
                    $sql = "\n" . ' e.id IN ' . "\n" . '(SELECT entryid FROM ' . $serendipity['dbPrefix'] . 'entrycat' . "\n" . ' WHERE categoryid IN (' . $news_cats . ')' . "\n" . ')';
                    // We don't want our exclusion logic to execute on *this*
                    // fetchEntries call!
                    $serendipity['newsbox'] = 'no_exclude';
                    //--JAM: yeah, it looks like a bug to me.  I wonder what else gets accidentally overwritten?
                    $oldLimit = $serendipity['fetchLimit'];
                    // We want the number of entries configurable
                    $max_entries = $this->get_config('max_entries', 5);
                    if (!is_numeric($max_entries)) {
                        $max_entries = 5;
                    }
                    $entries = serendipity_fetchEntries(null, true, $max_entries, false, false, 'timestamp DESC', $sql);
                    $serendipity['fetchLimit'] = $oldLimit;
                    unset($serendipity['newsbox']);
                    // Process our input data with new printEntries:
                    // $entries, no extended, no preview, block NEWSBOX, no smarty fetch, no hooks, footer
                    serendipity_printEntries($entries, 0, false, 'NEWSBOX', false, false, false);
                    $newsbox_data = array();
                    $newsbox_data['title'] = $this->get_config('title', PLUGIN_EVENT_NEWSBOX_DEFAULT_TITLE);
                    $newsbox_data['cats'] = explode(',', $news_cats);
                    $newsbox_data['content_type'] = $content_type;
                    $newsbox_data['isContainer'] = $content_type != 'categories';
                    $newsbox_data['multicat_action'] = $serendipity['baseURL'] . $serendipity['indexFile'];
                    $serendipity['smarty']->assign('newsbox_data', $newsbox_data);
                    $nb = serendipity_getTemplateFile('newsbox.tpl');
                    if ($nb && $nb != 'newsbox.tpl') {
                        // Template is obviously newsbox-aware
                        $this->html = serendipity_smarty_fetch('NEWSBOX', 'newsbox.tpl', false);
                    } else {
                        // Set the newsbox variable for the template, in case it's newsbox-aware
                        $serendipity['smarty']->assign('isNewsbox', true);
                        // Modify the footer link
                        $more = '<form style="display:inline;" action="' . $serendipity['baseURL'] . $serendipity['indexFile'] . '" method="post">';
                        foreach (explode(',', $news_cats) as $cat) {
                            $more .= '<input type="hidden" name="serendipity[multiCat][]" value="' . $cat . '">';
                        }
                        $more .= '<input class="serendipityPrettyButton input_button" type="submit" name="serendipity[isMultiCat]" value="More ' . $this->get_config('title', PLUGIN_EVENT_NEWSBOX_DEFAULT_TITLE) . '"></form>';
                        $serendipity['smarty']->assign('footer_info', $more);
                        // Get the HTML
                        $serendipity['skip_smarty_hooks'] = true;
                        // Don't call entries_header from the template!
                        $this->html = serendipity_smarty_fetch('NEWSBOX', 'entries.tpl', false);
                        unset($serendipity['skip_smarty_hooks']);
                        // Don't leave the newsbox variable set for the regular fetch
                        $serendipity['smarty']->clear_assign('isNewsbox');
                        // Check if the template supports newsboxes
                        // Matches class = "whatever_newsbox_whatever", taking care to allow
                        // whitespace where legal and match quote types (I don't think you
                        // can use a quote in a class name, but hey...)
                        if (preg_match('/class\\s*=\\s*(["\'])[^\\1]*newsbox/', $this->html) == 0) {
                            // Add the div; give it the default class "newsbox" and a title
                            $title = $this->get_config('title');
                            $this->html = "\n<div class=\"newsbox\"><h3 class=\"newsbox_title\">{$title}</h3>\n" . $this->html . "\n</div><!--newsbox-->\n";
                        }
                    }
                    // Done processing the newsbox
                    break;
                case 'frontend_fetchentries':
                    // Only on the frontpage
                    if (!$this->isFrontPage) {
                        return true;
                    }
                    // Don't even call this hook if we're already in this hook
                    if (isset($serendipity['newsbox']) && $serendipity['newsbox'] == 'no_exclude') {
                        return true;
                    }
                    // If we don't contain categories, we don't want to
                    // exclude categories accidentally
                    if ($content_type != 'categories') {
                        return true;
                    }
                    // Don't restrict the calendar, etc; only the main listing
                    $source = $addlData['source'];
                    if ($source != 'entries') {
                        return true;
                    }
                    // No joins required!
                    // $joins = array();
                    $conds = array();
                    if (isset($news_cats) && !empty($news_cats)) {
                        // Exclude entries in the newbox
                        $conds[] = ' (e.id NOT IN (SELECT entryid from ' . $serendipity['dbPrefix'] . 'entrycat' . ' WHERE categoryid IN (' . $news_cats . ')))';
                    }
                    if (count($conds) > 0) {
                        $cond = implode(' AND ', $conds);
                        if (empty($eventData['and'])) {
                            $eventData['and'] = " WHERE {$cond} ";
                        } else {
                            $eventData['and'] .= " AND {$cond} ";
                        }
                    }
                    return true;
                    break;
                case 'css':
                    // Can't tell if this is the fronpage or not.  Better
                    // generate the CSS, just in case.
                    if (strpos($eventData, 'newsbox') !== false) {
                        // This CSS is already newsbox-aware.
                        return true;
                    }
                    $eventData = $eventData . '
.newsbox
{
  border: 1px solid black;
  padding: 2px;
  margin-bottom: 4px;
}
.newsbox_title
{
  font-style: italic;
}
.newsbox_container
{
  border: 1px solid black;
  padding: 2px;
  margin-bottom: 4px;
  text-align: center;
  margin: 2px auto;
}
.newsbox_container .newsbox
{
  border: none;
  width: 48%;
  float: left;
  text-align: left;
  margin: 2px;
  display: inline;
}
                    ';
                    return true;
                    break;
                    // Placement cases: if configured placement equals the hook,
                    // print my HTML.  Hidden takes care of itself: there is no
                    // matching hook, so it never gets printed.  Contained
                    // newsboxes will also never match a hook; their HTML is
                    // requested by the containing newsbox.
                // Placement cases: if configured placement equals the hook,
                // print my HTML.  Hidden takes care of itself: there is no
                // matching hook, so it never gets printed.  Contained
                // newsboxes will also never match a hook; their HTML is
                // requested by the containing newsbox.
                case 'frontend_header':
                    if ($this->isFrontPage && $placement == 'page header') {
                        echo $this->getHTML();
                    }
                    return true;
                    break;
                case 'entries_header':
                    if ($this->isFrontPage && $placement == 'entry top') {
                        echo $this->getHTML();
                    }
                    return true;
                    break;
                case 'entries_footer':
                    if ($this->isFrontPage && $placement == 'entry bottom') {
                        // Entry footer markup is ugly.  Close the div.
                        echo '</div>';
                        echo $this->getHTML();
                        // Reopen the div we closed to avoid bad markup.
                        echo '<div>';
                    }
                    return true;
                    break;
                case 'frontend_footer':
                    if ($this->isFrontPage && $placement == 'page footer') {
                        echo $this->getHTML();
                    }
                    return true;
                    break;
                case 'newsbox:get_content':
                    // Custom hook to retrieve data for contained newsboxes.
                    // If the container asking for content is my container,
                    // add my content to the data array.
                    if ($addlData['id'] == $placement) {
                        // 1. Avoid recursion.
                        // 2. Go to step 1.
                        if (!$this->got_content[$addlData['id']]) {
                            $this->got_content[$addlData['id']] = true;
                            $eventData[] = $this->getHTML();
                        }
                        return true;
                    }
                    break;
                case 'newsbox:get_containers':
                    // Custom hook to find newsbox containers.  If I'm a newsbox
                    // container, return my instance ID.
                    if ($addlData['id'] != $this->instance && $this->get_config('content_type', 'categories') == 'newsboxes') {
                        $eventData[] = array('id' => $this->instance, 'name' => 'Newsbox: ' . $this->get_config('title', PLUGIN_EVENT_NEWSBOX_DEFAULT_TITLE));
                        return true;
                    }
                    break;
                default:
                    return false;
                    break;
            }
        } else {
            return false;
        }
        return true;
    }
/**
 * Prints the form for editing/creating new blog entries
 *
 * This is the core file where your edit form appears. The Heart Of Gold, so to say.
 *
 * @access public
 * @param   string      The URL where the entry form is submitted to
 * @param   array       An array of hidden input fields that should be passed on to the HTML FORM
 * @param   array       The entry superarray with your entry's contents
 * @param   string      Any error messages that might have occured on the last run
 * @return null
 */
function serendipity_printEntryForm($targetURL, $hiddens = array(), $entry = array(), $errMsg = "")
{
    global $serendipity;
    $serendipity['EditorBrowsers'] = '@(IE|Mozilla|Opera)@i';
    $draftD = '';
    $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 = '';
    }
    // Fix category list. If the entryForm is displayed after a POST request, the additional category information is lost.
    if (is_array($entry['categories']) && !is_array($entry['categories'][0])) {
        $categories = (array) $entry['categories'];
        $entry['categories'] = array();
        foreach ($categories as $catid) {
            $entry['categories'][] = serendipity_fetchCategoryInfo($catid);
        }
    }
    $n = "\n";
    $cat_list = '<select id="categoryselector" name="serendipity[categories][]" style="vertical-align: middle;" multiple="multiple">' . $n;
    $cat_list .= '    <option value="0">[' . NO_CATEGORY . ']</option>' . $n;
    $selected = array();
    if (is_array($entry['categories'])) {
        if (count($entry['categories']) > 1) {
            $categoryselector_expanded = true;
        }
        foreach ($entry['categories'] as $cat) {
            $selected[] = $cat['categoryid'];
        }
    }
    if (count($selected) > 1 || isset($serendipity['POST']['categories']) && is_array($serendipity['POST']['categories']) && sizeof($serendipity['POST']['categories']) > 1) {
        $categoryselector_expanded = true;
    }
    if (is_array($cats = serendipity_fetchCategories())) {
        $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
        foreach ($cats as $cat) {
            if (in_array($cat['categoryid'], $selected)) {
                $cat['is_selected'] = true;
            }
            $cat['depth_pad'] = str_repeat('&nbsp;', $cat['depth']);
            $template_vars['category_options'][] = $cat;
            $cat_list .= '<option value="' . $cat['categoryid'] . '"' . ($cat['is_selected'] ? ' selected="selected"' : '') . '>' . $cat['depth_pad'] . $cat['category_name'] . '</option>' . "\n";
        }
    }
    $cat_list .= '</select>' . $n;
    if (!empty($serendipity['GET']['title'])) {
        $entry['title'] = utf8_decode(urldecode($serendipity['GET']['title']));
    }
    if (!empty($serendipity['GET']['body'])) {
        $entry['body'] = utf8_decode(urldecode($serendipity['GET']['body']));
    }
    if (!empty($serendipity['GET']['url'])) {
        $entry['body'] .= "\n" . '<br /><a href="' . htmlspecialchars(utf8_decode(urldecode($serendipity['GET']['url']))) . '">' . $entry['title'] . '</a>';
    }
    $hidden = '';
    foreach ($hiddens as $key => $value) {
        $hidden .= '        <input type="hidden" name="' . $key . '" value="' . $value . '" />' . $n;
    }
    $hidden .= '        <input type="hidden" id="entryid" name="serendipity[id]" value="' . (isset($entry['id']) ? $entry['id'] : '') . '" />' . $n;
    $hidden .= '        <input type="hidden" name="serendipity[timestamp]" value="' . (isset($entry['timestamp']) ? serendipity_serverOffsetHour($entry['timestamp']) : serendipity_serverOffsetHour(time())) . '" />' . $n;
    $hidden .= '        <input type="hidden" name="serendipity[preview]" value="false" />';
    $hidden .= '        ' . serendipity_setFormToken();
    if (is_object($serendipity['smarty']) || !$_SESSION['no_smarty'] && serendipity_smarty_init()) {
        $use_smarty = true;
    } else {
        $use_smarty = false;
    }
    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 (preg_match($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]');
        $template_vars['entry_template'] = serendipity_getTemplateFile('admin/entries.tpl', 'serendipityPath');
        $serendipity['smarty']->registerPlugin('modifier', 'emit_htmlarea_code', 'serendipity_emit_htmlarea_code');
        $serendipity['smarty']->assign('admin_view', 'entryform');
        serendipity_plugin_api::hook_event('backend_entryform_smarty', $template_vars);
        $serendipity['smarty']->assignByRef('entry_vars', $template_vars);
        $serendipity['smarty']->display($template_vars['entry_template']);
        return true;
    }
    /* HTML CODE BELOW IS FOR FALLBACK PORTABILITY ONLY - MODIFY CODE IN TEMPLATE ADMIN/ENTRIES.TPL INSTEAD! */
    if (!empty($errMsg)) {
        ?>
        <div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="<?php 
        echo serendipity_getTemplateFile('admin/img/admin_msg_error.png');
        ?>
" alt="" /><?php 
        echo $errMsg;
        ?>
</div>
<?php 
    }
    ?>
        <form <?php 
    echo $entry['entry_form'];
    ?>
 action="<?php 
    echo $targetURL;
    ?>
" method="post" id="serendipityEntry" style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px">
        <?php 
    echo $hidden;
    ?>

        <table class="serendipityEntryEdit" border="0" width="100%">
            <tr>
                <td>
                   <b><?php 
    echo TITLE;
    ?>
:</b>
                </td>
                <td colspan="2">
                    <table width="100%" cellspacing="0" cellpadding="0" border="0">
                        <tr>
                            <td><input class="input_textbox" type="text" id="entryTitle" name="serendipity[title]" value="<?php 
    echo isset($entry['title']) ? htmlspecialchars($entry['title']) : '';
    ?>
" size="60" /></td>
                            <td align="right">
                                <select name="serendipity[isdraft]">
                                    <?php 
    if ($_SESSION['serendipityRightPublish']) {
        ?>
<option  value="false" <?php 
        echo $draftP;
        ?>
><?php 
        echo PUBLISH;
        ?>
</option><?php 
    }
    ?>
                                    <option  value="true"  <?php 
    echo $draftD;
    ?>
><?php 
    echo DRAFT;
    ?>
</option>
                                </select>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
<?php 
    if (isset($serendipity['allowDateManipulation']) && $serendipity['allowDateManipulation']) {
        ?>
                <td>
                    <b><?php 
        echo DATE;
        ?>
:</b>
                </td>
                <td>
                    <input type="hidden" name="serendipity[chk_timestamp]" value="<?php 
        echo serendipity_serverOffsetHour(isset($entry['timestamp']) && $entry['timestamp'] > 0 ? $entry['timestamp'] : time());
        ?>
" />
                    <input class="input_textbox" type="text" name="serendipity[new_timestamp]" id="serendipityNewTimestamp" value="<?php 
        echo date(DATE_FORMAT_2, serendipity_serverOffsetHour(isset($entry['timestamp']) && $entry['timestamp'] > 0 ? $entry['timestamp'] : time()));
        ?>
" />
                    <a href="#" onclick="document.getElementById('serendipityNewTimestamp').value = '<?php 
        echo date(DATE_FORMAT_2, serendipity_serverOffsetHour(time()));
        ?>
'; return false;" title="<?php 
        echo RESET_DATE_DESC;
        ?>
"><img src="<?php 
        echo serendipity_getTemplateFile('admin/img/clock.png');
        ?>
" border="0"  style="vertical-align: text-top;" alt="<?php 
        echo RESET_DATE;
        ?>
" /></a>
                </td>
                <td align="right">
<?php 
    } else {
        ?>
                <td align="right" colspan="3">
<?php 
    }
    ?>
                    <a style="border:0; text-decoration: none" href="#" onclick="showItem('categoryselector'); return false" title="<?php 
    echo TOGGLE_OPTION;
    ?>
"><img src="<?php 
    echo serendipity_getTemplateFile('img/plus.png');
    ?>
" id="option_categoryselector" style="border: 20px" alt="" border="0" /></a> <b><?php 
    echo CATEGORY;
    ?>
:</b> <?php 
    echo $cat_list;
    ?>
                    <script type="text/javascript" language="JavaScript">

                    function toggle_extended(setCookie) {
                        var textarea = document.getElementById('serendipity[extended]');
                        var button   = document.getElementById('option_extended');
                        var tools    = document.getElementById('tools_extended');
                        if ( textarea.style.display == 'none' ) {
                            textarea.style.display = '';
                            tools.style.display = '';
                            button.src = '<?php 
    echo serendipity_getTemplateFile('img/minus.png');
    ?>
';
                            if (setCookie == true) {
                                document.cookie = 'serendipity[toggle_extended]=true;';
                            }
                        } else {
                            textarea.style.display = 'none';
                            tools.style.display = 'none';
                            button.src = '<?php 
    echo serendipity_getTemplateFile('img/plus.png');
    ?>
';
                            if (setCookie == true) {
                                document.cookie = 'serendipity[toggle_extended]=;';
                            }
                        }
                    }

                    var selector_toggle  = new Array();
                    var selector_store   = new Array();
                    var selector_restore = new Array();

                    function showItem(id) {
                        var selected = 0;
                        if (typeof(id) == 'undefined' || typeof(id) == 'object') {
                            id = 'categoryselector';
                        }

                        if (document.getElementById) {
                            el = document.getElementById(id);
                            if (selector_toggle[id] && selector_toggle[id] == 'off') {
                                selector_restore[id] = new Array();
                                selector_toggle[id]  = 'on';

                                /* Hack to make sure that when the single dropdown is shown, don't have multiple selections */
                                last = 0;

                                for (i=0; i < el.options.length; i++) {
                                    if (el.options[i].selected == true) {
                                        selected++;
                                        last = i;
                                        selector_restore[id][last] = 'on';
                                    }

                                    if (selected > 1) {
                                        /* If there is more than one selected, we reset all those to false
                                           This is because otherwise the label will say 'No Category', but the categories will still be selected */
                                        for (j=0; j < el.options.length; j++) {
                                            /* Save selection in array to later restore them */
                                            if (el.options[j].selected == true) {
                                                el.options[j].selected = false;
                                                selector_restore[id][j] = 'on';
                                                last = j;
                                            } else {
                                                selector_restore[id][j] = false;
                                            }
                                        }
                                        break;
                                    }
                                }

                                el.selectedIndex = null;
                                if (last > 0) {
                                    el.selectedIndex = last;
                                }

                                el.size = 1;

                                /* Show a normal dropdown */
                                if (el.multiple) {
                                    el.multiple = false;
                                }

                                document.getElementById('option_' + id).src = '<?php 
    echo serendipity_getTemplateFile('img/plus.png');
    ?>
';
                            } else {
                                selector_store[id] = el.size;
                                if (selector_store[id] == 0) {
                                    selector_store[id] = 5;
                                }

                                last = 0;
                                if (el.selectedIndex > 0) {
                                    if (!selector_restore[id]) {
                                        selector_restore[id] = new Array();
                                    }

                                    for (j=0; j < el.options.length; j++) {
                                        /* Save selection in array to later restore them */
                                        if (el.options[j].selected == true) {
                                            selector_restore[id][j] = 'on';
                                            last = j;
                                        }
                                    }
                                }
                                el.selectedIndex = -1;
                                el.size = <?php 
    echo count($cats) + 1;
    ?>
;
                                selector_toggle[id] = 'off';

                                /* Show multiple items */
                                el.multiple = true;

                                /* Restore previously selected items? */
                                last = 0;
                                for (i = 0; i < el.options.length; i++) {
                                    if (selector_restore && selector_restore[id] && selector_restore[id][i] && selector_restore[id][i] == 'on') {
                                        val = el.options[i].value;
                                        if (el.options[i].selected != true) {
                                            el.options[i].selected = true;
                                            last = i;
                                            // [TODO] IE Bug: Don't ask me why, but this restoring only works in Internet Explorer if you put this:
                                            // alert('it doesnt matter what, just the alert is important');
                                        }
                                    }
                                }

                                document.getElementById('option_' + id).src = '<?php 
    echo serendipity_getTemplateFile('img/minus.png');
    ?>
';
                            }
                        }
                    }

                    function checkSave() {
<?php 
    $void = null;
    serendipity_plugin_api::hook_event('backend_entry_checkSave', $void);
    ?>
                        return true;
                    }

                    selector_toggle['categoryselector'] = '<?php 
    echo $categoryselector_expanded ? 'on' : 'off';
    ?>
';
                    addLoadEvent(showItem);
                    </script>
                    </td>
            </tr>
            <tr>
<?php 
    if (!$serendipity['wysiwyg']) {
        ?>
                <td colspan="2"><b><?php 
        echo ENTRY_BODY;
        ?>
</b></td>
                <td align="right">
<?php 
        /* Since the user has WYSIWYG editor disabled, we want to check if we should use the "better" non-WYSIWYG editor */
        if (!$serendipity['wysiwyg'] && preg_match($serendipity['EditorBrowsers'], $_SERVER['HTTP_USER_AGENT'])) {
            ?>
                  <script type="text/javascript" language="JavaScript">
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insI" value="I" accesskey="i" style="font-style: italic" onclick="wrapSelection(document.forms[\'serendipityEntry\'][\'serendipity[body]\'],\'<em>\',\'</em>\')" />');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insB" value="B" accesskey="b" style="font-weight: bold" onclick="wrapSelection(document.forms[\'serendipityEntry\'][\'serendipity[body]\'],\'<strong>\',\'</strong>\')" />');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insU" value="U" accesskey="u" style="text-decoration: underline;" onclick="wrapSelection(document.forms[\'serendipityEntry\'][\'serendipity[body]\'],\'<u>\',\'</u>\')" />');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insQ" value="<?php 
            echo QUOTE;
            ?>
" accesskey="q" style="font-style: italic" onclick="wrapSelection(document.forms[\'serendipityEntry\'][\'serendipity[body]\'],\'<blockquote>\',\'</blockquote>\')" />');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insJ" value="img" accesskey="j" onclick="wrapInsImage(document.forms[\'serendipityEntry\'][\'serendipity[body]\'])" />');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insImage" value="<?php 
            echo MEDIA;
            ?>
" style="" onclick="window.open(\'serendipity_admin_image_selector.php?serendipity[textarea]=body\', \'ImageSel\', \'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1\');" />');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insURL" value="URL" accesskey="l" onclick="wrapSelectionWithLink(document.forms[\'serendipityEntry\'][\'serendipity[body]\'])" />');
                  </script>
<?php 
            /* Do the "old" non-WYSIWYG editor */
        } elseif (!$serendipity['wysiwyg']) {
            ?>
                  <script type="text/javascript" language="JavaScript">
                        document.write('<input type="button" class="serendipityPrettyButton input_button" value=" B " onclick="serendipity_insBasic(document.forms[\'serendipityEntry\'][\'serendipity[body]\'], \'b\')">');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" value=" U " onclick="serendipity_insBasic(document.forms[\'serendipityEntry\'][\'serendipity[body]\'], \'u\')">');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" value=" I " onclick="serendipity_insBasic(document.forms[\'serendipityEntry\'][\'serendipity[body]\'], \'i\')">');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" value="<img>" onclick="serendipity_insImage(document.forms[\'serendipityEntry\'][\'serendipity[body]\'])">');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" value="<?php 
            echo MEDIA;
            ?>
" onclick="window.open(\'serendipity_admin_image_selector.php?serendipity[textarea]=body\', \'ImageSel\', \'width=800,height=600,toolbar=no\');">');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" value="Link" onclick="serendipity_insLink(document.forms[\'serendipityEntry\'][\'serendipity[body]\'])">');
                </script>
<?php 
        }
        serendipity_plugin_api::hook_event('backend_entry_toolbar_body', $entry);
    } else {
        ?>
            <td colspan="2"><b><?php 
        echo ENTRY_BODY;
        ?>
</b></td>
            <td><?php 
        serendipity_plugin_api::hook_event('backend_entry_toolbar_body', $entry);
        ?>

<?php 
    }
    ?>
                </td>
            </tr>

            <tr>
                <td colspan="3">
                    <textarea style="width: 100%" name="serendipity[body]" id="serendipity[body]" cols="80" rows="20"><?php 
    echo isset($entry['body']) ? htmlspecialchars($entry['body']) : '';
    ?>
</textarea>
                </td>
            </tr>

            <tr>
                <td colspan="3">
                    <table width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td align="left" width="70%">
                                <input class="input_checkbox" id="checkbox_allow_comments" type="checkbox" name="serendipity[allow_comments]" value="true" <?php 
    echo $allow_comments;
    ?>
 /><label for="checkbox_allow_comments"><?php 
    echo COMMENTS_ENABLE;
    ?>
</label><br />
                                <input class="input_checkbox" id="checkbox_moderate_comments" type="checkbox" name="serendipity[moderate_comments]" value="true" <?php 
    echo $moderate_comments;
    ?>
 /><label for="checkbox_moderate_comments"><?php 
    echo COMMENTS_MODERATE;
    ?>
</label>
                            </td>
                            <td align="right" rowspan="2" valign="middle" width="30%">
                                <input accesskey="p" type="submit" value="- <?php 
    echo PREVIEW;
    ?>
 -" class="serendipityPrettyButton input_button"  style="width: 150px" onclick="document.forms['serendipityEntry'].elements['serendipity[preview]'].value='true';" /><br />
                                <input accesskey="s" type="submit" onclick="return checkSave();" value="- <?php 
    echo SAVE;
    ?>
 -" class="serendipityPrettyButton input_button" style="width: 150px" />
                            </td>
                        </tr>
                    </table>
                    <br />
                </td>
            </tr>

            <tr>
                <td colspan="2">
<?php 
    if (!$serendipity['wysiwyg']) {
        ?>
                    <a style="border:0; text-decoration: none" href="#" onclick="toggle_extended(true); return false;" title="<?php 
        echo TOGGLE_OPTION;
        ?>
"><img src="<?php 
        echo serendipity_getTemplateFile('img/plus.png');
        ?>
" id="option_extended" alt="+/-" border="0" /></a>
<?php 
    }
    ?>
 <b><?php 
    echo EXTENDED_BODY;
    ?>
</b></td>
                <td align="right">
                <?php 
    if (!$serendipity['wysiwyg']) {
        ?>
                    <div id="tools_extended" style="display: none">
<?php 
        /* Since the user has WYSIWYG editor disabled, we want to check if we should use the "better" non-WYSIWYG editor */
        if (preg_match($serendipity['EditorBrowsers'], $_SERVER['HTTP_USER_AGENT'])) {
            ?>
                        <input type="button" class="serendipityPrettyButton input_button" name="insI" value="I" accesskey="i" style="font-style: italic" onclick="wrapSelection(document.forms['serendipityEntry']['serendipity[extended]'],'<em>','</em>')" />
                        <input type="button" class="serendipityPrettyButton input_button" name="insB" value="B" accesskey="b" style="font-weight: bold" onclick="wrapSelection(document.forms['serendipityEntry']['serendipity[extended]'],'<strong>','</strong>')" />
                        <input type="button" class="serendipityPrettyButton input_button" name="insU" value="U" accesskey="u" style="text-decoration: underline;" onclick="wrapSelection(document.forms['serendipityEntry']['serendipity[extended]'],'<u>','</u>')" />
                        <input type="button" class="serendipityPrettyButton input_button" name="insQ" value="<?php 
            echo QUOTE;
            ?>
" accesskey="q" style="font-style: italic" onclick="wrapSelection(document.forms['serendipityEntry']['serendipity[extended]'],'<blockquote>','</blockquote>')" />
                        <input type="button" class="serendipityPrettyButton input_button" name="insJ" value="img" accesskey="j" onclick="wrapInsImage(document.forms['serendipityEntry']['serendipity[extended]'])" />
                        <input type="button" class="serendipityPrettyButton input_button" name="insImage" value="<?php 
            echo MEDIA;
            ?>
" onclick="window.open('serendipity_admin_image_selector.php?serendipity[textarea]=extended', 'ImageSel', 'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1');" />
                        <input type="button" class="serendipityPrettyButton input_button" name="insURL" value="URL" accesskey="l" onclick="wrapSelectionWithLink(document.forms['serendipityEntry']['serendipity[extended]'])" />
<?php 
            /* Do the "old" non-WYSIWYG editor */
        } else {
            ?>
                        <input type="button" class="serendipityPrettyButton input_button" value=" B " onclick="serendipity_insBasic(document.forms['serendipityEntry']['serendipity[extended]'], 'b')">
                        <input type="button" class="serendipityPrettyButton input_button" value=" U " onclick="serendipity_insBasic(document.forms['serendipityEntry']['serendipity[extended]'], 'u')">
                        <input type="button" class="serendipityPrettyButton input_button" value=" I " onclick="serendipity_insBasic(document.forms['serendipityEntry']['serendipity[extended]'], 'i')">
                        <input type="button" class="serendipityPrettyButton input_button" value="<img>" onclick="serendipity_insImage(document.forms['serendipityEntry']['serendipity[extended]'])">
                        <input type="button" class="serendipityPrettyButton input_button" value="<?php 
            echo MEDIA;
            ?>
" onclick="window.open('serendipity_admin_image_selector.php?serendipity[textarea]=extended', 'ImageSel', 'width=800,height=600,toolbar=no');">
                        <input type="button" class="serendipityPrettyButton input_button" value="Link" onclick="serendipity_insLink(document.forms['serendipityEntry']['serendipity[extended]'])">
<?php 
        }
        serendipity_plugin_api::hook_event('backend_entry_toolbar_extended', $entry);
        ?>
                    </div>
<?php 
    } else {
        serendipity_plugin_api::hook_event('backend_entry_toolbar_extended', $entry);
    }
    ?>
               </td>
            </tr>

            <tr>
                <td colspan="3">
                    <textarea style="width: 100%;" name="serendipity[extended]" id="serendipity[extended]" cols="80" rows="20"><?php 
    echo isset($entry['extended']) ? htmlspecialchars($entry['extended']) : '';
    ?>
</textarea>
<?php 
    if (!$serendipity['wysiwyg']) {
        ?>
                    <script type="text/javascript" language="JavaScript">
                       toggle_extended();
                    </script>
<?php 
    }
    ?>
                </td>
            </tr>

            <tr>
                <td colspan="3">
                    <br />
                    <fieldset>
                        <legend><b><?php 
    echo ADVANCED_OPTIONS;
    ?>
</b></legend>
<?php 
    serendipity_plugin_api::hook_event('backend_display', $entry);
    ?>
                    </fieldset>
                </td>
            </tr>
        </table>
    </form>
<?php 
    if ((!empty($entry['extended']) || !empty($serendipity['COOKIE']['toggle_extended'])) && !$serendipity['wysiwyg']) {
        ?>
    <script type="text/javascript" language="JavaScript">
        toggle_extended();
    </script>
<?php 
    }
    if ($serendipity['wysiwyg']) {
        $fields = array('body' => 'serendipity[body]', 'extended' => 'serendipity[extended]');
        foreach ($fields as $f_jsname => $f_item) {
            serendipity_emit_htmlarea_code($f_item, $f_jsname);
        }
        serendipity_plugin_api::hook_event('backend_wysiwyg_finish', $fields);
    }
    echo '    <script type="text/javascript" language="JavaScript" src="serendipity_define.js.php"></script>';
    echo '    <script type="text/javascript" language="JavaScript" src="serendipity_editor.js"></script>';
}
/**
 * Prints the content of the iframe.
 *
 * Called by serendipity_is_iframe, when preview is requested. Fetches data from session.
 * An iframe is used so that a single s9y page must not timeout on intensive operations,
 * and so that the frontend stylesheet can be embedded without screwing up the backend.
 *
 * @access private
 * @see serendipity_is_iframe()
 * @param   mixed   The entry array (comes from session variable)
 * @param   string  Indicates whether an entry is previewed or saved. Save performs XML-RPC calls.
 * @param   boolean Use smarty templating?
 * @return  boolean Indicates whether iframe data was printed
 */
function serendipity_iframe(&$entry, $mode = null, $use_smarty = true)
{
    global $serendipity;
    if (empty($mode) || !is_array($entry)) {
        return false;
    }
    if (!serendipity_checkFormToken()) {
        return false;
    }
    if ($use_smarty) {
        $serendipity['smarty_raw_mode'] = true;
        // Force output of Smarty stuff in the backend
        $serendipity['smarty_preview'] = true;
        serendipity_smarty_init();
        $serendipity['smarty']->assign('is_preview', true);
        ob_start();
    }
    $show = 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>';
                }
                $entrylink = serendipity_archiveURL($res, $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp']));
                echo '<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . ENTRY_SAVED . ' (<a href="' . $entrylink . '" target="_blank">' . VIEW . '</a>)</div>';
            }
            echo '<br style="clear: both" />';
            $show = true;
            break;
        case 'preview':
            echo '<div id="serendipity_preview_spacer" style="float: left; height: 225px"></div>';
            serendipity_printEntries(array($entry), $entry['extended'] != '' ? 1 : 0, true);
            echo '<br id="serendipity_preview_spacer2" style="clear: both" />';
            $show = true;
            break;
    }
    if ($use_smarty) {
        $preview = ob_get_contents();
        ob_end_clean();
        $serendipity['smarty']->assign_by_ref('preview', $preview);
        $serendipity['smarty']->display(serendipity_getTemplateFile('preview_iframe.tpl', 'serendipityPath'));
    }
    return $show;
}
/**
 * Prints a media item
 *
 * @param  array    Array of image metadata
 * @param  string   URL for maintenance tasks
 * @param  boolean  Whether to show maintenance task items
 * @param  int      how many media items to display per row
 * @param  boolean  Enclose within a table cell?
 * @param  array    Additional Smarty variables
 * @param  boolean  If TRUE, will echo Smarty output.
 * @return string   Smarty block name
 *
 */
function serendipity_showMedia(&$file, &$paths, $url = '', $manage = false, $lineBreak = 3, $enclose = true, $smarty_vars = array(), $smarty_display = true)
{
    global $serendipity;
    $form_hidden = '';
    foreach ($serendipity['GET'] as $g_key => $g_val) {
        if (!is_array($g_val) && $g_key != 'page') {
            $form_hidden .= '<input type="hidden" name="serendipity[' . $g_key . ']" value="' . htmlspecialchars($g_val) . '" />';
        }
    }
    serendipity_smarty_init();
    $media = array('manage' => $manage, 'lineBreak' => $lineBreak, 'lineBreakP' => round(1 / $lineBreak * 100), 'url' => $url, 'enclose' => $enclose, 'zoomIMG' => serendipity_getTemplateFile('admin/img/big_zoom.png'), 'renameIMG' => serendipity_getTemplateFile('admin/img/big_rename.png'), 'resizeIMG' => serendipity_getTemplateFile('admin/img/big_resize.png'), 'rotatecwIMG' => serendipity_getTemplateFile('admin/img/big_rotate_cw.png'), 'rotateccwIMG' => serendipity_getTemplateFile('admin/img/big_rotate_ccw.png'), 'configureIMG' => serendipity_getTemplateFile('admin/img/configure.png'), 'deleteIMG' => serendipity_getTemplateFile('admin/img/big_delete.png'), 'prevIMG' => serendipity_getTemplateFile('admin/img/previous.png'), 'nextIMG' => serendipity_getTemplateFile('admin/img/next.png'), 'token' => serendipity_setFormToken(), 'form_hidden' => $form_hidden, 'blimit_path' => basename($limit_path), 'only_path' => $serendipity['GET']['only_path'], 'only_filename' => $serendipity['GET']['only_filename'], 'sortorder' => $serendipity['GET']['sortorder'], 'keywords_selected' => $serendipity['GET']['keywords'], 'filter' => $serendipity['GET']['filter'], 'sort_order' => serendipity_getImageFields(), 'authors' => serendipity_fetchUsers(), 'sort_row_interval' => array(8, 16, 50, 100), 'nr_files' => count($file), 'keywords' => explode(';', $serendipity['mediaKeywords']));
    $media = array_merge($media, $smarty_vars);
    $media['files'] =& $file;
    if (count($paths) > 0) {
        $media['paths'] =& $paths;
    } else {
        $media['paths'] =& serendipity_getMediaPaths();
    }
    $serendipity['smarty']->assign_by_ref('media', $media);
    if ($enclose) {
        serendipity_smarty_fetch('MEDIA_ITEMS', 'admin/media_items.tpl');
        $block = 'admin/media_pane.tpl';
        if ($smarty_display) {
            $serendipity['smarty']->display(serendipity_getTemplateFile('admin/media_pane.tpl', 'serendipityPath'));
        }
    } else {
        serendipity_smarty_fetch('MEDIA_ITEMS', 'admin/media_items.tpl');
        $block = 'admin/media_properties.tpl';
        if ($smarty_display) {
            $serendipity['smarty']->display(serendipity_getTemplateFile('admin/media_properties.tpl', 'serendipityPath'));
        }
    }
    return $block;
}
    function event_hook($event, &$bag, &$eventData, $addData = null)
    {
        global $serendipity;
        $hooks =& $bag->get('event_hooks');
        if (isset($hooks[$event])) {
            switch ($event) {
                case 'backend_delete_entry':
                    $this->deleteTagsForEntry((int) $eventData);
                    return true;
                case 'frontend_header':
                    if (serendipity_db_bool($this->get_config('use_flash'))) {
                        echo '<script type="text/javascript" src="';
                        echo $serendipity['serendipityHTTPPath'];
                        echo 'plugins/serendipity_event_freetag/swfobject.js"></script>' . "\n";
                        echo '<script type="text/javascript">' . "\n";
                        echo 'swfobject.registerObject("tagcloud", "9.0.0", "expressInstall.swf");' . "\n";
                        echo '</script>' . "\n";
                    }
                    $this->displayMetaKeywords($serendipity['GET']['id'], $this->displayTag);
                    return true;
                case 'frontend_display:rss-2.0:per_entry':
                case 'frontend_display:rss-0.91:per_entry':
                    $eventData['display_dat'] .= $this->getFeedXmlForTags('category', $eventData['properties']['freetag_tags']);
                    return true;
                case 'frontend_display:rss-1.0:per_entry':
                case 'frontend_display:rss-0.91:per_entry':
                case 'frontend_display:atom-0.3:per_entry':
                case 'frontend_display:atom-1.0:per_entry':
                    $eventData['display_dat'] .= $this->getFeedXmlForTags('dc:subject', $eventData['properties']['freetag_tags']);
                    return true;
                case 'external_plugin':
                    $uri_parts = explode('?', str_replace(array('&amp;', '%FF'), array('&', '.'), $eventData));
                    $taglist = serendipity_db_bool($this->get_config('taglist', false));
                    $param = $taglist ? explode('/', str_replace('/taglist', '', $uri_parts[0])) : explode('/', $uri_parts[0]);
                    $plugincode = array_shift($param);
                    $tagged_as_list = false;
                    // By option or manually added blogdomain.com/plugin/taglist/Serendipity/Blog/Plums - see below
                    if ($plugincode == "taglist") {
                        $plugincode = "tags";
                    }
                    if ($plugincode == "tag" || $plugincode == "tags" || $plugincode == "freetag") {
                        // Manually added (last) parameter 'taglist" to view tags by list for certain taglinks eg. blogdomain.com/plugin/tag/Serendipity/Blog/Plums/taglist - both need a modified entries.tpl
                        if ($taglist && in_array('taglist', $serendipity['uriArguments'])) {
                            $param = array_map('urldecode', $param);
                            $param = array_map('urldecode', $param);
                            // for doubled encoded tag umlauts via searchengines backlinks
                            $param = is_array($param) ? array_map('strip_tags', $param) : strip_tags($param);
                            $param = array_filter($param);
                            // empty removed XSS by strip_tags
                            if (!is_object($serendipity['smarty'])) {
                                serendipity_smarty_init();
                                // to avoid member function assign() on a non-object error, start Smarty templating
                            }
                            if (false === serendipity_db_bool($this->get_config('show_tagcloud', true))) {
                                // Since this is extra stuff, we need to regular assign the subtitle header and not use $serendipity['head_subtitle'] !
                                if (count($param) > 1) {
                                    if (function_exists('serendipity_specialchars')) {
                                        $serendipity['smarty']->assign('head_subtitle', sprintf(PLUGIN_EVENT_FREETAG_USING, implode(' + ', array_map('serendipity_specialchars', $param))));
                                    } else {
                                        $serendipity['smarty']->assign('head_subtitle', sprintf(PLUGIN_EVENT_FREETAG_USING, implode(' + ', array_map('htmlspecialchars', $param))));
                                    }
                                } else {
                                    $serendipity['smarty']->assign('head_subtitle', sprintf(PLUGIN_EVENT_FREETAG_USING, function_exists('serendipity_specialchars') ? serendipity_specialchars($param[0]) : htmlspecialchars($param[0], ENT_COMPAT, LANG_CHARSET)));
                                }
                            }
                            $serendipity['smarty']->assign('taglist', true);
                            foreach ($serendipity['uriArguments'] as $uak => $uav) {
                                if ($uav == 'taglist') {
                                    unset($serendipity['uriArguments'][$uak]);
                                }
                            }
                            $tagged_as_list = true;
                        }
                        /* Attempt to locate hidden variables within the URI */
                        foreach ($serendipity['uriArguments'] as $k => $v) {
                            if ($v[0] == 'P') {
                                /* Page */
                                $page = substr($v, 1);
                                if (is_numeric($page)) {
                                    $serendipity['GET']['page'] = $page;
                                    unset($serendipity['uriArguments'][$k]);
                                    if ($param[count($param) - 1] == "P{$page}.html") {
                                        array_pop($param);
                                        // knock it off of the param array as well
                                    }
                                }
                            }
                        }
                        if (count($param) == 0 || empty($param[0])) {
                            $serendipity['head_subtitle'] = PLUGIN_EVENT_FREETAG_ALLTAGS;
                            $this->displayTag = true;
                            $param = null;
                        } else {
                            if (count($param) == 1) {
                                $param = urldecode($param[0]);
                                $param = urldecode($param);
                                // for doubled encoded tag umlauts via searchengines backlinks
                                $param = strip_tags($param);
                                $serendipity['head_subtitle'] = sprintf(PLUGIN_EVENT_FREETAG_USING, function_exists('serendipity_specialchars') ? serendipity_specialchars($param) : htmlspecialchars($param, ENT_COMPAT, LANG_CHARSET));
                                $emit_404 = true;
                            } else {
                                if (!$tagged_as_list) {
                                    $param = array_map('urldecode', $param);
                                    $param = array_map('urldecode', $param);
                                    // for doubled encoded tag umlauts via searchengines backlinks in sprintf
                                }
                                $param = array_map('strip_tags', $param);
                                $param = array_filter($param);
                                // empty removed XSS by strip_tags
                                if (function_exists('serendipity_specialchars')) {
                                    $serendipity['head_subtitle'] = sprintf(PLUGIN_EVENT_FREETAG_USING, implode(' + ', array_map('serendipity_specialchars', $param)));
                                } else {
                                    $serendipity['head_subtitle'] = sprintf(PLUGIN_EVENT_FREETAG_USING, implode(' + ', array_map('htmlspecialchars', $param)));
                                }
                                $emit_404 = true;
                            }
                        }
                        // for XSS secureness, while using doubled decode
                        $param = is_array($param) ? array_map('strip_tags', $param) : strip_tags($param);
                        if (is_array($param)) {
                            array_filter($param);
                            // empty removed XSS by strip_tags
                        }
                        if (function_exists('serendipity_specialchars')) {
                            $param = is_array($param) ? array_map('serendipity_specialchars', $param) : serendipity_specialchars($param);
                        } else {
                            $param = is_array($param) ? array_map('htmlspecialchars', $param) : htmlspecialchars($param, ENT_COMPAT, LANG_CHARSET);
                        }
                        $this->tags['show'] = $param;
                        $serendipity['plugin_vars']['tag'] = $param;
                        if (is_array($param)) {
                            @define('PLUGIN_VARS_TAG', implode(',', $param));
                        } else {
                            @define('PLUGIN_VARS_TAG', $param);
                        }
                        $serendipity['GET']['subpage'] = $eventData;
                        unset($serendipity['GET']['category']);
                        // No restriction should be enforced here.
                        include_once S9Y_INCLUDE_PATH . 'include/genpage.inc.php';
                        if ($emit_404 && $this->TaggedEntries !== null && $this->TaggedEntries < 1) {
                            @header('HTTP/1.0 404 Not found');
                            @header('Status: 404 Not found');
                            if (serendipity_db_bool($this->get_config('send_http_header', true))) {
                                @header('X-FreeTag: not found');
                            }
                        } else {
                            if (serendipity_db_bool($this->get_config('send_http_header', true))) {
                                @header('X-FreeTag: ' . $this->TaggedEntries);
                            }
                        }
                        $raw_data = ob_get_contents();
                        ob_end_clean();
                        $serendipity['smarty']->assign('raw_data', $raw_data);
                        serendipity_gzCompression();
                        $serendipity['smarty']->display(serendipity_getTemplateFile($serendipity['smarty_file'], 'serendipityPath'));
                        @define('NO_EXIT', true);
                    }
                    break;
                case 'backend_sidebar_entries':
                    if ($serendipity['version'][0] < 2) {
                        ?>
                            <li class="serendipitySideBarMenuLink serendipitySideBarMenuEntryLinks"><a href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=managetags"><?php 
                        echo PLUGIN_EVENT_FREETAG_MANAGETAGS;
                        ?>
</a></li>
<?php 
                    } else {
                        ?>
                            <li><a href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=managetags"><?php 
                        echo PLUGIN_EVENT_FREETAG_MANAGETAGS;
                        ?>
</a></li>
<?php 
                    }
                    return true;
                    break;
                case 'backend_sidebar_entries_event_display_managetags':
                    $this->eventData = $eventData;
                    $this->displayManageTags($event, $bag, $eventData, $addData);
                    return true;
                    break;
                case 'backend_publish':
                case 'backend_save':
                    if (function_exists('mb_internal_encoding')) {
                        mb_internal_encoding(LANG_CHARSET);
                    }
                    if (!isset($eventData['id'])) {
                        return true;
                    }
                    $to_lower = serendipity_db_bool($this->get_config('lowercase_tags'));
                    $keylist = serendipity_db_query("SELECT tag, keywords FROM {$serendipity['dbPrefix']}tagkeywords", false, 'assoc');
                    $automatted = array(array());
                    if (is_array($keylist)) {
                        foreach ($keylist as $key) {
                            $keywords = explode(',', $key['keywords']);
                            foreach ($keywords as $keyword) {
                                $automatted[trim($keyword)][$key['tag']] = true;
                            }
                        }
                    }
                    // When this variable is not set, the entry might be saved i.e. by recreating cache or automatted trackback.
                    // Do not loose such tags. :)
                    if (!isset($serendipity['POST']['properties']['freetag_tagList'])) {
                        $serendipity['POST']['properties']['freetag_tagList'] = implode(',', $this->getTagsForEntry($eventData['id']));
                    }
                    $tags = $this->makeTagsFromTagList($serendipity['POST']['properties']['freetag_tagList']);
                    if (serendipity_db_bool($this->get_config('keyword2tag'))) {
                        $searchtext = strip_tags($eventData['body'] . $eventData['extended']);
                        foreach ($automatted as $keyword => $ktags) {
                            $keyword = trim($keyword);
                            if (empty($keyword)) {
                                continue;
                            }
                            if (!is_array($ktags) || count($ktags) < 1) {
                                continue;
                            }
                            $regex = sprintf("/((\\s+|[\\(\\[-]+)%s([-\\/,\\.\\?!'\";\\)\\]]*+|[\\/-]+))/i", $keyword);
                            if (preg_match($regex, $searchtext) > 0) {
                                foreach ($ktags as $tag => $is_assigned) {
                                    if (!is_array($tags) || !in_array(strtolower($tag), $tags) && !in_array($tag, $tags)) {
                                        if ($to_lower) {
                                            if (function_exists("mb_strtolower")) {
                                                $tag = mb_strtolower($tag);
                                            } else {
                                                $tag = strtolower($tag);
                                            }
                                        }
                                        $tags[] = $tag;
                                        printf(PLUGIN_EVENT_FREETAG_KEYWORDS_ADD, function_exists('serendipity_specialchars') ? serendipity_specialchars($keyword) : htmlspecialchars($keyword, ENT_COMPAT, LANG_CHARSET), function_exists('serendipity_specialchars') ? serendipity_specialchars($tag) : htmlspecialchars($tag, ENT_COMPAT, LANG_CHARSET));
                                    }
                                }
                            }
                        }
                    }
                    if (empty($tags)) {
                        $tags = array();
                    }
                    if (serendipity_db_bool($this->get_config('cat2tag'))) {
                        if (is_array($cats = serendipity_fetchCategories())) {
                            $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
                            foreach ($cats as $cat) {
                                if ($to_lower) {
                                    if (function_exists("mb_strtolower")) {
                                        $cat['category_name'] = mb_strtolower($cat['category_name']);
                                    } else {
                                        $cat['category_name'] = strtolower($cat['category_name']);
                                    }
                                }
                                $names = explode(',', $cat['category_name']);
                                foreach ($names as $name) {
                                    $name = trim($name);
                                    if (is_array($eventData['categories']) && in_array($cat['categoryid'], $eventData['categories']) && !in_array($name, $tags)) {
                                        $tags[] = $name;
                                    }
                                }
                            }
                        }
                    }
                    $serendipity['POST']['properties']['freetag_tagList'] = implode(',', $tags);
                    $this->deleteTagsForEntry($eventData['id']);
                    $this->addTagsToEntry($eventData['id'], $tags);
                    if ($serendipity['POST']['properties']['freetag_kill']) {
                        $this->deleteTagsForEntry($eventData['id']);
                    }
                    return true;
                    break;
                case 'css_backend':
                    if ($serendipity['version'][0] > 1) {
                        ?>

.freetagMenu li {
    display: block;
    margin: 0 0 .5em;
}

.freetags_manage {
    border: 1px solid #aaa;
    border-bottom: 0 none;
    width: 100%;
}

.freetags_manage thead tr {
    background-color: #eee;
}

.freetags_manage tr {
    border-bottom: 1px solid #aaa;
}

.freetags_manage th,
.freetags_manage td {
    padding: .125em .25em;
}

.freetags_list li {
    margin: 0 0 .25em;
}

@media only screen and (min-width: 768px) {
    .freetagMenu li {
        display: inline-block;
        margin: 0 .25em .5em 0;
    }
}

<?php 
                    }
                    return true;
                    break;
                case 'js_backend':
                    // autocomplete with serendipity 2.0
                    if ($this->get_config('admin_ftayt')) {
                        echo '
function enableAutocomplete() {
    if (typeof(tags) != "undefined") {
        $("#properties_freetag_tagList").autocomplete(tags, {
            minChars: 0,
            multiple: true,
            scrollHeight: 200,
            matchContains: "word",
            autoFill: false
        });
    }
};

addLoadEvent(enableAutocomplete);

';
                    }
                    break;
                case 'backend_display':
                    if (function_exists('mb_internal_encoding')) {
                        mb_internal_encoding(LANG_CHARSET);
                    }
                    if (!empty($serendipity['POST']['properties']['freetag_tagList'])) {
                        $tagList = $serendipity['POST']['properties']['freetag_tagList'];
                    } else {
                        if (isset($eventData['id'])) {
                            $tagList = implode(',', $this->getTagsForEntry($eventData['id']));
                        } else {
                            $tagList = '';
                        }
                    }
                    if (serendipity_db_bool($this->get_config('lowercase_tags', true))) {
                        if (function_exists("mb_strtolower")) {
                            $tagList = mb_strtolower($tagList);
                        } else {
                            $tagList = strtolower($tagList);
                        }
                    }
                    $freetags = $this->makeTagsFromTagList($tagList);
                    if (!empty($freetags)) {
                        $tagList = implode(',', $freetags);
                    }
                    $taglist = (array) $this->getAllTags();
                    if ($this->get_config('admin_ftayt')) {
                        foreach ($taglist as $k => $v) {
                            $wicktags[] = '\'' . addslashes($k) . '\'';
                        }
                        // jQuery Migrate is used due to $.browser of autocomplete plugin not being available in jquery 1.9+
                        echo '
                        ' . ($serendipity['version'][0] < 2 ? '<script src="' . $serendipity['baseURL'] . 'plugins/serendipity_event_freetag/jquery-1.11.1.min.js" type="text/javascript"></script>' : '') . '
                        <link rel="stylesheet" type="text/css" href="' . $serendipity['baseURL'] . 'plugins/serendipity_event_freetag/jquery.autocomplete.css" />
                        <script src="' . $serendipity['baseURL'] . 'plugins/serendipity_event_freetag/jquery-migrate-1.2.1.min.js"></script>
                        <script type="text/javascript" src="' . $serendipity['baseURL'] . 'plugins/serendipity_event_freetag/jquery.autocomplete.min.js"></script>
                        <script type="text/javascript">
                        var tags = [' . implode(',', $wicktags) . '];
                         ' . ($serendipity['version'][0] < 2 ? '
                        function enableAutocomplete() {
                            $("#properties_freetag_tagList").autocomplete(tags, {
                                        minChars: 0,
                                        multiple: true,
                                        scrollHeight: 200,
                                        matchContains: "word",
                                        autoFill: false
                                    })};
                            addLoadEvent(enableAutocomplete);
                         ' : '') . '
                        </script>';
                    }
                    if ($this->get_config('admin_show_taglist')) {
                        ?>
                        <script type="text/javascript">
                        function addTag(addTag)
                        {
                            var freetags = document.getElementById("properties_freetag_tagList").value.split(',');

                            inList = false;
                            for (var freetag = 0; freetag < freetags.length; freetag++) {
                                if (freetags[freetag] && trim(freetags[freetag].toLowerCase()) == addTag.toLowerCase()) {
                                    inList = true;
                                }
                            }

                            if (!inList) {
                                if (document.getElementById("properties_freetag_tagList").value.lastIndexOf(',') == (document.getElementById("properties_freetag_tagList").value.length-1)) {
                                    sepChar = '';
                                } else {
                                    sepChar = ',';
                                }

                                document.getElementById("properties_freetag_tagList").value = document.getElementById("properties_freetag_tagList").value + sepChar + addTag;
                            }
                        }

                        function trim(str)
                        {
                            if (str) return str.replace(/^\s*|\s*$/g,"");
                             else return '';
                        }
                        </script>
<?php 
                    }
                    if ($serendipity['version'][0] < 2) {
                        ?>
                        <fieldset style="margin: 5px">
                            <legend><?php 
                        echo PLUGIN_EVENT_FREETAG_TITLE;
                        ?>
</legend>
                            <label for="serendipity[properties][freetag_tagList]" title="<?php 
                        echo PLUGIN_EVENT_FREETAG_TITLE;
                        ?>
"><?php 
                        echo PLUGIN_EVENT_FREETAG_ENTERDESC;
                        ?>
:</label><br/>
                            <input type="text" name="serendipity[properties][freetag_tagList]" id="properties_freetag_tagList" class="wickEnabled input_textbox" value="<?php 
                        echo function_exists('serendipity_specialchars') ? serendipity_specialchars($tagList) : htmlspecialchars($tagList, ENT_COMPAT, LANG_CHARSET);
                        ?>
" style="width: 100%" />

                            <input type="checkbox" name="serendipity[properties][freetag_kill]" id="properties_freetag_kill" class="input_checkbox" />
                            <label for="serendipity[properties][freetag_kill]" title="<?php 
                        echo PLUGIN_EVENT_FREETAG_KILL;
                        ?>
"><?php 
                        echo PLUGIN_EVENT_FREETAG_KILL;
                        ?>
</label><br/>
<?php 
                        if ($this->get_config('admin_show_taglist')) {
                            ?>
                            <a name="tagListAnchor"></a>
                            <div id="backend_freetag_list" style="margin: 5px; border: 1px dotted #000; padding: 5px; font-size: 9px;">
<?php 
                        }
                    } else {
                        ?>
                        <fieldset id="edit_entry_freetags" class="entryproperties_freetag">
                            <span class="wrap_legend"><legend><?php 
                        echo PLUGIN_EVENT_FREETAG_TITLE;
                        ?>
</legend></span>
                            <div class="form_field">
                                <label for="properties_freetag_tagList" class="block_level"><?php 
                        echo PLUGIN_EVENT_FREETAG_ENTERDESC;
                        ?>
:</label>
                                <input id="properties_freetag_tagList" type="text" name="serendipity[properties][freetag_tagList]" class="wickEnabled" value="<?php 
                        echo function_exists('serendipity_specialchars') ? serendipity_specialchars($tagList) : htmlspecialchars($tagList, ENT_COMPAT, LANG_CHARSET);
                        ?>
">
                            </div>
                            <div class="form_check">
                                <input id="properties_freetag_kill" type="checkbox" name="serendipity[properties][freetag_kill]">
                                <label for="properties_freetag_kill"><?php 
                        echo PLUGIN_EVENT_FREETAG_KILL;
                        ?>
</label>
                            </div>
<?php 
                        if ($this->get_config('admin_show_taglist')) {
                            ?>
                            <a name="tagListAnchor"></a>
                            <div id="backend_freetag_list">
<?php 
                        }
                    }
                    if ($this->get_config('admin_show_taglist')) {
                        $lastletter = '';
                        foreach ($taglist as $tag => $count) {
                            if (function_exists('mb_strtoupper')) {
                                $upc = mb_strtoupper(mb_substr($tag, 0, 1, LANG_CHARSET), LANG_CHARSET);
                            } else {
                                $upc = strtoupper(substr($tag, 0, 1));
                            }
                            if ($upc != $lastletter) {
                                if ($serendipity['version'][0] < 2) {
                                    echo " <b>|" . $upc . ':</b> ';
                                }
                            }
                            if ($serendipity['version'][0] < 2) {
                                echo "<a href=\"#tagListAnchor\" style=\"text-decoration: none\" onClick=\"addTag('{$tag}')\">{$tag}</a>, ";
                            } else {
                                echo "<a href=\"#tagListAnchor\" onClick=\"addTag('{$tag}')\">{$tag}</a> ";
                            }
                            $lastletter = $upc;
                        }
                        echo "</div>";
                    }
                    ?>
                        </fieldset>
<?php 
                    return true;
                    break;
                case 'frontend_entryproperties':
                    $this->importEntryTagsIntoProperties($eventData, $addData);
                    return true;
                    break;
                case 'frontend_fetchentries':
                case 'frontend_fetchentry':
                    if (!empty($this->tags['show'])) {
                        if (is_array($this->tags['show'])) {
                            $showtag = array_map('serendipity_db_escape_string', $this->tags['show']);
                        } else {
                            $showtag = serendipity_db_escape_string($this->tags['show']);
                        }
                    } else {
                        if (!empty($serendipity['GET']['tag'])) {
                            $showtag = serendipity_db_escape_string(urldecode($serendipity['GET']['tag']));
                        }
                    }
                    if (is_array($showtag)) {
                        $arr_showtag = $showtag;
                    } else {
                        $arr_showtag = explode(';', $showtag);
                    }
                    $multimode = 'and';
                    if (count($arr_showtag) > 1) {
                        $showtag = $arr_showtag;
                        $multimode = 'or';
                    }
                    if (!empty($show_tag) && is_string($show_tag) && serendipity_db_bool($this->get_config('lowercase_tags', true))) {
                        if (function_exists("mb_strtolower")) {
                            if (function_exists('mb_internal_encoding')) {
                                mb_internal_encoding(LANG_CHARSET);
                            }
                            $showtag = mb_strtolower($showtag);
                        } else {
                            $showtag = strtolower($showtag);
                        }
                    }
                    $coll_target = $this->get_config('collation', '');
                    if (empty($coll_target) && stristr($serendipity['dbType'], 'mysql')) {
                        $cd = serendipity_db_query("SHOW FULL COLUMNS FROM {$serendipity['dbPrefix']}entrytags LIKE 'tag'");
                        if (!empty($cd[0]['Collation'])) {
                            $coll_target = $cd[0]['Collation'];
                            $this->set_config('collation', $coll_target);
                        }
                    }
                    if (!empty($showtag)) {
                        if (LANG_CHARSET == 'UTF-8' && stristr($serendipity['dbType'], 'mysql') && !stristr($coll_target, 'utf8')) {
                            $collate = "COLLATE utf8_general_ci";
                            $collateP = '_utf8 ';
                        } else {
                            $collate = $collateP = "";
                        }
                        $cond = $join = '';
                        if (is_string($showtag)) {
                            $join = "INNER JOIN {$serendipity['dbPrefix']}entrytags AS entrytags ON (e.id = entrytags.entryid) ";
                            $cond = "entrytags.tag = {$collateP} '{$showtag}' {$collate}";
                        } else {
                            if (is_array($showtag)) {
                                $_taglist = array();
                                $cond = '(1=2 ';
                                foreach ($showtag as $_showtag) {
                                    $_taglist[] = serendipity_db_escape_string($_showtag);
                                    $cond .= " OR entrytags.tag = {$collateP} '" . serendipity_db_escape_string($_showtag) . "' {$collate} ";
                                }
                                $cond .= ' ) ';
                                $total = count($showtag);
                                $join = "INNER JOIN {$serendipity['dbPrefix']}entrytags AS entrytags " . "ON e.id = entrytags.entryid ";
                                if ($multimode == 'and') {
                                    $eventData['having'] = " HAVING count(entrytags.tag) = {$total}";
                                }
                            }
                        }
                        if (empty($eventData['and'])) {
                            $eventData['and'] = " WHERE {$cond} ";
                        } else {
                            $eventData['and'] .= " AND {$cond} ";
                        }
                        if (empty($eventData['joins'])) {
                            $eventData['joins'] = $join;
                        } else {
                            $eventData['joins'] .= $join;
                        }
                        $this->displayTag = $showtag;
                        $serendipity['plugin_vars']['displayTag'] = $showtag;
                        @define('PLUGIN_VARS_DISPLAYTAG', $showtag);
                    }
                    return true;
                    break;
                case 'frontend_rss':
                    if (!empty($this->displayTag)) {
                        $eventData['title'] .= serendipity_utf8_encode(function_exists('serendipity_specialchars') ? serendipity_specialchars(' (' . sprintf(PLUGIN_EVENT_FREETAG_USING, $this->displayTag) . ')') : htmlspecialchars(' (' . sprintf(PLUGIN_EVENT_FREETAG_USING, $this->displayTag) . ')', ENT_COMPAT, LANG_CHARSET));
                    }
                    return true;
                    break;
                case 'entries_header':
                    if (isset($eventData['plugin_vars']['tag']) && serendipity_db_bool($this->get_config('show_tagcloud'))) {
                        $this->displayTagCloud($eventData['plugin_vars']['tag']);
                    }
                    return true;
                    break;
                case 'css':
                    if (strpos($eventData, '.serendipity_freeTag')) {
                        // class exists in CSS, so a user has customized it and we don't need default
                        return true;
                    }
                    $this->addToCSS($eventData);
                    return true;
                    break;
                case 'entry_display':
                    // Don't display entries if we are getting a full tag list
                    if (is_array($eventData)) {
                        $this->TaggedEntries = count($eventData);
                        if (serendipity_db_bool($this->get_config('send_http_header', true))) {
                            @header('X-FreeTag-Count: Array');
                        }
                    } else {
                        if (serendipity_db_bool($this->get_config('send_http_header', true))) {
                            @header('X-FreeTag-Count: Empty');
                        }
                        $this->TaggedEntries = 0;
                    }
                    if ($this->displayTag === true) {
                        $eventData['clean_page'] = true;
                        return true;
                    }
                    $this->displayEntry($eventData, $addData);
                    return true;
                    break;
                case 'xmlrpc_updertEntry':
                    if (isset($eventData['id']) && isset($eventData['mt_keywords'])) {
                        //XMLRPC call
                        $tags = $this->makeTagsFromTagList($eventData['mt_keywords']);
                        if (!empty($tags)) {
                            $this->deleteTagsForEntry($eventData['id']);
                            $this->addTagsToEntry($eventData['id'], $tags);
                        }
                    }
                    return true;
                    break;
                case 'xmlrpc_fetchEntry':
                    $eventData['mt_keywords'] = implode(',', $this->getTagsForEntry($eventData['id']));
                    return true;
                    break;
                case 'xmlrpc_deleteEntry':
                    if (isset($eventData["id"])) {
                        $this->deleteTagsForEntry($eventData["id"]);
                    }
                    return true;
                    break;
                default:
                    return false;
                    break;
            }
        } else {
            return false;
        }
    }
    function event_hook($event, &$bag, &$eventData, $addData = null)
    {
        global $serendipity;
        $hooks =& $bag->get('event_hooks');
        if (isset($hooks[$event])) {
            switch ($event) {
                case 'backend_publish':
                case 'backend_save':
                    if (!isset($serendipity['POST']['properties']) || !is_array($serendipity['POST']['properties']) || !isset($eventData['id'])) {
                        return true;
                    }
                    $links = (array) explode("\n", str_replace("\r", '', $serendipity['POST']['properties']['relatedentries']));
                    $html_links = array();
                    foreach ($links as $link) {
                        if (empty($link)) {
                            continue;
                        }
                        $parts = explode($this->get_config('explodechar', '='), $link);
                        if (empty($parts[1])) {
                            $parts[1] = $parts[0];
                        }
                        $html_links[] = array('url' => $parts[0], 'title' => function_exists('serendipity_specialchars') ? serendipity_specialchars($parts[1]) : htmlspecialchars($parts[1], ENT_COMPAT, LANG_CHARSET));
                    }
                    serendipity_smarty_init();
                    $serendipity['smarty']->assign(array('plugin_relatedentries_html_intro' => PLUGIN_EVENT_RELATEDLINKS_LIST, 'plugin_relatedentries_links' => $html_links));
                    $tfile = serendipity_getTemplateFile('plugin_relatedlinks.tpl', 'serendipityPath');
                    if (!$tfile) {
                        $tfile = dirname(__FILE__) . '/plugin_relatedlinks.tpl';
                    }
                    $inclusion = $serendipity['smarty']->security_settings[INCLUDE_ANY];
                    $serendipity['smarty']->security_settings[INCLUDE_ANY] = true;
                    $content = $serendipity['smarty']->fetch('file:' . $tfile);
                    if (count($html_links) < 1) {
                        $content = true;
                    }
                    $serendipity['smarty']->security_settings[INCLUDE_ANY] = $inclusion;
                    if (!empty($content)) {
                        $q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int) $eventData['id'] . " AND (property = 'relatedentries' OR property = 'post_relatedentries')";
                        serendipity_db_query($q);
                        $q = "INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES (" . (int) $eventData['id'] . ", 'relatedentries', '" . serendipity_db_escape_string($content) . "')";
                        serendipity_db_query($q);
                        $q = "INSERT INTO {$serendipity['dbPrefix']}entryproperties (entryid, property, value) VALUES (" . (int) $eventData['id'] . ", 'post_relatedentries', '" . serendipity_db_escape_string($serendipity['POST']['properties']['relatedentries']) . "')";
                        serendipity_db_query($q);
                    }
                    return true;
                    break;
                case 'backend_display':
                    if (isset($serendipity['POST']['properties']['relatedentries'])) {
                        $links = $serendipity['POST']['properties']['relatedentries'];
                    } else {
                        if (isset($eventData['id'])) {
                            $links = $this->getLinks($eventData['id']);
                        } else {
                            $links = '';
                        }
                    }
                    ?>
                    <fieldset style="margin: 5px">
                        <legend><?php 
                    echo PLUGIN_EVENT_RELATEDLINKS_TITLE;
                    ?>
</legend>
                        <label for="serendipity[properties][relatedentries]" title="<?php 
                    echo PLUGIN_EVENT_RELATEDLINKS_TITLE;
                    ?>
">
                            <?php 
                    echo PLUGIN_EVENT_RELATEDLINKS_ENTERDESC;
                    ?>
:</label><br />
                        <textarea name="serendipity[properties][relatedentries]" style="width: 90%; height: 100px" id="properties_relatedentries"><?php 
                    echo function_exists('serendipity_specialchars') ? serendipity_specialchars($links) : htmlspecialchars($links, ENT_COMPAT, LANG_CHARSET);
                    ?>
</textarea>
                    </fieldset>
<?php 
                    return true;
                    break;
                case 'frontend_display:html:per_entry':
                    $this->showRelatedLinks(false, $eventData, $addData);
                    return true;
                    break;
                case 'frontend_display_relatedlinks':
                    $this->showRelatedLinks(true, $eventData, $addData);
                    return true;
                    break;
                default:
                    return false;
                    break;
            }
        } else {
            return false;
        }
    }
/**
 * Prints a media item
 *
 * @param  array    Array of image metadata
 * @param  string   URL for maintenance tasks
 * @param  boolean  Whether to show maintenance task items
 * @param  int      how many media items to display per row
 * @param  boolean  Enclose within a table cell?
 * @param  array    Additional Smarty variables
 * @return string   Generated HTML
 *
 */
function serendipity_showMedia(&$file, &$paths, $url = '', $manage = false, $lineBreak = 3, $enclose = true, $smarty_vars = array())
{
    global $serendipity;
    $form_hidden = '';
    // do not add, if not for the default media list form
    if (($serendipity['GET']['adminAction'] == 'default' || empty($serendipity['GET']['adminAction'])) && !$serendipity['GET']['fid']) {
        foreach ($serendipity['GET'] as $g_key => $g_val) {
            // do not add token, since this is assigned separately to properties and list forms
            if (!is_array($g_val) && $g_key != 'page' && $g_key != 'token') {
                $form_hidden .= '        <input type="hidden" name="serendipity[' . $g_key . ']" value="' . serendipity_specialchars($g_val) . '">' . "\n";
            }
        }
    }
    if (!is_object($serendipity['smarty'])) {
        serendipity_smarty_init();
    }
    $order_fields = serendipity_getImageFields();
    // reset filename for building template filters, since this is hardcoded as 'only_filename'
    unset($order_fields['i.name']);
    $media = array('manage' => $manage, 'multiperm' => serendipity_checkPermission('adminImagesDirectories'), 'lineBreak' => $lineBreak, 'lineBreakP' => round(1 / $lineBreak * 100), 'url' => $url, 'enclose' => $enclose, 'token' => serendipity_setFormToken(), 'form_hidden' => $form_hidden, 'blimit_path' => empty($smarty_vars['limit_path']) ? '' : basename($smarty_vars['limit_path']), 'only_path' => $serendipity['GET']['only_path'], 'only_filename' => $serendipity['GET']['only_filename'], 'sortorder' => $serendipity['GET']['sortorder'], 'keywords_selected' => $serendipity['GET']['keywords'], 'filter' => $serendipity['GET']['filter'], 'sort_order' => $order_fields, 'simpleFilters' => $serendipity['simpleFilters'], 'hideSubdirFiles' => $serendipity['GET']['hideSubdirFiles'], 'authors' => serendipity_fetchUsers(), 'sort_row_interval' => array(8, 16, 50, 100), 'nr_files' => count($file), 'keywords' => explode(';', $serendipity['mediaKeywords']), 'thumbSize' => $serendipity['thumbSize'], 'sortParams' => array('perpage', 'order', 'ordermode'));
    $media = array_merge($media, $smarty_vars);
    $media['files'] =& $file;
    if (count($paths) > 0) {
        $media['paths'] =& $paths;
    } else {
        $media['paths'] =& serendipity_getMediaPaths();
    }
    $serendipity['smarty']->assignByRef('media', $media);
    if ($enclose) {
        serendipity_smarty_fetch('MEDIA_ITEMS', 'admin/media_items.tpl');
        return serendipity_smarty_show('admin/media_pane.tpl');
    } else {
        serendipity_smarty_fetch('MEDIA_ITEMS', 'admin/media_items.tpl');
        return serendipity_smarty_show('admin/media_properties.tpl');
    }
}
    function event_hook($event, &$bag, &$eventData, $addData = null)
    {
        global $serendipity;
        static $markup = null;
        static $isolate = null;
        static $p_tags = null;
        static $isobr = null;
        static $clean_tags = null;
        global $_buf;
        $hooks =& $bag->get('event_hooks');
        if ($markup === null) {
            $markup = serendipity_db_bool($this->get_config('check_markup'));
        }
        if ($p_tags === null) {
            $p_tags = serendipity_db_bool($this->get_config('p_tags'));
        }
        if ($isobr === null) {
            $isobr = serendipity_db_bool($this->get_config('isobr'));
        }
        if ($clean_tags === null) {
            $clean_tags = serendipity_db_bool($this->get_config('clean_tags'));
        }
        if (isset($hooks[$event])) {
            switch ($event) {
                case 'frontend_display':
                    // check single entry for temporary disabled markups
                    if (!$eventData['properties']['ep_disable_markup_' . $this->instance] && (isset($serendipity['POST']['properties']['disable_markups']) && !in_array($this->instance, $serendipity['POST']['properties']['disable_markups'])) && !$eventData['properties']['ep_no_textile'] && !isset($serendipity['POST']['properties']['ep_no_textile']) && !$eventData['properties']['ep_no_markdown'] && !isset($serendipity['POST']['properties']['ep_no_markdown'])) {
                        // yes, this markup shall be applied
                        $serendipity['nl2br']['entry_disabled_markup'] = false;
                    } else {
                        // no, do not apply markup
                        $serendipity['nl2br']['entry_disabled_markup'] = true;
                    }
                    /* PLEASE NOTE:
                        $serendipity['POST']['properties']['disable_markups'] = array(false); is the only workable solution for (sidebar?) plugins (see sidebar plugins: guestbook, multilingual), to explicitly allow to apply nl2br to markup (if we want to)
                    */
                    // don't run, if the textile, or markdown plugin already took care about markup
                    if ($markup && $serendipity['nl2br']['entry_disabled_markup'] === false && (class_exists('serendipity_event_textile') || class_exists('serendipity_event_markdown'))) {
                        return true;
                    }
                    // NOTE: the wysiwyg-editor needs to send its own ['properties']['ep_no_nl2br'] to disable the nl2br() parser!
                    // check for users isolation tags
                    if ($isolate === null) {
                        $isolate = $this->get_config('isolate');
                        $tags = (array) explode(',', $isolate);
                        $isolate = array();
                        foreach ($tags as $tag) {
                            $tag = trim($tag);
                            if (!empty($tag)) {
                                $isolate[] = $tag;
                            }
                        }
                        if (count($isolate) < 1) {
                            $isolate = false;
                        }
                    }
                    foreach ($this->markup_elements as $temp) {
                        if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) && !$eventData['properties']['ep_disable_markup_' . $this->instance] && (isset($serendipity['POST']['properties']['disable_markups']) && !in_array($this->instance, $serendipity['POST']['properties']['disable_markups'])) && !$eventData['properties']['ep_no_nl2br'] && !isset($serendipity['POST']['properties']['ep_no_nl2br'])) {
                            $element = $temp['element'];
                            if ($p_tags) {
                                $eventData[$element] = $this->nl2p($eventData[$element]);
                            } else {
                                if ($isolate) {
                                    $eventData[$element] = $this->isolate($eventData[$element], '~[<\\[](' . implode('|', $isolate) . ').*?[>\\]].*?[<\\[]/\\1[>\\]]~si');
                                    $eventData[$element] = nl2br($eventData[$element]);
                                    $eventData[$element] = $this->restore($eventData[$element]);
                                } else {
                                    if ($isobr) {
                                        $eventData[$element] = $this->isolate($eventData[$element], '~[<\\[](nl).*?[>\\]].*?[<\\[]/\\1[>\\]]~si');
                                        $eventData[$element] = nl2br($eventData[$element]);
                                        $eventData[$element] = $this->restore($eventData[$element]);
                                        // unset nl tagline, if is
                                        $eventData[$element] = str_replace(array("<nl>", "</nl><br />", "</nl><br/>", "</nl>"), "", $eventData[$element]);
                                    } else {
                                        $eventData[$element] = nl2br($eventData[$element]);
                                    }
                                }
                            }
                            /* this is an option if not using new isobr default config setting */
                            if (!$p_tags && $isobr === false && $clean_tags === true) {
                                // convert line endings to Unix style, if not already done
                                $eventData[$element] = str_replace(array("\r\n", "\r"), "\n", $eventData[$element]);
                                // clean special tags from nl2br
                                $eventData[$element] = $this->clean_nl2brtags($eventData[$element]);
                            }
                        }
                    }
                    return true;
                    break;
                case 'backend_configure':
                    // check single entry for temporary disabled markups
                    if ($isobr) {
                        $serendipity['nl2br']['iso2br'] = true;
                        // include to global as also used by staticpages now
                        if (!is_object($serendipity['smarty'])) {
                            serendipity_smarty_init();
                            // if not set to avoid member function assign() on a non-object error, start Smarty templating
                        }
                        // hook into default/admin/entries.tpl somehow via the Heart Of Gold = serendipity_printEntryForm() before! it is loaded
                        $serendipity['smarty']->assign('iso2br', true);
                    }
                    return true;
                    break;
                case 'css':
                    ?>

/* nl2br plugin */
p.whiteline {
    margin-top: 0em;
    margin-bottom: 1em;
}

p.break {
    margin-top: 0em;
    margin-bottom: 0em;
}

<?php 
                    return true;
                    break;
                default:
                    return false;
            }
        } else {
            return false;
        }
    }
/**
 * Purge compiled Smarty Templates
 *
 * @access public
 * @return null
 */
function serendipity_smarty_purge()
{
    global $serendipity;
    /* Attempt to init Smarty, brrr */
    serendipity_smarty_init();
    $files = serendipity_traversePath($serendipity['smarty']->getCompileDir() . DIRECTORY_SEPARATOR, '', false, '/.+\\.tpl\\.php$/');
    if (!is_array($files)) {
        return false;
    }
    foreach ($files as $file) {
        @unlink($serendipity['smarty']->getCompileDir() . DIRECTORY_SEPARATOR . $file['name']);
    }
}