<?php
	require_once( $GLOBALS["site_root"] . "/includes/models/Forum.inc.php" );

	class ForumURL {
		public static function renderURL( $p = array() , $extendpath = "" ) {
			switch ($GLOBALS["language"]) {
			default:
			case "hu": return FNTH_render_url( $GLOBALS["site_www"] . "/szakmai-forum/" . $extendpath , $p );
			case "en": return FNTH_render_url( $GLOBALS["site_www"] . "/forum/" . $extendpath , $p );
			}
		}

		public static function renderURLFromTopicId( $forum_topic_id = 0 , $p = array() ) {
			$fm = new ForumModel();
			$topic = $fm->getForumTopicFromId( $forum_topic_id );
			$query = sprintf( "select forum_topic_aliasname from forum_topics where
				forum_topic_meta_l<=%d and
				forum_topic_meta_r>=%d
			order by
				forum_topic_meta_l",
				$topic["forum_topic_meta_l"],
				$topic["forum_topic_meta_r"] );
			$ds = FNTH_db_get_column( $query , "forum_topic_aliasname" );
			return self::renderURL( $p , implode( "/" , $ds ) . "/" );
		}

		public static function renderURLFromTopicPostId( $forum_post_id = 0 , $forum_post = false , $forum_topic = false ) {
			$fm = new ForumModel();
			if (!$forum_post) {
				$forum_post = $fm->getForumPostFromId( $forum_post_id );
			}
			if (!$forum_topic) {
				$forum_topic = $fm->getTopicFromId( $forum_post["forum_topic_id"] );
			}
			$query = sprintf( "select count(*) as num from forum_posts where forum_topic_id=%d and not is_admin_moderated" , $forum_post["forum_topic_id"] );	
			$numofrecords = FNTH_db_get_field( $query , "num" );

			$current_postnum = $numofrecords - $forum_post["meta_ordering"];
			$current_pagenum = (int)($current_postnum/ForumModel::getPageSize());
			$p = array();
			$p["pn"]=$current_pagenum;
			$retval = ForumURL::renderURLFromTopicId( $forum_post["forum_topic_id"] , $p );
			return $retval."#forum_post_".$forum_post["forum_post_id"];
		}

		public static function renderSearchURL( $p = array() ) {
			switch ($GLOBALS["language"]) {
			default:
			case "hu": return FNTH_render_url( $GLOBALS["site_www"] . "/szakmai-forum-kereses/" , $p );
			case "en": return FNTH_render_url( $GLOBALS["site_www"] . "/forum-search/" , $p );
			}
		}
	}
?>
