diff --git a/3.0/modules/addthis/config/addthis.php b/3.0/modules/addthis/config/addthis.php new file mode 100644 index 00000000..04e314c9 --- /dev/null +++ b/3.0/modules/addthis/config/addthis.php @@ -0,0 +1,29 @@ + email address that appears as the from address + * line-length => word wrap length (PHP documentations suggest no larger tha 70 characters + * reply-to => what goes into the reply to header + */ +$config["ranges"] = array( + "Addthis1" => array("low" => "65.249.152.0", "high" => "65.249.159.255"), + "Addthis2" => array("low" => "208.122.55.0", "high" => "208.122.55.255") +); diff --git a/3.0/modules/addthis/controllers/addthis.php b/3.0/modules/addthis/controllers/addthis.php new file mode 100644 index 00000000..6e55a17b --- /dev/null +++ b/3.0/modules/addthis/controllers/addthis.php @@ -0,0 +1,123 @@ +file_url(true); + $thumb_url = $item->thumb_url(true); + } else { + $proxy = ORM::factory("addthis_proxy"); + $proxy->uuid = md5(rand()); + $proxy->item_id = $item->id; + $proxy->save(); + $full_url = url::abs_site("addthis/print_proxy/full/$proxy->uuid"); + $thumb_url = url::abs_site("addthis/print_proxy/thumb/$proxy->uuid"); + } + + $v = new View("addthis_form.html"); + $v->order_parms = array( + "addthis_api_version" => "100", + "company_id" => module::get_var("addthis", "company_id"), + "event_id" => module::get_var("addthis", "event_id"), + "cmd" => "addimg", + "partner_code" => "69", + "return_url" => url::abs_site("addthis/close_window"), + "num_images" => "1", + "image_1" => $full_url, + "thumb_1" => $thumb_url, + "image_height_1" => $item->height, + "image_width_1" => $item->width, + "thumb_height_1" => $item->thumb_height, + "thumb_width_1" => $item->thumb_width, + "title_1" => html::purify($item->title)); + + print $v; + } + + public function print_proxy($type, $id) { + // If its a request for the full size then make sure we are coming from an + // authorized address + if ($type == "full") { + $remote_addr = ip2long($this->input->server("REMOTE_ADDR")); + if ($remote_addr === false) { + Kohana::show_404(); + } + $config = Kohana::config("addthis"); + + $authorized = false; + foreach ($config["ranges"] as $ip_range) { + $low = ip2long($ip_range["low"]); + $high = ip2long($ip_range["high"]); + $authorized = $low !== false && $high !== false && + $low <= $remote_addr && $remote_addr <= $high; + if ($authorized) { + break; + } + } + if (!$authorized) { + Kohana::show_404(); + } + } + + $proxy = ORM::factory("addthis_proxy", array("uuid" => $id)); + if (!$proxy->loaded || !$proxy->item->loaded) { + Kohana::show_404(); + } + + $file = $type == "full" ? $proxy->item->file_path() : $proxy->item->thumb_path(); + if (!file_exists($file)) { + kohana::show_404(); + } + + // We don't need to save the session for this request + Session::abort_save(); + + if (!TEST_MODE) { + // Dump out the image + header("Content-Type: $proxy->item->mime_type"); + Kohana::close_buffers(false); + $fd = fopen($file, "rb"); + fpassthru($fd); + fclose($fd); + + // If the request was for the image and not the thumb, then delete the proxy. + if ($type == "full") { + $proxy->delete(); + } + } + + $this->_clean_expired(); + } + + public function close_window() { + print ""; + } + + private function _clean_expired() { + Database::instance()->query( + "DELETE FROM {addthis_proxies} " . + "WHERE request_date <= (CURDATE() - INTERVAL 10 DAY) " . + "LIMIT 20"); + } +} \ No newline at end of file diff --git a/3.0/modules/addthis/controllers/admin_addthis.php b/3.0/modules/addthis/controllers/admin_addthis.php new file mode 100644 index 00000000..9c537b00 --- /dev/null +++ b/3.0/modules/addthis/controllers/admin_addthis.php @@ -0,0 +1,26 @@ +content = new View("admin_addthis.html"); + print $v; + } +} \ No newline at end of file diff --git a/3.0/modules/addthis/css/addthis_menu.css b/3.0/modules/addthis/css/addthis_menu.css new file mode 100644 index 00000000..b1deae01 --- /dev/null +++ b/3.0/modules/addthis/css/addthis_menu.css @@ -0,0 +1,3 @@ +#g-view-menu #g-addthis-link { + background-image: url('../images/addthis_logo.png'); +} diff --git a/3.0/modules/addthis/helpers/addthis_event.php b/3.0/modules/addthis/helpers/addthis_event.php new file mode 100644 index 00000000..c0415564 --- /dev/null +++ b/3.0/modules/addthis/helpers/addthis_event.php @@ -0,0 +1,48 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("addthis_menu") + ->label(t("AddThis")) + ->url(url::site("admin/addthis"))); + } + + static function photo_menu($menu, $theme) { + $item = $theme->item(); + $menu->append(Menu::factory("link") + ->id("addthis") + ->label(t("Bookmark and Share: $item->title")) + ->url("") + ->css_id("g-addthis-link") + ->css_class("addthis_button")); + } + + static function album_menu($menu, $theme) { + $item = $theme->item(); + $menu->append(Menu::factory("link") + ->id("addthis") + ->label(t("Bookmark and Share: $item->title")) + ->url("") + ->css_id("g-addthis-link") + ->css_class("addthis_button")); + } +} diff --git a/3.0/modules/addthis/helpers/addthis_installer.php b/3.0/modules/addthis/helpers/addthis_installer.php new file mode 100644 index 00000000..ac401eb6 --- /dev/null +++ b/3.0/modules/addthis/helpers/addthis_installer.php @@ -0,0 +1,45 @@ +query("CREATE TABLE {addthis_proxies} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `uuid` char(32) NOT NULL, + `request_date` TIMESTAMP NOT NULL DEFAULT current_timestamp, + `item_id` int(9) NOT NULL, + PRIMARY KEY (`id`)) + DEFAULT CHARSET=utf8;"); + + module::set_var("addthis", "username", ""); + module::set_version("addthis", 1); + } + + static function upgrade($version) { + if ($version == 1) { + module::set_version("addthis", $version = 1); + } + } + + static function uninstall() { + Database::instance()->query("DROP TABLE IF EXISTS {addthis_proxies}"); + module::delete("addthis"); + } +} diff --git a/3.0/modules/addthis/helpers/addthis_theme.php b/3.0/modules/addthis/helpers/addthis_theme.php new file mode 100644 index 00000000..7308954e --- /dev/null +++ b/3.0/modules/addthis/helpers/addthis_theme.php @@ -0,0 +1,29 @@ +css("addthis_menu.css"); + return "\n" . + ""; + } +} diff --git a/3.0/modules/addthis/images/addthis_logo.png b/3.0/modules/addthis/images/addthis_logo.png new file mode 100644 index 00000000..39372a0c Binary files /dev/null and b/3.0/modules/addthis/images/addthis_logo.png differ diff --git a/3.0/modules/addthis/models/addthis_proxy.php b/3.0/modules/addthis/models/addthis_proxy.php new file mode 100644 index 00000000..dd7ff120 --- /dev/null +++ b/3.0/modules/addthis/models/addthis_proxy.php @@ -0,0 +1,22 @@ + +
+ " alt="Add This logo" class="g-right"/> +

+
+

+ +AddThis uses services to provide an intelligent, optimized sharing menu that is designed to offer the right options at the right time and maximize distribution of your content - everywhere.") ?> +

+ +

+ register with Add This and enter your addthis username in the Advanced Settings page you can get Analytics. Example data below.", + array("signup_url" => "http://www.addthis.com/register", + "advanced_settings_url" => html::mark_clean(url::site("admin/advanced_settings")))) ?> +

+
+
+