From a63742ac9d7bcc3ea01e02de583b7bce0a0773ce Mon Sep 17 00:00:00 2001 From: Chad Kieffer Date: Sun, 26 Dec 2010 11:19:46 -0700 Subject: [PATCH 1/4] Update link labels to adhere to capitalization rules. --- 3.1/modules/bitly/helpers/bitly_event.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/3.1/modules/bitly/helpers/bitly_event.php b/3.1/modules/bitly/helpers/bitly_event.php index 3701df8e..4074b4e4 100644 --- a/3.1/modules/bitly/helpers/bitly_event.php +++ b/3.1/modules/bitly/helpers/bitly_event.php @@ -31,7 +31,7 @@ class bitly_event_Core { $menu->get("options_menu") ->append(Menu::factory("link") ->id("bitly") - ->label(t("Shorten Link with bit.ly")) + ->label(t("Shorten link with bit.ly")) ->url(url::site("bitly/shorten/$item->id?csrf=$theme->csrf")) ->css_id("g-bitly-link") ->css_class("g-bitly-shorten ui-icon-link")); @@ -41,7 +41,7 @@ class bitly_event_Core { $menu->get("options_menu") ->append(Menu::factory("link") ->id("bitly") - ->label(t("Shorten Link with bit.ly")) + ->label(t("Shorten link with bit.ly")) ->url(url::site("bitly/shorten/$item->id?csrf=$theme->csrf")) ->css_class("g-bitly-shorten ui-icon-link")); } From d422f581a47093234a20af96b145d9c243c72b20 Mon Sep 17 00:00:00 2001 From: Chad Kieffer Date: Sun, 26 Dec 2010 16:18:07 -0700 Subject: [PATCH 2/4] Dropped owner_id, it can be derived via the item. Added global_hash --- 3.1/modules/bitly/helpers/bitly.php | 4 +--- 3.1/modules/bitly/helpers/bitly_installer.php | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/3.1/modules/bitly/helpers/bitly.php b/3.1/modules/bitly/helpers/bitly.php index 276c7796..6462804b 100644 --- a/3.1/modules/bitly/helpers/bitly.php +++ b/3.1/modules/bitly/helpers/bitly.php @@ -194,9 +194,7 @@ class bitly_Core { $link = ORM::factory("bitly_link"); $link->item_id = $item_id; $link->hash = $json_response->data->hash; - //$link->global_hash = $json_response->data->global_hash; - //$new_hash = $json_response->data->new_hash; - $link->owner_id = $item->owner_id; + $link->global_hash = $json_response->data->global_hash; $link->save(); message::success("$long_url has been shortened to $short_url"); diff --git a/3.1/modules/bitly/helpers/bitly_installer.php b/3.1/modules/bitly/helpers/bitly_installer.php index c55fbb66..4fd0c8ad 100644 --- a/3.1/modules/bitly/helpers/bitly_installer.php +++ b/3.1/modules/bitly/helpers/bitly_installer.php @@ -25,7 +25,7 @@ class bitly_installer { `id` int(9) NOT NULL AUTO_INCREMENT, `item_id` int(9) NOT NULL, `hash` char(6) NOT NULL, - `owner_id` int(9) NOT NULL, + `global_hash` char(6) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8;"); module::set_version("bitly", 1); From d0cfcbf20edd9f84f758ee59bb129e42c380154d Mon Sep 17 00:00:00 2001 From: Chad Kieffer Date: Sun, 26 Dec 2010 18:03:08 -0700 Subject: [PATCH 3/4] Add check to see if current user is the owner before displaying shorten link menu item. --- 3.1/modules/bitly/helpers/bitly_event.php | 31 +++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/3.1/modules/bitly/helpers/bitly_event.php b/3.1/modules/bitly/helpers/bitly_event.php index 4074b4e4..29463606 100644 --- a/3.1/modules/bitly/helpers/bitly_event.php +++ b/3.1/modules/bitly/helpers/bitly_event.php @@ -27,22 +27,25 @@ class bitly_event_Core { } static function site_menu($menu, $theme) { - $item = $theme->item(); - $menu->get("options_menu") - ->append(Menu::factory("link") - ->id("bitly") - ->label(t("Shorten link with bit.ly")) - ->url(url::site("bitly/shorten/$item->id?csrf=$theme->csrf")) - ->css_id("g-bitly-link") - ->css_class("g-bitly-shorten ui-icon-link")); + if ($theme->item->owner->id == identity::active_user()->id) { + $menu->get("options_menu") + ->append(Menu::factory("link") + ->id("bitly") + ->label(t("Shorten link with bit.ly")) + ->url(url::site("bitly/shorten/{$theme->item->id}?csrf=$theme->csrf")) + ->css_id("g-bitly-link") + ->css_class("g-bitly-shorten ui-icon-link")); + } } static function context_menu($menu, $theme, $item) { - $menu->get("options_menu") - ->append(Menu::factory("link") - ->id("bitly") - ->label(t("Shorten link with bit.ly")) - ->url(url::site("bitly/shorten/$item->id?csrf=$theme->csrf")) - ->css_class("g-bitly-shorten ui-icon-link")); + if ($theme->item->owner->id == identity::active_user()->id) { + $menu->get("options_menu") + ->append(Menu::factory("link") + ->id("bitly") + ->label(t("Shorten link with bit.ly")) + ->url(url::site("bitly/shorten/$item->id?csrf=$theme->csrf")) + ->css_class("g-bitly-shorten ui-icon-link")); + } } } From e1ad88ab10526e6023566152c46bf3057924de6a Mon Sep 17 00:00:00 2001 From: Chad Kieffer Date: Sun, 26 Dec 2010 22:58:06 -0700 Subject: [PATCH 4/4] Removed debug line. --- 3.1/modules/bitly/helpers/bitly.php | 1 - 1 file changed, 1 deletion(-) diff --git a/3.1/modules/bitly/helpers/bitly.php b/3.1/modules/bitly/helpers/bitly.php index 6462804b..2ba90670 100644 --- a/3.1/modules/bitly/helpers/bitly.php +++ b/3.1/modules/bitly/helpers/bitly.php @@ -145,7 +145,6 @@ class bitly_Core { */ private static function _http_post($http_request) { $response = ''; - //Kohana_Log::add("debug", "Send request\n" . print_r($http_request, 1)); if (false !== ($fs = @fsockopen(self::$api_host, 80, $errno, $errstr, 5))) { fwrite($fs, $http_request); while ( !feof($fs) ) {