/** * Creates a node, then tests the statistics tokens generated from it. */ function testStatisticsTokenReplacement() { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); // Create user and node. $user = $this->drupalCreateUser(array('create page content')); $this->drupalLogin($user); $node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $user->id())); // Hit the node. $this->drupalGet('node/' . $node->id()); // Manually calling statistics.php, simulating ajax behavior. $nid = $node->id(); $post = http_build_query(array('nid' => $nid)); $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $client = \Drupal::service('http_client_factory')->fromOptions(['config/curl' => [CURLOPT_TIMEOUT => 10]]); $client->post($stats_path, array('headers' => $headers, 'body' => $post)); $statistics = statistics_get($node->id()); // Generate and test tokens. $tests = array(); $tests['[node:total-count]'] = 1; $tests['[node:day-count]'] = 1; $tests['[node:last-view]'] = format_date($statistics['timestamp']); $tests['[node:last-view:short]'] = format_date($statistics['timestamp'], 'short'); // Test to make sure that we generated something for each token. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { $output = \Drupal::token()->replace($input, array('node' => $node), array('langcode' => $language_interface->getId())); $this->assertEqual($output, $expected, format_string('Statistics token %token replaced.', array('%token' => $input))); } }
/** * Verifies node hit counter logging and script placement. */ function testLogging() { global $base_url; $path = 'node/' . $this->node->id(); $module_path = drupal_get_path('module', 'statistics'); $stats_path = $base_url . '/' . $module_path . '/statistics.php'; $expected_library = $module_path . '/statistics.js'; $expected_settings = '"statistics":{"data":{"nid":"' . $this->node->id() . '"}'; // Verify that logging scripts are not found on a non-node page. $this->drupalGet('node'); $this->assertNoRaw($expected_library, 'Statistics library JS not found on node page.'); $this->assertNoRaw($expected_settings, 'Statistics settings not found on node page.'); // Verify that logging scripts are not found on a non-existent node page. $this->drupalGet('node/9999'); $this->assertNoRaw($expected_library, 'Statistics library JS not found on non-existent node page.'); $this->assertNoRaw($expected_settings, 'Statistics settings not found on non-existent node page.'); // Verify that logging scripts are found on a valid node page. $this->drupalGet($path); $this->assertRaw($expected_library, 'Found statistics library JS on node page.'); $this->assertRaw($expected_settings, 'Found statistics settings on node page.'); // Manually call statistics.php to simulate ajax data collection behavior. $nid = $this->node->id(); $post = array('nid' => $nid); $this->client->post($stats_path, array('form_params' => $post)); $node_counter = statistics_get($this->node->id()); $this->assertIdentical($node_counter['totalcount'], '1'); }
/** * Tests the integration of the {node_counter} table in views. */ public function testNodeCounterIntegration() { $this->drupalLogin($this->webUser); $this->drupalGet('node/' . $this->node->id()); // Manually calling statistics.php, simulating ajax behavior. // @see \Drupal\statistics\Tests\StatisticsLoggingTest::testLogging(). global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $client = \Drupal::service('http_client_factory')->fromOptions(['config/curl', array(CURLOPT_TIMEOUT => 10)]); $client->post($stats_path, array('form_params' => array('nid' => $this->node->id()))); $this->drupalGet('test_statistics_integration'); $expected = statistics_get($this->node->id()); // Convert the timestamp to year, to match the expected output of the date // handler. $expected['timestamp'] = date('Y', $expected['timestamp']); foreach ($expected as $field => $value) { $xpath = "//div[contains(@class, views-field-{$field})]/span[@class = 'field-content']"; $this->assertFieldByXpath($xpath, $value, "The {$field} output matches the expected."); } $this->drupalLogout(); $this->drupalLogin($this->deniedUser); $this->drupalGet('test_statistics_integration'); $this->assertResponse(200); foreach ($expected as $field => $value) { $xpath = "//div[contains(@class, views-field-{$field})]/span[@class = 'field-content']"; $this->assertNoFieldByXpath($xpath, $value, "The {$field} output is not displayed."); } }
/** * Override or insert variables into the node template. */ function kurr_preprocess_node(&$variables) { if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) { $variables['classes_array'][] = 'node-full'; } $stats = statistics_get($variables['node']->nid); $variables['stats_total_count'] = $stats['totalcount']; }
/** * Verifies node hit counter logging and script placement. */ function testLogging() { $path = 'node/' . $this->node->id(); $module_path = drupal_get_path('module', 'statistics'); $stats_path = base_path() . $module_path . '/statistics.php'; $lib_path = base_path() . $module_path . '/statistics.js'; $expected_library = '/<script src=".*?' . preg_quote($lib_path, '/.') . '.*?">/is'; // Verify that logging scripts are not found on a non-node page. $this->drupalGet('node'); $settings = $this->getDrupalSettings(); $this->assertNoPattern($expected_library, 'Statistics library JS not found on node page.'); $this->assertFalse(isset($settings['statistics']), 'Statistics settings not found on node page.'); // Verify that logging scripts are not found on a non-existent node page. $this->drupalGet('node/9999'); $settings = $this->getDrupalSettings(); $this->assertNoPattern($expected_library, 'Statistics library JS not found on non-existent node page.'); $this->assertFalse(isset($settings['statistics']), 'Statistics settings not found on node page.'); // Verify that logging scripts are found on a valid node page. $this->drupalGet($path); $settings = $this->getDrupalSettings(); $this->assertPattern($expected_library, 'Found statistics library JS on node page.'); $this->assertIdentical($this->node->id(), $settings['statistics']['data']['nid'], 'Found statistics settings on node page.'); // Verify the same when loading the site in a non-default language. $this->drupalGet($this->language['langcode'] . '/' . $path); $settings = $this->getDrupalSettings(); $this->assertPattern($expected_library, 'Found statistics library JS on a valid node page in a non-default language.'); $this->assertIdentical($this->node->id(), $settings['statistics']['data']['nid'], 'Found statistics settings on valid node page in a non-default language.'); // Manually call statistics.php to simulate ajax data collection behavior. global $base_root; $post = array('nid' => $this->node->id()); $this->client->post($base_root . $stats_path, array('form_params' => $post)); $node_counter = statistics_get($this->node->id()); $this->assertIdentical($node_counter['totalcount'], '1'); }
/** * Override or insert variables into the node template. */ function adopted_preprocess_node(&$variables, $vars) { $node = $variables['node']; //print_r($node); if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) { $variables['classes_array'][] = 'node-full'; } $variables['date'] = t('!datetime', array('!datetime' => date('j F Y', $variables['created']))); //print_r($node); $nid = $node->nid; $stats = statistics_get($nid); $vars['stats_total_count'] = $stats['totalcount']; print $vars['stats_total_count']; }
function epf_preprocess_node(&$variables) { $node = $variables['node']; list(, , $bundle) = entity_extract_ids('node', $node); $output = ''; // $variables['ins']=$variables['content']['links']; foreach (field_info_instances('node', $bundle) as $instance) { if ($instance['field_name'] == 'authorname') { if (!empty($node->{$instance['field_name']})) { $variables['paper_authors'] = $node->{$instance['field_name']}['und'][0]['value']; } } if ($instance['field_name'] == 'field_reviewer') { if (!empty($node->{$instance['field_name']})) { $variables['reviewer'] = $node->{$instance['field_name']}['und'][0]['value']; } } if ($instance['field_name'] == 'datebegin') { if (!empty($node->{$instance['field_name']})) { $variables['datebegin'] = substr($node->{$instance['field_name']}['und'][0]['value'], 0, 10); } } if ($instance['field_name'] == 'dateend') { if (!empty($node->{$instance['field_name']})) { $variables['dateend'] = substr($node->{$instance['field_name']}['und'][0]['value'], 0, 10); } } if ($instance['field_name'] == 'city') { if (!empty($node->{$instance['field_name']})) { $variables['city'] = $node->{$instance['field_name']}['und'][0]['value']; } } if ($instance['field_name'] == 'website') { if (!empty($node->{$instance['field_name']})) { $variables['website'] = $node->{$instance['field_name']}['und'][0]['value']; } } if ($instance['widget']['module'] == 'arxiv') { if (!empty($node->{$instance['field_name']})) { $variables['paper_authors'] = $node->{$instance['field_name']}['und'][0]['authors']; } if (!empty($node->{$instance['field_name']}) && $node->{$instance['field_name']}['und'][0]['pdfUrl'] != '') { $output .= '<a href="' . url('/paper/download/' . $node->nid . '/pdf') . '" >pdf </a>'; } if (!empty($node->{$instance['field_name']}) && $node->{$instance['field_name']}['und'][0]['psUrl'] != '') { $output .= '<a href="' . url('/paper/download/' . $node->nid . '/ps') . '" >ps </a>'; } if (!empty($node->{$instance['field_name']}) && $node->{$instance['field_name']}['und'][0]['otherUrl'] != '') { $output .= '<a href="' . url('/paper/download/' . $node->nid . '/other') . '" >other </a>'; } } if ($instance['field_name'] == 'field_author') { if (!empty($node->{$instance['field_name']})) { $variables['paper_authors'] = $node->{$instance['field_name']}['und'][0]['value']; } } if ($instance['field_name'] == 'field_upload') { if (!empty($node->{$instance['field_name']}) && $node->{$instance['field_name']}['und'][0]['filename'] != '') { $url = file_create_url($node->{$instance['field_name']}['und'][0]['uri']); $output .= '<a href="' . url('/paper/download/' . $node->nid) . '" >download </a>'; } } if ($instance['field_name'] == 'field_prefix') { if (!empty($node->{$instance['field_name']})) { $variables['news_prefix'] = $node->{$instance['field_name']}['und'][0]['value']; } } } if (substr($node->type, 0, 5) == 'paper') { $statistics = statistics_get($node->nid); $obj = db_select('arxiv_downNo', 'm')->fields('m', array('downloadNo'))->condition('m.nid', $node->nid)->execute()->fetchAll(); if ($obj) { $variables['download'] = $output . ' (' . (empty($statistics['totalcount']) ? 0 : $statistics['totalcount']) . ' views, ' . $obj[0]->downloadNo . ' download, ' . $node->comment_count . ' comments)'; } else { $variables['download'] = $output . ' (' . (empty($statistics['totalcount']) ? 0 : $statistics['totalcount']) . ' views, 0 download, ' . $node->comment_count . ' comments)'; } } if ($variables['page']) { $variables['submitted'] = t('posted on !datetime', array('!datetime' => $variables['date'])); } else { $variables['submitted'] = t('posted by !username, !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date'])); } }
?> <div id="node-<?php print $node->nid; ?> " class="<?php print $classes; ?> clearfix node-<?php print $node->nid; ?> " role="article"<?php print $attributes; ?> > <?php $hitcount = statistics_get($node->nid); unset($content['links']['statistics']); if ($title || $user_picture || $display_submitted) { ?> <header class="node-header clearfix"> <!-- Node title --> <?php if ($title && !$page) { print render($title_prefix); ?> <h3 class="title node-title"<?php print $title_attributes; ?> > <a href="<?php print $node_url;
$vote = $vote3['count']; } if ($result['fields']['sis_ratings'] == '0') { $vote = 0; } $votes = '<span style="margin-left: 20px;">(' . $vote . ' votes)</span>'; $vote = 0; if ($result[type] == 'Dataset' && $value != 0) { print '<div style="width:100px; float:right;">' . theme('fivestar_static', $result['fields']['sis_ratings']) . $votes . '</div>'; } print '<div style="width:580px; float:left ">' . strip_tags($text) . '<br/></div>'; /* */ $teaser = FALSE; $page = TRUE; $thisNode = node_build_content($thisNode, $teaser, $page); $statistics = statistics_get($thisNode->nid); if ($statistics == null) { $total_count = 0; } else { $total_count = $statistics['totalcount']; } //Popularity // print '<div class="item list-bullet" style="width:65px; margin-left: 55px;">'..'</div>'; if ($result[type] == 'Dataset') { print '<div class="item list-bullet" style="width:220px; font-size:1em; padding-bottom:0px; "><a title="' . $thisNode->field_ds_agency_name[0][safe][title] . '" href="' . $base_url . '/search/apachesolr_search/?filters=is_cck_field_ds_agency_name%3A' . $thisNode->field_ds_agency_name[0][safe][nid] . '">' . $thisNode->field_ds_agency_name[0][safe][title] . '</a></div>'; } //FileFormat //print_r($thisNode); print '</div></div>'; } // print '<br/><br/>';