Example #1
0
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::INIT:
             $this->parentdir = Config::output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR;
             if (!file_exists($this->parentdir) || is_file($this->parentdir)) {
                 mkdir($this->parentdir, 0777, true) or die("Can't create the output directory");
             }
             $this->setOutputDir($this->parentdir . 'OPS' . DIRECTORY_SEPARATOR);
             if (!file_exists($this->getOutputDir()) || is_file($this->getOutputDir())) {
                 mkdir($this->outputdir, 0777, true) or die("Can't create the cache directory");
             }
             $this->info = $this->initInfo();
             $this->openOPF($this->info, $this->getOutputDir());
             $this->openNCX($this->info, $this->getOutputDir());
             $this->createMimeTypeFile($this->parentdir);
             $this->createContainerFile($this->parentdir);
             $this->createBuildFile($this->parentdir, $this->info['epub_file']);
             $this->createCSSFile($this->getOutputDir());
             $this->loadVersionAcronymInfo();
             $this->postConstruct();
             break;
         case Render::FINALIZE:
             $this->closeOPF();
             $this->closeNCX();
             break;
         default:
             parent::update($event, $val);
     }
 }
Example #2
0
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::CHUNK:
             $this->flags = $val;
             break;
         case Render::STANDALONE:
             if ($val) {
                 $this->registerElementMap(static::getDefaultElementMap());
                 $this->registerTextMap(static::getDefaultTextMap());
             }
             break;
         case Render::INIT:
             $this->setOutputDir(Config::output_dir() . strtolower($this->getFormatName()) . '/');
             $this->postConstruct();
             if (file_exists($this->getOutputDir())) {
                 if (!is_dir($this->getOutputDir())) {
                     v("Output directory is a file?", E_USER_ERROR);
                 }
             } else {
                 if (!mkdir($this->getOutputDir())) {
                     v("Can't create output directory", E_USER_ERROR);
                 }
             }
             if (Config::css()) {
                 $this->fetchStylesheet();
             }
             break;
         case Render::VERBOSE:
             v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING);
             break;
     }
 }
Example #3
0
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::STANDALONE:
             if ($val) {
                 $this->registerElementMap($this->getDefaultElementMap());
                 $this->registerTextMap($this->getDefaultTextMap());
             } else {
                 $this->registerElementMap($this->elementmap);
                 $this->registerTextMap($this->elementmap);
             }
             break;
         case Render::INIT:
             if (!class_exists("HaruDoc")) {
                 die("PDF output needs libharu & haru/pecl extensions... Please install them and start PhD again.\n");
             }
             $this->setOutputDir(Config::output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR);
             if (!file_exists($this->getOutputDir()) || is_file($this->getOutputDir())) {
                 mkdir($this->getOutputDir(), 0777, true) or die("Can't create the cache directory.\n");
             }
             break;
         case Render::VERBOSE:
             v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING);
             break;
     }
 }
Example #4
0
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::CHUNK:
         case Render::STANDALONE:
         case Render::VERBOSE:
             parent::update($event, $val);
             break;
         case Render::INIT:
             $this->setOutputDir(Config::output_dir() . strtolower($this->getFormatName()) . '/');
             $this->postConstruct();
             if (file_exists($this->getOutputDir())) {
                 if (!is_dir($this->getOutputDir())) {
                     v("Output directory is a file?", E_USER_ERROR);
                 }
             } else {
                 if (!mkdir($this->getOutputDir(), 0777, true)) {
                     v("Can't create output directory", E_USER_ERROR);
                 }
             }
             if (Config::css()) {
                 $this->fetchStylesheet();
             }
             break;
     }
 }
Example #5
0
File: CHM.php Project: philip/phd
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::CHUNK:
             parent::update($event, $val);
             break;
         case Render::STANDALONE:
             parent::update($event, $val);
             break;
         case Render::INIT:
             $this->chmdir = Config::output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR;
             if (!file_exists($this->chmdir) || is_file($this->chmdir)) {
                 mkdir($this->chmdir) or die("Can't create the CHM project directory");
             }
             $this->outputdir = Config::output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR . "res" . DIRECTORY_SEPARATOR;
             $this->postConstruct();
             if (!file_exists($this->outputdir) || is_file($this->outputdir)) {
                 mkdir($this->outputdir) or die("Can't create the cache directory");
             }
             $lang = Config::language();
             $this->hhpStream = fopen($this->chmdir . "pear_manual_{$lang}.hhp", "w");
             $this->hhcStream = fopen($this->chmdir . "pear_manual_{$lang}.hhc", "w");
             $this->hhkStream = fopen($this->chmdir . "pear_manual_{$lang}.hhk", "w");
             foreach (array("reset-fonts", "style", "manual") as $name) {
                 if (!file_exists($this->outputdir . "{$name}.css")) {
                     file_put_contents($this->outputdir . "{$name}.css", $this->fetchStylesheet($name));
                 }
             }
             self::headerChm();
             break;
         case Render::VERBOSE:
             parent::update($event, $val);
             break;
     }
 }
Example #6
0
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::CHUNK:
             parent::update($event, $val);
             break;
         case Render::STANDALONE:
             parent::update($event, $val);
             break;
         case Render::INIT:
             $this->loadVersionAcronymInfo();
             $this->chmdir = Config::output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR;
             if (!file_exists($this->chmdir) || is_file($this->chmdir)) {
                 mkdir($this->chmdir, 0777, true) or die("Can't create the CHM project directory");
             }
             $this->outputdir = Config::output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR . "res" . DIRECTORY_SEPARATOR;
             $this->postConstruct();
             if (!file_exists($this->outputdir) || is_file($this->outputdir)) {
                 mkdir($this->outputdir, 0777, true) or die("Can't create the cache directory");
             }
             $lang = Config::language();
             $this->hhpStream = fopen($this->chmdir . "php_manual_{$lang}.hhp", "w");
             $this->hhcStream = fopen($this->chmdir . "php_manual_{$lang}.hhc", "w");
             $this->hhkStream = fopen($this->chmdir . "php_manual_{$lang}.hhk", "w");
             $stylesheet = $this->generateStylesheet();
             $this->headerChm();
             // Save the stylesheet.
             file_put_contents($this->outputdir . "style.css", $stylesheet . '#usernotes {margin-left : inherit;}' . PHP_EOL . '#layout-content { width: 100% !important; }' . PHP_EOL);
             break;
         case Render::VERBOSE:
             parent::update($event, $val);
             break;
     }
 }
Example #7
0
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::CHUNK:
             $this->flags = $val;
             break;
         case Render::STANDALONE:
             if ($val) {
                 $this->registerElementMap(parent::getDefaultElementMap());
                 $this->registerTextMap(parent::getDefaultTextMap());
             }
             break;
         case Render::INIT:
             if ($val) {
                 if (!is_resource($this->getFileStream())) {
                     $filename = Config::output_dir();
                     if (Config::output_filename()) {
                         $filename .= Config::output_filename();
                     } else {
                         $filename .= strtolower($this->getFormatName()) . $this->getExt();
                     }
                     $this->postConstruct();
                     if (Config::css()) {
                         $this->fetchStylesheet();
                     }
                     $this->setFileStream(fopen($filename, "w+"));
                     fwrite($this->getFileStream(), $this->header());
                 }
             }
             break;
         case Render::VERBOSE:
             v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING);
             break;
     }
 }
Example #8
0
File: CHM.php Project: philip/phd
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::CHUNK:
             parent::update($event, $val);
             break;
         case Render::STANDALONE:
             parent::update($event, $val);
             break;
         case Render::INIT:
             $this->loadVersionAcronymInfo();
             $this->chmdir = Config::output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR;
             if (!file_exists($this->chmdir) || is_file($this->chmdir)) {
                 mkdir($this->chmdir) or die("Can't create the CHM project directory");
             }
             $this->outputdir = Config::output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR . "res" . DIRECTORY_SEPARATOR;
             $this->postConstruct();
             if (!file_exists($this->outputdir) || is_file($this->outputdir)) {
                 mkdir($this->outputdir) or die("Can't create the cache directory");
             }
             $lang = Config::language();
             $this->hhpStream = fopen($this->chmdir . "php_manual_{$lang}.hhp", "w");
             $this->hhcStream = fopen($this->chmdir . "php_manual_{$lang}.hhc", "w");
             $this->hhkStream = fopen($this->chmdir . "php_manual_{$lang}.hhk", "w");
             file_put_contents($this->outputdir . "style.css", $this->fetchStylesheet() . PHP_EOL . 'body { padding : 3px;}');
             self::headerChm();
             break;
         case Render::VERBOSE:
             parent::update($event, $val);
             break;
     }
 }
Example #9
0
 public function __construct()
 {
     if (file_exists(Config::output_dir() . "index.sqlite")) {
         $this->sqlite = new \SQLite3(Config::output_dir() . 'index.sqlite');
         $this->sortIDs();
     }
 }
Example #10
0
File: Index.php Project: philip/phd
    public function update($event, $value = null)
    {
        switch ($event) {
            case Render::CHUNK:
                $this->flags = $value;
                break;
            case Render::STANDALONE:
                if ($value) {
                    $this->registerElementMap(static::getDefaultElementMap());
                    $this->registerTextMap(static::getDefaultTextMap());
                    $this->registerPIHandlers($this->pihandlers);
                }
                break;
            case Render::INIT:
                if ($value) {
                    if (file_exists(Config::output_dir() . "index.sqlite")) {
                        $db = new \SQLite3(Config::output_dir() . 'index.sqlite');
                        $db->exec('DELETE FROM ids');
                        $db->exec('DELETE FROM indexing');
                    } else {
                        $db = new \SQLite3(Config::output_dir() . 'index.sqlite');
                        $create = <<<SQL
CREATE TABLE ids (
    docbook_id TEXT,
    filename TEXT,
    parent_id TEXT,
    sdesc TEXT,
    ldesc TEXT,
    element TEXT,
    previous TEXT,
    next TEXT,
    chunk INTEGER
);
CREATE TABLE indexing (
    time INTEGER PRIMARY KEY
);
SQL;
                        $db->exec('PRAGMA default_synchronous=OFF');
                        $db->exec('PRAGMA count_changes=OFF');
                        $db->exec('PRAGMA cache_size=100000');
                        $db->exec($create);
                    }
                    $this->db = $db;
                    $this->chunks = array();
                } else {
                    print_r($this->chunks);
                }
                break;
            case Render::FINALIZE:
                $retval = $this->db->exec("BEGIN TRANSACTION; INSERT INTO indexing (time) VALUES ('" . time() . "'); COMMIT");
                $this->commit();
                if ($this->db->lastErrorCode()) {
                    trigger_error($this->db->lastErrorMsg(), E_USER_WARNING);
                }
                break;
        }
    }
Example #11
0
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::CHUNK:
             switch ($val) {
                 case self::OPEN_CHUNK:
                     if ($this->getFileStream()) {
                         /* I have an already open stream, back it up */
                         $this->pChunk = $this->cchunk;
                     }
                     $this->pushFileStream(fopen("php://temp/maxmemory", "r+"));
                     $this->cchunk = $this->dchunk;
                     $this->chunkOpen = true;
                     break;
                 case self::CLOSE_CHUNK:
                     $stream = $this->popFileStream();
                     $this->writeChunk($stream);
                     fclose($stream);
                     /* Do I have a parent stream I need to resume? */
                     if ($this->getFileStream()) {
                         $this->cchunk = $this->pChunk;
                         $this->chunkOpen = true;
                     } else {
                         $this->cchunk = array();
                         $this->chunkOpen = false;
                     }
                     break;
                 default:
                     var_dump("Unknown action");
             }
             break;
         case Render::STANDALONE:
             if ($val) {
                 $this->registerElementMap(self::getDefaultElementMap());
                 $this->registerTextMap(self::getDefaultTextMap());
             } else {
                 $this->registerElementMap(static::getDefaultElementMap());
                 $this->registerTextMap(static::getDefaultTextMap());
             }
             break;
         case Render::INIT:
             $this->setOutputDir(Config::output_dir() . strtolower($this->toValidName($this->getFormatName())) . '/');
             if (file_exists($this->getOutputDir())) {
                 if (!is_dir($this->getOutputDir())) {
                     v("Output directory is a file?", E_USER_ERROR);
                 }
             } else {
                 if (!mkdir($this->getOutputDir(), 0777, true)) {
                     v("Can't create output directory", E_USER_ERROR);
                 }
             }
             break;
         case Render::VERBOSE:
             v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING);
             break;
     }
 }
Example #12
0
 public function createFileName()
 {
     $filename = Config::output_dir();
     if (Config::output_filename()) {
         $filename .= Config::output_filename();
     } else {
         $filename .= strtolower($this->getFormatName()) . $this->getExt();
     }
     return $filename;
 }
Example #13
0
File: XHTML.php Project: philip/phd
 /**
  * Called after the constructor finished.
  * This is needed since themes set their outputdir and outputfile
  * in the constructor. That file/dir is used for mediamanager.
  * That means we cannot instantiate and complete the manager in our
  * constructor centrally.
  *
  * Each theme needs its own media manager, since the manager contains
  * the output path.
  *
  * @return void
  */
 public function postConstruct()
 {
     $this->mediamanager = new MediaManager(Config::xml_root());
     $outputdir = $this->getOutputDir();
     if (isset($outputdir) && $outputdir) {
         $this->mediamanager->output_dir = $outputdir;
     } else {
         $this->mediamanager->output_dir = Config::output_dir() . '/' . strtolower($this->getFormatName()) . '-data/';
         $this->mediamanager->relative_ref_path = basename($this->mediamanager->output_dir) . '/';
     }
 }
Example #14
0
 public function createDatabase()
 {
     $db = new \SQLite3(Config::output_dir() . strtolower($this->getFormatName()) . $this->getExt());
     $db->exec('DROP TABLE IF EXISTS functions');
     $db->exec('DROP TABLE IF EXISTS params');
     $db->exec('DROP TABLE IF EXISTS notes');
     $db->exec('DROP TABLE IF EXISTS seealso');
     $db->exec('DROP TABLE IF EXISTS changelogs');
     $db->exec('PRAGMA default_synchronous=OFF');
     $db->exec('PRAGMA count_changes=OFF');
     $db->exec('PRAGMA cache_size=100000');
     $db->exec($this->createSQL());
     $this->db = $db;
 }
Example #15
0
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::CHUNK:
             parent::update($event, $val);
             break;
         case Render::STANDALONE:
             parent::update($event, $val);
             break;
         case Render::INIT:
             $this->setOutputDir(Config::output_dir() . strtolower($this->getFormatName()) . '/');
             break;
             //No verbose
     }
 }
Example #16
0
 public function update($event, $value = null)
 {
     switch ($event) {
         case Render::STANDALONE:
             $this->registerElementMap($this->elementmap);
             $this->registerTextMap($this->textmap);
             break;
         case Render::FINALIZE:
             $filename = Config::output_dir() . strtolower($this->getFormatName()) . $this->getExt();
             file_put_contents($filename, $this->buffer);
             break;
         case Render::VERBOSE:
             v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING);
             break;
     }
 }
Example #17
0
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::FINALIZE:
             $this->writeJsonIndex();
             break;
         case Render::CHUNK:
             $this->flags = $val;
             break;
         case Render::STANDALONE:
             if ($val) {
                 $this->registerElementMap(static::getDefaultElementMap());
                 $this->registerTextMap(static::getDefaultTextMap());
             }
             break;
         case Render::INIT:
             $this->loadVersionAcronymInfo();
             // For HHVM - put in actual output_dir, not output_dir . strtolower($this->getFormatName) . '/'
             // This allows us to directly put the docs in manual/en instead of manual/en/php-web and having to sync back
             $this->setOutputDir(Config::output_dir() . '/');
             $this->postConstruct();
             if (file_exists($this->getOutputDir())) {
                 if (!is_dir($this->getOutputDir())) {
                     v("Output directory is a file?", E_USER_ERROR);
                 }
             } else {
                 if (!mkdir($this->getOutputDir(), 0777, true)) {
                     v("Can't create output directory", E_USER_ERROR);
                 }
             }
             if ($this->getFormatName() == "PHP-Web") {
                 if (!Config::no_toc() && is_dir($this->getOutputDir() . 'toc')) {
                     removeDir($this->getOutputDir() . 'toc');
                 }
                 if (!file_exists($this->getOutputDir() . "toc") || is_file($this->getOutputDir() . "toc")) {
                     mkdir($this->getOutputDir() . "toc", 0777, true) or die("Can't create the toc directory");
                 }
             }
             if (Config::css()) {
                 $this->fetchStylesheet();
             }
             break;
         case Render::VERBOSE:
             v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING);
             break;
     }
 }
Example #18
0
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::STANDALONE:
             if ($val) {
                 $this->registerElementMap(parent::getDefaultElementMap());
                 $this->registerTextMap(parent::getDefaultTextMap());
             }
             break;
         case Render::INIT:
             $this->setOutputDir(Config::output_dir());
             break;
         case Render::VERBOSE:
             v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING);
             break;
     }
 }
Example #19
0
File: Base.php Project: philip/phd
 public function INIT($value)
 {
     if (file_exists(Config::phpweb_version_filename())) {
         $this->versions = self::generateVersionInfo(Config::phpweb_version_filename());
     } else {
         trigger_error("Can't load the versions file", E_USER_ERROR);
     }
     $this->setOutputDir(Config::output_dir() . strtolower($this->getFormatName()) . '/');
     if (file_exists($this->getOutputDir())) {
         if (!is_dir($this->getOutputDir())) {
             v('Output directory is a file?', E_USER_ERROR);
         }
     } else {
         if (!mkdir($this->getOutputDir())) {
             v("Can't create output directory", E_USER_ERROR);
         }
     }
 }
Example #20
0
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::STANDALONE:
             if ($val) {
                 $this->registerElementMap($this->elementmap);
                 $this->registerTextMap($this->textmap);
             }
             break;
         case Render::INIT:
             if ($val) {
                 $this->setOutputDir(Config::output_dir());
                 $this->setFileStream(fopen($this->getOutputDir() . strtolower($this->getFormatName()), "w"));
                 self::headerToc();
             }
             break;
         case Render::VERBOSE:
             v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING);
             break;
     }
 }
Example #21
0
 public function __construct()
 {
     parent::__construct();
     $render_ids = Config::render_ids();
     if ($render_ids !== NULL) {
         if (is_array($render_ids)) {
             $this->partial = $render_ids;
         } else {
             $this->partial[$render_ids] = 1;
         }
         $skip_ids = Config::skip_ids();
         if ($skip_ids !== NULL) {
             if (is_array($skip_ids)) {
                 $this->skip = $skip_ids;
             } else {
                 $this->skip[$skip_ids] = 1;
             }
         }
     } else {
         throw new \Exception("Didn't get any IDs to seek");
     }
     $parents = array();
     if (file_exists(Config::output_dir() . "index.sqlite")) {
         $sqlite = new \SQLite3(Config::output_dir() . "index.sqlite");
         // Fetch all ancestors of the ids we should render
         foreach ($render_ids as $p => $v) {
             do {
                 $id = $sqlite->escapeString($p);
                 $row = $sqlite->query("SELECT parent_id FROM ids WHERE docbook_id = '{$id}'")->fetchArray(SQLITE3_ASSOC);
                 if ($row["parent_id"]) {
                     $parents[] = $p = $row["parent_id"];
                     continue;
                 }
                 break;
             } while (1);
         }
     }
     $this->parents = $parents;
 }
Example #22
0
 public function createOutputDirectory()
 {
     $this->setOutputDir(Config::output_dir() . strtolower($this->getFormatName()) . '/');
     if (file_exists($this->getOutputDir())) {
         if (!is_dir($this->getOutputDir())) {
             v('Output directory is a file?', E_USER_ERROR);
         }
     } else {
         if (!mkdir($this->getOutputDir(), 0777, true)) {
             v("Can't create output directory", E_USER_ERROR);
         }
     }
 }
Example #23
0
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::CHUNK:
             parent::update($event, $val);
             break;
         case Render::STANDALONE:
             parent::update($event, $val);
             break;
         case Render::INIT:
             $this->loadVersionAcronymInfo();
             $this->chmdir = Config::output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR;
             if (!file_exists($this->chmdir) || is_file($this->chmdir)) {
                 mkdir($this->chmdir, 0777, true) or die("Can't create the CHM project directory");
             }
             $this->outputdir = Config::output_dir() . strtolower($this->getFormatName()) . DIRECTORY_SEPARATOR . "res" . DIRECTORY_SEPARATOR;
             $this->postConstruct();
             if (!file_exists($this->outputdir) || is_file($this->outputdir)) {
                 mkdir($this->outputdir, 0777, true) or die("Can't create the cache directory");
             }
             $lang = Config::language();
             $this->hhpStream = fopen($this->chmdir . "php_manual_{$lang}.hhp", "w");
             $this->hhcStream = fopen($this->chmdir . "php_manual_{$lang}.hhc", "w");
             $this->hhkStream = fopen($this->chmdir . "php_manual_{$lang}.hhk", "w");
             $stylesheet = '';
             if (Config::css()) {
                 foreach (Config::css() as $cssname) {
                     $stylesheet .= $this->fetchStylesheet($cssname) . PHP_EOL;
                 }
             } else {
                 $stylesheet = $this->fetchStylesheet() . PHP_EOL;
             }
             self::headerChm();
             // Find referenced content - background images, sprites, etc.
             if (0 !== preg_match_all('`url\\((([\'"]|)((?:(?!file:).)*)\\2)\\)`', $stylesheet, $stylesheet_urls)) {
                 foreach (array_unique($stylesheet_urls[3]) as $stylesheet_url) {
                     // Parse the url, getting content from http://www.php.net if there is no scheme and host.
                     if (False !== ($parsed_url = parse_url($stylesheet_url))) {
                         if (!isset($parsed_url['scheme']) && !isset($parsed_url['host'])) {
                             $url_content = file_get_contents('http://www.php.net/' . $stylesheet_url);
                         } else {
                             // Otherwise content is fully identified.
                             $url_content = file_get_contents($stylesheet_url);
                         }
                         // Make sure the location to save the content is available.
                         @mkdir(dirname($content_filename = $this->outputdir . $parsed_url['path']));
                         // Save the referenced content to the new location.
                         file_put_contents($content_filename, $url_content);
                         // Add the content to the hpp file.
                         fwrite($this->hhpStream, 'res' . DIRECTORY_SEPARATOR . ($relative_url = trim(substr(realpath($content_filename), strlen(realpath($this->outputdir))), DIRECTORY_SEPARATOR)) . PHP_EOL);
                         // Force URLS to be relative to the "res" directory, but make them use the unix path separator as they will be processed by HTML.
                         $stylesheet = str_replace($stylesheet_url, str_replace(DIRECTORY_SEPARATOR, '/', $relative_url), $stylesheet);
                         v('Saved content from css : %s.', $parsed_url['path'], VERBOSE_MESSAGES);
                     } else {
                         v('Unable to save content from css : %s.', $stylesheet_url, E_USER_WARNING);
                     }
                 }
             }
             // Save the stylesheet.
             file_put_contents($this->outputdir . "style.css", $stylesheet . 'body {padding : 3px;}' . PHP_EOL . '#usernotes {margin-left : inherit;}' . PHP_EOL);
             break;
         case Render::VERBOSE:
             parent::update($event, $val);
             break;
     }
 }
Example #24
0
    public function update($event, $value = null)
    {
        switch ($event) {
            case Render::CHUNK:
                $this->flags = $value;
                break;
            case Render::STANDALONE:
                if ($value) {
                    $this->registerElementMap(static::getDefaultElementMap());
                    $this->registerTextMap(static::getDefaultTextMap());
                    $this->registerPIHandlers($this->pihandlers);
                }
                break;
            case Render::INIT:
                if ($value) {
                    if (Config::memoryindex()) {
                        $db = new \SQLite3(":memory:");
                    } else {
                        $db = new \SQLite3(Config::output_dir() . 'index.sqlite');
                        $db->exec('DROP TABLE IF EXISTS ids');
                        $db->exec('DROP TABLE IF EXISTS indexing');
                        $db->exec('DROP TABLE IF EXISTS changelogs');
                    }
                    $create = <<<SQL
CREATE TABLE ids (
    docbook_id TEXT,
    filename TEXT,
    parent_id TEXT,
    sdesc TEXT,
    ldesc TEXT,
    element TEXT,
    previous TEXT,
    next TEXT,
    chunk INTEGER
);
CREATE TABLE changelogs (
    membership TEXT, -- How the extension in distributed (pecl, core, bundled with/out external dependencies..)
    docbook_id TEXT,
    parent_id TEXT,
    version TEXT,
    description TEXT
);
CREATE TABLE indexing (
    time INTEGER PRIMARY KEY
);
SQL;
                    $db->exec('PRAGMA default_synchronous=OFF');
                    $db->exec('PRAGMA count_changes=OFF');
                    $db->exec('PRAGMA cache_size=100000');
                    $db->exec($create);
                    if (Config::memoryindex()) {
                        Config::set_indexcache($db);
                    }
                    $this->db = $db;
                    $this->chunks = array();
                } else {
                    print_r($this->chunks);
                }
                break;
            case Render::FINALIZE:
                $retval = $this->db->exec("BEGIN TRANSACTION; INSERT INTO indexing (time) VALUES ('" . time() . "'); COMMIT");
                $this->commit();
                if ($this->db->lastErrorCode()) {
                    trigger_error($this->db->lastErrorMsg(), E_USER_WARNING);
                }
                break;
        }
    }
Example #25
0
    v("Loaded config from existing file", VERBOSE_MESSAGES);
} else {
    // need to init regardless so we get package-dirs from the include-path
    Config::init(array());
}
Options_Parser::getopt();
/* If no docbook file was passed, die */
if (!is_dir(Config::xml_root()) || !is_file(Config::xml_file())) {
    trigger_error("No Docbook file given. Specify it on the command line with --docbook.", E_USER_ERROR);
}
if (!file_exists(Config::output_dir())) {
    v("Creating output directory..", VERBOSE_MESSAGES);
    if (!mkdir(Config::output_dir(), 0777, True)) {
        v("Can't create output directory : %s", Config::output_dir(), E_USER_ERROR);
    }
} elseif (!is_dir(Config::output_dir())) {
    v("Output directory is not a file?", E_USER_ERROR);
}
// This needs to be moved. Preferably into the PHP package.
if (!$conf) {
    Config::init(array("lang_dir" => __INSTALLDIR__ . DIRECTORY_SEPARATOR . "phpdotnet" . DIRECTORY_SEPARATOR . "phd" . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "langs" . DIRECTORY_SEPARATOR, "phpweb_version_filename" => Config::xml_root() . DIRECTORY_SEPARATOR . 'version.xml', "phpweb_acronym_filename" => Config::xml_root() . DIRECTORY_SEPARATOR . 'entities' . DIRECTORY_SEPARATOR . 'acronyms.xml'));
}
if (Config::saveconfig()) {
    v("Writing the config file", VERBOSE_MESSAGES);
    file_put_contents("phd.config.php", "<?php\nreturn " . var_export(Config::getAllFiltered(), 1) . ";");
}
if (Config::quit()) {
    exit(0);
}
function make_reader()
{
Example #26
0
File: XHTML.php Project: philip/phd
 protected function fetchStylesheet($name = null)
 {
     if (!$this->isChunked()) {
         foreach ((array) Config::css() as $css) {
             if ($style = file_get_contents($css)) {
                 $this->stylesheets[] = $style;
             } else {
                 v("Stylesheet %s not fetched.", $css, E_USER_WARNING);
             }
         }
         return;
     }
     $stylesDir = $this->getOutputDir();
     if (!$stylesDir) {
         $stylesDir = Config::output_dir();
     }
     $stylesDir .= 'styles/';
     if (file_exists($stylesDir)) {
         if (!is_dir($stylesDir)) {
             v("The styles/ directory is a file?", E_USER_ERROR);
         }
     } else {
         if (!mkdir($stylesDir)) {
             v("Can't create the styles/ directory.", E_USER_ERROR);
         }
     }
     foreach ((array) Config::css() as $css) {
         $basename = basename($css);
         $dest = md5(substr($css, 0, -strlen($basename))) . '-' . $basename;
         if (@copy($css, $stylesDir . $dest)) {
             $this->stylesheets[] = $dest;
         } else {
             v('Impossible to copy the %s file.', $css, E_USER_WARNING);
         }
     }
 }
Example #27
0
 /**
  * Called by Format::notify().
  *
  * Possible events:
  * - Render::STANDALONE
  *     Always called with true as value from Render::attach()
  *     Deprecated.
  *
  * - Render::INIT
  *     Called from Render::execute() when rendering
  *     is being started. Value is always true
  *
  * - Render::FINALIZE (from Render::execute())
  *     Called from Render::execute() when there is
  *     nothing more to read in the XML file.
  *
  * - Render::VERBOSE
  *     Called if the user specified the --verbose option
  *     as commandline parameter. Called in render.php
  *
  * - Render::CHUNK
  *     Called when a new chunk is opened or closed.
  *     Value is either Render::OPEN or Render::CLOSE
  *
  * @param integer $event Event flag (see Render class)
  * @param mixed   $val   Additional value flag. Depends
  *                       on $event type
  *
  * @return void
  */
 public function update($event, $val = null)
 {
     switch ($event) {
         case Render::STANDALONE:
             if ($val) {
                 $this->registerElementMap(static::getDefaultElementMap());
                 $this->registerTextMap(static::getDefaultTextMap());
             }
             break;
         case Render::INIT:
             $this->setOutputDir(Config::output_dir() . strtolower($this->getFormatName()) . '/');
             $dir = $this->getOutputDir();
             if (file_exists($dir)) {
                 if (!is_dir($dir)) {
                     v('Output directory is a file?', E_USER_ERROR);
                 }
             } else {
                 if (!mkdir($dir, 0777, true)) {
                     v('Cannot create output directory', E_USER_ERROR);
                 }
             }
             break;
         case Render::VERBOSE:
             v('Starting %s rendering', $this->getFormatName(), VERBOSE_FORMAT_RENDERING);
             break;
     }
 }
Example #28
0
 public function createFileName()
 {
     return Config::output_dir() . strtolower($this->getFormatName()) . $this->getExt();
 }
Example #29
0
 /**
  * this method handles function aliases; the PHP documentation will
  * not explictly have the function signatures for function aliases; but
  * we want the signature to be in the tag file.  Therefore, we  for function
  * aliases we must lookup the function being aliases, and make that be
  * the new function's signature as well.
  * This function assumes that only function are aliased; not methods.
  */
 private function handleFunctionAliases()
 {
     $fileName = Config::output_dir() . strtolower($this->getFormatName()) . '/php.tags';
     $tagFile = fopen($fileName, 'ab+');
     // i guess we loop through the tag file to find the aliases
     $tagLines = array();
     while (!feof($tagFile)) {
         $line = fgets($tagFile);
         $tag = explode("\t", $line);
         $isMethodTag = FALSE;
         foreach ($tag as $tagItem) {
             if (stripos($tagItem, "class:") !== FALSE) {
                 $isMethodTag = TRUE;
                 break;
             }
         }
         // the function name is the first column of the tag line
         // make sure to methods
         if (!$isMethodTag && isset($this->functionAliases[$tag[0]])) {
             // replace the aliased function name with the
             // new name
             // there may be multiple aliases for a function
             $aliases = $this->functionAliases[$tag[0]];
             foreach ($aliases as $alias) {
                 $tagLines[] = str_replace($tag[0], $alias, $line);
             }
         }
     }
     // now we have all the signature lets write out the tags
     fseek($tagFile, -1, SEEK_END);
     foreach ($tagLines as $line) {
         fputs($tagFile, $line);
     }
     fclose($tagFile);
 }