You are here

function featured_content_save in Featured Content 6

Same name and namespace in other branches
  1. 6.2 featured_content.admin.inc \featured_content_save()

Returns the 'save' $op info for hook_block().

1 call to featured_content_save()
featured_content_add_block_form_submit in ./featured_content.admin.inc
Save new block.

File

./featured_content.admin.inc, line 780
Provides infrequently used functions for featured content module.

Code

function featured_content_save($delta, $edit) {
  $featured_blocks = variable_get('featured_content_blocks', array());
  $vocabularies = taxonomy_get_vocabularies();

  // general settings
  if (!is_array($featured_blocks[$delta])) {
    $featured_blocks[$delta] = array();
  }
  if (!is_array($featured_blocks[$delta]['more'])) {
    $featured_blocks[$delta]['more'] = array();
  }
  if (!is_array($featured_blocks[$delta]['rss'])) {
    $featured_blocks[$delta]['rss'] = array();
  }
  $featured_blocks[$delta]['name'] = $edit['featured_content_block_name'];
  $featured_blocks[$delta]['header'] = $edit['featured_content_block_header'];
  $featured_blocks[$delta]['footer'] = $edit['featured_content_block_footer'];
  $featured_blocks[$delta]['empty'] = $edit['featured_content_block_empty'];
  $featured_blocks[$delta]['type'] = $edit['featured_content_block_type'];
  $featured_blocks[$delta]['sort'] = $edit['featured_content_block_sort'];
  $featured_blocks[$delta]['display'] = $edit['featured_content_block_display'];
  $featured_blocks[$delta]['style'] = $edit['featured_content_block_style'];
  $featured_blocks[$delta]['more']['text'] = $edit['featured_content_block_more_text'];
  $featured_blocks[$delta]['more']['num'] = $edit['featured_content_block_more_num'];
  $featured_blocks[$delta]['more']['display'] = $edit['featured_content_block_more_display'];
  $featured_blocks[$delta]['more']['style'] = $edit['featured_content_block_more_style'];
  $featured_blocks[$delta]['more']['title'] = $edit['featured_content_block_more_title'];
  $featured_blocks[$delta]['more']['header'] = $edit['featured_content_block_more_header'];
  $featured_blocks[$delta]['more']['footer'] = $edit['featured_content_block_more_footer'];
  $featured_blocks[$delta]['more']['url'] = $edit['featured_content_block_more_url'];
  $featured_blocks[$delta]['rss']['display'] = $edit['featured_content_block_rss_display'];
  $featured_blocks[$delta]['rss']['title'] = $edit['featured_content_block_rss_title'];

  // if sort is set to popularity, print warning
  if ($edit['featured_content_block_sort'] == 'popular_asc' || $edit['featured_content_block_sort'] == 'popular_desc') {
    if (featured_content_node_statistics_enabled()) {
      drupal_set_message(t('You have chosen to sort by popularity. Since the
          Statistics module is turned on and Count Content Views is enabled,
          this will work as expected. If you disable either of these in the
          future, the content items will no longer be sorted by popularity.'));
    }
    else {
      if (!module_exists('statistics')) {
        drupal_set_message(t('You have chosen to sort by popularity, but the
            Statistics module is currently turned off. Turn on the Statistics
            module (!admin_modules_page) and enable Count Content Views
            (!statistics_settings_page) so the content items can be sorted
            by popularity.', array(
          '!admin_modules_page' => l(t('admin/build/modules'), 'admin/build/modules'),
          '!statistics_settings_page' => l(t('admin/reports/settings'), 'admin/reports/settings'),
        )));
      }
      elseif (!variable_get('statistics_count_content_views', 0)) {
        drupal_set_message(t('You have chosen to sort by popularity. Although
            the Statistics module is currently turned on, Count Content Views
            is currently disabled. Enable Count Content Views
            (!statistics_settings_page) so the content items can be sorted
            by popularity.', array(
          '!statistics_settings_page' => l(t('admin/reports/settings'), 'admin/reports/settings'),
        )));
      }
    }
  }
  $num_show = $edit['featured_content_block_num_show'];
  if (!is_numeric($num_show) || $num_show <= 0 || $num_show > variable_get('featured_content_max_node_show', 20)) {
    $num_show = variable_get('featured_content_max_node_show', 20);
    if (!is_numeric($num_show) || $num_show <= 0) {
      $num_show = 20;
    }
  }
  $featured_blocks[$delta]['num_show'] = $num_show;

  // manual settings
  $featured_blocks[$delta]['manual']['paths'] = $edit['manual_paths'];
  $tmp = preg_replace('/(\\r\\n?|\\n)/', '|||', $edit['manual_paths']);
  $paths = explode('|||', $tmp);
  foreach ($paths as $path) {
    $path = trim($path);
    if ($path) {
      if (!valid_url($path, TRUE)) {

        // check for external URLs
        // assume it's an internal URL
        $path = drupal_get_normal_path($path);
      }
      $matches = array();
      if (preg_match("/^node\\/(.*)/", $path, $matches)) {
        $nids[] = $matches[1];
      }
      else {
        if (preg_match("/\\*/", $path, $matches)) {
          $path_sql = str_replace('*', '%', $path);
          $path_sql = str_replace('/', '\\/', $path_sql);
          $results = db_query("SELECT src FROM {url_alias} WHERE dst LIKE '%s'", $path_sql);
          while ($row = db_fetch_object($results)) {
            if (preg_match("/^node\\/(.*)/", $row->src, $matches)) {
              $nids[] = $matches[1];
            }
          }
        }
      }
    }
  }
  $featured_blocks[$delta]['manual']['nids'] = $nids;

  // cck settings
  if (module_exists('content')) {
    $cck_fields = content_fields();
    if (!empty($cck_fields)) {
      foreach ($cck_fields as $field_name => $field_data) {
        $featured_blocks[$delta]['cck']['fields'][$field_name] = $edit['cck_fields_' . $field_name];
      }
    }
  }

  // filter settings
  $featured_blocks[$delta]['filter']['include_node'] = $edit['filter_include_node'];
  $featured_blocks[$delta]['filter']['paths']['match'][0] = $edit['filter_paths_match_0'];
  $featured_blocks[$delta]['filter']['paths']['match'][1] = $edit['filter_paths_match_1'];
  $featured_blocks[$delta]['filter']['paths']['match'][2] = $edit['filter_paths_match_2'];
  $featured_blocks[$delta]['filter']['paths']['match'][3] = $edit['filter_paths_match_3'];
  $languages = featured_content_get_languages();
  foreach ($languages as $language_code => $language_label) {
    $featured_blocks[$delta]['filter']['languages'][$language_code] = $edit['filter_languages_' . $language_code];
  }
  $content_types = featured_content_get_content_types();
  foreach ($content_types as $content_type_name => $content_type_label) {
    $featured_blocks[$delta]['filter']['content_types']['type'][$content_type_name] = $edit['filter_content_types_type_' . $content_type_name];
  }
  $users = featured_content_get_users();
  foreach ($users as $user_uid => $user_label) {
    $featured_blocks[$delta]['filter']['users']['user'][$user_uid] = $edit['filter_users_user_' . $user_uid];
  }
  foreach ($vocabularies as $vocabulary) {
    $vid = $vocabulary->vid;
    $terms = featured_content_get_vocabulary_terms($vocabulary);
    foreach ($terms as $term_tid => $term_name) {
      $featured_blocks[$delta]['filter']['vocab'][$vid]['term'][$term_tid] = $edit['filter_vocab_term_' . $term_tid];
    }
  }
  $featured_blocks[$delta]['filter']['primary_term']['node'] = $edit['filter_primary_term_node'];
  if (module_exists('views') && function_exists('views_get_all_views')) {
    $views = views_get_all_views();
    if (!empty($views)) {
      $featured_blocks[$delta]['filter']['view_include_arg'] = empty($edit['filter_view_include_arg']) ? 0 : 1;
      foreach ($views as $view_name => $view_data) {
        if (!empty($view_data->display)) {
          foreach ($view_data->display as $display_name => $display_data) {
            $featured_blocks[$delta]['filter']['views']['view'][$view_name][$display_name] = $edit['filter_views_view_' . $view_name . '_' . $display_name];
          }
        }
      }
    }
  }
  if (module_exists('search')) {
    $featured_blocks[$delta]['filter']['keyword'] = array();
    $featured_blocks[$delta]['filter']['keyword']['filter_by_keyword'] = $edit['filter_by_keyword'];
    $featured_blocks[$delta]['filter']['keyword']['num_words_in_title_keyword'] = $edit['num_words_in_title_keyword'];
    $featured_blocks[$delta]['search']['include_node'] = $edit['search_include_node'];
    $featured_blocks[$delta]['search']['num_words_in_title'] = $edit['num_words_in_title'];
  }

  // visibility settings
  $featured_blocks[$delta]['visibility']['content_types']['selected'] = $edit['visibility_content_types_selected'];
  $featured_blocks[$delta]['visibility']['users']['selected'] = $edit['visibility_users_selected'];
  foreach ($vocabularies as $vocabulary) {
    $vid = $vocabulary->vid;
    $featured_blocks[$delta]['visibility']['vocab'][$vid]['selected'] = $edit['visibility_vocab_' . $vid . '_selected'];
  }
  variable_set('featured_content_blocks', $featured_blocks);
}