From 662824ef608d810b86f6ecc9e94b1199f77af769 Mon Sep 17 00:00:00 2001 From: Astiii Date: Thu, 3 May 2012 18:43:20 +0300 Subject: [PATCH 1/2] Update shrtr.module --- shrtr.module | 58 ++++++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/shrtr.module b/shrtr.module index d6f4496..dd99efd 100644 --- a/shrtr.module +++ b/shrtr.module @@ -7,6 +7,7 @@ function shrtr_permission() { ), ); } + /** * Implements hook_menu(). */ @@ -34,26 +35,12 @@ function shrtr_menu() { 'page callback' => 'shrtr_list_page', 'access arguments' => array('access content'), ); - $items['admin/config/content/shrtr'] = array( - 'title' => 'Expire time enable/disable', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('shrtr_admin_page'), - 'access arguments' => array('access content'), - ); - return $items; -} -function shrtr_admin_page(){ -$form['shrtr_expire_disable'] = array( - '#type' => 'checkbox', - '#default_value' => variable_get('shrtr_expire_disable',0), - '#title' => t('Expire Time Disable'), -); -return system_settings_form($form); + return $items; } /** - * Returns a form array for submit new ULR-s. + * Returns a form array for submit new URL-s. */ function shrtr_new_form($form = array(), &$form_state) { $form['url'] = array( @@ -65,20 +52,17 @@ function shrtr_new_form($form = array(), &$form_state) { $form['message'] = array( '#markup' => t('Give a URL to shorten.'), ); - $enable_disable = variable_get('shrtr_expire_disable', 0); - if($enable_disable == 0){ - $form['expire'] = array( - '#type' => 'select', - '#title' => t('Expire'), - '#options' => array( - 0 => t('Never'), - 600 => '10' . t('min'), - 1200 => '20' . t('min'), - ), - '#default_value' => 0, - '#description' => t('Time to expire'), - ); - } + $form['expire'] = array( + '#type' => 'select', + '#title' => t('Expire'), + '#options' => array( + 0 => t('Never'), + 600 => '10' . t('min'), + 1200 => '20' . t('min'), + ), + '#default_value' => 0, + '#description' => t('Time to expire'), + ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), @@ -136,6 +120,7 @@ function shrtr_new_form_submit($form, &$form_state) { 'uid' => $user->uid, 'created' => REQUEST_TIME, 'expire' => $expire, + 'hits' => $hits, 'alias' => $alias, ); @@ -149,12 +134,17 @@ function shrtr_new_form_submit($form, &$form_state) { */ function shrtr_goto($alias) { $result = db_select('shrtr_urls', 's') - ->fields('s', array('url', 'expire')) + ->fields('s', array('url', 'expire', 'hits')) ->condition('alias', $alias) ->execute() ->fetchAssoc(); if ($result['expire'] == 0 || $result['expire'] > REQUEST_TIME) { + $ujhit = $result['hits'] + 1; + db_update('shrtr_urls') + ->fields(array('hits' => $ujhit)) + ->condition('alias', $alias) + ->execute(); drupal_goto($result['url']); } else { @@ -194,7 +184,7 @@ function shrtr_list_page() { ->fields('s') ->execute(); - $header = array(t('ID'), t('User'), t('Original URL'), t('New URL'), t('Subbmitted'), t('Expire time')); + $header = array(t('ID'), t('User'), t('Original URL'), t('New URL'), t('Submitted'), t('Expire time'), t('Hits')); $rows = array(); while ($url = $urls->fetchAssoc()) { @@ -206,6 +196,7 @@ function shrtr_list_page() { $row[] = l($new_url, $new_url); $row[] = format_date($url['created']); $row[] = format_date($url['expire']); + $row[] = $url['hits']; $rows[] = $row; } @@ -225,7 +216,7 @@ function shrtr_urls_admin() { ->fields('s') ->execute(); - $header = array(t('ID'), t('Enabled'), t('User'), t('Original URL'), t('New URL'), t('Subbmitted'), t('Expire time')); + $header = array(t('ID'), t('Enabled'), t('User'), t('Original URL'), t('New URL'), t('Submitted'), t('Expire time'), t('Number of hits')); $rows = array(); $default = array(); @@ -239,6 +230,7 @@ function shrtr_urls_admin() { $row[] = l($new_url, $new_url); $row[] = format_date($url['created']); $row[] = format_date($url['expire']); + $row[] = $url['hits']; $rows[$url['id']] = $row; $default[$url['id']] = $url['enabled']; } From 6d299032dea9c9a95974b4f2e108dfc8a6bf6d3d Mon Sep 17 00:00:00 2001 From: Astiii Date: Thu, 3 May 2012 18:43:48 +0300 Subject: [PATCH 2/2] Update shrtr.install --- shrtr.install | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/shrtr.install b/shrtr.install index 45127f0..82e25f5 100644 --- a/shrtr.install +++ b/shrtr.install @@ -50,6 +50,12 @@ function shrtr_schema() { 'default' => 1, 'length' => 1, ), + 'hits' => array( + 'description' => 'Hits', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), ), 'primary key' => array('id'), 'unique keys' => array( @@ -64,3 +70,18 @@ function shrtr_schema() { ); return $schema; } + +/** +* Creates hit counter field. +*/ +function shrtr_update_7901() { + $hits = array( + 'description' => 'Hits', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ); + db_add_field('shrtr_urls', 'expire', $hits); + + return t('Hit counter field of added to database.'); +}