コード例 #1
0
 /**
  * Gets all versions of a note
  *
  * @NoAdminRequired
  * @NoCSRFRequired
  * @CORS
  *
  * @return array
  */
 public function getAllVersions()
 {
     $source = $this->request->getParam("file_name", "");
     list($uid, $filename) = Storage::getUidAndFilename($source);
     $versions = Storage::getVersions($uid, $filename, $source);
     $versionsResults = array();
     if (is_array($versions) && count($versions) > 0) {
         require_once __DIR__ . '/../3rdparty/finediff/finediff.php';
         $users_view = new View('/' . $uid);
         $currentData = $users_view->file_get_contents('files/' . $filename);
         //            $previousData = $currentData;
         //            $versions = array_reverse( $versions, true );
         foreach ($versions as $versionData) {
             // get timestamp of version
             $mtime = (int) $versionData["version"];
             // get filename of note version
             $versionFileName = 'files_versions/' . $filename . '.v' . $mtime;
             // load the data from the file
             $data = $users_view->file_get_contents($versionFileName);
             // calculate diff between versions
             $opcodes = \FineDiff::getDiffOpcodes($currentData, $data);
             $html = \FineDiff::renderDiffToHTMLFromOpcodes($currentData, $opcodes);
             $versionsResults[] = array("timestamp" => $mtime, "humanReadableTimestamp" => $versionData["humanReadableTimestamp"], "diffHtml" => $html, "data" => $data);
             //                $previousData = $data;
         }
         //            $versionsResults = array_reverse( $versionsResults );
     }
     return array("file_name" => $source, "versions" => $versionsResults);
 }
コード例 #2
0
 public static function compareLicense($fromText, $toText)
 {
     $from_text = mb_convert_encoding($fromText, 'HTML-ENTITIES', 'UTF-8');
     $to_text = mb_convert_encoding($toText, 'HTML-ENTITIES', 'UTF-8');
     $granularity = FineDiff::$wordGranularity;
     $diff_opcodes = FineDiff::getDiffOpcodes($from_text, $to_text, $granularity);
     self::$diffLength = strlen($diff_opcodes);
     $rendered_diff = FineDiff::renderDiffToHTMLFromOpcodes($from_text, $diff_opcodes);
     return $rendered_diff;
 }
コード例 #3
0
/**
 * Smarty string diff plugin
 *
 * Type:     insert<br>
 * Name:     string_diff<br>
 * Date:     August 26, 2014
 * Purpose:  Creates an HTML diff of two text strings
 * Input:    two strings
 * Example:  {insert name="string_diff" from_text="foo" to_text="bar"}
 * @license http://www.gnu.org/licenses/gpl.html
 * @copyright 2009-2015 Matt Jacobs
 * @author   Matt Jacobs
 * @version 1.0
 */
function smarty_insert_string_diff($params, &$smarty)
{
    if (empty($params['from_text']) && empty($params['to_text'])) {
        trigger_error("Missing 'from_text' and 'to_text' paramaters");
        return;
    } elseif (empty($params['from_text'])) {
        return "<ins>" . $params['to_text'] . "</ins>";
    } elseif (empty($params['to_text'])) {
        return "<del>" . $params['from_text'] . "</del>";
    }
    require_once THINKUP_WEBAPP_PATH . '_lib/extlib/FineDiff/finediff.php';
    $opcodes = FineDiff::getDiffOpcodes($params['from_text'], $params['to_text'], $granularityStack = FineDiff::$wordGranularity);
    $diff = FineDiff::renderDiffToHTMLFromOpcodes($params['from_text'], $opcodes);
    if (isset($params['is_email']) && $params['is_email']) {
        $diff = str_replace('<ins', '<ins style="background: #e4f9e8; text-decoration: none;"', $diff);
        $diff = str_replace('<del', '<del style="background: #f8d9dd; color: #dc4154;"', $diff);
    }
    return $diff;
}
コード例 #4
0
ファイル: run.php プロジェクト: Flesh192/magento
/**
 * Prints a test result
 */
function test($file, $minExpected, $skip)
{
    global $cssmin;
    if (!empty($skip) && in_array(basename($file), $skip)) {
        p("INFO: CSSmin: skipping " . basename($file), 'info');
        return;
    }
    $src = file_get_contents($file);
    $minOutput = $cssmin->run($src);
    $passed = assertTrue(strcmp($minOutput, $minExpected) === 0, 'CSSmin: ' . basename(dirname($file)) . '/' . basename($file));
    if (!$passed) {
        p("---Output: " . countBytes($minOutput) . " bytes", '');
        $opcodes = FineDiff::getDiffOpcodes($minExpected, $minOutput);
        code(FineDiff::renderDiffToHTMLFromOpcodes($minExpected, $opcodes));
        p("---Expected: " . countBytes($minExpected) . " bytes", '');
        code($minExpected);
        p("---Source: " . countBytes($src) . " bytes", '');
        code($src);
    }
}
コード例 #5
0
ファイル: Pastes.php プロジェクト: LanceSandino/Stikked
 function getPaste($seg = 2, $replies = false, $diff = false)
 {
     if ($this->uri->segment($seg) == '') {
         redirect('');
     } else {
         $pid = $this->uri->segment($seg);
         $data['script'] = 'jquery.js';
     }
     $this->load->library('process');
     $this->db->where('pid', $pid);
     $query = $this->db->get('pastes');
     foreach ($query->result_array() as $row) {
         $data['title'] = $row['title'];
         $data['pid'] = $row['pid'];
         $data['name'] = $row['name'];
         $data['lang_code'] = $row['lang'];
         $data['lang'] = $this->languages->code_to_description($row['lang']);
         $data['paste'] = $this->process->syntax(htmlspecialchars_decode($row['raw']), $row['lang']);
         $data['created'] = $row['created'];
         $data['private'] = $row['private'];
         $data['expire'] = $row['expire'];
         $data['toexpire'] = $row['toexpire'];
         $data['url'] = $this->_get_url($row['pid']);
         $data['raw'] = $row['raw'];
         $data['hits'] = $row['hits'];
         $data['hits_updated'] = $row['hits_updated'];
         $data['snipurl'] = $row['snipurl'];
         $inreply = $row['replyto'];
     }
     if ($inreply) {
         $this->db->select('name, title');
         $this->db->where('pid', $inreply);
         $query = $this->db->get('pastes');
         if ($query->num_rows() > 0) {
             foreach ($query->result_array() as $row) {
                 $data['inreply']['title'] = $row['title'];
                 $data['inreply']['name'] = $row['name'];
                 $data['inreply']['url'] = site_url('view/' . $inreply);
             }
         } else {
             $data['inreply'] = false;
         }
         if ($diff) {
             $this->db->select('raw');
             $this->db->where('pid', $inreply);
             $query = $this->db->get('pastes');
             if ($query->num_rows() > 0) {
                 foreach ($query->result_array() as $row) {
                     //diff
                     //yes, I'm aware, two times htmlspecialchars_decode(). Needs to be, since it's saved that way in the DB from the original stikked author ages ago ;)
                     include_once APPPATH . '/libraries/finediff.php';
                     $from_text = htmlspecialchars_decode(utf8_decode($row['raw']));
                     $to_text = htmlspecialchars_decode(utf8_decode($data['raw']));
                     $opcodes = FineDiff::getDiffOpcodes($from_text, $to_text, FineDiff::$wordGranularity);
                     $to_text = FineDiff::renderToTextFromOpcodes($from_text, $opcodes);
                     $data['paste'] = htmlspecialchars_decode($this->_format_diff(nl2br(FineDiff::renderDiffToHTMLFromOpcodes($from_text, $opcodes))));
                 }
             } else {
                 $data['inreply'] = false;
             }
         }
     }
     if ($replies) {
         $amount = $this->config->item('per_page');
         $page = $this->uri->segment(3) ? $this->uri->segment(3) : 0;
         $this->db->select('title, name, created, pid, lang');
         $this->db->where('replyto', $data['pid']);
         $this->db->order_by('id', 'desc');
         $this->db->limit($amount);
         $query = $this->db->get('pastes', $amount, $page);
         if ($query->num_rows() > 0) {
             $n = 0;
             foreach ($query->result_array() as $row) {
                 $data['replies'][$n]['title'] = $row['title'];
                 $data['replies'][$n]['name'] = $row['name'];
                 $data['replies'][$n]['lang'] = $row['lang'];
                 $data['replies'][$n]['created'] = $row['created'];
                 $data['replies'][$n]['pid'] = $row['pid'];
                 $n++;
             }
             $config['base_url'] = site_url('view/' . $data['pid']);
             $config['total_rows'] = $this->countReplies($data['pid']);
             $config['per_page'] = $amount;
             $config['num_links'] = 9;
             $config['full_tag_open'] = '<div class="pages">';
             $config['full_tag_close'] = '</div>';
             $config['uri_segment'] = 3;
             $this->load->library('pagination');
             $this->pagination->initialize($config);
             $data['pages'] = $this->pagination->create_links();
         } else {
             $replies = false;
         }
     }
     /*
      * Hits
      * First check if record already exists.  If it does, do not insert.
      * INSERT IGNORE INTO does not work for postgres.
      */
     $this->db->select('count(paste_id) as count');
     $this->db->where('paste_id', $pid);
     $this->db->where('ip_address', $this->input->ip_address());
     $query = $this->db->get('trending');
     $hits_count = $query->result_array();
     $hits_count = $hits_count[0]['count'];
     if ($hits_count == 0) {
         $this->db->insert('trending', array('paste_id' => $pid, 'ip_address' => $this->input->ip_address(), 'created' => time()));
     }
     //update hits counter every minute
     if (time() > 60 + $data['hits_updated']) {
         $this->calculate_hits($pid, $data['hits']);
     }
     //burn if necessary
     if ($data['expire'] == 0 and $data['toexpire'] == 1) {
         $this->delete_paste($data['pid']);
     }
     return $data;
 }
コード例 #6
0
ファイル: action.php プロジェクト: PtitSniper/plume
<?php

require_once 'common.php';
$jsonResponse = array();
$jsonResponse['success'] = false;
//Actions
switch ($action) {
    case 'viewdiff':
        echo '<pre>';
        $content = stripslashes(file_get_contents(MD_ROOT . $_['page'] . MD_EXTENSION));
        $diff_opcodes = file_get_contents($_['version']);
        $from_text = FineDiff::renderToTextFromOpcodes($content, $diff_opcodes);
        $diff_opcodes = FineDiff::getDiffOpcodes($from_text, $content);
        echo FineDiff::renderDiffToHTMLFromOpcodes($from_text, $diff_opcodes) . '</pre>';
        break;
    case 'edit':
        if ($myUser != false) {
            $emptyMessage = $page == MD_MENU ? MD_MENU_DEFAUT_CONTENT : 'Le contenu de  **' . $page . '** est vide :p';
            $content = file_exists($pagePath) ? file_get_contents($pagePath) : $emptyMessage;
            $content = stripslashes($content);
            $archives = glob(ARCHIVES_ROOT . $page . '/*');
            if (is_array($archives) && count($archives) > 0) {
                foreach ($archives as $archive) {
                    list($d, $m, $y, $h, $i, $v, $a) = explode('-', basename($archive));
                    $jsonResponse['versions'][] = array('date' => $d . '/' . $m . '/' . $y . ' ' . $h . 'h' . $i, 'author' => $a, 'version' => $v, 'link' => $archive);
                }
                usort($jsonResponse['versions'], 'sortVersions');
            }
            if (isset($_['version'])) {
                foreach ($jsonResponse['versions'] as $version) {
                    if ($version['version'] == $_['version']) {
コード例 #7
0
ファイル: settings.php プロジェクト: nuxodin/shwups-cms-v4
            continue;
        }
        if (!isset($both['remote'])) {
            'fehlt remote';
            continue;
        }
        $remote = file_get_contents($both['remote']);
        $local = file_get_contents($both['local']);
        if ($remote === $local) {
            echo '<span style="color:green">ok!</span>';
            continue;
        } else {
            echo '<span style="color:red">different!</span>';
            require_once __DIR__ . '/../lib/finediff.php';
            $opcodes = \FineDiff::getDiffOpcodes($remote, $local);
            // store opcodes for later use...
            //Later, $to_text can be re-created from $from_text using $opcodes as follow:
            echo '<pre style="box-shadow:0 0 5px rgba(0,0,0,0.7); padding:10px">';
            echo \FineDiff::renderDiffToHTMLFromOpcodes($remote, $opcodes);
            echo '</pre>';
            echo '<style>' . 'del { color: red;   background: #fdd; text-decoration: none; }' . 'ins { color: green; background: #dfd; text-decoration: none; }' . '</style>';
        }
    }
    ?>
		</div>
	<?php 
}
?>


</div><?php 
コード例 #8
0
 /**
  * @param      $from_text
  * @param      $to_text
  *
  * @param bool $charDiff
  *
  * @return array
  */
 function mb_renderDiffHtml($from_text, $to_text, $charDiff = null)
 {
     //if ($from_text === 'Lang' && $to_text === 'Language') xdebug_break();
     if ($from_text == $to_text) {
         return $to_text;
     }
     $removeSpaces = false;
     if ($charDiff === null) {
         $charDiff = mb_strtolower($from_text) === mb_strtolower($to_text) || abs(mb_strlen($from_text) - mb_strlen($to_text)) <= 2 || $from_text && $to_text && (strpos($from_text, $to_text) !== false || $to_text && strpos($to_text, $from_text) !== false);
     }
     if ($charDiff) {
         //use word diff but space all entities so that we get char diff
         $removeSpaces = true;
         $from_text = mb_chunk_split($from_text, 1, ' ');
         $to_text = mb_chunk_split($to_text, 1, ' ');
     }
     $from_text = mb_convert_encoding($from_text, 'HTML-ENTITIES', 'UTF-8');
     $to_text = mb_convert_encoding($to_text, 'HTML-ENTITIES', 'UTF-8');
     $opcodes = \FineDiff::getDiffOpcodes($from_text, $to_text, \FineDiff::$wordGranularity);
     $diff = \FineDiff::renderDiffToHTMLFromOpcodes($from_text, $opcodes);
     $diff = mb_convert_encoding($diff, 'UTF-8', 'HTML-ENTITIES');
     if ($removeSpaces) {
         $diff = mb_unsplit($diff, ' ');
     }
     return $diff;
 }
コード例 #9
0
ファイル: admin.php プロジェクト: rbgvictoria/vicflora
 private function compareProfiles($from, $to, $granularity = 2)
 {
     require_once 'third_party/FineDiff.php';
     $granularityStacks = array(FineDiff::$paragraphGranularity, FineDiff::$sentenceGranularity, FineDiff::$wordGranularity, FineDiff::$characterGranularity);
     $diff_opcodes = FineDiff::getDiffOpcodes($from, $to, $granularityStacks[$granularity]);
     return FineDiff::renderDiffToHTMLFromOpcodes($from, $diff_opcodes);
 }
コード例 #10
0
}
$ttf_title = $ttf_label;
// let's output a page to the user
require_once "include_header.php";
// start counting revisions
$revnum = 0;
// grab the revisions
$sql = "SELECT ttf_revision.*, ttf_user.username " . "FROM ttf_revision, ttf_user " . "WHERE ttf_revision.author_id = ttf_user.user_id " . "      && type='{$type}' && ref_id='{$ref_id}' " . "ORDER BY date ASC";
if (!($result = mysql_query($sql))) {
    showerror();
}
while ($rev = mysql_fetch_array($result)) {
    $date = formatdate($rev["date"]);
    if (isset($lastrev)) {
        $opcodes = FineDiff::getDiffOpcodes(output($lastrev), output($rev["body"]), FineDiff::$wordGranularity);
        $revbody = FineDiff::renderDiffToHTMLFromOpcodes(output($lastrev), $opcodes);
        $lastrev = $rev["body"];
    } else {
        $revbody = $rev["body"];
        $lastrev = $rev["body"];
    }
    echo "            <div class=\"contenttitle_sm\">\n";
    echo "                rev {$revnum}, rev_id {$rev["rev_id"]} by\n";
    echo "                <a class=\"link\" href=\"profile.php?user_id={$rev["author_id"]}\">" . output($rev["username"]) . "</a>";
    if (!empty($rev["ip"])) {
        echo "                ({$rev["ip"]})\n";
    }
    echo "                <span title=\"{$date[1]}\">{$date[0]}</span>\n";
    echo "            </div>\n";
    echo "            <div class=\"contentbox_sm\">\n";
    echo nl2br($revbody) . "\n";
コード例 #11
0
ファイル: viewdiff.php プロジェクト: kwix/SimpleVers
                        $num_files -= 1;
                        if ($num_files < $cache_lo_water_mark) {
                            break;
                        }
                    }
                }
            }
            // save diff in cache
            $data_to_serialize = array('granularity' => $granularity, 'from_text' => $from_text, 'diff_opcodes' => $diff_opcodes, 'data_key' => $data_key);
            $serialized_data = serialize($data_to_serialize);
            @file_put_contents("./cache/{$filename}", gzcompress($serialized_data));
            @chmod("./cache/{$filename}", 0666);
        }
    }
}
$rendered_diff = FineDiff::renderDiffToHTMLFromOpcodes($from_text, $diff_opcodes);
$from_len = strlen($from_text);
$to_len = strlen($to_text);
?>
<div class="panecontainer" style="width:80%;text-align: left;">
    <p>Diff
        <span style="color:gray">
            (diff: <?php 
printf('%.3f', $exec_time);
?>
 seconds, diff len: <?php 
echo $diff_opcodes_len;
?>
 chars)
        </span>
        &emsp;/&emsp;Show
コード例 #12
0
ファイル: msg_hist_inc.php プロジェクト: BGmot/kitchen
                if ($row['content_flags'] & $content_nsfw) {
                    $nsfw .= '<span class="nsfw">NSFW</span>';
                }
                $subj = print_subject(encode_subject($row['subject']));
                if (extension_loaded('mbstring')) {
                    $content_to_compare = $row['compare_to'];
                    if (is_null($content_to_compare)) {
                        $content_to_compare = $row['msg_subject'];
                    }
                    $from_text = $subj;
                    // htmlentities($body, HTML_ENTITIES,'UTF-8');
                    $to_text = print_subject(encode_subject($content_to_compare));
                    $from_text = mb_convert_encoding($from_text, 'HTML-ENTITIES', 'UTF-8');
                    $to_text = mb_convert_encoding($to_text, 'HTML-ENTITIES', 'UTF-8');
                    $diff_opcodes = FineDiff::getDiffOpcodes($from_text, $to_text);
                    $subj = mb_convert_encoding(FineDiff::renderDiffToHTMLFromOpcodes($from_text, $diff_opcodes), 'UTF-8', 'HTML-ENTITIES');
                }
                $line = $icons . '<a id="' . $msg_id . '_' . $row['id'] . '" name="' . $msg_id . '_' . $row['id'] . '" target="bottom" href="' . $root_dir . $page_version . '?id=' . $msg_id . '&ver=' . $row['id'] . '">' . $subj . '</a> ' . $nsfw . ' ' . ' [' . $row['views'] . ' views] ' . $row['created'] . ' <b>' . $row['chars'] . '</b> bytes';
            }
            if (isset($version) && $version == $row['id']) {
                print '<font color="green">&gt;</font>';
            } else {
                print '<span style="opacity:0;">&gt;</span>';
            }
            print '<i><font color="gray">' . $line . '</font></i>';
            print '<br/>';
        }
        print "</div>";
    }
    mysql_free_result($result);
}
コード例 #13
0
 public function GET_page_compare($key, $left, $right)
 {
     $page = $this->getPage($key);
     $slug = $page->slug;
     if (!$slug) {
         // 존재하지 않는 문서이므로 생성 권장
         return redirect("/wiki/{$key}", 302);
     }
     if ($slug && $slug != $key) {
         // 이미 존재하는 문서인데 slug가 아니라 title로 들어왔다면 slug로 바꿔서 redirect 한다.
         // url 에 title 보다는 slug 를 권장하므로 영구적이동(301)
         return redirect("/wiki/{$slug}/compare/{$left}/{$right}", 301);
     }
     $l_page = WikiHistory::where('wiki_page_id', $page->id)->where('rev', $left)->first();
     $r_page = WikiHistory::where('wiki_page_id', $page->id)->where('rev', $right)->first();
     if (!$l_page || !$r_page) {
         // l 과 r 중 하나가 revision 이 없으므로 문서로 이동
         return redirect("/wiki/{$slug}", 302);
     }
     $this->setMetaTas($page);
     include "finediff.php";
     $l_text = mb_convert_encoding($l_page->content, 'HTML-ENTITIES', 'UTF-8');
     $r_text = mb_convert_encoding($r_page->content, 'HTML-ENTITIES', 'UTF-8');
     $opcodes = \FineDiff::getDiffOpcodes($l_text, $r_text, [\FineDiff::paragraphDelimiters, \FineDiff::sentenceDelimiters, \FineDiff::wordDelimiters, ';']);
     $rendered_diff = \FineDiff::renderDiffToHTMLFromOpcodes($l_text, $opcodes);
     $rendered_diff = mb_convert_encoding($rendered_diff, 'UTF-8', 'HTML-ENTITIES');
     $rendered_diff = str_replace('\\r\\n', '\\n', $rendered_diff);
     $rendered_diff = str_replace('\\r', '\\n', $rendered_diff);
     $rendered_diff = str_replace('\\n', '&nbsp;<br/>', $rendered_diff);
     return view('ncells::wiki.pages.wiki_compare', ['page' => $page, 'rendered_diff' => $rendered_diff]);
 }
コード例 #14
0
ファイル: content.php プロジェクト: rjon76/netspotapp
 /**
  * function update page las modify time
  * @author garbagecat
  * @version 21.11.2014
  */
 public function setModify($action = 'unknown', $data = null)
 {
     $auth = Zend_Auth::getInstance();
     $identity = $auth->getIdentity();
     $login = $identity->u_login;
     $rows = array('pl_date' => time(), 'pl_page_id' => $this->pageId, 'pl_author' => $login, 'pl_action' => $action, 'pl_text' => '');
     if ($this->testFields($rows, 'pages_logs')) {
         //$fs = "<p align=\"left\"><a href=\"/content/edit/id/{$this->pageId}/#fs%?%\" target=\"_blank\"><em>go if there</em><a/></p> ";
         $fs = "<p align=\"left\"><a class=\"log-link\" href=\"/content/edit/id/{$this->pageId}/#fs%d\" target=\"_blank\" title=\"go to the object changes, if it exists\">. . .<a/></p> ";
         $icon = '<img class="log-icon" src="%s" width="16" alt="%s"/> ';
         switch ($action) {
             case "addBlock":
                 $text = '';
                 $select = $this->siteDbAdapter->select();
                 $select->from('blocks', array('b_name'));
                 $select->where('b_id = ?', $data['blockId']);
                 $select->limit(1);
                 $result = $this->siteDbAdapter->fetchRow($select->__toString());
                 $text = $result['b_name'];
                 $icon = sprintf($icon, '/images/add2.png', 'added block');
                 $rows['pl_text'] = "{$icon} Block \"{$text}\" was added";
                 $result = $this->siteDbAdapter->insert('pages_logs', $rows);
                 break;
             case "deleteBlock":
                 $text = ' ';
                 foreach ($data['bpIds'] as $bp) {
                     if ($this->content['content'][$bp]['bp_id'] == $bpid) {
                         $text .= '"' . $this->content['content'][$bp]['b_name'] . ' ID - ' . $this->content['content'][$bp]['bp_order'] . '", ';
                     }
                 }
                 $text = substr($text, 0, -2);
                 $icon = sprintf($icon, '/images/delete.png', 'delete block');
                 $rows['pl_text'] = "{$icon} Block {$text} was delete";
                 $result = $this->siteDbAdapter->insert('pages_logs', $rows);
                 break;
             case "addBlockField":
                 //$this->setModify('addBlockField', $data = array('bpId'=>$b2pId,'fieldId'=>$fieldId));
                 $text = '';
                 $bpId = $data['bpId'];
                 $text .= '"' . $this->content['content'][$bpId]['b_name'] . 'ID - ' . $this->content['content'][$bpId]['bp_order'] . '"';
                 $select = $this->siteDbAdapter->select();
                 $select->from('blocks_fields', array('bf_name'));
                 $select->where('bf_id = ?', $data['fieldId']);
                 $select->limit(1);
                 $result = $this->siteDbAdapter->fetchRow($select->__toString());
                 $text .= ' &gt; "' . $result['bf_name'] . '"';
                 //$fs = str_replace('%?%', $this->content['content'][$bpId]['bp_id'],$fs);
                 $fs = sprintf($fs, $this->content['content'][$bpId]['bp_id']);
                 $icon = sprintf($icon, '/images/add.png', 'added field');
                 $rows['pl_text'] = "{$icon} Field {$text} was added" . $fs;
                 $result = $this->siteDbAdapter->insert('pages_logs', $rows);
                 break;
             case "deleteBlockField":
                 $text = '';
                 foreach ($this->content['content'] as $it) {
                     foreach ($it['fields'] as $item) {
                         if ($item['bd_id'] == $data['bdId']) {
                             $text .= '"' . $item['b_name'] . ' ID - ' . $item['bp_order'] . '" &gt; "' . $item['bf_name'] . '"';
                             $fs = sprintf($fs, $item['bp_id']);
                             //$fs = str_replace('%?%', $item['bp_id'],$fs);
                         }
                     }
                 }
                 $icon = sprintf($icon, '/images/delete.png', 'delete field');
                 $rows['pl_text'] = "{$icon} Field {$text} was delete" . $fs;
                 $result = $this->siteDbAdapter->insert('pages_logs', $rows);
                 break;
             case "hiddenBlock":
                 $text = '';
                 if (isset($this->content['content'][$data['bpId']])) {
                     $text = '"' . $this->content['content'][$data['bpId']]['b_name'] . ' ID - ' . $this->content['content'][$data['bpId']]['bp_order'] . '", ';
                     $fs = sprintf($fs, $this->content['content'][$data['bpId']]['bp_id']);
                     //$fs = str_replace('%?%', $this->content['content'][$data['bpId']]['bp_id'],$fs);
                 }
                 $icon = sprintf($icon, '/images/visible.png', 'displayed');
                 $rows['pl_text'] = "{$icon} Block {$text} was " . ($data['type'] ? 'hidden' : 'visible') . $fs;
                 $result = $this->siteDbAdapter->insert('pages_logs', $rows);
                 break;
             case "hiddenField":
                 $text = '';
                 foreach ($this->content['content'] as $it) {
                     foreach ($it['fields'] as $item) {
                         if ($item['bd_id'] == $data['bdid']) {
                             $text .= '"' . $item['b_name'] . ' ID - ' . $item['bp_order'] . '" &gt; "' . $item['bf_name'] . '"';
                             $fs = sprintf($fs, $item['bp_id']);
                             //$fs = str_replace('%?%', $item['bp_id'],$fs);
                         }
                     }
                 }
                 $icon = sprintf($icon, '/images/visible.png', 'displayed');
                 $rows['pl_text'] = "{$icon} Field {$text} was " . ($data['type'] ? 'hidden' : 'visible') . $fs;
                 $result = $this->siteDbAdapter->insert('pages_logs', $rows);
                 break;
             case "editBlockField":
                 $text = '';
                 $different = false;
                 $select = $this->siteDbAdapter->select();
                 $select->from('blocks_data', array('bd_value', 'bd_field_id'));
                 $select->joinLeft('blocks_fields', 'bf_id = bd_field_id', array('bf_type'));
                 $select->where('bd_id = ?', $data['bdId']);
                 $select->limit(1);
                 $row = $this->siteDbAdapter->fetchRow($select->__toString());
                 $old = $row['bd_value'];
                 $new = $data['text'];
                 $field_type = $row['bf_type'];
                 //$diff = FineDiff::getDiffOpcodes($old, $new);
                 //$diff = FineDiff::renderToTextFromOpcodes($old, $diff);
                 if ($field_type == "L") {
                     $old = implode(' ', unserialize($old));
                     $new = implode(' ', unserialize($new));
                 } elseif ($field_type == "A" || $field_type == "I" || $field_type == "J" || $field_type == "W") {
                     $old = self::multi_implode(' ', unserialize($old));
                     $new = self::multi_implode(' ', unserialize($new));
                 }
                 if ($old != $new) {
                     $different = true;
                 }
                 $diff = FineDiff::getDiffOpcodes($old, $new, 3);
                 $diffHTML = FineDiff::renderDiffToHTMLFromOpcodes($old, $diff);
                 //$diffHTML = FineDiff::renderToTextFromOpcodes($old, $diff);
                 foreach ($this->content as $item) {
                     if ($item['bd_id'] == $data['bdId']) {
                         $text = '"' . $item['b_name'] . '" ';
                     }
                 }
                 foreach ($this->content['content'] as $it) {
                     foreach ($it['fields'] as $item) {
                         if ($item['bd_id'] == $data['bdId']) {
                             $fs = sprintf($fs, $item['bp_id']);
                             //$fs = str_replace('%?%', $item['bp_id'],$fs);
                             $old = $item['bd_value'];
                             $text .= '"' . $item['b_name'] . ' ID - ' . $item['bp_order'] . '"' . '&gt; "' . $item['bf_name'] . '(' . $field_type . ')' . '"';
                         }
                     }
                 }
                 if (strlen($new) > 1000) {
                     if (!empty($old)) {
                         $diffs = htmlentities('<br/><br/><del>' . self::snippet($old, 1000) . "</del><br/>" . ' ' . self::snippet($new, 1000));
                     } else {
                         $diffs = htmlentities('<br/>' . self::snippet($new, 1000));
                     }
                     $diffs .= '<br/><em>(see last 1000 characters)</em>';
                 } else {
                     if (!empty($old)) {
                         $diffs = htmlentities('<br/>' . $diffHTML);
                     } else {
                         $diffs = htmlentities('<br/>' . $new);
                     }
                 }
                 if (!empty($old) && $diffHTML != $old && $different) {
                     $icon = sprintf($icon, '/images/edit.png', 'edit');
                     $rows['pl_text'] = "{$icon} {$text} {$diffs}" . $fs;
                     $result = $this->siteDbAdapter->insert('pages_logs', $rows);
                 }
                 break;
         }
     }
 }
コード例 #15
0
ファイル: core.php プロジェクト: orhongool/board
/**
 * Get difference between current and previous version
 *
 * @param string $from_text Original text
 * @param string $to_text   Changed text
 *
 * @return difference
 */
function getRevisiondifference($from_text, $to_text)
{
    // limit input
    $from_text = substr($from_text, 0, 1024 * 100);
    $to_text = substr($to_text, 0, 1024 * 100);
    // ensure input is suitable for diff
    $from_text = mb_convert_encoding($from_text, 'HTML-ENTITIES', 'UTF-8');
    $to_text = mb_convert_encoding($to_text, 'HTML-ENTITIES', 'UTF-8');
    $granularity = 2;
    // 0: Paragraph/lines, 1: Sentence, 2: Word, 3: Character
    $granularityStacks = array(FineDiff::$paragraphGranularity, FineDiff::$sentenceGranularity, FineDiff::$wordGranularity, FineDiff::$characterGranularity);
    $diff_opcodes = FineDiff::getDiffOpcodes($from_text, $to_text, $granularityStacks[$granularity]);
    $difference = FineDiff::renderDiffToHTMLFromOpcodes($from_text, $diff_opcodes);
    return $difference;
}
コード例 #16
0
ファイル: ver_inc.php プロジェクト: BGmot/kitchen
            $row = mysql_fetch_assoc($result) or die('error to fetch parent row');
            $proceeded = false;
            $parent_author = htmlentities($row['username'], HTML_ENTITIES, 'UTF-8');
            $parent_date = $row['created'];
            if ($row['status'] == 2) {
                $in_response = 'In response to: <I><font color="gray"><del>This message has been deleted</del></font></I>  by <b>' . $parent_author . '</b>' . ', ' . $parent_date . '<br> ';
            } else {
                $parent_subject = htmlentities(translit($row['subject'], $proceeded), HTML_ENTITIES, 'UTF-8');
                $in_response = 'In response to: <a href="' . $root_dir . $page_msg . '?id=' . $parent . '">' . $parent_subject . '</a> by <b>' . $parent_author . '</b>' . ', ' . $parent_date . '<br> ';
            }
        }
    }
} else {
    die('No such message');
}
mysql_free_result($result);
notify_about_new_pm($user_id, $last_pm_check_time, "bottom");
$modified = null;
$trans_body = $msgbody;
if (extension_loaded('mbstring')) {
    include 'finediff.php';
    $from_text = $body;
    $to_text = $content_to_compare;
    $diff_opcodes = FineDiff::getDiffOpcodes($from_text, $to_text, FineDiff::$characterGranularity);
    $trans_body = nl2br(FineDiff::renderDiffToHTMLFromOpcodes($from_text, $diff_opcodes));
}
require_once 'msg_form_inc.php';
?>


コード例 #17
0
ファイル: core.php プロジェクト: espantosdarren/board
/**
 * Get difference between current and previous version
 *
 * @param string $from_text Original text
 * @param string $to_text   Changed text
 *
 * @return difference
 */
function getRevisiondifference($from_text, $to_text)
{
    // limit input
    $from_text = substr($from_text, 0, 1024 * 100);
    $to_text = substr($to_text, 0, 1024 * 100);
    $granularity = 2;
    // 0: Paragraph/lines, 1: Sentence, 2: Word, 3: Character
    $granularityStacks = array(FineDiff::$paragraphGranularity, FineDiff::$sentenceGranularity, FineDiff::$wordGranularity, FineDiff::$characterGranularity);
    $diff_opcodes = FineDiff::getDiffOpcodes($from_text, $to_text, $granularityStacks[$granularity]);
    $difference = FineDiff::renderDiffToHTMLFromOpcodes($from_text, $diff_opcodes);
    return $difference;
}
コード例 #18
0
 public function yoloDiff($t1, $t2)
 {
     include 'includes/framework/frameworkClasses/finediff.php';
     $opcodes = FineDiff::getDiffOpcodes($t1, $t2, FineDiff::$wordGranularity);
     debug(array('HTML' => FineDiff::renderDiffToHTMLFromOpcodes($t1, $opcodes), 'text' => FineDiff::renderToTextFromOpcodes($t1, $opcodes)));
     return FineDiff::renderDiffToHTMLFromOpcodes($t1, $opcodes);
 }
コード例 #19
0
ファイル: diff.php プロジェクト: ppschweiz/basisentscheid
/**
 * wrapper for PHP-FineDiff library
 *
 * @param string  $from_text
 * @param string  $to_text
 */
function diff($from_text, $to_text) {
	/** @noinspection PhpUndefinedClassInspection */
	$opcodes = FineDiff::getDiffOpcodes($from_text, $to_text);
	/** @noinspection PhpUndefinedClassInspection */
	echo FineDiff::renderDiffToHTMLFromOpcodes($from_text, $opcodes);
}
コード例 #20
0
ファイル: articleedit.php プロジェクト: sea75300/fanpresscm3
 /**
  * @see \fpcm\controller\abstracts\controller::request()
  * @return boolean
  */
 public function request()
 {
     if (is_null($this->getRequestVar('articleid'))) {
         $this->redirect('articles/list');
     }
     $this->article = new \fpcm\model\articles\article($this->getRequestVar('articleid'));
     if (!$this->article->exists()) {
         $this->view->setNotFound('LOAD_FAILED_ARTICLE', 'articles/list');
         return true;
     }
     if (!$this->article->getEditPermission()) {
         $this->view = new \fpcm\model\view\error();
         $this->view->addErrorMessage('PERMISSIONS_REQUIRED');
         $this->view->render();
         return false;
     }
     if ($this->getRequestVar('revrestore')) {
         $this->view->addNoticeMessage('SAVE_SUCCESS_ARTICLEREVRESTORE');
     }
     $this->checkPageToken = $this->checkPageToken();
     if ($this->buttonClicked('doAction') && !$this->checkPageToken) {
         $this->view->addErrorMessage('CSRF_INVALID');
     }
     $revisionIdsArray = !is_null($this->getRequestVar('revisionIds')) ? array_map('intval', $this->getRequestVar('revisionIds')) : false;
     if ($this->buttonClicked('revisionDelete') && $revisionIdsArray && !$this->showRevision && $this->checkPageToken) {
         if ($this->article->deleteRevisions($revisionIdsArray)) {
             $this->view->addNoticeMessage('DELETE_SUCCESS_REVISIONS');
         } else {
             $this->view->addErrorMessage('DELETE_FAILED_REVISIONS');
         }
     }
     $this->revisionId = !is_null($this->getRequestVar('rev')) ? (int) $this->getRequestVar('rev') : (is_array($revisionIdsArray) ? array_shift($revisionIdsArray) : false);
     if ($this->buttonClicked('articleRevisionRestore') && ($this->getRequestVar('rev') || $this->getRequestVar('revisionIds')) && $this->checkPageToken) {
         if ($this->revisionId && $this->article->restoreRevision($this->revisionId)) {
             $this->redirect('articles/edit&articleid=' . $this->article->getId() . '&revrestore=1');
         } else {
             $this->view->addErrorMessage('SAVE_FAILED_ARTICLEREVRESTORE');
         }
     }
     if ($this->revisionId) {
         include_once \fpcm\classes\loader::libGetFilePath('PHP-FineDiff', 'finediff.php');
         $this->currentArticle = clone $this->article;
         if (!$this->revisionId) {
             $this->revisionId = (int) $this->getRequestVar('rev');
         }
         $this->showRevision = $this->article->getRevision($this->revisionId) ? true : false;
         $from = $this->currentArticle->getContent();
         $to = $this->article->getContent();
         $opcode = \FineDiff::getDiffOpcodes($from, $to, \FineDiff::$sentenceGranularity);
         $this->view->assign('textFrom', \FineDiff::renderDiffToHTMLFromOpcodes($from, $opcode));
         $this->view->assign('textTo', \FineDiff::renderDiffToHTMLFromOpcodes($to, $opcode));
     }
     if ($this->buttonClicked('articleDelete') && !$this->showRevision && $this->checkPageToken) {
         if ($this->article->delete()) {
             $this->redirect('articles/listall');
         } else {
             $this->view->addErrorMessage('DELETE_FAILED_ARTICLE');
         }
     }
     $res = false;
     $allTimer = time();
     if ($this->buttonClicked('articleSave') && !$this->showRevision && $this->checkPageToken) {
         $this->article->prepareRevision();
         $data = $this->getRequestVar('article', array(4, 7));
         $this->article->setTitle($data['title']);
         $this->article->setContent($data['content']);
         $cats = $this->categoryList->getCategoriesCurrentUser();
         $categories = isset($data['categories']) ? array_map('intval', $data['categories']) : array(array_shift($cats)->getId());
         $this->article->setCategories($categories);
         if (isset($data['postponed']) && !isset($data['archived'])) {
             $timer = strtotime($data['postponedate'] . ' ' . (int) $data['postponehour'] . ':' . (int) $data['postponeminute'] . ':00');
             $postpone = 1;
             if ($timer === false) {
                 $timer = $allTimer;
                 $postpone = 0;
             }
             $this->article->setPostponed($postpone);
             $this->article->setCreatetime($timer);
         } else {
             if ($this->article->getPostponed() || $this->article->getDraft() && !isset($data['draft'])) {
                 $this->article->setCreatetime($allTimer);
             }
             $this->article->setPostponed(0);
         }
         $this->article->setPinned(isset($data['pinned']) ? 1 : 0);
         $this->article->setDraft(isset($data['draft']) ? 1 : 0);
         $this->article->setComments(isset($data['comments']) ? 1 : 0);
         $this->article->setApproval($this->permissions->check(array('article' => 'approve')) ? 1 : 0);
         $this->article->setImagepath(isset($data['imagepath']) ? $data['imagepath'] : '');
         $this->article->setSources(isset($data['sources']) ? $data['sources'] : '');
         if (isset($data['archived'])) {
             $this->article->setArchived(1);
             $this->article->setPinned(0);
             $this->article->setDraft(0);
         } else {
             $this->article->setArchived(0);
         }
         if (!$this->article->getTitle() || !$this->article->getContent()) {
             $this->view->addErrorMessage('SAVE_FAILED_ARTICLE_EMPTY');
             return true;
         }
         if (isset($data['author']) && trim($data['author'])) {
             $this->article->setCreateuser($data['author']);
         }
         if (isset($data['tweettxt']) && $data['tweettxt']) {
             $this->article->setTweetOverride($data['tweettxt']);
         }
         $this->article->setChangetime($allTimer);
         $this->article->setChangeuser($this->session->getUserId());
         $this->article->setMd5path($this->article->getArticleNicePath());
         $this->article->prepareDataSave();
         $saved = true;
         $res = $this->article->update();
         if ($res) {
             $this->article->createRevision();
         }
     }
     $this->handleCommentActions();
     if ($res || $this->getRequestVar('added') == 1) {
         $this->view->addNoticeMessage('SAVE_SUCCESS_ARTICLE');
     } elseif ($this->getRequestVar('added') == 2) {
         $this->view->addNoticeMessage('SAVE_SUCCESS_ARTICLE_APPROVAL');
     } elseif (isset($saved) && !$res) {
         $this->view->addErrorMessage('SAVE_FAILED_ARTICLE');
     }
     if (!$this->revisionId) {
         $this->article->prepareDataLoad();
     }
     return true;
 }