Post by justinesmithies » Sat Apr 20, 2013 4:10 am

I have written a plugin for OC and it has links like http://test.codetrove.com/index.php?rou ... _post_id=4 and the software modifys the link to add #3 at the end to display the 3rd reply.
This all works fine until someone activates SEO URLS . The #3 or whatever number is given is lost.

If i look at http://www.clickbuyget.com/9-gfbcf then add #3 it displays the 3rd reply but thats not the point the original url had #3 at the very end and it got lost during rewrite.

Is there something i could modify in seo_url.php ?????

Any help would be appreciated.

This is my modified SEO_URL.PHP :

Code: Select all

<?php
class ControllerCommonSeoUrl extends Controller {
	public function index() {
		// Add rewrite to url class
		if ($this->config->get('config_seo_url')) {
			$this->url->addRewrite($this);
		}
		
		// Decode URL
		if (isset($this->request->get['_route_'])) {
			$parts = explode('/', $this->request->get['_route_']);
			
			foreach ($parts as $part) {
				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($part) . "'");
				
				if ($query->num_rows) {
					$url = explode('=', $query->row['query']);
					
					if ($url[0] == 'product_id') {
						$this->request->get['product_id'] = $url[1];
					}
					
					if ($url[0] == 'category_id') {
						if (!isset($this->request->get['path'])) {
							$this->request->get['path'] = $url[1];
						} else {
							$this->request->get['path'] .= '_' . $url[1];
						}
					}	
					
					if ($url[0] == 'manufacturer_id') {
						$this->request->get['manufacturer_id'] = $url[1];
					}
					
					if ($url[0] == 'information_id') {
						$this->request->get['information_id'] = $url[1];
					}

					#add this

					if ($url[0] == 'forum_post_id') {
						$this->request->get['forum_post_id'] = $url[1];
					}

					if ($url[0] == 'forum_category_id') {
						if (!isset($this->request->get['forum_path'])) {
							$this->request->get['forum_path'] = $url[1];
						} else {
							$this->request->get['forum_path'] .= '_' . $url[1];
						}
					}
					#end
					
				} else {
					$this->request->get['route'] = 'error/not_found';	
				}
			}
			
			if (isset($this->request->get['product_id'])) {
				$this->request->get['route'] = 'product/product';
			} elseif (isset($this->request->get['path'])) {
				$this->request->get['route'] = 'product/category';
			} elseif (isset($this->request->get['manufacturer_id'])) {
				$this->request->get['route'] = 'product/manufacturer/product';
			} elseif (isset($this->request->get['information_id'])) {
				$this->request->get['route'] = 'information/information';
			}#add this
			elseif (isset($this->request->get['forum_post_id'])) {
				$this->request->get['route'] = 'forum/read';
			}elseif (isset($this->request->get['forum_path'])) {
				$this->request->get['route'] = 'forum/forum_category';
			}#end

			
			if (isset($this->request->get['route'])) {
				return $this->forward($this->request->get['route']);
			}
		}
	}
	
	public function rewrite($link) {
		if ($this->config->get('config_seo_url')) {
			$url_data = parse_url(str_replace('&', '&', $link));
		
			$url = ''; 
			
			$data = array();
			
			parse_str($url_data['query'], $data);
			
			foreach ($data as $key => $value) {
				if (isset($data['route'])) {
					#add this  ($data['route'] == 'forum/read' && $key == 'forum_post_id')
					if (($data['route'] == 'forum/read' && $key == 'forum_post_id') || ($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/product' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
						$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'");
					
						if ($query->num_rows) {
							$url .= '/' . $query->row['keyword'];
							
							unset($data[$key]);
						}					
					} elseif ($key == 'path') {
						$categories = explode('_', $value);
						
						foreach ($categories as $category) {
							$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'category_id=" . (int)$category . "'");
					
							if ($query->num_rows) {
								$url .= '/' . $query->row['keyword'];
							}							
						}
						
						unset($data[$key]);
					}
					#add this
					elseif ($key == 'forum_path') {
						$categories = explode('_', $value);
						
						foreach ($categories as $category) {
							$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'forum_category_id=" . (int)$category . "'");
					
							if ($query->num_rows) {
								$url .= '/' . $query->row['keyword'];
							}							
						}
						
						unset($data[$key]);
					}#end 
				}
			}
		
			if ($url) {
				unset($data['route']);
			
				$query = '';
			
				if ($data) {
					foreach ($data as $key => $value) {
						$query .= '&' . $key . '=' . $value;
					}
					
					if ($query) {
						$query = '?' . trim($query, '&');
					}
				}

				return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query;
			} else {
				return $link;
			}
		} else {
			return $link;
		}		
	}	
}
?>
Last edited by justinesmithies on Sat Apr 20, 2013 4:33 am, edited 1 time in total.

User avatar

Posts

Joined
Sun Dec 23, 2012 5:31 am

Post by justinesmithies » Sat Apr 20, 2013 4:33 am

I solved it by adding this :

Code: Select all

 . '#' . $url_data['fragment']

User avatar

Posts

Joined
Sun Dec 23, 2012 5:31 am
Who is online

Users browsing this forum: No registered users and 305 guests