2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
12 define('AT_INCLUDE_PATH', 'include/');
13 require(AT_INCLUDE_PATH . 'vitals.inc.php');
15 // hack for eXe content, remove now
16 header ('content-type: text/css');
17 echo('@import url(exestyles.css);');
21 if (isset ($_GET['cid'])){
22 $cid = intval ($_GET['cid']);
24 $sql = "SELECT * FROM ".TABLE_PREFIX."head WHERE course_id=$_SESSION[course_id] AND content_id=$cid";
25 $result = mysql_query($sql, $db);
27 if (($result != 0) && ($row = mysql_fetch_assoc($result))){
29 $styleText = get_styles ($row['text'], $_GET['path']);
31 header ('content-type: text/css');
36 // Takes the contents of the 'head' section and returns the 'style' and 'link' elements.
37 function get_styles ($headText, $path) {
40 // get the contents of all the 'style' elements
41 $styleStartPos = strpos ($headText, '<style');
42 while ($styleStartPos !== false) {
44 // remove the start and end 'style' elements
45 // (we're using just the contents of the 'style' element)
46 $styleStartPos = strPos ($headText, '>', $styleStartPos) + 1;
47 $styleEndPos = strPos ($headText, '</style', $styleStartPos) -1;
49 // contents of 'style' element
50 $tempString = substr ($headText, $styleStartPos, ($styleEndPos - $styleStartPos) + 1);
52 // add full path to any 'import' statements
53 $importStartPos = strpos ($tempString, '@import');
54 if ($importStartPos !== false){
55 $bracketStartPos = strpos ($tempString, '(', $importStartPos);
56 if ($bracketStartPos !== false){
57 $bracketEndPos = strpos ($tempString, ')', $bracketStartPos);
58 if ($bracketEndPos !== false){
59 $uriCss = trim (substr ($tempString, $bracketStartPos + 1, ($bracketEndPos - $bracketStartPos)));
61 $tempString2 = substr ($tempString, '0', $bracketStartPos);
62 $tempString = $tempString2.'('.$path.$uriCss.substr ($tempString, $bracketEndPos + '1');
67 $styleText = $styleText."\n".$tempString;
69 // look for another 'style' element
70 $styleStartPos = strpos ($headText, '<style', $styleEndPos);
73 // get all the links to external stylesheets
74 $linkStartPos = strpos ($headText, '<link');
75 while ($linkStartPos !== false) {
76 $linkEndPos = strPos ($headText, '>', $linkStartPos);
78 // ensure this is a 'stylesheet' link
79 $stylesheetPos = strpos ($headText, "\"text/css\"", $linkStartPos);
80 if (($stylesheetPos !== false) && ($stylesheetPos < $linkEndPos)){
82 // get the 'href' attribute value
83 $hrefPos = strpos ($headText, 'href', $linkStartPos);
84 if ($hrefPos !== false){
85 $hrefPos = strpos ($headText, '=', $hrefPos);
86 if ($hrefPos !== false){
89 // get first character in attribute value
92 // find first attribute character
93 while (($headText[$index] == " ") || ($headText[$index] == '\'') || ($headText[$index] == "\"")){
95 if ($index > strlen($headText)){
101 // find end of attribute character
102 $indexEnd = $indexStart;
103 while (($headText[$indexEnd] != " ") && ($headText[$indexEnd] != '\'') && ($headText[$indexEnd] != "\"")){
105 if ($index > strlen($headText)){
112 // convert the href attribute value to an "import url" statement
113 $importStatement = '@import url('.$path.substr ($headText, $indexStart, ($indexEnd - $indexStart)).');';
114 $styleText = $styleText."\n".$importStatement;
117 // look for another 'link' element
118 $linkStartPos = strpos ($headText, '<link', $linkEndPos);