/branches/coding-style/fp-includes/core/core.theme.php
PHP | 743 lines | 391 code | 49 blank | 303 comment | 45 complexity | 180068b27b0a92a54e2493f8e873f501 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, MIT
- <?php
- /**
- * Enter description here...
- *
- * @global $fp_config, $theme, $FLATPRESS
- * @return array
- */
- function theme_loadsettings() {
- global $fp_config, $theme, $FLATPRESS;
- $theme = array(
- 'name' => 'theme', // name of the theme
- 'author' => 'anonymous',// author of the theme
- 'www' => 'http://flatpress.nowhereland.it',// theme website
- 'version' => -1,// fp version
- 'style' => array(
- 'style_def' => 'style.css',// default style (must be in res/ dir
- 'style_admin' => 'style.css',// default style for admin panel (usually it's the same of the theme)
- ),
- // if false a default css is used to style some elements of the panel
- // if true, we'll suppose these elements are already styled in your own css's
- 'admin_custom_interf' => false
- );
- if (!defined('THE_THEME')) {
- define('THE_THEME', $fp_config['general']['theme']);
- }
- // backward compatibility:
- $conf1 = THEMES_DIR . THE_THEME . '/theme_conf.php';
- /*
- new naming convention. Yeah, I know, just an underscore
- instead of the dot, so? It is more "consistent" :D
- */
- $conf2 = THEMES_DIR . THE_THEME . '/theme.conf.php';
- ob_start();
- if (file_exists($conf2)) {
- include($conf2);
- } elseif (file_exists($conf1)) {
- include($conf1);
- }
- if (!defined('THEME_LEGACY_MODE')) {
- if ($theme['version'] < 0.702) {
- define('THEME_LEGACY_MODE', true);
- theme_register_default_widgetsets();
- } else {
- define('THEME_LEGACY_MODE', false);
- if (isset($theme['default_style'])) {
- if (!isset($fp_config['general']['style'])) {
- $fp_config['general']['style'] = $theme['default_style'];
- }
- include(THEMES_DIR . THE_THEME .'/'. $fp_config['general']['style'] .'/style.conf.php');
- $theme['style'] = $style;
- } else {
- $theme['style'] = array(
- 'style_def' => $theme['style_def']
- ? $theme['style_def']
- : 'style.css',
- 'style_admin' => $theme['style_admin']
- ? $theme['style_admin']
- : 'style.css',
- );
- }
- }
- // no widgets registered, load default set
- if (!get_registered_widgets()) {
- theme_register_default_widgetsets();
- }
- }
- ob_end_clean();
- return $theme;
- }
- /**
- * Registers the four default widget sets.
- *
- */
- function theme_register_default_widgetsets() {
- register_widgetset('left');
- register_widgetset('right');
- register_widgetset('top');
- register_widgetset('bottom');
- }
- /**
- * Enter description here...
- *
- * @param string $id
- * @return string
- */
- function theme_getdir($id = THE_THEME) {
- return theme_exists($id);
- }
- /**
- * Enter description here...
- *
- * @param string $id
- * @return string
- */
- function theme_exists($id) {
- // quick fix for win
- $f = THEMES_DIR . $id;
- if (file_exists($f)) {
- return $f .'/';
- }
- return '';
- }
- /**
- * Enter description here...
- *
- * @param string $id Not used.
- * @param string $themeid
- * @return string
- */
- function theme_style_exists($id, $themeid = THE_THEME) {
- if ($f = theme_exists($themeid)) {
- if (file_exists($f)) {
- // DMKE: $f is either '' or $themeid.'/'
- // And now we're adding another slash...?
- return $f .'/';
- }
- }
- return '';
- }
- /**
- * Enter description here...
- *
- * @param string $id
- * @return string
- */
- function theme_geturl($id = THE_THEME) {
- return BLOG_BASEURL . THEMES_DIR . $id .'/';
- }
- /**
- * Enter description here...
- *
- * @param string $style
- * @param string $id
- * @return string
- */
- function theme_style_geturl($style, $id = THE_THEME) {
- return theme_geturl($id) . $style .'/';
- }
- /**
- * Gets an array with all available theme directories.
- * Currently it won't be checked if a theme directory contains
- * really a theme...
- *
- * @return array
- */
- function theme_list() {
- $dir = THEMES_DIR;
- $dh = opendir($dir);
- $i = 0;
- // DMKE: This construct is alway again quite ugly... Anyway it works ;-)
- while (false !== ($filename = readdir($dh))) {
- if (($filename != '.') && ($filename != '..')) {
- $files[$i++] = $filename;
- }
- }
- sort($files);
- return $files;
- }
- /**
- * Prints additional meta data and the links to the feeds.
- *
- * @global $fp_config
- */
- function theme_wp_head() {
- global $fp_config;
- // DMKE: I *REALLY* don't like these comments...
- // Maybe they could be eneabled with a VERBOSE_OUTPUT constant?
- echo "\n<!-- FP STD HEADER -->\n";
- echo "\n<meta name=\"generator\" content=\"FlatPress ".
- system_ver() ."\" />\n";
- echo "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"Get RSS 2.0 Feed\" href=\"".
- theme_feed_link('rss2') ."\" />\n";
- echo "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"Get Atom 1.0 Feed\" href=\"".
- theme_feed_link('atom') ."\" />\n";
- echo "<!-- EOF FP STD HEADER -->\n";
- }
- /**
- * Prints the link(s) to the stylesheet(s)
- *
- * @global $fp_config, $theme
- */
- function theme_head_stylesheet() {
- global $fp_config, $theme;
- // DMKE: Same as in line 175
- echo "\n<!-- FP STD STYLESHEET -->\n";
- echo '<link media="screen,projection,handheld" href="';
- echo BLOG_BASEURL . THEMES_DIR . THE_THEME;
- $css = defined('MOD_ADMIN_PANEL')
- ? $theme['style']['style_admin']
- : $theme['style']['style_def'];
- $substyle = isset($fp_config['general']['style'])
- ? '/'. $fp_config['general']['style'] .'/'
- : '/';
- echo $substyle . 'res/'. $css .'" type="text/css" rel="stylesheet" />';
- if (@$theme['style']['style_print']) {
- echo '<link media="print" href="';
- echo BLOG_BASEURL . THEMES_DIR . THE_THEME;
- echo $substyle .'res/'. $theme['style']['style_print'] .'" type="text/css" rel="stylesheet" />';
- }
- echo "\n<!-- FP STD STYLESHEET -->\n";
- }
- /**
- * Enter description here...
- *
- * @global $theme
- */
- function admin_head_action() {
- global $theme;
- if (!$theme['admin_custom_interface']) {
- echo '<link media="screen" href="'.
- BLOG_BASEURL .'admin/res/admin.css" type="text/css" rel="stylesheet" />';
- }
- }
- add_filter('admin_head', 'admin_head_action');
- add_action('wp_head', 'theme_wp_head');
- add_action('wp_head', 'theme_head_stylesheet');
- /**
- * Enter description here...
- *
- */
- function get_wp_head() {
- do_action('wp_head');
- if (class_exists('AdminPanel')) {
- do_action('admin_head');
- }
- }
- $smarty->register_function('header', 'get_wp_head');
-
- /**
- * Prints the footer defined in the configuration panel.
- *
- * @global $fp_config
- */
- function theme_wp_footer() {
- global $fp_config;
- echo $fp_config['general']['footer'];
- }
- add_action('wp_footer', 'theme_wp_footer');
- /**
- * Enter description here...
- *
- */
- function get_wp_footer() {
- do_action('wp_footer');
- }
- $smarty->register_function('footer', 'get_wp_footer');
- /**
- * Sends charset header.
- *
- */
- function theme_charset() {
- global $fp_config;
- header('Content-Type: text/html; charset='. $fp_config['general']['charset']);
- }
- add_action('init', 'theme_charset');
- /**
- * Enter description here...
- *
- * @global $fp_config, $lang, $theme, $fp_params
- * @param object $smarty
- */
- function theme_init(&$smarty) { /* &$mode */
- global $fp_config, $lang, $theme, $fp_params;
- // avoid compiled tpl collision (i.e. change theme without this and cry)
- $smarty->compile_id = md5($fp_config['general']['theme']);
- $smarty->template_dir = ABS_PATH . THEMES_DIR . $fp_config['general']['theme'] .'/';
- $loggedin = user_loggedin();
- $flatpress = $fp_config['general'];
- $flatpress['loggedin'] = $loggedin;
- /*
- retained for compatibility
- todo: ugly, clean this up
- smarty has constant facilities included ^_^
- $flatpress['FP_INTERFACE'] = FP_INTERFACE;
- $flatpress['BLOGURL'] = BLOG_BASEURL;
- */
- if ($loggedin) {
- $flatpress['user'] = user_get();
- }
- /*
- useful shorthand for themes
- e.g. {$flatpress.themeurl}imgs/myimage.png
- */
- if (isset($fp_config['general']['style'])) {
- $flatpress['themeurl'] = theme_style_geturl($fp_config['general']['style']);
- } else {
- $flatpress['themeurl'] = theme_geturl();
- }
- $flatpress['params'] = $fp_params;
- $flatpress_upper = array_change_key_case($flatpress, CASE_UPPER);
- $flatpress = array_merge($flatpress, $flatpress_upper);
- $smarty->assign('flatpress', $flatpress);
- $smarty->assign('lang', $lang);
- $smarty->assign('blogtitle', $fp_config['general']['title']);
- $smarty->assign('pagetitle', apply_filters('wp_title', "", '»'));
- $smarty->assign_by_ref('fp_config', $fp_config);
- $smarty->register_modifier('tag', 'theme_apply_filters_wrapper');
- $smarty->register_modifier('link', 'theme_apply_filters_link_wrapper');
- $smarty->register_modifier('filed', 'theme_entry_categories');
- if (!isset($fp_params['feed']) || empty($fp_params['feed'])) {
- $smarty->register_modifier('date_format_daily', 'theme_smarty_modifier_date_format_daily');
- $smarty->register_modifier('date_format', 'theme_date_format');
- }
- $smarty->register_modifier('date_rfc3339', 'theme_smarty_modifier_date_rfc3339');
- $smarty->register_function('action', 'theme_smarty_function_action');
- }
- /**
- * Enter description here...
- *
- * @param mixed $params Not used
- * @param mixed $content
- * @return mixed
- */
- function smarty_block_page($params, $content) {
- return $content;
- }
- $smarty->register_block('page', 'smarty_block_page');
- /**
- * Enter description here...
- *
- * @param var $var
- * @param string $hook
- * @return mixed
- */
- function theme_apply_filters_wrapper($var, $hook) {
- $args = func_get_args();
- $tmp = $args[0];
- $args[0] = $args[1];
- $args[1] = $tmp;
- return call_user_func_array('apply_filters', $args);
- }
- /**
- * Enter description here...
- *
- * @param unknown_type $var
- * @param unknown_type $hook
- * @return unknown
- */
- function theme_apply_filters_link_wrapper($var, $hook) {
- return apply_filters($hook, '', $var);
- }
- /**
- * Enter description here...
- *
- * @param array $params
- * @param object $smarty
- */
- function theme_smarty_function_action($params, &$smarty) {
- if (isset($params['hook'])) {
- do_action($params['hook']);
- }
- }
- /**
- * Enter description here...
- *
- * @global $fp_config
- * @param string $string
- * @param string $format
- * @param int $default_date
- * @return string
- */
- function theme_date_format($string, $format = null, $default_date = '') {
- $timestamp = 0;
- if ($string) {
- $timestamp = $string; // smarty_make_timestamp($string);
- } elseif ($default_date != '') {
- $timestamp = $default_date; // smarty_make_timestamp($default_date);
- } else {
- return;
- }
- if (is_null($format)) {
- global $fp_config;
- $format = $fp_config['locale']['timeformat'];
- }
- return date_strformat($format, $timestamp);
- }
- /**
- * Enter description here...
- *
- * @global $THEME_CURRENT_DAY, $lang, $fp_config
- * @param string $string
- * @param string $format
- * @param int $default_date
- * @return string
- */
- function theme_smarty_modifier_date_format_daily(
- $string, $format = null, $default_date = ''
- ) {
- global $THEME_CURRENT_DAY, $lang, $fp_config;
- if (is_null($format)) {
- $format = $fp_config['locale']['dateformat'];
- }
- $current_day = theme_date_format($string, $format, $default_date);
- if (
- !isset($THEME_CURRENT_DAY) ||
- $THEME_CURRENT_DAY != $current_day
- ) {
- $THEME_CURRENT_DAY = $current_day;
- return $current_day;
- }
- return '';
- }
- /**
- * Get date in RFC3339. Used e.g. in XML/Atom
- *
- * @param int $timestamp
- * @return string Date in RFC3339
- * @author Boris Korobkov
- * @see http://tools.ietf.org/html/rfc3339
- * @see http://it.php.net/manual/en/function.date.php#75757
- */
- function theme_smarty_modifier_date_rfc3339($timestamp = '') {
- if (!$timestamp) {
- $timestamp = time();
- }
- $date = date('Y-m-d\TH:i:s', $timestamp);
- $matches = array();
- if (preg_match('/^([\-+])(\d{2})(\d{2})$/', date('O', $timestamp), $matches)) {
- $date .= $matches[1] . $matches[2] .':'. $matches[3];
- } else {
- $date .= 'Z';
- }
- return $date;
- }
- // {{{ permalink, commentlink, staticlink: filters
- /**
- * Generates the url of the newsfeed.
- *
- * @param mixed $str Not usec
- * @param string $type Either 'rss2' or 'atom'
- * @return string
- */
- function theme_def_feed_link($str, $type) {
- return BLOG_BASEURL . "?x=feed:$type";
- }
- add_filter('feed_link', 'theme_def_feed_link', 0, 2);
- /**
- * Gets the url of the newsfeed.
- *
- * @param string $feed Either 'rss2' (default) or 'atom'
- * @return string
- */
- function theme_feed_link($feed = 'rss2') {
- return apply_filters('feed_link', '', $feed);
- }
- /**
- * Generates the url to the newsfeed of an entry's comments.
- *
- * @param mixed $str Not used
- * @param string $feed Either 'rss2' or 'atom'
- * @param string $id The entry ID
- * @return string
- */
- function theme_def_feed_comments_link($str, $feed, $id) {
- return BLOG_BASEURL . "?x=entry:$id;comments:1;feed:$feed";
- }
- add_filter('post_comments_feed_link', 'theme_def_feed_comments_link', 0, 3);
- /**
- * Gets the url to the newsfeed of an entry's comments.
- *
- * @param string $feed Either 'rss2' (default) or 'atom'
- * @param string $id The entry ID
- * @return string
- */
- function theme_comments_feed_link ($feed = 'rss2', $id) {
- return apply_filters('post_comments_feed_link', '', $feed, $id);
- }
- /**
- * Generates the url to an entry.
- *
- * @param mixed $str Not used
- * @param strig $id The entry ID
- * @return string
- */
- function theme_def_permalink($str, $id) {
- return BLOG_BASEURL . "?x=entry:$id";
- }
- add_filter('post_link', 'theme_def_permalink', 0, 2);
- /**
- * Gets the url to an entry
- *
- * @param string $id
- * @return string
- */
- function get_permalink ($id) {
- return apply_filters('post_link', '', $id);
- }
- /**
- * Generates the url to the comments of a given entry.
- *
- * @param mixed $str Not used
- * @param string $id The entry ID
- * @return string
- */
- function theme_def_commentlink($str, $id) {
- return BLOG_BASEURL . "?x=entry:$id;comments:1";
- }
- add_filter('comments_link', 'theme_def_commentlink', 0, 2);
- /**
- * Gets the url to the comments of a given entry.
- *
- * @param string $id The entry ID
- * @return string
- */
- function get_comments_link ($id) {
- return apply_filters('comments_link', '', $id);
- }
- /**
- * Generates the url to a static page.
- *
- * @param mixed $str Not used
- * @param string $id The page ID
- * @return string
- */
- function theme_def_staticlink($str, $id) {
- return BLOG_BASEURL . "?page=$id";
- }
- add_filter('page_link', 'theme_def_staticlink', 0, 2);
- /**
- * Gets the url to a static page
- *
- * @param string $id The page ID
- * @return string
- */
- function theme_staticlink ($id) {
- return apply_filters('page_link', '', $id);
- }
- /**
- * Generates the url to a category.
- *
- * @param mixed $str Not uses
- * @param string $catid The category
- * @return string
- */
- function theme_def_catlink($str, $catid) {
- return BLOG_BASEURL . "?x=cat:$catid";
- }
- add_filter('category_link', 'theme_def_catlink', 0, 2);
- /**
- * Gets the url to a category.
- *
- * @param string $catid The category
- * @return string
- */
- function get_category_link($catid) {
- return apply_filters('category_link', '', $catid);
- }
- /**
- * Gets the url to a yearly archive.
- *
- * @param string|int $year
- * @return string
- */
- function get_year_link($year) {
- return wp_specialchars(
- apply_filters(
- 'year_link',
- BLOG_BASEURL .'?x=y:'. str_pad($year, 2, '0', STR_PAD_LEFT),
- $year
- )
- );
- }
- /**
- * Gets the url to a monthly archive.
- *
- * @param string|int $year
- * @param string|int $month
- * @return string
- */
- function get_month_link($year, $month) {
- return wp_specialchars(
- apply_filters(
- 'month_link',
- BLOG_BASEURL
- .'?x=y:'. str_pad($year, 2, '0', STR_PAD_LEFT)
- .';m:'. str_pad($month, 2, '0', STR_PAD_LEFT),
- $year,
- $month
- )
- );
- }
- /**
- * Gets the url to a daily archive.
- *
- * @param string|int $year
- * @param string|int $month
- * @param string|int $day
- * @return string
- */
- function get_day_link($year, $month, $day) {
- return wp_specialchars(
- apply_filters(
- 'day_link',
- BLOG_BASEURL
- .'?x=y:'. str_pad($year, 2, '0', STR_PAD_LEFT)
- .';m:'. str_pad($month, 2, '0', STR_PAD_LEFT)
- .';d:'. str_pad($day, 2, '0', STR_PAD_LEFT),
- $year,
- $month,
- $day
- )
- );
- }
- // }}}
- /**
- * Enter description here...
- *
- * @global $lang
- * @param int $count
- * @return string
- */
- function theme_entry_commentcount($count) {
- global $lang;
- switch ($count) {
- case 0:
- return $lang['main']['nocomments'];
- break;
- case 1:
- return $lang['main']['comment'];
- break;
- default:
- return $count .' '. $lang['main']['comments'];
- break;
- }
- }
- add_filter('comments_number', 'theme_entry_commentcount');
- /**
- * Enter description here...
- *
- * @param unknown_type $cats
- * @param boolean $link
- * @param string $separator
- * @return unknown
- */
- function theme_entry_categories($cats, $link = true, $separator = ', ') {
- if (!$cats) {
- return;
- } else {
- $filed = array();
- if ($tmp1 = entry_categories_get('defs')) {
- foreach ($tmp1 as $k => $c) {
- if (array_intersect(array($k), $cats)) {
- $filed[] = $link
- ? "<a href=\"" . get_category_link($k) ."\">$c</a>"
- : $c;
- }
- }
- }
- if ($filed) {
- return implode($separator, $filed);
- }
- }
- }
- /* this is called only in legacy mode */
- // {{{ ENTRY
- /**
- * Enter description here...
- *
- * @param array $contarr
- * @param string $id
- * @return array
- */
- function &theme_entry_filters(&$contarr, $id = null) {
- $contarr['subject'] = apply_filters('the_title', $contarr['subject']);
- $contarr['content'] = apply_filters('the_content', $contarr['content']);
- if (isset($contarr['comments'])) {
- $contarr['commentcount'] = $contarr['comments'];
- $contarr['comments'] = apply_filters('comments_number', $contarr['commentcount']);
- }
- $contarr['permalink'] = get_permalink($id);
- $contarr['commentlink'] = get_comments_link($id);
- return $contarr;
- }
- //{{{ COMMENTS
- /**
- * Enter description here...
- *
- * @param array $contarr
- * @param mixed $key Not used
- * @return array
- */
- function &theme_comments_filters(&$contarr, $key) {
- $contarr['name'] = apply_filters('comment_author_name', $contarr['name']);
- if (isset($contarr['email'])) {
- $contarr['email'] = apply_filters('comment_author_email', $contarr['email']);
- $contarr['mailto'] = 'mailto:' . $contarr['email'];
- }
- if (!isset($contarr['url'])) {
- $contarr['url'] = '#';
- }
- $contarr['timestamp'] = $contarr['date'];
- $contarr['content'] = apply_filters('comment_text', $contarr['content']);
- return $contarr;
- }
- ?>