forked from topspin/topspin-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopspin_shortcodes.php
More file actions
176 lines (169 loc) · 8.02 KB
/
topspin_shortcodes.php
File metadata and controls
176 lines (169 loc) · 8.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/*
* Last Modified: January 24, 2011
*
* ----------------------------------
* Change Log
* ----------------------------------
* 2012-01-24
- Added nav menu shortcode @eThan
* 2011-09-19
- Fixed shortcode content positioning - [@bryanlanders - https://github.com/topspin/topspin-wordpress/issues/19]
* 2011-08-01
- Updated topspin_shortcode_featured_item() to display multiple featured images
- Fixed the pagination to work with and without permalinks
- Added new short code [topspin_store_item]
* 2011-04-05
* - updated topspin_shortcode_buy_buttons()
update template file path orders for new template modes:
3.1: <current-theme>/topspin-mode, <parent-theme>/topspin-mode
3.0.0: <current-theme>/topspin-template, <parent-theme>/topspin-template
Default: <plugin-dir>/topspin-mode
* - update topspin_shortcode_featured_item()
update template file path orders for new template modes: (see top)
*/
### Short Codes
add_shortcode('topspin_store_item','topspin_shortcode_store_item');
add_shortcode('topspin_buy_buttons','topspin_shortcode_buy_buttons');
add_shortcode('topspin_featured_item','topspin_shortcode_featured_item');
add_shortcode('topspin_store_nav_menu','topspin_shortcode_store_nav_menu');
### [topspin_store_item]
### @id The item ID
function topspin_shortcode_store_item($atts) {
global $store;
$defaults = array('id'=>0);
$a = shortcode_atts($defaults,$atts);
if($a['id']) {
$featureditem = topspin_get_item($a['id']);
if($featureditem) {
ob_start();
## Template File
$templateMode = $store->getSetting('topspin_template_mode');
$templatefile = 'templates/topspin-'.$templateMode.'/featured-item.php';
## 3.1
if(file_exists(TOPSPIN_CURRENT_THEME_PATH.'/topspin-'.$templateMode.'/featured-item.php')) { $templatefile = TOPSPIN_CURRENT_THEME_PATH.'/topspin-'.$templateMode.'/featured-item.php'; }
elseif(file_exists(TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-'.$templateMode.'/featured-item.php')) { $templatefile = TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-'.$templateMode.'/featured-item.php'; }
## 3.0.0
if(file_exists(TOPSPIN_CURRENT_THEME_PATH.'/topspin-templates/featured-item.php')) { $templatefile = TOPSPIN_CURRENT_THEME_PATH.'/topspin-templates/featured-item.php'; }
elseif(file_exists(TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-templates/featured-item.php')) { $templatefile = TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-templates/featured-item.php'; }
include($templatefile);
$html = ob_get_contents();
ob_end_clean();
return $html;
}
}
}
### [topspin_buy_buttons]
### @id Default: the current store's ID
function topspin_shortcode_buy_buttons($atts) {
## Outputs the current store grid
global $store;
global $post;
//Query string append sign
$permalinkEnabled = (get_option('permalink_structure')!='') ? true : false;
$queryAppendSign = ($permalinkEnabled) ? '?' : '&';
$defaults = array(
'id' => (isset($atts['id'])) ? $atts['id'] : $store->getStoreId($post->ID)
);
$a = shortcode_atts($defaults,$atts);
$storeID = $a['id'];
$storedata = $store->getStore($storeID);
$storedata['grid_item_width'] = ($storedata['grid_columns']) ? floor(100/$storedata['grid_columns']) : 100;
## Set Page
$page = (isset($_GET['page'])) ? $_GET['page'] : 1;
## Get Items
$allitems = $store->getStoreItems($storeID,0);
## Get Paged Items
$storeitems = ($storedata['show_all_items']) ? $allitems : $store->getStoreItemsPage($allitems,$storedata['items_per_page'],$page);
## Set Additional Store Data
if($storedata['show_all_items']) {
$storedata['total_items'] = count($allitems);
$storedata['total_pages'] = 1;
$storedata['curr_page'] = $page;
$storedata['prev_page'] = '';
$storedata['next_page'] = '';
}
else {
$storedata['total_items'] = count($allitems);
$storedata['total_pages'] = ceil($storedata['total_items']/$storedata['items_per_page']);
$storedata['curr_page'] = $page;
$storedata['prev_page'] = ($page==1) ? '' : get_permalink($post->ID).$queryAppendSign.'page='.($page-1);
$storedata['next_page'] = ($storedata['curr_page']<$storedata['total_pages']) ? get_permalink($post->ID).$queryAppendSign.'page='.($page+1) : '';
}
ob_start();
## Template File
$templateMode = $store->getSetting('topspin_template_mode');
$templatefile = 'templates/topspin-'.$templateMode.'/item-listings.php';
## 3.1
if(file_exists(TOPSPIN_CURRENT_THEME_PATH.'/topspin-'.$templateMode.'/item-listings.php')) { $templatefile = TOPSPIN_CURRENT_THEME_PATH.'/topspin-'.$templateMode.'/item-listings.php'; }
elseif(file_exists(TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-'.$templateMode.'/item-listings.php')) { $templatefile = TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-'.$templateMode.'/item-listings.php'; }
## 3.0.0
if(file_exists(TOPSPIN_CURRENT_THEME_PATH.'/topspin-templates/item-listings.php')) { $templatefile = TOPSPIN_CURRENT_THEME_PATH.'/topspin-templates/item-listings.php'; }
elseif(file_exists(TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-templates/item-listings.php')) { $templatefile = TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-templates/item-listings.php'; }
include($templatefile);
$html = ob_get_contents();
ob_end_clean();
return $html;
}
### [topspin_featured_item]
### @id Default: the current store's ID
function topspin_shortcode_featured_item($atts) {
## Outputs the current store's featured item
global $store;
global $post;
$defaults = array(
'id' => (isset($atts['id'])) ? $atts['id'] : $store->getStoreId($post->ID)
);
$a = shortcode_atts($defaults,$atts);
$storeID = $a['id'];
$featuredItems = $store->getStoreFeaturedItems($storeID);
if(count($featuredItems)) {
ob_start();
## Template File
$templateMode = $store->getSetting('topspin_template_mode');
$templatefile = 'templates/topspin-'.$templateMode.'/featured-item.php';
## 3.1
if(file_exists(TOPSPIN_CURRENT_THEME_PATH.'/topspin-'.$templateMode.'/featured-item.php')) { $templatefile = TOPSPIN_CURRENT_THEME_PATH.'/topspin-'.$templateMode.'/featured-item.php'; }
elseif(file_exists(TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-'.$templateMode.'/featured-item.php')) { $templatefile = TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-'.$templateMode.'/featured-item.php'; }
## 3.0.0
if(file_exists(TOPSPIN_CURRENT_THEME_PATH.'/topspin-templates/featured-item.php')) { $templatefile = TOPSPIN_CURRENT_THEME_PATH.'/topspin-templates/featured-item.php'; }
elseif(file_exists(TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-templates/featured-item.php')) { $templatefile = TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-templates/featured-item.php'; }
$html = '';
foreach($featuredItems as $featureditem) {
include($templatefile);
ob_flush();
$html .= ob_get_contents();
}
ob_end_clean();
return $html;
}
}
### [topspin_store_nav_menu]
### @id Default: the current store's ID
function topspin_shortcode_store_nav_menu($atts) {
global $store;
global $post;
$defaults = array(
'id' => (isset($atts['id'])) ? $atts['id'] : $store->getStoreId($post->ID)
);
$a = shortcode_atts($defaults,$atts);
$storeID = $a['id'];
$storelist = $store->stores_get_nested_list();
if($store->getSetting('topspin_navmenu') && count($storelist)) {
ob_start();
## Template File
$templateMode = $store->getSetting('topspin_template_mode');
$templatefile = 'templates/topspin-'.$templateMode.'/nav-menu.php';
## 3.1
if(file_exists(TOPSPIN_CURRENT_THEME_PATH.'/topspin-'.$templateMode.'/nav-menu.php')) { $templatefile = TOPSPIN_CURRENT_THEME_PATH.'/topspin-'.$templateMode.'/nav-menu.php'; }
elseif(file_exists(TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-'.$templateMode.'/nav-menu.php')) { $templatefile = TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-templates/nav-menu.php'; }
## 3.0.0
if(file_exists(TOPSPIN_CURRENT_THEME_PATH.'/topspin-templates/nav-menu.php')) { $templatefile = TOPSPIN_CURRENT_THEME_PATH.'/topspin-templates/nav-menu.php'; }
elseif(file_exists(TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-templates/nav-menu.php')) { $templatefile = TOPSPIN_CURRENT_THEMEPARENT_PATH.'/topspin-templates/nav-menu.php'; }
include($templatefile);
$html = ob_get_contents();
ob_end_clean();
return $html;
}
}
?>