Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/cc/entity.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/>.
00024 defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
00025 
00026 class cc_forum extends entities {
00027 
00028     public function full_path ($path, $dir_sep = DIRECTORY_SEPARATOR) {
00029 
00030         $token = '$IMS-CC-FILEBASE$';
00031         $path = str_replace($token, '', $path);
00032 
00033         if (is_string($path) && ($path != '')) {
00034             $dir_sep;
00035             $dot_dir = '.';
00036             $up_dir = '..';
00037             $length = strlen($path);
00038             $rtemp = trim($path);
00039             $start = strrpos($path, $dir_sep);
00040             $can_continue = ($start !== false);
00041             $result = $can_continue ? '' : $path;
00042             $rcount = 0;
00043 
00044             while ($can_continue) {
00045 
00046                 $dir_part = ($start !== false) ? substr($rtemp, $start + 1, $length - $start) : $rtemp;
00047                 $can_continue = ($dir_part !== false);
00048 
00049                 if ($can_continue) {
00050                     if ($dir_part != $dot_dir) {
00051                         if ($dir_part == $up_dir) {
00052                             $rcount++;
00053                         } else {
00054                             if ($rcount > 0) {
00055                                 $rcount --;
00056                             } else {
00057                                 $result = ($result == '') ? $dir_part : $dir_part . $dir_sep . $result;
00058                             }
00059                         }
00060                     }
00061                     $rtemp = substr($path, 0, $start);
00062                     $start = strrpos($rtemp, $dir_sep);
00063                     $can_continue = (($start !== false) || (strlen($rtemp) > 0));
00064                 }
00065             }
00066         }
00067 
00068         return $result;
00069     }
00070 
00071     public function generate_node () {
00072 
00073         cc2moodle::log_action('Creating Forum mods');
00074 
00075         $response = '';
00076 
00077         if (!empty(cc2moodle::$instances['instances'][MOODLE_TYPE_FORUM])) {
00078             foreach (cc2moodle::$instances['instances'][MOODLE_TYPE_FORUM] as $instance) {
00079                 $response .= $this->create_node_course_modules_mod_forum($instance);
00080             }
00081         }
00082 
00083         return $response;
00084     }
00085 
00086     private function create_node_course_modules_mod_forum ($instance) {
00087 
00088         $sheet_mod_forum = cc2moodle::loadsheet(SHEET_COURSE_SECTIONS_SECTION_MODS_MOD_FORUM);
00089 
00090         $topic_data = $this->get_topic_data($instance);
00091 
00092         $result = '';
00093         if (!empty($topic_data)) {
00094 
00095             $find_tags = array('[#mod_instance#]',
00096                                '[#mod_forum_title#]',
00097                                '[#mod_forum_intro#]',
00098                                '[#date_now#]');
00099 
00100             $replace_values = array($instance['instance'],
00101                                     //To be more true to the actual forum name we use only forum title
00102                                     self::safexml($topic_data['title']),
00103                                     self::safexml($topic_data['description']),
00104                                     time());
00105 
00106             $result = str_replace($find_tags, $replace_values, $sheet_mod_forum);
00107 
00108         }
00109 
00110         return $result;
00111     }
00112 
00113     public function get_topic_data ($instance) {
00114 
00115         $topic_data = '';
00116 
00117         $topic_file = $this->get_external_xml($instance['resource_indentifier']);
00118 
00119         if (!empty($topic_file)) {
00120 
00121             $topic_file_path = cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $topic_file;
00122             $topic_file_dir = dirname($topic_file_path);
00123             $topic = $this->load_xml_resource($topic_file_path);
00124 
00125             if (!empty($topic)) {
00126 
00127                 $xpath = cc2moodle::newx_path($topic, cc2moodle::getforumns());
00128 
00129                 $topic_title = $xpath->query('/dt:topic/title');
00130                 $topic_title = !empty($topic_title->item(0)->nodeValue) ? $topic_title->item(0)->nodeValue : 'Untitled Topic';
00131 
00132                 $topic_text = $xpath->query('/dt:topic/text');
00133                 $topic_text = !empty($topic_text->item(0)->nodeValue) ? $this->update_sources($topic_text->item(0)->nodeValue, dirname($topic_file)) : '';
00134                 $topic_text = !empty($topic_text) ? str_replace("%24", "\$", $this->include_titles($topic_text)) : '';
00135 
00136                 if (!empty($topic_title)) {
00137                     $topic_data['title'] = $topic_title;
00138                     $topic_data['description'] = $topic_text;
00139                 }
00140             }
00141 
00142             $topic_attachments = $xpath->query('/dt:topic/attachments/attachment/@href');
00143 
00144             if ($topic_attachments->length > 0) {
00145 
00146                 $attachment_html = '';
00147 
00148                 foreach ($topic_attachments as $file) {
00149                     $attachment_html .= $this->generate_attachment_html($this->full_path($file->nodeValue,'/'));
00150                 }
00151 
00152                 $topic_data['description'] = !empty($attachment_html) ? $topic_text . '<p>Attachments:</p>' . $attachment_html : $topic_text;
00153             }
00154         }
00155 
00156         return $topic_data;
00157     }
00158 
00159     private function generate_attachment_html ($filename) {
00160 
00161         $images_extensions = array('gif' , 'jpeg' , 'jpg' , 'jif' , 'jfif' , 'png' , 'bmp');
00162 
00163         $fileinfo = pathinfo($filename);
00164 
00165         if (in_array($fileinfo['extension'], $images_extensions)) {
00166             return '<img src="$@FILEPHP@$/' . $filename . '" title="' . $fileinfo['basename'] . '" alt="' . $fileinfo['basename'] . '" /><br />';
00167         } else {
00168             return '<a href="$@FILEPHP@$/' . $filename . '" title="' . $fileinfo['basename'] . '" alt="' . $fileinfo['basename'] . '">' . $fileinfo['basename'] . '</a><br />';
00169         }
00170 
00171         return '';
00172     }
00173 }
 All Data Structures Namespaces Files Functions Variables Enumerations