We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10380
    • 6 Posts
    I have a guest book type set-up and I would like to limit users (registered users and unregistered IP addresses) from posting more than once every 6 months. I tried changing the postdelay variable to 12000555 seconds or so but the problem is that I have several different guest book pages that I would like each user to be able to post on every six months. With the post delay set that high they can only post on one of the pages every 6 months.

    I’m guessing I’ll have to modify the actual Jot code which I’m sure I can figure out but if anyone knows an easier way or could tell me what to edit in the Jot code that would be great. Thanks!
      • 10380
      • 6 Posts
      I did end up editing the Jot snippet in order to do this. If anyone else wants to do it or maybe add it into the main Jot code, here is what I did:

      In assets\snippets\jot\jot.class.inc.php:

      At about line 85 add:

      $this->config["postdelayForPage"] = !is_null($this->Get("postdelayForPage")) ? $this->Get("postdelayForPage") : 0; // Set post delay for page in seconds


      At about line 536 add:
      		//-- Security check for page (Post Delay?)
      		if ($saveComment && $this->form['error'] == 0 && $this->config["postdelayForPage"] != 0 && $pObj->hasPostedOnPage($this->config["postdelayForPage"],$this->config["user"],$this->config["docid"])) {
      			$this->form['error'] = 30; // Post too fast (within delay)
      			return;
      		};
      



      In assets\snippets\jot\includes\jot.db.class.inc.php:

      At about line 173 add:
      	function hasPostedOnPage($interval,$user,$docid) {
      		global $modx;
      		$chktime = strtotime("-".$interval." seconds");
      		$sql = 'SELECT count(id) as post FROM '.$this->tbl["content"].' WHERE uparent = '.$docid.' AND sechash = "'.$user['sechash'].'" AND createdon > '.$chktime;
      		$returnValue = intval($modx->db->getValue($sql));
      		if ($returnValue > 0 ) { return true; } else { return false; }
      	}


      And finally, In the Jot snippet in ModX add this line add the bottom:
      $Jot->Set("postdelayForPage", $postdelayForPage);


      Then on whichever page or chunk that you call Jot you can add the attribute &postdelayForPage=`15552000` to limit the number of seconds that someone can post on the same page.

      Note: You will probably also want to add a custom error message in your form such as:
      &30=You can only submit a guestbook posting on this page every six months.