public function main() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->loadLanguage('tool/backup'); $this->loadModel('tool/backup'); $this->document->setTitle($this->language->get('heading_title')); //shedule task for backup if ($this->request->is_POST() && $this->_validate()) { if (is_uploaded_file($this->request->files['restore']['tmp_name'])) { if (pathinfo($this->request->files['restore']['name'], PATHINFO_EXTENSION) == 'sql') { $filetype = 'sql'; $content = file_get_contents($this->request->files['restore']['tmp_name']); } else { $content = false; } } elseif (is_uploaded_file($this->request->files['import']['tmp_name'])) { if (pathinfo($this->request->files['import']['name'], PATHINFO_EXTENSION) == 'xml') { $filetype = 'xml'; $content = file_get_contents($this->request->files['import']['tmp_name']); } else { $content = false; } } else { $content = false; //if do sheduled task for backup $task_details = $this->model_tool_backup->createBackupTask('sheduled_backup', $this->request->post); if (!$task_details) { $this->error['warning'] = array_merge($this->error, $this->model_tool_backup->errors); } else { $this->session->data['success'] = sprintf($this->language->get('text_success_scheduled'), $this->html->getSecureURL('tool/task')); $this->redirect($this->html->getSecureURL('tool/backup')); } } if ($content) { $this->cache->delete('*'); if ($filetype == 'sql') { $this->model_tool_backup->restore($content); $this->session->data['success'] = $this->language->get('text_success'); $this->redirect($this->html->getSecureURL('tool/backup')); } else { if ($this->model_tool_backup->load($content)) { $this->session->data['success'] = $this->language->get('text_success_xml'); $this->redirect($this->html->getSecureURL('tool/backup')); } else { $this->error['warning'] = $this->language->get('error_xml'); } } } elseif (!has_value($this->request->post['do_backup'])) { if ($this->request->files) { $this->error['warning'] = $this->language->get('error_empty') . ' (' . pathinfo($this->request->files['restore']['name'], PATHINFO_EXTENSION) . ')'; } else { $this->error['warning'] = $this->language->get('error_upload'); $uploaded_file = ''; if (isset($this->request->files['restore'])) { $uploaded_file = $this->request->files['restore']; } elseif ($this->request->files['import']) { $uploaded_file = $this->request->files['import']; } if ($uploaded_file) { $this->error['warning'] .= '<br>Error: ' . getTextUploadError($uploaded_file['error']); } } } } if (isset($this->error['warning'])) { $this->data['error_warning'] = $this->error['warning']; } elseif ($this->session->data['error']) { $this->data['error_warning'] = $this->session->data['error']; unset($this->session->data['error']); } else { $bkp = new ABackup('manual_backup'); $bkp->validate(); $this->data['error_warning'] = implode("\n", $bkp->error); } if (isset($this->session->data['success'])) { $this->data['success'] = $this->session->data['success']; unset($this->session->data['success']); } else { $this->data['success'] = ''; } $this->document->resetBreadcrumbs(); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE)); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('tool/backup'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: ', 'current' => true)); $this->loadModel('tool/backup'); $this->data['tables'] = $this->model_tool_backup->getTables(); //if we cannot to get table list from database -show error if ($this->data['tables'] === false) { $this->data['tables'] = array(); } $table_sizes = $this->model_tool_backup->getTableSizes($this->data['tables']); $tables = array(); $db_size = 0; foreach ($this->data['tables'] as $table) { $tables[$table] = $table . ' (' . $table_sizes[$table]['text'] . ')'; $db_size += $table_sizes[$table]['bytes']; } //size of data of database (sql-file will be greater) if ($db_size > 1048576) { $this->data['entry_tables_size'] = round($db_size / 1048576, 1) . 'Mb'; } else { $this->data['entry_tables_size'] = round($db_size / 1024, 1) . 'Kb'; } $form = new AForm('ST'); $form->setForm(array('form_name' => 'backup')); $this->data['form']['id'] = 'backup'; $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'backup', 'action' => $this->html->getSecureURL('tool/backup'), 'attr' => 'class="aform form-horizontal"')) . $form->getFieldHtml(array('type' => 'hidden', 'name' => 'do_backup', 'value' => 1)); $this->data['form']['fields']['tables'] = $form->getFieldHtml(array('type' => 'checkboxgroup', 'name' => 'table_list[]', 'value' => $this->data['tables'], 'options' => $tables, 'scrollbox' => true, 'style' => 'checkboxgroup')); $c_size = $this->model_tool_backup->getCodeSize(); if ($c_size > 1048576) { $code_size = round($c_size / 1048576, 1) . 'Mb'; } else { $code_size = round($c_size / 1024, 1) . 'Kb'; } $this->data['entry_backup_code'] = sprintf($this->language->get('entry_backup_code'), $code_size); $this->data['form']['fields']['backup_code'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'backup_code', 'value' => '1', 'checked' => true)); $c_size = $this->model_tool_backup->getContentSize(); if ($c_size > 1048576) { $content_size = round($c_size / 1048576, 1) . 'Mb'; } else { $content_size = round($c_size / 1024, 1) . 'Kb'; } $this->data['entry_backup_content'] = sprintf($this->language->get('entry_backup_content'), $content_size); $this->data['form']['fields']['backup_content'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'backup_content', 'value' => '1', 'checked' => true)); $this->data['form']['fields']['compress_backup'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'compress_backup', 'value' => 1)); $this->data['entry_compress_backup'] = sprintf($this->language->get('entry_compress_backup'), str_replace(DIR_ROOT, '', DIR_BACKUP), DIR_BACKUP); $this->data['form']['build_task_url'] = $this->html->getSecureURL('r/tool/backup/buildTask'); $this->data['form']['complete_task_url'] = $this->html->getSecureURL('r/tool/backup/complete'); $this->data['form']['backup_now'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'backup_now', 'text' => $this->language->get('button_backup_now'), 'style' => 'button1')); $this->data['form']['backup_schedule'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'backup_schedule', 'text' => $this->language->get('button_backup_schedule'), 'style' => 'button1')); $form = new AForm('ST'); $form->setForm(array('form_name' => 'restore_form')); $this->data['restoreform']['id'] = 'restore_form'; $this->data['restoreform']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'restore_form', 'action' => $this->html->getSecureURL('tool/backup'), 'attr' => 'class="aform form-horizontal"')); $this->data['restoreform']['file'] = $form->getFieldHtml(array('type' => 'file', 'name' => 'restore')); $this->data['restoreform']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('tab_restore'), 'style' => 'button1')); $form = new AForm('ST'); $form->setForm(array('form_name' => 'loadxml_form')); $this->data['xmlform']['id'] = 'loadxml_form'; $this->data['xmlform']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'loadxml_form', 'action' => $this->html->getSecureURL('tool/backup'), 'attr' => 'class="aform form-horizontal"')); $this->data['xmlform']['file'] = $form->getFieldHtml(array('type' => 'file', 'name' => 'import')); $this->data['xmlform']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_load'), 'style' => 'button1')); $this->data['text_fail_note'] = sprintf($this->language->get('text_fail_note'), DIR_APP_SECTION . 'system/backup'); $this->view->batchAssign($this->data); $this->view->assign('help_url', $this->gen_help_url()); $this->view->assign('current_url', $this->html->currentURL()); $this->processTemplate('pages/tool/backup.tpl'); //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); }
public function upload() { //clean temporary directory $this->_clean_temp_dir(); $this->session->data['package_info'] = array(); $package_info =& $this->session->data['package_info']; $package_info['package_source'] = 'file'; $package_info['tmp_dir'] = $this->_get_temp_dir(); // process post if ($this->request->is_POST()) { if (is_uploaded_file($this->request->files['package_file']['tmp_name'])) { if (!is_int(strpos($this->request->files['package_file']['name'], '.tar.gz'))) { unlink($this->request->files['package_file']['tmp_name']); $this->session->data['error'] .= $this->language->get('error_archive_extension'); } else { $result = move_uploaded_file($this->request->files['package_file']['tmp_name'], $package_info['tmp_dir'] . $this->request->files['package_file']['name']); if (!$result || $this->request->files['package_file']['error']) { $this->session->data['error'] .= '<br>Error: ' . getTextUploadError($this->request->files['package_file']['error']); } else { $package_info['package_name'] = $this->request->files['package_file']['name']; $package_info['package_size'] = $this->request->files['package_file']['size']; $this->redirect($this->html->getSecureURL('tool/package_installer/agreement')); } } } else { if ($this->request->post['package_url']) { $package_info['package_url'] = $this->request->post['package_url']; $this->redirect($this->html->getSecureURL('tool/package_installer/download')); } else { $this->session->data['error'] .= '<br>Error: ' . getTextUploadError($this->request->files['package_file']['error']); } } } $this->document->setTitle($this->language->get('heading_title')); $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE)); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('tool/package_installer'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: ', 'current' => true)); $form = new AForm('ST'); $form->setForm(array('form_name' => 'uploadFrm')); $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'uploadFrm', 'action' => $this->html->getSecureURL('tool/package_installer/upload'), 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"')); $this->data['form']['fields']['upload_file'] = $form->getFieldHtml(array('type' => 'file', 'name' => 'package_file', 'value' => '', 'attr' => ' autocomplete="off" ')); $this->data['form']['fields']['upload_url'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'package_url', 'value' => '', 'attr' => ' autocomplete="off" ')); $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('text_continue'))); if (isset($this->session->data['error'])) { $error_txt = $this->session->data['error']; $error_txt .= '<br>' . $this->language->get('error_additional_help_text'); $this->data['error_warning'] = $error_txt; unset($package_info['package_dir'], $error_txt); } unset($this->session->data['error']); //run pre-check $this->_pre_check(); $this->data['heading_title'] = $this->language->get('heading_title'); $this->_initTabs('upload'); $this->data['upload'] = true; $this->data['text_or'] = $this->language->get('text_or'); $this->view->assign('help_url', $this->gen_help_url('')); $this->view->batchAssign($this->data); $this->processTemplate('pages/tool/package_installer.tpl'); }
/** * @throws AException * NOTE: this method have a few hk_processData calls. */ public function main() { $error_msg = array(); $cart_rt = 'checkout/cart'; $product_rt = 'product/product'; $checkout_rt = 'checkout/shipping'; $home_rt = 'index/home'; //is this an embed mode if ($this->config->get('embed_mode') == true) { $cart_rt = 'r/checkout/cart/embed'; } //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); //process all possible requests first if ($this->request->is_GET() && isset($this->request->get['product_id'])) { if (isset($this->request->get['option'])) { $option = $this->request->get['option']; } else { $option = array(); } if (isset($this->request->get['quantity'])) { $quantity = $this->request->get['quantity']; } else { $quantity = 1; } unset($this->session->data['shipping_methods']); unset($this->session->data['shipping_method']); unset($this->session->data['payment_methods']); unset($this->session->data['payment_method']); $this->cart->add($this->request->get['product_id'], $quantity, $option); $this->extensions->hk_ProcessData($this, 'add_product'); $this->redirect($this->html->getSecureURL($cart_rt)); } else { if ($this->request->is_GET() && isset($this->request->get['remove'])) { //remove product with button claick. $this->cart->remove($this->request->get['remove']); $this->extensions->hk_ProcessData($this, 'remove_product'); $this->redirect($this->html->getSecureURL($cart_rt)); } else { if ($this->request->is_POST()) { //if this is coupon, validate and apply if (isset($this->request->post['coupon']) && $this->_validateCoupon()) { $this->session->data['coupon'] = $this->request->post['coupon']; $this->data['success'] = $this->session->data['success'] = $this->language->get('text_coupon_success'); unset($this->session->data['success']); //process data $this->extensions->hk_ProcessData($this, 'apply_coupon'); } if ($this->error['error_warning']) { $error_msg[] = $this->error['error_warning']; } if (isset($this->request->post['quantity'])) { //we update cart if (!is_array($this->request->post['quantity'])) { $this->loadModel('catalog/product', 'storefront'); $product_id = $this->request->post['product_id']; if (isset($this->request->post['option'])) { $options = $this->request->post['option']; } else { $options = array(); } //for FILE-attributes if (has_value($this->request->files['option']['name'])) { $fm = new AFile(); foreach ($this->request->files['option']['name'] as $id => $name) { $attribute_data = $this->model_catalog_product->getProductOption($product_id, $id); $attribute_data['settings'] = unserialize($attribute_data['settings']); $file_path_info = $fm->getUploadFilePath($attribute_data['settings']['directory'], $name); $options[$id] = $file_path_info['name']; if (!has_value($name)) { continue; } if ($attribute_data['required'] && !$this->request->files['option']['size'][$id]) { $this->session->data['error'] = $this->language->get('error_required_options'); $this->redirect($_SERVER['HTTP_REFERER']); } $file_data = array('option_id' => $id, 'name' => $file_path_info['name'], 'path' => $file_path_info['path'], 'type' => $this->request->files['option']['type'][$id], 'tmp_name' => $this->request->files['option']['tmp_name'][$id], 'error' => $this->request->files['option']['error'][$id], 'size' => $this->request->files['option']['size'][$id]); $file_errors = $fm->validateFileOption($attribute_data['settings'], $file_data); if (has_value($file_errors)) { $this->session->data['error'] = implode('<br/>', $file_errors); $this->redirect($_SERVER['HTTP_REFERER']); } else { $result = move_uploaded_file($file_data['tmp_name'], $file_path_info['path']); if (!$result || $this->request->files['package_file']['error']) { $this->session->data['error'] .= '<br>Error: ' . getTextUploadError($this->request->files['option']['error'][$id]); $this->redirect($_SERVER['HTTP_REFERER']); } } $dataset = new ADataset('file_uploads', 'admin'); $dataset->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => $file_path_info['name'], 'type' => $file_data['type'], 'section' => 'product_option', 'section_id' => $attribute_data['attribute_id'], 'path' => $file_path_info['path'])); } } if ($text_errors = $this->model_catalog_product->validateProductOptions($product_id, $options)) { $this->session->data['error'] = $text_errors; //send options values back via _GET $url = '&' . http_build_query(array('option' => $this->request->post['option'])); $this->redirect($this->html->getSecureURL($product_rt, '&product_id=' . $this->request->post['product_id'] . $url)); } $this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $options); } else { foreach ($this->request->post['quantity'] as $key => $value) { $this->cart->update($key, $value); } } unset($this->session->data['shipping_methods']); unset($this->session->data['shipping_method']); unset($this->session->data['payment_methods']); unset($this->session->data['payment_method']); } if (isset($this->request->post['remove'])) { foreach (array_keys($this->request->post['remove']) as $key) { $this->cart->remove($key); } } $this->extensions->hk_ProcessData($this); //next page is requested after cart update if (isset($this->request->post['next_step'])) { $this->redirect($this->html->getSecureURL($this->request->post['next_step'])); } if (isset($this->request->post['redirect'])) { $this->session->data['redirect'] = $this->request->post['redirect']; } if (isset($this->request->post['quantity']) || isset($this->request->post['remove'])) { unset($this->session->data['shipping_methods']); unset($this->session->data['shipping_method']); unset($this->session->data['payment_methods']); unset($this->session->data['payment_method']); $this->redirect($this->html->getSecureURL($cart_rt)); } } } } $this->document->setTitle($this->language->get('heading_title')); $this->document->resetBreadcrumbs(); $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => false)); $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/cart'), 'text' => $this->language->get('text_basket'), 'separator' => $this->language->get('text_separator'))); if ($this->cart->hasProducts()) { if (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { $error_msg[] = $this->language->get('error_stock'); } $this->loadModel('tool/seo_url', 'storefront'); $form = new AForm(); $form->setForm(array('form_name' => 'cart')); $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'cart', 'action' => $this->html->getSecureURL($cart_rt))); $cart_products = $this->cart->getProducts(); $product_ids = array(); foreach ($cart_products as $result) { $product_ids[] = (int) $result['product_id']; } $resource = new AResource('image'); $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height')); $products = array(); foreach ($cart_products as $result) { $option_data = array(); $thumbnail = $thumbnails[$result['product_id']]; foreach ($result['option'] as $option) { $title = ''; if ($option['element_type'] == 'H') { continue; } //hide hidden options $value = $option['value']; // hide binary value for checkbox if ($option['element_type'] == 'C' && in_array($value, array(0, 1))) { $value = ''; } // strip long textarea value if ($option['element_type'] == 'T') { $title = strip_tags($value); $title = str_replace('\\r\\n', "\n", $title); $value = str_replace('\\r\\n', "\n", $value); if (mb_strlen($value) > 64) { $value = mb_substr($value, 0, 64) . '...'; } } $option_data[] = array('name' => $option['name'], 'value' => $value, 'title' => $title); } $products[] = array('remove' => $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'remove[' . $result['key'] . ']')), 'remove_url' => $this->html->getSecureURL($cart_rt, '&remove=' . $result['key']), 'key' => $result['key'], 'name' => $result['name'], 'model' => $result['model'], 'thumb' => $thumbnail, 'option' => $option_data, 'quantity' => $form->getFieldHtml(array('type' => 'input', 'name' => 'quantity[' . $result['key'] . ']', 'value' => $result['quantity'], 'attr' => ' size="3" ', 'style' => 'short')), 'stock' => $result['stock'], 'price' => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))), 'total' => $this->currency->format($this->tax->calculate($result['total'], $result['tax_class_id'], $this->config->get('config_tax'))), 'href' => $this->html->getSEOURL($product_rt, '&key=' . $result['key'], true)); } $this->data['products'] = $products; $this->data['form']['update'] = $form->getFieldHtml(array('type' => 'submit', 'name' => $this->language->get('button_update'))); $this->data['form']['checkout'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'checkout', 'text' => $this->language->get('button_checkout'), 'style' => 'button')); if ($this->config->get('config_cart_weight')) { $this->data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class')); } else { $this->data['weight'] = false; } $display_totals = $this->cart->buildTotalDisplay(); $this->data['totals'] = $display_totals['total_data']; if (isset($this->session->data['redirect'])) { $this->data['continue'] = str_replace('&', '&', $this->session->data['redirect']); unset($this->session->data['redirect']); } else { $this->data['continue'] = $this->html->getURL($home_rt); } $this->data['form']['continue_shopping'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'continue_shopping', 'text' => $this->language->get('button_shopping'), 'style' => 'button', 'href' => $this->data['continue'])); $this->data['checkout'] = $this->html->getSecureURL($checkout_rt); $this->data['checkout_rt'] = $checkout_rt; #Check if order total max/min is set and met $cf_total_min = $this->config->get('total_order_minimum'); $cf_total_max = $this->config->get('total_order_maximum'); if (!$this->cart->hasMinRequirement()) { $this->data['form']['checkout'] = ''; $error_msg[] = sprintf($this->language->get('error_order_minimum'), $this->currency->format($cf_total_min)); } if (!$this->cart->hasMaxRequirement()) { $this->data['form']['checkout'] = ''; $error_msg[] = sprintf($this->language->get('error_order_maximum'), $this->currency->format($cf_total_max)); } //prepare coupon display if ($this->config->get('config_coupon_on_cart_page')) { $this->view->assign('coupon_status', $this->config->get('coupon_status')); $action = $this->html->getSecureURL($cart_rt); $coupon_form = $this->dispatch('blocks/coupon_codes', array('action' => $action)); $this->view->assign('coupon_form', $coupon_form->dispatchGetOutput()); } if ($this->config->get('config_shipping_tax_estimate')) { $form = new AForm(); $form->setForm(array('form_name' => 'estimate')); $this->data['form_estimate']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'estimate', 'action' => $this->html->getSecureURL($cart_rt))); $this->data['estimates_enabled'] = true; } //try to get shipping address details if we have them $country_id = $this->config->get('config_country_id'); if ($this->session->data['shipping_address_id']) { $this->loadModel('account/address', 'storefront'); $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']); $postcode = $shipping_address['postcode']; $country_id = $shipping_address['country_id']; $zone_id = $shipping_address['zone_id']; } // use default address of customer for estimate form whe shipping address is unknown if (!$zone_id && $this->customer->isLogged()) { $this->loadModel('account/address', 'storefront'); $payment_address = $this->model_account_address->getAddress($this->customer->getAddressId()); $postcode = $payment_address['postcode']; $country_id = $payment_address['country_id']; $zone_id = $payment_address['zone_id']; } if ($this->request->post['postcode']) { $postcode = $this->request->post['postcode']; } if ($this->request->post['country'][0]) { $country_id = $this->request->post['country'][0]; } if ($this->request->post['country_zones'][0]) { $zone_id = $this->request->post['country_zones'][0]; } if ($zone_id) { $this->loadModel('localisation/zone', 'storefront'); $zone_data = $this->model_localisation_zone->getZone($zone_id); } $this->data['form_estimate']['postcode'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'postcode', 'value' => $postcode, 'style' => 'short')); $this->data['form_estimate']['country_zones'] = $form->getFieldHtml(array('type' => 'zones', 'name' => 'country', 'submit_mode' => 'id', 'value' => $country_id, 'zone_name' => $zone_data['name'], 'zone_value' => $zone_id)); $this->data['form_estimate']['submit'] = $form->getFieldHtml(array('type' => 'submit', 'name' => $this->language->get('button_text_estimate'))); if ($this->session->data['error']) { $error_msg[] = $this->session->data['error']; unset($this->session->data['error']); } $this->view->assign('error_warning', $error_msg); $this->view->setTemplate('pages/checkout/cart.tpl'); } else { $this->data['heading_title'] = $this->language->get('heading_title'); $this->data['text_error'] = $this->language->get('text_error'); $this->data['button_continue'] = $this->html->buildElement(array('name' => 'continue', 'type' => 'button', 'text' => $this->language->get('button_continue'), 'href' => $this->html->getURL($home_rt), 'style' => 'button')); if ($this->config->get('embed_mode') == true) { $this->data['back_url'] = $this->html->getURL('r/product/category'); } $this->view->setTemplate('pages/error/not_found.tpl'); } $this->view->batchAssign($this->data); $this->processTemplate(); //init controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); }
/** * @param array $data * @return bool * @throws AException */ public function generateExtension($data = array()) { $project_xml = $config_xml = array(); //when clone template if (has_value($data['clone_method'])) { $project_xml['clone_method'] = $data['clone_method']; $project_xml['proto_template'] = $data['proto_template']; } $extension_name = $data['extension_txt_id'] = $this->_prepareData('extension_txt_id', $data['extension_txt_id']); if (!$data['extension_txt_id']) { $this->error['extension_txt_id'] = 'Extension text Id required.'; return false; } $project_xml['extension_txt_id'] = $config_xml['extension_txt_id'] = $extension_name; if (file_exists(DIR_EXT . $extension_name)) { $this->error[] = 'Extension with text id "' . $extension_name . '" is already exists! Delete it first and refresh page.'; //return false; } $data['extension_type'] = $data['extension_type'] == 'other' ? 'extension' : $data['extension_type']; $project_xml['extension_type'] = $config_xml['extension_type'] = $data['extension_type']; $project_xml['extension_title'] = $data['extension_title']; $extension_directory = DIR_EXT . $extension_name; $data['header_comment'] = $this->_prepareData('header_comment', $data['header_comment']); $project_xml['header_comment'] = $data['header_comment']; $data['header_comment'] = "<?php\n" . $data['header_comment']; $data['header_comment'] .= "\n\n"; $data['header_comment'] .= "if (! defined ( 'DIR_CORE' )) {\nheader ( 'Location: static_pages/' );\n}\n\n"; $project_xml['header_comment'] = $data['header_comment']; if ($data['extension_admin_language_files']) { $data['extension_admin_language_files'] = $this->_prepareData('extension_admin_language_files', $data['extension_admin_language_files']); $project_xml['extension_admin_language_files'] = $data['extension_admin_language_files']; } if ($data['extension_storefront_language_files']) { $data['extension_storefront_language_files'] = $this->_prepareData('extension_storefront_language_files', $data['extension_storefront_language_files']); $project_xml['extension_storefront_language_files'] = $data['extension_storefront_language_files']; } // generating directory and files if (!is_dir($extension_directory)) { mkdir($extension_directory, 0777); } if ($data['hook_file']) { $project_xml['hook_file'] = $data['hook_file'] = $this->_prepareData('hook_file', $data['hook_file']); if (!file_exists($extension_directory . '/core/' . $data['hook_file'])) { if (!is_dir($extension_directory . '/core')) { mkdir($extension_directory . '/core', 0777); } $t = explode('_', $extension_name); foreach ($t as &$r) { $r = ucfirst($r); } unset($r); $class_name = implode('', $t); $content = "class Extension" . $class_name . " extends Extension {\n\n }\n"; $hook_class_name = "Extension" . $class_name; $project_xml['hook_class_name'] = $hook_class_name; file_put_contents($extension_directory . '/core/' . $data['hook_file'], $data['header_comment'] . $content); } } $project_xml['route'] = $data['route']; //GENERATING PHP FILES // do by letters M.V.C. order //MODELS $models = array('admin' => array(), 'storefront' => array()); foreach ($this->sections as $section) { if (!isset($data[$section . '_model_routes'])) { continue; } foreach ($data[$section . '_model_routes'] as $k => $route) { $file = trim($data[$section . '_model_files'][$k], '\\/ '); if ($route && $file) { $route = trim($route, '\\/ '); $file = substr($file, -4) != '.php' ? $file . '.php' : $file; $content = $data['header_comment']; // build class name $class_name = 'Model'; $rt = str_replace('/', '_', $route); $rt = explode('_', $rt); foreach ($rt as &$r) { $r = ucfirst($r); } unset($r); $class_name .= implode('', $rt); $rt = str_replace('.php', '', $file); $rt = explode('_', $rt); foreach ($rt as &$r) { $r = ucfirst($r); } unset($r); $class_name .= implode('', $rt); $content .= "class " . $class_name . " extends Model {\n\n\t\t\tpublic \$data = array ();\n\t\t\tprivate \$error = array ();\n }\n"; $dir = $extension_directory . '/' . $section . '/model/' . $route; if (!is_dir($dir)) { mkdir($dir, 0777, true); } if (!file_exists($dir . '/' . $file)) { file_put_contents($dir . '/' . $file, $content); } $rt = str_replace('.php', '', $file); $models[$section][] = $route . '/' . $rt; $project_xml['models'][$section][] = array('route' => $route, 'file' => $rt); } } } // VIEWS (tpl-files) $views = array('admin' => array(), 'storefront' => array()); foreach ($this->sections as $section) { foreach (array('page', 'response') as $ctrl_type) { if (!isset($data[$section . '_' . $ctrl_type . '_view_routes'])) { continue; } foreach ($data[$section . '_' . $ctrl_type . '_view_routes'] as $k => $route) { $file = trim($data[$section . '_' . $ctrl_type . '_view_files'][$k], '\\/ '); if ($route && $file) { $route = trim($route, '\\/ '); $file = substr($file, -4) != '.tpl' ? $file . '.tpl' : $file; $route_prefix = $this->getRtPrefixByControllerType($ctrl_type); $template_name = $data['extension_type'] == 'template' ? $extension_name : 'default'; $dir = $extension_directory . '/' . $section . '/view/' . $template_name . '/template/' . $route_prefix . '/' . $route; if (!is_dir($dir)) { mkdir($dir, 0777, true); } if (!file_exists($dir . '/' . $file)) { file_put_contents($dir . '/' . $file, ''); } $views[$section][$ctrl_type][] = $route_prefix . '/' . $route . '/' . $file; $project_xml['views'][$section][] = array('route' => $route_prefix . '/' . $route, 'file' => $file); } } } } // Controllers $controllers = array('admin' => array(), 'storefront' => array()); foreach ($this->sections as $section) { foreach (array('page', 'response', 'block', 'form', 'common', 'api', 'task') as $ctrl_type) { if (!isset($data[$section . '_' . $ctrl_type . '_controller_routes'])) { continue; } foreach ($data[$section . '_' . $ctrl_type . '_controller_routes'] as $k => $route) { $file = trim($data[$section . '_' . $ctrl_type . '_controller_files'][$k], '\\/ '); if ($route && $file) { $route = trim($route, '\\/ '); $file = rtrim($file, '.php'); $content = $data['header_comment']; $route_prefix = $this->getRtPrefixByControllerType($ctrl_type); // build class name $class_name = 'Controller' . ucfirst($route_prefix); $rt = str_replace('/', '_', $route); $rt = explode('_', $rt); foreach ($rt as &$r) { $r = ucfirst($r); } unset($r); $class_name .= implode('', $rt); $rt = str_replace('.php', '', $file); $rt = explode('_', $rt); foreach ($rt as &$r) { $r = ucfirst($r); } unset($r); $class_name .= implode('', $rt); $content .= "class " . $class_name . " extends AController {\n\n\t\tpublic \$data = array ();\n\t\tprivate \$error = array ();\n }\n"; $dir = $extension_directory . '/' . $section . '/controller/' . $route_prefix . '/' . $route; if (!is_dir($dir)) { mkdir($dir, 0777, true); } if (!file_exists($dir . '/' . $file . '.php')) { file_put_contents($dir . '/' . $file . '.php', $content); } $rt = str_replace('.php', '', $file); $controllers[$section][$ctrl_type][] = $route_prefix . '/' . $route . '/' . $rt; $project_xml['controllers'][$section][] = array('route' => $route_prefix . '/' . $route, 'file' => $file); } } } } unset($content); // LANGUAGE files for extension translates $languages = array('admin' => array(), 'storefront' => array()); //NOTE! unacceptable extension without at least one admin language file if (!$data['extension_admin_language_files']) { $data['extension_admin_language_files'] = array('english'); } foreach ($this->sections as $section) { if (!isset($data['extension_' . $section . '_language_files'])) { continue; } foreach ($data['extension_' . $section . '_language_files'] as $language_name) { if ($language_name) { $language_name = strtolower($language_name); $file = $extension_name . '.xml'; $languages[$section][$extension_name . '/' . $extension_name] = $extension_name . '/' . $extension_name; $project_xml['languages'][$section][] = $language_name . '/' . $extension_name . '/' . $extension_name; if (file_exists($extension_directory . '/' . $section . '/language/' . strtolower($language_name) . '/' . $extension_name . '/' . $file)) { continue; } $dir = $extension_directory . '/' . $section . '/language/' . $language_name . '/' . $extension_name; if (!is_dir($dir)) { mkdir($dir, 0777, true); } if ($section == 'admin') { $this->_save_base_language_xml($data, $language_name); } else { if (!file_exists($dir . '/' . $file)) { file_put_contents($dir . '/' . $file, ''); } } } } } // COMMON PART if ($data['install_php']) { $content = $data['header_comment'] . "\n\n\n"; $install_content = ''; //build layout.xml for template clone if ($project_xml['extension_type'] == 'template') { $this->load->model('tool/developer_tools_layout_xml'); $this->model_tool_developer_tools_layout_xml->saveXml($data['extension_txt_id'], 'default'); $install_content = "\$file = DIR_EXT . '/" . $data['extension_txt_id'] . "/layout.xml';\n" . "\$layout = new ALayoutManager('default');\n" . "\$layout->loadXml(array('file' => \$file));\n"; } if (!is_file($extension_directory . '/install.php')) { file_put_contents($extension_directory . '/install.php', $content . $install_content); } if ($project_xml['extension_type'] == 'template') { $uninstall_content = "\$extension_id = '" . $data['extension_txt_id'] . "';\n" . "// delete template layouts\n" . "\$layout = new ALayoutManager(\$extension_id);\n" . "\$layout->deleteTemplateLayouts();"; } if (!is_file($extension_directory . '/uninstall.php')) { file_put_contents($extension_directory . '/uninstall.php', $content . $uninstall_content); } unset($content, $install_content, $uninstall_content); } $project_xml['install_php'] = $config_xml['install_php'] = (int) $data['install_php']; if ($data['install_sql']) { if (!is_file($extension_directory . '/install.sql')) { file_put_contents($extension_directory . '/install.sql', ""); } if (!is_file($extension_directory . '/uninstall.sql')) { file_put_contents($extension_directory . '/uninstall.sql', ""); } } $project_xml['install_sql'] = $config_xml['install_sql'] = (int) $data['install_sql']; $data['help_note'] = trim($data['help_note']); $project_xml['help_note'] = $data['help_note']; $config_xml['note'] = $data['help_note'] ? true : false; $project_xml['help_url'] = (string) $data['help_url']; // extension icon $project_xml['icon_default'] = $data['icon_default'] = (int) $data['icon_default']; if (!$data['icon_default'] && $this->request->files['icon']) { if ($this->request->files['icon']['error']) { $this->error[] = getTextUploadError($this->request->files['icon']['error']); } if ($this->request->files['icon']['type'] == 'image/png' && $this->request->files['icon']['size'] > 0) { if (!is_dir($extension_directory . '/image')) { mkdir($extension_directory . '/image', 0777); } move_uploaded_file($this->request->files['icon']["tmp_name"], $extension_directory . '/image/icon.png'); } $project_xml['icon'] = 'icon.png'; } /*if($this->request->files['preview']){ foreach($this->request->files['preview']['name'] as $k=>$item){ if($this->request->files['preview']['error'][$k]){ $this->error[] = getTextUploadError($this->request->files['preview']['error'][$k]); } if($this->request->files['preview']['type'][$k]=='image/png' && $this->request->files['preview']['size'][$k]>0){ if(!is_dir($extension_directory.'/image')){ mkdir($extension_directory.'/image',0777); } move_uploaded_file($this->request->files['preview']["tmp_name"][$k],$extension_directory.'/image/preview'.$k.'.png'); $project_xml['preview'][] = 'preview'.$k.'.png'; $config_xml['preview'][] = 'preview'.$k.'.png'; } } } */ $project_xml['version'] = $config_xml['version'] = $data['version']; $project_xml['category'] = $config_xml['category'] = $data['extension_category']; $data['cartversions'] = array_unique((array) $data['cartversions']); $project_xml['cartversions'] = $config_xml['cartversions'] = $data['cartversions']; $project_xml['priority'] = $config_xml['priority'] = (int) $data['priority']; /*if($data['dependency']){ $project_xml['dependencies'] = array(); foreach($data['dependency']['name'] as $k => $dep_name){ if($dep_name){ $project_xml['dependencies']['item'][] = array('@attributes' => array( 'prior_version' => $data['dependency']['prior_versions'][$k], 'version' => $data['dependency']['versions'][$k]), '@value' => $dep_name); } } $config_xml['dependencies'] = $project_xml['dependencies']; }*/ $config_xml['settings'] = array('item' => array('@attributes' => array('id' => $data['extension_txt_id'] . "_status"), 'type' => 'checkbox', 'default_value' => '0')); $config_xml['note'] = $data['help_note'] ? true : false; if ($data['help_file']) { $data['help_file'] = trim((string) $data['help_file']); $project_xml['help_file'] = $data['help_file']; if (!is_dir(DIR_EXT . $extension_name . "/help")) { mkdir(DIR_EXT . $extension_name . "/help", 0777); } file_put_contents(DIR_EXT . $extension_name . "/help/" . $extension_name . '.txt', $data['help_file']); $data['help_file'] = "help/" . $extension_name . '.txt'; } $config_xml['install_sql'] = $data['install_sql']; $config_xml['install_php'] = $data['install_php']; $this->saveConfigXml($config_xml); // change mode recurcive $this->_chmod_R($extension_directory, 0777, 0777); $this->_replicate_default_dir_tree_($project_xml); // when cloning template check clone_method var // save project xml $this->saveProjectXml($project_xml); $this->saveMainFileByProjectConfig($project_xml); $this->session->data['dev_tools_prj_id'] = $project_xml['extension_txt_id'] . '_v' . $project_xml['version']; //for cloning of template need to install if ($project_xml['clone_method']) { //1. refresh extensions list to write new into db, table extensions $ex = new ExtensionsApi(); unset($ex); $em = new AExtensionManager(); $em->install($project_xml['extension_txt_id'], getExtensionConfigXml($project_xml['extension_txt_id'])); //enable $em->editSetting($project_xml['extension_txt_id'], array($project_xml['extension_txt_id'] . '_status' => 1)); } return true; }
public function main() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->document->setTitle($this->language->get('heading_title')); if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->_validate()) { if (is_uploaded_file($this->request->files['restore']['tmp_name'])) { if (pathinfo($this->request->files['restore']['name'], PATHINFO_EXTENSION) == 'sql') { $filetype = 'sql'; $content = file_get_contents($this->request->files['restore']['tmp_name']); } else { $content = false; } } elseif (is_uploaded_file($this->request->files['import']['tmp_name'])) { if (pathinfo($this->request->files['import']['name'], PATHINFO_EXTENSION) == 'xml') { $filetype = 'xml'; $content = file_get_contents($this->request->files['import']['tmp_name']); } else { $content = false; } } else { $content = false; } if ($content) { $this->cache->delete('*'); if ($filetype == 'sql') { $this->model_tool_backup->restore($content); $this->session->data['success'] = $this->language->get('text_success'); $this->redirect($this->html->getSecureURL('tool/backup')); } else { if ($this->model_tool_backup->load($content)) { $this->session->data['success'] = $this->language->get('text_success_xml'); $this->redirect($this->html->getSecureURL('tool/backup')); } else { $this->error['warning'] = $this->language->get('error_xml'); } } } else { if ($this->request->files) { $this->error['warning'] = $this->language->get('error_empty') . ' (' . pathinfo($this->request->files['restore']['name'], PATHINFO_EXTENSION) . ')'; } else { $this->error['warning'] = $this->language->get('error_upload'); $uploaded_file = ''; if (isset($this->request->files['restore'])) { $uploaded_file = $this->request->files['restore']; } elseif ($this->request->files['import']) { $uploaded_file = $this->request->files['import']; } if ($uploaded_file) { $this->error['warning'] .= '<br>Error: ' . getTextUploadError($uploaded_file['error']); } } } } $this->data['heading_title'] = $this->language->get('heading_title'); $this->data['text_select_all'] = $this->language->get('text_select_all'); $this->data['text_unselect_all'] = $this->language->get('text_unselect_all'); $this->data['entry_restore'] = $this->language->get('entry_restore'); $this->data['entry_backup'] = $this->language->get('entry_backup'); $this->data['entry_loadxml'] = $this->language->get('entry_loadxml'); $this->data['button_backup'] = $this->language->get('button_backup'); $this->data['button_restore'] = $this->language->get('button_restore'); $this->data['tab_backup'] = $this->language->get('tab_backup'); $this->data['tab_restore'] = $this->language->get('tab_restore'); $this->data['tab_loadxml'] = $this->language->get('tab_loadxml'); if (isset($this->error['warning'])) { $this->data['error_warning'] = $this->error['warning']; } elseif ($this->session->data['error']) { $this->data['error_warning'] = $this->session->data['error']; unset($this->session->data['error']); } else { $this->data['error_warning'] = ''; } if (isset($this->session->data['success'])) { $this->data['success'] = $this->session->data['success']; unset($this->session->data['success']); } else { $this->data['success'] = ''; } $this->document->resetBreadcrumbs(); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE)); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('tool/backup'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: ')); $this->data['backup'] = $this->html->getSecureURL('tool/backup_file'); $this->loadModel('tool/backup'); $this->data['tables'] = $this->model_tool_backup->getTables(); $tables = array(); foreach ($this->data['tables'] as $table) { $tables[$table] = $table; } $this->data['note_rl'] = $this->language->get('note_rl'); $this->data['note_config'] = $this->language->get('note_config'); $form = new AForm('ST'); $form->setForm(array('form_name' => 'backup')); $this->data['form']['id'] = 'backup'; $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'backup', 'action' => $this->data['backup'])); $this->data['form']['fields']['tables'] = $form->getFieldHtml(array('type' => 'checkboxgroup', 'name' => 'backup[]', 'value' => $this->data['tables'], 'options' => $tables, 'scrollbox' => true, 'style' => 'omg')); $this->data['form']['backup_rl'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'backup_rl', 'value' => 'rl', 'label_text' => $this->data['note_rl'], 'checked' => true)); $this->data['form']['backup_config'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'backup_config', 'label_text' => $this->data['note_config'], 'value' => 'config')); $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_backup'), 'style' => 'button1')); $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2')); $this->data['restore'] = $this->html->getSecureURL('tool/backup'); $form = new AForm('ST'); $form->setForm(array('form_name' => 'restore_form')); $this->data['restoreform']['id'] = 'restore_form'; $this->data['restoreform']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'restore_form', 'action' => $this->data['restore'])); $this->data['restoreform']['file'] = $form->getFieldHtml(array('type' => 'file', 'name' => 'restore')); $this->data['restoreform']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_go'), 'style' => 'button1')); $form = new AForm('ST'); $form->setForm(array('form_name' => 'loadxml_form')); $this->data['xmlform']['id'] = 'loadxml_form'; $this->data['xmlform']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'loadxml_form', 'action' => $this->data['restore'])); $this->data['xmlform']['file'] = $form->getFieldHtml(array('type' => 'file', 'name' => 'import')); $this->data['xmlform']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_go'), 'style' => 'button1')); $this->view->batchAssign($this->data); $this->view->assign('help_url', $this->gen_help_url()); $this->view->assign('current_url', $this->html->currentURL()); $this->processTemplate('pages/tool/backup.tpl'); //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); }
private function handle_file_upload($uploaded_file, $name, $size, $type, $error) { $file = new stdClass(); // Remove path information and dots around the filename, to prevent uploading // into different directories or replacing hidden system files. // Also remove control characters and spaces (\x00..\x20) around the filename: $name = $name == '' ? 'UnknownFile' : $name; $name = str_replace(" ", "_", stripslashes($name)); // basename removes first part of filename like тест_архив.zip (with non-latin characters). Basename of that name will be _архив.zip if ($this->strpos_array($name, array('/', '\'')) !== false) { $name = basename($name); } else { $res = strrpos($name, '/'); if ($res !== false) { $name = substr($name, $res + 1); } $res = strrpos($name, '\''); if ($res !== false) { $name = substr($name, $res + 1); } } $file->name = trim($name, "... "); $file->size = intval($size); $file->type = $type; // error check if ($error) { $error = getTextUploadError($error); } $error = $this->has_error($uploaded_file, $file, $error); if (!$error && $file->name) { if (!is_dir(DIR_RESOURCE . $this->options['upload_dir'])) { $path = ''; $directories = explode('/', str_replace('../', '', $this->options['upload_dir'])); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!is_dir(DIR_RESOURCE . $path)) { @mkdir(DIR_RESOURCE . $path, 0777); chmod(DIR_RESOURCE . $path, 0777); } } } if (!is_dir(DIR_RESOURCE . $this->options['upload_dir']) || !is_writeable(DIR_RESOURCE . $this->options['upload_dir'])) { $error = "Please check 'resources' folder permissions."; } } if (!$error && $file->name) { $file_path = DIR_RESOURCE . $this->options['upload_dir'] . $file->name; $append_file = !$this->options['discard_aborted_uploads'] && is_file($file_path) && $file->size > filesize($file_path); clearstatcache(); if ($uploaded_file && is_uploaded_file($uploaded_file)) { // multipart/formdata uploads (POST method uploads) if ($append_file) { file_put_contents($file_path, fopen($uploaded_file, 'r'), FILE_APPEND); } else { $result = move_uploaded_file($uploaded_file, $file_path); if ($result === false) { $file->error = 'Failed! Check error log for details.'; $error = new AError('Error! Tryed to move uploaded file from ' . $uploaded_file . ' to ' . $file_path); $error->toLog(); } } } else { // Non-multipart uploads (PUT method support) file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0); } $file_size = filesize($file_path); if ($file_size === $file->size) { $file->url = $this->options['upload_url'] . rawurlencode($file->name); chmod($file_path, 0777); } else { if ($this->options['discard_aborted_uploads']) { unlink($file_path); $file->error = 'Failed! Check error log for details.'; } } $file->size = $file_size; $file->delete_url = $this->options['script_url'] . '&resource_id=%ID%'; $file->delete_type = 'DELETE'; } else { $file->error = $error; } return $file; }
public function generateExtension($data = array()) { $project_xml = $config_xml = array(); $extension_name = $data['extension_txt_id'] = $this->_prepareData('extension_txt_id', $data['extension_txt_id']); if (!$data['extension_txt_id']) { $this->error['extension_txt_id'] = 'Extension text Id required.'; return false; } $project_xml['extension_txt_id'] = $config_xml['extension_txt_id'] = $extension_name; if (file_exists(DIR_EXT . $extension_name)) { exit('Extension with text id "' . $extension_name . '" is already exists! Delete it first and refresh page.'); } $data['extension_type'] = $data['extension_type'] == 'other' ? 'extension' : $data['extension_type']; $project_xml['extension_type'] = $config_xml['extension_type'] = $data['extension_type']; $project_xml['copy_default'] = $this->_prepareData('copy_default', $data['copy_default'], $project_xml); $project_xml['extension_title'] = $data['extension_title']; $extension_directory = DIR_EXT . $extension_name; $data['header_comment'] = $this->_prepareData('header_comment', $data['header_comment']); $project_xml['header_comment'] = $data['header_comment']; $data['header_comment'] = "<?php\n" . $data['header_comment']; $data['header_comment'] .= "\n\n"; $data['header_comment'] .= "if (! defined ( 'DIR_CORE' )) {\nheader ( 'Location: static_pages/' );\n}\n\n"; $project_xml['header_comment'] = $data['header_comment']; if ($data['extension_admin_language_files']) { $data['extension_admin_language_files'] = $this->_prepareData('extension_admin_language_files', $data['extension_admin_language_files']); $project_xml['extension_admin_language_files'] = $data['extension_admin_language_files']; } if ($data['extension_storefront_language_files']) { $data['extension_storefront_language_files'] = $this->_prepareData('extension_storefront_language_files', $data['extension_storefront_language_files']); $project_xml['extension_storefront_language_files'] = $data['extension_storefront_language_files']; } // generating directory and files mkdir($extension_directory, 0777); if ($data['hook_file']) { $project_xml['hook_file'] = $data['hook_file'] = $this->_prepareData('hook_file', $data['hook_file']); if (!file_exists($extension_directory . '/core/' . $data['hook_file'])) { if (!is_dir($extension_directory . '/core')) { mkdir($extension_directory . '/core', 0777); } $t = explode('_', $extension_name); foreach ($t as &$r) { $r = ucfirst($r); } unset($r); $class_name = implode('', $t); $content = "class Extension" . $class_name . " extends Extension {\n\n }\n"; $hook_class_name = "Extension" . $class_name; $project_xml['hook_class_name'] = $hook_class_name; file_put_contents($extension_directory . '/core/' . $data['hook_file'], $data['header_comment'] . $content); } } $project_xml['route'] = $data['route']; //GENERATING PHP FILES // go by letters MVC order :) //MODELS $models = array('admin' => array(), 'storefront' => array()); foreach ($this->sections as $section) { if (!isset($data[$section . '_model_routes'])) { continue; } foreach ($data[$section . '_model_routes'] as $k => $route) { $file = trim($data[$section . '_model_files'][$k], '\\/ '); if ($route && $file) { $route = trim($route, '\\/ '); $file = substr($file, -4) != '.php' ? $file . '.php' : $file; $content = $data['header_comment']; // build class name $class_name = 'Model'; $rt = str_replace('/', '_', $route); $rt = explode('_', $rt); foreach ($rt as &$r) { $r = ucfirst($r); } unset($r); $class_name .= implode('', $rt); $rt = str_replace('.php', '', $file); $rt = explode('_', $rt); foreach ($rt as &$r) { $r = ucfirst($r); } unset($r); $class_name .= implode('', $rt); $content .= "class " . $class_name . " extends Model {\n\n\t\t\tpublic \$data = array ();\n\t\t\tprivate \$error = array ();\n }\n"; $dir = $extension_directory . '/' . $section . '/model/' . $route; if (!file_exists($dir)) { mkdir($dir, 0777, true); } if (!file_exists($dir . '/' . $file)) { file_put_contents($dir . '/' . $file, $content); } $rt = str_replace('.php', '', $file); $models[$section][] = $route . '/' . $rt; $project_xml['models'][$section][] = array('route' => $route, 'file' => $rt); } } } // VIEWS (tpl-files) $views = array('admin' => array(), 'storefront' => array()); foreach ($this->sections as $section) { foreach (array('page', 'response') as $ctrl_type) { if (!isset($data[$section . '_' . $ctrl_type . '_view_routes'])) { continue; } foreach ($data[$section . '_' . $ctrl_type . '_view_routes'] as $k => $route) { $file = trim($data[$section . '_' . $ctrl_type . '_view_files'][$k], '\\/ '); if ($route && $file) { $route = trim($route, '\\/ '); $file = substr($file, -4) != '.tpl' ? $file . '.tpl' : $file; $route_prefix = $this->getRtPrefixByControllerType($ctrl_type); $template_name = $data['extension_type'] == 'template' ? $extension_name : 'default_html5'; $dir = $extension_directory . '/' . $section . '/view/' . $template_name . '/template/' . $route_prefix . '/' . $route; if (!file_exists($dir)) { mkdir($dir, 0777, true); } if (!file_exists($dir . '/' . $file)) { file_put_contents($dir . '/' . $file, ''); } $views[$section][$ctrl_type][] = $route_prefix . '/' . $route . '/' . $file; $project_xml['views'][$section][] = array('route' => $route_prefix . '/' . $route, 'file' => $file); } } } } // Controllers $controllers = array('admin' => array(), 'storefront' => array()); foreach ($this->sections as $section) { foreach (array('page', 'response', 'block', 'form', 'common') as $ctrl_type) { if (!isset($data[$section . '_' . $ctrl_type . '_controller_routes'])) { continue; } foreach ($data[$section . '_' . $ctrl_type . '_controller_routes'] as $k => $route) { $file = trim($data[$section . '_' . $ctrl_type . '_controller_files'][$k], '\\/ '); if ($route && $file) { $route = trim($route, '\\/ '); $file = substr($file, -4) != '.php' ? $file . '.php' : $file; $content = $data['header_comment']; $route_prefix = $this->getRtPrefixByControllerType($ctrl_type); // build class name $class_name = 'Controller' . ucfirst($route_prefix); $rt = str_replace('/', '_', $route); $rt = explode('_', $rt); foreach ($rt as &$r) { $r = ucfirst($r); } unset($r); $class_name .= implode('', $rt); $rt = str_replace('.php', '', $file); $rt = explode('_', $rt); foreach ($rt as &$r) { $r = ucfirst($r); } unset($r); $class_name .= implode('', $rt); $content .= "class " . $class_name . " extends AController {\n\n\t\tpublic \$data = array ();\n\t\tprivate \$error = array ();\n }\n"; $dir = $extension_directory . '/' . $section . '/controller/' . $route_prefix . '/' . $route; if (!file_exists($dir)) { mkdir($dir, 0777, true); } if (!file_exists($dir . '/' . $file)) { file_put_contents($dir . '/' . $file, $content); } $rt = str_replace('.php', '', $file); $controllers[$section][$ctrl_type][] = $route_prefix . '/' . $route . '/' . $rt; $project_xml['controllers'][$section][] = array('route' => $route_prefix . '/' . $route, 'file' => $file); } } } } // LANGUAGE files for extension translates $languages = array('admin' => array(), 'storefront' => array()); foreach ($this->sections as $section) { if (!isset($data['extension_' . $section . '_language_files'])) { continue; } foreach ($data['extension_' . $section . '_language_files'] as $language_name) { if ($language_name) { $language_name = strtolower($language_name); $file = $extension_name . '.xml'; $languages[$section][$extension_name . '/' . $extension_name] = $extension_name . '/' . $extension_name; $project_xml['languages'][$section][] = $extension_name . '/' . $extension_name; if (file_exists($extension_directory . '/' . $section . '/language/' . strtolower($language_name) . '/' . $extension_name . '/' . $file)) { continue; } mkdir($extension_directory . '/' . $section . '/language/' . $language_name . '/' . $extension_name, 0777, true); if ($section == 'admin') { $this->_save_base_language_xml($data, $language_name); } else { file_put_contents($extension_directory . '/' . $section . '/language/' . $language_name . '/' . $extension_name . '/' . $file, ''); } } } } // COMMON PART if ($data['install_php']) { file_put_contents($extension_directory . '/install.php', $data['header_comment']); file_put_contents($extension_directory . '/uninstall.php', $data['header_comment']); } $project_xml['install_php'] = $config_xml['install_php'] = (int) $data['install_php']; if ($data['install_sql']) { file_put_contents($extension_directory . '/install.sql', ""); file_put_contents($extension_directory . '/uninstall.sql', ""); } $project_xml['install_sql'] = $config_xml['install_sql'] = (int) $data['install_sql']; $data['help_note'] = trim($data['help_note']); $project_xml['help_note'] = $data['help_note']; $config_xml['note'] = $data['help_note'] ? true : false; $project_xml['help_url'] = (string) $data['help_url']; // extension icon $project_xml['icon_default'] = $data['icon_default'] = (int) $data['icon_default']; if (!$data['icon_default'] && $this->request->files['icon']) { if ($this->request->files['icon']['error']) { $this->error[] = getTextUploadError($this->request->files['icon']['error']); } if ($this->request->files['icon']['type'] == 'image/png' && $this->request->files['icon']['size'] > 0) { if (!is_dir($extension_directory . '/image')) { mkdir($extension_directory . '/image', 0777); } move_uploaded_file($this->request->files['icon']["tmp_name"], $extension_directory . '/image/icon.png'); } $project_xml['icon'] = 'icon.png'; } /*if($this->request->files['preview']){ foreach($this->request->files['preview']['name'] as $k=>$item){ if($this->request->files['preview']['error'][$k]){ $this->error[] = getTextUploadError($this->request->files['preview']['error'][$k]); } if($this->request->files['preview']['type'][$k]=='image/png' && $this->request->files['preview']['size'][$k]>0){ if(!is_dir($extension_directory.'/image')){ mkdir($extension_directory.'/image',0777); } move_uploaded_file($this->request->files['preview']["tmp_name"][$k],$extension_directory.'/image/preview'.$k.'.png'); $project_xml['preview'][] = 'preview'.$k.'.png'; $config_xml['preview'][] = 'preview'.$k.'.png'; } } } */ $project_xml['version'] = $config_xml['version'] = $data['version']; $project_xml['category'] = $config_xml['category'] = $data['extension_category']; $data['cartversions'] = array_unique((array) $data['cartversions']); $project_xml['cartversions'] = $config_xml['cartversions'] = $data['cartversions']; $project_xml['priority'] = $config_xml['priority'] = (int) $data['priority']; if ($data['dependency']) { $project_xml['dependencies'] = array(); foreach ($data['dependency']['name'] as $k => $dep_name) { if ($dep_name) { $project_xml['dependencies']['item'][] = array('@attributes' => array('prior_version' => $data['dependency']['prior_versions'][$k], 'version' => $data['dependency']['versions'][$k]), '@value' => $dep_name); } } $config_xml['dependencies'] = $project_xml['dependencies']; } $config_xml['settings'] = array('item' => array('@attributes' => array('id' => $data['extension_txt_id'] . "_status"), 'type' => 'checkbox', 'default_value' => '0')); $config_xml['note'] = $data['help_note'] ? true : false; if ($data['help_file']) { $data['help_file'] = trim((string) $data['help_file']); $project_xml['help_file'] = $data['help_file']; if (!is_dir(DIR_EXT . $extension_name . "/help")) { mkdir(DIR_EXT . $extension_name . "/help", 0777); } file_put_contents(DIR_EXT . $extension_name . "/help/" . $extension_name . '.txt', $data['help_file']); $data['help_file'] = "help/" . $extension_name . '.txt'; } $config_xml['install_sql'] = $data['install_sql']; $config_xml['install_php'] = $data['install_php']; $this->saveConfigXml($config_xml); // change mode recurcive $this->_chmod_R($extension_directory, 0777, 0777); $this->_replicate_default_dir_tree_($project_xml); // save project xml $this->saveProjectXml($project_xml); $this->saveMainFileByProjectConfig($project_xml); return true; }
public function upload() { //clean temporary directory $this->_clean_temp_dir(); $this->session->data['package_info'] = array(); $package_info =& $this->session->data['package_info']; $package_info['package_source'] = 'file'; // check destination $package_info['tmp_dir'] = $this->_get_temp_dir(); if (!is_writable($package_info['tmp_dir'])) { $this->session->data['error'] = $this->language->get('error_dir_permission') . ' ' . $package_info['tmp_dir']; unset($this->session->data['package_info']); $this->redirect($this->html->getSecureURL('tool/package_installer/upload')); } // process post if ($this->request->server['REQUEST_METHOD'] == 'POST') { if (is_uploaded_file($this->request->files['package_file']['tmp_name'])) { if (!is_int(strpos($this->request->files['package_file']['name'], '.tar.gz'))) { unlink($this->request->files['package_file']['tmp_name']); $this->session->data['error'] .= $this->language->get('error_archive_extension'); } else { $result = move_uploaded_file($this->request->files['package_file']['tmp_name'], $package_info['tmp_dir'] . $this->request->files['package_file']['name']); if (!$result || $this->request->files['package_file']['error']) { $this->session->data['error'] .= '<br>Error: ' . getTextUploadError($this->request->files['package_file']['error']); } else { $package_info['package_name'] = $this->request->files['package_file']['name']; $package_info['package_size'] = $this->request->files['package_file']['size']; $this->redirect($this->html->getSecureURL('tool/package_installer/agreement')); } } } else { if ($this->request->post['package_url']) { $package_info['package_url'] = $this->request->post['package_url']; $this->redirect($this->html->getSecureURL('tool/package_installer/download')); } else { $this->session->data['error'] .= '<br>Error: ' . getTextUploadError($this->request->files['package_file']['error']); } } } $this->document->setTitle($this->language->get('heading_title')); $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE)); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('tool/package_installer'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: ')); $form = new AForm('ST'); $form->setForm(array('form_name' => 'uploadFrm')); $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'uploadFrm', 'action' => $this->html->getSecureURL('tool/package_installer/upload'))); $this->data['entry_upload_file'] = $this->language->get('entry_upload_file'); $this->data['form']['file'] = $form->getFieldHtml(array('type' => 'file', 'name' => 'package_file', 'value' => '', 'attr' => ' autocomplete="off" ')); $this->data['entry_upload_url'] = $this->language->get('entry_upload_url'); $this->data['form']['url'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'package_url', 'value' => '', 'attr' => ' autocomplete="off" ')); $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2')); $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('text_continue'), 'style' => 'button1')); if (isset($this->session->data['error'])) { $this->view->assign('error', $this->session->data['error']); unset($package_info['package_dir']); } unset($this->session->data['error']); $this->data['heading_title'] = $this->language->get('heading_title'); $this->data['tabs'] = array(array('href' => $this->html->getSecureURL('tool/package_installer'), 'text' => $this->language->get('text_network_install'), 'active' => false), array('href' => $this->_get_begin_href(), 'text' => $this->language->get('text_extension_upload'), 'active' => true)); $this->data['upload'] = true; $this->data['text_or'] = $this->language->get('text_or'); $this->view->assign('help_url', $this->gen_help_url('')); $this->view->batchAssign($this->data); $this->processTemplate('pages/tool/package_installer.tpl'); }