Skip to content

Commit

Permalink
improvements related to layout export and languages
Browse files Browse the repository at this point in the history
  • Loading branch information
abolabo committed Nov 27, 2024
1 parent ad4e818 commit 23803cb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,14 @@ public function edit()

$langs = $lm->getAvailableLanguages();
foreach ($langs as $lang) {
$lm->definitionAutoLoad($lang['language_id'], $this->request->get['section'], $block);
$res = $lm->definitionAutoLoad(
$lang['language_id'],
$this->request->get['section'],
$block
);
if(!$res){
$this->log->write($lm->error);
}
}
$this->data['success'] = $this->language->get('developer_tools_text_language_file_edit_success');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,17 @@ public function generateExtension($data = []){
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 ( in_array($this->request->files['icon']['type'], ['image/webp','image/jpg','image/jpeg','image/gif','image/png'])
&& $this->request->files['icon']['size'] > 0
){
$iconFileExt = pathinfo($this->request->files['icon']["name"], PATHINFO_EXTENSION);
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');
move_uploaded_file($this->request->files['icon']["tmp_name"], $extension_directory . '/image/icon.'.$iconFileExt);
$project_xml['icon'] = 'icon.'.$iconFileExt;
}
$project_xml['icon'] = 'icon.png';

}

$project_xml['version'] = $config_xml['version'] = $data['version'];
Expand Down Expand Up @@ -644,9 +648,7 @@ private function _write_main_file($data){
// build main.php
$content = $data['header_comment'];
$tab = ' ';
$content .= $data['hook_file'] ? "\nif(!class_exists('" . $data['hook_class_name'] . "')){\n" .
$tab . "include_once('core/" . $data['hook_file'] . "');\n"
. "}\n" : "";
$content .= $data['hook_file'] ? "\n" . $tab . "require_once(DIR_EXT.'" . $data['extension_name'] . "'.DS.'core'.DS.'" . $data['hook_file'] . "');\n" : "";

$content .= "\$controllers = array(\n" . $tab . "'storefront' => array(";
if ($data['controllers']['storefront']){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
if (!defined('DIR_CORE')){
header('Location: static_pages/');
}
require_once(DIR_EXT . 'developer_tools/core/lib/array2xml.php');
require_once(DIR_EXT . 'developer_tools'.DS.'core'.DS.'lib'.DS.'array2xml.php');
/**
* @property ALayoutManager $lm
*/
Expand All @@ -41,7 +41,7 @@ public function saveXml($dst_template_id, $src_template_id, $path = ''){
'template_id' => $dst_template_id,
'type' => $this->_getTextLayoutType($layout['layout_type'])
];
//note: layout can be orphan and do not assigned to any pages and do not contains any blocks
//note: layout can be orphan
$pages = $this->_getLayoutPages4Xml($layout_id);
if($pages){
$xml_data['layout'][$i]['pages'] = ['page' => $pages];
Expand All @@ -60,11 +60,11 @@ public function saveXml($dst_template_id, $src_template_id, $path = ''){
$xml = $xml->saveXML();

$core_path = $path;
if(substr($core_path, -11) == '/layout.xml') {
if( str_ends_with( $core_path, DS.'layout.xml') ) {
$core_path = substr($core_path, 0, -11);
}

$path = !$path ? DIR_EXT . $dst_template_id . '/layout.xml' : $core_path . '/layout.xml';
$path = !$path ? DIR_EXT . $dst_template_id . DS.'layout.xml' : $core_path . DS . 'layout.xml';

if ($xml){
$result = file_put_contents($path, $xml);
Expand Down Expand Up @@ -230,24 +230,23 @@ private function _getLayoutBlocks4Xml($layout_id, $parent_instance_id = 0){
private function _getBlockInfo4Xml($block_id){
$block_id = (int)$block_id;
$sql = "SELECT b.block_id as block_id,
b.block_txt_id as block_txt_id,
b.controller as controller,
bt.parent_block_id as parent_block_id,
bt.template as template,
pb.block_txt_id as parent_block_txt_id
b.block_txt_id as block_txt_id,
b.controller as controller,
bt.parent_block_id as parent_block_id,
bt.template as template,
pb.block_txt_id as parent_block_txt_id
FROM " . $this->db->table('blocks')." as b
LEFT JOIN " . $this->db->table('block_templates') . " as bt ON (b.block_id = bt.block_id)
LEFT JOIN " . $this->db->table('blocks') . " as pb ON (pb.block_id = bt.parent_block_id)
LEFT JOIN " . $this->db->table('block_templates') . " as bt
ON (b.block_id = bt.block_id AND bt.parent_block_id = ".$this->placeholder_block_id.")
LEFT JOIN " . $this->db->table('blocks') . " as pb
ON (pb.block_id = bt.parent_block_id)
WHERE b.block_id = " . $block_id;
$result = $this->db->query($sql);
$output = [];
foreach ($result->rows as $row){
$output['block_txt_id'] = $row['block_txt_id'];
if( $this->template_id_src != 'default' || versionCompare(VERSION,'1.2.4', '<') ){
$output['controller'] = $row['controller'];
}

if (($this->template_id_src != 'default' || versionCompare(VERSION,'1.2.4', '<')) && $this->placeholder_block_id == $row['parent_block_id']){
$output['controller'] = $row['controller'];
if ( $this->placeholder_block_id == $row['parent_block_id']){
$output['templates']['template'][] = [
'parent_block' => $row['parent_block_txt_id'],
'template_name' => $row['template']
Expand Down

0 comments on commit 23803cb

Please sign in to comment.