function finish($async)
 {
     if ($async->outs[0] !== $async->outs[2] or $async->errs[0] !== $async->errs[2] or $async->exits[0] !== $async->exits[2]) {
         $output = diff($async->outs[0], $async->outs[2]);
         $async->outs = $output;
         $this->async_failure("Outputs dont match PHP outputs", $async);
     } else {
         $this->async_success($async);
     }
 }
function htmlDiff($old, $new)
{
    $diff = diff(explode(' ', $old), explode(' ', $new));
    foreach ($diff as $k) {
        if (is_array($k)) {
            $ret .= (!empty($k['d']) ? "<del>" . implode(' ', $k['d']) . "</del> " : '') . (!empty($k['i']) ? "<ins>" . implode(' ', $k['i']) . "</ins> " : '');
        } else {
            $ret .= $k . ' ';
        }
    }
    return $ret;
}
function htmlDiff($old, $new, $format = array('+' => '<ins>%s</ins>', '-' => '<del>%s</del>'))
{
    $diff = diff(str_split($old), str_split($new));
    $ret = '';
    foreach ($diff as $k) {
        if (is_array($k)) {
            $ret .= (!empty($k['d']) ? sprintf($format['-'], implode('', $k['d'])) : '') . (!empty($k['i']) ? sprintf($format['+'], implode('', $k['i'])) : '');
        } else {
            $ret .= $k . '';
        }
    }
    return $ret;
}
Exemple #4
0
 public function do_url()
 {
     if (!isset(Vars::$get['page'])) {
         throw new CommandException('パラメータが足りません。', $this);
     }
     $page = Page::getinstance(Vars::$get['page']);
     $ret['title'] = $page->getpagename() . ' の変更点';
     $smarty = $this->getSmarty();
     $smarty->assign('diff', diff($page->getsource(1), $page->getsource(0)));
     $ret['body'] = $smarty->fetch('diff.tpl.htm');
     $ret['pagename'] = $page->getpagename();
     return $ret;
 }
Exemple #5
0
function run_main()
{
    $old_rev = (int) $_GET["old_rev"];
    $new_rev = (int) $_GET["new_rev"];
    $unsafe_filename = $_GET["filename"];
    $sort_first = $_GET["sort"] or false;
    # Sanitize the revisions: 0 < old_rev < new_rev < 5000
    if (!(0 < $old_rev)) {
        bad();
    }
    if (!($old_rev < $new_rev)) {
        bad();
    }
    if (!($new_rev < 5000)) {
        bad();
    }
    # Sanitize the inputs: the file should be within the results/$rev subdirectory
    $relative_filename = "results/{$new_rev}/{$unsafe_filename}";
    $real_filename = realpath($relative_filename);
    # We find the dir by checking the fullname of this script, and stripping off the script name at the end
    $real_scriptname = realpath(__FILE__);
    $scriptname = "test/framework/records/diff.php";
    $script_dir = str_replace($scriptname, "", $real_scriptname);
    # Check that the script is within these bounds
    if (strpos($real_filename, $script_dir) !== 0) {
        # FALSE is a fail, but 0 isnt
        bad();
    }
    $old_filename = realpath("results/{$old_rev}/{$unsafe_filename}");
    $new_filename = realpath("results/{$new_rev}/{$unsafe_filename}");
    if (!file_exists($old_filename)) {
        die("No old file");
    }
    if (!file_exists($new_filename)) {
        die("No new file");
    }
    $old = file_get_contents($old_filename);
    if ($sort_first) {
        $split = split("\n", $old);
        sort($split);
        $old = join("\n", $split);
    }
    $new = file_get_contents($new_filename);
    if ($sort_first) {
        $split = split("\n", $new);
        sort($split);
        $new = join("\n", $split);
    }
    echo "<pre>" . diff($old, $new) . "</pre>\n";
}
Exemple #6
0
 function pageWritten()
 {
     global $WIKI_TITLE, $PG_DIR, $page, $HIST_DIR, $LANG, $VAR_DIR, $PROTECTED_READ;
     if ($PROTECTED_READ) {
         return false;
     }
     $pagelink = ($_SERVER["HTTPS"] ? "https://" : "http://") . $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["SCRIPT_NAME"];
     preg_match("/<\\/language>(.*)<\\/channel>/s", @file_get_contents($VAR_DIR . "rss.xml"), $matches);
     $items = $matches[1];
     $pos = -1;
     // count items
     for ($i = 0; $i < $this->max_changes - 1; $i++) {
         if (!($pos = strpos($items, "</item>", $pos + 1))) {
             break;
         }
     }
     if ($pos) {
         // if count is higher than $max_changes - 1, cut out the rest
         $items = substr($items, 0, $pos + 7);
     }
     if ($opening_dir = @opendir($HIST_DIR . $page . "/")) {
         // find two last revisions of page
         $files = array();
         while ($filename = @readdir($opening_dir)) {
             if (preg_match('/\\.bak$/', $filename)) {
                 $files[] = $filename;
             }
         }
         rsort($files);
         $newest = diff($files[0], $files[1], $this->short_diff);
         // LionWiki diff function
         clearstatcache();
         $timestamp = filemtime($PG_DIR . $page . ".txt");
         $n_item = "\n\t<item>\n\t  <title>" . h($page) . "</title>\n\t  <pubDate>" . date("r", $timestamp) . "</pubDate>\n\t  <link>" . h($pagelink) . "?page=" . u($page) . "</link>\n\t  <description>{$newest}</description>\n\t</item>";
     } else {
         echo "RSS plugin: can't open history directory!";
     }
     $rss = str_replace('{WIKI_TITLE}', h($WIKI_TITLE), $this->template);
     $rss = str_replace('{PAGE_LINK}', h($pagelink), $rss);
     $rss = str_replace('{LANG}', h($LANG), $rss);
     $rss = str_replace('{WIKI_DESCRIPTION}', "RSS feed from " . h($WIKI_TITLE), $rss);
     $rss = str_replace('{CONTENT_RSS}', $n_item . $items, $rss);
     if (!($file = @fopen($VAR_DIR . "rss.xml", "w"))) {
         echo "Opening file for writing RSS file is not possible! Please create file rss.xml in your var directory and make it writable (chmod 666).";
         return false;
     }
     fwrite($file, $rss);
     fclose($file);
     return false;
 }
Exemple #7
0
/**
 * Altered source code below
 */
function htmlDiff($old, $new)
{
    if ($old == $new) {
        return '<span style="color:#999;">&mdash; no changes &mdash;</span>';
    }
    $ret = '';
    $diff = diff(explode(' ', $old), explode(' ', $new));
    foreach ($diff as $k) {
        if (is_array($k)) {
            $ret .= (!empty($k['d']) ? '<span style="color:#666; text-decoration:line-through;">' . implode(' ', $k['d']) . '</span> ' : '') . (!empty($k['i']) ? '<span style="color:#f00; font-weight:bold;">' . implode(' ', $k['i']) . '</span> ' : '');
        } else {
            $ret .= $k . ' ';
        }
    }
    return $ret;
}
Exemple #8
0
 protected function change_page($page)
 {
     $pagename = $page->getpagename();
     if (!$page->isexist()) {
         $head = "「{$pagename}」が削除されました。";
     } else {
         if (!$page->isexist(1)) {
             $head = "「{$pagename}」が作成されました。";
         } else {
             $head = "「{$pagename}」が変更されました。";
         }
     }
     $subject = '[' . SITENAME . "] {$pagename}";
     $text[] = $head;
     $text[] = $this->geturl($page);
     $text[] = '----------------------------------------------------------------------';
     $text[] = diff($page->getsource(1), $page->getsource(0), MAIL_DIFF);
     sendmail($subject, join("\n", $text));
 }
Exemple #9
0
function diff($old, $new)
{
    $matrix = array();
    $maxlen = 0;
    foreach ($old as $oindex => $ovalue) {
        $nkeys = array_keys($new, $ovalue);
        foreach ($nkeys as $nindex) {
            $matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ? $matrix[$oindex - 1][$nindex - 1] + 1 : 1;
            if ($matrix[$oindex][$nindex] > $maxlen) {
                $maxlen = $matrix[$oindex][$nindex];
                $omax = $oindex + 1 - $maxlen;
                $nmax = $nindex + 1 - $maxlen;
            }
        }
    }
    if ($maxlen == 0) {
        return array(array('d' => $old, 'i' => $new));
    }
    return array_merge(diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)), array_slice($new, $nmax, $maxlen), diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)));
}
Exemple #10
0
function diffsparsejson($old, $new)
{
    $diff = diff(diffstringsplit($old), diffstringsplit($new));
    $adj = 0;
    $out = array();
    foreach ($diff as $k => $v) {
        if (is_array($v)) {
            if (empty($v['d']) && empty($v['i'])) {
                $adj += 1;
                continue;
            } else {
                if (empty($v['d'])) {
                    //insert
                    $out[] = array(0, $k - $adj, $v['i']);
                    $adj += 1;
                } else {
                    if (empty($v['i'])) {
                        //delete
                        $out[] = array(1, $k - $adj, count($v['d']));
                        $adj -= count($v['d']) - 1;
                    } else {
                        //replace
                        $out[] = array(2, $k - $adj, count($v['d']), $v['i']);
                        $adj -= count($v['d']) - 1;
                    }
                }
            }
        }
    }
    if (count($out) == 0) {
        return '';
    } else {
        if (function_exists('json_encode')) {
            return json_encode($out);
        } else {
            require_once "JSON.php";
            $jsonser = new Services_JSON();
            return $jsonser->encode($out);
        }
    }
}
Exemple #11
0
function fill($draw, $note)
{
    global $summr;
    global $notes;
    foreach ($notes as $nom => $qnt) {
        if (!isset($draw[$nom])) {
            $draw[$nom] = 0;
        }
    }
    $diff = $draw != $notes ? diff($draw) : $notes;
    foreach ($diff as $nom => &$qnt) {
        if ($nom == $note) {
            continue;
        }
        while (getSumm($draw) + $nom <= $summr && $qnt > 0) {
            $qnt--;
            $draw[$nom]++;
        }
    }
    return $draw;
}
Exemple #12
0
function history($data)
{
    if ($data['id']) {
        $id = $data['id'];
    } else {
        echo 'Error';
    }
    $rs = getWHistory($id);
    $cnt = count($rs);
    if ($cnt > 1) {
        if (isset($data['v1']) && $data['v1'] != 'undefined') {
            $v1 = $data['v1'];
        } else {
            $v1 = $cnt - 2;
        }
        if (isset($data['v2']) && $data['v1'] != 'undefined') {
            $v2 = $data['v2'];
        } else {
            $v2 = $cnt - 1;
        }
        $diffrs = diff($rs[$v1]["content"], $rs[$v2]["content"]);
        $content["version"] = $cnt;
    }
    $contentdata = '';
    if ($rs) {
        for ($i = 0; $i < $cnt; $i++) {
            $v = $rs[$i]["version"];
            $datum = substr($rs[$i]["initdate"], 8, 2) . "." . substr($rs[$i]["initdate"], 5, 2) . "." . substr($rs[$i]["initdate"], 0, 4);
            $datum .= " " . substr($rs[$i]["initdate"], 11, 2) . ":" . substr($rs[$i]["initdate"], 14, 2);
            $contdata .= "<p><input type='checkbox' name='diff' id='diff{$v}' value='{$i}'>{$v} ";
            $contdata .= $datum . " - " . $rs[$i]["login"] . " - " . strlen($rs[$i]["content"]) . " Byte</p>";
        }
        if ($cnt > 1) {
            $contdata .= "Version: " . $rs[$v1]["version"] . "<hr />" . $diffrs[0] . "<br /><br />Version: " . $rs[$v2]["version"] . "<hr />" . $diffrs[1];
        }
    } else {
        $contdata = ".:no_data:.{$cnt}";
    }
    echo $contdata;
}
Exemple #13
0
 /**
  * ポストされたデータを元に書き込む。
  */
 protected function write()
 {
     $source = mb_ereg_replace('\\r?\\n', "\n", Vars::$post['source']);
     $seed = Vars::$post['seed'];
     $notimestamp = isset(Vars::$post['notimestamp']) && Vars::$post['notimestamp'] == 'on' ? true : false;
     $page = Page::getinstance(Vars::$post['pagename']);
     if ($seed != md5($page->getsource())) {
         $ret['title'] = '更新が衝突しました';
         $smarty = $this->getSmarty();
         $smarty->assign('pagename', $page->getpagename());
         $smarty->assign('diff', diff($page->getsource(), $source));
         $smarty->assign('form', $this->getpostform($page->getpagename(), $source, $notimestamp, md5($page->getsource())));
         $ret['body'] = $smarty->fetch('conflict.tpl.htm');
         $ret['pagename'] = $page->getpagename();
         return $ret;
     } else {
         if ($source != $page->getsource()) {
             //内容に変更がある場合のみ更新
             $page->write($source, $notimestamp);
             $this->notify(array('write', $page));
         }
         redirect($page);
     }
 }
Exemple #14
0
function test_file($file)
{
    echo "Testing {$file} \n";
    $mpq = new MPQFile($file);
    $rep = $mpq->parseReplay();
    if (!$rep) {
        echo "Parse error!";
        return;
    }
    $new = $rep->jsonify();
    if (file_exists($file . '.parsed')) {
        $old = file_get_contents($file . '.parsed');
        $diff = diff($old, $new);
        if ($diff != -1) {
            echo $file . ': position ' . $diff . ' old: >>' . substr($old, $diff - 5, 10) . '<< new: >>' . substr($new, $diff - 5, 10) . "<< ";
            file_put_contents($file . '.new.parsed', $new);
            echo "New content saved as " . $file . ".new.parsed\n";
            //printDiff($old, $new);
        }
    } else {
        file_put_contents($file . '.parsed', $new);
        echo "Content saved as {$file}.parsed\n";
    }
}
Exemple #15
0
<section class="proposal_content diff">
<h2><?php 
echo _("Title");
?>
</h2>
<p class="proposal proposal_title"><? diff($draft->title, $draft2->title)?></p>
<h2><?php 
echo _("Content");
?>
</h2>
<p class="proposal"><? diff($draft->content, $draft2->content)?></p>
<h2><?php 
echo _("Reason");
?>
</h2>
<p class="proposal"><? diff($draft->reason, $draft2->reason)?></p>
</section>

<div class="clearfix"></div>

<?

html_foot();


/**
 * wrapper for PHP-FineDiff library
 *
 * @param string  $from_text
 * @param string  $to_text
 */
    if (Database::num_rows($query2) > 0) {
        $files = array();
        // Add item to an array
        while ($invisible_folders = Database::fetch_assoc($query2)) {
            //3rd: Get all files that are in the found invisible folder (these are "invisible" too)
            $sql = "SELECT path, docs.id, props.to_group_id, docs.c_id\n                    FROM {$doc_table} AS docs\n                    INNER JOIN {$prop_table} AS props\n                    ON\n                        docs.id = props.ref AND\n                        docs.c_id = props.c_id\n                    WHERE\n                        docs.c_id = {$courseId} AND\n                        props.tool ='" . TOOL_DOCUMENT . "' AND\n                        docs.path LIKE '" . $invisible_folders['path'] . "/%' AND\n                        docs.filetype = 'file' AND\n                        (props.session_id IN ('0', '{$sessionId}') OR props.session_id IS NULL) AND\n                        props.visibility ='1'";
            $query3 = Database::query($sql);
            // Add tem to an array
            while ($files_in_invisible_folder = Database::fetch_assoc($query3)) {
                $files_in_invisible_folder_path[] = $files_in_invisible_folder['path'];
                $files[$files_in_invisible_folder['path']] = $files_in_invisible_folder;
            }
        }
        // Compare the array with visible files and the array with files in invisible folders
        // and keep the difference (= all visible files that are not in an invisible folder)
        $files_for_zipfile = diff((array) $all_visible_files_path, (array) $files_in_invisible_folder_path);
    } else {
        // No invisible folders found, so all visible files can be added to the zipfile
        $files_for_zipfile = $all_visible_files_path;
    }
    Session::write('doc_files_to_download', $files);
    // Add all files in our final array to the zipfile
    for ($i = 0; $i < count($files_for_zipfile); $i++) {
        $zip->add($sysCoursePath . $courseInfo['path'] . '/document' . $files_for_zipfile[$i], PCLZIP_OPT_REMOVE_PATH, $sysCoursePath . $courseInfo['path'] . '/document' . $remove_dir, PCLZIP_CB_PRE_ADD, 'fixDocumentNameCallback');
    }
    Session::erase('doc_files_to_download');
}
// Launch event
Event::event_download($path == '/' ? 'documents.zip (folder)' : basename($path) . '.zip (folder)');
// Start download of created file
$name = $path == '/' ? 'documents.zip' : $documentInfo['title'] . '.zip';
}
// Check if the IDs match.. if they don't, comparing is quite useless.
$revNewArr = array();
$revOldArr = array();
$revNewArr['id'] = $revNewObj->get('id');
$revOldArr['id'] = $revOldObj->get('id');
if ($revNewArr['id'] !== $revOldArr['id']) {
    $err = array('total' => 1, 'results' => array(0 => array('change' => 'ERROR', 'oldvalue' => $modx->lexicon('versionx.error.revsdontmatch'))));
    die(json_encode($err));
}
// If the script got down here, let's compare the content.
$c1 = $revNewObj->get('contentField');
$c2 = $revOldObj->get('contentField');
$c1n = explode("\n", htmlentities(trim($c1)));
$c2n = explode("\n", htmlentities(trim($c2)));
// Include the diff class by Paul Butler (© 2007)
include_once 'diff.class.php';
// Fetch the changes by calling the diff class
$changed = diff($c2n, $c1n);
// Instantiate a simple line counter
$chline = 0;
foreach ($changed as $k) {
    $chline++;
    if (is_array($k)) {
        $ret[] = array('line' => $chline, 'body' => (!empty($k['d']) ? "<del>" . implode(' ', $k['d']) . "</del> " : '') . (!empty($k['i']) ? "<ins>" . implode(' ', $k['i']) . "</ins> " : ''));
    }
    // @TODO: Make the below a setting wether or not to display the non-changed lines.
    //else $ret[] = array('line' => $chline,'body' => $k);
}
$result = array('total' => count($ret), 'results' => $ret, 'xpdoresult' => $rl[0]);
echo json_encode($result);
Exemple #18
0
 protected function diffnow()
 {
     if (!isset(Vars::$get['page'])) {
         throw new CommadnException('パラメータが足りません。', $this);
     }
     $num = isset(Vars::$get['num']) ? Vars::$get['num'] : 1;
     $page = Page::getinstance(Vars::$get['page']);
     $timestamp = $page->gettimestamp($num);
     $diff = diff($page->getsource($num), $page->getsource(0));
     $renderer = new DiffRenderer($diff);
     $ret['title'] = $page->getpagename() . ' の現在との差分';
     $smarty = $this->getSmarty();
     $smarty->assign('pagename', $page->getpagename());
     $smarty->assign('timestamp', $timestamp);
     $smarty->assign('backupnumber', $num);
     $smarty->assign('diff', $diff);
     $ret['body'] = $smarty->fetch('diffnow.tpl.htm');
     $ret['pagename'] = $page->getpagename();
     return $ret;
 }
Exemple #19
0
 // show differences
 case 'diff':
     include 'modules/wiki/lib/lib.diff.php';
     if ($wikiStore->pageExists($wikiId, $wiki_title)) {
         // older version
         $wikiPage->loadPageVersion($old);
         $old = $wikiPage->getContent();
         $oldTime = $wikiPage->getCurrentVersionMtime();
         $oldEditor = $wikiPage->getEditorId();
         // newer version
         $wikiPage->loadPageVersion($new);
         $new = $wikiPage->getContent();
         $newTime = $wikiPage->getCurrentVersionMtime();
         $newEditor = $wikiPage->getEditorId();
         // get differences
         $diff = '<table style="border: 0;">' . diff($old, $new, true, 'format_table_line') . '</table>';
     }
     break;
     // page history
     //case 'history':
     // recent changes
 // page history
 //case 'history':
 // recent changes
 case 'recent':
     $recentChanges = $wiki->recentChanges();
     break;
     // all pages
 // all pages
 case 'all':
     $allPages = $wiki->allPages();
Exemple #20
0
    $CON .= '</form>';
} elseif ($action == 'diff') {
    if (!$f1 && ($dir = @opendir("{$HIST_DIR}{$page}/"))) {
        // diff is made on two last revisions
        while ($f = @readdir($dir)) {
            if (substr($f, -4) == '.bak') {
                $files[] = $f;
            }
        }
        rsort($files);
        die(header("Location:{$self}?action=diff&page=" . u($page) . "&f1={$files['0']}&f2={$files['1']}"));
    }
    $r1 = "<a href=\"{$self}?page=" . u($page) . "&amp;action=rev&amp;f1={$f1}\">" . rev_time($f1) . "</a>";
    $r2 = "<a href=\"{$self}?page=" . u($page) . "&amp;action=rev&amp;f1={$f2}\">" . rev_time($f2) . "</a>";
    $CON = str_replace(array("{REVISION1}", "{REVISION2}"), array($r1, $r2), $T_REV_DIFF);
    $CON .= diff($f1, $f2);
} elseif ($action == 'search') {
    for ($files = array(), $dir = opendir($PG_DIR); $f = readdir($dir);) {
        if (substr($f, -4) == '.txt' && ($c = @file_get_contents($PG_DIR . $f))) {
            if (!$query || stristr($f . $c, $query) !== false) {
                $files[] = substr($f, 0, -4);
            }
        }
    }
    sort($files);
    foreach ($files as $f) {
        $list .= "<li><a href=\"{$self}?page=" . u($f) . '&amp;redirect=no">' . h($f) . "</a></li>";
    }
    $CON = "<ul>{$list}</ul>";
    if ($query && !file_exists("{$PG_DIR}{$query}.txt")) {
        // offer to create the page
Exemple #21
0
 if (!empty($msg['video'])) {
     $old[] = "video: " . $msg['video'];
 }
 $new[] = "Subject: " . $nmsg['subject'];
 $new = array_merge($new, explode("\n", $nmsg['message']));
 if (!empty($nmsg['url'])) {
     $new[] = "urltext: " . $nmsg['urltext'];
     $new[] = "url: " . $nmsg['url'];
 }
 if (!empty($nmsg['imageurl'])) {
     $new[] = "imageurl: " . $nmsg['imageurl'];
 }
 if (!empty($nmsg['video'])) {
     $new[] = "video: " . $nmsg['video'];
 }
 $diff .= diff($old, $new);
 /* IMAGEURL HACK - prepend before insert */
 /* for diffing and for entry into the db */
 $nmsg = image_url_hack_insert($nmsg);
 /* Add it into the database */
 $iid = mid_to_iid($mid);
 if (!isset($iid)) {
     err_not_found("message {$mid} has no iid");
     exit;
 }
 $sql = "update f_messages{$iid} set name = ?, email = ?, flags = ?, subject = ?, " . "message = ?, url = ?, urltext = ?, video = ?, state = ?, " . "changes = CONCAT(changes, 'Edited by ', ?, '/', ?, ' at ', NOW(), ' from ', ?, '\n', ?, '\n') " . "where mid = ?";
 db_exec($sql, array($nmsg['name'], $nmsg['email'], $nmsg['flags'], $nmsg['subject'], $nmsg['message'], $nmsg['url'], $nmsg['urltext'], $nmsg['video'], $nmsg['state'], $user->name, $user->aid, $remote_addr, $diff, $mid));
 $sql = "replace into f_updates ( fid, mid ) values ( ?, ? )";
 db_exec($sql, array($forum['fid'], $mid));
 /* update user post counts and f_indexes */
 if ($state_changed) {
Exemple #22
0
function collision_detection($current, $new)
{
    $out = "h1. Mid-air collision detected\n\n";
    $out .= "While you were editing that, someone else submitted an edit. Below are the differences between them:\n\n";
    $out .= diff(wordwrap(stripslashes($new['content'])), wordwrap(stripslashes($current['content'])));
    $out .= "\n\nWhatever you submit now will be the new copy, please fold in the previous person's information. \n\n";
    return $out;
}
Exemple #23
0
function ban_ban_users_courses_diff($ban_courses, $ban_users)
{
    next1($ban_courses, true);
    next2($ban_users, true);
    return diff('next1', 'next2', 'ban_ban_users_courses_cmp', 'ban_users_courses_insert', 'ban_users_courses_delete', 'ban_users_courses_update');
}
function getDiscounts($type)
{
    $query = new Query();
    $values = $query->select("discountid, monto, description, date_expiration", "cash_discount", "type = {$type}", "", "obj");
    if (count($values) > 0) {
        echo "<select id='discount_select' name='discount_select' class='form-control'>";
        echo "<option value='0' monto='0' selected>Seleccione un descuento</option>";
        foreach ($values as $d) {
            $dateLast = date('Y-m-d', strtotime($d->date_expiration));
            $now = date("Y-m-d");
            if (diff($dateLast, $now) == 0) {
                $query->remove("cash_discount", "discountid = {$d->discountid}");
            } else {
                echo "<option value='" . $d->discountid . "' monto='" . $d->monto . "'>" . utf8_encode($d->description) . "</option>";
            }
        }
        echo "</select>";
    } else {
        echo "<div class='alert alizarin' role='alert'>No hay descuentos disponibles.</div>";
    }
}
Exemple #25
0
			<th>Username</th>
			<th>Time</th>
			<th>Old value</th>
			<th>New value</th>
		</tr>
		<?php 
    $field_edit_final_list = array();
    foreach ($field_edits as $field => $field_entry) {
        for ($i = 0; $i < sizeof($field_entry); $i++) {
            $field_edit_final_list[] = $field_entry[$i];
        }
    }
    usort($field_edit_final_list, 'pagediff');
    foreach ($field_edit_final_list as $entry) {
        if (in_array($entry['field'], array('mod_pages', 'admin_pages'))) {
            diff($entry, $old_disp, $new_disp);
            $old = implode('<br />', $old_disp);
            $new = implode('<br />', $new_disp);
        } else {
            $old = htmlspecialchars($entry['old_value']);
            $new = htmlspecialchars($entry['new_value']);
        }
        echo '<tr><td>' . $entry['field'] . '</td><td>' . htmlspecialchars($entry['username']) . '</td><td>' . user_date($entry['time']) . '</td><td><pre>' . $old . '</pre></td><td><pre>' . $new . '</pre></td></tr>';
    }
    ?>
	</table>
<?php 
}
?>
</div>
<?php 
Exemple #26
0
	!is_number($_GET['new']) || 
	!is_number($_GET['id']) || 
	$_GET['old'] > $_GET['new']
) { error(0); }

$ArticleID = $_GET['id'];

$Article = $Alias->article($ArticleID);
list($Revision, $Title, $Body, $Read, $Edit, $Date, $AuthorID, $AuthorName) = array_shift($Article);
if($Read > $LoggedUser['Class']){ error(404); }

show_header('Compare Article Revisions');
$Diff2 = get_body($ArticleID, $_GET['new']);
$Diff1 = get_body($ArticleID, $_GET['old']);
?>
<div class="thin">
	<h2>Compare <a href="wiki.php?action=article&id=<?php 
echo $ArticleID;
?>
"><?php 
echo $Title;
?>
</a> Revisions</h2>
	<div class="box center_revision" id="center">
		<div class="body"><? foreach(diff($Diff1, $Diff2) AS $Line) { echo $Line; } ?></div>
	</div>
</div>
<?
show_footer();
?>
<?php

/*
 * Script used for manipulating c2c.osm
 * - see changes (based on what we can get from josm format)
 * - clean (remove deleted items, attributes new ids etc)
 * - extract kml
 */
libxml_use_internal_errors(true);
if ($argc < 3) {
    usage();
}
switch ($argv[1]) {
    case 'diff':
        diff();
        break;
    case 'clean':
        clean();
        break;
    case 'extract':
        extractkml();
        break;
    default:
        usage();
}
/*
 * Print to stdout a kml
 * extracted from josm file that can then
 * be imported into camptocamp
 */
function extractkml()
function html_diff($old, $new)
{
    $diff = diff(explode(' ', $old), explode(' ', $new));
    $ret = '';
    foreach ($diff as $k) {
        if (is_array($k)) {
            $ret .= (!empty($k['d']) ? "<del>" . implode(' ', $k['d']) . "</del> " : '') . (!empty($k['i']) ? "<span style='background:#B8EFDD;'>" . implode(' ', $k['i']) . "</span> " : '');
        } else {
            $ret .= $k . ' ';
        }
    }
    return $ret;
}
 function sendRSSFeed()
 {
     if ($this->passwordProtected) {
         /* As there's no login panel for RSS feeds, we use HTTP Basic auth here. */
         if (count($this->users) < 1 && (empty($this->username) || strlen($this->password) !== 32)) {
             die("Username or Password misconfigured.");
         }
         if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !$this->checkPassword($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
             header('WWW-Authenticate: Basic realm="' . addslashes($this->likiTitle) . '"');
             header('HTTP/1.0 401 Unauthorized');
             print "<html><h1>Access denied.</h1></html>\n";
             $this->quit();
         }
     }
     // load dns cache
     if (!file_exists($this->dataDir . '/_DNSCACHE_')) {
         $dnscache = array();
     } else {
         $dnscache = unserialize(implode('', file($this->dataDir . '/_DNSCACHE_')));
     }
     // remove entries older than a day
     $yesterday = time() - 60 * 60 * 24;
     foreach ($dnscache as $key => $r) {
         if ($r['written'] < $yesterday) {
             array_splice($dnscache, $key, 1);
         }
     }
     // still does not work with splitting at every char, because of encoding trouble :(
     $splitAtSpaces = true;
     //header('Content-type: text/plain; charset=UTF-8');
     header('Content-type: text/xml; charset=UTF-8');
     echo '<' . '?' . 'xml version="1.0" encoding="UTF-8"' . '?' . '>' . "\n";
     echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">' . "\n";
     echo " <channel>\n";
     echo "  <atom:link href=\"" . htmlspecialchars($this->baseUrl . '/?action=feed', ENT_QUOTES) . "\" rel=\"self\" type=\"application/rss+xml\" />\n";
     echo "  <title>Changelog for &#x201c;{$this->likiTitle}&#x201d;</title>\n";
     echo "  <link>" . htmlspecialchars($this->baseUrl, ENT_QUOTES) . "</link>\n";
     echo "  <description>An automatic log of changes to the Liki.</description>\n";
     //echo "  <language>$lang</language>\n";
     //echo "  <copyright>$copyright</copyright>\n";
     //echo "  <pubDate>$pubDate</pubDate>\n";
     if ($log = $this->backend->getDetailedChangeLog(30)) {
         foreach ($log as $e) {
             $changelog = "<div style='font-family:Monaco,monospace; line-height: 12px; font-size: 10px; white-space:wrap; color:black;'>";
             $linesModified = 0;
             $linesDeleted = 0;
             $linesInserted = 0;
             $ld = diff(explode("\n", $e['content_before']), explode("\n", $e['content_after']));
             $linediff = array();
             foreach ($ld as $n => $cs) {
                 if (is_array($cs) && count($cs['d']) == 0 && count($cs['i']) == 0) {
                     // ignore
                     continue;
                 }
                 $linediff[$n] = $cs;
             }
             foreach ($linediff as $number => $changeset) {
                 // this line is unchanged, but a changeset is nearby
                 if (!is_array($changeset) && $changeset !== false) {
                     for ($i = -5; $i < 6; $i++) {
                         if ($i == 0) {
                             continue;
                         }
                         if (array_key_exists($number + $i, $linediff) && is_array($linediff[$number + $i])) {
                             $changelog .= "<p style='margin:0;padding-left:12px;color:#555;'>" . htmlspecialchars($this->trimDown($changeset, 70)) . "&nbsp;</p>\n";
                             // mark it, so we don't output it two times
                             $changeset = false;
                         }
                     }
                     continue;
                 }
                 $mod = min(count($changeset['d']), count($changeset['i']));
                 $linesDeleted += count($changeset['d']) - $mod;
                 $linesInserted += count($changeset['i']) - $mod;
                 $linesModified += $mod;
                 // only some lines added or removed
                 if (count($changeset['d']) == 0 || count($changeset['i']) == 0) {
                     foreach ($changeset['d'] as $line) {
                         $changelog .= "<p style='margin:0;padding-left:10px;border-left:2px solid red;color:#aaa;'>" . htmlspecialchars($line) . "&nbsp;</p>\n";
                     }
                     foreach ($changeset['i'] as $line) {
                         $changelog .= "<p style='margin:0;padding-left:10px;border-left:2px solid green;color:black;'>" . htmlspecialchars($line) . "&nbsp;</p>\n";
                     }
                     continue;
                 }
                 // more complex stuff for changed lines
                 $before = str_replace("\n", "&nbsp;<br />\n", htmlspecialchars(implode("\n", $changeset['d'])));
                 $after = str_replace("\n", "&nbsp;<br />\n", htmlspecialchars(implode("\n", $changeset['i'])));
                 $paragraph = "";
                 if ($splitAtSpaces) {
                     $before_array = explode(" ", $before);
                     $after_array = explode(" ", $after);
                     $splitChar = ' ';
                 } else {
                     $before_array = preg_split('//u', $before);
                     $after_array = preg_split('//u', $after);
                     $splitChar = '';
                 }
                 foreach (diff($before_array, $after_array) as $d) {
                     if (is_array($d)) {
                         $paragraph .= !empty($d['d']) ? "<span style='background-color:#fdd;color:#aaa;'>" . implode($splitChar, $d['d']) . "</span>" . $splitChar : '';
                         $paragraph .= !empty($d['i']) ? "<span style='background-color:#dfd;color:black;'>" . implode($splitChar, $d['i']) . "</span>" . $splitChar : '';
                     } else {
                         $paragraph .= $d . $splitChar;
                     }
                 }
                 $changelog .= "<p style='padding-left:10px;border-left:2px dotted #555;color:#555;'>{$paragraph}&nbsp;</p>\n";
             }
             if ($changelog) {
                 $changelog .= "</div>\n";
                 echo "  <item>\n";
                 echo "   <title>" . htmlspecialchars($e['name'] . " (~{$linesModified} -{$linesDeleted} +{$linesInserted})") . "</title>\n";
                 echo "   <description><![CDATA[{$changelog}]]></description>\n";
                 $author = encodeLongIP($e['remote_ip'], $dnscache);
                 //echo "   <author>" .htmlspecialchars($author). "</author>\n";
                 echo "   <dc:creator>" . htmlspecialchars($author) . "</dc:creator>\n";
                 echo "   <guid isPermaLink='true'>" . htmlspecialchars($this->baseUrl . '/permalink/' . $e['revision_id']) . "</guid>\n";
                 echo "   <link>" . htmlspecialchars($this->baseUrl . '/' . urlencode($e['name'])) . "</link>\n";
                 echo "   <pubDate>" . date("r", $e['timestamp']) . "</pubDate>\n";
                 echo "  </item>\n";
             }
             flush();
         }
     }
     echo ' </channel>' . "\n";
     echo '</rss>' . "\n";
     flush();
     $tmpName = $this->dataDir . '/_DNSCACHE_' . md5(uniqid());
     if (file_put_contents($tmpName, serialize($dnscache)) !== FALSE) {
         rename($tmpName, $this->dataDir . '/_DNSCACHE_');
     }
 }
Exemple #30
0
 /**
  * Get history
  */
 public function getHistory()
 {
     $tbl_wiki = $this->tbl_wiki;
     $condition_session = $this->condition_session;
     $groupfilter = $this->groupfilter;
     $page = $this->page;
     $course_id = $this->course_id;
     $session_id = $this->session_id;
     $userId = api_get_user_id();
     if (!$_GET['title']) {
         self::setMessage(Display::display_error_message(get_lang("MustSelectPage"), false, true));
         return;
     }
     /* First, see the property visibility that is at the last register and
        therefore we should select descending order.
        But to give ownership to each record,
        this is no longer necessary except for the title. TODO: check this*/
     $sql = 'SELECT * FROM ' . $tbl_wiki . '
             WHERE
                 c_id = ' . $course_id . ' AND
                 reflink="' . Database::escape_string($page) . '" AND
                 ' . $groupfilter . $condition_session . '
             ORDER BY id DESC';
     $result = Database::query($sql);
     $KeyVisibility = null;
     $KeyAssignment = null;
     $KeyTitle = null;
     $KeyUserId = null;
     while ($row = Database::fetch_array($result)) {
         $KeyVisibility = $row['visibility'];
         $KeyAssignment = $row['assignment'];
         $KeyTitle = $row['title'];
         $KeyUserId = $row['user_id'];
     }
     $icon_assignment = null;
     if ($KeyAssignment == 1) {
         $icon_assignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'), '', ICON_SIZE_SMALL);
     } elseif ($KeyAssignment == 2) {
         $icon_assignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWorkExtra'), '', ICON_SIZE_SMALL);
     }
     // Second, show
     //if the page is hidden and is a job only sees its author and professor
     if ($KeyVisibility == 1 || api_is_allowed_to_edit(false, true) || api_is_platform_admin() || $KeyAssignment == 2 && $KeyVisibility == 0 && $userId == $KeyUserId) {
         // We show the complete history
         if (!isset($_POST['HistoryDifferences']) && !isset($_POST['HistoryDifferences2'])) {
             $sql = 'SELECT * FROM ' . $tbl_wiki . '
                     WHERE
                         c_id = ' . $course_id . ' AND
                         reflink="' . Database::escape_string($page) . '" AND
                         ' . $groupfilter . $condition_session . '
                     ORDER BY id DESC';
             $result = Database::query($sql);
             $title = $_GET['title'];
             $group_id = api_get_group_id();
             echo '<div id="wikititle">';
             echo $icon_assignment . '&nbsp;&nbsp;&nbsp;' . api_htmlentities($KeyTitle);
             echo '</div>';
             echo '<form id="differences" method="POST" action="index.php?' . api_get_cidreq() . '&action=history&title=' . api_htmlentities(urlencode($title)) . '&session_id=' . api_htmlentities($session_id) . '&group_id=' . api_htmlentities($group_id) . '">';
             echo '<ul style="list-style-type: none;">';
             echo '<br/>';
             echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">' . get_lang('ShowDifferences') . ' ' . get_lang('LinesDiff') . '</button>';
             echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">' . get_lang('ShowDifferences') . ' ' . get_lang('WordsDiff') . '</button>';
             echo '<br/><br/>';
             $counter = 0;
             $total_versions = Database::num_rows($result);
             while ($row = Database::fetch_array($result)) {
                 $userinfo = api_get_user_info($row['user_id']);
                 $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES);
                 echo '<li style="margin-bottom: 5px;">';
                 $counter == 0 ? $oldstyle = 'style="visibility: hidden;"' : ($oldstyle = '');
                 $counter == 0 ? $newchecked = ' checked' : ($newchecked = '');
                 $counter == $total_versions - 1 ? $newstyle = 'style="visibility: hidden;"' : ($newstyle = '');
                 $counter == 1 ? $oldchecked = ' checked' : ($oldchecked = '');
                 echo '<input name="old" value="' . $row['id'] . '" type="radio" ' . $oldstyle . ' ' . $oldchecked . '/> ';
                 echo '<input name="new" value="' . $row['id'] . '" type="radio" ' . $newstyle . ' ' . $newchecked . '/> ';
                 echo '<a href="' . api_get_self() . '?action=showpage&title=' . api_htmlentities(urlencode($page)) . '&view=' . $row['id'] . '">';
                 echo '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&action=showpage&title=' . api_htmlentities(urlencode($page)) . '&view=' . $row['id'] . '">';
                 echo api_get_local_time($row['dtime'], null, date_default_timezone_get());
                 echo '</a>';
                 echo ' (' . get_lang('Version') . ' ' . $row['version'] . ')';
                 echo ' ' . get_lang('By') . ' ';
                 if ($row['user_id'] != 0) {
                     echo UserManager::getUserProfileLink($userinfo);
                 } else {
                     echo get_lang('Anonymous') . ' (' . api_htmlentities($row['user_ip']) . ')';
                 }
                 echo ' ( ' . get_lang('Progress') . ': ' . api_htmlentities($row['progress']) . '%, ';
                 $comment = $row['comment'];
                 if (!empty($comment)) {
                     echo get_lang('Comments') . ': ' . api_htmlentities(api_substr($row['comment'], 0, 100));
                     if (api_strlen($row['comment']) > 100) {
                         echo '... ';
                     }
                 } else {
                     echo get_lang('Comments') . ':  ---';
                 }
                 echo ' ) </li>';
                 $counter++;
             }
             //end while
             echo '<br/>';
             echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">' . get_lang('ShowDifferences') . ' ' . get_lang('LinesDiff') . '</button>';
             echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">' . get_lang('ShowDifferences') . ' ' . get_lang('WordsDiff') . '</button>';
             echo '</ul></form>';
         } else {
             // We show the differences between two versions
             $version_old = array();
             if (isset($_POST['old'])) {
                 $sql_old = "SELECT * FROM {$tbl_wiki}\n                                WHERE c_id = {$course_id} AND id='" . Database::escape_string($_POST['old']) . "'";
                 $result_old = Database::query($sql_old);
                 $version_old = Database::fetch_array($result_old);
             }
             $sql_new = "SELECT * FROM {$tbl_wiki}\n                            WHERE c_id = {$course_id} AND id='" . Database::escape_string($_POST['new']) . "'";
             $result_new = Database::query($sql_new);
             $version_new = Database::fetch_array($result_new);
             $oldTime = isset($version_old['dtime']) ? $version_old['dtime'] : null;
             $oldContent = isset($version_old['content']) ? $version_old['content'] : null;
             if (isset($_POST['HistoryDifferences'])) {
                 include 'diff.inc.php';
                 //title
                 echo '<div id="wikititle">' . api_htmlentities($version_new['title']) . '
                         <font size="-2"><i>(' . get_lang('DifferencesNew') . '</i>
                         <font style="background-color:#aaaaaa">' . $version_new['dtime'] . '</font>
                         <i>' . get_lang('DifferencesOld') . '</i>
                         <font style="background-color:#aaaaaa">' . $oldTime . '</font>
             ) ' . get_lang('Legend') . ':  <span class="diffAdded" >' . get_lang('WikiDiffAddedLine') . '</span>
             <span class="diffDeleted" >' . get_lang('WikiDiffDeletedLine') . '</span> <span class="diffMoved">' . get_lang('WikiDiffMovedLine') . '</span></font>
             </div>';
             }
             if (isset($_POST['HistoryDifferences2'])) {
                 //title
                 echo '<div id="wikititle">' . api_htmlentities($version_new['title']) . '
                     <font size="-2"><i>(' . get_lang('DifferencesNew') . '</i> <font style="background-color:#aaaaaa">' . $version_new['dtime'] . '</font>
                     <i>' . get_lang('DifferencesOld') . '</i> <font style="background-color:#aaaaaa">' . $oldTime . '</font>)
                     ' . get_lang('Legend') . ':  <span class="diffAddedTex" >' . get_lang('WikiDiffAddedTex') . '</span>
                     <span class="diffDeletedTex" >' . get_lang('WikiDiffDeletedTex') . '</span></font></div>';
             }
             if (isset($_POST['HistoryDifferences'])) {
                 echo '<table>' . diff($oldContent, $version_new['content'], true, 'format_table_line') . '</table>';
                 // format_line mode is better for words
                 echo '<br />';
                 echo '<strong>' . get_lang('Legend') . '</strong><div class="diff">' . "\n";
                 echo '<table><tr>';
                 echo '<td>';
                 echo '</td><td>';
                 echo '<span class="diffEqual" >' . get_lang('WikiDiffUnchangedLine') . '</span><br />';
                 echo '<span class="diffAdded" >' . get_lang('WikiDiffAddedLine') . '</span><br />';
                 echo '<span class="diffDeleted" >' . get_lang('WikiDiffDeletedLine') . '</span><br />';
                 echo '<span class="diffMoved" >' . get_lang('WikiDiffMovedLine') . '</span><br />';
                 echo '</td>';
                 echo '</tr></table>';
             }
             if (isset($_POST['HistoryDifferences2'])) {
                 $lines1 = array(strip_tags($oldContent));
                 //without <> tags
                 $lines2 = array(strip_tags($version_new['content']));
                 //without <> tags
                 $diff = new Text_Diff($lines1, $lines2);
                 $renderer = new Text_Diff_Renderer_inline();
                 echo '<style>del{background:#fcc}ins{background:#cfc}</style>' . $renderer->render($diff);
                 // Code inline
                 echo '<br />';
                 echo '<strong>' . get_lang('Legend') . '</strong><div class="diff">' . "\n";
                 echo '<table><tr>';
                 echo '<td>';
                 echo '</td><td>';
                 echo '<span class="diffAddedTex" >' . get_lang('WikiDiffAddedTex') . '</span><br />';
                 echo '<span class="diffDeletedTex" >' . get_lang('WikiDiffDeletedTex') . '</span><br />';
                 echo '</td>';
                 echo '</tr></table>';
             }
         }
     }
 }