Plugin Directory

Changeset 439221


Ignore:
Timestamp:
09/16/2011 08:59:51 PM (15 years ago)
Author:
dexxaye
Message:

0.8 Commit

Location:
auto-url/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • auto-url/trunk/auto-url-data.php

    r436897 r439221  
    7070                            FROM $wpdb->posts p
    7171                            LEFT JOIN " . AU_ALIAS_TABLE_NAME . " a ON (a.post_id = p.ID)
    72                             WHERE p.post_type IN ('post', 'page') AND p.post_status = 'publish'
     72                            WHERE (p.post_type IN ('post','page') AND p.post_status = 'publish')
     73                            OR (p.post_type IN ('attachment'))
    7374                            ORDER BY p.post_type, p.post_title");
    7475
  • auto-url/trunk/auto-url.php

    r436897 r439221  
    55  Plugin URI: http://www.bunchacode.com/programming/auto-url
    66  Description: generates customized permalinks according to post types, categories and tags
    7   Version: 0.7
    8   Author: Jiong Ye
     7  Version: 0.8
     8  Author: FunkyDude
    99  Author URI: http://www.bunchacode.com
    1010  License: GPL2
     
    2525  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2626 */
    27 ?>
    28 <?php
    2927
    3028global $au_db_version, $wpdb;
     
    4038
    4139function auto_url_install() {
    42     global $wpdb;
    43 
    44     require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
     40    global $wpdb, $au_db_version;
    4541
    4642    $sql = "CREATE TABLE " . AU_ALIAS_TABLE_NAME . " (
     
    5349            KEY `post_id` (`post_id`)
    5450            );";
     51
     52    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    5553    dbDelta($sql);
    5654
    5755    update_option(AU_DB_VERSION_NAME, $au_db_version);
    58     update_option(AU_OPTION_PATTERN_NAME, '{"type":{"post":"\/show\/post\/%name%","page":"\/show\/page\/%name%"}}');
     56
     57    if (!get_option(AU_OPTION_PATTERN_NAME))
     58        update_option(AU_OPTION_PATTERN_NAME, '{"type":{"post":"\/show\/post\/%name%","page":"\/show\/page\/%name%"}}');
    5959}
    6060
    6161register_activation_hook(__FILE__, 'auto_url_install');
     62
     63function auto_url_db_check() {
     64    global $au_db_version;
     65    if (get_site_option(AU_DB_VERSION_NAME) != $au_db_version) {
     66        auto_url_install();
     67    }
     68}
     69
     70add_action('plugins_loaded', 'auto_url_db_check');
    6271
    6372/*
     
    147156        if ($action == 'Save') {
    148157            if (is_array($_POST['p'])) {
    149                 if (auto_url_is_valid_pattern($_POST['p'])) {
     158                $r = auto_url_is_valid_pattern($_POST['p']);
     159                if ($r['result']) {
    150160                    update_option(AU_OPTION_PATTERN_NAME, json_encode($_POST['p']));
    151161                    $message = 'Patterns Saved.';
    152162                } else {
    153                     $message = 'Invalid Patterns. Pattern must have either %id% or %name% to uniquely identify a post.';
     163                    $message = $r['message'];
    154164                }
    155165            }
     
    173183
    174184function auto_url_is_valid_pattern($patternGroups) {
    175     foreach ($patternGroups as $group) {
     185    foreach ($patternGroups as $type => $group) {
    176186        foreach ($group as $i => $p) {
     187            if ($type == 'type' && $i == 'media') {
     188                if (!strstr($p, '%id%')) {
     189                    return array(
     190                        'result' => false,
     191                        'message' => 'Post type media must contain %id% token in pattern.'
     192                    );
     193                }
     194            }
    177195            if (strlen(trim($p))) {
    178196                if (!strstr($p, '%id%') && !strstr($p, '%name%') && !strstr($p, '%namepath%')) {
    179                     return false;
    180                 }
    181             }
    182         }
    183     }
    184     return true;
     197                    return array(
     198                        'result' => false,
     199                        'message' => 'Invalid Patterns. Pattern must have either %id% or %name% to uniquely identify a post or page.'
     200                    );
     201                    ;
     202                }
     203            }
     204        }
     205    }
     206    return array('result' => true);
    185207}
    186208
     
    195217
    196218    //generate tag url
    197     for ($i = 0; $i < count($posts); $i++) {
    198         if (!empty($patterns['tag'])) {
     219    if (!empty($patterns['tag'])) {
     220        for ($i = 0; $i < count($posts); $i++) {
    199221            foreach ($patterns['tag'] as $id => $pattern) {
    200222                if (has_tag($id, $posts[$i]->ID)) {
     
    210232
    211233    //generate category url
    212     for ($i = 0; $i < count($posts); $i++) {
    213         if (!empty($patterns['category'])) {
     234    if (!empty($patterns['category'])) {
     235        for ($i = 0; $i < count($posts); $i++) {
    214236            foreach ($patterns['category'] as $id => $pattern) {
    215237                if (in_category($id, $posts[$i]->ID)) {
     
    225247
    226248    //generate posts url
    227     for ($i = 0; $i < count($posts); $i++) {
    228         if (isset($patterns['type']) && !empty($patterns['type'])) {
     249    if (isset($patterns['type']) && !empty($patterns['type'])) {
     250        for ($i = 0; $i < count($posts); $i++) {
    229251            if ($posts[$i]->post_type == 'post') {
    230252                if (auto_url_generate_url($posts[$i], $patterns['type']['post'])) {
     
    234256                if (auto_url_generate_url($posts[$i], $patterns['type']['page'])) {
    235257                    $count['Page links generated'] = isset($count['Page links generated']) ? $count['Page links generated'] + 1 : 1;
     258                }
     259            } else if ($posts[$i]->post_type == 'attachment') {
     260                if (auto_url_generate_url($posts[$i], $patterns['type']['media'])) {
     261                    $count['Media links generated'] = isset($count['Media links generated']) ? $count['Media links generated'] + 1 : 1;
    236262                }
    237263            }
     
    292318            break;
    293319        case '%name%':
    294             return $p->post_name;
     320            if ($p->post_type == 'post' || $p->post_type == 'page')
     321                return $p->post_name;
     322            else if ($p->post_type == 'attachment')
     323                return auto_url_generate_slug($p->post_title);
    295324            break;
    296325        case '%namepath%':
     
    389418        if (!empty($p)) {
    390419            $autoUrl = auto_url_get_url($p->ID);
    391             if (!empty($autoUrl))
    392                 return rtrim(get_option('siteurl'), "/") . $autoUrl->link;
     420            if (!empty($autoUrl)) {
     421                switch ($p->post_type) {
     422                    case 'post':
     423                    case 'page':
     424                    case 'attachment':
     425                        return rtrim(get_option('siteurl'), "/") . $autoUrl->link;
     426                        break;
     427                    default:
     428                        break;
     429                }
     430            }
    393431        }
    394432    }
     
    397435}
    398436
     437add_filter('attachment_link', 'auto_url_post_link_filter', 10, 3);
    399438add_filter('page_link', 'auto_url_post_link_filter', 10, 3);
    400439add_filter('post_link', 'auto_url_post_link_filter', 10, 3);
     
    438477                case 'post':
    439478                case 'page':
     479                case 'attachment':
    440480                    $vars = auto_url_fill_vars($links, $parts, $autoUrl);
    441481                    break;
     
    443483        }
    444484    }
    445 
    446485
    447486    return $vars;
     
    470509            $translate['%id%'] = 'page_id';
    471510            break;
     511        case 'attachment':
     512            $translate['%id%'] = 'attachment_id';
     513            break;
    472514    }
    473515
     
    481523    return $replacement;
    482524}
     525
     526?>
  • auto-url/trunk/css/auto_url_admin.css

    r435918 r439221  
    2828.placeHolderToken{width:65px;height:25px;}
    2929
     30#searchBox{width:350px;}
     31
    3032.removeToken{color:#ff0000 !important;padding:0 0 0 8px;font-size:1.1em;}
    3133
  • auto-url/trunk/readme.txt

    r436897 r439221  
    11=== Auto URL ===
    22Contributors: dexxaye
    3 Tags: url,permalink
     3Tags: url,permalink, attachment, media, rewrite, seo
    44Requires at least: 3.1
    55Tested up to: 3.2.1
    6 Stable tag: 0.7
     6Stable tag: 0.8
    77
    88Auto URL generates customized permalinks according to post types, categories and tags
     
    1111
    1212Auto URL generates customized permalinks according to post types, categories and tags.
    13 You can generate your own customized url for posts and pages by using different tokens.
     13You can generate your own customized url for posts, pages and attachments by using different tokens.
    1414Your posts and pages will still be accessible via your old permalinks.
    1515
  • auto-url/trunk/templates/pattern.php

    r436897 r439221  
    5656        <label>Page:</label>
    5757        <input type="text" name="p[type][page]" value="<?php echo isset($patterns['type']['page'])?$patterns['type']['page']:'';?>"/>
     58    </div>
     59    <div class="formRow patternRow">
     60        <label>Media:</label>
     61        <input type="text" name="p[type][media]" value="<?php echo isset($patterns['type']['media'])?$patterns['type']['media']:'';?>"/>
    5862    </div>
    5963</fieldset>
  • auto-url/trunk/templates/url.php

    r435918 r439221  
    11<?php include('common/header.php');?>
     2<div class="formRow">
     3    <input type="text" id="searchBox" value='Search...' />
     4</div>
    25<table id="autoUrlTable" class="wp-list-table widefat" cellspacing="0">
    36    <thead>
Note: See TracChangeset for help on using the changeset viewer.