示例#1
0
 /**
  * Get an array of all lists, and their groups!
  *
  * @param string $storeId
  * @return  array
  */
 public function getDataArray($storeId)
 {
     $selectLists = array();
     // If cache is set, use that
     if (isset($this->_cache[$storeId])) {
         return $this->_cache[$storeId];
     }
     // If login details not set, return empty list
     if (!$this->_config()->getUrlConsole($storeId) || !$this->_config()->getUsername($storeId) || !$this->_config()->getPassword($storeId)) {
         if (Mage::getStoreConfig('mailup_newsletter/mailup/enable_log', $storeId)) {
             Mage::log('Login details not complete - cannot retrieve lists');
         }
         return $selectLists;
     }
     // Attempt login (return empty if fails)
     $wsSend = new MailUpWsSend($storeId);
     $accessKey = $wsSend->loginFromId();
     if ($accessKey === false) {
         if (Mage::getStoreConfig('mailup_newsletter/mailup/enable_log', $storeId)) {
             Mage::log('Login failed - cannot retrieve lists');
         }
         return $selectLists;
     }
     // Attempt to make call to get lists from API
     require_once dirname(__DIR__) . "/MailUpWsImport.php";
     $wsImport = new MailUpWsImport($storeId);
     $xmlString = $wsImport->GetNlList();
     if (!$xmlString) {
         if (Mage::getStoreConfig('mailup_newsletter/mailup/enable_log', $storeId)) {
             Mage::log('MailUpWsImport got empty response when fetching lists even though login succeeded');
         }
         return $selectLists;
     }
     // Try to decode response. If <Lists> is not in selection, then return
     $xmlString = html_entity_decode($xmlString);
     $startLists = strpos($xmlString, '<Lists>');
     // On XML error, $startLists will fail
     if ($startLists === false) {
         if (Mage::getStoreConfig('mailup_newsletter/mailup/enable_log', $storeId)) {
             Mage::log('MailUpWsImport got error response when fetching lists');
         }
         return $selectLists;
     }
     // Extract lists and their groups from <List> section of response
     $endPos = strpos($xmlString, '</Lists>');
     $endLists = $endPos + strlen('</Lists>') - $startLists;
     $xmlLists = substr($xmlString, $startLists, $endLists);
     $xmlLists = str_replace("&", "&amp;", $xmlLists);
     $xml = simplexml_load_string($xmlLists);
     foreach ($xml->List as $list) {
         $groups = array();
         foreach ($list->Groups->Group as $tmp) {
             $groups[(string) $tmp["idGroup"]] = (string) $tmp["groupName"];
         }
         $selectLists[(string) $list['idList']] = array('idList' => (string) $list['idList'], 'listName' => (string) $list['listName'], 'listGUID' => (string) $list['listGUID'], "groups" => $groups);
     }
     // Cache results as this is a success
     $this->_cache[$storeId] = $selectLists;
     return $selectLists;
 }
示例#2
0
 /**
  * Get ListGuid (Alphanumeric code associated to a distribution list) for given list
  *
  * @param $listId
  * @return false|string
  */
 public function getListGuid($listId)
 {
     $wsImport = new MailUpWsImport();
     $xmlString = $wsImport->GetNlList();
     if (!$xmlString) {
         return $this;
     }
     $xmlString = html_entity_decode($xmlString);
     $startLists = strpos($xmlString, '<Lists>');
     $endPos = strpos($xmlString, '</Lists>');
     $endLists = $endPos + strlen('</Lists>') - $startLists;
     $xmlLists = substr($xmlString, $startLists, $endLists);
     $xmlLists = str_replace("&", "&amp;", $xmlLists);
     $xml = simplexml_load_string($xmlLists);
     $listGUID = false;
     foreach ($xml->List as $list) {
         if ($list['idList'] == $listId) {
             $listGUID = $list["listGUID"];
             break;
         }
     }
     return $listGUID;
 }