本文整理汇总了PHP中Diff::comparer方法的典型用法代码示例。如果您正苦于以下问题:PHP Diff::comparer方法的具体用法?PHP Diff::comparer怎么用?PHP Diff::comparer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Diff
的用法示例。
在下文中一共展示了Diff::comparer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afficher_diff_champ_dist
/**
* Afficher le diff d'un champ texte generique
*
* @param string $champ
* @param string $old
* @param string $new
* @param string $format
* apercu, diff ou complet
* @return string
*/
function afficher_diff_champ_dist($champ, $old, $new, $format = 'diff')
{
// ne pas se compliquer la vie !
if ($old == $new) {
$out = $format != 'complet' ? '' : $new;
} else {
if ($f = charger_fonction($champ, 'afficher_diff', true)) {
return $f($champ, $old, $new, $format);
}
$diff = new Diff(new DiffTexte());
$n = preparer_diff($new);
$o = preparer_diff($old);
$out = afficher_diff($diff->comparer($n, $o));
if ($format == 'diff' or $format == 'apercu') {
$out = afficher_para_modifies($out, $format == 'apercu');
}
}
return $out;
}
示例2: revision_comparee
function revision_comparee($id_article, $id_version, $format='diff', $id_diff=NULL) {
include_spip('inc/diff');
// chercher le numero de la version precedente
if (!$id_diff) {
$id_diff = sql_getfetsel("id_version", "spip_versions", "id_article=" . intval($id_article) . " AND id_version < " . intval($id_version), "", "id_version DESC", "1");
}
if ($id_version && $id_diff) {
// si l'ordre est inverse, on remet a l'endroit
if ($id_diff > $id_version) {
$t = $id_version;
$id_version = $id_diff;
$id_diff = $t;
}
$old = recuperer_version($id_article, $id_diff);
$new = recuperer_version($id_article, $id_version);
$textes = array();
// Mode "diff": on ne s'interesse qu'aux champs presents dans $new
// Mode "complet": on veut afficher tous les champs
switch ($format) {
case 'complet':
$champs = liste_champs_versionnes('spip_articles');
break;
case 'diff':
case 'apercu':
default:
$champs = array_keys($new);
break;
}
foreach ($champs as $champ) {
// si la version precedente est partielle,
// il faut remonter dans le temps
$id_ref = $id_diff-1;
while (!isset($old[$champ])
AND $id_ref>0) {
$prev = recuperer_version($id_article, $id_ref--);
if (isset($prev[$champ]))
$old[$champ] = $prev[$champ];
}
if (!strlen($new[$champ]) && !strlen($old[$champ])) continue;
// si on n'a que le vieux, ou que le nouveau, on ne
// l'affiche qu'en mode "complet"
if ($format == 'complet')
$textes[$champ] = strlen($new[$champ])
? $new[$champ] : $old[$champ];
// si on a les deux, le diff nous interesse, plus ou moins court
if (isset($new[$champ])
AND isset($old[$champ])) {
// cas particulier : id_rubrique
if (in_array($champ, array('id_rubrique'))) {
$textes[$champ] = _T('version_deplace_rubrique',
array('from'=> titre_rubrique($old[$champ])
,'to'=>titre_rubrique($new[$champ]))
);
}
// champs textuels
else {
$diff = new Diff(new DiffTexte);
$n = preparer_diff($new[$champ]);
$o = preparer_diff($old[$champ]);
$textes[$champ] = afficher_diff($diff->comparer($n,$o));
if ($format == 'diff' OR $format == 'apercu')
$textes[$champ] = afficher_para_modifies($textes[$champ], ($format == 'apercu'));
}
}
}
}
// que donner par defaut ? (par exemple si id_version=1)
if (!$textes)
$textes = recuperer_version($id_article, $id_version);
return $textes;
}
示例3: _diff
public function _diff($p, $p_old)
{
$diff = new Diff(new DiffPhrase());
return $diff->comparer($p, $p_old);
}
示例4: signaler_conflits_edition
function signaler_conflits_edition($conflits, $redirect='') {
include_spip('inc/minipres');
include_spip('inc/revisions');
include_spip('inc/suivi_versions');
include_spip('inc/diff');
foreach ($conflits as $champ=>$a) {
// probleme de stockage ou conflit d'edition ?
$base = isset($a['save']) ? $a['save'] : $a['base'];
$diff = new Diff(new DiffTexte);
$n = preparer_diff($a['post']);
$o = preparer_diff($base);
$d = propre_diff(
afficher_para_modifies(afficher_diff($diff->comparer($n,$o))));
$titre = isset($a['save']) ? _L('Echec lors de l\'enregistrement du champ @champ@', array('champ' => $champ)) : $champ;
$diffs[] = "<h2>$titre</h2>\n"
. "<h3>"._T('info_conflit_edition_differences')."</h3>\n"
. "<div style='max-height:8em; overflow: auto; width:99%;'>".$d."</div>\n"
. "<h4>"._T('info_conflit_edition_votre_version')."</h4>"
. display_conflit_champ($a['post'])
. "<h4>"._T('info_conflit_edition_version_enregistree')."</h4>"
. display_conflit_champ($base);
}
if ($redirect) {
$id = uniqid(rand());
$redirect = "<form action='$redirect' method='get'
id='$id'
style='float:".$GLOBALS['spip_lang_right']."; margin-top:2em;'>\n"
.form_hidden($redirect)
."<input type='submit' value='"._T('icone_retour')."' />
</form>\n";
// pour les documents, on est probablement en ajax : il faut ajaxer
if (_AJAX)
$redirect .= '<script type="text/javascript">'
.'setTimeout(function(){$("#'.$id.'")
.ajaxForm({target:$("#'.$id.'").parent()});
}, 200);'
."</script>\n";
}
echo minipres(
_T('titre_conflit_edition'),
'<style>
.diff-para-deplace { background: #e8e8ff; }
.diff-para-ajoute { background: #d0ffc0; color: #000; }
.diff-para-supprime { background: #ffd0c0; color: #904040; text-decoration: line-through; }
.diff-deplace { background: #e8e8ff; }
.diff-ajoute { background: #d0ffc0; }
.diff-supprime { background: #ffd0c0; color: #802020; text-decoration: line-through; }
.diff-para-deplace .diff-ajoute { background: #b8ffb8; border: 1px solid #808080; }
.diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; }
.diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; }
</style>'
.'<p>'._T('info_conflit_edition_avis_non_sauvegarde').'</p>'
.'<p>'._T('texte_conflit_edition_correction').'</p>'
."<div style='text-align:".$GLOBALS['spip_lang_left'].";'>"
. join("\n",$diffs)
."</div>\n"
. $redirect
);
}