Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
general-topic
Link formatting when upgrading 4.5 to 5.1.3
Avatar
Peter
Member
Free Members
sp_UserOfflineSmall Offline
Sep 8, 2012 - 7:41 pm

I'm working on upgrading from 4.5 to 5.1.3.

It looks like links that were auto shortened and now formatted like this...

<a href="http://www.theglobeandmail.com/globe-investor/personal-finance/problem-with-post-edit-buttonigher-fees-borrowing-costs-welcome-to-booming-big-six-banking/article4521956/" rel="nofollow" target="_blank">http://www.theglobeandmail.com.....le4521956/</a>

... are not properly shortened anymore. They instead show up as just the part before the periods and thus the actual link is broken. Would installing a forum plugin (such as the TinyMCE one) fix the issue or is it an inherent issue with new auto-shortening logic?

Avatar
Peter
Member
Free Members
sp_UserOfflineSmall Offline
Sep 8, 2012 - 7:43 pm

In fact, the above post is a perfect illustration of the issue, as is the test below :)

Testing by editing the HTML source: http://www.theglobeandmail.com.....le4521956/

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Sep 8, 2012 - 8:08 pm

It seems somewhere between 4.5.1 and 5.x, we made a change in the url shortening... earlier, it incorrectly was saving shortened urls in the database vs shortening them on display... we corrected that in 5.0 but does have some knock off on earlier shortenings due to a bug in wp where the make clickabled function chokes on a dot/period in a url anchor text and thus dorks it up... We are trying to find another make clickable function besides that wp one that works properly, but have not found one yet that does not mess up elsewhere... a catch 22 situation at the moment...

but new posts wont have this problem...

Avatar
Peter
Member
Free Members
sp_UserOfflineSmall Offline
Sep 9, 2012 - 10:19 pm

Here's a quick script to clean up old style links! It could probably use Simple:Press API functions for fetching and updating posts (speaking of which, is there documentation for manipulating the various content elemenest?).

<?php

/*
    For migrating from Simple:Press (WordPress forum plugin) 4.5 to 5.1.3 and cleaning up link shortening
    In 4.5, links were shortened on save
    In 5.1.3, links are shortened on display

    Run this script in the root of your WordPress directory: php clean_up_links.php

    Source: https://simple-press.com/suppo.....5-to-5-1-3
*/

include 'wp-load.php';

$postCount = $wpdb->get_var( 'SELECT COUNT(*) FROM wp_sfposts' );
$limit = 100;

print "\n Total post count: $postCount";
print "\n Looping through $limit at a time";
print "\n";

for( $offset = 0; $offset < $postCount; $offset += $limit )
{
    $posts = $wpdb->get_results( "SELECT post_id, post_content FROM wp_sfposts LIMIT $limit, $offset ORDER BY post_id ASC" );
    foreach( $posts as $post )
    {
        /*
            Matches would be:
            0 = The entire string
            1 = The link in the <a> tag
            2 = The rest of the parameters in the <a> tag (nofollow, target, etc.)
            3 = The part after the 5 periods

            So then we want to replace 0 with 1 for each result

            We are assuming that the links have 5 consecutive periods
        */

        $postContent = $post->post_content;
        $postID = $post->post_id;

        preg_match_all( "/<a href=\"(.*?)\"(.*?)\.\.\.\.\.(.*?)<\/a>/is", $postContent, $linkMatches );

        if( !empty( $linkMatches[0] ) )
        {
            foreach( $linkMatches[0] as $index => $stringMatch )
            {
                $postContent = str_replace( $stringMatch, $linkMatches[1][$index], $postContent );
                $wpdb->query( $wpdb->prepare( "UPDATE wp_sfposts SET post_content = %s WHERE post_id = %d LIMIT 1;", $postContent, $postID ) );
            }
        }
    }

    // Basic feedback to the user
    print '+';
}

?>

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Sep 10, 2012 - 8:04 pm

hey Peter, welcome back!

wow, going to have to take a closer look at that when I get a chance...  might be something we want to including in the upgrade script from 4.5...

sorry, what do you mean by content elements?  the display template functions?  have you checked out the codex?  http://codex.simple-press.com

its far from complete but we continue to populate it with more data as we go... sorry, just a limit to what the 3 of us can do! ;)

Avatar
Peter
Member
Free Members
sp_UserOfflineSmall Offline
Sep 10, 2012 - 11:04 pm

Regarding "manipulating various content elements", I mean code like:

sp_update_post( $postID, $postContent );

... so that we don't have to directly write SQL.

I think there was code like that in 4.5.  It might be obvious in 5.1.3, although I don't see it in the codex.  Then again, I might just need to get familiar with the "new" version :)

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 11, 2012 - 2:16 am

As Steve said above we are trying hard to get the Codex API pages documented but it is a time thing with such a small team. In the meantime we suggest to users that if they need some API clarification on any point, they ask here and we will endeavour to give detailed explanations, advice and pointers and help walk them through things.

There just are not enough hours in a day!

andy-signature.png
YELLOW
SWORDFISH
Avatar
Peter
Member
Free Members
sp_UserOfflineSmall Offline
Sep 16, 2012 - 3:10 pm

I can't edit my original code post, so here's a small correction: the database query should show:

LIMIT $limit, $offset

instead of:

LIMIT $offset, $limit

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 17, 2012 - 4:14 am

Well maybe I am missing something this early in the morning! But your SQL statement above looks right to me...

andy-signature.png
YELLOW
SWORDFISH
Avatar
Peter
Member
Free Members
sp_UserOfflineSmall Offline
Sep 17, 2012 - 9:19 am

Oops, I flipped the correction :)

Should be:

LIMIT $offset, $limit

instead of:

LIMIT $limit, $offset

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 619
Members: 17362
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10127
Posts: 79625