Implement saving favicon, mobicon, and default image for domain

This commit is contained in:
Kijin Sung 2017-03-12 22:55:57 +09:00
parent 190e9f039e
commit 4257edf7fa
3 changed files with 42 additions and 86 deletions

View file

@ -456,6 +456,11 @@ class Storage
return false; return false;
} }
if (is_uploaded_file($source))
{
@chmod($destination, 0666 & ~self::getUmask());
}
if (function_exists('opcache_invalidate')) if (function_exists('opcache_invalidate'))
{ {
if (substr($source, -4) === '.php') if (substr($source, -4) === '.php')

View file

@ -542,11 +542,6 @@ class adminAdminController extends admin
Rhymix\Framework\Config::set('use_mobile_view', $vars->use_mobile_view === 'Y'); Rhymix\Framework\Config::set('use_mobile_view', $vars->use_mobile_view === 'Y');
} }
// Favicon and mobicon
$this->_saveFavicon('favicon.ico', $vars->is_delete_favicon);
$this->_saveFavicon('mobicon.png', $vars->is_delete_mobicon);
$this->_saveDefaultImage($vars->is_delete_default_image);
// Save // Save
if (!Rhymix\Framework\Config::save()) if (!Rhymix\Framework\Config::save())
{ {
@ -1105,6 +1100,20 @@ class adminAdminController extends admin
} }
} }
// Save the favicon, mobicon, and default image.
if ($vars->favicon || $vars->delete_favicon)
{
$this->_saveFavicon($args->domain_srl, $vars->favicon, 'favicon.ico', $vars->delete_favicon);
}
if ($vars->mobicon || $vars->delete_mobicon)
{
$this->_saveFavicon($args->domain_srl, $vars->mobicon, 'mobicon.png', $vars->delete_mobicon);
}
if ($vars->default_image || $vars->delete_default_image)
{
$this->_saveDefaultImage($args->domain_srl, $vars->default_image, $vars->delete_default_image);
}
// Update system configuration to match the default domain. // Update system configuration to match the default domain.
if ($domain_info && $domain_srl === '0') if ($domain_info && $domain_srl === '0')
{ {
@ -1221,69 +1230,12 @@ class adminAdminController extends admin
$this->setMessage('success_deleted'); $this->setMessage('success_deleted');
} }
/** protected function _saveFavicon($domain_srl, $uploaded_fileinfo, $iconname, $deleteIcon = false)
* Upload favicon and mobicon.
*/
public function procAdminFaviconUpload()
{
if ($favicon = Context::get('favicon'))
{
$name = 'favicon';
$tmpFileName = $this->_saveFaviconTemp($favicon, 'favicon.ico');
}
elseif ($mobicon = Context::get('mobicon'))
{
$name = 'mobicon';
$tmpFileName = $this->_saveFaviconTemp($mobicon, 'mobicon.png');
}
elseif ($default_image = Context::get('default_image'))
{
$name = 'default_image';
$tmpFileName = $this->_saveFaviconTemp($default_image, 'default_image.png');
}
else
{
$name = $tmpFileName = '';
Context::set('msg', lang('msg_invalid_format'));
}
Context::set('name', $name);
Context::set('tmpFileName', $tmpFileName . '?' . time());
$this->setTemplatePath($this->module_path . 'tpl');
$this->setTemplateFile("favicon_upload.html");
}
protected function _saveFaviconTemp($icon, $iconname)
{
$site_info = Context::get('site_module_info');
$virtual_site = '';
if ($site_info->site_srl)
{
$virtual_site = $site_info->site_srl . '/';
}
$original_filename = $icon['tmp_name'];
$type = $icon['type'];
$relative_filename = 'files/attach/xeicon/'.$virtual_site.'tmp/'.$iconname;
$target_filename = \RX_BASEDIR . $relative_filename;
if (!preg_match('/^(favicon|mobicon|default_image)\.(ico|png|jpe?g)$/', $iconname))
{
Context::set('msg', lang('msg_invalid_format'));
return;
}
Rhymix\Framework\Storage::copy($original_filename, $target_filename, 0666 & ~umask());
return $relative_filename;
}
protected function _saveFavicon($iconname, $deleteIcon = false)
{ {
$image_filepath = 'files/attach/xeicon/'; $image_filepath = 'files/attach/xeicon/';
$site_info = Context::get('site_module_info'); if ($domain_srl)
if ($site_info->site_srl)
{ {
$image_filepath .= $site_info->site_srl . '/'; $image_filepath .= intval($domain_srl) . '/';
} }
if ($deleteIcon) if ($deleteIcon)
@ -1292,21 +1244,20 @@ class adminAdminController extends admin
return; return;
} }
$tmpicon_filepath = $image_filepath . 'tmp/' . $iconname; $original_filename = $uploaded_fileinfo['tmp_name'];
$icon_filepath = $image_filepath . $iconname; $icon_filepath = $image_filepath . $iconname;
if (file_exists(\RX_BASEDIR . $tmpicon_filepath)) if (is_uploaded_file($original_filename))
{ {
Rhymix\Framework\Storage::move(\RX_BASEDIR . $tmpicon_filepath, \RX_BASEDIR . $icon_filepath); Rhymix\Framework\Storage::move($original_filename, \RX_BASEDIR . $icon_filepath);
} }
} }
protected function _saveDefaultImage($deleteIcon = false) protected function _saveDefaultImage($domain_srl, $uploaded_fileinfo, $deleteIcon = false)
{ {
$image_filepath = 'files/attach/xeicon/'; $image_filepath = 'files/attach/xeicon/';
$site_info = Context::get('site_module_info'); if ($domain_srl)
if ($site_info->site_srl)
{ {
$image_filepath .= $site_info->site_srl . '/'; $image_filepath .= intval($domain_srl) . '/';
} }
if ($deleteIcon) if ($deleteIcon)
@ -1320,17 +1271,17 @@ class adminAdminController extends admin
return; return;
} }
$tmpicon_filepath = \RX_BASEDIR . $image_filepath . 'tmp/default_image.png'; $original_filename = $uploaded_fileinfo['tmp_name'];
if (file_exists($tmpicon_filepath)) if (is_uploaded_file($original_filename))
{ {
list($width, $height, $type) = @getimagesize($tmpicon_filepath); list($width, $height, $type) = @getimagesize($original_filename);
switch ($type) switch ($type)
{ {
case 'image/gif': $target_filename = $image_filepath . 'default_image.gif'; break; case 'image/gif': $target_filename = $image_filepath . 'default_image.gif'; break;
case 'image/jpeg': $target_filename = $image_filepath . 'default_image.jpg'; break; case 'image/jpeg': $target_filename = $image_filepath . 'default_image.jpg'; break;
case 'image/png': default: $target_filename = $image_filepath . 'default_image.png'; case 'image/png': default: $target_filename = $image_filepath . 'default_image.png';
} }
Rhymix\Framework\Storage::move($tmpicon_filepath, \RX_BASEDIR . $target_filename); Rhymix\Framework\Storage::move($original_filename, \RX_BASEDIR . $target_filename);
Rhymix\Framework\Storage::writePHPData(\RX_BASEDIR . 'files/attach/xeicon/' . $virtual_site . 'default_image.php', array( Rhymix\Framework\Storage::writePHPData(\RX_BASEDIR . 'files/attach/xeicon/' . $virtual_site . 'default_image.php', array(
'filename' => $target_filename, 'width' => $width, 'height' => $height, 'filename' => $target_filename, 'width' => $width, 'height' => $height,
)); ));

View file

@ -3,7 +3,7 @@
<p>{$XE_VALIDATOR_MESSAGE}</p> <p>{$XE_VALIDATOR_MESSAGE}</p>
</div> </div>
<section class="section"> <section class="section">
<form action="./" method="post" class="x_form-horizontal"> <form action="./" method="post" class="x_form-horizontal" enctype="multipart/form-data">
<input type="hidden" name="module" value="admin" /> <input type="hidden" name="module" value="admin" />
<input type="hidden" name="act" value="procAdminInsertDomain" /> <input type="hidden" name="act" value="procAdminInsertDomain" />
<input type="hidden" name="xe_validator_id" value="modules/admin/tpl/config_domains_edit/1" /> <input type="hidden" name="xe_validator_id" value="modules/admin/tpl/config_domains_edit/1" />
@ -103,10 +103,10 @@
<img src="{$favicon_url ?: (\RX_BASEURL . 'modules/admin/tpl/img/faviconSample.png')}" alt="Favicon" class="fn1" style="width:16px;height:16px"> <img src="{$favicon_url ?: (\RX_BASEURL . 'modules/admin/tpl/img/faviconSample.png')}" alt="Favicon" class="fn1" style="width:16px;height:16px">
<img src="{$favicon_url ?: (\RX_BASEURL . 'modules/admin/tpl/img/faviconSample.png')}" alt="Favicon" class="fn2" style="width:16px;height:16px"> <img src="{$favicon_url ?: (\RX_BASEURL . 'modules/admin/tpl/img/faviconSample.png')}" alt="Favicon" class="fn2" style="width:16px;height:16px">
</p> </p>
<label cond="$favicon_url"> <label for="delete_favicon" cond="$favicon_url">
<input type="checkbox" name="delete_favicon" value="1" /> {$lang->cmd_delete} <input type="checkbox" name="delete_favicon" id="delete_favicon" value="1" /> {$lang->cmd_delete}
</label> </label>
<input type="file" name="favicon" id="favicon" title="Favicon"/> <input type="file" name="favicon" id="favicon" title="Favicon" />
<span class="x_help-block">{$lang->about_use_favicon}</span> <span class="x_help-block">{$lang->about_use_favicon}</span>
</div> </div>
</div> </div>
@ -118,10 +118,10 @@
<img src="{$mobicon_url ?: (\RX_BASEURL . 'modules/admin/tpl/img/mobiconSample.png')}" alt="Mobile Home Icon" width="32" height="32" /> <img src="{$mobicon_url ?: (\RX_BASEURL . 'modules/admin/tpl/img/mobiconSample.png')}" alt="Mobile Home Icon" width="32" height="32" />
<span>Rhymix</span> <span>Rhymix</span>
</p> </p>
<label cond="$mobicon_url"> <label for="delete_mobicon" cond="$mobicon_url">
<input type="checkbox" name="delete_mobicon" value="1" /> {$lang->cmd_delete} <input type="checkbox" name="delete_mobicon" id="delete_mobicon" value="1" /> {$lang->cmd_delete}
</label> </label>
<input type="file" name="mobicon" id="mobicon" title="Mobile Home Icon"/> <input type="file" name="mobicon" id="mobicon" title="Mobile Home Icon" />
<span class="x_help-block">{$lang->detail_use_mobile_icon}</span> <span class="x_help-block">{$lang->detail_use_mobile_icon}</span>
</div> </div>
</div> </div>
@ -132,10 +132,10 @@
<p id="default_imagePreview" cond="$default_image_url"> <p id="default_imagePreview" cond="$default_image_url">
<img src="{$default_image_url}" alt="Default Image" style="width:200px;height:auto" /> <img src="{$default_image_url}" alt="Default Image" style="width:200px;height:auto" />
</p> </p>
<label cond="$default_image_url"> <label for="delete_default_image" cond="$default_image_url">
<input type="checkbox" name="delete_default_image" value="1" /> {$lang->cmd_delete} <input type="checkbox" name="delete_default_image" id="delete_default_image" value="1" /> {$lang->cmd_delete}
</label> </label>
<input type="file" name="default_image" id="default_image" title="Default Image"/> <input type="file" name="default_image" id="default_image" title="Default Image" />
<span class="x_help-block">{$lang->about_site_default_image}</span> <span class="x_help-block">{$lang->about_site_default_image}</span>
</div> </div>
</div> </div>