public function Process() { $this->cachedir = JPATH_ROOT . "/cache/" . get_class($this); file_exists($this->cachedir) or mkdir($this->cachedir); //$this->CacheLifetime = intval($this->Params->get("cache_lifetime", 2)) * 60; // Converte da minuti in secondi $this->CacheLifetime = 2 * 60; // Converte da minuti in secondi 2 minuti $tw_consumer_key = trim($this->Params->get("twitter_consumer_key", "")); $tw_consumer_secret = trim($this->Params->get("twitter_consumer_secret", "")); $app_id = trim($this->Params->get("pusher_app_id", "")); $app_key = trim($this->Params->get("pusher_app_key", "")); $app_secret = trim($this->Params->get("pusher_app_secret", "")); /* if (isset($_POST['channel_name']) && isset($_POST['socket_id']) && isset($_POST['only_get_num']) && $_POST['only_get_num']){ $verify_channel=$_POST['channel_name'];//private- presence- $verify_socketid=$_POST['socket_id']; $parts=explode('-',$verify_channel); $channel_type=$parts[0]; if ($channel_type == 'presence'){ $pusher = new Pusher($app_key, $app_secret, $app_id); $presence_data = array( 'displayName' => 'hidden', 'objectType' => 'person', 'image' => array('url'=>''), 'userid'=>'hidden-hidden', 'link'=>'' ); echo $pusher->presence_auth($verify_channel, $verify_socketid, $presence_data['userid'], $presence_data); JFactory::getApplication()->close(); } } */ if (isset($_POST['only_get_num']) && $_POST['only_get_num']) { if (!isset($_POST['channel_name'])) { $this->returnError("Invalid channel"); } $verify_channel = $_POST['channel_name']; //private- presence- $parts = explode('-', $verify_channel); $channel_type = $parts[0]; if ($channel_type == 'presence') { //Caching! QUi $cache_expired = true; $num_users_connected = 0; $cachefile = $this->cachedir . "/" . $this->getHash(array($app_key, $verify_channel), array($app_secret, $app_id)); if (file_exists($cachefile)) { $age = time() - filemtime($cachefile); $lt = $this->CacheLifetime; if ($age < $lt) { $num_users_connected = file_get_contents($cachefile); $cache_expired = false; } } if ($cache_expired) { $pusher = new Pusher($app_key, $app_secret, $app_id); //echo json_encode($pusher->get('/channels/'.$verify_channel.'/members')); $users = $pusher->get('/channels/' . $verify_channel . '/users'); $users = json_decode($users['body'], true); $num_users_connected = count($users['users']); file_put_contents($cachefile, $num_users_connected); } //error_log(var_export($users,true)."\n",3,'C:\workspace\php-errors.log'); echo json_encode(array('c' => $num_users_connected)); JFactory::getApplication()->close(); } else { $this->returnError("Invalid channel"); } } $anonymous_login = intval($this->Params->get("anonymous_login", "1")) == 1; $joomla_login = intval($this->Params->get("joomla_login", "1")) == 1; $facebook_login = false; $googleplus_login = false; $twitter_login = false; $fb_app_id = trim($this->Params->get("facebook_app_id", "")); $fb_app_secret = trim($this->Params->get("facebook_app_secret", "")); if (!empty($fb_app_id) && !empty($fb_app_secret)) { $facebook_login = true; } $gp_client_id = trim($this->Params->get("googleplus_client_id", "")); $gp_client_secret = trim($this->Params->get("googleplus_client_secret", "")); if (!empty($gp_client_id) && !empty($gp_client_secret)) { $googleplus_login = true; } if (!empty($tw_consumer_key) && !empty($tw_consumer_secret)) { $twitter_login = true; } $available_logins = array(); if ($anonymous_login) { $available_logins[] = 'anonymous'; } if ($joomla_login) { $available_logins[] = 'joomla'; } if ($facebook_login) { $available_logins[] = 'facebook'; } if ($googleplus_login) { $available_logins[] = 'googleplus'; } if ($twitter_login) { $available_logins[] = 'twitter'; } if ($twitter_login && isset($_REQUEST['tw_verify'])) { $this->twitter_verify_and_die($tw_consumer_key, $tw_consumer_secret); } if ($twitter_login && isset($_POST['tw_get'])) { $this->twitter_get_and_die($tw_consumer_key, $tw_consumer_secret); } if (isset($_POST['tw_get_status'])) { $this->twitterLogin(true); if ($this->logged_in) { header('Cache-Control: no-cache, must-revalidate'); header('Content-type: application/json'); echo json_encode($this->actor); JFactory::getApplication()->close(); die; } else { $this->returnError("Not logged in"); } } $this->logged_in = false; $this->actor = array(); $session = JFactory::getSession(); if (isset($_POST['logout'])) { $session_var_name = 'oc_user_id_' . $_POST['logout']; if ($session->has($session_var_name)) { $session->clear($session_var_name); } if ($_POST['logout'] == 'twitter' && $session->has("oc_twitter_oauth_access_token_response")) { $session->clear("oc_twitter_oauth_access_token_response"); } JFactory::getApplication()->close(); return; } $oc_logged_in = ''; if (!empty($_COOKIE['oc_logged_in'])) { $oc_logged_in = $_COOKIE['oc_logged_in']; } if (!empty($_POST['loginonly'])) { $oc_logged_in = $_POST['loginonly']; } if (!empty($oc_logged_in) && in_array($oc_logged_in, $available_logins)) { $session_var_name = 'oc_user_id_' . $oc_logged_in; if (isset($_COOKIE[$session_var_name]) && $session->has($session_var_name)) { $actor = $session->get($session_var_name); if ($actor['userid'] == $_COOKIE[$session_var_name]) { $this->logged_in = true; $this->actor = $actor; } } if (!$this->logged_in) { if ($oc_logged_in == 'googleplus') { $this->googleplusLogin(); } else { if ($oc_logged_in == 'facebook') { $this->facebookLogin(); } else { if ($oc_logged_in == 'joomla') { $this->joomlaLogin(); } else { if ($oc_logged_in == 'twitter') { $this->twitterLogin(); } else { if ($oc_logged_in == 'anonymous') { $this->anonymousLogin($_COOKIE['oc_anon_name'], $_COOKIE['oc_anon_email']); } } } } } if ($this->logged_in) { $session->set($session_var_name, $this->actor); } } } if (isset($_POST['loginonly'])) { if ($this->logged_in) { header('Cache-Control: no-cache, must-revalidate'); header('Content-type: application/json'); echo json_encode(array('OK')); //die(); JFactory::getApplication()->close(); return; } else { $this->returnError("Not logged in"); } } if (isset($_POST['channel_name']) && isset($_POST['socket_id'])) { //authendpoint private or presence $verify_channel = $_POST['channel_name']; //private- presence- $verify_socketid = $_POST['socket_id']; $parts = explode('-', $verify_channel); $channel_type = $parts[0]; if (!in_array($channel_type, array('private', 'presence'))) { $this->returnError('invalid private or presence channel'); } if ($this->logged_in) { $pusher = new Pusher($app_key, $app_secret, $app_id); $presence_data = $this->actor; if ($channel_type == 'presence') { echo $pusher->presence_auth($verify_channel, $verify_socketid, $this->actor['userid'], $presence_data); } else { echo $pusher->socket_auth($verify_channel, $verify_socketid); } JFactory::getApplication()->close(); } else { $this->returnError("Forbidden"); } return; } if (isset($_POST['chat_info'])) { //send message $channel_name = "private-" . $this->get_channel_name($this->Params->get("pusher_channel_name", "channel1")); $result = array(); //'activity' => $data, 'pusherResponse' => $response); //if (isset($_POST['chat_info']['logout']) && isset($_POST['chat_info']['logout']['logout_from'])){ //non devo fare nulla // $this->logged_in=false; //} if ($this->logged_in && isset($_POST['chat_info']['text']) && !empty($_POST['chat_info']['text'])) { //creo il messaggio date_default_timezone_set('UTC'); $data = array('id' => uniqid(), 'body' => mb_substr($_POST['chat_info']['text'], 0, 300), 'published' => date('r'), 'type' => 'chat-message', 'actor' => $this->actor); $data['actor']['displayName'] = mb_substr($data['actor']['displayName'], 0, 30); //invio del messaggio $pusher = new Pusher($app_key, $app_secret, $app_id); $response = $pusher->trigger($channel_name, 'chat_message', $data); $result = array('activity' => $data, 'pusherResponse' => $response); } //output result header('Cache-Control: no-cache, must-revalidate'); header('Content-type: application/json'); echo json_encode($result); //die(); JFactory::getApplication()->close(); return; } //se arrivo qui non è ne una presence ne una send $this->returnError('invalid data', 400); }