Minor - Move method stripGivenTags() to ChamiloApi class

pull/2487/head
Yannick Warnier 9 years ago
parent c81418b67c
commit 0680e019a9
  1. 3
      main/exercise/export/exercise_import.inc.php
  2. 20
      main/inc/lib/api.lib.php
  3. 15
      src/Chamilo/CoreBundle/Component/Utils/ChamiloApi.php

@ -7,6 +7,7 @@
* @author Guillaume Lederer <guillaume@claroline.net>
* @author Yannick Warnier <yannick.warnier@beeznest.com>
*/
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
/**
* Unzip the exercise in the temp folder
@ -258,7 +259,7 @@ function qti_parse_file($exercisePath, $file, $questionFile)
//parse XML question file
//$data = str_replace(array('<p>', '</p>', '<front>', '</front>'), '', $data);
$data = stripGivenTags($data, array('p', 'front'));
$data = ChamiloApi::stripGivenTags($data, array('p', 'front'));
$qtiVersion = array();
$match = preg_match('/ims_qtiasiv(\d)p(\d)/', $data, $qtiVersion);
$qtiMainVersion = 2; //by default, assume QTI version 2

@ -6,7 +6,9 @@ use ChamiloSession as Session;
/**
* This is a code library for Chamilo.
* It is included by default in every Chamilo file (through including the global.inc.php)
*
* This library is in process of being transferred to src/Chamilo/CoreBundle/Component/Utils/ChamiloApi.
* Whenever a function is transferred to the ChamiloApi class, the places where it is used should include
* the "use Chamilo\CoreBundle\Component\Utils\ChamiloApi;" statement.
* @package chamilo.library
*/
@ -8038,19 +8040,3 @@ function api_protect_limit_for_session_admin()
function api_is_student_view_active() {
return (isset($_SESSION['studentview']) && $_SESSION['studentview'] == "studentview");
}
/**
* Like strip_tags(), but leaves an additional space and removes only the given tags
* @param string $string
* @param array $tags Tags to be removed
* @return string The original string without the given tags
*/
function stripGivenTags($string, $tags) {
foreach ($tags as $tag) {
$string2 = preg_replace('#</' . $tag . '[^>]*>#i', ' ', $string);
if ($string2 != $string) {
$string = preg_replace('/<' . $tag . '[^>]*>/i', ' ', $string2);
}
}
return $string;
}

@ -129,4 +129,19 @@ class ChamiloApi
return \Display::url($image, api_get_path(WEB_PATH) . 'index.php');
}
/**
* Like strip_tags(), but leaves an additional space and removes only the given tags
* @param string $string
* @param array $tags Tags to be removed
* @return string The original string without the given tags
*/
public static function stripGivenTags($string, $tags) {
foreach ($tags as $tag) {
$string2 = preg_replace('#</' . $tag . '[^>]*>#i', ' ', $string);
if ($string2 != $string) {
$string = preg_replace('/<' . $tag . '[^>]*>/i', ' ', $string2);
}
}
return $string;
}
}

Loading…
Cancel
Save