Example #1
0
     }
     break;
     /* LOGIN */
 /* LOGIN */
 case 'login':
     if (!isset($_POST['username']) || !strlen(trim($_POST['username']))) {
         $arrReturnValue['response'] = 'Invalid param username.';
     } elseif (!isset($_POST['password']) || !strlen(trim($_POST['password']))) {
         $arrReturnValue['response'] = 'Invalid param password.';
     } else {
         $intLoginState = isset($_POST['invisible']) && $_POST['invisible'] == 1 ? Client::USER_IS_OFFLINE : Client::USER_IS_ONLINE;
         try {
             $objYM = new Client(trim($_POST['username']), trim($_POST['password']), APP_CONSUMER_KEY, APP_CONSUMER_SECRET);
             $objYM->logIn($intLoginState);
             /* get groups & contacts */
             $groups = $objYM->fetchGroups();
             $arrAjaxResponse = array();
             foreach ($groups['groups'] as $group) {
                 $groupName = htmlspecialchars($group['group']['name']);
                 $arrAjaxResponse[$groupName] = array();
                 foreach ($group['group']['contacts'] as $contact) {
                     $buddy = array('id' => $contact['contact']['id'], 'name' => (isset($contact['contact']['addressbook']['firstname']) ? $contact['contact']['addressbook']['firstname'] : '') . ' ' . (isset($contact['contact']['addressbook']['lastname']) ? $contact['contact']['addressbook']['lastname'] : ''));
                     if (!strlen(trim($buddy['name']))) {
                         $buddy['name'] = $buddy['id'];
                     }
                     $buddy['name'] = htmlspecialchars(trim($buddy['name']));
                     switch ($contact['contact']['presence']['presenceState']) {
                         case Client::USER_IS_ONLINE:
                             $buddy['state'] = 'online';
                             $buddy['status'] = isset($contact['contact']['presence']['presenceMessage']) ? $contact['contact']['presence']['presenceMessage'] : '';
                             break;