Skip to content

Commit

Permalink
Add ability to filter the source URL in the references.
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Sep 8, 2016
1 parent 4160a9a commit 87d74c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 15 additions & 1 deletion gp-includes/things/project.php
Expand Up @@ -234,7 +234,21 @@ public function regenerate_paths( $parent_project_id = null ) {

public function source_url( $file, $line ) {
if ( $this->source_url_template() ) {
return str_replace( array('%file%', '%line%'), array($file, $line), $this->source_url_template() );
$source_url = str_replace( array( '%file%', '%line%' ), array( $file, $line ), $this->source_url_template() );

/**
* Allows per-reference overriding of the source URL defined as project setting.
*
* @since 2.2.0
*
* @param string $source_url The originally generated source URL.
* @param GP_Project $project The current project.
* @param string $file The referenced file name.
* @param string $line The line number in the referenced file.
*
* @return string|false
*/
return apply_filters( 'gp_reference_source_url', $source_url, $this, $file, $line );
}
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions gp-templates/helper-functions.php
Expand Up @@ -140,8 +140,7 @@ function references( $project, $entry ) {
<?php
foreach( $entry->references as $reference ):
list( $file, $line ) = array_pad( explode( ':', $reference ), 2, 0 );
// TODO: allow the user to override the project setting
if ( $source_url = $project->source_url( $file, $line ) ):
if ( $project->source_url( $file, $line ) ) :
?>
<li><a target="_blank" tabindex="-1" href="<?php echo $source_url; ?>"><?php echo $file.':'.$line ?></a></li>
<?php
Expand Down

0 comments on commit 87d74c8

Please sign in to comment.