Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r18428: LJSUP-7915 (Native sharing server side)

Committer: ailyin
LJSUP-7915 (Native sharing server side)
U   trunk/bin/upgrading/en.dat
U   trunk/bin/upgrading/s2layers/core1.s2
U   trunk/bin/upgrading/s2layers/i18nc/ru1.s2
U   trunk/cgi-bin/LJ/HTML/Template.pm
A   trunk/cgi-bin/LJ/Share.pm
U   trunk/cgi-bin/LJ/Text.pm
U   trunk/cgi-bin/LJ/Widget/Browse.pm
U   trunk/cgi-bin/imageconf.pl
A   trunk/htdocs/js/share.js
A   trunk/htdocs/stc/share.css
U   trunk/templates/Browse/recent_posts.tmpl
Modified: trunk/bin/upgrading/en.dat
===================================================================
--- trunk/bin/upgrading/en.dat	2011-03-02 03:19:12 UTC (rev 18427)
+++ trunk/bin/upgrading/en.dat	2011-03-02 04:32:51 UTC (rev 18428)
@@ -2681,6 +2681,8 @@
 
 img.sharethis=Share this!
 
+img.share=Share
+
 img.tellfriend=Tell a Friend!
 
 img.track=Track This

Modified: trunk/bin/upgrading/s2layers/core1.s2
===================================================================
--- trunk/bin/upgrading/s2layers/core1.s2	2011-03-02 03:19:12 UTC (rev 18427)
+++ trunk/bin/upgrading/s2layers/core1.s2	2011-03-02 04:32:51 UTC (rev 18428)
@@ -1389,6 +1389,11 @@
 }
 set text_share_this = "Share this!";
 
+property string text_share {
+    des = "Text to share this with a friend";
+}
+set text_share = "Share";
+
 property string text_share_facebook {
     des = "Text to share this with a friend on Facebook";
 }

Modified: trunk/bin/upgrading/s2layers/i18nc/ru1.s2
===================================================================
--- trunk/bin/upgrading/s2layers/i18nc/ru1.s2	2011-03-02 03:19:12 UTC (rev 18427)
+++ trunk/bin/upgrading/s2layers/i18nc/ru1.s2	2011-03-02 04:32:51 UTC (rev 18428)
@@ -113,6 +113,7 @@
 set text_icon_alt_private = "[личная запись]";
 set text_copyr_agree = "Разрешаю воспроизводить в любой форме";
 set text_copyr_disagree = "Запрещаю воспроизводить в какой-либо форме";
+set text_share_this = "Поделиться";
 
 # Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4]
 function lang_map_plural (int n) : int {

Modified: trunk/cgi-bin/LJ/HTML/Template.pm
===================================================================
--- trunk/cgi-bin/LJ/HTML/Template.pm	2011-03-02 03:19:12 UTC (rev 18427)
+++ trunk/cgi-bin/LJ/HTML/Template.pm	2011-03-02 04:32:51 UTC (rev 18428)
@@ -66,6 +66,14 @@
             },
         );
 
+        HTML::Template::Pro->register_function(
+            'lj_enabled' => sub {
+                my ($what) = @_;
+                my $remote = LJ::get_remote();
+                return LJ::is_enabled( $what, $remote );
+            },
+        );
+
         my $template = HTML::Template::Pro->new(
             global_vars => 1, # normally variables declared outside a loop are not available inside
                               # a loop.  This option makes <TMPL_VAR>s like global variables in Perl

Modified: trunk/cgi-bin/LJ/Text.pm
===================================================================
--- trunk/cgi-bin/LJ/Text.pm	2011-03-02 03:19:12 UTC (rev 18427)
+++ trunk/cgi-bin/LJ/Text.pm	2011-03-02 04:32:51 UTC (rev 18428)
@@ -326,4 +326,23 @@
     return $str;
 }
 
+# runs HTML cleaner on the passed string (to ensure that
+# <lj user="exampleusername"> is expanded), and then actually removes
+# all HTML tags in the result
+#
+# TODO: save some hassle running clean_comment, and/or make this an option
+# for the HTML cleaner itself
+sub drop_html {
+    my ( $class, $what ) = @_;
+
+    LJ::CleanHTML::clean_comment(\$what);
+
+    $what =~ s/<.*?>/ /g;
+    $what =~ s/\s+/ /g;
+    $what =~ s/^\s+//;
+    $what =~ s/\s+$//;
+
+    return $what;
+}
+
 1;

Modified: trunk/cgi-bin/LJ/Widget/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Browse.pm	2011-03-02 03:19:12 UTC (rev 18427)
+++ trunk/cgi-bin/LJ/Widget/Browse.pm	2011-03-02 04:32:51 UTC (rev 18428)
@@ -9,6 +9,7 @@
 sub need_res { qw( stc/widgets/widget-layout.css stc/widgets/search.css stc/widgets/add-community.css stc/widgets/featuredposts.css stc/widgets/featuredcomms.css ) }
 
 use LJ::Browse::Parser;
+use LJ::Share;
 
 sub _build_tree {
     my ($parentid, $level, $test_uri, $vertical, @categories) = @_;
@@ -282,6 +283,12 @@
             $event = $parsed->{'text'};
             my $images = $parsed->{'images'};
 
+            my $sharing_js = '';
+            if ( LJ::is_enabled('sharing') ) {
+                LJ::Share->request_resources;
+                $sharing_js = LJ::Share->render_js({ 'entry' => $entry });
+            }
+
             push @tmpl_posts, {
                 subject         => $trimmed_subj,
                 is_subject_trimmed => $subject ne $trimmed_subj ? 1 : 0,
@@ -298,6 +305,7 @@
                 photo_for_post  => scalar @$images ? $images->[0] : '',
                 comments_count  => $entry->reply_count,
                 is_need_more    => $parsed->{'is_removed_video'} || $parsed->{'is_text_trimmed'},
+                sharing_js      => $sharing_js,
             };
         }
     }

Modified: trunk/cgi-bin/imageconf.pl
===================================================================
--- trunk/cgi-bin/imageconf.pl	2011-03-02 03:19:12 UTC (rev 18427)
+++ trunk/cgi-bin/imageconf.pl	2011-03-02 04:32:51 UTC (rev 18428)
@@ -173,6 +173,13 @@
     'alt' => 'img.sharethis',
 };
 
+$img{'share'} = {
+    'src' => '/btn_share.gif?v=1',
+    'width' => 24,
+    'height' => 24,
+    'alt' => 'img.share',
+};
+
 # load the site-local version, if it's around.
 if (-e "$LJ::HOME/cgi-bin/imageconf-local.pl") {
     require "$LJ::HOME/cgi-bin/imageconf-local.pl";

Added: trunk/htdocs/js/share.js
===================================================================
--- trunk/htdocs/js/share.js	                        (rev 0)
+++ trunk/htdocs/js/share.js	2011-03-02 04:32:51 UTC (rev 18428)
@@ -0,0 +1,170 @@
+;(function( window, $ ) {
+
+var default_options = {
+	services: {
+		livejournal: {
+			title: 'LiveJournal', bindLink: 'http://www.livejournal.com/update.bml?repost={url}'
+		},
+		facebook: {
+			title: 'Facebook', bindLink: 'http://www.facebook.com/sharer.php?u={url}'
+		},
+		twitter: {
+			title: 'Twitter', bindLink: 'http://twitter.com/share?url={url}&text={title}'
+		},
+		vkontakte: {
+			title: 'Vkontakte', bindLink: 'http://vkontakte.ru/share.php?url={url}'
+		},
+		moimir: {
+			title: 'Moi Mir', bindLink: 'http://connect.mail.ru/share?url={url}'
+		},
+		stumbleupon: {
+			title: 'Stumbleupon', bindLink: 'http://www.stumbleupon.com/submit?url={url}'
+		},
+		digg: {
+			title: 'Digg', bindLink: 'http://digg.com/submit?url={url}'
+		},
+		email: {
+			title: 'E-mail', bindLink: 'http://api.addthis.com/oexchange/0.8/forward/email/offer?username=internal&url={url}'
+		},
+		tumblr: {
+			title: 'Tumblr', bindLink: 'http://www.tumblr.com/share?v=3&u={url}'
+		},
+		odnoklassniki: {
+			title: 'Odnoklassniki', bindLink: 'http://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1&st._surl={url}'
+		}
+	},
+	links: [ 'livejournal', 'facebook', 'twitter', 'vkontakte', 'odnoklassniki', 'moimir', 'email', 'digg', 'tumblr', 'stumbleupon' ]
+};
+
+var global_options = $.extend( true, {}, default_options );
+
+window.LJShare = {};
+
+window.LJShare.init = function( opts ) {
+	if( opts ) {
+		global_options.services = $.extend( true, {}, default_options.services, opts.services );
+		global_options.links = opts.links || global_options.links;
+	}
+}
+
+window.LJShare.link = function( opts ) {
+	var defaults = {
+		title: '',
+		description: '',
+		url: ''
+	}
+
+	var link = jQuery( 'a:last' ),
+		url = link.attr( 'href' ),
+		options = jQuery.extend( {}, defaults, { url: url } , opts ),
+		dom;
+
+	options.links = ( opts.links ) ? opts.links : global_options.links;
+
+
+	function buildDom() {
+		var list = jQuery( '<ul>', { "class": 'ljshare-service-list' } ),
+			li, a, clickFunc;
+
+		for( var i = 0; i < options.links.length; ++i ) {
+			a = jQuery( '<a>' )
+				.html( global_options.services[ options.links[i] ].title );
+
+			global_options.services[ options.links[i] ].href = a;
+			$( '<li>', { "class": 'ljshare-service-' + options.links[i] } )
+				.append( a )
+				.appendTo( list );
+		}
+
+		dom = $( '<div>', { 'class': 'ljshare-container' } ).css( {
+			position: 'absolute',
+			visibility: 'hidden'
+		} ).append( list );
+	}
+
+	function injectDom() {
+		dom.appendTo( $( document.body ) );
+	}
+
+	function bindControls() {
+		dom.bind( 'click', function( ev ) {
+			ev.stopPropagation();
+		} );
+
+		$( window ).bind( 'click', function( ev ) {
+			togglePopup( false );
+		} );
+
+		for( var i = 0; i < options.links.length; ++i ) {
+			_bindLink( global_options.services[ options.links[i] ] );
+		}
+	}
+
+	function _bindLink( service ) {
+		if( typeof service.bindLink === "string" ) {
+			callback = function() {
+				togglePopup( false );
+				window.open( service.bindLink.replace( "{url}", encodeURIComponent( options.url ) )
+																		.replace( "{title}", options.title ) );
+			}
+		} else {
+			callback = service.bindLink;
+		}
+		service.href.click( callback );
+	}
+
+	function updatePopupPosition() {
+		var linkPos = link.offset(),
+			linkH = link.height(), linkW = link.width();
+
+		var scrollOffset = ( window.scrollY !== undefined ) ? scrollY :
+								( window.pageYOffset ) ? pageYOffset :
+								(((t = document.documentElement) || (t = document.body.parentNode)) && typeof t.ScrollTop == 'number' ? t : document.body).ScrollTop;
+
+		var upperSpace = linkPos.top - scrollOffset;
+		var lowerSpace = $( window ).height() - upperSpace - linkH;
+		var domH = dom.height(), domW = dom.width();
+
+		var linkTop = linkPos.top, linkLeft = linkPos.left;
+
+		if( lowerSpace < domH && upperSpace > domH ) {
+			linkTop -= domH + 5;
+		} else {
+			linkTop += linkH + 5;
+		}
+
+		var windowW = $( window ).width();
+		if( linkPos.left + domW > windowW ) {
+			linkLeft = windowW - domW - 10;
+		}
+
+		dom.css( {
+			left: linkLeft + "px",
+			top: linkTop + "px"
+		} );
+	}
+
+	function togglePopup( show ) {
+		show = show || false;
+		if( show ) {
+			updatePopupPosition();
+		}
+
+		dom.css( 'visibility', ( show ) ? 'visible' : 'hidden' );
+	}
+
+	link.attr( 'href', 'javascript:void(0)' )
+		.click( function( ev ) {
+			if( !dom ) {
+				buildDom();
+				injectDom();
+				bindControls();
+			}
+
+			togglePopup( true );
+			ev.preventDefault();
+			ev.stopPropagation();
+		} );
+}
+
+} )( window, jQuery );

Added: trunk/htdocs/stc/share.css
===================================================================
--- trunk/htdocs/stc/share.css	                        (rev 0)
+++ trunk/htdocs/stc/share.css	2011-03-02 04:32:51 UTC (rev 18428)
@@ -0,0 +1,20 @@
+.ljshare-container {
+    position: absolute;
+    border: 1px solid #555;
+    -moz-border-radius: 4px;
+    background-color: #fff;
+    padding: 0.1em;
+    line-height: 1.3em;
+}
+
+.ljshare-service-list li {
+    border: 1px solid #fff;
+    padding: 0.1em;
+}
+
+.ljshare-service-list li:hover {
+    background-color: #eee;
+    border: 1px solid #bbb;
+    -moz-border-radius: 2px;
+    cursor: pointer;
+}

Modified: trunk/templates/Browse/recent_posts.tmpl
===================================================================
--- trunk/templates/Browse/recent_posts.tmpl	2011-03-02 03:19:12 UTC (rev 18427)
+++ trunk/templates/Browse/recent_posts.tmpl	2011-03-02 04:32:51 UTC (rev 18428)
@@ -29,19 +29,26 @@
 		<ul class="b-share">
 			<li class="b-share-fb"><a href="http://facebook.com/sharer.php?u=<tmpl_var expr="eurl(url_to_post)">" target="_blank">">facebook</a></li>
 			<li class="b-share-twitter"><a href="http://twitter.com/share?url=<tmpl_var expr="eurl(url_to_post)">&text=<tmpl_var expr="eurl(subject)">" target="_blank">twitter</a></li>
-			<li class="b-share-sharethis"><a href="javascript:void(0);">sharethis</a></li>
+            <tmpl_if expr="lj_enabled('sharethis')">
+                <li class="b-share-sharethis"><a href="javascript:void(0);">sharethis</a></li>
+            </tmpl_if>
+            <tmpl_if expr="lj_enabled('sharing')">
+                <li class="b-share-sharethis"><a href="#">share</a><tmpl_var sharing_js></li>
+            </tmpl_if>
 			<li class="b-share-email"><a href="javascript:void(0);">mail</a></li>
 			<li class="b-share-fb-like"><iframe src="http://www.facebook.com/plugins/like.php?href=<tmpl_var expr="eurl(url_to_post)">&amp;layout=button_count&amp;show_faces=true&amp;width=150&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true"></iframe></li>
 		</ul>
-		<script type="text/javascript">
-		(function() {
-			var s = SHARETHIS.addEntry({url:'<tmpl_var url_to_post>', title: '<tmpl_var expr="ejs(subject)">'}, {button: false});
-			var ul = jQuery('ul:last');
+        <tmpl_if expr="lj_enabled('sharethis')">
+            <script type="text/javascript">
+            (function() {
+                var s = SHARETHIS.addEntry({url:'<tmpl_var url_to_post>', title: '<tmpl_var expr="ejs(subject)">'}, {button: false});
+                var ul = jQuery('ul:last');
 
-			s.attachButton( ul.find('.b-share-sharethis a')[0]);
-			s.attachChicklet("email", ul.find('.b-share-email a')[0]);
-		}());
-		</script>
+                s.attachButton( ul.find('.b-share-sharethis a')[0]);
+                s.attachChicklet("email", ul.find('.b-share-email a')[0]);
+            }());
+            </script>
+        </tmpl_if>
 		<p class="b-catalogue-item-comments"><span class="b-catalogue-comments-count"><a href="<tmpl_var url_to_post>#comments"><tmpl_var comments_count> comments</a> |</span> <a href="<tmpl_var url_to_post>?mode=reply">Leave comment</a></p>
 	</li>
 </tmpl_loop>

Tags: andy, css, dat, js, livejournal, pl, pm, s2, tmpl
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments