public function loadAction() { $request = new Varien_Object($this->getRequest()->getParams()); if ($request && $request->getKey()) { $uploader = new Mage_Core_Model_File_Uploader('file'); $allowed = Mage::getSingleton('cms/wysiwyg_images_storage')->getAllowedExtensions('image'); $uploader->setAllowedExtensions($allowed); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $result = $uploader->save(Mage::helper('cms/wysiwyg_images')->getCurrentPath()); $imageUrl = sprintf('/media/%s/%s', Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY, $result['file']); $array = array('filelink' => $imageUrl, 'filename' => $_FILES['file']['name']); echo stripslashes(json_encode($array)); exit; } }
/** * Add field to Options form based on option configuration * * @param Varien_Object $parameter * @return Varien_Data_Form_Element_Abstract */ protected function _addField($parameter) { if ($parameter->getKey() != 'template') { return parent::_addField($parameter); } return false; }
/** * Code partially taken from the old Zopim Live Chat Module * A lot has been improved but can still better be improved * @todo split into several actions if possible */ public function accountAction() { $this->loadLayout(); $chatAccountBlock = $this->getLayout()->getBlock('zopim_account'); $key = Mage::getStoreConfig('chat/chatconfig/key'); $username = Mage::getStoreConfig('chat/chatconfig/username'); $salt = Mage::getStoreConfig('chat/chatconfig/salt'); $zopimObject = new Varien_Object(array('key' => $key, 'username' => $username, 'salt' => $salt)); $error = array(); $gotologin = 0; if ($this->getRequest()->getParam('deactivate') == "yes") { $zopimObject->setSalt(null); $zopimObject->setKey('zopim'); } else { if ($this->getRequest()->getParam('zopimusername') != "") { // logging in $zopimusername = $this->getRequest()->getParam('zopimusername'); $zopimpassword = $this->getRequest()->getParam('zopimpassword'); $logindata = array("email" => $zopimusername, "password" => $zopimpassword); $loginresult = Zend_Json::decode(Mage::helper('chat')->doPostRequest(Diglin_Chat_Helper_Data::ZOPIM_LOGIN_URL, $logindata)); if (isset($loginresult["error"])) { $error["login"] = $this->__("<b>Could not log in to Zopim. Please check your login details. If problem persists, try connecting without SSL enabled.</b>"); $gotologin = 1; $zopimObject->setSalt(null); } elseif (isset($loginresult["salt"])) { $zopimObject->setUsername($zopimusername); $zopimObject->setSalt($loginresult["salt"]); $account = Zend_Json::decode(Mage::helper('chat')->doPostRequest(Diglin_Chat_Helper_Data::ZOPIM_GETACCOUNTDETAILS_URL, array("salt" => $loginresult["salt"]))); if (isset($account)) { $zopimObject->setKey($account["account_key"]); } } else { $zopimObject->setSalt(null); $error["login"] = $this->__("<b>Could not log in to Zopim. We were unable to contact Zopim servers. Please check with your server administrator to ensure that <a href='http://www.php.net/manual/en/book.curl.php'>PHP Curl</a> is installed and permissions are set correctly.</b>"); } } else { if ($this->getRequest()->getParam('zopimfirstname') != "") { $createdata = array("email" => $this->getRequest()->getParam('zopimnewemail'), "first_name" => $this->getRequest()->getParam('zopimfirstname'), "last_name" => $this->getRequest()->getParam('zopimlastname'), "display_name" => $this->getRequest()->getParam('zopimfirstname') . " " . $this->getRequest()->getParam('zopimlastname'), "aref_id" => '477070', "eref" => "", "source" => "magento", "recaptcha_challenge_field" => $this->getRequest()->getParam('recaptcha_challenge_field'), "recaptcha_response_field" => $this->getRequest()->getParam('recaptcha_response_field')); $signupresult = Zend_Json::decode(Mage::helper('chat')->doPostRequest(Diglin_Chat_Helper_Data::ZOPIM_SIGNUP_URL, $createdata)); if (isset($signupresult["error"])) { $error["auth"] = $this->__("Error during activation: <b>" . $signupresult["error"] . "</b> Please try again."); } else { if (isset($signupresult["account_key"])) { $message = $this->__("<b>Thank you for signing up. Please check your mail for your password to complete the process. </b>"); $gotologin = 1; } else { if (isset($signupresult['url'])) { $message = $this->__('<b>Thank you for signing up. Please click on <button onclick="%s"><span><span>this button</span></span></button> to complete the process.</b>', "window.open('" . $signupresult['url'] . "')"); $gotologin = 1; } else { $error["auth"] = $this->__("<b>Could not activate account. The Magento installation was unable to contact Zopim servers. Please check with your server administrator to ensure that <a href='http://www.php.net/manual/en/book.curl.php'>PHP Curl</a> is installed and permissions are set correctly.</b>"); } } } } } } if ($zopimObject->getKey() != "" && $zopimObject->getKey() != "zopim") { if (isset($account)) { $accountDetails = $account; } else { $accountDetails = Zend_Json::decode(Mage::helper('chat')->doPostRequest(Diglin_Chat_Helper_Data::ZOPIM_GETACCOUNTDETAILS_URL, array("salt" => $zopimObject->getSalt()))); } if (!isset($accountDetails) || isset($accountDetails["error"])) { $gotologin = 1; $error["auth"] = $this->__('Account no longer linked! We could not verify your Zopim account. Please check your password and try again.'); } else { $chatAccountBlock->setIsAuthenticated(true); } } if (isset($error["auth"])) { $this->_getSession()->addError($error["auth"]); } else { if (isset($error["login"])) { $this->_getSession()->addError($error["login"]); } else { if (isset($message)) { $this->_getSession()->addSuccess($message); } } } if ($chatAccountBlock->getIsAuthenticated()) { if ($accountDetails["package_id"] == "trial") { $accountDetails["package_id"] = "Free Lite Package + 14 Days Full-features"; } else { $accountDetails["package_id"] .= " Package"; } } else { if ($this->getRequest()->getParam('zopimfirstname')) { $chatAccountBlock->setWasChecked('checked'); } if (!$chatAccountBlock->getIsAuthenticated() && $gotologin != 1) { $chatAccountBlock->setShowSignup('showSignup(1);'); } else { $chatAccountBlock->setShowSignup('showSignup(0);'); } } $chatAccountBlock->setUsername($zopimObject->getUsername()); if (isset($accountDetails)) { $chatAccountBlock->setAccountDetails($accountDetails["package_id"]); } // Save values into configuration $config = Mage::getConfig(); if ($zopimObject->getKey() && $zopimObject->getKey() != 'zopim') { $config->saveConfig('chat/chatconfig/enabled', 1, 'default', 0); } if ($zopimObject->getKey() == 'zopim') { $zopimObject->setKey(null); $config->saveConfig('chat/chatconfig/enabled', 0, 'default', 0); } $config->saveConfig('chat/chatconfig/key', $zopimObject->getKey(), 'default', 0); $config->saveConfig('chat/chatconfig/username', $zopimObject->getUsername(), 'default', 0); $config->saveConfig('chat/chatconfig/salt', $zopimObject->getSalt(), 'default', 0); Mage::app()->cleanCache(array(Mage_Core_Model_Config::CACHE_TAG)); $this->_initLayoutMessages('adminhtml/session'); $this->renderLayout(); }
/** * Add field to Options form based on parameter configuration * * @param Varien_Object $parameter * @return Varien_Data_Form_Element_Abstract */ protected function _addField($parameter) { $form = $this->getForm(); $fieldset = $this->getMainFieldset(); //$form->getElement('options_fieldset'); // prepare element data with values (either from request of from default values) $fieldName = $parameter->getKey(); $data = array('name' => $form->addSuffixToName($fieldName, 'parameters'), 'label' => $this->_translationHelper->__($parameter->getLabel()), 'required' => $parameter->getRequired(), 'class' => 'widget-option', 'note' => $this->_translationHelper->__($parameter->getDescription())); if ($values = $this->getWidgetValues()) { $data['value'] = isset($values[$fieldName]) ? $values[$fieldName] : ''; } else { $data['value'] = $parameter->getValue(); //prepare unique id value if ($fieldName == 'unique_id' && $data['value'] == '') { $data['value'] = md5(microtime(1)); } } // prepare element dropdown values if ($values = $parameter->getValues()) { // dropdown options are specified in configuration $data['values'] = array(); foreach ($values as $option) { $data['values'][] = array('label' => $this->_translationHelper->__($option['label']), 'value' => $option['value']); } } elseif ($sourceModel = $parameter->getSourceModel()) { $data['values'] = Mage::getModel($sourceModel)->toOptionArray(); } // prepare field type or renderer $fieldRenderer = null; $fieldType = $parameter->getType(); // hidden element if (!$parameter->getVisible()) { $fieldType = 'hidden'; } elseif (false !== strpos($fieldType, '/')) { $fieldRenderer = $this->getLayout()->createBlock($fieldType); $fieldType = $this->_defaultElementType; } // instantiate field and render html $field = $fieldset->addField($this->getMainFieldsetHtmlId() . '_' . $fieldName, $fieldType, $data); if ($fieldRenderer) { $field->setRenderer($fieldRenderer); } // extra html preparations if ($helper = $parameter->getHelperBlock()) { $helperBlock = $this->getLayout()->createBlock($helper->getType(), '', $helper->getData()); if ($helperBlock instanceof Varien_Object) { $helperBlock->setConfig($helper->getData())->setFieldsetId($fieldset->getId())->setTranslationHelper($this->_translationHelper)->prepareElementHtml($field); } } // dependencies from other fields $dependenceBlock = $this->getChild('form_after'); $dependenceBlock->addFieldMap($field->getId(), $fieldName); if ($parameter->getDepends()) { foreach ($parameter->getDepends() as $from => $row) { $values = isset($row['values']) ? array_values($row['values']) : (string) $row['value']; $dependenceBlock->addFieldDependence($fieldName, $from, $values); } } return $field; }
public function render(Varien_Object $row) { $domainName = Mage::getStoreConfig(Eltrino_DiamanteDesk_Helper_Data::XML_PATH_DIAMANTE_DESK_API_SERVER_ADDRESS); return sprintf('<a href="%s" target="_blank">%s</a>', trim($domainName, '/') . static::LINK_TO_DIAMANTEDESK_TICKET_BACKEND . $row->getKey(), Mage::helper('eltrino_diamantedesk')->__('View in DiamanteDesk')); }