Пример #1
0
 function downloadTemplatePackage()
 {
     $session = JFactory::getSession();
     $post = JRequest::get('post');
     $login_identifier = md5('state_update_login_' . strtolower($this->_template_name));
     $state_login = $session->get($login_identifier, false, 'jsntemplatesession');
     $link = '';
     if (!$state_login) {
         jexit('Invalid Token');
     }
     if ($this->_template_edition != '' && $this->_template_edition != 'free') {
         $edition = $this->_template_edition;
     } else {
         $edition = 'free';
     }
     $tmp_path = JPATH_ROOT . DS . 'tmp';
     if (is_writable($tmp_path)) {
         $post['customer_password'] = JRequest::getString('customer_password', '', 'post', JREQUEST_ALLOWRAW);
         $obj_updater_helper = new JSNAutoUpdaterHelper();
         $result = $obj_updater_helper->downloadTemplatePackage($post);
         if ($result) {
             $errorCode = strtolower((string) $result);
             switch ($errorCode) {
                 case 'err00':
                     $message = JText::_('JSN_SAMPLE_DATA_LIGHTCART_RETURN_ERR00');
                     break;
                 case 'err01':
                     $message = JText::_('JSN_SAMPLE_DATA_LIGHTCART_RETURN_ERR01');
                     break;
                 case 'err02':
                     $message = JText::_('JSN_SAMPLE_DATA_LIGHTCART_RETURN_ERR02');
                     break;
                 case 'err03':
                     $message = JText::_('JSN_SAMPLE_DATA_LIGHTCART_RETURN_ERR03');
                     break;
                 default:
                     $message = '';
                     break;
             }
             if ($message != '') {
                 $obj_updater_helper->destroySession();
                 echo json_encode(array('download' => false, 'file_name' => '', 'connection' => true, 'message' => $message, 'manual' => false));
             } else {
                 echo json_encode(array('download' => true, 'file_name' => (string) $result, 'connection' => true, 'message' => '', 'manual' => false));
             }
             return;
         } else {
             if ($edition == 'free') {
                 $templateNameParts = explode('_', strtolower($this->_template_name));
                 $link = 'http://www.joomlashine.com/joomla-templates/' . $templateNameParts[0] . '-' . $templateNameParts[1] . '-download.html';
             } else {
                 $link = 'http://www.joomlashine.com/customer-area.html';
             }
             $obj_updater_helper->destroySession();
             echo json_encode(array('download' => false, 'file_name' => '', 'message' => JText::sprintf('JSN_UPDATE_DOWNLOAD_FAILED', $link), 'connection' => false, 'manual' => true));
             return;
         }
     } else {
         $obj_updater_helper->destroySession();
         echo json_encode(array('download' => false, 'file_name' => '', 'message' => JText::_('JSN_UPDATE_TEMP_FOLDER_UNWRITABLE'), 'connection' => false, 'manual' => false));
         return;
     }
 }