Diff
8 years ago
dashboard
7 years ago
rest-api
7 years ago
.htaccess
7 years ago
Diff.php
14 years ago
GeoLite2-Country.mmdb
7 years ago
IPTraf.php
8 years ago
IPTrafList.php
7 years ago
compat.php
8 years ago
conntest.php
7 years ago
cronview.php
8 years ago
dbview.php
8 years ago
diffResult.php
8 years ago
email_genericAlert.php
7 years ago
email_newIssues.php
7 years ago
email_unlockRequest.php
8 years ago
email_unsubscribeRequest.php
7 years ago
flags.php
7 years ago
live_activity.php
8 years ago
menu_dashboard.php
7 years ago
menu_dashboard_options.php
7 years ago
menu_firewall.php
7 years ago
menu_firewall_blocking.php
7 years ago
menu_firewall_blocking_options.php
8 years ago
menu_firewall_waf.php
7 years ago
menu_firewall_waf_options.php
7 years ago
menu_options.php
7 years ago
menu_scanner.php
7 years ago
menu_scanner_credentials.php
8 years ago
menu_scanner_options.php
8 years ago
menu_support.php
7 years ago
menu_tools.php
7 years ago
menu_tools_diagnostic.php
7 years ago
menu_tools_importExport.php
7 years ago
menu_tools_livetraffic.php
7 years ago
menu_tools_twoFactor.php
8 years ago
menu_tools_whois.php
8 years ago
menu_wordfence_central.php
7 years ago
sysinfo.php
8 years ago
unknownFiles.php
8 years ago
viewFullActivityLog.php
8 years ago
wf503.php
7 years ago
wfAPI.php
7 years ago
wfActivityReport.php
7 years ago
wfAdminNoticeQueue.php
8 years ago
wfArray.php
7 years ago
wfBrowscap.php
8 years ago
wfBrowscapCache.php
7 years ago
wfBulkCountries.php
7 years ago
wfCache.php
9 years ago
wfCentralAPI.php
7 years ago
wfConfig.php
7 years ago
wfCrawl.php
8 years ago
wfCredentialsController.php
7 years ago
wfCrypt.php
8 years ago
wfDB.php
7 years ago
wfDashboard.php
7 years ago
wfDateLocalization.php
8 years ago
wfDiagnostic.php
7 years ago
wfDict.php
8 years ago
wfDirectoryIterator.php
7 years ago
wfHelperBin.php
11 years ago
wfHelperString.php
11 years ago
wfIPWhitelist.php
7 years ago
wfImportExportController.php
7 years ago
wfIssues.php
7 years ago
wfJWT.php
7 years ago
wfLockedOut.php
7 years ago
wfLog.php
7 years ago
wfMD5BloomFilter.php
8 years ago
wfNotification.php
8 years ago
wfOnboardingController.php
7 years ago
wfPersistenceController.php
8 years ago
wfRESTAPI.php
7 years ago
wfScan.php
7 years ago
wfScanEngine.php
7 years ago
wfSchema.php
7 years ago
wfStyle.php
8 years ago
wfSupportController.php
7 years ago
wfUnlockMsg.php
7 years ago
wfUpdateCheck.php
8 years ago
wfUtils.php
7 years ago
wfVersionCheckController.php
8 years ago
wfView.php
10 years ago
wfViewResult.php
8 years ago
wordfenceClass.php
7 years ago
wordfenceConstants.php
7 years ago
wordfenceHash.php
7 years ago
wordfenceScanner.php
7 years ago
wordfenceURLHoover.php
7 years ago
wfView.php
128 lines
| 1 | <?php |
| 2 | |
| 3 | class wfView { |
| 4 | |
| 5 | /** |
| 6 | * @var string |
| 7 | */ |
| 8 | protected $view_path; |
| 9 | |
| 10 | /** |
| 11 | * @var string |
| 12 | */ |
| 13 | protected $view_file_extension = '.php'; |
| 14 | |
| 15 | /** |
| 16 | * @var string |
| 17 | */ |
| 18 | protected $view; |
| 19 | |
| 20 | /** |
| 21 | * @var array |
| 22 | */ |
| 23 | protected $data; |
| 24 | |
| 25 | /** |
| 26 | * @param string $view |
| 27 | * @param array $data |
| 28 | * @return wfView |
| 29 | */ |
| 30 | public static function create($view, $data = array()) { |
| 31 | return new self($view, $data); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @param string $view |
| 36 | * @param array $data |
| 37 | */ |
| 38 | public function __construct($view, $data = array()) { |
| 39 | $this->view_path = WORDFENCE_PATH . 'views'; |
| 40 | $this->view = $view; |
| 41 | $this->data = $data; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @return string |
| 46 | * @throws wfViewNotFoundException |
| 47 | */ |
| 48 | public function render() { |
| 49 | $view = preg_replace('/\.{2,}/', '.', $this->view); |
| 50 | $view_path = $this->view_path . '/' . $view . $this->view_file_extension; |
| 51 | if (!file_exists($view_path)) { |
| 52 | throw new wfViewNotFoundException('The view ' . $view_path . ' does not exist or is not readable.'); |
| 53 | } |
| 54 | |
| 55 | extract($this->data, EXTR_SKIP); |
| 56 | |
| 57 | ob_start(); |
| 58 | /** @noinspection PhpIncludeInspection */ |
| 59 | include $view_path; |
| 60 | return ob_get_clean(); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @return string |
| 65 | */ |
| 66 | public function __toString() { |
| 67 | try { |
| 68 | return $this->render(); |
| 69 | } catch (wfViewNotFoundException $e) { |
| 70 | return defined('WP_DEBUG') && WP_DEBUG ? $e->getMessage() : 'The view could not be loaded.'; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @param $data |
| 76 | * @return $this |
| 77 | */ |
| 78 | public function addData($data) { |
| 79 | $this->data = array_merge($data, $this->data); |
| 80 | return $this; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @return array |
| 85 | */ |
| 86 | public function getData() { |
| 87 | return $this->data; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @param array $data |
| 92 | * @return $this |
| 93 | */ |
| 94 | public function setData($data) { |
| 95 | $this->data = $data; |
| 96 | return $this; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @return string |
| 101 | */ |
| 102 | public function getView() { |
| 103 | return $this->view; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @param string $view |
| 108 | * @return $this |
| 109 | */ |
| 110 | public function setView($view) { |
| 111 | $this->view = $view; |
| 112 | return $this; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Prevent POP |
| 117 | */ |
| 118 | public function __wakeup() { |
| 119 | $this->view_path = WORDFENCE_PATH . 'views'; |
| 120 | $this->view = null; |
| 121 | $this->data = array(); |
| 122 | $this->view_file_extension = '.php'; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | class wfViewNotFoundException extends Exception { |
| 127 | } |
| 128 |