|
3 | 3 | /* For licensing terms, see /license.txt */
|
4 | 4 |
|
5 | 5 | use Chamilo\CourseBundle\Entity\CLink;
|
| 6 | +use GuzzleHttp\Client; |
6 | 7 |
|
7 | 8 | /**
|
8 | 9 | * Function library for the links tool.
|
@@ -1553,8 +1554,9 @@ public static function listLinksAndCategories(
|
1553 | 1554 | if ($showChildren) {
|
1554 | 1555 | $childrenContent = self::showLinksPerCategory(
|
1555 | 1556 | $myrow['id'],
|
1556 |
| - api_get_course_int_id(), |
1557 |
| - api_get_session_id() |
| 1557 | + $course_id, |
| 1558 | + $session_id, |
| 1559 | + $showActionLinks |
1558 | 1560 | );
|
1559 | 1561 | }
|
1560 | 1562 |
|
@@ -1791,49 +1793,45 @@ public static function moveLinkDown($id)
|
1791 | 1793 | return self::moveLinkDisplayOrder($id, 'DESC');
|
1792 | 1794 | }
|
1793 | 1795 |
|
1794 |
| - /** |
1795 |
| - * @param string $url |
1796 |
| - * |
1797 |
| - * @return bool |
1798 |
| - */ |
1799 |
| - public static function checkUrl($url) |
| 1796 | + public static function checkUrl(string $url): bool |
1800 | 1797 | {
|
1801 |
| - // Check if curl is available. |
1802 |
| - if (!in_array('curl', get_loaded_extensions())) { |
1803 |
| - return false; |
1804 |
| - } |
1805 |
| - |
1806 |
| - // set URL and other appropriate options |
1807 | 1798 | $defaults = [
|
1808 |
| - CURLOPT_URL => $url, |
1809 |
| - CURLOPT_FOLLOWLOCATION => true, // follow redirects accept youtube.com |
1810 |
| - CURLOPT_HEADER => 0, |
1811 |
| - CURLOPT_RETURNTRANSFER => true, |
1812 |
| - CURLOPT_TIMEOUT => 4, |
| 1799 | + 'allow_redirects' => [ |
| 1800 | + 'max' => 5, // max number of redirects allowed |
| 1801 | + 'strict' => true, // whether to use strict redirects or not |
| 1802 | + 'referer' => true, // whether to add the Referer header when redirecting |
| 1803 | + 'protocols' => ['http', 'https'], // protocols allowed to be redirected to |
| 1804 | + 'track_redirects' => true // whether to keep track of the number of redirects |
| 1805 | + ], |
| 1806 | + 'connect_timeout' => 4, |
| 1807 | + 'timeout' => 4, |
1813 | 1808 | ];
|
1814 | 1809 |
|
1815 | 1810 | $proxySettings = api_get_configuration_value('proxy_settings');
|
1816 | 1811 |
|
1817 | 1812 | if (!empty($proxySettings) &&
|
1818 | 1813 | isset($proxySettings['curl_setopt_array'])
|
1819 | 1814 | ) {
|
1820 |
| - $defaults[CURLOPT_PROXY] = $proxySettings['curl_setopt_array']['CURLOPT_PROXY']; |
1821 |
| - $defaults[CURLOPT_PROXYPORT] = $proxySettings['curl_setopt_array']['CURLOPT_PROXYPORT']; |
| 1815 | + $defaults['proxy'] = sprintf( |
| 1816 | + '%s:%s', |
| 1817 | + $proxySettings['curl_setopt_array']['CURLOPT_PROXY'], |
| 1818 | + $proxySettings['curl_setopt_array']['CURLOPT_PROXYPORT'] |
| 1819 | + ); |
1822 | 1820 | }
|
1823 | 1821 |
|
1824 |
| - // Create a new cURL resource |
1825 |
| - $ch = curl_init(); |
1826 |
| - curl_setopt_array($ch, $defaults); |
| 1822 | + $client = new Client(['defaults' => $defaults]); |
1827 | 1823 |
|
1828 |
| - // grab URL and pass it to the browser |
1829 |
| - ob_start(); |
1830 |
| - $result = curl_exec($ch); |
1831 |
| - ob_get_clean(); |
| 1824 | + try { |
| 1825 | + $response = $client->get($url); |
1832 | 1826 |
|
1833 |
| - // close cURL resource, and free up system resources |
1834 |
| - curl_close($ch); |
| 1827 | + if (200 !== $response->getStatusCode()) { |
| 1828 | + return false; |
| 1829 | + } |
1835 | 1830 |
|
1836 |
| - return $result; |
| 1831 | + return true; |
| 1832 | + } catch (Exception $e) { |
| 1833 | + return false; |
| 1834 | + } |
1837 | 1835 | }
|
1838 | 1836 |
|
1839 | 1837 | /**
|
|
0 commit comments