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