views
6 days ago
FileList.php
5 years ago
Hooks.php
3 years ago
Package.php
1 year ago
PackageController.php
4 days ago
PackageLocks.php
4 days ago
PackageTemplate.php
5 years ago
RestAPI.php
3 years ago
Shortcodes.php
6 days ago
PackageTemplate.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace WPDM\Package; |
| 5 | |
| 6 | |
| 7 | use WPDM\__\FileSystem; |
| 8 | use WPDM\__\Template; |
| 9 | |
| 10 | class PackageTemplate |
| 11 | { |
| 12 | |
| 13 | |
| 14 | function __construct() |
| 15 | { |
| 16 | |
| 17 | } |
| 18 | |
| 19 | function getTemplateContent($template, $packageID, $type = 'link') |
| 20 | { |
| 21 | |
| 22 | $default['link'] = 'link-template-default.php'; |
| 23 | $default['page'] = 'page-template-default.php'; |
| 24 | |
| 25 | if ($template == '') |
| 26 | $template = $default[$type]; |
| 27 | |
| 28 | //Custom templates ( xml file ) |
| 29 | $template_content = WPDM()->packageTemplate->get($template, $type, true); |
| 30 | |
| 31 | if($template_content) |
| 32 | $template = $template_content; |
| 33 | else |
| 34 | if(!strpos(strip_tags($template), "]")){ |
| 35 | |
| 36 | //PHP templates ( php file ) |
| 37 | $template = wpdm_basename($template); |
| 38 | $template = str_replace(".php", "", $template).".php"; |
| 39 | |
| 40 | $template_file = Template::locate("{$type}-templates/{$template}", __DIR__.'/views'); |
| 41 | if(!$template_file) |
| 42 | $template_file = Template::locate("{$type}-templates/{$type}-template-{$template}", __DIR__.'/views'); |
| 43 | |
| 44 | if($template_file !== ''){ |
| 45 | ob_start(); |
| 46 | global $wp_filter; |
| 47 | $all_tc = $wp_filter['the_content']; |
| 48 | unset($wp_filter['the_content']); |
| 49 | remove_filter("the_content", "wpdm_downloadable"); |
| 50 | $ID = $packageID; |
| 51 | include $template_file; |
| 52 | $template = ob_get_clean(); |
| 53 | $wp_filter['the_content'] = $all_tc; |
| 54 | if(!preg_match("/\[([^\]]+)\]/", $template,$found)){ |
| 55 | return $template; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | } |
| 60 | return $template; |
| 61 | } |
| 62 | |
| 63 | public function parseTemplate($template, $packageID, $type = 'link') |
| 64 | { |
| 65 | $template = $this->getTemplateContent($template, $packageID, $type); |
| 66 | preg_match_all("/\[([^\]]+)\]/", $template, $matched); |
| 67 | return $matched[1]; |
| 68 | } |
| 69 | |
| 70 | function getValue($package, $var) |
| 71 | { |
| 72 | |
| 73 | } |
| 74 | |
| 75 | } |
| 76 |