diff --git a/shrtr.install b/shrtr.install index 45127f0..2c30989 100644 --- a/shrtr.install +++ b/shrtr.install @@ -1,8 +1,8 @@ 'Shortened URLs', @@ -47,9 +47,15 @@ function shrtr_schema() { 'description' => 'Enabled', 'type' => 'int', 'not null' => TRUE, - 'default' => 1, + 'default' => 0, '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.'); +} diff --git a/shrtr.module b/shrtr.module index a1ea841..50cbafc 100644 --- a/shrtr.module +++ b/shrtr.module @@ -40,7 +40,7 @@ function shrtr_menu() { } /** - * 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( @@ -120,6 +120,7 @@ function shrtr_new_form_submit($form, &$form_state) { 'uid' => $user->uid, 'created' => REQUEST_TIME, 'expire' => $expire, + 'hits' => $hits, 'alias' => $alias, ); @@ -133,12 +134,13 @@ 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) { + $result['hits']++; drupal_goto($result['url']); } else { @@ -178,7 +180,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()) { @@ -190,6 +192,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; } @@ -209,7 +212,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();