/** * This function sets the stats for a thread like count, timestamp, etc. */ function phorum_update_thread_info($thread) { $PHORUM = $GLOBALS["PHORUM"]; $messages = phorum_db_get_messages($thread, 0, 1, 1); //these are not needed here unset($messages['users']); // Compute the threadviewcount, based on the individual message views. // This can be useful for updating the view counters after enabling // the view_count_per_thread option. $threadviewcount = 0; foreach ($messages as $id => $message) { $threadviewcount += $message['viewcount']; } // remove hidden/unapproved messages from the array $filtered_messages = array_filter($messages, "phorum_remove_hidden"); $thread_count = count($filtered_messages); if ($thread_count > 0) { $message_ids = array_keys($filtered_messages); sort($message_ids); $parent_message = $filtered_messages[$thread]; // find the latest post in the thread (aka recent_message) $last_message_id_by_time = 0; $last_post_time = 0; foreach ($filtered_messages as $message_id => $message_data) { if ($message_data['datestamp'] > $last_post_time) { $last_post_time = $message_data['datestamp']; $last_message_id_by_time = $message_id; } } $recent_message = $filtered_messages[$last_message_id_by_time]; // prep the message to save $message = array(); $message["thread_count"] = $thread_count; $message["threadviewcount"] = $threadviewcount; $message["modifystamp"] = $recent_message["datestamp"]; $message["recent_message_id"] = $recent_message["message_id"]; $message["recent_user_id"] = $recent_message["user_id"]; $message["recent_author"] = $recent_message["author"]; $message["meta"] = $parent_message["meta"]; // For cleaning up pre-5.2 recent post data. unset($message["meta"]["recent_post"]); $message["meta"]["message_ids"] = $message_ids; // used only for mods $message_ids_moderator = array_keys($messages); sort($message_ids_moderator); $message["meta"]["message_ids_moderator"] = $message_ids_moderator; if ($PHORUM['cache_messages']) { // we can simply store them here again, no need to invalidate the cache // this function is called in any place where we change something to the thread phorum_cache_put('message_index', $PHORUM['forum_id'] . "-{$thread}-1", $message["meta"]["message_ids"]); phorum_cache_put('message_index', $PHORUM['forum_id'] . "-{$thread}-0", $message["meta"]["message_ids_moderator"]); // but we need to invalidate the main-message as its changed for the recent author/message phorum_cache_remove('message', $thread); } phorum_db_update_message($thread, $message); } }
function phorum_check_cache($is_install = FALSE) { $PHORUM = $GLOBALS["PHORUM"]; $dir = $PHORUM["cache"]; // Some general solution descriptions. $solution_1 = "Change the Cache Directory setting under\n General Settings."; $solution_2 = "Change the Cache Directory setting under General \n Settings or give your webserver more permissions\n for the current cache directory."; // Check if the cache directory exists. if (!file_exists($dir) || !is_dir($dir)) { return array($is_install ? PHORUM_SANITY_WARN : PHORUM_SANITY_CRIT, "The system is unable to find the cache\n directory \"" . htmlspecialchars($dir) . "\" on\n your system.", $solution_1); } $dummy_file = "{$dir}/sanity_check_dummy_file"; // Check if we can create files in the cache directory. $fp = @fopen($dummy_file, "w"); if (!$fp) { return array($is_install ? PHORUM_SANITY_WARN : PHORUM_SANITY_CRIT, "The system is unable to write files\n to your cache directory \"" . htmlspecialchars($dir) . "\".\n The system error was:<br/><br/>" . htmlspecialchars($php_errormsg) . ".", $solution_2); } if (!fclose($fp)) { return array($is_install ? PHORUM_SANITY_WARN : PHORUM_SANITY_CRIT, "The system is able to write a file to your cache\n directory \"" . htmlspecialchars($dir) . "\",\n however closing the file failed.", "Failure to close a file mostly indicates that the disk\n on which the file is written is full. So check if your\n server doesn't have any full disk and free some space\n if this is the case."); } // Some very unusual thing might happen. On Windows2000 we have seen // that the webserver can write a message to the cache directory, // but that it cannot read it afterwards. Probably due to // specific NTFS file permission settings. So here we have to make // sure that we can open the file that we just wrote. $checkfp = fopen($dummy_file, "r"); if (!$checkfp) { return array($is_install ? PHORUM_SANITY_WARN : PHORUM_SANITY_CRIT, "The system was able to write a file to your cache directory \n \"" . htmlspecialchars($dir) . "\", but afterwards the created\n file could not be read by the webserver. This is probably \n caused by the file permissions on your cache directory.", $solution_2); } fclose($checkfp); unlink($dummy_file); $dummy_dir = "{$dir}/sanity_check_dummy_dir"; // Check if we can create directories in the cache directory. if (!@mkdir($dummy_dir)) { return array($is_install ? PHORUM_SANITY_WARN : PHORUM_SANITY_CRIT, "The system is unable to create directories\n in your cache directory \"" . htmlspecialchars($dir) . "\".\n The system error was:<br/><br/>" . htmlspecialchars($php_errormsg) . ".", $solution_2); } rmdir($dummy_dir); // All seems OK. Do a final system check where we check // the caching system like the Phorum system will do. phorum_cache_put('sanity_checks', 'dummy', 'dummy'); $entry = phorum_cache_get('sanity_checks', 'dummy'); phorum_cache_remove('sanity_checks', 'dummy'); if ($entry != 'dummy') { return array(PHORUM_SANITY_WARN, "There might be a problem in Phorum's caching system.\n Storing and retrieving a dummy key failed. If you\n experience problems with your Phorum installation,\n it might be because of this.", "As a work around, you can disable the caching facilities\n in the admin interface (note: this will not remove this\n warning; it will only keep you out of troubles by making\n sure that the caching system is not used). Please contact\n the Phorum developers to find out what the problem is."); } return array(PHORUM_SANITY_OK, NULL, NULL); }
case "js": $data = phorum_feed_make_js($messages, $forums, $feed_url, $feed_title, $feed_description); $content_type = "text/javascript"; break; case "atom": $data = phorum_feed_make_atom($messages, $forums, $feed_url, $feed_title, $feed_description); $content_type = "application/xml"; break; default: $data = phorum_feed_make_rss($messages, $forums, $feed_url, $feed_title, $feed_description); $content_type = "application/xml"; break; } // stick the xml in cache for 5 minutes for future use if (isset($PHORUM['cache_rss']) && !empty($PHORUM['cache_rss'])) { phorum_cache_put("feed", $cache_key, array($data, $content_type, 600)); } } // output the proper header and the data header("Content-type: {$content_type};"); echo $data; /* * [hook] * feed_sent * * [description] * This hook is called whenever the feed has been sent to the client * (regardless of the cache setting). This can be used to add internal * server side tracking code. * * [category]
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 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_cache_get('newflags', $newflagkey, $PHORUM['cache_version']); } if ($newinfo == NULL) { $newinfo = phorum_db_newflag_get_flags($ann_forum_id); if ($PHORUM['cache_newflags']) { phorum_cache_put('newflags', $newflagkey, $newinfo, 86400, $PHORUM['cache_version']); } } } require_once "./include/format_functions.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_get_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_date($PHORUM["short_date_time"], $message["modifystamp"]); $message["raw_datestamp"] = $message["datestamp"]; $message["datestamp"] = phorum_date($PHORUM["short_date_time"], $message["datestamp"]); $message["URL"]["READ"] = phorum_get_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_format_messages($PHORUM["DATA"]["ANNOUNCEMENTS"]); // Build the announcements code. ob_start(); include phorum_get_template("announcements::announcements"); $PHORUM['DATA']['MOD_ANNOUNCEMENTS'] = ob_get_contents(); ob_end_clean(); }
* The filter hook will not be run for every request to * javascript.php, but only in case the JavaScript code has * to be refreshed. * * [input] * The generated JavaScript code. * * [output] * The filtered JavaScript code. */ if (isset($PHORUM['hooks']['javascript_filter'])) { $content = phorum_api_hook('javascript_filter', $content); } if (!empty($PHORUM['cache_javascript'])) { $cache_time = time(); phorum_cache_put('js', $cache_key, array($cache_time, $content), 86400); } // Send the JavaScript to the browser. header("Content-Type: text/javascript"); print "/* FRESH */"; print $content; // Exit here explicitly for not giving back control to portable and // embedded Phorum setups. exit(0); } // Find the modification time for the cache file. $last_modified = $cache_time; // Check if a If-Modified-Since header is in the request. If yes, then // check if the JavaScript code has changed, based on the filemtime() data from // above. If nothing changed, then we return a 304 header, to tell the // browser to use the cached data.
function phorum_check_cache(){ $PHORUM = $GLOBALS["PHORUM"]; $dir = $PHORUM["cache"]; // Some general solution descriptions. $solution_1 = "Change the Cache Directory setting under General Settings."; $solution_2 = "Change the Cache Directory setting under General Settings or give your webserver more permissions for the current cache directory."; // Check if the cache directory exists. if (! file_exists($dir) || ! is_dir($dir)) return array( PHORUM_SANITY_CRIT, "The system is unable to find the cache directory \"".htmlspecialchars($dir)."\" on your system.", $solution_1 ); // Check if we can create files in the cache directory. $fp = @fopen ("$dir/sanity_check_dummy_file", "w"); if (! $fp) return array ( PHORUM_SANITY_CRIT, "The system is unable to write files to your cache directory \"".htmlspecialchars($dir)."\". The system error was:<br/><br/>". htmlspecialchars($php_errormsg).".", $solution_2 ); fclose($fp); // Some very unusual thing might happen. On Windows2000 we have seen // that the webserver can write a message to the cache directory, // but that it cannot read it afterwards. Probably due to // specific NTFS file permission settings. So here we have to make // sure that we can open the file that we just wrote. $checkfp = fopen("$dir/sanity_check_dummy_file", "r"); if (! $checkfp) return array( PHORUM_SANITY_CRIT, "The system was able to write a file to your cache directory \"".htmlspecialchars($dir)."\", but afterwards the created file could not be read by the webserver. This is probably caused by the file permissions on your cache directory.", $solution_2 ); unlink("$dir/sanity_check_dummy_file"); // Check if we can create directories in the cache directory. if (! @mkdir("$dir/sanity_check_dummy_dir")) return array( PHORUM_SANITY_CRIT, "The system is unable to create directories in your cache directory \"".htmlspecialchars($dir)."\". The system error was:<br/><br/>".htmlspecialchars($php_errormsg).".", $solution_2 ); rmdir("$dir/sanity_check_dummy_dir"); // All seems OK. Do a final system check where we check // the caching system like the Phorum system will do. phorum_cache_put('sanity_checks', 'dummy', 'dummy'); $entry = phorum_cache_get('sanity_checks', 'dummy'); phorum_cache_remove('sanity_checks', 'dummy'); if ($entry != 'dummy') return array( PHORUM_SANITY_WARN, "There might be a problem in Phorum's caching system. Storing and retrieving a dummy key failed. If you experience problems with your Phorum installation, it might me because of this.", "As a work around, you can disable the caching facilities in the admin interface. Please contact the Phorum developers to find out what the problem is.", ); return array (PHORUM_SANITY_OK, NULL); }
$data['datestamp'] = phorum_date($PHORUM["short_date_time"], $data["modifystamp"]); $data['raw_lastpost'] = $data['modifystamp']; $data['lastpost'] = phorum_date($PHORUM["short_date_time"], $data["modifystamp"]); $data["URL"]["READ"] = phorum_get_url(PHORUM_FOREIGN_READ_URL, $data["forum_id"], $data["thread"]); $data["URL"]["NEWPOST"] = phorum_get_url(PHORUM_FOREIGN_READ_URL, $data["forum_id"], $data["thread"], "gotonewpost"); // Check if there are new messages for the current thread. if (!isset($PHORUM['user']['newinfo'][$data["forum_id"]])) { $PHORUM['user']['newinfo'][$data["forum_id"]] = null; if ($PHORUM['cache_newflags']) { $newflagkey = $data["forum_id"] . "-" . $PHORUM['user']['user_id']; $PHORUM['user']['newinfo'][$data["forum_id"]] = phorum_cache_get('newflags', $newflagkey, $forums[$data["forum_id"]]['cache_version']); } if ($PHORUM['user']['newinfo'][$data["forum_id"]] == null) { $PHORUM['user']['newinfo'][$data["forum_id"]] = phorum_db_newflag_get_flags($data["forum_id"]); if ($PHORUM['cache_newflags']) { phorum_cache_put('newflags', $newflagkey, $PHORUM['user']['newinfo'][$data["forum_id"]], 86400, $forums[$data["forum_id"]]['cache_version']); } } } $new = array(); foreach ($data["meta"]["message_ids"] as $mid) { if (!isset($PHORUM['user']['newinfo'][$data["forum_id"]][$mid]) && $mid > $PHORUM['user']['newinfo'][$data["forum_id"]]['min_id']) { $new[] = $mid; } } if (count($new)) { $data["new"] = $PHORUM["DATA"]["LANG"]["newflag"]; } $subscr_array_final[] = $data; } require_once "./include/format_functions.php";
/** * Strips HTML <tags> and BBcode [tags] from the body. * * @param body - The block of body text to strip * @return stripped - The stripped body */ function phorum_strip_body($body, $strip_tags = true) { if ($strip_tags) { // Strip HTML <tags> $stripped = preg_replace("|</*[a-z][^>]*>|i", "", $body); // Strip BB Code [tags] $stripped = preg_replace("|\\[/*[a-z][^\\]]*\\]|i", "", $stripped); } else { $stripped = $body; } // do badwords check // Prepare the bad-words replacement code. $bad_word_check = false; $banlists = NULL; if (!empty($PHORUM['cache_banlists']) && !empty($PHORUM['banlist_version'])) { $cache_key = $PHORUM['forum_id']; $banlists = phorum_cache_get('banlist', $cache_key, $PHORUM['banlist_version']); } // not found or no caching enabled if ($banlists === NULL) { $banlists = phorum_db_get_banlists(); if (!empty($PHORUM['cache_banlists']) && !empty($PHORUM['banlist_version'])) { phorum_cache_put('banlist', $cache_key, $banlists, 7200, $PHORUM['banlist_version']); } } if (isset($banlists[PHORUM_BAD_WORDS]) && is_array($banlists[PHORUM_BAD_WORDS])) { $replace_vals = array(); $replace_words = array(); foreach ($banlists[PHORUM_BAD_WORDS] as $item) { $replace_words[] = "/\\b" . preg_quote($item['string'], '/') . "(ing|ed|s|er|es)*\\b/i"; $replace_vals[] = PHORUM_BADWORD_REPLACE; $bad_word_check = true; } } if ($bad_word_check) { $stripped = preg_replace($replace_words, $replace_vals, $stripped); } return $stripped; }
function phorum_write_language_file($lang, $CURRENT) { // Sort array keys. ksort($CURRENT['DATA']['LANG']); ksort($CURRENT['STORE']['DEPRECATED']); $langfile = "<?php\n" . "\n" . $CURRENT['STORE']['keep_comment'] . "\n" . "\n" . "// ============================================================\n" . "// General settings\n" . "// ============================================================\n" . "\n" . "// The language name as it is presented in the interface.\n" . "\$language = " . urldecode($CURRENT['STORE']['language']) . ";\n" . "\n" . "// Uncomment this to hide this language from the user-select-box.\n" . ($CURRENT['STORE']['language_hide'] ? '' : '//') . "\$language_hide = 1;\n" . "\n" . "// Date formatting. Check the PHP-docs for the syntax of these\n" . "// entries (http://www.php.net/strftime). One tip: do not use\n" . "// %T for showing the time zone, as users can change their time zone.\n" . "\$PHORUM['long_date_time'] = " . urldecode($CURRENT['long_date_time']) . ";\n" . "\$PHORUM['short_date_time'] = " . urldecode($CURRENT['short_date_time']) . ";\n" . "\$PHORUM['long_date'] = " . urldecode($CURRENT['long_date']) . ";\n" . "\$PHORUM['short_date'] = " . urldecode($CURRENT['short_date']) . ";\n" . "\n" . "// The locale setting for enabling localized times/dates. Take a look\n" . "// at http://www.w3.org/WAI/ER/IG/ert/iso639.htm for the needed string.\n" . "\$PHORUM['locale'] = " . urldecode($CURRENT['locale']) . ";\n" . "\n" . "// Numeric separators used to format numbers.\n" . "\$PHORUM['thous_sep'] = " . urldecode($CURRENT['thous_sep']) . ";\n" . "\$PHORUM['dec_sep'] = " . urldecode($CURRENT['dec_sep']) . ";\n" . "\n" . "// The charset to use for displaying special characters.\n" . "\$PHORUM['DATA']['CHARSET'] = " . urldecode($CURRENT['DATA']['CHARSET']) . ";\n" . "\n" . "// The charset to use for htmlspecialchars() calls. PHP does\n" . "// not implement all available charsets, which might result in\n" . "// warning messages if an unsupported charset is used.\n" . "//\n" . "// See http://www.php.net/htmlspecialchars for info on charset\n" . "// compatibility. If the charset that you specified above is\n" . "// compatible with htmlspecialchars(), then you can leave this\n" . "// variable empty. Otherwise, specify a compatible character\n" . "// set (ISO-8859-1 is usually a good choice for this).\n" . "\$PHORUM['DATA']['HCHARSET'] = " . urldecode($CURRENT['DATA']['HCHARSET']) . ";\n" . "\n" . "// The encoding used for outgoing mail messages.\n" . "\$PHORUM['DATA']['MAILENCODING'] = " . urldecode($CURRENT['DATA']['MAILENCODING']) . ";\n" . "\n" . "// Some languages need additional meta tags to set encoding, etc.\n" . "\$PHORUM['DATA']['LANG_META'] = " . urldecode($CURRENT['DATA']['LANG_META']) . ";\n" . "\n" . "// ============================================================\n" . "// Language translation strings\n" . "// ============================================================\n" . "\n" . "\$PHORUM['DATA']['LANG'] = array(\n"; // Add active language data to the array. foreach ($CURRENT['DATA']['LANG'] as $key => $val) { if ($key == 'TIME') { continue; } if (isset($CURRENT['STORE']['DEPRECATED'][$key])) { continue; } $langfile .= " '{$key}' => " . urldecode($val) . ",\n"; } // Add deprecated language data to the array. if (count($CURRENT['STORE']['DEPRECATED'])) { $langfile .= "\n" . " // ============================================================\n" . " // DEPRECATED:\n" . " // These are all language strings which are not used anymore.\n" . " // You might want to keep them to make this language file work\n" . " // for versions of Phorum prior to version " . PHORUM . "\n" . " // ============================================================\n" . "\n"; foreach ($CURRENT['STORE']['DEPRECATED'] as $key => $dummy) { $langfile .= " '{$key}' => " . urldecode($CURRENT['DATA']['LANG'][$key]) . ",\n"; } } $langfile .= ");\n" . "\n" . "// ============================================================\n" . "// Timezone description strings\n" . "// ============================================================\n" . "\n" . "\$PHORUM['DATA']['LANG']['TIME'] = array(\n"; foreach ($CURRENT['DATA']['LANG']['TIME'] as $key => $val) { $pre = sprintf(" %6s", "'{$key}'"); $langfile .= "{$pre} => " . urldecode($val) . ",\n"; } $langfile .= ");\n" . "\n" . "?>\n"; phorum_cache_put('updated_language', $lang, $langfile); }
/** * This function retrieves a user from the database, given the user id. * If $user_id is an array of user ids, it will retrieve all of the users * in the array. If $detailed is set to true, the function gets the users * full information. Setting this to false omits permission data, pm counts, * and group membership. $detailed is true by default and may be omitted. * @param user_id - can be a single user id, or an array of user ids. * @param detailed - get detailed user information (defaults to true). * @param checknewpm - check for new private messages for the user (defaults to false). * @return array - either an array representing a single user's information, * or an array of users */ function phorum_user_get( $user_id, $detailed = true, $checkpm = false ) { $PHORUM = $GLOBALS["PHORUM"]; if ( !is_array( $user_id ) ) { $user_ids = array( $user_id ); } else { $user_ids = $user_id; } if ( count( $user_ids ) ) { $cache_users=array(); $tmp_users=array(); $cachecnt=0; // get users from cache if enabled if(isset($PHORUM['cache_users']) && $PHORUM['cache_users']) { foreach($user_ids as $id => $cur_user_id) { $data=phorum_cache_get('user',$cur_user_id); if($data != null) { // null if no key found $cache_users[$cur_user_id]=$data; unset($user_ids[$id]); $cachecnt++; } } unset($data); // we need to get the dynamic data too! // only selecting date_last_active, forum_last_active, // posts ... any more? if($cachecnt > 0) { $dynamic_data=phorum_db_user_get_fields(array_keys($cache_users),array('date_last_active','last_active_forum','posts')); foreach($dynamic_data as $d_uid => $d_data) { $cache_users[$d_uid]=array_merge($cache_users[$d_uid],$d_data); } } } if(count($user_ids)) { $tmp_users = phorum_db_user_get( $user_ids, $detailed ); foreach( $tmp_users as $uid => $user ) { if ( !$user["admin"] ) { if ( isset( $user["group_permissions"] ) ) { foreach( $user["group_permissions"] as $forum_id => $perm ) { if(!isset($user["permissions"][$forum_id])) $user["permissions"][$forum_id]=0; $user["permissions"][$forum_id] = $user["permissions"][$forum_id] | $perm; } } if ( isset( $user["forum_permissions"] ) ) { foreach( $user["forum_permissions"] as $forum_id => $perm ) { $user["permissions"][$forum_id] = $perm; } } } // check if the user has new private messages if ( ($checkpm || (isset($PHORUM['cache_users']) && $PHORUM['cache_users'])) && $PHORUM["enable_pm"] && $PHORUM["enable_new_pm_count"] ) { $user["new_private_messages"] = phorum_db_pm_checknew( $uid ); } // store users in cache if enabled if( $detailed && isset($PHORUM['cache_users']) && $PHORUM['cache_users']) { phorum_cache_put('user',$uid,$user); } $tmp_users[$uid] = $user; } } } // merging cached and retrieved users $ret = $tmp_users + $cache_users; if ( !is_array( $user_id ) ) { if (isset($ret[$user_id])) $ret = $ret[$user_id]; else $ret = NULL; } return $ret; }
/** * Check a single banlist for a match. * @param value - The value to check. * @param type - The type of banlist to check the value against. * @return True if all is okay. False if a match has been found. */ function phorum_check_ban_lists($value, $type) { $PHORUM = $GLOBALS['PHORUM']; // Load the ban lists. if (!isset($GLOBALS["PHORUM"]["banlists"])) { $cache_key = $PHORUM['forum_id']; if (isset($PHORUM['cache_banlists']) && $PHORUM['cache_banlists']) { $GLOBALS["PHORUM"]["banlists"] = phorum_cache_get('banlist', $cache_key, $PHORUM['banlist_version']); if (!is_array($GLOBALS["PHORUM"]["banlists"]) || !count($GLOBALS["PHORUM"]["banlists"])) { unset($GLOBALS["PHORUM"]["banlists"]); } } // not found or no caching enabled if (!isset($GLOBALS["PHORUM"]["banlists"])) { $GLOBALS["PHORUM"]["banlists"] = phorum_db_get_banlists(); if (isset($GLOBALS["PHORUM"]["banlists"]) && isset($PHORUM['cache_banlists']) && $PHORUM['cache_banlists']) { phorum_cache_put('banlist', $cache_key, $GLOBALS["PHORUM"]["banlists"], 7200, $PHORUM['banlist_version']); } } } if (!isset($GLOBALS['PHORUM']['banlists'])) { return true; } $banlists = $GLOBALS['PHORUM']['banlists']; $value = trim($value); if (!empty($value)) { if (isset($banlists[$type]) && is_array($banlists[$type])) { foreach ($banlists[$type] as $item) { if (!empty($item['string']) && ($item["pcre"] && @preg_match("/\\b" . $item['string'] . "\\b/i", $value) || !$item["pcre"] && stristr($value, $item["string"]) && $type != PHORUM_BAD_USERID || $type == PHORUM_BAD_USERID && $value == $item["string"])) { return false; } } } } return true; }
} } } if (isset($row['recent_message_id'])) { // should always be true // building the recent message link if ($pages > 1) { $rows[$key]["URL"]["LAST_POST"] = str_replace(array('%thread_id%', '%message_id%', '%page_num%'), array($row['thread'], $row['recent_message_id'], $pages), $recent_page_url_template); } else { $rows[$key]["URL"]["LAST_POST"] = str_replace(array('%thread_id%', '%message_id%'), array($row['thread'], $row['recent_message_id']), $recent_url_template); } } } } if ($PHORUM['cache_messages'] && (!$PHORUM['DATA']['LOGGEDIN'] || $PHORUM['use_cookies']) && !$PHORUM['count_views']) { phorum_cache_put('message_list', $cache_key, $rows); } } if ($PHORUM["count_views"] == 2) { // viewcount as column $PHORUM["DATA"]["VIEWCOUNT_COLUMN"] = true; } //timing_mark('after preparation'); if ($PHORUM['DATA']['LOGGEDIN']) { // used later if user is moderator if ($PHORUM["DATA"]["MODERATOR"]) { $delete_url_template = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_DELETE_MESSAGE, '%message_id%'); $delete_thread_url_template = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_DELETE_TREE, '%message_id%'); $move_thread_url_template = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_MOVE_THREAD, '%message_id%'); $merge_thread_url_template = phorum_get_url(PHORUM_MODERATION_URL, PHORUM_MERGE_THREAD, '%message_id%'); if (isset($row['pages_moderators'])) {
function phorum_write_language_file($lang, $CURRENT) { // Sort array keys. ksort($CURRENT['DATA']['LANG']); ksort($CURRENT['DATA']['STORE']['DEPRECATED']); $langfile = "<?php\n" . "\n" . $CURRENT['STORE']['keep_comment'] . "\n" . "\n" . "// ============================================================\n" . "// General settings\n" . "// ============================================================\n" . "\n" . "// The language name as it is presented in the interface.\n" . "\$language = " . urldecode($CURRENT['STORE']['language']) . ";\n" . "\n" . "// Uncomment this to hide this language from the user-select-box.\n" . ($CURRENT['STORE']['language_hide'] ? '' : '//') . "\$language_hide = 1;\n" . "\n" . "// Date formatting. Check the PHP-docs for the syntax of these\n" . "// entries (http://www.php.net/strftime). One tip: do not use\n" . "// %T for showing the time zone, as users can change their time zone.\n" . "\$PHORUM['long_date'] = " . urldecode($CURRENT['long_date']) . ";\n" . "\$PHORUM['short_date'] = " . urldecode($CURRENT['short_date']) . ";\n" . "\n" . "// The locale setting for enabling localized times/dates. Take a look\n" . "// at http://www.w3.org/WAI/ER/IG/ert/iso639.htm for the needed string.\n" . "\$PHORUM['locale'] = " . urldecode($CURRENT['locale']) . ";\n" . "\n" . "// The character set to use for converting html into safe valid text.\n" . "// Also used in the header template for the xml tag. For a list of\n" . "// supported character sets see: http://www.php.net/htmlentities\n" . "// You may also need to set a meta-tag with a character set in it.\n" . "\$PHORUM['DATA']['CHARSET'] = " . urldecode($CURRENT['DATA']['CHARSET']) . ";\n" . "\n" . "// The encoding used for outgoing mail messages.\n" . "\$PHORUM['DATA']['MAILENCODING'] = " . urldecode($CURRENT['DATA']['MAILENCODING']) . ";\n" . "\n" . "// Some languages need additional meta tags to set encoding, etc.\n" . "\$PHORUM['DATA']['LANG_META'] = " . urldecode($CURRENT['DATA']['LANG_META']) . ";\n" . "\n" . "// ============================================================\n" . "// Language translation strings\n" . "// ============================================================\n" . "\n" . "\$PHORUM['DATA']['LANG'] = array(\n"; // Add active language data to the array. foreach ($CURRENT['DATA']['LANG'] as $key => $val) { if ($key == 'TIME') continue; if (isset($CURRENT['STORE']['DEPRECATED'][$key])) continue; $langfile .= " '$key' => " . urldecode($val) . ",\n"; } // Add deprecated language data to the array. if (count($CURRENT['STORE']['DEPRECATED'])) { $langfile .= "\n" . " // ============================================================\n" . " // DEPRECATED:\n" . " // These are all language strings which are not used anymore.\n" . " // You might want to keep them to make this language file work\n" . " // for versions of Phorum prior to version " . PHORUM . "\n" . " // ============================================================\n" . "\n"; foreach ($CURRENT['STORE']['DEPRECATED'] as $key => $dummy) { $langfile .= " '$key' => " . urldecode($CURRENT['DATA']['LANG'][$key]) . ",\n"; } } $langfile .= ");\n" . "\n" . "// ============================================================\n" . "// Timezone description strings\n" . "// ============================================================\n" . "\n" . "\$PHORUM['DATA']['LANG']['TIME'] = array(\n"; foreach ($CURRENT['DATA']['LANG']['TIME'] as $key => $val) { $pre = sprintf(" %6s", "'$key'"); $langfile .= "$pre => " . urldecode($val) . ",\n"; } $langfile .= ");\n" . "\n" . "?>\n"; phorum_cache_put('updated_language', $lang, $langfile); }
/** * Retrieve data for Phorum users. * * @param mixed $user_id * Either a single user_id or an array of user_ids. * * @param boolean $detailed * If this parameter is TRUE (default is FALSE), then the user's * groups and permissions are included in the user data. * * @param boolean $use_write_server * This parameter is for internal use only. It is used to flag that * the database layer has to run the query against the master database * server (known as the "write server"; only applicable if the database * system is setup as a replicated master/slave environment). When you * are using this API call in your own code, then you most probably do * not need to use this parameter. * * @return mixed * If the $user_id parameter is a single user_id, then either an array * containing user data is returned or NULL if the user was not found. * If the $user_id parameter is an array of user_ids, then an array * of user data arrays is returned, indexed by the user_id. * Users for user_ids that are not found are not included in the * returned array. */ function phorum_api_user_get($user_id, $detailed = FALSE, $use_write_server = FALSE, $raw_data = FALSE) { $PHORUM = $GLOBALS['PHORUM']; if (!is_array($user_id)) { $user_ids = array($user_id); } else { $user_ids = $user_id; } // Prepare the return data array. For each requested user_id, // a slot is prepared in this array. Also, turn the user id array // into an array which has the user_id as both the key and value. $users = array(); $new_user_ids = array(); foreach ($user_ids as $id) { $users[$id] = NULL; $new_user_ids[$id] = $id; } $user_ids = $new_user_ids; // First, try to retrieve user data from the user cache, // if user caching is enabled. if ($raw_data === FALSE && !empty($PHORUM['cache_users'])) { $cached_users = phorum_cache_get('user', $user_ids); if (is_array($cached_users)) { foreach ($cached_users as $id => $user) { $users[$id] = $user; unset($user_ids[$id]); } // We need to retrieve the data for some dynamic fields // from the database. $dynamic_data = phorum_db_user_get_fields(array_keys($cached_users), array('date_last_active', 'last_active_forum', 'posts')); // Store the results in the users array. foreach ($dynamic_data as $id => $data) { $users[$id] = array_merge($users[$id], $data); } } } // Retrieve user data for the users for which no data was // retrieved from the cache. if (count($user_ids)) { $db_users = phorum_db_user_get($user_ids, $detailed, $use_write_server, $raw_data); foreach ($db_users as $id => $user) { // Merge the group and forum permissions into a final // permission value per forum. Forum permissions that are // assigned to a user directly override any group based // permission. if (!$user['admin']) { if (!empty($user['group_permissions'])) { foreach ($user['group_permissions'] as $fid => $perm) { if (!isset($user['permissions'][$fid])) { $user['permissions'][$fid] = $perm; } else { $user['permissions'][$fid] |= $perm; } } } if (!empty($user['forum_permissions'])) { foreach ($user['forum_permissions'] as $fid => $perm) { $user['permissions'][$fid] = $perm; } } } // If detailed information was requested, we store the data in // the cache. For non-detailed information, we do not cache the // data, because there is not much to gain there by caching. if ($detailed && !empty($PHORUM['cache_users']) && $raw_data === FALSE) { phorum_cache_put('user', $id, $user); } // Store the results in the users array. $users[$id] = $user; } } // Remove the users for which we did not find data from the array. foreach ($users as $id => $user) { if ($user === NULL) { unset($users[$id]); } } /** * [hook] * user_get * * [description] * This hook can be used to handle the data that was retrieved * from the database for a user. Modules can add and modify the * user data.<sbr/> * <sbr/> * In combination with the <hook>user_save</hook> hook, this hook * could also be used to store and retrieve some of the Phorum * user fields in some external system * * [category] * User data handling * * [when] * Just after user data has been retrieved from the database. * * [input] * This hook receives two arguments.<sbr/> * The first argument contains an array of users. * Each item in this array is an array containing data for * a single user, which can be updated.<sbr/> * The second argument contains a boolean that indicates whether * detailed information (i.e. including group info) is retrieved. * * [output] * The array that was used as the first argument for the hook call, * possibly with some updated users in it. * * [example] * <hookcode> * function phorum_mod_foo_user_get($user, $detailed) * { * // Let's asume that our usernames are based on the * // system users on a UNIX system. We could merge some * // info from the password file with the Phorum info here. * * // First try to lookup the password file entry. * // Return if this lookup fails. * $pw = posix_getpwnam($user['username']); * if (empty($pw)) return $user; * * // On a lot of systems, the "gecos" field contains * // the real name for the user. * $user['real_name'] = $pw["gecos"] != '' * ? $pw["gecos"] * : $user["real_name"]; * * // If a custom profile field "shell" was created, then * // we could also put the user's shell in the data. * $user['shell'] = $pw['shell']; * * return $user; * } * </hookcode> */ if (isset($PHORUM['hooks']['user_get'])) { $users = phorum_hook('user_get', $users, $detailed); } // Return the results. if (is_array($user_id)) { return $users; } else { return isset($users[$user_id]) ? $users[$user_id] : NULL; } }
/** * Retrieve newflags data for a forum for the active Phorum user. * * This is mainly an internal helper function, which normally is * called from other Phorum core code. There should be no need for * you to call it from other code. * * @param mixed $forum * Either a forum_id or a forum data array, containing at least the fields * forum_id and cache_version. * * @return mixed * The newflags data array for the forum or NULL if no newflags * are available for that forum. */ function phorum_api_newflags_by_forum($forum) { global $PHORUM; // No newflags for anonymous users. if (!$PHORUM['user']['user_id']) { return NULL; } // If a forum_id was provided as the argument, then load the forum info. if (!is_array($forum)) { $forums = phorum_db_get_forums($forum); if (empty($forums)) { trigger_error('phorum_api_newflags_by_forum(): unknown forum_id ' . $forum); } $forum = $forums[$forum]; } // Check the input data. if (!is_array($forum) || !isset($forum['forum_id']) || !isset($forum['cache_version'])) { trigger_error('phorum_api_newflags_by_forum(): illegal argument; no forum info ' . 'or either one of "forum_id" or "cache_version" is ' . 'missing in the data.'); return NULL; } $forum_id = (int) $forum['forum_id']; $cache_version = $forum['cache_version']; // Initialize call time newflags info cache. if (!isset($PHORUM['user']['newflags'])) { $PHORUM['user']['newflags'] = array(); } // First, try to retrieve a cached version of the newflags. if (!isset($PHORUM['user']['newflags'][$forum_id])) { $PHORUM['user']['newflags'][$forum_id] = NULL; if ($PHORUM['cache_newflags']) { $cachekey = $forum_id . '-' . $PHORUM['user']['user_id']; $PHORUM['user']['newflags'][$forum_id] = phorum_cache_get('newflags', $cachekey, $cache_version); } } // No cached data found? Then retrieve the newflags from the database. if ($PHORUM['user']['newflags'][$forum_id] === NULL) { $PHORUM['user']['newflags'][$forum_id] = phorum_db_newflag_get_flags($forum_id); if ($PHORUM['cache_newflags']) { phorum_cache_put('newflags', $cachekey, $PHORUM['user']['newflags'][$forum_id], 86400, $cache_version); } } return $PHORUM['user']['newflags'][$forum_id]; }
$db_messages = array(); $msg_not_in_cache = 0; foreach ($message_ids_page as $mid) { if (!isset($cache_messages[$mid])) { $db_messages[] = $mid; $msg_not_in_cache++; } else { $data[$mid] = $cache_messages[$mid]; $data['users'][] = $data[$mid]['user_id']; } } if ($msg_not_in_cache) { $db_messages = phorum_db_get_message($db_messages, 'message_id'); // store the found messages in the cache foreach ($db_messages as $mid => $message) { phorum_cache_put('message', $mid, $message); $data[$mid] = $message; $data['users'][] = $data[$mid]['user_id']; } if ($PHORUM['threaded_read'] && isset($PHORUM["reverse_threading"]) && $PHORUM["reverse_threading"]) { krsort($data); } else { ksort($data); } } } else { $data = array('users' => array()); } } else { // Get the thread $data = phorum_db_get_messages($thread, $page);
); $data = create_rss_feed($channel, $items); } $charset = ''; if (! empty($GLOBALS["PHORUM"]["DATA"]["CHARSET"])) { $charset = '; charset=' . htmlspecialchars($GLOBALS["PHORUM"]["DATA"]['CHARSET']); } header("Content-Type: text/xml$charset"); echo $data; phorum_cache_put("rss", $cache_key, $data, 300); /*******************************************************/ function create_rss_feed($channel, $items) { if(empty($items)){ return; } $encoding = ''; if (! empty($GLOBALS["PHORUM"]["DATA"]["CHARSET"])) { $encoding = 'encoding="' . htmlspecialchars($GLOBALS["PHORUM"]["DATA"]['CHARSET']) . '"'; }