function checkTransaction($params, $order, $act)
 {
     $order->order_total = $this->fixOrderTotal($order);
     if ($params['user_id'] != $_POST['user_id']) {
         return array(0, 'Error user_id. Order ID ' . $order->order_id);
     }
     if ($order->order_total != $_POST['amount']) {
         return array(0, 'Error amount. Order ID ' . $order->order_id);
     }
     if ($order->currency_code_iso != $_POST['currency_id']) {
         return array(0, 'Error currency_id. Order ID ' . $order->order_id);
     }
     if ($params['notify_password']) {
         $params['project_password'] = $params['notify_password'];
     }
     $data = array('transaction' => $_POST['transaction'], 'user_id' => $_POST['user_id'], 'project_id' => $_POST['project_id'], 'sender_holder' => $_POST['sender_holder'], 'sender_account_number' => $_POST['sender_account_number'], 'sender_bank_code' => $_POST['sender_bank_code'], 'sender_bank_name' => $_POST['sender_bank_name'], 'sender_bank_bic' => $_POST['sender_bank_bic'], 'sender_iban' => $_POST['sender_iban'], 'sender_country_id' => $_POST['sender_country_id'], 'recipient_holder' => $_POST['recipient_holder'], 'recipient_account_number' => $_POST['recipient_account_number'], 'recipient_bank_code' => $_POST['recipient_bank_code'], 'recipient_bank_name' => $_POST['recipient_bank_name'], 'recipient_bank_bic' => $_POST['recipient_bank_bic'], 'recipient_iban' => $_POST['recipient_iban'], 'recipient_country_id' => $_POST['recipient_country_id'], 'international_transaction' => $_POST['international_transaction'], 'amount' => $_POST['amount'], 'currency_id' => $_POST['currency_id'], 'reason_1' => $_POST['reason_1'], 'reason_2' => $_POST['reason_2'], 'security_criteria' => $_POST['security_criteria'], 'user_variable_0' => $_POST['user_variable_0'], 'user_variable_1' => $_POST['user_variable_1'], 'user_variable_2' => $_POST['user_variable_2'], 'user_variable_3' => $_POST['user_variable_3'], 'user_variable_4' => $_POST['user_variable_4'], 'user_variable_5' => $_POST['user_variable_5'], 'created' => $_POST['created'], 'project_password' => $params['project_password']);
     $data_implode = implode('|', $data);
     $hash = sha1($data_implode);
     $return = 0;
     if ($_POST['security_criteria']) {
         if ($_POST['hash'] == $hash) {
             $return = 1;
         } else {
             saveToLog("paymentdata.log", "Error hash. " . $hash);
         }
     }
     return array($return, "");
 }
 function checkTransaction($pmconfigs, $order, $act)
 {
     $jshopConfig =& JSFactory::getConfig();
     if ($order->order_total != $_POST['amount']) {
         return array(0, 'Error amount. Order ID ' . $order->order_id);
     }
     if (strtolower($pmconfigs['email_received']) != strtolower($_POST['pay_to_email'])) {
         return array(0, 'Error pay_to_email. Order ID ' . $order->order_id);
     }
     if ($order->currency_code_iso != $_POST['currency']) {
         return array(0, 'Error currency. Order ID ' . $order->order_id);
     }
     $status = trim(stripslashes($_POST['status']));
     $merchant_id = $pmconfigs['merchant_id'];
     $transaction_id = trim(stripslashes($_POST['transaction_id']));
     $mb_amount = trim(stripslashes($_POST['mb_amount']));
     $mb_currency = trim(stripslashes($_POST['mb_currency']));
     $secretword = $pmconfigs['secretword'];
     if ($secretword == "") {
         $string = $merchant_id . $transaction_id . $mb_amount . $mb_currency . $status;
     } else {
         $string = $merchant_id . $transaction_id . strtoupper(md5($secretword)) . $mb_amount . $mb_currency . $status;
     }
     $check_md5 = strtoupper(md5($string));
     if ($check_md5 != $_POST['md5sig']) {
         return array(0, 'Error md5sig ' . $_POST['md5sig'] . '. Order ID ' . $order->order_id);
     }
     if ($status == 2) {
         return array(1, '');
     } elseif ($status == 0) {
         saveToLog("payment.log", "Status pending. Order ID " . $order->order_id . ".");
         return array(2, "Status pending");
     } elseif ($status == -1) {
         saveToLog("payment.log", "Status cancelled. Order ID " . $order->order_id . ".");
         return array(3, "Status cancelled");
     } elseif ($status == -2) {
         saveToLog("payment.log", "Status failed. Order ID " . $order->order_id . ".");
         return array(3, "Status failed");
     } elseif ($status == -3) {
         saveToLog("payment.log", "Status Chargeback. Order ID " . $order->order_id . ".");
         return array(3, "Status Chargeback");
     } else {
         saveToLog("payment.log", "Status " . $status . ". Order ID " . $order->order_id . ".");
         return array(0, "Status " . $status);
     }
 }
 function checkTransaction($pmconfigs, $order, $act)
 {
     $jshopConfig =& JSFactory::getConfig();
     $item_name = sprintf(_JSHOP_PAYMENT_NUMBER, $order->order_number);
     $pymentparamsdata = $order->getPaymentParamsData();
     $lang =& JSFactory::getLang();
     $field_country_name = $lang->get("name");
     $_country =& JTable::getInstance('country', 'jshop');
     $_country->load($order->country);
     $country = $_country->{$field_country_name};
     if ($pmconfigs['testserver']) {
         $post_url = "https://test.authorize.net/gateway/transact.dll";
     } else {
         $post_url = "https://secure.authorize.net/gateway/transact.dll";
     }
     $post_values = array("x_login" => $pmconfigs['login'], "x_tran_key" => $pmconfigs['tran_key'], "x_version" => "3.1", "x_delim_data" => "TRUE", "x_delim_char" => "|", "x_relay_response" => "FALSE", "x_type" => "AUTH_CAPTURE", "x_method" => "CC", "x_card_num" => $pymentparamsdata['card_number'], "x_exp_date" => $pymentparamsdata['month'] . $pymentparamsdata['year'], "x_amount" => $order->order_total, "x_description" => $item_name, "x_first_name" => $order->f_name, "x_last_name" => $order->l_name, "x_address" => $order->street, "x_state" => $order->state, "x_zip" => $order->zip, "x_city" => $order->city, "x_country" => $country, "x_invoice_num" => $order->order_number);
     if ($pmconfigs['testmode']) {
         $post_values['x_test_request'] = "TRUE";
     }
     $post_string = "";
     foreach ($post_values as $key => $value) {
         $post_string .= "{$key}=" . urlencode($value) . "&";
     }
     $post_string = rtrim($post_string, "& ");
     $request = curl_init($post_url);
     curl_setopt($request, CURLOPT_HEADER, 0);
     curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($request, CURLOPT_POSTFIELDS, $post_string);
     curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE);
     $post_response = curl_exec($request);
     curl_close($request);
     if ($jshopConfig->savelog && $jshopConfig->savelogpaymentdata) {
         saveToLog("paymentdata.log", $post_response);
     }
     $response_array = explode($post_values["x_delim_char"], $post_response);
     if ($response_array[0] == 1) {
         return array(1, '');
     } else {
         saveToLog("payment.log", "Error. Order ID " . $order->order_id . ". " . $response_array[3]);
         return array(3, $response_array[3]);
     }
 }
Example #4
0
 function checkTransaction($pmconfigs, $order, $act)
 {
     $lang = JFactory::getLanguage();
     require_once dirname(dirname(__DIR__)) . '/lang/' . __CLASS__ . '/' . $lang->getTag() . '.php';
     $jshopConfig = JSFactory::getConfig();
     if ($this->payment_status > 0 && $this->err === false) {
         $status = constant('_JSHOP_PAGSEGURO_STATUS_' . $this->payment_status);
         $num = _JSHOP_ORDER_NUMBER . ': ' . $order->order_id;
         if ($this->payment_status == 3 || $this->payment_status == 4) {
             return array(1, $status, $transaction, $transactiondata);
         } elseif ($this->payment_status < 3) {
             saveToLog("payment.log", "Status pending. ({$num}, Reason: {$status})");
             return array(2, "{$status} ({$num})", $transaction, $transactiondata);
         } else {
             return array(3, "{$status} ({$num})", $transaction, $transactiondata);
         }
     } else {
         return array(0, "Error: {$err}", $transaction, $transactiondata);
     }
 }
Example #5
0
 function resize()
 {
     $mainframe =& JFactory::getApplication();
     $jshopConfig =& JSFactory::getConfig();
     require_once $jshopConfig->path . 'lib/image.lib.php';
     JPluginHelper::importPlugin('jshoppingadmin');
     $dispatcher =& JDispatcher::getInstance();
     $filelist = glob($jshopConfig->image_product_path . '/' . 'full_*');
     foreach ($filelist as $key => $value) {
         $url = $value;
         $url_parts = pathinfo($url);
         //filenames
         $name_full = $url_parts['basename'];
         $name_image = substr($url_parts['basename'], 5);
         $name_thumb = "thumb_" . $name_image;
         //file path
         $path_image = $jshopConfig->image_product_path . '/' . $name_image;
         $path_thumb = $jshopConfig->image_product_path . '/' . $name_thumb;
         $path_full = $jshopConfig->image_product_path . '/' . $name_full;
         //resize thumb
         $product_width_image = $jshopConfig->image_product_width;
         $product_height_image = $jshopConfig->image_product_height;
         if (!ImageLib::resizeImageMagic($path_full, $product_width_image, $product_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
             JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL . " " . $name_thumb);
             saveToLog("error.log", "Resize Product Image - Error create thumbail " . $name_thumb);
             $error = 1;
         }
         //resize image
         $product_full_width_image = $jshopConfig->image_product_full_width;
         $product_full_height_image = $jshopConfig->image_product_full_height;
         if (!ImageLib::resizeImageMagic($path_full, $product_full_width_image, $product_full_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_image, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
             JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL . " " . $name_image);
             saveToLog("error.log", "Resize Product Image - Error create image " . $name_image);
             $error = 1;
         }
         $dispatcher->trigger('onAfterSaveProductImage', array($product_id, $name_image));
     }
     if (!JRequest::getInt("noredirect")) {
         $mainframe->redirect("index.php?option=com_jshopping&controller=resize&task=view", _JSHOP_COMPLETED);
     }
 }
 public function doRegAdv($adv_user, $user, $return_to_task = 'step2')
 {
     $session = JFactory::getSession();
     //сохраняем указанный метод оплаты в сессию
     $payment_method = JRequest::getVar('payment_method', '');
     //class payment method
     if ($payment_method != '') {
         $session->set("payment_method", $payment_method);
     }
     $order_add_info = JRequest::getVar('order_add_info', '');
     if ($order_add_info != '') {
         $session->set("order_add_info", $order_add_info);
     }
     //проверяем, есть ли такой мейл в базе и редиректим на логин если нужно
     if ($this->checkThisEmail($adv_user->email) == false) {
         $this->checkUserLogin($return_to_task);
     }
     require_once JPATH_ROOT . "/components/com_jshopping/lib/functions.php";
     //echo'<pre>';print_r($_POST);echo'</pre>';die;
     $mainframe = JFactory::getApplication();
     $jshopConfig = JSFactory::getConfig();
     $config = JFactory::getConfig();
     $db = JFactory::getDBO();
     $params = JComponentHelper::getParams('com_users');
     $lang = JFactory::getLanguage();
     $lang->load('com_users');
     //$post = JRequest::get('post');
     //		if ($user->guest) {
     //		$redirecturl = base64_encode("index.php?option=com_hostorder");
     //		$joomlaLoginUrl = 'index.php?option=com_user&view=login&return=';
     //		   $finalUrl = $joomlaLoginUrl.$redirecturl;
     //
     //		global $mainframe;
     //		$mainframe->redirect($finalUrl);
     //echo'<pre>';print_r($adv_user);echo'</pre>';die;
     $usergroup = JSFactory::getTable('usergroup', 'jshop');
     $default_usergroup = $usergroup->getDefaultUsergroup();
     $post = array();
     $post['email'] = $adv_user->email;
     $post['phone'] = $adv_user->phone;
     $post['username'] = $post['email'];
     $post['f_name'] = $adv_user->f_name;
     $post['l_name'] = $adv_user->l_name;
     $post['u_name'] = $adv_user->email;
     $post['country'] = JRequest::getVar('country', 20);
     $post['lang'] = $jshopConfig->getLang();
     $post["password"] = substr(md5('up' . time()), 0, 8);
     $row = JSFactory::getTable('userShop', 'jshop');
     $row->bind($post);
     $row->user_id = 0;
     $row->usergroup_id = $default_usergroup;
     $row->password = $post['password'];
     $row->password2 = $post['password'];
     //echo'<pre>';print_r($row);echo'</pre>';die;
     $row->check("register");
     $adv_user->bind($post);
     $user = new JUser();
     $data = array();
     $data['groups'][] = $params->get('new_usertype', 2);
     $data['email'] = $post['email'];
     $data['password'] = $post['password'];
     $data['password2'] = $post['password'];
     $data['name'] = $post['f_name'] . ' ' . $post['l_name'];
     $data['username'] = $post["u_name"];
     $useractivation = $params->get('useractivation');
     $sendpassword = $params->get('sendpassword', 1);
     $user->bind($data);
     if (!$user->save()) {
         JError::raiseWarning('', $user->getError());
         saveToLog('error.log', 'Error registration-' . $user->getError());
         $mainframe->redirect(SEFLink("index.php?option=com_jshopping&controller=user&task=register", 1, 1, $jshopConfig->use_ssl));
         return 0;
     }
     $row->user_id = $user->id;
     $row->number = $row->getNewUserNumber();
     unset($row->password);
     unset($row->password2);
     if (!$db->insertObject($row->getTableName(), $row, $row->getKeyName())) {
         saveToLog('error.log', $db->getErrorMsg());
         JError::raiseWarning('', "Error insert in table " . $row->getTableName());
         $mainframe->redirect(SEFLink("index.php?option=com_jshopping&controller=user&task=register", 1, 1, $jshopConfig->use_ssl));
         return 0;
     }
     //echo'<pre>';print_r($adv_user);echo'</pre>';die;
     $adv_user->store();
     //echo'<pre>';print_r($adv_user);echo'</pre>';die;
     $session = JFactory::getSession();
     $session->set("order_user_id", $user->id);
     $data = $user->getProperties();
     $data['fromname'] = $config->get('fromname');
     $data['mailfrom'] = $config->get('mailfrom');
     $data['sitename'] = $config->get('sitename');
     $data['siteurl'] = JUri::base();
     $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
     if ($sendpassword) {
         $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl'], $data['username'], $data['password_clear']);
     } else {
         $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl']);
     }
     $mailer = JFactory::getMailer();
     $mailer->setSender(array($data['mailfrom'], $data['fromname']));
     $mailer->addRecipient($data['email']);
     $mailer->setSubject($emailSubject);
     $mailer->setBody($emailBody);
     $mailer->isHTML(false);
     $mailer->Send();
     $options = array();
     $options['remember'] = false;
     //$options['return'] = JURI::root();
     $credentials = array();
     $credentials['username'] = $post['email'];
     $credentials['password'] = $post['password'];
     //echo'<pre>';print_r($mainframe);echo'</pre>';die;
     $error = $mainframe->login($credentials, $options);
     //echo'<pre>';print_r($mainframe);echo'</pre>';die;
 }
 function uploadImage($post)
 {
     $jshopConfig = JSFactory::getConfig();
     $dispatcher = JDispatcher::getInstance();
     $upload = new UploadFile($_FILES['category_image']);
     $upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
     $upload->setDir($jshopConfig->image_category_path);
     $upload->setFileNameMd5(0);
     $upload->setFilterName(1);
     if ($upload->upload()) {
         $name = $upload->getName();
         if ($post['old_image'] && $name != $post['old_image']) {
             @unlink($jshopConfig->image_category_path . "/" . $post['old_image']);
         }
         @chmod($jshopConfig->image_category_path . "/" . $name, 0777);
         if ($post['size_im_category'] < 3) {
             if ($post['size_im_category'] == 1) {
                 $category_width_image = $jshopConfig->image_category_width;
                 $category_height_image = $jshopConfig->image_category_height;
             } else {
                 $category_width_image = JRequest::getInt('category_width_image');
                 $category_height_image = JRequest::getInt('category_height_image');
             }
             $path_full = $jshopConfig->image_category_path . "/" . $name;
             $path_thumb = $jshopConfig->image_category_path . "/" . $name;
             if ($category_width_image || $category_height_image) {
                 if (!ImageLib::resizeImageMagic($path_full, $category_width_image, $category_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
                     JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                     saveToLog("error.log", "SaveCategory - Error create thumbail");
                 }
             }
             @chmod($jshopConfig->image_category_path . "/" . $name, 0777);
         }
         $category_image = $name;
         $dispatcher->trigger('onAfterSaveCategoryImage', array(&$post, &$category_image, &$path_full, &$path_thumb));
     } else {
         $category_image = '';
         if ($upload->getError() != 4) {
             JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
             saveToLog("error.log", "SaveCategory - Error upload image. code: " . $upload->getError());
         }
     }
     return $category_image;
 }
Example #8
0
 function registersave()
 {
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $mainframe = JFactory::getApplication();
     $jshopConfig = JSFactory::getConfig();
     $config = JFactory::getConfig();
     $db = JFactory::getDBO();
     $params = JComponentHelper::getParams('com_users');
     $lang = JFactory::getLanguage();
     $lang->load('com_users');
     $post = JRequest::get('post');
     $dispatcher = JDispatcher::getInstance();
     if ($params->get('allowUserRegistration') == 0) {
         JError::raiseError(403, JText::_('Access Forbidden'));
         return;
     }
     $usergroup = JSFactory::getTable('usergroup', 'jshop');
     $default_usergroup = $usergroup->getDefaultUsergroup();
     $post['username'] = $post['u_name'];
     $post['password2'] = $post['password_2'];
     if ($post['f_name'] == "") {
         $post['f_name'] = $post['email'];
     }
     $post['name'] = $post['f_name'] . ' ' . $post['l_name'];
     if ($post['birthday']) {
         $post['birthday'] = getJsDateDB($post['birthday'], $jshopConfig->field_birthday_format);
     }
     $post['lang'] = $jshopConfig->getLang();
     $dispatcher->trigger('onBeforeRegister', array(&$post, &$default_usergroup));
     $row = JSFactory::getTable('userShop', 'jshop');
     $row->bind($post);
     $row->usergroup_id = $default_usergroup;
     $row->password = $post['password'];
     $row->password2 = $post['password2'];
     if (!$row->check("register")) {
         $session = JFactory::getSession();
         $registrationdata = JRequest::get('post');
         $session->set('registrationdata', $registrationdata);
         JError::raiseWarning('', $row->getError());
         $this->setRedirect(SEFLink("index.php?option=com_jshopping&controller=user&task=register&lrd=1", 1, 1, $jshopConfig->use_ssl));
         return 0;
     }
     if ($post["u_name"] == "") {
         $post["u_name"] = $post['email'];
         $row->u_name = $post["u_name"];
     }
     if ($post["password"] == "") {
         $post["password"] = substr(md5('up' . time()), 0, 8);
     }
     $user = new JUser();
     $data = array();
     $data['groups'][] = $params->get('new_usertype', 2);
     $data['email'] = $post['email'];
     $data['password'] = $post['password'];
     $data['password2'] = $post['password2'];
     $data['name'] = $post['f_name'] . ' ' . $post['l_name'];
     $data['username'] = $post["u_name"];
     $useractivation = $params->get('useractivation');
     $sendpassword = $params->get('sendpassword', 1);
     if ($useractivation == 1 || $useractivation == 2) {
         jimport('joomla.user.helper');
         $data['activation'] = JApplication::getHash(JUserHelper::genRandomPassword());
         $data['block'] = 1;
     }
     $user->bind($data);
     if (!$user->save()) {
         JError::raiseWarning('', $user->getError());
         saveToLog('error.log', 'Error registration-' . $user->getError());
         $this->setRedirect(SEFLink("index.php?option=com_jshopping&controller=user&task=register", 1, 1, $jshopConfig->use_ssl));
         return 0;
     }
     $row->user_id = $user->id;
     $row->number = $row->getNewUserNumber();
     unset($row->password);
     unset($row->password2);
     if (!$db->insertObject($row->getTableName(), $row, $row->getKeyName())) {
         saveToLog('error.log', $db->getErrorMsg());
         JError::raiseWarning('', "Error insert in table " . $row->getTableName());
         $this->setRedirect(SEFLink("index.php?option=com_jshopping&controller=user&task=register", 1, 1, $jshopConfig->use_ssl));
         return 0;
     }
     $data = $user->getProperties();
     $data['fromname'] = $config->get('fromname');
     $data['mailfrom'] = $config->get('mailfrom');
     $data['sitename'] = $config->get('sitename');
     $data['siteurl'] = JUri::base();
     if ($useractivation == 2) {
         $uri = JURI::getInstance();
         $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
         $data['activate'] = $base . JRoute::_('index.php?option=com_jshopping&controller=user&task=activate&token=' . $data['activation'], false);
         $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
         if ($sendpassword) {
             $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_jshopping&controller=user&task=activate&token=' . $data['activation'], $data['siteurl'], $data['username'], $data['password_clear']);
         } else {
             $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_jshopping&controller=user&task=activate&token=' . $data['activation'], $data['siteurl'], $data['username']);
         }
     } else {
         if ($useractivation == 1) {
             $uri = JURI::getInstance();
             $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
             $data['activate'] = $base . JRoute::_('index.php?option=com_jshopping&controller=user&task=activate&token=' . $data['activation'], false);
             $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
             if ($sendpassword) {
                 $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY', $data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_jshopping&controller=user&task=activate&token=' . $data['activation'], $data['siteurl'], $data['username'], $data['password_clear']);
             } else {
                 $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl'] . 'index.php?option=com_jshopping&controller=user&task=activate&token=' . $data['activation'], $data['siteurl'], $data['username']);
             }
         } else {
             $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
             if ($sendpassword) {
                 $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl'], $data['username'], $data['password_clear']);
             } else {
                 $emailBody = JText::sprintf('COM_USERS_EMAIL_REGISTERED_BODY_NOPW', $data['name'], $data['sitename'], $data['siteurl']);
             }
         }
     }
     $dispatcher->trigger('onBeforeRegisterSendMailClient', array(&$post, &$data, &$emailSubject, &$emailBody));
     $mailer = JFactory::getMailer();
     $mailer->setSender(array($data['mailfrom'], $data['fromname']));
     $mailer->addRecipient($data['email']);
     $mailer->setSubject($emailSubject);
     $mailer->setBody($emailBody);
     $mailer->isHTML(false);
     $dispatcher->trigger('onBeforeRegisterMailerSendMailClient', array(&$mailer, &$post, &$data, &$emailSubject, &$emailBody));
     $mailer->Send();
     if ($params->get('useractivation') < 2 && $params->get('mail_to_admin') == 1) {
         $emailSubject = JText::sprintf('COM_USERS_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
         $emailBodyAdmin = JText::sprintf('COM_USERS_EMAIL_REGISTERED_NOTIFICATION_TO_ADMIN_BODY', $data['name'], $data['username'], $data['siteurl']);
         $query = 'SELECT name, email, sendEmail FROM #__users WHERE sendEmail=1';
         $db->setQuery($query);
         $rows = $db->loadObjectList();
         $mode = false;
         foreach ($rows as $rowadm) {
             $dispatcher->trigger('onBeforeRegisterSendMailAdmin', array(&$post, &$data, &$emailSubject, &$emailBodyAdmin, &$rowadm, &$mode));
             $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $rowadm->email, $emailSubject, $emailBodyAdmin, $mode);
         }
     }
     $dispatcher->trigger('onAfterRegister', array(&$user, &$row, &$post, &$useractivation));
     if ($useractivation == 2) {
         $message = JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY');
     } elseif ($useractivation == 1) {
         $message = JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE');
     } else {
         $message = JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS');
     }
     $return = SEFLink("index.php?option=com_jshopping&controller=user&task=login", 1, 1, $jshopConfig->use_ssl);
     $this->setRedirect($return, $message);
 }
Example #9
0
function get_search_results($query, $start, $category, $searchtype, $results, $domain)
{
    global $sph_messages, $results_per_page, $links_to_next, $show_query_scores, $mysql_table_prefix, $desc_length;
    if ($results != "") {
        $results_per_page = $results;
    }
    if ($searchtype == "phrase") {
        $query = str_replace('"', '', $query);
        $query = "\"" . $query . "\"";
    }
    $starttime = getmicrotime();
    // catch " if only one time entered
    if (substr_count($query, '"') == 1) {
        $query = str_replace('"', '', $query);
    }
    $words = makeboollist($query);
    $ignorewords = $words['ignore'];
    $full_result['ignore_words'] = $words['ignore'];
    if ($start == 0) {
        $start = 1;
    }
    $result = search($words, $category, $start, $results_per_page, $searchtype, $domain);
    $query = stripslashes($query);
    $entitiesQuery = htmlspecialchars($query);
    $full_result['ent_query'] = $entitiesQuery;
    $endtime = getmicrotime() - $starttime;
    $rows = $result['results'];
    $time = round($endtime * 100) / 100;
    $full_result['time'] = $time;
    $did_you_mean = "";
    if (isset($result['did_you_mean'])) {
        $did_you_mean_b = $entitiesQuery;
        $did_you_mean = $entitiesQuery;
        while (list($key, $val) = each($result['did_you_mean'])) {
            if ($key != $val) {
                $did_you_mean_b = str_replace($key, "<b>{$val}</b>", $did_you_mean_b);
                $did_you_mean = str_replace($key, "{$val}", $did_you_mean);
            }
        }
    }
    $full_result['did_you_mean'] = $did_you_mean;
    $full_result['did_you_mean_b'] = $did_you_mean_b;
    $matchword = $sph_messages["matches"];
    if ($rows == 1) {
        $matchword = $sph_messages["match"];
    }
    $num_of_results = count($result) - 2;
    $full_result['num_of_results'] = $num_of_results;
    if ($start < 2) {
        saveToLog(addslashes($query), $time, $rows);
    }
    $from = ($start - 1) * $results_per_page + 1;
    $to = min($start * $results_per_page, $rows);
    $full_result['from'] = $from;
    $full_result['to'] = $to;
    $full_result['total_results'] = $rows;
    if ($rows > 0) {
        $maxweight = $result['maxweight'];
        $i = 0;
        while ($i < $num_of_results && $i < $results_per_page) {
            $title = $result[$i]['title'];
            $url = $result[$i]['url'];
            $fulltxt = $result[$i]['fulltxt'];
            $page_size = $result[$i]['size'];
            $domain = $result[$i]['domain'];
            if ($page_size != "") {
                $page_size = number_format($page_size, 1) . "kb";
            }
            $txtlen = strlen($fulltxt);
            if ($txtlen > $desc_length) {
                $places = array();
                foreach ($words['hilight'] as $word) {
                    $tmp = strtolower($fulltxt);
                    $found_in = strpos($tmp, $word);
                    $sum = -strlen($word);
                    while (!($found_in == '')) {
                        $pos = $found_in + strlen($word);
                        $sum += $pos;
                        //FIX!!
                        $tmp = substr($tmp, $pos);
                        $places[] = $sum;
                        $found_in = strpos($tmp, $word);
                    }
                }
                sort($places);
                $x = 0;
                $begin = 0;
                $end = 0;
                while (list($id, $place) = each($places)) {
                    while ($places[$id + $x] - $place < $desc_length && $x + $id < count($places) && $place < strlen($fulltxt) - $desc_length) {
                        $x++;
                        $begin = $id;
                        $end = $id + $x;
                    }
                }
                $begin_pos = max(0, $places[$begin] - 30);
                $fulltxt = substr($fulltxt, $begin_pos, $desc_length);
                if ($places[$begin] > 0) {
                    $begin_pos = strpos($fulltxt, " ");
                }
                $fulltxt = substr($fulltxt, $begin_pos, $desc_length);
                $fulltxt = substr($fulltxt, 0, strrpos($fulltxt, " "));
                $fulltxt = $fulltxt;
            }
            $weight = number_format($result[$i]['weight'] / $maxweight * 100, 2);
            if ($title == '') {
                $title = $sph_messages["Untitled"];
            }
            $regs = array();
            if (strlen($title) > 80) {
                $title = substr($title, 0, 76) . "...";
            }
            foreach ($words['hilight'] as $change) {
                while (preg_match("/[^\\>](" . $change . ")[^\\<]/i", " " . $title . " ", $regs)) {
                    $title = preg_replace("/" . $regs[1] . "/i", "<b>" . $regs[1] . "</b>", $title);
                }
                while (preg_match("/[^\\>](" . $change . ")[^\\<]/i", " " . $fulltxt . " ", $regs)) {
                    $fulltxt = preg_replace("/" . $regs[1] . "/i", "<b>" . $regs[1] . "</b>", $fulltxt);
                }
                $url2 = $url;
                while (preg_match("/[^\\>](" . $change . ")[^\\<]/i", $url2, $regs)) {
                    $url2 = preg_replace("/" . $regs[1] . "/i", "<b>" . $regs[1] . "</b>", $url2);
                }
            }
            $num = $from + $i;
            $full_result['qry_results'][$i]['num'] = $num;
            $full_result['qry_results'][$i]['weight'] = $weight;
            $full_result['qry_results'][$i]['url'] = $url;
            $full_result['qry_results'][$i]['title'] = $title;
            $full_result['qry_results'][$i]['fulltxt'] = $fulltxt;
            $full_result['qry_results'][$i]['url2'] = $url2;
            $full_result['qry_results'][$i]['page_size'] = $page_size;
            $full_result['qry_results'][$i]['domain_name'] = $domain;
            $i++;
        }
    }
    $pages = ceil($rows / $results_per_page);
    $full_result['pages'] = $pages;
    $prev = $start - 1;
    $full_result['prev'] = $prev;
    $next = $start + 1;
    $full_result['next'] = $next;
    $full_result['start'] = $start;
    $full_result['query'] = $entitiesQuery;
    if ($from <= $to) {
        $firstpage = $start - $links_to_next;
        if ($firstpage < 1) {
            $firstpage = 1;
        }
        $lastpage = $start + $links_to_next;
        if ($lastpage > $pages) {
            $lastpage = $pages;
        }
        for ($x = $firstpage; $x <= $lastpage; $x++) {
            $full_result['other_pages'][] = $x;
        }
    }
    return $full_result;
}
Example #10
0
 function checkTransaction($pmconfigs, $order, $act)
 {
     $jshopConfig = JSFactory::getConfig();
     if ($pmconfigs['testmode']) {
         $host = "www.sandbox.paypal.com";
     } else {
         $host = "www.paypal.com";
     }
     $hostname = $host;
     if ($pmconfigs['use_ssl']) {
         $host = "ssl://" . $host;
     }
     $order->order_total = $this->fixOrderTotal($order);
     $email_received = $_POST['business'];
     if ($email_received == "") {
         $email_received = $_POST['receiver_email'];
     }
     if ($order->order_total != $_POST['mc_gross']) {
         return array(0, 'Error mc_gross. Order ID ' . $order->order_id);
     }
     if (strtolower($pmconfigs['email_received']) != strtolower($email_received)) {
         return array(0, 'Error email received. Order ID ' . $order->order_id);
     }
     if ($order->currency_code_iso != $_POST['mc_currency']) {
         return array(0, 'Error currency. Order ID ' . $order->order_id);
     }
     $req = 'cmd=_notify-validate';
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
     }
     $payment_status = trim(stripslashes($_POST['payment_status']));
     $header = '';
     $header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Host: " . $hostname . "\r\n";
     $header .= "Connection: close\r\n";
     $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
     $debug = "";
     $port = 80;
     if ($pmconfigs['use_ssl']) {
         $port = 443;
     }
     $fp = fsockopen($host, $port, $errno, $errstr, 30);
     if (!$fp) {
         return array(0, 'Http error. Order number ' . $order->order_id);
     } else {
         @fputs($fp, $header . $req);
         while (!@feof($fp)) {
             $res = @fgets($fp, 1024);
             $res = trim($res);
             $debug .= $res . "\n";
             if (strcmp($res, "VERIFIED") == 0) {
                 if ($payment_status == 'Completed') {
                     return array(1, '');
                 } elseif ($payment_status == 'Pending') {
                     saveToLog("payment.log", "Status pending. Order ID " . $order->order_id . ". Reason: " . $_POST['pending_reason']);
                     return array(2, trim(stripslashes($_POST['pending_reason'])));
                 } elseif ($payment_status == 'Failed') {
                     return array(3, 'Status Failed. Order ID ' . $order->order_id);
                 } elseif ($payment_status == 'Refunded') {
                     return array(3, "Status Refunded. Order ID " . $order->order_id);
                 } else {
                     return array(0, "Order number " . $order->order_id . "\nPaypal error\nPayment status - {$payment_status}.");
                 }
             } else {
                 if (strcmp($res, "INVALID") == 0) {
                     return array(0, 'Invalid response. Order ID ' . $order->order_id);
                 }
             }
         }
         fclose($fp);
         if ($jshopConfig->savelog && $jshopConfig->savelogpaymentdata) {
             saveToLog("paymentdata.log", $debug);
         }
         return array(0, "Error response. Order ID " . $order->order_id);
     }
 }
Example #11
0
 public function saveToLogPaymentData()
 {
     $str = "url: " . $_SERVER['REQUEST_URI'] . "\n";
     foreach ($_POST as $k => $v) {
         $str .= $k . "=" . $v . "\n";
     }
     saveToLog("paymentdata.log", $str);
 }
Example #12
0
 function step7()
 {
     $checkout = JSFactory::getModel('checkout', 'jshop');
     $wmiframe = JRequest::getInt("wmiframe");
     $mainframe = JFactory::getApplication();
     $jshopConfig = JSFactory::getConfig();
     $session = JFactory::getSession();
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onLoadStep7', array());
     $pm_method = JSFactory::getTable('paymentMethod', 'jshop');
     $str = "url: " . $_SERVER['REQUEST_URI'] . "\n";
     foreach ($_POST as $k => $v) {
         $str .= $k . "=" . $v . "\n";
     }
     saveToLog("paymentdata.log", $str);
     $act = JRequest::getVar("act");
     $payment_method = JRequest::getVar("js_paymentclass");
     $pm_method->loadFromClass($payment_method);
     $paymentsysdata = $pm_method->getPaymentSystemData();
     $payment_system = $paymentsysdata->paymentSystem;
     if ($paymentsysdata->paymentSystemVerySimple) {
         if (JRequest::getInt('no_lang')) {
             JSFactory::loadLanguageFile();
         }
         saveToLog("payment.log", "#001 - Error payment method file. PM " . $payment_method);
         JError::raiseWarning(500, _JSHOP_ERROR_PAYMENT);
         return 0;
     }
     if ($paymentsysdata->paymentSystemError) {
         if (JRequest::getInt('no_lang')) {
             JSFactory::loadLanguageFile();
         }
         saveToLog("payment.log", "#002 - Error payment. CLASS " . $payment_method);
         JError::raiseWarning(500, _JSHOP_ERROR_PAYMENT);
         return 0;
     }
     $pmconfigs = $pm_method->getConfigs();
     $urlParamsPS = $payment_system->getUrlParams($pmconfigs);
     $order_id = $urlParamsPS['order_id'];
     $hash = $urlParamsPS['hash'];
     $checkHash = $urlParamsPS['checkHash'];
     $checkReturnParams = $urlParamsPS['checkReturnParams'];
     $session->set('jshop_send_end_form', 0);
     if ($act == "cancel") {
         $this->cancelPayOrder($order_id);
         return 0;
     }
     if ($act == "return" && !$checkReturnParams) {
         $checkout->setMaxStep(10);
         if (!$wmiframe) {
             $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=finish', 0, 1, $jshopConfig->use_ssl));
         } else {
             $this->iframeRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=finish', 0, 1, $jshopConfig->use_ssl));
         }
         return 1;
     }
     $order = JSFactory::getTable('order', 'jshop');
     $order->load($order_id);
     if (JRequest::getInt('no_lang')) {
         JSFactory::loadLanguageFile($order->getLang());
         $lang = JSFactory::getLang($order->getLang());
     }
     if ($checkHash && $order->order_hash != $hash) {
         saveToLog("payment.log", "#003 - Error order hash. Order id " . $order_id);
         JError::raiseWarning("", _JSHOP_ERROR_ORDER_HASH);
         return 0;
     }
     if (!$order->payment_method_id) {
         saveToLog("payment.log", "#004 - Error payment method id. Order id " . $order_id);
         JError::raiseWarning("", _JSHOP_ERROR_PAYMENT);
         return 0;
     }
     if ($order->payment_method_id != $pm_method->payment_id) {
         saveToLog("payment.log", "#005 - Error payment method set url. Order id " . $order_id);
         JError::raiseWarning("", _JSHOP_ERROR_PAYMENT);
         return 0;
     }
     $res = $payment_system->checkTransaction($pmconfigs, $order, $act);
     $rescode = $res[0];
     $restext = $res[1];
     $transaction = $res[2];
     $transactiondata = $res[3];
     $status = $payment_system->getStatusFromResCode($rescode, $pmconfigs);
     $order->transaction = $transaction;
     $order->store();
     $order->saveTransactionData($rescode, $status, $transactiondata);
     if ($restext != '') {
         saveToLog("payment.log", $restext);
     }
     if ($status && !$order->order_created) {
         $order->order_created = 1;
         $order->order_status = $status;
         $dispatcher->trigger('onStep7OrderCreated', array(&$order, &$res, &$checkout, &$pmconfigs));
         $order->store();
         if ($jshopConfig->send_order_email) {
             $checkout->sendOrderEmail($order->order_id);
         }
         if ($jshopConfig->order_stock_removed_only_paid_status) {
             $product_stock_removed = in_array($status, $jshopConfig->payment_status_enable_download_sale_file);
         } else {
             $product_stock_removed = 1;
         }
         if ($product_stock_removed) {
             $order->changeProductQTYinStock("-");
         }
         $checkout->changeStatusOrder($order_id, $status, 0);
     }
     if ($status && $order->order_status != $status) {
         $checkout->changeStatusOrder($order_id, $status, 1);
     }
     $dispatcher->trigger('onStep7BefereNotify', array(&$order, &$checkout, &$pmconfigs));
     if ($act == "notify") {
         $payment_system->nofityFinish($pmconfigs, $order, $rescode);
         die;
     }
     $payment_system->finish($pmconfigs, $order, $rescode, $act);
     if (in_array($rescode, array(0, 3, 4))) {
         JError::raiseWarning(500, $restext);
         if (!$wmiframe) {
             $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step5', 0, 1, $jshopConfig->use_ssl));
         } else {
             $this->iframeRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step5', 0, 1, $jshopConfig->use_ssl));
         }
         return 0;
     } else {
         $checkout->setMaxStep(10);
         if (!$wmiframe) {
             $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=finish', 0, 1, $jshopConfig->use_ssl));
         } else {
             $this->iframeRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=finish', 0, 1, $jshopConfig->use_ssl));
         }
         return 1;
     }
 }
 function showEndForm($pmconfigs, $order)
 {
     $mainframe =& JFactory::getApplication();
     $jshopConfig =& JSFactory::getConfig();
     $item_name = sprintf(_JSHOP_PAYMENT_NUMBER, $order->order_number);
     $notify_url = JURI::root() . "index.php?option=com_jshopping&controller=checkout&task=step7&act=notify&js_paymentclass=pm_ideal&no_lang=1";
     $return = JURI::root() . "index.php?option=com_jshopping&controller=checkout&task=step7&act=return&js_paymentclass=pm_ideal";
     $cancel_return = JURI::root() . "index.php?option=com_jshopping&controller=checkout&task=step7&act=cancel&js_paymentclass=pm_ideal";
     $params_data = $order->getPaymentParamsData();
     $bank_id = $params_data['bank_id'];
     $amount = intval($order->order_total * 100);
     $iDEAL = new iDEAL_Payment($pmconfigs['partnerid']);
     if ($pmconfigs['testmode']) {
         $iDEAL->setTestMode();
     }
     if ($iDEAL->createPayment($bank_id, $amount, $item_name, $return, $notify_url)) {
         $order1 =& JTable::getInstance('order', 'jshop');
         $order1->load($order->order_id);
         $order1->transaction = $iDEAL->getTransactionId();
         $order1->store();
         header("Location: " . $iDEAL->getBankURL());
         exit;
     } else {
         saveToLog("payment.log", "Error: Order ID " . $order->order_id . ". CODE: " . $iDEAL->getErrorCode() . ". MSG: " . $iDEAL->getErrorMessage());
         JError::raiseWarning("", $iDEAL->getErrorMessage());
         $mainframe->redirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step5', 0, 1, $jshopConfig->use_ssl));
         exit;
     }
 }
Example #14
0
 function copyFiles($startdir, $subdir = "")
 {
     if ($subdir != "" && !file_exists(JPATH_ROOT . $subdir)) {
         @mkdir(JPATH_ROOT . $subdir, 0755);
     }
     $files = JFolder::files($startdir . $subdir, '', false, false, array(), array());
     foreach ($files as $file) {
         if ($subdir == "" && ($file == "update.sql" || $file == "update.php" || $file == "checkupdate.php")) {
             continue;
         }
         if (@copy($startdir . $subdir . "/" . $file, JPATH_ROOT . $subdir . "/" . $file)) {
             //JError::raiseWarning( 500, "Copy file: ".$subdir."/".$file." OK");
         } else {
             JError::raiseWarning("", "Copy file: " . $subdir . "/" . $file . " ERROR");
             saveToLog("error.log", "Update - Copy file: " . $subdir . "/" . $file . " ERROR");
         }
     }
     $folders = JFolder::folders($startdir . $subdir, '');
     foreach ($folders as $folder) {
         $dir = $subdir . "/" . $folder;
         $this->copyFiles($startdir, $dir);
     }
 }
 static function sendToLog($message)
 {
     saveToLog("payment.log", $message);
 }
 function save()
 {
     $mainframe = JFactory::getApplication();
     $jshopConfig = JSFactory::getConfig();
     require_once $jshopConfig->path . 'lib/uploadfile.class.php';
     $id = JRequest::getInt("id");
     $productLabel = JTable::getInstance('productLabel', 'jshop');
     $post = JRequest::get("post");
     $lang = JSFactory::getLang();
     $post['name'] = $post[$lang->get("name")];
     JPluginHelper::importPlugin('jshoppingadmin');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onBeforeSaveProductLabel', array(&$post));
     $upload = new UploadFile($_FILES['image']);
     $upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
     $upload->setDir($jshopConfig->image_labels_path);
     $upload->setFileNameMd5(0);
     $upload->setFilterName(1);
     if ($upload->upload()) {
         if ($post['old_image']) {
             @unlink($jshopConfig->image_labels_path . "/" . $post['old_image']);
         }
         $post['image'] = $upload->getName();
         @chmod($jshopConfig->image_labels_path . "/" . $post['image'], 0777);
     } else {
         if ($upload->getError() != 4) {
             JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
             saveToLog("error.log", "Label - Error upload image. code: " . $upload->getError());
         }
     }
     if (!$productLabel->bind($post)) {
         JError::raiseWarning("", _JSHOP_ERROR_BIND);
         $this->setRedirect("index.php?option=com_jshopping&controller=productlabels");
         return 0;
     }
     if (!$productLabel->store()) {
         JError::raiseWarning("", _JSHOP_ERROR_SAVE_DATABASE);
         $this->setRedirect("index.php?option=com_jshopping&controller=productlabels");
         return 0;
     }
     $dispatcher->trigger('onAfterSaveProductLabel', array(&$productLabel));
     if ($this->getTask() == 'apply') {
         $this->setRedirect("index.php?option=com_jshopping&controller=productlabels&task=edit&id=" . $productLabel->id);
     } else {
         $this->setRedirect("index.php?option=com_jshopping&controller=productlabels");
     }
 }
function get_search_results($query, $start, $category, $searchtype, $results, $domain)
{
    global $sph_messages, $results_per_page, $links_to_next, $show_query_scores, $desc_length;
    if ($results != "") {
        $results_per_page = $results;
    }
    if ($searchtype == "phrase") {
        $query = str_replace('"', '', $query);
        $query = "\"" . $query . "\"";
    }
    $starttime = getmicrotime();
    // catch " if only one time entered
    $query = preg_replace("/&quot;/", "\"", $query);
    if (substr_count($query, '"') == 1) {
        $query = str_replace('"', '', $query);
    }
    $words = makeboollist($query);
    if (isset($words['ignore'])) {
        $ignorewords = $words['ignore'];
    } else {
        $ignorewords = "";
    }
    $full_result['ignore_words'] = $ignorewords;
    if ($start == 0) {
        $start = 1;
    }
    $result = search($words, $category, $start, $results_per_page, $searchtype, $domain);
    $query = stripslashes($query);
    $entitiesQuery = htmlspecialchars($query);
    $full_result['ent_query'] = $entitiesQuery;
    $endtime = getmicrotime() - $starttime;
    if (isset($result['results'])) {
        $rows = $result['results'];
    } else {
        $rows = "";
    }
    $time = round($endtime * 100) / 100;
    $full_result['time'] = $time;
    $did_you_mean = array();
    $did_you_mean_b = array();
    if (isset($result['did_you_mean']) && is_array($result['did_you_mean'])) {
        while (list($key, $alt) = each($result['did_you_mean'])) {
            $entities = html_to_latin1(utf8_decode($entitiesQuery));
            if ($key != $alt) {
                $alt = html_to_latin1(utf8_decode($alt));
                $alt = sanitize($alt);
                $entities = preg_replace("/&quot;/", "\"", $entities);
                if ($alt[0] == "/") {
                    /* this indicates that the search word is not found and there is no close alternative either */
                    $alt = substr($alt, 1);
                    $did_you_mean_b[] = latin1_to_html(str_ireplace($key, "<strike>{$alt}</strike>", $entities));
                    $did_you_mean[] = str_ireplace($key, "", $entities);
                } else {
                    $did_you_mean_b[] = latin1_to_html(str_ireplace($key, "<b>{$alt}</b>", $entities));
                    $did_you_mean[] = str_ireplace($key, utf8_encode($alt), $entities);
                }
            }
        }
    }
    $full_result['did_you_mean'] = $did_you_mean;
    $full_result['did_you_mean_b'] = $did_you_mean_b;
    $matchword = $sph_messages["matches"];
    if ($rows == 1) {
        $matchword = $sph_messages["match"];
    }
    $num_of_results = count($result) - 2;
    $full_result['num_of_results'] = $num_of_results;
    if ($start < 2) {
        saveToLog($query, $time, $rows);
    }
    $from = ($start - 1) * $results_per_page + 1;
    $to = min($start * $results_per_page, $rows);
    $full_result['from'] = $from;
    $full_result['to'] = $to;
    $full_result['total_results'] = $rows;
    if ($rows > 0) {
        $maxweight = $result['maxweight'];
        $i = 0;
        while ($i < $num_of_results && $i < $results_per_page) {
            if (!isset($result[$i]['url'])) {
                $i++;
                continue;
            }
            $url = $result[$i]['url'];
            $title = isset($result[$i]['title']) ? $result[$i]['title'] : "";
            $summary = $result[$i]['summary'];
            $lang = $result[$i]['lang'];
            $fulltxt = $result[$i]['fulltxt'];
            $page_size = $result[$i]['size'];
            $domain = $result[$i]['domain'];
            if ($page_size != "") {
                $page_size = number_format($page_size, 1) . "kb";
            }
            $txtlen = strlen($fulltxt);
            if ($txtlen > $desc_length) {
                $places = array();
                foreach ($words['hilight'] as $word) {
                    $word = latin1_to_html($word);
                    $tmp = strtolower($fulltxt);
                    $found_in = strpos($tmp, $word);
                    $sum = -strlen($word);
                    while (!($found_in == '')) {
                        $pos = $found_in + strlen($word);
                        $sum += $pos;
                        //FIX!!
                        $tmp = substr($tmp, $pos);
                        $places[] = $sum;
                        $found_in = strpos($tmp, $word);
                    }
                }
                sort($places);
                $x = 0;
                $begin = 0;
                $end = 0;
                while (list($id, $place) = each($places)) {
                    while (isset($places[$id + $x]) && $places[$id + $x] - $place < $desc_length && $x + $id < count($places) && $place < strlen($fulltxt) - $desc_length) {
                        $x++;
                        $begin = $id;
                        $end = $id + $x;
                    }
                }
                if (!isset($places[$begin])) {
                    $places[$begin] = 0;
                }
                $begin_pos = max(0, $places[$begin] - 30);
                $fulltxt = substr($fulltxt, $begin_pos, $desc_length);
                if ($places[$begin] > 0) {
                    $begin_pos = strpos($fulltxt, " ");
                }
                $fulltxt = substr($fulltxt, $begin_pos, $desc_length);
                $fulltxt = substr($fulltxt, 0, strrpos($fulltxt, " "));
                $fulltxt = $fulltxt;
            }
            $weight = number_format($result[$i]['weight'] / $maxweight * 100, 2);
            if ($title == '') {
                /* for an untitled document, use the filename without the path */
                $pos = strrpos($url, "/");
                if ($pos >= 0) {
                    $pos++;
                } else {
                    $pos = 0;
                }
                $title = substr($url, $pos);
            }
            $regs = array();
            if (strlen($title) > 80) {
                $title = substr($title, 0, 76) . "...";
            }
            foreach ($words['hilight'] as $change) {
                $change = latin1_to_html($change);
                $count = 0;
                while (preg_match("/[ .,;\\(\\)\\'\"](" . $change . ")[ .,;\\(\\)\\'\"]/i", " " . $title . " ", $regs) && ++$count < 20) {
                    $title = preg_replace("/([ .,;\\(\\)\\'\"])" . $regs[1] . "([ .,;\\(\\)\\'\"])/i", "\$1<b>" . $regs[1] . "</b>\$2", $title);
                }
                $count = 0;
                while (preg_match("/[ .,;\\(\\)\\'\"](" . $change . ")[ .,\\(\\)\\'\"]/i", " " . $fulltxt . " ", $regs) && ++$count < 20) {
                    $fulltxt = preg_replace("/([ .,;\\(\\)\\'\"])" . $regs[1] . "([ .,;\\(\\)\\'\"])/i", "\$1<b>" . $regs[1] . "</b>\$2", $fulltxt);
                }
            }
            $num = $from + $i;
            $full_result['qry_results'][$i]['num'] = $num;
            $full_result['qry_results'][$i]['weight'] = $weight;
            $full_result['qry_results'][$i]['url'] = $url;
            $full_result['qry_results'][$i]['title'] = $title;
            $full_result['qry_results'][$i]['summary'] = $summary;
            $full_result['qry_results'][$i]['lang'] = $lang;
            $full_result['qry_results'][$i]['fulltxt'] = $fulltxt;
            $full_result['qry_results'][$i]['page_size'] = $page_size;
            $full_result['qry_results'][$i]['domain_name'] = $domain;
            $i++;
        }
    }
    $pages = ceil($rows / $results_per_page);
    $full_result['pages'] = $pages;
    $prev = $start - 1;
    $full_result['prev'] = $prev;
    $next = $start + 1;
    $full_result['next'] = $next;
    $full_result['start'] = $start;
    $full_result['query'] = $entitiesQuery;
    if ($from <= $to) {
        $firstpage = $start - $links_to_next;
        if ($firstpage < 1) {
            $firstpage = 1;
        }
        $lastpage = $start + $links_to_next;
        if ($lastpage > $pages) {
            $lastpage = $pages;
        }
        for ($x = $firstpage; $x <= $lastpage; $x++) {
            $full_result['other_pages'][] = $x;
        }
    }
    return $full_result;
}
Example #18
0
function get_search_results($query, $start, $category, $searchtype, $results, $domain)
{
    global $sph_messages, $results_per_page, $all_wild, $show_meta_description, $title_length, $links_to_next, $wildsearch, $show_warning, $mark, $type, $show_query_scores, $index_host, $url_length, $query_hits, $mysql_table_prefix, $desc_length, $utf8, $case_sensitive;
    if ($results != "") {
        $results_per_page = $results;
    }
    if ($searchtype == "phrase") {
        $query = str_replace('"', '', $query);
        $query = "\"" . $query . "\"";
    }
    if ($utf8 == 1 && $case_sensitive == 0 && $searchtype != "phrase") {
        $query = lower_case($query);
    }
    $starttime = getmicrotime();
    // catch " if only one time entered
    if (substr_count($query, '"') == 1) {
        $query = str_replace('"', '', $query);
    }
    $words = makeboollist($query);
    $ignorewords = $words['ignore'];
    $full_result['ignore_words'] = $words['ignore'];
    if ($start == 0) {
        $start = 1;
    }
    $result = search($words, $category, $start, $results_per_page, $searchtype, $domain);
    $query = stripslashes($query);
    $entitiesQuery = htmlspecialchars(str_replace("\"", "", $query));
    $full_result['ent_query'] = $entitiesQuery;
    $endtime = getmicrotime() - $starttime;
    $rows = $result['results'];
    $time = round($endtime * 100) / 100;
    $full_result['time'] = $time;
    $did_you_mean = "";
    if (isset($result['did_you_mean'])) {
        $did_you_mean_b = $entitiesQuery;
        $did_you_mean = $entitiesQuery;
        while (list($key, $val) = each($result['did_you_mean'])) {
            if ($key != $val) {
                $did_you_mean_b = str_replace($key, "<b>{$val}</b>", $did_you_mean_b);
                $did_you_mean = str_replace($key, "{$val}", $did_you_mean);
            }
        }
    }
    $full_result['did_you_mean'] = $did_you_mean;
    $full_result['did_you_mean_b'] = $did_you_mean_b;
    $matchword = $sph_messages["matches"];
    if ($rows == 1) {
        $matchword = $sph_messages["match"];
    }
    $num_of_results = count($result) - 2;
    $full_result['num_of_results'] = $num_of_results;
    if ($start < 2) {
        saveToLog(addslashes($query), $time, $rows);
    }
    $from = ($start - 1) * $results_per_page + 1;
    $to = min($start * $results_per_page, $rows);
    $full_result['from'] = $from;
    $full_result['to'] = $to;
    $full_result['total_results'] = $rows;
    if ($rows > 0) {
        $maxweight = $result['maxweight'];
        $i = 0;
        while ($i < $num_of_results && $i < $results_per_page) {
            $title = $result[$i]['title'];
            $url = $result[$i]['url'];
            $fulltxt = $result[$i]['fulltxt'];
            $page_size = $result[$i]['size'];
            $domain = $result[$i]['domain'];
            if ($page_size != "") {
                $page_size = number_format($page_size, 1) . " kb";
            }
            //  If available, enable part of a word highlighting in result report
            if ($all_wild) {
                $words = makeboollist($all_wild);
            }
            $txtlen = strlen($fulltxt);
            //$refreshed = ereg_replace("[*!]", '',trim($query)); //  works also for *wildcard search
            if ($show_meta_description === 1 || $txtlen > $desc_length) {
                $places = array();
                $strictpos = strpos($query, '!');
                if ($strictpos === 0) {
                    // if !strict search enter here
                    if ($case_sensitive == '1') {
                        $recovered = str_replace('!', '', trim($query));
                        $tmp = $fulltxt;
                    } else {
                        $recovered = str_replace('!', '', trim(lower_case($query)));
                        $tmp = lower_case($fulltxt);
                    }
                    $words['hilight'][0] = "{$recovered}";
                    //  replace without ' ! '
                    $strict_length = strlen($recovered);
                    $found_in = '1';
                    //  pointer position start
                    $pos_absolut = '0';
                    foreach ($words['hilight'] as $word) {
                        while (!($found_in == '')) {
                            $found_in = strpos($tmp, $word);
                            $tmp_front = substr($tmp, $found_in - 1);
                            //  one character before found match position
                            $pos = $found_in + strlen($word);
                            $pos_absolut = $pos_absolut + $found_in;
                            $tmp = substr($tmp, $pos);
                            //  get rest of fulltxt
                            //  check weather found match is realy strict
                            $found_before = preg_match("/[(a-z)-_*.\\/\\:&@\\w]/", substr($tmp_front, 0, 1));
                            $found_behind = preg_match("/[(a-z)-_*.,\\/\\:&@\\w]/", substr($tmp, 0, 1));
                            if ($found_before === 0 && $found_behind === 0) {
                                $places[] = $pos_absolut;
                                //  remind absolut position of match
                                $found_in = '';
                            }
                        }
                    }
                } else {
                    // if not !strict search enter here (standard search)
                    foreach ($words['hilight'] as $word) {
                        if ($case_sensitive == '0') {
                            $tmp = lower_case($fulltxt);
                            $word = lower_case($word);
                        } else {
                            $tmp = $fulltxt;
                        }
                        $found_in = strpos($tmp, $word);
                        $sum = -strlen($word);
                        while (!($found_in == '')) {
                            $pos = $found_in + strlen($word);
                            $sum += $pos;
                            //FIX!!
                            $tmp = substr($tmp, $pos);
                            $places[] = $sum;
                            $found_in = strpos($tmp, $word);
                        }
                    }
                }
                sort($places);
                $x = 0;
                $begin = 0;
                $end = 0;
                while (list($id, $place) = each($places)) {
                    while ($places[$id + $x] - $place < $desc_length && $x + $id < count($places) && $place < strlen($fulltxt) - $desc_length) {
                        $x++;
                        $begin = $id;
                        $end = $id + $x;
                    }
                }
                $begin_pos = max(0, $places[$begin] - 80);
                $fulltxt = substr($fulltxt, $begin_pos, $desc_length);
                if ($places[$begin] > 0) {
                    $begin_pos = strpos($fulltxt, " ");
                }
                $fulltxt = substr($fulltxt, $begin_pos, $desc_length);
                $fulltxt = substr($fulltxt, 0, strrpos($fulltxt, " "));
                $fulltxt = $fulltxt;
            }
            if ($query_hits == '0') {
                //  calculate percentage of weight
                $weight = number_format($result[$i]['weight'] / $maxweight * 100, 1);
            } else {
                $weight = number_format($result[$i]['weight']);
            }
            if ($title == '') {
                $title = $sph_messages["Untitled"];
            }
            $regs = array();
            if (strlen($title) > $title_length) {
                // if necessary shorten length of title in result page
                $length_tot = strpos($title, " ", $title_length);
                // find end of last word for shortened title
                if ($length_tot) {
                    $title = substr($title, 0, $length_tot) . " ...";
                }
            }
            $url2 = $url;
            if (strlen($url) > $url_length) {
                // if necessary shorten length of URL in result page
                $url2 = substr($url, 0, $url_length) . "...";
            }
            if ($places[0] == '' && $query_hits == 1 && $type != 'tol') {
                //  if nothing found in HTML text and query hits as result output
                $weight = '0';
            }
            if ($places[0] == '' && $show_warning == '1' && $type != 'tol' || $show_warning == '1' && $weight == '0') {
                // if  no HTML text to highlight
                $warnmessage = $sph_messages['showWarning'];
                $fulltxt = "<span class='warn'>{$warnmessage}</span>";
            }
            if ($mark == 'markbold') {
                $highlight = "span class='mak_1'";
            }
            if ($mark == 'markblue') {
                $highlight = "span class='mak_2'";
            }
            if ($mark == 'markyellow') {
                $highlight = "span class='mak_3'";
            }
            if ($mark == 'markgreen') {
                $highlight = "span class='mak_4'";
            }
            foreach ($words['hilight'] as $change) {
                if (!($strictpos === 0)) {
                    //  no marking in title and url if strict search
                    if ($case_sensitive == '1') {
                        //  if we have to search case sensetive, enter here
                        while (@ereg("[^\\>](" . $change . ")[^\\<]", " " . $title . " ", $regs)) {
                            $title = ereg_replace($regs[1], "<{$highlight}>" . $regs[1] . "</span>", $title);
                        }
                        if ($index_host == '1') {
                            while (@ereg("[^\\>](" . $change . ")[^\\<]", $url2, $regs)) {
                                $url2 = ereg_replace($regs[1], "<{$highlight}>" . $regs[1] . "</span>", $url2);
                            }
                        }
                    } else {
                        // mark upper and lower case match
                        while (@eregi("[^\\>](" . $change . ")[^\\<]", " " . $title . " ", $regs)) {
                            $title = eregi_replace($regs[1], "<{$highlight}>" . $regs[1] . "</span>", $title);
                        }
                        if ($index_host == '1') {
                            while (@eregi("[^\\>](" . $change . ")[^\\<]", $url2, $regs)) {
                                $url2 = eregi_replace($regs[1], "<{$highlight}>" . $regs[1] . "</span>", $url2);
                            }
                        }
                    }
                }
                if ($strictpos === 0) {
                    //      if strict search mark only the real result with blanks before and behind
                    $change = " {$change} ";
                }
                if ($case_sensitive == '1') {
                    //  mark fulltext case sensitive
                    while (@ereg("[^\\>](" . $change . ")[^\\<]", " " . $fulltxt . " ", $regs)) {
                        $fulltxt = ereg_replace($regs[1], "<{$highlight}>" . $regs[1] . "</span>", $fulltxt);
                    }
                } else {
                    //      mark all in fulltext
                    while (@eregi("[^\\>](" . $change . ")[^\\<]", " " . $fulltxt . " ", $regs)) {
                        $fulltxt = eregi_replace($regs[1], "<{$highlight}>" . $regs[1] . "</span>", $fulltxt);
                    }
                }
            }
            $places = array();
            $num = $from + $i;
            $full_result['qry_results'][$i]['num'] = $num;
            $full_result['qry_results'][$i]['weight'] = $weight;
            $full_result['qry_results'][$i]['url'] = $url;
            $full_result['qry_results'][$i]['title'] = $title;
            $full_result['qry_results'][$i]['fulltxt'] = $fulltxt;
            $full_result['qry_results'][$i]['url2'] = $url2;
            $full_result['qry_results'][$i]['page_size'] = $page_size;
            $full_result['qry_results'][$i]['domain_name'] = $domain;
            $i++;
        }
    }
    $pages = ceil($rows / $results_per_page);
    $full_result['pages'] = $pages;
    $prev = $start - 1;
    $full_result['prev'] = $prev;
    $next = $start + 1;
    $full_result['next'] = $next;
    $full_result['start'] = $start;
    $full_result['query'] = $entitiesQuery;
    if ($from <= $to) {
        $firstpage = $start - $links_to_next;
        if ($firstpage < 1) {
            $firstpage = 1;
        }
        $lastpage = $start + $links_to_next;
        if ($lastpage > $pages) {
            $lastpage = $pages;
        }
        for ($x = $firstpage; $x <= $lastpage; $x++) {
            $full_result['other_pages'][] = $x;
        }
    }
    return $full_result;
}
Example #19
0
 function checkTransaction($pmconfigs, $order, $act)
 {
     $jshopConfig = JSFactory::getConfig();
     if ($pmconfigs['testmode']) {
         $host = "www.sandbox.paypal.com";
     } else {
         $host = "www.paypal.com";
     }
     $post = JRequest::get('post');
     $order->order_total = $this->fixOrderTotal($order);
     $email_received = $_POST['business'];
     if ($email_received == "") {
         $email_received = $_POST['receiver_email'];
     }
     $opending = 0;
     if ($order->order_total != $_POST['mc_gross'] || $order->currency_code_iso != $_POST['mc_currency']) {
         $opending = 1;
     }
     $payment_status = trim($post['payment_status']);
     $transaction = $post['txn_id'];
     $transactiondata = array('txn_id' => $post['txn_id'], 'payer_email' => $post['payer_email'], 'mc_gross' => $post['mc_gross'], 'mc_currency' => $post['mc_currency'], 'payment_status' => $post['payment_status']);
     if (strtolower($pmconfigs['email_received']) != strtolower($email_received)) {
         return array(0, 'Error email received. Order ID ' . $order->order_id, $transaction, $transactiondata);
     }
     $req = 'cmd=_notify-validate';
     if (function_exists('get_magic_quotes_gpc')) {
         $get_magic_quotes_exists = true;
     }
     foreach ($_POST as $key => $value) {
         if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
             $value = urlencode(stripslashes($value));
         } else {
             $value = urlencode($value);
         }
         $req .= "&{$key}={$value}";
     }
     $ch = curl_init('https://' . $host . '/cgi-bin/webscr');
     curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
     curl_setopt($ch, CURLOPT_SSLVERSION, 4);
     curl_setopt($ch, CURLOPT_USERAGENT, 'PayPal-PHP-SDK');
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
     if (!($res = curl_exec($ch))) {
         saveToLog("payment.log", "Paypal failed: " . curl_error($ch) . '(' . curl_errno($ch) . ')');
         curl_close($ch);
         exit;
     } else {
         curl_close($ch);
     }
     saveToLog("paymentdata.log", "RES: {$res}");
     if (strcmp($res, "VERIFIED") == 0) {
         if ($payment_status == 'Completed') {
             if ($opending) {
                 saveToLog("payment.log", "Status pending. Order ID " . $order->order_id . ". Error mc_gross or mc_currency.");
                 return array(2, "Status pending. Order ID " . $order->order_id, $transaction, $transactiondata);
             } else {
                 return array(1, '', $transaction, $transactiondata);
             }
         } elseif ($payment_status == 'Pending') {
             saveToLog("payment.log", "Status pending. Order ID " . $order->order_id . ". Reason: " . $_POST['pending_reason']);
             return array(2, trim(stripslashes($_POST['pending_reason'])), $transaction, $transactiondata);
         } else {
             return array(3, "Status {$payment_status}. Order ID " . $order->order_id, $transaction, $transactiondata);
         }
     } else {
         if (strcmp($res, "INVALID") == 0) {
             return array(0, 'Invalid response. Order ID ' . $order->order_id, $transaction, $transactiondata);
         }
     }
 }
function media_only($query, $start, $media_only, $type, $category, $catid, $mark, $db, $prefix, $domain)
{
    global $db_con, $mysql_table_prefix, $debug, $debug_user, $admin_dir, $include_dir, $case_sensitive;
    global $results_per_page, $image_dir, $sph_messages, $dbu_act, $template, $template_dir, $index_id3;
    global $use_cache, $mediacache_dir, $mcache_size, $max_cmresults, $max_results;
    global $dbu_act, $db1_slv, $db2_slv, $db3_slv, $db4_slv, $db5_slv, $elapsed;
    global $mytitle, $show_categories, $has_categories, $checked_cat, $tpl, $checked_all;
    global $adv, $advanced_search, $show_media, $description, $embedded;
    global $out, $xml_dir, $xml_name, $vowels, $noacc_el, $translit_el, $delim, $viking;
    global $cat_sel, $cat_sel0, $cat_sel0a, $cat_sel1, $cat_sel2, $cat_sel3, $cat_sel4, $cat_sel_all;
    //error_reporting (E_ALL);      //  for debug only
    $orig_query = $query;
    $starttime = getmicrotime();
    $query = str_replace('*', '', $query);
    //      kill wildcards, as media search already includes it
    if ($domain) {
        //  prepare the mysql query for domain search
        $domain_qry = "AND link_addr like '%" . $domain . "%'";
    } else {
        $domain_qry = "";
    }
    if (!$category) {
        $category = '0';
    }
    if ($debug_user == '1') {
        $slv1 = '';
        $slv2 = '';
        $slv3 = '';
        $slv4 = '';
        $slv5 = '';
        if ($db1_slv == 1) {
            $slv1 = '1,';
        }
        if ($db2_slv == 1) {
            $slv2 = '2,';
        }
        if ($db3_slv == 1) {
            $slv3 = '3,';
        }
        if ($db4_slv == 1) {
            $slv4 = '4,';
        }
        if ($db5_slv == 1) {
            $slv5 = '5';
        }
        echo "      <small>Results from database " . $slv1 . " " . $slv2 . " " . $slv3 . " " . $slv4 . " " . $slv5 . "</small>\n          <br />\n    ";
    }
    // if cached results should be used
    $cache_query = str_replace('"', '', $query);
    if (!$domain && $use_cache == '1' && !preg_match("/!|\\/|\\*|\\~|#|%|<|>|\\(|\\)|{|}|\\[|\\]|\\^|\\\\/", $cache_query)) {
        $cache_ok = '1';
        if (!is_dir($mediacache_dir)) {
            mkdir($mediacache_dir, 0777);
            //if not exist, try to create folder for media cache
            if (!is_dir($mediacache_dir)) {
                echo "<br />Unable to create folder for media cache<br />";
                $cache_ok = '';
            }
        }
        $no_cache = '1';
        if (is_dir($mediacache_dir)) {
            $rd_handle = fopen("" . $mediacache_dir . "/" . $cache_query . "_" . $type . "_" . $category . "_" . $cat_sel0 . "_" . $cat_sel0a . "_" . $cat_sel1 . "_" . $cat_sel2 . "_" . $cat_sel3 . "_" . $cat_sel4 . ".txt", "r+b");
            if ($rd_handle) {
                $cache_result = file_get_contents("" . $mediacache_dir . "/" . $cache_query . "_" . $type . "_" . $category . "_" . $cat_sel0 . "_" . $cat_sel0a . "_" . $cat_sel1 . "_" . $cat_sel2 . "_" . $cat_sel3 . "_" . $cat_sel4 . ".txt");
                if ($cache_result) {
                    $no_cache = '';
                    if ($debug_user == '1') {
                        echo "<small>Results found in cache</small><br />";
                    }
                    //  update cache-file with new modified date and time
                    file_put_contents("" . $mediacache_dir . "/" . $cache_query . "_" . $type . "_" . $category . "_" . $cat_sel0 . "_" . $cat_sel0a . "_" . $cat_sel1 . "_" . $cat_sel2 . "_" . $cat_sel3 . "_" . $cat_sel4 . ".txt", $cache_result);
                    //  make file content readable for result listing
                    $media_results = unserialize($cache_result);
                }
            }
            fclose($rd_handle);
        }
        //      get fresh results, because no cached result for this query available
        if ($no_cache == '1') {
            if ($debug_user == '1') {
                echo "<small>No results found in cache.<br />Get fresh result from database.</small><br />";
            }
            $media_results = all_fresh($query, $domain_qry, $mysql_table_prefix, $catid, $prefix);
            $media_count = count($media_results);
            //      if query did not match any media object
            if ($media_count < '1') {
                $msg = str_replace('%query', htmlentities(utf8_decode($query)), $sph_messages["noMediaMatch"]);
                //   display no media results found
                include "" . $template_dir . "/html/200_no media found.html";
                return '';
            }
        }
        $media_results = array_slice($media_results, 0, $max_cmresults);
        //  reduce to max allowed results per query
        if ($cache_ok == '1' && $no_cache == '1' && $media_results[0][2]) {
            //      create new cache file for new query input
            $wr_handle = fopen("" . $mediacache_dir . "/" . $cache_query . "_" . $type . "_" . $category . "_" . $cat_sel0 . "_" . $cat_sel0a . "_" . $cat_sel1 . "_" . $cat_sel2 . "_" . $cat_sel3 . "_" . $cat_sel4 . ".txt", "r");
            if (!$wr_handle) {
                //   create new cache file for current query input
                $result_string = serialize($media_results);
                if ($debug_user == '1') {
                    echo "<small>Create new result files and thumbnails for media cache.</small><br />";
                }
                $new_handle = fopen("" . $mediacache_dir . "/" . $cache_query . "_" . $type . "_" . $category . "_" . $cat_sel0 . "_" . $cat_sel0a . "_" . $cat_sel1 . "_" . $cat_sel2 . "_" . $cat_sel3 . "_" . $cat_sel4 . ".txt", "wb");
                if (!fwrite($new_handle, $result_string)) {
                    echo "<br />Unable to write into media cache<br />";
                }
                fclose($new_handle);
            } else {
                fclose($wr_handle);
            }
            //      get total size and time of creation for each cache file
            $size = '0';
            $all = array();
            $all_keys = array();
            $all_vals = array();
            if ($handle = opendir($mediacache_dir)) {
                while (false !== ($file = readdir($handle))) {
                    if ($file != "." && $file != "..") {
                        $size = $size + filesize("" . $mediacache_dir . "/" . $file . "");
                        $created = filemtime("" . $mediacache_dir . "/" . $file . "");
                        $all_vals[] = $file;
                        $all_keys[] = $created;
                    }
                }
            }
            $cache_size = $mcache_size * 1048576;
            //  cache size in Byte
            if ($size > $cache_size) {
                $all = array_combine($all_keys, $all_vals);
                ksort($all);
                //  find oldest cache file
                $del = current($all);
                @unlink("" . $mediacache_dir . "/" . $del . "");
                // delete oldest cache file
                if ($debug_user == '1') {
                    echo "<small>Cache overflow. Delete least significant file in cache ({$del})</small><br />";
                }
            }
            closedir($handle);
        }
    } else {
        //      get fresh results without cache
        $media_results = all_fresh($query, $domain_qry, $mysql_table_prefix, $catid, $prefix);
    }
    //  limit amount of results in result listing shown for pure media search
    $media_results = array_slice($media_results, 0, $max_results, TRUE);
    //  save info to query_log
    $endtime = getmicrotime() - $starttime;
    $media_count = count($media_results);
    $time = round($endtime, 3);
    $client_ip = $_SERVER['REMOTE_ADDR'];
    $orig_query = str_replace("*", "", $orig_query);
    //  remove wildcard character
    saveToLog(addslashes($orig_query), $time, $media_count, $client_ip, 1);
    //  if activated, prepare the XML result file
    if ($out == 'xml' && $xml_name) {
        media_xml($media_results, $media_count, $orig_query, $time);
    }
    //  single result option for wikinger-reisen.de
    if ($media_count == 1 && $viking) {
        require_once "wikinger.php";
        $search = 1;
        $media_only = 1;
        $client_ip = $_SERVER['REMOTE_ADDR'];
        $url = $media_results[0][2];
        //  URL of first result
        viking_option($url, $query, $search, $media_only, $category, $type, $db, $results_per_page, $prefix, $client_ip);
    }
    //      if query did not match any media object
    if ($media_count < '1') {
        //$msg = str_replace ('%query', htmlentities(utf8_decode($query)), $sph_messages["noMediaMatch"]);
        $msg = str_replace('%query', $orig_query, $sph_messages["noMediaMatch"]);
        //   display no media results found
        include "" . $template_dir . "/html/200_no media found.html";
        return '';
    }
    //Prepare results for listing
    $pages = ceil($media_count / $results_per_page);
    // Calculate count of required pages
    $class = "odrow";
    if (empty($start)) {
        $start = '1';
    }
    // As $start is not yet defined this is required for the first result page
    if ($start == '1') {
        $from = '0';
        // Also for first page in order not to multipy with 0
    } else {
        $from = ($start - 1) * $results_per_page;
        // First $num_row of actual page
    }
    $to = $media_count;
    // Last $num_row of actual page
    $rest = $media_count - $start;
    if ($media_count > $results_per_page) {
        // Display more then one page?
        $rest = $media_count - $from;
        $to = $from + $rest;
        // $to for last page
        if ($rest > $results_per_page) {
            $to = $from + $results_per_page;
        }
        // Calculate $num_row of actual page
    }
    //  result listing starts here
    if ($media_count > '0') {
        $fromm = $from + 1;
        $result = $sph_messages['Results'];
        $result = str_replace('%from', $from, $result);
        $result = str_replace('%to', $to, $result);
        $result = str_replace('%all', $media_count, $result);
        $matchword = $sph_messages["matches"];
        if ($media_count == 1) {
            $matchword = $sph_messages["match"];
        } else {
            $matchword = $sph_messages["matches"];
        }
        //  should we show the elapsed time in header?
        if ($elapsed) {
            $result = str_replace('%matchword', $matchword, $result);
            $result = str_replace('%secs', $time, $result);
        } else {
            $result = '';
            if ($media_count > 1) {
                $result = "" . $sph_messages['matches'] . " " . $from . " - " . $to . " " . $sph_messages['from'] . " " . $media_count . "";
            }
        }
        //  get name for valid catid
        $row = array();
        $row['category'] = '';
        if ($category != '-1') {
            $sql_query = "SELECT * from " . $mysql_table_prefix . "categories\n                                                where category_id = '{$catid}'";
            $reso = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            if ($reso->num_rows) {
                $row = $reso->fetch_array(MYSQL_ASSOC);
            }
        }
        //   display header for media-only results
        include "" . $template_dir . "/html/110_media-only header.html";
        //  loop through all results
        for ($i = $from; $i < $to; $i++) {
            $this_media = $media_results[$i];
            //      prepare current object-link for media counter
            $media_crypt = str_replace("&", "-_-", $this_media[3]);
            //  crypt the & character
            $media_click = "{$include_dir}/media_counter.php?url={$media_crypt}&amp;query={$query}&amp;db={$db}&amp;prefix={$prefix}&amp;client_ip={$client_ip}";
            //  redirect users click in order to update Most Popular Media
            //      prepare current page-link for click counter
            $link_crypt = str_replace("&", "-_-", $this_media[2]);
            $link_click = "{$include_dir}/click_counter.php?url={$link_crypt}&amp;query={$query}&amp;db={$db}&amp;prefix={$prefix}&amp;client_ip={$client_ip}";
            //  redirect users click in order to update Most Popular Links
            $media_title = $this_media[5];
            //  media title
            $thumb_link = utf8_encode($this_media[4]);
            //  link to thumbnail
            $i_1 = $i + 1;
            //  so table output does not start with zero
            $title = array();
            $sql_query = "SELECT title from " . $mysql_table_prefix . "links where link_id = " . $this_media[1] . "";
            //   if available get title of current page
            $result = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            if ($result->num_rows > '0') {
                $row = $result->fetch_array(MYSQLI_ASSOC);
                $page_title = $row["title"];
                // presents the page title
                $img_name = substr($this_media[3], strrpos($this_media[3], "/") + 1);
            }
            if ($class == "odrow") {
                $class = "evrow";
            } else {
                $class = "odrow";
            }
            //   display  media-only result listing
            include "" . $template_dir . "/html/120_media-only results.html";
        }
        //   display  end of result listing and links to other result pages
        include "" . $template_dir . "/html/190_more media-results.html";
    }
    return;
}
Example #21
0
 function save()
 {
     $jshopConfig = JSFactory::getConfig();
     require_once $jshopConfig->path . 'lib/uploadfile.class.php';
     JPluginHelper::importPlugin('jshoppingadmin');
     $dispatcher = JDispatcher::getInstance();
     $db = JFactory::getDBO();
     $value_id = JRequest::getInt("value_id");
     $attr_id = JRequest::getInt("attr_id");
     $post = JRequest::get("post");
     $attributValue = JTable::getInstance('attributValue', 'jshop');
     $dispatcher->trigger('onBeforeSaveAttributValue', array(&$post));
     $upload = new UploadFile($_FILES['image']);
     $upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
     $upload->setDir($jshopConfig->image_attributes_path);
     $upload->setFileNameMd5(0);
     $upload->setFilterName(1);
     if ($upload->upload()) {
         if ($post['old_image']) {
             @unlink($jshopConfig->image_attributes_path . "/" . $post['old_image']);
         }
         $post['image'] = $upload->getName();
         @chmod($jshopConfig->image_attributes_path . "/" . $post['image'], 0777);
     } else {
         if ($upload->getError() != 4) {
             JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
             saveToLog("error.log", "SaveAttributeValue - Error upload image. code: " . $upload->getError());
         }
     }
     if (!$value_id) {
         $query = "SELECT MAX(value_ordering) AS value_ordering FROM `#__jshopping_attr_values` where attr_id='" . $db->escape($attr_id) . "'";
         $db->setQuery($query);
         $row = $db->loadObject();
         $post['value_ordering'] = $row->value_ordering + 1;
     }
     if (!$attributValue->bind($post)) {
         JError::raiseWarning("", _JSHOP_ERROR_BIND);
         $this->setRedirect("index.php?option=com_jshopping&controller=attributesvalues&attr_id=" . $attr_id);
         return 0;
     }
     if (!$attributValue->store()) {
         JError::raiseWarning("", _JSHOP_ERROR_SAVE_DATABASE);
         $this->setRedirect("index.php?option=com_jshopping&controller=attributesvalues&attr_id=" . $attr_id);
         return 0;
     }
     $dispatcher->trigger('onAfterSaveAttributValue', array(&$attributValue));
     if ($this->getTask() == 'apply') {
         $this->setRedirect("index.php?option=com_jshopping&controller=attributesvalues&task=edit&attr_id=" . $attr_id . "&value_id=" . $attributValue->value_id);
     } else {
         $this->setRedirect("index.php?option=com_jshopping&controller=attributesvalues&attr_id=" . $attr_id);
     }
 }
Example #22
0
    function step7(){
        
        $mainframe =& JFactory::getApplication();
        $jshopConfig = &JSFactory::getConfig();
        $session =& JFactory::getSession();
        $pm_method = &JTable::getInstance('paymentMethod', 'jshop');
        
        if ($jshopConfig->savelog && $jshopConfig->savelogpaymentdata){            
            $str = "url: ".$_SERVER['REQUEST_URI']."\n";
            foreach($_POST as $k=>$v) $str .= $k."=".$v."\n";
            saveToLog("paymentdata.log", $str);
        }
        
        $act = JRequest::getVar("act");        
        $payment_method = JRequest::getVar("js_paymentclass");        
        
         if (!file_exists($jshopConfig->path . 'payments/' . $payment_method."/".$payment_method. '.php')) {
            if (JRequest::getInt('no_lang')) JSFactory::loadLanguageFile();
            saveToLog("payment.log", "#001 - Error payment method file. PM ".$payment_method);
            JError::raiseWarning(500, _JSHOP_ERROR_PAYMENT);            
            return 0;
        } 
        require_once ($jshopConfig->path . 'payments/' . $payment_method."/".$payment_method. '.php');        

        if (!class_exists($payment_method)) {
            if (JRequest::getInt('no_lang')) JSFactory::loadLanguageFile();
            saveToLog("payment.log", "#002 - Error payment. CLASS ".$payment_method);
            JError::raiseWarning(500, _JSHOP_ERROR_PAYMENT);            
            return 0;
        }
        
        $pmconfigs = $pm_method->getConfigsForClassName($payment_method);        
        $payment_system = new $payment_method();
        $urlParamsPS = $payment_system->getUrlParams($pmconfigs);
        
        $order_id = $urlParamsPS['order_id'];
        $hash = $urlParamsPS['hash'];
        $checkHash = $urlParamsPS['checkHash'];
        $checkReturnParams = $urlParamsPS['checkReturnParams'];
        
        $session->set('jshop_send_end_form', 0);
        
        if ($act == "cancel"){
            $this->_cancelPayOrder($order_id);
            return 0;
        }
        
        if ($act == "return" && !$checkReturnParams){
            $this->_setMaxStep(10);
            $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=finish', 0, 1, $jshopConfig->use_ssl));
            return 1;    
        }               
        
        $order = &JTable::getInstance('order', 'jshop');
        $order->load($order_id);
        
        if (JRequest::getInt('no_lang')){
            JSFactory::loadLanguageFile($order->getLang());
            $lang = &JSFactory::getLang($order->getLang());
        }

        if ($checkHash && $order->order_hash != $hash){
            saveToLog("payment.log", "#003 - Error order hash. Order id ".$order_id);
            JError::raiseWarning("", _JSHOP_ERROR_ORDER_HASH);
            return 0;    
        }
        
        if (!$order->payment_method_id){
            saveToLog("payment.log", "#004 - Error payment method id. Order id ".$order_id);
            JError::raiseWarning("", _JSHOP_ERROR_PAYMENT);
            return 0;    
        }        
                
        $pm_method->load($order->payment_method_id);
        
        if ($payment_method != $pm_method->payment_class){
            saveToLog("payment.log", "#005 - Error payment method set url. Order id ".$order_id);
            JError::raiseWarning("", _JSHOP_ERROR_PAYMENT);
            return 0;
        }
                
        $pmconfigs = $pm_method->getConfigs();
        $res = $payment_system->checkTransaction($pmconfigs, $order, $act);
        $rescode = $res[0];
        $restext = $res[1];        
        
        if ($rescode == 0 || $rescode == 3){        
            saveToLog("payment.log", $restext);
        }
        
        if ($rescode==0){
            $status = 0;
        }elseif($rescode==1){
            $status = $pmconfigs['transaction_end_status'];
        }elseif($rescode==2){
            $status = $pmconfigs['transaction_pending_status'];
        }elseif($rescode==3){
            $status = $pmconfigs['transaction_failed_status'];
        }
        
        if ($status && !$order->order_created){
            $order->order_created = 1;
            $order->order_status = $status;
            $order->store();
            $this->_sendOrderEmail($order->order_id);
            $order->changeProductQTYinStock("-");
            $this->_changeStatusOrder($order_id, $status, 0);
        }
            
        if ($status && $order->order_status != $status){            
           $this->_changeStatusOrder($order_id, $status, 1);
        }        

        if ($act == "notify"){
            $payment_system->nofityFinish($pmconfigs, $order, $rescode);            
            die();            
        }
              
        if ($rescode == 0 || $rescode == 3){			
            JError::raiseWarning(500, $restext); 
            $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step5',0,1,$jshopConfig->use_ssl));
            return 0;
        }else{
            $this->_setMaxStep(10);
            $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=finish',0,1,$jshopConfig->use_ssl));
            return 1;
        }
        
    }
Example #23
0
 public function userSave()
 {
     if (!$this->user_joomla_id) {
         throw new Exception('Error jshopUserregister->user_joomla_id');
     }
     $db = JFactory::getDBO();
     $this->user->user_id = $this->user_joomla_id;
     $this->user->number = $this->user->getNewUserNumber();
     if (!$db->insertObject($this->user->getTableName(), $this->user, $this->user->getKeyName())) {
         $this->savePostData();
         saveToLog('error.log', $db->getErrorMsg());
         $this->setError("Error insert in table " . $this->user->getTableName());
         return 0;
     } else {
         return 1;
     }
 }
Example #24
0
 function save()
 {
     $jshopConfig = JSFactory::getConfig();
     require_once $jshopConfig->path . 'lib/image.lib.php';
     require_once $jshopConfig->path . 'lib/uploadfile.class.php';
     $dispatcher = JDispatcher::getInstance();
     $apply = JRequest::getVar("apply");
     $_alias = JSFactory::getModel("alias");
     $db = JFactory::getDBO();
     $man = JSFactory::getTable('manufacturer', 'jshop');
     $man_id = JRequest::getInt("manufacturer_id");
     $post = JRequest::get("post");
     $_lang = JSFactory::getModel("languages");
     $languages = $_lang->getAllLanguages(1);
     foreach ($languages as $lang) {
         $post['name_' . $lang->language] = trim($post['name_' . $lang->language]);
         if ($jshopConfig->create_alias_product_category_auto && $post['alias_' . $lang->language] == "") {
             $post['alias_' . $lang->language] = $post['name_' . $lang->language];
         }
         $post['alias_' . $lang->language] = JApplication::stringURLSafe($post['alias_' . $lang->language]);
         if ($post['alias_' . $lang->language] != "" && !$_alias->checkExistAlias1Group($post['alias_' . $lang->language], $lang->language, 0, $man_id)) {
             $post['alias_' . $lang->language] = "";
             JError::raiseWarning("", _JSHOP_ERROR_ALIAS_ALREADY_EXIST);
         }
         $post['description_' . $lang->language] = JRequest::getVar('description' . $lang->id, '', 'post', "string", 2);
         $post['short_description_' . $lang->language] = JRequest::getVar('short_description_' . $lang->language, '', 'post', "string", 2);
     }
     if (!$post['manufacturer_publish']) {
         $post['manufacturer_publish'] = 0;
     }
     $dispatcher->trigger('onBeforeSaveManufacturer', array(&$post));
     if (!$man->bind($post)) {
         JError::raiseWarning("", _JSHOP_ERROR_BIND);
         $this->setRedirect("index.php?option=com_jshopping&controller=manufacturers");
         return 0;
     }
     if (!$man_id) {
         $man->ordering = null;
         $man->ordering = $man->getNextOrder();
     }
     $upload = new UploadFile($_FILES['manufacturer_logo']);
     $upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
     $upload->setDir($jshopConfig->image_manufs_path);
     $upload->setFileNameMd5(0);
     $upload->setFilterName(1);
     if ($upload->upload()) {
         if ($post['old_image']) {
             @unlink($jshopConfig->image_manufs_path . "/" . $post['old_image']);
         }
         $name = $upload->getName();
         @chmod($jshopConfig->image_manufs_path . "/" . $name, 0777);
         if ($post['size_im_category'] < 3) {
             if ($post['size_im_category'] == 1) {
                 $category_width_image = $jshopConfig->image_category_width;
                 $category_height_image = $jshopConfig->image_category_height;
             } else {
                 $category_width_image = JRequest::getInt('category_width_image');
                 $category_height_image = JRequest::getInt('category_height_image');
             }
             $path_full = $jshopConfig->image_manufs_path . "/" . $name;
             $path_thumb = $jshopConfig->image_manufs_path . "/" . $name;
             if (!ImageLib::resizeImageMagic($path_full, $category_width_image, $category_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color, $jshopConfig->image_interlace)) {
                 JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                 saveToLog("error.log", "SaveManufacturer - Error create thumbail");
             }
             @chmod($jshopConfig->image_manufs_path . "/" . $name, 0777);
             unset($img);
         }
         $man->manufacturer_logo = $name;
     } else {
         if ($upload->getError() != 4) {
             JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
             saveToLog("error.log", "SaveManufacturer - Error upload image. code: " . $upload->getError());
         }
     }
     if (!$man->store()) {
         JError::raiseWarning("", _JSHOP_ERROR_SAVE_DATABASE);
         $this->setRedirect("index.php?option=com_jshopping&controller=manufacturers");
         return 0;
     }
     $dispatcher->trigger('onAfterSaveManufacturer', array(&$man));
     if ($this->getTask() == 'apply') {
         $this->setRedirect("index.php?option=com_jshopping&controller=manufacturers&task=edit&man_id=" . $man->manufacturer_id);
     } else {
         $this->setRedirect("index.php?option=com_jshopping&controller=manufacturers");
     }
 }
Example #25
0
 function checkVersionUpdate($version)
 {
     $jshopConfig = JSFactory::getConfig();
     $currentVersion = $jshopConfig->getVersion();
     $groupVersion = intval($currentVersion);
     if (isset($version[$groupVersion])) {
         $min = $version[$groupVersion]['min'];
         $max = $version[$groupVersion]['max'];
         $min_cmp = version_compare($currentVersion, $min);
         $max_cmp = version_compare($currentVersion, $max);
         if ($min_cmp < 0) {
             JError::raiseWarning("", sprintf(_JSHOP_MIN_VERSION_ERROR, $min));
             saveToLog("install.log", "Error: " . sprintf(_JSHOP_MIN_VERSION_ERROR, $min));
             return 0;
         }
         if ($max_cmp > 0) {
             JError::raiseWarning("", sprintf(_JSHOP_MAX_VERSION_ERROR, $max));
             saveToLog("install.log", "Error: " . sprintf(_JSHOP_MAX_VERSION_ERROR, $max));
             return 0;
         }
     }
     return 1;
 }
Example #26
0
 function uploadFiles($product, $product_id, $post)
 {
     $jshopConfig = JSFactory::getConfig();
     $dispatcher = JDispatcher::getInstance();
     if (!isset($post['product_demo_descr'])) {
         $post['product_demo_descr'] = '';
     }
     if (!isset($post['product_file_descr'])) {
         $post['product_file_descr'] = '';
     }
     if (!isset($post['product_file_sort'])) {
         $post['product_file_sort'] = '';
     }
     for ($i = 0; $i < $jshopConfig->product_file_upload_count; $i++) {
         $file_demo = "";
         $file_sale = "";
         if ($jshopConfig->product_file_upload_via_ftp != 1) {
             $upload = new UploadFile($_FILES['product_demo_file_' . $i]);
             $upload->setDir($jshopConfig->demo_product_path);
             $upload->setFileNameMd5(0);
             $upload->setFilterName(1);
             if ($upload->upload()) {
                 $file_demo = $upload->getName();
                 @chmod($jshopConfig->demo_product_path . "/" . $file_demo, 0777);
             } else {
                 if ($upload->getError() != 4) {
                     JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_FILE_DEMO);
                     saveToLog("error.log", "SaveProduct - Error upload demo. code: " . $upload->getError());
                 }
             }
             unset($upload);
             $upload = new UploadFile($_FILES['product_file_' . $i]);
             $upload->setDir($jshopConfig->files_product_path);
             $upload->setFileNameMd5(0);
             $upload->setFilterName(1);
             if ($upload->upload()) {
                 $file_sale = $upload->getName();
                 @chmod($jshopConfig->files_product_path . "/" . $file_sale, 0777);
             } else {
                 if ($upload->getError() != 4) {
                     JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_FILE_SALE);
                     saveToLog("error.log", "SaveProduct - Error upload file sale. code: " . $upload->getError());
                 }
             }
             unset($upload);
         }
         if (!$file_demo && isset($post['product_demo_file_name_' . $i]) && $post['product_demo_file_name_' . $i]) {
             $file_demo = $post['product_demo_file_name_' . $i];
         }
         if (!$file_sale && isset($post['product_file_name_' . $i]) && $post['product_file_name_' . $i]) {
             $file_sale = $post['product_file_name_' . $i];
         }
         if ($file_demo != "" || $file_sale != "") {
             $this->addToProductFiles($product_id, $file_demo, $post['product_demo_descr_' . $i], $file_sale, $post['product_file_descr_' . $i], $post['product_file_sort_' . $i]);
         }
     }
     //Update description files
     $this->productUpdateDescriptionFiles($post['product_demo_descr'], $post['product_file_descr'], $post['product_file_sort']);
 }
 function step7()
 {
     $checkout = JModelLegacy::getInstance('checkout', 'jshop');
     $wmiframe = JRequest::getInt("wmiframe");
     $mainframe = JFactory::getApplication();
     $jshopConfig = JSFactory::getConfig();
     $session = JFactory::getSession();
     $pm_method = JTable::getInstance('paymentMethod', 'jshop');
     if ($jshopConfig->savelog && $jshopConfig->savelogpaymentdata) {
         $str = "url: " . $_SERVER['REQUEST_URI'] . "\n";
         foreach ($_POST as $k => $v) {
             $str .= $k . "=" . $v . "\n";
         }
         saveToLog("paymentdata.log", $str);
     }
     $act = JRequest::getVar("act");
     $payment_method = JRequest::getVar("js_paymentclass");
     $paymentsysdata = $pm_method->getPaymentSystemData($payment_method);
     $payment_system = $paymentsysdata->paymentSystem;
     if ($paymentsysdata->paymentSystemVerySimple) {
         if (JRequest::getInt('no_lang')) {
             JSFactory::loadLanguageFile();
         }
         saveToLog("payment.log", "#001 - Error payment method file. PM " . $payment_method);
         JError::raiseWarning(500, _JSHOP_ERROR_PAYMENT);
         return 0;
     }
     if ($paymentsysdata->paymentSystemError) {
         if (JRequest::getInt('no_lang')) {
             JSFactory::loadLanguageFile();
         }
         saveToLog("payment.log", "#002 - Error payment. CLASS " . $payment_method);
         JError::raiseWarning(500, _JSHOP_ERROR_PAYMENT);
         return 0;
     }
     $pmconfigs = $pm_method->getConfigsForClassName($payment_method);
     $urlParamsPS = $payment_system->getUrlParams($pmconfigs);
     $order_id = $urlParamsPS['order_id'];
     $hash = $urlParamsPS['hash'];
     $checkHash = $urlParamsPS['checkHash'];
     $checkReturnParams = $urlParamsPS['checkReturnParams'];
     $session->set('jshop_send_end_form', 0);
     if ($act == "cancel") {
         $this->_cancelPayOrder($order_id);
         return 0;
     }
     if ($act == "return" && !$checkReturnParams) {
         $checkout->setMaxStep(10);
         if (!$wmiframe) {
             $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=finish', 0, 1, $jshopConfig->use_ssl));
         } else {
             $this->iframeRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=finish', 0, 1, $jshopConfig->use_ssl));
         }
         return 1;
     }
     $order = JTable::getInstance('order', 'jshop');
     $order->load($order_id);
     if (JRequest::getInt('no_lang')) {
         JSFactory::loadLanguageFile($order->getLang());
         $lang = JSFactory::getLang($order->getLang());
     }
     if ($checkHash && $order->order_hash != $hash) {
         saveToLog("payment.log", "#003 - Error order hash. Order id " . $order_id);
         JError::raiseWarning("", _JSHOP_ERROR_ORDER_HASH);
         return 0;
     }
     if (!$order->payment_method_id) {
         saveToLog("payment.log", "#004 - Error payment method id. Order id " . $order_id);
         JError::raiseWarning("", _JSHOP_ERROR_PAYMENT);
         return 0;
     }
     $pm_method->load($order->payment_method_id);
     if ($payment_method != $pm_method->payment_class) {
         saveToLog("payment.log", "#005 - Error payment method set url. Order id " . $order_id);
         JError::raiseWarning("", _JSHOP_ERROR_PAYMENT);
         return 0;
     }
     $pmconfigs = $pm_method->getConfigs();
     $res = $payment_system->checkTransaction($pmconfigs, $order, $act);
     $rescode = $res[0];
     $restext = $res[1];
     if ($rescode != 1) {
         saveToLog("payment.log", $restext);
     }
     $status = 0;
     $types_status = array(0 => 0, 1 => $pmconfigs['transaction_end_status'], 2 => $pmconfigs['transaction_pending_status'], 3 => $pmconfigs['transaction_failed_status'], 4 => $pmconfigs['transaction_cancel_status'], 5 => $pmconfigs['transaction_open_status'], 6 => $pmconfigs['transaction_shipping_status'], 7 => $pmconfigs['transaction_refunded_status'], 8 => $pmconfigs['transaction_confirm_status'], 9 => $pmconfigs['transaction_complete_status'], 10 => $pmconfigs['transaction_other_status'], 99 => 0);
     if (isset($types_status[$rescode])) {
         $status = $types_status[$rescode];
     }
     if ($status && !$order->order_created) {
         $order->order_created = 1;
         $order->order_status = $status;
         $order->store();
         if ($jshopConfig->send_order_email) {
             $checkout->sendOrderEmail($order->order_id);
         }
         $checkout->sendOrderEmail($order->order_id);
         $order->changeProductQTYinStock("-");
         $checkout->changeStatusOrder($order_id, $status, 0);
     }
     if ($status && $order->order_status != $status) {
         $checkout->changeStatusOrder($order_id, $status, 1);
     }
     if ($act == "notify") {
         $payment_system->nofityFinish($pmconfigs, $order, $rescode);
         die;
     }
     $payment_system->finish($pmconfigs, $order, $rescode, $act);
     if (in_array($rescode, array(0, 3, 4))) {
         JError::raiseWarning(500, $restext);
         if (!$wmiframe) {
             $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step5', 0, 1, $jshopConfig->use_ssl));
         } else {
             $this->iframeRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=step5', 0, 1, $jshopConfig->use_ssl));
         }
         return 0;
     } else {
         $checkout->setMaxStep(10);
         if (!$wmiframe) {
             $this->setRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=finish', 0, 1, $jshopConfig->use_ssl));
         } else {
             $this->iframeRedirect(SEFLink('index.php?option=com_jshopping&controller=checkout&task=finish', 0, 1, $jshopConfig->use_ssl));
         }
         return 1;
     }
 }
 function save()
 {
     $mainframe = JFactory::getApplication();
     $jshopConfig = JSFactory::getConfig();
     require_once $jshopConfig->path . 'lib/image.lib.php';
     require_once $jshopConfig->path . 'lib/uploadfile.class.php';
     JPluginHelper::importPlugin('jshoppingadmin');
     $dispatcher = JDispatcher::getInstance();
     $_alias = $this->getModel("alias");
     $db = JFactory::getDBO();
     $category = JTable::getInstance("category", "jshop");
     if (!$_POST["category_id"]) {
         $_POST['category_add_date'] = getJsDate();
     }
     if (!isset($_POST['category_publish'])) {
         $_POST['category_publish'] = 0;
     }
     $post = JRequest::get('post');
     $_lang = $this->getModel("languages");
     $languages = $_lang->getAllLanguages(1);
     if ($post['category_parent_id'] == $post['category_id']) {
         $post['category_parent_id'] = 0;
     }
     $dispatcher->trigger('onBeforeSaveCategory', array(&$post));
     foreach ($languages as $lang) {
         $post['name_' . $lang->language] = trim($post['name_' . $lang->language]);
         if ($jshopConfig->create_alias_product_category_auto && $post['alias_' . $lang->language] == "") {
             $post['alias_' . $lang->language] = $post['name_' . $lang->language];
         }
         $post['alias_' . $lang->language] = JApplication::stringURLSafe($post['alias_' . $lang->language]);
         if ($post['alias_' . $lang->language] != "" && !$_alias->checkExistAlias1Group($post['alias_' . $lang->language], $lang->language, $post['category_id'], 0)) {
             $post['alias_' . $lang->language] = "";
             JError::raiseWarning("", _JSHOP_ERROR_ALIAS_ALREADY_EXIST);
         }
         $post['description_' . $lang->language] = JRequest::getVar('description' . $lang->id, '', 'post', "string", 2);
         $post['short_description_' . $lang->language] = JRequest::getVar('short_description_' . $lang->language, '', 'post', "string", 2);
     }
     if (!$category->bind($post)) {
         JError::raiseWarning("", _JSHOP_ERROR_BIND);
         $this->setRedirect("index.php?option=com_jshopping&controller=categories");
         return 0;
     }
     $edit = $category->category_id;
     $upload = new UploadFile($_FILES['category_image']);
     $upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
     $upload->setDir($jshopConfig->image_category_path);
     $upload->setFileNameMd5(0);
     $upload->setFilterName(1);
     if ($upload->upload()) {
         $name = $upload->getName();
         if ($post['old_image'] && $name != $post['old_image']) {
             @unlink($jshopConfig->image_category_path . "/" . $post['old_image']);
         }
         @chmod($jshopConfig->image_category_path . "/" . $name, 0777);
         if ($post['size_im_category'] < 3) {
             if ($post['size_im_category'] == 1) {
                 $category_width_image = $jshopConfig->image_category_width;
                 $category_height_image = $jshopConfig->image_category_height;
             } else {
                 $category_width_image = JRequest::getInt('category_width_image');
                 $category_height_image = JRequest::getInt('category_height_image');
             }
             $path_full = $jshopConfig->image_category_path . "/" . $name;
             $path_thumb = $jshopConfig->image_category_path . "/" . $name;
             if (!ImageLib::resizeImageMagic($path_full, $category_width_image, $category_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
                 JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                 saveToLog("error.log", "SaveCategory - Error create thumbail");
             }
             @chmod($jshopConfig->image_category_path . "/" . $name, 0777);
             unset($img);
         }
         $category->category_image = $name;
     } else {
         if ($upload->getError() != 4) {
             JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
             saveToLog("error.log", "SaveCategory - Error upload image. code: " . $upload->getError());
         }
     }
     $this->_reorderCategory($category);
     if (!$category->store()) {
         JError::raiseWarning("", _JSHOP_ERROR_SAVE_DATABASE);
         $this->setRedirect("index.php?option=com_jshopping&controller=categories");
         return 0;
     }
     $dispatcher->trigger('onAfterSaveCategory', array(&$category));
     $success = $edit ? _JSHOP_CATEGORY_SUCC_UPDATE : _JSHOP_CATEGORY_SUCC_ADDED;
     if ($this->getTask() == 'apply') {
         $this->setRedirect('index.php?option=com_jshopping&controller=categories&task=edit&category_id=' . $category->category_id, $success);
     } else {
         $this->setRedirect('index.php?option=com_jshopping&controller=categories', $success);
     }
 }