mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2010-05-02 06:57 am

[dw-free] Links to cross-posted entries

[commit: http://hg.dwscoalition.org/dw-free/rev/59955acbe4f8]

http://bugs.dwscoalition.org/show_bug.cgi?id=2361

Add option for the crossposter to specify that you want links to the
crossposted content. I.e., if this is on, your post on DW will include a
link to the crosspost on IJ, JF, LJ, etc.

Patch by [personal profile] allen.

Files modified:
  • bin/upgrading/proplists.dat
  • bin/upgrading/s2layers/core2.s2
  • bin/upgrading/update-db-general.pl
  • cgi-bin/DW/External/Account.pm
  • cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm
  • cgi-bin/DW/Setting/XPostAccounts.pm
  • cgi-bin/LJ/S2.pm
  • htdocs/manage/externalaccount.bml
  • htdocs/manage/externalaccount.bml.text
--------------------------------------------------------------------------------
diff -r 04ba85a71e7c -r 59955acbe4f8 bin/upgrading/proplists.dat
--- a/bin/upgrading/proplists.dat	Sun May 02 06:54:19 2010 +0000
+++ b/bin/upgrading/proplists.dat	Sun May 02 06:57:34 2010 +0000
@@ -1392,6 +1392,13 @@ logproplist.xpost:
   sortorder: 105
   ownership: user
 
+logproplist.xpostdetail:
+  datatype: blobchar
+  des: Maps to crossposts of this entry on other sites
+  prettyname: Crosspost Detail
+  sortorder: 106
+  ownership: user
+
 usermsgproplist.userpic:
   des: Userpic chosen by the user who created the message
 
diff -r 04ba85a71e7c -r 59955acbe4f8 bin/upgrading/s2layers/core2.s2
--- a/bin/upgrading/s2layers/core2.s2	Sun May 02 06:54:19 2010 +0000
+++ b/bin/upgrading/s2layers/core2.s2	Sun May 02 06:57:34 2010 +0000
@@ -2025,6 +2025,11 @@ property string text_meta_groups {
 }
 set text_meta_groups = "Custom Access Groups";
 
+property string text_meta_xpost {
+    des = "Text for 'Crossposts'";
+}
+set text_meta_xpost = "Crossposts";
+
 property string text_tags {
     des = "Text for 'Tags' header for an entry";
     example = "Tags:";
@@ -2873,6 +2878,9 @@ function lang_metadata_title(string whic
     }
     elseif ($which == "groups") {
         return $*text_meta_groups;
+    }
+    elseif ($which == "xpost") {
+        return $*text_meta_xpost;
     }
     else {
         return $which;
diff -r 04ba85a71e7c -r 59955acbe4f8 bin/upgrading/update-db-general.pl
--- a/bin/upgrading/update-db-general.pl	Sun May 02 06:54:19 2010 +0000
+++ b/bin/upgrading/update-db-general.pl	Sun May 02 06:57:34 2010 +0000
@@ -2840,6 +2840,7 @@ CREATE table externalaccount (
     servicetype varchar(32),
     serviceurl varchar(128),
     xpostbydefault enum('1','0') NOT NULL default '0',
+    recordlink enum('1','0') NOT NULL default '0',
     primary key (userid, acctid),
     index (userid)
 )
@@ -3876,6 +3877,12 @@ EOF
         do_sql("UPDATE userproplist SET datatype = 'blobchar' WHERE name = 'crosspost_footer_text'");
         set_dbnote( "xpost_footer_update", 1 );
     }
+
+    unless ( column_type( 'externalaccount', 'recordlink' ) ) {
+        do_alter( 'xpost_recordlink',
+                  "ALTER TABLE externalaccount ADD COLUMN recordlink enum('1','0') NOT NULL default '0'");
+    }
+
 });
 
 
diff -r 04ba85a71e7c -r 59955acbe4f8 cgi-bin/DW/External/Account.pm
--- a/cgi-bin/DW/External/Account.pm	Sun May 02 06:54:19 2010 +0000
+++ b/cgi-bin/DW/External/Account.pm	Sun May 02 06:57:34 2010 +0000
@@ -30,9 +30,9 @@ sub _memcache_stored_props          {
 sub _memcache_stored_props          {
     # first element of props is a VERSION
     # next - allowed object properties
-    return qw/ 1
+    return qw/ 2
                userid acctid
-               siteid username password servicename servicetype serviceurl xpostbydefault
+               siteid username password servicename servicetype serviceurl xpostbydefault recordlink
                /;
 }
 sub _memcache_hashref_to_object {
@@ -81,7 +81,7 @@ sub get_external_accounts {
         return @accounts;
     }
 
-    my $sth = $u->prepare("SELECT userid, acctid, siteid, username, password, servicename, servicetype, serviceurl, xpostbydefault FROM externalaccount WHERE userid=?");
+    my $sth = $u->prepare("SELECT userid, acctid, siteid, username, password, servicename, servicetype, serviceurl, xpostbydefault, recordlink FROM externalaccount WHERE userid=?");
     $sth->execute($u->userid);
     LJ::throw($u->errstr) if $u->err;
 
@@ -107,7 +107,7 @@ sub get_external_account {
         return $cached_value;
     }
 
-    my $sth = $u->prepare("SELECT userid, siteid, acctid, username, password, servicename, servicetype, serviceurl, xpostbydefault FROM externalaccount WHERE userid=? and acctid=?");
+    my $sth = $u->prepare("SELECT userid, siteid, acctid, username, password, servicename, servicetype, serviceurl, xpostbydefault, recordlink FROM externalaccount WHERE userid=? and acctid=?");
     $sth->execute($u->userid, $acctid);
     LJ::throw($u->err) if ($u->err);
 
@@ -137,6 +137,14 @@ sub record_xpost {
     $entry->set_prop('xpost', $xpost_ref_string);
 }
 
+# records the xpost detail information on the given entry
+sub record_xpost_detail {
+    my ($class, $entry, $xpost_ref) = @_;
+    
+    my $xpost_ref_string = $class->xpost_hash_to_string($xpost_ref);
+    $entry->set_prop('xpostdetail', $xpost_ref_string);
+}
+
 # saves the xpost information to the entry properties
 sub xpost_hash_to_string {
     my($class, $xpostmap) = @_;
@@ -156,7 +164,7 @@ sub xpost_string_to_hash {
 # instance methods
 sub absorb_row {
     my ($self, $row) = @_;
-    for my $f (qw(username siteid password servicename servicetype serviceurl xpostbydefault)) {
+    for my $f (qw(username siteid password servicename servicetype serviceurl xpostbydefault recordlink)) {
         $self->{$f} = $row->{$f};
     }
     return $self;
@@ -176,7 +184,7 @@ sub create {
     my $protocol = DW::External::XPostProtocol->get_protocol($protocol_id);
     my $encryptedpassword = $protocol->encrypt_password($opts->{password});
 
-    $u->do("INSERT INTO externalaccount (userid, acctid, siteid, username, password, servicename, servicetype, serviceurl, xpostbydefault) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", undef, $u->{userid}, $acctid, $opts->{siteid}, $opts->{username}, $encryptedpassword, $opts->{servicename}, $opts->{servicetype}, $opts->{serviceurl}, $opts->{xpostbydefault} ? '1' : '0');
+    $u->do("INSERT INTO externalaccount (userid, acctid, siteid, username, password, servicename, servicetype, serviceurl, xpostbydefault, recordlink) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", undef, $u->{userid}, $acctid, $opts->{siteid}, $opts->{username}, $encryptedpassword, $opts->{servicename}, $opts->{servicetype}, $opts->{serviceurl}, $opts->{xpostbydefault} ? '1' : '0', $opts->{recordlink} ? '1' : '0' );
     
     LJ::throw($u->errstr) if $u->err;
 
@@ -238,7 +246,7 @@ sub crosspost {
 sub crosspost {
     my ($self, $auth, $entry) = @_;
     
-    # get the prtocol
+    # get the protocol
     my $xpost_protocol = $self->protocol;
 
     # make sure we hae a proper protocol
@@ -263,8 +271,13 @@ sub crosspost {
 
         # handle the result
         if ($result->{success}) {
-            $xpost_mapping->{$self->acctid} = $result->{reference};
-            $self->record_xpost($entry, $xpost_mapping);
+            $xpost_mapping->{$self->acctid} = $result->{reference}->{itemid};
+            $self->record_xpost( $entry, $xpost_mapping );
+
+            my $xpost_detail_mapping = $self->xpost_string_to_hash($entry->prop('xpostdetail'));
+            $xpost_detail_mapping->{$self->acctid} = $result->{reference};
+            $self->record_xpost_detail( $entry, $xpost_detail_mapping );
+
             return {
                 success => 1,
                 message => LJ::Lang::ml($action_key . ".success", { username => $self->username, server => $self->servername, xpostlink => $result->{url} })
@@ -370,6 +383,10 @@ sub xpostbydefault {
     return $_[0]->{xpostbydefault};
 }
 
+sub recordlink {
+    return $_[0]->{recordlink};
+}
+
 # if there is an external site configured, returns it; otherwise returns undef
 sub externalsite {
     return undef unless $_[0]->{siteid};
@@ -434,6 +451,24 @@ sub set_xpostbydefault {
     return 1;
 }
 
+# updates the recordlink values for this ExternalAccount.
+sub set_recordlink {
+    my ($self, $recordlink) = @_;
+
+    my $u = $self->owner;
+
+    my $newvalue = $recordlink ? '1' : '0';
+    unless ($newvalue eq $self->recordlink) {
+        $u->do("UPDATE externalaccount SET recordlink=? WHERE userid=? AND acctid=?", undef, $newvalue, $u->{userid}, $self->acctid);
+        LJ::throw($u->errstr) if $u->err;
+        
+        $self->{recordlink} = $recordlink;
+        
+        $self->_remove_from_memcache($self->_memcache_id);
+    }
+    return 1;
+}
+
 # updates the password values for this ExternalAccount.
 sub set_password {
     my ($self, $password) = @_;
diff -r 04ba85a71e7c -r 59955acbe4f8 cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm
--- a/cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm	Sun May 02 06:54:19 2010 +0000
+++ b/cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm	Sun May 02 06:57:34 2010 +0000
@@ -250,10 +250,14 @@ sub crosspost {
     # crosspost, update, or delete
     my $xpost_result = $self->call_xmlrpc($proxyurl, $itemid ? 'editevent' : 'postevent', $req, $auth);
     if ($xpost_result->{success}) {
+        my $reference->{itemid} = $xpost_result->{result}->{itemid};
+        if ( $extacct->recordlink ) {
+            $reference->{url} = $xpost_result->{result}->{url};
+        }
         return {
             success => 1,
             url =>$xpost_result->{result}->{url},
-            reference => $xpost_result->{result}->{itemid}
+            reference => $reference,
         }
     } else {
         return $xpost_result;
diff -r 04ba85a71e7c -r 59955acbe4f8 cgi-bin/DW/Setting/XPostAccounts.pm
--- a/cgi-bin/DW/Setting/XPostAccounts.pm	Sun May 02 06:54:19 2010 +0000
+++ b/cgi-bin/DW/Setting/XPostAccounts.pm	Sun May 02 06:57:34 2010 +0000
@@ -5,7 +5,7 @@ use warnings;
 
 use Digest::MD5 qw(md5_hex);
 
-sub tags { qw(xpost_option_server xpost_option_username xpost_option_password xpost_option_xpostbydefault crosspost_footer_append crosspost_footer_text) }
+sub tags { qw(xpost_option_server xpost_option_username xpost_option_password xpost_option_xpostbydefault xpost_option_recordlink crosspost_footer_append crosspost_footer_text) }
 
 my $footer_length = 1024;
 
diff -r 04ba85a71e7c -r 59955acbe4f8 cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm	Sun May 02 06:54:19 2010 +0000
+++ b/cgi-bin/LJ/S2.pm	Sun May 02 06:57:34 2010 +0000
@@ -33,6 +33,7 @@ use LJ::S2::EntryPage;
 use LJ::S2::EntryPage;
 use LJ::S2::ReplyPage;
 use LJ::S2::TagsPage;
+use DW::External::Account;
 use Storable;
 use Apache2::Const qw/ :common /;
 use POSIX ();
@@ -1841,6 +1842,25 @@ sub Entry
         $e->{'metadata'}->{'music'} = $p->{'current_music'};
         LJ::CleanHTML::clean_subject(\$e->{'metadata'}->{'music'});
     }
+
+    # check for xpost values
+    if ( $p->{xpostdetail} ) {
+        my $xposthash = DW::External::Account->xpost_string_to_hash( $p->{xpostdetail} );
+        my $xpostlinks = "";
+        foreach my $xpostkey ( keys %$xposthash ) {
+            my $xpostvalue = $xposthash->{$xpostkey};
+            if ( $xpostvalue->{url} ) {
+                if ( $xpostlinks ) {
+                    $xpostlinks = $xpostlinks . " ";
+                }
+                $xpostlinks = $xpostlinks . '<a href = "' .  $xpostvalue->{url} . '">' .  $xpostvalue->{url} . '</a>';
+            }
+        }
+        if ( $xpostlinks ) {
+            $e->{metadata}->{xpost} = $xpostlinks;
+        }
+    }
+
     if (my $mid = $p->{'current_moodid'}) {
         my $theme = defined $arg->{'moodthemeid'} ? $arg->{'moodthemeid'} : $u->{'moodthemeid'};
         my %pic;
diff -r 04ba85a71e7c -r 59955acbe4f8 htdocs/manage/externalaccount.bml
--- a/htdocs/manage/externalaccount.bml	Sun May 02 06:54:19 2010 +0000
+++ b/htdocs/manage/externalaccount.bml	Sun May 02 06:57:34 2010 +0000
@@ -208,6 +208,17 @@ use strict;
     $body .= "<br />$xpostbydefault_errdiv" if $xpostbydefault_errdiv;
     $body .= "</td></tr>\n";
 
+    $body .= "<tr><td class='setting_label'><label for='recordlink'>" . $ML{'.setting.xpost.option.recordlink'} . "</label></td>";
+    $body .= "<td>" . LJ::html_check({
+        name     => "recordlink",
+        value    => 1,
+        id       => "recordlink",
+        selected => $editpage ? $editacct->recordlink : $POST{recordlink}
+    });
+    my $recordlink_errdiv = errdiv(\%errs, "recordlink");
+    $body .= "<br />$recordlink_errdiv" if $recordlink_errdiv;
+    $body .= "</td></tr>\n";
+
     $body .= "<tr><td class='setting_label'><label for='savepassword'>" . $ML{'.setting.xpost.option.savepassword'} . "</label></td>";
     $body .= "<td>" . LJ::html_check({
         name     => "savepassword",
@@ -265,6 +276,7 @@ sub create_external_account {
     $opts{password} = $POST->{password};
     $opts{username} = $POST->{username};
     $opts{xpostbydefault} = $POST->{xpostbydefault};
+    $opts{recordlink} = $POST->{recordlink};
     $opts{savepassword} = $POST->{savepassword};
 
     # username is required
@@ -393,6 +405,7 @@ sub edit_external_account {
         $acct->set_password($POST{password});
     }
     $acct->set_xpostbydefault($POST{xpostbydefault});
+    $acct->set_recordlink($POST{recordlink});
 
     return "&update=" . $acct->acctid;
 }
diff -r 04ba85a71e7c -r 59955acbe4f8 htdocs/manage/externalaccount.bml.text
--- a/htdocs/manage/externalaccount.bml.text	Sun May 02 06:54:19 2010 +0000
+++ b/htdocs/manage/externalaccount.bml.text	Sun May 02 06:57:34 2010 +0000
@@ -32,6 +32,8 @@
 
 .setting.xpost.option.password.info=(Please make sure you have caps-lock disabled and enter the correct password.)
 
+.setting.xpost.option.recordlink=Display Cross Post Links
+
 .setting.xpost.option.savepassword=Save Password
 
 .setting.xpost.option.servicename=Custom Service Name
--------------------------------------------------------------------------------