plugins/EnaniumBackgrounds.php
changeset 0 e8db3e017691
child 1 b69d36dc637e
equal deleted inserted replaced
-1:000000000000 0:e8db3e017691
       
     1 <?php
       
     2 /**!info**
       
     3 {
       
     4   "Plugin Name"  : "Enanium backgrounds",
       
     5   "Plugin URI"   : "http://enanocms.org/plugin/enaniumbg",
       
     6   "Description"  : "Provides several additional background images for Enanium.",
       
     7   "Author"       : "Dan Fuhry",
       
     8   "Version"      : "1.1.6",
       
     9   "Author URI"   : "http://enanocms.org/"
       
    10 }
       
    11 **!*/
       
    12 
       
    13 // $plugins->attachHook('enanium_search_form', 'enanium_paint_bg_controls();');
       
    14 $plugins->attachHook('enanium_main_header', 'enanium_paint_bg_controls();');
       
    15 $plugins->attachHook('compile_template', 'enanium_add_headers();');
       
    16 
       
    17 $ebg_images = array('default', 'aqua', 'blinds', 'dune', 'freshflower', 'garden', 'greenmeadow', 'ladybird', 'raindrops', 'storm', 'twowings', 'wood', 'yellowflower');
       
    18 
       
    19 $ebg_outsiders = array();
       
    20 if ( $dr = @opendir(ENANO_ROOT . '/plugins/enaniumbg') )
       
    21 {
       
    22   while ( $dh = @readdir($dr) )
       
    23   {
       
    24     if ( $dh == '.' || $dh == '..' || is_dir(ENANO_ROOT . "/plugins/enaniumbg/$dr") )
       
    25       continue;
       
    26     
       
    27     if ( in_array($dh, $ebg_images) || !preg_match('/\.jpg$/', $dh) )
       
    28       continue;
       
    29     
       
    30     $dh = preg_replace('/\.jpg$/', '', $dh);
       
    31     
       
    32     if ( !file_exists(ENANO_ROOT . "/plugins/enaniumbg/icons/$dh.png") )
       
    33       continue;
       
    34     
       
    35     $ebg_outsiders[] = $dh;
       
    36   }
       
    37   closedir($dr);
       
    38 }
       
    39 unset($dh, $dr);
       
    40 
       
    41 function enanium_paint_bg_controls()
       
    42 {
       
    43   global $ebg_images, $ebg_outsiders;
       
    44   global $lang;
       
    45   
       
    46   ?>
       
    47   <div id="enanium_bg_list">
       
    48     <?php
       
    49     foreach ( $ebg_images as $i => $image )
       
    50     {
       
    51       $sel = ( $image == '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) . '">';
       
    53       echo enanium_generate_sprite(scriptPath . '/plugins/enaniumbg/icons/sprite.png', 16, 16, 0, $i * 16);
       
    54       echo '</a>';
       
    55     }
       
    56     ?>
       
    57   </div>
       
    58   <?php
       
    59 }
       
    60 
       
    61 function enanium_add_headers()
       
    62 {
       
    63   global $db, $session, $paths, $template, $plugins; // Common objects
       
    64   global $lang;
       
    65   
       
    66   if ( $template->theme != 'enanium' )
       
    67     return;
       
    68   
       
    69   $template->add_header('<link rel="stylesheet" type="text/css" href="' . scriptPath . '/plugins/enaniumbg/enaniumbg.css" />');
       
    70   $template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/enaniumbg/enaniumbg.js"></script>');
       
    71 }
       
    72 
       
    73 function enanium_generate_sprite($sprite, $width, $height, $start_x, $start_y)
       
    74 {
       
    75   $start_x = 0 - $start_x;
       
    76   $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;" />';
       
    78 }
       
    79 
       
    80 /**!language**
       
    81 <code>
       
    82 {
       
    83   eng: {
       
    84     categories: ['meta', 'enaniumbg'],
       
    85     strings: {
       
    86       meta: {
       
    87         enaniumbg: 'Enanium backgrounds',
       
    88       },
       
    89       enaniumbg: {
       
    90         default: 'Default',
       
    91         aqua: 'Aqua',
       
    92         blinds: 'Blinds',
       
    93         dune: 'Dune',
       
    94         freshflower: 'Fresh flower',
       
    95         garden: 'Garden',
       
    96         greenmeadow: 'Greenmeadow',
       
    97         ladybird: 'Ladybird',
       
    98         raindrops: 'Raindrops',
       
    99         storm: 'Storm',
       
   100         twowings: 'Two Wings',
       
   101         wood: 'Wood',
       
   102         yellowflower: 'Yellow flower'
       
   103       }
       
   104     }
       
   105   }
       
   106 }
       
   107 </code>
       
   108 **!*/
       
   109