function buildEntry($item, &$entry) { global $serendipity; $bodyonly = serendipity_get_bool($this->data['bodyonly']); if ($item['description']) { $entry['body'] = $this->decode($item['description']); } if ($item['content:encoded']) { if (!isset($entry['body']) || $bodyonly) { $data =& $entry['body']; } else { $data =& $entry['extended']; } // See if the 'description' element is a substring of the 'content:encoded' part. If it is, // we will only fetch the full 'content:encoded' part. If it's not a substring, we append // the 'content:encoded' part to either body or extended entry (respecting the 'bodyonly' // switch). We substract 4 letters because of possible '...' additions to an entry. $testbody = substr(trim(strip_tags($entry['body'])), 0, -4); if ($testbody != substr(trim(strip_tags($item['content:encoded'])), 0, strlen($testbody))) { $data .= $this->decode($item['content:encoded']); } else { $data = $this->decode($item['content:encoded']); } } $entry['title'] = $this->decode($item['title']); if (!isset($item['pubdate']) && isset($item['pubDate'])) { $item['pubdate'] = $item['pubDate']; } $entry['timestamp'] = $this->decode(strtotime(isset($item['pubdate']) ? $item['pubdate'] : $item['dc:date'])); if ($entry['timestamp'] == -1) { // strtotime does not seem to parse ISO 8601 dates if (preg_match('@^([0-9]{4})\\-([0-9]{2})\\-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})[\\-\\+]([0-9]{2}):([0-9]{2})$@', isset($item['pubdate']) ? $item['pubdate'] : $item['dc:date'], $timematch)) { $entry['timestamp'] = mktime($timematch[4] - $timematch[7], $timematch[5] - $timematch[8], $timematch[6], $timematch[2], $timematch[3], $timematch[1]); } else { $entry['timestamp'] = time(); } } if ($this->data['type'] == 'draft') { $entry['isdraft'] = 'true'; } else { $entry['isdraft'] = 'false'; } if (!empty($item['category'])) { $cat = serendipity_fetchCategoryInfo(0, trim($this->decode($item['category']))); if (is_array($cat) && isset($cat['categoryid'])) { $entry['categories'][] = $cat['categoryid']; } } if (!is_array($entry['categories'])) { $entry['categories'][] = $this->data['category']; } if (!isset($entry['extended'])) { $entry['extended'] = ''; } $entry['allow_comments'] = true; return true; }
function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks =& $bag->get('event_hooks'); $links = array(); $article_show = false; if (isset($hooks[$event])) { switch ($event) { case 'frontend_display': if (isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id'])) { $article_show = true; $year = date('Y', serendipity_serverOffsetHour($eventData['timestamp'])); $month = date('m', serendipity_serverOffsetHour($eventData['timestamp'])); } else { break; } case 'entries_footer': if (isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id'])) { $links[] = '<a href="' . $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/articlepdf_' . $serendipity['GET']['id'] . '">' . PLUGIN_EVENT_BLOGPDF_VIEW_ENTRY . '</a>'; } if (isset($serendipity['GET']['category'])) { $cid = explode('_', $serendipity['GET']['category']); if (is_numeric($cid[0])) { $cat = serendipity_fetchCategoryInfo($cid[0]); $links[] = '<a href="' . $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/categorypdf_' . $cid[0] . '">' . sprintf(PLUGIN_EVENT_BLOGPDF_VIEW_CATEGORY, $cat['category_name']) . '</a>'; } } if (empty($year) && empty($month) && isset($serendipity['GET']['range']) && is_numeric($serendipity['GET']['range'])) { $year = substr($serendipity['GET']['range'], 0, 4); $month = substr($serendipity['GET']['range'], 4, 2); } if (empty($year)) { $year = date('Y', serendipity_serverOffsetHour()); } if (empty($month)) { $month = date('m', serendipity_serverOffsetHour()); } $links[] = '<a href="' . $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/monthpdf_' . $year . $month . '">' . PLUGIN_EVENT_BLOGPDF_VIEW_MONTH . '</a>'; $links[] = '<a href="' . $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/blogpdf">' . PLUGIN_EVENT_BLOGPDF_VIEW_FULL . '</a>'; if ($article_show) { $eventData['add_footer'] .= '<div class="serendipity_blogpdf">' . PLUGIN_EVENT_BLOGPDF_VIEW . implode(' | ', $links) . '</div>'; } else { echo '<div class="serendipity_blogpdf">' . PLUGIN_EVENT_BLOGPDF_VIEW . implode(' | ', $links) . '</div>'; } return true; break; case 'external_plugin': if (serendipity_db_bool($this->get_config('html2pdf'))) { include_once dirname(__FILE__) . '/html2fpdf.php'; } elseif (serendipity_db_bool($this->get_config('updf'))) { include_once dirname(__FILE__) . '/serendipity_blogupdf.inc.php'; } else { include_once dirname(__FILE__) . '/serendipity_blogpdf.inc.php'; } $cachetime = 60 * 60 * 24; // one day $parts = explode('_', $eventData); if (!empty($parts[1])) { $param = (int) $parts[1]; } else { $param = null; } $methods = array('blogpdf', 'articlepdf', 'monthpdf', 'categorypdf'); if (!in_array($parts[0], $methods)) { return; } if (serendipity_db_bool($this->get_config('html2pdf'))) { $this->pdf = new HTML2FPDF(); } else { $this->pdf = new PDF(); } $this->pdf->AliasNbPages(); switch ($parts[0]) { case 'blogpdf': $feedcache = $serendipity['serendipityPath'] . 'archives/blog.pdf'; $entries = serendipity_fetchEntries(); $this->process($feedcache, $entries); break; case 'articlepdf': $feedcache = $serendipity['serendipityPath'] . 'archives/article' . $param . '.pdf'; $this->single = true; $entry = serendipity_fetchEntry('id', $param); $this->process($feedcache, $entry); break; case 'monthpdf': $feedcache = $serendipity['serendipityPath'] . 'archives/month' . $param . '.pdf'; $entries = serendipity_fetchEntries($param); $this->process($feedcache, $entries); break; case 'categorypdf': $feedcache = $serendipity['serendipityPath'] . 'archives/category' . $param . '.pdf'; $serendipity['GET']['category'] = $param . '_category'; $entries = serendipity_fetchEntries(); $this->process($feedcache, $entries); break; } $this->pdf->Output(); return true; break; default: return false; break; } } else { return false; } }
if (is_numeric($entry['id'])) { $_entry = serendipity_fetchEntry('id', $entry['id'], 1, 1); $entry['realname'] = $_entry['author']; } elseif (!empty($serendipity['realname'])) { $entry['realname'] = $serendipity['realname']; } else { $entry['realname'] = $serendipity['serendipityUser']; } } $categories = (array) $entry['categories']; $entry['categories'] = array(); foreach ($categories as $catid) { if ($catid == 0) { continue; } $entry['categories'][] = serendipity_fetchCategoryInfo($catid); } if (count($entry['categories']) < 1) { unset($entry['categories']); } if (isset($entry['id'])) { $serendipity['GET']['id'] = $entry['id']; } else { $serendipity['GET']['id'] = 1; } if ($serendipity['use_iframe']) { 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="" />' . IFRAME_PREVIEW . '</div><br />'; serendipity_iframe_create('preview', $entry); } else { serendipity_iframe($entry, 'preview'); }
function serveArchives() { global $serendipity; $serendipity['view'] = 'archives'; $_args = locateHiddenVariables($serendipity['uriArguments']); /* We must always *assume* that Year, Month and Day are the first 3 arguments */ list(, $year, $month, $day) = $_args; if ($year == "archives") { unset($year); } $serendipity['GET']['action'] = 'read'; $serendipity['GET']['hidefooter'] = true; if (!isset($year)) { $year = date('Y'); $month = date('m'); $day = date('j'); $serendipity['GET']['action'] = null; $serendipity['GET']['hidefooter'] = null; } if (isset($year) && !is_numeric($year)) { $year = date('Y'); } if (isset($month) && !is_numeric($month)) { $month = date('m'); } if (isset($day) && !is_numeric($day)) { $day = date('d'); } switch ($serendipity['calendar']) { case 'gregorian': default: $gday = 1; if ($week) { $tm = strtotime('+ ' . ($week - 2) . ' WEEKS monday', mktime(0, 0, 0, 1, 1, $year)); $ts = mktime(0, 0, 0, date('m', $tm), date('j', $tm), $year); $te = mktime(23, 59, 59, date('m', $tm), date('j', $tm) + 7, $year); $date = serendipity_formatTime(WEEK . ' ' . $week . ', %Y', $ts, false); } else { if ($day) { $ts = mktime(0, 0, 0, $month, $day, $year); $te = mktime(23, 59, 59, $month, $day, $year); $date = serendipity_formatTime(DATE_FORMAT_ENTRY, $ts, false); } else { $ts = mktime(0, 0, 0, $month, $gday, $year); if (!isset($gday2)) { $gday2 = date('t', $ts); } $te = mktime(23, 59, 59, $month, $gday2, $year); $date = serendipity_formatTime('%B %Y', $ts, false); } } break; case 'persian-utf8': require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; $gday = 1; if ($week) { --$week; $week *= 7; ++$week; $day = $week; // convert day number of year to day number of month AND month number of year $j_days_in_month = array(0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29); if ($g_y % 4 == 3) { $j_days_in_month[12]++; } for ($i = 1; isset($j_days_in_month[$i]); ++$i) { if ($day - $j_days_in_month[$i] > 0) { $day -= $j_days_in_month[$i]; } else { break; } } $tm = persian_mktime(0, 0, 0, $i, $day, $year); $ts = persian_mktime(0, 0, 0, persian_date_utf('m', $tm), persian_date_utf('j', $tm), $year); $te = persian_mktime(23, 59, 59, persian_date_utf('m', $tm), persian_date_utf('j', $tm) + 7, $year); $date = serendipity_formatTime(WEEK . ' ' . $week . '، %Y', $ts, false); } else { if ($day) { $ts = persian_mktime(0, 0, 0, $month, $day, $year); $te = persian_mktime(23, 59, 59, $month, $day, $year); $date = serendipity_formatTime(DATE_FORMAT_ENTRY, $ts, false); } else { $ts = persian_mktime(0, 0, 0, $month, $gday, $year); if (!isset($gday2)) { $gday2 = persian_date_utf('t', $ts); } $te = persian_mktime(23, 59, 59, $month, $gday2, $year); $date = serendipity_formatTime('%B %Y', $ts, false); } } list($year, $month, $day) = p2g($year, $month, $day); break; } $serendipity['range'] = array($ts, $te); if ($serendipity['GET']['action'] == 'read') { if ($serendipity['GET']['category']) { $cInfo = serendipity_fetchCategoryInfo($serendipity['GET']['category']); $serendipity['head_title'] = $cInfo['category_name']; } $serendipity['head_subtitle'] .= sprintf(ENTRIES_FOR, $date); } include S9Y_INCLUDE_PATH . 'include/genpage.inc.php'; }
/** * 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(' ', $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>'; }
function universal_fetchCategories($post_categories) { global $serendipity; $categories = array(); if (is_array($post_categories)) { if (is_array($post_categories[0])) { // if it is a cat_id hash foreach ($post_categories as $cat_id => $cat_obj) { if (is_object($cat_obj)) { $cat_name = $cat_obj->getval(); if (!empty($cat_name)) { $cat = serendipity_fetchCategories(null, $cat_name); if (isset($cat[0]['categoryid'])) { $categories[$cat[0]['categoryid']] = $cat[0]['categoryid']; } } } elseif (is_array($cat_obj) && isset($cat_obj['categoryId'])) { $cat_id = $cat_obj['categoryId']; //->getval(); if (!empty($cat_id)) { $categories[$cat_id] = $cat_id; } } } } else { // Just an array with names, has to be resolved to ids foreach ($post_categories as $cat_name) { $info = serendipity_fetchCategoryInfo(0, $cat_name); if (is_array($info)) { $cat_id = $info['categoryid']; $categories[$cat_id] = $cat_id; } } } } return $categories; }
unset($serendipity['uriArguments'][$k]); } } elseif ($v[0] == 'A') { /* Author */ $url_author = substr($v, 1); if (is_numeric($url_author)) { $serendipity['GET']['viewAuthor'] = $_GET['viewAuthor'] = (int) $url_author; unset($_args[$k]); } } } if (!$is_multicat) { $matches[1] = serendipity_searchPermalink($serendipity['permalinkCategoryStructure'], implode('/', $_args), $matches[1], 'category'); $serendipity['GET']['category'] = $matches[1]; } $cInfo = serendipity_fetchCategoryInfo($serendipity['GET']['category']); if (!is_array($cInfo)) { $serendipity['view'] = '404'; $serendipity['viewtype'] = '404_2'; header('HTTP/1.0 404 Not found'); header('Status: 404 Not found'); } else { $serendipity['head_title'] = $cInfo['category_name']; $serendipity['head_subtitle'] = $serendipity['blogTitle']; } include S9Y_INCLUDE_PATH . 'include/genpage.inc.php'; } else { if ($is_multiauth || preg_match(PAT_PERMALINK_AUTHORS, $uri, $matches)) { $serendipity['view'] = 'authors'; if ($is_multiauth) { $serendipity['GET']['viewAuthor'] = implode(';', $serendipity['POST']['multiAuth']);
/** * Initialize the Smarty framework for use in Serendipity * * @access public * @return null */ function serendipity_smarty_init($vars = array()) { global $serendipity, $template_config, $template_global_config, $template_config_groups; if (!isset($serendipity['smarty'])) { $template_dir = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['template']; if (!defined('IN_serendipity_admin') && file_exists($template_dir . '/template.inc.php')) { // If this file exists, a custom template engine will be loaded. // Beware: Smarty is used in the Admin backend, despite of this. include_once $template_dir . '/template.inc.php'; } else { // Backend template overwritten here (NOT earlier due to frontend specific check) if (defined('IN_serendipity_admin')) { $template_dir = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['template_backend']; } // Set a session variable if Smarty fails: $prev_smarty = $_SESSION['no_smarty']; $_SESSION['no_smarty'] = true; if (LANG_CHARSET != 'UTF-8') { @define('SMARTY_MBSTRING', false); @define('SMARTY_RESOURCE_CHAR_SET', LANG_CHARSET); } // define cache resources to load with smarty - see smarty cache readme - needs enabled cache! #@define('APC_EXTENSION_LOADED', extension_loaded('apc') && ini_get('apc.enabled')); #@define('MEMCACHE_EXTENSION_LOADED', (class_exists('Memcached',false) || class_exists('Memcache',false)) && (extension_loaded("memcached") || extension_loaded("memcache"))); // Default Smarty Engine will be used @define('SMARTY_DIR', S9Y_PEAR_PATH . 'Smarty/libs/'); if (!class_exists('Smarty')) { include_once SMARTY_DIR . 'Smarty.class.php'; } if (!class_exists('Smarty')) { return false; } // include the serendipity smarty constructor if (!class_exists('Serendipity_Smarty')) { include_once S9Y_INCLUDE_PATH . '/include/serendipity_smarty_class.inc.php'; } if (!class_exists('Serendipity_Smarty')) { return false; } // set smarty instance #$serendipity['smarty'] = new Serendipity_Smarty; // initialize smarty object by instance $serendipity['smarty'] = Serendipity_Smarty::getInstance(); // debug moved to class // Hooray for Smarty: $_SESSION['no_smarty'] = $prev_smarty; // enable security policy by instance of the Smarty_Security class $serendipity['smarty']->enableSecurity('Serendipity_Smarty_Security_Policy'); // debugging... #echo '<pre>';print_r($serendipity['smarty']);echo '</pre>';#exit; #$serendipity['smarty']->testInstall();exit; // extreme debugging with undocumented internal flag which enables a trace output from the parser during debugging #$serendipity['smarty']->_parserdebug = true; // be careful! /** * ToDo: Check for possible API changes in Smarty 3.2 [smarty_modifier_foobar, --> [smarty_modifier_foobar, smarty_function_foobar, smarty_block_foobar] (in class)] * smarty_modifier_foobar(Smarty $smarty, $string, ...) vs. smarty_modifier_foobar($string, ...) **/ $serendipity['smarty']->registerPlugin('modifier', 'makeFilename', 'serendipity_makeFilename'); $serendipity['smarty']->registerPlugin('modifier', 'xhtml_target', 'serendipity_xhtml_target'); $serendipity['smarty']->registerPlugin('modifier', 'emptyPrefix', 'serendipity_emptyPrefix'); $serendipity['smarty']->registerPlugin('modifier', 'formatTime', 'serendipity_smarty_formatTime'); $serendipity['smarty']->registerPlugin('modifier', 'serendipity_utf8_encode', 'serendipity_utf8_encode'); $serendipity['smarty']->registerPlugin('modifier', 'ifRemember', 'serendipity_ifRemember'); $serendipity['smarty']->registerPlugin('modifier', 'checkPermission', 'serendipity_checkPermission'); $serendipity['smarty']->registerPlugin('modifier', 'serendipity_refhookPlugin', 'serendipity_smarty_refhookPlugin'); $serendipity['smarty']->registerPlugin('modifier', 'serendipity_html5time', 'serendipity_smarty_html5time'); $serendipity['smarty']->registerPlugin('modifier', 'rewriteURL', 'serendipity_rewriteURL'); $serendipity['smarty']->registerPlugin('function', 'serendipity_printSidebar', 'serendipity_smarty_printSidebar'); $serendipity['smarty']->registerPlugin('function', 'serendipity_hookPlugin', 'serendipity_smarty_hookPlugin'); $serendipity['smarty']->registerPlugin('function', 'serendipity_showPlugin', 'serendipity_smarty_showPlugin'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getFile', 'serendipity_smarty_getFile'); $serendipity['smarty']->registerPlugin('function', 'serendipity_printComments', 'serendipity_smarty_printComments'); $serendipity['smarty']->registerPlugin('function', 'serendipity_printTrackbacks', 'serendipity_smarty_printTrackbacks'); $serendipity['smarty']->registerPlugin('function', 'serendipity_rss_getguid', 'serendipity_smarty_rss_getguid'); $serendipity['smarty']->registerPlugin('function', 'serendipity_fetchPrintEntries', 'serendipity_smarty_fetchPrintEntries'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getTotalCount', 'serendipity_smarty_getTotalCount'); $serendipity['smarty']->registerPlugin('function', 'pickKey', 'serendipity_smarty_pickKey'); $serendipity['smarty']->registerPlugin('function', 'serendipity_showCommentForm', 'serendipity_smarty_showCommentForm'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getImageSize', 'serendipity_smarty_getImageSize'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getConfigVar', 'serendipity_smarty_getConfigVar'); $serendipity['smarty']->registerPlugin('function', 'serendipity_setFormToken', 'serendipity_smarty_setFormToken'); $serendipity['smarty']->registerFilter('pre', 'serendipity_replaceSmartyVars'); } if (!isset($serendipity['smarty_file'])) { $serendipity['smarty_file'] = 'index.tpl'; } $category = false; $category_info = array(); if (isset($serendipity['GET']['category'])) { $category = (int) $serendipity['GET']['category']; if (isset($GLOBALS['cInfo'])) { $category_info = $GLOBALS['cInfo']; } else { $category_info = serendipity_fetchCategoryInfo($category); } } if (!isset($serendipity['smarty_vars']['head_link_stylesheet'])) { $serendipity['smarty_vars']['head_link_stylesheet_frontend'] = serendipity_rewriteURL('serendipity.css'); if (IN_serendipity_admin === true) { $serendipity['smarty_vars']['head_link_stylesheet'] = serendipity_rewriteURL('serendipity_admin.css'); } else { $serendipity['smarty_vars']['head_link_stylesheet'] = serendipity_rewriteURL('serendipity.css'); } // When templates are switched, append a specific version string to make sure the browser does not cache the CSS if (strstr($serendipity['smarty_vars']['head_link_stylesheet'], '?')) { $serendipity['smarty_vars']['head_link_stylesheet'] .= '&v=' . $serendipity['last_template_change']; $serendipity['smarty_vars']['head_link_stylesheet_frontend'] .= '&v=' . $serendipity['last_template_change']; } else { $serendipity['smarty_vars']['head_link_stylesheet'] .= '?v=' . $serendipity['last_template_change']; $serendipity['smarty_vars']['head_link_stylesheet_frontend'] .= '?v=' . $serendipity['last_template_change']; } } if (!isset($serendipity['smarty_vars']['head_link_script'])) { if (IN_serendipity_admin === true) { $serendipity['smarty_vars']['head_link_script'] = serendipity_rewriteURL('serendipity_admin.js'); } else { $serendipity['smarty_vars']['head_link_script'] = serendipity_rewriteURL('serendipity.js'); } if (strstr($serendipity['smarty_vars']['head_link_script'], '?')) { $serendipity['smarty_vars']['head_link_script'] .= '&v=' . $serendipity['last_template_change']; } else { $serendipity['smarty_vars']['head_link_script'] .= '?v=' . $serendipity['last_template_change']; } } $wysiwyg_customPlugin = $wysiwyg_customConfig = null; if (defined('IN_serendipity_admin') && $serendipity['wysiwyg']) { // check force internal toolbar config file if (strpos($serendipity['wysiwygToolbar'], 'NOCC-') !== false) { $serendipity['wysiwygToolbar'] = substr($serendipity['wysiwygToolbar'], 5); $force_internal_toolbar = true; } // check ckeditor custom plugin file $ccp = serendipity_getTemplateFile('admin/ckeditor_custom_plugin.js', 'serendipityHTTPPath', true); $wysiwyg_customPlugin = !empty($ccp) && !$force_internal_toolbar ? $ccp : $serendipity['serendipityHTTPPath'] . 'htmlarea/ckeditor_s9y_plugin.js'; // check ckeditor custom config file $ccc = serendipity_getTemplateFile('admin/ckeditor_custom_config.js', 'serendipityHTTPPath', true); $wysiwyg_customConfig = !empty($ccc) && !$force_internal_toolbar ? $ccc : $serendipity['serendipityHTTPPath'] . 'htmlarea/ckeditor_s9y_config.js'; } $_force_backendpopups = explode(',', $serendipity['enableBackendPopupGranular']); $force_backendpopups = array(); foreach ($_force_backendpopups as $fbp_key => $fbp_val) { $fbp_val = trim($fbp_val); if (empty($fbp_val)) { continue; } $force_backendpopups[$fbp_val] = $fbp_val; } $serendipity['smarty']->assign(array('head_charset' => LANG_CHARSET, 'head_version' => $serendipity['version'], 'head_title' => $serendipity['head_title'], 'head_subtitle' => $serendipity['head_subtitle'], 'head_link_stylesheet' => $serendipity['smarty_vars']['head_link_stylesheet'], 'head_link_script' => $serendipity['smarty_vars']['head_link_script'], 'head_link_stylesheet_frontend' => $serendipity['smarty_vars']['head_link_stylesheet_frontend'], 'is_xhtml' => true, 'use_popups' => $serendipity['enablePopup'], 'use_backendpopups' => $serendipity['enableBackendPopup'], 'force_backendpopups' => $force_backendpopups, 'is_embedded' => !$serendipity['embed'] || $serendipity['embed'] === 'false' || $serendipity['embed'] === false ? false : true, 'is_raw_mode' => $serendipity['smarty_raw_mode'], 'is_logged_in' => serendipity_userLoggedIn(), 'entry_id' => isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id']) ? $serendipity['GET']['id'] : false, 'is_single_entry' => isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id']), 'blogTitle' => $serendipity['blogTitle'], 'blogSubTitle' => !empty($serendipity['blogSubTitle']) ? $serendipity['blogSubTitle'] : '', 'blogDescription' => $serendipity['blogDescription'], 'serendipityHTTPPath' => $serendipity['serendipityHTTPPath'], 'serendipityDefaultBaseURL' => $serendipity['defaultBaseURL'], 'serendipityBaseURL' => $serendipity['baseURL'], 'serendipityRewritePrefix' => $serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '', 'serendipityIndexFile' => $serendipity['indexFile'], 'serendipityVersion' => $serendipity['expose_s9y'] ? $serendipity['version'] : '', 'lang' => $serendipity['lang'], 'category' => $category, 'category_info' => $category_info, 'template' => $serendipity['template'], 'template_backend' => $serendipity['template_backend'], 'wysiwygToolbar' => $serendipity['wysiwygToolbar'], 'wysiwyg_customPlugin' => $wysiwyg_customPlugin, 'wysiwyg_customConfig' => $wysiwyg_customConfig, 'use_autosave' => serendipity_db_bool($serendipity['use_autosave']) ? 'true' : 'false', 'dateRange' => !empty($serendipity['range']) ? $serendipity['range'] : array())); if (count($vars) > 0) { $serendipity['smarty']->assign($vars); } // For advanced usage, we allow template authors to create a file 'config.inc.php' where they can // setup custom smarty variables, modifiers etc. to use in their templates. // If a template engine is defined we need that config.inc.php file as well. The template's actual file is loaded after that to be able to overwrite config. if (isset($serendipity['template_engine']) && $serendipity['template_engine'] != null) { $p = explode(',', $serendipity['template_engine']); foreach ($p as $te) { $config = $serendipity['serendipityPath'] . $serendipity['templatePath'] . trim($te) . '/config.inc.php'; if (file_exists($config)) { include_once $config; } } } // FIRST: Load config of the currently configured FRONTEND template. We might actually need this in the backend (sidebar configuration, IPTC options, some others). // SECOND: Load config of the currently set template, which can also be the BACKEND template, or be the same as before. include_once takes care of only including the file once. $config = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['template'] . '/config.inc.php'; if (file_exists($config)) { include_once $config; } $config = $serendipity['smarty']->getConfigDir(0) . '/config.inc.php'; if (file_exists($config)) { include_once $config; } if (is_array($template_loaded_config)) { $template_vars =& $template_loaded_config; $serendipity['smarty']->assignByRef('template_option', $template_vars); } elseif (is_array($template_config)) { $template_vars =& serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option']); $serendipity['smarty']->assignByRef('template_option', $template_vars); } } return true; }
$data['categoryName'] = $this_cat['category_name']; $cats = serendipity_fetchCategories('all'); $data['cats'] = array(); /* TODO, show dropdown as nested categories */ foreach ($cats as $cat_data) { if ($cat_data['categoryid'] != $serendipity['GET']['cid'] && (serendipity_checkPermission('adminCategoriesMaintainOthers') || $cat_data['authorid'] == '0' || $cat_data['authorid'] == $serendipity['authorid'])) { $data['cats'][] = $cat_data; } } } } if ($serendipity['GET']['adminAction'] == 'edit' || $serendipity['GET']['adminAction'] == 'new' || $serendipity['GET']['adminAction'] == 'newSub') { if ($serendipity['GET']['adminAction'] == 'edit') { $data['edit'] = true; $cid = (int) $serendipity['GET']['cid']; $this_cat = serendipity_fetchCategoryInfo($cid); $data['category_name'] = $this_cat['category_name']; $save = SAVE; $read_groups = serendipity_ACLGet($cid, 'category', 'read'); $write_groups = serendipity_ACLGet($cid, 'category', 'write'); } else { $data['new'] = true; $cid = false; $this_cat = array(); echo '<h2>' . CREATE_NEW_CAT . '</h2>'; $save = CREATE; $read_groups = array(0 => 0); $write_groups = array(0 => 0); } if ($serendipity['GET']['adminAction'] == 'newSub') { $data['new'] = true;
/** * Initialize the Smarty framework for use in Serendipity * * @access public * @return null */ function serendipity_smarty_init($vars = array()) { global $serendipity, $template_config, $template_global_config, $template_config_groups; if (!isset($serendipity['smarty'])) { $template_dir = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['template']; if (!defined('IN_serendipity_admin') && file_exists($template_dir . '/template.inc.php')) { // If this file exists, a custom template engine will be loaded. // Beware: Smarty is used in the Admin backend, despite of this. include $template_dir . '/template.inc.php'; } else { // Set a session variable if Smarty fails: $prev_smarty = $_SESSION['no_smarty']; $_SESSION['no_smarty'] = true; // Default Smarty Engine will be used @define('SMARTY_DIR', S9Y_PEAR_PATH . 'Smarty/libs/'); if (!class_exists('Smarty')) { include SMARTY_DIR . 'Smarty.class.php'; } if (!class_exists('Smarty')) { return false; } // Load serendipity smarty class loading class if (!class_exists('Serendipity_Smarty')) { include 'serendipity_smarty_class.inc.php'; } if (!class_exists('Serendipity_Smarty')) { return false; } // set smarty instance #$serendipity['smarty'] = new Serendipity_Smarty; // initialize smarty object by instance $serendipity['smarty'] = Serendipity_Smarty::getInstance(); // debug moved to class // Hooray for Smarty: $_SESSION['no_smarty'] = $prev_smarty; // enable security policy by instance of the Smarty_Security class $serendipity['smarty']->enableSecurity('Serendipity_Smarty_Security_Policy'); // debugging... #echo '<pre>';print_r($serendipity['smarty']);echo '</pre>';#exit; #$serendipity['smarty']->testInstall();exit; /** * prüfe auf eventuelle API Änderungen in 3.2 [smarty_modifier_foobar, --> [smarty_modifier_foobar, smarty_function_foobar, smarty_block_foobar] (siehe class) ] * smarty_modifier_foobar(Smarty $smarty, $string, …) vs. smarty_modifier_foobar($string, …) **/ $serendipity['smarty']->registerPlugin('modifier', 'makeFilename', 'serendipity_makeFilename'); $serendipity['smarty']->registerPlugin('modifier', 'xhtml_target', 'serendipity_xhtml_target'); $serendipity['smarty']->registerPlugin('modifier', 'emptyPrefix', 'serendipity_emptyPrefix'); $serendipity['smarty']->registerPlugin('modifier', 'formatTime', 'serendipity_smarty_formatTime'); $serendipity['smarty']->registerPlugin('modifier', 'serendipity_utf8_encode', 'serendipity_utf8_encode'); $serendipity['smarty']->registerPlugin('modifier', 'ifRemember', 'serendipity_ifRemember'); $serendipity['smarty']->registerPlugin('modifier', 'checkPermission', 'serendipity_checkPermission'); $serendipity['smarty']->registerPlugin('modifier', 'serendipity_refhookPlugin', 'serendipity_smarty_refhookPlugin'); $serendipity['smarty']->registerPlugin('function', 'serendipity_printSidebar', 'serendipity_smarty_printSidebar'); $serendipity['smarty']->registerPlugin('function', 'serendipity_hookPlugin', 'serendipity_smarty_hookPlugin'); $serendipity['smarty']->registerPlugin('function', 'serendipity_showPlugin', 'serendipity_smarty_showPlugin'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getFile', 'serendipity_smarty_getFile'); $serendipity['smarty']->registerPlugin('function', 'serendipity_printComments', 'serendipity_smarty_printComments'); $serendipity['smarty']->registerPlugin('function', 'serendipity_printTrackbacks', 'serendipity_smarty_printTrackbacks'); $serendipity['smarty']->registerPlugin('function', 'serendipity_rss_getguid', 'serendipity_smarty_rss_getguid'); $serendipity['smarty']->registerPlugin('function', 'serendipity_fetchPrintEntries', 'serendipity_smarty_fetchPrintEntries'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getTotalCount', 'serendipity_smarty_getTotalCount'); $serendipity['smarty']->registerPlugin('function', 'pickKey', 'serendipity_smarty_pickKey'); $serendipity['smarty']->registerPlugin('function', 'serendipity_showCommentForm', 'serendipity_smarty_showCommentForm'); $serendipity['smarty']->registerPlugin('function', 'serendipity_getImageSize', 'serendipity_smarty_getImageSize'); $serendipity['smarty']->registerFilter('pre', 'serendipity_replaceSmartyVars'); } if (!isset($serendipity['smarty_raw_mode'])) { if (file_exists($serendipity['smarty']->getConfigDir(0) . '/layout.php') && $serendipity['template'] != 'default') { $serendipity['smarty_raw_mode'] = true; } else { $serendipity['smarty_raw_mode'] = false; } } if (!isset($serendipity['smarty_file'])) { $serendipity['smarty_file'] = 'index.tpl'; } $category = false; $category_info = array(); if (isset($serendipity['GET']['category'])) { $category = (int) $serendipity['GET']['category']; if (isset($GLOBALS['cInfo'])) { $category_info = $GLOBALS['cInfo']; } else { $category_info = serendipity_fetchCategoryInfo($category); } } if (!isset($serendipity['smarty_vars']['head_link_stylesheet'])) { $serendipity['smarty_vars']['head_link_stylesheet'] = serendipity_rewriteURL('serendipity.css'); } $serendipity['smarty']->assign(array('head_charset' => LANG_CHARSET, 'head_version' => $serendipity['version'], 'head_title' => $serendipity['head_title'], 'head_subtitle' => $serendipity['head_subtitle'], 'head_link_stylesheet' => $serendipity['smarty_vars']['head_link_stylesheet'], 'is_xhtml' => true, 'use_popups' => $serendipity['enablePopup'], 'is_embedded' => !$serendipity['embed'] || $serendipity['embed'] === 'false' || $serendipity['embed'] === false ? false : true, 'is_raw_mode' => $serendipity['smarty_raw_mode'], 'is_logged_in' => serendipity_userLoggedIn(), 'entry_id' => isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id']) ? $serendipity['GET']['id'] : false, 'is_single_entry' => isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id']), 'blogTitle' => $serendipity['blogTitle'], 'blogSubTitle' => !empty($serendipity['blogSubTitle']) ? $serendipity['blogSubTitle'] : '', 'blogDescription' => $serendipity['blogDescription'], 'serendipityHTTPPath' => $serendipity['serendipityHTTPPath'], 'serendipityDefaultBaseURL' => $serendipity['defaultBaseURL'], 'serendipityBaseURL' => $serendipity['baseURL'], 'serendipityRewritePrefix' => $serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '', 'serendipityIndexFile' => $serendipity['indexFile'], 'serendipityVersion' => $serendipity['expose_s9y'] ? $serendipity['version'] : '', 'lang' => $serendipity['lang'], 'category' => $category, 'category_info' => $category_info, 'template' => $serendipity['template'], 'dateRange' => !empty($serendipity['range']) ? $serendipity['range'] : array())); if (count($vars) > 0) { $serendipity['smarty']->assign($vars); } // For advanced usage, we allow template authors to create a file 'config.inc.php' where they can // setup custom smarty variables, modifiers etc. to use in their templates. @(include_once $serendipity['smarty']->getConfigDir(0) . '/config.inc.php'); if (is_array($template_loaded_config)) { $template_vars =& $template_loaded_config; $serendipity['smarty']->assignByRef('template_option', $template_vars); } elseif (is_array($template_config)) { $template_vars =& serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option']); $serendipity['smarty']->assignByRef('template_option', $template_vars); } } 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; $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); } } $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(' ', $cat['depth']); $template_vars['category_options'][] = $cat; } } 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" . '<a class="block_level" href="' . serendipity_specialchars(utf8_decode(urldecode($serendipity['GET']['url']))) . '">' . $entry['title'] . '</a>'; } $template_vars['formToken'] = serendipity_setFormToken(); 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; } $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['hiddens'] = $hiddens; $template_vars['errMsg'] = $errMsg; $template_vars['entry'] =& $entry; $template_vars['targetURL'] = $targetURL; $template_vars['cat_count'] = count($cats) + 1; $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'); if (!is_object($serendipity['smarty'])) { serendipity_smarty_init(); } $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); return serendipity_smarty_show('admin/entries.tpl'); }
function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; if ($event == 'frontend_header') { $start_url = $serendipity['baseURL']; $start_title = $serendipity['blogTitle']; echo '<link rel="start" href="' . $start_url . '" title="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($start_title) : htmlspecialchars($start_title, ENT_COMPAT, LANG_CHARSET)) . '" />' . "\n"; if ($serendipity['GET']['action'] == 'read' && !empty($serendipity['GET']['id'])) { // Article detail view echo '<link rel="up" href="' . $start_url . '" title="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($start_title) : htmlspecialchars($start_title, ENT_COMPAT, LANG_CHARSET)) . '" />' . "\n"; $this->backAndForth($this->showPaging($serendipity['GET']['id'])); // END article detail view echo '<link rel="canonical" href="' . $this->getEntry($serendipity['GET']['id']) . '" />' . "\n"; } elseif ($serendipity['GET']['action'] == 'read' && is_array($serendipity['range'])) { // Specific Date Archives view echo '<link rel="up" href="' . serendipity_rewriteURL(PATH_ARCHIVE) . '" title="' . ARCHIVES . '" />' . "\n"; echo '<link rel="canonical" href="' . $this->getArchiveParameters() . '" />' . "\n"; $links = array(); $add_query = ''; $year = date('Y', $serendipity['range'][0]); $month = date('m', $serendipity['range'][0]); $day = date('d', $serendipity['range'][0]); $pageMonthNext = array('day' => '1', 'month' => $month + 1, 'year' => $year); $pageMonthPrev = array('day' => '1', 'month' => $month - 1, 'year' => $year); $pageDayNext = array('day' => $day + 1, 'month' => $month, 'year' => $year); $pageDayPrev = array('day' => $day - 1, 'month' => $month, 'year' => $year); $diff = $serendipity['range'][1] - $serendipity['range'][0]; if (isset($serendipity['GET']['category'])) { $categoryid = (int) serendipity_db_escape_string($serendipity['GET']['category']); $add_query = '/C' . $categoryid; } if ($diff < 86400) { // Paging day by day $ts = mktime(0, 0, 0, $pageDayPrev['month'], $pageDayPrev['day'], $pageDayPrev['year']); $links['prev'] = array('link' => serendipity_archiveDateUrl(sprintf('%4d/%02d/%02d', date('Y', $ts), date('m', $ts), date('d', $ts))), 'title' => sprintf(ENTRIES_FOR, serendipity_formatTime(DATE_FORMAT_ENTRY, $ts, false))); $ts = mktime(0, 0, 0, $pageDayNext['month'], $pageDayNext['day'], $pageDayNext['year']); $links['next'] = array('link' => serendipity_archiveDateUrl(sprintf('%4d/%02d/%02d', date('Y', $ts), date('m', $ts), date('d', $ts))), 'title' => sprintf(ENTRIES_FOR, serendipity_formatTime(DATE_FORMAT_ENTRY, $ts, false))); } elseif ($diff < 86400 * 28) { // Paging by week // TODO - Don't know :-) } else { // Paging by month $ts = mktime(0, 0, 0, $pageMonthPrev['month'], $pageMonthPrev['day'], $pageMonthPrev['year']); $links['prev'] = array('link' => serendipity_archiveDateUrl(sprintf('%4d/%02d', date('Y', $ts), date('m', $ts))), 'title' => sprintf(ENTRIES_FOR, serendipity_formatTime('%B %Y', $ts, false))); $ts = mktime(0, 0, 0, $pageMonthNext['month'], $pageMonthNext['day'], $pageMonthNext['year']); $links['next'] = array('link' => serendipity_archiveDateUrl(sprintf('%4d/%02d', date('Y', $ts), date('m', $ts))), 'title' => sprintf(ENTRIES_FOR, serendipity_formatTime('%B %Y', $ts, false))); } $this->backAndForth($links); // END Specific Date Archives view } elseif ($serendipity['GET']['action'] == 'archives') { // Full month/year archives overview echo '<link rel="up" href="' . serendipity_rewriteURL(PATH_ARCHIVE) . '" title="' . ARCHIVES . '" />' . "\n"; // END Full month/year archives overview echo '<link rel="canonical" href="' . $this->getArchiveParameters() . '" />' . "\n"; } elseif (!empty($serendipity['GET']['category'])) { // Category based view $cInfo = serendipity_fetchCategoryInfo($serendipity['GET']['category']); if (function_exists('serendipity_categoryURL')) { $categories_url = serendipity_categoryURL($cInfo, 'serendipityHTTPPath'); } else { $categories_url = serendipity_rewriteURL(PATH_CATEGORIES . '/' . serendipity_makePermalink(PERM_CATEGORIES, array('id' => $cInfo['categoryid'], 'title' => $cInfo['category_name'])), 'serendipityHTTPPath'); } echo '<link rel="up" href="' . $categories_url . '" title="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($cInfo['category_name']) : htmlspecialchars($cInfo['category_name'], ENT_COMPAT, LANG_CHARSET)) . '" />' . "\n"; echo '<link rel="canonical" href="' . $categories_url . '" />' . "\n"; $categories = serendipity_fetchCategories('all'); $links = array(); if (is_array($categories) && count($categories)) { $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED); $capture_next = false; foreach ($categories as $cat) { if ($capture_next) { $links['next'] = $this->getCat($cat); break; } if (is_array($prev_cat) && $cat['categoryid'] == $serendipity['GET']['category']) { $links['prev'] = $this->getCat($prev_cat); $capture_next = true; } $prev_cat = $cat; } } $this->backAndForth($links); // END Category based view } elseif (!empty($serendipity['GET']['viewAuthor'])) { // User view $uInfo = serendipity_fetchUsers(); $links = array(); if (is_array($uInfo)) { $capture_next = false; foreach ($uInfo as $user) { if ($capture_next) { $links['next'] = $this->getUser($user); break; } if ($user['authorid'] == $serendipity['GET']['viewAuthor']) { $authors_url = $this->getUser($user); echo '<link rel="up" href="' . $authors_url['link'] . '" title="' . $authors_url['title'] . '" />' . "\n"; echo '<link rel="canonical" href="' . $authors_url['link'] . '" />' . "\n"; if (is_array($prev_user)) { $links['prev'] = $this->getUser($prev_user); $capture_next = true; } } $prev_user = $user; } $this->backAndForth($links); } // END User view } else { // Frontpage $this->backAndForth(); // END Frontpage if ($serendipity['view'] == 'start') { echo '<link rel="canonical" href="' . $serendipity['baseURL'] . '" />' . "\n"; } } } }
/** * Smarty Function: Returns the s9y-URL for a given category-id * * @access public * @data array Smarty parameter input array: * cid: id of the category * @param object Smarty object * @return string The URL of the category - must be added to {$serendipityBaseURL} for a full URL */ function smarty_getCategoryLinkByID($data, &$smarty) { $cat = serendipity_fetchCategoryInfo($data['cid']); $result = serendipity_getPermalink($cat, 'category'); return $result; }
/** * Initialize the Smarty framework for use in Serendipity * * @access public * @return null */ function serendipity_smarty_init($vars = array()) { global $serendipity, $template_config; if (!isset($serendipity['smarty'])) { $template_dir = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['template']; if (!defined('IN_serendipity_admin') && file_exists($template_dir . '/template.inc.php')) { // If this file exists, a custom template engine will be loaded. // Beware: Smarty is used in the Admin backend, despite of this. include $template_dir . '/template.inc.php'; } else { // Set a session variable if Smarty fails: $prev_smarty = $_SESSION['no_smarty']; $_SESSION['no_smarty'] = true; // Default Smarty Engine will be used @define('SMARTY_DIR', S9Y_PEAR_PATH . 'Smarty/libs/'); if (!class_exists('Smarty')) { include SMARTY_DIR . 'Smarty.class.php'; } if (!class_exists('Smarty')) { return false; } $serendipity['smarty'] = new Smarty(); if ($serendipity['production'] === 'debug') { $serendipity['smarty']->force_compile = true; $serendipity['smarty']->debugging = true; } $serendipity['smarty']->template_dir = array($template_dir); $p = explode(',', $serendipity['template_engine']); foreach ($p as $te) { $serendipity['smarty']->template_dir[] = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $te; } $serendipity['smarty']->template_dir[] = $serendipity['serendipityPath'] . $serendipity['templatePath'] . 'default'; $serendipity['smarty']->compile_dir = $serendipity['serendipityPath'] . PATH_SMARTY_COMPILE; if (!is_dir($serendipity['smarty']->compile_dir) || !is_writable($serendipity['smarty']->compile_dir)) { printf(DIRECTORY_WRITE_ERROR, $serendipity['smarty']->compile_dir); return false; } // Hooray for Smarty: $_SESSION['no_smarty'] = $prev_smarty; $serendipity['smarty']->config_dir = $template_dir; $serendipity['smarty']->secure_dir = array($serendipity['serendipityPath'] . $serendipity['templatePath']); $serendipity['smarty']->security_settings['MODIFIER_FUNCS'] = array('sprintf', 'sizeof', 'count', 'rand', 'print_r', 'str_repeat'); $serendipity['smarty']->security_settings['ALLOW_CONSTANTS'] = true; $serendipity['smarty']->security = true; $serendipity['smarty']->use_sub_dirs = false; $serendipity['smarty']->compile_check = true; $serendipity['smarty']->compile_id =& $serendipity['template']; $serendipity['smarty']->register_modifier('makeFilename', 'serendipity_makeFilename'); $serendipity['smarty']->register_modifier('xhtml_target', 'serendipity_xhtml_target'); $serendipity['smarty']->register_modifier('emptyPrefix', 'serendipity_emptyPrefix'); $serendipity['smarty']->register_modifier('formatTime', 'serendipity_smarty_formatTime'); $serendipity['smarty']->register_modifier('serendipity_utf8_encode', 'serendipity_utf8_encode'); $serendipity['smarty']->register_modifier('ifRemember', 'serendipity_ifRemember'); $serendipity['smarty']->register_modifier('checkPermission', 'serendipity_checkPermission'); $serendipity['smarty']->register_modifier('serendipity_refhookPlugin', 'serendipity_smarty_refhookPlugin'); $serendipity['smarty']->register_function('serendipity_printSidebar', 'serendipity_smarty_printSidebar'); $serendipity['smarty']->register_function('serendipity_hookPlugin', 'serendipity_smarty_hookPlugin'); $serendipity['smarty']->register_function('serendipity_showPlugin', 'serendipity_smarty_showPlugin'); $serendipity['smarty']->register_function('serendipity_getFile', 'serendipity_smarty_getFile'); $serendipity['smarty']->register_function('serendipity_printComments', 'serendipity_smarty_printComments'); $serendipity['smarty']->register_function('serendipity_printTrackbacks', 'serendipity_smarty_printTrackbacks'); $serendipity['smarty']->register_function('serendipity_rss_getguid', 'serendipity_smarty_rss_getguid'); $serendipity['smarty']->register_function('serendipity_fetchPrintEntries', 'serendipity_smarty_fetchPrintEntries'); $serendipity['smarty']->register_function('serendipity_getTotalCount', 'serendipity_smarty_getTotalCount'); $serendipity['smarty']->register_function('pickKey', 'serendipity_smarty_pickKey'); $serendipity['smarty']->register_function('serendipity_showCommentForm', 'serendipity_smarty_showCommentForm'); $serendipity['smarty']->register_function('serendipity_getImageSize', 'serendipity_smarty_getImageSize'); $serendipity['smarty']->register_prefilter('serendipity_replaceSmartyVars'); } if (!isset($serendipity['smarty_raw_mode'])) { if (file_exists($serendipity['smarty']->config_dir . '/layout.php') && $serendipity['template'] != 'default') { $serendipity['smarty_raw_mode'] = true; } else { $serendipity['smarty_raw_mode'] = false; } } if (!isset($serendipity['smarty_file'])) { $serendipity['smarty_file'] = 'index.tpl'; } $category = false; $category_info = array(); if (isset($serendipity['GET']['category'])) { $category = (int) $serendipity['GET']['category']; if (isset($GLOBALS['cInfo'])) { $category_info = $GLOBALS['cInfo']; } else { $category_info = serendipity_fetchCategoryInfo($category); } } if (!isset($serendipity['smarty_vars']['head_link_stylesheet'])) { $serendipity['smarty_vars']['head_link_stylesheet'] = serendipity_rewriteURL('serendipity.css'); } $serendipity['smarty']->assign(array('head_charset' => LANG_CHARSET, 'head_version' => $serendipity['version'], 'head_title' => $serendipity['head_title'], 'head_subtitle' => $serendipity['head_subtitle'], 'head_link_stylesheet' => $serendipity['smarty_vars']['head_link_stylesheet'], 'is_xhtml' => true, 'use_popups' => $serendipity['enablePopup'], 'is_embedded' => !$serendipity['embed'] || $serendipity['embed'] === 'false' || $serendipity['embed'] === false ? false : true, 'is_raw_mode' => $serendipity['smarty_raw_mode'], 'is_logged_in' => serendipity_userLoggedIn(), 'entry_id' => isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id']) ? $serendipity['GET']['id'] : false, 'is_single_entry' => isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id']), 'blogTitle' => $serendipity['blogTitle'], 'blogSubTitle' => !empty($serendipity['blogSubTitle']) ? $serendipity['blogSubTitle'] : '', 'blogDescription' => $serendipity['blogDescription'], 'serendipityHTTPPath' => $serendipity['serendipityHTTPPath'], 'serendipityBaseURL' => $serendipity['baseURL'], 'serendipityRewritePrefix' => $serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '', 'serendipityIndexFile' => $serendipity['indexFile'], 'serendipityVersion' => $serendipity['expose_s9y'] ? $serendipity['version'] : '', 'lang' => $serendipity['lang'], 'category' => $category, 'category_info' => $category_info, 'template' => $serendipity['template'], 'dateRange' => !empty($serendipity['range']) ? $serendipity['range'] : array())); if (count($vars) > 0) { $serendipity['smarty']->assign($vars); } // For advanced usage, we allow template authors to create a file 'config.inc.php' where they can // setup custom smarty variables, modifiers etc. to use in their templates. @(include_once $serendipity['smarty']->config_dir . '/config.inc.php'); if (is_array($template_loaded_config)) { $template_vars =& $template_loaded_config; $serendipity['smarty']->assign_by_ref('template_option', $template_vars); } elseif (is_array($template_config)) { $template_vars =& serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option']); $serendipity['smarty']->assign_by_ref('template_option', $template_vars); } } return true; }
function workPopfetcher(&$eventData) { global $serendipity; static $debug = null; if ($debug === null) { $debug = $this->debug = serendipity_db_bool($this->get_config('debug')); } // updertEntry() will not function unless this is set: $serendipity['POST']['properties']['fake'] = 'fake'; $_SESSION['serendipityRightPublish'] = true; $this->out('<h3>' . PLUGIN_MF_NAME . ' v' . POPFETCHER_VERSION . ' @ ' . date("D M j G:i:s T Y") . '</h3>'); $debug_file = null; // DEVELOPERS: If set to a filename, you can bypass fetching POP and use a file instead. $debug_mail = $this->get_config('debug_mail'); if (strlen($debug_mail) != '' && file_exists($debug_mail)) { $debug_file = $debug_mail; } if ($debug_file != null) { $this->debug = true; } $authorid = $this->get_config('author'); if (empty($authorid) || $authorid == 'empty') { $authorid = isset($serendipity['authorid']) ? $serendipity['authorid'] : 1; } $mailserver = trim($this->get_config('mailserver')); $mailport = $this->get_config('mailport'); $mailuser = trim($this->get_config('mailuser')); $mailpass = trim($this->get_config('mailpass')); $timeout = $this->get_config('timeout'); $deleteflag = serendipity_db_bool($this->get_config('deleteflag')); $apopflag = serendipity_db_bool($this->get_config('apopflag')); $blogflag = serendipity_db_bool($this->get_config('blogflag')); $striptagsflag = serendipity_db_bool($this->get_config('striptagsflag')); $publishflag = serendipity_db_bool($this->get_config('publishflag')); $onlyfrom = $this->get_config('onlyfrom', ''); $maildir = trim($this->get_config('maildir')); $category = trim($this->get_config('category')); $adflag = serendipity_db_bool($this->get_config('adflag')); $plaintext_is_body_flag = serendipity_db_bool($this->get_config('plaintext_is_body')); $plaintext_use_extended_flag = serendipity_db_bool($this->get_config('plaintext_use_extended')); $list_virus = array('.pif', '.vbs', '.scr', '.bat', '.com', '.exe'); $list_imagetype = array('jpg', 'jpeg', 'gif', 'png', 'x-png', 'pjpeg'); $list_imageext = array('.gif', '.jpg', '.png', '.jpeg'); $list_ignore = array('.smil'); $output = ''; $dirpath = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $maildir; $dupcount = 0; // Upload directory must end with a slash character if (strrchr($dirpath, '/') != '/') { $output = MF_ERROR7; $this->out('<br />' . $output . '<br />'); return true; } // Upload directory must be writable if (!is_writable($dirpath)) { $output = MF_ERROR6; $this->out('<br />' . $output . '<br />'); return true; } if (serendipity_db_bool($this->get_config('subfolder'))) { $dirpath = $dirpath . '/' . date('Y'); if (!is_dir($dirpath)) { mkdir($dirpath); } $dirpath = $dirpath . '/' . date('m') . '/'; if (!is_dir($dirpath)) { mkdir($dirpath); } $maildir .= date('Y') . '/' . date('m') . '/'; } $maildir = str_replace('//', '/', $maildir); // Category (if specified) must exist if (!empty($category)) { $cid = serendipity_fetchCategoryInfo(null, $category); if ($cid == false) { $output = MF_ERROR8; $this->out('<br />' . $output . '<br />'); return true; } } if ($debug_file === null) { // Create new instance of POP3 connection $pop3 = new POP3($mailserver, $timeout); // Attempt to connect to mail server if (!$pop3->connect($mailserver, $mailport)) { $output = MF_ERROR1 . ': ' . $pop3->ERROR; $this->out('<br />' . $output . '<br />'); return true; } // Try APOP login if requested, otherwise, regular login if ($apopflag) { $Count = $pop3->apop($mailuser, $mailpass); } else { $Count = $pop3->login($mailuser, $mailpass); } // Check for error retrieving number of msgs in mailbox if ($Count === false or $Count == -1) { $output = MF_ERROR2 . ': ' . $pop3->ERROR; $this->out('<br />' . $output . '<br />'); return true; } // If no msgs in mailbox, exit if ($Count == 0) { $output = MF_MSG1; $this->out('<br />' . $output . '<br />'); return true; } // Get the list of email msgs $msglist = $pop3->uidl(); // Check for error in getting list of email msgs if (!is_array($msglist)) { $output = MF_ERROR3 . ': ' . $pop3->ERROR; $this->out('<br />' . $output . '<br />'); $pop3->quit(); return true; } } else { // Developer debug switch which reads from a file and not a POP3 connection. $dfiles = explode(':', $debug_file); $Count = count($dfiles); } $Message = array(); // ************************ // Fetch each email msg and attachments and put it into the $Message array // ************************ for ($i = 1; $i <= $Count; $i++) { // Messages are numbered starting with '1', not '0' if ($debug_file === null) { $MessArray = $pop3->get($i); } else { $MessArray = file($dfiles[$i - 1]); } // Should have an array. If not, there was an error if (!$MessArray or gettype($MessArray) != "array") { $output = MF_ERROR4 . ': ' . $pop3->ERROR; $this->out('<br />' . $output . '<br />'); $pop3->quit(); return true; } // Extract the msg from MessArray and store it in Message $Message[$i - 1] = ''; while (list($lineNum, $line) = each($MessArray)) { $Message[$i - 1] .= $line; } // Delete the msg if ($deleteflag && $debug_file === null) { $pop3->delete($i); } } if ($debug_file === null) { // Close the connection to the mail server $pop3->quit(); } // ************************ // Message processing section starts here // ************************ $this->out('<br />' . MF_MSG2 . ': ' . $Count . '<br />'); if ($deleteflag) { $this->out(MF_MSG11 . '<br />'); } else { $this->out(MF_MSG12 . '<br />'); } $params['include_bodies'] = true; $params['decode_bodies'] = true; $params['decode_headers'] = true; // Process each email msg foreach ($Message as $M) { $decode = new mimeDecode($M); #$this->out(print_r($M, true)); $s = $decode->decode($params); #$this->out(print_r($s, true)); if ($debug_file !== null) { // DEBUG Struct // echo '<pre>'; // print_r($s); // echo '</pre>'; } if ($s == null) { $this->out('<br />' . MF_ERROR9); return true; } $date = isset($s->headers['date']) ? $s->headers['date'] : MF_MSG3; $from = isset($s->headers['from']) ? $s->headers['from'] : MF_MSG4; if (!empty($onlyfrom) && trim($from) != trim($onlyfrom)) { $this->out('<br />' . sprintf(MF_ERROR_ONLYFROM, '"' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($from) : htmlspecialchars($from, ENT_COMPAT, LANG_CHARSET)) . '"', '"' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($onlyfrom) : htmlspecialchars($onlyfrom, ENT_COMPAT, LANG_CHARSET)) . '"')); continue; } if (empty($s->ctype_parameters['charset'])) { $s->ctype_parameters['charset'] = 'UTF-8'; } if (strtolower($s->ctype_parameters['charset']) == 'us-ascii') { $s->ctype_parameters['charset'] = 'ISO-8859-1'; } $subject = $this->decode(isset($s->headers['subject']) ? $s->headers['subject'] : MF_MSG17, $s->ctype_parameters['charset'], true); #$subject = $this->decode(isset($s->headers['subject']) ? $s->headers['subject'] : MF_MSG17, $s->ctype_parameters['charset']); #$subject = isset($s->headers['subject']) ? $s->headers['subject'] : MF_MSG17; $this->out('<hr />'); $this->out(MF_MSG5 . $date . '<br />'); $this->out(MF_MSG6 . (function_exists('serendipity_specialchars') ? serendipity_specialchars($from) : htmlspecialchars($from, ENT_COMPAT, LANG_CHARSET)) . '<br />'); $this->out(MF_MSG16 . $subject . '<br />'); // Find the author associated with the from address and // set them as the author of the post. $useAuthor = null; if ($authorid == 'byemail') { // We don't have tons of authors .. like two so this isn't a problem // If I wanted this to be "production" quality, I would have to add // a new s9y function that let you retrieve an author given an email address // I suppose I could go with a convention that the base name of the // email address had to be the author's name too. Lookup by name is // supported by s9y. $auths = serendipity_fetchUsers(); $vals = array(); $clean = strtolower($this->cleanEmail($from)); foreach ($auths as $auth) { if (isset($auth['email']) && strtolower($auth['email']) == $clean) { $useAuthor = $auth['authorid']; break; } } if (is_null($useAuthor)) { $this->out('<br />' . sprintf(MF_ERROR_NOAUTHOR, '"' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($clean) : htmlspecialchars($clean, ENT_COMPAT, LANG_CHARSET)) . '"')); continue; } } else { $useAuthor = $authorid; } $postattach = array(); $postbody = array(); $postex = array(); $verizonflag = false; $tmobileflag = false; $firstattachment = false; $firsttext = false; $o2flag = stristr($from, 'mms.o2online.de') !== FALSE; // A mail message with attachments is a series of "parts" if (isset($s->parts) and is_array($s->parts)) { if ($debug_file !== null || $debug) { $this->out('<pre>' . print_r($s->parts, true) . '</pre>'); } $textpref = $this->get_config('textpref'); if ($textpref != 'both') { $has_html = false; $has_text = false; $parts_html = array(); $parts_text = array(); foreach ($s->parts as $idx => $p) { if ($p->ctype_primary == 'text' && $p->ctype_secondary == 'html') { if ($debug_file !== null || $debug) { $this->out("This part is text/html.<br />\n"); } $has_html = true; $parts_html[] = $idx; } elseif ($p->ctype_primary == 'text' && $p->ctype_secondary == 'plain') { if ($debug_file !== null || $debug) { $this->out("This part is text/plain.<br />\n"); } $has_text = true; $parts_text[] = $idx; } } if ($debug_file !== null || $debug) { $this->out("Preference is: {$textpref}.<br />\n"); } if ($textpref == 'text' && $has_html) { if ($debug_file !== null || $debug) { $this->out("Preference is text/plain.<br />\n"); } foreach ($parts_html as $pidx) { if ($debug_file !== null || $debug) { $this->out("Stripping HTML part {$pidx}, because preference is plaintext.<br />\n"); } unset($s->parts[$pidx]); } } if ($textpref == 'html' && $has_text) { if ($debug_file !== null || $debug) { $this->out("Preference is text/html.<br />\n"); } foreach ($parts_text as $pidx) { if ($debug_file !== null || $debug) { $this->out("Stripping text part {$pidx}, because preference is html.<br />\n"); } unset($s->parts[$pidx]); } } } foreach ($s->parts as $p) { if ($debug_file !== null || $debug) { $this->out("Analyzing mail:<br />\n Disposition: {$p->disposition}<br />\n Body: " . (isset($p->body) ? 'Set' : 'Not Set') . "<br />\n Primary CType: {$p->ctype_primary}<br />\n Secondary CType: {$p->ctype_secondary}<br />\n Filename: {$p->d_parameters[filename]}\n .<br />\n"); } // Handle msgs with attachments and messages with images that are inlined if (isset($p->disposition) and $p->disposition == 'attachment' and isset($p->body) or isset($p->disposition) and $p->disposition == 'inline' and isset($p->body) and $p->ctype_primary == 'image' or !empty($p->body) and $p->ctype_primary == 'image') { $this->handleImage($p, $debug, $debug_file, $tmobileflag, $adflag, $dirpath, $list_virus, $list_ignore, $plaintext_is_body_flag, $firsttext, $plaintext_use_extended_flag, $postex, $postbody, $dupcount, $maildir, $authorid, $list_imagetype, $list_imageext, $subject); } elseif (strtolower($p->ctype_primary) == 'text' and isset($p->body)) { if ($debug_file !== null || $debug) { $this->out("<br />\nRecognized text part.<br />\n"); } if (trim($subject) == SPRINTPCS_IDENT_PICTURE) { $p->body = sprintpcs_pictureshare($maildir, $p->body, $authorid); if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } if (trim($subject) == SPRINTPCS_IDENT_ALBUM) { $p->body = sprintpcs_albumshare($maildir, $p->body, $authorid); if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } if (trim($subject) == SPRINTPCS_IDENT_VIDEO) { $p->body = sprintpcs_videoshare($maildir, $p->body, $authorid); if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } if (stristr($subject, CINGULAR_IDENT_PICTURE)) { $p->body = cingular_photo($maildir, $p->body); if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } if (stristr($p->body, VERIZON_IDENT_PICTURE)) { $p->body = verizon_photo($maildir, $p->body); $verizonflag = true; if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } // Because text and HTML attachments get inlined // sometimes (notably Hotmail), // we want to collect them all and attach them to the // regular msg body $bodytext = trim($this->decode($p->body, $p->ctype_parameters['charset'])); if (empty($bodytext)) { continue; } // Strip evil HTML if (preg_match('@<body[^>]*>(.+)</body>@imsU', $bodytext, $m)) { if ($debug_file !== null || $debug) { $this->out("Reduced HTML text.<br />\n"); } $bodytext = $m[1]; } if ($adflag && preg_match('@T\\-Mobile MMS@', $bodytext) && preg_match('@http://www\\.T\\-Mobile\\.(de|nl|com)/mms@', $bodytext)) { if ($debug_file !== null || $debug) { $this->out("<br />\nSkipping T-Mobile ad.<br />\n"); } continue; } if ($firsttext && $plaintext_use_extended_flag) { $postex[] = $bodytext; } else { $postbody[] = $bodytext; $firsttext = true; } } elseif (is_array($p->parts)) { if ($debug_file !== null || $debug) { $this->out("<br />\nRecognized text/multipart.<br />\n"); } if ($textpref != 'both') { $has_html = false; $has_text = false; $parts_html = array(); $parts_text = array(); foreach ($p->parts as $idx => $subp) { if ($subp->ctype_primary == 'text' && $subp->ctype_secondary == 'html') { $has_html = true; $parts_html[] = $idx; } elseif ($subp->ctype_primary == 'text' && $subp->ctype_secondary == 'plain') { $has_text = true; $parts_text[] = $idx; } } if ($textpref == 'text' && $has_html) { foreach ($parts_html as $pidx) { if ($debug_file !== null || $debug) { $this->out("Stripping HTML part {$pidx}, because preference is plaintext.<br />\n"); } unset($p->parts[$pidx]); } } if ($textpref == 'html' && $has_text) { foreach ($parts_text as $pidx) { if ($debug_file !== null || $debug) { $this->out("Stripping text part {$pidx}, because preference is html.<br />\n"); } unset($p->parts[$pidx]); } } } foreach ($p->parts as $subpart) { if ($subpart->ctype_primary == 'text' && $subpart->ctype_secondary == 'html' && $o2flag) { $bodytext = trim($this->decode(popfetcher_provider_o2::getBody($subpart->body), $subpart->ctype_parameters['charset'])); if (empty($bodytext)) { continue; } if ($firsttext && $plaintext_use_extended_flag) { $postex[] = $bodytext; } else { $postbody[] = $bodytext; $firsttext = true; } } elseif ($subpart->ctype_primary == 'text') { $bodytext = trim($this->decode($subpart->body, $subpart->ctype_parameters['charset'])); if (preg_match('@<body[^>]*>(.+)</body>@imsU', $bodytext, $m)) { if ($debug_file !== null || $debug) { $this->out("Reduced HTML text.<br />\n"); } $bodytext = $m[1]; } if ($firsttext && $plaintext_use_extended_flag) { $postex[] = $bodytext; } else { $postbody[] = $bodytext; $firsttext = true; } } elseif ($subpart->ctype_primary == 'image') { // Handle inline multipart images $this->handleImage($subpart, $debug, $debug_file, $tmobileflag, $adflag, $dirpath, $list_virus, $list_ignore, $plaintext_is_body_flag, $firsttext, $plaintext_use_extended_flag, $postex, $postbody, $dupcount, $maildir, $authorid, $list_imagetype, $list_imageext, $subject); } } } else { if ($debug_file !== null || $debug) { $this->out("<br />\nRecognized unknown part.<br />\n"); } if ($p->disposition == 'inline' && isset($p->d_parameters['filename'])) { // Use makeFilename to get rid of spaces and other oddities $filename = serendipity_makeFilename($p->d_parameters['filename']); // if no file extension exists, add default .txt file extension if (!strrpos($filename, ".")) { $filename = $filename . 'txt'; } if ($debug_file !== null || $debug) { $this->out("<br />\nStoring attachment as {$filename}<br />\n"); } $this->out('<br />' . MF_MSG8 . $filename); $fullname = $dirpath . $filename; // Extract file extension and file name for various processing $ext = substr(strrchr($filename, "."), 0); $name = substr($filename, 0, strrpos($filename, ".")); // Skip message and all attachments if possible virus found $lext = strtolower($ext); if (in_array($lext, $list_virus)) { $output = MF_MSG19 . ': ' . $filename; $this->out('<br />' . $output . '<br />'); continue 2; } if (in_array($lext, $list_ignore)) { $this->out('<br />' . MF_MSG20 . '<br />'); continue; } // Check for duplicate filename. Give dup file name file.time().dup.ext if (is_file($fullname)) { $this->out('<br />' . MF_MSG14 . $filename); $name = $name . time() . $dupcount . 'dup'; $filename = $name . $ext; $fullname = $dirpath . $filename; $dupcount++; } $fp = fopen($fullname, 'w'); if (!$fp) { $this->out('<br />' . MF_ERROR5 . $fullname); return true; } fwrite($fp, $p->body); fclose($fp); serendipity_insertImageInDatabase($filename, $maildir, $authorid, NULL); $attlink = '<a class="popfetcherfile" href="' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $maildir . $filename . '" target="_blank">' . $filename . '</a>'; // Inline pictures to match the structure of the mail if ($plaintext_is_body_flag) { // Only the first image is embedded in body, or if no extended entry is used if (!$firstattachment || !$plaintext_use_extended_flag) { $postbody[] = $attlink; } else { $postex[] = $attlink; $firsttext = true; } } else { // Standard attachment mode $postattach[] = $attlink; } $firstattachment = true; $this->out('<br />' . MF_MSG13 . $filename); } $this->out('<br />' . MF_MSG9); // Tmobile sends a weird nested text and html // sub-attachment (at least the nokia does) if (isset($s->headers['x-operator']) and strtolower($s->headers['x-operator']) == TMOBILE_IDENT_PICTURE) { $p->body = tmobile_photo($maildir, $p->body); $tmobileflag = true; if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } } } if ($blogflag) { if (trim($subject) == SPRINTPCS_IDENT_ALBUM || trim($subject) == SPRINTPCS_IDENT_PICTURE || trim($subject) == SPRINTPCS_IDENT_VIDEO || stristr($subject, CINGULAR_IDENT_PICTURE) || ($verizonflag and $subject == MF_MSG17) || ($tmobileflag and $subject == MF_MSG17)) { $time = strtotime($s->headers['date']); $stamp = $time == -1 ? date("l, F j, Y, g:ia") : date("l, F j, Y, g:ia", $time); $subject = MF_MSG23 . $stamp; } $msgbody = implode("<br />\n", $postbody); $msgbody .= implode("<br />\n", $postattach); //New draft post $entry = $this->workEntry($subject, $msgbody, $useAuthor, $postex, $cid, $s); } } elseif (strtolower($s->ctype_primary) == 'text') { // Email msg with no attachments if ($blogflag) { if (trim($subject) == SPRINTPCS_IDENT_ALBUM || trim($subject) == SPRINTPCS_IDENT_PICTURE || trim($subject) == SPRINTPCS_IDENT_VIDEO || stristr($subject, CINGULAR_IDENT_PICTURE) || (stristr($s->body, VERIZON_IDENT_PICTURE) and $subject == MF_MSG17) || ($tmobileflag and $subject == MF_MSG17)) { $time = strtotime($s->headers['date']); $stamp = $time == -1 ? date("l, F j, Y, g:ia") : date("l, F j, Y, g:ia", $time); $subject = MF_MSG23 . $stamp; } $bodytext = trim($this->decode($s->body, $s->ctype_parameters['charset'])); $entry = $this->workEntry($subject, $bodytext, $useAuthor, $postex, $cid, $s); } else { $this->out('<br />' . MF_MSG20); } } else { $this->out('<br />' . MF_MSG10 . '<br />'); } } echo '<br /><hr />'; }