Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like DocumentManager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DocumentManager, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | class DocumentManager |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Construct |
||
| 17 | */ |
||
| 18 | private function __construct() |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param string $course_code |
||
| 24 | * |
||
| 25 | * @return int the document folder quota for the current course in bytes |
||
| 26 | * or the default quota |
||
| 27 | */ |
||
| 28 | public static function get_course_quota($course_code = null) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Get the content type of a file by checking the extension |
||
| 51 | * We could use mime_content_type() with php-versions > 4.3, |
||
| 52 | * but this doesn't work as it should on Windows installations |
||
| 53 | * |
||
| 54 | * @param string $filename or boolean TRUE to return complete array |
||
| 55 | * @author ? first version |
||
| 56 | * @author Bert Vanderkimpen |
||
| 57 | * @return string |
||
| 58 | * |
||
| 59 | */ |
||
| 60 | public static function file_get_mime_type($filename) |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @param string |
||
| 279 | * @param string |
||
| 280 | * @return true if the user is allowed to see the document, false otherwise |
||
| 281 | * @author Sergio A Kessler, first version |
||
| 282 | * @author Roan Embrechts, bugfix |
||
| 283 | * @todo not only check if a file is visible, but also check if the user is allowed to see the file?? |
||
| 284 | */ |
||
| 285 | public static function file_visible_to_user($this_course, $doc_url) |
||
| 306 | |||
| 307 | /** |
||
| 308 | * This function streams a file to the client |
||
| 309 | * |
||
| 310 | * @param string $full_file_name |
||
| 311 | * @param boolean $forced |
||
| 312 | * @param string $name |
||
| 313 | * @param string $fixLinksHttpToHttps change file content from http to https |
||
| 314 | * |
||
| 315 | * @return false if file doesn't exist, true if stream succeeded |
||
| 316 | */ |
||
| 317 | public static function file_send_for_download( |
||
| 318 | $full_file_name, |
||
| 319 | $forced = false, |
||
| 320 | $name = '', |
||
| 321 | $fixLinksHttpToHttps = false |
||
| 322 | ) { |
||
| 323 | session_write_close(); //we do not need write access to session anymore |
||
| 324 | if (!is_file($full_file_name)) { |
||
| 325 | return false; |
||
| 326 | } |
||
| 327 | $filename = ($name == '') ? basename($full_file_name) : api_replace_dangerous_char($name); |
||
| 328 | $len = filesize($full_file_name); |
||
| 329 | // Fixing error when file name contains a "," |
||
| 330 | $filename = str_replace(',', '', $filename); |
||
| 331 | |||
| 332 | $sendFileHeaders = api_get_configuration_value('enable_x_sendfile_headers'); |
||
| 333 | |||
| 334 | if ($forced) { |
||
| 335 | // Force the browser to save the file instead of opening it |
||
| 336 | |||
| 337 | if (isset($sendFileHeaders) && |
||
| 338 | !empty($sendFileHeaders)) { |
||
| 339 | header("X-Sendfile: $filename"); |
||
| 340 | } |
||
| 341 | |||
| 342 | header('Content-type: application/octet-stream'); |
||
| 343 | header('Content-length: ' . $len); |
||
| 344 | View Code Duplication | if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) { |
|
| 345 | header('Content-Disposition: filename= ' . $filename); |
||
| 346 | } else { |
||
| 347 | header('Content-Disposition: attachment; filename= ' . $filename); |
||
| 348 | } |
||
| 349 | if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { |
||
| 350 | header('Pragma: '); |
||
| 351 | header('Cache-Control: '); |
||
| 352 | header('Cache-Control: public'); // IE cannot download from sessions without a cache |
||
| 353 | } |
||
| 354 | header('Content-Description: ' . $filename); |
||
| 355 | header('Content-Transfer-Encoding: binary'); |
||
| 356 | |||
| 357 | $res = fopen($full_file_name, 'r'); |
||
| 358 | fpassthru($res); |
||
| 359 | |||
| 360 | return true; |
||
| 361 | } else { |
||
| 362 | //no forced download, just let the browser decide what to do according to the mimetype |
||
| 363 | |||
| 364 | $content_type = self::file_get_mime_type($filename); |
||
| 365 | $lpFixedEncoding = api_get_configuration_value('lp_fixed_encoding'); |
||
| 366 | |||
| 367 | header('Expires: Wed, 01 Jan 1990 00:00:00 GMT'); |
||
| 368 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
||
| 369 | // Commented to avoid double caching declaration when playing with IE and HTTPS |
||
| 370 | //header('Cache-Control: no-cache, must-revalidate'); |
||
| 371 | //header('Pragma: no-cache'); |
||
| 372 | switch ($content_type) { |
||
| 373 | View Code Duplication | case 'text/html': |
|
| 374 | if (isset($lpFixedEncoding) && $lpFixedEncoding === 'true') { |
||
| 375 | $content_type .= '; charset=UTF-8'; |
||
| 376 | } else { |
||
| 377 | $encoding = @api_detect_encoding_html(file_get_contents($full_file_name)); |
||
| 378 | if (!empty($encoding)) { |
||
| 379 | $content_type .= '; charset=' . $encoding; |
||
| 380 | } |
||
| 381 | } |
||
| 382 | break; |
||
| 383 | View Code Duplication | case 'text/plain': |
|
| 384 | if (isset($lpFixedEncoding) && $lpFixedEncoding === 'true') { |
||
| 385 | $content_type .= '; charset=UTF-8'; |
||
| 386 | } else { |
||
| 387 | $encoding = @api_detect_encoding(strip_tags(file_get_contents($full_file_name))); |
||
| 388 | if (!empty($encoding)) { |
||
| 389 | $content_type .= '; charset=' . $encoding; |
||
| 390 | } |
||
| 391 | } |
||
| 392 | break; |
||
| 393 | case 'application/vnd.dwg': |
||
| 394 | case 'application/vnd.dwf': |
||
| 395 | header('Content-type: application/octet-stream'); |
||
| 396 | break; |
||
| 397 | } |
||
| 398 | header('Content-type: ' . $content_type); |
||
| 399 | header('Content-Length: ' . $len); |
||
| 400 | $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']); |
||
| 401 | View Code Duplication | if (strpos($user_agent, 'msie')) { |
|
| 402 | header('Content-Disposition: ; filename= ' . $filename); |
||
| 403 | } else { |
||
| 404 | header('Content-Disposition: inline; filename= ' . $filename); |
||
| 405 | } |
||
| 406 | |||
| 407 | if ($fixLinksHttpToHttps) { |
||
| 408 | $content = file_get_contents($full_file_name); |
||
| 409 | $content = str_replace( |
||
| 410 | array('http%3A%2F%2F', 'http://'), |
||
| 411 | array('https%3A%2F%2F', 'https://'), |
||
| 412 | $content |
||
| 413 | ); |
||
| 414 | echo $content; |
||
| 415 | } else { |
||
| 416 | readfile($full_file_name); |
||
| 417 | } |
||
| 418 | |||
| 419 | return true; |
||
| 420 | } |
||
| 421 | } |
||
| 422 | |||
| 423 | /** |
||
| 424 | * This function streams a string to the client for download. |
||
| 425 | * You have to ensure that the calling script then stops processing (exit();) |
||
| 426 | * otherwise it may cause subsequent use of the page to want to download |
||
| 427 | * other pages in php rather than interpreting them. |
||
| 428 | * |
||
| 429 | * @param string $full_string The string contents |
||
| 430 | * @param boolean $forced Whether "save" mode is forced (or opening directly authorized) |
||
| 431 | * @param string $name The name of the file in the end (including extension) |
||
| 432 | * |
||
| 433 | * @return false if file doesn't exist, true if stream succeeded |
||
| 434 | */ |
||
| 435 | public static function string_send_for_download($full_string, $forced = false, $name = '') |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Session folder filters |
||
| 504 | * |
||
| 505 | * @param string $path |
||
| 506 | * @param int $sessionId |
||
| 507 | * |
||
| 508 | * @return null|string |
||
| 509 | */ |
||
| 510 | public static function getSessionFolderFilters($path, $sessionId) |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Fetches all document data for the given user/group |
||
| 529 | * |
||
| 530 | * @param array $_course |
||
| 531 | * @param string $path |
||
| 532 | * @param int $to_group_id |
||
| 533 | * @param int $to_user_id |
||
| 534 | * @param boolean $can_see_invisible |
||
| 535 | * @param boolean $search |
||
| 536 | * @return array with all document data |
||
| 537 | */ |
||
| 538 | public static function get_all_document_data( |
||
| 734 | |||
| 735 | /** |
||
| 736 | * Gets the paths of all folders in a course |
||
| 737 | * can show all folders (except for the deleted ones) or only visible ones |
||
| 738 | * |
||
| 739 | * @param array $_course |
||
| 740 | * @param int $to_group_id |
||
| 741 | * @param boolean $can_see_invisible |
||
| 742 | * |
||
| 743 | * @return array with paths |
||
| 744 | */ |
||
| 745 | public static function get_all_document_folders( |
||
| 917 | |||
| 918 | /** |
||
| 919 | * This check if a document has the readonly property checked, then see if the user |
||
| 920 | * is the owner of this file, if all this is true then return true. |
||
| 921 | * |
||
| 922 | * @param array $_course |
||
| 923 | * @param int $user_id id of the current user |
||
| 924 | * @param string $file path stored in the database (if not defined, $documentId must be used) |
||
| 925 | * @param int $document_id in case you dont have the file path , |
||
| 926 | * insert the id of the file here and leave $file in blank '' |
||
| 927 | * @param bool $to_delete |
||
| 928 | * @param int $sessionId |
||
| 929 | * @return boolean true/false |
||
| 930 | * */ |
||
| 931 | public static function check_readonly( |
||
| 1011 | |||
| 1012 | /** |
||
| 1013 | * This check if a document is a folder or not |
||
| 1014 | * @param array $_course |
||
| 1015 | * @param int $document_id of the item |
||
| 1016 | * @return boolean true/false |
||
| 1017 | * */ |
||
| 1018 | public static function is_folder($_course, $document_id) |
||
| 1028 | |||
| 1029 | /** |
||
| 1030 | * @param int $document_id |
||
| 1031 | * @param array $course_info |
||
| 1032 | * @param int $session_id |
||
| 1033 | * @param bool $remove_content_from_db |
||
| 1034 | */ |
||
| 1035 | public static function deleteDocumentFromDb( |
||
| 1086 | |||
| 1087 | /** |
||
| 1088 | * This deletes a document by changing visibility to 2, renaming it to filename_DELETED_#id |
||
| 1089 | * Files/folders that are inside a deleted folder get visibility 2 |
||
| 1090 | * |
||
| 1091 | * @param array $_course |
||
| 1092 | * @param string $path, path stored in the database |
||
| 1093 | * @param string $base_work_dir, path to the documents folder (if not defined, $documentId must be used) |
||
| 1094 | * @param int $sessionId The ID of the session, if any |
||
| 1095 | * @param int $documentId The document id, if available |
||
| 1096 | * @param int $groupId |
||
| 1097 | * @return boolean true/false |
||
| 1098 | * @todo now only files/folders in a folder get visibility 2, we should rename them too. |
||
| 1099 | * @todo We should be able to get rid of this later when using only documentId (check further usage) |
||
| 1100 | */ |
||
| 1101 | public static function delete_document( |
||
| 1294 | |||
| 1295 | /** |
||
| 1296 | * Removes documents from search engine database |
||
| 1297 | * |
||
| 1298 | * @param string $course_id Course code |
||
| 1299 | * @param int $document_id Document id to delete |
||
| 1300 | */ |
||
| 1301 | View Code Duplication | public static function delete_document_from_search_engine($course_id, $document_id) |
|
| 1324 | |||
| 1325 | /** |
||
| 1326 | * Gets the id of a document with a given path |
||
| 1327 | * |
||
| 1328 | * @param array $courseInfo |
||
| 1329 | * @param string $path |
||
| 1330 | * @param int $sessionId |
||
| 1331 | * @return int id of document / false if no doc found |
||
| 1332 | */ |
||
| 1333 | public static function get_document_id($courseInfo, $path, $sessionId = null) |
||
| 1363 | |||
| 1364 | /** |
||
| 1365 | * Gets the document data with a given id |
||
| 1366 | * |
||
| 1367 | * @param int $id Document Id (id field in c_document table) |
||
| 1368 | * @param string $course_code Course code |
||
| 1369 | * @param bool $load_parents load folder parents. |
||
| 1370 | * @param int $session_id The session ID, |
||
| 1371 | * 0 if requires context *out of* session, and null to use global context |
||
| 1372 | * @return array document content |
||
| 1373 | */ |
||
| 1374 | public static function get_document_data_by_id( |
||
| 1465 | |||
| 1466 | /** |
||
| 1467 | * Allow to set a specific document as a new template for CKeditor |
||
| 1468 | * for a particular user in a particular course |
||
| 1469 | * |
||
| 1470 | * @param string $title |
||
| 1471 | * @param string $description |
||
| 1472 | * @param int $document_id_for_template the document id |
||
| 1473 | * @param string $course_code |
||
| 1474 | * @param int $user_id |
||
| 1475 | * @return bool |
||
| 1476 | */ |
||
| 1477 | public static function set_document_as_template($title, $description, $document_id_for_template, $course_code, $user_id, $image) |
||
| 1492 | |||
| 1493 | /** |
||
| 1494 | * Unset a document as template |
||
| 1495 | * |
||
| 1496 | * @param int $document_id |
||
| 1497 | * @param string $course_code |
||
| 1498 | * @param int $user_id |
||
| 1499 | */ |
||
| 1500 | public static function unset_document_as_template($document_id, $course_code, $user_id) |
||
| 1525 | |||
| 1526 | /** |
||
| 1527 | * Return true if the documentpath have visibility=1 as |
||
| 1528 | * item_property (you should use the is_visible_by_id) |
||
| 1529 | * |
||
| 1530 | * @param string $document_path the relative complete path of the document |
||
| 1531 | * @param array $course the _course array info of the document's course |
||
| 1532 | * @param int |
||
| 1533 | * @param string |
||
| 1534 | * @return bool |
||
| 1535 | */ |
||
| 1536 | public static function is_visible($doc_path, $course, $session_id = 0, $file_type = 'file') |
||
| 1606 | |||
| 1607 | /** |
||
| 1608 | * Return true if user can see a file |
||
| 1609 | * |
||
| 1610 | * @param int document id |
||
| 1611 | * @param array course info |
||
| 1612 | * @param int |
||
| 1613 | * @param int |
||
| 1614 | * @param bool |
||
| 1615 | * @return bool |
||
| 1616 | */ |
||
| 1617 | public static function is_visible_by_id( |
||
| 1726 | |||
| 1727 | /** |
||
| 1728 | * Allow attach a certificate to a course |
||
| 1729 | * @param string $course_id |
||
| 1730 | * @param int $document_id |
||
| 1731 | * @param int $session_id |
||
| 1732 | * |
||
| 1733 | * @return void() |
||
| 1734 | */ |
||
| 1735 | public static function attach_gradebook_certificate($course_id, $document_id, $session_id = 0) |
||
| 1754 | |||
| 1755 | /** |
||
| 1756 | * get the document id of default certificate |
||
| 1757 | * @param string $course_id |
||
| 1758 | * @param int $session_id |
||
| 1759 | * |
||
| 1760 | * @return int The default certificate id |
||
| 1761 | */ |
||
| 1762 | public static function get_default_certificate_id($course_id, $session_id = 0) |
||
| 1789 | |||
| 1790 | /** |
||
| 1791 | * allow replace user info in file html |
||
| 1792 | * @param int $user_id |
||
| 1793 | * @param string $course_code |
||
| 1794 | * @param int $sessionId |
||
| 1795 | * @param bool $is_preview |
||
| 1796 | * @return string The html content of the certificate |
||
| 1797 | */ |
||
| 1798 | public static function replace_user_info_into_html($user_id, $course_code, $sessionId, $is_preview = false) |
||
| 1841 | |||
| 1842 | /** |
||
| 1843 | * Return all content to replace and all content to be replace |
||
| 1844 | * @param int $user_id |
||
| 1845 | * @param int $course_id |
||
| 1846 | * @param bool $is_preview |
||
| 1847 | * @return array |
||
| 1848 | */ |
||
| 1849 | static function get_all_info_to_certificate($user_id, $course_id, $is_preview = false) |
||
| 1953 | |||
| 1954 | /** |
||
| 1955 | * Remove default certificate |
||
| 1956 | * @param string $course_id The course code |
||
| 1957 | * @param int $default_certificate_id The document id of the default certificate |
||
| 1958 | * @return void() |
||
| 1959 | */ |
||
| 1960 | public static function remove_attach_certificate($course_id, $default_certificate_id) |
||
| 1985 | |||
| 1986 | /** |
||
| 1987 | * Create directory certificate |
||
| 1988 | * @param string $courseCode |
||
| 1989 | * @return void() |
||
| 1990 | */ |
||
| 1991 | public static function create_directory_certificate_in_course($courseCode) |
||
| 2051 | |||
| 2052 | /** |
||
| 2053 | * Get the document id of the directory certificate |
||
| 2054 | * @return int The document id of the directory certificate |
||
| 2055 | */ |
||
| 2056 | public static function get_document_id_of_directory_certificate() |
||
| 2065 | |||
| 2066 | /** |
||
| 2067 | * Check if a directory given is for certificate |
||
| 2068 | * @param string $dir path of directory |
||
| 2069 | * @return bool true if is a certificate or false otherwise |
||
| 2070 | */ |
||
| 2071 | public static function is_certificate_mode($dir) |
||
| 2082 | |||
| 2083 | /** |
||
| 2084 | * Gets the list of included resources as a list of absolute or relative paths from a html file or string html |
||
| 2085 | * This allows for a better SCORM export or replace urls inside content html from copy course |
||
| 2086 | * The list will generally include pictures, flash objects, java applets, or any other |
||
| 2087 | * stuff included in the source of the current item. The current item is expected |
||
| 2088 | * to be an HTML file or string html. If it is not, then the function will return and empty list. |
||
| 2089 | * @param string source html (content or path) |
||
| 2090 | * @param bool is file or string html |
||
| 2091 | * @param string type (one of the app tools) - optional (otherwise takes the current item's type) |
||
| 2092 | * @param int level of recursivity we're in |
||
| 2093 | * @return array List of file paths. An additional field containing 'local' or 'remote' helps determine |
||
| 2094 | * if the file should be copied into the zip or just linked |
||
| 2095 | */ |
||
| 2096 | public static function get_resources_from_source_html($source_html, $is_file = false, $type = null, $recursivity = 1) |
||
| 2376 | |||
| 2377 | /** |
||
| 2378 | * Parses the HTML attributes given as string. |
||
| 2379 | * |
||
| 2380 | * @param string HTML attribute string |
||
| 2381 | * @param array List of attributes that we want to get back |
||
| 2382 | * @param array |
||
| 2383 | * @return array An associative array of attributes |
||
| 2384 | * @author Based on a function from the HTML_Common2 PEAR module * |
||
| 2385 | */ |
||
| 2386 | public static function parse_HTML_attributes($attrString, $wanted = array(), $explode_variables = array()) |
||
| 2467 | |||
| 2468 | /** |
||
| 2469 | * Replace urls inside content html from a copy course |
||
| 2470 | * @param string $content_html |
||
| 2471 | * @param string $origin_course_code |
||
| 2472 | * @param string $destination_course_directory |
||
| 2473 | * @param string $origin_course_path_from_zip |
||
| 2474 | * @param string $origin_course_info_path |
||
| 2475 | * |
||
| 2476 | * @return string new content html with replaced urls or return false if content is not a string |
||
| 2477 | */ |
||
| 2478 | static function replace_urls_inside_content_html_from_copy_course( |
||
| 2631 | |||
| 2632 | /** |
||
| 2633 | * Replace urls inside content html when moving a file |
||
| 2634 | * @todo this code is only called in document.php but is commented |
||
| 2635 | * @param string content html |
||
| 2636 | * @param string origin |
||
| 2637 | * @param string destination |
||
| 2638 | * @return string new content html with replaced urls or return false if content is not a string |
||
| 2639 | */ |
||
| 2640 | function replace_urls_inside_content_html_when_moving_file($file_name, $original_path, $destiny_path) |
||
| 2767 | |||
| 2768 | /** |
||
| 2769 | * @param int $document_id |
||
| 2770 | * @param string $course_code |
||
| 2771 | */ |
||
| 2772 | public static function export_to_pdf($document_id, $course_code) |
||
| 2780 | |||
| 2781 | /** |
||
| 2782 | * Uploads a document |
||
| 2783 | * |
||
| 2784 | * @param array $files the $_FILES variable |
||
| 2785 | * @param string $path |
||
| 2786 | * @param string $title |
||
| 2787 | * @param string $comment |
||
| 2788 | * @param int $unzip unzip or not the file |
||
| 2789 | * @param string $if_exists overwrite, rename or warn (default) |
||
| 2790 | * @param bool $index_document index document (search xapian module) |
||
| 2791 | * @param bool $show_output print html messages |
||
| 2792 | * @return array|bool |
||
| 2793 | */ |
||
| 2794 | public static function upload_document( |
||
| 2795 | $files, |
||
| 2796 | $path, |
||
| 2797 | $title = null, |
||
| 2798 | $comment = null, |
||
| 2799 | $unzip = 0, |
||
| 2800 | $if_exists = null, |
||
| 2801 | $index_document = false, |
||
| 2802 | $show_output = false, |
||
| 2803 | $fileKey = 'file' |
||
| 2804 | ) { |
||
| 2805 | $course_info = api_get_course_info(); |
||
| 2806 | $sessionId = api_get_session_id(); |
||
| 2807 | $course_dir = $course_info['path'] . '/document'; |
||
| 2808 | $sys_course_path = api_get_path(SYS_COURSE_PATH); |
||
| 2809 | $base_work_dir = $sys_course_path . $course_dir; |
||
| 2810 | |||
| 2811 | if (isset($files[$fileKey])) { |
||
| 2812 | $upload_ok = process_uploaded_file($files[$fileKey], $show_output); |
||
| 2813 | |||
| 2814 | if ($upload_ok) { |
||
| 2815 | // File got on the server without problems, now process it |
||
| 2816 | if ($title) { |
||
| 2817 | $titleAndExt = explode('.', $files[$fileKey]['name']); |
||
| 2818 | $ext = end($titleAndExt); |
||
| 2819 | $files[$fileKey]['name'] = $title.'.'.$ext; |
||
| 2820 | } |
||
| 2821 | $new_path = handle_uploaded_document( |
||
| 2822 | $course_info, |
||
| 2823 | $files[$fileKey], |
||
| 2824 | $base_work_dir, |
||
| 2825 | $path, |
||
| 2826 | api_get_user_id(), |
||
| 2827 | api_get_group_id(), |
||
| 2828 | null, |
||
| 2829 | $unzip, |
||
| 2830 | $if_exists, |
||
| 2831 | $show_output, |
||
| 2832 | false, |
||
| 2833 | null, |
||
| 2834 | $sessionId |
||
| 2835 | ); |
||
| 2836 | |||
| 2837 | if ($new_path) { |
||
| 2838 | $documentId = DocumentManager::get_document_id( |
||
| 2839 | $course_info, |
||
| 2840 | $new_path, |
||
| 2841 | $sessionId |
||
| 2842 | ); |
||
| 2843 | |||
| 2844 | if (!empty($documentId)) { |
||
| 2845 | $table_document = Database::get_course_table(TABLE_DOCUMENT); |
||
| 2846 | $params = array(); |
||
| 2847 | /*if ($if_exists == 'rename') { |
||
| 2848 | // Remove prefix |
||
| 2849 | $suffix = DocumentManager::getDocumentSuffix( |
||
| 2850 | $course_info, |
||
| 2851 | $sessionId, |
||
| 2852 | api_get_group_id() |
||
| 2853 | ); |
||
| 2854 | $new_path = basename($new_path); |
||
| 2855 | $new_path = str_replace($suffix, '', $new_path); |
||
| 2856 | error_log('renamed'); |
||
| 2857 | error_log($new_path); |
||
| 2858 | $params['title'] = get_document_title($new_path); |
||
| 2859 | } else { |
||
| 2860 | if (!empty($title)) { |
||
| 2861 | $params['title'] = get_document_title($title); |
||
| 2862 | } else { |
||
| 2863 | $params['title'] = get_document_title($files['file']['name']); |
||
| 2864 | } |
||
| 2865 | }*/ |
||
| 2866 | |||
| 2867 | if (!empty($comment)) { |
||
| 2868 | $params['comment'] = trim($comment); |
||
| 2869 | } |
||
| 2870 | |||
| 2871 | Database::update( |
||
| 2872 | $table_document, |
||
| 2873 | $params, |
||
| 2874 | array( |
||
| 2875 | 'id = ? AND c_id = ? ' => array( |
||
| 2876 | $documentId, |
||
| 2877 | $course_info['real_id'] |
||
| 2878 | ) |
||
| 2879 | ) |
||
| 2880 | ); |
||
| 2881 | } |
||
| 2882 | |||
| 2883 | // Showing message when sending zip files |
||
| 2884 | if ($new_path === true && $unzip == 1 && $show_output) { |
||
| 2885 | Display::display_confirmation_message( |
||
| 2886 | get_lang('UplUploadSucceeded') . '<br />', |
||
| 2887 | false |
||
| 2888 | ); |
||
| 2889 | } |
||
| 2890 | |||
| 2891 | if ($index_document) { |
||
| 2892 | self::index_document( |
||
| 2893 | $documentId, |
||
| 2894 | $course_info['code'], |
||
| 2895 | null, |
||
| 2896 | $_POST['language'], |
||
| 2897 | $_REQUEST, |
||
| 2898 | $if_exists |
||
| 2899 | ); |
||
| 2900 | } |
||
| 2901 | |||
| 2902 | View Code Duplication | if (!empty($documentId) && is_numeric($documentId)) { |
|
| 2903 | $documentData = self::get_document_data_by_id( |
||
| 2904 | $documentId, |
||
| 2905 | $course_info['code'], |
||
| 2906 | false, |
||
| 2907 | $sessionId |
||
| 2908 | ); |
||
| 2909 | |||
| 2910 | return $documentData; |
||
| 2911 | } |
||
| 2912 | } |
||
| 2913 | } |
||
| 2914 | } |
||
| 2915 | |||
| 2916 | return false; |
||
| 2917 | } |
||
| 2918 | |||
| 2919 | /** |
||
| 2920 | * Obtains the text inside the file with the right parser |
||
| 2921 | */ |
||
| 2922 | public static function get_text_content($doc_path, $doc_mime) |
||
| 2923 | { |
||
| 2924 | // TODO: review w$ compatibility |
||
| 2925 | // Use usual exec output lines array to store stdout instead of a temp file |
||
| 2926 | // because we need to store it at RAM anyway before index on ChamiloIndexer object |
||
| 2927 | $ret_val = null; |
||
| 2928 | switch ($doc_mime) { |
||
| 2929 | case 'text/plain': |
||
| 2930 | $handle = fopen($doc_path, 'r'); |
||
| 2931 | $output = array(fread($handle, filesize($doc_path))); |
||
| 2932 | fclose($handle); |
||
| 2933 | break; |
||
| 2934 | case 'application/pdf': |
||
| 2935 | exec("pdftotext $doc_path -", $output, $ret_val); |
||
| 2936 | break; |
||
| 2937 | case 'application/postscript': |
||
| 2938 | $temp_file = tempnam(sys_get_temp_dir(), 'chamilo'); |
||
| 2939 | exec("ps2pdf $doc_path $temp_file", $output, $ret_val); |
||
| 2940 | if ($ret_val !== 0) { // shell fail, probably 127 (command not found) |
||
| 2941 | return false; |
||
| 2942 | } |
||
| 2943 | exec("pdftotext $temp_file -", $output, $ret_val); |
||
| 2944 | unlink($temp_file); |
||
| 2945 | break; |
||
| 2946 | case 'application/msword': |
||
| 2947 | exec("catdoc $doc_path", $output, $ret_val); |
||
| 2948 | break; |
||
| 2949 | case 'text/html': |
||
| 2950 | exec("html2text $doc_path", $output, $ret_val); |
||
| 2951 | break; |
||
| 2952 | case 'text/rtf': |
||
| 2953 | // Note: correct handling of code pages in unrtf |
||
| 2954 | // on debian lenny unrtf v0.19.2 can not, but unrtf v0.20.5 can |
||
| 2955 | exec("unrtf --text $doc_path", $output, $ret_val); |
||
| 2956 | if ($ret_val == 127) { // command not found |
||
| 2957 | return false; |
||
| 2958 | } |
||
| 2959 | // Avoid index unrtf comments |
||
| 2960 | if (is_array($output) && count($output) > 1) { |
||
| 2961 | $parsed_output = array(); |
||
| 2962 | foreach ($output as & $line) { |
||
| 2963 | if (!preg_match('/^###/', $line, $matches)) { |
||
| 2964 | if (!empty($line)) { |
||
| 2965 | $parsed_output[] = $line; |
||
| 2966 | } |
||
| 2967 | } |
||
| 2968 | } |
||
| 2969 | $output = $parsed_output; |
||
| 2970 | } |
||
| 2971 | break; |
||
| 2972 | case 'application/vnd.ms-powerpoint': |
||
| 2973 | exec("catppt $doc_path", $output, $ret_val); |
||
| 2974 | break; |
||
| 2975 | case 'application/vnd.ms-excel': |
||
| 2976 | exec("xls2csv -c\" \" $doc_path", $output, $ret_val); |
||
| 2977 | break; |
||
| 2978 | } |
||
| 2979 | |||
| 2980 | $content = ''; |
||
| 2981 | if (!is_null($ret_val)) { |
||
| 2982 | if ($ret_val !== 0) { // shell fail, probably 127 (command not found) |
||
| 2983 | return false; |
||
| 2984 | } |
||
| 2985 | } |
||
| 2986 | if (isset($output)) { |
||
| 2987 | foreach ($output as & $line) { |
||
| 2988 | $content .= $line . "\n"; |
||
| 2989 | } |
||
| 2990 | return $content; |
||
| 2991 | } else { |
||
| 2992 | return false; |
||
| 2993 | } |
||
| 2994 | } |
||
| 2995 | |||
| 2996 | /** |
||
| 2997 | * Calculates the total size of all documents in a course |
||
| 2998 | * |
||
| 2999 | * @author Bert vanderkimpen |
||
| 3000 | * @param int $course_id |
||
| 3001 | * @param int $group_id (to calculate group document space) |
||
| 3002 | * @param int $session_id |
||
| 3003 | * |
||
| 3004 | * @return int total size |
||
| 3005 | */ |
||
| 3006 | static function documents_total_space($course_id = null, $group_id = null, $session_id = null) |
||
| 3007 | { |
||
| 3008 | $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); |
||
| 3009 | $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); |
||
| 3010 | |||
| 3011 | if (isset($course_id)) { |
||
| 3012 | $course_id = intval($course_id); |
||
| 3013 | } else { |
||
| 3014 | $course_id = api_get_course_int_id(); |
||
| 3015 | } |
||
| 3016 | |||
| 3017 | $group_condition = null; |
||
| 3018 | if (isset($group_id)) { |
||
| 3019 | $group_id = intval($group_id); |
||
| 3020 | $group_condition = " AND props.to_group_id='" . $group_id . "' "; |
||
| 3021 | } |
||
| 3022 | |||
| 3023 | $session_condition = null; |
||
| 3024 | if (isset($session_id)) { |
||
| 3025 | $session_id = intval($session_id); |
||
| 3026 | $session_condition = " AND props.session_id='" . $session_id . "' "; |
||
| 3027 | } |
||
| 3028 | |||
| 3029 | $sql = "SELECT SUM(size) |
||
| 3030 | FROM $TABLE_ITEMPROPERTY AS props |
||
| 3031 | INNER JOIN $TABLE_DOCUMENT AS docs |
||
| 3032 | ON (docs.id = props.ref AND props.c_id = docs.c_id) |
||
| 3033 | WHERE |
||
| 3034 | props.c_id = $course_id AND |
||
| 3035 | docs.c_id = $course_id AND |
||
| 3036 | props.tool = '" . TOOL_DOCUMENT . "' AND |
||
| 3037 | props.visibility <> 2 |
||
| 3038 | $group_condition |
||
| 3039 | $session_condition |
||
| 3040 | "; |
||
| 3041 | $result = Database::query($sql); |
||
| 3042 | |||
| 3043 | if ($result && Database::num_rows($result) != 0) { |
||
| 3044 | $row = Database::fetch_row($result); |
||
| 3045 | return $row[0]; |
||
| 3046 | } else { |
||
| 3047 | return 0; |
||
| 3048 | } |
||
| 3049 | } |
||
| 3050 | |||
| 3051 | /** |
||
| 3052 | * Here we count 1 Kilobyte = 1024 Bytes, 1 Megabyte = 1048576 Bytes |
||
| 3053 | */ |
||
| 3054 | static function display_quota($course_quota, $already_consumed_space) |
||
| 3055 | { |
||
| 3056 | $course_quota_m = round($course_quota / 1048576); |
||
| 3057 | $already_consumed_space_m = round($already_consumed_space / 1048576); |
||
| 3058 | |||
| 3059 | $message = get_lang('MaximumAllowedQuota') . ' <strong>' . $course_quota_m . ' megabyte</strong>.<br />'; |
||
| 3060 | $message .= get_lang('CourseCurrentlyUses') . ' <strong>' . $already_consumed_space_m . ' megabyte</strong>.<br />'; |
||
| 3061 | |||
| 3062 | $percentage = round(($already_consumed_space / $course_quota * 100), 1); |
||
| 3063 | |||
| 3064 | $other_percentage = $percentage < 100 ? 100 - $percentage : 0; |
||
| 3065 | |||
| 3066 | // Decide where to place percentage in graph |
||
| 3067 | if ($percentage >= 50) { |
||
| 3068 | $text_in_filled = ' ' . $other_percentage . '%'; |
||
| 3069 | $text_in_unfilled = ''; |
||
| 3070 | } else { |
||
| 3071 | $text_in_unfilled = ' ' . $other_percentage . '%'; |
||
| 3072 | $text_in_filled = ''; |
||
| 3073 | } |
||
| 3074 | |||
| 3075 | // Decide the background colour of the graph |
||
| 3076 | if ($percentage < 65) { |
||
| 3077 | $colour = '#00BB00'; // Safe - green |
||
| 3078 | } elseif ($percentage < 90) { |
||
| 3079 | $colour = '#ffd400'; // Filling up - yelloworange |
||
| 3080 | } else { |
||
| 3081 | $colour = '#DD0000'; // Full - red |
||
| 3082 | } |
||
| 3083 | |||
| 3084 | // This is used for the table width: a table of only 100 pixels looks too small |
||
| 3085 | $visual_percentage = 4 * $percentage; |
||
| 3086 | $visual_other_percentage = 4 * $other_percentage; |
||
| 3087 | |||
| 3088 | $message .= get_lang('PercentageQuotaInUse') . ': <strong>' . $percentage . '%</strong>.<br />' . |
||
| 3089 | get_lang('PercentageQuotaFree') . ': <strong>' . $other_percentage . '%</strong>.<br />'; |
||
| 3090 | |||
| 3091 | $show_percentage = ' ' . $percentage . '%'; |
||
| 3092 | $message .= '<div style="width: 80%; text-align: center; -moz-border-radius: 5px 5px 5px 5px; border: 1px solid #aaa; background-image: url(\'' . api_get_path(WEB_CODE_PATH) . 'css/' . api_get_visual_theme() . '/images/bg-header4.png\');" class="document-quota-bar">' . |
||
| 3093 | '<div style="width:' . $percentage . '%; background-color: #bbb; border-right:3px groove #bbb; -moz-border-radius:5px;"> </div>' . |
||
| 3094 | '<span style="margin-top: -15px; margin-left:-15px; position: absolute;font-weight:bold;">' . $show_percentage . '</span></div>'; |
||
| 3095 | echo $message; |
||
| 3096 | } |
||
| 3097 | |||
| 3098 | /** |
||
| 3099 | * Display the document quota in a simple way |
||
| 3100 | * |
||
| 3101 | * Here we count 1 Kilobyte = 1024 Bytes, 1 Megabyte = 1048576 Bytes |
||
| 3102 | */ |
||
| 3103 | static function display_simple_quota($course_quota, $already_consumed_space) |
||
| 3104 | { |
||
| 3105 | $course_quota_m = round($course_quota / 1048576); |
||
| 3106 | $already_consumed_space_m = round($already_consumed_space / 1048576, 2); |
||
| 3107 | $percentage = $already_consumed_space / $course_quota * 100; |
||
| 3108 | $percentage = round($percentage, 1); |
||
| 3109 | $message = get_lang('YouAreCurrentlyUsingXOfYourX'); |
||
| 3110 | $message = sprintf($message, $already_consumed_space_m, $percentage . '%', $course_quota_m . ' '); |
||
| 3111 | echo Display::div($message, array('id' => 'document_quota')); |
||
| 3112 | } |
||
| 3113 | |||
| 3114 | /** |
||
| 3115 | * Checks if there is enough place to add a file on a directory |
||
| 3116 | * on the base of a maximum directory size allowed |
||
| 3117 | * |
||
| 3118 | * @author Bert Vanderkimpen |
||
| 3119 | * @param int $file_size size of the file in byte |
||
| 3120 | * @param int $max_dir_space maximum size |
||
| 3121 | * @return boolean true if there is enough space, false otherwise |
||
| 3122 | * |
||
| 3123 | * @see enough_space() uses documents_total_space() function |
||
| 3124 | */ |
||
| 3125 | static function enough_space($file_size, $max_dir_space) { |
||
| 3126 | if ($max_dir_space) { |
||
| 3127 | $already_filled_space = self::documents_total_space(); |
||
| 3128 | if (($file_size + $already_filled_space) > $max_dir_space) { |
||
| 3129 | return false; |
||
| 3130 | } |
||
| 3131 | } |
||
| 3132 | return true; |
||
| 3133 | } |
||
| 3134 | |||
| 3135 | /** |
||
| 3136 | * @param array $params count, url, extension |
||
| 3137 | * @return string |
||
| 3138 | */ |
||
| 3139 | static function generate_jplayer_jquery($params = array()) |
||
| 3140 | { |
||
| 3141 | $js_path = api_get_path(WEB_LIBRARY_PATH) . 'javascript/'; |
||
| 3142 | |||
| 3143 | $js = ' |
||
| 3144 | $("#jquery_jplayer_' . $params['count'] . '").jPlayer({ |
||
| 3145 | ready: function() { |
||
| 3146 | $(this).jPlayer("setMedia", { |
||
| 3147 | ' . $params['extension'] . ' : "' . $params['url'] . '" |
||
| 3148 | }); |
||
| 3149 | }, |
||
| 3150 | play: function() { // To avoid both jPlayers playing together. |
||
| 3151 | $(this).jPlayer("pauseOthers"); |
||
| 3152 | }, |
||
| 3153 | //errorAlerts: true, |
||
| 3154 | //warningAlerts: true, |
||
| 3155 | swfPath: "' . $js_path . 'jquery-jplayer/jplayer/", |
||
| 3156 | //supplied: "m4a, oga, mp3, ogg, wav", |
||
| 3157 | supplied: "' . $params['extension'] . '", |
||
| 3158 | wmode: "window", |
||
| 3159 | solution: "flash, html", // Do not change this setting |
||
| 3160 | cssSelectorAncestor: "#jp_container_' . $params['count'] . '", |
||
| 3161 | }); ' . "\n\n"; |
||
| 3162 | |||
| 3163 | return $js; |
||
| 3164 | } |
||
| 3165 | |||
| 3166 | /** |
||
| 3167 | * |
||
| 3168 | * Shows a play icon next to the document title in the document list |
||
| 3169 | * @param int |
||
| 3170 | * @param string |
||
| 3171 | * @return string html content |
||
| 3172 | */ |
||
| 3173 | static function generate_media_preview($i, $type = 'simple') |
||
| 3174 | { |
||
| 3175 | $i = intval($i); |
||
| 3176 | |||
| 3177 | $extra_controls = $progress = ''; |
||
| 3178 | if ($type == 'advanced') { |
||
| 3179 | $extra_controls = ' <li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li> |
||
| 3180 | <li><a href="#" class="jp-mute" tabindex="1">mute</a></li> |
||
| 3181 | <li><a href="#" class="jp-unmute" tabindex="1">unmute</a></li>'; |
||
| 3182 | $progress = '<div class="jp-progress"> |
||
| 3183 | <div class="jp-seek-bar"> |
||
| 3184 | <div class="jp-play-bar"></div> |
||
| 3185 | </div> |
||
| 3186 | </div>'; |
||
| 3187 | } |
||
| 3188 | |||
| 3189 | //Shows only the play button |
||
| 3190 | $html = '<div id="jquery_jplayer_' . $i . '" class="jp-jplayer"></div> |
||
| 3191 | <div id="jp_container_' . $i . '" class="jp-audio"> |
||
| 3192 | <div class="jp-type-single"> |
||
| 3193 | <div class="jp-gui jp-interface"> |
||
| 3194 | <ul class="jp-controls"> |
||
| 3195 | <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li> |
||
| 3196 | <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li> |
||
| 3197 | ' . $extra_controls . ' |
||
| 3198 | </ul> |
||
| 3199 | ' . $progress . ' |
||
| 3200 | </div> |
||
| 3201 | </div> |
||
| 3202 | </div>'; |
||
| 3203 | //<div id="jplayer_inspector_'.$i.'"></div> |
||
| 3204 | return $html; |
||
| 3205 | } |
||
| 3206 | |||
| 3207 | /** |
||
| 3208 | * @param array $document_data |
||
| 3209 | * @return string |
||
| 3210 | */ |
||
| 3211 | public static function generate_video_preview($document_data = array()) |
||
| 3212 | { |
||
| 3213 | //<button class="jp-video-play-icon" role="button" tabindex="0">play</button> |
||
| 3214 | $html = ' |
||
| 3215 | <div id="jp_container_1" class="jp-video center-block" role="application" aria-label="media player"> |
||
| 3216 | <div class="jp-type-single"> |
||
| 3217 | <div id="jquery_jplayer_1" class="jp-jplayer"></div> |
||
| 3218 | <div class="jp-gui"> |
||
| 3219 | <div class="jp-video-play"> |
||
| 3220 | </div> |
||
| 3221 | <div class="jp-interface"> |
||
| 3222 | <div class="jp-progress"> |
||
| 3223 | <div class="jp-seek-bar"> |
||
| 3224 | <div class="jp-play-bar"></div> |
||
| 3225 | </div> |
||
| 3226 | </div> |
||
| 3227 | <div class="jp-current-time" role="timer" aria-label="time"> </div> |
||
| 3228 | <div class="jp-duration" role="timer" aria-label="duration"> </div> |
||
| 3229 | <div class="jp-controls-holder"> |
||
| 3230 | <div class="jp-controls"> |
||
| 3231 | <button class="jp-play" role="button" tabindex="0">play</button> |
||
| 3232 | <button class="jp-stop" role="button" tabindex="0">stop</button> |
||
| 3233 | </div> |
||
| 3234 | <div class="jp-volume-controls"> |
||
| 3235 | <button class="jp-mute" role="button" tabindex="0">mute</button> |
||
| 3236 | <button class="jp-volume-max" role="button" tabindex="0">max volume</button> |
||
| 3237 | <div class="jp-volume-bar"> |
||
| 3238 | <div class="jp-volume-bar-value"></div> |
||
| 3239 | </div> |
||
| 3240 | </div> |
||
| 3241 | <div class="jp-toggles"> |
||
| 3242 | <button class="jp-repeat" role="button" tabindex="0">repeat</button> |
||
| 3243 | <button class="jp-full-screen" role="button" tabindex="0">full screen</button> |
||
| 3244 | </div> |
||
| 3245 | </div> |
||
| 3246 | <div class="jp-details"> |
||
| 3247 | <div class="jp-title" aria-label="title"> </div> |
||
| 3248 | </div> |
||
| 3249 | </div> |
||
| 3250 | </div> |
||
| 3251 | <div class="jp-no-solution"> |
||
| 3252 | <span>' . get_lang('UpdateRequire') . '</span> |
||
| 3253 | ' . get_lang("ToPlayTheMediaYouWillNeedToUpdateYourBrowserToARecentVersionYouCanAlsoDownloadTheFile") . ' |
||
| 3254 | </div> |
||
| 3255 | </div> |
||
| 3256 | </div>'; |
||
| 3257 | return $html; |
||
| 3258 | } |
||
| 3259 | |||
| 3260 | /** |
||
| 3261 | * @param array $course_info |
||
| 3262 | * @param bool $lp_id |
||
| 3263 | * @param string $target |
||
| 3264 | * @param int $session_id |
||
| 3265 | * @param bool $add_move_button |
||
| 3266 | * @param string $filter_by_folder |
||
| 3267 | * @param string $overwrite_url |
||
| 3268 | * @param bool $showInvisibleFiles |
||
| 3269 | * @param bool $showOnlyFolders |
||
| 3270 | * @param int $folderId |
||
| 3271 | * @return string |
||
| 3272 | */ |
||
| 3273 | public static function get_document_preview( |
||
| 3274 | $course_info, |
||
| 3275 | $lp_id = false, |
||
| 3276 | $target = '', |
||
| 3277 | $session_id = 0, |
||
| 3278 | $add_move_button = false, |
||
| 3279 | $filter_by_folder = null, |
||
| 3280 | $overwrite_url = null, |
||
| 3281 | $showInvisibleFiles = false, |
||
| 3282 | $showOnlyFolders = false, |
||
| 3283 | $folderId = false |
||
| 3284 | ) { |
||
| 3285 | if (empty($course_info['real_id']) || empty($course_info['code']) || !is_array($course_info)) { |
||
| 3286 | return ''; |
||
| 3287 | } |
||
| 3288 | |||
| 3289 | $overwrite_url = Security::remove_XSS($overwrite_url); |
||
| 3290 | $user_id = api_get_user_id(); |
||
| 3291 | $user_in_course = false; |
||
| 3292 | |||
| 3293 | if (api_is_platform_admin()) { |
||
| 3294 | $user_in_course = true; |
||
| 3295 | } |
||
| 3296 | |||
| 3297 | if (!$user_in_course) { |
||
| 3298 | if (CourseManager::is_course_teacher($user_id, $course_info['code'])) { |
||
| 3299 | $user_in_course = true; |
||
| 3300 | } |
||
| 3301 | } |
||
| 3302 | |||
| 3303 | // Condition for the session |
||
| 3304 | $session_id = intval($session_id); |
||
| 3305 | |||
| 3306 | if (!$user_in_course) { |
||
| 3307 | if (empty($session_id)) { |
||
| 3308 | if (CourseManager::is_user_subscribed_in_course($user_id, $course_info['code'])) { |
||
| 3309 | $user_in_course = true; |
||
| 3310 | } |
||
| 3311 | // Check if course is open then we can consider that the student is registered to the course |
||
| 3312 | if (isset($course_info) && in_array($course_info['visibility'], array(2, 3))) { |
||
| 3313 | $user_in_course = true; |
||
| 3314 | } |
||
| 3315 | View Code Duplication | } else { |
|
| 3316 | $user_status = SessionManager::get_user_status_in_course_session( |
||
| 3317 | $user_id, |
||
| 3318 | $course_info['real_id'], |
||
| 3319 | $session_id |
||
| 3320 | ); |
||
| 3321 | //is true if is an student, course session teacher or coach |
||
| 3322 | if (in_array($user_status, array('0', '2', '6'))) { |
||
| 3323 | $user_in_course = true; |
||
| 3324 | } |
||
| 3325 | } |
||
| 3326 | } |
||
| 3327 | |||
| 3328 | $tbl_doc = Database::get_course_table(TABLE_DOCUMENT); |
||
| 3329 | $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY); |
||
| 3330 | $condition_session = " AND (last.session_id = '$session_id' OR last.session_id = '0' OR last.session_id IS NULL)"; |
||
| 3331 | |||
| 3332 | $add_folder_filter = null; |
||
| 3333 | if (!empty($filter_by_folder)) { |
||
| 3334 | $add_folder_filter = " AND docs.path LIKE '" . Database::escape_string($filter_by_folder) . "%'"; |
||
| 3335 | } |
||
| 3336 | |||
| 3337 | // If we are in LP display hidden folder https://support.chamilo.org/issues/6679 |
||
| 3338 | $lp_visibility_condition = null; |
||
| 3339 | if ($lp_id) { |
||
| 3340 | // $lp_visibility_condition = " OR filetype='folder'"; |
||
| 3341 | if ($showInvisibleFiles) { |
||
| 3342 | $lp_visibility_condition .= ' OR last.visibility = 0'; |
||
| 3343 | } |
||
| 3344 | } |
||
| 3345 | |||
| 3346 | $showOnlyFoldersCondition = null; |
||
| 3347 | if ($showOnlyFolders) { |
||
| 3348 | //$showOnlyFoldersCondition = " AND docs.filetype = 'folder' "; |
||
| 3349 | } |
||
| 3350 | |||
| 3351 | $folderCondition = " AND docs.path LIKE '/%' "; |
||
| 3352 | |||
| 3353 | if (!api_is_allowed_to_edit()) { |
||
| 3354 | $protectedFolders = self::getProtectedFolderFromStudent(); |
||
| 3355 | foreach ($protectedFolders as $folder) { |
||
| 3356 | $folderCondition .= " AND docs.path NOT LIKE '$folder' "; |
||
| 3357 | } |
||
| 3358 | } |
||
| 3359 | |||
| 3360 | $parentData = []; |
||
| 3361 | if ($folderId !== false) { |
||
| 3362 | $parentData = self::get_document_data_by_id($folderId, $course_info['code']); |
||
| 3363 | if (!empty($parentData)) { |
||
| 3364 | $cleanedPath = $parentData['path']; |
||
| 3365 | $num = substr_count($cleanedPath, '/'); |
||
| 3366 | |||
| 3367 | $notLikeCondition = null; |
||
| 3368 | for ($i = 1; $i <= $num; $i++) { |
||
| 3369 | $repeat = str_repeat('/%', $i+1); |
||
| 3370 | $notLikeCondition .= " AND docs.path NOT LIKE '".Database::escape_string($cleanedPath.$repeat)."' "; |
||
| 3371 | } |
||
| 3372 | |||
| 3373 | $folderCondition = " AND |
||
| 3374 | docs.id <> $folderId AND |
||
| 3375 | docs.path LIKE '".$cleanedPath."/%' |
||
| 3376 | $notLikeCondition |
||
| 3377 | "; |
||
| 3378 | } else { |
||
| 3379 | $folderCondition = " AND |
||
| 3380 | docs.filetype = 'file' "; |
||
| 3381 | } |
||
| 3382 | } |
||
| 3383 | |||
| 3384 | $levelCondition = null; |
||
| 3385 | if ($folderId === false) { |
||
| 3386 | $levelCondition = " AND docs.path NOT LIKE'/%/%'"; |
||
| 3387 | } |
||
| 3388 | |||
| 3389 | $sql = "SELECT last.visibility, docs.* |
||
| 3390 | FROM $tbl_item_prop AS last INNER JOIN $tbl_doc AS docs |
||
| 3391 | ON (docs.id = last.ref AND docs.c_id = last.c_id) |
||
| 3392 | WHERE |
||
| 3393 | docs.path NOT LIKE '%_DELETED_%' AND |
||
| 3394 | last.tool = '" . TOOL_DOCUMENT . "' $condition_session AND |
||
| 3395 | (last.visibility = '1' $lp_visibility_condition) AND |
||
| 3396 | last.visibility <> 2 AND |
||
| 3397 | docs.c_id = {$course_info['real_id']} AND |
||
| 3398 | last.c_id = {$course_info['real_id']} |
||
| 3399 | $showOnlyFoldersCondition |
||
| 3400 | $folderCondition |
||
| 3401 | $levelCondition |
||
| 3402 | $add_folder_filter |
||
| 3403 | ORDER BY docs.filetype DESC, docs.title ASC"; |
||
| 3404 | |||
| 3405 | $res_doc = Database::query($sql); |
||
| 3406 | $resources = Database::store_result($res_doc, 'ASSOC'); |
||
| 3407 | |||
| 3408 | $return = ''; |
||
| 3409 | if ($lp_id) { |
||
| 3410 | if ($folderId === false) { |
||
| 3411 | $return .= '<div class="lp_resource_element">'; |
||
| 3412 | $return .= Display::return_icon('new_doc.gif', '', array(), ICON_SIZE_SMALL); |
||
| 3413 | $return .= Display::url( |
||
| 3414 | get_lang('NewDocument'), |
||
| 3415 | api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_DOCUMENT.'&lp_id='.$_SESSION['oLP']->lp_id |
||
| 3416 | ); |
||
| 3417 | $return .= '</div>'; |
||
| 3418 | } |
||
| 3419 | } else { |
||
| 3420 | $return .= Display::div( |
||
| 3421 | Display::url( |
||
| 3422 | Display::return_icon('close.png', get_lang('Close'), array(), ICON_SIZE_SMALL), |
||
| 3423 | ' javascript:void(0);', |
||
| 3424 | array('id' => 'close_div_' . $course_info['real_id'] . '_' . $session_id, 'class' => 'close_div') |
||
| 3425 | ), |
||
| 3426 | array('style' => 'position:absolute;right:10px') |
||
| 3427 | ); |
||
| 3428 | } |
||
| 3429 | |||
| 3430 | // If you want to debug it, I advise you to do "echo" on the eval statements. |
||
| 3431 | $newResources = array(); |
||
| 3432 | |||
| 3433 | if (!empty($resources) && $user_in_course) { |
||
| 3434 | foreach ($resources as $resource) { |
||
| 3435 | $is_visible = self::is_visible_by_id( |
||
| 3436 | $resource['id'], |
||
| 3437 | $course_info, |
||
| 3438 | $session_id, |
||
| 3439 | api_get_user_id() |
||
| 3440 | ); |
||
| 3441 | |||
| 3442 | if (!$is_visible) { |
||
| 3443 | continue; |
||
| 3444 | } |
||
| 3445 | $newResources[] = $resource; |
||
| 3446 | } |
||
| 3447 | } |
||
| 3448 | |||
| 3449 | $label = get_lang('Documents'); |
||
| 3450 | |||
| 3451 | $documents = []; |
||
| 3452 | if ($folderId === false) { |
||
| 3453 | $documents[$label] = array( |
||
| 3454 | 'id' => 0, |
||
| 3455 | 'files' => $newResources |
||
| 3456 | ); |
||
| 3457 | } else { |
||
| 3458 | if (!empty($parentData)) { |
||
| 3459 | $documents[$parentData['title']] = array( |
||
| 3460 | 'id' => intval($folderId), |
||
| 3461 | 'files' => $newResources |
||
| 3462 | ); |
||
| 3463 | } |
||
| 3464 | } |
||
| 3465 | |||
| 3466 | $write_result = self::write_resources_tree( |
||
| 3467 | $course_info, |
||
| 3468 | $session_id, |
||
| 3469 | $documents, |
||
| 3470 | $lp_id, |
||
| 3471 | $target, |
||
| 3472 | $add_move_button, |
||
| 3473 | $overwrite_url, |
||
| 3474 | $folderId |
||
| 3475 | ); |
||
| 3476 | |||
| 3477 | $return .= $write_result; |
||
| 3478 | if ($lp_id == false) { |
||
| 3479 | $url = api_get_path(WEB_AJAX_PATH).'lp.ajax.php?a=get_documents&url='.$overwrite_url.'&lp_id='.$lp_id.'&cidReq='.$course_info['code']; |
||
| 3480 | $return .= "<script> |
||
| 3481 | $('.doc_folder').click(function() { |
||
| 3482 | var realId = this.id; |
||
| 3483 | var my_id = this.id.split('_')[2]; |
||
| 3484 | var tempId = 'temp_'+my_id; |
||
| 3485 | $('#res_'+my_id).show(); |
||
| 3486 | |||
| 3487 | var tempDiv = $('#'+realId).find('#'+tempId); |
||
| 3488 | if (tempDiv.length == 0) { |
||
| 3489 | $.ajax({ |
||
| 3490 | async: false, |
||
| 3491 | type: 'GET', |
||
| 3492 | url: '".$url."', |
||
| 3493 | data: 'folder_id='+my_id, |
||
| 3494 | success: function(data) { |
||
| 3495 | $('#'+realId).append('<div id='+tempId+'>'+data+'</div>'); |
||
| 3496 | } |
||
| 3497 | }); |
||
| 3498 | } |
||
| 3499 | }); |
||
| 3500 | |||
| 3501 | $('.close_div').click(function() { |
||
| 3502 | var course_id = this.id.split('_')[2]; |
||
| 3503 | var session_id = this.id.split('_')[3]; |
||
| 3504 | $('#document_result_'+course_id+'_'+session_id).hide(); |
||
| 3505 | $('.lp_resource').remove(); |
||
| 3506 | $('.document_preview_container').html(''); |
||
| 3507 | }); |
||
| 3508 | |||
| 3509 | </script>"; |
||
| 3510 | View Code Duplication | } else { |
|
| 3511 | //For LPs |
||
| 3512 | $url = api_get_path(WEB_AJAX_PATH).'lp.ajax.php?a=get_documents&lp_id='.$lp_id.'&'.api_get_cidreq(); |
||
| 3513 | $return .= "<script> |
||
| 3514 | |||
| 3515 | function testResources(id, img) { |
||
| 3516 | var numericId = id.split('_')[1]; |
||
| 3517 | var parentId = 'doc_id_'+numericId; |
||
| 3518 | var tempId = 'temp_'+numericId; |
||
| 3519 | var image = $('#'+img); |
||
| 3520 | |||
| 3521 | if (image.hasClass('open')) { |
||
| 3522 | image.removeClass('open'); |
||
| 3523 | image.attr('src', '" . Display::returnIconPath('nolines_plus.gif')."'); |
||
| 3524 | $('#'+id).show(); |
||
| 3525 | $('#'+tempId).hide(); |
||
| 3526 | } else { |
||
| 3527 | image.addClass('open'); |
||
| 3528 | image.attr('src', '" . Display::returnIconPath('nolines_minus.gif') . "'); |
||
| 3529 | $('#'+id).hide(); |
||
| 3530 | $('#'+tempId).show(); |
||
| 3531 | |||
| 3532 | var tempDiv = $('#'+parentId).find('#'+tempId); |
||
| 3533 | if (tempDiv.length == 0) { |
||
| 3534 | $.ajax({ |
||
| 3535 | type: 'GET', |
||
| 3536 | async: false, |
||
| 3537 | url: '".$url."', |
||
| 3538 | data: 'folder_id='+numericId, |
||
| 3539 | success: function(data) { |
||
| 3540 | tempDiv = $('#doc_id_'+numericId).append('<div id='+tempId+'>'+data+'</div>'); |
||
| 3541 | } |
||
| 3542 | }); |
||
| 3543 | } |
||
| 3544 | } |
||
| 3545 | } |
||
| 3546 | </script>"; |
||
| 3547 | } |
||
| 3548 | |||
| 3549 | if (!$user_in_course) { |
||
| 3550 | $return = ''; |
||
| 3551 | } |
||
| 3552 | |||
| 3553 | return $return; |
||
| 3554 | } |
||
| 3555 | |||
| 3556 | /** |
||
| 3557 | * @param array $course_info |
||
| 3558 | * @param int $session_id |
||
| 3559 | * @param array $resource |
||
| 3560 | * @param int $lp_id |
||
| 3561 | * @param bool $add_move_button |
||
| 3562 | * @param string $target |
||
| 3563 | * @param string $overwrite_url |
||
| 3564 | * @return null|string |
||
| 3565 | */ |
||
| 3566 | private static function parseFile( |
||
| 3567 | $course_info, |
||
| 3568 | $session_id, |
||
| 3569 | $resource, |
||
| 3570 | $lp_id, |
||
| 3571 | $add_move_button, |
||
| 3572 | $target, |
||
| 3573 | $overwrite_url |
||
| 3574 | ) { |
||
| 3575 | $img_sys_path = api_get_path(SYS_CODE_PATH) . 'img/'; |
||
| 3576 | $web_code_path = api_get_path(WEB_CODE_PATH); |
||
| 3577 | |||
| 3578 | $documentId = $resource['id']; |
||
| 3579 | $path = $resource['path']; |
||
| 3580 | |||
| 3581 | if (empty($path)) { |
||
| 3582 | $num = 0; |
||
| 3583 | } else { |
||
| 3584 | $num = substr_count($path, '/') - 1; |
||
| 3585 | } |
||
| 3586 | |||
| 3587 | // It's a file. |
||
| 3588 | $icon = choose_image($path); |
||
| 3589 | $position = strrpos($icon, '.'); |
||
| 3590 | $icon = substr($icon, 0, $position) . '_small.gif'; |
||
| 3591 | $my_file_title = $resource['title']; |
||
| 3592 | $visibility = $resource['visibility']; |
||
| 3593 | |||
| 3594 | // If title is empty we try to use the path |
||
| 3595 | if (empty($my_file_title)) { |
||
| 3596 | $my_file_title = basename($path); |
||
| 3597 | } |
||
| 3598 | |||
| 3599 | // Show the "image name" not the filename of the image. |
||
| 3600 | if ($lp_id) { |
||
| 3601 | // LP URL |
||
| 3602 | $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&action=add_item&type=' . TOOL_DOCUMENT . '&file=' . $documentId . '&lp_id=' . $lp_id; |
||
| 3603 | View Code Duplication | if (!empty($overwrite_url)) { |
|
| 3604 | $url = $overwrite_url . '&cidReq=' . $course_info['code'] . '&id_session=' . $session_id . '&document_id=' . $documentId.''; |
||
| 3605 | } |
||
| 3606 | } else { |
||
| 3607 | // Direct document URL |
||
| 3608 | $url = $web_code_path . 'document/document.php?cidReq=' . $course_info['code'] . '&id_session=' . $session_id . '&id=' . $documentId; |
||
| 3609 | View Code Duplication | if (!empty($overwrite_url)) { |
|
| 3610 | $url = $overwrite_url . '&cidReq=' . $course_info['code'] . '&id_session=' . $session_id . '&document_id=' . $documentId; |
||
| 3611 | } |
||
| 3612 | } |
||
| 3613 | |||
| 3614 | $img = Display::returnIconPath($icon); |
||
| 3615 | if (!file_exists($img_sys_path . $icon)) { |
||
| 3616 | $img = Display::returnIconPath('default_small.gif'); |
||
| 3617 | } |
||
| 3618 | |||
| 3619 | $link = Display::url( |
||
| 3620 | '<img alt="" src="' . $img . '" title="" /> ' . $my_file_title, $url, |
||
| 3621 | array('target' => $target) |
||
| 3622 | ); |
||
| 3623 | |||
| 3624 | $visibilityClass = null; |
||
| 3625 | if ($visibility == 0) { |
||
| 3626 | $visibilityClass = ' invisible '; |
||
| 3627 | } |
||
| 3628 | $return = null; |
||
| 3629 | |||
| 3630 | if ($lp_id == false) { |
||
| 3631 | $return .= '<li class="doc_resource '.$visibilityClass.' " data_id="' . $documentId . '" data_type="document" title="' . $my_file_title . '" >'; |
||
| 3632 | } else { |
||
| 3633 | $return .= '<li class="doc_resource lp_resource_element '.$visibilityClass.' " data_id="' . $documentId . '" data_type="document" title="' . $my_file_title . '" >'; |
||
| 3634 | } |
||
| 3635 | |||
| 3636 | $return .= '<div class="item_data" style="margin-left:' . ($num * 18) . 'px;margin-right:5px;">'; |
||
| 3637 | |||
| 3638 | View Code Duplication | if ($add_move_button) { |
|
| 3639 | $return .= '<a class="moved" href="#">'; |
||
| 3640 | $return .= Display::return_icon('move_everywhere.png', get_lang('Move'), array(), ICON_SIZE_TINY); |
||
| 3641 | $return .= '</a> '; |
||
| 3642 | } |
||
| 3643 | $return .= $link; |
||
| 3644 | $return .= '</div></li>'; |
||
| 3645 | |||
| 3646 | return $return; |
||
| 3647 | } |
||
| 3648 | |||
| 3649 | /** |
||
| 3650 | * @param int $folderId |
||
| 3651 | * @param array $resource |
||
| 3652 | * @param int $lp_id |
||
| 3653 | * @return null|string |
||
| 3654 | */ |
||
| 3655 | private static function parseFolder($folderId, $resource, $lp_id) |
||
| 3656 | { |
||
| 3657 | $title = isset($resource['title']) ? $resource['title'] : null; |
||
| 3658 | $path = isset($resource['path']) ? $resource['path'] : null; |
||
| 3659 | |||
| 3660 | if (empty($path)) { |
||
| 3661 | $num = 0; |
||
| 3662 | } else { |
||
| 3663 | $num = substr_count($path, '/'); |
||
| 3664 | } |
||
| 3665 | |||
| 3666 | // It's a folder. |
||
| 3667 | //hide some folders |
||
| 3668 | if (in_array($path, |
||
| 3669 | array('shared_folder', 'chat_files', 'HotPotatoes_files', 'css', 'certificates'))) { |
||
| 3670 | return null; |
||
| 3671 | } elseif (preg_match('/_groupdocs/', $path)) { |
||
| 3672 | return null; |
||
| 3673 | } elseif (preg_match('/sf_user_/', $path)) { |
||
| 3674 | return null; |
||
| 3675 | } elseif (preg_match('/shared_folder_session_/', $path)) { |
||
| 3676 | return null; |
||
| 3677 | } |
||
| 3678 | |||
| 3679 | //trad some titles |
||
| 3680 | /* |
||
| 3681 | if ($key == 'images') { |
||
| 3682 | $key = get_lang('Images'); |
||
| 3683 | } elseif ($key == 'gallery') { |
||
| 3684 | $key = get_lang('Gallery'); |
||
| 3685 | } elseif ($key == 'flash') { |
||
| 3686 | $key = get_lang('Flash'); |
||
| 3687 | } elseif ($key == 'audio') { |
||
| 3688 | $key = get_lang('Audio'); |
||
| 3689 | } elseif ($key == 'video') { |
||
| 3690 | $key = get_lang('Video'); |
||
| 3691 | }*/ |
||
| 3692 | |||
| 3693 | $onclick = ''; |
||
| 3694 | |||
| 3695 | // if in LP, hidden folder are displayed in grey |
||
| 3696 | $folder_class_hidden = ""; |
||
| 3697 | if ($lp_id) { |
||
| 3698 | if (isset($resource['visible']) && $resource['visible'] == 0) { |
||
| 3699 | $folder_class_hidden = "doc_folder_hidden"; // in base.css |
||
| 3700 | } |
||
| 3701 | $onclick = 'onclick="javascript: testResources(\'res_' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')"'; |
||
| 3702 | } |
||
| 3703 | $return = null; |
||
| 3704 | |||
| 3705 | if (empty($path)) { |
||
| 3706 | $return = '<ul class="lp_resource">'; |
||
| 3707 | } |
||
| 3708 | |||
| 3709 | $return .= '<li class="doc_folder '.$folder_class_hidden.'" id="doc_id_' . $resource['id'] . '" style="margin-left:' . ($num * 18) . 'px; ">'; |
||
| 3710 | |||
| 3711 | $image = Display::returnIconPath('nolines_plus.gif'); |
||
| 3712 | if (empty($path)) { |
||
| 3713 | $image = Display::returnIconPath('nolines_minus.gif'); |
||
| 3714 | } |
||
| 3715 | $return .= '<img style="cursor: pointer;" src="'.$image.'" align="absmiddle" id="img_'.$resource['id'] . '" '.$onclick.'>'; |
||
| 3716 | $return .= Display::return_icon('lp_folder.gif').' '; |
||
| 3717 | $return .= '<span '.$onclick.' style="cursor: pointer;" >'.$title.'</span>'; |
||
| 3718 | $return .= '</li>'; |
||
| 3719 | |||
| 3720 | if (empty($path)) { |
||
| 3721 | if ($folderId == false) { |
||
| 3722 | $return .= '<div id="res_' . $resource['id'] . '" >'; |
||
| 3723 | } else { |
||
| 3724 | $return .= '<div id="res_' . $resource['id'] . '" style="display: none;" >'; |
||
| 3725 | } |
||
| 3726 | } |
||
| 3727 | |||
| 3728 | return $return; |
||
| 3729 | } |
||
| 3730 | |||
| 3731 | /** |
||
| 3732 | * Generate and return an HTML list of resources based on a given array. |
||
| 3733 | * This list is used to show the course creator a list of available resources to choose from |
||
| 3734 | * when creating a learning path. |
||
| 3735 | * @param array $course_info |
||
| 3736 | * @param int $session_id |
||
| 3737 | * @param array $documents |
||
| 3738 | * @param bool $lp_id |
||
| 3739 | * @param string $target |
||
| 3740 | * @param bool $add_move_button |
||
| 3741 | * @param string $overwrite_url |
||
| 3742 | * @param int $folderId |
||
| 3743 | * |
||
| 3744 | * @return string |
||
| 3745 | */ |
||
| 3746 | public static function write_resources_tree( |
||
| 3803 | |||
| 3804 | /** |
||
| 3805 | * @param int $doc_id |
||
| 3806 | * @param string $course_code |
||
| 3807 | * @param int $session_id |
||
| 3808 | * @param int $user_id |
||
| 3809 | * @param int $groupId |
||
| 3810 | * @return bool |
||
| 3811 | */ |
||
| 3812 | public static function check_visibility_tree( |
||
| 3855 | |||
| 3856 | /** |
||
| 3857 | * Index a given document. |
||
| 3858 | * @param int Document ID inside its corresponding course |
||
| 3859 | * @param string Course code |
||
| 3860 | * @param int Session ID (not used yet) |
||
| 3861 | * @param string Language of document's content (defaults to course language) |
||
| 3862 | * @param array Array of specific fields (['code'=>'value',...]) |
||
| 3863 | * @param string What to do if the file already exists (default or overwrite) |
||
| 3864 | * @param bool When set to true, this runs the indexer without actually saving anything to any database |
||
| 3865 | * @return bool Returns true on presumed success, false on failure |
||
| 3866 | */ |
||
| 3867 | public static function index_document( |
||
| 4059 | |||
| 4060 | /** |
||
| 4061 | * @return array |
||
| 4062 | */ |
||
| 4063 | public static function get_web_odf_extension_list() |
||
| 4067 | |||
| 4068 | /** |
||
| 4069 | * Set of extension allowed to use Jodconverter |
||
| 4070 | * @param $mode 'from' |
||
| 4071 | * 'to' |
||
| 4072 | * 'all' |
||
| 4073 | * @param $format 'text' |
||
| 4074 | * 'spreadsheet' |
||
| 4075 | * 'presentation' |
||
| 4076 | * 'drawing' |
||
| 4077 | * 'all' |
||
| 4078 | * @return array |
||
| 4079 | */ |
||
| 4080 | public static function getJodconverterExtensionList($mode, $format) |
||
| 4191 | |||
| 4192 | /** |
||
| 4193 | * Get Format type list by extension and mode |
||
| 4194 | * @param string $mode Mode to search format type list |
||
| 4195 | * @example 'from' |
||
| 4196 | * @example 'to' |
||
| 4197 | * @param string $extension file extension to check file type |
||
| 4198 | * @return array |
||
| 4199 | */ |
||
| 4200 | public static function getFormatTypeListConvertor($mode = 'from', $extension) |
||
| 4216 | |||
| 4217 | /** |
||
| 4218 | * @param string $path |
||
| 4219 | * @param bool $is_certificate_mode |
||
| 4220 | * @return bool |
||
| 4221 | */ |
||
| 4222 | public static function is_folder_to_avoid($path, $is_certificate_mode = false) |
||
| 4275 | |||
| 4276 | /** |
||
| 4277 | * @return array |
||
| 4278 | */ |
||
| 4279 | View Code Duplication | public static function get_system_folders() |
|
| 4293 | |||
| 4294 | /** |
||
| 4295 | * @return array |
||
| 4296 | */ |
||
| 4297 | public static function getProtectedFolderFromStudent() |
||
| 4307 | |||
| 4308 | /** |
||
| 4309 | * @param string $courseCode |
||
| 4310 | * @return string 'visible' or 'invisible' string |
||
| 4311 | */ |
||
| 4312 | public static function getDocumentDefaultVisibility($courseCode) |
||
| 4335 | |||
| 4336 | /** |
||
| 4337 | * @param array $courseInfo |
||
| 4338 | * @param int $id doc id |
||
| 4339 | * @param string $visibility visible/invisible |
||
| 4340 | * @param int $userId |
||
| 4341 | */ |
||
| 4342 | public static function updateVisibilityFromAllSessions($courseInfo, $id, $visibility, $userId) |
||
| 4364 | |||
| 4365 | /** |
||
| 4366 | * @param string $file |
||
| 4367 | * @return string |
||
| 4368 | */ |
||
| 4369 | public static function readNanogongFile($file) |
||
| 4380 | |||
| 4381 | /** |
||
| 4382 | * @param string $filePath |
||
| 4383 | * @param string $path |
||
| 4384 | * @param array $courseInfo |
||
| 4385 | * @param int $sessionId |
||
| 4386 | * @param string $whatIfFileExists overwrite|rename |
||
| 4387 | * @param int $userId |
||
| 4388 | * @param int $groupId |
||
| 4389 | * @param int $toUserId |
||
| 4390 | * @param string $comment |
||
| 4391 | * @return bool|path |
||
| 4392 | */ |
||
| 4393 | public static function addFileToDocumentTool( |
||
| 4445 | |||
| 4446 | /** |
||
| 4447 | * Converts wav to mp3 file. |
||
| 4448 | * Requires the ffmpeg lib. In ubuntu: sudo apt-get install ffmpeg |
||
| 4449 | * @param string $wavFile |
||
| 4450 | * @param bool $removeWavFileIfSuccess |
||
| 4451 | * @return bool |
||
| 4452 | */ |
||
| 4453 | public static function convertWavToMp3($wavFile, $removeWavFileIfSuccess = false) |
||
| 4476 | |||
| 4477 | /** |
||
| 4478 | * @param string $documentData wav document information |
||
| 4479 | * @param array $courseInfo |
||
| 4480 | * @param int $sessionId |
||
| 4481 | * @param int $userId user that adds the document |
||
| 4482 | * @param string $whatIfFileExists |
||
| 4483 | * @param bool $deleteWavFile |
||
| 4484 | * |
||
| 4485 | * @return bool |
||
| 4486 | */ |
||
| 4487 | public static function addAndConvertWavToMp3( |
||
| 4539 | |||
| 4540 | /** |
||
| 4541 | * Sets |
||
| 4542 | * @param string $file ($document_data['path']) |
||
| 4543 | * @param string $file_url_sys |
||
| 4544 | * @return string |
||
| 4545 | */ |
||
| 4546 | public static function generateAudioTempFile($file, $file_url_sys) |
||
| 4584 | |||
| 4585 | /** |
||
| 4586 | * Erase temp nanogong audio. |
||
| 4587 | */ |
||
| 4588 | public static function removeGeneratedAudioTempFile() |
||
| 4598 | |||
| 4599 | /** |
||
| 4600 | * Check if the past is used in this course. |
||
| 4601 | * @param array $courseInfo |
||
| 4602 | * @param string $path |
||
| 4603 | * |
||
| 4604 | * @return array |
||
| 4605 | */ |
||
| 4606 | public static function getDocumentByPathInCourse($courseInfo, $path) |
||
| 4618 | |||
| 4619 | /** |
||
| 4620 | * @param array $_course |
||
| 4621 | * @return int |
||
| 4622 | */ |
||
| 4623 | public static function createDefaultAudioFolder($_course) |
||
| 4650 | |||
| 4651 | /** |
||
| 4652 | * Generate a default certificate for a courses |
||
| 4653 | * |
||
| 4654 | * @global string $css CSS directory |
||
| 4655 | * @global string $img_dir image directory |
||
| 4656 | * @global string $default_course_dir Course directory |
||
| 4657 | * @global string $js JS directory |
||
| 4658 | * @param array $courseData The course info |
||
| 4659 | * @param bool $fromBaseCourse |
||
| 4660 | * @param int $sessionId |
||
| 4661 | */ |
||
| 4662 | public static function generateDefaultCertificate($courseData, $fromBaseCourse = false, $sessionId = 0) |
||
| 4752 | |||
| 4753 | /** |
||
| 4754 | * Update the document name |
||
| 4755 | * @param int $documentId The document id |
||
| 4756 | * @param string $newName The new name |
||
| 4757 | */ |
||
| 4758 | public static function renameDocument($documentId, $newName) |
||
| 4775 | |||
| 4776 | /** |
||
| 4777 | * Get folder/file suffix |
||
| 4778 | * |
||
| 4779 | * @param array $courseInfo |
||
| 4780 | * @param int $sessionId |
||
| 4781 | * @param int $groupId |
||
| 4782 | * |
||
| 4783 | * @return string |
||
| 4784 | */ |
||
| 4785 | public static function getDocumentSuffix($courseInfo, $sessionId, $groupId) |
||
| 4795 | |||
| 4796 | /** |
||
| 4797 | * Fix a document name adding session id and group id |
||
| 4798 | * Turns picture.jpg -> picture__1__2.jpg |
||
| 4799 | * Where 1 = session id and 2 group id |
||
| 4800 | * Of session id and group id are empty then the function returns: |
||
| 4801 | * picture.jpg -> picture.jpg |
||
| 4802 | * |
||
| 4803 | * @param string $name folder or file name |
||
| 4804 | * @param string $type 'folder' or 'file' |
||
| 4805 | * @param array $courseInfo |
||
| 4806 | * @param int $sessionId |
||
| 4807 | * @param int $groupId |
||
| 4808 | * |
||
| 4809 | * @return string |
||
| 4810 | */ |
||
| 4811 | public static function fixDocumentName($name, $type, $courseInfo, $sessionId, $groupId) |
||
| 4826 | |||
| 4827 | /** |
||
| 4828 | * Add a suffix to a file Example: |
||
| 4829 | * /folder/picture.jpg => to /folder/picture_this.jpg |
||
| 4830 | * where "_this" is the suffix |
||
| 4831 | * @param string $name |
||
| 4832 | * @param string $suffix |
||
| 4833 | * @return string |
||
| 4834 | */ |
||
| 4835 | public static function addSuffixToFileName($name, $suffix) |
||
| 4852 | |||
| 4853 | /** |
||
| 4854 | * Check if folder exist in the course base or in the session course |
||
| 4855 | * @param string $folder Example: /folder/folder2 |
||
| 4856 | * @param array $courseInfo |
||
| 4857 | * @param int $sessionId |
||
| 4858 | * @param int $groupId |
||
| 4859 | * |
||
| 4860 | * @return bool |
||
| 4861 | */ |
||
| 4862 | View Code Duplication | public static function folderExists( |
|
| 4903 | |||
| 4904 | /** |
||
| 4905 | * Check if file exist in the course base or in the session course |
||
| 4906 | * @param string $fileName Example: /folder/picture.jpg |
||
| 4907 | * @param array $courseInfo |
||
| 4908 | * @param int $sessionId |
||
| 4909 | * @param int $groupId |
||
| 4910 | * |
||
| 4911 | * @return bool |
||
| 4912 | */ |
||
| 4913 | View Code Duplication | public static function documentExists( |
|
| 4957 | |||
| 4958 | /** |
||
| 4959 | * Undo the suffix applied to a file example: |
||
| 4960 | * turns picture__1__1.jpg to picture.jpg |
||
| 4961 | * @param string $name |
||
| 4962 | * @param int $courseId |
||
| 4963 | * @param int $sessionId |
||
| 4964 | * @param int $groupId |
||
| 4965 | * |
||
| 4966 | * @return string |
||
| 4967 | */ |
||
| 4968 | public static function undoFixDocumentName( |
||
| 4988 | |||
| 4989 | /** |
||
| 4990 | * @param string $path |
||
| 4991 | * @param string $name |
||
| 4992 | * @param array $courseInfo |
||
| 4993 | * @param int $sessionId |
||
| 4994 | * @param int $groupId |
||
| 4995 | * |
||
| 4996 | * @return string |
||
| 4997 | */ |
||
| 4998 | public static function getUniqueFileName($path, $name, $courseInfo, $sessionId, $groupId) |
||
| 5016 | |||
| 5017 | |||
| 5018 | /** |
||
| 5019 | * Builds the form that enables the user to |
||
| 5020 | * select a directory to browse/upload in |
||
| 5021 | * |
||
| 5022 | * @param array An array containing the folders we want to be able to select |
||
| 5023 | * @param string The current folder (path inside of the "document" directory, including the prefix "/") |
||
| 5024 | * @param string Group directory, if empty, prevents documents to be uploaded (because group documents cannot be uploaded in root) |
||
| 5025 | * @param boolean Whether to change the renderer (this will add a template <span> to the QuickForm object displaying the form) |
||
| 5026 | * @todo this funcionality is really bad : jmontoya |
||
| 5027 | * @return string html form |
||
| 5028 | */ |
||
| 5029 | public static function build_directory_selector($folders, $document_id, $group_dir = '', $change_renderer = false) |
||
| 5104 | |||
| 5105 | /** |
||
| 5106 | * Create a html hyperlink depending on if it's a folder or a file |
||
| 5107 | * |
||
| 5108 | * @param array $document_data |
||
| 5109 | * @param int $show_as_icon - if it is true, only a clickable icon will be shown |
||
| 5110 | * @param int $visibility (1/0) |
||
| 5111 | * @param int $counter |
||
| 5112 | * |
||
| 5113 | * @return string url |
||
| 5114 | */ |
||
| 5115 | public static function create_document_link( |
||
| 5116 | $document_data, |
||
| 5117 | $show_as_icon = false, |
||
| 5118 | $counter = null, |
||
| 5119 | $visibility |
||
| 5120 | ) { |
||
| 5121 | global $dbl_click_id; |
||
| 5122 | $course_info = api_get_course_info(); |
||
| 5123 | $www = api_get_path(WEB_COURSE_PATH) . $course_info['path'] . '/document'; |
||
| 5124 | $webOdflist = DocumentManager::get_web_odf_extension_list(); |
||
| 5125 | |||
| 5126 | // Get the title or the basename depending on what we're using |
||
| 5127 | View Code Duplication | if ($document_data['title'] != '') { |
|
| 5128 | $title = $document_data['title']; |
||
| 5129 | } else { |
||
| 5130 | $title = basename($document_data['path']); |
||
| 5131 | } |
||
| 5132 | |||
| 5133 | $filetype = $document_data['filetype']; |
||
| 5134 | $size = $filetype == 'folder' ? get_total_folder_size($document_data['path'], api_is_allowed_to_edit(null, true)) : $document_data['size']; |
||
| 5135 | $path = $document_data['path']; |
||
| 5136 | |||
| 5137 | $url_path = urlencode($document_data['path']); |
||
| 5138 | |||
| 5139 | // Add class="invisible" on invisible files |
||
| 5140 | $visibility_class = ($visibility == false) ? ' class="muted"' : ''; |
||
| 5141 | $forcedownload_link = null; |
||
| 5142 | $forcedownload_icon = null; |
||
| 5143 | $prevent_multiple_click = null; |
||
| 5144 | |||
| 5145 | if (!$show_as_icon) { |
||
| 5146 | // Build download link (icon) |
||
| 5147 | $forcedownload_link = ($filetype == 'folder') ? api_get_self() . '?' . api_get_cidreq() . '&action=downloadfolder&id=' . $document_data['id'] : api_get_self() . '?' . api_get_cidreq() . '&action=download&id=' . $document_data['id']; |
||
| 5148 | // Folder download or file download? |
||
| 5149 | $forcedownload_icon = ($filetype == 'folder') ? 'save_pack.png' : 'save.png'; |
||
| 5150 | // Prevent multiple clicks on zipped folder download |
||
| 5151 | $prevent_multiple_click = ($filetype == 'folder') ? " onclick=\"javascript: if(typeof clic_$dbl_click_id == 'undefined' || !clic_$dbl_click_id) { clic_$dbl_click_id=true; window.setTimeout('clic_" . ($dbl_click_id++) . "=false;',10000); } else { return false; }\"" : ''; |
||
| 5152 | } |
||
| 5153 | |||
| 5154 | $target = '_self'; |
||
| 5155 | $is_browser_viewable_file = false; |
||
| 5156 | |||
| 5157 | if ($filetype == 'file') { |
||
| 5158 | // Check the extension |
||
| 5159 | $ext = explode('.', $path); |
||
| 5160 | $ext = strtolower($ext[sizeof($ext) - 1]); |
||
| 5161 | |||
| 5162 | // HTML-files an some other types are shown in a frameset by default. |
||
| 5163 | $is_browser_viewable_file = self::is_browser_viewable($ext); |
||
| 5164 | |||
| 5165 | if ($is_browser_viewable_file) { |
||
| 5166 | if ($ext == 'pdf' || in_array($ext, $webOdflist)) { |
||
| 5167 | $url = api_get_self() . '?' . api_get_cidreq() . '&action=download&id=' . $document_data['id']; |
||
| 5168 | } else { |
||
| 5169 | $url = 'showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id']; |
||
| 5170 | } |
||
| 5171 | } else { |
||
| 5172 | // url-encode for problematic characters (we may not call them dangerous characters...) |
||
| 5173 | $path = str_replace('%2F', '/', $url_path) . '?' . api_get_cidreq(); |
||
| 5174 | $url = $www . $path; |
||
| 5175 | } |
||
| 5176 | |||
| 5177 | /*$path = str_replace('%2F', '/', $url_path); //yox view hack otherwise the image can't be well read |
||
| 5178 | $url = $www . $path;*/ |
||
| 5179 | } else { |
||
| 5180 | $url = api_get_self() . '?' . api_get_cidreq() . '&id=' . $document_data['id']; |
||
| 5181 | } |
||
| 5182 | |||
| 5183 | // The little download icon |
||
| 5184 | $tooltip_title = $title; |
||
| 5185 | |||
| 5186 | $tooltip_title_alt = $tooltip_title; |
||
| 5187 | if ($path == '/shared_folder') { |
||
| 5188 | $tooltip_title_alt = get_lang('UserFolders'); |
||
| 5189 | } elseif (strstr($path, 'shared_folder_session_')) { |
||
| 5190 | $tooltip_title_alt = get_lang('UserFolders') . ' (' . api_get_session_name(api_get_session_id()) . ')'; |
||
| 5191 | } elseif (strstr($tooltip_title, 'sf_user_')) { |
||
| 5192 | $userinfo = api_get_user_info(substr($tooltip_title, 8)); |
||
| 5193 | $tooltip_title_alt = get_lang('UserFolder') . ' ' . $userinfo['complete_name']; |
||
| 5194 | } elseif ($path == '/chat_files') { |
||
| 5195 | $tooltip_title_alt = get_lang('ChatFiles'); |
||
| 5196 | } elseif ($path == '/learning_path') { |
||
| 5197 | $tooltip_title_alt = get_lang('LearningPaths'); |
||
| 5198 | } elseif ($path == '/video') { |
||
| 5199 | $tooltip_title_alt = get_lang('Video'); |
||
| 5200 | } elseif ($path == '/audio') { |
||
| 5201 | $tooltip_title_alt = get_lang('Audio'); |
||
| 5202 | } elseif ($path == '/flash') { |
||
| 5203 | $tooltip_title_alt = get_lang('Flash'); |
||
| 5204 | } elseif ($path == '/images') { |
||
| 5205 | $tooltip_title_alt = get_lang('Images'); |
||
| 5206 | } elseif ($path == '/images/gallery') { |
||
| 5207 | $tooltip_title_alt = get_lang('DefaultCourseImages'); |
||
| 5208 | } |
||
| 5209 | |||
| 5210 | $current_session_id = api_get_session_id(); |
||
| 5211 | $copy_to_myfiles = $open_in_new_window_link = null; |
||
| 5212 | |||
| 5213 | $curdirpath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null; |
||
| 5214 | $send_to = null; |
||
| 5215 | |||
| 5216 | $checkExtension = $path; |
||
| 5217 | |||
| 5218 | if (!$show_as_icon) { |
||
| 5219 | if ($filetype == 'folder') { |
||
| 5220 | if (api_is_allowed_to_edit() || |
||
| 5221 | api_is_platform_admin() || |
||
| 5222 | api_get_setting('students_download_folders') == 'true' |
||
| 5223 | ) { |
||
| 5224 | //filter when I am into shared folder, I can show for donwload only my shared folder |
||
| 5225 | if (DocumentManager::is_shared_folder($curdirpath, $current_session_id)) { |
||
| 5226 | if (preg_match('/shared_folder\/sf_user_' . api_get_user_id() . '$/', urldecode($forcedownload_link)) || |
||
| 5227 | preg_match('/shared_folder_session_' . $current_session_id . '\/sf_user_' . api_get_user_id() . '$/', urldecode($forcedownload_link)) || |
||
| 5228 | api_is_allowed_to_edit() || api_is_platform_admin() |
||
| 5229 | ) { |
||
| 5230 | $force_download_html = ($size == 0) ? '' : '<a href="' . $forcedownload_link . '" style="float:right"' . $prevent_multiple_click . '>' . |
||
| 5231 | Display::return_icon($forcedownload_icon, get_lang('Download'), array(), ICON_SIZE_SMALL) . '</a>'; |
||
| 5232 | } |
||
| 5233 | } elseif (!preg_match('/shared_folder/', urldecode($forcedownload_link)) || |
||
| 5234 | api_is_allowed_to_edit() || |
||
| 5235 | api_is_platform_admin() |
||
| 5236 | ) { |
||
| 5237 | $force_download_html = ($size == 0) ? '' : '<a href="' . $forcedownload_link . '" style="float:right"' . $prevent_multiple_click . '>' . |
||
| 5238 | Display::return_icon($forcedownload_icon, get_lang('Download'), array(), ICON_SIZE_SMALL) . '</a>'; |
||
| 5239 | } |
||
| 5240 | } |
||
| 5241 | View Code Duplication | } else { |
|
| 5242 | $force_download_html = ($size == 0) ? '' : '<a href="' . $forcedownload_link . '" style="float:right"' . $prevent_multiple_click . '>' . |
||
| 5243 | Display::return_icon($forcedownload_icon, get_lang('Download'), array(), ICON_SIZE_SMALL) . '</a>'; |
||
| 5244 | } |
||
| 5245 | |||
| 5246 | // Copy files to users myfiles |
||
| 5247 | if (api_get_setting('allow_social_tool') == 'true' && |
||
| 5248 | api_get_setting('users_copy_files') == 'true' && |
||
| 5249 | !api_is_anonymous() |
||
| 5250 | ) { |
||
| 5251 | $copy_myfiles_link = ($filetype == 'file') ? api_get_self() . '?' . api_get_cidreq() . '&action=copytomyfiles&id=' . $document_data['id'] : api_get_self() . '?' . api_get_cidreq(); |
||
| 5252 | |||
| 5253 | View Code Duplication | if ($filetype == 'file') { |
|
| 5254 | |||
| 5255 | $copy_to_myfiles = '<a href="' . $copy_myfiles_link . '" style="float:right"' . $prevent_multiple_click . '>' . |
||
| 5256 | Display::return_icon('briefcase.png', get_lang('CopyToMyFiles'), array(), ICON_SIZE_SMALL) . ' </a>'; |
||
| 5257 | |||
| 5258 | if (api_get_setting('allow_my_files') === 'false') { |
||
| 5259 | $copy_to_myfiles = ''; |
||
| 5260 | } |
||
| 5261 | } |
||
| 5262 | |||
| 5263 | if ($filetype == 'file') { |
||
| 5264 | $send_to = Portfolio::share('document', $document_data['id'], array('style' => 'float:right;')); |
||
| 5265 | } |
||
| 5266 | } |
||
| 5267 | |||
| 5268 | $pdf_icon = ''; |
||
| 5269 | $extension = pathinfo($path, PATHINFO_EXTENSION); |
||
| 5270 | if (!api_is_allowed_to_edit() && |
||
| 5271 | api_get_setting('students_export2pdf') == 'true' && |
||
| 5272 | $filetype == 'file' && |
||
| 5273 | in_array($extension, array('html', 'htm')) |
||
| 5274 | ) { |
||
| 5275 | $pdf_icon = ' <a style="float:right".' . $prevent_multiple_click . ' href="' . api_get_self() . '?' . api_get_cidreq() . '&action=export_to_pdf&id=' . $document_data['id'] . '">' . |
||
| 5276 | Display::return_icon('pdf.png', get_lang('Export2PDF'), array(), ICON_SIZE_SMALL) . '</a> '; |
||
| 5277 | } |
||
| 5278 | |||
| 5279 | View Code Duplication | if ($is_browser_viewable_file) { |
|
| 5280 | $open_in_new_window_link = '<a href="' . $www . str_replace('%2F', '/', $url_path) . '?' . api_get_cidreq() . '" style="float:right"' . $prevent_multiple_click . ' target="_blank">' . |
||
| 5281 | Display::return_icon('open_in_new_window.png', get_lang('OpenInANewWindow'), array(), ICON_SIZE_SMALL) . ' </a>'; |
||
| 5282 | } |
||
| 5283 | |||
| 5284 | if ($filetype == 'file') { |
||
| 5285 | // Sound preview with jplayer |
||
| 5286 | if (preg_match('/mp3$/i', urldecode($checkExtension)) || |
||
| 5287 | (preg_match('/wav$/i', urldecode($checkExtension)) && !preg_match('/_chnano_.wav$/i', urldecode($url))) || |
||
| 5288 | preg_match('/ogg$/i', urldecode($checkExtension)) |
||
| 5289 | ) { |
||
| 5290 | return '<span style="float:left" ' . $visibility_class . '>' . |
||
| 5291 | $title . |
||
| 5292 | '</span>' . $force_download_html . $send_to . $copy_to_myfiles . $open_in_new_window_link . $pdf_icon; |
||
| 5293 | } elseif ( |
||
| 5294 | |||
| 5295 | // Show preview |
||
| 5296 | preg_match('/swf$/i', urldecode($checkExtension)) || |
||
| 5297 | preg_match('/png$/i', urldecode($checkExtension)) || |
||
| 5298 | preg_match('/gif$/i', urldecode($checkExtension)) || |
||
| 5299 | preg_match('/jpg$/i', urldecode($checkExtension)) || |
||
| 5300 | preg_match('/jpeg$/i', urldecode($checkExtension)) || |
||
| 5301 | preg_match('/bmp$/i', urldecode($checkExtension)) || |
||
| 5302 | preg_match('/svg$/i', urldecode($checkExtension)) || |
||
| 5303 | ( |
||
| 5304 | preg_match('/wav$/i', urldecode($checkExtension)) && |
||
| 5305 | preg_match('/_chnano_.wav$/i', urldecode($checkExtension)) && |
||
| 5306 | api_get_setting('enable_nanogong') == 'true' |
||
| 5307 | ) |
||
| 5308 | ) { |
||
| 5309 | // Simpler version of showinframesmin.php with no headers |
||
| 5310 | $url = 'show_content.php?' . api_get_cidreq() . '&id=' . $document_data['id']; |
||
| 5311 | $class = 'ajax'; |
||
| 5312 | if ($visibility == false) { |
||
| 5313 | $class = "ajax invisible"; |
||
| 5314 | } |
||
| 5315 | return Display::url( |
||
| 5316 | $title, |
||
| 5317 | $url, |
||
| 5318 | [ |
||
| 5319 | 'class' => $class, |
||
| 5320 | 'title' => $tooltip_title_alt, |
||
| 5321 | 'data-title' => $title, |
||
| 5322 | 'style' => 'float: left;' |
||
| 5323 | ] |
||
| 5324 | ) |
||
| 5325 | . $force_download_html . $send_to . $copy_to_myfiles |
||
| 5326 | . $open_in_new_window_link . $pdf_icon; |
||
| 5327 | } else { |
||
| 5328 | // For PDF Download the file. |
||
| 5329 | $pdfPreview = null; |
||
| 5330 | if ($ext != 'pdf' && !in_array($ext, $webOdflist)) { |
||
| 5331 | $url = 'showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id']; |
||
| 5332 | } else { |
||
| 5333 | $pdfPreview = Display::url( |
||
| 5334 | Display::return_icon('preview.gif', get_lang('Preview')), |
||
| 5335 | api_get_path(WEB_CODE_PATH).'document/showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id'], |
||
| 5336 | array('style' => 'float:right') |
||
| 5337 | ); |
||
| 5338 | } |
||
| 5339 | // No plugin just the old and good showinframes.php page |
||
| 5340 | return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" style="float:left" ' . $visibility_class . ' >' . $title . '</a>' . |
||
| 5341 | $pdfPreview.$force_download_html . $send_to . $copy_to_myfiles . $open_in_new_window_link . $pdf_icon; |
||
| 5342 | } |
||
| 5343 | } else { |
||
| 5344 | return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' . $title . '</a>' . |
||
| 5345 | $force_download_html . $send_to . $copy_to_myfiles . $open_in_new_window_link . $pdf_icon; |
||
| 5346 | } |
||
| 5347 | // end copy files to users myfiles |
||
| 5348 | } else { |
||
| 5349 | // Icon column |
||
| 5350 | if (preg_match('/shared_folder/', urldecode($checkExtension)) && |
||
| 5351 | preg_match('/shared_folder$/', urldecode($checkExtension)) == false && |
||
| 5352 | preg_match('/shared_folder_session_' . $current_session_id . '$/', urldecode($url)) == false |
||
| 5353 | ) { |
||
| 5354 | if ($filetype == 'file') { |
||
| 5355 | //Sound preview with jplayer |
||
| 5356 | if (preg_match('/mp3$/i', urldecode($checkExtension)) || |
||
| 5357 | (preg_match('/wav$/i', urldecode($checkExtension)) && !preg_match('/_chnano_.wav$/i', urldecode($url))) || |
||
| 5358 | preg_match('/ogg$/i', urldecode($checkExtension))) { |
||
| 5359 | $sound_preview = DocumentManager::generate_media_preview($counter); |
||
| 5360 | |||
| 5361 | return $sound_preview; |
||
| 5362 | } elseif ( |
||
| 5363 | // Show preview |
||
| 5364 | preg_match('/swf$/i', urldecode($checkExtension)) || |
||
| 5365 | preg_match('/png$/i', urldecode($checkExtension)) || |
||
| 5366 | preg_match('/gif$/i', urldecode($checkExtension)) || |
||
| 5367 | preg_match('/jpg$/i', urldecode($checkExtension)) || |
||
| 5368 | preg_match('/jpeg$/i', urldecode($checkExtension)) || |
||
| 5369 | preg_match('/bmp$/i', urldecode($checkExtension)) || |
||
| 5370 | preg_match('/svg$/i', urldecode($checkExtension)) || |
||
| 5371 | ( |
||
| 5372 | preg_match('/wav$/i', urldecode($checkExtension)) && |
||
| 5373 | preg_match('/_chnano_.wav$/i', urldecode($checkExtension)) && |
||
| 5374 | api_get_setting('enable_nanogong') == 'true' |
||
| 5375 | ) |
||
| 5376 | ) { |
||
| 5377 | $url = 'showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id']; |
||
| 5378 | return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' . |
||
| 5379 | DocumentManager::build_document_icon_tag($filetype, $path) . |
||
| 5380 | Display::return_icon('shared.png', get_lang('ResourceShared'), array()) . '</a>'; |
||
| 5381 | View Code Duplication | } else { |
|
| 5382 | return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' . |
||
| 5383 | DocumentManager::build_document_icon_tag($filetype, $path) . |
||
| 5384 | Display::return_icon('shared.png', get_lang('ResourceShared'), array()) . '</a>'; |
||
| 5385 | } |
||
| 5386 | View Code Duplication | } else { |
|
| 5387 | return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" target="' . $target . '"' . $visibility_class . ' style="float:left">' . |
||
| 5388 | DocumentManager::build_document_icon_tag($filetype, $path) . |
||
| 5389 | Display::return_icon('shared.png', get_lang('ResourceShared'), array()) . '</a>'; |
||
| 5390 | } |
||
| 5391 | } else { |
||
| 5392 | if ($filetype == 'file') { |
||
| 5393 | // Sound preview with jplayer |
||
| 5394 | if (preg_match('/mp3$/i', urldecode($checkExtension)) || |
||
| 5395 | (preg_match('/wav$/i', urldecode($checkExtension)) && !preg_match('/_chnano_.wav$/i', urldecode($url))) || |
||
| 5396 | preg_match('/ogg$/i', urldecode($checkExtension))) { |
||
| 5397 | $sound_preview = DocumentManager::generate_media_preview($counter); |
||
| 5398 | |||
| 5399 | return $sound_preview; |
||
| 5400 | } elseif ( |
||
| 5401 | //Show preview |
||
| 5402 | preg_match('/html$/i', urldecode($checkExtension)) || |
||
| 5403 | preg_match('/htm$/i', urldecode($checkExtension)) || |
||
| 5404 | preg_match('/swf$/i', urldecode($checkExtension)) || |
||
| 5405 | preg_match('/png$/i', urldecode($checkExtension)) || |
||
| 5406 | preg_match('/gif$/i', urldecode($checkExtension)) || |
||
| 5407 | preg_match('/jpg$/i', urldecode($checkExtension)) || |
||
| 5408 | preg_match('/jpeg$/i', urldecode($checkExtension)) || |
||
| 5409 | preg_match('/bmp$/i', urldecode($checkExtension)) || |
||
| 5410 | preg_match('/svg$/i', urldecode($checkExtension)) || |
||
| 5411 | ( |
||
| 5412 | preg_match('/wav$/i', urldecode($checkExtension)) && |
||
| 5413 | preg_match('/_chnano_.wav$/i', urldecode($checkExtension)) && |
||
| 5414 | api_get_setting('enable_nanogong') == 'true' |
||
| 5415 | ) |
||
| 5416 | ) { |
||
| 5417 | $url = 'showinframes.php?' . api_get_cidreq() . '&id=' . $document_data['id']; //without preview |
||
| 5418 | return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' . |
||
| 5419 | DocumentManager::build_document_icon_tag($filetype, $path) . '</a>'; |
||
| 5420 | View Code Duplication | } else { |
|
| 5421 | return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" ' . $visibility_class . ' style="float:left">' . |
||
| 5422 | DocumentManager::build_document_icon_tag($filetype, $path) . '</a>'; |
||
| 5423 | } |
||
| 5424 | View Code Duplication | } else { |
|
| 5425 | return '<a href="' . $url . '" title="' . $tooltip_title_alt . '" target="' . $target . '"' . $visibility_class . ' style="float:left">' . |
||
| 5426 | DocumentManager::build_document_icon_tag($filetype, $path) . '</a>'; |
||
| 5427 | } |
||
| 5428 | } |
||
| 5429 | } |
||
| 5430 | } |
||
| 5431 | |||
| 5432 | /** |
||
| 5433 | * Builds an img html tag for the file type |
||
| 5434 | * |
||
| 5435 | * @param string $type (file/folder) |
||
| 5436 | * @param string $path |
||
| 5437 | * @return string img html tag |
||
| 5438 | */ |
||
| 5439 | public static function build_document_icon_tag($type, $path) |
||
| 5535 | |||
| 5536 | /** |
||
| 5537 | * Creates the row of edit icons for a file/folder |
||
| 5538 | * |
||
| 5539 | * @param string $curdirpath current path (cfr open folder) |
||
| 5540 | * @param string $type (file/folder) |
||
| 5541 | * @param string $path dbase path of file/folder |
||
| 5542 | * @param int $visibility (1/0) |
||
| 5543 | * @param int $id dbase id of the document |
||
| 5544 | * @return string html img tags with hyperlinks |
||
| 5545 | */ |
||
| 5546 | public static function build_edit_icons($document_data, $id, $is_template, $is_read_only = 0, $visibility) |
||
| 5547 | { |
||
| 5548 | $web_odf_extension_list = DocumentManager::get_web_odf_extension_list(); |
||
| 5549 | $document_id = $document_data['id']; |
||
| 5770 | |||
| 5771 | /** |
||
| 5772 | * @param $folders |
||
| 5773 | * @param $curdirpath |
||
| 5774 | * @param $move_file |
||
| 5775 | * @param string $group_dir |
||
| 5776 | * @return string |
||
| 5777 | */ |
||
| 5778 | public static function build_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '') |
||
| 5867 | |||
| 5868 | /** |
||
| 5869 | * Gets the path translated with title of docs and folders |
||
| 5870 | * @param string $path the real path |
||
| 5871 | * @return the path which should be displayed |
||
| 5872 | */ |
||
| 5873 | public static function get_titles_of_path($path) |
||
| 5904 | |||
| 5905 | /** |
||
| 5906 | * Creates form that asks for the directory name. |
||
| 5907 | * @return string html-output text for the form |
||
| 5908 | */ |
||
| 5909 | public static function create_dir_form($dirId) |
||
| 5923 | |||
| 5924 | /** |
||
| 5925 | * Checks whether the user is in shared folder |
||
| 5926 | * @return return bool Return true when user is into shared folder |
||
| 5927 | */ |
||
| 5928 | public static function is_shared_folder($curdirpath, $current_session_id) |
||
| 5939 | |||
| 5940 | /** |
||
| 5941 | * Checks whether the user is into any user shared folder |
||
| 5942 | * @return return bool Return true when user is in any user shared folder |
||
| 5943 | */ |
||
| 5944 | public static function is_any_user_shared_folder($path, $current_session_id) |
||
| 5955 | |||
| 5956 | /** |
||
| 5957 | * Checks whether the user is into his shared folder or into a subfolder |
||
| 5958 | * @return bool Return true when user is in his user shared folder or into a subfolder |
||
| 5959 | */ |
||
| 5960 | public static function is_my_shared_folder($user_id, $path, $current_session_id) |
||
| 5976 | |||
| 5977 | /** |
||
| 5978 | * Check if the file name or folder searched exist |
||
| 5979 | * @return bool Return true when exist |
||
| 5980 | */ |
||
| 5981 | public static function search_keyword($document_name, $keyword) |
||
| 5989 | |||
| 5990 | /** |
||
| 5991 | * Checks whether a document can be previewed by using the browser. |
||
| 5992 | * @param string $file_extension The filename extension of the document (it must be in lower case). |
||
| 5993 | * @return bool Returns TRUE or FALSE. |
||
| 5994 | */ |
||
| 5995 | public static function is_browser_viewable($file_extension) |
||
| 6056 | |||
| 6057 | /** |
||
| 6058 | * @param array $courseInfo |
||
| 6059 | * @param int $sessionId |
||
| 6060 | * |
||
| 6061 | * @return array |
||
| 6062 | */ |
||
| 6063 | public static function getDeletedDocuments($courseInfo, $sessionId = 0) |
||
| 6084 | |||
| 6085 | /** |
||
| 6086 | * @param int $id |
||
| 6087 | * @param array $courseInfo |
||
| 6088 | * @param int $sessionId |
||
| 6089 | * |
||
| 6090 | * @return array |
||
| 6091 | */ |
||
| 6092 | public static function getDeletedDocument($id, $courseInfo, $sessionId = 0) |
||
| 6118 | |||
| 6119 | /** |
||
| 6120 | * @param int $id |
||
| 6121 | * @param array $courseInfo |
||
| 6122 | * @param int $sessionId |
||
| 6123 | * @return bool |
||
| 6124 | */ |
||
| 6125 | public static function purgeDocument($id, $courseInfo, $sessionId = 0) |
||
| 6139 | |||
| 6140 | /** |
||
| 6141 | * @param array $courseInfo |
||
| 6142 | * @param int $sessionId |
||
| 6143 | */ |
||
| 6144 | public static function purgeDocuments($courseInfo, $sessionId) |
||
| 6151 | |||
| 6152 | /** |
||
| 6153 | * @param int $id |
||
| 6154 | * @param array $courseInfo |
||
| 6155 | * @param int $sessionId |
||
| 6156 | * @return bool |
||
| 6157 | */ |
||
| 6158 | public static function downloadDeletedDocument($id, $courseInfo, $sessionId) |
||
| 6170 | |||
| 6171 | /** |
||
| 6172 | * @param array $courseInfo |
||
| 6173 | * @param int $sessionId |
||
| 6174 | * |
||
| 6175 | * @return bool |
||
| 6176 | */ |
||
| 6177 | public static function downloadAllDeletedDocument($courseInfo, $sessionId) |
||
| 6207 | |||
| 6208 | /** |
||
| 6209 | * |
||
| 6210 | * Delete documents from a session in a course. |
||
| 6211 | * @param array $courseInfo |
||
| 6212 | * @param int $sessionId |
||
| 6213 | * |
||
| 6214 | * @return bool |
||
| 6215 | */ |
||
| 6216 | public function deleteDocumentsFromSession($courseInfo, $sessionId) |
||
| 6271 | |||
| 6272 | public static function generateFinalItemDocument() |
||
| 6276 | } |
||
| 6277 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.