public function text_difference() { $stringa = "hola mundo como estas"; $stringb = "hola mundo como estas bien"; //debug(diff(explode(" ",$stringa),explode(" ",$stringb))); debug(htmlDiff($stringa, $stringb)); $stringa = "hola mundo como estas bien"; $stringb = "hola mundo como estas"; //debug(diff(explode(" ",$stringa),explode(" ",$stringb))); debug(htmlDiff($stringa, $stringb)); $stringa = "hola mundo como estas bien"; $stringb = "hola mundo estas bien"; //debug(diff(explode(" ",$stringa),explode(" ",$stringb))); debug(htmlDiff($stringa, $stringb)); $stringa = "hola mundo estas bien"; $stringb = "hola mundo estas bien"; //debug(diff(explode(" ",$stringa),explode(" ",$stringb))); debug(htmlDiff($stringa, $stringb)); $stringa = "hola mundo estás bien"; $stringb = "hola mundo estas bien"; //debug(diff(explode(" ",$stringa),explode(" ",$stringb))); debug(htmlDiff($stringa, $stringb)); $stringa = "hola mundo estás bien"; $stringb = "hola mundo estás bien"; //debug(diff(explode(" ",$stringa),explode(" ",$stringb))); debug(htmlDiff($stringa, $stringb)); }
function comparar($obja, $objb, $field) { if ($obja->{$field} == $objb->{$field}) { return $obja->{$field}; } else { return htmlDiff($obja->{$field}, $objb->{$field}); } }
$changeSet = $row; $changeSet['changesCount'] = 0; if ($row['OldUserId'] !== $row['NewUserId']) { $changeSet['changesCount']++; } if ($row['OldSourceId'] !== $row['NewSourceId']) { $changeSet['changesCount']++; } if ($row['OldStatus'] !== $row['NewStatus']) { $changeSet['OldStatusName'] = $statuses[$row['OldStatus']]; $changeSet['NewStatusName'] = $statuses[$row['NewStatus']]; $changeSet['changesCount']++; } if ($row['OldLexicon'] !== $row['NewLexicon']) { $changeSet['changesCount']++; } if ($row['OldModUserId'] !== $row['NewModUserId']) { $changeSet['changesCount']++; } if ($row['OldInternalRep'] !== $row['NewInternalRep']) { $changeSet['diff'] = htmlDiff($row['OldInternalRep'], $row['NewInternalRep']); $changeSet['changesCount']++; } if ($changeSet['changesCount'] > 0) { $changeSets[] = $changeSet; } } smarty_assign('page_title', 'Istoria definiției ' . $def->lexicon); smarty_assign('def', $def); smarty_assign('changeSets', $changeSets); smarty_displayCommonPageWithSkin('istoria-definitiei.ihtml');
<hr class="hidden" /> <ul id="resumen_tramite" class="clearfix"> <?php echo !empty($left->plazo) ? '<li class="first"><h4>Tiempo de Realización</h4><p>' . ($i == 1 ? htmlDiff($fichas[1]->plazo, $fichas[0]->plazo) : $left->plazo) . '</p></li>' : ''; ?> <?php echo !empty($left->vigencia) ? '<li class="first"><h4>Vigencia del Trámite</h4><p>' . ($i == 1 ? htmlDiff($fichas[1]->vigencia, $fichas[0]->vigencia) : $left->vigencia) . '</p></li>' : ''; ?> <?php echo !empty($left->costo) ? '<li class="first"><h4>Costo del Trámite</h4><p>' . ($i == 1 ? htmlDiff($fichas[1]->costo, $fichas[0]->costo) : $left->costo) . '</p></li>' : ''; ?> <?php echo !empty($left->informacion_multimedia) ? '<li class="first"><h4>Infografía, audio y video</h4><p>' . ($i == 1 ? htmlDiff($fichas[1]->informacion_multimedia, $fichas[0]->informacion_multimedia) : $left->informacion_multimedia) . '</p></li>' : ''; ?> <?php echo !empty($left->marco_legal) ? '<li class="marco_legal second"><h4>Marco Legal</h4><p>' . ($i == 1 ? htmlDiff($fichas[1]->marco_legal, $fichas[0]->marco_legal) : $left->marco_legal) . '</p></li>' : ''; ?> </ul> <img class="qr" src="https://chart.googleapis.com/chart?chs=220x220&cht=qr&chid=<?php echo md5(uniqid(rand(), true)); ?> &chl=Trámite:%20<?php echo $left->titulo; ?> %0D%0A%0D%0ADescripción:%20<?php echo substr(strip_tags($left->objetivo), 0, 800); ?> %0D%0A%0D%0AURL:%20<?php echo site_url('fichas/ver/' . $left->id . '/'); ?> " alt="<?php
/** * Get the parsed code with diff */ function get_diff($diff) { require_once "simplediff.php"; return nl2br(htmlDiff($diff->content, $this->content)); }
public function compareWith(Ficha $ficha) { $comparacion = NULL; $left = $this->toArray(false); $right = $ficha->toArray(false); $exclude = array('id', 'genero_id', 'convenio', 'updated_at', 'created_at', 'publicado', 'publicado_at', 'servicio_codigo', 'comentarios', 'alias', 'rating', 'estado', 'estado_justificacion', 'actualizable', 'diagramacion', 'locked', 'metaficha', 'metaficha_servicios', 'metaficha_campos', 'metaficha_opciones', 'votos_positivos', 'votos_negativos'); $labels = array('tipo' => array(1 => 'Personas', 2 => 'Empresas', 3 => 'Ambos', 0 => 'No asignado')); foreach ($left as $key => $val) { if (!in_array($key, $exclude)) { if ($right[$key] != $left[$key]) { if (array_key_exists($key, $labels)) { $diff = htmlDiff(strip_tags($labels[$key][$right[$key]]), strip_tags($labels[$key][$left[$key]])); } else { $diff = htmlDiff(strip_tags($right[$key]), strip_tags($left[$key])); } $diff = trim($diff); if ($diff) { $comparacion[$key]->left[] = $diff; $comparacion[$key]->right[] = $right[$key]; } } } } //Comparamos las relaciones one //Nombre => Valor_Para_Label $relacionesAComparar = array('Servicio' => 'nombre', 'Genero' => 'nombre'); foreach ($relacionesAComparar as $r => $label) { $left = $this->get($r); $right = $ficha->get($r); //debug($left->toArray()); //debug($right->toArray()); if ($left->toArray() !== $right->toArray()) { $comparacion[$r]->left[] = '<del>' . $right->{$label} . '</del> <ins>' . $left->{$label} . '</ins>'; // El htmldiff tenía problemas $comparacion[$r]->right[] = $right->{$label}; } } //Comparamos las relaciones many //[caso un valor] : Nombre => Valor_Para_Label //[caso multiple] : Nombre => Array(Array(label1,label2,...,labelN),separador) $relacionesAComparar = array('Tags' => 'nombre', 'Temas' => 'nombre', 'HechosVida' => 'nombre', 'RangosEdad' => array(array('edad_minima', 'edad_maxima'), '-')); //Caso multiple foreach ($relacionesAComparar as $r => $label) { $left = $this->get($r); $right = $ficha->get($r); if (!$this->bidimensional_array_equals($left->toArray(false), $right->toArray(false), array('id', 'ficha_id'))) { $tmp = array(); foreach ($right as $rig) { if (!is_array($label)) { $tmp[] = $rig->{$label}; } else { list($mlabels, $sep) = $label; $values = array(); foreach ($mlabels as $mlabel) { $values[] = $rig->{$mlabel}; } $val = implode($sep, $values); $tmp[] = $val; } } $right_label = implode(" ", $tmp); $tmp = array(); foreach ($left as $l) { if (!is_array($label)) { $tmp[] = $l->{$label}; } else { list($mlabels, $sep) = $label; $values = array(); foreach ($mlabels as $mlabel) { $values[] = $l->{$mlabel}; } $val = implode($sep, $values); $tmp[] = $val; } } $left_label = implode(" ", $tmp); $diff = trim(htmlDiff($right_label, $left_label)); if ($diff) { $comparacion[$r]->left[0] = $diff; $comparacion[$r]->right[0] = $right_label; } } } return $comparacion; }
function diffHTML() { global $diffString; $diffString = htmlDiff($_POST['diff1'], $_POST['diff2']); }
public function compareWith(Evento $version_anterior) { $comparacion = array(); $left = $this->toArray(false); $right = $version_anterior->toArray(false); $exclude = array('id', 'created_at', 'updated_at', 'publicado_at', 'maestro', 'maestro_id'); foreach ($left as $field => $value) { if (!in_array($field, $exclude)) { if ($right[$field] != $left[$field]) { $diff = trim(htmlDiff(strip_tags($right[$field]), strip_tags($left[$field]))); $comparacion[$field]->left[] = $diff; $comparacion[$field]->right[] = $right[$field]; } } } // INFO: comparacion de Regiones (relacion many) $left = $this->get('Regiones'); $right = $version_anterior->get('Regiones'); $left_nom = $right_nom = array(); foreach ($left as $lnom) { $left_nom[] = $lnom->nombre; } foreach ($right as $rnom) { $right_nom[] = $rnom->nombre; } $_a = array_diff($left_nom, $right_nom); $_b = array_diff($right_nom, $left_nom); if (!empty($_a) || !empty($_b)) { $left_label = implode(" ", $left_nom); $right_label = implode(" ", $right_nom); $diff = trim(htmlDiff($right_label, $left_label)); if ($diff) { $comparacion['Regiones']->left[0] = $diff; $comparacion['Regiones']->right[0] = $right_label; } } return $comparacion; }
public function compareWith(SubFicha $subficha) { $comparacion = NULL; $left = $this->toArray(false); $right = $subficha->toArray(false); $exclude = array('id', 'metaficha_id', 'locked', 'estado', 'estado_justificacion', 'actualizable', 'servicio_codigo', 'maestro', 'maestro_id', 'publicado', 'publicado_at', 'updated_at', 'primera_version_publicada_id', 'comentarios'); $labels = array('tipo' => array(1 => 'Personas', 2 => 'Empresas', 3 => 'Ambos', 0 => 'No asignado')); foreach ($left as $key => $val) { if (!in_array($key, $exclude)) { if ($right[$key] != $left[$key]) { if (array_key_exists($key, $labels)) { $diff = htmlDiff(strip_tags($labels[$key][$right[$key]]), strip_tags($labels[$key][$left[$key]])); } else { $diff = htmlDiff(strip_tags($right[$key]), strip_tags($left[$key])); } $diff = trim($diff); if ($diff) { $comparacion[$key]->left[] = $diff; $comparacion[$key]->right[] = $right[$key]; } } } } return $comparacion; }
function show(&$rows, $current) { //check that the version is at least 1.5.4 //checkVersion(); //ensure mootools is installed JHTML::_('behavior.mootools'); //if we have prior versions, show them if (count($rows) > 0) { //get the editor name $eName = JRequest::getVar('ename'); $eName = preg_replace('#[^A-Z0-9\\-\\_\\[\\]]#i', '', $eName); ?> <style type='text/css'> h1,h2,h3,h4,h5{ margin:2px; } #preview_container { /*height:180px; */ overflow:auto; width:50%; float:left; } #difference_container{ width:49%; float:left; border-left:1px solid black; } #version_pane{ overflow:auto; border-bottom:1px solid black; } .ins,.ins p,.ins a { text-decoration:underline !important; } .del,.del p,.del a { text-decoration:line-through !important; } </style> <script language='javascript' type='text/javascript'> //preview the content function showContent(t){ try { document.getElementById('preview_pane').style.visibility='visible'; document.getElementById('preview').innerHTML = t.title; document.getElementById('difference').innerHTML = t.rev; }catch(e){ alert("Error previewing content: " + e); } } //clear out the preview pane function hideContent(){ document.getElementById('preview_pane').style.visibility='hidden'; document.getElementById('preview').innerHTML = ''; } //asynch request to delete the passed id function requestDelete(id,autosave){ if(confirm('<?php echo JText::_('SURE'); ?> ')){ try { //url to delete if(autosave == 1){ var url = '<?php echo HTML_versions::getLink(); ?> &task=deleteautosave&no_html=1&id=' + id; }else{ var url = '<?php echo HTML_versions::getLink(); ?> &task=delete&no_html=1&id=' + id; } //tell the user when it's gone! var myAjax = new Ajax(url, { method: 'get', update:'version_error', 'onFailure': function(){ alert('<?php echo JText::_('Error deleting version: You are not authorized to delete this version. You did not create it or you are not the administrator.'); ?> '); } , 'onComplete': function(){ //hide the preview hideContent(); //remove the li from the list var d = document.getElementById('versions'); if(id > 0){ var remove = document.getElementById('version_' +id); d.removeChild(remove); }else{ alert('<?php echo JText::_('Error: Version table id numbers are not present. Alter the #__version table id field to be AUTOINCREMENT and this error will go away.'); ?> '); } } }); myAjax.request(); }catch(e){ alert("Error: Is Mootools available?:" + e); } } } //set the editor window to the selected content value function use(t){ try { window.parent.insertVersioning('<?php echo $eName; ?> ',t.title); parent.document.getElementById('title').value = t.rel; window.parent.document.getElementById('sbox-window').close(); }catch(e){ alert("Error inserting content: no editor found"); } } </script> <div id='version_pane'> <div id='version_error'></div> <h3><?php echo JText::_('VERSIONS'); ?> </h3> <!-- <a href="#" onclick="return false;" ><?php echo JText::_('Annotate current version'); ?> </a> --> <ul id='versions'> <?php //get the current version $current_text = str_replace("'", "'", @$current->introtext); if (strlen(@$current->fulltext) > 0) { $current_text = $current_text . '<hr id="system-readmore" />' . str_replace("'", "'", @$current->introtext); } foreach ($rows as $row) { $staged = ""; $autosaved = ""; if (@$row->stage == 1) { $staged = "<i>Staged</i>"; } if (@$row->autosaved == 1) { $autosaved = "<i>Autosaved</i>"; } $hovertext = str_replace("'", "'", @$row->introtext); $title = str_replace("'", "'", @$row->title); //append the fulltext to the content if (strlen($row->fulltext) > 0) { $complete = $hovertext . '<hr id="system-readmore" />' . str_replace("'", "'", @$row->fulltext); } else { $complete = $hovertext; } if (strlen(@$row->modified) > 0) { $ts = @$row->modified; } else { $ts = @$row->created; } //the first version has no modified by info, so we need to use created by instead for the first version only $modified_by_user =& JFactory::getUser((int) @$row->modified_by); $created_by_user =& JFactory::getUser((int) @$row->created_by); if (strlen(trim($modified_by_user->name)) == 0) { $name = $created_by_user->name; } else { $name = $modified_by_user->name; } $diff = htmlDiff($current_text, $complete); $length = (int) strlen($complete); if ($length > 1024) { $length = number_format($length / 1024, 2) . "K"; } if (HTML_versions::canDeleteVersions() === true) { if ($_REQUEST['task'] == 'showautosave') { $delete = "<a href='#' title='" . JText::_('DELETE') . "' onclick='requestDelete({$row->content_id},1); return false;'>[" . JText::_('DELETE') . "]</a>"; } else { $delete = "<a href='#' title='" . JText::_('DELETE') . "' onclick='requestDelete({$row->id},0); return false;'>[" . JText::_('DELETE') . "]</a>"; } } else { $delete = ""; } if (strpos($ts, '0000-00-00') !== false) { $ts = JText::_('Original'); //'(Original)'; } echo "<li id='version_{$row->id}'>{$autosaved} {$staged} {$ts} {$name} ({$length})\n\t\t\t\t\t\t\t<a href='#' title='{$complete}' rel='{$title}' rev='{$diff}' onclick='showContent(this); return false;'>\n\t\t\t\t\t\t\t\t<abbr title='{$hovertext}'>[" . JText::_('PREVIEW') . "]</abbr>\n\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t<a title='{$complete}' href='#' rel='{$title}' onclick='use(this); return false;' >[" . JText::_('USE') . "]</a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t{$delete}\n\t\t\t\t\t\n\t\t\t\t\t\t </li>"; } ?> </ul> </div> <div id="preview_pane" style="visibility:hidden;"> <div id='preview_container'> <h3><?php echo JText::_('PREVIEW'); ?> </h3> <!-- <h4 id='preview_title'></h4> --> <div id='preview'></div> </div> <div id='difference_container'> <h3 style="display:inline;"><?php echo JText::_('DIFFERENCE'); ?> </h3> (<span class="ins"><?php echo JText::_('ADDED'); ?> </span> <?php echo JText::_('AND'); ?> <span class="del"><?php echo JText::_('DELETED'); ?> </span>) <div id='difference'></div> </div> </div> <script language='javascript'> //add tooltips for previews, not really necessary, but handy //added try/catch try{ window.addEvent('domready', function(){ var abbrTools = new Tips($$('abbr')); }); }catch(e){ } </script> <?php } else { //no prior versions to show ?> <h2><?php echo JText::_('NOVERSIONS'); ?> </h2> <?php } }
/** * default action */ function action($item) { //! check access rights if (!Core::$user->has("siteadm|webadm")) { Http::redirect("403"); } //! if we have to delete a page version if (isset($_REQUEST['pagedel'])) { if (!empty($_REQUEST['created'])) { Page::delete($item, $_REQUEST['created']); } Http::redirect($item); } //! revert to an old version of the page if (isset($_REQUEST['revert'])) { if (!empty($_REQUEST['created'])) { Core::log('A', sprintf("Page %s reverted to %s by %s", $item, $_REQUEST['created'], Core::$user->name), "cmsaudit"); DS::exec("UPDATE pages set created=CURRENT_TIMESTAMP,modifyd=CURRENT_TIMESTAMP,modifyid=? WHERE id=? AND (lang='' OR lang=?) AND created=?", [Core::$user->id, $item, Core::$client->lang, $_REQUEST['created']]); } Http::redirect($item); } //! get the latest public version's date if (empty($_REQUEST['created'])) { $_REQUEST['created'] = DS::field("created", "pages", "(id=? OR ? LIKE id||'/%') AND (lang='' OR lang=?) AND publishid!=0", "", "id DESC,created DESC", [$item, $item, Core::$client->lang]); if (empty($_REQUEST['created'])) { $_REQUEST['created'] = DS::field("created", "pages", "(id=? OR ? LIKE id||'/%') AND (lang='' OR lang=?)", "", "id DESC,created ASC", [$item, $item, Core::$client->lang]); } } //! load frame page for page parameters and dds $frame = DS::fetch("data,dds", "pages", "id='frame' AND (lang='' OR lang=?) AND created<=?", "", "", [Core::$client->lang, $_REQUEST['created']]); $frame['dss'] = @json_decode($frame['dds'], true); $frame['data'] = @json_decode($frame['data'], true); View::assign("frame", $frame['data']); //! load archive version //! normally you would use Model, but that would only return the latest version $page = DS::fetch("*", "pages", "(id=? OR ? LIKE id||'/%') AND (lang='' OR lang=?) AND created=?", "", "id DESC,created DESC", [$item, $item, Core::$client->lang, $_REQUEST['created']]); $this->title = $page['name']; $title = L("ARCHIVE") . " " . $page['name']; if (is_string($page['data'])) { $page['data'] = @json_decode($page['data'], true); } if (is_array($page['data'])) { foreach ($page['data'] as $k => $v) { $this->{$k} = $v; } } foreach (["id", "name", "lang", "filter", "template", "pubd", "expd", "dds", "ownerid", "created"] as $k) { $this->{$k} = $page[$k]; } $p = @array_merge($frame['dds'], @json_decode($page['dds'], true)); if (is_array($p)) { foreach ($p as $k => $c) { if ($k != "dds") { try { $this->{$k} = DS::query($c[0], $c[1], @$c[2], @$c[3], @$c[4], @$c[5], View::getval(@$c[6])); } catch (\Exception $e) { Core::log("E", $item . " " . $e->getMessage() . " " . implode(" ", $c), "dds"); } } } } $old = View::template($this->template); //! if we have to compare to an older (or the latest) version if (isset($_REQUEST['diff'])) { include_once "vendor/phppe/CMS/libs/simplediff.php"; //! load current version $frame = DS::fetch("data,dds", "pages", "id='frame' AND (lang='' OR lang=?) AND publishid!=0", "", "created DESC", [Core::$client->lang]); $frame['dss'] = @json_decode($frame['dds'], true); $frame['data'] = @json_decode($frame['data'], true); View::assign("frame", $frame['data']); $page = DS::fetch("*", "pages", "id=? OR ? LIKE id||'/%'", "", "id DESC,created DESC", [$item, $item]); if (is_string($page['data'])) { $page['data'] = @json_decode($page['data'], true); } if (is_array($page['data'])) { foreach ($page['data'] as $k => $v) { $this->{$k} = $v; } } foreach (["id", "name", "lang", "filter", "template", "pubd", "expd", "dds", "ownerid", "created"] as $k) { $this->{$k} = $page[$k]; } $p = @array_merge($frame['dds'], @json_decode($page['dds'], true)); if (is_array($p)) { foreach ($p as $k => $c) { if ($k != "dds") { try { $this->{$k} = DS::query($c[0], $c[1], @$c[2], @$c[3], @$c[4], @$c[5], View::getval(@$c[6])); } catch (\Exception $e) { Core::log("E", $item . " " . $e->getMessage() . " " . implode(" ", $c), "dds"); } } } } $this->title = $page['name']; $curr = View::template($this->template); //! make sure diff splits on tag end $this->result = htmlDiff(preg_replace("/>([^\\ \t\n])/m", "> \\1", $old), preg_replace("/>([^\\ \t\n])/m", "> \\1", $curr)); //! remove diff inside tags $this->result = preg_replace("/(<[^<>]+)<ins>.*?<\\/ins>([^<>]*>)/ims", "\\1\\2", $this->result); $this->result = preg_replace("/(<[^<>]+)<del>(.*?)<\\/del>([^<>]*>)/ims", "\\1\\2\\3", $this->result); } else { $this->result = $old; } $this->title = $title; }
public static function getPage_Review($contents, $containers) { $repositoryID = self::validateID(self::getDataGET('project'), true); $languageID = self::validateID(self::getDataGET('language'), true); $repositoryData = Database::getRepositoryData($repositoryID); $languageData = Database::getLanguageData($languageID); if (empty($repositoryData)) { self::addBreadcrumbItem(URL::toProject($repositoryID), 'Project not found'); self::setTitle('Project not found'); $contents[] = new UI_Heading('Project not found', true); $contents[] = new UI_Paragraph('We\'re sorry, but we could not find the project that you requested.'); $contents[] = new UI_Paragraph('Please check if you have made any typing errors.'); } else { if (Authentication::getUserID() <= 0) { self::setTitle($repositoryData['name']); $contents[] = new UI_Heading(htmlspecialchars($repositoryData['name']), true); $contents[] = self::getLoginForm(); } else { $isAllowedToReview = Repository::hasUserPermissions(Authentication::getUserID(), $repositoryID, $repositoryData, Repository::ROLE_MODERATOR); self::addBreadcrumbItem(URL::toReview($repositoryID), 'Review'); if (empty($languageData)) { // review index page for this repository self::setTitle('Review contributions'); $contents[] = new UI_Heading('Review contributions', true); if ($isAllowedToReview) { $table = new UI_Table(array('Language', 'Review')); $table->setColumnPriorities(9, 3); $pendingLanguages = Database::getPendingEditsByRepository($repositoryID); if (count($pendingLanguages) > 0) { foreach ($pendingLanguages as $pendingLanguage) { $reviewURL = URL::toReviewLanguage($repositoryID, $pendingLanguage['languageID']); $linkedName = new UI_Link(Language::getLanguageNameFull($pendingLanguage['languageID']), $reviewURL, UI_Link::TYPE_UNIMPORTANT); $pendingCount = new UI_Link($pendingLanguage['COUNT(*)'], $reviewURL, UI_Link::TYPE_INFO); $table->addRow(array($linkedName->getHTML(), $pendingCount->getHTML())); } } else { $table->addRow(array('No pending contributions', 'No pending contributions')); } $contents[] = $table; } else { $contents[] = new UI_Paragraph('Only administrators, developers and moderators of this project are allowed to review contributions.'); } } else { // single-language review details page for this repository $editID = self::validateID(self::getDataGET('edit'), true); if ($editID <= 0) { $currentPageURL = URL::toReviewLanguage($repositoryID, $languageID); } else { $currentPageURL = URL::toReviewLanguage($repositoryID, $languageID, $editID); } self::addBreadcrumbItem(htmlspecialchars($currentPageURL), Language::getLanguageNameFull($languageID)); self::setTitle($languageData->getNameFull()); if ($editID <= 0) { $editData = Database::getPendingEdit($repositoryID, $languageID); } else { $editData = Database::getPendingEdit($repositoryID, $languageID, $editID); } if (empty($editData)) { // no edits available for review (anymore) if ($isAllowedToReview) { // user is a staff member allowed to review phrases UI::redirectToURL(URL::toReview($repositoryID)); // redirect to review index page } else { // user is a guest taking part in the discussion only $contents[] = new UI_Heading($languageData->getNameFull(), true); $contents[] = new UI_Paragraph('This link has expired and is not valid anymore.'); $contents[] = new UI_Paragraph('The discussion has been closed. Thanks for your collaboration!'); } } else { // edits available for review $form = new UI_Form(htmlspecialchars($currentPageURL), false); $table = new UI_Table(array('', '')); $table->setColumnPriorities(3, 9); $contributorName = empty($editData[0]['real_name']) ? '<span class="text-muted">' . htmlspecialchars($editData[0]['username']) . '</span>' : htmlspecialchars($editData[0]['real_name']) . ' <span class="text-muted">(' . htmlspecialchars($editData[0]['username']) . ')</span>'; $buttonApprove = new UI_Form_Button('Approve', UI_Link::TYPE_SUCCESS, UI_Form_Button::ACTION_SUBMIT, 'review[action]', 'approve'); $buttonReviewLater = new UI_Form_Button('Review later', UI_Link::TYPE_UNIMPORTANT, UI_Form_Button::ACTION_SUBMIT, 'review[action]', 'reviewLater'); $buttonReject = new UI_Form_Button('Reject', UI_Link::TYPE_WARNING, UI_Form_Button::ACTION_SUBMIT, 'review[action]', 'reject'); $buttonApproveAllByContributor = new UI_Form_Button('Approve all from this contributor', UI_Link::TYPE_SUCCESS, UI_Form_Button::ACTION_SUBMIT, 'review[action]', 'approveAllFromThisContributor', 'return confirm(\'Are you sure you want to execute this batch operation? Danger: Validity checks (e.g. placeholders, whitespace, HTML) will not be performed!\');'); $buttonRejectAllByContributor = new UI_Form_Button('Reject all from this contributor', UI_Link::TYPE_DANGER, UI_Form_Button::ACTION_SUBMIT, 'review[action]', 'rejectAllFromThisContributor', 'return confirm(\'Are you sure you want to execute this batch operation?\');'); $actionButtons = new UI_Form_ButtonGroup(array($buttonApprove, $buttonReviewLater, $buttonReject), true); if ($isAllowedToReview) { $newValueEdit = new UI_Form_Textarea('', 'review[newValue]', $editData[0]['suggestedValue'], '', true, htmlspecialchars($editData[0]['suggestedValue']), UI_Form_Textarea::getOptimalRowCount($editData[0]['suggestedValue'], 2), Language::isLanguageRTL($languageID)); $newValueHTML = $newValueEdit->getHTML(); } else { $newValueHTML = '<span dir="' . (Language::isLanguageRTL($languageID) ? 'rtl' : 'ltr') . '">' . nl2br(htmlspecialchars($editData[0]['suggestedValue'])) . '</span>'; } $referencedPhrase = Phrase::create(0, $editData[0]['phraseKey'], $editData[0]['payload']); $previousPhraseData = Database::getPhrase($repositoryID, $languageID, $editData[0]['phraseKey']); if (empty($previousPhraseData)) { $previousPhrase = Phrase::create(0, $editData[0]['phraseKey'], $editData[0]['payload'], 0, true); } else { $previousPhrase = Phrase::create(0, $editData[0]['phraseKey'], $previousPhraseData['payload']); } $valuesReference = $referencedPhrase->getPhraseValues(); $valueReference = isset($valuesReference[$editData[0]['phraseSubKey']]) && is_string($valuesReference[$editData[0]['phraseSubKey']]) ? $valuesReference[$editData[0]['phraseSubKey']] : ''; $valuesPrevious = $previousPhrase->getPhraseValues(); $valuePrevious = isset($valuesPrevious[$editData[0]['phraseSubKey']]) && is_string($valuesPrevious[$editData[0]['phraseSubKey']]) ? trim($valuesPrevious[$editData[0]['phraseSubKey']]) : ''; $pendingEditsCount = Database::getPendingEditsByRepositoryAndLanguageCount($repositoryID, $languageID); $pendingEditsCountHTML = $pendingEditsCount . ' edit' . ($pendingEditsCount == 1 ? '' : 's') . ' to review'; $contents[] = new UI_Heading($languageData->getNameFull(), true, 1, $pendingEditsCountHTML); // mark placeholders and HTML tags in the reference phrase $phraseWithMarkedEntities = htmlspecialchars($valueReference); $phraseWithMarkedEntities = Phrase::markEntities($phraseWithMarkedEntities, Phrase_Android::getPlaceholders($valueReference), 'text-primary', true); $phraseWithMarkedEntities = Phrase::markEntities($phraseWithMarkedEntities, Phrase_Android::getHTMLTags($valueReference), 'text-success', true); // mark placeholders and HTML tags in the current (old) value of the phrase $originalWithMarkedEntities = htmlspecialchars($valuePrevious); $originalWithMarkedEntities = Phrase::markEntities($originalWithMarkedEntities, Phrase_Android::getPlaceholders($valueReference), 'text-primary', true); $originalWithMarkedEntities = Phrase::markEntities($originalWithMarkedEntities, Phrase_Android::getHTMLTags($valueReference), 'text-success', true); $fullyQualifiedName = Phrase_Android::getFullyQualifiedName($referencedPhrase, $editData[0]['phraseSubKey']); $fullyQualifiedNameHTML = '<span dir="ltr" class="small" style="display:block; color:#999; margin-top:4px;">' . htmlspecialchars($fullyQualifiedName) . '</span>'; $translateBackLink = self::linkToTranslationService('Check', $languageID, $repositoryData['defaultLanguage'], $editData[0]['suggestedValue']); $translateBackLink->setSize(UI_Link::SIZE_SMALL); $table->addRow(array('<strong>' . Language::getLanguageNameFull($repositoryData['defaultLanguage']) . '</strong>' . $fullyQualifiedNameHTML, '<span dir="' . (Language::isLanguageRTL($repositoryData['defaultLanguage']) ? 'rtl' : 'ltr') . '">' . nl2br($phraseWithMarkedEntities) . '</span>')); $table->addRow(array('<strong>Old value</strong>' . $fullyQualifiedNameHTML, '<span dir="' . (Language::isLanguageRTL($languageID) ? 'rtl' : 'ltr') . '">' . nl2br($originalWithMarkedEntities) . '</span>')); $table->addRow(array('<strong>Applied changes</strong>', '<div dir="' . (Language::isLanguageRTL($languageID) ? 'rtl' : 'ltr') . '">' . nl2br(htmlDiff(htmlspecialchars($valuePrevious), htmlspecialchars($editData[0]['suggestedValue']))) . '</div>')); $table->addRow(array('<strong>New value</strong>' . $fullyQualifiedNameHTML . '<br />' . $translateBackLink->getHTML(), $newValueHTML)); $table->addRow(array('<strong>Submit time</strong>', date('d.m.Y H:i', $editData[0]['submit_time']))); if ($isAllowedToReview) { $table->addRow(array('<strong>Contributor</strong>', $contributorName)); } if ($isAllowedToReview) { $form->addContent(new UI_Form_Hidden('review[editID]', URL::encodeID($editData[0]['id']))); $form->addContent(new UI_Form_Hidden('review[referenceValue]', $valueReference)); $form->addContent(new UI_Form_Hidden('review[phraseObject]', base64_encode(serialize($previousPhrase)))); $form->addContent(new UI_Form_Hidden('review[phraseKey]', htmlspecialchars($editData[0]['phraseKey']))); $form->addContent(new UI_Form_Hidden('review[phraseSubKey]', htmlspecialchars($editData[0]['phraseSubKey']))); $form->addContent(new UI_Form_Hidden('review[contributorID]', URL::encodeID($editData[0]['userID']))); } if ($isAllowedToReview) { $form->addContent($actionButtons); } $form->addContent($table); if ($isAllowedToReview) { $form->addContent($actionButtons); $form->addContent(new UI_Form_ButtonGroup(array($buttonApproveAllByContributor, $buttonRejectAllByContributor), true)); } $contents[] = $form; if ($editID > 0 || $isAllowedToReview) { // only for guest users who have the direct link to this edit ID and staff members who are allowed to review phrases $contents[] = new UI_Heading('Discussion', true, UI_Heading::LEVEL_MIN, URL::toReviewLanguage($repositoryID, $languageID, $editData[0]['id'])); $discussion = new UI_Form(htmlspecialchars($currentPageURL), false); $discussion->addContent(new UI_Form_Text('Your message', 'discussion[message]', 'Type here ...')); $discussion->addContent(new UI_Form_Hidden('discussion[editID]', URL::encodeID($editData[0]['id']))); $discussion->addContent(new UI_Form_ButtonGroup(array(new UI_Form_Button('Send')))); $contents[] = $discussion; $discussionEntries = Database::getDiscussionEntries($editData[0]['id']); foreach ($discussionEntries as $discussionEntry) { $contents[] = new UI_Paragraph('<strong>' . htmlspecialchars($discussionEntry['username']) . '</strong> (' . Time::getTimeAgo($discussionEntry['timeSent']) . '):<br />' . htmlspecialchars($discussionEntry['content'])); } } } } } } $cell = new UI_Cell($contents); $row = new UI_Row(array($cell)); $containers[] = new UI_Container(array($row)); return new UI_Group($containers); }
/** * Compara el contenido con una version especificada * * @param Doctrine_Record $version_anterior contenido a comparar. * * @return string */ public function compareWith(Contenido $version_anterior) { $comparacion = array(); $left = $this->toArray(false); $right = $version_anterior->toArray(false); $exclude = array('id', 'maestro', 'maestro_id', 'publicado', 'publicado_at', 'updated_at', 'created_at'); foreach ($left as $field => $value) { if (!in_array($field, $exclude)) { if ($right[$field] != $left[$field]) { $diff = trim(htmlDiff(strip_tags($right[$field]), strip_tags($left[$field]))); $comparacion[$field]->left[] = $diff; $comparacion[$field]->right[] = $right[$field]; } } } return $comparacion; }