/** * Constructor - requires following vars: * * @param string $filename image path * * These are additional vars: * * @param int $newxsize new maximum image width * @param int $newysize new maximum image height * @param string $fileout output image path * @param int $thumbMaxSize whether thumbnail should have background fill to make it exactly $newxsize x $newysize * @param int $bgred 0-255 - red color variable for background filler * @param int $bggreen 0-255 - green color variable for background filler * @param int $bgblue 0-255 - blue color variable for background filler * */ function Img2Thumb($filename, $newxsize = 60, $newysize = 60, $fileout = '', $thumbMaxSize = 0, $bgred = 0, $bggreen = 0, $bgblue = 0) { //Some big pictures need that VmConfig::ensureMemoryLimit(128); // New modification - checks color int to be sure within range if ($thumbMaxSize) { $this->maxSize = true; } else { $this->maxSize = false; } if ($bgred >= 0 || $bgred <= 255) { $this->bg_red = $bgred; } else { $this->bg_red = 0; } if ($bggreen >= 0 || $bggreen <= 255) { $this->bg_green = $bggreen; } else { $this->bg_green = 0; } if ($bgblue >= 0 || $bgblue <= 255) { $this->bg_blue = $bgblue; } else { $this->bg_blue = 0; } $this->NewImgCreate($filename, $newxsize, $newysize, $fileout); }
public function __construct(){ // JTable::addIncludePath(VMPATH_ADMIN . DS . 'tables'); $this->_app = JFactory::getApplication(); $this->_db = JFactory::getDBO(); // $this->_oldToNew = new stdClass(); $this->starttime = microtime(true); $max_execution_time = VmConfig::getExecutionTime(); $jrmax_execution_time= vRequest::getInt('max_execution_time',300); if(!empty($jrmax_execution_time)){ // vmdebug('$jrmax_execution_time',$jrmax_execution_time); if($max_execution_time!==$jrmax_execution_time) @ini_set( 'max_execution_time', $jrmax_execution_time ); } $this->maxScriptTime = VmConfig::getExecutionTime() * 0.90-1; //Lets use 10% of the execution time as reserve to store the progress VmConfig::ensureMemoryLimit(128); $this->maxMemoryLimit = $this->return_bytes(ini_get('memory_limit')) * 0.85; $config = JFactory::getConfig(); $this->_prefix = $config->get('dbprefix'); $this->reCreaPri = VmConfig::get('reCreaPri',0); $this->reCreaKey = VmConfig::get('reCreaKey',1); }
public function __construct(){ // JTable::addIncludePath(VMPATH_ADMIN . DS . 'tables'); $this->_app = JFactory::getApplication(); $this->_db = JFactory::getDBO(); $this->_oldToNew = new stdClass(); $this->starttime = microtime(true); $max_execution_time = VmConfig::getExecutionTime(); $jrmax_execution_time= vRequest::getInt('max_execution_time'); if(!empty($jrmax_execution_time)){ // vmdebug('$jrmax_execution_time',$jrmax_execution_time); if($max_execution_time!=$jrmax_execution_time) @ini_set( 'max_execution_time', $jrmax_execution_time ); } else if($max_execution_time<60) { @ini_set( 'max_execution_time', 60 ); } $this->maxScriptTime = VmConfig::getExecutionTime()*0.80-1; //Lets use 30% of the execution time as reserve to store the progress $jrmemory_limit= vRequest::getInt('memory_limit'); if(!empty($jrmemory_limit)){ @ini_set( 'memory_limit', $jrmemory_limit.'M' ); } else { VmConfig::ensureMemoryLimit(128); } $this->maxMemoryLimit = $this->return_bytes(ini_get('memory_limit')) - (14 * 1024 * 1024) ; //Lets use 11MB for joomla // vmdebug('$this->maxMemoryLimit',$this->maxMemoryLimit); //134217728 //$this->maxMemoryLimit = $this -> return_bytes('20M'); // ini_set('memory_limit','35M'); $q = 'SELECT `id` FROM `#__virtuemart_migration_oldtonew_ids` '; $this->_db->setQuery($q); $res = $this->_db->loadResult(); if(empty($res)){ $q = 'INSERT INTO `#__virtuemart_migration_oldtonew_ids` (`id`) VALUES ("1")'; $this->_db->setQuery($q); $this->_db->execute(); $this->_app->enqueueMessage('Start with a new migration process and setup log maxScriptTime '.$this->maxScriptTime.' maxMemoryLimit '.$this->maxMemoryLimit/(1024*1024)); } else { $this->_app->enqueueMessage('Found prior migration process, resume migration maxScriptTime '.$this->maxScriptTime.' maxMemoryLimit '.$this->maxMemoryLimit/(1024*1024)); } $this->_keepOldProductIds = VmConfig::get('keepOldProductIds',FALSE); }
/** * Override of display to prevent caching * * @return JController A JController object to support chaining. */ public function display($cachable = false, $urlparams = false) { $format = JRequest::getWord('format', 'html'); $layout = JRequest::getWord('layout', 'invoice'); if ($format != 'pdf') { $viewName = 'invoice'; $view = $this->getView($viewName, $format); $view->headFooter = true; $view->display(); } else { //PDF needs more RAM than usual VmConfig::ensureMemoryLimit(64); $viewName = 'invoice'; $format = "html"; // Create the invoice PDF file on disk and send that back $orderDetails = $this->getOrderDetails(); $fileLocation = $this->getInvoicePDF($orderDetails, 'invoice', $layout); $fileName = basename($fileLocation); if (file_exists($fileLocation)) { $maxSpeed = 200; $range = 0; $size = filesize($fileLocation); $contentType = 'application/pdf'; header("Cache-Control: public"); header("Content-Transfer-Encoding: binary\n"); header('Content-Type: application/pdf'); $contentDisposition = 'attachment'; $agent = strtolower($_SERVER['HTTP_USER_AGENT']); if (strpos($agent, 'msie') !== FALSE) { $fileName = preg_replace('/\\./', '%2e', $fileName, substr_count($fileName, '.') - 1); } header("Content-Disposition: {$contentDisposition}; filename=\"{$fileName}\""); header("Accept-Ranges: bytes"); if (isset($_SERVER['HTTP_RANGE'])) { list($a, $range) = explode("=", $_SERVER['HTTP_RANGE']); str_replace($range, "-", $range); $size2 = $size - 1; $new_length = $size - $range; header("HTTP/1.1 206 Partial Content"); header("Content-Length: {$new_length}"); header("Content-Range: bytes {$range}{$size2}/{$size}"); } else { $size2 = $size - 1; header("Content-Range: bytes 0-{$size2}/{$size}"); header("Content-Length: " . $size); } if ($size == 0) { die('Zero byte file! Aborting download'); } //$contents = file_get_contents ($fileName); //echo $contents; // set_magic_quotes_runtime(0); $fp = fopen("{$fileLocation}", "rb"); fseek($fp, $range); while (!feof($fp) and connection_status() == 0) { set_time_limit(0); print fread($fp, 1024 * $maxSpeed); flush(); ob_flush(); sleep(1); } fclose($fp); JFactory::getApplication()->close(); } else { // TODO: Error message // vmError("File $fileName not found!"); } } }
public function display($tpl = null) { $mainframe = JFactory::getApplication(); $pathway = $mainframe->getPathway(); $task = JRequest::getWord('task', 'list'); $layoutName = JRequest::getWord('layout', 'list'); $this->setLayout($layoutName); $_currentUser = JFactory::getUser(); $document = JFactory::getDocument(); if (!empty($tpl)) { $format = $tpl; } else { $format = JRequest::getWord('format', 'html'); } $this->assignRef('format', $format); if ($format == 'pdf') { $document->setTitle(JText::_('COM_VIRTUEMART_INVOICE')); //PDF needs more RAM than usual VmConfig::ensureMemoryLimit(96); } else { if ($layoutName == 'details') { $document->setTitle(JText::_('COM_VIRTUEMART_ACC_ORDER_INFO')); $pathway->additem(JText::_('COM_VIRTUEMART_ACC_ORDER_INFO')); } else { $document->setTitle(JText::_('COM_VIRTUEMART_ORDERS_VIEW_DEFAULT_TITLE')); $pathway->additem(JText::_('COM_VIRTUEMART_ORDERS_VIEW_DEFAULT_TITLE')); } } $orderModel = VmModel::getModel('orders'); if ($layoutName == 'details') { $order_list_link = FALSE; $order_list_link = JRoute::_('index.php?option=com_virtuemart&view=orders&layout=list', FALSE); $this->assignRef('order_list_link', $order_list_link); $orderDetails = $orderModel->getMyOrderDetails(); if (!$orderDetails or empty($orderDetails['details'])) { echo JText::_('COM_VIRTUEMART_ORDER_NOTFOUND'); return; } $userFieldsModel = VmModel::getModel('userfields'); $_userFields = $userFieldsModel->getUserFields('account', array('captcha' => true, 'delimiters' => true), array('delimiter_userinfo', 'user_is_vendor', 'username', 'password', 'password2', 'agreed', 'address_type')); $orderbt = $orderDetails['details']['BT']; $orderst = array_key_exists('ST', $orderDetails['details']) ? $orderDetails['details']['ST'] : $orderbt; $userfields = $userFieldsModel->getUserFieldsFilled($_userFields, $orderbt); $_userFields = $userFieldsModel->getUserFields('shipment', array(), array('delimiter_userinfo', 'username', 'email', 'password', 'password2', 'agreed', 'address_type')); $shipmentfields = $userFieldsModel->getUserFieldsFilled($_userFields, $orderst); $shipment_name = ''; if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmshipment'); $dispatcher = JDispatcher::getInstance(); $returnValues = $dispatcher->trigger('plgVmOnShowOrderFEShipment', array($orderDetails['details']['BT']->virtuemart_order_id, $orderDetails['details']['BT']->virtuemart_shipmentmethod_id, &$shipment_name)); $payment_name = ''; if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmpayment'); $dispatcher = JDispatcher::getInstance(); $returnValues = $dispatcher->trigger('plgVmOnShowOrderFEPayment', array($orderDetails['details']['BT']->virtuemart_order_id, $orderDetails['details']['BT']->virtuemart_paymentmethod_id, &$payment_name)); if ($format == 'pdf') { $invoiceNumberDate = array(); $return = $orderModel->createInvoiceNumber($orderDetails['details']['BT'], $invoiceNumberDate); if (empty($invoiceNumberDate)) { $invoiceNumberDate[0] = 'no invoice number accessible'; $invoiceNumberDate[1] = 'no invoice date accessible'; } $this->assignRef('invoiceNumber', $invoiceNumberDate[0]); $this->assignRef('invoiceDate', $invoiceNumberDate[1]); } $this->assignRef('userfields', $userfields); $this->assignRef('shipmentfields', $shipmentfields); $this->assignRef('shipment_name', $shipment_name); $this->assignRef('payment_name', $payment_name); $this->assignRef('orderdetails', $orderDetails); if ($_currentUser->guest) { $details_url = juri::root() . 'index.php?option=com_virtuemart&view=orders&layout=details&tmpl=component&order_pass='******'order_pass', false) . '&order_number=' . JRequest::getString('order_number', false); } else { $details_url = juri::root() . 'index.php?option=com_virtuemart&view=orders&layout=details&tmpl=component&virtuemart_order_id=' . $this->orderdetails['details']['BT']->virtuemart_order_id; } $this->assignRef('details_url', $details_url); $tmpl = JRequest::getWord('tmpl'); $print = false; if ($tmpl) { $print = true; } $this->prepareVendor(); $this->assignRef('print', $print); $vendorId = 1; $emailCurrencyId = $orderDetails['details']['BT']->user_currency_id; $exchangeRate = FALSE; if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmpayment'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('plgVmgetEmailCurrency', array($orderDetails['details']['BT']->virtuemart_paymentmethod_id, $orderDetails['details']['BT']->virtuemart_order_id, &$emailCurrencyId)); if (!class_exists('CurrencyDisplay')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php'; } $currency = CurrencyDisplay::getInstance($emailCurrencyId, $vendorId); if ($emailCurrencyId) { vmdebug('exchangerate', $orderDetails['details']['BT']->user_currency_rate); $currency->exchangeRateShopper = $orderDetails['details']['BT']->user_currency_rate; } $this->assignRef('currency', $currency); // Implement the Joomla panels. If we need a ShipTo tab, make it the active one. // In tmpl/edit.php, this is the 4th tab (0-based, so set to 3 above) // jimport('joomla.html.pane'); // $pane = JPane::getInstance((__VM_ORDER_USE_SLIDERS?'Sliders':'Tabs')); // $this->assignRef('pane', $pane); } else { // 'list' -. default $useSSL = VmConfig::get('useSSL', 0); $useXHTML = true; $this->assignRef('useSSL', $useSSL); $this->assignRef('useXHTML', $useXHTML); if ($_currentUser->get('id') == 0) { // getOrdersList() returns all orders when no userID is set (admin function), // so explicetly define an empty array when not logged in. $orderList = array(); } else { $orderList = $orderModel->getOrdersList($_currentUser->get('id'), TRUE); foreach ($orderList as $order) { $vendorId = 1; $emailCurrencyId = $order->user_currency_id; $exchangeRate = FALSE; if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmpayment'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('plgVmgetEmailCurrency', array($order->virtuemart_paymentmethod_id, $order->virtuemart_order_id, &$emailCurrencyId)); if (!class_exists('CurrencyDisplay')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php'; } $currency = CurrencyDisplay::getInstance($emailCurrencyId, $vendorId); $this->assignRef('currency', $currency); if ($emailCurrencyId) { vmdebug('exchangerate', $order->user_currency_rate); $currency->exchangeRateShopper = $order->user_currency_rate; } $order->currency = $currency; } } $this->assignRef('orderlist', $orderList); } /* if (!class_exists('CurrencyDisplay')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'currencydisplay.php'); $currency = CurrencyDisplay::getInstance(); $this->assignRef('currency', $currency); */ $orderStatusModel = VmModel::getModel('orderstatus'); $_orderstatuses = $orderStatusModel->getOrderStatusList(); $orderstatuses = array(); foreach ($_orderstatuses as $_ordstat) { $orderstatuses[$_ordstat->order_status_code] = JText::_($_ordstat->order_status_name); } $this->assignRef('orderstatuses', $orderstatuses); if (!class_exists('ShopFunctions')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php'; } $document = JFactory::getDocument(); $document->setMetaData('robots', 'NOINDEX, NOFOLLOW, NOARCHIVE, NOSNIPPET'); // this is no setting in BE to change the layout ! //shopFunctionsF::setVmTemplate($this,0,0,$layoutName); parent::display($tpl); }
/** * With this function you can use a view to sent it by email. * Just use a task in a controller * * @param string $view for example user, cart * @param string $recipient shopper@whatever.com * @param bool $vendor true for notifying vendor of user action (e.g. registration) */ private static function sendVmMail(&$view, $recipient, $noVendorMail = FALSE) { VmConfig::ensureMemoryLimit(96); VmConfig::loadJLang('com_virtuemart', true); if ($noVendorMail and !empty($view->orderDetails) and !empty($view->orderDetails['details']['BT']->order_language)) { VmConfig::loadJLang('com_virtuemart', true, $view->orderDetails['details']['BT']->order_language); VmConfig::loadJLang('com_virtuemart_shoppers', TRUE, $view->orderDetails['details']['BT']->order_language); VmConfig::loadJLang('com_virtuemart_orders', TRUE, $view->orderDetails['details']['BT']->order_language); } else { VmConfig::loadJLang('com_virtuemart_shoppers', TRUE); VmConfig::loadJLang('com_virtuemart_orders', TRUE); } ob_start(); $view->renderMailLayout($noVendorMail, $recipient); $body = ob_get_contents(); ob_end_clean(); $subject = isset($view->subject) ? $view->subject : vmText::_('COM_VIRTUEMART_DEFAULT_MESSAGE_SUBJECT'); $mailer = JFactory::getMailer(); $mailer->addRecipient($recipient); $mailer->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8')); $mailer->isHTML(VmConfig::get('order_mail_html', TRUE)); $mailer->setBody($body); if (!$noVendorMail) { $replyTo[0] = $view->vendorEmail; $replyTo[1] = $view->vendor->vendor_name; $mailer->addReplyTo($replyTo); } else { if (isset($view->orderDetails['details']) and isset($view->orderDetails['details']['BT'])) { $replyTo[0] = $view->orderDetails['details']['BT']->email; $replyTo[1] = $view->orderDetails['details']['BT']->first_name . ' ' . $view->orderDetails['details']['BT']->last_name; } else { $replyTo[0] = $view->user->email; $replyTo[1] = $view->user->name; } $mailer->addReplyTo($replyTo); } if (isset($view->mediaToSend)) { foreach ((array) $view->mediaToSend as $media) { $mailer->addAttachment($media); } } // set proper sender $sender = array(); if (!empty($view->vendorEmail) and VmConfig::get('useVendorEmail', 0)) { $sender[0] = $view->vendorEmail; $sender[1] = $view->vendor->vendor_name; } else { // use default joomla's mail sender $app = JFactory::getApplication(); $sender[0] = $app->getCfg('mailfrom'); $sender[1] = $app->getCfg('fromname'); if (empty($sender[0])) { $config = JFactory::getConfig(); $sender = array($config->get('mailfrom'), $config->get('fromname')); } } $mailer->setSender($sender); return $mailer->Send(); }
public function display($cachable = false, $urlparams = false) { $format = JRequest::getWord('format', 'html'); $layout = JRequest::getWord('layout', 'invoice'); if ($format != 'pdf') { $viewName = 'invoice'; //PDF needs more RAM than usual VmConfig::ensureMemoryLimit(64); $view = $this->getView($viewName, $format); $view->headFooter = true; $view->display(); } else { $viewName = 'invoice'; $format = "html"; /* Create the invoice PDF file on disk and send that back */ $orderModel = VmModel::getModel('orders'); $orderDetails = $this->getOrderDetails(); $fileName = $this->getInvoicePDF($orderDetails, $viewName, $layout, $format); if (file_exists($fileName)) { header("Cache-Control: public"); header("Content-Transfer-Encoding: binary\n"); header('Content-Type: application/pdf'); $contentDisposition = 'attachment'; header("Content-Disposition: {$contentDisposition}; filename=\"" . basename($fileName) . "\""); $contents = file_get_contents($fileName); echo $contents; JFactory::getApplication()->close(); } else { // TODO: Error message // vmError("File $fileName not found!"); } } }
/** * With this function you can use a view to sent it by email. * Just use a task in a controller * * @param string $view for example user, cart * @param string $recipient shopper@whatever.com * @param bool $vendor true for notifying vendor of user action (e.g. registration) */ private static function sendVmMail(&$view, $recipient, $noVendorMail = FALSE) { VmConfig::ensureMemoryLimit(96); $jlang = JFactory::getLanguage(); if (VmConfig::get('enableEnglish', 1)) { $jlang->load('com_virtuemart', JPATH_SITE, 'en-GB', TRUE); } $jlang->load('com_virtuemart', JPATH_SITE, $jlang->getDefault(), TRUE); $jlang->load('com_virtuemart', JPATH_SITE, NULL, TRUE); if (!empty($view->orderDetails['details']['BT']->order_language)) { $jlang->load('com_virtuemart', JPATH_SITE, $view->orderDetails['details']['BT']->order_language, true); $jlang->load('com_virtuemart_shoppers', JPATH_SITE, $view->orderDetails['details']['BT']->order_language, true); $jlang->load('com_virtuemart_orders', JPATH_SITE, $view->orderDetails['details']['BT']->order_language, true); } else { VmConfig::loadJLang('com_virtuemart_shoppers', TRUE); VmConfig::loadJLang('com_virtuemart_orders', TRUE); } ob_start(); $view->renderMailLayout($noVendorMail, $recipient); $body = ob_get_contents(); ob_end_clean(); $subject = isset($view->subject) ? $view->subject : JText::_('COM_VIRTUEMART_DEFAULT_MESSAGE_SUBJECT'); $mailer = JFactory::getMailer(); $mailer->addRecipient($recipient); $mailer->setSubject(html_entity_decode($subject)); $mailer->isHTML(VmConfig::get('order_mail_html', TRUE)); $mailer->setBody($body); if (!$noVendorMail) { $replyto[0] = $view->vendorEmail; $replyto[1] = $view->vendor->vendor_name; $mailer->addReplyTo($replyto); } /* if (isset($view->replyTo)) { $mailer->addReplyTo($view->replyTo); }*/ if (isset($view->mediaToSend)) { foreach ((array) $view->mediaToSend as $media) { $mailer->addAttachment($media); } } // set proper sender $sender = array(); if (!empty($view->vendorEmail) and VmConfig::get('useVendorEmail', 0)) { $sender[0] = $view->vendorEmail; $sender[1] = $view->vendor->vendor_name; } else { // use default joomla's mail sender $app = JFactory::getApplication(); $sender[0] = $app->getCfg('mailfrom'); $sender[1] = $app->getCfg('fromname'); if (empty($sender[0])) { $config = JFactory::getConfig(); $sender = array($config->getValue('config.mailfrom'), $config->getValue('config.fromname')); } } $mailer->setSender($sender); return $mailer->Send(); }