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

Diff of /contributions/modules/ec_nodeaccess/ec_nodeaccess.module

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

revision 1.2.2.7, Sat Feb 28 15:28:18 2009 UTC revision 1.2.2.8, Sun Mar 1 01:23:05 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: ec_nodeaccess.module,v 1.2.2.6 2009/02/28 15:24:48 danielb Exp $  // $Id: ec_nodeaccess.module,v 1.2.2.7 2009/02/28 15:28:18 danielb Exp $
3    
4    
5  /**  /**
# Line 19  function ec_nodeaccess_perm() { Line 19  function ec_nodeaccess_perm() {
19    
20    
21  /**  /**
  * Implementation of hook_access().  
  */  
   
 function ec_nodeaccess_access($op, $node) {  
   global $user;  
 }  
   
   
 /**  
22   * @return list of information about Node Access Products   * @return list of information about Node Access Products
23   */   */
24    
# Line 89  function ec_nodeaccess_list() { Line 80  function ec_nodeaccess_list() {
80        $users_list, t('Users who have purchased this Node Access Product:'), 'ul', null) ."</div>";        $users_list, t('Users who have purchased this Node Access Product:'), 'ul', null) ."</div>";
81      $form['nap_fieldset_'. $node->nid]['access'] = array(      $form['nap_fieldset_'. $node->nid]['access'] = array(
82        '#value' => $output,        '#value' => $output,
83        );      );
84    }    }
85    return $form;    return $form;
86  }  }
# Line 251  function ec_nodeaccess_admin() { Line 242  function ec_nodeaccess_admin() {
242        '#type' => 'fieldset',        '#type' => 'fieldset',
243        '#attributes' => array('class' => 'views_fieldset'),        '#attributes' => array('class' => 'views_fieldset'),
244        '#title' => t('\'By View\' Settings'),        '#title' => t('\'By View\' Settings'),
245        '#weight' => -6,        '#weight' => -4,
246        '#collapsible' => TRUE,        '#collapsible' => TRUE,
247        '#collapsed' => FALSE,        '#collapsed' => FALSE,
248        '#description' => t('These settings refer to whether views will be displayed as options for granting access to on the Node Access products\' <i>add</i> and <i>edit</i> pages.'),        '#description' => t('These settings refer to whether views will be displayed as options for granting access to on the Node Access products\' <i>add</i> and <i>edit</i> pages.'),
249      );      );
250      $form['views_fieldset']['ec_nodeaccess_show_byviews'] = array(      $form['views_fieldset']['ec_nodeaccess_show_byviews'] = array(
251        '#type' => 'checkbox',        '#type' => 'checkbox',
252        '#title' => t('Show \'By Views\' options on the <i>add</i> and <i>edit</i> pages'),        '#title' => t('Show \'By View\' options on the <i>add</i> and <i>edit</i> pages'),
253        '#options' => array(        '#options' => array(
254        '1' => 'show',        '1' => 'show',
255        ),        ),
# Line 272  function ec_nodeaccess_admin() { Line 263  function ec_nodeaccess_admin() {
263        '#type' => 'fieldset',        '#type' => 'fieldset',
264        '#attributes' => array('class' => 'recur_fieldset'),        '#attributes' => array('class' => 'recur_fieldset'),
265        '#title' => t('\'Recurring Product\' Settings'),        '#title' => t('\'Recurring Product\' Settings'),
266        '#weight' => -4,        '#weight' => -2,
267        '#collapsible' => TRUE,        '#collapsible' => TRUE,
268        '#collapsed' => FALSE,        '#collapsed' => FALSE,
269        '#description' => t('Because the Recurring Product module is active, it is possible that a Node Access product be used in conjunction with Recurring product, effectively creating a subscription system.  These settings refer to how Node Access products should behave in regards to Recurring schedules.'),        '#description' => t('Because the Recurring Product module is active, it is possible that a Node Access product be used in conjunction with Recurring product, effectively creating a subscription system.  These settings refer to how Node Access products should behave in regards to Recurring schedules.'),
# Line 482  function ec_nodeaccess_form_alter($form_ Line 473  function ec_nodeaccess_form_alter($form_
473        if (count($views) > 1) {        if (count($views) > 1) {
474          $form['product']['nodeaccess']['views'] = array(          $form['product']['nodeaccess']['views'] = array(
475             '#type' => 'fieldset',             '#type' => 'fieldset',
476             '#title' => t('Advanced - Nodes that can be referenced (View)'),             '#title' => t('By View'),
477             '#collapsible' => TRUE,             '#collapsible' => TRUE,
478             '#collapsed' => $default_view == '',             '#collapsed' => ($default_view == '' && ($ec_nodeaccess_show_bycats || $ec_nodeaccess_show_bynodes)),
479              '#weight' => 4,
480           );           );
481          $form['product']['nodeaccess']['views']['ec_nodeaccess_view'] = array(          $form['product']['nodeaccess']['views']['ec_nodeaccess_view'] = array(
482            '#type' => 'select',            '#type' => 'select',
483            '#title' => t('View'),            '#title' => t('View'),
484            '#options' => $views,            '#options' => $views,
485            '#default_value' => $default_view,            '#default_value' => $default_view,
486            '#description' => t('Choose the "Views module" view that selects the nodes that can be purchased.<br>Note :<ul><li>This will discard the settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'),            '#description' => t('Select the view that chooses the nodes that buyers of this product will receive access to:</b> &nbsp;<br />If no view is selected this product is not a Node Access product.<br>Note :<ul><li>This will discard the settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'),
487          );          );
488          $form['product']['nodeaccess']['views']['ec_nodeaccess_view_args'] = array(          $form['product']['nodeaccess']['views']['ec_nodeaccess_view_args'] = array(
489            '#type' => 'textfield',            '#type' => 'textfield',
# Line 550  function ec_nodeaccess_nodeapi(&$node, $ Line 542  function ec_nodeaccess_nodeapi(&$node, $
542    switch ($op) {    switch ($op) {
543      case 'update':      case 'update':
544      case 'insert':      case 'insert':
545        ec_nodeaccess_save($node->nid, $node->ec_nodeaccess_nodes, $node->ec_nodeaccess_categories,  $node->ec_nodeaccess_view);        ec_nodeaccess_save($node->nid, $node->ec_nodeaccess_nodes, $node->ec_nodeaccess_categories,  $node->ec_nodeaccess_view, $node->ec_nodeaccess_view_args);
546        break;        break;
547    
548          node_access_rebuild();
549    }    }
550  }  }
551    
# Line 720  function ec_nodeaccess_cron() { Line 714  function ec_nodeaccess_cron() {
714      FROM {ec_nodeaccess_products}      FROM {ec_nodeaccess_products}
715      WHERE entry_id NOT IN (%s)", implode(", ", $safe_entry_ids));      WHERE entry_id NOT IN (%s)", implode(", ", $safe_entry_ids));
716    }    }
717      // This is to get the latest batch of nids from the views for user's access.
718      if (variable_get('ec_nodeaccess_show_byviews', '0') == '1' && module_exists('views')) {
719        node_access_rebuild();
720      }
721  }  }
722    
723    
# Line 761  function ec_nodeaccess_disabling($set = Line 759  function ec_nodeaccess_disabling($set =
759   * then calls node_access_rebuild() to update site-wide node access   * then calls node_access_rebuild() to update site-wide node access
760   */   */
761    
762  function ec_nodeaccess_save($nid, $nodes = array(), $categories = array(), $view = NULL) {  function ec_nodeaccess_save($nid, $nodes = array(), $categories = array(), $view = NULL, $view_args) {
763    if ($categories) {    if ($categories) {
764      $categories = array_filter($categories); // strips null/empty/false values      $categories = array_filter($categories); // strips null/empty/false values
765    }    }
# Line 782  function ec_nodeaccess_save($nid, $nodes Line 780  function ec_nodeaccess_save($nid, $nodes
780    }    }
781    if (!$previous) {    if (!$previous) {
782      // previous record does not match, means there are changes we need to save      // previous record does not match, means there are changes we need to save
783      $insertion = db_query("INSERT INTO {ec_nodeaccess_products} (nid, entry_date, categories, nodes, view, view_args) VALUES (%d, NOW(), '%s', '%s')", $nid, $categories, $nodes, $view, $view_args);      $insertion = db_query("INSERT INTO {ec_nodeaccess_products} (nid, entry_date, categories, nodes, view, view_args) VALUES (%d, NOW(), '%s', '%s', '%s', '%s')", $nid, $categories, $nodes, $view, $view_args);
784      if (!$insertion) {      if (!$insertion) {
785        drupal_set_message("There was a problem updating the database.  The node access options have not been saved.", error);        drupal_set_message("There was a problem updating the database.  The node access options have not been saved.", error);
786        return false;        return false;
# Line 806  function ec_nodeaccess_get_nap_settings( Line 804  function ec_nodeaccess_get_nap_settings(
804    if ($datetime == null) {    if ($datetime == null) {
805      $datetime = date('Y-m-d H:i:s'); //'now' in SQL datetime format      $datetime = date('Y-m-d H:i:s'); //'now' in SQL datetime format
806    }    }
807    $settings = db_fetch_array(db_query_range("SELECT categories, nodes, view, view_args,    $settings = db_fetch_array(db_query_range("SELECT categories, nodes, view, view_args
808      FROM {ec_nodeaccess_products}      FROM {ec_nodeaccess_products}
809      WHERE entry_date < '%s' AND nid = %d ORDER BY entry_date DESC", $datetime, $nid, 0, 1));      WHERE entry_date < '%s' AND nid = %d ORDER BY entry_date DESC", $datetime, $nid, 0, 1));
810    $settings['nodes'] = unserialize($settings['nodes']);    $settings['nodes'] = unserialize($settings['nodes']);
# Line 822  function ec_nodeaccess_get_nap_settings( Line 820  function ec_nodeaccess_get_nap_settings(
820   * Get an array of nids that are returned by the supplied view   * Get an array of nids that are returned by the supplied view
821   */   */
822    
823  function ec_nodeaccess_get_nids_from_view($view, $view_args) {  function ec_nodeaccess_get_nids_from_view($view_identifier, $view_args) {
824    
825      $view = views_get_view($view_identifier);
826    
827    // arguments for the view    // arguments for the view
828    $view_args = array_map(trim, explode(',', $view_args));    $view_args = array_map(trim, explode(',', $view_args));
829    
830    views_load_cache();    views_load_cache();
831    views_sanitize_view($view);    views_sanitize_view($view);
832    
833      if (!$view) {
834        return array();
835      }
836    
837    // make sure the fields get included in the query    // make sure the fields get included in the query
838    $view->page = true;    $view->page = true;
839    $view->page_type = 'list';    $view->page_type = 'list';

Legend:
Removed from v.1.2.2.7  
changed lines
  Added in v.1.2.2.8

  ViewVC Help
Powered by ViewVC 1.1.2