示例#1
0
 /**
  * Resolve diffs.
  * 
  * @param array $current The current content as an array.
  * @param array[] $revisions An array of revisions of the content.
  * @param array $diffdFields The fields that are diff'd.
  * @param bool $merge Merge the current and revision to return 1 entry.  (Cite)
  */
 public static function resolve($current, $revisions, $diffdFields, $merge = true)
 {
     $return = array();
     foreach ($revisions as $revision) {
         $nCurrent = $merge ? array_merge($current, $revision) : $revision;
         foreach ($diffdFields as $field) {
             if ($field[0] == '$') {
                 $s = true;
                 $field = substr($field, 1);
                 $current[$field] = serialize($current[$field]);
             }
             $nCurrent[$field] = FineDiff::renderToTextFromOpcodes($current[$field], $nCurrent[$field]);
         }
         $current = $nCurrent;
         if ($s) {
             $current[$field] = unserialize($current[$field]);
         }
         array_push($return, $current);
     }
     return $return;
 }
示例#2
0
 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;
 }
示例#3
0
         $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']) {
                     break;
                 } else {
                     $content = FineDiff::renderToTextFromOpcodes($content, file_get_contents($version['link']));
                 }
             }
         }
         $jsonResponse['success'] = true;
         $jsonResponse['content'] = $content;
     } else {
         $jsonResponse['message'] = 'Vous ne pouvez pas editer tant que vous n\'êtes pas connecté.';
     }
     echo json_encode($jsonResponse);
     break;
 case 'save':
     if ($myUser != false) {
         $newContent = html_entity_decode($_['content'], ENT_QUOTES, 'UTF-8');
         $oldContent = file_exists($pagePath) ? file_get_contents($pagePath) : '';
         if ($newContent != $oldContent) {
 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);
 }
示例#5
0
$diff_opcodes_len = 0;
$data_key = '';
$start_time = gettimeofday(true);
// restore from cache
if (isset($_GET['data'])) {
    if (ctype_alnum($_GET['data'])) {
        $filename = "{$_GET['data']}{$compressed_serialized_filename_extension}";
        $compressed_serialized_data = @file_get_contents("./cache/{$filename}");
        if ($compressed_serialized_data !== false) {
            @touch("./cache/{$filename}");
            $data_from_serialization = unserialize(gzuncompress($compressed_serialized_data));
            $granularity = $data_from_serialization['granularity'];
            $from_text = $data_from_serialization['from_text'];
            $diff_opcodes = $data_from_serialization['diff_opcodes'];
            $diff_opcodes_len = strlen($diff_opcodes);
            $to_text = FineDiff::renderToTextFromOpcodes($from_text, $diff_opcodes);
            $data_key = $data_from_serialization['data_key'];
        } else {
            echo '<p style="font-size:smaller">The page you are looking for has expired.</p>', "\n";
        }
    }
    $exec_time = gettimeofday(true) - $start_time;
} else {
    if (isset($_POST['granularity']) && ctype_digit($_POST['granularity'])) {
        $granularity = max(min(intval($_POST['granularity']), 3), 0);
    }
    if (!empty($_POST['from']) || !empty($_POST['to'])) {
        if (!empty($_POST['from'])) {
            $from_text = $_POST['from'];
        }
        if (!empty($_POST['to'])) {
示例#6
0
 public function scanFile(&$filename, &$content, &$polycontent)
 {
     $ret = array();
     $this->cleanfile = false;
     //check wp itself
     foreach ($this->wpinstalls as $basedir => $ver) {
         if (substr($filename, 0, strlen($basedir)) == $basedir) {
             $wpfile = substr($filename, strlen($basedir));
             //ignore .htacess and wp-config.php
             if ($wpfile == ".htaccess" || $wpfile == 'wp-config.php') {
                 return $ret;
             }
             //treat wp content differently
             if (substr($wpfile, 0, 11) == 'wp-content/') {
                 //TODO
             } else {
                 $originalfile = $this->zipfiles['wordpress-' . $ver . '.zip']->getFromName('wordpress/' . $wpfile);
                 $purefile = $originalfile;
                 if ($originalfile === FALSE) {
                     if ($this->scanner->tryFixing == true) {
                         $ret[] = array('message' => "Extra file in WP - file deleted", 'sure' => 80);
                         @unlink($filename);
                     } else {
                         $ret[] = array('message' => "Extra file in WP", 'sure' => 80);
                     }
                 } else {
                     $originalfile = str_replace(array("\r"), '', $originalfile);
                     $nolines = implode("\n", $content);
                     $nolines = str_replace(array(" ", "\t", "\n\n"), "", $nolines);
                     $originalfile = str_replace(array(" ", "\t", "\n\n"), "", $originalfile);
                     $nolines = $this->trimFile($nolines);
                     $originalfile = $this->trimFile($originalfile);
                     if ($originalfile == $nolines) {
                         $this->cleanfile = true;
                     } else {
                         $opcodes = FineDiff::getDiffOpcodes($nolines, $originalfile, FineDiff::$wordGranularity);
                         $to_text = FineDiff::renderToTextFromOpcodes($nolines, $opcodes);
                         if ($this->scanner->tryFixing == true) {
                             $ret[] = array('message' => "WP core file changed - replacing with original\n" . substr($to_text, 0, strlen($to_text) - 1), 'sure' => 80);
                             @file_put_contents($filename, $purefile);
                         } else {
                             $ret[] = array('message' => "WP core file changed\n" . substr($to_text, 0, strlen($to_text) - 1), 'sure' => 80);
                         }
                     }
                 }
             }
         }
     }
     //check plugins
     foreach ($this->wpplugins as $basedir => $info) {
         if (substr($filename, 0, strlen($basedir)) == $basedir) {
             $wpfile = $info['name'] . substr($filename, strlen($basedir));
             $originalfile = $info['zip']->getFromName($wpfile);
             $purefile = $originalfile;
             if ($originalfile === FALSE) {
                 if ($this->scanner->tryFixing == true) {
                     $ret[] = array('message' => "Extra file in plugin " . $info['name'] . " - file deleted", 'sure' => 80);
                     @unlink($filename);
                 } else {
                     $ret[] = array('message' => "Extra file in WP", 'sure' => 80);
                 }
             } else {
                 $originalfile = str_replace(array("\r"), '', $originalfile);
                 $nolines = implode("\n", $content);
                 $nolines = $this->trimFile($nolines);
                 $originalfile = $this->trimFile($originalfile);
                 if ($originalfile == $nolines) {
                     $this->cleanfile = true;
                 } else {
                     $opcodes = FineDiff::getDiffOpcodes($nolines, $originalfile, FineDiff::$wordGranularity);
                     $to_text = FineDiff::renderToTextFromOpcodes($nolines, $opcodes);
                     if ($this->scanner->tryFixing == true) {
                         $ret[] = array('message' => "Plugin file changed " . $info['name'] . " - replacing with original\n" . substr($to_text, 0, strlen($to_text) - 1), 'sure' => 80);
                         @file_put_contents($filename, $purefile);
                     } else {
                         $ret[] = array('message' => "Plugin file changed " . $info['name'] . "\n" . substr($to_text, 0, strlen($to_text) - 1), 'sure' => 80);
                     }
                 }
             }
         }
     }
     return $ret;
 }