Adding language settings to config.php so that people can control the language output...
[viewsvn.git] / diff.php
index ad462556d3b2b8749ec97ca5127a2e5938d265d2..71de17d1a3512fd893fe351a9a30d058b2aa884f 100644 (file)
--- a/diff.php
+++ b/diff.php
 <?php
 /*=====================================================================*\
-|| ################################################################### ||
+|| ###################################################################
 || # ViewSVN [#]version[#]
-|| # --------------------------------------------------------------- # ||
-|| # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
-|| # This file may not be reproduced in any way without permission.  # ||
-|| # --------------------------------------------------------------- # ||
-|| # User License Agreement at http://www.iris-studios.com/license/  # ||
-|| ################################################################### ||
+|| # Copyright ©2002-[#]year[#] Blue Static
+|| #
+|| # This program is free software; you can redistribute it and/or modify
+|| # it under the terms of the GNU General Public License as published by
+|| # the Free Software Foundation; version [#]gpl[#] of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
 \*=====================================================================*/
 
+$fetchtemplates = array(
+       'diff_line',
+       'diff_hunk',
+       'diff_file',
+       'diff',
+       'file_change',
+       'property'
+);
+
+define('SVN', '$Id$');
+
 require_once('./global.php');
+require_once('./includes/class_diff.php');
 
-echo $viewsvn->paths->construct_breadcrumb($path, false);
+$navbar = ConstructNavbar();
 
-$revs = $viewsvn->paths->fetch_rev_num(true);
-$high = $revs['high'];
-$low = $revs['low'];
+// ###################################################################
 
-if ($high == 'HEAD')
-{
-       $high = $viewsvn->svn->common->fetch_head_rev($path);
-}
+$link['log'] = ConstructLink('log', $input->in['repos'], $input->in['path'], $input->in['rev']);
 
-if ($low == 0)
+// ###################################################################
+
+$show['fullchangeset'] = !($input->in['path'] == '' OR $input->in['path'] == '/');
+if ($show['fullchangeset'])
 {
-       $low = $viewsvn->svn->common->fetch_prev_rev($path, $high);
+       $link['changeset'] = ConstructLink('diff', $input->in['repos'], null, $input->in['rev']);
 }
 
-$diff = new SVNDiff($repos, $relpath, $low, $high);
+$revision = new Revision($input->in['repos'], $input->in['rev'], $input->in['path']);
+$revision->getRevisionInfo();
 
-$isdir = (bool)$viewsvn->svn->common->isdir($path);
+$files = ConstructFileChanges($revision->files, $input->in['repos'], $revision->revision);
 
-echo <<<HTML
-<style type="text/css">
-<!--
-       
-       .diff_add
-       {
-               background-color: #99EE99;
-       }
+// ###################################################################
+
+$diff = new Diff($lib->run('diff -c' . $revision->revision . ' ' . $lib->arg($repos->fetchPath($input->in['repos']) . '/' . $input->in['path'])));
+
+$changes = '';
+foreach ($diff->fetch() AS $filename => $file)
+{
+       $hunktpl = '';
+       $proplist = '';
        
-       .diff_del
+       if (!$filename)
        {
-               background-color: #EE9999;
+               continue;
        }
        
-       table
+       if (is_array($file['lines']))
        {
-               font: normal 11px monospace;
-       }
-       
-//-->
-</style>
-HTML;
+               foreach ($file['lines'] AS $hunk)
+               {
+                       $lines = '';
 
-foreach ($diff->fetch() AS $filename => $file)
-{
-       echo '<h2>' . $filename . '</h2>';
+                       $show['hunk'] = true;
+                       $low = $file['revision']['low'];
+                       $high = $file['revision']['high'];
+
+                       $filename = (preg_match('/' . preg_quote($filename, '/') . '$/', $input->in['path']) ? $input->in['path'] : BSFunctions::FetchSourcePath($input->in['path']) . $filename);
+                       $rlow = ConstructLink('view', $input->in['repos'], $filename, $low);
+                       $rhigh = ConstructLink('view', $input->in['repos'], $filename, $high);
+                       eval('$lines .= "' . $template->fetch('diff_line') . '";');
+
+                       foreach ($hunk AS $key => $line)
+                       {
+                               $show['hunk'] = false;
+                               if ($line['act'] == '+')
+                               {
+                                       $class = 'diff_add';
+                               }
+                               else if ($line['act'] == '-')
+                               {
+                                       $class = 'diff_del';
+                               }
+                               else
+                               {
+                                       $class = 'diff_norm';
+                               }
+
+                               $line['line_clean'] = FormatCode($line['line']);
+
+                               eval('$lines .= "' . $template->fetch('diff_line') . '";');
+                       }
+                       eval('$hunktpl .= "' . $template->fetch('diff_hunk') . '";');
+               }
+       }
        
-       foreach ($file AS $hunk)
+       if (is_array($file['props']))
        {
-               echo '<table cellspacing="1" cellpadding="1" width="100%">';
-               
-               foreach ($hunk AS $key => $line)
+               $show['props'] = true;
+               foreach ($file['props'] AS $name => $values)
                {
-                       if ($key == 'hunk' AND isset($line['old']))
+                       // modified
+                       if (isset($values['add']) AND isset($values['del']))
                        {
-                               $filepath = ($isdir ? $path . $filename : $path);
-                               echo '
-                       <tr style="background-color: #F7F7F7">
-                               <td><a href="/viewsvn/' . $viewsvn->paths->out('view.php' . $viewsvn->paths->fetch_rev_str(false, $low), $filepath) . '">r' . $low . '</a></td>
-                               <td><a href="/viewsvn/' . $viewsvn->paths->out('view.php' . $viewsvn->paths->fetch_rev_str(false, $high), $filepath) . '">r' . $high . '</a></td>
-                               <td>&nbsp;</td>
-                       </tr>';
-                               continue;
+                               $data = sprintf(_('Property <strong>%1$s</strong> changed from <em>%2$s</em> to <em>%3$s</em>'), $name, $values['del'], $values['add']);
                        }
-                       
-                       if ($line['act'] == '+')
+                       // added
+                       else if (isset($values['add']))
                        {
-                               $color = '#DDFFDD';
+                               $data = sprintf(_('Property <strong>%1$s</strong> set to <em>%2$s</em>'), $name, $values['add']);
                        }
-                       else if ($line['act'] == '-')
+                       // removed
+                       else if (isset($values['del']))
                        {
-                               $color = '#FFDDDD';
+                               $data = sprintf(_('Property <strong>%1$s</strong> deleted'), $name);
                        }
-                       else
-                       {
-                               $color = 'white';
-                       }
-                       
-                       echo '
-                       <tr style="background-color: #EEEEDD; border-width: 0px 1px 1px 0px">
-                               <td>' . $line['oldlineno'] . '</td>
-                               <td>' . $line['newlineno'] . '</td>
-                               <td style="background-color: ' . $color . '">' . $viewsvn->svn->format($line['line']) . '</td>
-                       </tr>';
+                       eval('$proplist .= "' . $template->fetch('property') . '";');
                }
-               
-               echo '
-               </table>';
        }
        
-       echo '<hr />';
+       eval('$changes .= "' . $template->fetch('diff_file') . '";');
 }
 
+// ###################################################################
+
+eval('$template->flush("' . $template->fetch('diff') . '");');
+
 /*=====================================================================*\
 || ###################################################################
 || # $HeadURL$