Example #1
0
 /** Build the function definitons.
  *
  * @param Doclet doclet
  */
 function functionWriter(&$doclet)
 {
     parent::HTMLWriter($doclet);
     $this->_id = 'definition';
     $rootDoc =& $this->_doclet->rootDoc();
     $packages =& $rootDoc->packages();
     ksort($packages);
     foreach ($packages as $packageName => $package) {
         $this->_sections[0] = array('title' => 'Overview', 'url' => 'overview-summary.html');
         $this->_sections[1] = array('title' => 'Package', 'url' => $package->asPath() . '/package-summary.html');
         $this->_sections[2] = array('title' => 'Function', 'selected' => TRUE);
         //$this->_sections[3] = array('title' => 'Use');
         $this->_sections[4] = array('title' => 'Tree', 'url' => 'overview-tree.html');
         $this->_sections[5] = array('title' => 'Deprecated', 'url' => 'deprecated-list.html');
         $this->_sections[6] = array('title' => 'Index', 'url' => 'index-all.html');
         $this->_depth = $package->depth() + 1;
         ob_start();
         echo "<hr>\n\n";
         echo "<h1>Functions</h1>\n\n";
         echo "<hr>\n\n";
         $functions =& $package->functions();
         if ($functions) {
             ksort($functions);
             echo '<table id="summary_function" class="title">', "\n";
             echo '<tr><th colspan="2" class="title">Function Summary</th></tr>', "\n";
             foreach ($functions as $function) {
                 $textTag =& $function->tags('@text');
                 echo "<tr>\n";
                 echo '<td class="type">', $function->modifiers(FALSE), ' ', $function->returnTypeAsString(), "</td>\n";
                 echo '<td class="description">';
                 echo '<p class="name"><a href="#', $function->name(), '()">', $function->name(), '</a>', $function->flatSignature(), '</p>';
                 if ($textTag) {
                     echo '<p class="description">', strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>'), '</p>';
                 }
                 echo "</td>\n";
                 echo "</tr>\n";
             }
             echo "</table>\n\n";
             echo '<h2 id="detail_function">Function Detail</h2>', "\n";
             foreach ($functions as $function) {
                 $textTag =& $function->tags('@text');
                 echo '<div class="location">', $function->location(), "</div>\n";
                 echo '<h3 id="', $function->name(), '()">', $function->name(), "</h3>\n";
                 echo '<code class="signature">', $function->modifiers(), ' ', $function->returnTypeAsString(), ' <strong>';
                 echo $function->name(), '</strong>', $function->flatSignature();
                 echo "</code>\n";
                 echo '<div class="details">', "\n";
                 if ($textTag) {
                     echo $this->_processInlineTags($textTag), "\n";
                 }
                 $this->_processTags($function->tags());
                 echo "</div>\n\n";
                 echo "<hr>\n\n";
             }
         }
         $this->_output = ob_get_contents();
         ob_end_clean();
         $this->_write($package->asPath() . '/package-functions.html', 'Functions', TRUE);
     }
 }
    /** Build the HTML frameset.
     *
     * @param Doclet doclet
     */
    function frameOutputWriter(&$doclet)
    {
        parent::HTMLWriter($doclet);
        ob_start();
        echo <<<END
\t\t
<frameset cols="20%,80%">

<frameset rows="30%,70%">

<frame src="overview-frame.html" name="packagelist">
<frame src="allitems-frame.html" name="index">

</frameset>

<frame src="overview-summary.html" name="main">

<noframes>
    <body>
        <h2>Frame Alert</h2>
        <p>This document is designed to be viewed using frames. If you see this message, you are using a non-frame-capable browser.<br>
        Link to <a href="overview-summary.html">Non-frame version</a>.</p>
    </body>
</noframes>

</frameset>
END;
        $this->_output = ob_get_contents();
        ob_end_clean();
        $this->_write('index.html', FALSE, FALSE);
    }
 public function getCurrentQuota($action, $httpVars, $fileVars)
 {
     $u = $this->getUsage($this->getWorkingPath());
     HTMLWriter::charsetHeader("application/json");
     print json_encode(array('USAGE' => $u, 'TOTAL' => $this->getAuthorized()));
     return;
 }
Example #4
0
    /** Build the HTML frameset.
     *
     * @param Doclet doclet
     */
    public function frameOutputWriter(&$doclet)
    {
        parent::HTMLWriter($doclet);
        ob_start();
        echo <<<END

<frameset cols="20%,80%" frameborder="1" border="1" bordercolor="#bbb" framespacing="1">

<frame src="frame.html" name="index">
<frame src="namespaces.html" name="main">

<noframes>
    <body>
        <h2>Frame Alert</h2>
        <p>This document is designed to be viewed using frames. If you see this message, you are using a non-frame-capable browser.<br>
        Link to <a href="namespaces.html">Non-frame version</a>.</p>
    </body>
</noframes>

</frameset>
END;
        $this->_output = ob_get_contents();
        ob_end_clean();
        $this->_write('index.html', false, false, false);
    }
Example #5
0
 /** Build the project overview page.
  *
  * @param Doclet doclet
  */
 public function __construct(&$doclet)
 {
     parent::__construct($doclet);
     $this->_id = 'namespaces';
     $rootDoc =& $this->_doclet->rootDoc();
     $phpdoctor =& $this->_doclet->phpdoctor();
     $packages =& $rootDoc->packages();
     ksort($packages);
     ob_start();
     echo '<header>';
     echo '<h1>' . $this->_doclet->_docTitle . '</h1>';
     echo '<h2>Overview</h2>';
     echo '</header>';
     echo '<table>';
     foreach ($packages as $packageName => $package) {
         echo '<tr><td><a href="' . $package->asPath() . '.html">' . $package->name() . '</a></td></tr>';
     }
     echo '</table>';
     $textTag =& $rootDoc->tags('@text');
     if ($textTag) {
         $description = $this->_processInlineTags($textTag);
         if ($description) {
             echo '<h3>Description</h3>';
             echo '<div class="comment">', $description, "</div>\n\n";
         }
     }
     $this->_output = ob_get_contents();
     ob_end_clean();
     $this->_write('namespaces.html', 'Namespaces', true);
 }
Example #6
0
 /** Build the function definitons.
  *
  * @param Doclet doclet
  */
 public function functionWriter(&$doclet)
 {
     parent::HTMLWriter($doclet);
     $this->_id = 'definition';
     $rootDoc =& $this->_doclet->rootDoc();
     $packages =& $rootDoc->packages();
     ksort($packages);
     foreach ($packages as $packageName => $package) {
         $this->_depth = $package->depth() + 1;
         ob_start();
         echo '<header>';
         echo '<h1>' . $this->_doclet->_docTitle . '</h1>';
         echo "<span>Global</span>\n\n";
         echo "<h2>Functions</h2>\n\n";
         echo '</header>';
         $functions =& $package->functions();
         if ($functions) {
             ksort($functions);
             echo '<table>', "\n";
             foreach ($functions as $function) {
                 $textTag =& $function->tags('@text');
                 echo "<tr>\n";
                 echo '<td class="type">', $function->modifiers(FALSE), ' ', $function->returnTypeAsString(), "</td>\n";
                 echo '<td class="description">';
                 echo '<p class="name"><a href="#', $function->name(), '()">', $function->name(), '</a>', $function->flatSignature(), '</p>';
                 if ($textTag) {
                     echo '<p class="description">', strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>'), '</p>';
                 }
                 echo "</td>\n";
                 echo "</tr>\n";
             }
             echo "</table>\n\n";
             echo '<h2>Details</h2>', "\n";
             foreach ($functions as $function) {
                 $textTag =& $function->tags('@text');
                 $this->_sourceLocation($function);
                 echo '<h3 id="', $function->name(), '()">', $function->name(), "</h3>\n";
                 echo '<code class="signature">', $function->modifiers(), ' ', $function->returnTypeAsString(), ' <strong>';
                 echo $function->name(), '</strong>', $function->flatSignature();
                 echo "</code>\n";
                 echo '<div class="details">', "\n";
                 if ($textTag) {
                     echo $this->_processInlineTags($textTag), "\n";
                 }
                 $this->_processTags($function->tags());
                 echo "</div>\n\n";
             }
         }
         $this->_output = ob_get_contents();
         ob_end_clean();
         $this->_write($package->asPath() . '/package-functions.html', 'Functions', TRUE);
     }
 }
 public function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     switch ($action) {
         case "get_secure_token":
             HTMLWriter::charsetHeader("text/plain");
             print AuthService::generateSecureToken();
             //exit(0);
             break;
             //------------------------------------
             //	CHANGE USER PASSWORD
             //------------------------------------
         //------------------------------------
         //	CHANGE USER PASSWORD
         //------------------------------------
         case "pass_change":
             $userObject = AuthService::getLoggedUser();
             if ($userObject == null || $userObject->getId() == "guest") {
                 header("Content-Type:text/plain");
                 print "SUCCESS";
                 break;
             }
             $oldPass = $httpVars["old_pass"];
             $newPass = $httpVars["new_pass"];
             $passSeed = $httpVars["pass_seed"];
             if (strlen($newPass) < ConfService::getCoreConf("PASSWORD_MINLENGTH", "auth")) {
                 header("Content-Type:text/plain");
                 print "PASS_ERROR";
                 break;
             }
             if (AuthService::checkPassword($userObject->getId(), $oldPass, false, $passSeed)) {
                 AuthService::updatePassword($userObject->getId(), $newPass);
                 if ($userObject->getLock() == "pass_change") {
                     $userObject->removeLock();
                     $userObject->save("superuser");
                 }
             } else {
                 header("Content-Type:text/plain");
                 print "PASS_ERROR";
                 break;
             }
             header("Content-Type:text/plain");
             print "SUCCESS";
             break;
         default:
             break;
     }
     return "";
 }
Example #8
0
 /** Build the package index.
  *
  * @param Doclet doclet
  */
 function packageIndexWriter(&$doclet)
 {
     parent::htmlWriter($doclet);
     $phpdoctor =& $this->_doclet->phpdoctor();
     $this->_sections[0] = array('title' => 'Overview', 'selected' => TRUE);
     $this->_sections[1] = array('title' => 'Namespace');
     $this->_sections[2] = array('title' => 'Class');
     //$this->_sections[3] = array('title' => 'Use');
     if ($phpdoctor->getOption('tree')) {
         $this->_sections[4] = array('title' => 'Tree', 'url' => 'overview-tree.html');
     }
     if ($doclet->includeSource()) {
         $this->_sections[5] = array('title' => 'Files', 'url' => 'overview-files.html');
     }
     $this->_sections[6] = array('title' => 'Deprecated', 'url' => 'deprecated-list.html');
     $this->_sections[7] = array('title' => 'Todo', 'url' => 'todo-list.html');
     $this->_sections[8] = array('title' => 'Index', 'url' => 'index-all.html');
     ob_start();
     echo "<hr>\n\n";
     echo '<h1>' . $this->_doclet->docTitle() . "</h1>\n\n";
     $rootDoc =& $this->_doclet->rootDoc();
     $textTag =& $rootDoc->tags('@text');
     if ($textTag) {
         $description = $this->_processInlineTags($textTag, TRUE);
         if ($description) {
             echo '<div class="comment">', $description, "</div>\n\n";
             echo '<dl><dt>See:</dt><dd><b><a href="#overview_description">Description</a></b></dd></dl>' . "\n\n";
         }
     }
     echo '<table class="title">' . "\n";
     echo '<tr><th colspan="2" class="title">Namespaces</th></tr>' . "\n";
     $packages =& $rootDoc->packages();
     ksort($packages);
     foreach ($packages as $name => $package) {
         $textTag =& $package->tags('@text');
         echo '<tr><td class="name"><a href="' . $package->asPath() . '/package-summary.html">' . $package->name() . '</a></td>';
         echo '<td class="description">' . strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>') . '</td></tr>' . "\n";
     }
     echo '</table>' . "\n\n";
     $textTag =& $rootDoc->tags('@text');
     if ($textTag) {
         $description = $this->_processInlineTags($textTag);
         if ($description) {
             echo '<div class="comment" id="overview_description">', $description, "</div>\n\n";
         }
     }
     echo "<hr>\n\n";
     $this->_output = ob_get_contents();
     ob_end_clean();
     $this->_write('overview-summary.html', 'Overview', TRUE);
 }
 /** Build the package frame index.
  *
  * @param Doclet doclet
  */
 function packageFrameWriter(&$doclet)
 {
     parent::HTMLWriter($doclet);
     $rootDoc =& $this->_doclet->rootDoc();
     $this->_output =& $this->_allItems($rootDoc);
     $this->_write('allitems-frame.html', 'All Items', FALSE);
     $packages =& $rootDoc->packages();
     ksort($packages);
     foreach ($packages as $packageName => $package) {
         $this->_depth = $package->depth() + 1;
         $this->_output =& $this->_buildFrame($package);
         $this->_write($package->asPath() . '/package-frame.html', $package->name(), FALSE);
     }
 }
Example #10
0
 public function switchActions($actionName, $httpVars, $fileVars)
 {
     if ($actionName != "changes" || !isset($httpVars["seq_id"])) {
         return false;
     }
     require_once AJXP_BIN_FOLDER . "/dibi.compact.php";
     dibi::connect($this->sqlDriver);
     HTMLWriter::charsetHeader('application/json', 'UTF-8');
     $res = dibi::query("SELECT\n                [seq] , [ajxp_changes].[repository_identifier] , [ajxp_changes].[node_id] , [type] , [source] ,  [target] , [ajxp_index].[bytesize], [ajxp_index].[md5], [ajxp_index].[mtime], [ajxp_index].[node_path]\n                FROM [ajxp_changes]\n                LEFT JOIN [ajxp_index]\n                    ON [ajxp_changes].[node_id] = [ajxp_index].[node_id]\n                WHERE [ajxp_changes].[repository_identifier] = %s AND [seq] > %i\n                ORDER BY [ajxp_changes].[node_id], [seq] ASC", $this->computeIdentifier(ConfService::getRepository()), AJXP_Utils::sanitize($httpVars["seq_id"], AJXP_SANITIZE_ALPHANUM));
     echo '{"changes":[';
     $previousNodeId = -1;
     $previousRow = null;
     $order = array("path" => 0, "content" => 1, "create" => 2, "delete" => 3);
     $relocateAttrs = array("bytesize", "md5", "mtime", "node_path", "repository_identifier");
     foreach ($res as $row) {
         $row->node = array();
         foreach ($relocateAttrs as $att) {
             $row->node[$att] = $row->{$att};
             unset($row->{$att});
         }
         if ($row->node_id == $previousNodeId) {
             $previousRow->target = $row->target;
             $previousRow->seq = $row->seq;
             if ($order[$row->type] > $order[$previousRow->type]) {
                 $previousRow->type = $row->type;
             }
         } else {
             if (isset($previousRow) && ($previousRow->source != $previousRow->target || $previousRow->type == "content")) {
                 echo json_encode($previousRow) . ",";
             }
             $previousRow = $row;
             $previousNodeId = $row->node_id;
         }
         $lastSeq = $row->seq;
         flush();
     }
     if (isset($previousRow) && ($previousRow->source != $previousRow->target || $previousRow->type == "content")) {
         echo json_encode($previousRow);
     }
     if (isset($lastSeq)) {
         echo '], "last_seq":' . $lastSeq . '}';
     } else {
         $lastSeq = dibi::query("SELECT MAX([seq]) FROM [ajxp_changes]")->fetchSingle();
         if (empty($lastSeq)) {
             $lastSeq = 1;
         }
         echo '], "last_seq":' . $lastSeq . '}';
     }
 }
Example #11
0
 function functionWriter(&$doclet)
 {
     parent::HTMLWriter($doclet);
     $rootDoc =& $this->_doclet->rootDoc();
     $packages =& $rootDoc->packages();
     ksort($packages);
     foreach ($packages as $packageName => $package) {
         $doc = new DomDocument();
         $doc->preserveWhiteSpace = FALSE;
         $doc->formatOutput = TRUE;
         $dom_functions = $doc->createElement('functions');
         $dom_functions->setAttribute('package', $package->name());
         $functions =& $package->functions();
         if ($functions) {
             ksort($functions);
             foreach ($functions as $function) {
                 $dom_function = $doc->createElement('function');
                 $dom_modifiers = $doc->createElement('modifiers');
                 foreach (explode(' ', trim($function->modifiers())) as $modifier) {
                     $dom_modifiers->appendChild($doc->createElement('modifier', $modifier));
                 }
                 $dom_function->appendChild($dom_modifiers);
                 $type = $function->returnTypeAsString();
                 $type = $this->__removeTextFromMarkup($type);
                 $dom_function->setAttribute('name', $function->name());
                 $dom_function->setAttribute('return', $type);
                 $dom_signature = $doc->createElement('parameters');
                 $this->getSignature($function, $doc, $dom_signature);
                 $dom_function->appendChild($dom_signature);
                 $dom_location = $doc->createElement('location', $function->sourceFilename());
                 $dom_location->setAttribute('line', $function->sourceLine());
                 $dom_function->appendChild($dom_location);
                 $textTag =& $function->tags('@text');
                 if ($textTag) {
                     $dom_description = $doc->createElement('description', $this->_processInlineTags($textTag));
                     $dom_function->appendChild($dom_description);
                 }
                 $dom_functions->appendChild($dom_function);
             }
         }
         $doc->appendChild($dom_functions);
         $this->_output = $doc->saveXML();
         $this->_write($package->asPath() . '/package-functions.xml', 'Functions', TRUE);
     }
 }
 public function switchAction($action, $httpVars, $fileVars)
 {
     switch ($action) {
         case "get_js_source":
             $jsName = AJXP_Utils::decodeSecureMagic($httpVars["object_name"]);
             $jsType = $httpVars["object_type"];
             // class or interface?
             $fName = "class." . strtolower($jsName) . ".js";
             if ($jsName == "Splitter") {
                 $fName = "splitter.js";
             }
             if (!defined("CLIENT_RESOURCES_FOLDER")) {
                 define("CLIENT_RESOURCES_FOLDER", AJXP_PLUGINS_FOLDER . "/gui.ajax/res");
             }
             // Locate the file class.ClassName.js
             if ($jsType == "class") {
                 $searchLocations = array(CLIENT_RESOURCES_FOLDER . "/js/ajaxplorer", CLIENT_RESOURCES_FOLDER . "/js/lib", AJXP_INSTALL_PATH . "/plugins/");
             } else {
                 if ($jsType == "interface") {
                     $searchLocations = array(CLIENT_RESOURCES_FOLDER . "/js/ajaxplorer/interfaces");
                 }
             }
             foreach ($searchLocations as $location) {
                 $dir_iterator = new RecursiveDirectoryIterator($location);
                 $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
                 // could use CHILD_FIRST if you so wish
                 $break = false;
                 foreach ($iterator as $file) {
                     if (strtolower(basename($file->getPathname())) == $fName) {
                         HTMLWriter::charsetHeader("text/plain", "utf-8");
                         echo file_get_contents($file->getPathname());
                         $break = true;
                         break;
                     }
                 }
                 if ($break) {
                     break;
                 }
             }
             break;
     }
 }
Example #13
0
    /** Build the HTML frameset.
     *
     * @param Doclet doclet
     */
    function frameOutputWriter(&$doclet)
    {
        parent::HTMLWriter($doclet);
        ob_start();
        echo <<<END
\t\t
\t\t<table border="0" width="100%" height="100%">
\t\t\t<tr>
\t\t\t\t<td width="200" class="sidebar">
\t\t\t\t\t<iframe frameBorder="0" scrolling="no" src="overview-frame.html" class="overview-frame" name="packagelist" width="100%"></iframe>
\t\t\t\t\t<p>&nbsp;</p>
\t\t\t\t\t<iframe frameBorder="0" scrolling="no" src="allitems-frame.html" class="allitems-frame" name="index" width="100%"></iframe>
\t\t\t\t</td>
\t\t\t\t<td><iframe frameBorder="0" scrolling="no" src="overview-summary.html" class="overview-summary-frame" name="main" width="100%"></iframe></td>
\t\t\t</tr>
\t\t</table>
END;
        //<frameset cols="20%,80%" frameborder="1" framespacing="1" border="1">
        //
        //<frameset rows="30%,70%" frameborder="2" framespacing="2" border="2">
        //
        //<frame src="overview-frame.html" name="packagelist">
        //<frame src="allitems-frame.html" name="index">
        //
        //</frameset>
        //
        //<frame src="overview-summary.html" name="main">
        //
        //<noframes>
        //    <body>
        //        <h2>Frame Alert</h2>
        //        <p>This document is designed to be viewed using frames. If you see this message, you are using a non-frame-capable browser.<br>
        //        Link to <a href="overview-summary.html">Non-frame version</a>.</p>
        //    </body>
        //</noframes>
        //
        //</frameset>
        $this->_output = ob_get_contents();
        ob_end_clean();
        $this->_write('index.html', FALSE, FALSE);
    }
 /** Build the package frame index.
  *
  * @param Doclet doclet
  */
 function packageIndexFrameWriter(&$doclet)
 {
     parent::HTMLWriter($doclet);
     ob_start();
     echo '<body id="frame">', "\n\n";
     echo '<h1>' . $this->_doclet->getHeader() . "</h1>\n\n";
     echo "<ul>\n";
     echo '<li><a href="allitems-frame.html" target="index">All Items</a></li>' . "\n";
     echo "</ul>\n\n";
     echo "<h1>Namespaces</h1>\n\n";
     $rootDoc =& $this->_doclet->rootDoc();
     echo "<ul>\n";
     $packages =& $rootDoc->packages();
     ksort($packages);
     foreach ($packages as $name => $package) {
         echo '<li><a href="' . $package->asPath() . '/package-frame.html" target="index">' . $package->name() . '</a></li>' . "\n";
     }
     echo "</ul>\n\n";
     echo '</body>', "\n\n";
     $this->_output = ob_get_contents();
     ob_end_clean();
     $this->_write('overview-frame.html', 'Overview', FALSE);
 }
Example #15
0
    /** Build the package summaries.
     *
     * @param Doclet doclet
     */
    public function __construct(&$doclet)
    {
        parent::__construct($doclet);
        $this->_id = 'frame';
        $rootDoc = $this->_doclet->rootDoc();
        $phpdoctor = $this->_doclet->phpdoctor();
        $packages = $rootDoc->packages();
        ksort($packages);
        ob_start();
        #echo '<h1>'.$this->_doclet->_docTitle.'</h1>';
        $namespaces = array();
        foreach ($packages as $package) {
            $name = explode('\\', $package->name());
            $namespaces = $this->placeIntoNamespace($namespaces, $package, $name);
        }
        $this->outputNamespace($namespaces, $packages);
        echo <<<SCRIPT
<script>
window.onload = function () {
    var lis = document.getElementsByTagName("li");
    for (var foo = 0; foo < lis.length; foo++) {
        lis[foo].onclick = function (e) {
            e.stopPropagation();
            if (this.className == "parent open") {
                this.className = "parent";
            } else if (this.className == "parent") {
                this.className = "parent open";
            }
        };
    }
};
</script>
SCRIPT;
        $this->_output = ob_get_contents();
        ob_end_clean();
        $this->_write('frame.html', 'Frame', true, false);
    }
 public function applyActions($actionName, $httpVars, $fileVars)
 {
     $git = new VersionControl_Git($this->repoBase);
     switch ($actionName) {
         case "git_history":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $file = ltrim($file, "/");
             $res = $this->gitHistory($git, $file);
             AJXP_XMLWriter::header();
             $ic = AJXP_Utils::mimetype($file, "image", false);
             $index = count($res);
             $mess = ConfService::getMessages();
             foreach ($res as &$commit) {
                 unset($commit["DETAILS"]);
                 $commit["icon"] = $ic;
                 $commit["index"] = $index;
                 $commit["EVENT"] = $mess["meta.git." . $commit["EVENT"]];
                 $index--;
                 AJXP_XMLWriter::renderNode("/" . $commit["ID"], basename($commit["FILE"]), true, $commit);
             }
             AJXP_XMLWriter::close();
             break;
             break;
         case "git_revertfile":
             $originalFile = AJXP_Utils::decodeSecureMagic($httpVars["original_file"]);
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $commitId = $httpVars["commit_id"];
             $command = $git->getCommand("cat-file");
             $command->setOption("s", true);
             $command->addArgument($commitId . ":" . $file);
             $size = $command->execute();
             $command = $git->getCommand("show");
             $command->addArgument($commitId . ":" . $file);
             $commandLine = $command->createCommandString();
             $outputStream = fopen($this->repoBase . $originalFile, "w");
             $this->executeCommandInStreams($git, $commandLine, $outputStream);
             fclose($outputStream);
             $this->commitChanges();
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::reloadDataNode();
             AJXP_XMLWriter::close();
             break;
         case "git_getfile":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $commitId = $httpVars["commit_id"];
             $attach = $httpVars["attach"];
             $command = $git->getCommand("cat-file");
             $command->setOption("s", true);
             $command->addArgument($commitId . ":" . $file);
             $size = $command->execute();
             $command = $git->getCommand("show");
             $command->addArgument($commitId . ":" . $file);
             $commandLine = $command->createCommandString();
             if ($attach == "inline") {
                 $fileExt = substr(strrchr(basename($file), '.'), 1);
                 if (empty($fileExt)) {
                     $fileMime = "application/octet-stream";
                 } else {
                     $regex = "/^([\\w\\+\\-\\.\\/]+)\\s+(\\w+\\s)*({$fileExt}\\s)/i";
                     $lines = file(AJXP_INSTALL_PATH . "/" . AJXP_PLUGINS_FOLDER . "/editor.browser/resources/other/mime.types");
                     foreach ($lines as $line) {
                         if (substr($line, 0, 1) == '#') {
                             continue;
                         }
                         // skip comments
                         $line = rtrim($line) . " ";
                         if (!preg_match($regex, $line, $matches)) {
                             continue;
                         }
                         // no match to the extension
                         $fileMime = $matches[1];
                     }
                 }
                 if (empty($fileMime)) {
                     $fileMime = "application/octet-stream";
                 }
                 HTMLWriter::generateInlineHeaders(basename($file), $size, $fileMime);
             } else {
                 HTMLWriter::generateAttachmentsHeader(basename($file), $size, false, false);
             }
             $outputStream = fopen("php://output", "a");
             $this->executeCommandInStreams($git, $commandLine, $outputStream);
             fclose($outputStream);
             break;
             break;
         default:
             break;
     }
 }
 /**
  * Send output to the user.
  * @param String $htAccessToUpdate file path
  * @param String $htContent file content
  */
 public function sendInstallResult($htAccessToUpdate, $htContent)
 {
     ConfService::clearAllCaches();
     AJXP_Utils::setApplicationFirstRunPassed();
     if ($htAccessToUpdate != null) {
         HTMLWriter::charsetHeader("application/json");
         echo json_encode(array('file' => $htAccessToUpdate, 'content' => $htContent));
     } else {
         session_destroy();
         HTMLWriter::charsetHeader("text/plain");
         echo 'OK';
     }
 }
Example #18
0
 /** Build the class definitons.
  *
  * @param Doclet doclet
  */
 function classWriter(&$doclet)
 {
     parent::HTMLWriter($doclet);
     $this->_id = 'definition';
     $rootDoc =& $this->_doclet->rootDoc();
     $phpdoctor =& $this->_doclet->phpdoctor();
     $packages =& $rootDoc->packages();
     ksort($packages);
     foreach ($packages as $packageName => $package) {
         $this->_sections[0] = array('title' => 'Overview', 'url' => 'overview-summary.html');
         $this->_sections[1] = array('title' => 'Namespace', 'url' => $package->asPath() . '/package-summary.html');
         $this->_sections[2] = array('title' => 'Class', 'selected' => TRUE);
         //$this->_sections[3] = array('title' => 'Use');
         if ($phpdoctor->getOption('tree')) {
             $this->_sections[4] = array('title' => 'Tree', 'url' => $package->asPath() . '/package-tree.html');
         }
         if ($doclet->includeSource()) {
             $this->_sections[5] = array('title' => 'Files', 'url' => 'overview-files.html');
         }
         $this->_sections[6] = array('title' => 'Deprecated', 'url' => 'deprecated-list.html');
         $this->_sections[7] = array('title' => 'Todo', 'url' => 'todo-list.html');
         $this->_sections[8] = array('title' => 'Index', 'url' => 'index-all.html');
         $this->_depth = $package->depth() + 1;
         $classes =& $package->allClasses();
         if ($classes) {
             ksort($classes);
             foreach ($classes as $name => $class) {
                 ob_start();
                 echo "<hr>\n\n";
                 echo '<div class="qualifiedName">', $class->qualifiedName(), "</div>\n";
                 $this->_sourceLocation($class);
                 if ($class->isInterface()) {
                     echo '<h1>Interface ', $class->name(), "</h1>\n\n";
                 } else {
                     echo '<h1>Class ', $class->name(), "</h1>\n\n";
                 }
                 echo '<pre class="tree">';
                 $result = $this->_buildTree($rootDoc, $classes[$name]);
                 echo $result[0];
                 echo "</pre>\n\n";
                 $implements =& $class->interfaces();
                 if (count($implements) > 0) {
                     echo "<dl>\n";
                     echo "<dt>All Implemented Interfaces:</dt>\n";
                     echo '<dd>';
                     foreach ($implements as $interface) {
                         echo '<a href="', str_repeat('../', $this->_depth), $interface->asPath(), '">';
                         if ($interface->packageName() != $class->packageName()) {
                             echo $interface->packageName(), '\\';
                         }
                         echo $interface->name(), '</a> ';
                     }
                     echo "</dd>\n";
                     echo "</dl>\n\n";
                 }
                 $subclasses =& $class->subclasses();
                 if ($subclasses) {
                     echo "<dl>\n";
                     echo "<dt>All Known Subclasses:</dt>\n";
                     echo '<dd>';
                     foreach ($subclasses as $subclass) {
                         echo '<a href="', str_repeat('../', $this->_depth), $subclass->asPath(), '">';
                         if ($subclass->packageName() != $class->packageName()) {
                             echo $subclass->packageName(), '\\';
                         }
                         echo $subclass->name(), '</a> ';
                     }
                     echo "</dd>\n";
                     echo "</dl>\n\n";
                 }
                 echo "<hr>\n\n";
                 if ($class->isInterface()) {
                     echo '<p class="signature">', $class->modifiers(), ' interface <strong>', $class->name(), '</strong>';
                 } else {
                     echo '<p class="signature">', $class->modifiers(), ' class <strong>', $class->name(), '</strong>';
                 }
                 if ($class->superclass()) {
                     $superclass =& $rootDoc->classNamed($class->superclass());
                     if ($superclass) {
                         echo '<br>extends <a href="', str_repeat('../', $this->_depth), $superclass->asPath(), '">', $superclass->name(), "</a>\n\n";
                     } else {
                         echo '<br>extends ', $class->superclass(), "\n\n";
                     }
                 }
                 echo "</p>\n\n";
                 $textTag =& $class->tags('@text');
                 if ($textTag) {
                     echo '<div class="comment" id="overview_description">', $this->_processInlineTags($textTag), "</div>\n\n";
                 }
                 $this->_processTags($class->tags());
                 echo "<hr>\n\n";
                 $constants =& $class->constants();
                 ksort($constants);
                 $fields =& $class->fields();
                 ksort($fields);
                 $constructor =& $class->constructor();
                 $methods =& $class->methods(TRUE);
                 ksort($methods);
                 if ($constants) {
                     echo '<table id="summary_field">', "\n";
                     echo '<tr><th colspan="2">Constant Summary</th></tr>', "\n";
                     foreach ($constants as $field) {
                         $textTag =& $field->tags('@text');
                         echo "<tr>\n";
                         echo '<td class="type">', $field->modifiers(FALSE), ' ', $field->typeAsString(), "</td>\n";
                         echo '<td class="description">';
                         echo '<p class="name"><a href="#', $field->name(), '">';
                         if (is_null($field->constantValue())) {
                             echo '$';
                         }
                         echo $field->name(), '</a></p>';
                         if ($textTag) {
                             echo '<p class="description">', strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>'), '</p>';
                         }
                         echo "</td>\n";
                         echo "</tr>\n";
                     }
                     echo "</table>\n\n";
                 }
                 if ($fields) {
                     echo '<table id="summary_field">', "\n";
                     echo '<tr><th colspan="2">Field Summary</th></tr>', "\n";
                     foreach ($fields as $field) {
                         $textTag =& $field->tags('@text');
                         echo "<tr>\n";
                         echo '<td class="type">', $field->modifiers(FALSE), ' ', $field->typeAsString(), "</td>\n";
                         echo '<td class="description">';
                         echo '<p class="name"><a href="#', $field->name(), '">';
                         if (is_null($field->constantValue())) {
                             echo '$';
                         }
                         echo $field->name(), '</a></p>';
                         if ($textTag) {
                             echo '<p class="description">', strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>'), '</p>';
                         }
                         echo "</td>\n";
                         echo "</tr>\n";
                     }
                     echo "</table>\n\n";
                 }
                 if ($class->superclass()) {
                     $superclass =& $rootDoc->classNamed($class->superclass());
                     if ($superclass) {
                         $this->inheritFields($superclass, $rootDoc, $package);
                     }
                 }
                 if ($constructor) {
                     echo '<table id="summary_constructor">', "\n";
                     echo '<tr><th colspan="2">Constructor Summary</th></tr>', "\n";
                     $textTag =& $constructor->tags('@text');
                     echo "<tr>\n";
                     echo '<td class="type">', $constructor->modifiers(FALSE), ' ', $constructor->returnTypeAsString(), "</td>\n";
                     echo '<td class="description">';
                     echo '<p class="name"><a href="#', $constructor->name(), '()">', $constructor->name(), '</a>', $constructor->flatSignature(), '</p>';
                     if ($textTag) {
                         echo '<p class="description">', strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>'), '</p>';
                     }
                     echo "</td>\n";
                     echo "</tr>\n";
                     echo "</table>\n\n";
                 }
                 if ($methods) {
                     echo '<table id="summary_method">', "\n";
                     echo '<tr><th colspan="2">Method Summary</th></tr>', "\n";
                     foreach ($methods as $method) {
                         $textTag =& $method->tags('@text');
                         echo "<tr>\n";
                         echo '<td class="type">', $method->modifiers(FALSE), ' ', $method->returnTypeAsString(), "</td>\n";
                         echo '<td class="description">';
                         echo '<p class="name"><a href="#', $method->name(), '()">', $method->name(), '</a>', $method->flatSignature(), '</p>';
                         if ($textTag) {
                             echo '<p class="description">', strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>'), '</p>';
                         }
                         echo "</td>\n";
                         echo "</tr>\n";
                     }
                     echo "</table>\n\n";
                 }
                 if ($class->superclass()) {
                     $superclass =& $rootDoc->classNamed($class->superclass());
                     if ($superclass) {
                         $this->inheritMethods($superclass, $rootDoc, $package);
                     }
                 }
                 if ($constants) {
                     echo '<h2 id="detail_field">Constant Detail</h2>', "\n";
                     foreach ($constants as $field) {
                         $textTag =& $field->tags('@text');
                         $type =& $field->type();
                         $this->_sourceLocation($field);
                         echo '<h3 id="', $field->name(), '">', $field->name(), "</h3>\n";
                         echo '<code class="signature">', $field->modifiers(), ' ', $field->typeAsString(), ' <strong>';
                         if (is_null($field->constantValue())) {
                             echo '$';
                         }
                         echo $field->name(), '</strong>';
                         if (!is_null($field->value())) {
                             echo ' = ', htmlspecialchars($field->value());
                         }
                         echo "</code>\n";
                         echo '<div class="details">', "\n";
                         if ($textTag) {
                             echo $this->_processInlineTags($textTag);
                         }
                         $this->_processTags($field->tags());
                         echo "</div>\n\n";
                         echo "<hr>\n\n";
                     }
                 }
                 if ($fields) {
                     echo '<h2 id="detail_field">Field Detail</h2>', "\n";
                     foreach ($fields as $field) {
                         $textTag =& $field->tags('@text');
                         $type =& $field->type();
                         $this->_sourceLocation($field);
                         echo '<h3 id="', $field->name(), '">', $field->name(), "</h3>\n";
                         echo '<code class="signature">', $field->modifiers(), ' ', $field->typeAsString(), ' <strong>';
                         if (is_null($field->constantValue())) {
                             echo '$';
                         }
                         echo $field->name(), '</strong>';
                         if (!is_null($field->value())) {
                             echo ' = ', htmlspecialchars($field->value());
                         }
                         echo "</code>\n";
                         echo '<div class="details">', "\n";
                         if ($textTag) {
                             echo $this->_processInlineTags($textTag);
                         }
                         $this->_processTags($field->tags());
                         echo "</div>\n\n";
                         echo "<hr>\n\n";
                     }
                 }
                 if ($constructor) {
                     echo '<h2 id="detail_method">Constructor Detail</h2>', "\n";
                     $textTag =& $constructor->tags('@text');
                     $this->_sourceLocation($constructor);
                     echo '<h3 id="', $constructor->name(), '()">', $constructor->name(), "</h3>\n";
                     echo '<code class="signature">', $constructor->modifiers(), ' ', $constructor->returnTypeAsString(), ' <strong>';
                     echo $constructor->name(), '</strong>', $constructor->flatSignature();
                     echo "</code>\n";
                     echo '<div class="details">', "\n";
                     if ($textTag) {
                         echo $this->_processInlineTags($textTag);
                     }
                     $this->_processTags($constructor->tags());
                     echo "</div>\n\n";
                     echo "<hr>\n\n";
                 }
                 if ($methods) {
                     echo '<h2 id="detail_method">Method Detail</h2>', "\n";
                     foreach ($methods as $method) {
                         $textTag =& $method->tags('@text');
                         $this->_sourceLocation($method);
                         echo '<h3 id="', $method->name(), '()">', $method->name(), "</h3>\n";
                         echo '<code class="signature">', $method->modifiers(), ' ', $method->returnTypeAsString(), ' <strong>';
                         echo $method->name(), '</strong>', $method->flatSignature();
                         echo "</code>\n";
                         echo '<div class="details">', "\n";
                         if ($textTag) {
                             echo $this->_processInlineTags($textTag);
                         }
                         $this->_processTags($method->tags());
                         echo "</div>\n\n";
                         echo "<hr>\n\n";
                     }
                 }
                 $this->_output = ob_get_contents();
                 ob_end_clean();
                 $this->_write($package->asPath() . '/' . strtolower($class->name()) . '.html', $class->name(), TRUE);
             }
         }
     }
 }
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     if (preg_match('/MSIE 7/', $_SERVER['HTTP_USER_AGENT']) || preg_match('/MSIE 8/', $_SERVER['HTTP_USER_AGENT'])) {
         // Force legacy theme for the moment
         $this->pluginConf["GUI_THEME"] = "oxygen";
     }
     if (!defined("AJXP_THEME_FOLDER")) {
         define("CLIENT_RESOURCES_FOLDER", AJXP_PLUGINS_FOLDER . "/gui.ajax/res");
         define("AJXP_THEME_FOLDER", CLIENT_RESOURCES_FOLDER . "/themes/" . $this->pluginConf["GUI_THEME"]);
     }
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = AJXP_Utils::securePath($getValue);
     }
     if (isset($dir) && $action != "upload") {
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     $mess = ConfService::getMessages();
     switch ($action) {
         //------------------------------------
         //	GET AN HTML TEMPLATE
         //------------------------------------
         case "get_template":
             HTMLWriter::charsetHeader();
             $folder = CLIENT_RESOURCES_FOLDER . "/html";
             if (isset($httpVars["pluginName"])) {
                 $folder = AJXP_INSTALL_PATH . "/" . AJXP_PLUGINS_FOLDER . "/" . AJXP_Utils::securePath($httpVars["pluginName"]);
                 if (isset($httpVars["pluginPath"])) {
                     $folder .= "/" . AJXP_Utils::securePath($httpVars["pluginPath"]);
                 }
             }
             $crtTheme = $this->pluginConf["GUI_THEME"];
             $thFolder = AJXP_THEME_FOLDER . "/html";
             if (isset($template_name)) {
                 if (is_file($thFolder . "/" . $template_name)) {
                     include $thFolder . "/" . $template_name;
                 } else {
                     if (is_file($folder . "/" . $template_name)) {
                         include $folder . "/" . $template_name;
                     }
                 }
             }
             break;
             //------------------------------------
             //	GET I18N MESSAGES
             //------------------------------------
         //------------------------------------
         //	GET I18N MESSAGES
         //------------------------------------
         case "get_i18n_messages":
             $refresh = false;
             if (isset($httpVars["lang"])) {
                 ConfService::setLanguage($httpVars["lang"]);
                 $refresh = true;
             }
             HTMLWriter::charsetHeader('text/javascript');
             HTMLWriter::writeI18nMessagesClass(ConfService::getMessages($refresh));
             break;
             //------------------------------------
             //	SEND XML REGISTRY
             //------------------------------------
         //------------------------------------
         //	SEND XML REGISTRY
         //------------------------------------
         case "get_xml_registry":
             $regDoc = AJXP_PluginsService::getXmlRegistry();
             $changes = AJXP_Controller::filterActionsRegistry($regDoc);
             if ($changes) {
                 AJXP_PluginsService::updateXmlRegistry($regDoc);
             }
             if (isset($_GET["xPath"])) {
                 $regPath = new DOMXPath($regDoc);
                 $nodes = $regPath->query($_GET["xPath"]);
                 AJXP_XMLWriter::header("ajxp_registry_part", array("xPath" => $_GET["xPath"]));
                 if ($nodes->length) {
                     print AJXP_XMLWriter::replaceAjxpXmlKeywords($regDoc->saveXML($nodes->item(0)));
                 }
                 AJXP_XMLWriter::close("ajxp_registry_part");
             } else {
                 AJXP_Utils::safeIniSet("zlib.output_compression", "4096");
                 header('Content-Type: application/xml; charset=UTF-8');
                 print AJXP_XMLWriter::replaceAjxpXmlKeywords($regDoc->saveXML());
             }
             break;
             //------------------------------------
             //	DISPLAY DOC
             //------------------------------------
         //------------------------------------
         //	DISPLAY DOC
         //------------------------------------
         case "display_doc":
             HTMLWriter::charsetHeader();
             echo HTMLWriter::getDocFile(AJXP_Utils::securePath(htmlentities($_GET["doc_file"])));
             break;
             //------------------------------------
             //	GET BOOT GUI
             //------------------------------------
         //------------------------------------
         //	GET BOOT GUI
         //------------------------------------
         case "get_boot_gui":
             header("X-UA-Compatible: chrome=1");
             HTMLWriter::charsetHeader();
             if (!is_file(TESTS_RESULT_FILE)) {
                 $outputArray = array();
                 $testedParams = array();
                 $passed = AJXP_Utils::runTests($outputArray, $testedParams);
                 if (!$passed && !isset($_GET["ignore_tests"])) {
                     die(AJXP_Utils::testResultsToTable($outputArray, $testedParams));
                 } else {
                     AJXP_Utils::testResultsToFile($outputArray, $testedParams);
                 }
             }
             $START_PARAMETERS = array("BOOTER_URL" => "index.php?get_action=get_boot_conf", "MAIN_ELEMENT" => "ajxp_desktop");
             if (AuthService::usersEnabled()) {
                 AuthService::preLogUser(isset($httpVars["remote_session"]) ? $httpVars["remote_session"] : "");
                 AuthService::bootSequence($START_PARAMETERS);
                 if (AuthService::getLoggedUser() != null || AuthService::logUser(null, null) == 1) {
                     if (AuthService::getDefaultRootId() == -1) {
                         AuthService::disconnect();
                     } else {
                         $loggedUser = AuthService::getLoggedUser();
                         if (!$loggedUser->canRead(ConfService::getCurrentRootDirIndex()) && AuthService::getDefaultRootId() != ConfService::getCurrentRootDirIndex()) {
                             ConfService::switchRootDir(AuthService::getDefaultRootId());
                         }
                     }
                 }
             }
             AJXP_Utils::parseApplicationGetParameters($_GET, $START_PARAMETERS, $_SESSION);
             $confErrors = ConfService::getErrors();
             if (count($confErrors)) {
                 $START_PARAMETERS["ALERT"] = implode(", ", array_values($confErrors));
             }
             $JSON_START_PARAMETERS = json_encode($START_PARAMETERS);
             $crtTheme = $this->pluginConf["GUI_THEME"];
             if (ConfService::getConf("JS_DEBUG")) {
                 if (!isset($mess)) {
                     $mess = ConfService::getMessages();
                 }
                 if (is_file(AJXP_INSTALL_PATH . "/plugins/gui.ajax/res/themes/{$crtTheme}/html/gui_debug.html")) {
                     include AJXP_INSTALL_PATH . "/plugins/gui.ajax/res/themes/{$crtTheme}/html/gui_debug.html";
                 } else {
                     include AJXP_INSTALL_PATH . "/plugins/gui.ajax/res/html/gui_debug.html";
                 }
             } else {
                 if (is_file(AJXP_INSTALL_PATH . "/plugins/gui.ajax/res/themes/{$crtTheme}/html/gui.html")) {
                     $content = file_get_contents(AJXP_INSTALL_PATH . "/plugins/gui.ajax/res/themes/{$crtTheme}/html/gui.html");
                 } else {
                     $content = file_get_contents(AJXP_INSTALL_PATH . "/plugins/gui.ajax/res/html/gui.html");
                 }
                 if (preg_match('/MSIE 7/', $_SERVER['HTTP_USER_AGENT']) || preg_match('/MSIE 8/', $_SERVER['HTTP_USER_AGENT'])) {
                     $content = str_replace("ajaxplorer_boot.js", "ajaxplorer_boot_protolegacy.js", $content);
                 }
                 $content = AJXP_XMLWriter::replaceAjxpXmlKeywords($content, false);
                 if ($JSON_START_PARAMETERS) {
                     $content = str_replace("//AJXP_JSON_START_PARAMETERS", "startParameters = " . $JSON_START_PARAMETERS . ";", $content);
                 }
                 print $content;
             }
             break;
             //------------------------------------
             //	GET CONFIG FOR BOOT
             //------------------------------------
         //------------------------------------
         //	GET CONFIG FOR BOOT
         //------------------------------------
         case "get_boot_conf":
             if (isset($_GET["server_prefix_uri"])) {
                 $_SESSION["AJXP_SERVER_PREFIX_URI"] = $_GET["server_prefix_uri"];
             }
             $config = array();
             $config["ajxpResourcesFolder"] = "plugins/gui.ajax/res";
             $config["ajxpServerAccess"] = AJXP_SERVER_ACCESS;
             $config["zipEnabled"] = ConfService::zipEnabled();
             $config["multipleFilesDownloadEnabled"] = ConfService::getCoreConf("ZIP_CREATION");
             $config["customWording"] = array("welcomeMessage" => $this->pluginConf["CUSTOM_WELCOME_MESSAGE"], "title" => ConfService::getCoreConf("APPLICATION_TITLE"), "icon" => $this->pluginConf["CUSTOM_ICON"], "iconWidth" => $this->pluginConf["CUSTOM_ICON_WIDTH"], "iconHeight" => $this->pluginConf["CUSTOM_ICON_HEIGHT"], "iconOnly" => $this->pluginConf["CUSTOM_ICON_ONLY"], "titleFontSize" => $this->pluginConf["CUSTOM_FONT_SIZE"]);
             $config["usersEnabled"] = AuthService::usersEnabled();
             $config["loggedUser"] = AuthService::getLoggedUser() != null;
             $config["currentLanguage"] = ConfService::getLanguage();
             $config["session_timeout"] = intval(ini_get("session.gc_maxlifetime"));
             if (!isset($this->pluginConf["CLIENT_TIMEOUT_TIME"]) || $this->pluginConf["CLIENT_TIMEOUT_TIME"] == "") {
                 $to = $config["session_timeout"];
             } else {
                 $to = $this->pluginConf["CLIENT_TIMEOUT_TIME"];
             }
             $config["client_timeout"] = $to;
             $config["client_timeout_warning"] = $this->pluginConf["CLIENT_TIMEOUT_WARN"];
             $config["availableLanguages"] = ConfService::getConf("AVAILABLE_LANG");
             $config["usersEditable"] = ConfService::getAuthDriverImpl()->usersEditable();
             $config["ajxpVersion"] = AJXP_VERSION;
             $config["ajxpVersionDate"] = AJXP_VERSION_DATE;
             if (stristr($_SERVER["HTTP_USER_AGENT"], "msie 6")) {
                 $config["cssResources"] = array("css/pngHack/pngHack.css");
             }
             if (!empty($this->pluginConf['GOOGLE_ANALYTICS_ID'])) {
                 $config["googleAnalyticsData"] = array("id" => $this->pluginConf['GOOGLE_ANALYTICS_ID'], "domain" => $this->pluginConf['GOOGLE_ANALYTICS_DOMAIN'], "event" => $this->pluginConf['GOOGLE_ANALYTICS_EVENT']);
             }
             $config["i18nMessages"] = ConfService::getMessages();
             $config["password_min_length"] = ConfService::getCoreConf("PASSWORD_MINLENGTH", "auth");
             $config["SECURE_TOKEN"] = AuthService::generateSecureToken();
             $config["streaming_supported"] = "true";
             $config["theme"] = $this->pluginConf["GUI_THEME"];
             header("Content-type:application/json;charset=UTF-8");
             print json_encode($config);
             break;
         default:
             break;
     }
     return false;
 }
 /**
  * @param array $data
  * @param array $options
  * @param ShareStore $shareStore
  */
 public static function render($data, $options, $shareStore)
 {
     if (isset($data["SECURITY_MODIFIED"]) && $data["SECURITY_MODIFIED"] === true) {
         self::renderError($data, "false");
         return;
     }
     // create driver from $data
     $className = $data["DRIVER"] . "AccessDriver";
     $u = parse_url($_SERVER["REQUEST_URI"]);
     $shortHash = pathinfo(basename($u["path"]), PATHINFO_FILENAME);
     // Load language messages
     $language = ConfService::getLanguage();
     if (isset($_GET["lang"])) {
         $language = basename($_GET["lang"]);
     }
     $messages = array();
     if (is_file(dirname(__FILE__) . "/res/i18n/" . $language . ".php")) {
         include dirname(__FILE__) . "/res/i18n/" . $language . ".php";
     } else {
         include dirname(__FILE__) . "/res/i18n/en.php";
     }
     if (isset($mess)) {
         $messages = $mess;
     }
     $AJXP_LINK_HAS_PASSWORD = false;
     $AJXP_LINK_BASENAME = SystemTextEncoding::toUTF8(basename($data["FILE_PATH"]));
     AJXP_PluginsService::getInstance()->initActivePlugins();
     ConfService::setLanguage($language);
     $mess = ConfService::getMessages();
     if ($shareStore->isShareExpired($shortHash, $data)) {
         self::renderError(array(), $shortHash, $mess["share_center.165"]);
         return;
     }
     $customs = array("title", "legend", "legend_pass", "background_attributes_1", "text_color", "background_color", "textshadow_color");
     $images = array("button", "background_1");
     $confs = $options;
     $confs["CUSTOM_SHAREPAGE_BACKGROUND_ATTRIBUTES_1"] = "background-repeat:repeat;background-position:50% 50%;";
     $confs["CUSTOM_SHAREPAGE_BACKGROUND_1"] = "plugins/action.share/res/hi-res/02.jpg";
     $confs["CUSTOM_SHAREPAGE_TEXT_COLOR"] = "#ffffff";
     $confs["CUSTOM_SHAREPAGE_TEXTSHADOW_COLOR"] = "rgba(0,0,0,5)";
     foreach ($customs as $custom) {
         $varName = "CUSTOM_SHAREPAGE_" . strtoupper($custom);
         ${$varName} = $confs[$varName];
     }
     $dlFolder = realpath(ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER"));
     foreach ($images as $custom) {
         $varName = "CUSTOM_SHAREPAGE_" . strtoupper($custom);
         if (!empty($confs[$varName])) {
             if (strpos($confs[$varName], "plugins/") === 0 && is_file(AJXP_INSTALL_PATH . "/" . $confs[$varName])) {
                 $realFile = AJXP_INSTALL_PATH . "/" . $confs[$varName];
                 copy($realFile, $dlFolder . "/binary-" . basename($realFile));
                 ${$varName} = "binary-" . basename($realFile);
             } else {
                 ${$varName} = "binary-" . $confs[$varName];
                 if (is_file($dlFolder . "/binary-" . $confs[$varName])) {
                     continue;
                 }
                 $copiedImageName = $dlFolder . "/binary-" . $confs[$varName];
                 $imgFile = fopen($copiedImageName, "wb");
                 ConfService::getConfStorageImpl()->loadBinary(array(), $confs[$varName], $imgFile);
                 fclose($imgFile);
             }
         }
     }
     HTMLWriter::charsetHeader();
     // Check password
     if (strlen($data["PASSWORD"])) {
         if (!isset($_POST['password']) || $_POST['password'] != $data["PASSWORD"]) {
             $AJXP_LINK_HAS_PASSWORD = true;
             $AJXP_LINK_WRONG_PASSWORD = isset($_POST['password']) && $_POST['password'] != $data["PASSWORD"];
             include AJXP_INSTALL_PATH . "/plugins/action.share/res/public_links.php";
             $res = '<div style="position: absolute;z-index: 10000; bottom: 0; right: 0; color: #666;font-family: HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size: 13px;text-align: right;padding: 6px; line-height: 20px;text-shadow: 0px 1px 0px white;" class="no_select_bg"><br>Build your own box with Pydio : <a style="color: #000000;" target="_blank" href="http://pyd.io/">http://pyd.io/</a><br/>Community - Free non supported version © C. du Jeu 2008-2014 </div>';
             AJXP_Controller::applyHook("tpl.filter_html", array(&$res));
             echo $res;
             return;
         }
     } else {
         if (!isset($_GET["dl"])) {
             include AJXP_INSTALL_PATH . "/plugins/action.share/res/public_links.php";
             $res = '<div style="position: absolute;z-index: 10000; bottom: 0; right: 0; color: #666;font-family: HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size: 13px;text-align: right;padding: 6px; line-height: 20px;text-shadow: 0px 1px 0px white;" class="no_select_bg"><br>Build your own box with Pydio : <a style="color: #000000;" target="_blank" href="http://pyd.io/">http://pyd.io/</a><br/>Community - Free non supported version © C. du Jeu 2008-2014 </div>';
             AJXP_Controller::applyHook("tpl.filter_html", array(&$res));
             echo $res;
             return;
         }
     }
     $filePath = AJXP_INSTALL_PATH . "/plugins/access." . $data["DRIVER"] . "/class." . $className . ".php";
     if (!is_file($filePath)) {
         die("Warning, cannot find driver for conf storage! ({$className}, {$filePath})");
     }
     require_once $filePath;
     $driver = new $className($data["PLUGIN_ID"], $data["BASE_DIR"]);
     $driver->loadManifest();
     //$hash = md5(serialize($data));
     $shareStore->incrementDownloadCounter($shortHash);
     //AuthService::logUser($data["OWNER_ID"], "", true);
     AuthService::logTemporaryUser($data["OWNER_ID"], $shortHash);
     if (isset($data["SAFE_USER"]) && isset($data["SAFE_PASS"])) {
         // FORCE SESSION MODE
         AJXP_Safe::getInstance()->forceSessionCredentialsUsage();
         AJXP_Safe::storeCredentials($data["SAFE_USER"], $data["SAFE_PASS"]);
     }
     $repoObject = $data["REPOSITORY"];
     ConfService::switchRootDir($repoObject->getId());
     ConfService::loadRepositoryDriver();
     AJXP_PluginsService::getInstance()->initActivePlugins();
     try {
         $params = array("file" => SystemTextEncoding::toUTF8($data["FILE_PATH"]));
         if (isset($data["PLUGINS_DATA"])) {
             $params["PLUGINS_DATA"] = $data["PLUGINS_DATA"];
         }
         if (isset($_GET["ct"]) && $_GET["ct"] == "true") {
             $mime = pathinfo($params["file"], PATHINFO_EXTENSION);
             $editors = AJXP_PluginsService::searchAllManifests("//editor[contains(@mimes,'{$mime}') and @previewProvider='true']", "node", true, true, false);
             if (count($editors)) {
                 foreach ($editors as $editor) {
                     $xPath = new DOMXPath($editor->ownerDocument);
                     $callbacks = $xPath->query("//action[@contentTypedProvider]", $editor);
                     if ($callbacks->length) {
                         $data["ACTION"] = $callbacks->item(0)->getAttribute("name");
                         if ($data["ACTION"] == "audio_proxy") {
                             $params["file"] = base64_encode($params["file"]);
                         }
                         break;
                     }
                 }
             }
         }
         AJXP_Controller::findActionAndApply($data["ACTION"], $params, null);
         register_shutdown_function(array("AuthService", "clearTemporaryUser"), $shortHash);
     } catch (Exception $e) {
         AuthService::clearTemporaryUser($shortHash);
         die($e->getMessage());
     }
 }
 public function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = AJXP_Utils::securePath($getValue);
     }
     if (isset($dir) && $action != "upload") {
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     $mess = ConfService::getMessages();
     switch ($action) {
         //------------------------------------
         //	SWITCH THE ROOT REPOSITORY
         //------------------------------------
         case "switch_repository":
             if (!isset($repository_id)) {
                 break;
             }
             $dirList = ConfService::getRepositoriesList();
             /** @var $repository_id string */
             if (!isset($dirList[$repository_id])) {
                 $errorMessage = "Trying to switch to an unkown repository!";
                 break;
             }
             ConfService::switchRootDir($repository_id);
             // Load try to init the driver now, to trigger an exception
             // if it's not loading right.
             ConfService::loadRepositoryDriver();
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $user = AuthService::getLoggedUser();
                 $activeRepId = ConfService::getCurrentRepositoryId();
                 $user->setArrayPref("history", "last_repository", $activeRepId);
                 $user->save("user");
             }
             //$logMessage = "Successfully Switched!";
             $this->logInfo("Switch Repository", array("rep. id" => $repository_id));
             break;
             //------------------------------------
             //	SEND XML REGISTRY
             //------------------------------------
         //------------------------------------
         //	SEND XML REGISTRY
         //------------------------------------
         case "get_xml_registry":
         case "state":
             $regDoc = AJXP_PluginsService::getXmlRegistry();
             $changes = AJXP_Controller::filterRegistryFromRole($regDoc);
             if ($changes) {
                 AJXP_PluginsService::updateXmlRegistry($regDoc);
             }
             $clone = $regDoc->cloneNode(true);
             $clonePath = new DOMXPath($clone);
             $serverCallbacks = $clonePath->query("//serverCallback|hooks");
             foreach ($serverCallbacks as $callback) {
                 $callback->parentNode->removeChild($callback);
             }
             $xPath = '';
             if (isset($httpVars["xPath"])) {
                 $xPath = ltrim(AJXP_Utils::securePath($httpVars["xPath"]), "/");
             }
             if (!empty($xPath)) {
                 $nodes = $clonePath->query($xPath);
                 if ($httpVars["format"] == "json") {
                     $data = AJXP_XMLWriter::xmlToArray($nodes->item(0));
                     HTMLWriter::charsetHeader("application/json");
                     echo json_encode($data);
                 } else {
                     AJXP_XMLWriter::header("ajxp_registry_part", array("xPath" => $xPath));
                     if ($nodes->length) {
                         print AJXP_XMLWriter::replaceAjxpXmlKeywords($clone->saveXML($nodes->item(0)));
                     }
                     AJXP_XMLWriter::close("ajxp_registry_part");
                 }
             } else {
                 AJXP_Utils::safeIniSet("zlib.output_compression", "4096");
                 if ($httpVars["format"] == "json") {
                     $data = AJXP_XMLWriter::xmlToArray($clone);
                     HTMLWriter::charsetHeader("application/json");
                     echo json_encode($data);
                 } else {
                     header('Content-Type: application/xml; charset=UTF-8');
                     print AJXP_XMLWriter::replaceAjxpXmlKeywords($clone->saveXML());
                 }
             }
             break;
             //------------------------------------
             //	BOOKMARK BAR
             //------------------------------------
         //------------------------------------
         //	BOOKMARK BAR
         //------------------------------------
         case "get_bookmarks":
             $bmUser = null;
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $bmUser = AuthService::getLoggedUser();
             } else {
                 if (!AuthService::usersEnabled()) {
                     $confStorage = ConfService::getConfStorageImpl();
                     $bmUser = $confStorage->createUserObject("shared");
                 }
             }
             if ($bmUser == null) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::close();
             }
             $driver = ConfService::loadRepositoryDriver();
             if (!is_a($driver, "AjxpWrapperProvider")) {
                 $driver = false;
             }
             if (isset($httpVars["bm_action"]) && isset($httpVars["bm_path"])) {
                 $bmPath = AJXP_Utils::decodeSecureMagic($httpVars["bm_path"]);
                 if ($httpVars["bm_action"] == "add_bookmark") {
                     $title = "";
                     if (isset($httpVars["bm_title"])) {
                         $title = AJXP_Utils::decodeSecureMagic($httpVars["bm_title"]);
                     }
                     if ($title == "" && $bmPath == "/") {
                         $title = ConfService::getCurrentRootDirDisplay();
                     }
                     $bmUser->addBookMark($bmPath, $title);
                     if ($driver) {
                         $node = new AJXP_Node($driver->getResourceUrl($bmPath));
                         $node->setMetadata("ajxp_bookmarked", array("ajxp_bookmarked" => "true"), true, AJXP_METADATA_SCOPE_REPOSITORY, true);
                     }
                 } else {
                     if ($httpVars["bm_action"] == "delete_bookmark") {
                         $bmUser->removeBookmark($bmPath);
                         if ($driver) {
                             $node = new AJXP_Node($driver->getResourceUrl($bmPath));
                             $node->removeMetadata("ajxp_bookmarked", true, AJXP_METADATA_SCOPE_REPOSITORY, true);
                         }
                     } else {
                         if ($httpVars["bm_action"] == "rename_bookmark" && isset($httpVars["bm_title"])) {
                             $title = AJXP_Utils::decodeSecureMagic($httpVars["bm_title"]);
                             $bmUser->renameBookmark($bmPath, $title);
                         }
                     }
                 }
                 AJXP_Controller::applyHook("msg.instant", array("<reload_bookmarks/>", ConfService::getRepository()->getId()));
                 if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                     $bmUser->save("user");
                     AuthService::updateUser($bmUser);
                 } else {
                     if (!AuthService::usersEnabled()) {
                         $bmUser->save("user");
                     }
                 }
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::writeBookmarks($bmUser->getBookmarks(), true, isset($httpVars["format"]) ? $httpVars["format"] : "legacy");
             AJXP_XMLWriter::close();
             break;
             //------------------------------------
             //	SAVE USER PREFERENCE
             //------------------------------------
         //------------------------------------
         //	SAVE USER PREFERENCE
         //------------------------------------
         case "save_user_pref":
             $userObject = AuthService::getLoggedUser();
             $i = 0;
             while (isset($httpVars["pref_name_" . $i]) && isset($httpVars["pref_value_" . $i])) {
                 $prefName = AJXP_Utils::sanitize($httpVars["pref_name_" . $i], AJXP_SANITIZE_ALPHANUM);
                 $prefValue = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($httpVars["pref_value_" . $i]));
                 if ($prefName == "password") {
                     continue;
                 }
                 if ($prefName != "pending_folder" && $userObject == null) {
                     $i++;
                     continue;
                 }
                 $userObject->setPref($prefName, $prefValue);
                 $userObject->save("user");
                 AuthService::updateUser($userObject);
                 //setcookie("AJXP_$prefName", $prefValue);
                 $i++;
             }
             header("Content-Type:text/plain");
             print "SUCCESS";
             break;
             //------------------------------------
             //	SAVE USER PREFERENCE
             //------------------------------------
         //------------------------------------
         //	SAVE USER PREFERENCE
         //------------------------------------
         case "custom_data_edit":
         case "user_create_user":
             $data = array();
             if ($action == "user_create_user" && isset($httpVars["NEW_new_user_id"])) {
                 $updating = false;
                 AJXP_Utils::parseStandardFormParameters($httpVars, $data, null, "NEW_");
                 $original_id = AJXP_Utils::decodeSecureMagic($data["new_user_id"]);
                 $data["new_user_id"] = AJXP_Utils::decodeSecureMagic($data["new_user_id"], AJXP_SANITIZE_EMAILCHARS);
                 if ($original_id != $data["new_user_id"]) {
                     throw new Exception(str_replace("%s", $data["new_user_id"], $mess["ajxp_conf.127"]));
                 }
                 if (AuthService::userExists($data["new_user_id"], "w")) {
                     throw new Exception($mess["ajxp_conf.43"]);
                 }
                 $loggedUser = AuthService::getLoggedUser();
                 $limit = $loggedUser->personalRole->filterParameterValue("core.conf", "USER_SHARED_USERS_LIMIT", AJXP_REPO_SCOPE_ALL, "");
                 if (!empty($limit) && intval($limit) > 0) {
                     $count = count($this->getUserChildren($loggedUser->getId()));
                     if ($count >= $limit) {
                         throw new Exception($mess['483']);
                     }
                 }
                 AuthService::createUser($data["new_user_id"], $data["new_password"]);
                 $userObject = ConfService::getConfStorageImpl()->createUserObject($data["new_user_id"]);
                 $userObject->setParent($loggedUser->getId());
                 $userObject->save('superuser');
                 $userObject->personalRole->clearAcls();
                 $userObject->setGroupPath($loggedUser->getGroupPath());
                 $userObject->setProfile("shared");
             } else {
                 if ($action == "user_create_user" && isset($httpVars["NEW_existing_user_id"])) {
                     $updating = true;
                     AJXP_Utils::parseStandardFormParameters($httpVars, $data, null, "NEW_");
                     $userId = $data["existing_user_id"];
                     if (!AuthService::userExists($userId)) {
                         throw new Exception("Cannot find user");
                     }
                     $userObject = ConfService::getConfStorageImpl()->createUserObject($userId);
                     if ($userObject->getParent() != AuthService::getLoggedUser()->getId()) {
                         throw new Exception("Cannot find user");
                     }
                     if (!empty($data["new_password"])) {
                         AuthService::updatePassword($userId, $data["new_password"]);
                     }
                 } else {
                     $updating = false;
                     $userObject = AuthService::getLoggedUser();
                     AJXP_Utils::parseStandardFormParameters($httpVars, $data, null, "PREFERENCES_");
                 }
             }
             $paramNodes = AJXP_PluginsService::searchAllManifests("//server_settings/param[contains(@scope,'user') and @expose='true']", "node", false, false, true);
             $rChanges = false;
             if (is_array($paramNodes) && count($paramNodes)) {
                 foreach ($paramNodes as $xmlNode) {
                     if ($xmlNode->getAttribute("expose") == "true") {
                         $parentNode = $xmlNode->parentNode->parentNode;
                         $pluginId = $parentNode->getAttribute("id");
                         if (empty($pluginId)) {
                             $pluginId = $parentNode->nodeName . "." . $parentNode->getAttribute("name");
                         }
                         $name = $xmlNode->getAttribute("name");
                         if (isset($data[$name]) || $data[$name] === "") {
                             if ($data[$name] == "__AJXP_VALUE_SET__") {
                                 continue;
                             }
                             if ($data[$name] === "" || $userObject->parentRole == null || $userObject->parentRole->filterParameterValue($pluginId, $name, AJXP_REPO_SCOPE_ALL, "") != $data[$name] || $userObject->personalRole->filterParameterValue($pluginId, $name, AJXP_REPO_SCOPE_ALL, "") != $data[$name]) {
                                 $userObject->personalRole->setParameterValue($pluginId, $name, $data[$name]);
                                 $rChanges = true;
                             }
                         }
                     }
                 }
             }
             if ($rChanges) {
                 AuthService::updateRole($userObject->personalRole, $userObject);
                 $userObject->recomputeMergedRole();
                 if ($action == "custom_data_edit") {
                     AuthService::updateUser($userObject);
                 }
             }
             if ($action == "user_create_user") {
                 AJXP_Controller::applyHook($updating ? "user.after_update" : "user.after_create", array($userObject));
                 if (isset($data["send_email"]) && $data["send_email"] == true && !empty($data["email"])) {
                     $mailer = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("mailer");
                     if ($mailer !== false) {
                         $mess = ConfService::getMessages();
                         $link = AJXP_Utils::detectServerURL();
                         $apptitle = ConfService::getCoreConf("APPLICATION_TITLE");
                         $subject = str_replace("%s", $apptitle, $mess["507"]);
                         $body = str_replace(array("%s", "%link", "%user", "%pass"), array($apptitle, $link, $data["new_user_id"], $data["new_password"]), $mess["508"]);
                         $mailer->sendMail(array($data["email"]), $subject, $body);
                     }
                 }
                 echo "SUCCESS";
             } else {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage($mess["241"], null);
                 AJXP_XMLWriter::close();
             }
             break;
         case "user_update_user":
             if (!isset($httpVars["user_id"])) {
                 throw new Exception("invalid arguments");
             }
             $userId = $httpVars["user_id"];
             if (!AuthService::userExists($userId)) {
                 throw new Exception("Cannot find user");
             }
             $userObject = ConfService::getConfStorageImpl()->createUserObject($userId);
             if ($userObject->getParent() != AuthService::getLoggedUser()->getId()) {
                 throw new Exception("Cannot find user");
             }
             $paramsString = ConfService::getCoreConf("NEWUSERS_EDIT_PARAMETERS", "conf");
             $result = array();
             $params = explode(",", $paramsString);
             foreach ($params as $p) {
                 $result[$p] = $userObject->personalRole->filterParameterValue("core.conf", $p, AJXP_REPO_SCOPE_ALL, "");
             }
             HTMLWriter::charsetHeader("application/json");
             echo json_encode($result);
             break;
             //------------------------------------
             // WEBDAV PREFERENCES
             //------------------------------------
         //------------------------------------
         // WEBDAV PREFERENCES
         //------------------------------------
         case "webdav_preferences":
             $userObject = AuthService::getLoggedUser();
             $webdavActive = false;
             $passSet = false;
             $digestSet = false;
             // Detect http/https and host
             if (ConfService::getCoreConf("WEBDAV_BASEHOST") != "") {
                 $baseURL = ConfService::getCoreConf("WEBDAV_BASEHOST");
             } else {
                 $baseURL = AJXP_Utils::detectServerURL();
             }
             $webdavBaseUrl = $baseURL . ConfService::getCoreConf("WEBDAV_BASEURI") . "/";
             $davData = $userObject->getPref("AJXP_WEBDAV_DATA");
             $digestSet = isset($davData["HA1"]);
             if (isset($httpVars["activate"]) || isset($httpVars["webdav_pass"])) {
                 if (!empty($httpVars["activate"])) {
                     $activate = $httpVars["activate"] == "true" ? true : false;
                     if (empty($davData)) {
                         $davData = array();
                     }
                     $davData["ACTIVE"] = $activate;
                 }
                 if (!empty($httpVars["webdav_pass"])) {
                     $password = $httpVars["webdav_pass"];
                     if (function_exists('mcrypt_encrypt')) {
                         $user = $userObject->getId();
                         $secret = defined("AJXP_SAFE_SECRET_KEY") ? AJXP_SAFE_SECRET_KEY : "CDAFx¨op#";
                         $password = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($user . $secret), $password, MCRYPT_MODE_ECB));
                     }
                     $davData["PASS"] = $password;
                 }
                 $userObject->setPref("AJXP_WEBDAV_DATA", $davData);
                 $userObject->save("user");
             }
             if (!empty($davData)) {
                 $webdavActive = isset($davData["ACTIVE"]) && $davData["ACTIVE"] === true;
                 $passSet = isset($davData["PASS"]);
             }
             $repoList = ConfService::getRepositoriesList();
             $davRepos = array();
             $loggedUser = AuthService::getLoggedUser();
             foreach ($repoList as $repoIndex => $repoObject) {
                 $accessType = $repoObject->getAccessType();
                 $driver = AJXP_PluginsService::getInstance()->getPluginByTypeName("access", $accessType);
                 if (is_a($driver, "AjxpWrapperProvider") && !$repoObject->getOption("AJXP_WEBDAV_DISABLED") && ($loggedUser->canRead($repoIndex) || $loggedUser->canWrite($repoIndex))) {
                     $davRepos[$repoIndex] = $webdavBaseUrl . "" . ($repoObject->getSlug() == null ? $repoObject->getId() : $repoObject->getSlug());
                 }
             }
             $prefs = array("webdav_active" => $webdavActive, "password_set" => $passSet, "digest_set" => $digestSet, "webdav_force_basic" => ConfService::getCoreConf("WEBDAV_FORCE_BASIC") === true, "webdav_base_url" => $webdavBaseUrl, "webdav_repositories" => $davRepos);
             HTMLWriter::charsetHeader("application/json");
             print json_encode($prefs);
             break;
         case "get_user_template_logo":
             $tplId = $httpVars["template_id"];
             $iconFormat = $httpVars["icon_format"];
             $repo = ConfService::getRepositoryById($tplId);
             $logo = $repo->getOption("TPL_ICON_" . strtoupper($iconFormat));
             if (isset($logo) && is_file(AJXP_DATA_PATH . "/plugins/core.conf/tpl_logos/" . $logo)) {
                 header("Content-Type: " . AJXP_Utils::getImageMimeType($logo) . "; name=\"" . $logo . "\"");
                 header("Content-Length: " . filesize(AJXP_DATA_PATH . "/plugins/core.conf/tpl_logos/" . $logo));
                 header('Pragma:');
                 header('Cache-Control: public');
                 header("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - 10000) . " GMT");
                 header("Expires: " . gmdate("D, d M Y H:i:s", time() + 5 * 24 * 3600) . " GMT");
                 readfile(AJXP_DATA_PATH . "/plugins/core.conf/tpl_logos/" . $logo);
             } else {
                 $logo = "default_template_logo-" . ($iconFormat == "small" ? 16 : 22) . ".png";
                 header("Content-Type: " . AJXP_Utils::getImageMimeType($logo) . "; name=\"" . $logo . "\"");
                 header("Content-Length: " . filesize(AJXP_INSTALL_PATH . "/" . AJXP_PLUGINS_FOLDER . "/core.conf/" . $logo));
                 header('Pragma:');
                 header('Cache-Control: public');
                 header("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - 10000) . " GMT");
                 header("Expires: " . gmdate("D, d M Y H:i:s", time() + 5 * 24 * 3600) . " GMT");
                 readfile(AJXP_INSTALL_PATH . "/" . AJXP_PLUGINS_FOLDER . "/core.conf/" . $logo);
             }
             break;
         case "get_user_templates_definition":
             AJXP_XMLWriter::header("repository_templates");
             $count = 0;
             $repositories = ConfService::listRepositoriesWithCriteria(array("isTemplate" => 1), $count);
             $pServ = AJXP_PluginsService::getInstance();
             foreach ($repositories as $repo) {
                 if (!$repo->isTemplate) {
                     continue;
                 }
                 if (!$repo->getOption("TPL_USER_CAN_CREATE")) {
                     continue;
                 }
                 $repoId = $repo->getId();
                 $repoLabel = $repo->getDisplay();
                 $repoType = $repo->getAccessType();
                 print "<template repository_id=\"{$repoId}\" repository_label=\"{$repoLabel}\" repository_type=\"{$repoType}\">";
                 $driverPlug = $pServ->getPluginByTypeName("access", $repoType);
                 $params = $driverPlug->getManifestRawContent("//param", "node");
                 $tplDefined = $repo->getOptionsDefined();
                 $defaultLabel = '';
                 foreach ($params as $paramNode) {
                     $name = $paramNode->getAttribute("name");
                     if (strpos($name, "TPL_") === 0) {
                         if ($name == "TPL_DEFAULT_LABEL") {
                             $defaultLabel = str_replace("AJXP_USER", AuthService::getLoggedUser()->getId(), $repo->getOption($name));
                         }
                         continue;
                     }
                     if (in_array($paramNode->getAttribute("name"), $tplDefined)) {
                         continue;
                     }
                     if ($paramNode->getAttribute('no_templates') == 'true') {
                         continue;
                     }
                     print AJXP_XMLWriter::replaceAjxpXmlKeywords($paramNode->ownerDocument->saveXML($paramNode));
                 }
                 // ADD LABEL
                 echo '<param name="DISPLAY" type="string" label="' . $mess[359] . '" description="' . $mess[429] . '" mandatory="true" default="' . $defaultLabel . '"/>';
                 print "</template>";
             }
             AJXP_XMLWriter::close("repository_templates");
             break;
         case "user_create_repository":
             $tplId = $httpVars["template_id"];
             $tplRepo = ConfService::getRepositoryById($tplId);
             $options = array();
             AJXP_Utils::parseStandardFormParameters($httpVars, $options);
             $loggedUser = AuthService::getLoggedUser();
             $newRep = $tplRepo->createTemplateChild(AJXP_Utils::sanitize($httpVars["DISPLAY"]), $options, null, $loggedUser->getId());
             $gPath = $loggedUser->getGroupPath();
             if (!empty($gPath)) {
                 $newRep->setGroupPath($gPath);
             }
             $res = ConfService::addRepository($newRep);
             AJXP_XMLWriter::header();
             if ($res == -1) {
                 AJXP_XMLWriter::sendMessage(null, $mess[426]);
             } else {
                 // Make sure we do not overwrite otherwise loaded rights.
                 $loggedUser->load();
                 $loggedUser->personalRole->setAcl($newRep->getUniqueId(), "rw");
                 $loggedUser->save("superuser");
                 $loggedUser->recomputeMergedRole();
                 AuthService::updateUser($loggedUser);
                 AJXP_XMLWriter::sendMessage($mess[425], null);
                 AJXP_XMLWriter::reloadDataNode("", $newRep->getUniqueId());
                 AJXP_XMLWriter::reloadRepositoryList();
             }
             AJXP_XMLWriter::close();
             break;
         case "user_delete_repository":
             $repoId = $httpVars["repository_id"];
             $repository = ConfService::getRepositoryById($repoId);
             if (!$repository->getUniqueUser() || $repository->getUniqueUser() != AuthService::getLoggedUser()->getId()) {
                 throw new Exception("You are not allowed to perform this operation!");
             }
             $res = ConfService::deleteRepository($repoId);
             AJXP_XMLWriter::header();
             if ($res == -1) {
                 AJXP_XMLWriter::sendMessage(null, $mess[427]);
             } else {
                 $loggedUser = AuthService::getLoggedUser();
                 // Make sure we do not override remotely set rights
                 $loggedUser->load();
                 $loggedUser->personalRole->setAcl($repoId, "");
                 $loggedUser->save("superuser");
                 AuthService::updateUser($loggedUser);
                 AJXP_XMLWriter::sendMessage($mess[428], null);
                 AJXP_XMLWriter::reloadRepositoryList();
             }
             AJXP_XMLWriter::close();
             break;
         case "user_delete_user":
             $userId = $httpVars["user_id"];
             $userObject = ConfService::getConfStorageImpl()->createUserObject($userId);
             if ($userObject == null || !$userObject->hasParent() || $userObject->getParent() != AuthService::getLoggedUser()->getId()) {
                 throw new Exception("You are not allowed to edit this user");
             }
             AuthService::deleteUser($userId);
             echo "SUCCESS";
             break;
         case "user_list_authorized_users":
             $defaultFormat = "html";
             HTMLWriter::charsetHeader();
             if (!ConfService::getAuthDriverImpl()->usersEditable()) {
                 break;
             }
             $loggedUser = AuthService::getLoggedUser();
             $crtValue = $httpVars["value"];
             $usersOnly = isset($httpVars["users_only"]) && $httpVars["users_only"] == "true";
             $existingOnly = isset($httpVars["existing_only"]) && $httpVars["existing_only"] == "true";
             if (!empty($crtValue)) {
                 $regexp = '^' . $crtValue;
             } else {
                 $regexp = null;
             }
             $skipDisplayWithoutRegexp = ConfService::getCoreConf("USERS_LIST_REGEXP_MANDATORY", "conf");
             if ($skipDisplayWithoutRegexp && $regexp == null) {
                 print "<ul></ul>";
                 break;
             }
             $limit = intval(ConfService::getCoreConf("USERS_LIST_COMPLETE_LIMIT", "conf"));
             $searchAll = ConfService::getCoreConf("CROSSUSERS_ALLGROUPS", "conf");
             $displayAll = ConfService::getCoreConf("CROSSUSERS_ALLGROUPS_DISPLAY", "conf");
             $baseGroup = "/";
             if ($regexp == null && !$displayAll || $regexp != null && !$searchAll) {
                 $baseGroup = AuthService::filterBaseGroup("/");
             }
             AuthService::setGroupFiltering(false);
             $allUsers = AuthService::listUsers($baseGroup, $regexp, 0, $limit, false);
             if (!$usersOnly) {
                 $allGroups = array();
                 $roleOrGroup = ConfService::getCoreConf("GROUP_OR_ROLE", "conf");
                 $rolePrefix = $excludeString = $includeString = null;
                 if (!is_array($roleOrGroup)) {
                     $roleOrGroup = array("group_switch_value" => $roleOrGroup);
                 }
                 $listRoleType = false;
                 if (isset($roleOrGroup["PREFIX"])) {
                     $rolePrefix = $loggedUser->mergedRole->filterParameterValue("core.conf", "PREFIX", null, $roleOrGroup["PREFIX"]);
                     $excludeString = $loggedUser->mergedRole->filterParameterValue("core.conf", "EXCLUDED", null, $roleOrGroup["EXCLUDED"]);
                     $includeString = $loggedUser->mergedRole->filterParameterValue("core.conf", "INCLUDED", null, $roleOrGroup["INCLUDED"]);
                     $listUserRolesOnly = $loggedUser->mergedRole->filterParameterValue("core.conf", "LIST_ROLE_BY", null, $roleOrGroup["LIST_ROLE_BY"]);
                     if (is_array($listUserRolesOnly) && isset($listUserRolesOnly["group_switch_value"])) {
                         switch ($listUserRolesOnly["group_switch_value"]) {
                             case "userroles":
                                 $listRoleType = true;
                                 break;
                             case "allroles":
                                 $listRoleType = false;
                                 break;
                             default:
                                 break;
                         }
                     }
                 }
                 switch (strtolower($roleOrGroup["group_switch_value"])) {
                     case 'user':
                         // donothing
                         break;
                     case 'group':
                         $authGroups = AuthService::listChildrenGroups($baseGroup);
                         foreach ($authGroups as $gId => $gName) {
                             $allGroups["AJXP_GRP_" . rtrim($baseGroup, "/") . "/" . ltrim($gId, "/")] = $gName;
                         }
                         break;
                     case 'role':
                         $allGroups = $this->getUserRoleList($loggedUser, $rolePrefix, $includeString, $excludeString, $listRoleType);
                         break;
                     case 'rolegroup':
                         $groups = array();
                         $authGroups = AuthService::listChildrenGroups($baseGroup);
                         foreach ($authGroups as $gId => $gName) {
                             $groups["AJXP_GRP_" . rtrim($baseGroup, "/") . "/" . ltrim($gId, "/")] = $gName;
                         }
                         $roles = $this->getUserRoleList($loggedUser, $rolePrefix, $includeString, $excludeString, $listRoleType);
                         empty($groups) ? $allGroups = $roles : (empty($roles) ? $allGroups = $groups : ($allGroups = array_merge($groups, $roles)));
                         //$allGroups = array_merge($groups, $roles);
                         break;
                     default:
                         break;
                 }
             }
             $users = "";
             $index = 0;
             if ($regexp != null && (!count($allUsers) || !empty($crtValue) && !array_key_exists(strtolower($crtValue), $allUsers)) && ConfService::getCoreConf("USER_CREATE_USERS", "conf") && !$existingOnly) {
                 $users .= "<li class='complete_user_entry_temp' data-temporary='true' data-label='{$crtValue}'><span class='user_entry_label'>{$crtValue} (" . $mess["448"] . ")</span></li>";
             } else {
                 if ($existingOnly && !empty($crtValue)) {
                     $users .= "<li class='complete_user_entry_temp' data-temporary='true' data-label='{$crtValue}' data-entry_id='{$crtValue}'><span class='user_entry_label'>{$crtValue}</span></li>";
                 }
             }
             $mess = ConfService::getMessages();
             if ($regexp == null && !$usersOnly) {
                 $users .= "<li class='complete_group_entry' data-group='AJXP_GRP_/' data-label='" . $mess["447"] . "'><span class='user_entry_label'>" . $mess["447"] . "</span></li>";
             }
             $indexGroup = 0;
             if (!$usersOnly && is_array($allGroups)) {
                 foreach ($allGroups as $groupId => $groupLabel) {
                     if ($regexp == null || preg_match("/{$regexp}/i", $groupLabel)) {
                         $users .= "<li class='complete_group_entry' data-group='{$groupId}' data-label='{$groupLabel}' data-entry_id='{$groupId}'><span class='user_entry_label'>" . $groupLabel . "</span></li>";
                         $indexGroup++;
                     }
                     if ($indexGroup == $limit) {
                         break;
                     }
                 }
             }
             if ($regexp == null && method_exists($this, "listUserTeams")) {
                 $teams = $this->listUserTeams();
                 foreach ($teams as $tId => $tData) {
                     $users .= "<li class='complete_group_entry' data-group='/AJXP_TEAM/{$tId}' data-label='[team] " . $tData["LABEL"] . "'><span class='user_entry_label'>[team] " . $tData["LABEL"] . "</span></li>";
                 }
             }
             foreach ($allUsers as $userId => $userObject) {
                 if ($userObject->getId() == $loggedUser->getId()) {
                     continue;
                 }
                 if (!$userObject->hasParent() && ConfService::getCoreConf("ALLOW_CROSSUSERS_SHARING", "conf") || $userObject->getParent() == $loggedUser->getId()) {
                     $userLabel = $userObject->personalRole->filterParameterValue("core.conf", "USER_DISPLAY_NAME", AJXP_REPO_SCOPE_ALL, $userId);
                     //if($regexp != null && ! (preg_match("/$regexp/i", $userId) || preg_match("/$regexp/i", $userLabel)) ) continue;
                     if (empty($userLabel)) {
                         $userLabel = $userId;
                     }
                     $userDisplay = $userLabel == $userId ? $userId : $userLabel . " ({$userId})";
                     if (ConfService::getCoreConf("USERS_LIST_HIDE_LOGIN", "conf") == true && $userLabel != $userId) {
                         $userDisplay = $userLabel;
                     }
                     $users .= "<li class='complete_user_entry' data-label='{$userLabel}' data-entry_id='{$userId}'><span class='user_entry_label'>" . $userDisplay . "</span></li>";
                     $index++;
                 }
                 if ($index == $limit) {
                     break;
                 }
             }
             if (strlen($users)) {
                 print "<ul>" . $users . "</ul>";
             }
             AuthService::setGroupFiltering(true);
             break;
         case "load_repository_info":
             $data = array();
             $repo = ConfService::getRepository();
             if ($repo != null) {
                 $users = AuthService::countUsersForRepository(ConfService::getRepository()->getId(), true);
                 $data["core.users"] = $users;
                 if (isset($httpVars["collect"]) && $httpVars["collect"] == "true") {
                     AJXP_Controller::applyHook("repository.load_info", array(&$data));
                 }
             }
             HTMLWriter::charsetHeader("application/json");
             echo json_encode($data);
             break;
         case "get_binary_param":
             if (isset($httpVars["tmp_file"])) {
                 $file = AJXP_Utils::getAjxpTmpDir() . "/" . AJXP_Utils::securePath($httpVars["tmp_file"]);
                 if (isset($file)) {
                     header("Content-Type:image/png");
                     readfile($file);
                 }
             } else {
                 if (isset($httpVars["binary_id"])) {
                     if (isset($httpVars["user_id"]) && AuthService::getLoggedUser() != null && AuthService::getLoggedUser()->isAdmin()) {
                         $context = array("USER" => $httpVars["user_id"]);
                     } else {
                         $context = array("USER" => AuthService::getLoggedUser()->getId());
                     }
                     $this->loadBinary($context, $httpVars["binary_id"]);
                 }
             }
             break;
         case "get_global_binary_param":
             if (isset($httpVars["tmp_file"])) {
                 $file = AJXP_Utils::getAjxpTmpDir() . "/" . AJXP_Utils::securePath($httpVars["tmp_file"]);
                 if (isset($file)) {
                     header("Content-Type:image/png");
                     readfile($file);
                 }
             } else {
                 if (isset($httpVars["binary_id"])) {
                     $this->loadBinary(array(), $httpVars["binary_id"]);
                 }
             }
             break;
         case "store_binary_temp":
             if (count($fileVars)) {
                 $keys = array_keys($fileVars);
                 $boxData = $fileVars[$keys[0]];
                 $err = AJXP_Utils::parseFileDataErrors($boxData);
                 if ($err != null) {
                 } else {
                     $rand = substr(md5(time()), 0, 6);
                     $tmp = $rand . "-" . $boxData["name"];
                     @move_uploaded_file($boxData["tmp_name"], AJXP_Utils::getAjxpTmpDir() . "/" . $tmp);
                 }
             }
             if (isset($tmp) && file_exists(AJXP_Utils::getAjxpTmpDir() . "/" . $tmp)) {
                 print '<script type="text/javascript">';
                 print 'parent.formManagerHiddenIFrameSubmission("' . $tmp . '");';
                 print '</script>';
             }
             break;
         default:
             break;
     }
     if (isset($logMessage) || isset($errorMessage)) {
         $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false);
     }
     if (isset($requireAuth)) {
         $xmlBuffer .= AJXP_XMLWriter::requireAuth(false);
     }
     return $xmlBuffer;
 }
Example #22
0
 /** Build the todo index.
  *
  * @param Doclet doclet
  */
 function todoWriter(&$doclet)
 {
     parent::HTMLWriter($doclet);
     $rootDoc =& $this->_doclet->rootDoc();
     $this->_sections[0] = array('title' => 'Overview', 'url' => 'overview-summary.html');
     $this->_sections[1] = array('title' => 'Package');
     $this->_sections[2] = array('title' => 'Class');
     //$this->_sections[3] = array('title' => 'Use');
     $this->_sections[4] = array('title' => 'Tree', 'url' => 'overview-tree.html');
     if ($doclet->includeSource()) {
         $this->_sections[5] = array('title' => 'Files', 'url' => 'overview-files.html');
     }
     $this->_sections[6] = array('title' => 'Deprecated', 'url' => 'deprecated-list.html');
     $this->_sections[7] = array('title' => 'Todo', 'selected' => TRUE);
     $this->_sections[8] = array('title' => 'Index', 'url' => 'index-all.html');
     $todoClasses = array();
     $classes =& $rootDoc->classes();
     $todoFields = array();
     $todoMethods = array();
     if ($classes) {
         foreach ($classes as $class) {
             if ($class->tags('@todo')) {
                 $todoClasses[] = $class;
             }
             $fields =& $class->fields();
             if ($fields) {
                 foreach ($fields as $field) {
                     if ($field->tags('@todo')) {
                         $todoFields[] = $field;
                     }
                 }
             }
             $classes =& $class->methods();
             if ($classes) {
                 foreach ($classes as $method) {
                     if ($method->tags('@todo')) {
                         $todoMethods[] = $method;
                     }
                 }
             }
         }
     }
     $todoGlobals = array();
     $globals =& $rootDoc->globals();
     if ($globals) {
         foreach ($globals as $global) {
             if ($global->tags('@todo')) {
                 $todoGlobals[] = $global;
             }
         }
     }
     $todoFunctions = array();
     $functions =& $rootDoc->functions();
     if ($functions) {
         foreach ($functions as $function) {
             if ($function->tags('@todo')) {
                 $todoFunctions[] = $function;
             }
         }
     }
     ob_start();
     echo "<hr>\n\n";
     echo '<h1>Todo</h1>';
     echo "<hr>\n\n";
     if ($todoClasses || $todoFields || $todoMethods || $todoGlobals || $todoFunctions) {
         echo "<h2>Contents</h2>\n";
         echo "<ul>\n";
         if ($todoClasses) {
             echo '<li><a href="#todo_class">Todo Classes</a></li>';
         }
         if ($todoFields) {
             echo '<li><a href="#todo_field">Todo Fields</a></li>';
         }
         if ($todoMethods) {
             echo '<li><a href="#todo_method">Todo Methods</a></li>';
         }
         if ($todoGlobals) {
             echo '<li><a href="#todo_global">Todo Globals</a></li>';
         }
         if ($todoFunctions) {
             echo '<li><a href="#todo_function">Todo Functions</a></li>';
         }
         echo "</ul>\n";
     }
     if ($todoClasses) {
         echo '<table id="todo_class" class="detail">', "\n";
         echo '<tr><th colspan="2" class="title">Todo Classes</th></tr>', "\n";
         foreach ($todoClasses as $class) {
             $textTag =& $class->tags('@text');
             echo '<tr><td class="name"><a href="', $class->asPath(), '">', $class->qualifiedName(), '</a></td>';
             echo '<td class="description">';
             if ($textTag) {
                 echo strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>');
             }
             echo "</td></tr>\n";
         }
         echo "</table>\n\n";
     }
     if ($todoFields) {
         echo '<table id="todo_field" class="detail">', "\n";
         echo '<tr><th colspan="2" class="title">Todo Fields</th></tr>', "\n";
         foreach ($todoFields as $field) {
             $textTag =& $field->tags('@text');
             echo "<tr>\n";
             echo '<td class="name"><a href="', $field->asPath(), '">', $field->qualifiedName(), "</a></td>\n";
             echo '<td class="description">';
             if ($textTag) {
                 echo strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>');
             }
             echo "</td>\n";
             echo "</tr>\n";
         }
         echo "</table>\n\n";
     }
     if ($todoMethods) {
         echo '<table id="todo_method" class="detail">', "\n";
         echo '<tr><th colspan="2" class="title">Todo Methods</th></tr>', "\n";
         foreach ($todoMethods as $method) {
             $textTag =& $method->tags('@text');
             echo "<tr>\n";
             echo '<td class="name"><a href="', $method->asPath(), '">', $method->qualifiedName(), "</a></td>\n";
             echo '<td class="description">';
             if ($textTag) {
                 echo strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>');
             }
             echo "</td>\n";
             echo "</tr>\n";
         }
         echo "</table>\n\n";
     }
     if ($todoGlobals) {
         echo '<table id="todo_global" class="detail">', "\n";
         echo '<tr><th colspan="2" class="title">Todo Globals</th></tr>', "\n";
         foreach ($todoGlobals as $global) {
             $textTag =& $global->tags('@text');
             echo "<tr>\n";
             echo '<td class="name"><a href="', $global->asPath(), '">', $global->qualifiedName(), "</a></td>\n";
             echo '<td class="description">';
             if ($textTag) {
                 echo strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>');
             }
             echo "</td>\n";
             echo "</tr>\n";
         }
         echo "</table>\n\n";
     }
     if ($todoFunctions) {
         echo '<table id="todo_function" class="detail">', "\n";
         echo '<tr><th colspan="2" class="title">Todo Functions</th></tr>', "\n";
         foreach ($todoFunctions as $function) {
             $textTag =& $function->tags('@text');
             echo "<tr>\n";
             echo '<td class="name"><a href="', $function->asPath(), '">', $function->qualifiedName(), "</a></td>\n";
             echo '<td class="description">';
             if ($textTag) {
                 echo strip_tags($this->_processInlineTags($textTag, TRUE), '<a><b><strong><u><em>');
             }
             echo "</td>\n";
             echo "</tr>\n";
         }
         echo "</table>\n\n";
     }
     $this->_output = ob_get_contents();
     ob_end_clean();
     $this->_write('todo-list.html', 'Todo', TRUE);
 }
 public function listTags($actionName, &$httpVars, &$fileVars)
 {
     HTMLWriter::charsetHeader("application/json");
     $tags = $this->loadTags();
     if (empty($tags)) {
         $tags = array();
     }
     echo json_encode($tags);
 }
 public function switchAction($action, $httpVars, $filesVars)
 {
     $repository = ConfService::getRepositoryById($httpVars["repository_id"]);
     if (!$repository->detectStreamWrapper(true)) {
         return false;
     }
     if (AuthService::usersEnabled()) {
         $loggedUser = AuthService::getLoggedUser();
         if ($loggedUser === null && ConfService::getCoreConf("ALLOW_GUEST_BROWSING", "auth")) {
             AuthService::logUser("guest", null);
             $loggedUser = AuthService::getLoggedUser();
         }
         if (!$loggedUser->canSwitchTo($repository->getId())) {
             echo "You do not have permissions to access this resource";
             return false;
         }
     }
     $selection = new UserSelection($repository, $httpVars);
     if ($action == "open_file") {
         $selectedNode = $selection->getUniqueNode();
         $selectedNodeUrl = $selectedNode->getUrl();
         if (!file_exists($selectedNodeUrl) || !is_readable($selectedNodeUrl)) {
             echo "File does not exist";
             return false;
         }
         $filesize = filesize($selectedNodeUrl);
         $fp = fopen($selectedNodeUrl, "rb");
         $fileMime = "application/octet-stream";
         //Get mimetype with fileinfo PECL extension
         if (class_exists("finfo")) {
             $finfo = new finfo(FILEINFO_MIME);
             $fileMime = $finfo->buffer(fread($fp, 2000));
         }
         //Get mimetype with (deprecated) mime_content_type
         if (strpos($fileMime, "application/octet-stream") === 0 && function_exists("mime_content_type")) {
             $fileMime = @mime_content_type($fp);
         }
         //Guess mimetype based on file extension
         if (strpos($fileMime, "application/octet-stream") === 0) {
             $fileExt = substr(strrchr(basename($selectedNodeUrl), '.'), 1);
             if (empty($fileExt)) {
                 $fileMime = "application/octet-stream";
             } else {
                 $regex = "/^([\\w\\+\\-\\.\\/]+)\\s+(\\w+\\s)*({$fileExt}\\s)/i";
                 $lines = file($this->getBaseDir() . "/resources/other/mime.types");
                 foreach ($lines as $line) {
                     if (substr($line, 0, 1) == '#') {
                         continue;
                     }
                     // skip comments
                     $line = rtrim($line) . " ";
                     if (!preg_match($regex, $line, $matches)) {
                         continue;
                     }
                     // no match to the extension
                     $fileMime = $matches[1];
                 }
             }
         }
         fclose($fp);
         // If still no mimetype, give up and serve application/octet-stream
         if (empty($fileMime)) {
             $fileMime = "application/octet-stream";
         }
         //Send headers
         HTMLWriter::generateInlineHeaders(basename($selectedNodeUrl), $filesize, $fileMime);
         $stream = fopen("php://output", "a");
         AJXP_MetaStreamWrapper::copyFileInStream($selectedNodeUrl, $stream);
         fflush($stream);
         fclose($stream);
         AJXP_Controller::applyHook("node.read", array($selectedNode));
         $this->logInfo('Download', 'Read content of ' . $selectedNodeUrl, array("files" => $selectedNodeUrl));
     }
 }
Example #25
0
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                echo "\n\nNo change detected reflecting file deletion, this is not normal, exiting.";
                var_dump($data);
                exit;
            }
        } else {
            echo "\n\nData not decoded as JSON, normal?";
            var_dump($data);
            exit;
        }
        echo "<script>window.scrollTo(0, 100000);</script>";
        //echo "</pre>";
    } else {
        $host = $_SERVER["HTTP_HOST"];
        $protocol = $_SERVER["HTTPS"] === "on" ? "https" : "http";
        $path = dirname($_SERVER["REQUEST_URI"]);
        HTMLWriter::charsetHeader();
        require AJXP_TESTS_FOLDER . "/api_test.phtml";
    }
} else {
    $outputArray = array();
    $testedParams = array();
    $passed = true;
    $passed = AJXP_Utils::runTests($outputArray, $testedParams);
    AJXP_Utils::testResultsToTable($outputArray, $testedParams, true);
    AJXP_Utils::testResultsToFile($outputArray, $testedParams);
}
 /**
  * @param String $actionName
  * @param Array $httpVars
  * @param Array $fileVars
  */
 public function switchActions($actionName, $httpVars, $fileVars)
 {
     $userSelection = new UserSelection($this->accessDriver->repository, $httpVars);
     $uniqNode = $userSelection->getUniqueNode();
     $feedStore = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("feed");
     $existingFeed = $uniqNode->retrieveMetadata(AJXP_META_SPACE_COMMENTS, false);
     if ($existingFeed == null) {
         $existingFeed = array();
     }
     $mess = ConfService::getMessages();
     switch ($actionName) {
         case "post_comment":
             $uId = AuthService::getLoggedUser()->getId();
             $limit = $this->getFilteredOption("COMMENT_SIZE_LIMIT");
             if (!empty($limit)) {
                 $content = substr(AJXP_Utils::decodeSecureMagic($httpVars["content"]), 0, $limit);
             } else {
                 $content = AJXP_Utils::decodeSecureMagic($httpVars["content"]);
             }
             $com = array("date" => time(), "author" => $uId, "content" => $content);
             $existingFeed[] = $com;
             if ($feedStore !== false) {
                 $feedStore->persistMetaObject($uniqNode->getPath(), base64_encode($content), $uniqNode->getRepositoryId(), $uniqNode->getRepository()->securityScope(), $uniqNode->getRepository()->getOwner(), AuthService::getLoggedUser()->getId(), AuthService::getLoggedUser()->getGroupPath());
             } else {
                 $uniqNode->removeMetadata(AJXP_META_SPACE_COMMENTS, false);
                 $uniqNode->setMetadata(AJXP_META_SPACE_COMMENTS, $existingFeed, false);
             }
             HTMLWriter::charsetHeader("application/json");
             $com["hdate"] = AJXP_Utils::relativeDate($com["date"], $mess);
             $com["path"] = $uniqNode->getPath();
             echo json_encode($com);
             break;
         case "load_comments_feed":
             HTMLWriter::charsetHeader("application/json");
             if ($feedStore !== false) {
                 $sortBy = isset($httpVars["sort_by"]) ? AJXP_Utils::decodeSecureMagic($httpVars["sort_by"]) : "date";
                 $sortDir = isset($httpVars["sort_dir"]) ? AJXP_Utils::decodeSecureMagic($httpVars["sort_dir"]) : "asc";
                 $offset = isset($httpVars["offset"]) ? intval($httpVars["offset"]) : 0;
                 $limit = isset($httpVars["limit"]) ? intval($httpVars["limit"]) : 100;
                 $uniqNode->loadNodeInfo();
                 $data = $feedStore->findMetaObjectsByIndexPath($this->accessDriver->repository->getId(), $uniqNode->getPath(), AuthService::getLoggedUser()->getId(), AuthService::getLoggedUser()->getGroupPath(), $offset, $limit, $sortBy, $sortDir, !$uniqNode->isLeaf());
                 $theFeed = array();
                 foreach ($data as $stdObject) {
                     $rPath = substr($stdObject->path, strlen($uniqNode->getPath()));
                     if ($rPath == false && $stdObject->path == $uniqNode->getPath()) {
                         $rPath = "";
                     }
                     $rPath = ltrim($rPath, "/");
                     $newItem = array("date" => $stdObject->date, "hdate" => AJXP_Utils::relativeDate($stdObject->date, $mess), "author" => $stdObject->author, "content" => base64_decode($stdObject->content), "path" => $stdObject->path, "rpath" => $rPath, "uuid" => $stdObject->uuid);
                     if (isset($previous) && $previous["author"] == $newItem["author"] && $previous["path"] == $newItem["path"] && $previous["hdate"] == $newItem["hdate"]) {
                         $theFeed[count($theFeed) - 1]["content"] .= '<br>' . $newItem["content"];
                     } else {
                         $theFeed[] = $newItem;
                     }
                     $previous = $newItem;
                 }
                 echo json_encode($theFeed);
             } else {
                 foreach ($existingFeed as &$item) {
                     $item["hdate"] = AJXP_Utils::relativeDate($item["date"], $mess);
                 }
                 echo json_encode($existingFeed);
             }
             break;
         case "delete_comment":
             $data = json_decode($httpVars["comment_data"], true);
             if ($feedStore === false) {
                 $reFeed = array();
                 if ($data["author"] != AuthService::getLoggedUser()->getId()) {
                     break;
                 }
                 foreach ($existingFeed as $fElement) {
                     if ($fElement["date"] == $data["date"] && $fElement["author"] == $data["author"] && $fElement["content"] == $data["content"]) {
                         continue;
                     }
                     $fElement["hdate"] = AJXP_Utils::relativeDate($fElement["date"], $mess);
                     $reFeed[] = $fElement;
                 }
                 $uniqNode->removeMetadata(AJXP_META_SPACE_COMMENTS, false);
                 $uniqNode->setMetadata(AJXP_META_SPACE_COMMENTS, $reFeed, false);
                 HTMLWriter::charsetHeader("application/json");
                 echo json_encode($reFeed);
             } else {
                 $feedStore->dismissAlertById($data["uuid"], 1);
             }
             break;
         default:
             break;
     }
 }
 public function extractExif($actionName, $httpVars, $fileVars)
 {
     $repo = $this->accessDriver->repository;
     $userSelection = new UserSelection($this->accessDriver->repository, $httpVars);
     $repo->detectStreamWrapper(true);
     $selectedNode = $userSelection->getUniqueNode();
     $realFile = AJXP_MetaStreamWrapper::getRealFSReference($selectedNode->getUrl());
     AJXP_Utils::safeIniSet('exif.encode_unicode', 'UTF-8');
     $exifData = @exif_read_data($realFile, 0, TRUE);
     if ($exifData === false || !is_array($exifData)) {
         return;
     }
     if ($exifData !== false && isset($exifData["GPS"])) {
         $exifData["COMPUTED_GPS"] = $this->convertGPSData($exifData);
     }
     $iptc = $this->extractIPTC($realFile);
     if (count($iptc)) {
         $exifData["IPTC"] = $iptc;
     }
     $excludeTags = array();
     // array("componentsconfiguration", "filesource", "scenetype", "makernote", "datadump");
     $format = "xml";
     if (isset($httpVars["format"]) && $httpVars["format"] == "json") {
         $format = "json";
     }
     $filteredData = array();
     foreach ($exifData as $section => $data) {
         $filteredData[$section] = array();
         foreach ($data as $key => $value) {
             if (is_array($value)) {
                 $value = implode(",", $value);
             }
             if (in_array(strtolower($key), $excludeTags)) {
                 continue;
             }
             if (strpos($key, "UndefinedTag:") === 0) {
                 continue;
             }
             $value = preg_replace('/[^[:print:]]/', '', $value);
             $filteredData[$section][$key] = SystemTextEncoding::toUTF8($value);
         }
     }
     if ($format == "xml") {
         AJXP_XMLWriter::header("metadata", array("file" => $selectedNode->getPath(), "type" => "EXIF"));
         foreach ($filteredData as $section => $data) {
             print "<exifSection name='{$section}'>";
             foreach ($data as $key => $value) {
                 print "<exifTag name=\"{$key}\">" . AJXP_Utils::xmlEntities($value) . "</exifTag>";
             }
             print "</exifSection>";
         }
         AJXP_XMLWriter::close("metadata");
     } else {
         HTMLWriter::charsetHeader("application/json");
         echo json_encode($filteredData);
     }
 }
 public function switchAction($actionName, $httpVars, $fileVars)
 {
     $this->baseURL = rtrim($this->getFilteredOption("ETHERPAD_SERVER"), "/");
     $this->apiKey = $this->getFilteredOption("ETHERPAD_APIKEY");
     $userSelection = new UserSelection(ConfService::getRepository(), $httpVars);
     if ($userSelection->isEmpty()) {
         throw new Exception("Empty selection");
     }
     $repository = ConfService::getRepository();
     if (!$repository->detectStreamWrapper(false)) {
         return false;
     }
     $selectedNode = $userSelection->getUniqueNode();
     $selectedNode->loadNodeInfo();
     if (!$selectedNode->isLeaf()) {
         throw new Exception("Cannot handle folders, please select a file!");
     }
     $nodeExtension = strtolower(pathinfo($selectedNode->getPath(), PATHINFO_EXTENSION));
     // Determine pad ID
     if ($nodeExtension == "pad") {
         $padID = file_get_contents($selectedNode->getUrl());
     } else {
         // TRY TO LOAD PAD ID FROM NODE SHARED METADATA
         $metadata = $selectedNode->retrieveMetadata("etherpad", AJXP_METADATA_ALLUSERS, AJXP_METADATA_SCOPE_GLOBAL, false);
         if (isset($metadata["pad_id"])) {
             $padID = $metadata["pad_id"];
         } else {
             $padID = AJXP_Utils::generateRandomString();
             $selectedNode->setMetadata("etherpad", array("pad_id" => $padID), AJXP_METADATA_ALLUSERS, AJXP_METADATA_SCOPE_GLOBAL, false);
         }
     }
     require_once "etherpad-client/etherpad-lite-client.php";
     $client = new EtherpadLiteClient($this->apiKey, $this->baseURL . "/api");
     $loggedUser = AuthService::getLoggedUser();
     $userName = $loggedUser->getId();
     $userLabel = $loggedUser->mergedRole->filterParameterValue("core.conf", "USER_DISPLAY_NAME", AJXP_REPO_SCOPE_ALL, $userName);
     $res = $client->createAuthorIfNotExistsFor($userName, $userLabel);
     $authorID = $res->authorID;
     $res2 = $client->createGroupIfNotExistsFor($loggedUser->getGroupPath());
     $groupID = $res2->groupID;
     $fullId = $groupID . "\$" . $padID;
     if ($actionName == "etherpad_create") {
         $resP = $client->listPads($groupID);
         $currentContent = file_get_contents($selectedNode->getUrl());
         if ($nodeExtension == "html" && strpos($currentContent, "<html>") === false) {
             $currentContent = "<html><head></head><body>{$currentContent}</body></html>";
         }
         if (!in_array($fullId, $resP->padIDs)) {
             $client->createGroupPad($groupID, $padID, null);
             if ($nodeExtension == "html" && !empty($currentContent)) {
                 $client->setHTML($fullId, $currentContent);
             } else {
                 if ($nodeExtension != "pad") {
                     $client->setText($fullId, $currentContent);
                 }
             }
         } else {
             if ($nodeExtension != "pad") {
                 // If someone is already connected, do not override.
                 $existingAuthors = $client->listAuthorsOfPad($fullId);
                 if (!count($existingAuthors->authorIDs)) {
                     if ($nodeExtension == "html" && !empty($currentContent)) {
                         $client->setHTML($fullId, $currentContent);
                     } else {
                         $client->setText($fullId, $currentContent);
                     }
                 }
             }
         }
         $res4 = $client->createSession($groupID, $authorID, time() + 14400);
         $sessionID = $res4->sessionID;
         setcookie('sessionID', $sessionID, null, "/");
         $padID = $groupID . '$' . $padID;
         $data = array("url" => $this->baseURL . "/p/" . $padID, "padID" => $padID, "sessionID" => $sessionID);
         HTMLWriter::charsetHeader('application/json');
         echo json_encode($data);
     } else {
         if ($actionName == "etherpad_save") {
             $padID = $httpVars["pad_id"];
             if ($nodeExtension == "html" || $nodeExtension == "pad") {
                 $res = $client->getHTML($padID);
                 $content = $res->html;
             } else {
                 $res = $client->getText($padID);
                 $content = $res->text;
             }
             if ($nodeExtension == "pad") {
                 // Create a new file and save the content in it.
                 $origUrl = $selectedNode->getUrl();
                 $mess = ConfService::getMessages();
                 $dateStamp = date(" Y-m-d H:i", time());
                 $startUrl = preg_replace('"\\.pad$"', $dateStamp . '.html', $origUrl);
                 $newNode = new AJXP_Node($startUrl);
                 AJXP_Controller::applyHook("node.before_create", array($newNode, strlen($content)));
                 file_put_contents($newNode->getUrl(), $content);
                 AJXP_Controller::applyHook("node.change", array(null, $newNode));
             } else {
                 AJXP_Controller::applyHook("node.before_change", array($selectedNode, strlen($content)));
                 file_put_contents($selectedNode->getUrl(), $content);
                 clearstatcache(true, $selectedNode->getUrl());
                 $selectedNode->loadNodeInfo(true);
                 AJXP_Controller::applyHook("node.change", array($selectedNode, $selectedNode));
             }
         } else {
             if ($actionName == "etherpad_close") {
                 // WE SHOULD DETECT IF THERE IS NOBODY CONNECTED ANYMORE, AND DELETE THE PAD.
                 // BUT SEEMS LIKE THERE'S NO WAY TO PROPERLY REMOVE AN AUTHOR VIA API
                 $sessionID = $httpVars["session_id"];
                 $client->deleteSession($sessionID);
             } else {
                 if ($actionName == "etherpad_proxy_api") {
                     if ($httpVars["api_action"] == "list_pads") {
                         $res = $client->listPads($groupID);
                     } else {
                         if ($httpVars["api_action"] == "list_authors_for_pad") {
                             $res = $client->listAuthorsOfPad($httpVars["pad_id"]);
                         }
                     }
                     HTMLWriter::charsetHeader("application/json");
                     echo json_encode($res);
                 } else {
                     if ($actionName == "etherpad_get_content") {
                         HTMLWriter::charsetHeader("text/plain");
                         echo $client->getText($httpVars["pad_id"])->text;
                     }
                 }
             }
         }
     }
     return null;
 }
 public function switchActions($actionName, $httpVars, $fileVars)
 {
     if ($actionName != "changes" || !isset($httpVars["seq_id"])) {
         return false;
     }
     if (!dibi::isConnected()) {
         dibi::connect($this->sqlDriver);
     }
     $filter = null;
     $masks = array();
     $currentRepo = $this->accessDriver->repository;
     AJXP_Controller::applyHook("role.masks", array($currentRepo->getId(), &$masks, AJXP_Permission::READ));
     $recycle = $currentRepo->getOption("RECYCLE_BIN");
     $recycle = !empty($recycle) ? $recycle : false;
     if ($this->options["OBSERVE_STORAGE_CHANGES"] === true) {
         // Do it every XX minutes
         $minutes = 5;
         if (isset($this->options["OBSERVE_STORAGE_EVERY"])) {
             $minutes = intval($this->options["OBSERVE_STORAGE_EVERY"]);
         }
         $file = $this->getResyncTimestampFile();
         $last = 0;
         if (is_file($file)) {
             $last = intval(file_get_contents($file));
         }
         if (time() - $last > $minutes * 60) {
             $this->resyncAction("resync_storage", array(), array());
         }
     }
     if ($this->options["REQUIRES_INDEXATION"]) {
         if (ConfService::backgroundActionsSupported()) {
             AJXP_Controller::applyActionInBackground(ConfService::getRepository()->getId(), "index", array());
         } else {
             AJXP_Controller::findActionAndApply("index", array(), array());
         }
         // Unset the REQUIRES_INDEXATION FLAG
         $meta = $currentRepo->getOption("META_SOURCES");
         unset($meta["meta.syncable"]["REQUIRES_INDEXATION"]);
         $currentRepo->addOption("META_SOURCES", $meta);
         ConfService::replaceRepository($currentRepo->getId(), $currentRepo);
     }
     HTMLWriter::charsetHeader('application/json', 'UTF-8');
     $stream = isset($httpVars["stream"]);
     $separator = $stream ? "\n" : ",";
     $veryLastSeq = intval(dibi::query("SELECT MAX([seq]) FROM [ajxp_changes]")->fetchSingle());
     $seqId = intval(AJXP_Utils::sanitize($httpVars["seq_id"], AJXP_SANITIZE_ALPHANUM));
     if ($veryLastSeq > 0 && $seqId > $veryLastSeq) {
         // This is not normal! Send a signal reload all changes from start.
         if (!$stream) {
             echo json_encode(array('changes' => array(), 'last_seq' => 1));
         } else {
             echo 'LAST_SEQ:1';
         }
         return null;
     }
     $ands = array();
     $ands[] = array("[ajxp_changes].[repository_identifier] = %s", $this->computeIdentifier($currentRepo));
     $ands[] = array("[seq] > %i", $seqId);
     if (isset($httpVars["filter"])) {
         $filter = AJXP_Utils::decodeSecureMagic($httpVars["filter"]);
         $filterLike = rtrim($filter, "/") . "/";
         $ands[] = array("[source] LIKE %like~ OR [target] LIKE %like~", $filterLike, $filterLike);
     }
     if (count($masks)) {
         $ors = array();
         foreach ($masks as $mask) {
             $filterLike = rtrim($mask, "/") . "/";
             $ors[] = array("[source] LIKE %like~ OR [target] LIKE %like~", $filterLike, $filterLike);
         }
         if (count($ors)) {
             $ands[] = array("%or", $ors);
         }
     }
     $res = dibi::query("SELECT\n            [seq] , [ajxp_changes].[repository_identifier] , [ajxp_changes].[node_id] , [type] , [source] ,  [target] , [ajxp_index].[bytesize], [ajxp_index].[md5], [ajxp_index].[mtime], [ajxp_index].[node_path]\n            FROM [ajxp_changes]\n            LEFT JOIN [ajxp_index]\n                ON [ajxp_changes].[node_id] = [ajxp_index].[node_id]\n            WHERE %and\n            ORDER BY [ajxp_changes].[node_id], [seq] ASC", $ands);
     if (!$stream) {
         echo '{"changes":[';
     }
     $previousNodeId = -1;
     $previousRow = null;
     $order = array("path" => 0, "content" => 1, "create" => 2, "delete" => 3);
     $relocateAttrs = array("bytesize", "md5", "mtime", "node_path", "repository_identifier");
     $valuesSent = false;
     foreach ($res as $row) {
         $row->node = array();
         foreach ($relocateAttrs as $att) {
             $row->node[$att] = $row->{$att};
             unset($row->{$att});
         }
         if (!empty($recycle)) {
             $this->cancelRecycleNodes($row, $recycle);
         }
         if (!isset($httpVars["flatten"]) || $httpVars["flatten"] == "false") {
             if (!$this->filterMasks($row, $masks) && !$this->filterRow($row, $filter)) {
                 if ($valuesSent) {
                     echo $separator;
                 }
                 echo json_encode($row);
                 $valuesSent = true;
             }
         } else {
             if ($row->node_id == $previousNodeId) {
                 $previousRow->target = $row->target;
                 $previousRow->seq = $row->seq;
                 if ($order[$row->type] > $order[$previousRow->type]) {
                     $previousRow->type = $row->type;
                 }
             } else {
                 if (isset($previousRow) && ($previousRow->source != $previousRow->target || $previousRow->type == "content")) {
                     if ($this->filterMasks($previousRow, $masks) || $this->filterRow($previousRow, $filter)) {
                         $previousRow = $row;
                         $previousNodeId = $row->node_id;
                         $lastSeq = $row->seq;
                         continue;
                     }
                     if ($valuesSent) {
                         echo $separator;
                     }
                     echo json_encode($previousRow);
                     $valuesSent = true;
                 }
                 $previousRow = $row;
                 $previousNodeId = $row->node_id;
             }
             $lastSeq = $row->seq;
             flush();
         }
         //CODES HERE HAVE BEEN MOVE OUT OF THE LOOP
     }
     /**********RETURN TO SENDER************/
     // is 'not NULL' included in isSet()?
     if ($previousRow && isset($previousRow) && ($previousRow->source != $previousRow->target || $previousRow->type == "content") && !$this->filterRow($previousRow, $filter)) {
         if ($valuesSent) {
             echo $separator;
         }
         echo json_encode($previousRow);
         if ($previousRow->seq > $lastSeq) {
             $lastSeq = $previousRow->seq;
         }
         $valuesSent = true;
     }
     /*************************************/
     if (isset($lastSeq)) {
         if ($stream) {
             echo "\nLAST_SEQ:" . $lastSeq;
         } else {
             echo '], "last_seq":' . $lastSeq . '}';
         }
     } else {
         $lastSeq = dibi::query("SELECT MAX([seq]) FROM [ajxp_changes]")->fetchSingle();
         if (empty($lastSeq)) {
             $lastSeq = 1;
         }
         if ($stream) {
             echo "\nLAST_SEQ:" . $lastSeq;
         } else {
             echo '], "last_seq":' . $lastSeq . '}';
         }
     }
     return null;
 }
 public function handleTasks($action, $httpVars, $fileVars)
 {
     $tasks = AJXP_Utils::loadSerialFile($this->getDbFile(), false, "json");
     switch ($action) {
         case "scheduler_addTask":
             if (isset($httpVars["task_id"])) {
                 foreach ($tasks as $index => $task) {
                     if ($task["task_id"] == $httpVars["task_id"]) {
                         $data = $task;
                         $theIndex = $index;
                     }
                 }
             }
             if (!isset($theIndex)) {
                 $data = array();
                 $data["task_id"] = substr(md5(time()), 0, 16);
             }
             $data["label"] = $httpVars["label"];
             $data["schedule"] = $httpVars["schedule"];
             $data["action_name"] = $httpVars["action_name"];
             $data["repository_id"] = $httpVars["repository_id"];
             $i = 1;
             while (array_key_exists("repository_id_" . $i, $httpVars)) {
                 $data["repository_id"] .= "," . $httpVars["repository_id_" . $i];
                 $i++;
             }
             $data["user_id"] = $httpVars["user_id"];
             $data["PARAMS"] = array();
             if (!empty($httpVars["param_name"]) && !empty($httpVars["param_value"])) {
                 $data["PARAMS"][$httpVars["param_name"]] = $httpVars["param_value"];
             }
             foreach ($httpVars as $key => $value) {
                 if (preg_match('/^param_name_/', $key)) {
                     $paramIndex = str_replace("param_name_", "", $key);
                     if (preg_match('/ajxptype/', $paramIndex)) {
                         continue;
                     }
                     if (preg_match('/replication/', $paramIndex)) {
                         continue;
                     }
                     if (isset($httpVars["param_value_" . $paramIndex])) {
                         $data["PARAMS"][$value] = $httpVars["param_value_" . $paramIndex];
                     }
                 }
             }
             if (isset($theIndex)) {
                 $tasks[$theIndex] = $data;
             } else {
                 $tasks[] = $data;
             }
             AJXP_Utils::saveSerialFile($this->getDbFile(), $tasks, true, false, "json");
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage("Successfully added/edited task", null);
             AJXP_XMLWriter::reloadDataNode();
             AJXP_XMLWriter::close();
             break;
         case "scheduler_removeTask":
             $this->removeTask($httpVars["task_id"]);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage("Successfully removed task", null);
             AJXP_XMLWriter::reloadDataNode();
             AJXP_XMLWriter::close();
             break;
         case "scheduler_loadTask":
             $found = false;
             foreach ($tasks as $task) {
                 if ($task["task_id"] == $httpVars["task_id"]) {
                     $index = 0;
                     $found = true;
                     foreach ($task["PARAMS"] as $pName => $pValue) {
                         if ($index == 0) {
                             $task["param_name"] = $pName;
                             $task["param_value"] = $pValue;
                         } else {
                             $task["param_name_" . $index] = $pName;
                             $task["param_value_" . $index] = $pValue;
                         }
                         $index++;
                     }
                     unset($task["PARAMS"]);
                     if (strpos($task["repository_id"], ",") !== false) {
                         $ids = explode(",", $task["repository_id"]);
                         $task["repository_id"] = $ids[0];
                         for ($i = 1; $i < count($ids); $i++) {
                             $task["repository_id_" . $i] = $ids[$i];
                         }
                     }
                     break;
                 }
             }
             if ($found) {
                 HTMLWriter::charsetHeader("application/json");
                 echo json_encode($task);
             }
             break;
         default:
             break;
     }
     //var_dump($tasks);
 }