/**
  * Generate a settings form for this handler.
  */
 public function settingsForm($field, $instance)
 {
     #    echo '<pre>';
     #    print_r($instance);
     #    echo '</pre>';
     #    die;
     $options = array();
     if (!empty($field['settings']['handler_settings']['target_bundles'])) {
         $target_bundles = $field['settings']['handler_settings']['target_bundles'];
     } else {
         // By default, entity reference assumes that all bundles are enabled.
         $target_bundles = array_keys(node_type_get_types());
     }
     foreach ($target_bundles as $content_type) {
         $options[$content_type] = t(node_type_get_name($content_type));
     }
     $default_options = array();
     if (isset($instance['settings']['behaviors']['node_links'])) {
         foreach ($instance['settings']['behaviors']['node_links']['content_types'] as $content_type) {
             if ($content_type) {
                 $default_options[] = $content_type;
             }
         }
     }
     $form['content_types'] = array('#type' => 'checkboxes', '#title' => t('Content Types'), '#options' => $options, '#default_value' => $default_options, '#description' => t('Select the content types that will have create links for this type.'));
     return $form;
 }
Example #2
0
/**
 * Execute a search for a set of key words.
 *
 * We call do_search() with the keys, the module name, and extra SQL fragments
 * to use when searching. See hook_update_index() for more information.
 *
 * @param $keys
 *   The search keywords as entered by the user.
 *
 * @return
 *   An array of search results. To use the default search result
 *   display, each item should have the following keys':
 *   - 'link': Required. The URL of the found item.
 *   - 'type': The type of item.
 *   - 'title': Required. The name of the item.
 *   - 'user': The author of the item.
 *   - 'date': A timestamp when the item was last modified.
 *   - 'extra': An array of optional extra information items.
 *   - 'snippet': An excerpt or preview to show with the result (can be
 *     generated with search_excerpt()).
 *
 * @ingroup search
 */
function hook_search_execute($keys = NULL)
{
    // Build matching conditions
    $query = db_search()->extend('PagerDefault');
    $query->join('node', 'n', 'n.nid = i.sid');
    $query->condition('n.status', 1)->addTag('node_access')->searchExpression($keys, 'node');
    // Insert special keywords.
    $query->setOption('type', 'n.type');
    $query->setOption('language', 'n.language');
    if ($query->setOption('term', 'ti.tid')) {
        $query->join('taxonomy_index', 'ti', 'n.nid = ti.nid');
    }
    // Only continue if the first pass query matches.
    if (!$query->executeFirstPass()) {
        return array();
    }
    // Add the ranking expressions.
    _node_rankings($query);
    // Add a count query.
    $inner_query = clone $query;
    $count_query = db_select($inner_query->fields('i', array('sid')));
    $count_query->addExpression('COUNT(*)');
    $query->setCountQuery($count_query);
    $find = $query->limit(10)->execute();
    // Load results.
    $results = array();
    foreach ($find as $item) {
        // Build the node body.
        $node = node_load($item->sid);
        node_build_content($node, 'search_result');
        $node->body = drupal_render($node->content);
        // Fetch comments for snippet.
        $node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node);
        // Fetch terms for snippet.
        $node->rendered .= ' ' . module_invoke('taxonomy', 'node_update_index', $node);
        $extra = module_invoke_all('node_search_result', $node);
        $results[] = array('link' => url('node/' . $item->sid, array('absolute' => TRUE)), 'type' => check_plain(node_type_get_name($node)), 'title' => $node->title, 'user' => theme('username', array('account' => $node)), 'date' => $node->changed, 'node' => $node, 'extra' => $extra, 'score' => $item->calculated_score, 'snippet' => search_excerpt($keys, $node->body));
    }
    return $results;
}
Example #3
0
/**
 * Prepare a message based on parameters; called from drupal_mail().
 *
 * Note that hook_mail(), unlike hook_mail_alter(), is only called on the
 * $module argument to drupal_mail(), not all modules.
 *
 * @param $key
 *   An identifier of the mail.
 * @param $message
 *   An array to be filled in. Elements in this array include:
 *   - id: An ID to identify the mail sent. Look at module source code
 *     or drupal_mail() for possible id values.
 *   - to: The address or addresses the message will be sent to. The formatting
 *     of this string will be validated with the
 *     @link http://php.net/manual/filter.filters.validate.php PHP e-mail validation filter. @endlink
 *   - subject: Subject of the e-mail to be sent. This must not contain any
 *     newline characters, or the mail may not be sent properly. drupal_mail()
 *     sets this to an empty string when the hook is invoked.
 *   - body: An array of lines containing the message to be sent. Drupal will
 *     format the correct line endings for you. drupal_mail() sets this to an
 *     empty array when the hook is invoked.
 *   - from: The address the message will be marked as being from, which is
 *     set by drupal_mail() to either a custom address or the site-wide
 *     default email address when the hook is invoked.
 *   - headers: Associative array containing mail headers, such as From,
 *     Sender, MIME-Version, Content-Type, etc. drupal_mail() pre-fills
 *     several headers in this array.
 * @param $params
 *   An array of parameters supplied by the caller of drupal_mail().
 */
function hook_mail($key, &$message, $params)
{
    $account = $params['account'];
    $context = $params['context'];
    $variables = array('%site_name' => variable_get('site_name', 'Drupal'), '%username' => format_username($account));
    if ($context['hook'] == 'taxonomy') {
        $entity = $params['entity'];
        $vocabulary = taxonomy_vocabulary_load($entity->vid);
        $variables += array('%term_name' => $entity->name, '%term_description' => $entity->description, '%term_id' => $entity->tid, '%vocabulary_name' => $vocabulary->name, '%vocabulary_description' => $vocabulary->description, '%vocabulary_id' => $vocabulary->vid);
    }
    // Node-based variable translation is only available if we have a node.
    if (isset($params['node'])) {
        $node = $params['node'];
        $variables += array('%uid' => $node->uid, '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)), '%node_type' => node_type_get_name($node), '%title' => $node->title, '%teaser' => $node->teaser, '%body' => $node->body);
    }
    $subject = strtr($context['subject'], $variables);
    $body = strtr($context['message'], $variables);
    $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
    $message['body'][] = drupal_html_to_text($body);
}
<article id="node-<?php 
print $node->nid;
?>
" class="<?php 
print $classes;
?>
 clearfix"<?php 
print $attributes;
?>
>
  <div class="node-list taxonomy-generic">
    <?php 
if (!empty($title)) {
    ?>
      <h3><?php 
    print node_type_get_name($node);
    ?>
</h3>
      <h2<?php 
    print $title_attributes;
    ?>
><a href="<?php 
    print $node_url;
    ?>
"><?php 
    print $title;
    ?>
</a></h2>
    <?php 
}
?>
Example #5
0
/**
 * Define a custom search routine.
 *
 * This hook allows a module to perform searches on content it defines
 * (custom node types, users, or comments, for example) when a site search
 * is performed.
 *
 * Note that you can use form API to extend the search. You will need to use
 * hook_form_alter() to add any additional required form elements. You can
 * process their values on submission using a custom validation function.
 * You will need to merge any custom search values into the search keys
 * using a key:value syntax. This allows all search queries to have a clean
 * and permanent URL. See node_form_search_form_alter() for an example.
 *
 * The example given here is for node.module, which uses the indexed search
 * capabilities. To do this, node module also implements hook_update_index()
 * which is used to create and maintain the index.
 *
 * We call do_search() with the keys, the module name, and extra SQL fragments
 * to use when searching. See hook_update_index() for more information.
 *
 * @param $op
 *   A string defining which operation to perform:
 *   - 'admin': The hook should return a form array containing any fieldsets the
 *     module wants to add to the Search settings page at admin/settings/search.
 *   - 'name': The hook should return a translated name defining the type of
 *     items that are searched for with this module ('content', 'users', ...).
 *   - 'reset': The search index is going to be rebuilt. Modules which use
 *     hook_update_index() should update their indexing bookkeeping so that it
 *     starts from scratch the next time hook_update_index() is called.
 *   - 'search': The hook should perform a search using the keywords in $keys.
 *   - 'status': If the module implements hook_update_index(), it should return
 *     an array containing the following keys:
 *     - remaining: The amount of items that still need to be indexed.
 *     - total: The total amount of items (both indexed and unindexed).
 * @param $keys
 *   The search keywords as entered by the user.
 * @return
 *   This varies depending on the operation.
 *   - 'admin': The form array for the Search settings page at
 *     admin/settings/search.
 *   - 'name': The translated string of 'Content'.
 *   - 'reset': None.
 *   - 'search': An array of search results. To use the default search result
 *     display, each item should have the following keys':
 *     - 'link': Required. The URL of the found item.
 *     - 'type': The type of item.
 *     - 'title': Required. The name of the item.
 *     - 'user': The author of the item.
 *     - 'date': A timestamp when the item was last modified.
 *     - 'extra': An array of optional extra information items.
 *     - 'snippet': An excerpt or preview to show with the result (can be
 *     generated with search_excerpt()).
 *   - 'status': An associative array with the key-value pairs:
 *     - 'remaining': The number of items left to index.
 *     - 'total': The total number of items to index.
 *
 * @ingroup search
 */
function hook_search($op = 'search', $keys = NULL)
{
    switch ($op) {
        case 'name':
            return t('Content');
        case 'reset':
            db_query("UPDATE {search_dataset} SET reindex = %d WHERE type = 'node'", REQUEST_TIME);
            return;
        case 'status':
            $total = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1'));
            $remaining = db_result(db_query("SELECT COUNT(*) FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE n.status = 1 AND d.sid IS NULL OR d.reindex <> 0"));
            return array('remaining' => $remaining, 'total' => $total);
        case 'admin':
            $form = array();
            // Output form for defining rank factor weights.
            $form['content_ranking'] = array('#type' => 'fieldset', '#title' => t('Content ranking'));
            $form['content_ranking']['#theme'] = 'node_search_admin';
            $form['content_ranking']['info'] = array('#value' => '<em>' . t('The following numbers control which properties the content search should favor when ordering the results. Higher numbers mean more influence, zero means the property is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . '</em>');
            // Note: reversed to reflect that higher number = higher ranking.
            $options = drupal_map_assoc(range(0, 10));
            foreach (module_invoke_all('ranking') as $var => $values) {
                $form['content_ranking']['factors']['node_rank_' . $var] = array('#title' => $values['title'], '#type' => 'select', '#options' => $options, '#default_value' => variable_get('node_rank_' . $var, 0));
            }
            return $form;
        case 'search':
            // Build matching conditions
            list($join1, $where1) = _db_rewrite_sql();
            $arguments1 = array();
            $conditions1 = 'n.status = 1';
            if ($type = search_query_extract($keys, 'type')) {
                $types = array();
                foreach (explode(',', $type) as $t) {
                    $types[] = "n.type = '%s'";
                    $arguments1[] = $t;
                }
                $conditions1 .= ' AND (' . implode(' OR ', $types) . ')';
                $keys = search_query_insert($keys, 'type');
            }
            if ($category = search_query_extract($keys, 'category')) {
                $categories = array();
                foreach (explode(',', $category) as $c) {
                    $categories[] = "tn.tid = %d";
                    $arguments1[] = $c;
                }
                $conditions1 .= ' AND (' . implode(' OR ', $categories) . ')';
                $join1 .= ' INNER JOIN {taxonomy_term_node} tn ON n.vid = tn.vid';
                $keys = search_query_insert($keys, 'category');
            }
            if ($languages = search_query_extract($keys, 'language')) {
                $categories = array();
                foreach (explode(',', $languages) as $l) {
                    $categories[] = "n.language = '%s'";
                    $arguments1[] = $l;
                }
                $conditions1 .= ' AND (' . implode(' OR ', $categories) . ')';
                $keys = search_query_insert($keys, 'language');
            }
            // Get the ranking expressions.
            $rankings = _node_rankings();
            // When all search factors are disabled (ie they have a weight of zero),
            // The default score is based only on keyword relevance.
            if ($rankings['total'] == 0) {
                $total = 1;
                $arguments2 = array();
                $join2 = '';
                $select2 = 'i.relevance AS score';
            } else {
                $total = $rankings['total'];
                $arguments2 = $rankings['arguments'];
                $join2 = implode(' ', $rankings['join']);
                $select2 = '(' . implode(' + ', $rankings['score']) . ') AS score';
            }
            // Do search.
            $find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid ' . $join1, $conditions1 . (empty($where1) ? '' : ' AND ' . $where1), $arguments1, $select2, $join2, $arguments2);
            // Load results.
            $results = array();
            foreach ($find as $item) {
                // Build the node body.
                $node = node_load($item->sid);
                $node = node_build_content($node, 'search_result');
                $node->body = drupal_render($node->content);
                // Fetch comments for snippet.
                $node->body .= module_invoke('comment', 'node', $node, 'update_index');
                // Fetch terms for snippet.
                $node->body .= module_invoke('taxonomy', 'node', $node, 'update_index');
                $extra = module_invoke_all('node_search_result', $node);
                $results[] = array('link' => url('node/' . $item->sid, array('absolute' => TRUE)), 'type' => check_plain(node_type_get_name($node)), 'title' => $node->title, 'user' => theme('username', $node), 'date' => $node->changed, 'node' => $node, 'extra' => $extra, 'score' => $total ? $item->score / $total : 0, 'snippet' => search_excerpt($keys, $node->body));
            }
            return $results;
    }
}
/**
 * Implements hook_form_FORM_ID_alter() on the Subscriptions delete form
 */
function opbamboo_form_subscriptions_del_form_alter(&$form, &$form_state)
{
    // dpm(compact('form','form_state'),__FUNCTION__);
    if (empty($form['data']['#value'][1])) {
        dpm(compact('form', 'form_state'), __FUNCTION__ . ' no subscription key? form[data][#value][1] is empty');
    } elseif ($form['data']['#value'][1] == 'nid') {
        if ($node = node_load($form['data']['#value'][2])) {
            drupal_set_title('Unfollow <em>' . filter_xss($node->title) . '</em>', PASS_THROUGH);
        }
    } elseif ($form['data']['#value'][1] == 'type') {
        $type = $form['data']['#value'][2];
        if ($type_name = node_type_get_name($type)) {
            $op_forum = op_common_op_forum_load($type);
            $nouns = isset($op_forum->nouns) ? $op_forum->nouns : 'proposals';
            drupal_set_title('Unfollow all <em>' . filter_xss($type_name) . '</em> ' . $nouns, PASS_THROUGH);
        }
    } elseif ($form['data']['#value'][1] == 'gid') {
        $gid = $form['data']['#value'][2];
        if ($group = opg_core_gid_to_group($gid) and $opg = opg_core_load_opg($group)) {
            drupal_set_title('Unfollow all <em>' . filter_xss($opg['label']) . '</em> ' . $opg['nouns'], PASS_THROUGH);
            $form['description']['#markup'] = 'Are you sure you want to stop following this ' . $opg['lcgroupword'] . '?';
        }
    }
    if ($form['actions']['submit']['#value'] == 'Unsubscribe') {
        $form['actions']['submit']['#value'] = 'Unfollow';
    }
    // make it look buttony - ?
    $form['actions']['cancel']['#attributes']['class'][] = 'btn';
}
<?php 
if (isset($content['field_flickr'])) {
    ?>
  <?php 
    print drupal_render($content['field_flickr']);
}
?>

<?php 
if (isset($content['field_internal_contents'])) {
    $internal = $content['field_internal_contents'];
    $content_type = '';
    foreach ($internal['#items'] as $key => $value) {
        $node = node_load($internal['#items'][$key]['target_id']);
        $type = node_type_get_name($node);
        if ($content_type != $type) {
            echo $type;
            $content_type = $type;
        }
        echo '<div>' . $internal[$key]['#markup'] . '</div>';
    }
}
?>

<?php 
if (isset($content['field_file'])) {
    ?>
  <?php 
    print drupal_render($content['field_file']);
}
Example #8
0
/**
 * Overriding alendar links above the pager.
 */
function glossy_preprocess_date_views_pager(&$vars) {
  $view = $vars['plugin']->view;
  if ($view->plugin_name != 'calendar_style') {
    return;
  }
  $options = $view->style_options;

  // If we're not on a view with a path (a page), no links are needed.
  $current_path = !empty($view->display_handler->options['path']) ? $view->display_handler->options['path'] : '';
  if (empty($current_path)) {
    return;
  }
  // Find all the displays in this view that use the calendar style and have a path and create links to each.
  $calendar_links = array();
  $base = array('attributes' => array('rel' => 'nofollow'));
  foreach($view->display as $id => $display) {

    if ($display->display_options['style_plugin'] == 'calendar_style' && !empty($display->display_options['path'])) {
      $path = $display->display_options['path'];
      $title = $display->display_title;
      // @TODO Why is this sometimes empty for a style that uses the default value?
      $type = !empty($display->display_options['style_options']['calendar_type']) ? $display->display_options['style_options']['calendar_type'] : 'month';

      // Make sure the links to other calendar displays use the right path for that display.
      // Get rid of pager links when swapping between displays to force the base argument 
      // to be structured correctly for the type of display. This means you can't use
      // these links in a block or panel.
      $href = str_replace($current_path, $path, date_pager_url($view, $type, NULL, TRUE));

      // Once we have a path for the links to other displays, add it to our links array.
      $calendar_links['calendar calendar-'. $type] = array('title' => $title, 'href' => $href);
    }
  }

  // If an 'Add new ... link is provided, add it here.
  // the query will bring the user back here after adding the node.
  if (!empty($view->date_info->calendar_date_link) 
  && (user_access("administer nodes") || user_access('create '. $view->date_info->calendar_date_link .' content'))) {
    $name = node_type_get_name($view->date_info->calendar_date_link);
    $href = 'node/add/' . str_replace('_', '-', $view->date_info->calendar_date_link);
    $query = drupal_get_query_parameters(array('destination' => $view->date_info->url));    
    $calendar_links['calendar calendar-add'] = $base + array(
      'title' => t('Add+'), 
      'href' => $href, 
      'query' => $query,
      );
  }

  // Append the calendar links above the pager.
	$type = arg(1);
	$type = isset($type) && in_array($type, array('day', 'week', 'month', 'year')) ? $type : '';
  $links = array(
    'links' => $calendar_links, 
    'attributes' => array('class' => array('calendar-links', 'item-list', $type, 'clearfix')),
  );
  $vars['pager_prefix'] = theme('links', $links);
}
Example #9
0
/**
 * Hook invoked when a signup is being created to gather other signup data.
 *
 * This hook allows other modules to inject information into the custom signup
 * data for each signup.  The array is merged with the values of any custom
 * fields from theme_signup_user_form(), serialized, and stored in the
 * {signup_log} database table.
 *
 * @param stdClass $node
 *   Fully-loaded node object being signed up to.
 * @param stdClass $account
 *   Full-loaded user object who is signing up.
 *
 * @return array
 *   Keyed array of fields to include in the custom data for this signup. The
 *   keys for the array are used as labels when displaying the field, so they
 *   should be human-readable (and wrapped in t() to allow translation).
 *
 * @see signup_sign_up_user()
 * @see theme_signup_user_form()
 */
function hook_signup_sign_up($node, $account)
{
    return array(t('Node type') => node_type_get_name($node->type), t('User created') => format_date($account->created));
}