You are here

function jqp_status_page in jQuery Plugin Handler (JQP) 6.2

Page callback for admin/build/jqp.

Lists all installed javascript libraries.

1 string reference to 'jqp_status_page'
jqp_menu in ./jqp.module
Implementation of hook_menu().

File

./jqp.admin.inc, line 14
This file includes all functionality for the libraries configuration pages

Code

function jqp_status_page() {
  $js_libraries = jqp_rebuild_cache();
  if (!empty($js_libraries)) {

    // Set the table header.
    $header = array(
      t('Name'),
      t('Description'),
      t('Versions'),
      t('Operations'),
      t('Status'),
    );
    foreach ($js_libraries as $name => $library) {

      // Reset the status class to 'ok'.
      $status = 'ok';

      // Reset all arrays.
      $versions = $links = $warnings = array();

      // Get all versions and check wheter all files exists
      foreach (array(
        'scripts',
        'stylesheets',
      ) as $type) {

        // Proceed only if there are files added to this type
        if (!empty($library->info[$type])) {
          foreach ($library->info[$type] as $v => $files) {
            unset($files['changed']);
            $versions[$v] = $v == 0 ? 'default' : $v;
            $links[$v] = l(t('configure'), "admin/build/jqp/{$name}/{$v}");

            // Check if all files for this version exist
            foreach ($files as $file) {
              if (!file_exists($file)) {

                // The file does not exist.
                // Set the status of this version to 'warning' and stop checking.
                $warnings[$v] = TRUE;
                $status = 'warning';
                continue;
              }
            }
          }
        }
      }

      // Reset the $first which is used to check if we're in the first tr of a library
      $first = TRUE;
      foreach (array_keys($versions) as $v) {
        $library_name = '';
        if ($first) {
          if ($library->info['project_url']) {
            $library_name = l($library->info['name'], $library->info['project_url'], array(
              'attributes' => array(
                'title' => t('Click here to go to %library\'s project page.', array(
                  '%library' => $library->info['name'],
                )),
              ),
            ));
          }
          else {
            $library_name = $library->info['name'];
          }
        }

        // Create the unique table row
        $rows[$name . $v] = array(
          'data' => array(
            $library_name ? "<strong>{$library_name}</strong>" : '',
            $first ? $library->info['description'] : '',
            $versions[$v],
            $links[$v],
            theme('image', "misc/watchdog-" . ($warnings[$v] ? 'warning' : 'ok') . ".png"),
          ),
          'class' => ($first ? 'first ' : '') . $status,
        );

        // The first table row for this library is created.
        // Set $first to FALSE for reference.
        $first = FALSE;
      }
      $rows[$name . $v]['class'] .= ' last';
    }

    // Add a bit of custom css to overwrite the default 'odd' and 'even' behaviour.
    drupal_add_css(drupal_get_path('module', 'jqp') . '/jqp.admin.css');

    // Create the table
    $output = theme('table', $header, $rows, array(
      'class' => 'js_libraries_table multirow',
    ));
  }
  else {

    // Nothing to show.
    $output = "<p>" . t('No javascript libraries installed yet!') . "</p>";
  }
  return $output;
}