Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/cc/entity11.forum.class.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00023 defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
00024 
00025 class cc11_forum extends entities11 {
00026 
00027     public function full_path ($path, $dir_sep = DIRECTORY_SEPARATOR) {
00028 
00029         $token = '$IMS-CC-FILEBASE$';
00030         $path = str_replace($token, '', $path);
00031 
00032         if (is_string($path) && ($path != '')) {
00033             $dir_sep;
00034             $dot_dir = '.';
00035             $up_dir = '..';
00036             $length = strlen($path);
00037             $rtemp = trim($path);
00038             $start = strrpos($path, $dir_sep);
00039             $can_continue = ($start !== false);
00040             $result = $can_continue ? '' : $path;
00041             $rcount = 0;
00042 
00043             while ($can_continue) {
00044 
00045                 $dir_part = ($start !== false) ? substr($rtemp, $start + 1, $length - $start) : $rtemp;
00046                 $can_continue = ($dir_part !== false);
00047 
00048                 if ($can_continue) {
00049                     if ($dir_part != $dot_dir) {
00050                         if ($dir_part == $up_dir) {
00051                             $rcount++;
00052                         } else {
00053                             if ($rcount > 0) {
00054                                 $rcount --;
00055                             } else {
00056                                 $result = ($result == '') ? $dir_part : $dir_part . $dir_sep . $result;
00057                             }
00058                         }
00059                     }
00060                     $rtemp = substr($path, 0, $start);
00061                     $start = strrpos($rtemp, $dir_sep);
00062                     $can_continue = (($start !== false) || (strlen($rtemp) > 0));
00063                 }
00064             }
00065         }
00066 
00067         return $result;
00068     }
00069 
00070     public function generate_node () {
00071 
00072         cc2moodle::log_action('Creating Forum mods');
00073 
00074         $response = '';
00075 
00076         if (!empty(cc2moodle::$instances['instances'][MOODLE_TYPE_FORUM])) {
00077             foreach (cc2moodle::$instances['instances'][MOODLE_TYPE_FORUM] as $instance) {
00078                 $response .= $this->create_node_course_modules_mod_forum($instance);
00079             }
00080         }
00081 
00082         return $response;
00083     }
00084 
00085     private function create_node_course_modules_mod_forum ($instance) {
00086 
00087         $sheet_mod_forum = cc112moodle::loadsheet(SHEET_COURSE_SECTIONS_SECTION_MODS_MOD_FORUM);
00088 
00089         $topic_data = $this->get_topic_data($instance);
00090 
00091         $result = '';
00092         if (!empty($topic_data)) {
00093 
00094             $find_tags = array('[#mod_instance#]',
00095                                    '[#mod_forum_title#]',
00096                                    '[#mod_forum_intro#]',
00097                                    '[#date_now#]');
00098 
00099             $replace_values = array($instance['instance'],
00100             //To be more true to the actual forum name we use only forum title
00101             self::safexml($topic_data['title']),
00102             self::safexml($topic_data['description']),
00103             time());
00104 
00105             $result = str_replace($find_tags, $replace_values, $sheet_mod_forum);
00106 
00107         }
00108 
00109         return $result;
00110     }
00111 
00112     public function get_topic_data ($instance) {
00113 
00114         $topic_data = '';
00115 
00116         $topic_file = $this->get_external_xml($instance['resource_indentifier']);
00117 
00118         if (!empty($topic_file)) {
00119 
00120             $topic_file_path = cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $topic_file;
00121             $topic_file_dir = dirname($topic_file_path);
00122             $topic = $this->load_xml_resource($topic_file_path);
00123 
00124             if (!empty($topic)) {
00125 
00126                 $xpath = cc2moodle::newx_path($topic, cc112moodle::$forumns);
00127 
00128                 $topic_title = $xpath->query('/dt:topic/dt:title');
00129                 if ($topic_title->length > 0 && !empty($topic_title->item(0)->nodeValue)) {
00130                     $topic_title = $topic_title->item(0)->nodeValue;
00131                 } else {
00132                     $topic_title = 'Untitled Topic';
00133                 }
00134 
00135                 $topic_text = $xpath->query('/dt:topic/dt:text');
00136                 $topic_text = !empty($topic_text->item(0)->nodeValue) ? $this->update_sources($topic_text->item(0)->nodeValue, dirname($topic_file)) : '';
00137                 $topic_text = !empty($topic_text) ? str_replace("%24", "\$", $this->include_titles($topic_text)) : '';
00138 
00139                 if (!empty($topic_title)) {
00140                     $topic_data['title'] = $topic_title;
00141                     $topic_data['description'] = $topic_text;
00142                 }
00143             }
00144 
00145             $topic_attachments = $xpath->query('/dt:topic/dt:attachments/dt:attachment/@href');
00146 
00147             if ($topic_attachments->length > 0) {
00148 
00149                 $attachment_html = '';
00150 
00151                 foreach ($topic_attachments as $file) {
00152                     $attachment_html .= $this->generate_attachment_html($this->full_path($file->nodeValue,'/'));
00153                 }
00154 
00155                 $topic_data['description'] = !empty($attachment_html) ? $topic_text . '<p>Attachments:</p>' . $attachment_html : $topic_text;
00156             }
00157         }
00158 
00159         return $topic_data;
00160     }
00161 
00162     private function generate_attachment_html ($filename) {
00163 
00164         $images_extensions = array('gif' , 'jpeg' , 'jpg' , 'jif' , 'jfif' , 'png' , 'bmp');
00165 
00166         $fileinfo = pathinfo($filename);
00167 
00168         if (in_array($fileinfo['extension'], $images_extensions)) {
00169             return '<img src="$@FILEPHP@$/' . $filename . '" title="' . $fileinfo['basename'] . '" alt="' . $fileinfo['basename'] . '" /><br />';
00170         } else {
00171             return '<a href="$@FILEPHP@$/' . $filename . '" title="' . $fileinfo['basename'] . '" alt="' . $fileinfo['basename'] . '">' . $fileinfo['basename'] . '</a><br />';
00172         }
00173 
00174         return '';
00175     }
00176 }
00177 
 All Data Structures Namespaces Files Functions Variables Enumerations