<commit_before><?php
/*"******************************************************************************************************
*   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
*   (c) 2007-2008 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
* 																										*
* 	class_modul_guestbook_portal.php																	*
* 	Portal-class of the guestbook       																*
*-------------------------------------------------------------------------------------------------------*
*	$Id$                             *
********************************************************************************************************/

//Include base classes
include_once(_portalpath_."/class_portal.php");
include_once(_portalpath_."/interface_portal.php");

//include needed classes
include_once(_systempath_."/class_modul_guestbook_post.php");
include_once(_systempath_."/class_modul_guestbook_guestbook.php");

/**
 * Portal-class of the guestbook. Handles postings
 *
 * @package modul_guestbook
 */
class class_modul_guestbook_portal extends class_portal implements interface_portal {
	/**
	 * Constructor
	 *
	 * @param mixed $arrElementData
	 */
	public function __construct($arrElementData) {
		$arrModul["name"] 				= "modul_guestbook";
		$arrModul["author"] 			= "<EMAIL>";
		$arrModul["table"] 	    		= _dbprefix_."guestbook_book";
		$arrModul["table2"] 			= _dbprefix_."guestbook_post";
		$arrModul["moduleId"] 			= _gaestebuch_modul_id_;
		$arrModul["modul"] 			    = "guestbook";

        parent::__construct($arrModul, $arrElementData);
	}

	/**
	 * Action-block, controling the behaviour of the class
	 *
	 * @return string
	 */
	public function action() {
		$strReturn = "";
		$strAction = "";

		if($this->getParam("action") != "")
		    $strAction = $this->getParam("action");

		if($strAction == "insertGuestbook")
			$strReturn = $this->actionInsert();
		elseif($strAction == "saveGuestbook") {
			if($this->validateData()) {
			    try {
				    $strReturn = $this->actionSave();
				    if($strReturn == "")
				        header("Location: "._indexpath_."?page=".$this->getPagename());
			    }
			    catch (class_exception $objException) {
			        $objException->processException();
			        $strReturn = "An internal error occured: ".$objException->getMessage();
			    }
			}
			else {
				$this->setParam("eintragen_fehler", $this->getText("eintragen_fehler"));
				$strReturn = $this->actionInsert($this->getAllParams());
			}
		}
		else
		    $strReturn = $this->actionList();

		return $strReturn;

	}

//---Aktionsfunktionen-----------------------------------------------------------------------------------

	/**
	 * Returns a list of all posts in the current gb
	 *
	 * @return string
	 */
	public function actionList() {
		$strReturn = "";
		$arrTemplate = array();
		$arrTemplate["liste_posts"] ="";
        //Load all posts
        include_once(_systempath_."/class_array_section_iterator.php");
	    $objArraySectionIterator = new class_array_section_iterator(class_modul_guestbook_post::getPostsCount($this->arrElementData["guestbook_id"], true));
	    $objArraySectionIterator->setIntElementsPerPage($this->arrElementData["guestbook_amount"]);
	    $objArraySectionIterator->setPageNumber((int)($this->getParam("pv") != "" ? $this->getParam("pv") : 1));
	    $objArraySectionIterator->setArraySection(class_modul_guestbook_post::getPostsSection($this->arrElementData["guestbook_id"], true, $objArraySectionIterator->calculateStartPos(), $objArraySectionIterator->calculateEndPos()));

	    $arrObjPosts = $objArraySectionIterator->getArrayExtended();

		$arrObjPosts = $this->objToolkit->pager($this->arrElementData["guestbook_amount"], ($this->getParam("pv") != "" ? $this->getParam("pv") : 1), $this->getText("weiter"), $this->getText("zurueck"), "", ($this->getParam("page") != "" ? $this->getParam("page") : ""), $arrObjPosts);

		//and posts in the template!
		foreach($arrObjPosts["arrData"] as $objOnePost) {
			$strTemplatePostID = $this->objTemplate->readTemplate("/modul_guestbook/".$this->arrElementData["guestbook_template"], "post");
			$arrtemplatePost = array();
			$arrtemplatePost["post_name"] = "<a href=\"mailto:".$objOnePost->getGuestbookPostEmail()."\">".$objOnePost->getGuestbookPostName()."</a>";
			$arrtemplatePost["post_page"] = "<a href=\"http://".$objOnePost->getGuestbookPostPage()."\">".$objOnePost->getGuestbookPostPage()."</a>";
			$arrtemplatePost["post_text"] = $objOnePost->getGuestbookPostText();
			//replace encoded newlines
			$arrtemplatePost["post_text"] = uniStrReplace("&lt;br /&gt;", "<br />" , $arrtemplatePost["post_text"]);
			$arrtemplatePost["post_date"] = timeToString($objOnePost->getGuestbookPostDate());
			$arrTemplate["liste_posts"] .= $this->objTemplate->fillTemplate($arrtemplatePost, $strTemplatePostID);
		}
        // A link to the post-form
		$arrTemplate["link_newentry"] = getLinkPortal(($this->getParam("page") ? $this->getParam("page") : ""), "", "", $this->getText("eintragen"), "insertGuestbook");
		$arrTemplate["link_forward"] = $arrObjPosts["strForward"];
		$arrTemplate["link_pages"] = $arrObjPosts["strPages"];
		$arrTemplate["link_back"] = $arrObjPosts["strBack"];

		$strTemplateID = $this->objTemplate->readTemplate("/modul_guestbook/".$this->arrElementData["guestbook_template"], "list");
		$strReturn .= $this->objTemplate->fillTemplate($arrTemplate, $strTemplateID);
		return $strReturn . "";
	}


	/**
	 * Creates a form to handle a new post
	 *
	 * @param mixed $arrTemplate values to fill in<commit_msg>modul_guestbook: rightView()-checking added to portal-class<commit_after><?php
/*"******************************************************************************************************
*   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
*   (c) 2007-2008 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
* 																										*
* 	class_modul_guestbook_portal.php																	*
* 	Portal-class of the guestbook       																*
*-------------------------------------------------------------------------------------------------------*
*	$Id$                             *
********************************************************************************************************/

//Include base classes
include_once(_portalpath_."/class_portal.php");
include_once(_portalpath_."/interface_portal.php");

//include needed classes
include_once(_systempath_."/class_modul_guestbook_post.php");
include_once(_systempath_."/class_modul_guestbook_guestbook.php");

/**
 * Portal-class of the guestbook. Handles postings
 *
 * @package modul_guestbook
 */
class class_modul_guestbook_portal extends class_portal implements interface_portal {
	/**
	 * Constructor
	 *
	 * @param mixed $arrElementData
	 */
	public function __construct($arrElementData) {
		$arrModul["name"] 				= "modul_guestbook";
		$arrModul["author"] 			= "<EMAIL>";
		$arrModul["table"] 	    		= _dbprefix_."guestbook_book";
		$arrModul["table2"] 			= _dbprefix_."guestbook_post";
		$arrModul["moduleId"] 			= _gaestebuch_modul_id_;
		$arrModul["modul"] 			    = "guestbook";

        parent::__construct($arrModul, $arrElementData);
	}

	/**
	 * Action-block, controling the behaviour of the class
	 *
	 * @return string
	 */
	public function action() {
		$strReturn = "";
		$strAction = "";

		if($this->getParam("action") != "")
		    $strAction = $this->getParam("action");

		if($strAction == "insertGuestbook")
			$strReturn = $this->actionInsert();
		elseif($strAction == "saveGuestbook") {
			if($this->validateData()) {
			    try {
				    $strReturn = $this->actionSave();
				    if($strReturn == "")
				        header("Location: "._indexpath_."?page=".$this->getPagename());
			    }
			    catch (class_exception $objException) {
			        $objException->processException();
			        $strReturn = "An internal error occured: ".$objException->getMessage();
			    }
			}
			else {
				$this->setParam("eintragen_fehler", $this->getText("eintragen_fehler"));
				$strReturn = $this->actionInsert($this->getAllParams());
			}
		}
		else
		    $strReturn = $this->actionList();

		return $strReturn;

	}

//---Aktionsfunktionen-----------------------------------------------------------------------------------

	/**
	 * Returns a list of all posts in the current gb
	 *
	 * @return string
	 */
	public function actionList() {
		$strReturn = "";
		$arrTemplate = array();
		$arrTemplate["liste_posts"] ="";
        //Load all posts
        include_once(_systempath_."/class_array_section_iterator.php");
	    $objArraySectionIterator = new class_array_section_iterator(class_modul_guestbook_post::getPostsCount($this->arrElementData["guestbook_id"], true));
	    $objArraySectionIterator->setIntElementsPerPage($this->arrElementData["guestbook_amount"]);
	    $objArraySectionIterator->setPageNumber((int)($this->getParam("pv") != "" ? $this->getParam("pv") : 1));
	    $objArraySectionIterator->setArraySection(class_modul_guestbook_post::getPostsSection($this->arrElementData["guestbook_id"], true, $objArraySectionIterator->calculateStartPos(), $objArraySectionIterator->calculateEndPos()));

	    $arrObjPosts = $objArraySectionIterator->getArrayExtended();

		$arrObjPosts = $this->objToolkit->pager($this->arrElementData["guestbook_amount"], ($this->getParam("pv") != "" ? $this->getParam("pv") : 1), $this->getText("weiter"), $this->getText("zurueck"), "", ($this->getParam("page") != "" ? $this->getParam("page") : ""), $arrObjPosts);

		//and posts in the template!
		foreach($arrObjPosts["arrData"] as $objOnePost) {
			if($this->objRights->rightView($objOnePost->getSystemid())){
				$strTemplatePostID = $this->objTemplate->readTemplate("/modul_guestbook/".$this->arrElementData["guestbook_template"], "post");
				$arrtemplatePost = array();
				$arrtemplatePost["post_name"] = "<a href=\"mailto:".$objOnePost->getGuestbookPostEmail()."\">".$objOnePost->getGuestbookPostName()."</a>";
				$arrtemplatePost["post_page"] = "<a href=\"http://".$objOnePost->getGuestbookPostPage()."\">".$objOnePost->getGuestbookPostPage()."</a>";
				$arrtemplatePost["post_text"] = $objOnePost->getGuestbookPostText();
				//replace encoded newlines
				$arrtemplatePost["post_text"] = uniStrReplace("&lt;br /&gt;", "<br />" , $arrtemplatePost["post_text"]);
				$arrtemplatePost["post_date"] = timeToString($objOnePost->getGuestbookPostDate());
				$arrTemplate["liste_posts"] .= $this->objTemplate->fillTemplate($arrtemplatePost, $strTemplatePostID);
			}
		}
        // A link to the post-form
		$arrTemplate["link_newentry"] = getLinkPortal(($this->getParam("page") ? $this->getParam("page") : ""), "", "", $this->getText("eintragen"), "insertGuestbook");
		$arrTemplate["link_forward"] = $arrObjPosts["strForward"];
		$arrTemplate["link_pages"] = $arrObjPosts["strPages"];
		$arrTemplate["link_back"] = $arrObjPosts["strBack"];

		$strTemplateID = $this->objTemplate->readTemplate("/modul_guestbook/".$this->arrElementData["guestbook_template"], "list");
		$strReturn .= $this->objTemplate->fillTemplate($arrTemplate, $strTemplateID);
		return $strReturn . "";
	}


	/**
	 * Creates a form to handle a new post
	 *
	 * @param mixed $arrTemplate values to fill in
{'fraction_non_alphanumeric': 0.2414348710990502, 'fraction_numerical': 0.0035617367706919944, 'mean_word_length': 3.2102820421278113, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 122, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7245883', 'n_tokens_mistral': 3858, 'n_tokens_neox': 3447, 'n_words': 486}