/** * VQModObject::_parseMods() * * @param DOMNode $node <modification> node to be parsed * @return null * @description Parses modifications in preparation for the applyMod method to work */ private function _parseMods(DOMNode $node) { $files = $node->getElementsByTagName('file'); $replaces = VQMod::$_replaces; foreach ($files as $file) { $path = $file->getAttribute('path') ? $file->getAttribute('path') : ''; $filesToMod = explode(',', $file->getAttribute('name')); foreach ($filesToMod as $filename) { $fileToMod = $path . $filename; if (!empty($replaces)) { foreach ($replaces as $r) { if (count($r) == 2) { $fileToMod = preg_replace($r[0], $r[1], $fileToMod); } } } $error = $file->hasAttribute('error') ? $file->getAttribute('error') : 'log'; $fullPath = VQMod::path($fileToMod); if (!$fullPath || !file_exists($fullPath)) { if (strpos($fileToMod, '*') !== false) { $fullPath = VQMod::getCwd() . $fileToMod; } else { if ($error == 'log' || $error == 'abort') { $skip = $error == 'log' ? ' (SKIPPED)' : ' (ABORTING MOD)'; VQMod::$log->write('VQModObject::parseMods - Could not resolve path for [' . $fileToMod . ']' . $skip, $this); } if ($error == 'log' || $error == 'skip') { continue; } elseif ($error == 'abort') { return false; } } } $operations = $file->getElementsByTagName('operation'); foreach ($operations as $opIndex => $operation) { $error = $operation->hasAttribute('error') ? $operation->getAttribute('error') : 'abort'; $ignoreif = $operation->getElementsByTagName('ignoreif')->item(0); if ($ignoreif) { $ignoreif = new VQSearchNode($ignoreif); } else { $ignoreif = false; } $this->mods[$fullPath][] = array('search' => new VQSearchNode($operation->getElementsByTagName('search')->item(0)), 'add' => new VQAddNode($operation->getElementsByTagName('add')->item(0)), 'ignoreif' => $ignoreif, 'error' => $error, 'fileToMod' => $fileToMod, 'opIndex' => $opIndex); } } } }
/** * VQModLog::__destruct() * * @return null * @description Logs any messages to the log file just before object is destroyed */ public function __destruct() { if (empty($this->_logs) || VQMod::$logging == false) { return; } $logPath = VQMod::path(VQMod::$logFolder . date('w_D') . '.log', true); $txt = array(); $txt[] = str_repeat('-', 10) . ' Date: ' . date('Y-m-d H:i:s') . ' ~ IP : ' . (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'N/A') . ' ' . str_repeat('-', 10); $txt[] = 'REQUEST URI : ' . $_SERVER['REQUEST_URI']; foreach ($this->_logs as $count => $log) { if ($log['obj']) { $vars = get_object_vars($log['obj']); $txt[] = 'MOD DETAILS:'; foreach ($vars as $k => $v) { if (is_string($v)) { $txt[] = ' ' . str_pad($k, 10, ' ', STR_PAD_RIGHT) . ': ' . $v; } } } foreach ($log['log'] as $msg) { $txt[] = $msg; } if ($count > count($this->_logs) - 1) { $txt[] = ''; } } $txt[] = $this->_sep; $txt[] = str_repeat(PHP_EOL, 2); $append = true; if (!file_exists($logPath)) { $append = false; } else { $content = file_get_contents($logPath); if (!empty($content) && strpos($content, ' Date: ' . date('Y-m-d ')) === false) { $append = false; } } $result = file_put_contents($logPath, implode(PHP_EOL, $txt), $append ? FILE_APPEND | LOCK_EX : LOCK_EX); if (!$result) { die('VQModLog::__destruct - LOG FILE "' . $logPath . '" COULD NOT BE WRITTEN'); } }