Changeset 439221
- Timestamp:
- 09/16/2011 08:59:51 PM (15 years ago)
- Location:
- auto-url/trunk
- Files:
-
- 6 edited
-
auto-url-data.php (modified) (1 diff)
-
auto-url.php (modified) (17 diffs)
-
css/auto_url_admin.css (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
templates/pattern.php (modified) (1 diff)
-
templates/url.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
auto-url/trunk/auto-url-data.php
r436897 r439221 70 70 FROM $wpdb->posts p 71 71 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')) 73 74 ORDER BY p.post_type, p.post_title"); 74 75 -
auto-url/trunk/auto-url.php
r436897 r439221 5 5 Plugin URI: http://www.bunchacode.com/programming/auto-url 6 6 Description: generates customized permalinks according to post types, categories and tags 7 Version: 0. 78 Author: Jiong Ye7 Version: 0.8 8 Author: FunkyDude 9 9 Author URI: http://www.bunchacode.com 10 10 License: GPL2 … … 25 25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 26 */ 27 ?>28 <?php29 27 30 28 global $au_db_version, $wpdb; … … 40 38 41 39 function auto_url_install() { 42 global $wpdb; 43 44 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 40 global $wpdb, $au_db_version; 45 41 46 42 $sql = "CREATE TABLE " . AU_ALIAS_TABLE_NAME . " ( … … 53 49 KEY `post_id` (`post_id`) 54 50 );"; 51 52 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 55 53 dbDelta($sql); 56 54 57 55 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%"}}'); 59 59 } 60 60 61 61 register_activation_hook(__FILE__, 'auto_url_install'); 62 63 function 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 70 add_action('plugins_loaded', 'auto_url_db_check'); 62 71 63 72 /* … … 147 156 if ($action == 'Save') { 148 157 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']) { 150 160 update_option(AU_OPTION_PATTERN_NAME, json_encode($_POST['p'])); 151 161 $message = 'Patterns Saved.'; 152 162 } else { 153 $message = 'Invalid Patterns. Pattern must have either %id% or %name% to uniquely identify a post.';163 $message = $r['message']; 154 164 } 155 165 } … … 173 183 174 184 function auto_url_is_valid_pattern($patternGroups) { 175 foreach ($patternGroups as $ group) {185 foreach ($patternGroups as $type => $group) { 176 186 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 } 177 195 if (strlen(trim($p))) { 178 196 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); 185 207 } 186 208 … … 195 217 196 218 //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++) { 199 221 foreach ($patterns['tag'] as $id => $pattern) { 200 222 if (has_tag($id, $posts[$i]->ID)) { … … 210 232 211 233 //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++) { 214 236 foreach ($patterns['category'] as $id => $pattern) { 215 237 if (in_category($id, $posts[$i]->ID)) { … … 225 247 226 248 //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++) { 229 251 if ($posts[$i]->post_type == 'post') { 230 252 if (auto_url_generate_url($posts[$i], $patterns['type']['post'])) { … … 234 256 if (auto_url_generate_url($posts[$i], $patterns['type']['page'])) { 235 257 $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; 236 262 } 237 263 } … … 292 318 break; 293 319 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); 295 324 break; 296 325 case '%namepath%': … … 389 418 if (!empty($p)) { 390 419 $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 } 393 431 } 394 432 } … … 397 435 } 398 436 437 add_filter('attachment_link', 'auto_url_post_link_filter', 10, 3); 399 438 add_filter('page_link', 'auto_url_post_link_filter', 10, 3); 400 439 add_filter('post_link', 'auto_url_post_link_filter', 10, 3); … … 438 477 case 'post': 439 478 case 'page': 479 case 'attachment': 440 480 $vars = auto_url_fill_vars($links, $parts, $autoUrl); 441 481 break; … … 443 483 } 444 484 } 445 446 485 447 486 return $vars; … … 470 509 $translate['%id%'] = 'page_id'; 471 510 break; 511 case 'attachment': 512 $translate['%id%'] = 'attachment_id'; 513 break; 472 514 } 473 515 … … 481 523 return $replacement; 482 524 } 525 526 ?> -
auto-url/trunk/css/auto_url_admin.css
r435918 r439221 28 28 .placeHolderToken{width:65px;height:25px;} 29 29 30 #searchBox{width:350px;} 31 30 32 .removeToken{color:#ff0000 !important;padding:0 0 0 8px;font-size:1.1em;} 31 33 -
auto-url/trunk/readme.txt
r436897 r439221 1 1 === Auto URL === 2 2 Contributors: dexxaye 3 Tags: url,permalink 3 Tags: url,permalink, attachment, media, rewrite, seo 4 4 Requires at least: 3.1 5 5 Tested up to: 3.2.1 6 Stable tag: 0. 76 Stable tag: 0.8 7 7 8 8 Auto URL generates customized permalinks according to post types, categories and tags … … 11 11 12 12 Auto 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.13 You can generate your own customized url for posts, pages and attachments by using different tokens. 14 14 Your posts and pages will still be accessible via your old permalinks. 15 15 -
auto-url/trunk/templates/pattern.php
r436897 r439221 56 56 <label>Page:</label> 57 57 <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']:'';?>"/> 58 62 </div> 59 63 </fieldset> -
auto-url/trunk/templates/url.php
r435918 r439221 1 1 <?php include('common/header.php');?> 2 <div class="formRow"> 3 <input type="text" id="searchBox" value='Search...' /> 4 </div> 2 5 <table id="autoUrlTable" class="wp-list-table widefat" cellspacing="0"> 3 6 <thead>
Note: See TracChangeset
for help on using the changeset viewer.