Beispiel #1
0
 public function __construct(array $options = null)
 {
     if (is_array($options)) {
         $this->setOptions($options);
     }
     #Generate new ones with random hash built it as standard sir, for your safety!
     $this->_hash = Application_Model_Cookie::generateRandomKey();
 }
Beispiel #2
0
 public function testCookieModel()
 {
     $cookie = new Application_Model_Cookie();
     $cookie->setNick("testNick");
     $cookie->setEmail("*****@*****.**");
     $cookie->setDisplayMode(1);
     $cookie->setSaveName('testNickSave');
     $cookie->setPassword('testNickPass');
     $cookie->setTwitter('testNickTwit');
     $cookie->setFacebook('testNickFace');
     $cookie->setCCEmail('1');
     if ($cookie->getNick() != "testNick") {
         $this->fail("Nick SetterGetter Failed");
     }
     if ($cookie->getEmail() != "*****@*****.**") {
         $this->fail("Email SetterGetterFailed");
     }
     if ($cookie->getDisplayMode() != 1) {
         $this->fail("DisplayMode SetterGetterFailed");
     }
     if ($cookie->getSaveName() != 'testNickSave') {
         $this->fail("Savename GetterSetterFailed");
     }
     if ($cookie->getPassword() != 'testNickPass') {
         $this->fail("Password SetterGetterFailed");
     }
     if ($cookie->getTwitter() != 'testNickTwit') {
         $this->fail("Twitter SetterGetterFailed");
     }
     if ($cookie->getFacebook() != 'testNickFace') {
         $this->fail("Facebook SetterGetterFailed");
     }
     if ($cookie->getCCEmail() != '1') {
         $this->fail("CCEmail SetterGetterFailed");
     }
     $rkey = $cookie->generateRandomKey();
     if ($rkey == $cookie->generateRandomKey()) {
         $this->fail("Random Keys Aren't Random They're '{$rkey}'");
     }
     if (strlen($rkey) != 60) {
         $this->fail("Random Keys The Wrong Length, '{$rkey}' isn't 60 long");
     }
 }
Beispiel #3
0
 public function save(Application_Model_Cookie $cookie)
 {
     $data = array('id' => $cookie->getId(), 'nick' => $cookie->getNick(), 'displaymode' => $cookie->getDisplayMode(), 'savename' => $cookie->getSaveName(), 'email' => $cookie->getEmail(), 'password' => $cookie->getPassword(), 'twitter' => $cookie->getTwitter(), 'facebook' => $cookie->getFacebook(), 'ccemail' => $cookie->getCCEmail(), 'created' => date('Y-m-d H:i:s'), 'updated' => date('Y-m-d H:i:s'));
     if (!isset($data['id']) || $data['id'] === 0 || $data['id'] === null || $data['id'] == "") {
         $data['id'] = Application_Model_Cookie::generateRandomKey();
         $cookie->setId($data['id']);
         $this->getDbTable()->insert($data);
     } else {
         unset($data['created']);
         //Added by Pre: Don't want to change Created date when updating.
         $this->getDbTable()->update($data, array('id = ?' => $data['id']));
     }
 }
Beispiel #4
0
 protected function _generateHash()
 {
     $this->_hash = Application_Model_Cookie::generateRandomKey();
     $this->setValue($this->_hash);
     return $this->_hash;
 }
Beispiel #5
0
 public function doPollingStuffAndOutputJSON($jsonArray = array())
 {
     /***************************************************************
      * Every actions wants to return the polling data I reckon,
      * say if there's any new posts, update the CSRF etc.
      * so they all call this. Even the pollAction, which does
      * very little lese.
      */
     $cookie = Application_Model_DbTable_Cookie::getUserCookie();
     //Generate a new CSRF if this one is too old and tired.
     $csrf = $this->getRequest()->getParam('csrf');
     $csrfmapper = new Application_Model_CsrfhashMapper();
     $age = $csrfmapper->findAge($cookie->getId(), $csrf);
     if ($age == null || $age > 30) {
         //Either no or old CSR, give a new one.
         $csrf = Application_Model_Cookie::generateRandomKey();
         $csrfObj = $csrfmapper->findOrCreate($cookie->getId(), $csrf);
     }
     $url = addslashes($this->getRequest()->getParam('url'));
     $max = (int) $this->getRequest()->getParam('maxCommentId');
     $min = (int) $this->getRequest()->getParam('minCommentId');
     //Get all the comments for this URL that are higher in ID than $max.
     $this->comments = array();
     $dp = $this->convertUrlToDP($url);
     if (is_array($dp)) {
         $mapper = new Application_Model_CommentMapper();
         $dom = addslashes($dp['domain']);
         $path = addslashes($dp['path']);
         if ($min == null) {
             $minmax = "id > {$max}";
         } else {
             $minmax = "id < {$min}";
         }
         if ($cookie->getDisplayMode() == 2) {
             //All posts from the entire internet!? Are ou CRAZY!
             $rows = $mapper->findWhere($minmax);
         } else {
             if ($cookie->getDisplayMode() == 1) {
                 //All posts to any page on this domain. Sorted.
                 $rows = $mapper->findWhere("domain='" . $dom . "' and " . $minmax);
             } else {
                 $rows = $mapper->findWhere("domain='" . $dom . "' and path='" . $path . "' and " . $minmax);
             }
         }
         foreach ($rows as $r) {
             $this->comments[] = $mapper->convertRowToArray($r, $cookie);
         }
     }
     $sendArray = array_merge($jsonArray, array("comments" => $this->comments, "success" => "true", "setCookie" => $cookie->getId(), "url" => $url, "csrf" => $csrf));
     $this->getHelper('json')->sendJSON($sendArray);
 }