コード例 #1
0
ファイル: helper.php プロジェクト: Lothurm/J3.x
 function getTechnology()
 {
     static $_technology;
     $app = JFactory::getApplication('site');
     $input = $app->input;
     $params = $app->getParams();
     $indCookie = $params->get('indCookies', true);
     if ($indCookie) {
         $cookie = new JInputCookie();
     }
     // use cookies
     if (!isset($_technology)) {
         // Find the value for tech - first from the cookie when cookies are used
         if ($indCookie) {
             $tmp = $cookie->get('tech');
         }
         if (!isset($tmp)) {
             // if not found in cookie -> look in url
             $tmp = $input->get('tech');
         }
         if (!isset($tmp)) {
             // if not found in url -> set default value of 'a'
             $_technology = 'a';
         } else {
             if ($tmp != 'a' and $tmp != 'j' and $tmp != 'b') {
                 // if technology is wrong value -> set default value of 'a'
                 $_technology = 'a';
             } else {
                 $_technology = $tmp;
             }
         }
     }
     if ($indCookie) {
         // set up a cookie for non default value
         if ($_technology != 'a') {
             //set a cookie for 1 hour = 3600 seconds
             $expire = time() + 60 * 60;
             //setcookie("tech", $_technology, time()+3600, "/","", 0);
         } else {
             //delete cookie by setting 1 hour (= 3600 seconds) in the past
             $expire = time() - 60 * 60;
             //setcookie("tech", $_technology, time()-3600, "/","", 0);
         }
         $cookie->set('tech', $_technology, $expire, '/');
     }
     return $_technology;
 }
コード例 #2
0
ファイル: joaktree.php プロジェクト: Lothurm/J3.x
 public function setCookie()
 {
     static $indOneTime;
     if (isset($indOneTime) && $indOneTime) {
         return true;
     }
     // set up cookie
     $params = JoaktreeHelper::getJTParams();
     $indCookie = $params->get('indCookies', true);
     if ($indCookie) {
         // we fetch the cookie
         $cookie = new JInputCookie();
         $tmp = $cookie->get('jt_last_persons', '', 'string');
         // prepare the array
         if ($tmp) {
             $personList = (array) json_decode(base64_decode($tmp));
         } else {
             $personList = array();
         }
         // check whether this person is already in array
         $person =& $this->getPerson();
         $value = $person->app_id . '!' . $person->id . '!' . $person->tree_id;
         if (in_array($value, $personList)) {
             // loop through array and move person to first position
             $newList = array();
             $newList[] = $value;
             foreach ($personList as $item) {
                 if ($item != $value) {
                     $newList[] = $item;
                 }
             }
         } else {
             // place the first person to start of array
             $newList = $personList;
             array_unshift($newList, $value);
         }
         // if the array is too big, remove the last person
         if (count($newList) > 10) {
             array_pop($newList);
         }
         // and store the new cookie
         //$expire = mktime().time()+60*60*24*180;
         $expire = time() + 60 * 60 * 24 * 180;
         $cookie->set('jt_last_persons', base64_encode(json_encode($newList)), $expire, '/');
     }
     $indOneTime = true;
     return true;
 }