| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSight template functions |
| 4 |
* |
| 5 |
* @package WPSight \ Functions |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* wpsight_get_template() |
| 15 |
* |
| 16 |
* Load specific template file. |
| 17 |
* |
| 18 |
* @param string|array $template_names Template name (incl. file extension like .php) |
| 19 |
* @param string $template_path Custom template path for plugins and addons (default: '') |
| 20 |
* @param bool $load Call load_template() if true or return template path if false |
| 21 |
* @uses wpsight_locate_template() |
| 22 |
* @return string $located Absolute path to template file (if $load is false) |
| 23 |
* |
| 24 |
* @since 1.0.0 |
| 25 |
*/ |
| 26 |
function wpsight_get_template( $template_names, $args = array(), $template_path = '', $load = true, $require_once = false ) { |
| 27 |
|
| 28 |
// Execute code for this template |
| 29 |
do_action( 'wpsight_get_template', $template_names, $args, $template_path, $load, $require_once ); |
| 30 |
|
| 31 |
wpsight_locate_template( $template_names, $args, $template_path, $load, $require_once ); |
| 32 |
|
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* wpsight_locate_template() |
| 37 |
* |
| 38 |
* Locate a template and return the path |
| 39 |
* for inclusion or load if desired. |
| 40 |
* |
| 41 |
* This is the load order: |
| 42 |
* |
| 43 |
* /wp-content/themes/ theme (child) / $template_name |
| 44 |
* |
| 45 |
* /wp-content/themes/ theme (parent) / $template_name |
| 46 |
* |
| 47 |
* $template_path (custom path from addon for example) / $template_name |
| 48 |
* |
| 49 |
* /wp-content/plugins/ WPSIGHT_DOMAIN (e.g. wpcasa) / templates / $template_name |
| 50 |
* |
| 51 |
* @param string|array $template_names Template name (incl. file extension like .php) |
| 52 |
* @param string $template_path Custom template path for plugins and addons (default: '') |
| 53 |
* @param bool $load Call load_template() if true or return template path if false |
| 54 |
* @uses WPSight_Template::locate_template() |
| 55 |
* @return string $located Absolute path to template file (if $load is false) |
| 56 |
* |
| 57 |
* @since 1.0.0 |
| 58 |
*/ |
| 59 |
function wpsight_locate_template( $template_names, $args = array(), $template_path = '', $load = false, $require_once = false ) { |
| 60 |
return WPSight_Template::locate_template( $template_names, $args, $template_path, $load, $require_once ); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* wpsight_get_template_part() |
| 65 |
* |
| 66 |
* Load specific template part. |
| 67 |
* |
| 68 |
* @param string $slug The slug name for the generic template |
| 69 |
* @param string $name The name of the specialized template |
| 70 |
* @param string $template_path Custom template path for plugins and addons (default: '') |
| 71 |
* @param bool $load Call load_template() if true or return template path if false |
| 72 |
* @return string $located Absolute path to template file (if $load is false) |
| 73 |
* |
| 74 |
* @since 1.0.0 |
| 75 |
*/ |
| 76 |
function wpsight_get_template_part( $slug, $name = null, $args = array(), $template_path = '', $load = true, $require_once = false ) { |
| 77 |
return WPSight_Template::get_template_part( $slug, $name, $args, $template_path, $load, $require_once ); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* wpsight_get_templates_dir() |
| 82 |
* |
| 83 |
* Return path to WPSIGHT_DOMAIN (e.g. wpcasa) |
| 84 |
* templates directory. |
| 85 |
* |
| 86 |
* @return string |
| 87 |
* |
| 88 |
* @since 1.0.0 |
| 89 |
*/ |
| 90 |
function wpsight_get_templates_dir() { |
| 91 |
return WPSIGHT_PLUGIN_DIR . '/templates/'; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* wpsight_get_templates_url() |
| 96 |
* |
| 97 |
* Return URL to WPSIGHT_DOMAIN (e.g. wpcasa) |
| 98 |
* templates directory. |
| 99 |
* |
| 100 |
* @return string |
| 101 |
* |
| 102 |
* @since 1.0.0 |
| 103 |
*/ |
| 104 |
function wpsight_get_templates_url() { |
| 105 |
return WPSIGHT_PLUGIN_URL . '/templates/'; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* wpsight_orderby() |
| 110 |
* |
| 111 |
* Echo wpsight_get_orderby() |
| 112 |
* |
| 113 |
* @param array $args Array of arguments |
| 114 |
* @uses wpsight_get_orderby() |
| 115 |
* |
| 116 |
* @since 1.0.0 |
| 117 |
*/ |
| 118 |
function wpsight_orderby( $args = array() ) { |
| 119 |
$allowed_html = wpsight_allowed_html_tags(); |
| 120 |
$orderby_select = wpsight_get_orderby( $args ); |
| 121 |
echo wp_kses( $orderby_select, $allowed_html ); |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* wpsight_get_orderby() |
| 126 |
* |
| 127 |
* Return orderby options for listing pages |
| 128 |
* |
| 129 |
* @param array $args Array of arguments |
| 130 |
* @return string|bool $orderby HTML output or false if empty |
| 131 |
* |
| 132 |
* @since 1.0.0 |
| 133 |
*/ |
| 134 |
function wpsight_get_orderby( $args = array() ) { |
| 135 |
return WPSight_Template::get_orderby( $args ); |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* wpsight_get_panel() |
| 140 |
* |
| 141 |
* Return formatted listings control panel (with title and order options) |
| 142 |
* |
| 143 |
* @param array $args Array of arguments |
| 144 |
* @uses WPSight_Template::get_panel() |
| 145 |
* @return string|bool HTML markup of listings panel or false if empty |
| 146 |
* |
| 147 |
* @since 1.0.0 |
| 148 |
*/ |
| 149 |
function wpsight_get_panel( $args = array() ) { |
| 150 |
return WPSight_Template::get_panel( $args ); |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* wpsight_panel() |
| 155 |
* |
| 156 |
* Echo wpsight_get_panel() |
| 157 |
* |
| 158 |
* @param array $args Array of arguments |
| 159 |
* @uses wpsight_get_panel() |
| 160 |
* |
| 161 |
* @since 1.0.0 |
| 162 |
*/ |
| 163 |
function wpsight_panel( $args = array() ) { |
| 164 |
$allowed_html = wpsight_allowed_html_tags(); |
| 165 |
$panel_html = wpsight_get_panel( $args ); |
| 166 |
echo wp_kses( $panel_html, $allowed_html ); |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* wpsight_get_listing_title() |
| 171 |
* |
| 172 |
* Return formatted single listing |
| 173 |
* title with title actions. |
| 174 |
* |
| 175 |
* @param integer $post_id Post ID of specific listing |
| 176 |
* @param array $actions Array of listing title actions |
| 177 |
* @uses WPSight_Template::get_listing_title() |
| 178 |
* @return string HTML markup of listing title |
| 179 |
* |
| 180 |
* @since 1.0.0 |
| 181 |
*/ |
| 182 |
function wpsight_get_listing_title( $post_id = '', $actions = array() ) { |
| 183 |
return WPSight_Template::get_listing_title( $post_id, $actions ); |
| 184 |
} |
| 185 |
|
| 186 |
/** |
| 187 |
* wpsight_listing_title() |
| 188 |
* |
| 189 |
* Echo wpsight_get_listing_title() |
| 190 |
* |
| 191 |
* @param integer $post_id Post ID of specific listing |
| 192 |
* @param array $actions Array of listing title actions |
| 193 |
* @uses wpsight_get_listing_title() |
| 194 |
* |
| 195 |
* @since 1.0.0 |
| 196 |
*/ |
| 197 |
function wpsight_listing_title( $post_id = '', array $actions = array() ) { |
| 198 |
$allowed_html = wpsight_allowed_html_tags(); |
| 199 |
$listing_title = wpsight_get_listing_title( $post_id, $actions ); |
| 200 |
echo wp_kses( $listing_title, $allowed_html ); |
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* wpsight_get_archive_title() |
| 205 |
* |
| 206 |
* Return formatted listings archive title |
| 207 |
* |
| 208 |
* @uses WPSight_Template::get_archive_title() |
| 209 |
* @return string Listings archive title for the given query |
| 210 |
* |
| 211 |
* @since 1.0.0 |
| 212 |
*/ |
| 213 |
function wpsight_get_archive_title() { |
| 214 |
return WPSight_Template::get_archive_title(); |
| 215 |
} |
| 216 |
|
| 217 |
/** |
| 218 |
* wpsight_archive_title() |
| 219 |
* |
| 220 |
* Echo wpsight_get_archive_title() |
| 221 |
* |
| 222 |
* @uses wpsight_get_archive_title() |
| 223 |
* |
| 224 |
* @since 1.0.0 |
| 225 |
*/ |
| 226 |
function wpsight_archive_title() { |
| 227 |
$allowed_html = wpsight_allowed_html_tags(); |
| 228 |
$archive_title = wpsight_get_archive_title(); |
| 229 |
echo wp_kses( $archive_title, $allowed_html ); |
| 230 |
} |
| 231 |
|
| 232 |
/** |
| 233 |
* wpsight_get_pagination() |
| 234 |
* |
| 235 |
* Return formatted pagination |
| 236 |
* |
| 237 |
* @param int $max_num_pages max_num_pages parameter of corresponding query |
| 238 |
* @param array $args paginate_links() arguments |
| 239 |
* @uses WPSight_Template::get_pagination() |
| 240 |
* @return string|bool HTML markup of pagination or false if empty |
| 241 |
* |
| 242 |
* @since 1.0.0 |
| 243 |
*/ |
| 244 |
function wpsight_get_pagination( $max_num_pages = '', $args = array() ) { |
| 245 |
return WPSight_Template::get_pagination( $max_num_pages, $args ); |
| 246 |
} |
| 247 |
|
| 248 |
/** |
| 249 |
* wpsight_pagination() |
| 250 |
* |
| 251 |
* Echo wpsight_get_pagination() |
| 252 |
* |
| 253 |
* @param int $max_num_pages max_num_pages parameter of corresponding query |
| 254 |
* @param array $args paginate_links() arguments |
| 255 |
* @uses wpsight_get_pagination() |
| 256 |
* |
| 257 |
* @since 1.0.0 |
| 258 |
*/ |
| 259 |
function wpsight_pagination( $max_num_pages, $args = array() ) { |
| 260 |
$allowed_html = wpsight_allowed_html_tags(); |
| 261 |
$pagination_html = wpsight_get_pagination( $max_num_pages, $args ); |
| 262 |
echo wp_kses( $pagination_html, $allowed_html ); |
| 263 |
} |
| 264 |
|
| 265 |
/** |
| 266 |
* wpsight_listing_class() |
| 267 |
* |
| 268 |
* Display listing/post classes. |
| 269 |
* |
| 270 |
* @param string $class Additional CSS class |
| 271 |
* @param mixed $post_id |
| 272 |
* @uses wpsight_get_listing_class() |
| 273 |
* |
| 274 |
* @since 1.0.0 |
| 275 |
*/ |
| 276 |
function wpsight_listing_class( $class = '', $post_id = false ) { |
| 277 |
// echo 'class="' . join( ' ', wpsight_get_listing_class( $class, $post_id ) ) . '"'; |
| 278 |
$class_attr = 'class="' . join( ' ', wpsight_get_listing_class( $class, $post_id ) ) . '"'; |
| 279 |
echo wp_kses_data( $class_attr ); |
| 280 |
} |
| 281 |
|
| 282 |
/** |
| 283 |
* wpsight_get_listing_class() |
| 284 |
* |
| 285 |
* Get listing/post classes. |
| 286 |
* |
| 287 |
* @param string $class |
| 288 |
* @param mixed $post_id |
| 289 |
* @uses WPSight_Template::get_listing_class() |
| 290 |
* |
| 291 |
* @return bool|array |
| 292 |
*/ |
| 293 |
function wpsight_get_listing_class( $class = '', $post_id = false ) { |
| 294 |
return WPSight_Template::get_listing_class( $class, $post_id ); |
| 295 |
} |
| 296 |
|
| 297 |
/** |
| 298 |
* wpsight_get_listing_actions() |
| 299 |
* |
| 300 |
* Get listing actions (save, print etc.) array. |
| 301 |
* |
| 302 |
* @param integer $post_id Post ID of specific listing |
| 303 |
* @uses WPSight_Template::get_listing_actions() |
| 304 |
* @return array Array of listing actions |
| 305 |
* |
| 306 |
* @since 1.0.0 |
| 307 |
*/ |
| 308 |
function wpsight_get_listing_actions( $post_id = '' ) { |
| 309 |
return WPSight_Template::get_listing_actions( $post_id ); |
| 310 |
} |
| 311 |
|
| 312 |
/** |
| 313 |
* wpsight_listing_actions() |
| 314 |
* |
| 315 |
* Return link to listing actions |
| 316 |
* |
| 317 |
* @param string $post_id |
| 318 |
* @param array $actions |
| 319 |
* @uses WPSight_Template::listing_actions() |
| 320 |
* @return string |
| 321 |
* |
| 322 |
* @since 1.0.0 |
| 323 |
*/ |
| 324 |
function wpsight_listing_actions( $post_id = '', $actions = array() ) { |
| 325 |
$allowed_html = wpsight_allowed_html_tags(); |
| 326 |
$listing_actions = WPSight_Template::listing_actions( $post_id, $actions ); |
| 327 |
echo wp_kses( $listing_actions, $allowed_html ); |
| 328 |
} |
| 329 |
|