svn: /web/doc-editor/trunk/php/ ExtJsController.php PreviewFile.php

[email protected] (Yannick Torres)
Newsgroups php.doc.web
Message-ID <[email protected]>
yannick                                  Sun, 05 Jun 2011 19:33:09 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=311839

Log:
Preview functionnality

Changed paths:
    U   web/doc-editor/trunk/php/ExtJsController.php
    A   web/doc-editor/trunk/php/PreviewFile.php

Modified: web/doc-editor/trunk/php/ExtJsController.php
===================================================================
--- web/doc-editor/trunk/php/ExtJsController.php	2011-06-05 19:31:03 UTC (rev 311838)
+++ web/doc-editor/trunk/php/ExtJsController.php	2011-06-05 19:33:09 UTC (rev 311839)
@@ -15,6 +15,7 @@
 require_once dirname(__FILE__) . '/LogManager.php';
 require_once dirname(__FILE__) . '/LockFile.php';
 require_once dirname(__FILE__) . '/NewsReader.php';
+require_once dirname(__FILE__) . '/PreviewFile.php';
 require_once dirname(__FILE__) . '/ProjectManager.php';
 require_once dirname(__FILE__) . '/RepositoryFetcher.php';
 require_once dirname(__FILE__) . '/RepositoryManager.php';
@@ -2151,4 +2152,24 @@
         );

     }
+
+    /**
+     *
+     */
+    public function previewFile()
+    {
+        AccountManager::getInstance()->isLogged();
+
+        $path = $this->getRequestVariable('path');
+
+        $preview = new PreviewFile($path);
+
+        return JsonResponseBuilder::success(
+            array(
+                'url' => $preview->getPreviewUrl(),
+                'buildCmd' => $preview->getBuildCmd()
+            )
+        );
+
+    }
 }

Added: web/doc-editor/trunk/php/PreviewFile.php
===================================================================
--- web/doc-editor/trunk/php/PreviewFile.php	                        (rev 0)
+++ web/doc-editor/trunk/php/PreviewFile.php	2011-06-05 19:33:09 UTC (rev 311839)
@@ -0,0 +1,113 @@
+<?php
+
+class PreviewFile
+{
+    public $path;
+    public $previewUrl;
+    private $am;
+    private $outputDir;
+    private $inputDir;
+    private $buildCmd;
+
+    /**
+     */
+    public function __construct($path)
+    {
+        $this->am = AccountManager::getInstance();
+
+        // Only available for PHP project
+        if( $this->am->project != 'PHP' ) {
+            return false;
+        }
+
+        $this->path = $path;
+
+        $this->checkPath();
+        $this->makePreview();
+
+    }
+
+    private function checkPath()
+    {
+        $appConf = $this->am->appConf;
+        $project = $this->am->project;
+
+        $fullPath = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'/'.$this->path;
+
+        if( file_exists($fullPath.'.new') ) {
+            $this->path = $this->path.'.new';
+        }
+
+    }
+
+    private function checkDir()
+    {
+        // Output
+        $this->outputDir = $this->am->appConf['GLOBAL_CONFIGURATION']['data.path'].$this->am->appConf[$this->am->project]['vcs.module'].'/output-'.$this->am->vcsLogin.'/';
+        if( !is_dir($this->outputDir) ) {
+            mkdir($this->outputDir);
+        }
+
+        // Input
+        $this->inputDir = $this->am->appConf[$this->am->project]['preview.baseURI.path'].'manual/en/';
+        if( !is_dir($this->inputDir) ) {
+            mkdir($this->am->appConf[$this->am->project]['preview.baseURI.path'].'manual');
+            mkdir($this->inputDir);
+        }
+    }
+
+    /**
+     */
+    private function makePreview()
+    {
+        $appConf = $this->am->appConf;
+        $project = $this->am->project;
+
+        $this->checkDir();
+
+        // We clean the input output directory
+        $cmd = 'rm -R '.$this->outputDir.'* ; rm -R '.$this->inputDir.'*';
+        exec("$cmd");
+
+        // We start the build for this file
+        $cmd = 'cd '.$appConf[$project]['vcs.path'].'; '.$appConf['GLOBAL_CONFIGURATION']['php.bin'].' doc-base/configure.php --generate='.$this->path.' ; '.$appConf['GLOBAL_CONFIGURATION']['php.bin'].' ../phd/render.php --package PHP --format php -d doc-base/.manual.xml --output '.$this->outputDir;
+        exec("$cmd");
+
+        $this->buildCmd = $cmd;
+
+        // We move the result into preview.baseURI
+        $cmd = 'mv '.$this->outputDir.'php-web/* '.$this->inputDir;
+        exec("$cmd");
+
+        $this->getOutputFileName();
+
+    }
+
+    private function getOutputFileName()
+    {
+        // The output file name is the first ID of the file
+        $file = explode('/', $this->path);
+        $lang = $file[0];
+        array_shift($file);
+        $path = implode('/',$file);
+
+        $fileInfo = new File($lang, $path);
+        $info = $fileInfo->getInfo();
+
+        $xmlIDs = explode('|',$info['xmlid']);
+        $xmlID = $xmlIDs[0];
+
+        $this->previewUrl = $this->am->appConf[$this->am->project]['preview.baseURI'].'manual/en/'.$xmlID.'.php';
+    }
+
+    public function getPreviewUrl() {
+        return $this->previewUrl;
+    }
+
+    public function getBuildCmd() {
+        return $this->buildCmd;
+    }
+
+}
+
+?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.