123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- <?php
- $dbTable = Database::get_course_table(TABLE_DOCUMENT);
- function hotpotatoes_init($base_work_dir)
- {
-
- $document_path = $base_work_dir.'/';
- if (!is_dir($document_path)) {
- if (is_file($document_path)) {
- @unlink($document_path);
- }
- @mkdir($document_path, api_get_permissions_for_new_directories());
- return true;
- } else {
- return false;
- }
-
-
-
-
-
-
-
-
- }
- function GetQuizName($fname, $fpath)
- {
- $title = GetComment($fname);
- if (trim($title) == '') {
- if (file_exists($fpath.$fname)) {
- if (!($fp = @fopen($fpath.$fname, 'r'))) {
-
- return basename($fname);
- }
- $contents = @fread($fp, filesize($fpath.$fname));
- @fclose($fp);
- $title = api_get_title_html($contents);
- }
- }
- if ($title == '') {
- $title = basename($fname);
- }
- return (string) $title;
- }
- function GetComment($path, $courseCode = '')
- {
- $dbTable = Database::get_course_table(TABLE_DOCUMENT);
- $course_info = api_get_course_info($courseCode);
- $path = Database::escape_string($path);
- if (!empty($course_info) && !empty($path)) {
- $query = "SELECT comment FROM $dbTable WHERE c_id = {$course_info['real_id']}";
- $result = Database::query($query);
- while ($row = Database::fetch_array($result)) {
- return $row[0];
- }
- }
- return null;
- }
- function SetComment($path, $comment)
- {
- $dbTable = Database::get_course_table(TABLE_DOCUMENT);
- $path = Database::escape_string($path);
- $comment = Database::escape_string($comment);
- $course_id = api_get_course_int_id();
- $query = "UPDATE $dbTable SET comment = '$comment'
- WHERE $course_id AND path = '$path'";
- $result = Database::query($query);
- return $result;
- }
- function ReadFileCont($full_file_path)
- {
- if (empty($full_file_path)) {
- return false;
- }
- if (Security::check_abs_path(dirname($full_file_path).'/', api_get_path(SYS_COURSE_PATH))) {
- if (is_file($full_file_path)) {
- if (!($fp = fopen(urldecode($full_file_path), 'r'))) {
- return '';
- }
- $contents = fread($fp, filesize($full_file_path));
- fclose($fp);
- return $contents;
- }
- }
- return false;
- }
- function WriteFileCont($full_file_path, $content)
- {
-
- $_course = api_get_course_info();
- if (Security::check_abs_path(dirname($full_file_path).'/', api_get_path(SYS_COURSE_PATH).$_course['path'].'/')) {
-
- if (basename($full_file_path) != Security::filter_filename(basename($full_file_path))) {
- return false;
- }
-
-
-
- $fp = fopen(urldecode($full_file_path), 'w');
- if ($fp !== false) {
- fwrite($fp, $content);
- fclose($fp);
- return true;
- }
- }
- return false;
- }
- function GetImgName($imageTag)
- {
-
- $match = array();
-
- preg_match('/src(\s)*=(\s)*[\'"]([^\'"]*)[\'"]/i', $imageTag, $match);
-
- $src = $match[3];
-
- if (stristr($src, 'http') === false) {
-
- if ($src == '') {
- return '';
- } else {
- $tmp_src = basename($src);
- if ($tmp_src == '') {
- return $src;
- } else {
- return $tmp_src;
- }
- }
- } else {
-
- return '';
- }
- }
- function GetSrcName($imageTag)
- {
-
- $match = array();
- preg_match("|(src=\".*\" )|U", $imageTag, $match);
- list(, $srctag) = each($match);
- $src = substr($srctag, 5, (strlen($srctag) - 7));
- if (stristr($src, 'http') === false) {
-
- return $src;
- } else {
- return '';
- }
- }
- function GetImgParams($fname, $fpath, &$imgparams, &$imgcount)
- {
-
- $imgparams = array();
-
- $contents = ReadFileCont("$fpath"."$fname");
- $matches = array();
- preg_match_all('(<img .*>)', $contents, $matches);
- $imgcount = 0;
- while (list(, $match) = each($matches)) {
-
- while (list(, $imageTag) = each($match)) {
- $imgname = GetImgName($imageTag);
- if ($imgname != '' && !in_array($imgname, $imgparams)) {
- array_push($imgparams, $imgname);
- $imgcount = $imgcount + 1;
- }
- }
- }
- }
- function GenerateHiddenList($imgparams)
- {
- $list = '';
- if (is_array($imgparams)) {
- while (list(, $string) = each($imgparams)) {
- $list .= "<input type=\"hidden\" name=\"imgparams[]\" value=\"$string\" />\n";
- }
- }
- return $list;
- }
- function myarraysearch(&$array, $node)
- {
- $match = false;
- $tmp_array = array();
- for ($i = 0; $i < count($array); $i++) {
- if (!strcmp($array[$i], $node)) {
- $match = $node;
- } else {
- array_push($tmp_array, $array[$i]);
- }
- }
- $array = $tmp_array;
- return $match;
- }
- function CheckImageName(&$imgparams, $string)
- {
- $checked = myarraysearch($imgparams, $string);
- return $checked;
- }
- function ReplaceImgTag($content)
- {
- $newcontent = $content;
- $matches = array();
- preg_match_all('(<img .*>)', $content, $matches);
- while (list(, $match) = each($matches)) {
- while (list(, $imageTag) = each($match)) {
- $imgname = GetSrcName($imageTag);
- if ($imgname != '') {
- $prehref = $imgname;
- $posthref = basename($imgname);
- $newcontent = str_replace($prehref, $posthref, $newcontent);
- }
- }
- }
- return $newcontent;
- }
- function FillFolderName($name, $nsize)
- {
- $str = '';
- for ($i = 0; $i < $nsize - strlen($name); $i++) {
- $str .= '0';
- }
- $str .= $name;
- return $str;
- }
- function GenerateHpFolder($folder)
- {
- $filelist = array();
- if ($dir = @opendir($folder)) {
- while (($file = readdir($dir)) !== false) {
- if ($file != '.') {
- if ($file != '..') {
- $full_name = $folder.'/'.$file;
- if (is_dir($full_name)) {
- $filelist[] = $file;
- }
- }
- }
- }
- }
- $name = '';
- $w = true;
- while ($w == true) {
- $name = FillFolderName(mt_rand(1, 99999), 6);
- $checked = myarraysearch($filelist, $name);
-
- if (!$checked) {
- $w = false;
- }
- }
- return $name;
- }
- function GetFolderName($fname)
- {
- $name = explode('/', $fname);
- $name = $name[sizeof($name) - 2];
- return $name;
- }
- function GetFolderPath($fname)
- {
- $str = '';
- $name = explode('/', $fname);
- for ($i = 0; $i < sizeof($name) - 1; $i++) {
- $str = $str.$name[$i].'/';
- }
- return $str;
- }
- function CheckSubFolder($path)
- {
- $folder = GetFolderPath($path);
- $dflag = 0;
- if ($dir = @opendir($folder)) {
- while (($file = readdir($dir)) !== false) {
- if ($file != '.') {
- if ($file != '..') {
- $full_name = $folder.'/'.$file;
- if (is_dir($full_name)) {
- $dflag = 1;
- }
- }
- }
- }
- }
- return $dflag;
- }
- function HotPotGCt($folder, $flag, $user_id)
- {
-
- $filelist = array();
- if ($dir = @opendir($folder)) {
- while (($file = readdir($dir)) !== false) {
- if ($file != '.') {
- if ($file != '..') {
- $full_name = $folder.'/'.$file;
- if (is_dir($full_name)) {
- HotPotGCt($folder.'/'.$file, $flag, $user_id);
- } else {
- $filelist[] = $file;
- }
- }
- }
- }
- closedir($dir);
- }
- while (list(, $val) = each($filelist)) {
- if (stristr($val, $user_id.'.t.html')) {
- if ($flag == 1) {
- my_delete($folder.'/'.$val);
- } else {
- echo $folder.'/'.$val.'<br />';
- }
- }
- }
- }
- function deleteAttempt($id)
- {
- $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
- $id = intval($id);
- $sql = "DELETE FROM $table WHERE id = $id";
- Database::query($sql);
- }
|