ソースを参照

Adding webodf document page see #4602

Julio Montoya 13 年 前
コミット
0485066bc8
3 ファイル変更84 行追加4 行削除
  1. 67 0
      main/document/edit_odf.php
  2. 12 3
      main/document/showinframes.php
  3. 5 1
      main/inc/lib/document.lib.php

+ 67 - 0
main/document/edit_odf.php

@@ -0,0 +1,67 @@
+<?php
+
+require_once '../inc/global.inc.php';
+
+$document_id = $_GET['id'];
+
+if ($document_id) {
+    $document_data = DocumentManager::get_document_data_by_id($document_id);
+    if (empty($document_data)) {
+        api_not_allowed();    
+    }
+} else {
+    api_not_allowed();
+}
+
+//Check user visibility
+//$is_visible = DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id());
+$is_visible = DocumentManager::check_visibility_tree($document_id, api_get_course_id(), api_get_session_id(), api_get_user_id());
+
+if (!api_is_allowed_to_edit() && !$is_visible) {
+    api_not_allowed(true);
+}
+
+$header_file  = $document_data['path'];
+$pathinfo = pathinfo($header_file);
+
+$show_web_odf = false;
+$web_odf_supported_files = DocumentManager::get_web_odf_extension_list();
+
+if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) {
+    $show_web_odf  = true;
+}
+
+$file_url_web = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$header_file.'?'.api_get_cidreq();
+
+if ($show_web_odf) {
+    $htmlHeadXtra[] = api_get_js('webodf/webodf.js');
+    $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/webodf/webodf.css');
+    $htmlHeadXtra[] = '
+    <script type="text/javascript" charset="utf-8">        
+        function init() {
+                var odfelement = document.getElementById("odf"),
+                odfcanvas = new odf.OdfCanvas(odfelement);
+                odfcanvas.load("'.$file_url_web.'");
+        }
+        $(document).ready(function() {        
+            window.setTimeout(init, 0);
+        });        
+  </script>';  
+}
+
+$interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($my_cur_dir_path).$req_gid, "name"=> get_lang('Documents'));
+
+// Interbreadcrumb for the current directory root path
+if (empty($document_data['parents'])) {
+    $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
+} else {    
+    foreach($document_data['parents'] as $document_sub_data) {
+        if ($document_data['title'] == $document_sub_data['title']) {
+            continue;
+        }
+        $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
+    }
+}
+Display::display_header('');
+echo '<div id="odf"></div>';
+Display::display_footer();

+ 12 - 3
main/document/showinframes.php

@@ -198,15 +198,24 @@ $htmlHeadXtra[] = '
 -->
 </script>';
 
+$pathinfo = pathinfo($header_file);
 
-//Display::display_header($tool_name, 'User');
+$web_odf_supported_files = DocumentManager::get_web_odf_extension_list();
+if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) {
+    $show_web_odf  = true;
+}
 
 Display::display_header('');
+
 echo "<div align=\"center\">";
 $file_url_web = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$header_file.'?'.api_get_cidreq();
-echo '<a class="btn" href="'.$file_url_web.'" target="_blank">'.get_lang('_cut_paste_link').'</a></div>';
+echo '<a class="btn" href="'.$file_url_web.'" target="_blank">'.get_lang('_cut_paste_link').'</a>';
+
+if ($show_web_odf) {
+    //echo Display::url(get_lang('Show'), api_get_path(WEB_CODE_PATH).'document/edit_odf.php?id='.$document_data['id'], array('class' => 'btn'));
+}
+echo "</div>";
 
-$pathinfo =pathinfo($header_file);
 if ($pathinfo['extension']=='wav' && api_get_setting('enable_nanogong') == 'true'){
 	echo '<div align="center">';
 		echo '<br/>';

+ 5 - 1
main/inc/lib/document.lib.php

@@ -28,7 +28,7 @@ define('DEFAULT_DOCUMENT_QUOTA', $default_quota);
  *	@package chamilo.library
  */
 class DocumentManager {
-
+    
     private function __construct() {
 
     }
@@ -2964,5 +2964,9 @@ class DocumentManager {
         }
         return true;
     }
+    
+    public function get_web_odf_extension_list(){
+        return array('ods', 'odt');
+    }
 }
 //end class DocumentManager