Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 3d4bdf9

Browse files
author
Jamie Snape
committed
Add Markdown view helper and tidy other view helpers
1 parent 7865c8d commit 3d4bdf9

File tree

8 files changed

+92
-66
lines changed

8 files changed

+92
-66
lines changed

core/views/helpers/Dateago.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,19 @@
1919
=========================================================================*/
2020

2121
/** Date ago view helper. */
22-
class Zend_View_Helper_Dateago
22+
class Zend_View_Helper_Dateago extends Zend_View_Helper_Abstract
2323
{
24-
/** Date ago view helper. */
24+
/**
25+
* Date ago view helper.
26+
*
27+
* @param int|string $timestamp timestamp
28+
* @return string date ago as a formatted string
29+
*/
2530
public function dateago($timestamp)
2631
{
27-
Zend_Loader::loadClass('DateComponent', BASE_PATH.'/core/controllers/components');
28-
$component = new DateComponent();
32+
/** @var DateComponent $dateComponent */
33+
$dateComponent = MidasLoader::loadComponent('Date');
2934

30-
return $component->ago($timestamp);
31-
}
32-
33-
/** Set the view. */
34-
public function setView(Zend_View_Interface $view)
35-
{
36-
$this->view = $view;
35+
return htmlspecialchars($dateComponent->ago($timestamp), ENT_QUOTES, 'UTF-8');
3736
}
3837
}

core/views/helpers/Duration.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,19 @@
1919
=========================================================================*/
2020

2121
/** Duration view helper. */
22-
class Zend_View_Helper_Duration
22+
class Zend_View_Helper_Duration extends Zend_View_Helper_Abstract
2323
{
24-
/** Duration view helper. */
24+
/**
25+
* Duration view helper.
26+
*
27+
* @param int|string $timestamp timestamp
28+
* @return string duration as a formatted string
29+
*/
2530
public function duration($timestamp)
2631
{
27-
Zend_Loader::loadClass('DateComponent', BASE_PATH.'/core/controllers/components');
28-
$component = new DateComponent();
32+
/** @var DateComponent $dateComponent */
33+
$dateComponent = MidasLoader::loadComponent('Date');
2934

30-
return $component->duration($timestamp);
31-
}
32-
33-
/** Set the view. */
34-
public function setView(Zend_View_Interface $view)
35-
{
36-
$this->view = $view;
35+
return htmlspecialchars($dateComponent->duration($timestamp), ENT_QUOTES, 'UTF-8');
3736
}
3837
}

core/views/helpers/Linkuser.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,22 @@
1919
=========================================================================*/
2020

2121
/** Link user view helper. */
22-
class Zend_View_Helper_Linkuser
22+
class Zend_View_Helper_Linkuser extends Zend_View_Helper_Abstract
2323
{
24-
/** Link user view helper. */
24+
/**
25+
* Link user view helper.
26+
*
27+
* @param UserDao $userDao user DAO
28+
* @return string full name of the user, linked to their profile if it is public
29+
*/
2530
public function linkuser($userDao)
2631
{
2732
if ($userDao->getPrivacy() == MIDAS_USER_PUBLIC || isset($this->view->userDao) && $this->view->userDao->isAdmin(
2833
) || isset($this->view->userDao) && $userDao->getKey() == $this->view->userDao->getKey()
2934
) {
30-
return '<a class="userTitle" href="'.$this->view->webroot.'/user/'.$userDao->getKey().'">'.$userDao->getFullName().'</a>';
35+
return '<a class="userTitle" href="'.$this->view->webroot.'/user/'.htmlspecialchars($userDao->getKey(), ENT_QUOTES, 'UTF-8').'">'.htmlspecialchars($userDao->getFullName(), ENT_QUOTES, 'UTF-8').'</a>';
3136
}
3237

33-
return $userDao->getFullName();
34-
}
35-
36-
/** Set the view. */
37-
public function setView(Zend_View_Interface $view)
38-
{
39-
$this->view = $view;
38+
return htmlspecialchars($userDao->getFullName(), ENT_QUOTES, 'UTF-8');
4039
}
4140
}

core/views/helpers/Markdown.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Markdown view helper. */
22+
class Zend_View_Helper_Markdown extends Zend_View_Helper_Abstract
23+
{
24+
/**
25+
* Markdown view helper.
26+
*
27+
* @param string $text Markdown or Markdown Extra text
28+
* @return string HTML text
29+
*/
30+
public function markdown($text)
31+
{
32+
return UtilityComponent::markdown(htmlspecialchars($text, ENT_QUOTES, 'UTF-8'));
33+
}
34+
}

core/views/helpers/Slicename.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,17 @@
1919
=========================================================================*/
2020

2121
/** Slice name view helper. */
22-
class Zend_View_Helper_Slicename
22+
class Zend_View_Helper_Slicename extends Zend_View_Helper_Abstract
2323
{
24-
/** Slice name view helper. */
24+
/**
25+
* Slice name view helper.
26+
*
27+
* @param string $name name
28+
* @param int $nchar number of characters
29+
* @return string sliced name
30+
*/
2531
public function slicename($name, $nchar)
2632
{
27-
Zend_Loader::loadClass('UtilityComponent', BASE_PATH.'/core/controllers/components');
28-
$component = new UtilityComponent();
29-
30-
return $component->sliceName($name, $nchar);
31-
}
32-
33-
/** Set view */
34-
public function setView(Zend_View_Interface $view)
35-
{
36-
$this->view = $view;
33+
return htmlspecialchars(UtilityComponent::sliceName($name, $nchar), ENT_QUOTES, 'UTF-8');
3734
}
3835
}

core/views/helpers/T.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,18 @@
1919
=========================================================================*/
2020

2121
/** Translation view helper. */
22-
class Zend_View_Helper_T
22+
class Zend_View_Helper_T extends Zend_View_Helper_Abstract
2323
{
24-
/** Translation view helper. */
24+
/**
25+
* Translation view helper.
26+
*
27+
* @param string $text text
28+
* @return string translated text if available, otherwise the input text
29+
*/
2530
public function t($text)
2631
{
2732
Zend_Loader::loadClass("InternationalizationComponent", BASE_PATH.'/core/controllers/components');
2833

29-
return InternationalizationComponent::translate($text);
30-
}
31-
32-
/** Set the view. */
33-
public function setView(Zend_View_Interface $view)
34-
{
35-
$this->view = $view;
34+
return htmlspecialchars(InternationalizationComponent::translate($text), ENT_QUOTES, 'UTF-8');
3635
}
3736
}

core/views/helpers/Userthumbnail.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@
1919
=========================================================================*/
2020

2121
/** User thumbnail view helper. */
22-
class Zend_View_Helper_Userthumbnail
22+
class Zend_View_Helper_Userthumbnail extends Zend_View_Helper_Abstract
2323
{
24-
/** User thumbnail view helper. */
24+
/**
25+
* User thumbnail view helper.
26+
*
27+
* @param string $thumbnail link to thumbnail, if any
28+
* @param string $id value of id attribute
29+
*/
2530
public function userthumbnail($thumbnail, $id = '')
2631
{
32+
$id = htmlspecialchars($id, ENT_QUOTES, 'UTF-8');
33+
$thumbnail = htmlspecialchars($thumbnail, ENT_QUOTES, 'UTF-8');
34+
2735
if (empty($thumbnail)) {
2836
echo '<img id="'.$id.'" class="thumbnailSmall" src="'.$this->view->coreWebroot.'/public/images/icons/unknownUser.png" alt="" />';
2937
} elseif (preg_match("@^https?://@", $thumbnail)) {
@@ -32,10 +40,4 @@ public function userthumbnail($thumbnail, $id = '')
3240
echo '<img id="'.$id.'" class="thumbnailSmall" src="'.$this->view->webroot.'/'.$thumbnail.'" alt="" />';
3341
}
3442
}
35-
36-
/** Set the view. */
37-
public function setView(Zend_View_Interface $view)
38-
{
39-
$this->view = $view;
40-
}
4143
}

core/views/licenses/view.phtml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@
1818
limitations under the License.
1919
=========================================================================*/
2020
?>
21-
<link type="text/css" rel="stylesheet"
22-
href="<?php echo $this->coreWebroot ?>/public/css/common/common.genericPage.css"/>
21+
<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot ?>/public/css/common/common.genericPage.css" />
2322

2423
<div class="licenseView">
25-
<?php
26-
echo $this->license->getFulltext();
27-
?>
24+
<?php echo $this->markdown($this->license->getFulltext()); ?>
2825
</div>

0 commit comments

Comments
 (0)