add contents
This commit is contained in:
708
lib/plugins/odt/helper/config.php
Normal file
708
lib/plugins/odt/helper/config.php
Normal file
@@ -0,0 +1,708 @@
|
||||
<?php
|
||||
/**
|
||||
* Helper class handling ODT plugin configuration stuff.
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author LarsDW223
|
||||
*/
|
||||
|
||||
// must be run within Dokuwiki
|
||||
if (!defined('DOKU_INC')) die();
|
||||
|
||||
/**
|
||||
* Class helper_plugin_odt_config
|
||||
*
|
||||
* @package helper\config
|
||||
*/
|
||||
class helper_plugin_odt_config extends DokuWiki_Plugin {
|
||||
/** @var array Central storage for config parameters. */
|
||||
protected $config = array();
|
||||
protected $mode = null;
|
||||
protected $messages = null;
|
||||
protected $convert_to = null;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function getMethods() {
|
||||
$result = array();
|
||||
$result[] = array(
|
||||
'name' => 'setParam',
|
||||
'desc' => 'set config param $name to $value.',
|
||||
'params' => array('name' => 'string', 'value' => 'mixed'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'getParam',
|
||||
'desc' => 'returns the current value for config param $value',
|
||||
'params' => array('name' => 'string'),
|
||||
'return' => array('value' => 'mixed'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'isParam',
|
||||
'desc' => 'Is $name a known config param?',
|
||||
'params' => array('name' => 'string'),
|
||||
'return' => array('isParam' => 'bool'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'isRefreshable',
|
||||
'desc' => 'Is $name a refreshable config param?',
|
||||
'params' => array('name' => 'string'),
|
||||
'return' => array('isRefreshable' => 'bool'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'hasDWGlobalSetting',
|
||||
'desc' => 'Does param $name have a corresponding global DW param to inherit from?',
|
||||
'params' => array('name' => 'string'),
|
||||
'return' => array('hasDWGlobalSetting' => 'bool'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'isGlobalSetting',
|
||||
'desc' => 'Does param $name have a global config setting?',
|
||||
'params' => array('name' => 'string'),
|
||||
'return' => array('isGlobalSetting' => 'bool'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'isURLSetting',
|
||||
'desc' => 'Does param $name have a URL setting?',
|
||||
'params' => array('name' => 'string'),
|
||||
'return' => array('isURLSetting' => 'bool'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'isMetaSetting',
|
||||
'desc' => 'Does param $name have a Metadata setting?',
|
||||
'params' => array('name' => 'string'),
|
||||
'return' => array('isMetaSetting' => 'bool'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'addingToMetaIsAllowed',
|
||||
'desc' => 'Is it allowed to add $name (at position $pos) to the meta data?',
|
||||
'params' => array('name' => 'string', 'pos' => 'integer'),
|
||||
'return' => array('addingAllowed' => 'bool'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'load',
|
||||
'desc' => 'Load the corrent settings from the global config, URL params or syntax tags/meta data',
|
||||
'params' => array('warnings' => 'string'),
|
||||
'return' => array('mode' => 'string'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'refresh',
|
||||
'desc' => 'Refresh the corrent settings from the global config, URL params or syntax tags/meta data',
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'hash',
|
||||
'desc' => 'Get MD5 hash of currently stored settings.',
|
||||
'return' => array('hash' => 'string'),
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor. Loads helper plugins.
|
||||
*/
|
||||
public function __construct() {
|
||||
// Set up empty array with known config parameters
|
||||
|
||||
// Option 'dformat', taken from global value.
|
||||
$this->config ['dformat'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => 'dformat',
|
||||
'hasGlobal' => false,
|
||||
'hasURL' => false,
|
||||
'hasMeta' => false,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Option 'useheading', taken from global value.
|
||||
$this->config ['useheading'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => 'useheading',
|
||||
'hasGlobal' => false,
|
||||
'hasURL' => false,
|
||||
'hasMeta' => false,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Temp directory, taken from global value.
|
||||
$this->config ['tmpdir'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => 'tmpdir',
|
||||
'hasGlobal' => false,
|
||||
'hasURL' => false,
|
||||
'hasMeta' => false,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Media directory, taken from global value.
|
||||
$this->config ['mediadir'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => 'mediadir',
|
||||
'hasGlobal' => false,
|
||||
'hasURL' => false,
|
||||
'hasMeta' => false,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Data directory, taken from global value.
|
||||
$this->config ['datadir'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => 'datadir',
|
||||
'hasGlobal' => false,
|
||||
'hasURL' => false,
|
||||
'hasMeta' => false,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Save directory, taken from global value.
|
||||
$this->config ['savedir'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => 'savedir',
|
||||
'hasGlobal' => false,
|
||||
'hasURL' => false,
|
||||
'hasMeta' => false,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Option 'showexportbutton'
|
||||
$this->config ['showexportbutton'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => false,
|
||||
'hasMeta' => false,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Option 'showpdfexportbutton'
|
||||
$this->config ['showpdfexportbutton'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => false,
|
||||
'hasMeta' => false,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Template directory.
|
||||
$this->config ['tpl_dir'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => false,
|
||||
'hasMeta' => false,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// ODT template.
|
||||
$this->config ['odt_template'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Template =ODT template, old parameter,
|
||||
// included for backwards compatibility.
|
||||
$this->config ['template'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// CSS usage.
|
||||
$this->config ['css_usage'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// CSS template.
|
||||
$this->config ['css_template'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// CSS media selector (screen or print)
|
||||
$this->config ['media_sel'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Standard font size for CSS import = value for 1em/100%
|
||||
$this->config ['css_font_size'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Apply CSS font size to ODT template styles/scratch styles
|
||||
$this->config ['apply_fs_to_non_css'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Twips per pixel x and y
|
||||
$this->config ['twips_per_pixel_x'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
$this->config ['twips_per_pixel_y'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Page format, orientation and margins
|
||||
//
|
||||
// This settings also have a syntax tag changing the page format
|
||||
// and introducing a pagebreak. The meta setting changes the start
|
||||
// page format and may only be set if at the start of the document.
|
||||
// Otherwise changing the page fomat in the document would also
|
||||
// change the format of the first page!
|
||||
$this->config ['format'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => true,
|
||||
'refresh' => false);
|
||||
$this->config ['orientation'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => true,
|
||||
'refresh' => false);
|
||||
$this->config ['margin_top'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => true,
|
||||
'refresh' => false);
|
||||
$this->config ['margin_right'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => true,
|
||||
'refresh' => false);
|
||||
$this->config ['margin_bottom'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => true,
|
||||
'refresh' => false);
|
||||
$this->config ['margin_left'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => true,
|
||||
'refresh' => false);
|
||||
$this->config ['page'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => false,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => true,
|
||||
'refresh' => false);
|
||||
// Disable links
|
||||
$this->config ['disable_links'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => true);
|
||||
// TOC: maxlevel
|
||||
$this->config ['toc_maxlevel'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => 'maxtoclevel',
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// TOC: toc_leader_sign
|
||||
$this->config ['toc_leader_sign'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// TOC: toc_indents
|
||||
$this->config ['toc_indents'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// TOC: toc_pagebreak
|
||||
$this->config ['toc_pagebreak'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// TOC-Style (default, assigned to each level)
|
||||
$this->config ['toc_style'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Index display in browser
|
||||
$this->config ['index_in_browser'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Index display in browser
|
||||
$this->config ['outline_list_style'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// Command line template for pdf conversion
|
||||
$this->config ['convert_to_pdf'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => false,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
// List-Label-Alignment (ordered lists)
|
||||
$this->config ['olist_label_align'] =
|
||||
array('value' => NULL,
|
||||
'DWGlobalName' => NULL,
|
||||
'hasGlobal' => true,
|
||||
'hasURL' => true,
|
||||
'hasMeta' => true,
|
||||
'addMetaAtStartOnly' => false,
|
||||
'refresh' => false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a config parameter.
|
||||
* @param string $name Name of the config param
|
||||
* @param string $value Value to be set
|
||||
*/
|
||||
public function setParam($name, $value) {
|
||||
if (!empty($name)) {
|
||||
$this->config [$name]['value'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a config parameter.
|
||||
*
|
||||
* @param string $name Name of the config param
|
||||
* @return mixed Current value of param $name
|
||||
*/
|
||||
public function getParam($name) {
|
||||
return $this->config [$name]['value'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the $name specified the name of a ODT plugin config parameter?
|
||||
*
|
||||
* @param string $name Name of the config param
|
||||
* @return bool Is it a config parameter?
|
||||
*/
|
||||
public function isParam($name) {
|
||||
if (!empty($name)) {
|
||||
return array_key_exists($name, $this->config);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the config parameter need a refresh?
|
||||
*
|
||||
* @param string $name Name of the config param
|
||||
* @return bool is refreshable
|
||||
*/
|
||||
public function isRefreshable($name) {
|
||||
if (!empty($name)) {
|
||||
return $this->config [$name]['refresh'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the config parameter have a DokuWiki global config setting?
|
||||
*
|
||||
* @param string $name Name of the config param
|
||||
* @return string Name of global DokuWiki option or NULL
|
||||
*/
|
||||
public function hasDWGlobalSetting($name) {
|
||||
if (!empty($name)) {
|
||||
return $this->config [$name]['DWGlobalName'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the config parameter have a global config setting?
|
||||
*
|
||||
* @param string $name Name of the config param
|
||||
* @return bool is global setting
|
||||
*/
|
||||
public function isGlobalSetting($name) {
|
||||
if (!empty($name)) {
|
||||
return $this->config [$name]['hasGlobal'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the config parameter have a URL config setting?
|
||||
*
|
||||
* @param string $name Name of the config param
|
||||
* @return bool is URL Setting
|
||||
*/
|
||||
public function isURLSetting($name) {
|
||||
if (!empty($name)) {
|
||||
return $this->config [$name]['hasURL'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the config parameter have a Meta-Data config setting?
|
||||
*
|
||||
* @param string $name Name of the config param
|
||||
* @return bool is Meta Setting
|
||||
*/
|
||||
public function isMetaSetting($name) {
|
||||
if (!empty($name)) {
|
||||
return $this->config [$name]['hasMeta'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* May the parameter be added to the Meta data?
|
||||
*
|
||||
* @param string $name Name of the config param
|
||||
* @param string $pos Poistion in wiki page
|
||||
* @return bool
|
||||
*/
|
||||
public function addingToMetaIsAllowed($name, $pos) {
|
||||
if (!empty($name) and $this->isMetaSetting($name)) {
|
||||
if ($pos != 0 and $this->config [$name]['addMetaAtStartOnly']) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all config parameters: global config options, URL and syntax tag.
|
||||
* Check export mode: scratch, ODT template or CSS template?
|
||||
*
|
||||
* @param string $warning (reference) warning message
|
||||
* @return string Export mode to be used
|
||||
*/
|
||||
protected function loadIntern(&$warning, $refresh) {
|
||||
global $conf, $ID, $INPUT;
|
||||
|
||||
if ( $this->mode == null ) {
|
||||
$this->mode = 'scratch';
|
||||
}
|
||||
|
||||
// Get all known config parameters, see __construct().
|
||||
$odt_meta = p_get_metadata($ID, 'relation odt');
|
||||
foreach ($this->config as $name => $value) {
|
||||
if ( !$refresh || $this->isRefreshable($name) ) {
|
||||
$value = $this->getParam ($name);
|
||||
|
||||
// Check DokuWiki global configuration.
|
||||
$dw_name = $this->hasDWGlobalSetting ($name);
|
||||
if (!$value && $conf[$dw_name]) {
|
||||
$this->setParam ($name, $conf[$dw_name]);
|
||||
}
|
||||
|
||||
// Check plugin configuration.
|
||||
if (!$value && $this->isGlobalSetting($name) && $this->getConf($name)) {
|
||||
$this->setParam ($name, $this->getConf($name));
|
||||
}
|
||||
|
||||
// Check if parameter is provided in the URL.
|
||||
$url_param = $INPUT->get->str($name, $value, true);
|
||||
if ($this->isURLSetting($name) && isset($url_param)) {
|
||||
$this->setParam ($name, $url_param);
|
||||
}
|
||||
|
||||
// Check meta data in case syntax tags have written
|
||||
// the config parameters to it.
|
||||
$value = $odt_meta[$name];
|
||||
if($this->isMetaSetting($name) && !empty($value)) {
|
||||
$this->setParam ($name, $value);
|
||||
}
|
||||
|
||||
// ODT-Template based export required?
|
||||
// (old parameter)
|
||||
$template = $this->getParam ('template');
|
||||
if ( $name == 'template' && !empty($template) ) {
|
||||
// ODT-Template chosen
|
||||
if (file_exists($this->getParam('mediadir').'/'.$this->getParam('tpl_dir')."/".$this->getParam ('template'))) {
|
||||
//template found
|
||||
$this->mode = 'ODT template';
|
||||
} else {
|
||||
// template chosen but not found : warn the user and use the default template
|
||||
$warning = sprintf($this->getLang('tpl_not_found'),$this->getParam ('template'),$this->getParam ('tpl_dir'));
|
||||
$this->messages .= $warning;
|
||||
}
|
||||
}
|
||||
|
||||
// ODT-Template based export required?
|
||||
$odt_template = $this->getParam ('odt_template');
|
||||
if ( $name == 'odt_template' && !empty($odt_template) ) {
|
||||
// ODT-Template chosen
|
||||
if (file_exists($this->getParam('mediadir').'/'.$this->getParam('tpl_dir')."/".$this->getParam ('odt_template'))) {
|
||||
// Template found: ODT or CSS?
|
||||
if ( strpos ($odt_template, '.css') === false ) {
|
||||
$this->mode = 'ODT template';
|
||||
} else {
|
||||
$this->mode = 'CSS template';
|
||||
}
|
||||
} else {
|
||||
// template chosen but not found : warn the user and use the default template
|
||||
$warning = sprintf($this->getLang('tpl_not_found'),$this->getParam ('odt_template'),$this->getParam ('tpl_dir'));
|
||||
}
|
||||
}
|
||||
|
||||
// Convert Yes/No-String in 'disable_links' to boolean.
|
||||
if ( $name == 'disable_links' ) {
|
||||
$temp = $this->getParam ('disable_links');
|
||||
if ( strcasecmp($temp, 'Yes') != 0 && $temp !== true ) {
|
||||
$this->setParam ('disable_links', false);
|
||||
} else {
|
||||
$this->setParam ('disable_links', true);
|
||||
}
|
||||
}
|
||||
|
||||
// Convert Yes/No-String in 'toc_pagebreak' to boolean.
|
||||
if ( $name == 'toc_pagebreak' ) {
|
||||
$temp = $this->getParam ('toc_pagebreak');
|
||||
if ( strcasecmp($temp, 'Yes') == 0 || $temp === true ) {
|
||||
$this->setParam ('toc_pagebreak', true);
|
||||
} else {
|
||||
$this->setParam ('toc_pagebreak', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$template = $this->getParam ('template');
|
||||
$odt_template = $this->getParam ('odt_template');
|
||||
if (!empty($template) && empty($odt_template)) {
|
||||
$this->setParam ('odt_template', $this->getParam ('template'));
|
||||
}
|
||||
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load config parameters. See loadIntern().
|
||||
*
|
||||
* @param string $warning (reference) warning message
|
||||
* @return string Export mode to be used
|
||||
*/
|
||||
public function load(&$warning) {
|
||||
return $this->loadIntern($warning, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh config parameters. See loadIntern().
|
||||
*/
|
||||
public function refresh() {
|
||||
$this->loadIntern($warning, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hash for current config content.
|
||||
*
|
||||
* @return string The calculated hash
|
||||
*/
|
||||
public function hash() {
|
||||
$content = '';
|
||||
|
||||
// Get all known config parameters in one string
|
||||
foreach ($this->config as $name => $value) {
|
||||
$content .= $name.'='.$this->getParam ($name).';';
|
||||
}
|
||||
|
||||
// Return the md5 hash for it.
|
||||
return hash('md5', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get warning messages from loading the config which
|
||||
* can be presented to the user.
|
||||
*
|
||||
* @return string Collected messages.
|
||||
*/
|
||||
public function getMessages() {
|
||||
return $this->messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set conversion option.
|
||||
*
|
||||
* @param string $format Conversion format (e.g. 'pdf')
|
||||
*/
|
||||
public function setConvertTo($format) {
|
||||
$this->convert_to = $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set conversion option.
|
||||
*
|
||||
* @return string Currently set conversion option
|
||||
* or NULL (output ODT format)
|
||||
*/
|
||||
public function getConvertTo() {
|
||||
return ($this->convert_to);
|
||||
}
|
||||
}
|
74
lib/plugins/odt/helper/csscolors.php
Normal file
74
lib/plugins/odt/helper/csscolors.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* Simple helper class to query CSS color values and names.
|
||||
*
|
||||
* This is only a wrapper for csscolor in ODT/css/csscolors.php
|
||||
* making the functions accessible as a helper plugin.
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author LarsDW223
|
||||
*/
|
||||
|
||||
// must be run within Dokuwiki
|
||||
if (!defined('DOKU_INC')) die();
|
||||
|
||||
require_once DOKU_PLUGIN . 'odt/ODT/css/csscolors.php';
|
||||
|
||||
/**
|
||||
* Class helper_plugin_odt_csscolors
|
||||
*
|
||||
* @package helper\csscolors
|
||||
*/
|
||||
class helper_plugin_odt_csscolors extends DokuWiki_Plugin {
|
||||
/**
|
||||
* Return list of implemented methods.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getMethods() {
|
||||
$result = array();
|
||||
$result[] = array(
|
||||
'name' => 'getColorValue',
|
||||
'desc' => 'returns the color value for a given CSS color name. Returns "#000000" if the name is unknown',
|
||||
'params' => array('name' => 'string'),
|
||||
'return' => array('color value' => 'string'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'getValueName',
|
||||
'desc' => 'returns the CSS color name for a given color value. Returns "Black" if the value is unknown',
|
||||
'params' => array('value' => 'string'),
|
||||
'return' => array('name' => 'string'),
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the color value for the color with $name.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @return string
|
||||
*/
|
||||
public static function getColorValue ($name=NULL) {
|
||||
return csscolors::getColorValue ($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the color name for the given color $value.
|
||||
*
|
||||
* @param null $value
|
||||
* @return string
|
||||
*/
|
||||
public static function getValueName ($value=NULL) {
|
||||
return csscolors::getValueName ($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given $name a known CSS color name?
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isKnownColorName ($name=NULL) {
|
||||
return csscolors::isKnownColorName ($name);
|
||||
}
|
||||
}
|
62
lib/plugins/odt/helper/cssdocument.php
Normal file
62
lib/plugins/odt/helper/cssdocument.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* Helper class to fake a document tree for CSS matching.
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author LarsDW223
|
||||
*/
|
||||
|
||||
require_once DOKU_INC.'lib/plugins/odt/helper/ecm_interface.php';
|
||||
require_once DOKU_INC.'lib/plugins/odt/ODT/css/cssdocument.php';
|
||||
|
||||
// must be run within Dokuwiki
|
||||
if (!defined('DOKU_INC')) die();
|
||||
|
||||
/**
|
||||
* Class css_document
|
||||
*
|
||||
* @package helper\cssdocument
|
||||
*/
|
||||
class helper_plugin_odt_cssdocument extends DokuWiki_Plugin {
|
||||
protected $internal = NULL;
|
||||
|
||||
public function __construct() {
|
||||
$this->internal = new cssdocument();
|
||||
}
|
||||
|
||||
public function open ($element, $attributes=NULL, $pseudo_classes=NULL, $pseudo_elements=NULL) {
|
||||
$this->internal->open ($element, $attributes, $pseudo_classes, $pseudo_elements);
|
||||
}
|
||||
|
||||
public function close ($element) {
|
||||
$this->internal->close ($element);
|
||||
}
|
||||
|
||||
public function getCurrentElement() {
|
||||
return $this->internal->getCurrentElement ();
|
||||
}
|
||||
|
||||
public function getEntry ($index) {
|
||||
return $this->internal->getEntry ($index);
|
||||
}
|
||||
|
||||
public function getCurrentEntry () {
|
||||
return $this->internal->getCurrentEntry ();
|
||||
}
|
||||
|
||||
public function getIndexLastOpened () {
|
||||
return $this->internal->getIndexLastOpened ();
|
||||
}
|
||||
|
||||
public function findParent ($start) {
|
||||
return $this->internal->findParent ($start);
|
||||
}
|
||||
|
||||
public function getPrecedingSibling ($current) {
|
||||
return $this->internal->getPrecedingSibling ($current);
|
||||
}
|
||||
|
||||
public function getDump () {
|
||||
return $this->internal->getDump ($current);
|
||||
}
|
||||
}
|
1498
lib/plugins/odt/helper/cssimport.php
Normal file
1498
lib/plugins/odt/helper/cssimport.php
Normal file
File diff suppressed because it is too large
Load Diff
112
lib/plugins/odt/helper/cssimportnew.php
Normal file
112
lib/plugins/odt/helper/cssimportnew.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Helper class to read in a CSS style.
|
||||
*
|
||||
* This is just a wrapper for the ODT CSS class to make it's
|
||||
* functionality available as a DokuWiki helper plugin.
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author LarsDW223
|
||||
*/
|
||||
|
||||
require_once DOKU_PLUGIN . 'odt/ODT/css/cssimportnew.php';
|
||||
|
||||
// must be run within Dokuwiki
|
||||
if (!defined('DOKU_INC')) die();
|
||||
|
||||
/**
|
||||
* Class helper_plugin_odt_cssimport
|
||||
*
|
||||
* @package helper\cssimportnew
|
||||
*/
|
||||
class helper_plugin_odt_cssimportnew extends DokuWiki_Plugin {
|
||||
protected $internal = NULL;
|
||||
|
||||
public function __construct() {
|
||||
$this->internal = new cssimportnew();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get reference to internal cssimportnew object.
|
||||
*
|
||||
* @return cssimportnew
|
||||
*/
|
||||
function getInternal($contents) {
|
||||
return $this->internal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $contents
|
||||
* @return bool
|
||||
*/
|
||||
function importFromString($contents) {
|
||||
return $this->internal->importFromString($contents);
|
||||
}
|
||||
|
||||
public function setMedia ($media) {
|
||||
$this->internal->setMedia($media);
|
||||
}
|
||||
|
||||
public function getMedia () {
|
||||
return $this->internal->getMedia();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filename
|
||||
* @return bool|void
|
||||
*/
|
||||
function importFromFile($filename) {
|
||||
return $this->internal->importFromFile($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRaw () {
|
||||
return $this->internal->getRaw();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $element
|
||||
* @param $classString
|
||||
* @param $name
|
||||
* @param null $media
|
||||
* @return null
|
||||
*/
|
||||
public function getPropertyForElement ($name, iElementCSSMatchable $element) {
|
||||
return $this->internal->getPropertyForElement ($name, $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dest
|
||||
* @param $element
|
||||
* @param $classString
|
||||
* @param null $media
|
||||
*/
|
||||
public function getPropertiesForElement (&$dest, iElementCSSMatchable $element, helper_plugin_odt_units $units) {
|
||||
$this->internal->getPropertiesForElement ($dest, $element, $units->getInternal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function rulesToString () {
|
||||
return $this->internal->rulesToString ();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $URL
|
||||
* @param $replacement
|
||||
* @return string
|
||||
*/
|
||||
public function replaceURLPrefix ($URL, $replacement) {
|
||||
return $this->internal->replaceURLPrefix ($URL, $replacement);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $callback
|
||||
*/
|
||||
public function adjustLengthValues ($callback) {
|
||||
$this->internal->adjustLengthValues ($callback);
|
||||
}
|
||||
}
|
237
lib/plugins/odt/helper/dwcssloader.php
Normal file
237
lib/plugins/odt/helper/dwcssloader.php
Normal file
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
/**
|
||||
* Helper class to load standrad DokuWiki CSS files.
|
||||
* Adopted code from dw2pdf plugin by Andreas Gohr <andi@splitbrain.org>.
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author LarsDW223
|
||||
*/
|
||||
|
||||
// must be run within Dokuwiki
|
||||
if (!defined('DOKU_INC')) die();
|
||||
|
||||
|
||||
/**
|
||||
* Class helper_plugin_odt_dwcssloader
|
||||
*
|
||||
* @package helper\dwcssloader
|
||||
*/
|
||||
class helper_plugin_odt_dwcssloader extends DokuWiki_Plugin {
|
||||
/** var string Usually empty, can be used for debugging */
|
||||
public $trace_dump = NULL;
|
||||
|
||||
/**
|
||||
* Return list of implemented methods.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getMethods() {
|
||||
$result = array();
|
||||
$result[] = array(
|
||||
'name' => 'load',
|
||||
'desc' => 'Loads standard DokuWiki, plugin specific and format specific CSS files and templates. Includes handling of replacements and less parsing.',
|
||||
'params' => array('$plugin_name' => 'string',
|
||||
'$format' => 'string',
|
||||
'$template' => 'string'),
|
||||
'return' => array('All CSS styles' => 'string'),
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all the style sheets and apply the needed replacements
|
||||
* @param $plugin_name
|
||||
* @param $format
|
||||
* @param $template
|
||||
* @return string
|
||||
*/
|
||||
public function load($plugin_name, $format, $template) {
|
||||
$mediatypes = array('screen', 'all', 'print');
|
||||
|
||||
//reusue the CSS dispatcher functions without triggering the main function
|
||||
define('SIMPLE_TEST', 1);
|
||||
require_once(DOKU_INC . 'lib/exe/css.php');
|
||||
|
||||
// Always only use small letters in format
|
||||
$format = strtolower ($format);
|
||||
|
||||
// load style.ini
|
||||
if (function_exists('css_styleini')) {
|
||||
// compatiblity layer for pre-Greebo releases of DokuWiki
|
||||
$styleini = css_styleini($template);
|
||||
} else {
|
||||
// Greebo functionality
|
||||
$styleUtils = new \dokuwiki\StyleUtils();
|
||||
$styleini = $styleUtils->cssStyleini($template);
|
||||
}
|
||||
|
||||
$template_files = array();
|
||||
foreach($mediatypes as $mediatype) {
|
||||
$template_files[$mediatype] = array();
|
||||
|
||||
// load template styles
|
||||
if (isset($styleini['stylesheets'][$mediatype])) {
|
||||
$template_files[$mediatype] = array_merge($template_files[$mediatype], $styleini['stylesheets'][$mediatype]);
|
||||
}
|
||||
}
|
||||
|
||||
// prepare CSS files
|
||||
$files = array_merge(
|
||||
array(
|
||||
DOKU_INC . 'lib/styles/screen.css'
|
||||
=> DOKU_BASE . 'lib/styles/',
|
||||
DOKU_INC . 'lib/styles/print.css'
|
||||
=> DOKU_BASE . 'lib/styles/',
|
||||
),
|
||||
css_pluginstyles('all'),
|
||||
$this->css_pluginFormatStyles($format),
|
||||
array(
|
||||
DOKU_PLUGIN . $plugin_name.'/conf/style.css'
|
||||
=> DOKU_BASE . 'lib/plugins/'.$plugin_name.'/conf/',
|
||||
DOKU_PLUGIN . $plugin_name.'/tpl/' . $template . '/style.css'
|
||||
=> DOKU_BASE . 'lib/plugins/'.$plugin_name.'/tpl/' . $template . '/',
|
||||
DOKU_PLUGIN . $plugin_name.'/conf/style.local.css'
|
||||
=> DOKU_BASE . 'lib/plugins/'.$plugin_name.'/conf/',
|
||||
)
|
||||
);
|
||||
$css = '';
|
||||
$css .= $this->get_css_for_filetypes();
|
||||
|
||||
// build the stylesheet
|
||||
foreach($files as $file => $location) {
|
||||
$display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
|
||||
$css_content = "\n/* XXXXXXXXX $display XXXXXXXXX */\n";
|
||||
$css_content = css_loadfile($file, $location);
|
||||
if (strpos ($file, 'screen.css') !== false ||
|
||||
strpos ($file, 'screen.less') !== false) {
|
||||
$css .= "\n@media screen {\n" . $css_content . "\n}\n";
|
||||
} else if (strpos ($file, 'style.css') !== false ||
|
||||
strpos ($file, 'style.less') !== false) {
|
||||
$css .= "\n@media screen {\n" . $css_content . "\n}\n";
|
||||
} else if (strpos ($file, $format.'.css') !== false ||
|
||||
strpos ($file, $format.'.less') !== false) {
|
||||
$css .= "\n@media print {\n" . $css_content . "\n}\n";
|
||||
} else if (strpos ($file, 'print.css') !== false ||
|
||||
strpos ($file, 'print.less') !== false) {
|
||||
$css .= "\n@media print {\n" . $css_content . "\n}\n";
|
||||
} else {
|
||||
$css .= $css_content;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($mediatypes as $mediatype) {
|
||||
// load files
|
||||
$css_content = '';
|
||||
foreach($template_files[$mediatype] as $file => $location){
|
||||
$display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
|
||||
$css_content .= "\n/* XXXXXXXXX $display XXXXXXXXX */\n";
|
||||
$css_content .= css_loadfile($file, $location);
|
||||
}
|
||||
switch ($mediatype) {
|
||||
case 'screen':
|
||||
$css .= NL.'@media screen { /* START screen styles */'.NL.$css_content.NL.'} /* /@media END screen styles */'.NL;
|
||||
break;
|
||||
case 'print':
|
||||
$css .= NL.'@media print { /* START print styles */'.NL.$css_content.NL.'} /* /@media END print styles */'.NL;
|
||||
break;
|
||||
case 'all':
|
||||
case 'feed':
|
||||
default:
|
||||
$css .= NL.'/* START rest styles */ '.NL.$css_content.NL.'/* END rest styles */'.NL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(function_exists('css_parseless')) {
|
||||
// apply pattern replacements
|
||||
$css = css_applystyle($css, $styleini['replacements']);
|
||||
|
||||
// parse less
|
||||
$css = css_parseless($css);
|
||||
} else {
|
||||
// @deprecated 2013-12-19: fix backward compatibility
|
||||
$css = css_applystyle($css, DOKU_INC . 'lib/tpl/' . $template . '/');
|
||||
}
|
||||
|
||||
return $css;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of possible Plugin Styles for format $format
|
||||
*
|
||||
* Checks for a $format.'.css', falls back to print.css
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
* @param string $format
|
||||
* @return array
|
||||
*/
|
||||
protected function css_pluginFormatStyles($format) {
|
||||
$list = array();
|
||||
$plugins = plugin_list();
|
||||
|
||||
foreach($plugins as $p) {
|
||||
// Always load normal/screen CSS code
|
||||
// That way plugins can choose with the media selector which CSS code they like to use
|
||||
$list[DOKU_PLUGIN . $p ."/screen.css"] = DOKU_INC . "lib/plugins/". $p ."/";
|
||||
$list[DOKU_PLUGIN . $p ."/screen.less"] = DOKU_INC . "lib/plugins/". $p ."/";
|
||||
$list[DOKU_PLUGIN . $p ."/style.css"] = DOKU_INC . "lib/plugins/". $p ."/";
|
||||
$list[DOKU_PLUGIN . $p ."/style.less"] = DOKU_INC . "lib/plugins/". $p ."/";
|
||||
|
||||
// Do $format.css (e.g. odt.css) or print.css exists?
|
||||
$format_css = file_exists(DOKU_PLUGIN . $p ."/". $format .".css");
|
||||
$format_less = file_exists(DOKU_PLUGIN . $p ."/". $format .".less");
|
||||
$print_css = file_exists(DOKU_PLUGIN . $p ."/print.css");
|
||||
$print_less = file_exists(DOKU_PLUGIN . $p ."/print.less");
|
||||
if($format_css || $format_less) {
|
||||
$list[DOKU_PLUGIN . $p ."/". $format .".css"] = DOKU_INC . "lib/plugins/". $p ."/";
|
||||
$list[DOKU_PLUGIN . $p ."/". $format .".less"] = DOKU_INC . "lib/plugins/". $p ."/";
|
||||
} else if ($print_css || $print_less) {
|
||||
$list[DOKU_PLUGIN . $p ."/print.css"] = DOKU_INC . "lib/plugins/". $p ."/";
|
||||
$list[DOKU_PLUGIN . $p ."/print.less"] = DOKU_INC . "lib/plugins/". $p ."/";
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns classes for file download links
|
||||
* (Adjusted from lib/exe/css.php: function css_filetypes())
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
protected function get_css_for_filetypes() {
|
||||
$css = '';
|
||||
|
||||
// default style
|
||||
$css .= '.mediafile {';
|
||||
$css .= ' background: transparent url('.DOKU_BASE.'lib/images/fileicons/file.png) 0px 1px no-repeat;';
|
||||
$css .= ' padding-left: 18px;';
|
||||
$css .= ' padding-bottom: 1px;';
|
||||
$css .= '}';
|
||||
|
||||
// additional styles when icon available
|
||||
// scan directory for all icons
|
||||
$exts = array();
|
||||
if($dh = opendir(DOKU_INC.'lib/images/fileicons')){
|
||||
while(false !== ($file = readdir($dh))){
|
||||
if(preg_match('/([_\-a-z0-9]+(?:\.[_\-a-z0-9]+)*?)\.(png|gif)/i',$file,$match)){
|
||||
$ext = strtolower($match[1]);
|
||||
$type = '.'.strtolower($match[2]);
|
||||
if($ext!='file' && (!isset($exts[$ext]) || $type=='.png')){
|
||||
$exts[$ext] = $type;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
foreach($exts as $ext=>$type){
|
||||
$class = preg_replace('/[^_\-a-z0-9]+/','_',$ext);
|
||||
$css .= ".mf_$class {";
|
||||
$css .= ' background-image: url('.DOKU_BASE.'lib/images/fileicons/'.$ext.$type.')';
|
||||
$css .= '}';
|
||||
}
|
||||
|
||||
return $css;
|
||||
}
|
||||
}
|
47
lib/plugins/odt/helper/ecm_interface.php
Normal file
47
lib/plugins/odt/helper/ecm_interface.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Definition of Interface iElementCSSMatchable
|
||||
*
|
||||
* The goal of the interface is to define functions which
|
||||
* are required by the CSS import helper plugin (class
|
||||
* helper_plugin_odt_cssimport, cssimport.php). To be more precise
|
||||
* these functions are required by the class css_selector to do the
|
||||
* matching with a given element.
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author LarsDW223
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface iElementCSSMatchable
|
||||
*
|
||||
* To prevent clashes with other interfaces function names all functions
|
||||
* are prefixed with iECSSM_.
|
||||
*
|
||||
* @package CSS\iElementCSSMatchable
|
||||
*/
|
||||
interface iElementCSSMatchable
|
||||
{
|
||||
// Return the element's name as string.
|
||||
public function iECSSM_getName();
|
||||
|
||||
// Return the element's attribute's as an array with
|
||||
// key-value pairs:
|
||||
// key = attribute-name,
|
||||
// value = attribute-value (without '"');
|
||||
public function iECSSM_getAttributes();
|
||||
|
||||
// Return the element's parent.
|
||||
public function iECSSM_getParent();
|
||||
|
||||
// Return the element's immediately preceding sibling
|
||||
public function iECSSM_getPrecedingSibling();
|
||||
|
||||
// Does the element belong to the given pseudo class?
|
||||
// (e.g. 'visited', 'first-child')
|
||||
public function iECSSM_has_pseudo_class($class);
|
||||
|
||||
// Does the element belong to the given pseudo element?
|
||||
// (e.g. 'first-letter', 'before')
|
||||
public function iECSSM_has_pseudo_element($element);
|
||||
}
|
297
lib/plugins/odt/helper/stylefactory.php
Normal file
297
lib/plugins/odt/helper/stylefactory.php
Normal file
@@ -0,0 +1,297 @@
|
||||
<?php
|
||||
/**
|
||||
* Helper class for creating ODT styles.
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author LarsDW223
|
||||
*/
|
||||
|
||||
// must be run within Dokuwiki
|
||||
if (!defined('DOKU_INC')) die();
|
||||
|
||||
require_once DOKU_INC.'lib/plugins/odt/ODT/styles/ODTTextStyle.php';
|
||||
require_once DOKU_INC.'lib/plugins/odt/ODT/styles/ODTParagraphStyle.php';
|
||||
require_once DOKU_INC.'lib/plugins/odt/ODT/styles/ODTTableStyle.php';
|
||||
require_once DOKU_INC.'lib/plugins/odt/ODT/styles/ODTTableRowStyle.php';
|
||||
require_once DOKU_INC.'lib/plugins/odt/ODT/styles/ODTTableColumnStyle.php';
|
||||
require_once DOKU_INC.'lib/plugins/odt/ODT/styles/ODTTableCellStyle.php';
|
||||
|
||||
/**
|
||||
* Class helper_plugin_odt_stylefactory
|
||||
*
|
||||
* @package helper\stylefactory
|
||||
*/
|
||||
class helper_plugin_odt_stylefactory extends DokuWiki_Plugin {
|
||||
protected static $style_base_name = 'PluginODTAutoStyle_';
|
||||
protected static $style_count = 0;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function getMethods() {
|
||||
$result = array();
|
||||
$result[] = array(
|
||||
'name' => 'createTextStyle',
|
||||
'desc' => 'Returns ODT text style definition in $style with the wanted properties. Returns NULL, if no relevant properties were found, otherwise the new style name.',
|
||||
'params' => array('$style' => 'string',
|
||||
'$properties' => 'array',
|
||||
'$disabled_props' => 'array',
|
||||
'$parent' => 'string'),
|
||||
'return' => array('ODT text style name' => 'string'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'createParagraphStyle',
|
||||
'desc' => 'Returns ODT paragrap style definition in $style with the wanted properties. Returns NULL, if no relevant properties were found, otherwise the new style name.',
|
||||
'params' => array('$style' => 'string',
|
||||
'$properties' => 'array',
|
||||
'$disabled_props' => 'array',
|
||||
'$parent' => 'string'),
|
||||
'return' => array('ODT paragraph style name' => 'string'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'createTableTableStyle',
|
||||
'desc' => 'Returns ODT table style definition in $style with the wanted properties. Returns NULL, if no relevant properties were found, otherwise the new style name.',
|
||||
'params' => array('$style' => 'string',
|
||||
'$properties' => 'array',
|
||||
'$disabled_props' => 'array',
|
||||
'$max_width_cm' => 'integer'),
|
||||
'return' => array('ODT table style name' => 'string'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'createTableRowStyle',
|
||||
'desc' => 'Returns ODT table row style definition in $style with the wanted properties. Returns NULL, if no relevant properties were found, otherwise the new style name.',
|
||||
'params' => array('$style' => 'string',
|
||||
'$properties' => 'array',
|
||||
'$disabled_props' => 'array'),
|
||||
'return' => array('ODT table row style name' => 'string'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'createTableCellStyle',
|
||||
'desc' => 'Returns ODT table cell style definition in $style with the wanted properties. Returns NULL, if no relevant properties were found, otherwise the new style name.',
|
||||
'params' => array('$style' => 'string',
|
||||
'$properties' => 'array',
|
||||
'$disabled_props' => 'array'),
|
||||
'return' => array('ODT table cell style name' => 'string'),
|
||||
);
|
||||
$result[] = array(
|
||||
'name' => 'createTableColumnStyle',
|
||||
'desc' => 'Returns ODT table column style definition in $style with the wanted properties. Returns NULL, if no relevant properties were found, otherwise the new style name.',
|
||||
'params' => array('$style' => 'string',
|
||||
'$properties' => 'array',
|
||||
'$disabled_props' => 'array'),
|
||||
'return' => array('ODT table column style name' => 'string'),
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates a text style using the style as set in the assoziative array $properties.
|
||||
* The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'.
|
||||
* Properties which shall not be used in the style can be disabled by setting the value in disabled_props
|
||||
* to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property.
|
||||
*
|
||||
* The currently supported properties are:
|
||||
* background-color, color, font-style, font-weight, font-size, border, font-family, font-variant, letter-spacing,
|
||||
* vertical-align, background-image
|
||||
*
|
||||
* The function returns the name of the new style or NULL if all relevant properties are empty.
|
||||
*
|
||||
* @author LarsDW223
|
||||
* @param $properties
|
||||
* @param null $disabled_props
|
||||
* @return ODTTextStyle or NULL
|
||||
*/
|
||||
public static function createTextStyle(array $properties, array $disabled_props = NULL){
|
||||
return ODTTextStyle::createTextStyle($properties, $disabled_props);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates a paragraph style using the style as set in the assoziative array $properties.
|
||||
* The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'.
|
||||
* Properties which shall not be used in the style can be disabled by setting the value in disabled_props
|
||||
* to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property.
|
||||
*
|
||||
* The currently supported properties are:
|
||||
* background-color, color, font-style, font-weight, font-size, border, font-family, font-variant, letter-spacing,
|
||||
* vertical-align, line-height, background-image
|
||||
*
|
||||
* The function returns the name of the new style or NULL if all relevant properties are empty.
|
||||
*
|
||||
* @author LarsDW223
|
||||
* @param $properties
|
||||
* @param null $disabled_props
|
||||
* @return ODTParagraphStyle or NULL
|
||||
*/
|
||||
public static function createParagraphStyle(array $properties, array $disabled_props = NULL){
|
||||
return ODTParagraphStyle::createParagraphStyle($properties, $disabled_props);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates a table table style using the style as set in the assoziative array $properties.
|
||||
* The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'.
|
||||
* Properties which shall not be used in the style can be disabled by setting the value in disabled_props
|
||||
* to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property.
|
||||
*
|
||||
* The currently supported properties are:
|
||||
* width, border-collapse, background-color
|
||||
*
|
||||
* The function returns the name of the new style or NULL if all relevant properties are empty.
|
||||
*
|
||||
* @author LarsDW223
|
||||
* @param $properties
|
||||
* @param null $disabled_props
|
||||
* @param int $max_width_cm
|
||||
* @return ODTTableStyle or NULL
|
||||
*/
|
||||
public static function createTableTableStyle(array $properties, array $disabled_props = NULL, $max_width_cm = 17){
|
||||
return ODTTableStyle::createTableTableStyle($properties, $disabled_props, $max_width_cm);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates a table row style using the style as set in the assoziative array $properties.
|
||||
* The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'.
|
||||
* Properties which shall not be used in the style can be disabled by setting the value in disabled_props
|
||||
* to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property.
|
||||
*
|
||||
* The currently supported properties are:
|
||||
* height, background-color
|
||||
*
|
||||
* The function returns the name of the new style or NULL if all relevant properties are empty.
|
||||
*
|
||||
* @author LarsDW223
|
||||
* @param $properties
|
||||
* @param null $disabled_props
|
||||
* @return ODTTableRowStyle
|
||||
*/
|
||||
public static function createTableRowStyle(array $properties, array $disabled_props = NULL){
|
||||
return ODTTableRowStyle::createTableRowStyle($properties, $disabled_props);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates a table cell style using the style as set in the assoziative array $properties.
|
||||
* The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'.
|
||||
* Properties which shall not be used in the style can be disabled by setting the value in disabled_props
|
||||
* to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property.
|
||||
*
|
||||
* The currently supported properties are:
|
||||
* background-color, vertical-align
|
||||
*
|
||||
* The function returns the name of the new style or NULL if all relevant properties are empty.
|
||||
*
|
||||
* @author LarsDW223
|
||||
* @param $properties
|
||||
* @param null $disabled_props
|
||||
* @return ODTTableCellStyle or NULL
|
||||
*/
|
||||
public static function createTableCellStyle(array $properties, array $disabled_props = NULL){
|
||||
return ODTTableCellStyle::createTableCellStyle($properties, $disabled_props);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates a table column style using the style as set in the assoziative array $properties.
|
||||
* The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'.
|
||||
* Properties which shall not be used in the style can be disabled by setting the value in disabled_props
|
||||
* to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property.
|
||||
*
|
||||
* The currently supported properties are:
|
||||
* width
|
||||
*
|
||||
* The function returns the name of the new style or NULL if all relevant properties are empty.
|
||||
*
|
||||
* @author LarsDW223
|
||||
*
|
||||
* @param $style
|
||||
* @param $properties
|
||||
* @param null $disabled_props
|
||||
* @param null $style_name
|
||||
* @return ODTUnknownStyle or NULL
|
||||
*/
|
||||
public static function createTableColumnStyle(array $properties, array $disabled_props = NULL){
|
||||
return ODTTableColumnStyle::createTableColumnStyle($properties, $disabled_props);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates a frame style for multiple columns, using the style as set in the assoziative array $properties.
|
||||
* The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'.
|
||||
* Properties which shall not be used in the style can be disabled by setting the value in disabled_props
|
||||
* to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property.
|
||||
*
|
||||
* The currently supported properties are:
|
||||
* column-count, column-rule, column-gap
|
||||
*
|
||||
* The function returns the name of the new style or NULL if all relevant properties are empty.
|
||||
*
|
||||
* @author LarsDW223
|
||||
*
|
||||
* @param $style
|
||||
* @param $properties
|
||||
* @param null $disabled_props
|
||||
* @return ODTUnknownStyle or NULL
|
||||
*/
|
||||
public static function createMultiColumnFrameStyle(array $properties, array $disabled_props = NULL) {
|
||||
return ODTUnknownStyle::createMultiColumnFrameStyle($properties, $disabled_props);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates a page layout style with the parameters given in $properies.
|
||||
*
|
||||
* The currently supported properties are:
|
||||
* style-name, width, height, margin-top, margin-bottom, margin-right and margin-left.
|
||||
* All properties except the style-name are expected to be numeric values.
|
||||
* The function will add 'cm' itself, so do not add any units.
|
||||
*
|
||||
* The function returns the name of the new style or NULL if all relevant properties are empty.
|
||||
*
|
||||
* @author LarsDW223
|
||||
*
|
||||
* @param $properties
|
||||
* @param null $disabled_props
|
||||
* @return ODTUnknownStyle or NULL
|
||||
*/
|
||||
public static function createPageLayoutStyle(array $properties, array $disabled_props = NULL) {
|
||||
return ODTUnknownStyle::createPageLayoutStyle($properties, $disabled_props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple helper function for creating a text style $name setting the specfied font size $size.
|
||||
*
|
||||
* @author LarsDW223
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $size
|
||||
* @return ODTTextStyle
|
||||
*/
|
||||
public static function createSizeOnlyTextStyle ($name, $size) {
|
||||
return ODTTextStyle::createSizeOnlyTextStyle ($name, $size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple helper function for creating a paragrapg style for a pagebreak.
|
||||
*
|
||||
* @author LarsDW223
|
||||
*
|
||||
* @param string $parent Name of the parent style to set
|
||||
* @param string $before Pagebreak before or after?
|
||||
* @return ODTParagraphStyle
|
||||
*/
|
||||
public static function createPagebreakStyle($style_name, $parent=NULL,$before=true) {
|
||||
return ODTParagraphStyle::createPagebreakStyle($style_name, $parent,$before);
|
||||
}
|
||||
|
||||
/**
|
||||
* The function adjusts the property value for ODT:
|
||||
* - 'em' units are converted to 'pt' units
|
||||
* - CSS color names are converted to its RGB value
|
||||
* - short color values like #fff are converted to the long format, e.g #ffffff
|
||||
*
|
||||
* @author LarsDW223
|
||||
*
|
||||
* @param string $property The property name
|
||||
* @param string $value The value
|
||||
* @param integer $emValue Factor for conversion from 'em' to 'pt'
|
||||
* @return string Converted value
|
||||
*/
|
||||
public function adjustValueForODT ($property, $value, $emValue = 0) {
|
||||
return ODTUtility::adjustValueForODT ($property, $value, $emValue);
|
||||
}
|
||||
}
|
169
lib/plugins/odt/helper/units.php
Normal file
169
lib/plugins/odt/helper/units.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* Simple helper class to work with units (e.g. 'px', 'pt', 'cm'...)
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author LarsDW223
|
||||
*/
|
||||
|
||||
require_once DOKU_PLUGIN . 'odt/ODT/ODTUnits.php';
|
||||
|
||||
// must be run within Dokuwiki
|
||||
if (!defined('DOKU_INC')) die();
|
||||
|
||||
/**
|
||||
* Class helper_plugin_odt_units
|
||||
*
|
||||
* @package helper\units
|
||||
*/
|
||||
class helper_plugin_odt_units extends DokuWiki_Plugin {
|
||||
protected $internal = NULL;
|
||||
|
||||
public function __construct() {
|
||||
$this->internal = new ODTUnits();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function getMethods() {
|
||||
$result = array();
|
||||
$result[] = array(
|
||||
'name' => 'getColorValue',
|
||||
'desc' => 'returns the color value for a given CSS color name. Returns "#000000" if the name is unknown',
|
||||
'params' => array('name' => 'string'),
|
||||
'return' => array('color value' => 'string'),
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips of the leading digits from $value. So left over will be the unit only.
|
||||
*
|
||||
* @param int $value The length value string, e.g. '1cm'.
|
||||
* @return string The unit of $value, e.g. 'cm'
|
||||
*/
|
||||
public static function stripDigits ($value) {
|
||||
return ODTUnits::stripDigits ($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets only the digits from $value without the unit.
|
||||
*
|
||||
* @param string|int $value The length value string, e.g. '1cm'.
|
||||
* @return string The digits of $value, e.g. '1'
|
||||
*/
|
||||
public static function getDigits ($value) {
|
||||
return ODTUnits::getDigits ($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if $unit is a valid XSL unit.
|
||||
*
|
||||
* @param string $unit The unit string, e.g. 'cm'.
|
||||
* @return boolean true if valid, false otherwise
|
||||
*/
|
||||
public static function isValidXSLUnit($unit) {
|
||||
return ODTUnits::isValidXSLUnit($unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if length value string $value has a valid XSL unit.
|
||||
*
|
||||
* @param string|int $value The length value string, e.g. '1cm'.
|
||||
* @return boolean true if valid, false otherwise
|
||||
*/
|
||||
public static function hasValidXSLUnit($value) {
|
||||
return ODTUnits::hasValidXSLUnit($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pixel per em unit used for px to em conversion.
|
||||
*
|
||||
* @param int $value The value to be set.
|
||||
*/
|
||||
public function setPixelPerEm ($value) {
|
||||
$this->internal->setPixelPerEm ($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the pixel per em unit.
|
||||
*
|
||||
* @return int The current value.
|
||||
*/
|
||||
public function getPixelPerEm () {
|
||||
return $this->internal->getPixelPerEm ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the twips per pixel (X axis) used for px to pt conversion.
|
||||
*
|
||||
* @param int $value The value to be set.
|
||||
*/
|
||||
public function setTwipsPerPixelX ($value) {
|
||||
$this->internal->setTwipsPerPixelX ($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the twips per pixel (Y axis) unit used for px to pt conversion.
|
||||
*
|
||||
* @param int $value The value to be set.
|
||||
*/
|
||||
public function setTwipsPerPixelY ($value) {
|
||||
$this->internal->setTwipsPerPixelY ($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the twips per pixel (X axis) setting.
|
||||
*
|
||||
* @return int The current value.
|
||||
*/
|
||||
public function getTwipsPerPixelX () {
|
||||
return $this->internal->getTwipsPerPixelX ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the twips per pixel (Y axis) setting.
|
||||
*
|
||||
* @return int The current value.
|
||||
*/
|
||||
public function getTwipsPerPixelY () {
|
||||
return $this->internal->getTwipsPerPixelY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert pixel (X axis) to points according to the current settings.
|
||||
*
|
||||
* @param string|int $pixel String with pixel length value, e.g. '20px'
|
||||
* @return string The current value.
|
||||
*/
|
||||
public function pixelToPointsX ($pixel) {
|
||||
return $this->internal->pixelToPointsX ($pixel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert pixel (Y axis) to points according to the current settings.
|
||||
*
|
||||
* @param string|int $pixel String with pixel length value, e.g. '20px'
|
||||
* @return string The current value.
|
||||
*/
|
||||
public function pixelToPointsY ($pixel) {
|
||||
return $this->internal->pixelToPointsY ($pixel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert length value with valid XSL unit to points.
|
||||
*
|
||||
* @param string $value String with length value, e.g. '20px', '20cm'...
|
||||
* @param string $axis Is the value to be converted a value on the X or Y axis? Default is 'y'.
|
||||
* Only relevant for conversion from 'px' or 'em'.
|
||||
* @return string The current value.
|
||||
*/
|
||||
public function toPoints ($value, $axis = 'y') {
|
||||
return $this->internal->toPoints ($value, $axis);
|
||||
}
|
||||
|
||||
public function getInternal() {
|
||||
return $this->internal;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user