/** * Recursive function to convert the json to the right format * * @param object $node JSON object of a node/top node * @param string $context Record or Collection * @param string $hierarchyID Collection ID * @param integer $level Indicating the depth of recursion * * @return array */ protected function buildNodeArray($node, $context, $hierarchyID, $level = 0) { $escaper = new \Zend\Escaper\Escaper('utf-8'); $htmlID = $level . '_' . preg_replace('/\\W/', '-', $node->id); $ret = ['id' => $htmlID, 'text' => $escaper->escapeHtml($node->title), 'li_attr' => ['recordid' => $node->id], 'a_attr' => ['href' => $this->getContextualUrl($node, $context, $hierarchyID, $htmlID), 'title' => $node->title], 'type' => $node->type]; if (isset($node->children)) { $ret['children'] = []; $level++; for ($i = 0; $i < count($node->children); $i++) { $ret['children'][$i] = $this->buildNodeArray($node->children[$i], $context, $hierarchyID, $level); } } return $ret; }
/** * Function errorHandler * All error display and log * Display the Error, Line and File * Same behavior of HelpfulDie fuction in OpenEMR * Path /library/sql.inc * * @param type $e * @param string $sql * @param array $binds */ public function errorHandler($e, $sql, $binds = '') { $escaper = new \Zend\Escaper\Escaper('utf-8'); $trace = $e->getTraceAsString(); $nLast = strpos($trace, '[internal function]'); $trace = substr($trace, 0, $nLast - 3); $logMsg = ''; do { $logMsg .= "\r Exception: " . $escaper->escapeHtml($e->getMessage()); } while ($e = $e->getPrevious()); /** List all Params */ $processedBinds = ""; if (is_array($binds)) { $firstLoop = true; foreach ($binds as $valueBind) { if ($firstLoop) { $processedBinds .= "'" . $valueBind . "'"; $firstLoop = false; } else { $processedBinds .= ",'" . $valueBind . "'"; } } if (!empty($processedBinds)) { $processedBinds = "(" . $processedBinds . ")"; } } echo '<pre><span style="color: red;">'; echo 'ERROR : ' . $logMsg; echo "\r\n"; echo 'SQL statement : ' . $escaper->escapeHtml($sql); echo $escaper->escapeHtml($processedBinds); echo '</span></pre>'; echo '<pre>'; echo $trace; echo '</pre>'; /** Error Logging */ $logMsg .= "\n SQL statement : {$sql}" . $processedBinds; $logMsg .= "\n {$trace}"; error_log("ERROR: " . $logMsg, 0); }
/** * Escape a string * * @param string $string * @return string */ protected function escape($string) { $enc = 'UTF-8'; if ($this->view instanceof \Zend\View\Renderer\RendererInterface && method_exists($this->view, 'getEncoding')) { $enc = $this->view->getEncoding(); $escaper = $this->view->plugin('escapeHtml'); return $escaper((string) $string); } /** * bump this out to a protected method to kill the instance penalty! */ $escaper = new \Zend\Escaper\Escaper($enc); return $escaper->escapeHtml((string) $string); /** * Replaced to ensure consistent escaping */ //return htmlspecialchars((string) $string, ENT_COMPAT, $enc); }
/** * Convert JSTree JSON structure to HTML * * @param object $node JSON object of a the JSTree * @param string $context Record or Collection * @param string $hierarchyID Collection ID * @param string $recordID The currently active record * * @return string */ protected function jsonToHTML($node, $context, $hierarchyID, $recordID = false) { $escaper = new \Zend\Escaper\Escaper('utf-8'); $name = strlen($node->title) > 100 ? substr($node->title, 0, 100) . '...' : $node->title; $href = $this->getContextualUrl($node, $context); $icon = $node->type == 'record' ? 'file-o' : 'folder-open'; $html = '<li'; if ($node->type == 'collection') { $html .= ' class="hierarchy'; if ($recordID && $recordID == $node->id) { $html .= ' currentHierarchy'; } $html .= '"'; } elseif ($recordID && $recordID == $node->id) { $html .= ' class="currentRecord"'; } $html .= '><i class="fa fa-li fa-' . $icon . '"></i> ' . '<a name="tree-' . $escaper->escapeHtmlAttr($node->id) . '" href="' . $escaper->escapeHtmlAttr($href) . '" title="' . $escaper->escapeHtml($node->title) . '">' . $escaper->escapeHtml($name) . '</a>'; if (isset($node->children)) { $html .= '<ul class="fa-ul">'; foreach ($node->children as $child) { $html .= $this->jsonToHTML($child, $context, $hierarchyID, $recordID); } $html .= '</ul>'; } return $html . '</li>'; }
/** * (non-PHPdoc) * @see \mithra62\Platforms\View\ViewInterface::m62Escape() */ public function m62Escape($string) { $escaper = new \Zend\Escaper\Escaper('utf-8'); return $escaper->escapeHtml($string); }