/[drupal]/contributions/modules/plugin_manager/plugin_manager.admin.inc
ViewVC logotype

Diff of /contributions/modules/plugin_manager/plugin_manager.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.52.2.80.2.4, Sun Feb 1 01:07:09 2009 UTC revision 1.52.2.80.2.5, Sun Feb 1 01:55:18 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: plugin_manager.admin.inc,v 1.52.2.80.2.3 2009/02/01 00:19:52 joshuarogers Exp $  // $Id: plugin_manager.admin.inc,v 1.52.2.80.2.4 2009/02/01 01:07:09 joshuarogers Exp $
3    
4  /**  /**
5   * @file   * @file
6   * The Forms used by the plugin manager.   * The Forms used by the plugin manager.
7   */   */
8    
 function plugin_manager_modules_redirect() {  
     drupal_set_message(t("Search for the modules you want to install, add them to your queue, and then install them."));  
     drupal_goto('admin/plugin_manager/search');  
 }  
   
 function plugin_manager_themes_redirect() {  
     drupal_set_message(t("Search for the themes you want to install, add them to your queue, and then install them."));  
     drupal_goto('admin/plugin_manager/search');  
 }  
   
 /**  
  * FAPI for the first page of the installer  
  *  
  * @ingroup forms  
  * @see plugin_manager_install_1()  
  */  
 function plugin_manager_page_1() {  
   $queue_info = variable_get("plugin_manager_queue_info", array());  
   
   // Put a version drop down for each of the files  
   foreach ($queue_info AS $project => $info) {  
     $form[$project .'_version'] = array(  
       '#title' => t('%title version', array('%title' => $info['title'])),  
       '#type' => 'select',  
       '#options' => $info['version'],  
     );  
   }  
   
   // Put the continue button up.  
   $form['submit'] = array(  
     '#type' => 'submit',  
     '#value' => t('Continue to Step 2'),  
   );  
   return $form;  
 }  
   
 /**  
  * FAPI for the second page of the installer  
  *  
  * @ingroup forms  
  * @see plugin_manager_install_2()  
  */  
 function plugin_manager_page_2($form_state) {  
   // On to page two.  
   $queue_info = variable_get("plugin_manager_queue_info", array());  
   
   $link_attr['attributes']['target'] = 'blank';  
   
   // Make each one of the md5sum boxes.  
   foreach ($queue_info AS $name => $plugin) {  
     $version = $form_state['storage'][1][$name .'_version'];  
     $link = $plugin['release'][$version]['release_link'];  
     $form[$name .'_md5sum'] = array(  
       '#title' => t('%plugin_title md5_file hash (copy/paste from above or <a href="!uri">available here</a>)', array('%plugin_title' => $plugin['title'], '!uri' => url($link, $link_attr))),  
       '#type' => 'textfield',  
       '#size' => 32,  
       '#prefix' => "<iframe src='$link' style='width:100%;height:260px;'></iframe>",  
       '#required' => TRUE,  
     );  
   }  
   
   // Put the continue button up.  
   $form['submit'] = array(  
     '#type' => 'submit',  
     '#value' => t('Continue to Step 3'),  
   );  
   return $form;  
 }  
   
 /**  
  * FAPI for the third page of the installer  
  *  
  * @ingroup forms  
  * @see plugin_manager_install_3()  
  */  
 function plugin_manager_page_3($form_state) {  
   $form['backend'] = array(  
     '#title' => t('Installation method'),  
     '#type' => 'select',  
     '#options' => plugin_manager_backends(),  
   );  
   $form['host'] = array(  
     '#title' => t('Hostname'),  
     '#type' => 'textfield',  
     '#default_value' => variable_get('plugin_manager_hostname', 'localhost'),  
   );  
   $form['username'] = array(  
     '#title' => t('Username'),  
     '#type' => 'textfield',  
     '#default_value' => variable_get('plugin_manager_username', ''),  
   );  
   $form['save_username'] = array(  
     '#title' => t('Save Username'),  
     '#type' => 'checkbox',  
   );  
   $form['password'] = array(  
     '#title' => t('Password'),  
     '#type' => 'password',  
   );  
   $form['submit'] = array(  
     '#type' => 'submit',  
     '#value' => t('Install'),  
   );  
   return $form;  
 }  
   
 function plugin_manager_page_4($form_state) {  
   update_get_available(TRUE); // refresh the update database  
   $form[] = array(  
     '#value' => t("Now you're done.  Unless it is stated otherwise above, your modules and/or themes should be properly installed now.  So what should you do now?") .'<p>'. l(t("If you installed new modules, you can enable them here."), 'admin/build/modules') .'</p><p>'. l(t('If you installed new themes, you can select them here.'), 'admin/build/themes') .'</p>',  
   );  
   
   return $form;  
 }  
   
 /**  
  * A page to list all of the queued changes and begin installation of them.  
  */  
 function plugin_manager_install_form($form_state) {  
   // Make sure that the plugin manager can be run.  
   if (!plugin_manager_runnable()) {  
     return array();  
   }  
   
   // Show the congrats page.  
   if (isset($form_state['storage']['page']) AND $form_state['storage']['page'] == 4) {  
     return plugin_manager_page_4($form_state);  
   }  
   
   // If there aren't any, then just tell the just that.  And quit.  
   $queue = plugin_manager_get_queue();  
   if (empty($queue)) {  
     drupal_set_message(t("Nothing has been queued for install."));  
     return array();  
   }  
   
   // @todo Examine this code.  
   // Get the total list and grab the release_history for each and set the download links.  
   $queue_info = plugin_manager_get_release_history($queue);  
   variable_set("plugin_manager_queue_info", $queue_info);  
   
   // If we don't need to select a version, then skip that page.  
   $latest = variable_get('plugin_manager_latest_version', 1);  
   if ($latest AND !isset($form_state['storage']['page'])) {  
     $files = array();  
     foreach ($queue_info AS $name => $plugin) {  
       $link = $plugin['release'][0]['download_link'];  
       $files[$name] = plugin_manager_get($link);  
       // Check for an error.  
       if ($files[$name] == FALSE) {  
         drupal_set_message(t('Could not download @name', array('@name' => $name)), 'error');  
         return;  
       }  
       else {  
         drupal_set_message(t('Downloaded @name', array('@name' => $name)));  
       }  
     }  
     variable_set("plugin_manager_downloaded_files", $files);  
     $form_state['storage']['page'] = 2;  
     foreach ($queue AS $name) {  
       $form_state['storage'][1][$name .'_version'] = 0;  
     }  
   }  
   
   // Allow the choice of versions on the first page.  
   if (!isset($form_state['storage']['page'])) {  
     return plugin_manager_page_1();  
   }  
   elseif ($form_state['storage']['page'] == 2) {  
     return plugin_manager_page_2($form_state);  
   }  
   else {  
     return plugin_manager_page_3($form_state);  
   }  
 }  
   
 /**  
  * Process the first page of the installer, by downloading the needed files.  
  */  
 function plugin_manager_install_1($form, &$form_state) {  
   // Download the files.  
   $files = array();  
   $queue_info = variable_get("plugin_manager_queue_info", array());  
   foreach ($queue_info AS $name => $plugin) {  
     $version = $form_state['storage'][1][$name .'_version'];  
     $link = $plugin['release'][$version]['download_link'];  
     $files[$name] = plugin_manager_get($link);  
   
     // Check for an error.  
     if ($files[$name] == FALSE) {  
       drupal_set_message(t('Could not download @name', array('@name' => $name)), 'error');  
       return;  
     }  
   }  
   variable_set("plugin_manager_downloaded_files", $files);  
   
   // Proceed to the next page.  
   $form_state['storage']['page'] = 2;  
   return;  
 }  
   
 /**  
  * Process the second page of the installer by comparing calculated md5sums  
  * to the md5sums supplied by the user.  
  */  
 function plugin_manager_install_2($form, &$form_state) {  
   $form_state['storage'][2] = $form_state['values'];  
   // Compare the calculated and supplied md5sums.  
   $files = variable_get("plugin_manager_downloaded_files", array());  
   
   foreach ($files AS $name => $file) {  
     $md5 = $form_state['storage'][2][$name .'_md5sum'];  
     if (md5_file($file) != $md5) {  
       drupal_set_message(t('The md5sum is incorrect for @plugin', array('@plugin' => $plugin['title'])), 'error');  
       $form_state['storage']['page'] = 2;  
       return;  
     }  
   }  
   
   $form_state['storage']['page'] = 3;  
   return;  
 }  
   
 /**  
  * Process the third page of the installer.  Extract, install, log and  
  * clean up the files.  
  */  
 function plugin_manager_install_3($form, &$form_state) {  
   // Load the appropriate backend.  
   $backend_list = plugin_manager_backends();  
   $backend = $backend_list[$form_state['values']['backend']];  
   $form_state['storage']['page'] = 3;  
   
   // Save the ftp_host variable  
   variable_set("plugin_manager_ftp_hostname", $form_state['values']['host']);  
   if ($form_state['values']['save_username'] == '1') {  
     variable_set("plugin_manager_username", $form_state['values']['username']);  
   }  
   
   // Go through each on of the files.  
   $plugins = variable_get("plugin_manager_downloaded_files", array());  
   foreach ($plugins AS $name => $plugin) {  
     // Extract the files  
     $files = plugin_manager_untar($plugin);  
   
     // Find out whether the thing is a module or theme.  
     $row = db_fetch_array(  
       db_query(  
         "SELECT lower(tag) AS tag  
          FROM {plugin_manager_taxonomy}  
          WHERE short_name = '%s'  
          AND tag IN('Modules', 'Themes')", $name  
       )  
     );  
   
     // Copy the extracted files  
     $copy = call_user_func_array($backend .'_plugin_manager_copy',  
       array($files, $row['tag'], $form_state['values']['host'],  
         $form_state['values']['username'], $form_state['values']['password']));  
   
     foreach (array_reverse($files) AS $file) {  
       // Remove the extracted files.  
       $file = file_directory_path() .'/plugin_manager_extraction/'. $file;  
       if (is_dir($file)) {  
         rmdir($file);  
       }  
       else {  
         unlink($file);  
       }  
     }  
   
     // If it failed, stop now.  
     if (!$copy) {  
       drupal_set_message(t("Unable to install @name", array('@name' => $name)), 'error');  
       return;  
     }  
   
     global $base_url;  
     drupal_set_message(t("Successfully installed @name.", array('@name' => $name)) . l(t('View README.txt'), $base_url .'/sites/all/modules/'. check_plain($name) .'/README.txt'));  
     // rebuild caches  
     drupal_rebuild_theme_registry();  
     node_types_rebuild();  
     menu_rebuild();  
     cache_clear_all('schema', 'cache');  
     module_rebuild_cache();  
   
     unlink($plugin);  
   }  
   
   variable_set("plugin_manager_queue_info", array());  
   plugin_manager_clear_queue();  
   $form_state['storage']['page'] = 4;  
 }  
   
 /**  
  * Process the data presented in the plugin_manager_install form.  
  */  
 function plugin_manager_install_form_submit($form, &$form_state) {  
   // If page one was submitted, download the requested files.  
   if (!isset($form_state['storage']['page']) OR ($form_state['storage']['page'] == 1)) {  
     $form_state['storage'][1] = $form_state['values'];  
     return plugin_manager_install_1($form, $form_state);  
   }  
   elseif ($form_state['storage']['page'] == 2) {  
     return plugin_manager_install_2($form, $form_state);  
   }  
   return plugin_manager_install_3($form, $form_state);  
 }  
   
 /**  
  * FAPI for the uninstall page.  
  *  
  * Shows a list of packages to the user, allowing them to mark packages for removal.  
  * @ingroup forms  
  * @see plugin_manager_uninstall_submit()  
  */  
 function plugin_manager_uninstall_form($form_state) {  
   
   // Get a list of the non-installed plugins.  
   $result = db_query(  
     "SELECT filename,name,type  
      FROM {system}  
      WHERE status = 0  
      ORDER BY type"  
   );  
   while ($row = db_fetch_array($result)) {  
     if (strpos($row['filename'], 'sites/all/'. $row['type'] .'s/'. $row['name']) !==0 || !file_exists($row['filename'])) continue;  
     $info_file = join('.', array_slice(explode('.', $row['filename']), 0, -1)) .'.info';  
     $info = drupal_parse_info_file($info_file);  
     if (!$info['name'])$info['name'] = $row['name'];  
     if (!$form[$row['type']]) {  
         $form[$row['type']] = array(  
         '#type' => 'fieldset',  
         '#title' => htmlentities('Disabled '. ucwords($row['type']) .'s'),  
         '#collapsible' => FALSE,  
         '#collapsed' => FALSE,  
         );  
     }  
     $form[$row['type']][$row['name']] = array(  
       '#type' => 'checkbox',  
       '#name' => $row['name'],  
       '#title' => htmlentities($info['name']),  
     );  
   }  
   $form['backend'] = array(  
     '#title' => t('Removal method'),  
     '#type' => 'select',  
     '#options' => plugin_manager_backends(),  
   );  
   $form['host'] = array(  
     '#title' => t('Hostname'),  
     '#type' => 'textfield',  
     '#default_value' => variable_get('plugin_manager_hostname', 'localhost'),  
   );  
   $form['username'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Username'),  
     '#default_value' => variable_get('plugin_manager_username', ''),  
   );  
   $form['password'] = array(  
     '#type' => 'password',  
     '#title' => t('Password'),  
     '#default_value' => '',  
   );  
   $form[] = array(  
     '#type' => 'submit',  
     '#value' => t('Uninstall'),  
   );  
   return $form;  
 }  
   
 /**  
  * Remove package files from the server.  
  */  
 function plugin_manager_uninstall_form_submit($form, &$form_state) {  
   $backend_list = plugin_manager_backends();  
   $backend = $backend_list[$form_state['values']['backend']];  
   
   foreach ($form_state['values'] AS $plugin => $value) {  
   
     // If it isn't supposed to be removed, then skip it.  
     if ($value != 1) {  
       continue;  
     }  
   
     // Get the files to remove.  
     $row = db_fetch_array(db_query(  
         "SELECT filename, name, type  
          FROM {system}  
          WHERE name='%s'", array($plugin)));  
     if (strpos($row['filename'], 'sites/all/'. $row['type'] .'s/'. $row['name'] .'/') !==0 || !file_exists($row['filename'])) {  
         drupal_set_message(t("Illegal Uninstall. Please report this bug."));  
         return;  
     }  
     // Remove the files / folders requested.  
     $remove = call_user_func_array($backend .'_plugin_manager_remove',  
       array('sites/all/'. $row['type'] .'s/'. $row['name'], $form_state['values']['host'],  
         $form_state['values']['username'], $form_state['values']['password']));  
     if ($remove) {  
         drupal_set_message(t("Successfully uninstalled @plugin.", array('@plugin' => $plugin)));  
     }  
     else  
         drupal_set_message(t("Unable to uninstall @plugin.", array('@plugin' => $plugin)), 'error');  
   }  
 }  
   
 /** Package Update Section **/  
   
 /**  
  * @callback for admin/plugin_manager/update  
  * List packages w/ available updates and give the option to install.  
  * Makes use of the core "update" module.  
  */  
 function plugin_manager_update_form() {  
   $available = update_get_available(TRUE);  
   $projects = update_calculate_project_data($available);  
   
   $some = FALSE;  
   foreach ($projects as $name => $project) {  
     if ($project['status'] == UPDATE_NOT_CURRENT) {  
       $some=TRUE;  
       $form[$name] = array(  
         '#type' => 'checkbox',  
         '#title' => $project['title'],  
         '#default_value' => 'true'  
       );  
     }  
   }//}  
   if (!$some)  
       drupal_set_message(t("There are no available updates for your drupal installation."));  
   $form['submit'] = array(  
     '#type' => 'submit',  
     '#value' => 'Install Updates'  
   );  
   return $form;  
 }  
   
 function plugin_manager_update_form_submit($form, &$form_state) {  
   foreach ($form_state['values'] AS $name => $value) {  
     if ($value == '1') {  
       plugin_manager_add_to_queue($name);  
     }  
     else {  
       plugin_manager_remove_from_queue($name);  
     }  
   }  
   $queue = plugin_manager_get_queue();  
   if ($queue) {  
     drupal_goto("admin/plugin_manager/install");  
   }  
 }  
   
 /**  
  * Alert the user to outdated plugins, and give them an opporunity to  
  * automatically update them.  
  * @alters the system_modules and system_themes pages (admin/modules | themes)  
  */  
 function plugin_manager_form_alter(&$form, $form_state, $form_id) {  
   if ($form_id == 'system_modules' || $form_id == 'system_themes' ) {  
     $reqs = update_requirements('runtime');  
     if (isset($reqs['update_contrib']['reason'])) {  
       drupal_set_message(l(t('It looks like you have some outdated modules.  Go Here to update your site automatically.'), 'admin/plugin_manager/update'));  
     }  
   }  
 }  
   
 /** Plugin Manager Search Section **/  
   
9  /**  /**
10   * This is the main function for the Ajax Search page   * This is the main function for the Ajax Search page
11   * of Plugin Manager.   * of Plugin Manager.
# Line 487  function plugin_manager_form(){ Line 19  function plugin_manager_form(){
19    
20    $form[] = array(    $form[] = array(
21      '#prefix' => '<div class="pm-header">',      '#prefix' => '<div class="pm-header">',
22      '#value' => '<div class="pm-term-header">'. t('Categories:') .'</div><a href="javascript:void(0);" onclick="pm_unclick();"><span class="pm-term-uncheck"></span></a><a href="javascript:void(0);" onclick="javascript:pm_check();"><span class="pm-term-check"></span></a>',      '#value' => '<div class="pm-term-header">'. t('Categories:') .'</div><a href="javascript:void(0);" id="clickall" onclick="pm_unclick();"><span class="pm-term-uncheck"></span></a><a href="javascript:pm_check_all();"><span class="pm-term-check"></span></a>',
23      '#suffix' => '</div>',      '#suffix' => '</div>',
24    );    );
25    
# Line 498  function plugin_manager_form(){ Line 30  function plugin_manager_form(){
30        WHERE term != 'Modules'        WHERE term != 'Modules'
31        ORDER BY term"        ORDER BY term"
32    );    );
   
33    while ($row = db_fetch_array($result)) {    while ($row = db_fetch_array($result)) {
34      $term = $row['term'];      $term = $row['term'];
35      $form[] = array(      $form[] = array(
# Line 512  function plugin_manager_form(){ Line 43  function plugin_manager_form(){
43      );      );
44    }    }
45    
46      // Start the second column.
47      $form[] = array('#value' => '</div>',);
48      $form[] = array('#value' => '<div id="pm-content-column">',);
49      $form[] = array(
50        '#prefix' => '<div class="pm-header">',
51        '#value' => '<div class="pm-content-header">H</div>',
52        '#suffix' => '</div>',
53      );
54    $form[] = array('#value' => '</div>',);    $form[] = array('#value' => '</div>',);
55    
56    return $form;    return $form;
57  }  }
58    

Legend:
Removed from v.1.52.2.80.2.4  
changed lines
  Added in v.1.52.2.80.2.5

  ViewVC Help
Powered by ViewVC 1.1.2