/[drupal]/contributions/modules/adlib/adlib.module
ViewVC logotype

Diff of /contributions/modules/adlib/adlib.module

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

revision 1.9, Thu Apr 30 15:06:31 2009 UTC revision 1.10, Fri May 1 03:46:15 2009 UTC
# Line 117  function adlib_form_alter($form_id, &$fo Line 117  function adlib_form_alter($form_id, &$fo
117    elseif ($is_node_form || variable_get('adlib_forms', ADLIB_FORMS_NODE_ONLY) == ADLIB_FORMS_ALL) {    elseif ($is_node_form || variable_get('adlib_forms', ADLIB_FORMS_NODE_ONLY) == ADLIB_FORMS_ALL) {
118      // If this form already has an adlib, apply it.      // If this form already has an adlib, apply it.
119      $language = isset($form['#node']) && isset($form['#node']->language)? $form['#node']->language : NULL;      $language = isset($form['#node']) && isset($form['#node']->language)? $form['#node']->language : NULL;
120      if (user_access('use adlibs') && $adlib_node = adlib_get_adlib_node($form_id, $language)) {      if (user_access('use adlibs') && $adlib_node = adlib_get_adlib_node($form_id, $language, $form['#node'])) {
121          $form['#adlib'] = check_markup($adlib_node->body, $adlib_node->format);
122        $form['#adlib'] = $adlib_node->body;        $form['#adlib'] = $adlib_node->body;
123        $form['#pre_render'][] = 'adlib_add_adlib';        $form['#pre_render'][] = 'adlib_add_adlib';
124      }      }
# Line 160  function adlib_form_alter($form_id, &$fo Line 161  function adlib_form_alter($form_id, &$fo
161   * Get the adlib node for a given form. If translation is available,   * Get the adlib node for a given form. If translation is available,
162   * a translation in the requested language will be returned if present.   * a translation in the requested language will be returned if present.
163   */   */
164  function adlib_get_adlib_node($form_id, $language) {  function adlib_get_adlib_node($form_id, $language, $content_node) {
165    $adlib_type = variable_get('adlib_type', 'adlib');    $adlib_type = variable_get('adlib_type', 'adlib');
166    
167    if ($node = node_load(array('type' => $adlib_type, 'title' => $form_id))) {    if ($node = node_load(array('type' => $adlib_type, 'title' => $form_id))) {
# Line 168  function adlib_get_adlib_node($form_id, Line 169  function adlib_get_adlib_node($form_id,
169      if ($language && isset($node->translation) && isset($node->translation[$language])) {      if ($language && isset($node->translation) && isset($node->translation[$language])) {
170        $node = node_load($node->translation[$language]->nid);        $node = node_load($node->translation[$language]->nid);
171      }      }
172        // Allow other modules to alter the adlib.
173        // When updating to D6, use drupal_alter().
174        adlib_alter($node, $form_id, $language, $content_node);
175      return $node;      return $node;
176    }    }
177    return FALSE;    return FALSE;
178  }  }
179    
180  /**  /**
181     * Backport of drupal_alter().
182     */
183    function adlib_alter(&$data) {
184      // Hang onto a reference to the data array so that it isn't blown away later.
185      // Also, merge in any parameters that need to be passed by reference.
186      $args = array(&$data);
187      if (isset($by_ref_parameters)) {
188        $args = array_merge($args, $by_ref_parameters);
189      }
190    
191      // Now, use func_get_args() to pull in any additional parameters passed into
192      // the drupal_alter() call.
193      $additional_args = func_get_args();
194      array_shift($additional_args);
195      $args = array_merge($args, $additional_args);
196    
197      foreach (module_implements('adlib_alter') as $module) {
198        $function = $module . '_adlib_alter';
199        call_user_func_array($function, $args);
200      }
201    }
202    
203    /**
204   * Implementation of hook_nodeapi().   * Implementation of hook_nodeapi().
205   *   *
206   * For content types with adlibs, display the adlib.   * For content types with adlibs, display the adlib.
# Line 212  function adlib_nodeapi(&$node, $op, $tea Line 239  function adlib_nodeapi(&$node, $op, $tea
239        else {        else {
240          $form_id = $node->type . '_node_form';          $form_id = $node->type . '_node_form';
241          // If this node type already has an adlib, apply it.          // If this node type already has an adlib, apply it.
242          if ($adlib_type && $adlib_node = adlib_get_adlib_node($form_id, $node->language ? $node->language : NULL)) {          if ($adlib_type && $adlib_node = adlib_get_adlib_node($form_id, $node->language ? $node->language : NULL, $node)) {
243            $adlib = $adlib_node->body;            $adlib = $adlib_node->body;
244            if ($matches = _adlib_get_matches($adlib)) {            if ($matches = _adlib_get_matches($adlib)) {
245              foreach ($matches as $match) {              foreach ($matches as $match) {
# Line 227  function adlib_nodeapi(&$node, $op, $tea Line 254  function adlib_nodeapi(&$node, $op, $tea
254        break;        break;
255      // Support for i18n translation module.      // Support for i18n translation module.
256      // When updating to D6, change this to 'prepare translation' op.      // When updating to D6, change this to 'prepare translation' op.
257        // In D5 this is somewhat fragile as it depends on our changes
258        // happening after the translation module (by module weight).
259      case 'prepare':      case 'prepare':
260        if (isset($node->translation_source) && !empty($_GET['language']) && $node->type == variable_get('adlib_type', 'adlib')) {        if (isset($node->translation_source) && !empty($_GET['language']) && $node->type == variable_get('adlib_type', 'adlib')) {
261          // We are translating a node from a source node.          // We are translating a node from a source node.
262          $node->title = $node->translation_source->title . '_' . $_GET['language'];          $node->title = $node->translation_source->title . ' ' . $_GET['language'];
263        }        }
264        break;        break;
265    }    }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.2