|
| 1 | +<?php |
| 2 | + |
| 3 | +# Copyright (c) 2015 John Bailey |
| 4 | +# Copyright (c) 2012 John Reese |
| 5 | +# Licensed under the MIT license |
| 6 | + |
| 7 | +if ( false === include_once( config_get( 'plugin_path' ) . 'SourceSVN/SourceSVN.php' ) ) { |
| 8 | + return; |
| 9 | +} |
| 10 | + |
| 11 | +class SourceViewVCPlugin extends SourceSVNPlugin { |
| 12 | + public function register() { |
| 13 | + $this->name = lang_get( 'plugin_SourceViewVC_title' ); |
| 14 | + $this->description = lang_get( 'plugin_SourceViewVC_description' ); |
| 15 | + |
| 16 | + $this->version = '0.1'; |
| 17 | + $this->requires = array( |
| 18 | + 'MantisCore' => '1.2.0', |
| 19 | + 'Source' => '0.16', |
| 20 | + 'SourceSVN' => '0.16', |
| 21 | + ); |
| 22 | + |
| 23 | + $this->author = 'John Bailey'; |
| 24 | + $this-> contact = '[email protected]'; |
| 25 | + $this->url = 'https://github.com/mantisbt-plugins/source-integration'; |
| 26 | + } |
| 27 | + |
| 28 | + public $type = 'viewvc'; |
| 29 | + |
| 30 | + public function show_type() { |
| 31 | + return lang_get( 'plugin_SourceViewVC_svn' ); |
| 32 | + } |
| 33 | + |
| 34 | + public function get_viewvc_url( $p_repo ) { |
| 35 | + return isset( $p_repo->info['viewvc_url'] ) |
| 36 | + ? $p_repo->info['viewvc_url'] |
| 37 | + : ''; |
| 38 | + } |
| 39 | + |
| 40 | + public function get_viewvc_name( $p_repo ) { |
| 41 | + return isset( $p_repo->info['viewvc_name'] ) |
| 42 | + ? $p_repo->info['viewvc_name'] |
| 43 | + : ''; |
| 44 | + } |
| 45 | + |
| 46 | + public function get_viewvc_use_checkout( $p_repo ) { |
| 47 | + return isset( $p_repo->info['viewvc_use_checkout'] ) |
| 48 | + ? $p_repo->info['viewvc_use_checkout'] |
| 49 | + : false; |
| 50 | + } |
| 51 | + |
| 52 | + public function get_viewvc_root_as_url( $p_repo ) { |
| 53 | + return isset( $p_repo->info['viewvc_root_as_url'] ) |
| 54 | + ? $p_repo->info['viewvc_root_as_url'] |
| 55 | + : false; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Builds the ViewVC URL base string |
| 60 | + * @param object $p_repo repository |
| 61 | + * @param string $p_file optional filename (as absolute path from root) |
| 62 | + * @param array $p_opts optional additional ViewVC URL parameters |
| 63 | + * @return string ViewVC URL |
| 64 | + */ |
| 65 | + protected function url_base( $p_repo, $p_file = '', $p_opts=array() ) { |
| 66 | + $t_name = urlencode( $this->get_viewvc_name( $p_repo ) ); |
| 67 | + $t_root_as_url = $this->get_viewvc_root_as_url( $p_repo ); |
| 68 | + |
| 69 | + $t_url = rtrim( $this->get_viewvc_url( $p_repo ), '/' ); |
| 70 | + |
| 71 | + if( $t_root_as_url ) { |
| 72 | + $t_url_name = '/'.$t_name; |
| 73 | + } else { |
| 74 | + $t_url_name = ''; |
| 75 | + $p_opts['root']=$t_name; |
| 76 | + } |
| 77 | + |
| 78 | + return $t_url . $t_url_name . $p_file . '?' . http_build_query( $p_opts ); |
| 79 | + } |
| 80 | + |
| 81 | + public function url_repo( $p_repo, $p_changeset=null ) { |
| 82 | + $t_opts = array(); |
| 83 | + |
| 84 | + if ( !is_null( $p_changeset ) ) { |
| 85 | + $t_opts['revision'] = $p_changeset->revision; |
| 86 | + } |
| 87 | + |
| 88 | + return $this->url_base( $p_repo, '', $t_opts); |
| 89 | + } |
| 90 | + |
| 91 | + public function url_changeset( $p_repo, $p_changeset ) { |
| 92 | + $t_rev = $p_changeset->revision; |
| 93 | + $t_opts = array(); |
| 94 | + $t_opts['view'] = 'revision'; |
| 95 | + $t_opts['revision'] = $t_rev; |
| 96 | + |
| 97 | + return $this->url_base( $p_repo, '', $t_opts ); |
| 98 | + } |
| 99 | + |
| 100 | + public function url_file( $p_repo, $p_changeset, $p_file ) { |
| 101 | + |
| 102 | + # if the file has been removed, it doesn't exist in current revision |
| 103 | + # so we generate a link to (current revision - 1) |
| 104 | + $t_revision = ($p_file->action == 'rm') |
| 105 | + ? $p_changeset->revision - 1 |
| 106 | + : $p_changeset->revision; |
| 107 | + $t_use_checkout = $this->get_viewvc_use_checkout( $p_repo ); |
| 108 | + |
| 109 | + $t_opts = array(); |
| 110 | + $t_opts['revision'] = $t_revision; |
| 111 | + |
| 112 | + if( !$t_use_checkout ) |
| 113 | + { |
| 114 | + $t_opts['view'] = 'markup'; |
| 115 | + } |
| 116 | + |
| 117 | + return $this->url_base( $p_repo, $p_file->filename, $t_opts ); |
| 118 | + } |
| 119 | + |
| 120 | + public function url_diff( $p_repo, $p_changeset, $p_file ) { |
| 121 | + if ( $p_file->action == 'rm' || $p_file->action == 'add' ) { |
| 122 | + return ''; |
| 123 | + } |
| 124 | + |
| 125 | + $t_opts = array(); |
| 126 | + $t_opts['r1'] = $p_changeset->revision; |
| 127 | + $t_opts['r2'] = $p_changeset->revision - 1; |
| 128 | + |
| 129 | + return $this->url_base( $p_repo, $p_file->filename, $t_opts ); |
| 130 | + } |
| 131 | + |
| 132 | + public function update_repo_form( $p_repo ) { |
| 133 | + $t_url = $this->get_viewvc_url( $p_repo ); |
| 134 | + $t_name = $this->get_viewvc_name( $p_repo ); |
| 135 | + $t_use_checkout = $this->get_viewvc_use_checkout( $p_repo ); |
| 136 | + $t_root_as_url = $this->get_viewvc_root_as_url( $p_repo ); |
| 137 | + |
| 138 | +?> |
| 139 | +<tr <?php echo helper_alternate_class() ?>> |
| 140 | +<td class="category"><?php echo lang_get( 'plugin_SourceViewVC_viewvc_url' ) ?></td> |
| 141 | +<td><input name="viewvc_url" maxlength="250" size="40" value="<?php echo string_attribute( $t_url ) ?>"/></td> |
| 142 | +</tr> |
| 143 | +<tr <?php echo helper_alternate_class() ?>> |
| 144 | +<td class="category"><?php echo lang_get( 'plugin_SourceViewVC_viewvc_name' ) ?></td> |
| 145 | +<td><input name="viewvc_name" maxlength="250" size="40" value="<?php echo string_attribute( $t_name ) ?>"/></td> |
| 146 | +</tr> |
| 147 | +<tr <?php echo helper_alternate_class() ?>> |
| 148 | +<td class="category"><?php echo lang_get( 'plugin_SourceViewVC_viewvc_root_as_url' ) ?></td> |
| 149 | +<td><input name="viewvc_root_as_url" type="checkbox" <?php echo ($t_root_as_url ? 'checked="checked"' : '') ?>/></td> |
| 150 | +</tr> |
| 151 | +<tr <?php echo helper_alternate_class() ?>> |
| 152 | +<td class="category"><?php echo lang_get( 'plugin_SourceViewVC_viewvc_use_checkout' ) ?></td> |
| 153 | +<td><input name="viewvc_use_checkout" type="checkbox" <?php echo ($t_use_checkout ? 'checked="checked"' : '') ?>/></td> |
| 154 | +</tr> |
| 155 | +<?php |
| 156 | + |
| 157 | + return parent::update_repo_form( $p_repo ); |
| 158 | + } |
| 159 | + |
| 160 | + public function update_repo( $p_repo ) { |
| 161 | + |
| 162 | + $p_repo->info['viewvc_url'] = gpc_get_string( 'viewvc_url' ); |
| 163 | + $p_repo->info['viewvc_name'] = gpc_get_string( 'viewvc_name' ); |
| 164 | + $p_repo->info['viewvc_use_checkout'] = gpc_get_bool( 'viewvc_use_checkout', false ); |
| 165 | + $p_repo->info['viewvc_root_as_url'] = gpc_get_bool( 'viewvc_root_as_url', false ); |
| 166 | + |
| 167 | + return parent::update_repo( $p_repo ); |
| 168 | + } |
| 169 | +} |
0 commit comments