mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
Merging language-pack-related updates from Eloy's MOODLE_16_UTF8 branch.
Do not use that branch any more!!
This commit is contained in:
parent
678943cba7
commit
6aaa17c7cc
@ -5,6 +5,7 @@
|
||||
header('Location: ../install.php');
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
require_once("../config.php");
|
||||
include_once("$CFG->dirroot/lib/adminlib.php"); // Contains various admin-only functions
|
||||
@ -74,7 +75,7 @@
|
||||
@set_time_limit(0);
|
||||
@ob_implicit_flush(true);
|
||||
@ob_end_flush();
|
||||
|
||||
|
||||
|
||||
/// Check if the main tables have been installed yet or not.
|
||||
|
||||
@ -205,9 +206,18 @@
|
||||
if (!set_config("release", $release)) {
|
||||
notify("ERROR: Could not update release version in database!!");
|
||||
}
|
||||
if (!empty($CFG->unicodedb)) {
|
||||
$defaultlang = 'en_utf8';
|
||||
} else {
|
||||
$defaultlang = 'en';
|
||||
}
|
||||
print_continue("index.php");
|
||||
print_simple_box_start("CENTER");
|
||||
include("$CFG->dirroot/lang/en/docs/release.html");
|
||||
if (file_exists("$CFG->dataroot/lang/$defaultlang/docs/release.html")) {
|
||||
include("$CFG->dataroot/lang/$defaultlang/docs/release.html");
|
||||
} else if (file_exists("$CFG->dirroot/lang/$defaultlang/docs/release.html")) {
|
||||
include("$CFG->dirroot/lang/$defaultlang/docs/release.html");
|
||||
}
|
||||
print_simple_box_end();
|
||||
print_continue("index.php");
|
||||
exit;
|
||||
|
@ -46,7 +46,7 @@
|
||||
|
||||
/// Otherwise print the form.
|
||||
|
||||
$module = required_param('module', '', PARAM_CLEANFILE);
|
||||
$module = optional_param('module', '', PARAM_CLEANFILE);
|
||||
require_once("$CFG->dirroot/mod/$module/lib.php");
|
||||
|
||||
$stradmin = get_string("administration");
|
||||
|
@ -52,7 +52,7 @@
|
||||
'gdversion' => 1,
|
||||
'guestloginbutton' => 1,
|
||||
'htmleditor' => true,
|
||||
'lang' => 'en',
|
||||
'lang' => !empty($CFG->unicodedb) ? 'en_utf8' : 'en',
|
||||
'langcache' => 1,
|
||||
'langmenu' => 1,
|
||||
'langlist' => '',
|
||||
|
431
lib/excellib.class.php
Normal file
431
lib/excellib.class.php
Normal file
@ -0,0 +1,431 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// We need to add this to allow "our" PEAR package to work smoothly
|
||||
/// without modifying one bit, putting it in the 1st place of the
|
||||
/// include_path to be localised by Moodle without problems
|
||||
ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));
|
||||
|
||||
require_once 'Spreadsheet/Excel/Writer.php';
|
||||
|
||||
/**
|
||||
* Define and operate over one Moodle Workbook.
|
||||
*
|
||||
* A big part of this class acts as a wrapper over the PEAR
|
||||
* Spreadsheet_Excel_Writer_Workbook and OLE libraries
|
||||
* maintaining Moodle functions isolated from underlying code.
|
||||
*/
|
||||
class MoodleExcelWorkbook {
|
||||
|
||||
var $pear_excel_workbook;
|
||||
|
||||
/* Constructs one Moodle Workbook.
|
||||
* @param string $filename The name of the file
|
||||
*/
|
||||
function MoodleExcelWorkbook($filename) {
|
||||
/// Internally, create one PEAR Spreadsheet_Excel_Writer_Workbook class
|
||||
$this->pear_excel_workbook = new Spreadsheet_Excel_Writer($filename);
|
||||
/// Prepare it to accept UTF-16LE data and to encode it properly
|
||||
$this->pear_excel_workbook->setVersion(8);
|
||||
}
|
||||
|
||||
/* Create one Moodle Worksheet
|
||||
* @param string $name Name of the sheet
|
||||
*/
|
||||
function &add_worksheet($name = '') {
|
||||
/// Create the Moodle Worksheet. Returns one pointer to it
|
||||
$ws =& new MoodleExcelWorksheet ($name, $this->pear_excel_workbook);
|
||||
return $ws;
|
||||
}
|
||||
|
||||
/* Create one Moodle Format
|
||||
* @param array $properties array of properties [name]=value;
|
||||
* valid names are set_XXXX existing
|
||||
* functions without the set_ part
|
||||
* i.e: [bold]=1 for set_bold(1)...Optional!
|
||||
*/
|
||||
function &add_format($properties = array()) {
|
||||
/// Create the Moodle Format. Returns one pointer to it
|
||||
$ft =& new MoodleExcelFormat ($this->pear_excel_workbook, $properties);
|
||||
return $ft;
|
||||
}
|
||||
|
||||
/* Close the Moodle Workbook
|
||||
*/
|
||||
function close() {
|
||||
$this->pear_excel_workbook->close();
|
||||
}
|
||||
|
||||
/* Write the correct HTTP headers
|
||||
* @param string $name Name of the downloaded file
|
||||
*/
|
||||
function send($filename) {
|
||||
$this->pear_excel_workbook->send($filename);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define and operate over one Worksheet.
|
||||
*
|
||||
* A big part of this class acts as a wrapper over the PEAR
|
||||
* Spreadsheet_Excel_Writer_Workbook and OLE libraries
|
||||
* maintaining Moodle functions isolated from underlying code.
|
||||
*/
|
||||
class MoodleExcelWorksheet {
|
||||
|
||||
var $pear_excel_worksheet;
|
||||
|
||||
/* Constructs one Moodle Worksheet.
|
||||
* @param string $filename The name of the file
|
||||
* @param object $workbook The internal PEAR Workbook onject we are creating
|
||||
*/
|
||||
function MoodleExcelWorksheet($name, &$workbook) {
|
||||
/// Internally, add one sheet to the workbook
|
||||
$this->pear_excel_worksheet =& $workbook->addWorksheet($name);
|
||||
/// Set encoding to UTF-16LE
|
||||
$this->pear_excel_worksheet->setInputEncoding('UTF-16LE');
|
||||
}
|
||||
|
||||
/* Write one string somewhere in the worksheet
|
||||
* @param integer $row Zero indexed row
|
||||
* @param integer $col Zero indexed column
|
||||
* @param string $str The string to write
|
||||
* @param mixed $format The XF format for the cell
|
||||
*/
|
||||
function write_string($row, $col, $str, $format=0) {
|
||||
/// Calculate the internal PEAR format
|
||||
$format = $this->MoodleExcelFormat2PearExcelFormat($format);
|
||||
/// Loading the textlib singleton instance. We are going to need it.
|
||||
$textlib = textlib_get_instance();
|
||||
/// Convert the text from its original encoding to UTF-16LE
|
||||
$str = $textlib->convert($str, current_charset(), 'utf-16le');
|
||||
/// Add the string safely to the PEAR Worksheet
|
||||
$this->pear_excel_worksheet->writeString($row, $col, $str, $format);
|
||||
}
|
||||
|
||||
/* Write one number somewhere in the worksheet
|
||||
* @param integer $row Zero indexed row
|
||||
* @param integer $col Zero indexed column
|
||||
* @param float $num The number to write
|
||||
* @param mixed $format The XF format for the cell
|
||||
*/
|
||||
function write_number($row, $col, $num, $format=0) {
|
||||
/// Calculate the internal PEAR format
|
||||
$format = $this->MoodleExcelFormat2PearExcelFormat($format);
|
||||
/// Add the number safely to the PEAR Worksheet
|
||||
$this->pear_excel_worksheet->writeNumber($row, $col, $num, $format);
|
||||
}
|
||||
|
||||
/* Write one url somewhere in the worksheet
|
||||
* @param integer $row Zero indexed row
|
||||
* @param integer $col Zero indexed column
|
||||
* @param string $url The url to write
|
||||
* @param mixed $format The XF format for the cell
|
||||
*/
|
||||
function write_url($row, $col, $url, $format=0) {
|
||||
/// Calculate the internal PEAR format
|
||||
$format = $this->MoodleExcelFormat2PearExcelFormat($format);
|
||||
/// Add the url safely to the PEAR Worksheet
|
||||
$this->pear_excel_worksheet->writeUrl($row, $col, $url, $format);
|
||||
}
|
||||
|
||||
/* Write one formula somewhere in the worksheet
|
||||
* @param integer $row Zero indexed row
|
||||
* @param integer $col Zero indexed column
|
||||
* @param string $formula The formula to write
|
||||
* @param mixed $format The XF format for the cell
|
||||
*/
|
||||
function write_formula($row, $col, $formula, $format=0) {
|
||||
/// Calculate the internal PEAR format
|
||||
$format = $this->MoodleExcelFormat2PearExcelFormat($format);
|
||||
/// Add the formula safely to the PEAR Worksheet
|
||||
$this->pear_excel_worksheet->writeFormula($row, $col, $formula, $format);
|
||||
}
|
||||
|
||||
/* Write one blanck somewhere in the worksheet
|
||||
* @param integer $row Zero indexed row
|
||||
* @param integer $col Zero indexed column
|
||||
* @param mixed $format The XF format for the cell
|
||||
*/
|
||||
function write_blank($row, $col, $format=0) {
|
||||
/// Calculate the internal PEAR format
|
||||
$format = $this->MoodleExcelFormat2PearExcelFormat($format);
|
||||
/// Add the blank safely to the PEAR Worksheet
|
||||
$this->pear_excel_worksheet->writeBlank($row, $col, $format);
|
||||
}
|
||||
|
||||
/* Write anything somewhere in the worksheet
|
||||
* Type will be automatically detected
|
||||
* @param integer $row Zero indexed row
|
||||
* @param integer $col Zero indexed column
|
||||
* @param mixed $token What we are writing
|
||||
* @param mixed $format The XF format for the cell
|
||||
*/
|
||||
function write($row, $col, $token, $format=0) {
|
||||
|
||||
/// Analyse what are we trying to send
|
||||
if (preg_match("/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/", $token)) {
|
||||
/// Match number
|
||||
return $this->write_number($row, $col, $token, $format);
|
||||
} elseif (preg_match("/^[fh]tt?p:\/\//", $token)) {
|
||||
/// Match http or ftp URL
|
||||
return $this->write_url($row, $col, $token, '', $format);
|
||||
} elseif (preg_match("/^mailto:/", $token)) {
|
||||
/// Match mailto:
|
||||
return $this->write_url($row, $col, $token, '', $format);
|
||||
} elseif (preg_match("/^(?:in|ex)ternal:/", $token)) {
|
||||
/// Match internal or external sheet link
|
||||
return $this->write_url($row, $col, $token, '', $format);
|
||||
} elseif (preg_match("/^=/", $token)) {
|
||||
/// Match formula
|
||||
return $this->write_formula($row, $col, $token, $format);
|
||||
} elseif (preg_match("/^@/", $token)) {
|
||||
/// Match formula
|
||||
return $this->write_formula($row, $col, $token, $format);
|
||||
} elseif ($token == '') {
|
||||
/// Match blank
|
||||
return $this->write_blank($row, $col, $format);
|
||||
} else {
|
||||
/// Default: match string
|
||||
return $this->write_string($row, $col, $token, $format);
|
||||
}
|
||||
}
|
||||
|
||||
/* Returns the PEAR Excel Format for one Moodle Excel Format
|
||||
* @param mixed MoodleExcelFormat object
|
||||
* @return mixed PEAR Excel Format object
|
||||
*/
|
||||
function MoodleExcelFormat2PearExcelFormat($format) {
|
||||
if ($format != 0) {
|
||||
return $format->pear_excel_format;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Define and operate over one Format.
|
||||
*
|
||||
* A big part of this class acts as a wrapper over the PEAR
|
||||
* Spreadsheet_Excel_Writer_Workbook and OLE libraries
|
||||
* maintaining Moodle functions isolated from underlying code.
|
||||
*/
|
||||
class MoodleExcelFormat {
|
||||
|
||||
var $pear_excel_format;
|
||||
|
||||
/* Constructs one Moodle Format.
|
||||
* @param object $workbook The internal PEAR Workbook onject we are creating
|
||||
*/
|
||||
function MoodleExcelFormat(&$workbook, $properties = array()) {
|
||||
/// Internally, add one sheet to the workbook
|
||||
$this->pear_excel_format =& $workbook->addFormat();
|
||||
/// If we have something in the array of properties, compute them
|
||||
foreach($properties as $property => $value) {
|
||||
if(method_exists($this,"set_$property")) {
|
||||
$aux = 'set_'.$property;
|
||||
$this->$aux($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set weight of the format
|
||||
* @param integer $weight Weight for the text, 0 maps to 400 (normal text),
|
||||
* 1 maps to 700 (bold text). Valid range is: 100-1000.
|
||||
* It's Optional, default is 1 (bold).
|
||||
*/
|
||||
function set_bold($weight = 1) {
|
||||
/// Set the bold safely to the PEAR Format
|
||||
$this->pear_excel_format->setBold($weight);
|
||||
}
|
||||
|
||||
/* Set underline of the format
|
||||
* @param integer $underline The value for underline. Possible values are:
|
||||
* 1 => underline, 2 => double underline
|
||||
*/
|
||||
function set_underline($underline) {
|
||||
/// Set the underline safely to the PEAR Format
|
||||
$this->pear_excel_format->setUnderline($underline);
|
||||
}
|
||||
|
||||
/* Set italic of the format
|
||||
*/
|
||||
function set_italic() {
|
||||
/// Set the italic safely to the PEAR Format
|
||||
$this->pear_excel_format->setItalic();
|
||||
}
|
||||
|
||||
/* Set strikeout of the format
|
||||
*/
|
||||
function set_strikeout() {
|
||||
/// Set the strikeout safely to the PEAR Format
|
||||
$this->pear_excel_format->setStrikeOut();
|
||||
}
|
||||
|
||||
/* Set outlining of the format
|
||||
*/
|
||||
function set_outline() {
|
||||
/// Set the outlining safely to the PEAR Format
|
||||
$this->pear_excel_format->setOutLine();
|
||||
}
|
||||
|
||||
/* Set shadow of the format
|
||||
*/
|
||||
function set_shadow() {
|
||||
/// Set the shadow safely to the PEAR Format
|
||||
$this->pear_excel_format->setShadow();
|
||||
}
|
||||
|
||||
/* Set the script of the text
|
||||
* @param integer $script The value for script type. Possible values are:
|
||||
* 1 => superscript, 2 => subscript
|
||||
*/
|
||||
function set_script($script) {
|
||||
/// Set the script safely to the PEAR Format
|
||||
$this->pear_excel_format->setScript($script);
|
||||
}
|
||||
|
||||
/* Set color of the format
|
||||
* @param mixed $color either a string (like 'blue'), or an integer (range is [8...63])
|
||||
*/
|
||||
function set_color($color) {
|
||||
/// Set the background color safely to the PEAR Format
|
||||
$this->pear_excel_format->setColor($color);
|
||||
}
|
||||
|
||||
/* Set foreground color of the format
|
||||
* @param mixed $color either a string (like 'blue'), or an integer (range is [8...63])
|
||||
*/
|
||||
function set_fg_color($color) {
|
||||
/// Set the foreground color safely to the PEAR Format
|
||||
$this->pear_excel_format->setFgColor($color);
|
||||
}
|
||||
|
||||
/* Set background color of the format
|
||||
* @param mixed $color either a string (like 'blue'), or an integer (range is [8...63])
|
||||
*/
|
||||
function set_bg_color($color) {
|
||||
/// Set the background color safely to the PEAR Format
|
||||
$this->pear_excel_format->setBgColor($color);
|
||||
}
|
||||
|
||||
/* Set the fill pattern of the format
|
||||
* @param integer Optional. Defaults to 1. Meaningful values are: 0-18
|
||||
* 0 meaning no background.
|
||||
*/
|
||||
function set_pattern($pattern=1) {
|
||||
/// Set the fill pattern safely to the PEAR Format
|
||||
$this->pear_excel_format->setPattern($pattern);
|
||||
}
|
||||
|
||||
/* Set text wrap of the format
|
||||
*/
|
||||
function set_text_wrap() {
|
||||
/// Set the shadow safely to the PEAR Format
|
||||
$this->pear_excel_format->setTextWrap();
|
||||
}
|
||||
|
||||
/* Set the cell alignment of the format
|
||||
* @param string $location alignment for the cell ('left', 'right', etc...)
|
||||
*/
|
||||
function set_align($location) {
|
||||
/// Set the alignment of the cell safely to the PEAR Format
|
||||
$this->pear_excel_format->setAlign($location);
|
||||
}
|
||||
|
||||
/* Set the cell horizontal alignment of the format
|
||||
* @param string $location alignment for the cell ('left', 'right', etc...)
|
||||
*/
|
||||
function set_h_align($location) {
|
||||
/// Set the alignment of the cell safely to the PEAR Format
|
||||
$this->pear_excel_format->setHAlign($location);
|
||||
}
|
||||
|
||||
/* Set the cell vertical alignment of the format
|
||||
* @param string $location alignment for the cell ('top', 'vleft', etc...)
|
||||
*/
|
||||
function set_v_align($location) {
|
||||
/// Set the alignment of the cell safely to the PEAR Format
|
||||
$this->pear_excel_format->setVAlign($location);
|
||||
}
|
||||
|
||||
/* Set the top border of the format
|
||||
* @param integer $style style for the cell. 1 => thin, 2 => thick
|
||||
*/
|
||||
function set_top($style) {
|
||||
/// Set the top border of the cell safely to the PEAR Format
|
||||
$this->pear_excel_format->setTop($style);
|
||||
}
|
||||
|
||||
/* Set the bottom border of the format
|
||||
* @param integer $style style for the cell. 1 => thin, 2 => thick
|
||||
*/
|
||||
function set_bottom($style) {
|
||||
/// Set the bottom border of the cell safely to the PEAR Format
|
||||
$this->pear_excel_format->setBottom($style);
|
||||
}
|
||||
|
||||
/* Set the left border of the format
|
||||
* @param integer $style style for the cell. 1 => thin, 2 => thick
|
||||
*/
|
||||
function set_left($style) {
|
||||
/// Set the left border of the cell safely to the PEAR Format
|
||||
$this->pear_excel_format->setLeft($style);
|
||||
}
|
||||
|
||||
/* Set the right border of the format
|
||||
* @param integer $style style for the cell. 1 => thin, 2 => thick
|
||||
*/
|
||||
function set_right($style) {
|
||||
/// Set the right border of the cell safely to the PEAR Format
|
||||
$this->pear_excel_format->setRight($style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cells borders to the same style
|
||||
* @param integer $style style to apply for all cell borders. 1 => thin, 2 => thick.
|
||||
*/
|
||||
function set_border($style) {
|
||||
/// Set all the borders of the cell safely to the PEAR Format
|
||||
$this->pear_excel_format->setBorder($style);
|
||||
}
|
||||
|
||||
/* Set the numerical format of the format
|
||||
* It can be date, time, currency, etc...
|
||||
/* Set the numerical format of the format
|
||||
* It can be date, time, currency, etc...
|
||||
* @param integer $num_format The numeric format
|
||||
*/
|
||||
function set_num_format($num_format) {
|
||||
/// Set the numerical format safely to the PEAR Format
|
||||
$this->pear_excel_format->setNumFormat($num_format);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -177,7 +177,7 @@ function send_file($path, $filename, $lifetime=86400 , $filter=false, $pathisstr
|
||||
if (!$filter) {
|
||||
@header('Content-length: '.$filesize);
|
||||
if ($mimetype == 'text/plain') {
|
||||
@header('Content-type: text/plain; charset='.get_string('thischarset')); //add encoding
|
||||
@header('Content-type: text/plain; charset='.current_charset()); //add encoding
|
||||
} else {
|
||||
@header('Content-type: '.$mimetype);
|
||||
}
|
||||
@ -208,7 +208,7 @@ function send_file($path, $filename, $lifetime=86400 , $filter=false, $pathisstr
|
||||
$output = '<pre>'. format_text($text, FORMAT_MOODLE, $options, $courseid) .'</pre>';
|
||||
|
||||
@header('Content-length: '.strlen($output));
|
||||
@header('Content-type: text/html; charset='. get_string('thischarset')); //add encoding
|
||||
@header('Content-type: text/html; charset='. current_charset()); //add encoding
|
||||
echo $output;
|
||||
} else { // Just send it out raw
|
||||
@header('Content-length: '.$filesize);
|
||||
|
@ -2752,7 +2752,7 @@ function set_login_session_preferences() {
|
||||
|
||||
unset($SESSION->lang);
|
||||
unset($SESSION->encoding);
|
||||
$SESSION->encoding = get_string('thischarset');
|
||||
$SESSION->encoding = current_charset();
|
||||
|
||||
// Restore the calendar filters, if saved
|
||||
if (intval(get_user_preferences('calendar_persistflt', 0))) {
|
||||
@ -3701,7 +3701,7 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
|
||||
if (!empty($course->lang)) { // Course language is defined
|
||||
$CFG->courselang = $course->lang;
|
||||
}
|
||||
if (!empty($course->theme)) { // Course language is defined
|
||||
if (!empty($course->theme)) { // Course theme is defined
|
||||
$CFG->coursetheme = $course->theme;
|
||||
}
|
||||
|
||||
@ -3725,10 +3725,7 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
|
||||
$mail->Version = 'Moodle '. $CFG->version; // mailer version
|
||||
$mail->PluginDir = $CFG->libdir .'/phpmailer/'; // plugin directory (eg smtp plugin)
|
||||
|
||||
|
||||
if (current_language() != 'en') {
|
||||
$mail->CharSet = get_string('thischarset');
|
||||
}
|
||||
$mail->CharSet = current_charset(true); //User charset, recalculating it in each call
|
||||
|
||||
if ($CFG->smtphosts == 'qmail') {
|
||||
$mail->IsQmail(); // use Qmail system
|
||||
@ -4538,6 +4535,32 @@ function current_language() {
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the code of the current charset
|
||||
* based in some config options and the lang being used
|
||||
* caching it per request.
|
||||
* @param $ignorecache to skip cached value and recalculate it again
|
||||
* @uses $CFG
|
||||
* @return string
|
||||
*/
|
||||
function current_charset($ignorecache = false) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
static $currentcharset;
|
||||
|
||||
if (!empty($currentcharset) and !$ignorecache) { /// Cached. Return it.
|
||||
return $currentcharset;
|
||||
}
|
||||
|
||||
if (!empty($CFG->unicode) || !empty($CFG->unicodedb)) {
|
||||
$currentcharset = 'UTF-8';
|
||||
} else {
|
||||
$currentcharset = get_string('thischarset');
|
||||
}
|
||||
|
||||
return $currentcharset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints out a translated string.
|
||||
*
|
||||
@ -4653,6 +4676,26 @@ function get_string($identifier, $module='', $a=NULL) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Depending upon $CFG->unicodedb, we are going to check moodle.php or langconfig.php,
|
||||
/// default to a different lang pack, and redefine the module for some special strings
|
||||
/// that, under 1.6 lang packs, reside under langconfig.php
|
||||
$langconfigstrs = array('alphabet', 'backupnameformat', 'firstdayofweek', 'locale',
|
||||
'parentlanguage', 'strftimedate', 'strftimedateshort', 'strftimedatetime',
|
||||
'strftimedaydate', 'strftimedaydatetime', 'strftimedayshort', 'strftimedaytime',
|
||||
'strftimemonthyear', 'strftimerecent', 'strftimerecentfull', 'strftimetime',
|
||||
'thischarset', 'thisdirection', 'thislanguage');
|
||||
|
||||
if (!empty($CFG->unicodedb)) {
|
||||
$filetocheck = 'langconfig.php';
|
||||
$defaultlang = 'en_utf8';
|
||||
if (in_array($identifier, $langconfigstrs)) {
|
||||
$module = 'langconfig'; //This strings are under langconfig.php for 1.6 lang packs
|
||||
}
|
||||
} else {
|
||||
$filetocheck = 'moodle.php';
|
||||
$defaultlang = 'en';
|
||||
}
|
||||
|
||||
$lang = current_language();
|
||||
|
||||
if ($module == '') {
|
||||
@ -4701,14 +4744,14 @@ function get_string($identifier, $module='', $a=NULL) {
|
||||
}
|
||||
|
||||
/// If the preferred language was English we can abort now
|
||||
if ($lang == 'en') {
|
||||
if ($lang == $defaultlang) {
|
||||
return '[['. $identifier .']]';
|
||||
}
|
||||
|
||||
/// Is a parent language defined? If so, try to find this string in a parent language file
|
||||
|
||||
foreach ($locations as $location) {
|
||||
$langfile = $location.$lang.'/moodle.php';
|
||||
$langfile = $location.$lang.'/'.$filetocheck;
|
||||
if (file_exists($langfile)) {
|
||||
if ($result = get_string_from_file('parentlanguage', $langfile, "\$parentlang")) {
|
||||
eval($result);
|
||||
@ -4739,7 +4782,7 @@ function get_string($identifier, $module='', $a=NULL) {
|
||||
/// Our only remaining option is to try English
|
||||
|
||||
foreach ($locations as $location) {
|
||||
$locallangfile = $location.'en_local/'.$module.'.php'; //first, see if there's a local file
|
||||
$locallangfile = $location.$defaultlang.'_local/'.$module.'.php'; //first, see if there's a local file
|
||||
if (file_exists($locallangfile)) {
|
||||
if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring")) {
|
||||
eval($result);
|
||||
@ -4748,7 +4791,8 @@ function get_string($identifier, $module='', $a=NULL) {
|
||||
}
|
||||
|
||||
//if local_en not found, or string not found in local_en
|
||||
$langfile = $location.'en/'.$module.'.php';
|
||||
$langfile = $location.$defaultlang.'/'.$module.'.php';
|
||||
|
||||
if (file_exists($langfile)) {
|
||||
if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) {
|
||||
eval($result);
|
||||
@ -4818,6 +4862,13 @@ function get_list_of_languages() {
|
||||
|
||||
$languages = array();
|
||||
|
||||
/// Depending upon $CFG->unicodedb, we are going to check moodle.php or langconfig.php
|
||||
if (!empty($CFG->unicodedb)) {
|
||||
$filetocheck = 'langconfig.php';
|
||||
} else {
|
||||
$filetocheck = 'moodle.php';
|
||||
}
|
||||
|
||||
if ( (!defined('FULLME') || FULLME !== 'cron')
|
||||
&& !empty($CFG->langcache) && file_exists($CFG->dataroot .'/cache/languages')) {
|
||||
// read from cache
|
||||
@ -4835,55 +4886,57 @@ function get_list_of_languages() {
|
||||
if (!empty($CFG->langlist)) { // use admin's list of languages
|
||||
$langlist = explode(',', $CFG->langlist);
|
||||
foreach ($langlist as $lang) {
|
||||
if (file_exists($CFG->dirroot .'/lang/'. $lang .'/moodle.php') and strstr('_local',$lang)!==false) {
|
||||
include($CFG->dirroot .'/lang/'. $lang .'/moodle.php');
|
||||
$languages[$lang] = $string['thislanguage'].' ('. $lang .')';
|
||||
$lang = trim($lang); //Just trim spaces to be a bit more permissive
|
||||
if (strstr('_local',$lang)!==false) {
|
||||
continue;
|
||||
}
|
||||
/// Search under dirroot/lang
|
||||
if (file_exists($CFG->dirroot .'/lang/'. $lang .'/'. $filetocheck)) {
|
||||
include($CFG->dirroot .'/lang/'. $lang .'/'. $filetocheck);
|
||||
if (!empty($string['thislanguage'])) {
|
||||
$languages[$lang] = $string['thislanguage'].' ('. $lang .')';
|
||||
}
|
||||
unset($string);
|
||||
}
|
||||
/// And moodledata/lang
|
||||
if (file_exists($CFG->dataroot .'/lang/'. $lang .'/'. $filetocheck)) {
|
||||
include($CFG->dataroot .'/lang/'. $lang .'/'. $filetocheck);
|
||||
if (!empty($string['thislanguage'])) {
|
||||
$languages[$lang] = $string['thislanguage'].' ('. $lang .')';
|
||||
}
|
||||
unset($string);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!$langdirs = get_list_of_plugins('lang')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//add langs from $CFG->moddata/lang
|
||||
$ilangdirs = get_list_of_plugins('lang','',1);
|
||||
foreach ($ilangdirs as $ilang){
|
||||
$langdirs[] = $ilang;
|
||||
}
|
||||
|
||||
asort($langdirs); //sort by value
|
||||
|
||||
/// Fetch langs from moodle/lang directory
|
||||
$langdirs = get_list_of_plugins('lang');
|
||||
/// Fetch langs from moodledata/lang directory
|
||||
$langdirs2 = get_list_of_plugins('lang', '', $CFG->dataroot);
|
||||
/// Merge both lists of langs
|
||||
$langdirs = array_merge($langdirs, $langdirs2);
|
||||
/// Sort all
|
||||
asort($langdirs);
|
||||
/// Get some info from each lang (first from moodledata, then from moodle)
|
||||
foreach ($langdirs as $lang) {
|
||||
|
||||
///check if the current lang is the right version
|
||||
///i.e. CFG->unicodedb set, 1.6 packs
|
||||
///CFG->unicode not set. 1.5 packs
|
||||
$unicodepack = file_exists($CFG->dirroot .'/lang/'. $lang .'/langconfig.php') OR
|
||||
file_exists($CFG->dataroot .'/lang/'. $lang .'/langconfig.php');
|
||||
|
||||
//if db is unicode, pack is not unicode, or db is not unicode, but pack is, we skip it
|
||||
if ((!empty($CFG->unicodedb) && !$unicodepack) or (empty($CFG->unicodedb) && $unicodepack)){
|
||||
if (strstr('_local',$lang)!==false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file_exists($CFG->dirroot .'/lang/'. $lang .'/moodle.php') and strstr($lang,'_local')===false) {
|
||||
include($CFG->dirroot .'/lang/'. $lang .'/moodle.php');
|
||||
@include($CFG->dirroot .'/lang/'. $lang .'/langconfig.php');
|
||||
$languages[$lang] = $string['thislanguage'] .' ('. $lang .')';
|
||||
if (file_exists($CFG->dataroot .'/lang/'. $lang .'/'. $filetocheck)) {
|
||||
include($CFG->dataroot .'/lang/'. $lang .'/'. $filetocheck);
|
||||
if (!empty($string['thislanguage'])) {
|
||||
$languages[$lang] = $string['thislanguage'] .' ('. $lang .')';
|
||||
}
|
||||
unset($string);
|
||||
}
|
||||
|
||||
if (file_exists($CFG->dataroot .'/lang/'. $lang .'/moodle.php') and strstr($lang,'_local')===false) {
|
||||
include($CFG->dataroot .'/lang/'. $lang .'/moodle.php');
|
||||
@include($CFG->dataroot .'/lang/'. $lang .'/langconfig.php');
|
||||
$languages[$lang] = $string['thislanguage'] .' ('. $lang .')';
|
||||
} else if (file_exists($CFG->dirroot .'/lang/'. $lang .'/'. $filetocheck)) {
|
||||
include($CFG->dirroot .'/lang/'. $lang .'/'. $filetocheck);
|
||||
if (!empty($string['thislanguage'])) {
|
||||
$languages[$lang] = $string['thislanguage'] .' ('. $lang .')';
|
||||
}
|
||||
unset($string);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ( defined('FULLME') && FULLME === 'cron' && !empty($CFG->langcache)) {
|
||||
if ($file = fopen($CFG->dataroot .'/cache/languages', 'w')) {
|
||||
foreach ($languages as $key => $value) {
|
||||
@ -4908,19 +4961,31 @@ function get_list_of_countries() {
|
||||
|
||||
$lang = current_language();
|
||||
|
||||
if (!file_exists($CFG->dirroot .'/lang/'. $lang .'/countries.php')) {
|
||||
if ($parentlang = get_string('parentlanguage')) {
|
||||
if (file_exists($CFG->dirroot .'/lang/'. $parentlang .'/countries.php')) {
|
||||
$lang = $parentlang;
|
||||
} else {
|
||||
$lang = 'en'; // countries.php must exist in this pack
|
||||
}
|
||||
} else {
|
||||
$lang = 'en'; // countries.php must exist in this pack
|
||||
}
|
||||
if (!empty($CFG->unicodedb)) {
|
||||
$defaultlang = 'en_utf8';
|
||||
} else {
|
||||
$defaultlang = 'en';
|
||||
}
|
||||
|
||||
include($CFG->dirroot .'/lang/'. $lang .'/countries.php');
|
||||
if (!file_exists($CFG->dirroot .'/lang/'. $lang .'/countries.php') &&
|
||||
!file_exists($CFG->dataroot.'/lang/'. $lang .'/countries.php')) {
|
||||
if ($parentlang = get_string('parentlanguage')) {
|
||||
if (file_exists($CFG->dirroot .'/lang/'. $parentlang .'/countries.php') ||
|
||||
file_exists($CFG->dataroot.'/lang/'. $parentlang .'/countries.php')) {
|
||||
$lang = $parentlang;
|
||||
} else {
|
||||
$lang = $defaultlang; // countries.php must exist in this pack
|
||||
}
|
||||
} else {
|
||||
$lang = $defaultlang; // countries.php must exist in this pack
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists($CFG->dataroot .'/lang/'. $lang .'/countries.php')) {
|
||||
include($CFG->dataroot .'/lang/'. $lang .'/countries.php');
|
||||
} else if (file_exists($CFG->dirroot .'/lang/'. $lang .'/countries.php')) {
|
||||
include($CFG->dirroot .'/lang/'. $lang .'/countries.php');
|
||||
}
|
||||
|
||||
if (!empty($string)) {
|
||||
asort($string);
|
||||
@ -5384,30 +5449,35 @@ function show_event($event) {
|
||||
* Lists plugin directories within some directory
|
||||
*
|
||||
* @uses $CFG
|
||||
* @param string $plugin ?
|
||||
* @param string $exclude ?
|
||||
* @return array
|
||||
* @todo Finish documenting this function
|
||||
* @param string $plugin dir under we'll look for plugins (defaults to 'mod')
|
||||
* @param string $exclude dir name to exclude from the list (defaults to none)
|
||||
* @param string $basedir full path to the base dir where $plugin resides (defaults to $CFG->dirroot)
|
||||
* @return array of plugins found under the requested parameters
|
||||
*/
|
||||
function get_list_of_plugins($plugin='mod', $exclude='', $dirmode='0') {
|
||||
function get_list_of_plugins($plugin='mod', $exclude='', $basedir='') {
|
||||
|
||||
global $CFG;
|
||||
if ($dirmode == 0){
|
||||
$rootdir = $CFG->dirroot;
|
||||
|
||||
$plugins = array();
|
||||
|
||||
if (empty($basedir)) {
|
||||
$basedir = $CFG->dirroot .'/'. $plugin;
|
||||
} else {
|
||||
$basedir = $basedir .'/'. $plugin;
|
||||
}
|
||||
else {
|
||||
$rootdir = $CFG->dataroot;
|
||||
}
|
||||
$basedir = opendir($rootdir .'/'. $plugin);
|
||||
while (false !== ($dir = readdir($basedir))) {
|
||||
$firstchar = substr($dir, 0, 1);
|
||||
if ($firstchar == '.' or $dir == 'CVS' or $dir == '_vti_cnf' or $dir == $exclude) {
|
||||
continue;
|
||||
if (filetype($basedir) == 'dir') {
|
||||
$dirhandle = opendir($basedir);
|
||||
while (false !== ($dir = readdir($dirhandle))) {
|
||||
$firstchar = substr($dir, 0, 1);
|
||||
if ($firstchar == '.' or $dir == 'CVS' or $dir == '_vti_cnf' or $dir == $exclude) {
|
||||
continue;
|
||||
}
|
||||
if (filetype($basedir .'/'. $dir) != 'dir') {
|
||||
continue;
|
||||
}
|
||||
$plugins[] = $dir;
|
||||
}
|
||||
if (filetype($rootdir .'/'. $plugin .'/'. $dir) != 'dir') {
|
||||
continue;
|
||||
}
|
||||
$plugins[] = $dir;
|
||||
closedir($dirhandle);
|
||||
}
|
||||
if ($plugins) {
|
||||
asort($plugins);
|
||||
@ -5776,6 +5846,23 @@ function count_words($string) {
|
||||
return count(preg_split("/\w\b/", $string)) - 1;
|
||||
}
|
||||
|
||||
/** Count letters in a string.
|
||||
*
|
||||
* Letters are defined as chars not in tags and different from whitespace.
|
||||
*
|
||||
* @param string $string The text to be searched for letters.
|
||||
* @return int The count of letters in the specified text.
|
||||
*/
|
||||
function count_letters($string) {
|
||||
/// Loading the textlib singleton instance. We are going to need it.
|
||||
$textlib = textlib_get_instance();
|
||||
|
||||
$string = strip_tags($string); // Tags are out now
|
||||
$string = ereg_replace('[[:space:]]*','',$string); //Whitespace are out now
|
||||
|
||||
return $textlib->strlen($string, current_charset());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and return a random string of the specified length.
|
||||
*
|
||||
|
410
lib/pear/OLE.php
Executable file
410
lib/pear/OLE.php
Executable file
@ -0,0 +1,410 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
/**
|
||||
* Constants for OLE package
|
||||
*/
|
||||
define('OLE_PPS_TYPE_ROOT', 5);
|
||||
define('OLE_PPS_TYPE_DIR', 1);
|
||||
define('OLE_PPS_TYPE_FILE', 2);
|
||||
define('OLE_DATA_SIZE_SMALL', 0x1000);
|
||||
define('OLE_LONG_INT_SIZE', 4);
|
||||
define('OLE_PPS_SIZE', 0x80);
|
||||
|
||||
require_once('PEAR.php');
|
||||
require_once 'OLE/PPS.php';
|
||||
|
||||
/**
|
||||
* OLE package base class.
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE extends PEAR
|
||||
{
|
||||
/**
|
||||
* The file handle for reading an OLE container
|
||||
* @var resource
|
||||
*/
|
||||
var $_file_handle;
|
||||
|
||||
/**
|
||||
* Array of PPS's found on the OLE container
|
||||
* @var array
|
||||
*/
|
||||
var $_list;
|
||||
|
||||
/**
|
||||
* Creates a new OLE object
|
||||
* Remember to use ampersand when creating an OLE object ($my_ole =& new OLE();)
|
||||
* @access public
|
||||
*/
|
||||
function OLE()
|
||||
{
|
||||
$this->_list = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an OLE container from the contents of the file given.
|
||||
*
|
||||
* @acces public
|
||||
* @param string $file
|
||||
* @return mixed true on success, PEAR_Error on failure
|
||||
*/
|
||||
function read($file)
|
||||
{
|
||||
/* consider storing offsets as constants */
|
||||
$big_block_size_offset = 30;
|
||||
$iBdbCnt_offset = 44;
|
||||
$bd_start_offset = 68;
|
||||
|
||||
$fh = @fopen($file, "r");
|
||||
if ($fh == false) {
|
||||
return $this->raiseError("Can't open file $file");
|
||||
}
|
||||
$this->_file_handle = $fh;
|
||||
|
||||
/* begin reading OLE attributes */
|
||||
fseek($fh, 0);
|
||||
$signature = fread($fh, 8);
|
||||
if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
|
||||
return $this->raiseError("File doesn't seem to be an OLE container.");
|
||||
}
|
||||
fseek($fh, $big_block_size_offset);
|
||||
$packed_array = unpack("v", fread($fh, 2));
|
||||
$big_block_size = pow(2, $packed_array['']);
|
||||
|
||||
$packed_array = unpack("v", fread($fh, 2));
|
||||
$small_block_size = pow(2, $packed_array['']);
|
||||
$i1stBdL = ($big_block_size - 0x4C) / OLE_LONG_INT_SIZE;
|
||||
|
||||
fseek($fh, $iBdbCnt_offset);
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$iBdbCnt = $packed_array[''];
|
||||
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$pps_wk_start = $packed_array[''];
|
||||
|
||||
fseek($fh, $bd_start_offset);
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$bd_start = $packed_array[''];
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$bd_count = $packed_array[''];
|
||||
$packed_array = unpack("V", fread($fh, 4));
|
||||
$iAll = $packed_array['']; // this may be wrong
|
||||
/* create OLE_PPS objects from */
|
||||
$ret = $this->_readPpsWks($pps_wk_start, $big_block_size);
|
||||
if (PEAR::isError($ret)) {
|
||||
return $ret;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor (using PEAR)
|
||||
* Just closes the file handle on the OLE file.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _OLE()
|
||||
{
|
||||
fclose($this->_file_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about all PPS's on the OLE container from the PPS WK's
|
||||
* creates an OLE_PPS object for each one.
|
||||
*
|
||||
* @access private
|
||||
* @param integer $pps_wk_start Position inside the OLE file where PPS WK's start
|
||||
* @param integer $big_block_size Size of big blobks in the OLE file
|
||||
* @return mixed true on success, PEAR_Error on failure
|
||||
*/
|
||||
function _readPpsWks($pps_wk_start, $big_block_size)
|
||||
{
|
||||
$pointer = ($pps_wk_start + 1) * $big_block_size;
|
||||
while (1)
|
||||
{
|
||||
fseek($this->_file_handle, $pointer);
|
||||
$pps_wk = fread($this->_file_handle, OLE_PPS_SIZE);
|
||||
if (strlen($pps_wk) != OLE_PPS_SIZE) {
|
||||
break; // Excel likes to add a trailing byte sometimes
|
||||
//return $this->raiseError("PPS at $pointer seems too short: ".strlen($pps_wk));
|
||||
}
|
||||
$name_length = unpack("c", substr($pps_wk, 64, 2)); // FIXME (2 bytes??)
|
||||
$name_length = $name_length[''] - 2;
|
||||
$name = substr($pps_wk, 0, $name_length);
|
||||
$type = unpack("c", substr($pps_wk, 66, 1));
|
||||
if (($type[''] != OLE_PPS_TYPE_ROOT) and
|
||||
($type[''] != OLE_PPS_TYPE_DIR) and
|
||||
($type[''] != OLE_PPS_TYPE_FILE))
|
||||
{
|
||||
return $this->raiseError("PPS at $pointer has unknown type: {$type['']}");
|
||||
}
|
||||
$prev = unpack("V", substr($pps_wk, 68, 4));
|
||||
$next = unpack("V", substr($pps_wk, 72, 4));
|
||||
$dir = unpack("V", substr($pps_wk, 76, 4));
|
||||
// there is no magic number, it can take different values.
|
||||
//$magic = unpack("V", strrev(substr($pps_wk, 92, 4)));
|
||||
$time_1st = substr($pps_wk, 100, 8);
|
||||
$time_2nd = substr($pps_wk, 108, 8);
|
||||
$start_block = unpack("V", substr($pps_wk, 116, 4));
|
||||
$size = unpack("V", substr($pps_wk, 120, 4));
|
||||
// _data member will point to position in file!!
|
||||
// OLE_PPS object is created with an empty children array!!
|
||||
$this->_list[] = new OLE_PPS(null, '', $type[''], $prev[''], $next[''],
|
||||
$dir[''], OLE::OLE2LocalDate($time_1st),
|
||||
OLE::OLE2LocalDate($time_2nd),
|
||||
($start_block[''] + 1) * $big_block_size, array());
|
||||
// give it a size
|
||||
$this->_list[count($this->_list) - 1]->Size = $size[''];
|
||||
// check if the PPS tree (starting from root) is complete
|
||||
if ($this->_ppsTreeComplete(0)) {
|
||||
break;
|
||||
}
|
||||
$pointer += OLE_PPS_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* It checks whether the PPS tree is complete (all PPS's read)
|
||||
* starting with the given PPS (not necessarily root)
|
||||
*
|
||||
* @access private
|
||||
* @param integer $index The index of the PPS from which we are checking
|
||||
* @return boolean Whether the PPS tree for the given PPS is complete
|
||||
*/
|
||||
function _ppsTreeComplete($index)
|
||||
{
|
||||
if ($this->_list[$index]->NextPps != -1) {
|
||||
if (!isset($this->_list[$this->_list[$index]->NextPps])) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return $this->_ppsTreeComplete($this->_list[$index]->NextPps);
|
||||
}
|
||||
}
|
||||
if ($this->_list[$index]->DirPps != -1) {
|
||||
if (!isset($this->_list[$this->_list[$index]->DirPps])) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return $this->_ppsTreeComplete($this->_list[$index]->DirPps);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a PPS is a File PPS or not.
|
||||
* If there is no PPS for the index given, it will return false.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS
|
||||
* @return bool true if it's a File PPS, false otherwise
|
||||
*/
|
||||
function isFile($index)
|
||||
{
|
||||
if (isset($this->_list[$index])) {
|
||||
return ($this->_list[$index]->Type == OLE_PPS_TYPE_FILE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a PPS is a Root PPS or not.
|
||||
* If there is no PPS for the index given, it will return false.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS.
|
||||
* @return bool true if it's a Root PPS, false otherwise
|
||||
*/
|
||||
function isRoot($index)
|
||||
{
|
||||
if (isset($this->_list[$index])) {
|
||||
return ($this->_list[$index]->Type == OLE_PPS_TYPE_ROOT);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the total number of PPS's found in the OLE container.
|
||||
*
|
||||
* @access public
|
||||
* @return integer The total number of PPS's found in the OLE container
|
||||
*/
|
||||
function ppsTotal()
|
||||
{
|
||||
return count($this->_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data from a PPS
|
||||
* If there is no PPS for the index given, it will return an empty string.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS
|
||||
* @param integer $position The position from which to start reading
|
||||
* (relative to the PPS)
|
||||
* @param integer $length The amount of bytes to read (at most)
|
||||
* @return string The binary string containing the data requested
|
||||
*/
|
||||
function getData($index, $position, $length)
|
||||
{
|
||||
// if position is not valid return empty string
|
||||
if (!isset($this->_list[$index]) or ($position >= $this->_list[$index]->Size) or ($position < 0)) {
|
||||
return '';
|
||||
}
|
||||
// Beware!!! _data member is actually a position
|
||||
fseek($this->_file_handle, $this->_list[$index]->_data + $position);
|
||||
return fread($this->_file_handle, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data length from a PPS
|
||||
* If there is no PPS for the index given, it will return 0.
|
||||
*
|
||||
* @access public
|
||||
* @param integer $index The index for the PPS
|
||||
* @return integer The amount of bytes in data the PPS has
|
||||
*/
|
||||
function getDataLength($index)
|
||||
{
|
||||
if (isset($this->_list[$index])) {
|
||||
return $this->_list[$index]->Size;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to transform ASCII text to Unicode
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param string $ascii The ASCII string to transform
|
||||
* @return string The string in Unicode
|
||||
*/
|
||||
function Asc2Ucs($ascii)
|
||||
{
|
||||
$rawname = '';
|
||||
for ($i = 0; $i < strlen($ascii); $i++) {
|
||||
$rawname .= $ascii{$i}."\x00";
|
||||
}
|
||||
return $rawname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function
|
||||
* Returns a string for the OLE container with the date given
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param integer $date A timestamp
|
||||
* @return string The string for the OLE container
|
||||
*/
|
||||
function LocalDate2OLE($date = null)
|
||||
{
|
||||
if (!isset($date)) {
|
||||
return "\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
}
|
||||
|
||||
// factor used for separating numbers into 4 bytes parts
|
||||
$factor = pow(2,32);
|
||||
|
||||
// days from 1-1-1601 until the beggining of UNIX era
|
||||
$days = 134774;
|
||||
// calculate seconds
|
||||
$big_date = $days*24*3600 + gmmktime(date("H",$date),date("i",$date),date("s",$date),
|
||||
date("m",$date),date("d",$date),date("Y",$date));
|
||||
// multiply just to make MS happy
|
||||
$big_date *= 10000000;
|
||||
|
||||
$high_part = floor($big_date/$factor);
|
||||
// lower 4 bytes
|
||||
$low_part = floor((($big_date/$factor) - $high_part)*$factor);
|
||||
|
||||
// Make HEX string
|
||||
$res = '';
|
||||
|
||||
for ($i=0; $i<4; $i++)
|
||||
{
|
||||
$hex = $low_part % 0x100;
|
||||
$res .= pack('c', $hex);
|
||||
$low_part /= 0x100;
|
||||
}
|
||||
for ($i=0; $i<4; $i++)
|
||||
{
|
||||
$hex = $high_part % 0x100;
|
||||
$res .= pack('c', $hex);
|
||||
$high_part /= 0x100;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a timestamp from an OLE container's date
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param integer $string A binary string with the encoded date
|
||||
* @return string The timestamp corresponding to the string
|
||||
*/
|
||||
function OLE2LocalDate($string)
|
||||
{
|
||||
if (strlen($string) != 8) {
|
||||
return new PEAR_Error("Expecting 8 byte string");
|
||||
}
|
||||
|
||||
// factor used for separating numbers into 4 bytes parts
|
||||
$factor = pow(2,32);
|
||||
$high_part = 0;
|
||||
for ($i=0; $i<4; $i++)
|
||||
{
|
||||
$al = unpack('C', $string{(7 - $i)});
|
||||
$high_part += $al[''];
|
||||
if ($i < 3) {
|
||||
$high_part *= 0x100;
|
||||
}
|
||||
}
|
||||
$low_part = 0;
|
||||
for ($i=4; $i<8; $i++)
|
||||
{
|
||||
$al = unpack('C', $string{(7 - $i)});
|
||||
$low_part += $al[''];
|
||||
if ($i < 7) {
|
||||
$low_part *= 0x100;
|
||||
}
|
||||
}
|
||||
$big_date = ($high_part*$factor) + $low_part;
|
||||
// translate to seconds
|
||||
$big_date /= 10000000;
|
||||
|
||||
// days from 1-1-1601 until the beggining of UNIX era
|
||||
$days = 134774;
|
||||
|
||||
// translate to seconds from beggining of UNIX era
|
||||
$big_date -= $days*24*3600;
|
||||
return floor($big_date);
|
||||
}
|
||||
}
|
||||
?>
|
219
lib/pear/OLE/PPS.php
Executable file
219
lib/pear/OLE/PPS.php
Executable file
@ -0,0 +1,219 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
require_once('PEAR.php');
|
||||
require_once('OLE.php');
|
||||
|
||||
/**
|
||||
* Class for creating PPS's for OLE containers
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE_PPS extends PEAR
|
||||
{
|
||||
/**
|
||||
* The PPS index
|
||||
* @var integer
|
||||
*/
|
||||
var $No;
|
||||
|
||||
/**
|
||||
* The PPS name (in Unicode)
|
||||
* @var string
|
||||
*/
|
||||
var $Name;
|
||||
|
||||
/**
|
||||
* The PPS type. Dir, Root or File
|
||||
* @var integer
|
||||
*/
|
||||
var $Type;
|
||||
|
||||
/**
|
||||
* The index of the previous PPS
|
||||
* @var integer
|
||||
*/
|
||||
var $PrevPps;
|
||||
|
||||
/**
|
||||
* The index of the next PPS
|
||||
* @var integer
|
||||
*/
|
||||
var $NextPps;
|
||||
|
||||
/**
|
||||
* The index of it's first child if this is a Dir or Root PPS
|
||||
* @var integer
|
||||
*/
|
||||
var $DirPps;
|
||||
|
||||
/**
|
||||
* A timestamp
|
||||
* @var integer
|
||||
*/
|
||||
var $Time1st;
|
||||
|
||||
/**
|
||||
* A timestamp
|
||||
* @var integer
|
||||
*/
|
||||
var $Time2nd;
|
||||
|
||||
/**
|
||||
* Starting block (small or big) for this PPS's data inside the container
|
||||
* @var integer
|
||||
*/
|
||||
var $_StartBlock;
|
||||
|
||||
/**
|
||||
* The size of the PPS's data (in bytes)
|
||||
* @var integer
|
||||
*/
|
||||
var $Size;
|
||||
|
||||
/**
|
||||
* The PPS's data (only used if it's not using a temporary file)
|
||||
* @var string
|
||||
*/
|
||||
var $_data;
|
||||
|
||||
/**
|
||||
* Array of child PPS's (only used by Root and Dir PPS's)
|
||||
* @var array
|
||||
*/
|
||||
var $children = array();
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*
|
||||
* @access public
|
||||
* @param integer $No The PPS index
|
||||
* @param string $name The PPS name (in Unicode)
|
||||
* @param integer $type The PPS type. Dir, Root or File
|
||||
* @param integer $prev The index of the previous PPS
|
||||
* @param integer $next The index of the next PPS
|
||||
* @param integer $dir The index of it's first child if this is a Dir or Root PPS
|
||||
* @param integer $time_1st A timestamp
|
||||
* @param integer $time_2nd A timestamp
|
||||
* @param array $children Array containing children PPS for this PPS
|
||||
*/
|
||||
function OLE_PPS($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children)
|
||||
{
|
||||
$this->No = $No;
|
||||
$this->Name = $name;
|
||||
$this->Type = $type;
|
||||
$this->PrevPps = $prev;
|
||||
$this->NextPps = $next;
|
||||
$this->DirPps = $dir;
|
||||
$this->Time1st = $time_1st;
|
||||
$this->Time2nd = $time_2nd;
|
||||
$this->_data = $data;
|
||||
$this->children = $children;
|
||||
if ($data != '') {
|
||||
$this->Size = strlen($data);
|
||||
}
|
||||
else {
|
||||
$this->Size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of data saved for this PPS
|
||||
*
|
||||
* @access private
|
||||
* @return integer The amount of data (in bytes)
|
||||
*/
|
||||
function _DataLen()
|
||||
{
|
||||
if (!isset($this->_data)) {
|
||||
return 0;
|
||||
}
|
||||
if (isset($this->_PPS_FILE))
|
||||
{
|
||||
fseek($this->_PPS_FILE, 0);
|
||||
$stats = fstat($this->_PPS_FILE);
|
||||
return $stats[7];
|
||||
}
|
||||
else {
|
||||
return strlen($this->_data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string with the PPS's WK (What is a WK?)
|
||||
*
|
||||
* @access private
|
||||
* @return string The binary string
|
||||
*/
|
||||
function _getPpsWk()
|
||||
{
|
||||
$ret = $this->Name;
|
||||
for ($i = 0; $i < (64 - strlen($this->Name)); $i++) {
|
||||
$ret .= "\x00";
|
||||
}
|
||||
$ret .= pack("v", strlen($this->Name) + 2) // 66
|
||||
. pack("c", $this->Type) // 67
|
||||
. pack("c", 0x00) //UK // 68
|
||||
. pack("V", $this->PrevPps) //Prev // 72
|
||||
. pack("V", $this->NextPps) //Next // 76
|
||||
. pack("V", $this->DirPps) //Dir // 80
|
||||
. "\x00\x09\x02\x00" // 84
|
||||
. "\x00\x00\x00\x00" // 88
|
||||
. "\xc0\x00\x00\x00" // 92
|
||||
. "\x00\x00\x00\x46" // 96 // Seems to be ok only for Root
|
||||
. "\x00\x00\x00\x00" // 100
|
||||
. OLE::LocalDate2OLE($this->Time1st) // 108
|
||||
. OLE::LocalDate2OLE($this->Time2nd) // 116
|
||||
. pack("V", isset($this->_StartBlock)?
|
||||
$this->_StartBlock:0) // 120
|
||||
. pack("V", $this->Size) // 124
|
||||
. pack("V", 0); // 128
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates index and pointers to previous, next and children PPS's for this
|
||||
* PPS. I don't think it'll work with Dir PPS's.
|
||||
*
|
||||
* @access private
|
||||
* @param array &$pps_array Reference to the array of PPS's for the whole OLE
|
||||
* container
|
||||
* @return integer The index for this PPS
|
||||
*/
|
||||
function _savePpsSetPnt(&$pps_array)
|
||||
{
|
||||
$pps_array[count($pps_array)] = &$this;
|
||||
$this->No = count($pps_array) - 1;
|
||||
$this->PrevPps = 0xFFFFFFFF;
|
||||
$this->NextPps = 0xFFFFFFFF;
|
||||
if (count($this->children) > 0) {
|
||||
$this->DirPps = $this->children[0]->_savePpsSetPnt($pps_array);
|
||||
}
|
||||
else {
|
||||
$this->DirPps = 0xFFFFFFFF;
|
||||
}
|
||||
return $this->No;
|
||||
}
|
||||
}
|
||||
?>
|
114
lib/pear/OLE/PPS/File.php
Executable file
114
lib/pear/OLE/PPS/File.php
Executable file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
require_once ('OLE/PPS.php');
|
||||
|
||||
/**
|
||||
* Class for creating File PPS's for OLE containers
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE_PPS_File extends OLE_PPS
|
||||
{
|
||||
/**
|
||||
* The temporary dir for storing the OLE file
|
||||
* @var string
|
||||
*/
|
||||
var $_tmp_dir;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*
|
||||
* @access public
|
||||
* @param string $name The name of the file (in Unicode)
|
||||
* @see OLE::Asc2Ucs()
|
||||
*/
|
||||
function OLE_PPS_File($name)
|
||||
{
|
||||
$this->_tmp_dir = '';
|
||||
$this->OLE_PPS(
|
||||
null,
|
||||
$name,
|
||||
OLE_PPS_TYPE_FILE,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'',
|
||||
array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temp dir used for storing the OLE file
|
||||
*
|
||||
* @access public
|
||||
* @param string $dir The dir to be used as temp dir
|
||||
* @return true if given dir is valid, false otherwise
|
||||
*/
|
||||
function setTempDir($dir)
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
$this->_tmp_dir = $dir;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization method. Has to be called right after OLE_PPS_File().
|
||||
*
|
||||
* @access public
|
||||
* @return mixed true on success. PEAR_Error on failure
|
||||
*/
|
||||
function init()
|
||||
{
|
||||
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_File");
|
||||
$fh = @fopen($this->_tmp_filename, "w+b");
|
||||
if ($fh == false) {
|
||||
return $this->raiseError("Can't create temporary file");
|
||||
}
|
||||
$this->_PPS_FILE = $fh;
|
||||
if ($this->_PPS_FILE) {
|
||||
fseek($this->_PPS_FILE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append data to PPS
|
||||
*
|
||||
* @access public
|
||||
* @param string $data The data to append
|
||||
*/
|
||||
function append($data)
|
||||
{
|
||||
if ($this->_PPS_FILE) {
|
||||
fwrite($this->_PPS_FILE, $data);
|
||||
}
|
||||
else {
|
||||
$this->_data .= $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
519
lib/pear/OLE/PPS/Root.php
Executable file
519
lib/pear/OLE/PPS/Root.php
Executable file
@ -0,0 +1,519 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Xavier Noguer <xnoguer@php.net> |
|
||||
// | Based on OLE::Storage_Lite by Kawai, Takanori |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
require_once ('OLE/PPS.php');
|
||||
|
||||
/**
|
||||
* Class for creating Root PPS's for OLE containers
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category Structures
|
||||
* @package OLE
|
||||
*/
|
||||
class OLE_PPS_Root extends OLE_PPS
|
||||
{
|
||||
/**
|
||||
* The temporary dir for storing the OLE file
|
||||
* @var string
|
||||
*/
|
||||
var $_tmp_dir;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param integer $time_1st A timestamp
|
||||
* @param integer $time_2nd A timestamp
|
||||
*/
|
||||
function OLE_PPS_Root($time_1st, $time_2nd, $raChild)
|
||||
{
|
||||
$this->_tmp_dir = '';
|
||||
$this->OLE_PPS(
|
||||
null,
|
||||
OLE::Asc2Ucs('Root Entry'),
|
||||
OLE_PPS_TYPE_ROOT,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$time_1st,
|
||||
$time_2nd,
|
||||
null,
|
||||
$raChild);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temp dir used for storing the OLE file
|
||||
*
|
||||
* @access public
|
||||
* @param string $dir The dir to be used as temp dir
|
||||
* @return true if given dir is valid, false otherwise
|
||||
*/
|
||||
function setTempDir($dir)
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
$this->_tmp_dir = $dir;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for saving the whole OLE container (including files).
|
||||
* In fact, if called with an empty argument (or '-'), it saves to a
|
||||
* temporary file and then outputs it's contents to stdout.
|
||||
*
|
||||
* @param string $filename The name of the file where to save the OLE container
|
||||
* @access public
|
||||
* @return mixed true on success, PEAR_Error on failure
|
||||
*/
|
||||
function save($filename)
|
||||
{
|
||||
// Initial Setting for saving
|
||||
$this->_BIG_BLOCK_SIZE = pow(2,
|
||||
((isset($this->_BIG_BLOCK_SIZE))? $this->_adjust2($this->_BIG_BLOCK_SIZE) : 9));
|
||||
$this->_SMALL_BLOCK_SIZE= pow(2,
|
||||
((isset($this->_SMALL_BLOCK_SIZE))? $this->_adjust2($this->_SMALL_BLOCK_SIZE): 6));
|
||||
|
||||
// Open temp file if we are sending output to stdout
|
||||
if (($filename == '-') or ($filename == ''))
|
||||
{
|
||||
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
|
||||
$this->_FILEH_ = @fopen($this->_tmp_filename,"w+b");
|
||||
if ($this->_FILEH_ == false) {
|
||||
return $this->raiseError("Can't create temporary file.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_FILEH_ = @fopen($filename, "wb");
|
||||
if ($this->_FILEH_ == false) {
|
||||
return $this->raiseError("Can't open $filename. It may be in use or protected.");
|
||||
}
|
||||
}
|
||||
// Make an array of PPS's (for Save)
|
||||
$aList = array();
|
||||
$this->_savePpsSetPnt($aList);
|
||||
// calculate values for header
|
||||
list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList); //, $rhInfo);
|
||||
// Save Header
|
||||
$this->_saveHeader($iSBDcnt, $iBBcnt, $iPPScnt);
|
||||
|
||||
// Make Small Data string (write SBD)
|
||||
$this->_data = $this->_makeSmallData($aList);
|
||||
|
||||
// Write BB
|
||||
$this->_saveBigData($iSBDcnt, $aList);
|
||||
// Write PPS
|
||||
$this->_savePps($aList);
|
||||
// Write Big Block Depot and BDList and Adding Header informations
|
||||
$this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
|
||||
// Close File, send it to stdout if necessary
|
||||
if(($filename == '-') or ($filename == ''))
|
||||
{
|
||||
fseek($this->_FILEH_, 0);
|
||||
fpassthru($this->_FILEH_);
|
||||
@fclose($this->_FILEH_);
|
||||
// Delete the temporary file.
|
||||
@unlink($this->_tmp_filename);
|
||||
}
|
||||
else {
|
||||
@fclose($this->_FILEH_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate some numbers
|
||||
*
|
||||
* @access private
|
||||
* @param array $raList Reference to an array of PPS's
|
||||
* @return array The array of numbers
|
||||
*/
|
||||
function _calcSize(&$raList)
|
||||
{
|
||||
// Calculate Basic Setting
|
||||
list($iSBDcnt, $iBBcnt, $iPPScnt) = array(0,0,0);
|
||||
$iSmallLen = 0;
|
||||
$iSBcnt = 0;
|
||||
for ($i = 0; $i < count($raList); $i++) {
|
||||
if($raList[$i]->Type == OLE_PPS_TYPE_FILE) {
|
||||
$raList[$i]->Size = $raList[$i]->_DataLen();
|
||||
if($raList[$i]->Size < OLE_DATA_SIZE_SMALL) {
|
||||
$iSBcnt += floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
|
||||
+ (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
|
||||
}
|
||||
else {
|
||||
$iBBcnt += (floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
|
||||
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
$iSmallLen = $iSBcnt * $this->_SMALL_BLOCK_SIZE;
|
||||
$iSlCnt = floor($this->_BIG_BLOCK_SIZE / OLE_LONG_INT_SIZE);
|
||||
$iSBDcnt = floor($iSBcnt / $iSlCnt) + (($iSBcnt % $iSlCnt)? 1:0);
|
||||
$iBBcnt += (floor($iSmallLen / $this->_BIG_BLOCK_SIZE) +
|
||||
(( $iSmallLen % $this->_BIG_BLOCK_SIZE)? 1: 0));
|
||||
$iCnt = count($raList);
|
||||
$iBdCnt = $this->_BIG_BLOCK_SIZE / OLE_PPS_SIZE;
|
||||
$iPPScnt = (floor($iCnt/$iBdCnt) + (($iCnt % $iBdCnt)? 1: 0));
|
||||
|
||||
return array($iSBDcnt, $iBBcnt, $iPPScnt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for caculating a magic value for block sizes
|
||||
*
|
||||
* @access private
|
||||
* @param integer $i2 The argument
|
||||
* @see save()
|
||||
* @return integer
|
||||
*/
|
||||
function _adjust2($i2)
|
||||
{
|
||||
$iWk = log($i2)/log(2);
|
||||
return ($iWk > floor($iWk))? floor($iWk)+1:$iWk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save OLE header
|
||||
*
|
||||
* @access private
|
||||
* @param integer $iSBDcnt
|
||||
* @param integer $iBBcnt
|
||||
* @param integer $iPPScnt
|
||||
*/
|
||||
function _saveHeader($iSBDcnt, $iBBcnt, $iPPScnt)
|
||||
{
|
||||
$FILE = $this->_FILEH_;
|
||||
|
||||
// Calculate Basic Setting
|
||||
$iBlCnt = $this->_BIG_BLOCK_SIZE / OLE_LONG_INT_SIZE;
|
||||
$i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / OLE_LONG_INT_SIZE;
|
||||
|
||||
$iBdExL = 0;
|
||||
$iAll = $iBBcnt + $iPPScnt + $iSBDcnt;
|
||||
$iAllW = $iAll;
|
||||
$iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
|
||||
$iBdCnt = floor(($iAll + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
|
||||
|
||||
// Calculate BD count
|
||||
if ($iBdCnt >$i1stBdL)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
$iBdExL++;
|
||||
$iAllW++;
|
||||
$iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt)? 1: 0);
|
||||
$iBdCnt = floor(($iAllW + $iBdCntW) / $iBlCnt) + ((($iAllW+$iBdCntW) % $iBlCnt)? 1: 0);
|
||||
if ($iBdCnt <= ($iBdExL*$iBlCnt+ $i1stBdL)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save Header
|
||||
fwrite($FILE,
|
||||
"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
|
||||
. "\x00\x00\x00\x00"
|
||||
. "\x00\x00\x00\x00"
|
||||
. "\x00\x00\x00\x00"
|
||||
. "\x00\x00\x00\x00"
|
||||
. pack("v", 0x3b)
|
||||
. pack("v", 0x03)
|
||||
. pack("v", -2)
|
||||
. pack("v", 9)
|
||||
. pack("v", 6)
|
||||
. pack("v", 0)
|
||||
. "\x00\x00\x00\x00"
|
||||
. "\x00\x00\x00\x00"
|
||||
. pack("V", $iBdCnt)
|
||||
. pack("V", $iBBcnt+$iSBDcnt) //ROOT START
|
||||
. pack("V", 0)
|
||||
. pack("V", 0x1000)
|
||||
. pack("V", 0) //Small Block Depot
|
||||
. pack("V", 1)
|
||||
);
|
||||
// Extra BDList Start, Count
|
||||
if ($iBdCnt < $i1stBdL)
|
||||
{
|
||||
fwrite($FILE,
|
||||
pack("V", -2). // Extra BDList Start
|
||||
pack("V", 0) // Extra BDList Count
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($FILE, pack("V", $iAll+$iBdCnt) . pack("V", $iBdExL));
|
||||
}
|
||||
|
||||
// BDList
|
||||
for ($i=0; $i<$i1stBdL and $i < $iBdCnt; $i++) {
|
||||
fwrite($FILE, pack("V", $iAll+$i));
|
||||
}
|
||||
if ($i < $i1stBdL)
|
||||
{
|
||||
for ($j = 0; $j < ($i1stBdL-$i); $j++) {
|
||||
fwrite($FILE, (pack("V", -1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saving big data (PPS's with data bigger than OLE_DATA_SIZE_SMALL)
|
||||
*
|
||||
* @access private
|
||||
* @param integer $iStBlk
|
||||
* @param array &$raList Reference to array of PPS's
|
||||
*/
|
||||
function _saveBigData($iStBlk, &$raList)
|
||||
{
|
||||
$FILE = $this->_FILEH_;
|
||||
|
||||
// cycle through PPS's
|
||||
for ($i = 0; $i < count($raList); $i++)
|
||||
{
|
||||
if($raList[$i]->Type != OLE_PPS_TYPE_DIR)
|
||||
{
|
||||
$raList[$i]->Size = $raList[$i]->_DataLen();
|
||||
if(($raList[$i]->Size >= OLE_DATA_SIZE_SMALL) or
|
||||
(($raList[$i]->Type == OLE_PPS_TYPE_ROOT) and isset($raList[$i]->_data)))
|
||||
{
|
||||
// Write Data
|
||||
if(isset($raList[$i]->_PPS_FILE))
|
||||
{
|
||||
$iLen = 0;
|
||||
fseek($raList[$i]->_PPS_FILE, 0); // To The Top
|
||||
while($sBuff = fread($raList[$i]->_PPS_FILE, 4096))
|
||||
{
|
||||
$iLen += strlen($sBuff);
|
||||
fwrite($FILE, $sBuff);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fwrite($FILE, $raList[$i]->_data);
|
||||
}
|
||||
|
||||
if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)
|
||||
{
|
||||
for ($j = 0; $j < ($this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)); $j++) {
|
||||
fwrite($FILE, "\x00");
|
||||
}
|
||||
}
|
||||
// Set For PPS
|
||||
$raList[$i]->_StartBlock = $iStBlk;
|
||||
$iStBlk +=
|
||||
(floor($raList[$i]->Size / $this->_BIG_BLOCK_SIZE) +
|
||||
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
|
||||
}
|
||||
// Close file for each PPS, and unlink it
|
||||
if (isset($raList[$i]->_PPS_FILE))
|
||||
{
|
||||
@fclose($raList[$i]->_PPS_FILE);
|
||||
$raList[$i]->_PPS_FILE = null;
|
||||
@unlink($raList[$i]->_tmp_filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get small data (PPS's with data smaller than OLE_DATA_SIZE_SMALL)
|
||||
*
|
||||
* @access private
|
||||
* @param array &$raList Reference to array of PPS's
|
||||
*/
|
||||
function _makeSmallData(&$raList)
|
||||
{
|
||||
$sRes = '';
|
||||
$FILE = $this->_FILEH_;
|
||||
$iSmBlk = 0;
|
||||
|
||||
for ($i = 0; $i < count($raList); $i++)
|
||||
{
|
||||
// Make SBD, small data string
|
||||
if ($raList[$i]->Type == OLE_PPS_TYPE_FILE)
|
||||
{
|
||||
if ($raList[$i]->Size <= 0) {
|
||||
continue;
|
||||
}
|
||||
if ($raList[$i]->Size < OLE_DATA_SIZE_SMALL)
|
||||
{
|
||||
$iSmbCnt = floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
|
||||
+ (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
|
||||
// Add to SBD
|
||||
for ($j = 0; $j < ($iSmbCnt-1); $j++) {
|
||||
fwrite($FILE, pack("V", $j+$iSmBlk+1));
|
||||
}
|
||||
fwrite($FILE, pack("V", -2));
|
||||
|
||||
// Add to Data String(this will be written for RootEntry)
|
||||
if ($raList[$i]->_PPS_FILE)
|
||||
{
|
||||
fseek($raList[$i]->_PPS_FILE, 0); // To The Top
|
||||
while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
|
||||
$sRes .= $sBuff;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$sRes .= $raList[$i]->_data;
|
||||
}
|
||||
if($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)
|
||||
{
|
||||
for ($j = 0; $j < ($this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); $j++) {
|
||||
$sRes .= "\x00";
|
||||
}
|
||||
}
|
||||
// Set for PPS
|
||||
$raList[$i]->_StartBlock = $iSmBlk;
|
||||
$iSmBlk += $iSmbCnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
$iSbCnt = floor($this->_BIG_BLOCK_SIZE / OLE_LONG_INT_SIZE);
|
||||
if($iSmBlk % $iSbCnt)
|
||||
{
|
||||
for ($i = 0; $i < ($iSbCnt - ($iSmBlk % $iSbCnt)); $i++) {
|
||||
fwrite($FILE, pack("V", -1));
|
||||
}
|
||||
}
|
||||
return $sRes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all the PPS's WKs
|
||||
*
|
||||
* @access private
|
||||
* @param array $raList Reference to an array with all PPS's
|
||||
*/
|
||||
function _savePps(&$raList)
|
||||
{
|
||||
// Save each PPS WK
|
||||
for ($i = 0; $i < count($raList); $i++) {
|
||||
fwrite($this->_FILEH_, $raList[$i]->_getPpsWk());
|
||||
}
|
||||
// Adjust for Block
|
||||
$iCnt = count($raList);
|
||||
$iBCnt = $this->_BIG_BLOCK_SIZE / OLE_PPS_SIZE;
|
||||
if ($iCnt % $iBCnt)
|
||||
{
|
||||
for ($i = 0; $i < (($iBCnt - ($iCnt % $iBCnt)) * OLE_PPS_SIZE); $i++) {
|
||||
fwrite($this->_FILEH_, "\x00");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saving Big Block Depot
|
||||
*
|
||||
* @access private
|
||||
* @param integer $iSbdSize
|
||||
* @param integer $iBsize
|
||||
* @param integer $iPpsCnt
|
||||
*/
|
||||
function _saveBbd($iSbdSize, $iBsize, $iPpsCnt)
|
||||
{
|
||||
$FILE = $this->_FILEH_;
|
||||
// Calculate Basic Setting
|
||||
$iBbCnt = $this->_BIG_BLOCK_SIZE / OLE_LONG_INT_SIZE;
|
||||
$i1stBdL = ($this->_BIG_BLOCK_SIZE - 0x4C) / OLE_LONG_INT_SIZE;
|
||||
|
||||
$iBdExL = 0;
|
||||
$iAll = $iBsize + $iPpsCnt + $iSbdSize;
|
||||
$iAllW = $iAll;
|
||||
$iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
|
||||
$iBdCnt = floor(($iAll + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
|
||||
// Calculate BD count
|
||||
if ($iBdCnt >$i1stBdL)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
$iBdExL++;
|
||||
$iAllW++;
|
||||
$iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt)? 1: 0);
|
||||
$iBdCnt = floor(($iAllW + $iBdCntW) / $iBbCnt) + ((($iAllW+$iBdCntW) % $iBbCnt)? 1: 0);
|
||||
if ($iBdCnt <= ($iBdExL*$iBbCnt+ $i1stBdL)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Making BD
|
||||
// Set for SBD
|
||||
if ($iSbdSize > 0)
|
||||
{
|
||||
for ($i = 0; $i<($iSbdSize-1); $i++) {
|
||||
fwrite($FILE, pack("V", $i+1));
|
||||
}
|
||||
fwrite($FILE, pack("V", -2));
|
||||
}
|
||||
// Set for B
|
||||
for ($i = 0; $i<($iBsize-1); $i++) {
|
||||
fwrite($FILE, pack("V", $i+$iSbdSize+1));
|
||||
}
|
||||
fwrite($FILE, pack("V", -2));
|
||||
|
||||
// Set for PPS
|
||||
for ($i = 0; $i<($iPpsCnt-1); $i++) {
|
||||
fwrite($FILE, pack("V", $i+$iSbdSize+$iBsize+1));
|
||||
}
|
||||
fwrite($FILE, pack("V", -2));
|
||||
// Set for BBD itself ( 0xFFFFFFFD : BBD)
|
||||
for ($i=0; $i<$iBdCnt;$i++) {
|
||||
fwrite($FILE, pack("V", 0xFFFFFFFD));
|
||||
}
|
||||
// Set for ExtraBDList
|
||||
for ($i=0; $i<$iBdExL;$i++) {
|
||||
fwrite($FILE, pack("V", 0xFFFFFFFC));
|
||||
}
|
||||
// Adjust for Block
|
||||
if (($iAllW + $iBdCnt) % $iBbCnt)
|
||||
{
|
||||
for ($i = 0; $i < ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt)); $i++) {
|
||||
fwrite($FILE, pack("V", -1));
|
||||
}
|
||||
}
|
||||
// Extra BDList
|
||||
if ($iBdCnt > $i1stBdL)
|
||||
{
|
||||
$iN=0;
|
||||
$iNb=0;
|
||||
for ($i=$i1stBdL;$i<$iBdCnt; $i++, $iN++)
|
||||
{
|
||||
if ($iN>=($iBbCnt-1))
|
||||
{
|
||||
$iN = 0;
|
||||
$iNb++;
|
||||
fwrite($FILE, pack("V", $iAll+$iBdCnt+$iNb));
|
||||
}
|
||||
fwrite($FILE, pack("V", $iBsize+$iSbdSize+$iPpsCnt+$i));
|
||||
}
|
||||
if (($iBdCnt-$i1stBdL) % ($iBbCnt-1))
|
||||
{
|
||||
for ($i = 0; $i < (($iBbCnt-1) - (($iBdCnt-$i1stBdL) % ($iBbCnt-1))); $i++) {
|
||||
fwrite($FILE, pack("V", -1));
|
||||
}
|
||||
}
|
||||
fwrite($FILE, pack("V", -2));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
1095
lib/pear/PEAR.php
Normal file
1095
lib/pear/PEAR.php
Normal file
File diff suppressed because it is too large
Load Diff
32
lib/pear/README.txt
Normal file
32
lib/pear/README.txt
Normal file
@ -0,0 +1,32 @@
|
||||
This files are part of the PEAR package (http://pear.php.net).
|
||||
|
||||
In detail, the libraries added here are:
|
||||
|
||||
- PEAR Spreadsheet_Excel_Writer classes:
|
||||
- Current version: 0.9.0
|
||||
- by Xavier Noguer and Mika Tuupola
|
||||
- License: LGPL
|
||||
- http://pear.php.net/package/Spreadsheet_Excel_Writer
|
||||
- PEAR OLE classes:
|
||||
- Current version: 0.5
|
||||
- by Xavier Noguer
|
||||
- License: PHP
|
||||
- http://pear.php.net/package/OLE
|
||||
- PEAR main class:
|
||||
- Current version: 1.4.5
|
||||
- by Stig Bakken, Thomas V.V.Cox, Pierre-Alain Joye,
|
||||
Greg Beaver and Martin Jansen
|
||||
- License: PHP
|
||||
- http://pear.php.net/package/PEAR
|
||||
|
||||
We must not use these classes directly ever. Instead we must build
|
||||
some wrapper classes to isolate Moodle code from internal PEAR
|
||||
implementations, allowing us to migrate if needed to other
|
||||
libraries in the future. For an example of wrapped classes,
|
||||
see the excel.class.lib file, that includes code to build
|
||||
Excel files using the cool library inside PEAR, but using
|
||||
the old calls used before Moodle 1.6 to maintain compatibility.
|
||||
|
||||
Please, don't forget it! Always use wrapper classes/functions!
|
||||
|
||||
Ciao, Eloy Lafuente, 2005-12-17 :-)
|
104
lib/pear/Spreadsheet/Excel/Writer.php
Normal file
104
lib/pear/Spreadsheet/Excel/Writer.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/*
|
||||
* Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
|
||||
*
|
||||
* PERL Spreadsheet::WriteExcel module.
|
||||
*
|
||||
* The author of the Spreadsheet::WriteExcel module is John McNamara
|
||||
* <jmcnamara@cpan.org>
|
||||
*
|
||||
* I _DO_ maintain this code, and John McNamara has nothing to do with the
|
||||
* porting of this code to PHP. Any questions directly related to this
|
||||
* class library should be directed to me.
|
||||
*
|
||||
* License Information:
|
||||
*
|
||||
* Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
|
||||
* Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
require_once 'PEAR.php';
|
||||
require_once 'Spreadsheet/Excel/Writer/Workbook.php';
|
||||
|
||||
/**
|
||||
* Class for writing Excel Spreadsheets. This class should change COMPLETELY.
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@rezebra.com>
|
||||
* @category FileFormats
|
||||
* @package Spreadsheet_Excel_Writer
|
||||
*/
|
||||
|
||||
class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook
|
||||
{
|
||||
/**
|
||||
* The constructor. It just creates a Workbook
|
||||
*
|
||||
* @param string $filename The optional filename for the Workbook.
|
||||
* @return Spreadsheet_Excel_Writer_Workbook The Workbook created
|
||||
*/
|
||||
function Spreadsheet_Excel_Writer($filename = '')
|
||||
{
|
||||
$this->_filename = $filename;
|
||||
$this->Spreadsheet_Excel_Writer_Workbook($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send HTTP headers for the Excel file.
|
||||
*
|
||||
* @param string $filename The filename to use for HTTP headers
|
||||
* @access public
|
||||
*/
|
||||
function send($filename)
|
||||
{
|
||||
header("Content-type: application/vnd.ms-excel");
|
||||
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||
header("Expires: 0");
|
||||
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
|
||||
header("Pragma: public");
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function for writing formulas
|
||||
* Converts a cell's coordinates to the A1 format.
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param integer $row Row for the cell to convert (0-indexed).
|
||||
* @param integer $col Column for the cell to convert (0-indexed).
|
||||
* @return string The cell identifier in A1 format
|
||||
*/
|
||||
function rowcolToCell($row, $col)
|
||||
{
|
||||
if ($col > 255) { //maximum column value exceeded
|
||||
return new PEAR_Error("Maximum column value exceeded: $col");
|
||||
}
|
||||
|
||||
$int = (int)($col / 26);
|
||||
$frac = $col % 26;
|
||||
$chr1 = '';
|
||||
|
||||
if ($int > 0) {
|
||||
$chr1 = chr(ord('A') + $int - 1);
|
||||
}
|
||||
|
||||
$chr2 = chr(ord('A') + $frac);
|
||||
$row++;
|
||||
|
||||
return $chr1 . $chr2 . $row;
|
||||
}
|
||||
}
|
||||
?>
|
238
lib/pear/Spreadsheet/Excel/Writer/BIFFwriter.php
Normal file
238
lib/pear/Spreadsheet/Excel/Writer/BIFFwriter.php
Normal file
@ -0,0 +1,238 @@
|
||||
<?php
|
||||
/*
|
||||
* Module written/ported by Xavier Noguer <xnoguer@php.net>
|
||||
*
|
||||
* The majority of this is _NOT_ my code. I simply ported it from the
|
||||
* PERL Spreadsheet::WriteExcel module.
|
||||
*
|
||||
* The author of the Spreadsheet::WriteExcel module is John McNamara
|
||||
* <jmcnamara@cpan.org>
|
||||
*
|
||||
* I _DO_ maintain this code, and John McNamara has nothing to do with the
|
||||
* porting of this code to PHP. Any questions directly related to this
|
||||
* class library should be directed to me.
|
||||
*
|
||||
* License Information:
|
||||
*
|
||||
* Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
|
||||
* Copyright (c) 2002-2003 Xavier Noguer xnoguer@php.net
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
/**
|
||||
* Class for writing Excel BIFF records.
|
||||
*
|
||||
* From "MICROSOFT EXCEL BINARY FILE FORMAT" by Mark O'Brien (Microsoft Corporation):
|
||||
*
|
||||
* BIFF (BInary File Format) is the file format in which Excel documents are
|
||||
* saved on disk. A BIFF file is a complete description of an Excel document.
|
||||
* BIFF files consist of sequences of variable-length records. There are many
|
||||
* different types of BIFF records. For example, one record type describes a
|
||||
* formula entered into a cell; one describes the size and location of a
|
||||
* window into a document; another describes a picture format.
|
||||
*
|
||||
* @author Xavier Noguer <xnoguer@php.net>
|
||||
* @category FileFormats
|
||||
* @package Spreadsheet_Excel_Writer
|
||||
*/
|
||||
|
||||
class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
|
||||
{
|
||||
/**
|
||||
* The BIFF/Excel version (5).
|
||||
* @var integer
|
||||
*/
|
||||
var $_BIFF_version = 0x0500;
|
||||
|
||||
/**
|
||||
* The byte order of this architecture. 0 => little endian, 1 => big endian
|
||||
* @var integer
|
||||
*/
|
||||
var $_byte_order;
|
||||
|
||||
/**
|
||||
* The string containing the data of the BIFF stream
|
||||
* @var string
|
||||
*/
|
||||
var $_data;
|
||||
|
||||
/**
|
||||
* The size of the data in bytes. Should be the same as strlen($this->_data)
|
||||
* @var integer
|
||||
*/
|
||||
var $_datasize;
|
||||
|
||||
/**
|
||||
* The maximun length for a BIFF record. See _addContinue()
|
||||
* @var integer
|
||||
* @see _addContinue()
|
||||
*/
|
||||
var $_limit;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function Spreadsheet_Excel_Writer_BIFFwriter()
|
||||
{
|
||||
$this->_byte_order = '';
|
||||
$this->_data = '';
|
||||
$this->_datasize = 0;
|
||||
$this->_limit = 2080;
|
||||
// Set the byte order
|
||||
$this->_setByteOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the byte order and store it as class data to avoid
|
||||
* recalculating it for each call to new().
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _setByteOrder()
|
||||
{
|
||||
// Check if "pack" gives the required IEEE 64bit float
|
||||
$teststr = pack("d", 1.2345);
|
||||
$number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F);
|
||||
if ($number == $teststr) {
|
||||
$byte_order = 0; // Little Endian
|
||||
} elseif ($number == strrev($teststr)){
|
||||
$byte_order = 1; // Big Endian
|
||||
} else {
|
||||
// Give up. I'll fix this in a later version.
|
||||
return $this->raiseError("Required floating point format ".
|
||||
"not supported on this platform.");
|
||||
}
|
||||
$this->_byte_order = $byte_order;
|
||||
}
|
||||
|
||||
/**
|
||||
* General storage function
|
||||
*
|
||||
* @param string $data binary data to prepend
|
||||
* @access private
|
||||
*/
|
||||
function _prepend($data)
|
||||
{
|
||||
if (strlen($data) > $this->_limit) {
|
||||
$data = $this->_addContinue($data);
|
||||
}
|
||||
$this->_data = $data.$this->_data;
|
||||
$this->_datasize += strlen($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* General storage function
|
||||
*
|
||||
* @param string $data binary data to append
|
||||
* @access private
|
||||
*/
|
||||
function _append($data)
|
||||
{
|
||||
if (strlen($data) > $this->_limit) {
|
||||
$data = $this->_addContinue($data);
|
||||
}
|
||||
$this->_data = $this->_data.$data;
|
||||
$this->_datasize += strlen($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes Excel BOF record to indicate the beginning of a stream or
|
||||
* sub-stream in the BIFF file.
|
||||
*
|
||||
* @param integer $type Type of BIFF file to write: 0x0005 Workbook,
|
||||
* 0x0010 Worksheet.
|
||||
* @access private
|
||||
*/
|
||||
function _storeBof($type)
|
||||
{
|
||||
$record = 0x0809; // Record identifier
|
||||
|
||||
// According to the SDK $build and $year should be set to zero.
|
||||
// However, this throws a warning in Excel 5. So, use magic numbers.
|
||||
if ($this->_BIFF_version == 0x0500) {
|
||||
$length = 0x0008;
|
||||
$unknown = '';
|
||||
$build = 0x096C;
|
||||
$year = 0x07C9;
|
||||
} elseif ($this->_BIFF_version == 0x0600) {
|
||||
$length = 0x0010;
|
||||
$unknown = pack("VV", 0x00000041, 0x00000006); //unknown last 8 bytes for BIFF8
|
||||
$build = 0x0DBB;
|
||||
$year = 0x07CC;
|
||||
}
|
||||
$version = $this->_BIFF_version;
|
||||
|
||||
$header = pack("vv", $record, $length);
|
||||
$data = pack("vvvv", $version, $type, $build, $year);
|
||||
$this->_prepend($header . $data . $unknown);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes Excel EOF record to indicate the end of a BIFF stream.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _storeEof()
|
||||
{
|
||||
$record = 0x000A; // Record identifier
|
||||
$length = 0x0000; // Number of bytes to follow
|
||||
$header = pack("vv", $record, $length);
|
||||
$this->_append($header);
|
||||
}
|
||||
|
||||
/**
|
||||
* Excel limits the size of BIFF records. In Excel 5 the limit is 2084 bytes. In
|
||||
* Excel 97 the limit is 8228 bytes. Records that are longer than these limits
|
||||
* must be split up into CONTINUE blocks.
|
||||
*
|
||||
* This function takes a long BIFF record and inserts CONTINUE records as
|
||||
* necessary.
|
||||
*
|
||||
* @param string $data The original binary data to be written
|
||||
* @return string A very convenient string of continue blocks
|
||||
* @access private
|
||||
*/
|
||||
function _addContinue($data)
|
||||
{
|
||||
$limit = $this->_limit;
|
||||
$record = 0x003C; // Record identifier
|
||||
|
||||
// The first 2080/8224 bytes remain intact. However, we have to change
|
||||
// the length field of the record.
|
||||
$tmp = substr($data, 0, 2).pack("v", $limit-4).substr($data, 4, $limit - 4);
|
||||
|
||||
$header = pack("vv", $record, $limit); // Headers for continue records
|
||||
|
||||
// Retrieve chunks of 2080/8224 bytes +4 for the header.
|
||||
$data_length = strlen($data);
|
||||
for ($i = $limit; $i < ($data_length - $limit); $i += $limit) {
|
||||
$tmp .= $header;
|
||||
$tmp .= substr($data, $i, $limit);
|
||||
}
|
||||
|
||||
// Retrieve the last chunk of data
|
||||
$header = pack("vv", $record, strlen($data) - $i);
|
||||
$tmp .= $header;
|
||||
$tmp .= substr($data, $i, strlen($data) - $i);
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
?>
|
1102
lib/pear/Spreadsheet/Excel/Writer/Format.php
Normal file
1102
lib/pear/Spreadsheet/Excel/Writer/Format.php
Normal file
File diff suppressed because it is too large
Load Diff
1689
lib/pear/Spreadsheet/Excel/Writer/Parser.php
Normal file
1689
lib/pear/Spreadsheet/Excel/Writer/Parser.php
Normal file
File diff suppressed because it is too large
Load Diff
230
lib/pear/Spreadsheet/Excel/Writer/Validator.php
Normal file
230
lib/pear/Spreadsheet/Excel/Writer/Validator.php
Normal file
@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/*
|
||||
* Module written by Herman Kuiper <herman@ozuzo.net>
|
||||
*
|
||||
* License Information:
|
||||
*
|
||||
* Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
|
||||
* Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
//require_once('PEAR.php');
|
||||
|
||||
// Possible operator types
|
||||
|
||||
/*
|
||||
FIXME: change prefixes
|
||||
*/
|
||||
define("OP_BETWEEN", 0x00);
|
||||
define("OP_NOTBETWEEN", 0x01);
|
||||
define("OP_EQUAL", 0x02);
|
||||
define("OP_NOTEQUAL", 0x03);
|
||||
define("OP_GT", 0x04);
|
||||
define("OP_LT", 0x05);
|
||||
define("OP_GTE", 0x06);
|
||||
define("OP_LTE", 0x07);
|
||||
|
||||
/**
|
||||
* Baseclass for generating Excel DV records (validations)
|
||||
*
|
||||
* @author Herman Kuiper
|
||||
* @category FileFormats
|
||||
* @package Spreadsheet_Excel_Writer
|
||||
*/
|
||||
class Spreadsheet_Excel_Writer_Validator
|
||||
{
|
||||
var $_type;
|
||||
var $_style;
|
||||
var $_fixedList;
|
||||
var $_blank;
|
||||
var $_incell;
|
||||
var $_showprompt;
|
||||
var $_showerror;
|
||||
var $_title_prompt;
|
||||
var $_descr_prompt;
|
||||
var $_title_error;
|
||||
var $_descr_error;
|
||||
var $_operator;
|
||||
var $_formula1;
|
||||
var $_formula2;
|
||||
/**
|
||||
* The parser from the workbook. Used to parse validation formulas also
|
||||
* @var Spreadsheet_Excel_Writer_Parser
|
||||
*/
|
||||
var $_parser;
|
||||
|
||||
function Spreadsheet_Excel_Writer_Validator(&$parser)
|
||||
{
|
||||
$this->_parser = $parser;
|
||||
$this->_type = 0x01; // FIXME: add method for setting datatype
|
||||
$this->_style = 0x00;
|
||||
$this->_fixedList = false;
|
||||
$this->_blank = false;
|
||||
$this->_incell = false;
|
||||
$this->_showprompt = false;
|
||||
$this->_showerror = true;
|
||||
$this->_title_prompt = "\x00";
|
||||
$this->_descr_prompt = "\x00";
|
||||
$this->_title_error = "\x00";
|
||||
$this->_descr_error = "\x00";
|
||||
$this->_operator = 0x00; // default is equal
|
||||
$this->_formula1 = '';
|
||||
$this->_formula2 = '';
|
||||
}
|
||||
|
||||
function setPrompt($promptTitle = "\x00", $promptDescription = "\x00", $showPrompt = true)
|
||||
{
|
||||
$this->_showprompt = $showPrompt;
|
||||
$this->_title_prompt = $promptTitle;
|
||||
$this->_descr_prompt = $promptDescription;
|
||||
}
|
||||
|
||||
function setError($errorTitle = "\x00", $errorDescription = "\x00", $showError = true)
|
||||
{
|
||||
$this->_showerror = $showError;
|
||||
$this->_title_error = $errorTitle;
|
||||
$this->_descr_error = $errorDescription;
|
||||
}
|
||||
|
||||
function allowBlank()
|
||||
{
|
||||
$this->_blank = true;
|
||||
}
|
||||
|
||||
function onInvalidStop()
|
||||
{
|
||||
$this->_style = 0x00;
|
||||
}
|
||||
|
||||
function onInvalidWarn()
|
||||
{
|
||||
$this->_style = 0x01;
|
||||
}
|
||||
|
||||
function onInvalidInfo()
|
||||
{
|
||||
$this->_style = 0x02;
|
||||
}
|
||||
|
||||
function setFormula1($formula)
|
||||
{
|
||||
// Parse the formula using the parser in Parser.php
|
||||
$error = $this->_parser->parse($formula);
|
||||
if (PEAR::isError($error)) {
|
||||
return $this->_formula1;
|
||||
}
|
||||
|
||||
$this->_formula1 = $this->_parser->toReversePolish();
|
||||
if (PEAR::isError($this->_formula1)) {
|
||||
return $this->_formula1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function setFormula2($formula)
|
||||
{
|
||||
// Parse the formula using the parser in Parser.php
|
||||
$error = $this->_parser->parse($formula);
|
||||
if (PEAR::isError($error)) {
|
||||
return $this->_formula2;
|
||||
}
|
||||
|
||||
$this->_formula2 = $this->_parser->toReversePolish();
|
||||
if (PEAR::isError($this->_formula2)) {
|
||||
return $this->_formula2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function _getOptions()
|
||||
{
|
||||
$options = $this->_type;
|
||||
$options |= $this->_style << 3;
|
||||
if ($this->_fixedList) {
|
||||
$options |= 0x80;
|
||||
}
|
||||
if ($this->_blank) {
|
||||
$options |= 0x100;
|
||||
}
|
||||
if (!$this->_incell) {
|
||||
$options |= 0x200;
|
||||
}
|
||||
if ($this->_showprompt) {
|
||||
$options |= 0x40000;
|
||||
}
|
||||
if ($this->_showerror) {
|
||||
$options |= 0x80000;
|
||||
}
|
||||
$options |= $this->_operator << 20;
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function _getData()
|
||||
{
|
||||
$title_prompt_len = strlen($this->_title_prompt);
|
||||
$descr_prompt_len = strlen($this->_descr_prompt);
|
||||
$title_error_len = strlen($this->_title_error);
|
||||
$descr_error_len = strlen($this->_descr_error);
|
||||
|
||||
$formula1_size = strlen($this->_formula1);
|
||||
$formula2_size = strlen($this->_formula2);
|
||||
|
||||
$data = pack("V", $this->_getOptions());
|
||||
$data .= pack("vC", $title_prompt_len, 0x00) . $this->_title_prompt;
|
||||
$data .= pack("vC", $title_error_len, 0x00) . $this->_title_error;
|
||||
$data .= pack("vC", $descr_prompt_len, 0x00) . $this->_descr_prompt;
|
||||
$data .= pack("vC", $descr_error_len, 0x00) . $this->_descr_error;
|
||||
|
||||
$data .= pack("vv", $formula1_size, 0x0000) . $this->_formula1;
|
||||
$data .= pack("vv", $formula2_size, 0x0000) . $this->_formula2;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/*class Spreadsheet_Excel_Writer_Validation_List extends Spreadsheet_Excel_Writer_Validation
|
||||
{
|
||||
function Spreadsheet_Excel_Writer_Validation_list()
|
||||
{
|
||||
parent::Spreadsheet_Excel_Writer_Validation();
|
||||
$this->_type = 0x03;
|
||||
}
|
||||
|
||||
function setList($source, $incell = true)
|
||||
{
|
||||
$this->_incell = $incell;
|
||||
$this->_fixedList = true;
|
||||
|
||||
$source = implode("\x00", $source);
|
||||
$this->_formula1 = pack("CCC", 0x17, strlen($source), 0x0c) . $source;
|
||||
}
|
||||
|
||||
function setRow($row, $col1, $col2, $incell = true)
|
||||
{
|
||||
$this->_incell = $incell;
|
||||
//$this->_formula1 = ...;
|
||||
}
|
||||
|
||||
function setCol($col, $row1, $row2, $incell = true)
|
||||
{
|
||||
$this->_incell = $incell;
|
||||
//$this->_formula1 = ...;
|
||||
}
|
||||
}*/
|
||||
|
||||
?>
|
1528
lib/pear/Spreadsheet/Excel/Writer/Workbook.php
Normal file
1528
lib/pear/Spreadsheet/Excel/Writer/Workbook.php
Normal file
File diff suppressed because it is too large
Load Diff
3502
lib/pear/Spreadsheet/Excel/Writer/Worksheet.php
Normal file
3502
lib/pear/Spreadsheet/Excel/Writer/Worksheet.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -417,19 +417,6 @@ function rss_display_feeds($courseid='', $userid='', $rssid='') {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* translates HTML special characters back to ASCII
|
||||
* RSS feeds may have encoded html commands which we want to translate properly
|
||||
* to display as intended rather than as source (html script visible in feed)
|
||||
* This function taken from Simplog - www.simplog.net
|
||||
*/
|
||||
function rss_unhtmlentities($string) {
|
||||
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
|
||||
$trans_tbl = array_flip ($trans_tbl);
|
||||
return strtr ($string, $trans_tbl);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper function for rss_get_form
|
||||
*/
|
||||
@ -562,3 +549,4 @@ function rss_add_enclosures($item){
|
||||
|
||||
return $returnstring;
|
||||
}
|
||||
?>
|
||||
|
@ -140,6 +140,16 @@ $CFG->httpswwwroot = $CFG->wwwroot;
|
||||
die;
|
||||
}
|
||||
|
||||
/// Set the client/server and connection to utf8 if necessary
|
||||
if ($dbconnected && $CFG->unicodedb) {
|
||||
if ($db->databaseType == 'mysql') {
|
||||
$db->Execute("SET NAMES 'utf8'");
|
||||
$db->Execute("SET CHARSET 'utf8'"); /// This could be not necessary if DB is set to Unicode, but...
|
||||
} else if ($db->databaseType == 'postgres7') {
|
||||
$db->Execute("SET NAMES 'utf8'");
|
||||
}
|
||||
}
|
||||
|
||||
error_reporting(E_ALL); // Show errors from now on.
|
||||
|
||||
if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
|
||||
@ -155,7 +165,8 @@ $CFG->httpswwwroot = $CFG->wwwroot;
|
||||
|
||||
|
||||
/// Load up standard libraries
|
||||
|
||||
|
||||
require_once($CFG->libdir .'/textlib.class.php'); // Functions to handle multibyte strings
|
||||
require_once($CFG->libdir .'/weblib.php'); // Functions for producing HTML
|
||||
require_once($CFG->libdir .'/datalib.php'); // Functions for accessing databases
|
||||
require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions
|
||||
@ -430,13 +441,14 @@ $CFG->httpswwwroot = $CFG->wwwroot;
|
||||
/// majority of cases), use the stored locale specified by admin.
|
||||
|
||||
if (isset($_GET['lang'])) {
|
||||
if (!detect_munged_arguments($lang, 0) and file_exists($CFG->dirroot .'/lang/'. $lang)) {
|
||||
if (!detect_munged_arguments($lang, 0) and (file_exists($CFG->dataroot .'/lang/'. $lang) or
|
||||
file_exists($CFG->dirroot .'/lang/'. $lang))) {
|
||||
$SESSION->lang = $lang;
|
||||
$SESSION->encoding = get_string('thischarset');
|
||||
}
|
||||
}
|
||||
if (empty($CFG->lang)) {
|
||||
$CFG->lang = "en";
|
||||
$CFG->lang = !empty($CFG->unicodedb) ? 'en_utf8' : 'en';
|
||||
}
|
||||
|
||||
moodle_setlocale();
|
||||
|
@ -62,6 +62,10 @@
|
||||
/// As we implement the singleton pattern to use this class (only one instance
|
||||
/// is shared globally), we need this helper function
|
||||
|
||||
/// IMPORTANT Note: Typo3 libraries always expect lowercase charsets to use 100%
|
||||
/// its capabilities so, don't forget to make the conversion
|
||||
/// from every wrapper function!
|
||||
|
||||
function textlib_get_instance () {
|
||||
static $instance;
|
||||
if (!is_object($instance)) {
|
||||
@ -106,7 +110,7 @@ class textlib {
|
||||
/// Avoid some notices from Typo3 code
|
||||
$oldlevel = error_reporting(E_PARSE);
|
||||
/// Call Typo3 conv() function. It will do all the work
|
||||
$result = $this->typo3cs->conv($text, $fromCS, $toCS);
|
||||
$result = $this->typo3cs->conv($text, strtolower($fromCS), strtolower($toCS));
|
||||
/// Restore original debug level
|
||||
error_reporting($oldlevel);
|
||||
return $result;
|
||||
@ -115,7 +119,7 @@ class textlib {
|
||||
/* Multibyte safe substr() function, uses mbstring if available. */
|
||||
function substr($text, $start, $len=null, $charset='utf-8') {
|
||||
/// Call Typo3 substr() function. It will do all the work
|
||||
return $this->typo3cs->substr($charset,$text,$start,$len);
|
||||
return $this->typo3cs->substr(strtolower($charset),$text,$start,$len);
|
||||
}
|
||||
|
||||
/* Multibyte safe strlen() function, uses mbstring if available. */
|
||||
@ -123,7 +127,7 @@ class textlib {
|
||||
/// Avoid some notices from Typo3 code
|
||||
$oldlevel = error_reporting(E_PARSE);
|
||||
/// Call Typo3 strlen() function. It will do all the work
|
||||
$result = $this->typo3cs->strlen($charset,$text);
|
||||
$result = $this->typo3cs->strlen(strtolower($charset),$text);
|
||||
/// Restore original debug level
|
||||
error_reporting($oldlevel);
|
||||
return $result;
|
||||
@ -134,7 +138,7 @@ class textlib {
|
||||
/// Avoid some notices from Typo3 code
|
||||
$oldlevel = error_reporting(E_PARSE);
|
||||
/// Call Typo3 conv_case() function. It will do all the work
|
||||
$result = $this->typo3cs->conv_case($charset,$text,'toLower');
|
||||
$result = $this->typo3cs->conv_case(strtolower($charset),$text,'toLower');
|
||||
/// Restore original debug level
|
||||
error_reporting($oldlevel);
|
||||
return $result;
|
||||
@ -145,7 +149,7 @@ class textlib {
|
||||
/// Avoid some notices from Typo3 code
|
||||
$oldlevel = error_reporting(E_PARSE);
|
||||
/// Call Typo3 conv_case() function. It will do all the work
|
||||
$result = $this->typo3cs->conv_case($charset,$text,'toUpper');
|
||||
$result = $this->typo3cs->conv_case(strtolower($charset),$text,'toUpper');
|
||||
/// Restore original debug level
|
||||
error_reporting($oldlevel);
|
||||
return $result;
|
||||
|
@ -38,6 +38,9 @@
|
||||
* @package moodlecore
|
||||
*/
|
||||
|
||||
/// We are going to uses filterlib functions here
|
||||
require_once("$CFG->libdir/filterlib.php");
|
||||
|
||||
/// Constants
|
||||
|
||||
/// Define text formatting types ... eventually we can add Wiki, BBcode etc
|
||||
@ -366,6 +369,8 @@ function stripslashes_recursive($var) {
|
||||
* Given some normal text this function will break up any
|
||||
* long words to a given size by inserting the given character
|
||||
*
|
||||
* It's multibyte savvy and doesn't change anything inside html tags.
|
||||
*
|
||||
* @param string $string the string to be modified
|
||||
* @param int $maxsize maximum length of the string to be returned
|
||||
* @param string $cutchar the string used to represent word breaks
|
||||
@ -373,23 +378,21 @@ function stripslashes_recursive($var) {
|
||||
*/
|
||||
function break_up_long_words($string, $maxsize=20, $cutchar=' ') {
|
||||
|
||||
static $currentlang;
|
||||
/// Loading the textlib singleton instance. We are going to need it.
|
||||
$textlib = textlib_get_instance();
|
||||
|
||||
if (empty($currentlang)) {
|
||||
$currentlang = current_language();
|
||||
}
|
||||
|
||||
if (in_array(substr($currentlang,0,2), array('ja', 'kn', 'sr', 'vi', 'zh'))) { // Multibyte languages
|
||||
return $string;
|
||||
}
|
||||
/// First of all, save all the tags inside the text to skip them
|
||||
$tags = array();
|
||||
filter_save_tags($string,$tags);
|
||||
|
||||
/// Process the string adding the cut when necessary
|
||||
$output = '';
|
||||
$length = strlen($string);
|
||||
$length = $textlib->strlen($string, current_charset());
|
||||
$wordlength = 0;
|
||||
|
||||
for ($i=0; $i<$length; $i++) {
|
||||
$char = $string[$i];
|
||||
if ($char == ' ' or $char == "\t" or $char == "\n" or $char == "\r") {
|
||||
$char = $textlib->substr($string, $i, 1, current_charset());
|
||||
if ($char == ' ' or $char == "\t" or $char == "\n" or $char == "\r" or $char == "<" or $char == ">") {
|
||||
$wordlength = 0;
|
||||
} else {
|
||||
$wordlength++;
|
||||
@ -400,6 +403,12 @@ function break_up_long_words($string, $maxsize=20, $cutchar=' ') {
|
||||
}
|
||||
$output .= $char;
|
||||
}
|
||||
|
||||
/// Finally load the tags back again
|
||||
if (!empty($tags)) {
|
||||
$output = str_replace(array_keys($tags), $tags, $output);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
@ -1787,18 +1796,12 @@ function print_header ($title='', $heading='', $navigation='', $focus='', $meta=
|
||||
}
|
||||
|
||||
|
||||
if (!empty($CFG->unicode)) {
|
||||
$encoding = 'utf-8';
|
||||
} else if (!empty($CFG->courselang)) {
|
||||
$encoding = get_string('thischarset');
|
||||
$encoding = current_charset();
|
||||
if (!empty($CFG->courselang)) {
|
||||
moodle_setlocale();
|
||||
} else {
|
||||
if (!empty($SESSION->encoding)) {
|
||||
$encoding = $SESSION->encoding;
|
||||
} else {
|
||||
$SESSION->encoding = $encoding = get_string('thischarset');
|
||||
}
|
||||
}
|
||||
$SESSION->encoding = $encoding;
|
||||
|
||||
$meta = '<meta http-equiv="content-type" content="text/html; charset='. $encoding .'" />'. "\n". $meta ."\n";
|
||||
if (!$usexml) {
|
||||
@header('Content-type: text/html; charset='.$encoding);
|
||||
|
Loading…
x
Reference in New Issue
Block a user