mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 03:01:43 +09:00
issue 1263, changed a upload process on layout modify
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.3.1@10971 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
78e0330b21
commit
9c72597b95
6 changed files with 190 additions and 39 deletions
|
|
@ -24,6 +24,8 @@
|
|||
<action name="procLayoutAdminCodeUpdate" type="controller" ruleset="codeUpdate" />
|
||||
<action name="procLayoutAdminUserImageUpload" type="controller" ruleset="imageUpload" />
|
||||
<action name="procLayoutAdminUserImageDelete" type="controller" />
|
||||
<action name="procLayoutAdminConfigImageUpload" type="controller" />
|
||||
<action name="procLayoutAdminConfigImageDelete" type="controller" />
|
||||
<action name="procLayoutAdminDelete" type="controller" ruleset="deleteLayout" />
|
||||
|
||||
<action name="procLayoutAdminInsert" type="controller" standalone="true" ruleset="insertLayout" />
|
||||
|
|
|
|||
|
|
@ -148,31 +148,7 @@
|
|||
foreach($layout_info->extra_var as $name => $vars) {
|
||||
if($vars->type!='image') continue;
|
||||
|
||||
$image_obj = $extra_vars->{$name};
|
||||
$extra_vars->{$name} = $layout_info->extra_var->{$name}->value;
|
||||
// Get a variable on a request to delete
|
||||
$del_var = $extra_vars->{"del_".$name};
|
||||
unset($extra_vars->{"del_".$name});
|
||||
// Delete the old file if there is a request to delete or a new file is uploaded
|
||||
if($del_var == 'Y' || $image_obj['tmp_name']) {
|
||||
FileHandler::removeFile($extra_vars->{$name});
|
||||
$extra_vars->{$name} = '';
|
||||
if($del_var == 'Y' && !$image_obj['tmp_name']) continue;
|
||||
}
|
||||
// Ignore if the file is not successfully uploaded
|
||||
if(!$image_obj['tmp_name'] || !is_uploaded_file($image_obj['tmp_name'])) continue;
|
||||
// Ignore if the file is not an image (swf the paths ~)
|
||||
if(!preg_match("/\.(jpg|jpeg|gif|png|swf)$/i", $image_obj['name'])) continue;
|
||||
// Upload the file to a path
|
||||
$path = sprintf("./files/attach/images/%s/", $args->layout_srl);
|
||||
// Create a directory
|
||||
if(!FileHandler::makeDir($path)) continue;
|
||||
|
||||
$filename = $path.$image_obj['name'];
|
||||
// Move the file
|
||||
if(!move_uploaded_file($image_obj['tmp_name'], $filename)) continue;
|
||||
|
||||
$extra_vars->{$name} = $filename;
|
||||
$extra_vars->{$name} = $vars->value;
|
||||
}
|
||||
}
|
||||
// Save header script into "config" of layout module
|
||||
|
|
@ -760,5 +736,110 @@
|
|||
// Remove uploaded file
|
||||
FileHandler::removeFile($source_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload config image
|
||||
*/
|
||||
function procLayoutAdminConfigImageUpload()
|
||||
{
|
||||
$layoutSrl = Context::get('layout_srl');
|
||||
$name = Context::get('name');
|
||||
$img = Context::get('img');
|
||||
|
||||
$this->setTemplatePath($this->module_path.'tpl');
|
||||
$this->setTemplateFile("after_upload_config_image.html");
|
||||
|
||||
if(!$img['tmp_name'] || !is_uploaded_file($img['tmp_name']))
|
||||
{
|
||||
Context::set('msg', Context::getLang('upload failed'));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!preg_match('/\.(jpg|jpeg|gif|png|swf)$/i', $img['name']))
|
||||
{
|
||||
Context::set('msg', Context::getLang('not allowed extension'));
|
||||
return;
|
||||
}
|
||||
|
||||
$path = sprintf('./files/attach/images/%s/', $layoutSrl);
|
||||
if(!FileHandler::makeDir($path))
|
||||
{
|
||||
Context::set('msg', Context::getLang('make directory failed'));
|
||||
return;
|
||||
}
|
||||
|
||||
$ext = substr(strrchr($img['name'],'.'),1);
|
||||
$_fileName = md5(crypt(rand(1000000,900000), rand(0,100))).'.'.$ext;
|
||||
$fileName = $path . $_fileName;
|
||||
|
||||
if(!move_uploaded_file($img['tmp_name'], $fileName))
|
||||
{
|
||||
Context::set('msg', Context::getLang('move file failed'));
|
||||
return;
|
||||
}
|
||||
|
||||
$oModel = &getModel('layout');
|
||||
$layoutInfo = $oModel->getLayout($layoutSrl);
|
||||
|
||||
if($layoutInfo->extra_var_count)
|
||||
{
|
||||
foreach($layoutInfo->extra_var as $varId => $val)
|
||||
{
|
||||
$newLayoutInfo->{$varId} = $val->value;
|
||||
}
|
||||
}
|
||||
|
||||
$newLayoutInfo->{$name} = $fileName;
|
||||
|
||||
$args->layout_srl = $layoutSrl;
|
||||
$args->extra_vars = serialize($newLayoutInfo);
|
||||
$output = $this->updateLayout($args);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
FileHandler::removeFile($fileName);
|
||||
Context::set('msg', Context::getLang($output->getMessage()));
|
||||
return;
|
||||
}
|
||||
|
||||
Context::set('name', $name);
|
||||
Context::set('fileName', $fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete config image
|
||||
*/
|
||||
function procLayoutAdminConfigImageDelete()
|
||||
{
|
||||
$layoutSrl = Context::get('layout_srl');
|
||||
$name = Context::get('name');
|
||||
|
||||
$this->setTemplatePath($this->module_path.'tpl');
|
||||
$this->setTemplateFile("after_delete_config_image.html");
|
||||
|
||||
$oModel = &getModel('layout');
|
||||
$layoutInfo = $oModel->getLayout($layoutSrl);
|
||||
|
||||
if($layoutInfo->extra_var_count)
|
||||
{
|
||||
foreach($layoutInfo->extra_var as $varId => $val)
|
||||
{
|
||||
$newLayoutInfo->{$varId} = $val->value;
|
||||
}
|
||||
}
|
||||
|
||||
unset($newLayoutInfo->{$name});
|
||||
|
||||
$args->layout_srl = $layoutSrl;
|
||||
$args->extra_vars = serialize($newLayoutInfo);
|
||||
$output = $this->updateLayout($args);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
Context::set('msg', Context::getLang($output->getMessage()));
|
||||
return $output;
|
||||
}
|
||||
|
||||
FileHandler::removeFile($layoutInfo->extra_var->{$name}->value);
|
||||
Context::set('name', $name);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
7
modules/layout/tpl/after_delete_config_image.html
Normal file
7
modules/layout/tpl/after_delete_config_image.html
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<script type="text/javascript">
|
||||
<!--@if($msg)-->
|
||||
alert('{$msg}');
|
||||
<!--@else-->
|
||||
parent.afterDeleteConfigImage('{$name}');
|
||||
<!--@end-->
|
||||
</script>
|
||||
7
modules/layout/tpl/after_upload_config_image.html
Normal file
7
modules/layout/tpl/after_upload_config_image.html
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<script type="text/javascript">
|
||||
<!--@if($msg)-->
|
||||
alert('{$msg}');
|
||||
<!--@else-->
|
||||
parent.afterUploadConfigImage('{$name}', '{$fileName}');
|
||||
<!--@end-->
|
||||
</script>
|
||||
32
modules/layout/tpl/js/layout_modify.js
Normal file
32
modules/layout/tpl/js/layout_modify.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
function doSubmitConfig()
|
||||
{
|
||||
var $forms = jQuery('#layout_config').find('input[name][type="hidden"], input[name][type="text"], input[name][type="checkbox"]:checked, select[name], textarea[name]');
|
||||
var $configForm = jQuery('#config_form');
|
||||
var $container = $configForm.children('div');
|
||||
$container.empty();
|
||||
|
||||
$forms.each(function($)
|
||||
{
|
||||
var $this = jQuery(this);
|
||||
|
||||
if($this.parents('.imageUpload').length) return;
|
||||
|
||||
var $input = jQuery('<input>').attr('type', 'hidden').attr('name', $this.attr('name')).val($this.val());
|
||||
$container.append($input);
|
||||
});
|
||||
|
||||
$configForm.submit();
|
||||
}
|
||||
|
||||
function afterUploadConfigImage(name, fileName)
|
||||
{
|
||||
jQuery('#preview_' + name + ' img').attr('src', fileName);
|
||||
jQuery('#preview_' + name).show();
|
||||
jQuery('#file_' + name).val('');
|
||||
}
|
||||
|
||||
function afterDeleteConfigImage(name)
|
||||
{
|
||||
jQuery('#preview_' + name + ' img').removeAttr('src');
|
||||
jQuery('#preview_' + name).hide();
|
||||
}
|
||||
|
|
@ -1,16 +1,21 @@
|
|||
<include target="header.html" />
|
||||
<load target="js/layout_modify.js" />
|
||||
|
||||
<h2 cond="$act == 'dispLayoutAdminModify'" class="h2">{$selected_layout->layout_title}</h2>
|
||||
<h2 cond="$act == 'dispLayoutAdminInsert'" class="h2">{$selected_layout->title}</h2>
|
||||
|
||||
<form ruleset="updateLayout"|cond="$act == 'dispLayoutAdminModify'" ruleset="insertLayout"|cond="$act == 'dispLayoutAdminInsert'" action="./" class="form" enctype="multipart/form-data" method="post">
|
||||
<input type="hidden" name="module" value="layout" />
|
||||
<input type="hidden" name="act" value="procLayoutAdminUpdate"|cond="$act == 'dispLayoutAdminModify'" value="procLayoutAdminInsert"|cond="$act == 'dispLayoutAdminInsert'" />
|
||||
<input type="hidden" name="layout_srl" value="{$layout_srl}" />
|
||||
<input type="hidden" name="layout" value="{$selected_layout->layout}" />
|
||||
<input type="hidden" name="_layout_type" value="{$selected_layout->layout_type}" />
|
||||
<input type="hidden" name="success_return_url" value="{getUrl('act', 'dispLayoutAdminInstanceList')}" />
|
||||
<form id="config_form" ruleset="updateLayout"|cond="$act == 'dispLayoutAdminModify'" ruleset="insertLayout"|cond="$act == 'dispLayoutAdminInsert'" action="./" class="form" enctype="multipart/form-data" method="post">
|
||||
<input type="hidden" name="module" value="layout" />
|
||||
<input type="hidden" name="act" value="procLayoutAdminUpdate"|cond="$act == 'dispLayoutAdminModify'" value="procLayoutAdminInsert"|cond="$act == 'dispLayoutAdminInsert'" />
|
||||
<input type="hidden" name="layout_srl" value="{$layout_srl}" />
|
||||
<input type="hidden" name="layout" value="{$selected_layout->layout}" />
|
||||
<input type="hidden" name="_layout_type" value="{$selected_layout->layout_type}" />
|
||||
<input type="hidden" name="success_return_url" value="{getUrl('act', 'dispLayoutAdminInstanceList')}" />
|
||||
<!--// For submit config. Do not delete this division. -->
|
||||
<div></div>
|
||||
</form>
|
||||
|
||||
<div id="layout_config" class="form">
|
||||
<ul>
|
||||
<li>
|
||||
<p class="q">{$lang->layout}</p>
|
||||
|
|
@ -44,7 +49,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<block loop="$selected_layout->extra_var => $name, $var">
|
||||
<block cond="$act == 'dispLayoutAdminModify'" loop="$selected_layout->extra_var => $name, $var">
|
||||
<block cond="!$not_first && !$var->group"><ul></block>
|
||||
<block cond="$group != $var->group">
|
||||
<block cond="$not_first"></ul></block>
|
||||
|
|
@ -71,10 +76,26 @@
|
|||
</div>
|
||||
|
||||
<block cond="$var->type == 'image'">
|
||||
<block cond="$var->value">
|
||||
<p><img src="../../../{$var->value}" alt="" /> <input type="checkbox" name="del_{$name}" value="Y" id="del_{$name}" /><label for="del_{$name}">{$lang->cmd_delete}</label></p>
|
||||
</block>
|
||||
<p><input type="file" name="{$name}" value="" /></p>
|
||||
<div id="preview_{$name}" style="display:none;"|cond="!$var->value">
|
||||
<img src="../../../{$var->value}"|cond="$var->value" alt="" style="max-width: 250px"/>
|
||||
<form action="./" method="post" target="hiddenIframe" class="imageUpload" style="display:inline;">
|
||||
<input type="hidden" name="module" value="layout" />
|
||||
<input type="hidden" name="act" value="procLayoutAdminConfigImageDelete" />
|
||||
<input type="hidden" name="layout_srl" value="{$layout_srl}" />
|
||||
<input type="hidden" name="name" value="{$name}" />
|
||||
<input type="submit" value="{$lang->cmd_delete}" />
|
||||
</form>
|
||||
</div>
|
||||
<form action="./" enctype="multipart/form-data" method="post" target="hiddenIframe" class="imageUpload">
|
||||
<input type="hidden" name="module" value="layout" />
|
||||
<input type="hidden" name="act" value="procLayoutAdminConfigImageUpload" />
|
||||
<input type="hidden" name="layout_srl" value="{$layout_srl}" />
|
||||
<input type="hidden" name="name" value="{$name}" />
|
||||
<p>
|
||||
<input type="file" name="img" id="file_{$name}" value="" />
|
||||
<input type="submit" value="{$lang->cmd_submit}" />
|
||||
</p>
|
||||
</form>
|
||||
</block>
|
||||
|
||||
<select cond="$var->type == 'select'" name="{$name}">
|
||||
|
|
@ -149,9 +170,10 @@
|
|||
|
||||
<div class="btnArea">
|
||||
<span class="btn medium">
|
||||
<input type="submit" value="{$lang->cmd_insert}"|cond="$act == 'dispLayoutAdminInsert'" value="{$lang->cmd_save}"|cond="$act == 'dispLayoutAdminModify'" />
|
||||
<input type="submit" value="{$lang->cmd_insert}"|cond="$act == 'dispLayoutAdminInsert'" value="{$lang->cmd_save}"|cond="$act == 'dispLayoutAdminModify'" onclick="doSubmitConfig()"/>
|
||||
</span>
|
||||
</div>
|
||||
<include target="include.multilang.html" />
|
||||
<include target="include.multilang.textarea.html" />
|
||||
</form>
|
||||
</div>
|
||||
<iframe name="hiddenIframe" src="about:blank" width="0" height="0" frameborder="0"></iframe>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue