You are here

function smileys_admin_list in Smileys 6

Same name and namespace in other branches
  1. 5 smileys.module \smileys_admin_list()
1 string reference to 'smileys_admin_list'
smileys_menu in ./smileys.module
Implementation of hook_menu().

File

./smileys.admin.inc, line 105

Code

function smileys_admin_list() {
  _smileys_check_filter();
  $path = drupal_get_path('module', 'smileys');
  drupal_add_js($path . '/scripts/admin/smileys-admin.js', 'module', 'header', FALSE, TRUE, FALSE);
  drupal_add_css($path . '/scripts/admin/smileys-admin.css', 'module', 'all', FALSE);
  $header = array(
    t('Smiley'),
    t('Visibility'),
    t('Acronyms'),
    t('Description'),
    t('Category'),
    t('Weight'),
  );
  $rows = array();
  $packages = array();
  $categories = array(
    'Miscellaneous' => 'Miscellaneous',
  );
  $smileyp = db_query("SELECT DISTINCT package FROM {smileys} ORDER BY package");
  while ($pack = db_fetch_object($smileyp)) {
    $categories[$pack->package] = $pack->package;
  }
  ksort($categories);
  $categories = array_unique($categories);
  $output = '<form id="smileys-admin-form">';
  $smileyp = db_query("SELECT DISTINCT package FROM {smileys} ORDER BY package");
  while ($pack = db_fetch_object($smileyp)) {
    $packages[] = check_plain($pack->package);
    $select = '';
    foreach ($categories as $category) {
      $select .= '<option value="' . $category . '"' . ($category == $pack->package ? 'selected="selected"' : '') . '>' . check_plain($category) . '</option>' . "\n";
    }
    $rows[] = array(
      'data' => array(
        array(
          'data' => '<span>' . check_plain($pack->package) . '</span>',
          'class' => 'category',
          'colspan' => 7,
        ),
      ),
      'class' => 'category',
    );
    $rows[] = array(
      'data' => array(
        array(
          'data' => '<em>' . t('No smileys in this category') . '</em>',
          'colspan' => 7,
        ),
      ),
      'class' => "category-message category-populated category-" . str_replace(array(
        '_',
        ' ',
      ), '-', drupal_strtolower(check_plain($pack->package))) . "-message",
    );
    $list = _smileys_list(1, " WHERE package = '" . check_plain($pack->package) . "' ORDER BY weight");
    foreach ($list as $smiley) {
      $each_acronym = explode(' ', $smiley->acronyms);
      if ($smiley->promote_to_box == -1) {
        $promoted = '<span class="smiley-deselected" id="' . $smiley->id . '">&nbsp;</span>';
      }
      elseif ($smiley->promote_to_box == 0) {
        $promoted = '<span class="smiley-middle" id="' . $smiley->id . '">&nbsp;</span>';
      }
      elseif ($smiley->promote_to_box == 1) {
        $promoted = '<span class="smiley-selected" id="' . $smiley->id . '">&nbsp;</span>';
      }
      $acronyms = '';
      foreach ($each_acronym as $key => $eac) {
        $eac = str_replace("&lt;", "<", $eac);
        $eac = str_replace("&gt;", ">", $eac);
        $acronyms .= '<span style="color:' . ($key % 2 == 0 ? "#000000" : "#53616e") . ';">' . check_plain($eac) . '</span>&nbsp;';
      }
      $rows[] = array(
        'data' => array(
          array(
            'data' => '<div class="nub">' . l(t('Edit'), 'admin/settings/smileys/edit/' . $smiley->id, array(
              'attributes' => array(
                'class' => 'edit',
                'title' => t('Edit this smiley'),
              ),
            )) . l(t('Delete'), 'admin/settings/smileys/delete/' . $smiley->id, array(
              'attributes' => array(
                'class' => 'delete',
                'title' => t('Delete this smiley'),
              ),
            )) . '</div>' . theme('image', check_url($smiley->image), check_plain($smiley->description), check_plain($smiley->description)),
            'class' => 'nub-td',
          ),
          $promoted,
          $acronyms,
          check_plain($smiley->description),
          '<center><select id="edit-category" class="form-select smiley-category-select smiley-category-' . str_replace(array(
            '_',
            ' ',
          ), '-', drupal_strtolower($pack->package)) . '" name="category">' . $select . '</select></center>',
          '<center><input style="text-align: center;" size="1" id="' . $smiley->id . '" class="smiley-weight" value="' . $smiley->weight . '"></input></center>',
        ),
        'class' => 'draggable',
      );
      $acronyms = '';
    }
  }
  $form['smileys'] = array(
    '#type' => 'markup',
    '#value' => theme('table', $header, $rows, array(
      'id' => 'smileys_admin_list',
    )),
  );
  $output .= drupal_render($form);
  foreach ($packages as $package) {
    drupal_add_tabledrag('smileys_admin_list', 'match', 'sibling', 'smiley-category-select', 'smiley-category-' . str_replace(array(
      '_',
      ' ',
    ), '-', drupal_strtolower($package)), NULL, FALSE);
    drupal_add_tabledrag('smileys_admin_list', 'order', 'sibling', 'smiley-weight');
  }
  if (count($rows) == 0) {
    if (module_exists('smileys_import')) {
      $msg = t('No smileys found. You may !add, or !import.', array(
        '!add' => l(t('add a custom smileys'), 'admin/settings/smileys/add'),
        '!import' => l(t('import smiley packages'), 'admin/settings/smileys/import'),
      ));
    }
    else {
      $msg = t('No smileys found. You may !add, or install smileys_import module & import smiley packages.', array(
        '!add' => l(t('add custom smileys'), 'admin/settings/smileys/add'),
      ));
    }
    drupal_set_message($msg);
    $output = '';
  }
  else {
    $output .= '<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>' . t('Visibility Legend') . '</i><br /><span class="smiley-selected"></span>' . t('Visible on select box + popup') . '<br /><span class="smiley-middle"></span>' . t('Visible on only on popup i.e. "More Smileys"') . '<br /><span class="smiley-deselected"></span>' . t('Invisible (but not disabled)');
  }
  return $output . '</form>';
}