plugins/EnaniumBackgrounds.php
changeset 1 b69d36dc637e
parent 0 e8db3e017691
child 2 178d22e361d6
equal deleted inserted replaced
0:e8db3e017691 1:b69d36dc637e
    11 **!*/
    11 **!*/
    12 
    12 
    13 // $plugins->attachHook('enanium_search_form', 'enanium_paint_bg_controls();');
    13 // $plugins->attachHook('enanium_search_form', 'enanium_paint_bg_controls();');
    14 $plugins->attachHook('enanium_main_header', 'enanium_paint_bg_controls();');
    14 $plugins->attachHook('enanium_main_header', 'enanium_paint_bg_controls();');
    15 $plugins->attachHook('compile_template', 'enanium_add_headers();');
    15 $plugins->attachHook('compile_template', 'enanium_add_headers();');
       
    16 $plugins->attachHook('acl_rule_init', '$this->addAdminNode("adm_cat_appearance", "enaniumbg_acppage", "EnaniumConfig", scriptPath . "/plugins/enaniumbg/icons/garden.png");');
    16 
    17 
    17 $ebg_images = array('default', 'aqua', 'blinds', 'dune', 'freshflower', 'garden', 'greenmeadow', 'ladybird', 'raindrops', 'storm', 'twowings', 'wood', 'yellowflower');
    18 $ebg_images = array('default', 'aqua', 'blinds', 'dune', 'freshflower', 'garden', 'greenmeadow', 'ladybird', 'raindrops', 'storm', 'twowings', 'wood', 'yellowflower');
    18 
    19 
    19 $ebg_outsiders = array();
    20 $ebg_outsiders = array();
    20 if ( $dr = @opendir(ENANO_ROOT . '/plugins/enaniumbg') )
    21 if ( $dr = @opendir(ENANO_ROOT . '/plugins/enaniumbg') )
    21 {
    22 {
    22   while ( $dh = @readdir($dr) )
    23   while ( $dh = @readdir($dr) )
    23   {
    24   {
    24     if ( $dh == '.' || $dh == '..' || is_dir(ENANO_ROOT . "/plugins/enaniumbg/$dr") )
    25     if ( $dh == '.' || $dh == '..' || is_dir(ENANO_ROOT . "/plugins/enaniumbg/$dh") )
    25       continue;
    26       continue;
    26     
    27     
    27     if ( in_array($dh, $ebg_images) || !preg_match('/\.jpg$/', $dh) )
    28     if ( !preg_match('/\.jpg$/', $dh) )
    28       continue;
    29       continue;
    29     
    30     
    30     $dh = preg_replace('/\.jpg$/', '', $dh);
    31     $dh = preg_replace('/\.jpg$/', '', $dh);
       
    32     
       
    33     if ( in_array($dh, $ebg_images) )
       
    34       continue;
    31     
    35     
    32     if ( !file_exists(ENANO_ROOT . "/plugins/enaniumbg/icons/$dh.png") )
    36     if ( !file_exists(ENANO_ROOT . "/plugins/enaniumbg/icons/$dh.png") )
    33       continue;
    37       continue;
    34     
    38     
    35     $ebg_outsiders[] = $dh;
    39     $ebg_outsiders[] = $dh;
    40 
    44 
    41 function enanium_paint_bg_controls()
    45 function enanium_paint_bg_controls()
    42 {
    46 {
    43   global $ebg_images, $ebg_outsiders;
    47   global $ebg_images, $ebg_outsiders;
    44   global $lang;
    48   global $lang;
       
    49   
       
    50   if ( !getConfig('enanium_show_switcher', 1) )
       
    51     return;
    45   
    52   
    46   ?>
    53   ?>
    47   <div id="enanium_bg_list">
    54   <div id="enanium_bg_list">
    48     <?php
    55     <?php
    49     foreach ( $ebg_images as $i => $image )
    56     foreach ( $ebg_images as $i => $image )
    50     {
    57     {
    51       $sel = ( $image == 'default' ) ? ' class="selected"' : '';
    58       $sel = ( $image == getConfig('enanium_bg', 'default') ) ? ' class="selected"' : '';
    52       echo '<a' . $sel . ' href="#bg:' . $image . '" id="ebg_' . $image . '" onclick="enanium_change_bg(\'' . $image . '\', this); return false;" title="' . $lang->get('enaniumbg_' . $image) . '">';
    59       echo '<a' . $sel . ' href="#bg:' . $image . '" id="ebg_' . $image . '" onclick="enanium_change_bg(\'' . $image . '\', this); return false;" title="' . $lang->get('enaniumbg_' . $image) . '">';
    53       echo enanium_generate_sprite(scriptPath . '/plugins/enaniumbg/icons/sprite.png', 16, 16, 0, $i * 16);
    60       echo enanium_generate_sprite(scriptPath . '/plugins/enaniumbg/icons/sprite.png', 16, 16, 0, $i * 16);
       
    61       echo '</a>';
       
    62     }
       
    63     foreach ( $ebg_outsiders as $image )
       
    64     {
       
    65       $sel = ( $image == getConfig('enanium_bg', 'default') ) ? ' class="selected"' : '';
       
    66       echo '<a' . $sel . ' href="#bg:' . $image . '" id="ebg_' . $image . '" onclick="enanium_change_bg(\'' . $image . '\', this); return false;" title="' . htmlspecialchars(ucwords(str_replace('_', ' ', $image))) . '">';
       
    67       echo '<img alt=" " src="' . scriptPath . '/plugins/enaniumbg/icons/' . $image . '.png" />';
    54       echo '</a>';
    68       echo '</a>';
    55     }
    69     }
    56     ?>
    70     ?>
    57   </div>
    71   </div>
    58   <?php
    72   <?php
    59 }
    73 }
    60 
    74 
    61 function enanium_add_headers()
    75 function enanium_add_headers()
    62 {
    76 {
    63   global $db, $session, $paths, $template, $plugins; // Common objects
    77   global $db, $session, $paths, $template, $plugins; // Common objects
       
    78   global $ebg_images, $ebg_outsiders;
    64   global $lang;
    79   global $lang;
    65   
    80   
    66   if ( $template->theme != 'enanium' )
    81   if ( $template->theme != 'enanium' )
    67     return;
    82     return;
    68   
    83   
    69   $template->add_header('<link rel="stylesheet" type="text/css" href="' . scriptPath . '/plugins/enaniumbg/enaniumbg.css" />');
    84   $repeat = getConfig('enanium_background_repeat', 'no-repeat');
    70   $template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/enaniumbg/enaniumbg.js"></script>');
    85   $attachment = getConfig('enanium_background_attachment', 'fixed');
       
    86   $position = getConfig('enanium_background_position', 'center top');
       
    87   
       
    88   if ( getConfig('enanium_show_switcher', 1) )
       
    89   {
       
    90     $template->add_header('<link rel="stylesheet" type="text/css" href="' . scriptPath . '/plugins/enaniumbg/enaniumbg.css" />');
       
    91     
       
    92     $addheader = <<<EOF
       
    93     <script type="text/javascript">
       
    94       var enanium_bg_repeat = '$repeat';
       
    95       var enanium_bg_attachment = '$attachment';
       
    96       var enanium_bg_position = '$position';
       
    97     </script>
       
    98 EOF;
       
    99     $template->add_header($addheader);
       
   100     $template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/enaniumbg/enaniumbg.js"></script>');
       
   101   }
       
   102   
       
   103   if ( ($img = getConfig('enanium_bg', 'default')) !== 'default' )
       
   104   {
       
   105     if ( !file_exists(ENANO_ROOT . "/plugins/enaniumbg/$img.jpg") )
       
   106       return;
       
   107     
       
   108     $scriptpath = scriptPath;
       
   109     $addheader = <<<EOF
       
   110     <style type="text/css">
       
   111       body {
       
   112         background-image: url({$scriptpath}/plugins/enaniumbg/{$img}.jpg);
       
   113         background-color: #000000;
       
   114         background-repeat: $repeat;
       
   115         background-attachment: $attachment;
       
   116         background-position: $position;
       
   117       }
       
   118       td#cell-content {
       
   119         background-color: transparent;
       
   120         background-image: url({$scriptpath}/plugins/enaniumbg/transw70.png);
       
   121       }
       
   122     </style>
       
   123 EOF;
       
   124     $template->add_header($addheader);
       
   125   }
    71 }
   126 }
    72 
   127 
    73 function enanium_generate_sprite($sprite, $width, $height, $start_x, $start_y)
   128 function enanium_generate_sprite($sprite, $width, $height, $start_x, $start_y)
    74 {
   129 {
    75   $start_x = 0 - $start_x;
   130   $start_x = 0 - $start_x;
    76   $start_y = 0 - $start_y;
   131   $start_y = 0 - $start_y;
    77   return '<img alt=" " src="' . cdnPath . '/images/spacer.gif" width="' . $width . '" height="' . $height . '" style="background-image: url(\'' . $sprite . '\'); background-repeat: no-repeat; background-position: ' . $start_x . 'px ' . $start_y . 'px;" />';
   132   return '<img alt=" " src="' . cdnPath . '/images/spacer.gif" width="' . $width . '" height="' . $height . '" style="background-image: url(\'' . $sprite . '\'); background-repeat: no-repeat; background-position: ' . $start_x . 'px ' . $start_y . 'px;" />';
       
   133 }
       
   134 
       
   135 function page_Admin_EnaniumConfig()
       
   136 {
       
   137   global $db, $session, $paths, $template, $plugins; // Common objects
       
   138   global $lang;
       
   139   
       
   140   if ( isset($_POST['enanium_bg']) )
       
   141   {
       
   142     $bg = $_POST['enanium_bg'];
       
   143     if ( file_exists(ENANO_ROOT . "/plugins/enaniumbg/$bg.jpg") )
       
   144       setConfig('enanium_bg', $bg);
       
   145     
       
   146     $val = isset($_POST['show_switcher']) ? '1' : '0';
       
   147     setConfig('enanium_show_switcher', $val);
       
   148     
       
   149     setConfig('enanium_background_repeat', $_POST['background_repeat']);
       
   150     setConfig('enanium_background_attachment', $_POST['background_attachment']);
       
   151     setConfig('enanium_background_position', $_POST['background_position']);
       
   152     
       
   153     echo '<div class="info-box">' . $lang->get('enaniumbg_acp_msg_changes_saved') . '</div>';
       
   154   }
       
   155   
       
   156   acp_start_form();
       
   157   ?>
       
   158   <div class="tblholder">
       
   159     <table border="0" cellspacing="1" cellpadding="4">
       
   160       <tr>
       
   161         <th colspan="2"><?php echo $lang->get('enaniumbg_acp_th'); ?></th>
       
   162       </tr>
       
   163       <tr>
       
   164         <td class="row2" style="width: 50%;">
       
   165           <?php echo $lang->get('enaniumbg_acp_field_default_bg'); ?><br />
       
   166           <small><?php echo $lang->get('enaniumbg_acp_field_default_bg_hint'); ?></small>
       
   167         </td>
       
   168         <td class="row1" style="width: 50%;">
       
   169           <select name="enanium_bg">
       
   170             <?php
       
   171             global $ebg_images, $ebg_outsiders;
       
   172             if ( !empty($ebg_outsiders) )
       
   173             {
       
   174               foreach ( $ebg_outsiders as $image )
       
   175               {
       
   176                 $sel = $image == getConfig('enanium_bg', 'default') ? 'selected="selected" ' : '';
       
   177                 echo '<option ' . $sel . 'value="' . $image . '">' . ucwords(str_replace('_', ' ', $image)) . '</option>';
       
   178               }
       
   179               echo '<option disabled="disabled" value="">--------------------</option>';
       
   180             }
       
   181             foreach ( $ebg_images as $image )
       
   182             {
       
   183               $sel = $image == getConfig('enanium_bg', 'default') ? 'selected="selected" ' : '';
       
   184               echo '<option ' . $sel . 'value="' . $image . '">' . $lang->get("enaniumbg_$image") . '</option>';
       
   185             }
       
   186             ?>
       
   187           </select>
       
   188         </td>
       
   189       </tr>
       
   190       <tr>
       
   191         <td class="row2">
       
   192           <label for="ebg_chk_show_switcher"><?php echo $lang->get('enaniumbg_acp_field_show_switcher'); ?></label><br />
       
   193           <small><?php echo $lang->get('enaniumbg_acp_field_show_switcher_hint'); ?></small>
       
   194         </td>
       
   195         <td class="row1">
       
   196           <input id="ebg_chk_show_switcher" type="checkbox" name="show_switcher" <?php echo getConfig('enanium_show_switcher', 1) == '1' ? 'checked="checked" ' : ''; ?>/>
       
   197         </td>
       
   198       </tr>
       
   199       <tr>
       
   200         <td class="row2">
       
   201           <?php echo $lang->get('enaniumbg_acp_field_tile'); ?><br />
       
   202           <small><?php echo $lang->get('enaniumbg_acp_field_tile_hint'); ?></small>
       
   203         </td>
       
   204         <td class="row1">
       
   205           <label>
       
   206             <input type="radio" name="background_repeat" value="repeat" <?php echo getConfig('enanium_background_repeat', 'no-repeat') == 'repeat' ? 'checked="checked" ' : ''; ?>/>
       
   207             <?php echo $lang->get('enaniumbg_acp_field_tile_tile'); ?>
       
   208           </label><br />
       
   209           <label>
       
   210             <input type="radio" name="background_repeat" value="no-repeat" <?php echo getConfig('enanium_background_repeat', 'no-repeat') == 'no-repeat' ? 'checked="checked" ' : ''; ?>/>
       
   211             <?php echo $lang->get('enaniumbg_acp_field_tile_norepeat'); ?>
       
   212           </label>
       
   213         </td>
       
   214       </tr>
       
   215       <tr>
       
   216         <td class="row2">
       
   217           <?php echo $lang->get('enaniumbg_acp_field_scroll'); ?><br />
       
   218           <small><?php echo $lang->get('enaniumbg_acp_field_scroll_hint'); ?></small>
       
   219         </td>
       
   220         <td class="row1">
       
   221           <label>
       
   222             <input type="radio" name="background_attachment" value="fixed" <?php echo getConfig('enanium_background_attachment', 'fixed') == 'fixed' ? 'checked="checked" ' : ''; ?>/>
       
   223             <?php echo $lang->get('enaniumbg_acp_field_scroll_fixed'); ?>
       
   224           </label><br />
       
   225           <label>
       
   226             <input type="radio" name="background_attachment" value="scroll" <?php echo getConfig('enanium_background_attachment', 'fixed') == 'scroll' ? 'checked="checked" ' : ''; ?>/>
       
   227             <?php echo $lang->get('enaniumbg_acp_field_scroll_scroll'); ?>
       
   228           </label>
       
   229         </td>
       
   230       </tr>
       
   231       <tr>
       
   232         <td class="row2">
       
   233           <?php echo $lang->get('enaniumbg_acp_field_anchor'); ?>
       
   234         </td>
       
   235         <td class="row1">
       
   236         <table border="0" style="background-color: transparent; width: 120px; padding: 5px; border: 1px solid #404040;">
       
   237             <?php
       
   238             foreach ( array('top', 'center', 'bottom') as $ypos )
       
   239             {
       
   240               echo '<tr>';
       
   241               foreach ( array('left', 'center', 'right') as $xpos )
       
   242               {
       
   243                 ?><td style="width: 40px; line-height: 30px; text-align: center;"><input type="radio" name="background_position" value="<?php echo "$xpos $ypos"; ?>" <?php echo getConfig('enanium_background_position', 'center top') == "$xpos $ypos" ? 'checked="checked" ' : ''; ?>/><?php
       
   244               }
       
   245               echo '</tr>';
       
   246             }
       
   247             ?>
       
   248           </table>
       
   249         </td>
       
   250       </tr>
       
   251       <tr>
       
   252         <th class="subhead" colspan="2">
       
   253           <input type="submit" value="<?php echo $lang->get('etc_save_changes'); ?>" />
       
   254         </th>
       
   255       </tr>
       
   256     </table>
       
   257   </div>
       
   258   </form>
       
   259   <?php
    78 }
   260 }
    79 
   261 
    80 /**!language**
   262 /**!language**
    81 <code>
   263 <code>
    82 {
   264 {
    97         ladybird: 'Ladybird',
   279         ladybird: 'Ladybird',
    98         raindrops: 'Raindrops',
   280         raindrops: 'Raindrops',
    99         storm: 'Storm',
   281         storm: 'Storm',
   100         twowings: 'Two Wings',
   282         twowings: 'Two Wings',
   101         wood: 'Wood',
   283         wood: 'Wood',
   102         yellowflower: 'Yellow flower'
   284         yellowflower: 'Yellow flower',
       
   285         
       
   286         acp_th: 'Enanium background configuration',
       
   287         acp_field_default_bg: 'Default background:',
       
   288         acp_field_default_bg_hint: '<b>Tip:</b> You can add more backgrounds to Enanium! Upload a JPEG image to plugins/enaniumbg/. Then, upload a 16x16 icon of the image, with the same filename, to plugins/enaniumbg/icons/. The plugin will automatically add the image to the list here and to the switcher, if enabled.',
       
   289         acp_field_show_switcher: 'Show background switcher:',
       
   290         acp_field_show_switcher_hint: 'If the switcher is turned off, the background selected above will always be used.',
       
   291         
       
   292         acp_field_tile: 'Allow background to be tiled:',
       
   293         acp_field_tile_hint: 'If this is off, the background will be letterboxed and/or pillarboxed if the screen is too small.',
       
   294         acp_field_tile_tile: 'Tile',
       
   295         acp_field_tile_norepeat: 'Don\'t tile',
       
   296         
       
   297         acp_field_scroll: 'Scroll background image with page:',
       
   298         acp_field_scroll_hint: 'This may produce undesired results if "%this.enaniumbg_acp_field_tile_norepeat%" is selected.',
       
   299         acp_field_scroll_fixed: 'Background fixed and always in view',
       
   300         acp_field_scroll_scroll: 'Scroll background',
       
   301         
       
   302         acp_field_anchor: 'Background position anchor:',
       
   303         
       
   304         acp_msg_changes_saved: 'Your changes have been saved.',
       
   305         acppage: 'Enanium configuration',
   103       }
   306       }
   104     }
   307     }
   105   }
   308   }
   106 }
   309 }
   107 </code>
   310 </code>