/** * Options getter for MailUp field mapping drop-down list * * @return array */ public function toOptionArray() { // If in this instantiation of Mage options have been fetched, return them, bypassing even cache if ($this->_options !== null) { return $this->_options; } $websiteCode = Mage::app()->getRequest()->getParam('website'); $storeCode = Mage::app()->getRequest()->getParam('store'); if ($storeCode) { $storeId = Mage::app()->getStore($storeCode)->getId(); $cacheId = 'mailup_fields_array_store_' . $storeId; } elseif ($websiteCode) { $storeId = Mage::app()->getWebsite($websiteCode)->getDefaultGroup()->getDefaultStoreId(); $cacheId = 'mailup_fields_array_store_' . $storeId; } else { $storeId = NULL; $cacheId = 'mailup_fields_array'; //$storeId = Mage::app()->getDefaultStoreView()->getStoreId(); } // Blank option $options = array(array('value' => '', 'label' => '')); // Attempt to fetch options from cache (handles invalidation after CACHE_LIFETIME) if (false !== ($data = Mage::app()->getCache()->load($cacheId))) { $options = unserialize($data); } else { // If cache is invalid, make request to MailUp via API $wsSend = new MailUpWsSend($storeId); $accessKey = $wsSend->loginFromId(); if ($accessKey !== false) { $wsFields = $wsSend->getFields($accessKey); if ($wsFields !== null) { foreach ($wsFields as $label => $value) { $options[] = array('value' => $value, 'label' => $label); } } // Only store a persistent cache of entries if there was a successful response from MailUp Mage::app()->getCache()->save(serialize($options), $cacheId, array(), self::CACHE_LIFETIME); } else { // Force options to be empty so that nothing is saved // (thus defaults or saved values will still be available) $options = array(); } } // Whether the cache was used, or a call was made (successfully or otherwise), store the result for this run $this->_options = $options; return $options; }
/** * Start the process, if we've already run NewImportProcess * and we have a process ID we can Start it. */ public function startProcessAction() { require_once dirname(__FILE__) . "/../Model/MailUpWsImport.php"; require_once dirname(__FILE__) . "/../Model/Wssend.php"; $wsSend = new MailUpWsSend($job->getStoreId()); $wsImport = new MailUpWsImport($job->getStoreId()); $accessKey = $wsSend->loginFromId(); /** * We need the ListID and ListGuid, which we will NOT * have for sync items, as we've not saved the process id * or anything else!! */ //StartProcess(int idList, int listGUID, int idProcess) /*$return = $wsImport->startProcess(array( 'idList' => $job->getListid(), 'listGUID' => $job->getListGuid(), 'idProcess' => $job->getProcessId() ));*/ }
public function deleteList() { $model = $this->getModel(); $cids = JRequest::getVar('cid', array(), '', 'array'); $row = JTable::getInstance('list', 'MailUpTable'); $componentParams =& JComponentHelper::getParams('com_mailup'); $url = $componentParams->get('FrontendURL', 'defaultValue'); $user_console = $componentParams->get('user', 'defaultValue'); $pwd_console = $componentParams->get('pwd', 'defaultValue'); $id_console = $componentParams->get('consoleID', 'defaultValue'); $nameUnique = $componentParams->get('nameUnique', 'defaultValue'); $WsSend = new MailUpWsSend(); $WsSend->loginFromId($user_console, $pwd_console, $id_console); foreach ($cids as $idList) { $row->load($idList); // COMMENTATA PER EVITARE DI CANCELLARE DATI SENSIBILI -> DA ABILITARE //$xmlLists = $WsSend->DeleteList($row->get('listid'), $nameUnique); $model->deleteLists($idList); } $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); }
public function applyList() { $model = $this->getModel(); $form = JRequest::get(); $plugin =& JPluginHelper::getPlugin('user', 'mailupsubscriber'); $pluginParams = new JParameter($plugin->params); //Passwor e username console $user_console = $pluginParams->get('user', 'defaultValue'); $pwd_console = $pluginParams->get('pwd', 'defaultValue'); $id_console = $pluginParams->get('consoleID', 'defaultValue'); $nameUnique = $pluginParams->get('nameUnique', 'defaultValue'); $WsSend = new MailUpWsSend(); $WsSend->loginFromId($user_console, $pwd_console, $id_console); $xmlLists = $WsSend->CreateList($form['jform']['name'], $nameUnique); if ($xmlLists) { $xml = $model->xmltostring($xmlString); foreach ($xml->List as $list) { $selectList = array('listId' => (string) $list['Id'], 'listName' => (string) $list['Name'], 'guid' => (string) $list['Guid']); } } $model->insertList($form['jform']['name'], $form['jform']['description'], $selectList['listId'], $selectList['guid'], $form['jform']['alias']); $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); }
/** * 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("&", "&", $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; }
public function testFieldsAction() { $wsSend = new MailUpWsSend(); $accessKey = $wsSend->loginFromId(); if ($accessKey !== false) { $fields = $wsSend->GetFields($accessKey); print_r($fields); die('success'); } else { die('no access key returned'); } }
/** * Test username and password by making a soap login request * * @param $usernameWs * @param $passwordWs * @param $storeId * @return boolean */ protected function _testConnectionUserPassword($usernameWs, $passwordWs, $storeId) { $wssend = new MailUpWsSend($storeId); $loginSuccess = $wssend->loginFromId($usernameWs, $passwordWs); return $loginSuccess !== false; }