Projet

Général

Profil

Paste
Télécharger (3,43 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / colorbox / drush / colorbox.drush.inc @ 13755f8d

1
<?php
2

    
3
/**
4
 * @file
5
 *   drush integration for colorbox.
6
 */
7

    
8
/**
9
 * The Colorbox plugin URI.
10
 */
11
define('COLORBOX_DOWNLOAD_URI', 'https://github.com/jackmoore/colorbox/archive/1.x.zip');
12
define('COLORBOX_DOWNLOAD_PREFIX', 'colorbox-');
13

    
14
/**
15
 * Implementation of hook_drush_command().
16
 *
17
 * In this hook, you specify which commands your
18
 * drush module makes available, what it does and
19
 * description.
20
 *
21
 * Notice how this structure closely resembles how
22
 * you define menu hooks.
23
 *
24
 * See `drush topic docs-commands` for a list of recognized keys.
25
 *
26
 * @return
27
 *   An associative array describing your command(s).
28
 */
29
function colorbox_drush_command() {
30
  $items = array();
31

    
32
  // the key in the $items array is the name of the command.
33
  $items['colorbox-plugin'] = array(
34
    'callback' => 'drush_colorbox_plugin',
35
    'description' => dt('Download and install the Colorbox plugin.'),
36
    'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap.
37
    'arguments' => array(
38
      'path' => dt('Optional. A path where to install the Colorbox plugin. If omitted Drush will use the default location.'),
39
    ),
40
    'aliases' => array('colorboxplugin'),
41
  );
42

    
43
  return $items;
44
}
45

    
46
/**
47
 * Implementation of hook_drush_help().
48
 *
49
 * This function is called whenever a drush user calls
50
 * 'drush help <name-of-your-command>'
51
 *
52
 * @param
53
 *   A string with the help section (prepend with 'drush:')
54
 *
55
 * @return
56
 *   A string with the help text for your command.
57
 */
58
function colorbox_drush_help($section) {
59
  switch ($section) {
60
    case 'drush:colorbox-plugin':
61
      return dt('Download and install the Colorbox plugin from jacklmoore.com/colorbox, default location is sites/all/libraries.');
62
  }
63
}
64

    
65
/**
66
 * Implements drush_MODULE_post_pm_enable().
67
 */
68
// function drush_colorbox_post_pm_enable() {
69
//   $modules = func_get_args();
70
//   if (in_array('colorbox', $modules)) {
71
//     drush_colorbox_plugin();
72
//   }
73
// }
74

    
75
/**
76
 * Command to download the Colorbox plugin.
77
 */
78
function drush_colorbox_plugin() {
79
  $args = func_get_args();
80
  if (!empty($args[0])) {
81
    $path = $args[0];
82
  }
83
  else {
84
    $path = 'sites/all/libraries';
85
  }
86

    
87
  // Create the path if it does not exist.
88
  if (!is_dir($path)) {
89
    drush_op('mkdir', $path);
90
    drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
91
  }
92

    
93
  // Set the directory to the download location.
94
  $olddir = getcwd();
95
  chdir($path);
96

    
97
  // Download the zip archive
98
  if ($filepath = drush_download_file(COLORBOX_DOWNLOAD_URI)) {
99
    $filename = basename($filepath);
100
    $dirname = COLORBOX_DOWNLOAD_PREFIX . basename($filepath, '.zip');
101

    
102
    // Remove any existing Colorbox plugin directory
103
    if (is_dir($dirname) || is_dir('colorbox')) {
104
      drush_delete_dir($dirname, TRUE);
105
      drush_delete_dir('colorbox', TRUE);
106
      drush_log(dt('A existing Colorbox plugin was deleted from @path', array('@path' => $path)), 'notice');
107
    }
108

    
109
    // Decompress the zip archive
110
    drush_tarball_extract($filename);
111

    
112
    // Change the directory name to "colorbox" if needed.
113
    if ($dirname != 'colorbox') {
114
      drush_move_dir($dirname, 'colorbox', TRUE);
115
      $dirname = 'colorbox';
116
    }
117
  }
118

    
119
  if (is_dir($dirname)) {
120
    drush_log(dt('Colorbox plugin has been installed in @path', array('@path' => $path)), 'success');
121
  }
122
  else {
123
    drush_log(dt('Drush was unable to install the Colorbox plugin to @path', array('@path' => $path)), 'error');
124
  }
125

    
126
  // Set working directory back to the previous working directory.
127
  chdir($olddir);
128
}