Changeset 26298


Ignore:
Timestamp:
Dec 28, 2013, 6:08:42 PM (10 years ago)
Author:
mistic100
Message:

update for 2.6 + better calculation + option to force ratio
TODO: issue with PNG (unable to generate thumbnail with IM)

Location:
extensions/header_manager
Files:
1 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • extensions/header_manager/admin.php

    r19181 r26298  
    11<?php
    2 if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
     2defined('HEADER_MANAGER_PATH') or die('Hacking attempt!');
    33
    44global $template, $page;
     
    3131
    3232$template->assign_var_from_handle('ADMIN_CONTENT', 'header_manager');
    33 
    34 ?>
  • extensions/header_manager/admin/add.php

    r24010 r26298  
    11<?php
    2 if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
     2defined('HEADER_MANAGER_PATH') or die('Hacking attempt!');
    33
    44// cancel crop
     
    1515 
    1616  $banner = get_banner($_POST['picture_file']);
     17 
    1718  $img = new banner_image($banner['PATH']);
    18   $crop = hm_get_crop_display(array('width'=>$img->get_width(), 'height'=>$img->get_height()));
    19  
    2019  $img->banner_resize(
    2120    $banner['PATH'],
    22     $_POST['x'],
    23     $_POST['y'],
    24     $_POST['x2'],
    25     $_POST['y2'],
    26     $crop['display_width'],
    27     $crop['display_height']
     21    $_POST
    2822    );
    2923  $img->destroy();
    3024 
    31   $img = new banner_image($banner['PATH']);
     25  $img = new pwg_image($banner['PATH']);
    3226  $img->pwg_resize(
    3327    $banner['THUMB'],
     
    6761  if (!pwg_db_num_rows($result))
    6862  {
    69     array_push($page['errors'], l10n('Unknown picture id'));
     63    $page['errors'][] = l10n('Unknown picture id');
    7064  }
    7165  else
     
    8680  if ($file['error'] > 0)
    8781  {
    88     array_push($page['errors'], l10n('Unknown upload error'));
     82    $page['errors'][] = l10n('Unknown upload error');
    8983  }
    90   else if ( !in_array($file['type'], array('image/jpeg','image/png','image/gif')) )
     84  else if (!in_array($file['type'], array('image/jpeg','image/png','image/gif')))
    9185  {
    92     array_push($page['errors'], l10n('Incorrect file type,').' '.sprintf(l10n('Allowed file types: %s.'), 'jpg, png, gif'));
     86    $page['errors'][] = l10n('Incorrect file type,').' '.l10n('Allowed file types: %s.', 'jpg, png, gif');
    9387  }
    9488 
     
    117111  $conf['header_manager']['height'] = intval($_POST['height']);
    118112  conf_update_param('header_manager', serialize($conf['header_manager']));
    119    
     113
    120114  $picture['banner_src'] = HEADER_MANAGER_DIR . $picture['filename'];
    121115 
     
    149143}
    150144
    151 $template->assign('F_ACTION', HEADER_MANAGER_ADMIN . '-add' .(!empty($_GET['redirect']) ? '&amp;redirect='.urlencode($_GET['redirect']) : ''));
     145$template->assign('F_ACTION', HEADER_MANAGER_ADMIN . '-add' .
     146  (!empty($_GET['redirect']) ? '&amp;redirect='.urlencode($_GET['redirect']) : ''));
    152147
    153 $template->set_filename('header_manager', dirname(__FILE__).'/template/add.tpl');
    154 
    155 ?>
     148$template->set_filename('header_manager', realpath(HEADER_MANAGER_PATH . 'admin/template/add.tpl'));
  • extensions/header_manager/admin/album.php

    r24010 r26298  
    11<?php
    2 // +-----------------------------------------------------------------------+
    3 // | Piwigo - a PHP based photo gallery                                    |
    4 // +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
    6 // | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    7 // | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
    8 // +-----------------------------------------------------------------------+
    9 // | This program is free software; you can redistribute it and/or modify  |
    10 // | it under the terms of the GNU General Public License as published by  |
    11 // | the Free Software Foundation                                          |
    12 // |                                                                       |
    13 // | This program is distributed in the hope that it will be useful, but   |
    14 // | WITHOUT ANY WARRANTY; without even the implied warranty of            |
    15 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
    16 // | General Public License for more details.                              |
    17 // |                                                                       |
    18 // | You should have received a copy of the GNU General Public License     |
    19 // | along with this program; if not, write to the Free Software           |
    20 // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
    21 // | USA.                                                                  |
    22 // +-----------------------------------------------------------------------+
    23 
    24 if(!defined("PHPWG_ROOT_PATH")) die ("Hacking attempt!");
     2defined('HEADER_MANAGER_PATH') or die ("Hacking attempt!");
    253
    264// +-----------------------------------------------------------------------+
     
    4725}
    4826
     27$cat_id = $_GET['cat_id'];
     28
     29
    4930// +-----------------------------------------------------------------------+
    5031// | Tabs                                                                  |
     
    6041
    6142
    62 $cat_id = $_GET['cat_id'];
    63 
    64 
    6543// +-----------------------------------------------------------------------+
    6644// | Save Form                                                             |
     
    6846if (isset($_POST['save_banner']))
    6947{
    70   if ( !isset($_POST['image']) or $_POST['image'] == 'default')
     48  if (!isset($_POST['image']) or $_POST['image'] == 'default')
    7149  {
    7250    $query = '
     
    136114));
    137115
    138 $template->set_filename('header_manager', dirname(__FILE__).'/template/album.tpl');
    139 
    140 ?>
     116$template->set_filename('header_manager', realpath(HEADER_MANAGER_PATH . 'admin/template/album.tpl'));
  • extensions/header_manager/admin/config.php

    r20169 r26298  
    11<?php
    2 if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
     2defined('HEADER_MANAGER_PATH') or die('Hacking attempt!');
    33
    44// change banner to last uploaded
    5 if ( pwg_get_session_var('added_banner')!==null and $conf['header_manager']['image']!='random' )
     5if (pwg_get_session_var('added_banner')!==null and $conf['header_manager']['image']!='random')
    66{
    77  $conf['header_manager']['image'] = pwg_get_session_var('added_banner');
     
    2929  conf_update_param('header_manager', serialize($conf['header_manager']));
    3030 
    31   array_push($page['infos'], l10n('Information data registered in database'));
     31  $page['infos'][] = l10n('Information data registered in database');
    3232}
    3333
     
    3737{
    3838  $banner = get_banner($_GET['delete_banner']);
    39   if ( $banner !== false or @unlink($banner['PATH']) )
     39  if ($banner !== false or @unlink($banner['PATH']))
    4040  {
    4141    @unlink($banner['THUMB']);
     
    5353    pwg_query($query);
    5454   
    55     array_push($page['infos'], l10n('Banner deleted'));
     55    $page['infos'][] = l10n('Banner deleted');
    5656  }
    5757  else
    5858  {
    59     array_push($page['warnings'], l10n('File/directory read error').' : ' . HEADER_MANAGER_DIR . $_GET['delete_banner']);
     59    $page['warnings'][] = l10n('File/directory read error').' : ' . HEADER_MANAGER_DIR . $_GET['delete_banner'];
    6060  }
    6161}
     
    6363if (isset($_GET['delete_cat_banner']))
    6464{
    65     $query = '
     65  $query = '
    6666DELETE FROM '.HEADER_MANAGER_TABLE.'
    6767  WHERE category_id = "'.$_GET['delete_cat_banner'].'"
    6868;';
    69     pwg_query($query);
     69  pwg_query($query);
    7070}
    7171
     
    8585  ORDER BY global_rank ASC
    8686;';
    87 $categories = hash_from_query($query, 'id');
     87$categories = query2array($query, 'id');
    8888
    8989foreach ($categories as $category)
     
    9191  $tpl_cat =
    9292    array(
    93       'NAME'        => get_cat_display_name_from_id($category['id'], HEADER_MANAGER_ADMIN.'-album&amp;cat_id='),
    94       'ID'          => $category['id'],
    95       'IMAGE'       => get_filename_wo_extension($category['image']),
    96       'DEEP'        => $category['deep'],
    97       'U_DELETE'    => HEADER_MANAGER_ADMIN.'-config&amp;delete_cat_banner='.$category['id'],
     93      'NAME'     => get_cat_display_name_from_id($category['id'], HEADER_MANAGER_ADMIN.'-album&amp;cat_id='),
     94      'ID'       => $category['id'],
     95      'IMAGE'    => get_filename_wo_extension($category['image']),
     96      'DEEP'     => $category['deep'],
     97      'U_DELETE' => HEADER_MANAGER_ADMIN.'-config&amp;delete_cat_banner='.$category['id'],
    9898    );
    9999 
     
    103103
    104104// config template
    105 if ( empty($conf['header_manager']['image']) or get_banner($conf['header_manager']['image']) === false )
     105if (empty($conf['header_manager']['image']) or get_banner($conf['header_manager']['image']) === false)
    106106{
    107107  $conf['header_manager']['image'] = 'random';
     
    116116  ));
    117117
    118 $template->set_filename('header_manager', dirname(__FILE__).'/template/config.tpl');
    119 
    120 ?>
     118$template->set_filename('header_manager', realpath(HEADER_MANAGER_PATH . 'admin/template/config.tpl'));
  • extensions/header_manager/admin/template/add.tpl

    r24010 r26298  
    1 {combine_css path=$HEADER_MANAGER_PATH|@cat:"admin/template/style.css"}
     1{combine_css path=$HEADER_MANAGER_PATH|cat:'admin/template/style.css'}
    22
    33<div class="titrePage">
     
    1010
    1111{footer_script require="jquery"}
    12 var jcrop_api;
     12(function(){
     13  var jcrop_api;
    1314
    14 jQuery("#jcrop").Jcrop({ldelim}
    15     boxWidth: {$crop.display_width},
    16     boxHeight: {$crop.display_height},
     15  jQuery("#jcrop").Jcrop({
     16    boxWidth: {$crop.box_width},
     17    boxHeight: {$crop.box_height},
     18    trueSize: [{$picture.width}, {$picture.height}],
     19    aspectRatio: {$crop.real_width}/{$crop.real_height},
    1720    setSelect: [{$crop.l}, {$crop.t}, {$crop.r}, {$crop.b}],
    18     onChange: jOnChange,
    19     onRelease: jOnRelease
    20         },
    21   function(){ldelim}
     21    onChange: function(sel) {
     22      jQuery("input[name='x']").val(Math.round(sel.x));
     23      jQuery("input[name='y']").val(Math.round(sel.y));
     24      jQuery("input[name='x2']").val(Math.round(sel.x2));
     25      jQuery("input[name='y2']").val(Math.round(sel.y2));
     26     
     27      var final_width = Math.min(Math.round(sel.x2-sel.x), {$crop.desired_width}),
     28          final_height = Math.round((sel.y2-sel.y)*final_width/(sel.x2-sel.x));
     29     
     30      jQuery("#width").html(final_width);
     31      jQuery("#height").html(final_height);
     32    },
     33    onRelease: function() {
     34      jcrop_api.setSelect([{$crop.l}, {$crop.t}, {$crop.r}, {$crop.b}]);
     35    }
     36  },
     37  function() {
    2238    jcrop_api = this;
    2339  });
    2440 
    25 function jOnChange(sel) {ldelim}
    26         jQuery("input[name='x']").val(sel.x);
    27         jQuery("input[name='y']").val(sel.y);
    28         jQuery("input[name='x2']").val(sel.x2);
    29         jQuery("input[name='y2']").val(sel.y2);
    30  
    31   jQuery("#width").html(sel.x2-sel.x);
    32   jQuery("#height").html(sel.y2-sel.y);
    33 }
    34  
    35 function jOnRelease() {ldelim}
    36         jcrop_api.setSelect([{$crop.l}, {$crop.t}, {$crop.r}, {$crop.b}]);
    37 }
     41  jQuery('input[name="keep_ratio"]').on('change', function() {
     42    jcrop_api.setOptions({
     43      aspectRatio: jQuery(this).prop('checked') ? {$crop.real_width}/{$crop.real_height} : 0
     44    });
     45    if (!jQuery(this).prop('checked')) {
     46      jcrop_api.release();
     47    }
     48  });
     49}());
    3850{/footer_script}
    3951
    4052<form method="post" action="{$F_ACTION}">
    4153<fieldset>
    42   <legend>{'Crop banner image'|@translate}</legend>
    43   {'Choose the part of the image you want to use as your header.'|@translate}<br>
     54  <legend>{'Crop banner image'|translate}</legend>
     55  {'Choose the part of the image you want to use as your header.'|translate}<br>
    4456 
    45   <img id="jcrop" src="{$picture.banner_src}" width="{$crop.display_width}" height="{$crop.display_height}">
     57  <img id="jcrop" src="{$picture.banner_src}">
    4658 
    4759  <ul>
    48     <li><b>{'Width'|@translate}:</b> <span id="width"></span>px</li>
    49     <li><b>{'Height'|@translate}:</b> <span id="height"></span>px</li>
     60    <li><b>{'Width'|translate}:</b> <span id="width"></span>px</li>
     61    <li><b>{'Height'|translate}:</b> <span id="height"></span>px</li>
     62    <li><label><input type="checkbox" name="keep_ratio" checked> {'Respect %s aspect ratio'|translate:($crop.desired_width|cat:'/'|cat:$crop.desired_height)}</label></li>
    5063  </ul>
    5164 
     
    5669  <input type="hidden" name="picture_file" value="{$picture.filename}">
    5770 
    58   <input type="submit" name="submit_crop" value="{'Submit'|@translate}">
    59   <input type="submit" name="cancel_crop" value="{'Cancel'|@translate}">
     71  <input type="submit" name="submit_crop" value="{'Submit'|translate}">
     72  <input type="submit" name="cancel_crop" value="{'Cancel'|translate}">
    6073</fieldset>
    6174</form>
    6275
    6376{else}
    64 {footer_script require="jquery"}{literal}
     77{footer_script require="jquery"}
    6578jQuery(".showInfo").tipTip({
    6679  delay: 0,
     
    7588    $("input[name='upload_gallery_image']").click();
    7689    return false;
    77   } else {
     90  }
     91  else {
    7892    return true;
    7993  }
    8094});
    81 {/literal}{/footer_script}
     95{/footer_script}
    8296
    8397<form method="post" action="{$F_ACTION}" ENCTYPE="multipart/form-data">
    8498  <fieldset>
    85     <legend>{'Default banner size'|@translate}</legend>
     99    <legend>{'Default banner size'|translate}</legend>
    86100   
    87101    <label>
    88       {'Width'|@translate}:
     102      {'Width'|translate}:
    89103      <input type="text" name="width" size="4" value="{$BANNER_WIDTH}"> px
    90104    </label>
     
    92106    <br>
    93107    <label>
    94       {'Height'|@translate}:
     108      {'Height'|translate}:
    95109      <input type="text" name="height" size="4" value="{$BANNER_HEIGHT}"> px
    96110    </label>
    97111    <br>
    98112    <br>
    99     <i>{'For MontBlancXL and BlancMontXL, advised size is 900&times;190.'|@translate}</i>
     113    <i>{'For MontBlancXL and BlancMontXL, advised size is 900&times;190.'|translate}</i>
    100114  </fieldset>
    101115 
    102116  <fieldset>
    103     <legend>{'Select an image'|@translate}</legend>
    104     {'You can upload a custom header image or select one from your gallery. On the next screen you will be able to crop the image.'|@translate}
     117    <legend>{'Select an image'|translate}</legend>
     118    {'You can upload a custom header image or select one from your gallery. On the next screen you will be able to crop the image.'|translate}
    105119    <br><br>
    106120   
    107     <b>{'Choose an image from your computer'|@translate}</b>
     121    <b>{'Choose an image from your computer'|translate}</b>
    108122    <blockquote>
    109       {'Maximum file size: %sB.'|@translate|@sprintf:$upload_max_filesize_shorthand} {'Allowed file types: %s.'|@translate|@sprintf:'jpg, png, gif'}<br>
     123      {'Maximum file size: %sB.'|translate:$upload_max_filesize_shorthand} {'Allowed file types: %s.'|translate:'jpg, png, gif'}<br>
    110124      <input type="file" name="new_image">
    111125      <input type="hidden" name="MAX_FILE_SIZE" value="{$upload_max_filesize}">
    112       <input type="submit" name="upload_new_image" value="{'Upload'|@translate}" class="submit">
     126      <input type="submit" name="upload_new_image" value="{'Upload'|translate}" class="submit">
    113127    </blockquote>
    114128   
    115     <b>{'or choose a picture from the gallery'|@translate}</b>
     129    <b>{'or choose a picture from the gallery'|translate}</b>
    116130    <blockquote>
    117       {'Picture id.'|@translate} <a class="icon-info-circled-1 showInfo" title="{'The numeric identifier can be found on the picture edition page, near the thumbnail.'|@translate}"></a>
     131      {'Picture id.'|translate} <a class="icon-info-circled-1 showInfo" title="{'The numeric identifier can be found on the picture edition page, near the thumbnail.'|translate}"></a>
    118132      <input type="text" name="picture_id" size="5">
    119       <input type="submit" name="upload_gallery_image" value="{'Use'|@translate}" class="submit">
     133      <input type="submit" name="upload_gallery_image" value="{'Use'|translate}" class="submit">
    120134    </blockquote>
    121135  </fieldset>
  • extensions/header_manager/admin/template/album.tpl

    r24010 r26298  
    1 {combine_css path=$HEADER_MANAGER_PATH|@cat:"admin/template/style.css"}
     1{combine_css path=$HEADER_MANAGER_PATH|cat:'admin/template/style.css'}
    22
    33<div class="titrePage">
    4   <h2><span style="letter-spacing:0">{$CATEGORIES_NAV}</span> &#8250; {'Edit album'|@translate} [{'Banner'|@translate}]</h2>
     4  <h2><span style="letter-spacing:0">{$CATEGORIES_NAV}</span> &#8250; {'Edit album'|translate} [{'Banner'|translate}]</h2>
    55</div>
    66
     
    99    <div class="banner-radio" style="display:block;">
    1010      <input type="radio" name="image" value="default" id="banner-default"{if $BANNER_IMAGE=='default'}checked="checked"{/if}>
    11       <label for="banner-default"><b>{'Default banner'|@translate}</b></label>
     11      <label for="banner-default"><b>{'Default banner'|translate}</b></label>
    1212    </div>
    1313    {foreach from=$banners item=image}
     
    2323    {/foreach}
    2424  {else}
    25     <p style="text-align:left;">{'No banner added yet'|@translate}</p>
     25    <p style="text-align:left;">{'No banner added yet'|translate}</p>
    2626  {/if}
    2727 
    2828  <p style="text-align:left;">
    29     <a href="{$ADD_IMAGE_URL}&redirect={$F_ACTION|urlencode}">{'Add a banner'|@translate}</a>
     29    <a href="{$ADD_IMAGE_URL}&redirect={$F_ACTION|urlencode}">{'Add a banner'|translate}</a>
    3030  </p>
    3131   
    3232  {if $banners}
    3333  <p class="actionButtons">
    34     <label><input type="checkbox" name="deep" value="1" {if $BANNER_DEEP}checked="checked"{/if}> {'Apply to sub-albums'|@translate}</label>
     34    <label><input type="checkbox" name="deep" value="1" {if $BANNER_DEEP}checked="checked"{/if}> {'Apply to sub-albums'|translate}</label>
    3535    <br><br>
    36     <input type="submit" name="save_banner" value="{'Submit'|@translate}" class="submit">
     36    <input type="submit" name="save_banner" value="{'Submit'|translate}" class="submit">
    3737  </p>
    3838  {/if}
  • extensions/header_manager/admin/template/config.tpl

    r20169 r26298  
    1 {combine_css path=$HEADER_MANAGER_PATH|@cat:"admin/template/style.css"}
     1{combine_css path=$HEADER_MANAGER_PATH|cat:'admin/template/style.css'}
    22
    3 {footer_script require="jquery"}{literal}
     3{footer_script require="jquery"}
    44jQuery("input[name='display']").change(function() {
    55  jQuery(".display-help:not(#"+ jQuery(this).val() +")").slideUp();
     
    1313  defaultPosition: 'top'
    1414});
    15 {/literal}{/footer_script}
     15{/footer_script}
    1616
    1717<div class="titrePage">
     
    2121<form method="post" action="{$CONFIG_URL}" class="properties">
    2222  <fieldset>
    23     <legend>{'Display'|@translate}</legend>
     23    <legend>{'Display'|translate}</legend>
    2424   
    25     <label><input type="radio" name="display" value="image_only" {if $BANNER_DISPLAY=='image_only'}checked="checked"{/if}> {'Image only'|@translate}</label><br>
     25    <label><input type="radio" name="display" value="image_only" {if $BANNER_DISPLAY=='image_only'}checked="checked"{/if}> {'Image only'|translate}</label><br>
    2626   
    27     <label><input type="radio" name="display" value="with_title" {if $BANNER_DISPLAY=='with_title'}checked="checked"{/if}> {'Gallery title above image'|@translate}</label><br>
     27    <label><input type="radio" name="display" value="with_title" {if $BANNER_DISPLAY=='with_title'}checked="checked"{/if}> {'Gallery title above image'|translate}</label><br>
    2828    <div class="display-help" id="with_title" {if $BANNER_DISPLAY!='with_title'}style="display:none;"{/if}>
    29       <i>{'You can customize the display by adding CSS rules to'|@translate}</i>
     29      <i>{'You can customize the display by adding CSS rules to'|translate}</i>
    3030      <span style="font-family:monospace;font-size:14px;color:#000;background:#eee;padding:0 2px;">#<span style="color:#09f;font-weight:bold;">theHeader</span> <span style="color:#00f;">div</span>.<span style="color:#f00;">banner</span></span>
    3131    </div>
    3232   
    33     <label><input type="radio" name="display" value="with_text" {if $BANNER_DISPLAY=='with_text'}checked="checked"{/if}> {'With text'|@translate}</label><br>
     33    <label><input type="radio" name="display" value="with_text" {if $BANNER_DISPLAY=='with_text'}checked="checked"{/if}> {'With text'|translate}</label><br>
    3434    <div class="display-help" id="with_text" {if $BANNER_DISPLAY!='with_text'}style="display:none;"{/if}>
    3535      <textarea rows="5" cols="50" class="description" name="conf_page_banner">{$CONF_PAGE_BANNER}</textarea><br>
    36       <i>{'Put <b>%header_manager%</b> where you want to display the image.'|@translate}</i>
     36      <i>{'Put <b>%header_manager%</b> where you want to display the image.'|translate}</i>
    3737    </div>
    3838   
    39     <label><input style="margin-top:20px;" type="checkbox" name="banner_on_picture" value="true" {if $BANNER_ON_PICTURE}checked="checked"{/if}> <b>{'Display banner on photo page'|@translate}</b></label>
     39    <label><input style="margin-top:20px;" type="checkbox" name="banner_on_picture" value="true" {if $BANNER_ON_PICTURE}checked="checked"{/if}> <b>{'Display banner on photo page'|translate}</b></label>
    4040  </fieldset>
    4141 
    4242  <fieldset id="batchManagerGlobal">
    43     <legend>{'Banner'|@translate}</legend>
     43    <legend>{'Banner'|translate}</legend>
    4444   
    4545  {if $banners}
    4646    <div class="banner-radio" style="display:block;">
    4747      <input type="radio" name="image" value="random" id="banner-random" {if $BANNER_IMAGE=='random'}checked="checked"{/if}>
    48       <label for="banner-random"><b>{'Random'|@translate}</b></label>
     48      <label for="banner-random"><b>{'Random'|translate}</b></label>
    4949    </div>
    5050    {foreach from=$banners item=image key=name}
     
    5454      </span>
    5555      <span class="banner-wrapper">
    56         <a href="{$CONFIG_URL}&amp;delete_banner={$image.NAME}" title="{'Delete'|@translate}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');" class="delete-banner">&times;</a>
     56        <a href="{$CONFIG_URL}&amp;delete_banner={$image.NAME}" title="{'Delete'|translate}" onclick="return confirm('{'Are you sure?'|translate|@escape:javascript}');" class="delete-banner">&times;</a>
    5757        <span class="banner-size">{$image.SIZE[0]} &times; {$image.SIZE[1]} px</span>
    5858        <label for="banner-{$image.NAME}" title="{$name}"><img src="{$image.THUMB}" alt="{$image.NAME}"></label>
     
    6161    {/foreach}
    6262  {else}
    63     {'No banner added yet'|@translate}
     63    {'No banner added yet'|translate}
    6464  {/if}
    6565   
    6666    <br><br>
    67     <a href="{$ADD_IMAGE_URL}">{'Add a banner'|@translate}</a>
     67    <a href="{$ADD_IMAGE_URL}">{'Add a banner'|translate}</a>
    6868  </fieldset>
    6969
    70   <p class="formButtons"><input type="submit" name="save_config" value="{'Submit'|@translate}" class="submit"></p>
     70  <p class="formButtons"><input type="submit" name="save_config" value="{'Submit'|translate}" class="submit"></p>
    7171 
    7272  <fieldset>
    73     <legend>{'Album specific banners'|@translate}</legend>
    74     <i>{'In order to add a specific banner, go to the admin page of the desired album.'|@translate}</i>
     73    <legend>{'Album specific banners'|translate}</legend>
     74    <i>{'In order to add a specific banner, go to the admin page of the desired album.'|translate}</i>
    7575   
    7676  {if $categories}
     
    8080        {$cat.NAME}
    8181        <a class="showImage" title="<img src='{$banners[$cat.IMAGE].THUMB}'>"><img src="{$HEADER_MANAGER_PATH}admin/template/image_{$cat.DEEP}.png"></a>
    82         <a href="{$cat.U_DELETE}" title="{'Restore default banner'|@translate}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');"><img src="{$themeconf.admin_icon_dir}/delete.png"></a>
     82        <a href="{$cat.U_DELETE}" title="{'Restore default banner'|translate}" onclick="return confirm('{'Are you sure?'|translate|@escape:javascript}');"><img src="{$themeconf.admin_icon_dir}/delete.png"></a>
    8383      </li>
    8484    {/foreach}
     
    8686   
    8787    <p>
    88       <img src="{$HEADER_MANAGER_PATH}admin/template/image_0.png"> : {'Non recursive'|@translate} &bull;
    89       <img src="{$HEADER_MANAGER_PATH}admin/template/image_1.png"> : {'Recursive'|@translate}
     88      <img src="{$HEADER_MANAGER_PATH}admin/template/image_0.png"> : {'Non recursive'|translate} &bull;
     89      <img src="{$HEADER_MANAGER_PATH}admin/template/image_1.png"> : {'Recursive'|translate}
    9090    </p>
    9191  {/if}
  • extensions/header_manager/include/banner.class.php

    r15854 r26298  
    11<?php
    2 if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
     2defined('HEADER_MANAGER_PATH') or die('Hacking attempt!');
    33
    44include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php');
     
    99class banner_image extends pwg_image
    1010{
    11   function banner_resize($destination_filepath, $x, $y, $x2, $y2, $width, $height)
     11  function banner_resize($destination_filepath, $selection)
    1212  {
    1313    global $conf;
     
    1818    $source_height = $this->image->get_height();
    1919
    20     $resize_dimensions = array(
    21       'width' => $width,
    22       'height'=> $height,
    23       'crop' => array(
    24         'width' => $x2-$x,
    25         'height' => $y2-$y,
    26         'x' => $x,
    27         'y' => $y,
    28         ),
     20    $crop = array(
     21      'width' => $selection['x2']-$selection['x'],
     22      'height' => $selection['y2']-$selection['y'],
     23      'x' => $selection['x'],
     24      'y' => $selection['y'],
    2925      );
    3026   
    31     // maybe resizing/croping is useless ?
    32     if ( $resize_dimensions['crop']['width'] == $source_width and $resize_dimensions['crop']['height'] == $source_height )
     27    // maybe resizing/cropping is useless ?
     28    if ($conf['header_manager']['width'] == $source_width and $conf['header_manager']['height'] == $source_height)
    3329    {
    3430      // the image doesn't need any resize! We just copy it to the destination
    3531      copy($this->source_filepath, $destination_filepath);
    36       return $this->get_resize_result($destination_filepath, $resize_dimensions['width'], $resize_dimensions['height'], $starttime);
     32      return $this->get_resize_result($destination_filepath, $source_width, $source_height, $starttime);
    3733    }
    3834   
     
    4036    $this->image->strip();
    4137   
     38    // crop
     39    $this->image->crop($crop['width'], $crop['height'], $crop['x'], $crop['y']);
     40   
    4241    // resize to what is displayed on crop screen
    43     if ($source_width > $conf['header_manager']['width'])
     42    if ($crop['width'] > $conf['header_manager']['width'])
    4443    {
    45       $this->image->resize($resize_dimensions['width'], $source_height*$resize_dimensions['width']/$source_width);
     44      $this->image->resize($conf['header_manager']['width'], $crop['height']*$conf['header_manager']['width']/$crop['width']);
    4645    }
    47    
    48     // crop
    49     $this->image->crop($resize_dimensions['crop']['width'], $resize_dimensions['crop']['height'], $resize_dimensions['crop']['x'], $resize_dimensions['crop']['y']);
    5046   
    5147    // save
     
    5349
    5450    // everything should be OK if we are here!
    55     return $this->get_resize_result($destination_filepath, $resize_dimensions['crop']['width'], $resize_dimensions['crop']['height'], $starttime);
     51    return $this->get_resize_result($destination_filepath, $crop['width'], $crop['height'], $starttime);
    5652  }
    5753 
     
    6965  }
    7066}
    71 
    72 ?>
  • extensions/header_manager/include/functions.inc.php

    r22857 r26298  
    88function list_banners($delete_orphans=false)
    99{
    10   if (!file_exists(HEADER_MANAGER_DIR)) return array();
     10  if (!file_exists(HEADER_MANAGER_DIR))
     11  {
     12    return array();
     13  }
     14 
    1115  $dir = scandir(HEADER_MANAGER_DIR);
    1216  $banners = array();
     
    1418  foreach ($dir as $file)
    1519  {
    16     if ( in_array($file, array('.','..','index.php','.svn')) ) continue;
    17     if ( !in_array(strtolower(get_extension($file)), array('jpg','jpeg','png','gif')) ) continue;
    18     if ( strpos($file, '-thumbnail')!==false ) continue;
     20    if (in_array($file, array('.','..','index.php','.svn'))) continue;
     21    if (!in_array(strtolower(get_extension($file)), array('jpg','jpeg','png','gif'))) continue;
     22    if (strpos($file, '-thumbnail')!==false) continue;
    1923   
    2024    $banner = get_banner($file);
    2125
    22     if ( $delete_orphans and !file_exists($banner['THUMB']) )
     26    if ($delete_orphans and !file_exists($banner['THUMB']))
    2327    {
    2428      @unlink($banner['PATH']);
     
    4347    return array(
    4448      'NAME' => $file,
    45       'PATH' => get_root_url().HEADER_MANAGER_DIR . $file,
    46       'THUMB' => get_root_url().HEADER_MANAGER_DIR . get_filename_wo_extension($file) . '-thumbnail.'. get_extension($file),
     49      'PATH' => get_root_url() . HEADER_MANAGER_DIR . $file,
     50      'THUMB' => get_root_url() . HEADER_MANAGER_DIR . get_filename_wo_extension($file) . '-thumbnail.' . get_extension($file),
    4751      'SIZE' => getimagesize(HEADER_MANAGER_DIR . $file),
    4852      );
     
    8589  $crop['coi']['y'] = ($picture['coi']['b']+$picture['coi']['t'])/2;
    8690 
    87   // define default crop frame
    88   if ($picture['width'] > $conf['header_manager']['width'])
     91  $crop['desired_width'] = $conf['header_manager']['width'];
     92  $crop['desired_height'] = $conf['header_manager']['height'];
     93 
     94  if ($picture['width'] > $crop['desired_width'])
    8995  {
    90     $crop['display_width'] = $conf['header_manager']['width'];
    91     $crop['display_height'] = round($picture['height']*$crop['display_width']/$picture['width']);
    92    
    93     $crop['coi']['x'] = round($crop['coi']['x']*$crop['display_width']/$picture['width']);
    94     $crop['coi']['y'] = round($crop['coi']['y']*$crop['display_height']/$picture['height']);
    95    
    96     $crop['l'] = 0;
    97     $crop['r'] = $conf['header_manager']['width'];
    98     $crop['t'] = max(0, $crop['coi']['y']-$conf['header_manager']['height']/2);
    99     $crop['b'] = min($crop['display_height'], $crop['t']+$conf['header_manager']['height']);
     96    $crop['box_width'] = $crop['desired_width'];
     97    $crop['box_height'] = round($picture['height']*$crop['box_width']/$picture['width']);
    10098  }
    10199  else
    102100  {
    103     $crop['display_width'] = $picture['width'];
    104     $crop['display_height'] = $picture['height'];
    105    
    106     $adapted_crop_height = round($conf['header_manager']['height']*$picture['width']/$conf['header_manager']['width']);
    107    
    108     $crop['l'] = 0;
    109     $crop['r'] = $picture['width'];
    110     $crop['t'] = max(0, $crop['coi']['y']-$adapted_crop_height/2);
    111     $crop['b'] = min($crop['display_height'], $crop['t']+$adapted_crop_height);
     101    $crop['box_width'] = $picture['width'];
     102    $crop['box_height'] = $picture['height'];
    112103  }
     104 
     105  $crop['real_width'] = $picture['width'];
     106  $crop['real_height'] = round($crop['desired_height']*$crop['real_width']/$crop['desired_width']);
     107 
     108  $crop['l'] = 0;
     109  $crop['r'] = $crop['real_width'];
     110  $crop['t'] = max(0, $crop['coi']['y']-$crop['real_height']/2);
     111  $crop['b'] = min($picture['height'], $crop['t']+$crop['real_height']);
    113112 
    114113  return $crop;
    115114}
    116 
    117 /**
    118  * clean table when categroies are delete
    119  */
    120 function header_manager_delete_categories($ids)
    121 {
    122   $query = '
    123 DELETE FROM '.HEADER_MANAGER_TABLE.'
    124   WHERE category_id IN('.implode(',', $ids).')
    125 ;';
    126   pwg_query($query);
    127 }
    128 
    129 ?>
  • extensions/header_manager/include/header_manager.inc.php

    r20169 r26298  
    11<?php
    2 if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
     2defined('HEADER_MANAGER_PATH') or die('Hacking attempt!');
    33
    44/**
     
    99  global $conf, $user, $template, $page;
    1010 
    11   if ( script_basename() == 'picture' and !$conf['header_manager']['banner_on_picture'] )
     11  if (script_basename() == 'picture' and !$conf['header_manager']['banner_on_picture'])
    1212  {
    13     return null;
     13    return '';
     14  }
     15 
     16  // no support for Kardon (not enough space)
     17  if ($user['theme'] == 'kardon')
     18  {
     19    return $page_banner;
    1420  }
    1521 
     
    4854  if (!isset($banner))
    4955  {
    50     if ( empty($conf['header_manager']['image']) or $conf['header_manager']['image'] == 'random')
     56    if (empty($conf['header_manager']['image']) or $conf['header_manager']['image'] == 'random')
    5157    {
    5258      $banners = array_values(list_banners());
    53       if (!count($banners)) return $page_banner;
     59      if (!count($banners))
     60      {
     61        return $page_banner;
     62      }
    5463      $banner = $banners[ mt_rand(0, count($banners)-1) ];
    5564    }
     
    5766    {
    5867      $banner = get_banner($conf['header_manager']['image']);
    59       if ($banner === false) return $page_banner;
     68      if ($banner === false)
     69      {
     70        return $page_banner;
     71      }
    6072    }
    6173  }
    6274 
    6375  // for MontBlancXL and BlancMontXL the banner is displayed as background of the header
    64   if ( in_array($user['theme'], array('blancmontxl','montblancxl')) )
     76  if (in_array($user['theme'], array('blancmontxl','montblancxl')))
    6577  {
    66     $template->append('head_elements',
    67 '<style type="text/css">
    68 #theHeader { background: transparent url('.$banner['PATH'].') center bottom no-repeat; }
    69 </style>'
     78    $template->block_html_style(null,
     79      '#theHeader { background: transparent url('.$banner['PATH'].') center bottom no-repeat; }'
    7080      );
    7181
    7282    if ($conf['header_manager']['display'] == 'image_only')
    7383    {
    74       $page_banner = null;
     84      $page_banner = '';
    7585    }
    7686    else
    7787    {
    78       $page_banner = str_replace('%header_manager%', null, $page_banner);
     88      $page_banner = str_replace('%header_manager%', '', $page_banner);
    7989    }
    8090  }
    81   // no support for Kardon (not enough space)
    82   else if ($user['theme'] != 'kardon')
     91  else
    8392  {
    84     $template->append('head_elements',
    85 '<style type="text/css">
    86 #theHeader div.banner { background:transparent url(\''.$banner['PATH'].'\') center center no-repeat;height:'.$banner['SIZE'][1].'px;line-height:'.($banner['SIZE'][1]-12).'px;font-size:2.5em;color:#fff;text-shadow:0 0 5px #000;text-align:center; }
    87 </style>'
     93    $template->block_html_style(null,
     94      '#theHeader div.banner { background:transparent url(\''.$banner['PATH'].'\') center center no-repeat; height:'. ($banner['SIZE'][1]) .'px; line-height:'. ($banner['SIZE'][1]-12) .'px; font-size:2.5em; color:#fff; text-shadow:0 0 5px #000; text-align:center; }'
    8895      );
    8996   
    90     $banner_img = '<div class="banner">'.($conf['header_manager']['display']=='with_title' ? $conf['gallery_title'] : '&nbsp;').'</div>';
     97    $banner_img = '<div class="banner">'. ($conf['header_manager']['display']=='with_title' ? $conf['gallery_title'] : '&nbsp;') .'</div>';
    9198   
    9299    if ($conf['header_manager']['display'] == 'with_text')
     
    96103    else
    97104    {
    98       $page_banner = '<a href="'.get_gallery_home_url().'">'.$banner_img.'</a>';
     105      $page_banner = '<a href="'. get_gallery_home_url() .'">'. $banner_img .'</a>';
    99106    }
    100107  }
     
    109116  return array_search($a['category_id'], $ids) < array_search($b['category_id'], $ids);
    110117}
    111 
    112 ?>
  • extensions/header_manager/main.inc.php

    r24010 r26298  
    99*/
    1010
    11 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     11defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
    1212
    1313global $prefixeTable;
     
    3737
    3838/**
    39  * update plugin & unserialize conf
     39 * initialization
    4040 */
    4141function header_manager_init()
     
    4343  global $conf, $pwg_loaded_plugins, $page;
    4444 
    45   if (
    46     HEADER_MANAGER_VERSION == 'auto' or
    47     $pwg_loaded_plugins['header_manager']['version'] == 'auto' or
    48     version_compare($pwg_loaded_plugins['header_manager']['version'], HEADER_MANAGER_VERSION, '<')
    49   )
    50   {
    51     include_once(HEADER_MANAGER_PATH . 'include/install.inc.php');
    52     header_manager_install();
    53    
    54     if ( $pwg_loaded_plugins['header_manager']['version'] != 'auto' and HEADER_MANAGER_VERSION != 'auto' )
    55     {
    56       $query = '
    57 UPDATE '. PLUGINS_TABLE .'
    58 SET version = "'. HEADER_MANAGER_VERSION .'"
    59 WHERE id = "header_manager"';
    60       pwg_query($query);
    61      
    62       $pwg_loaded_plugins['header_manager']['version'] = HEADER_MANAGER_VERSION;
    63      
    64       if (defined('IN_ADMIN'))
    65       {
    66         $_SESSION['page_infos'][] = 'Header Manager updated to version '. HEADER_MANAGER_VERSION;
    67       }
    68     }
    69   }
     45  include_once(HEADER_MANAGER_PATH . 'maintain.inc.php');
     46  $maintain = new header_manager_maintain('header_manager');
     47  $maintain->autoUpdate(HEADER_MANAGER_VERSION, 'install');
    7048 
    7149  $conf['header_manager'] = unserialize($conf['header_manager']);
     
    7755function header_manager_admin_menu($menu)
    7856{
    79   array_push($menu, array(
     57  $menu[] = array(
    8058    'NAME' => 'Header Manager',
    8159    'URL' => HEADER_MANAGER_ADMIN,
    82   ));
     60    );
    8361  return $menu;
    8462}
     
    10280}
    10381
    104 ?>
     82/**
     83 * clean table when categories are deleted
     84 */
     85function header_manager_delete_categories($ids)
     86{
     87  $query = '
     88DELETE FROM '.HEADER_MANAGER_TABLE.'
     89  WHERE category_id IN('.implode(',', $ids).')
     90;';
     91  pwg_query($query);
     92}
  • extensions/header_manager/maintain.inc.php

    r17655 r26298  
    11<?php
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
    33
    4 include_once(PHPWG_PLUGINS_PATH . 'header_manager/include/install.inc.php');
     4class header_manager_maintain extends PluginMaintain
     5{
     6  private $installed = false;
    57 
    6 function plugin_install()
    7 {
    8   header_manager_install();
    9  
    10   define('header_manager_installed', true);
    11 }
     8  private $default_conf = array(
     9      'width' => 1000,
     10      'height' => 150,
     11      'image' => 'random',
     12      'display' => 'image_only',
     13      'banner_on_picture' => true,
     14    );
    1215
    13 function plugin_activate()
    14 {
    15   if (!defined('header_manager_installed'))
     16  function install($plugin_version, &$errors=array())
    1617  {
    17     header_manager_install();
     18    global $conf, $prefixeTable;
     19
     20    // configuration
     21    if (empty($conf['header_manager']))
     22    {
     23      $conf['header_manager'] = serialize($this->default_conf);
     24      conf_update_param('header_manager', $conf['header_manager']);
     25    }
     26    else
     27    {
     28      $new_conf = is_string($conf['header_manager']) ? unserialize($conf['header_manager']) : $conf['header_manager'];
     29      if (!isset($new_conf['banner_on_picture']))
     30      {
     31        $new_conf['banner_on_picture'] = true;
     32        $conf['header_manager'] = serialize($new_conf);
     33        conf_update_param('header_manager', $conf['header_manager']);
     34      }
     35    }
     36
     37    // banners directory
     38    if (!file_exists(PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'banners'))
     39    {
     40      mkdir(PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'banners', 0755);
     41    }
     42
     43    // banners table
     44    $query = '
     45CREATE TABLE IF NOT EXISTS `' .$prefixeTable . 'category_banner` (
     46  `category_id` smallint(5) unsigned NOT NULL,
     47  `image` varchar(255) NOT NULL,
     48  `deep` tinyint(1) DEFAULT 1,
     49  PRIMARY KEY (`category_id`)
     50) ENGINE=MyISAM DEFAULT CHARSET=utf8
     51;';
     52    pwg_query($query);
     53
     54    $this->installed = true;
     55  }
     56
     57  function activate($plugin_version, &$errors=array())
     58  {
     59    if (!$this->installed)
     60    {
     61      $this->install($plugin_version, $errors);
     62    }
     63  }
     64
     65  function deactivate()
     66  {
     67  }
     68
     69  function uninstall()
     70  {
     71    global $prefixeTable;
     72
     73    conf_delete_param('header_manager');
     74
     75    pwg_query('DROP TABLE `' .$prefixeTable . 'category_banner`;');
    1876  }
    1977}
    20 
    21 function plugin_uninstall()
    22 {
    23   global $prefixeTable;
    24  
    25   pwg_query('DROP TABLE `' .$prefixeTable . 'category_banner`;');
    26   pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "header_manager" LIMIT 1;');
    27 }
    28 
    29 ?>
Note: See TracChangeset for help on using the changeset viewer.