Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: gamesmad on April 13, 2012, 10:54:49 AM

Title: Aeva Media & PrettyURLs
Post by: gamesmad on April 13, 2012, 10:54:49 AM
Could anybody advise me on how to get PrettyURLs to work with Aeva Media?

There seems to be basic support (http://domain.com/media), but further than that the URLs are not "pretty" (http://domain.com/media/?sa=item;in=1).

Are there some additional filters I could setup?

Edit - I have found this http://www.simplemachines.org/community/index.php?topic=146969.msg2487779#msg2487779 but not sure if it is the right thing?
Title: Re: Aeva Media & PrettyURLs
Post by: gamesmad on April 17, 2012, 08:20:02 AM
Bump.
Title: Re: Aeva Media & PrettyURLs
Post by: Suki on April 17, 2012, 09:06:33 AM
I don't know Pretty urls or aeva that well, but by looking at the code posted, the main problem to sort out is the regex and if nothing had changed, the code posted there should work, did you tried it?
Title: Re: Aeva Media & PrettyURLs
Post by: gamesmad on April 20, 2012, 08:59:18 AM
Thanks for your reply.  I haven't tried the code as I'm unsure where to put it?

I've had a look in the PrettyURLs files in Sources and couldn't find anything that looked in a similar format.  I assume I am looking for a file with other similar code in?
Title: Re: Aeva Media & PrettyURLs
Post by: Suki on April 20, 2012, 09:14:30 AM
Taking a quick look, it should go on prettyurls PrettyUrls-Filters.php, I'm not so sure how the filters system works as I never used pretty urls.
Title: Re: Aeva Media & PrettyURLs
Post by: nend on May 01, 2012, 11:42:09 PM
Easy,

In PrettyUrls-Filters.php Add this function
// Filter Aeva Media URLs
function pretty_aeva_filter($urls)
{
global $boardurl;

$pattern = array(
'~.*[?;&]action=media;sa=media;in=([0-9]+);(thumba?|preview)(.*)~S',
'~.*[?;&]action=media;sa=(album|item|media);in=([0-9]+)(.*)~S',
'~.*[?;&]action=media(.*)~S',
);
$replacement = array(
$boardurl . '/media/$2/$1/?$3',
$boardurl . '/media/$1/$2/?$3',
$boardurl . '/media/?$1',
);
foreach ($urls as $url_id => $url)
if (!isset($url['replacement']) && strpos($url['url'], 'action=media') !== false)
$urls[$url_id]['replacement'] = preg_replace($pattern, $replacement, $url['url']);
return $urls;
}


In PrettyUrls-Tests.php add this function.

// Dummy Aeva Test
function pretty_aeva_test()
{
global $scripturl, $txt;

// Just return a few
return array(
'<a href="' . $scripturl . '?action=media;sa=album;in=1">' . $txt['help'] . '</a>',
'<a href="' . $scripturl . '?action=media;sa=item;in=123">' . $txt['search'] . '</a>',
'<a href="' . $scripturl . '?action=media;sa=media;in=38">' . $txt['members_title'] . '</a>',
);
}


Now on to the db, navigate to...
http://yoursite.com/path-to-forum/index.php?action=admin;area=pretty;sa=filters

This is a hidden menu, not selectable, but it is there to edit the json structure in the db.

Replace content with this.
{
    "aeva": {
        "description": "Aeva Media filter",
        "enabled": 1,
        "filter": {
            "priority": 38,
            "callback": "pretty_aeva_filter"
        },
        "rewrite": {
            "priority": 38,
            "rule": [
                "RewriteRule ^media/(thumba?|preview)/([0-9]+)/?(.*)$ index.php?action=media;sa=media;in=$2;$1;$3 [L,QSA]",
                "RewriteRule ^media/(?:(album|item|media)/([0-9]+)/?)?(.*)$ index.php?action=media;sa=$1;in=$2;$3 [L,QSA]"
            ]
        },
        "test_callback": "pretty_aeva_test",
        "title": "Aeva Media"
    },
    "boards": {
        "description": "Rewrite Board URLs",
        "enabled": 1,
        "filter": {
            "priority": 45,
            "callback": "pretty_urls_board_filter"
        },
        "rewrite": {
            "priority": 50,
            "rule": [
                "RewriteRule ^ROOTURL([-_!~*'()$a-zA-Z0-9]+)/?$ ./index.php?pretty;board=$1.0 [L,QSA]",
                "RewriteRule ^ROOTURL([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/?$ ./index.php?pretty;board=$1.$2 [L,QSA]"
            ]
        },
        "test_callback": "pretty_boards_test",
        "title": "Boards"
    },
    "topics": {
        "description": "Rewrite Topic URLs",
        "enabled": 1,
        "filter": {
            "priority": 40,
            "callback": "pretty_urls_topic_filter"
        },
        "rewrite": {
            "priority": 55,
            "rule": [
                "RewriteRule ^ROOTURL([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/?$ ./index.php?pretty;board=$1;topic=$2.0 [L,QSA]",
                "RewriteRule ^ROOTURL([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/?$ ./index.php?pretty;board=$1;topic=$2.$3 [L,QSA]"
            ]
        },
        "test_callback": "pretty_topics_test",
        "title": "Topics"
    },
    "actions": {
        "description": "Rewrite Action URLs (ie, index.php?action=something)",
        "enabled": 1,
        "filter": {
            "priority": 55,
            "callback": "pretty_urls_actions_filter"
        },
        "rewrite": {
            "priority": 45,
            "rule": "#ACTIONS"
        },
        "test_callback": "pretty_actions_test",
        "title": "Actions"
    },
    "profiles": {
        "description": "Rewrite Profile URLs. As this uses the Username of an account rather than it's Display Name, it may not be desirable to your users.",
        "enabled": 0,
        "filter": {
            "priority": 50,
            "callback": "pretty_profiles_filter"
        },
        "rewrite": {
            "priority": 40,
            "rule": "RewriteRule ^profile/([^/]+)/?$ ./index.php?pretty;action=profile;user=$1 [L,QSA]"
        },
        "test_callback": "pretty_profiles_test",
        "title": "Profiles"
    }
}


Piece of cake, lol,  ;)

*edit

The link in my sig has a Aeva Gallery with it done this way. I just copied and pasted my work from there.