From d7a23def7e82e74113ac31629d7f656f04fd4e3e Mon Sep 17 00:00:00 2001 From: Lorenz Schori Date: Mon, 21 Jan 2013 08:13:09 +0100 Subject: [PATCH 3/6] Update authcache poll stuff for drupal 7 --- ajax/authcache.php | 11 ++++++++--- authcache.js | 26 ++++++-------------------- authcache.module | 29 ++++++++++++++++++----------- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/ajax/authcache.php b/ajax/authcache.php index 2f48a1b..82d6a0f 100644 --- a/ajax/authcache.php +++ b/ajax/authcache.php @@ -227,12 +227,17 @@ function _authcache_poll($vars) { // FULL bootstrap required in case custom theming is used drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $node = node_load($vars['nid']); - $node = poll_view($node, TRUE, FALSE, $vars['block']); - $output = $node->content['body']['#value']; + $build = node_view($node); + + if (isset($build['poll_view_voting'])) { + $output = render($build['poll_view_voting']); + } + elseif (isset($build['poll_view_results'])) { + $output = render($build['poll_view_results']); + } return array( 'nid' => $vars['nid'], - 'block' => $vars['block'], 'html' => $output, ); } diff --git a/authcache.js b/authcache.js index bc92e42..3cfae06 100644 --- a/authcache.js +++ b/authcache.js @@ -138,21 +138,12 @@ Authcache.init.preprocess = function() { }); // Get poll results/form - if (jQuery("#block-poll-0").length || jQuery("#poll-view-voting").length) { - jQuery(".poll").each(function(i, el) { - elNid = jQuery(el).find(".authcache-poll"); - nid = elNid.get(0).getAttribute("data-nid"); + jQuery(".authcache-poll").each(function() { + var nid = jQuery(this).attr('data-nid'); + ajaxJson = {'poll[nid]': nid} - ajaxJson = { - 'poll[nid]' : nid, - 'poll[block]' : jQuery(el).parents(".block-inner").length, - 'time' : jQuery.cookie('nid' + nid), - 'max_age' : 600 - }; - - Authcache.ajaxRequest(ajaxJson); - }); - } + Authcache.ajaxRequest(ajaxJson); + }); }; @@ -306,12 +297,7 @@ function _authcache_forum_topic_info(vars) { * @see poll.module */ function _authcache_poll(vars) { - if (vars.block == 1) { - jQuery("#block-poll-0 .poll").html(vars.html); - } - else { - jQuery("#node-" + vars.nid + " .poll").html(vars.html); - } + jQuery('.authcache-poll[data-nid="' + vars.nid + '"]').html(vars.html); } /** diff --git a/authcache.module b/authcache.module index 2c74a55..f9bb582 100644 --- a/authcache.module +++ b/authcache.module @@ -482,6 +482,24 @@ function authcache_comment_view_alter(&$build) { } } +function authcache_node_view_alter(&$build) { + global $_authcache_is_ajax; + $node = $build['#node']; + + if ($node->type == 'poll' && !$_authcache_is_ajax) { + if (isset($build['poll_view_voting'])) { + $build['poll_view_voting'] = array( + '#markup' => '', + ); + } + if (isset($build['poll_view_results'])) { + $build['poll_view_results'] = array( + '#markup' => '', + ); + } + } +} + /** * Implements hook_exit(). * @@ -656,17 +674,6 @@ function authcache_preprocess_forum_topic_list(&$variables) { } } -/** - * Save poll node id - * - * @see poll.module - */ -function authcache_preprocess_poll_vote(&$variables) { - if ($variables['authcache_is_cacheable'] === true) { - $variables['choice'] .= ''; - } -} - // // Authcache hooks // -- 1.7.10.4