function phorum_get_url() { $PHORUM = $GLOBALS["PHORUM"]; $argv = func_get_args(); $url = ""; $suffix = ""; $pathinfo = NULL; $add_forum_id = false; $add_get_vars = true; $type = array_shift($argv); if (!isset($PHORUM["url_patterns"][$type])) { // these URL types need extra care // please do not add anything to this unless it is a last resort switch ($type) { case PHORUM_READ_URL: $name = "read"; $add_forum_id = true; $add_get_vars = true; if (!empty($argv[1]) && (is_numeric($argv[1]) || $argv[1] == '%message_id%')) { $suffix = "#msg-{$argv['1']}"; } break; case PHORUM_REPLY_URL: if (isset($PHORUM["reply_on_read_page"]) && $PHORUM["reply_on_read_page"]) { $name = "read"; $suffix = "#REPLY"; } else { $name = "posting"; // For reply on a separate page, we call posting.php on // its own. In that case argv[0] is the editor mode we // want to use (reply in this case). Currently, the thread // id is in argv[0], but we don't need that one for // posting.php. So we simply replace argv[0] with the // correct argument. $argv[0] = "reply"; } $add_get_vars = true; $add_forum_id = true; break; case PHORUM_FOREIGN_READ_URL: $name = "read"; $add_forum_id = false; $add_get_vars = true; if (!empty($argv[2]) && is_numeric($argv[2])) { $suffix = "#msg-{$argv['2']}"; } break; case PHORUM_FILE_URL: $name = "file"; $add_forum_id = true; // If a filename=... parameter is set, then change that // parameter to a URL path, unless this feature is not // enabled in the admin setup. $unset = array(); if (!empty($PHORUM['file_url_uses_pathinfo'])) { $file_id = NULL; $filename = NULL; $download = ''; foreach ($argv as $id => $arg) { if (substr($arg, 0, 5) == 'file=') { $file_id = substr($arg, 5); // %file_id% is sometimes used for creating URL // templates, so we should not mangle that one. if ($file_id != '%file_id%') { settype($file_id, 'int'); } $unset[] = $id; } elseif (substr($arg, 0, 9) == 'filename=') { $filename = urldecode(substr($arg, 9)); // %file_name% is sometimes used for creating URL // templates, so we should not mangle that one. if ($filename != '%file_name%') { $filename = preg_replace('/[^\\w\\_\\-\\.]/', '_', $filename); $filename = preg_replace('/_+/', '_', $filename); } $unset[] = $id; } elseif (substr($arg, 0, 9) == 'download=') { $download = 'download/'; $unset[] = $id; } } if ($file_id !== NULL && $filename !== NULL) { foreach ($unset as $id) { unset($argv[$id]); } $add_forum_id = false; $pathinfo = "/{$download}{$PHORUM['forum_id']}/{$file_id}/{$filename}"; } } break; // this is for adding own generic urls // this is for adding own generic urls case PHORUM_CUSTOM_URL: // first arg is our page $name = array_shift($argv); // second arg determines if we should add the forum_id $add_forum_id = (bool) array_shift($argv); break; } } else { list($name, $add_forum_id, $add_get_vars) = $PHORUM["url_patterns"][$type]; // add forum id if setting is conditional and there are no params if ($add_forum_id == PHORUM_URL_COND_FORUM_ID && count($argv) == 0) { $add_forum_id = PHORUM_URL_ADD_FORUM_ID; } } if (isset($name)) { $query_string = ""; $url = $PHORUM["http_path"] . "/"; if ($name) { $url .= $name . "." . PHORUM_FILE_EXTENSION; } if ($add_forum_id == PHORUM_URL_ADD_FORUM_ID) { $query_string = $PHORUM["forum_id"] . ","; } if (count($argv) > 0) { $query_string .= implode(",", $argv) . ","; } if ($add_get_vars) { if (!empty($PHORUM["DATA"]["GET_VARS"]) && $add_get_vars) { $query_string .= implode(",", $PHORUM["DATA"]["GET_VARS"]) . ","; } } if ($query_string) { $query_string = substr($query_string, 0, -1); // trim off ending , } if (function_exists("phorum_custom_get_url")) { $query_items = $query_string == '' ? array() : explode(',', $query_string); $url = phorum_custom_get_url($name, $query_items, $suffix, $pathinfo); } else { if ($pathinfo !== null) { $url .= $pathinfo; } if ($query_string) { $url .= "?" . $query_string; } if (!empty($suffix)) { $url .= $suffix; } } } else { trigger_error("Unhandled page type " . $type . ".", E_USER_WARNING); } return $url; }
/** * Generate a Phorum URL. */ function phorum_api_url() { global $PHORUM; // So we do not call function_exists() for each phorum_api_url() call. static $do_custom_url = NULL; if ($do_custom_url === NULL) { $do_custom_url = function_exists('phorum_custom_get_url'); } $argv = func_get_args(); $url = ''; $suffix = ''; $pathinfo = NULL; $add_forum_id = 1; $add_get_vars = TRUE; $type = array_shift($argv); if (!isset($PHORUM['API']['url_patterns'][$type])) { // these URL types need extra care // please do not add anything to this unless it is a last resort switch ($type) { case PHORUM_REPLY_URL: $add_get_vars = TRUE; $add_forum_id = 2; // The reply URL depends on how the reply form is handled. if (!empty($PHORUM['reply_on_read_page'])) { $name = 'read'; $suffix = '#REPLY'; } else { $name = 'posting'; } break; case PHORUM_FILE_URL: $name = 'file'; $add_forum_id = 2; // If a filename=... parameter is set, then change that // parameter to a URL path, unless this feature is not // enabled in the admin setup. $unset = array(); if (!empty($PHORUM['file_url_uses_pathinfo'])) { $file_id = NULL; $filename = NULL; $download = ''; foreach ($argv as $id => $arg) { if (substr($arg, 0, 5) == 'file=') { $file_id = substr($arg, 5); // %file_id% is sometimes used for creating URL // templates, so we should not mangle that one. if ($file_id != '%file_id%') { settype($file_id, 'int'); } $unset[] = $id; } elseif (substr($arg, 0, 9) == 'filename=') { $filename = urldecode(substr($arg, 9)); // %file_name% is sometimes used for creating URL // templates, so we should not mangle that one. if ($filename != '%file_name%') { $filename = preg_replace('/[^\\w\\_\\-\\.]/', '_', $filename); $filename = preg_replace('/_+/', '_', $filename); } $unset[] = $id; } elseif (substr($arg, 0, 9) == 'download=') { $download = 'download/'; $unset[] = $id; } } if ($file_id !== NULL && $filename !== NULL) { foreach ($unset as $id) { unset($argv[$id]); } $add_forum_id = 2; $pathinfo = "/{$download}{$PHORUM['forum_id']}/" . "{$file_id}/{$filename}"; } } break; // this is for adding own generic urls // this is for adding own generic urls case PHORUM_CUSTOM_URL: // first arg is our page $name = array_shift($argv); // second arg determines if we should add the forum_id $add_forum_id = (bool) array_shift($argv) ? 2 : 0; break; default: trigger_error("phorum_api_url(): Illegal URL type " . "\"{$type}\" used", E_USER_ERROR); break; } } else { list($name, $add_forum_id, $add_get_vars, $suffix_p, $suffix_fld) = $PHORUM['API']['url_patterns'][$type]; if ($suffix_p !== NULL) { if (empty($suffix_fld)) { $suffix = $suffix_p; } else { $suffix_fld--; // because we shift()ed $argv before. if (!empty($argv[$suffix_fld]) && (is_numeric($argv[$suffix_fld]) || strpos($argv[$suffix_fld], '%') === 0)) { $suffix = $suffix_p . $argv[$suffix_fld]; } } } } // Build the URL. $url = $PHORUM['http_path'] . '/'; if ($name) { $url .= $name . '.' . PHORUM_FILE_EXTENSION; } // Build the query parameters to add. // Add forum id if requested. if ($add_forum_id === 2) { array_unshift($argv, $PHORUM['forum_id']); } // Add forum id if setting is conditional and there are no params. if ($add_forum_id === 3 & count($argv) == 0) { array_unshift($argv, $PHORUM['forum_id']); } // Add forum id and (if available) the thread and message id. if ($add_forum_id === 4) { if (!empty($PHORUM['ref_message_id'])) { array_push($argv, 'ref_message_id=' . $PHORUM['ref_message_id']); } if (!empty($PHORUM['ref_thread_id'])) { array_push($argv, 'ref_thread_id=' . $PHORUM['ref_thread_id']); } array_unshift($argv, $PHORUM['forum_id']); } // Add GET vars if requested. if ($add_get_vars) { $query_params = array_merge($argv, $PHORUM['DATA']['GET_VARS']); } else { $query_params = $argv; } /** * @todo document the 'url_build' hook. */ if (isset($PHORUM['hooks']['url_build'])) { $hook_url = phorum_api_hook('url_build', NULL, $name, $query_params, $suffix, $pathinfo); if ($hook_url !== NULL) { return $hook_url; } } // Allow full overriding of the URL building mechanism by // implementing the function "phorum_custom_get_url()". // This is a legacy solution (a hook avant la lettre). // When writing new code, then please use the "url_build" // hook instead. if ($do_custom_url) { $url = phorum_custom_get_url($name, $query_params, $suffix, $pathinfo); } else { if ($pathinfo !== null) { $url .= $pathinfo; } if (!empty($query_params)) { $url .= '?' . implode(',', $query_params); } if ($suffix) { $url .= $suffix; } } return $url; }
function phorum_get_url() { $PHORUM = $GLOBALS["PHORUM"]; $args = ""; $url = ""; $suffix = ""; $add_forum_id = false; $add_get_vars = true; $argv = func_get_args(); $type = array_shift( $argv ); switch ( $type ) { case PHORUM_LIST_URL: $page = "list"; if ( empty( $argv ) ) $add_forum_id = true; break; case PHORUM_READ_URL: $page = "read"; $add_forum_id = true; if ( !empty( $argv[1] ) && is_numeric( $argv[1] ) ) $suffix = "#msg-$argv[1]"; break; case PHORUM_FOREIGN_READ_URL: $page = "read"; if ( !empty( $argv[2] ) && is_numeric( $argv[2] ) ) $suffix = "#msg-$argv[2]"; break; case PHORUM_REPLY_URL: if(isset($PHORUM["reply_on_read_page"]) && $PHORUM["reply_on_read_page"]){ $page = "read"; $suffix = "#REPLY"; } else { $page = "posting"; // For reply on a separate page, we call posting.php on its own. // In that case argv[0] is the editor mode we want to use // (reply in this case). Currently, the thread id is in argv[0], // but we don't need that one for posting.php. So we simply // replace argv[0] with the correct argument. $argv[0] = "reply"; } $add_forum_id = true; break; case PHORUM_POSTING_URL: $page = "posting"; $add_forum_id = true; break; case PHORUM_REDIRECT_URL: $page = "redirect"; $add_forum_id = false; break; case PHORUM_SEARCH_URL: $page = "search"; $add_forum_id = true; break; case PHORUM_SEARCH_ACTION_URL: $page = "search"; $add_get_vars = true; break; case PHORUM_DOWN_URL: $page = "down"; $add_forum_id = true; break; case PHORUM_VIOLATION_URL: $page = "violation"; $add_forum_id = true; break; case PHORUM_INDEX_URL: $page = "index"; break; case PHORUM_LOGIN_URL: $page = "login"; $add_forum_id = true; break; case PHORUM_LOGIN_ACTION_URL: $page = "login"; break; case PHORUM_REGISTER_URL: $page = "register"; $add_forum_id = true; break; case PHORUM_REGISTER_ACTION_URL: $page = "register"; break; case PHORUM_PROFILE_URL: $page = "profile"; $add_forum_id = true; break; case PHORUM_SUBSCRIBE_URL: $page = "subscribe"; $add_forum_id = true; break; case PHORUM_MODERATION_URL: $page = "moderation"; $add_forum_id = true; break; case PHORUM_MODERATION_ACTION_URL: $page = "moderation"; $add_get_vars = false; break; case PHORUM_PREPOST_URL: $page = "control"; $argv[] = "panel=messages"; $add_forum_id = true; break; case PHORUM_CONTROLCENTER_URL: $page = "control"; $add_forum_id = true; break; case PHORUM_CONTROLCENTER_ACTION_URL: $page = "control"; break; case PHORUM_PM_URL: $page = "pm"; $add_forum_id = true; break; case PHORUM_PM_ACTION_URL: $page = "pm"; break; case PHORUM_FILE_URL: $page = "file"; $add_forum_id = true; break; case PHORUM_FOLLOW_URL: $page = "follow"; $add_forum_id = true; break; case PHORUM_FOLLOW_ACTION_URL: $page = "follow"; $add_forum_id = false; break; case PHORUM_REPORT_URL: $page = "report"; $add_forum_id = true; break; case PHORUM_RSS_URL: switch(phorum_page){ case "list": $add_forum_id = true; break; case "read": $add_forum_id = true; array_push($argv, $PHORUM["args"]["1"]); break; } $page = "rss"; break; // this is for adding own generic urls case PHORUM_CUSTOM_URL: $page = array_shift($argv); // first arg is our page $add_forum_id_tmp=array_shift($argv); // second determining if we should add the forum_id $add_forum_id = $add_forum_id_tmp?true:false; break; case PHORUM_BASE_URL: // only to flag phorum_custom_get_url() that base url is requested $page = ''; break; default: trigger_error( "Unhandled page type.", E_USER_WARNING ); break; } // build the query string $query_items = array(); if ( $add_forum_id ) { $query_items[] = ( int )$PHORUM["forum_id"]; } if ( count( $argv ) > 0 ) { $query_items = array_merge( $query_items, $argv ); } if ( !empty( $PHORUM["DATA"]["GET_VARS"] ) && $add_get_vars ) { $query_items = array_merge( $query_items, $PHORUM["DATA"]["GET_VARS"] ); } // build the url if ( !function_exists( "phorum_custom_get_url" ) ) { if ($type == PHORUM_BASE_URL) return $PHORUM["http_path"] . '/'; $url = "$PHORUM[http_path]/$page." . PHORUM_FILE_EXTENSION; if ( count( $query_items ) ) $url .= "?" . implode( ",", $query_items ); if ( !empty( $suffix ) ) $url .= $suffix; } else { $url = phorum_custom_get_url( $page, $query_items, $suffix ); } return $url; }