/** * Wrapper function to handle most common output scenarios. * * @param string|array $templates * If a string, then that template is included. * If an array, then all templates are included in the order of the array. */ function phorum_api_output($templates) { if (!is_array($templates)) { $templates = array($templates); } /* * [hook] * output_templates * * [description] * This hook can be used to alter the list of templates that * will be displayed by the phorum_api_output() call. * * [category] * Page output * * [when] * Before sending any output from phorum_api_output(). * * [input] * An array, containing the names of the templates to display * in the page body (between the header and footer template). * * [output] * Same as input, possibly modified. * * [example] * <hookcode> * function phorum_mod_foo_output_templates($templates) * { * // Add some advertisements at the top and bottom of the page. * array_unshift($templates, "foo::top_advertisement); * array_push($templates, "foo::bottom_advertisement); * * return $templates; * } * </hookcode> */ if (isset($PHORUM['hooks']['output_templates'])) { $templates = phorum_api_hook('output_templates', $templates); } /* * [availability] * Phorum 5 >= 5.2.16 * * [hook] * output_templates_<page> * * [description] * This hook provides the same functionality as the * <hook>output_templates</hook> hook. The difference is that this * hook is called for a specific phorum_page, which makes * this a lightweight hook if you only need to do processing * for a single phorum_page. * * [category] * Page output * * [when] * Before sending any output from phorum_api_output(). * * [input] * An array, containing the names of the templates to display * in the page body (between the header and footer template). * * [output] * Same as input, possibly modified. */ if (isset($GLOBALS['PHORUM']['hooks']['output_templates_' . phorum_page])) { $templates = phorum_api_hook('output_templates_' . phorum_page, $templates); } /* * [hook] * start_output * * [description] * This hook gives modules a chance to apply some last minute * changes to the Phorum data. You can also use this hook to * call <phpfunc>ob_start</phpfunc> if you need to buffer Phorum's * full output (e.g. to do some post processing on the data * from the <hook>end_output</hook> hook.<sbr/> * <sbr/> * Note: this hook is only called for standard pages (the ones * that are constructed using a header, body and footer) and not * for output from scripts that do raw output like * <filename>file.php</filename>, <filename>javascript.php</filename>, * <filename>css.php</filename> and <filename>rss.php</filename>. * * [category] * Page output * * [when] * After setting up all Phorum data, right before sending the * page header template. * * [input] * No input. * * [output] * No output. * * [example] * <hookcode> * function phorum_mod_foo_start_output() * { * global $PHORUM; * * // Add some custom data to the page title. * $title = $PHORUM['DATA']['HTML_TITLE']; * $PHORUM['DATA']['HTML_TITLE'] = "-=| Phorum Rocks! |=- $title"; * } * </hookcode> */ if (isset($GLOBALS['PHORUM']['hooks']['start_output'])) { phorum_api_hook('start_output'); } /* * [availability] * Phorum 5 >= 5.2.16 * * [hook] * start_output_<page> * * [description] * This hook provides the same functionality as the * <hook>start_output</hook> hook. The difference is that this * hook is called for a specific phorum_page, which makes * this a lightweight hook if you only need to do processing * for a single phorum_page. * * [category] * Page output * * [when] * After setting up all Phorum data, right before sending the * page header template. * * [input] * No input. * * [output] * No output. */ if (isset($GLOBALS['PHORUM']['hooks']['start_output_' . phorum_page])) { phorum_api_hook('start_output_' . phorum_page); } // Add some information to the breadcrumbs to make it easy for the // templates to apply different styling for the first and the // last (i.e. the currently active) breadcrumbs item. // // Reindex the array. It might not be sequential, due to module tinkering. $bc =& $GLOBALS['PHORUM']['DATA']['BREADCRUMBS']; $bc = array_values($bc); // Add a "FIRST" and "LAST" field to the appropriate records. $bc[0]['FIRST'] = TRUE; $bc[count($bc) - 1]['LAST'] = TRUE; // Copy only what we need into the current scope. We do this at // this point and not earlier, so the hooks before this code can be // used for changing values in the $PHORUM data. $PHORUM = array('DATA' => $GLOBALS['PHORUM']['DATA'], 'locale' => $GLOBALS['PHORUM']['locale'], 'hooks' => $GLOBALS['PHORUM']['hooks']); include phorum_api_template('header'); /* * [hook] * after_header * * [description] * This hook can be used for adding content to the pages that is * displayed after the page header template, but before the main * page content. * * [category] * Page output * * [when] * After sending the page header template, but before sending the * main page content. * * [input] * No input. * * [output] * No output. * * [example] * <hookcode> * function phorum_mod_foo_after_header() * { * // Only add data after the header for the index and list pages. * if (phorum_page != 'index' && phorum_page != 'list') return; * * // Add some static notification after the header. * print '<div style="border:1px solid orange; padding: 1em">'; * print 'Welcome to our forums!'; * print '</div>'; * } * </hookcode> */ if (isset($PHORUM['hooks']['after_header'])) { phorum_api_hook('after_header'); } /* * [availability] * Phorum 5 >= 5.2.16 * * [hook] * after_header_<page> * * [description] * This hook provides the same functionality as the * <hook>after_header</hook> hook. The difference is that this * hook is called for a specific phorum_page, which makes * this a lightweight hook if you only need to do processing * for a single phorum_page. * * [category] * Page output * * [when] * After sending the page header template, but before sending the * main page content. * * [input] * No input. * * [output] * No output. */ if (isset($GLOBALS['PHORUM']['hooks']['after_header_' . phorum_page])) { phorum_api_hook('after_header_' . phorum_page); } foreach ($templates as $template) { include phorum_api_template($template); } /* * [availability] * Phorum 5 >= 5.2.16 * * [hook] * before_footer_<page> * * [description] * This hook provides the same functionality as the * <hook>before_footer</hook> hook. The difference is that this * hook is called for a specific phorum_page, which makes * this a lightweight hook if you only need to do processing * for a single phorum_page. * * [category] * Page output * * [when] * After sending the main page content, but before sending the * page footer template. * * [input] * No input. * * [output] * No output. */ if (isset($GLOBALS['PHORUM']['hooks']['before_footer_' . phorum_page])) { phorum_api_hook('before_footer_' . phorum_page); } /* * [hook] * before_footer * * [description] * This hook can be used for adding content to the pages that is * displayed after the main page content, but before the page footer. * * [category] * Page output * * [when] * After sending the main page content, but before sending the * page footer template. * * [input] * No input. * * [output] * No output. * * [example] * <hookcode> * function phorum_mod_foo_before_footer() * { * // Add some static notification before the footer. * print '<div style="font-size: 90%">'; * print ' For technical support, please send a mail to '; * print ' <a href="mailto:tech@example.com">the webmaster</a>.'; * print '</div>'; * } * </hookcode> */ if (isset($PHORUM['hooks']['before_footer'])) { phorum_api_hook('before_footer'); } include phorum_api_template('footer'); /* * [hook] * end_output * * [description] * This hook can be used for performing post output tasks. * One of the things that you could use this for, is for * reading in buffered output using <phpfunc>ob_get_contents</phpfunc> * in case you started buffering using <phpfunc>ob_start</phpfunc> * from the <hook>start_output</hook> hook. * * [category] * Page output * * [when] * After sending the page footer template. * * [input] * No input. * * [output] * No output. * * [example] * <hookcode> * function phorum_mod_foo_end_output() * { * // Some made up call to some fake statistics package. * include "/usr/share/lib/footracker.php"; * footracker_register_request(); * } * </hookcode> */ if (isset($PHORUM['hooks']['end_output'])) { phorum_api_hook('end_output'); } /* * [availability] * Phorum 5 >= 5.2.16 * * [hook] * end_output_<page> * * [description] * This hook provides the same functionality as the * <hook>end_output</hook> hook. The difference is that this * hook is called for a specific phorum_page, which makes * this a lightweight hook if you only need to do processing * for a single phorum_page. * * [category] * Page output * * [when] * After sending the page footer template. * * [input] * No input. * * [output] * No output. */ if (isset($GLOBALS['PHORUM']['hooks']['end_output_' . phorum_page])) { phorum_api_hook('end_output_' . phorum_page); } }
/** * Set the active template. * * This function can be used to setup the data that is needed for activating * a different template or template storage path. This can be especially * useful for modules that can use this function to switch Phorum to a * template that is stored inside the module's directory (so no file copying * required to get the module's template tree into place). If for example * module "Foo" has a template directory "./mods/foo/templates/bar", then * the module could use this code to make sure that this template is used. * <code> * phorum_api_template_set( * "bar", * PHORUM_PATH."/mods/foo/templates", * $PHORUM['http_path']."/mods/foo/templates" * ); * </code> * * Beware that after doing this, the module's template directory is expected * to carry a full standard Phorum template and not only templates that are * required by the module for access through the "foo::templatename" * construction. Therefore, this template needs to have an info.php that * describes the template and a copy of all other template files that * Phorum normally uses. * * @param string $template * The name of the template to active (e.g. "emerald", "lightweight", etc.) * If this parameter is NULL, then no change will be done to the * currently activated template. * * @param string $template_path * The path to the base of the template directory. By default, * this is "./templates". If this parameter is NULL, then * no change will be done to the currenctly configured path. * * @param string $template_http_path * The URL to the base of the template directory. By default, * this is "<http_path>/templates". If this parameter is NULL, then * no change will be done to the currenctly configured http path. * */ function phorum_api_template_set($template = NULL, $template_path = NULL, $template_http_path = NULL) { global $PHORUM; if ($template !== NULL) { $PHORUM['template'] = basename($template); } if ($template_path !== NULL) { $PHORUM['template_path'] = $template_path; } if ($template_http_path !== NULL) { $PHORUM['template_http_path'] = $template_http_path; } // Apply defaults when needed. if (empty($PHORUM['template_path'])) { $PHORUM['template_path'] = PHORUM_PATH . '/templates'; } if (empty($PHORUM['template_http_path'])) { $PHORUM['template_path'] = $PHORUM['http_path'] . '/templates'; } // Setup related template data. $PHORUM["DATA"]["TEMPLATE"] = htmlspecialchars($PHORUM['template']); $PHORUM["DATA"]["URL"]["TEMPLATE"] = htmlspecialchars("{$PHORUM['template_http_path']}/{$PHORUM['template']}"); // Load the settings file for the configured template. ob_start(); include phorum_api_template('settings'); ob_end_clean(); }
* * for using that script you have either to use the chdir call or put it in the phorum-dir * keep in mind that others could use this script to overwrite files on your webserver * therefore there is the first exit(); in there, you have to remove it to use the script too * * to have Phorum use the static CSS, you'll have to edit header.tpl, instead the include of the css * you have to use a link href ... */ // that's here for security measures, remove it if you want to use the script!!! exit; //chdir("../"); include './common.php'; if ($argc < 2) { echo "needs 2 parameters, first as forum-id, second as filename (including path) of the css to be generated.\n"; exit; } // the second arg is the filename $filepath = $argv[2]; if (is_dir($filename)) { echo "the second argument has to be a filename and no directory!\n"; exit; } echo "Generating static CSS-file for Forum " . $PHORUM['forum_id'] . "\n"; ob_start(); include phorum_api_template('css'); $css_str = ob_get_contents(); ob_end_clean(); echo "writing CSS-file to " . $filepath . ".\n"; $fp = fopen($filepath, "w"); fputs($fp, $css_str); fclose($fp);
function phorum_mod_bbcode_tpl_editor_disable_bbcode() { global $PHORUM; if (empty($PHORUM["mod_bbcode"]["allow_disable_per_post"])) { return; } include phorum_api_template('bbcode::disable_option'); }
if (!file_exists(PHORUM_PATH . "/templates/{$PHORUM['template']}/info.php")) { $PHORUM['template'] = $PHORUM['default_forum_options']['template']; // If the template directory for the default forum settings template // cannot be found, then fallback to the hard-coded default. if (!file_exists(PHORUM_PATH . "/templates/{$PHORUM['template']}/info.php")) { $PHORUM['template'] = PHORUM_DEFAULT_TEMPLATE; } } // Use output buffering so we don't get header errors if there's // some additional output in the upcoming included files (e.g. UTF-8 // byte order markers or whitespace outside the php tags). ob_start(); // User output buffering so we don't get header errors. // Not loaded if we are running an external or scheduled script. if (!defined('PHORUM_SCRIPT')) { include phorum_api_template('settings'); $PHORUM["DATA"]["TEMPLATE"] = htmlspecialchars($PHORUM['template']); $PHORUM["DATA"]["URL"]["TEMPLATE"] = htmlspecialchars("{$PHORUM['template_http_path']}/{$PHORUM['template']}"); $PHORUM["DATA"]["URL"]["CSS"] = phorum_api_url(PHORUM_CSS_URL, "css"); $PHORUM["DATA"]["URL"]["CSS_PRINT"] = phorum_api_url(PHORUM_CSS_URL, "css_print"); $PHORUM["DATA"]["URL"]["JAVASCRIPT"] = phorum_api_url(PHORUM_JAVASCRIPT_URL); $PHORUM["DATA"]["URL"]["AJAX"] = phorum_api_url(PHORUM_AJAX_URL); } // Language names that modules might be using to reference the same // language. Before Phorum 5.3, the language filename format was // not standardized, so some other formats might still be in use. // The included language file can fill this array with appropriate // language names when needed. $PHORUM['compat_languages'] = array(); // Load the main language file. $PHORUM['language'] = basename($PHORUM['language']);
function phorum_mod_smileys_tpl_editor_disable_smileys() { global $PHORUM; if (empty($PHORUM["mod_smileys"]["allow_disable_per_post"])) { return; } include phorum_api_template('smileys::disable_option'); }
$module_registrations[$id]['type'] = $m[1]; $module_registrations[$id]['source'] = $m[2]; switch ($m[1]) { case "file": if (!isset($r['cache_key'])) { $mtime = @filemtime($m[2]); $r['cache_key'] = $mtime; $module_registrations[$id]['cache_key'] = $mtime; } break; case "template": // We load the parsed template into memory. This will refresh // the cached template file if required. This is the easiest // way to make this work correctly for nested template files. ob_start(); include phorum_api_template($m[2]); $module_registrations[$id]['content'] = ob_get_contents(); ob_end_clean(); // We use the mtime of the compiled template as the cache // key if no specific cache key was set. if (!isset($r['cache_key'])) { list($m[2], $php, $tpl) = phorum_api_template_resolve($m[2]); $mtime = @filemtime($php); $r['cache_key'] = $mtime; $module_registrations[$id]['cache_key'] = $mtime; } break; case "function": if (!isset($r['cache_key'])) { trigger_error("javascript_register hook: module registration " . "error: \"cache_key\" field missing for source " . "\"{$r['source']}\" in module \"{$r['module']}\"."); exit(1);
<br/> <input type="text" id="checkpm_user_id" value="<?php if ($PHORUM['user']['user_id']) { print $PHORUM['user']['user_id']; } ?> " /> <input type="button" value="Check PM for user id" onclick="checkpm(); return false"/> </form> <strong>Output</strong><br/> <div id="viewer" style="border: 1px solid #ddd; padding:10px; margin-bottom:5px; font-size: 9px"> </div> <strong>Debugging information</strong><br/> <div id="logger" style="border: 1px solid #ddd; padding:10px; font-size: 9px"> </div> <div id="state" style="border: 1px solid #ddd; border-top: none; padding:10px; font-size: 9px"> </div> <script type="text/javascript"> viewer = document.getElementById('viewer'); viewer.innerHTML = ''; </script> <?php include phorum_api_template('footer'); ?>
/** * @deprecated Replaced by {@link phorum_api_template()}. */ function phorum_get_template($template) { return phorum_api_template($template); }
function phorum_setup_announcements() { global $PHORUM; // This variable will be used to store the formatted announcements. $PHORUM['DATA']['MOD_ANNOUNCEMENTS'] = ''; // Check if we are on a page on which the announcements have to be shown. if (phorum_page == 'index') { // Hide the announcements, unless enabled for "index". $hide = empty($PHORUM["mod_announcements"]["pages"]["index"]); // Show announcements for the root page if "home" is enabled. if ($PHORUM['vroot'] == $PHORUM['forum_id'] && !empty($PHORUM["mod_announcements"]["pages"]["home"])) { $hide = FALSE; } if ($hide) { return; } } else { if (empty($PHORUM["mod_announcements"]["pages"][phorum_page])) { return; } } // Check if we are on a page on which the announcements have to be shown. if (!empty($PHORUM["mod_announcements"]["pages"]["home"])) { if ($PHORUM['vroot'] != $PHORUM['forum_id'] || phorum_page != 'index') { return; } } else { if (empty($PHORUM["mod_announcements"]["pages"][phorum_page])) { return; } } // Check if we need to show announcements. $ann_forum_id = NULL; // Inside a vroot, where we have a vroot configuration for the forum // to use for announcements and the current forum is not that // announcement forum. if ($PHORUM['vroot'] > 0 && !empty($PHORUM["mod_announcements"]["vroot"][$PHORUM['vroot']]) && $PHORUM["forum_id"] != $PHORUM["mod_announcements"]["vroot"][$PHORUM['vroot']]) { $ann_forum_id = $PHORUM["mod_announcements"]["vroot"][$PHORUM['vroot']]; // Inside the top level folder, where we have a forum that is configured // to be used for announcements and the current forum is not that // announcement forum. } elseif ($PHORUM['vroot'] == 0 && !empty($PHORUM["mod_announcements"]["forum_id"]) && $PHORUM["forum_id"] != $PHORUM["mod_announcements"]["forum_id"]) { $ann_forum_id = $PHORUM["mod_announcements"]["forum_id"]; } // If no announcement forum_id is found, no announcements // have to be shown. if ($ann_forum_id === NULL) { return; } // Retrieve the last number of posts from the announcement forum. $messages = $PHORUM['DB']->get_recent_messages($PHORUM["mod_announcements"]["number_to_show"], 0, $ann_forum_id, 0, true); unset($messages["users"]); // No announcements to show? Then we are done. if (count($messages) == 0) { return; } // Read the newflags information for authenticated users. $newinfo = NULL; if ($PHORUM["DATA"]["LOGGEDIN"]) { $newflagkey = $ann_forum_id . "-" . $PHORUM['user']['user_id']; if ($PHORUM['cache_newflags']) { $newinfo = phorum_api_cache_get('newflags', $newflagkey, $PHORUM['cache_version']); } if ($newinfo == NULL) { $newinfo = $PHORUM['DB']->newflag_get_flags($ann_forum_id); if ($PHORUM['cache_newflags']) { phorum_api_cache_put('newflags', $newflagkey, $newinfo, 86400, $PHORUM['cache_version']); } } } require_once PHORUM_PATH . '/include/api/format/messages.php'; // Process the announcements. foreach ($messages as $message) { // Skip this message if it's older than the number of days that was // configured in the settings screen. if (!empty($PHORUM["mod_announcements"]["days_to_show"]) && $message["datestamp"] < time() - $PHORUM["mod_announcements"]["days_to_show"] * 86400) { continue; } // Check if there are new messages in the thread. if (isset($newinfo)) { $new = 0; foreach ($message["meta"]["message_ids"] as $id) { if (!isset($newinfo[$id]) && $id > $newinfo['min_id']) { $new = 1; break; } } // There are new messages. Setup the template data for showing // a new flag. if ($new) { $message["new"] = $new ? $PHORUM["DATA"]["LANG"]["newflag"] : NULL; $message["URL"]["NEWPOST"] = phorum_api_url(PHORUM_FOREIGN_READ_URL, $message["forum_id"], $message["thread"], "gotonewpost"); } elseif ($PHORUM["mod_announcements"]["only_show_unread"]) { continue; } } // Setup template data for the message. unset($message['body']); $message["lastpost"] = phorum_api_format_date($PHORUM["short_date_time"], $message["modifystamp"]); $message["raw_datestamp"] = $message["datestamp"]; $message["datestamp"] = phorum_api_format_date($PHORUM["short_date_time"], $message["datestamp"]); $message["URL"]["READ"] = phorum_api_url(PHORUM_FOREIGN_READ_URL, $message["forum_id"], $message["message_id"]); $PHORUM["DATA"]["ANNOUNCEMENTS"][] = $message; } // If all announcements were skipped, then we are done. if (!isset($PHORUM["DATA"]["ANNOUNCEMENTS"])) { return; } // format / clean etc. the messages found $PHORUM["DATA"]["ANNOUNCEMENTS"] = phorum_api_format_messages($PHORUM["DATA"]["ANNOUNCEMENTS"]); // Build the announcements code. ob_start(); include phorum_api_template("announcements::announcements"); $PHORUM['DATA']['MOD_ANNOUNCEMENTS'] = ob_get_contents(); ob_end_clean(); }