| 1 |
<?php |
| 2 |
|
| 3 |
defined('ABSPATH') or die("Cannot access pages directly."); |
| 4 |
|
| 5 |
/** |
| 6 |
* Class PDTTpl is an extremely lightweight templater used to render tables |
| 7 |
* for the WPDataTables module. |
| 8 |
* |
| 9 |
* @author cjbug@ya.ru |
| 10 |
* |
| 11 |
* @since September 2012 |
| 12 |
*/ |
| 13 |
class PDTTpl{ |
| 14 |
|
| 15 |
private $data; |
| 16 |
private $body; |
| 17 |
private $js; |
| 18 |
private $css; |
| 19 |
|
| 20 |
function setTemplate($b) { $this->body = $b; } |
| 21 |
function addCss($c) { $this->data['_css'][] = $c; } |
| 22 |
function addJs($j) { $this->data['_js'][] = $j; } |
| 23 |
function addBread($n,$l) { $this->breadcrumbs[$n] = $l; } |
| 24 |
|
| 25 |
function addData($key, $val){ |
| 26 |
$this->data[$key] = $val; |
| 27 |
} |
| 28 |
|
| 29 |
function addDataRef($key, $val){ |
| 30 |
$this->data[$key] = $val; |
| 31 |
} |
| 32 |
|
| 33 |
function showData(){ |
| 34 |
if(!empty($this->data)){ |
| 35 |
foreach ($this->data as $key=>$value) { |
| 36 |
$$key=$value; |
| 37 |
} |
| 38 |
unset($this->data); |
| 39 |
} |
| 40 |
if(!empty($_css)){ |
| 41 |
foreach($_css as $css_file){ |
| 42 |
echo '<link rel="stylesheet" href="'.$css_file.'" type="text/css" media="screen, projection" />'."\n"; |
| 43 |
} |
| 44 |
unset($_css); |
| 45 |
} |
| 46 |
if(!empty($_js)){ |
| 47 |
foreach($_js as $js_file){ |
| 48 |
echo '<script type="text/javascript" src="'.$js_file.'"></script>'."\n"; |
| 49 |
} |
| 50 |
unset($_js); |
| 51 |
} |
| 52 |
/** |
| 53 |
* New filter introduced in version 1.6 |
| 54 |
* |
| 55 |
* @author Vladica Bibeskovic |
| 56 |
*/ |
| 57 |
$template_file = apply_filters('wpdatatables_filter_template_file_location', WDT_TEMPLATE_PATH . $this->body); |
| 58 |
if( file_exists( $template_file )) { |
| 59 |
include( $template_file ); |
| 60 |
} else { |
| 61 |
include( WDT_TEMPLATE_PATH . $this->body ); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
function returnData(){ |
| 66 |
ob_start(); |
| 67 |
$this->showData(); |
| 68 |
$ret_val = ob_get_contents(); |
| 69 |
ob_end_clean(); |
| 70 |
return $ret_val; |
| 71 |
} |
| 72 |
|
| 73 |
} |
| 74 |
?> |