cvs: phd /formats xhtml.php /include PhDMediaManager.class.php /themes/pear pearweb.php /themes/php phpweb.php

From: Date: Tue, 10 Feb 2009 22:35:22 +0000
Subject: cvs: phd /formats xhtml.php /include PhDMediaManager.class.php /themes/pear pearweb.php /themes/php phpweb.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-3184@lists.php.net to get a copy of this message
cweiske Tue Feb 10 22:35:22 2009 UTC Modified files: /phd/formats xhtml.php /phd/include PhDMediaManager.class.php /phd/themes/pear pearweb.php /phd/themes/php phpweb.php Log: Copy images automatically into images/ folder. http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.88&r2=1.89&diff_format=u Index: phd/formats/xhtml.php diff -u phd/formats/xhtml.php:1.88 phd/formats/xhtml.php:1.89 --- phd/formats/xhtml.php:1.88 Thu Jan 29 15:49:34 2009 +++ phd/formats/xhtml.php Tue Feb 10 22:35:21 2009 @@ -1,5 +1,6 @@ <?php -/* $Id: xhtml.php,v 1.88 2009/01/29 15:49:34 cweiske Exp $ */ +/* $Id: xhtml.php,v 1.89 2009/02/10 22:35:21 cweiske Exp $ */ +require $ROOT. "/include/PhDMediaManager.class.php"; class XHTMLPhDFormat extends PhDFormat { protected $elementmap = array( /* {{{ */ @@ -204,6 +205,7 @@ 'replaceable' => 'span', 'row' => 'format_row', 'screen' => 'format_screen', + 'screenshot' => 'div', 'sect1' => 'format_chunk', 'sect2' => 'format_chunk', 'sect3' => 'format_chunk', @@ -368,6 +370,14 @@ * @see CDATA() */ public $role = false; + + /** + * Media manager object + * + * @var PhDMediaManager + */ + public $mediamanager = null; + /* Current Chunk variables */ protected $cchunk = array(); /* Default Chunk variables */ @@ -405,9 +415,18 @@ ), ); - public function __construct(array $IDs) { + public function __construct(array $IDs) + { parent::__construct($IDs); + $this->mediamanager = new PhDMediaManager(); } + + public function registerTheme(PhDTheme $theme) + { + parent::registerTheme($theme); + $this->mediamanager->output_dir = $theme->outputdir; + } + public function __call($func, $args) { if ($args[0]) { trigger_error("No mapper found for '{$func}'", E_USER_WARNING); @@ -1237,10 +1256,13 @@ $this->cchunk["mediaobject"]["alt"] = $value; } public function format_imagedata($open, $name, $attrs) { + $file = $attrs[PhDReader::XMLNS_DOCBOOK]["fileref"]; + $newpath = $this->mediamanager->handleFile($file); + if ($this->cchunk["mediaobject"]["alt"] !== false) { - return '<img src="' .$attrs[PhDReader::XMLNS_DOCBOOK]["fileref"]. '" alt="' .$this->cchunk["mediaobject"]["alt"]. '" />'; + return '<img src="' . $newpath . '" alt="' .$this->cchunk["mediaobject"]["alt"]. '" />'; } - return '<img src="' .$attrs[PhDReader::XMLNS_DOCBOOK]["fileref"]. '" />'; + return '<img src="' . $newpath . '" />'; } public function format_dl($open, $name, $attrs, $props) http://cvs.php.net/viewvc.cgi/phd/include/PhDMediaManager.class.php?r1=1.1&r2=1.2&diff_format=u Index: phd/include/PhDMediaManager.class.php diff -u /dev/null phd/include/PhDMediaManager.class.php:1.2 --- /dev/null Tue Feb 10 22:35:22 2009 +++ phd/include/PhDMediaManager.class.php Tue Feb 10 22:35:21 2009 @@ -0,0 +1,89 @@ +<?php +/* $Id: PhDMediaManager.class.php,v 1.2 2009/02/10 22:35:21 cweiske Exp $ */ + +/** +* Handles images (and other media objects) referenced in the docbook files. +* Copies over, returns proper filenames etc. +* Useful for xhtml output. +* +* @author Christian Weiske <cweiske@php.net> +*/ +class PhDMediaManager +{ + /** + * Directory where files are put + * + * @var string + */ + public $output_dir = null; + + /** + * If the image media directory exists + * + * @var boolean + */ + protected $media_dir_exists = false; + + + + /** + * Handles the file: + * - Generate proper filename (short version with only one directory) + * - Copy file over to this directory + * - Return filename relative to output directory + * + * @param string $filename File name relative to docbook document root + * + * @return string New file path that should be used in xhtml document + */ + public function handleFile($filename) + { + $basename = basename($filename); + $newname = md5(substr($filename, 0, -strlen($basename))) . '-' . $basename; + //FIXME: make images dynamic according to file type (e.g. video) + $newpath = 'images/' . $newname; + + $this->copyOver($filename, $newpath); + + return $newpath; + }//public function handleFile(..) + + + + /** + * Copies the file referenced with $filename into + * $output_dir/$newpath. + * + * @param string $filename Original filename + * @param string $newpath New path relative to output directory + * + * @return void + */ + protected function copyOver($filename, $newpath) + { + $fullpath = $this->output_dir . '/' . $newpath; + + if (file_exists($fullpath)) { + //no need to copy over again + return; + } + + if (!file_exists($filename)) { + trigger_error('Image does not exist: ' . $filename, E_USER_WARNING); + return; + } + + if (!$this->media_dir_exists) { + $dir = dirname($fullpath); + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } + $this->media_dir_exists = true; + } + + copy($filename, $fullpath); + }//protected function copyOver(..) + +}//class PhDMediaManager + +?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/phd/themes/pear/pearweb.php?r1=1.9&r2=1.10&diff_format=u Index: phd/themes/pear/pearweb.php diff -u phd/themes/pear/pearweb.php:1.9 phd/themes/pear/pearweb.php:1.10 --- phd/themes/pear/pearweb.php:1.9 Fri Jan 2 12:08:14 2009 +++ phd/themes/pear/pearweb.php Tue Feb 10 22:35:21 2009 @@ -5,15 +5,15 @@ * PEAR theme for the many php files used for pearweb * * @package PhD -* @version CVS: $Id: pearweb.php,v 1.9 2009/01/02 12:08:14 cweiske Exp $ +* @version CVS: $Id: pearweb.php,v 1.10 2009/02/10 22:35:21 cweiske Exp $ */ class pearweb extends peartheme { protected $streams = array(); protected $writeit = false; - - protected $outputdir = ''; + + public $outputdir = ''; /** * URL prefix for all API doc link generated with <phd:pearapi>. http://cvs.php.net/viewvc.cgi/phd/themes/php/phpweb.php?r1=1.29&r2=1.30&diff_format=u Index: phd/themes/php/phpweb.php diff -u phd/themes/php/phpweb.php:1.29 phd/themes/php/phpweb.php:1.30 --- phd/themes/php/phpweb.php:1.29 Tue Nov 4 23:04:04 2008 +++ phd/themes/php/phpweb.php Tue Feb 10 22:35:21 2009 @@ -1,11 +1,11 @@ <?php -/* $Id: phpweb.php,v 1.29 2008/11/04 23:04:04 cweiske Exp $ */ +/* $Id: phpweb.php,v 1.30 2009/02/10 22:35:21 cweiske Exp $ */ require_once $ROOT . '/themes/php/phpdotnet.php'; class phpweb extends phpdotnet { protected $streams = array(); protected $writeit = false; - protected $outputdir = ''; + public $outputdir = ''; public function __construct($IDs, $filename, $ext = "php", $chunked = true) {

« previous php.doc.cvs (#3184) next »