group = $_REQUEST['group']; $this->name = $_REQUEST['name']; } $this->status = $this->status (); } //*************************** // GETTER / SETTER //*************************** public function __get ($name) { switch ($name) { case "srcview": return !empty ($_SESSION['cms']['compare']['srcview']); case "value": return $this->status['value']; case "diff": return $this->status['diff']; case "type": return $this->status['type']; case "css_file": return Setting::get ("system", "htmlCssFile"); default: return $this->$name; } } public function __set ($name, $value) { } private function status () { $status = array (); $group = new Group (array ('id' => $this->group)); $status['value']['offline'] = $group[$this->name]; $group->edit_mode = Base::MODE_ONLINE; $status['value']['online'] = $group[$this->name]; $status['type'] = Setting::get ("group/{$group->name}/{$this->name}", "type"); $status['messages'] = array (); $status['quickbar']['disabledButtons'] = array (); $status['diff'] = ""; if (empty ($_REQUEST['action'])) { if ($status['type'] == "html") { $status['value']['offline'] = $this->formatHtml ($status['value']['offline']); $status['value']['online'] = $this->formatHtml ($status['value']['online']); } else { $status['quickbar']['disabledButtons']['swapview'] = true; $_SESSION['cms']['compare']['srcview'] = false; } if ($status['type'] == "image" || $status['type'] == "file") { $group->edit_mode = Base::MODE_VIEW; $offline = $group->element ($this->name); $group->edit_mode = Base::MODE_ONLINE; $online = $group->element ($this->name); if ($offline->getBinary () == $online->getBinary ()) { $status['messages'][] = array ('type' => "ready", 'text' => I18n::tr ("edit", "compare/identical versions")); } else { $status['messages'][] = array ('type' => "info", 'text' => I18n::tr ("edit", "compare/different versions")); } } else { $diff = new Diff (explode ("\n", $status['value']['online']), explode ("\n", $status['value']['offline'])); $df = new TableDiffFormatter (); $status['diff'] = preg_replace ("/(&|\?)/", "\\1", $df->format ($diff)); if (!$status['diff']) { $status['messages'][] = array ('type' => "ready", 'text' => I18n::tr ("edit", "compare/identical versions")); } } $status['value']['offline'] = $this->formatTags ($status['value']['offline']); $status['value']['online'] = $this->formatTags ($status['value']['online']); } $status['statusbar']['value'] = "{$this->name}"; // Elementname, User, letzte Ă„nderung,... if (User::get ("is_admin")) { $status['statusbar']['value'] .= " – #{$this->group}"; } return $status; } public function swapView () { $_SESSION['cms']['compare']['srcview'] = empty ($_SESSION['cms']['compare']['srcview']) ? true : false; } public function message ($text) { return I18n::tr ("edit", "compare/$text", $text); } private function formatTags ($html) { $html = preg_replace ("/(<\S+ [^>]*)(src|href)=\".*?\"/", "\\1src=\"...\"", $html); $html = str_replace ("<", "<", $html); return $html; } private function formatHtml ($html) { // tags wrap $html = preg_replace ("/(\n|\r)<|>(\n|\r)/", "", $html); $html = preg_replace ("/\n|\r/", " ", $html); $html = preg_replace ("/[\t ]+/", " ", $html); $html = preg_replace ("/(<\/h\d>|<\/p>|]*>|]*>|<\/li>|]*>|<\/ul>|]*>|<\/ol>|]*>|<\/tr>|<\/td>|]*>|<\/table>)/i", "\\1\n", $html); $html = preg_replace ("/\n ]*>)/i", $html, $erg, PREG_OFFSET_CAPTURE|PREG_SET_ORDER); foreach (array_reverse ($erg) as $row) { $pos = $row[1][1]; $html = substr ($html, 0, $pos) . preg_replace ("/\n/", "\n ", substr ($html, $pos)); } preg_match_all ("/(<\/(ul|ol|table|tr|td)>)/i", $html, $erg, PREG_OFFSET_CAPTURE|PREG_SET_ORDER); foreach (array_reverse ($erg) as $row) { $pos = $row[1][1]; $html = substr ($html, 0, $pos-2) . preg_replace ("/ /", "", substr ($html, $pos-2, 2)) . preg_replace ("/\n /", "\n", substr ($html, $pos)); } // special chars $html = str_replace (" ", " ", $html); return $html; } // Wandelt das gegebene Array/Text in eine Form um, die direkt einer JavaScript Variablen zugewiesen werden kann public function toJavaScript ($value) { if (is_array ($value)) { $values = array (); foreach ($value as $key => $val) { $values[] = "'$key':".$this->toJavaScript ($val); } return "{".implode (",", $values)."}"; } else { $value = Database::escape ($value); return ($value===true) ? "true" : (($value===false) ? "false" : "'$value'"); } } } ?>