Skip to content

Commit d286ae1

Browse files
committed
fix: bug with seo urls
1 parent 8a1fe31 commit d286ae1

File tree

12 files changed

+82
-34
lines changed

12 files changed

+82
-34
lines changed

.DS_Store

0 Bytes
Binary file not shown.

model/common/seo.php

+40-32
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,60 @@
22

33

44
class VFA_ModelCommonSeo extends VFA_Model {
5+
public function addUrl($url, $type, $id)
6+
{
7+
global $wpdb;
8+
9+
$sql = 'SELECT *
10+
FROM
11+
`'.$wpdb->prefix.'vuefront_url`
12+
WHERE url LIKE \''.$url.'\'';
13+
14+
$result = $wpdb->get_row( $sql );
15+
if (!$result) {
16+
$wpdb->insert( $wpdb->prefix.'vuefront_url' , array("url" => $url, "id" => $id, "type" => $type));
17+
}
18+
}
519
public function get_category_by_url($url) {
620
foreach( (get_terms()) as $category) {
721
$keyword = str_replace(get_site_url(), '', get_term_link((int)$category->term_id));
822
$keyword = trim($keyword, '/?');
923
$keyword = trim($keyword, '/');
24+
var_dump($keyword);
1025

11-
if ( '/' . $keyword == $url )
12-
26+
if ( $keyword == $url ) {
27+
return array('id' => $category->term_id, 'slug' => $category->slug, 'type' => $category->taxonomy);
28+
}
29+
if ( '/' . $keyword == $url ) {
30+
return array('id' => $category->term_id, 'slug' => $category->slug, 'type' => $category->taxonomy);
31+
}
32+
if ( '/?' . $keyword == $url ) {
1333
return array('id' => $category->term_id, 'slug' => $category->slug, 'type' => $category->taxonomy);
34+
}
35+
1436
}
1537
return false;
1638
}
1739
public function searchKeyword($url) {
18-
$search = url_to_postid($url);
19-
$type = '';
20-
21-
if ($search != 0) {
22-
if (get_post_type($search) == 'post') {
23-
$type = 'post';
24-
} else if (get_post_type($search) == 'page') {
25-
$type = 'page';
26-
} else {
27-
$type = 'product';
28-
}
29-
} else {
30-
$search = $this->get_category_by_url($url);
31-
if ($search) {
32-
if ($search['type'] == 'category') {
33-
$type = 'blog-category';
34-
$search = $search['id'];
35-
} else if($search['type'] == 'pwb-brand') {
36-
$type = 'manufacturer';
37-
$search = $search['slug'];
38-
} else {
39-
$type='category';
40-
$search = $search['id'];
41-
}
42-
} else {
43-
$search = '';
44-
}
4540

46-
}
41+
global $wpdb;
42+
43+
$sql = 'SELECT *
44+
FROM
45+
`'.$wpdb->prefix.'vuefront_url`
46+
WHERE url LIKE \''.$url.'\'';
4747

48+
$result = $wpdb->get_row( $sql );
49+
if (!$result) {
50+
return array(
51+
'id' => '',
52+
'type' => '',
53+
'url' => $url
54+
);
55+
}
4856
return array(
49-
'id' => $search,
50-
'type' => $type,
57+
'id' => $result->id,
58+
'type' => $result->type,
5159
'url' => $url
5260
);
5361
}

plugin.php

+29-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: VueFront
44
* Plugin URI: https://github.com/vuefront/wordpress
55
* Description: VueFront CMS Connect App for Wordpress.
6-
* Version: 2.0.0
6+
* Version: 2.1.0
77
* Author: VueFront
88
* Author URI: http://vuefront.com
99
*/
@@ -37,6 +37,8 @@ function VFA_simulate_as_not_rest($is_rest_api_request)
3737
add_action('wp_ajax_vf_update', 'VFA_vuefront_admin_action_update');
3838
add_action('wp_ajax_vf_turn_off', 'VFA_vuefront_admin_action_turn_off');
3939
add_action('wp_ajax_vf_information', 'VFA_vuefront_admin_action_vf_information');
40+
register_activation_hook (__FILE__, 'VFA_install');
41+
add_action( 'plugins_loaded', 'VFA_update_db_check' );
4042

4143
function VFA_vuefront_admin_styles()
4244
{
@@ -143,6 +145,32 @@ function VFA_vuefront_admin_action_apps_create()
143145
wp_die();
144146
}
145147

148+
function VFA_install () {
149+
global $wpdb;
150+
151+
$table_name = $wpdb->prefix . "vuefront_url";
152+
153+
$charset_collate = $wpdb->get_charset_collate();
154+
155+
$sql = 'CREATE TABLE IF NOT EXISTS `' . $table_name . '` (
156+
`id_url` int(11) unsigned NOT NULL AUTO_INCREMENT,
157+
`id` varchar( 255 ) NOT NULL,
158+
`type` varchar(64) NOT NULL,
159+
`url` varchar(255) NOT NULL,
160+
PRIMARY KEY (`id_url`)
161+
) '.$charset_collate;
162+
163+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
164+
dbDelta( $sql );
165+
}
166+
167+
function VFA_update_db_check() {
168+
global $vfa_db_version;
169+
if ( get_site_option( 'vfa_db_version' ) != $vfa_db_version ) {
170+
VFA_install();
171+
}
172+
}
173+
146174
function VFA_vuefront_admin_action_apps_edit() {
147175
$setting = get_option('vuefront-apps');
148176

resolver/blog/category.php

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public function url($data) {
106106

107107
if($keyword != '') {
108108
$result = '/'.$keyword;
109+
$this->load->model('common/seo');
110+
$this->model_common_seo->addUrl($result, 'blog-category', $category_info['id']);
109111
}
110112

111113
return $result;

resolver/blog/post.php

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ public function url($data) {
156156

157157
if ($post_info['keyword']) {
158158
$result = '/'.$post_info['keyword'];
159+
$this->load->model('common/seo');
160+
$this->model_common_seo->addUrl($result, 'blog-post', $post_info['id']);
159161
}
160162

161163
return $result;

resolver/common/page.php

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public function url($data) {
7878

7979
if ($post_info['keyword']) {
8080
$result = '/'.$post_info['keyword'];
81+
$this->load->model('common/seo');
82+
$this->model_common_seo->addUrl($result, 'page', $post_info['id']);
8183
}
8284

8385
return $result;

resolver/store/category.php

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ public function url($data) {
128128

129129
if($keyword != '') {
130130
$result = '/'.$keyword;
131+
$this->load->model('common/seo');
132+
$this->model_common_seo->addUrl($result, 'category', $category_info['id']);
131133
}
132134

133135
return $result;

resolver/store/manufacturer.php

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public function url($data)
9797

9898
if ($category_info['keyword']) {
9999
$result = '/'.$category_info['keyword'];
100+
$this->load->model('common/seo');
101+
$this->model_common_seo->addUrl($result, 'manufacturer', $category_info['id']);
100102
}
101103

102104

resolver/store/product.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function get($args) {
5353
$this->load->model('common/vuefront');
5454
$resultEvent = $this->model_common_vuefront->pushEvent("fetch_product", array( "extra" => array(), "product_id" => $product->ID));
5555

56-
$keyword = str_replace(get_site_url(), '', get_post_permalink((int)$product->ID));
56+
$keyword = str_replace(get_site_url(), '', get_permalink((int)$product->ID));
5757
$keyword = trim($keyword, '/?');
5858
$keyword = trim($keyword, '/');
5959

@@ -302,6 +302,8 @@ public function url($data)
302302

303303
if ($product_info['keyword']) {
304304
$result = '/'.$product_info['keyword'];
305+
$this->load->model('common/seo');
306+
$this->model_common_seo->addUrl($result, 'product', $product_info['id']);
305307
}
306308

307309
return $result;

view/.DS_Store

0 Bytes
Binary file not shown.

view/javascript/.DS_Store

0 Bytes
Binary file not shown.

view/javascript/d_pax/.DS_Store

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)