1
0

Adding social share to git repository for version 2

Added facebook like with configuraiton options
Added configuration options to facebook share, google +1 and twitter
buttons.
This commit is contained in:
Jason Hardin 2012-01-30 20:40:34 -08:00
parent 7819cbba37
commit 7aa5342ec7
11 changed files with 427 additions and 0 deletions

View File

@ -0,0 +1,146 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Admin_Social_Share_Controller extends Admin_Controller {
public function index() {
print $this->_get_view();
}
public function handler() {
access::verify_csrf();
$form = $this->_get_form();
if ($form->validate()) {
module::set_var("social_share", "facebook_share_enabled", $form->facebook_share_settings->facebook_share_enabled->value);
module::set_var("social_share", "facebook_share_layout", $form->facebook_share_settings->facebook_share_layout->value);
module::set_var("social_share", "facebook_share_link_text", $form->facebook_share_settings->facebook_share_link_text->value);
module::set_var("social_share", "facebook_like_enabled", $form->facebook_like_settings->facebook_like_enabled->value);
module::set_var("social_share", "facebook_like_appId", $form->facebook_like_settings->facebook_like_appId->value);
module::set_var("social_share", "facebook_like_adminId", $form->facebook_like_settings->facebook_like_adminId->value);
module::set_var("social_share", "facebook_like_site_name", $form->facebook_like_settings->facebook_like_site_name->value);
module::set_var("social_share", "facebook_like_code_type", $form->facebook_like_settings->facebook_like_code_type->value);
module::set_var("social_share", "facebook_like_show_faces", $form->facebook_like_settings->facebook_like_show_faces->value, true);
module::set_var("social_share", "facebook_like_send", $form->facebook_like_settings->facebook_like_send->value, true);
module::set_var("social_share", "facebook_like_action", $form->facebook_like_settings->facebook_like_action->value);
module::set_var("social_share", "facebook_like_layout", $form->facebook_like_settings->facebook_like_layout->value);
module::set_var("social_share", "google_enabled", $form->google_settings->google_enabled->value);
module::set_var("social_share", "google_size", $form->google_settings->google_size->value);
module::set_var("social_share", "google_annotation", $form->google_settings->google_annotation->value);
module::set_var("social_share", "twitter_enabled", $form->twitter_settings->twitter_enabled->value);
module::set_var("social_share", "twitter_count_location", $form->twitter_settings->twitter_count_location->value);
module::set_var("social_share", "twitter_size", $form->twitter_settings->twitter_size->value);
message::success(t("Your settings have been saved."));
url::redirect("admin/social_share");
}
print $this->_get_view($form);
}
private function _get_view($form=null) {
$v = new Admin_View("admin.html");
$v->content = new View("admin_social_share.html");
$v->content->form = empty($form) ? $this->_get_form() : $form;
return $v;
}
private function _get_form() {
$form = new Forge("admin/social_share/handler", "", "post", array("id" => "g-admin-form"));
$group_facebook_share = $form->group("facebook_share_settings")->label(t("Facebook Share Button Settings"));
$group_facebook_share->checkbox("facebook_share_enabled")->label(t("Display the button"))
->checked(module::get_var("social_share", "facebook_share_enabled", false) == 1);
$group_facebook_share->dropdown("facebook_share_layout")
->label(t("The button layout to use"))
->options(array( "button" => t("Button"),
"icon_link" => t("Icon and Link"),
"icon" => t("Icon")))
->selected(module::get_var("social_share", "facebook_share_layout"));
$group_facebook_share->input("facebook_share_link_text")->label(t('Enter the text to place next to the Facebook icon.'))
->value(module::get_var("social_share", "facebook_share_link_text", "Share"));
$group_facebook_like = $form->group("facebook_like_settings")->label(t("Facebook Like Button Settings"));
$group_facebook_like->checkbox("facebook_like_enabled")->label(t("Display the button"))
->checked(module::get_var("social_share", "facebook_like_enabled", false) == 1);
$group_facebook_like->input("facebook_like_appId")->label(t('Enter the appId from <a href="http://developers.facebook.com/setup/" target="_blank">FaceBook Create an App</a>. You must get your *own* appID. If you see the number "123456789012345" it is only a demo.<br />
Note: www.example.com/ is different than example.com/'))
->value(module::get_var("social_share", "facebook_like_appId", "123456789012345"))
->rules("valid_numeric");
$group_facebook_like->input("facebook_like_adminId")->label(t('Enter <strong>your</strong Facebook <strong>numeric</strong> ID, which you can get as the "Admin" field in Stage 2 of <a href="http://developers.facebook.com/docs/reference/plugins/like/" target="_blank">FaceBook Like Button Config</a>. If you see the number "123456789012345" it is only a demo.<br />'))
->value(module::get_var("social_share", "facebook_like_adminId", "123456789012345"))
->rules("valid_numeric");
$group_facebook_like->input("facebook_like_site_name")->label(t('Enter the site name you want to show on Facebook.'))
->value(module::get_var("social_share", "facebook_like_site_name", "Gallery"));
$group_facebook_like->dropdown("facebook_like_code_type")
->label(t("The type of Ccde to display for the button"))
->options(array( "html5" => t("HTML5 (allows the Send button and better dialogs)"),
"xfbml" => t("XFBML (allows the Send button and better dialogs)"),
"iframe" => t("iFrame")))
->selected(module::get_var("social_share", "facebook_like_code_type"));
$group_facebook_like->checkbox("facebook_like_show_faces")->label(t("Display profile photos of the Facebook friends who 'Like' below the Like button (standard layout only)."))
->checked(module::get_var("social_share", "facebook_like_show_faces"));
$group_facebook_like->checkbox("facebook_like_send")->label(t("Include a Send button with the Like button. This only works with the XFBML version."))
->checked(module::get_var("social_share", "facebook_like_send"));
$group_facebook_like->dropdown("facebook_like_action")
->label(t("Verb to display"))
->options(array("like" => t("Like"),
"recommend" => t("Recommend")))
->selected(module::get_var("social_share", "facebook_like_action"));
$group_facebook_like->dropdown("facebook_like_layout")
->label(t("Layout style. Determines the size and amount of social context next to the button"))
->options(array("standard" => t("Standard."),
"button_count" => t("Button count"),
"box_count" => t("Box count")))
->selected(module::get_var("social_share", "facebook_like_layout"));
$group_google = $form->group("google_settings")->label(t("Google+ +1 Button Settings"));
$group_google->checkbox("google_enabled")->label(t("Display the button"))
->checked(module::get_var("social_share", "google_enabled", false) == 1);
$group_google->dropdown("google_size")
->label(t("Size of the button"))
->options(array("standard" => t("Standard (24px)"),
"small" => t("Small (15px)"),
"medium" => t("Medium (20px)"),
"tall" => t("Tall (60px)")))
->selected(module::get_var("social_share", "google_size"));
$group_google->dropdown("google_annotation")
->label(t("Annotation location"))
->options(array("inline" => t("Inline"),
"bubble" => t("Bubble"),
"none" => t("None")))
->selected(module::get_var("social_share", "google_annotation"));
$group_twitter = $form->group("twitter_settings")->label(t("Twitter Tweet Settings"));
$group_twitter->checkbox("twitter_enabled")->label(t("Display the button"))
->checked(module::get_var("social_share", "twitter_enabled", false) == 1);
$group_twitter->dropdown("twitter_count_location")
->label(t("Tweet count location"))
->options(array("horizontal" => t("Horizontal"),
"vertical" => t("Vertical"),
"none" => t("None")))
->selected(module::get_var("social_share", "twitter_count_location"));
$group_twitter->dropdown("twitter_size")
->label(t("Size of the button. Large does not work with a vertical count location"))
->options(array("medium" => t("Medium"),
"large" => t("Large")))
->selected(module::get_var("social_share", "twitter_size"));
$form->submit("submit")->value(t("Save"));
return $form;
}
}

View File

@ -0,0 +1,47 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class social_share_block_Core {
static function get_site_list() {
return array(
"social_share" => t("Social Share"));
}
static function get($block_id, $theme) {
$block = new Block();
$block->css_id = "g-social-share";
$block->title = 'Share With Friends';
$block->content = '';
if(module::get_var("social_share", "facebook_share_enabled")){
$block->content .= new View("facebook_share.html");
}
if(module::get_var("social_share", "facebook_like_enabled")){
$block->content .= new View("facebook_like.html");
}
if(module::get_var("social_share", "google_enabled")){
$block->content .= new View("google.html");
}
if(module::get_var("social_share", "twitter_enabled")){
$block->content .= new View("twitter.html");
}
return $block;
}
}

View File

@ -0,0 +1,28 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class social_share_event_Core {
static function admin_menu($menu, $theme) {
$menu->get("settings_menu")
->append(Menu::factory("link")
->id("social_share_menu")
->label(t("Social Share"))
->url(url::site("admin/social_share")));
}
}

View File

@ -0,0 +1,56 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class social_share_installer {
static function deactivate() {
module::clear_var("social_share", "facebook_share_enabled");
module::clear_var("social_share", "facebook_share_layout");
module::clear_var("social_share", "facebook_share_link_text");
module::clear_var("social_share", "facebook_like_enabled");
module::clear_var("social_share", "facebook_like_appId");
module::clear_var("social_share", "facebook_like_adminId");
module::clear_var("social_share", "facebook_like_site_name");
module::clear_var("social_share", "facebook_like_code_type");
module::clear_var("social_share", "facebook_like_show_faces");
module::clear_var("social_share", "facebook_like_send");
module::clear_var("social_share", "facebook_like_action");
module::clear_var("social_share", "facebook_like_layout");
module::clear_var("social_share", "google_enabled");
module::clear_var("social_share", "google_size");
module::clear_var("social_share", "google_annotation");
module::clear_var("social_share", "twitter_enabled");
module::clear_var("social_share", "twitter_count_location");
module::clear_var("social_share", "twitter_size");
}
static function upgrade($version) {
if ($version < 1) {
module::set_version("social_share", $version = 1);
}
if ($version < 2) {
module::set_var("social_share", "facebook_share_enabled", module::get_var("social_share", "facebook"));
module::clear_var("social_share", "facebook");
module::set_var("social_share", "google_enabled", module::get_var("social_share", "google"));
module::clear_var("social_share", "google");
module::set_var("social_share", "twitter_enabled", module::get_var("social_share", "twitter"));
module::clear_var("social_share", "twitter");
module::set_version("social_share", $version = 2);
}
}
}

View File

@ -0,0 +1,38 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class social_share_theme_Core {
static function head($theme) {
if ($theme->item()) {
$item = $theme->item();
$url = $item->thumb_url(true);
$appId = module::get_var("social_share", "facebook_like_appId");
$adminId = module::get_var("social_share", "facebook_like_adminId");
$site_name = module::get_var("social_share", "facebook_like_site_name");
$selfURL = url::abs_current(true);
return "\t<meta property=\"og:image\" content=\"$url\"/>
<meta property=\"og:title\" content=\"$item->title\"/>
<meta property=\"og:type\" content=\"article\"/>
<meta property=\"og:url\" content=\"$selfURL\"/>
<meta property=\"og:site_name\" content=\"$site_name\"/>
<meta property=\"fb:app_id\" content=\"$appId\"/>
<meta property=\"fb:admins\" content=\"$adminId\"/>";
}
}
}

View File

@ -0,0 +1,7 @@
name = "Social Share"
description = "Adds links to share the page to social media sites in the sidebar."
version = 2
author_name = "jasonhardin"
author_url = "http://codex.gallery2.org/User:psychoph"
info_url = "http://codex.gallery2.org/Gallery3:Modules:social_share"
discuss_url = "http://gallery.menalto.com/forum_module_social_share"

View File

@ -0,0 +1,6 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div id="g-admin-social-share">
<h2><?= t("Social Share Administration") ?></h2>
<?= $form ?>
<br clear="all" />
</div>

View File

@ -0,0 +1,75 @@
<?php defined("SYSPATH") or die("No direct script access.");
$appId = module::get_var("social_share", "facebook_like_appId");
$selfURL = url::abs_current(true);
$codeType = module::get_var("social_share", "facebook_like_code_type");
$layout = module::get_var("social_share", "facebook_like_layout", "standard");
$action = module::get_var("social_share", "facebook_like_action", "like");
if (module::get_var("social_share", "facebook_like_show_faces")) {
$show_faces = "true";
$hite = 65;
} else {
$show_faces = "false";
$hite = 35;
}
if (module::get_var("social_share", "facebook_like_send")) {
$send = "true";
} else {
$send = "false";
}
?>
<div class="g-social_share-facebook_like">
<?php if ($codeType == 'iframe'){ ?>
<iframe src="http://www.facebook.com/plugins/like.php?app_id=<?= $appId ?>
&amp;href=<?= $selfURL; ?>
&amp;layout=<?= $layout?>
&amp;send=false
&amp;show_faces=<?= $show_faces ?>
&amp;width=180
&amp;locale=<?= locales::cookie_locale(); ?>
&amp;action=<?= $layout ?>
&amp;colorscheme=light&amp;height=<?= $hite; ?>" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:180px; height:<?= $hite; ?>px;" allowTransparency="true">
</iframe>
<?php } else { ?>
<div id="fb-root"></div>
<script>(function(d, s, id) {
window.FB = null;FB=null;// this is needed for the facebook share button being on.
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<?php if($codeType == 'xfbml'){?>
<fb:like href="<?= $selfURL; ?>" send="<?= $send ?>" width="180" show_faces="<?= $show_faces ?>" layout="<?= $layout?>" action="<?= $layout ?>"></fb:like>
<fb:like href="http://test.com" send="true" width="180" show_faces="false"></fb:like>
<?php } else { ?>
<div class="fb-like" data-href="<?= $selfURL; ?>" data-send="<?= $send ?>" data-layout="<?= $layout?>" data-width="180" data-show-faces="<?= $show_faces ?>" data-action="<?= $layout ?>"></div>
<?php }
}
?>
</div>
<?php
/**
* Only show the like button, css and JS if the item is vewable by the guest user
* as facebook is a guest user to get the thumb of the item. If this is a dynamic
* album then use the root album to check to see if the guest has permissions.
*/
$guest = user::lookup("1");
$item = "";
if ($theme->item()) {
$item = $theme->item();
} else {
$item = ORM::factory("item", 1);
}
if (access::user_can($guest, "view", $item)) {
$show_like_code = true;
}
?>

View File

@ -0,0 +1,5 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div class="g-social_share-facebook_share">
<a id="facebookicon" name="fb_share" type="<?= module::get_var("social_share", "facebook_share_layout") ?>">test</a>
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
</div>

View File

@ -0,0 +1,14 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div class="g-social_share-google">
<!-- Place this tag where you want the +1 button to render -->
<div class="g-plusone"" size="<?= module::get_var("social_share", "google_size") ?>" annotation="<?= module::get_var("social_share", "google_annotation") ?>"></div>
<!-- Place this render call where appropriate -->
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
</div>

View File

@ -0,0 +1,5 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div class="g-social_share-twitter_tweet">
<a href="https://twitter.com/share" class="twitter-share-button" data-lang="en" data-size="<?= module::get_var("social_share", "twitter_size") ?>" data-count="<?= module::get_var("social_share", "twitter_count_location") ?>">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>