Skip to content

Commit 434a386

Browse files
committed
Fixed required fallback image filename
1 parent b2e1fa8 commit 434a386

2 files changed

Lines changed: 53 additions & 47 deletions

File tree

inc/widgets/widgets/_coll_logo.widget.php

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,11 @@ function get_param_definitions( $params )
111111
'label' => T_('Fallback image filename'),
112112
'note' => T_('If no file was selected. Relative to the root of the selected source.'),
113113
'defaultvalue' => 'logo.png',
114-
'valid_pattern' => array( 'pattern'=>'~^[a-z0-9_\-/][a-z0-9_.\-/]*$~i',
115-
'error'=>T_('Invalid filename.') ),
114+
'valid_pattern' => array( 'pattern'=>'~^$|^[a-z0-9_\-/][a-z0-9_.\-/]*$~i',
115+
'error'=>T_('Invalid filename.') ),
116+
// the following is necessary to catch user input value of "<". Otherwise, "<" and succeeding characters
117+
// will translate to an empty string and pass the regex pattern below
118+
'type' => 'html_input',
116119
),
117120
'size_begin_line' => array(
118121
'type' => 'begin_line',
@@ -214,8 +217,21 @@ function display( $params )
214217
$File = & $FileCache->get_by_ID( $file_ID, false );
215218
}
216219

217-
if( ( $check_file == 'check' || $check_file === '1' ) && ( empty( $File ) || ! file_exists( $File->get_full_path() ) ) && ! file_exists( $image_path.$this->disp_params['logo_file'] ) )
218-
{ // Logo file doesn't exist, Exit here because widget setting requires this:
220+
if( ! empty( $File ) && file_exists( $File->get_full_path() ) )
221+
{
222+
$image_url = $File->get_url();
223+
}
224+
elseif( ! empty( $this->disp_params['logo_file'] ) && ( $check_file == 'none' || file_exists( $image_path.$this->disp_params['logo_file'] ) ) )
225+
{
226+
$image_url .= $this->disp_params['logo_file'];
227+
}
228+
else
229+
{
230+
$image_url = '';
231+
}
232+
233+
if( $check_file != 'title' && empty( $image_url ) )
234+
{
219235
return true;
220236
}
221237

@@ -237,12 +253,16 @@ function display( $params )
237253
$image_attrs .= ' height="'.intval( $this->disp_params['height'] ).'"';
238254
}
239255

240-
if( ! empty( $File ) )
256+
if( $check_file == 'title' && empty( $image_url ) )
257+
{ // Logo file doesn't exist, Display a collection title because widget setting requires this:
258+
$title .= $Blog->get( 'name' );
259+
}
260+
else
241261
{
242262
// Initialize image attributes:
243263
$image_attrs = array(
244-
'src' => $File->get_url(),
245-
'alt' => empty( $this->disp_params['alt'] ) ? $Blog->dget( 'name', 'htmlattr' ) : $this->disp_params['alt']
264+
'src' => $image_url,
265+
'alt' => empty( $this->disp_params['alt'] ) ? $Blog->dget( 'name', 'htmlattr' ) : $this->disp_params['alt'],
246266
);
247267

248268
// Image width:
@@ -254,29 +274,6 @@ function display( $params )
254274

255275
$title .= '<img'.get_field_attribs_as_string( $image_attrs ).' />';
256276
}
257-
else
258-
{
259-
if( $check_file == 'title' && ! file_exists( $image_path.$this->disp_params['logo_file'] ) )
260-
{ // Logo file doesn't exist, Display a collection title because widget setting requires this:
261-
$title .= $Blog->get( 'name' );
262-
}
263-
else
264-
{
265-
// Initialize image attributes:
266-
$image_attrs = array(
267-
'src' => $image_url.$this->disp_params['logo_file'],
268-
'alt' => empty( $this->disp_params['alt'] ) ? $Blog->dget( 'name', 'htmlattr' ) : $this->disp_params['alt'],
269-
);
270-
// Image width:
271-
$image_attrs['style'] = 'width:'.( empty( $this->disp_params['width'] ) ? 'auto' : format_to_output( $this->disp_params['width'], 'htmlattr' ) ).';';
272-
// Image height:
273-
$image_attrs['style'] .= 'height:'.( empty( $this->disp_params['height'] ) ? 'auto' : format_to_output( $this->disp_params['height'], 'htmlattr' ) ).';';
274-
// If no unit is specified in a size, consider the unit to be px:
275-
$image_attrs['style'] = preg_replace( '/(\d+);/', '$1px;', $image_attrs['style'] );
276-
277-
$title .= '<img'.get_field_attribs_as_string( $image_attrs ).' />';
278-
}
279-
}
280277

281278
$title .= '</a>';
282279

inc/widgets/widgets/_image.widget.php

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,11 @@ function get_param_definitions( $params )
111111
'label' => T_('Fallback image filename'),
112112
'note' => T_('If no file was selected. Relative to the root of the selected source.'),
113113
'defaultvalue' => 'logo.png',
114-
'valid_pattern' => array( 'pattern'=>'~^[a-z0-9_\-/][a-z0-9_.\-/]*$~i',
115-
'error'=>T_('Invalid filename.') ),
114+
'valid_pattern' => array( 'pattern'=>'~^$|^[a-z0-9_\-/][a-z0-9_.\-/]*$~i',
115+
'error'=>T_('Invalid filename.') ),
116+
// the following is necessary to catch user input value of "<". Otherwise, "<" and succeeding characters
117+
// will translate to an empty string and pass the regex pattern below
118+
'type' => 'html_input',
116119
),
117120
'size_begin_line' => array(
118121
'type' => 'begin_line',
@@ -207,7 +210,21 @@ function display( $params )
207210
break;
208211
}
209212

210-
if( $this->disp_params['check_file'] && ( empty( $File ) || ! file_exists( $File->get_full_path() ) ) && ! file_exists( $image_path.$this->disp_params['image_file'] ) )
213+
if( ! empty( $File ) && file_exists( $File->get_full_path() ) )
214+
{
215+
$image_url = $File->get_url();
216+
}
217+
elseif( ! empty( $this->disp_params['image_file'] ) && file_exists( $image_path.$this->disp_params['image_file'] ) )
218+
{
219+
$image_url .= $this->disp_params['image_file'];
220+
}
221+
else
222+
{
223+
$image_url = '';
224+
}
225+
226+
227+
if( $this->disp_params['check_file'] && empty( $image_url ) )
211228
{ // Logo file doesn't exist, Exit here because of widget setting requires this
212229
return true;
213230
}
@@ -216,20 +233,12 @@ function display( $params )
216233

217234
echo $this->disp_params['block_start'];
218235

219-
if( ! empty( $File ) )
220-
{
221-
$image_attrs = array(
222-
'src' => $File->get_url(),
223-
'alt' => $this->disp_params['alt'],
224-
);
225-
}
226-
else
227-
{
228-
$image_attrs = array(
229-
'src' => $image_url.$this->disp_params['image_file'],
230-
'alt' => $this->disp_params['alt'],
231-
);
232-
}
236+
237+
$image_attrs = array(
238+
'src' => $image_url,
239+
'alt' => $this->disp_params['alt'],
240+
);
241+
233242
// Initialize image attributes:
234243
$image_attrs['style'] = 'width:'.( empty( $this->disp_params['width'] ) ? 'auto' : format_to_output( $this->disp_params['width'], 'htmlattr' ) ).';';
235244
// Image height:

0 commit comments

Comments
 (0)