function parseXML($xml_content, $forced_encoding = null) { $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1); xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 0); $utf8_content = serendipity_utf8_encode($xml_content); xml_parse_into_struct($xml_parser, $utf8_content, $xml_array); xml_parser_free($xml_parser); return $xml_array; }
/** * Parses entries to display them for RSS/Atom feeds to be passed on to generic Smarty templates * * This function searches for existing RSS feed template customizations. As long as a template * with the same name as the $version variable exists, it will be emitted. * * @access public * @see serendipity_fetchEntries(), rss.php * @param array A superarray of entries to output * @param string The version/type of a RSS/Atom feed to display (atom1_0, rss2_0 etc) * @param boolean If true, this is a comments feed. If false, it's an Entry feed. * @param boolean Indicates if this feed is a fulltext feed (true) or only excercpt (false) * @param boolean Indicates if E-Mail addresses should be shown (true) or hidden (false) * @return */ function serendipity_printEntries_rss(&$entries, $version, $comments = false, $fullFeed = false, $showMail = true) { global $serendipity; $options = array('version' => $version, 'comments' => $comments, 'fullFeed' => $fullFeed, 'showMail' => $showMail); serendipity_plugin_api::hook_event('frontend_entries_rss', $entries, $options); if (is_array($entries)) { foreach ($entries as $key => $_entry) { $entry =& $entries[$key]; if (isset($entry['entrytimestamp'])) { $e_ts = $entry['entrytimestamp']; } else { $e_ts = $entry['timestamp']; } $entry['feed_id'] = isset($entry['entryid']) && !empty($entry['entryid']) ? $entry['entryid'] : $entry['id']; // set feed guid only, if not already defined externaly if (empty($entry['feed_guid'])) { $entry['feed_guid'] = serendipity_rss_getguid($entry, $options['comments']); } $entry['feed_entryLink'] = serendipity_archiveURL($entry['feed_id'], $entry['title'], 'baseURL', true, array('timestamp' => $e_ts)); if ($options['comments'] == true) { // Display username as part of the title for easier feed-readability if ($entry['type'] == 'TRACKBACK' && !empty($entry['ctitle'])) { $entry['author'] .= ' - ' . $entry['ctitle']; } $entry['title'] = (!empty($entry['author']) ? $entry['author'] : ANONYMOUS) . ': ' . $entry['title']; // No HTML allowed here: $entry['body'] = strip_tags($entry['body']); } // Embed a link to extended entry, if existing if ($options['fullFeed']) { $entry['body'] .= ' ' . $entry['extended']; $ext = ''; } elseif ($entry['exflag']) { $ext = '<br /><a href="' . $entry['feed_entryLink'] . '#extended">' . sprintf(VIEW_EXTENDED_ENTRY, htmlspecialchars($entry['title'])) . '</a>'; } else { $ext = ''; } $addData = array('from' => 'functions_entries:printEntries_rss', 'rss_options' => $options); serendipity_plugin_api::hook_event('frontend_display', $entry, $addData); // Do some relative -> absolute URI replacing magic. Replaces all HREF/SRC (<a>, <img>, ...) references to only the serendipitypath with the full baseURL URI // garvin: Could impose some problems. Closely watch this one. $entry['body'] = preg_replace('@(href|src)=("|\')(' . preg_quote($serendipity['serendipityHTTPPath']) . ')(.*)("|\')(.*)>@imsU', '\\1=\\2' . $serendipity['baseURL'] . '\\4\\2\\6>', $entry['body']); // jbalcorn: clean up body for XML compliance as best we can. $entry['body'] = xhtml_cleanup($entry['body']); // extract author information if (isset($entry['no_email']) && $entry['no_email'] || $options['showMail'] === FALSE) { $entry['email'] = '*****@*****.**'; // RSS Feeds need an E-Mail address! } elseif (empty($entry['email'])) { $query = "select email FROM {$serendipity['dbPrefix']}authors WHERE authorid = '" . serendipity_db_escape_string($entry['authorid']) . "'"; $results = serendipity_db_query($query); $entry['email'] = $results[0]['email']; } if (!is_array($entry['categories'])) { $entry['categories'] = array(0 => array('category_name' => $entry['category_name'], 'feed_category_name' => serendipity_utf8_encode(htmlspecialchars($entry['category_name'])), 'categoryURL' => serendipity_categoryURL($entry, 'baseURL'))); } else { foreach ($entry['categories'] as $cid => $_cat) { $cat =& $entry['categories'][$cid]; $cat['categoryURL'] = serendipity_categoryURL($cat, 'baseURL'); $cat['feed_category_name'] = serendipity_utf8_encode(htmlspecialchars($cat['category_name'])); } } // Prepare variables // 1. UTF8 encoding + htmlspecialchars. $entry['feed_title'] = serendipity_utf8_encode(htmlspecialchars($entry['title'])); $entry['feed_blogTitle'] = serendipity_utf8_encode(htmlspecialchars($serendipity['blogTitle'])); $entry['feed_title'] = serendipity_utf8_encode(htmlspecialchars($entry['title'])); $entry['feed_author'] = serendipity_utf8_encode(htmlspecialchars($entry['author'])); $entry['feed_email'] = serendipity_utf8_encode(htmlspecialchars($entry['email'])); // 2. gmdate $entry['feed_timestamp'] = gmdate('Y-m-d\\TH:i:s\\Z', serendipity_serverOffsetHour($entry['timestamp'])); $entry['feed_last_modified'] = gmdate('Y-m-d\\TH:i:s\\Z', serendipity_serverOffsetHour($entry['last_modified'])); $entry['feed_timestamp_r'] = date('r', serendipity_serverOffsetHour($entry['timestamp'])); // 3. UTF8 encoding $entry['feed_body'] = serendipity_utf8_encode($entry['body']); $entry['feed_ext'] = serendipity_utf8_encode($ext); $entry_hook = 'frontend_display:unknown:per-entry'; switch ($version) { case 'opml1.0': $entry_hook = 'frontend_display:opml-1.0:per_entry'; break; case '0.91': $entry_hook = 'frontend_display:rss-0.91:per_entry'; break; case '1.0': $entry_hook = 'frontend_display:rss-1.0:per_entry'; break; case '2.0': $entry_hook = 'frontend_display:rss-2.0:per_entry'; break; case 'atom0.3': $entry_hook = 'frontend_display:atom-0.3:per_entry'; break; case 'atom1.0': $entry_hook = 'frontend_display:atom-1.0:per_entry'; break; } serendipity_plugin_api::hook_event($entry_hook, $entry); $entry['per_entry_display_dat'] = $entry['display_dat']; } } }
function microformats_serendipity_show($params, &$smarty) { static $images = array(); global $serendipity; /*echo '<pre>'; print_r($serendipity); echo '</pre>';*/ $params['mf_type'] = $params['type']; /*echo '<pre>'; print_r($serendipity['smarty']); echo '</pre>';*/ switch ($params['mf_type']) { case 'hReview': $params['id'] = ''; if (!empty($params['data'])) { $params['name'] = $params['data']['mf_' . $params['mf_type'] . '_name']; $params['type'] = $params['data']['mf_' . $params['mf_type'] . '_type']; $params['url'] = $params['data']['mf_' . $params['mf_type'] . '_url']; $params['image'] = $params['data']['mf_' . $params['mf_type'] . '_image']; $params['rating'] = floatval($params['data']['mf_' . $params['mf_type'] . '_rating']); $params['summary'] = $params['data']['mf_' . $params['mf_type'] . '_summary']; $params['desc'] = $params['data']['mf_' . $params['mf_type'] . '_desc']; $params['date'] = $params['data']['mf_' . $params['mf_type'] . '_date']; //$params['timezone'] = $params['data']['mf_'.$params['mf_type'].'_timezone']; $params['reviewer'] = $params['data']['mf_' . $params['mf_type'] . '_reviewer']; } /*echo '<pre>'; print_r($params); echo '</pre>';*/ if (empty($params['name'])) { return ''; } if (empty($params['stars'])) { $params['stars'] = 0; } if (!empty($params['points'])) { $params['stars'] = $params['points'] / 2; } else { $params['points'] = $params['stars']; } if (empty($params['path'])) { $params['path'] = 'serendipityHTTPPath'; } if (!empty($params['who'])) { $params['tpl_who'] = '_' . $params['who']; } if (!isset($images[$params['path']][$params['mf_type']])) { $images[$params['path']][$params['mf_type']] = array('full' => microformats_serendipity_show_image(serendipity_getTemplateFile('img/star_' . $params['mf_type'] . '_full.png', $params['path']), '*'), 'half' => microformats_serendipity_show_image(serendipity_getTemplateFile('img/star_' . $params['mf_type'] . '_half.png', $params['path']), '.'), 'zero' => microformats_serendipity_show_image(serendipity_getTemplateFile('img/star_' . $params['mf_type'] . '_zero.png', $params['path']), 'o')); } $out = ''; for ($i = $params['stars']; $i >= 1; $i--) { $out .= $images[$params['path']][$params['mf_type']]['full']; } if ($i > 0) { $out .= $images[$params['path']][$params['mf_type']]['half']; $params['stars'] = $params['stars'] + 1; } for ($i = 5 - $params['stars']; $i > 0; $i--) { $out .= $images[$params['path']][$params['mf_type']]['zero']; } break; case 'hCalendar': $params['id'] = ''; if (!empty($params['data'])) { $params['summary'] = $params['data']['mf_' . $params['mf_type'] . '_summary']; $params['location'] = $params['data']['mf_' . $params['mf_type'] . '_location']; $params['url'] = $params['data']['mf_' . $params['mf_type'] . '_url']; $params['startdate'] = $params['data']['mf_' . $params['mf_type'] . '_startdate']; $params['enddate'] = $params['data']['mf_' . $params['mf_type'] . '_enddate']; $params['desc'] = $params['data']['mf_' . $params['mf_type'] . '_desc']; //$params['timezone'] = $params['data']['mf_'.$params['mf_type'].'_timezone']; } //echo '<pre>'; //print_r($params); //echo '</pre>'; if (empty($params['summary'])) { return ''; } break; } //$filename = 'microformats_' . $params['type'] . $params['tpl_who'] . '.tpl'; $filename = $params['mf_type'] . '.tpl'; $tfile = serendipity_getTemplateFile($filename, 'serendipityPath'); if (!$tfile || $tfile == $filename) { $tfile = dirname(__FILE__) . '/' . $filename; } $inclusion = $serendipity['smarty']->security_settings[INCLUDE_ANY]; $serendipity['smarty']->security_settings[INCLUDE_ANY] = true; switch ($params['mf_type']) { case 'hReview': $serendipity['smarty']->assign(array('hreview_summary' => $params['summary'], 'hreview_date' => microformats_calculate_date($params['date'], $serendipity['smarty']->_tpl_vars['timezone']), 'hreview_date_humanreadable' => date('d.m.Y H:i T', $params['date']), 'hreview_reviewer' => $params['reviewer'], 'hreview_type' => $params['type'], 'hreview_image' => $params['image'], 'hreview_url' => $params['url'], 'hreview_name' => $params['name'], 'hreview_desc' => $params['desc'], 'hreview_desc_escaped' => htmlentities($params['desc'], ENT_COMPAT, LANG_CHARSET), 'hreview_rating' => floor($params['rating']), 'hreview_ratingvalue' => $params['rating'], 'hreview_best' => (int) $serendipity['smarty']->_tpl_vars['best'])); echo 'Creating range from 1.0 to ' . $params['rating'] . '(' . floatval($params['rating']) . ') by ' . $serendipity['smarty']->_tpl_vars['step'] . '(' . floatval($serendipity['smarty']->get_template_vars('step')) . ')'; echo '<br />Best: ' . $serendipity['smarty']->_tpl_vars['best'] . '(' . $serendipity['smarty']->get_template_vars('best') . ')'; echo '<br />Name: ' . $serendipity['smarty']->_tpl_vars['hreview_name'] . '(' . $serendipity['smarty']->get_template_vars('hreview_name') . ')'; $loop = range(1.0, floatval($params['rating']), floatval($serendipity['smarty']->get_template_vars('step'))); foreach ($loop as $v) { $hreview_rating_symbols .= '♥'; } $serendipity['smarty']->assign(array('hreview_rating_symbols' => $hreview_rating_symbols)); //print_r($serendipity['smarty']); break; case 'hCalendar': $serendipity['smarty']->assign(array('hcalendar_summary' => $params['summary'], 'hcalendar_location' => $params['location'], 'hcalendar_url' => $params['url'], 'hcalendar_startdate' => microformats_calculate_date($params['startdate'], $serendipity['smarty']->_tpl_vars['timezone']), 'hcalendar_enddate' => microformats_calculate_date($params['enddate'], $serendipity['smarty']->_tpl_vars['timezone']), 'hcalendar_startdate_subnode' => date('Y-m-d', strtotime($params['startdate'])), 'hcalendar_startdate_humanreadable' => date('d.m.Y H:i T', $params['startdate']), 'hcalendar_enddate_humanreadable' => date('d.m.Y H:i T', $params['enddate']), 'hcalendar_desc' => $params['desc'], 'hcalendar_desc_escaped' => htmlentities($params['desc'], ENT_COMPAT, LANG_CHARSET))); break; } $content = $serendipity['smarty']->fetch('file:' . $tfile); $serendipity['smarty']->security_settings[INCLUDE_ANY] = $inclusion; if (!empty($params['escaped'])) { echo serendipity_utf8_encode(function_exists('serendipity_specialchars') ? serendipity_specialchars($content) : htmlspecialchars($content, ENT_COMPAT, LANG_CHARSET)); } else { echo $content; } }
function getFeedXmlForTags($element, $tagList) { $out = ''; if (!is_array($tagList)) { return $out; } foreach ($tagList as $tag) { $out .= serendipity_utf8_encode("<{$element}>" . (function_exists('serendipity_specialchars') ? serendipity_specialchars($tag) : htmlspecialchars($tag, ENT_COMPAT, LANG_CHARSET)) . "</{$element}>\n"); } return $out; }
function showRecursive($ary, &$xml, $child_name = 'id', $parent_name = 'parent_id', $parentid = 0) { global $serendipity; if (sizeof($ary) == 0) { return array(); } if ($parentid === VIEWMODE_THREADED) { $parentid = 0; } foreach ($ary as $data) { if ($parentid === VIEWMODE_LINEAR || !isset($data[$parent_name]) || $data[$parent_name] == $parentid) { echo '<outline title="' . serendipity_utf8_encode($data['category_name']) . '">' . "\n"; if (is_array($xml[$data['categoryid']])) { foreach ($xml[$data['categoryid']] as $feed) { if (empty($feed['feedurl'])) { continue; } printf(' <outline title="%s" xmlUrl="%s" htmlUrl="%s" description="%s" />' . "\n", serendipity_utf8_encode(function_exists('serendipity_specialchars') ? serendipity_specialchars($feed['feedname']) : htmlspecialchars($feed['feedname'], ENT_COMPAT, LANG_CHARSET)), serendipity_utf8_encode(function_exists('serendipity_specialchars') ? serendipity_specialchars($feed['feedurl']) : htmlspecialchars($feed['feedurl'], ENT_COMPAT, LANG_CHARSET)), serendipity_utf8_encode(function_exists('serendipity_specialchars') ? serendipity_specialchars($feed['htmlurl']) : htmlspecialchars($feed['htmlurl'], ENT_COMPAT, LANG_CHARSET)), serendipity_utf8_encode(function_exists('serendipity_specialchars') ? serendipity_specialchars($feed['feedname']) : htmlspecialchars($feed['feedname'], ENT_COMPAT, LANG_CHARSET))); } } if ($data[$child_name] && $parentid !== VIEWMODE_LINEAR) { $this->showRecursive($ary, $xml, $child_name, $parent_name, $data[$child_name]); } echo "</outline>\n"; } } return true; }
function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks =& $bag->get('event_hooks'); if (isset($hooks[$event])) { switch ($event) { case 'backend_sidebar_entries': ?> <li class="serendipitySideBarMenuLink serendipitySideBarMenuEntryLinks"><a href="?serendipity[adminModule]=event_display&serendipity[adminAction]=mycalendar"><?php echo PLUGIN_MYCALENDAR_TITLE; ?> </a></li> <?php break; case 'backend_sidebar_entries_event_display_mycalendar': $this->showevents(); break; case 'external_plugin': if ($eventData == 'mycalendar.rss') { $plugins = serendipity_plugin_api::enum_plugins('*', false, 'serendipity_plugin_mycalendar', null); if (!is_array($plugins)) { return; } foreach ($plugins as $plugin_data) { $plugin =& serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid'], $plugin_data['path']); } if (!is_object($plugin)) { return; } $items = $plugin->generate_content($eventData, true); header('Content-Type: text/xml; charset=UTF-8'); echo '<?xml version="1.0" encoding="utf-8" ?>' . "\n"; ?> <rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:admin="http://webns.net/mvcb/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:content="http://purl.org/rss/1.0/modules/content/" > <channel> <title><?php echo $serendipity['blogTitle'] . ' - ' . PLUGIN_MYCALENDAR_TITLE; ?> </title> <link><?php echo $serendipity['baseURL']; ?> </link> <description><?php echo PLUGIN_MYCALENDAR_SIDE_NAME; ?> </description> <generator>Serendipity - http://www.s9y.org/</generator> <?php foreach ($items as $item) { ?> <item> <title><?php echo serendipity_utf8_encode(function_exists('serendipity_specialchars') ? serendipity_specialchars($item['title']) : htmlspecialchars($item['title'], ENT_COMPAT, LANG_CHARSET)); ?> </title> <link><?php echo serendipity_utf8_encode(function_exists('serendipity_specialchars') ? serendipity_specialchars($item['url']) : htmlspecialchars($item['url'], ENT_COMPAT, LANG_CHARSET)); ?> </link> <author><?php echo $serendipity['blogTitle']; ?> </author> <content:encoded> <?php echo serendipity_utf8_encode(function_exists('serendipity_specialchars') ? serendipity_specialchars($item['content']) : htmlspecialchars($item['content'], ENT_COMPAT, LANG_CHARSET)); ?> </content:encoded> <pubDate><?php echo $item['date']; ?> </pubDate> <guid isPermaLink="false"><?php echo serendipity_utf8_encode(function_exists('serendipity_specialchars') ? serendipity_specialchars($item['url']) : htmlspecialchars($item['url'], ENT_COMPAT, LANG_CHARSET)); ?> </guid> </item> <?php } ?> </channel> </rss> <?php } break; case 'frontend_calendar': $this->get_month_events($eventData, $addData); break; } } return true; }
} break; } if (isset($serendipity['serendipityRealname'])) { $title .= ' (' . LOGIN . ': ' . $serendipity['serendipityRealname'] . ')'; } if (!empty($serendipity['GET']['category'])) { $cInfo = serendipity_fetchCategoryInfo((int) $serendipity['GET']['category']); $title = serendipity_utf8_encode(htmlspecialchars($title . ' - ' . $cInfo['category_name'])); } elseif (!empty($serendipity['GET']['viewAuthor'])) { list($aInfo) = serendipity_fetchAuthor((int) $serendipity['GET']['viewAuthor']); $title = serendipity_utf8_encode(htmlspecialchars($aInfo['realname'] . ' - ' . $title)); } else { $title = serendipity_utf8_encode(htmlspecialchars($title)); } $description = serendipity_utf8_encode(htmlspecialchars($description)); $metadata = array('title' => $title, 'description' => $description, 'language' => $serendipity['lang'], 'additional_fields' => array(), 'link' => $serendipity['baseURL'], 'email' => $serendipity['blogMail'], 'fullFeed' => false, 'showMail' => false, 'version' => $version); if (!defined('S9Y_FRAMEWORK_PLUGIN_API')) { include S9Y_INCLUDE_PATH . 'include/plugin_api.inc.php'; } $plugins = serendipity_plugin_api::enum_plugins(); if (is_array($plugins)) { // load each plugin to make some introspection foreach ($plugins as $plugin_data) { if (preg_match('|@serendipity_syndication_plugin|', $plugin_data['name'])) { $plugin =& serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid']); $metadata['additional_fields'] = $plugin->generate_rss_fields($metadata['title'], $metadata['description'], $entries); if (is_array($metadata['additional_fields'])) { // Fix up array keys, because "." are not allowed when wanting to output using Smarty foreach ($metadata['additional_fields'] as $_aid => $af) { $aid = str_replace('.', '', $_aid);
/** * event hook: frontend_display:feeds (rss/atom) * * @param string XML element * @param array $eventData['properties']['freetag_tags'] * @return string XML element per tag */ function getFeedXmlForTags($element, $tagList) { $out = ''; if (!is_array($tagList)) { return $out; } foreach ($tagList as $tag) { $out .= serendipity_utf8_encode("<{$element}>" . self::specialchars_mapper($tag) . "</{$element}>\n"); } return $out; }
function communityrating_serendipity_show($params, &$smarty) { static $images = array(); global $serendipity; if (empty($params['type'])) { $params['type'] = 'IMDB'; } $params['id'] = ''; if (!empty($params['data'])) { $params['points'] = $params['data']['cr_' . $params['type'] . '_rating']; $params['id'] = $params['data']['cr_' . $params['type'] . '_id']; } if (empty($params['stars'])) { $params['stars'] = 0; } if (!empty($params['url'])) { $url = $params['url'] . '_' . $params['type'] . '_' . $params['id']; $cache = $serendipity['smarty']->compile_dir . '/cr_' . md5($url); if (!file_exists($cache) || filemtime($cache) < time() - 604800) { $fp = @fopen($cache, 'a'); if ($fp) { fwrite($fp, date('d.m.Y H:i')); fclose($fp); } require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; $req = new HTTP_Request($url); if (!PEAR::isError($req->sendRequest()) || $req->getResponseCode() == '200') { $data = $req->getResponseBody(); $id = ''; if (preg_match('@<rating>(.+)</rating>@imsU', $data, $match)) { $id = $match[1]; } $url = ''; if (preg_match('@<url>(.+)</url>@imsU', $data, $match)) { $url = $match[1]; } $fp = fopen($cache . '.id', 'w'); if ($fp) { fwrite($fp, $id); fclose($fp); } $fp = fopen($cache . '.url', 'w'); if ($fp) { fwrite($fp, $url); fclose($fp); } } } $params['points'] = (int) @file_get_contents($cache . '.id'); $params['foreign_url'] = @file_get_contents($cache . '.url'); } if (!empty($params['points'])) { $params['stars'] = $params['points'] / 2; } else { $params['points'] = $params['stars']; } if ($params['points'] < 1) { return ''; } if (empty($params['path'])) { $params['path'] = 'serendipityHTTPPath'; } if (!empty($params['who'])) { $params['tpl_who'] = '_' . $params['who']; } if (!isset($images[$params['path']][$params['type']])) { $images[$params['path']][$params['type']] = array('full' => communityrating_serendipity_show_image(serendipity_getTemplateFile('img/star_' . $params['type'] . '_full.png', $params['path']), '*'), 'half' => communityrating_serendipity_show_image(serendipity_getTemplateFile('img/star_' . $params['type'] . '_half.png', $params['path']), '.'), 'zero' => communityrating_serendipity_show_image(serendipity_getTemplateFile('img/star_' . $params['type'] . '_zero.png', $params['path']), 'o')); } $out = ''; for ($i = $params['stars']; $i >= 1; $i--) { $out .= $images[$params['path']][$params['type']]['full']; } if ($i > 0) { $out .= $images[$params['path']][$params['type']]['half']; $params['stars'] = $params['stars'] + 1; } for ($i = 5 - $params['stars']; $i > 0; $i--) { $out .= $images[$params['path']][$params['type']]['zero']; } $filename = 'communityrating_' . $params['type'] . $params['tpl_who'] . '.tpl'; $tfile = serendipity_getTemplateFile($filename, 'serendipityPath'); if (!$tfile || $tfile == $filename) { $tfile = dirname(__FILE__) . '/' . $filename; } $inclusion = $serendipity['smarty']->security_settings[INCLUDE_ANY]; $serendipity['smarty']->security_settings[INCLUDE_ANY] = true; $serendipity['smarty']->assign(array('communityrating_images' => $out, 'communityrating_rating' => $params['points'], 'communityrating_type' => $params['type'], 'communityrating_id' => $params['id'], 'communityrating_foreign_url' => $params['foreign_url'])); $content = $serendipity['smarty']->fetch('file:' . $tfile); $serendipity['smarty']->security_settings[INCLUDE_ANY] = $inclusion; if (!empty($params['escaped'])) { echo serendipity_utf8_encode(function_exists('serendipity_specialchars') ? serendipity_specialchars($content) : htmlspecialchars($content, ENT_COMPAT, LANG_CHARSET)); } else { echo $content; } }
function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks =& $bag->get('event_hooks'); if (isset($hooks[$event])) { switch ($event) { case 'backend_sidebar_entries_event_display_linklist': if ($this->get_config('active') != 'true') { return false; } if (isset($_POST['REMOVE'])) { if (isset($_POST['serendipity']['link_to_remove'])) { foreach ($_POST['serendipity']['link_to_remove'] as $key) { $this->del_link($key); } } else { if (isset($_POST['serendipity']['category_to_remove'])) { foreach ($_POST['serendipity']['category_to_remove'] as $key) { $this->del_category($key); } } } } if (isset($_POST['SAVE'])) { foreach ($_POST['serendipity']['link_to_recat'] as $key => $row) { $this->update_cat($key, $row); } } if (isset($_POST['ADD'])) { if (isset($_POST['serendipity']['add_link']['title']) && isset($_POST['serendipity']['add_link']['link'])) { $this->add_link($_POST['serendipity']['add_link']['link'], $_POST['serendipity']['add_link']['title'], $_POST['serendipity']['add_link']['desc'], $_POST['serendipity']['link_to_recat']['cat']); } else { if (isset($_POST['serendipity']['add_category']['title'])) { $this->add_cat($_POST['serendipity']['add_category']['title'], $_POST['serendipity']['link_to_recat']['cat']); } } } if (isset($_POST['EDIT'])) { if (isset($_POST['serendipity']['add_link']['title']) && isset($_POST['serendipity']['add_link']['link']) && isset($_POST['serendipity']['add_link']['id'])) { $this->update_link($_POST['serendipity']['add_link']['id'], $_POST['serendipity']['add_link']['link'], $_POST['serendipity']['add_link']['title'], $_POST['serendipity']['add_link']['desc'], $_POST['serendipity']['link_to_recat']['cat']); } } switch ($_GET['submit']) { case 'move up': $this->move_up($_GET['serendipity']['link_to_move']); break; case 'move down': $this->move_down($_GET['serendipity']['link_to_move']); break; } if ($this->get_config('cache') == 'yes') { if (@(include_once "Cache/Lite.php")) { $cache_obj = new Cache_Lite(array('cacheDir' => $serendipity['serendipityPath'] . 'templates_c/', 'automaticSerialization' => true)); $output = $this->generate_output(true); $cache_obj->save($output, 'linklist_cache'); } else { $output = $this->generate_output(true); $this->set_config('cached_output', $output); } } if (isset($_GET['serendipity']['edit_link'])) { $this->output_add_edit_linkadmin(TRUE, $_GET['serendipity']['edit_link']); } else { if (isset($_GET['serendipity']['manage_category'])) { $this->output_categoryadmin(TRUE, $_GET['serendipity']['edit_link']); } else { $this->output_add_edit_linkadmin(FALSE); $this->output_linkadmin(); } } return true; break; case 'backend_sidebar_entries': if ($this->get_config('active') == 'true' && $serendipity['version'][0] < 2) { echo "\n" . '<li class="serendipitySideBarMenuLink serendipitySideBarMenuEntryLinks"><a href="?serendipity[adminModule]=event_display&serendipity[adminAction]=linklist">' . PLUGIN_LINKLIST_ADMINLINK . '</a></li>'; } return true; break; case 'backend_sidebar_admin_appearance': if ($this->get_config('active') == 'true' && $serendipity['version'][0] > 1) { echo "\n" . '<li><a href="?serendipity[adminModule]=event_display&serendipity[adminAction]=linklist">' . PLUGIN_LINKLIST_ADMINLINK . '</a></li>'; } return true; break; case 'css': if ($this->get_config('style') == 'dtree') { $searchstr = '.dtree'; $filename = 'serendipity_event_dtree.css'; } else { $searchstr = '.linklist'; $filename = 'serendipity_event_linklist.css'; } // class exists in CSS by another Plugin, or a User has customized it and we don't need default $pos = strpos($eventData, $searchstr); if ($pos === false) { $tfile = serendipity_getTemplateFile($filename, 'serendipityPath'); if (!$tfile || $tfile == $filename) { $tfile = dirname(__FILE__) . '/' . $filename; } $eventData .= file_get_contents($tfile); } return true; break; case 'external_plugin': $uri_parts = explode('?', str_replace('&', '&', $eventData)); $parts = explode('&', $uri_parts[0]); $uri_part = $parts[0]; switch ($uri_part) { case 'lldtree.js': // name unique! header('Content-Type: text/javascript'); echo file_get_contents(dirname(__FILE__) . '/dtree.js'); break; case 'linklist.js': header('Content-Type: text/javascript'); echo file_get_contents(dirname(__FILE__) . '/linklist.js'); break; } return true; break; case 'plugins_linklist_input': $eventData['links'] = $this->generate_output(false); return true; break; case 'plugins_linklist_conf': $this->set_config('style', $eventData['style']); $this->set_config('display', $eventData['display']); $this->set_config('category', $eventData['category']); $this->set_config('cache', $eventData['cache']); $eventData['changed'] = 'false'; if ($eventData['enabled'] == 'true') { if ($this->get_config('active') != 'true') { $eventData['changed'] = 'true'; $this->set_config('active', 'true'); $this->set_config('active', 'true'); $this->set_config('category', 'custom'); $q = 'SELECT count(id) FROM ' . $serendipity['dbPrefix'] . 'links'; $sql = serendipity_db_query($q); if ($sql[0][0] == 0) { $xml = xml_parser_create('UTF-8'); xml_parse_into_struct($xml, '<list>' . serendipity_utf8_encode($eventData['links']) . '</list>', $struct, $index); xml_parser_free($xml); $depth = -1; for ($level[] = 0, $i = 1, $j = 1; isset($struct[$i]); $i++, $j++) { if (isset($struct[$i]['type'])) { if ($struct[$i]['type'] == 'open' && strtolower($struct[$i]['tag']) == 'dir') { $this->add_cat($this->decode($struct[$i]['attributes']['NAME']), $in_cat[0]); $q = 'SELECT categoryid FROM ' . $serendipity['dbPrefix'] . 'link_category where category_name = "' . serendipity_db_escape_string($this->decode($struct[$i]['attributes']['NAME'])) . '"'; $sql = serendipity_db_query($q); $in_cat[] = $sql[0][0]; $depth++; } else { if ($struct[$i]['type'] == 'close' && strtolower($struct[$i]['tag']) == 'dir') { $blah = array_pop($in_cat); $depth--; } else { if ($struct[$i]['type'] == 'complete' && strtolower($struct[$i]['tag']) == 'link') { $this->add_link($this->decode($struct[$i]['attributes']['LINK']), $this->decode($struct[$i]['attributes']['NAME']), $this->decode($struct[$i]['attributes']['DESCRIP']), $in_cat[$depth]); } } } } } } if ($eventData['cache'] == 'yes') { if (@(include_once "Cache/Lite.php")) { $cache_obj = new Cache_Lite(array('cacheDir' => $serendipity['serendipityPath'] . 'templates_c/', 'automaticSerialization' => true)); $output = $this->generate_output(true); $eventData['links'] = $output; $cache_obj->save($output, 'linklist_cache'); } else { $output = $this->generate_output(true); $eventData['links'] = $output; $this->set_config('cached_output', $output); } } } } else { if ($this->get_config('active') == 'true') { $this->set_config('active', 'false'); $this->set_config('cache', 'no'); $this->set_config('display', 'category'); $eventData['links'] = $this->generate_output(true); if (@(include_once "Cache/Lite.php")) { $cache_obj = new Cache_Lite(array('cacheDir' => $serendipity['serendipityPath'] . 'templates_c/', 'automaticSerialization' => true)); @$cache_obj->remove('linklist_cache'); } else { $this->set_config('cached_output', ''); } $eventData['changed'] = 'true'; } } return true; break; default: return false; break; } } else { return false; } }
function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks =& $bag->get('event_hooks'); if (isset($hooks[$event])) { switch ($event) { case 'backend_display': $props =& $this->getSupportedProperties(); ?> <fieldset style="margin: 5px"> <legend><?php echo PLUGIN_EVENT_COMMUNITYRATING_TITLE; ?> </legend> <?php foreach ($props as $prop => $prop_val) { if (preg_match('@_(id|rating)$@', $prop)) { continue; } $vals = array('id' => '', 'rating' => ''); foreach ($vals as $vidx => $val) { if (isset($eventData['properties']['cr_' . $prop . '_' . $vidx])) { $vals[$vidx] = $eventData['properties']['cr_' . $prop . '_' . $vidx]; } elseif (isset($serendipity['POST']['properties'][$prop . '_' . $vidx])) { $vals[$vidx] = $serendipity['POST']['properties'][$prop . '_' . $vidx]; } else { $vals[$vidx] = ''; } } ?> <strong><?php echo $prop; ?> :</strong><br /> <label title="<?php echo PLUGIN_EVENT_COMMUNITYRATING_ID; ?> " for="properties_rating_id"><?php echo PLUGIN_EVENT_COMMUNITYRATING_ID; ?> </label>: <input class="input_textbox" id="properties_rating_id" type="text" name="serendipity[properties][<?php echo $prop . '_id'; ?> ]" value="<?php echo function_exists('serendipity_specialchars') ? serendipity_specialchars($vals['id']) : htmlspecialchars($vals['id'], ENT_COMPAT, LANG_CHARSET); ?> " size="10" /> <label title="<?php echo PLUGIN_EVENT_COMMUNITYRATING_RATING; ?> " for="properties_rating_points"><?php echo PLUGIN_EVENT_COMMUNITYRATING_RATING; ?> </label>: <input class="input_textbox" id="properties_rating_points" type="text" name="serendipity[properties][<?php echo $prop . '_rating'; ?> ]" value="<?php echo function_exists('serendipity_specialchars') ? serendipity_specialchars($vals['rating']) : htmlspecialchars($vals['rating'], ENT_COMPAT, LANG_CHARSET); ?> " size="2" /> <br /> <?php } ?> </fieldset> <?php return true; break; case 'backend_publish': case 'backend_save': if (!isset($serendipity['POST']['properties']) || !is_array($serendipity['POST']['properties']) || !isset($eventData['id'])) { return true; } $this->addProperties($serendipity['POST']['properties'], $eventData); return true; break; case 'entry_display': $this->smarty_init(); // PH: This is done after Garvins suggestion to patchup $eventData in case an entry // is in the process of being created. This must be done for the extended properties // to be applied in the preview. if (is_array($serendipity['POST']['properties']) && count($serendipity['POST']['properties']) > 0) { $parr = array(); $supported_properties =& $this->getSupportedProperties(); foreach ($supported_properties as $prop_key => $prop_val) { if (isset($serendipity['POST']['properties'][$prop_key])) { $eventData[0]['properties']['cr_' . $prop_key] = $serendipity['POST']['properties'][$prop_key]; } } } break; case 'frontend_fetchentries': case 'frontend_rss': $this->smarty_init(); break; case 'external_plugin': $params = explode('_', $eventData); if ($params[0] == 'communityrating') { $type = serendipity_db_escape_string($params[1]); $id = serendipity_db_escape_string($params[2]); if ($id == 'all') { $sql = "SELECT e.title, e.timestamp, p1.property, p1.entryid, p2.value, p1.value AS backupvalue\n FROM {$serendipity['dbPrefix']}entryproperties AS p1\n LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties AS p2\n ON (p2.entryid = p1.entryid AND p2.property = 'cr_{$type}_rating')\n LEFT OUTER JOIN {$serendipity['dbPrefix']}entries AS e\n ON p2.entryid = e.id\n WHERE (p1.property = 'cr_{$type}_id')\n OR (p1.property LIKE 'cr_{$type}_rating:%')\n ORDER BY p2.value DESC"; } else { $sql = "SELECT e.title, e.timestamp, p1.property, p1.entryid, p2.value, p1.value AS backupvalue\n FROM {$serendipity['dbPrefix']}entryproperties AS p1\n LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties AS p2\n ON (p2.entryid = p1.entryid AND p2.property = 'cr_{$type}_rating')\n LEFT OUTER JOIN {$serendipity['dbPrefix']}entries AS e\n ON p2.entryid = e.id\n WHERE (p1.property = 'cr_{$type}_id' AND p1.value = '{$id}')\n OR (p1.property = 'cr_{$type}_rating:{$id}')\n ORDER BY p2.value DESC\n LIMIT 1"; } $rows = serendipity_db_query($sql, false, 'assoc'); header('HTTP/1.0 200'); header('Status: 200 OK'); header('Content-Type: text/xml'); echo '<?xml version="1.0" encoding="UTF-8" ?>' . "\n"; echo '<communityratings>' . "\n"; if (is_array($rows)) { foreach ($rows as $row) { if ($id == 'all') { if (preg_match('@:(.*)$@', $row['property'], $match)) { $cid = $match[1]; } else { $cid = $row['backupvalue']; } } else { $cid = $id; } echo '<communityrating>' . "\n"; echo '<id>' . serendipity_utf8_encode($cid) . '</id>' . "\n"; if (empty($row['value'])) { $row['value'] = $row['backupvalue']; } echo '<rating>' . serendipity_utf8_encode($row['value']) . '</rating>' . "\n"; if ($row['entryid'] > 0) { echo '<url>' . serendipity_utf8_encode(serendipity_archiveURL($row['entryid'], $row['title'], 'baseURL', true, array('timestamp' => $row['timestamp']))) . '</url>' . "\n"; } echo '</communityrating>' . "\n"; } } echo '</communityratings>' . "\n"; } default: return false; break; } } else { return false; } }
function gen_output($links, $style) { global $serendipity; $imgdir = $this->get_config('imgdir'); $use_descrip = $this->get_config('use_description', false); /* XML definitaion */ $xml = xml_parser_create('UTF-8'); $linkxml = serendipity_utf8_encode($links); xml_parse_into_struct($xml, '<list>' . $linkxml . '</list>', $struct, $index); xml_parser_free($xml); if ($imgdir === 1 or $imgdir === "true" or $imgdir === true or $imgdir === "") { $imgdir = $serendipity['baseURL'] . 'plugins/' . $plugin_dir; } $str = $this->get_config('prepend_text'); $str .= "\n\n"; if ($style == "dtree") { $str .= "\n" . '<script src="' . $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/lldtree.js" type="text/javascript"></script>' . "\n"; if ($this->get_config('showOpenAndCloseLinks') == 'true' && $this->get_config('locationOfOpenAndClose') == 'top') { $str .= '<p><a href="javascript: d.openAll();">' . $this->get_config('openAllText') . '</a> | <a href="javascript: d.closeAll();">' . $this->get_config('closeAllText') . '</a></p>'; } $str .= '<script type="text/javascript"> <!-- d = new dTree("d","' . $imgdir . '");' . "\n"; /* configuration section*/ if ($this->get_config('useSelection') != true) { $str .= 'd.config.useSelection=false;' . "\n"; } if ($this->get_config('useCookies') != true) { $str .= 'd.config.useCookies=false;' . "\n"; } if ($this->get_config('useLines') != true) { $str .= 'd.config.useLines=false;' . "\n"; } if ($this->get_config('useIcons') != true) { $str .= 'd.config.useIcons=false;' . "\n"; } if ($this->get_config('useStatusText') == true) { $str .= 'd.config.useStatusText=true;' . "\n"; } if ($this->get_config('closeSameLevel') == true) { $str .= 'd.config.closeSameLevel=true;' . "\n"; } $my_target = $this->get_config('target'); if (!empty($my_target)) { $str .= 'd.config.target="' . $my_target . '";' . "\n"; } /* Add Directory and Links */ $str .= 'd.add(0,-1,"' . $this->get_config('top_level') . '");' . "\n"; for ($level[] = 0, $i = 1, $j = 1; isset($struct[$i]); $i++, $j++) { if (isset($struct[$i]['type'])) { if ($struct[$i]['type'] == 'open' && strtolower($struct[$i]['tag']) == 'dir') { $str .= 'd.add(' . $j . ',' . $level[count($level) - 1] . ',"' . $this->decode($struct[$i]['attributes']['NAME']) . '");' . "\n"; $level[] = $j; } else { if ($struct[$i]['type'] == 'close' && strtolower($struct[$i]['tag']) == 'dir') { $dump = array_pop($level); } else { if ($struct[$i]['type'] == 'complete' && strtolower($struct[$i]['tag']) == 'link') { if (isset($struct[$i]['attributes']['NAME']) && $struct[$i]['attributes']['NAME'] != "" && $use_descrip) { $title_text = $this->decode($struct[$i]['attributes']['DESCRIP']); } else { $title_text = $struct[$i]['attributes']['NAME']; } $str .= 'd.add(' . $j . ',' . $level[count($level) - 1] . ',"' . $this->decode($struct[$i]['attributes']['NAME']) . '","' . $this->decode($struct[$i]['attributes']['LINK']) . '","' . $title_text . '");' . $delimiter; } } } } } $str .= 'document.write(d); //--> </script>'; if ($this->get_config('showOpenAndCloseLinks') == 'true' && $this->get_config('locationOfOpenAndClose') == 'bottom') { $str .= '<p><a href="javascript: d.openAll();">' . $this->get_config('openAllText') . '</a> | <a href="javascript: d.closeAll();">' . $this->get_config('closeAllText') . '</a></p>'; } } else { if ($this->get_config('call_markup') != 'true') { $delimiter = "\n"; } else { $delimiter = ""; } if ($this->get_config('style') == "simp_css") { $lessformatting = TRUE; } else { $lessformatting = FALSE; } //Parse it to a simple array $link_array = array(); $dirname = array(); $level = array(); $dir_array[''] = array('dirname' => '', 'level' => 1, linkcount => 0, 'links' => $link_array, 'dircount' => 0, 'directories' => $link_array); for ($level[] = 0, $i = 1, $j = 1; isset($struct[$i]); $i++, $j++) { if (isset($struct[$i]['type'])) { if ($struct[$i]['type'] == 'open' && strtolower($struct[$i]['tag']) == 'dir') { $dir_array[$dirname[0]]['directories'][] = $this->decode($struct[$i]['attributes']['NAME']); $dir_array[$dirname[0]]['dircount']++; array_unshift($dirname, $this->decode($struct[$i]['attributes']['NAME'])); array_unshift($level, $j); $dir_array[$dirname[0]] = array('dirname' => $dirname[0], 'level' => count($level), 'linkcount' => 0, 'links' => $link_array, 'dircount' => 0, 'directories' => $link_array); } else { if ($struct[$i]['type'] == 'close' && strtolower($struct[$i]['tag']) == 'dir') { $dump = array_shift($dirname); $dump = array_shift($level); } else { if ($struct[$i]['type'] == 'complete' && strtolower($struct[$i]['tag']) == 'link') { $dir_array[$dirname[0]]['linkcount']++; if (count($level) == 0) { $level_pass = 1; } else { $level_pass = count($level) + 1; } $basic_array = array('linkloc' => $this->decode($struct[$i]['attributes']['LINK']), 'name' => $this->decode($struct[$i]['attributes']['NAME']), 'descr' => $this->decode($struct[$i]['attributes']['DESCRIP']), 'level' => $level_pass, 'dirname' => $dirname, 'hcard' => $this->decode($struct[$i]['attributes']['HCARD']), 'rel' => $this->decode($struct[$i]['attributes']['REL'])); $dir_array[$dirname[0]]['links'][] = $basic_array; } } } } } /* ??? //Process array into output if ($this->get_config('useIcons')) { } else { } */ $imagear['imgdir'] = $imgdir; $imagear['uselines'] = $this->get_config('useLines'); $imagear['useicons'] = $this->get_config('useIcons'); if ($imagear['useicons']) { $imagear['folder'] = '/img/folder.gif'; $imagear['folderopen'] = '/img/folderopen.gif'; $imagear['page'] = '/img/page.gif'; } if ($this->get_config('useLines')) { $imagear['line'] = '/img/line.gif'; $imagear['join'] = '/img/join.gif'; $imagear['joinBottom'] = '/img/joinbottom.gif'; $imagear['plus'] = '/img/plus.gif'; $imagear['plusBottom'] = '/img/plusbottom.gif'; $imagear['minus'] = '/img/minus.gif'; $imagear['minusBottom'] = '/img/minusbottom.gif'; $imagear['empty_image'] = '/img/empty.gif'; } else { $imagear['line'] = '/img/empty.gif'; $imagear['join'] = '/img/empty.gif'; $imagear['joinBottom'] = '/img/empty.gif'; $imagear['plus'] = '/img/nolines_plus.gif'; $imagear['plusBottom'] = '/img/nolines_plus.gif'; $imagear['minus'] = '/img/nolines_minus.gif'; $imagear['minusBottom'] = '/img/nolines_minus.gif'; $imagear['empty_image'] = '/img/empty.gif'; } if (!$lessformatting) { $str .= '<script src="' . $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/linklist.js" type="text/javascript"></script>' . "\n"; } $class = !$lessformatting ? 'csslist' : 'simple'; $str .= '<div class="linklist"><ul class="' . $class . '">' . $delimiter; $more_track = array(); $str .= $this->build_tree($dir_array, "", $imagear, $more_track, $strtemp, $lessformatting, $delimiter, $use_descrip); $str .= '</ul></div>'; } $str .= $this->get_config('append_text'); if ($this->get_config('call_markup') == 'true') { $entry = array('html_nugget' => $str); serendipity_plugin_api::hook_event('frontend_display', $entry); return $entry['html_nugget']; } else { return $str; } }