cvs: phpdoc /scripts/online_editor README.txt base.php cvslist.php cvsupdate.txt editxml.php index.php intro.php login.php viewvc-style.css
workbench.php /scripts/online_editor/images dir.png loading.gif notyet.png r2.png r3.png r4.png r5.png r6.png text.png unknown.png up2date.png
| From: | Salah Faya | Date: | Tue, 06 May 2008 11:43:48 +0000 |
| Subject: | cvs: phpdoc /scripts/online_editor README.txt base.php cvslist.php cvsupdate.txt editxml.php index.php intro.php login.php viewvc-style.css workbench.php /scripts/online_editor/images dir.png loading.gif notyet.png r2.png r3.png r4.png r5.png r6.png text.png unknown.png up2date.png |
||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-1605@lists.php.net to get a copy of this message | ||
visualmind Tue May 6 11:43:48 2008 UTC
Added files:
/phpdoc/scripts/online_editor README.txt base.php cvslist.php
cvsupdate.txt editxml.php index.php
intro.php login.php viewvc-style.css
workbench.php
/phpdoc/scripts/online_editor/images dir.png loading.gif notyet.png
r2.png r3.png r4.png r5.png
r6.png text.png unknown.png
up2date.png
Log:
First version of the Online Editor tool, reference to http://news.php.net/php.doc/969378843 and following
discussion
http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/README.txt?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/README.txt +++ phpdoc/scripts/online_editor/README.txt ============================================================================= Developed by Salah Faya visualmind(@)php.net Version 1.0 - essentially developed for Arabic Translation of PHP Manual Now updated to work with all phpdoc translations ============================================================================= This tool can be used to edit phpdoc files online. Installation requires to have it placed accessable through web. It also requires to have a cvs checkout of the phpdoc (both English and the desired language). Then edit the base.php to adjust settings and you are ready to go. CVS Update must be performed manually, same goes for cvsupdate.txt A running version can be tested online at www.php4arab.info/phpmanual/translation/editor/ ============================================================================= http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/base.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/base.php +++ phpdoc/scripts/online_editor/base.php <?php //*-- The PHPDOC Online XML Editing Tool //*-- Developed by Salah Faya visualmind(@)php.net //*-- Version 1.0 - essentially developed for Arabic Translation of PHP Manual //*-- Now updated to work with all phpdoc translations //--- base file (all other files require this to start) //------- Configuration // Root path of cvs $cvsRootPath = '/path/to/cvs/'; // Path to english xml sources from cvs $enDocCVSPath = $cvsRootPath.'phpdoc/en/'; // Require User Login by email (needed for user file saving) $requireLogin = false; if ($requireLogin) { // Users folder where their cached files are saved - must be writable $usersCachePath = '/path/to/editor/users/'; // Files Permissions Mod $filesChMod = 0777; } // Languages and paths: addLanguage('Arabic', $cvsRootPath.'phpdoc-ar/ar/', 'ar', 'utf-8', 'RTL', 'doc-ar@lists.php.net', 'doc-ar-subscribe@lists.php.net', 'Salah Faya visualmind(@)php.net'); addLanguage('Chinese-Simplified', $cvsRootPath.'phpdoc-zh/zh/', 'zh', 'gb2312', 'LTR', 'doc-zh@lists.php.net', 'doc-zh-subscribe@lists.php.net', ''); addLanguage('Chinese-Traditional', $cvsRootPath.'phpdoc-tw/tw/', 'tw', 'big5', 'LTR', 'doc-tw@lists.php.net', 'doc-tw-subscribe@lists.php.net', ''); addLanguage('Czech', $cvsRootPath.'phpdoc-cs/cs/', 'cs', 'iso-8859-2', 'LTR', 'doc-cs@lists.php.net', 'doc-cs-subscribe@lists.php.net', ''); addLanguage('French', $cvsRootPath.'phpdoc-fr/fr/', 'fr', 'iso-8859-1', 'LTR', 'doc-fr@lists.php.net', 'doc-fr-subscribe@lists.php.net', ''); addLanguage('Germany', $cvsRootPath.'phpdoc-de/de/', 'de', 'utf-8', 'LTR', 'doc-de@lists.php.net', 'doc-de-subscribe@lists.php.net', ''); //.. // Hide files (ignore) $ignoreListingFolders = array('.', '..', 'CVS'); $ignoreListingFiles = array('contributors.xml', 'contributors.ent', 'livedocs.ent'); //------- Base functions function addLanguage($lang, $cvspath, $id, $charset='utf-8', $direction='LTR', $mailing='', $mailsubscribe='', $coodinator='', $font='Fixedsys') { global $phpdocLangs; $phpdocLangs[$lang]['DocCVSPath'] = $cvspath; $phpdocLangs[$lang]['charset'] = $charset; $phpdocLangs[$lang]['direction'] = $direction; $phpdocLangs[$lang]['id'] = $id; $phpdocLangs[$lang]['mailing'] = $mailing; $phpdocLangs[$lang]['mailingSubscribe'] = $mailsubscribe; $phpdocLangs[$lang]['coordinator'] = $coordinator; $phpdocLangs[$lang]['font'] = $font; } function sessionCheck($arguments='') { session_start(); if (!isset($_SESSION['user'])) { if ($_SERVER['REQUEST_METHOD']=='GET') { $_SESSION['redo'] = $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']; } header('location: login.php'.$arguments); exit('<a href="login.php">Login first</a>'); } return $_SESSION['user']; } function getDateTimeToLog() { return date('d/m H:i [').time().']'; } function getUserIP() { return $_SERVER['REMOTE_ADDR']; } function getCacheName($filename) { // change reference/ext/file.xml to reference~ext~file.xml $filename = str_replace(array('/', '\\'), '~', $filename); return $filename; } function stripslashes2($text) { if (get_magic_quotes_gpc()) { $text = stripslashes($text); } return $text; } function getRevision($file, $en=false) { $f = fopen($file, "rb"); $data = fread($f, 200); fclose($f); // Use en-revision if ($en) { preg_match("#<!-- *EN-Revision: +([0-9\.]+)#i", $data, $result); $rev = $result[1]; } else { preg_match("#<!-- *\\$"."Revision: +([0-9\.]+)#i", $data, $result); $rev = $result[1]; } return $rev; } function getTranslationStatus($file) { global $user, $phpdocLangs, $enDocCVSPath; $lang = $user['phpdocLang']; $translationPath = $phpdocLangs[$lang]['DocCVSPath']; $trFile = $translationPath.$file; $enFile = $enDocCVSPath.$file; $status['lastEnRevision'] = getRevision($enFile); if (file_exists($trFile)) { $status['translated'] = true; $status['fileRevision'] = getRevision($trFile); $status['fileEnRevision'] = getRevision($trFile, true); if ($status['fileEnRevision'] && $status['lastEnRevision']) { $distance = round((float) $status['lastEnRevision'], 3) - round((float) $status['fileEnRevision'], 3) ; $backward = 0; if ($distance<0) { $backward = -1; } elseif ($distance && $distance<.03) { $backward = 1; } elseif ($distance && $distance<.2) { $backward = 2; } elseif ($distance && $distance<.4) { $backward = 3; } elseif ($distance && $distance<.6) { $backward = 4; } elseif ($distance && $distance>=.6) { $backward = 5; } $status['backward'] = $backward; $status['distance'] = $distance; } } else { $status['translated'] = false; } return $status; } ?> http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/cvslist.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/cvslist.php +++ phpdoc/scripts/online_editor/cvslist.php <?php //*-- The PHPDOC Online XML Editing Tool //*-- Developed by Salah Faya visualmind(@)php.net //*-- Version 1.0 - essentially developed for Arabic Translation of PHP Manual //*-- Now updated to work with all phpdoc translations //--- This file lists the folders and files in the left frame //------- Initialization require 'base.php'; $user = sessionCheck(); $lang = $user['phpdocLang']; $translationPath = $phpdocLangs[$lang]['DocCVSPath']; //------- Folder navigation vars $path = ''; $file = ''; if (isset($_REQUEST['path'])) { $path = $_REQUEST['path']; if (isset($_REQUEST['file'])) { $file = $_REQUEST['file']; } } // Prevent wrong paths if (strstr($path, '.') || $file=='..' || $file=='.') { exit; } // Path Slashes if (!$path) $path = '/'; if (substr($path, -1)!='/') $path .= '/'; // Usually, the path are based on english cvs $target = "$enDocCVSPath$path$file"; //------- Decide what to do // If file is selected, redirect to the editor.. if ($file) { // Find in user path first (editing cached file by default) $ffile = $user['cache'].getCacheName($path.$file); if (file_exists($ffile)) { header("location: editxml.php?file=$path$file&source=upath"); exit; } // Find in translated path (edit the translated file) $ffile = "$translationPath$path$file"; if (file_exists($ffile)) { header("location: editxml.php?file=$path$file&source=apath"); exit; } // So it's a new file? Use the english source if (file_exists($target)) { header("location: editxml.php?file=$path$file&source=epath"); exit; } } else { // No file selected, Listing (from english cvs) $d = opendir($target); while($f = readdir($d)) { if (is_dir($target.$f)) { if (in_array($f, $ignoreListingFolders)) continue; $dirs[] = $f; } elseif ((substr($f, -4)=='.xml' || substr($f, -4)=='.ent') && !in_array($f, $ignoreListingFiles)) { $files[] = $f; } } } //------- Functions function printPathAsLinks($path) { global $lang; $px = explode('/', $path); foreach($px as $i=>$p) { $pp .= $p.'/'; if (!$p && !$i) $p = $lang; print "<a href='?path=$pp'>$p</a>"; if ($p || !$i) print '/'; } print '<br>'; } function printDirectories($dirs, $path) { sort($dirs); foreach($dirs as $dir) { print "<a href='?path=$path$dir'><img src='images/dir.png' width=16 height=16 border=0 align=absmiddle> $dir</a> <br>"; } } function printFiles($files, $path) { global $translationPath, $user; sort($files); foreach($files as $fl) { $status = getTranslationStatus($path.$fl); if ($status['translated']) { if ($status['fileEnRevision'] && $status['lastEnRevision'] && $status['distance']>=0) { if (!$status['backward']) { $title = 'Up to date'; $img = 'images/up2date.png'; } else { $title = 'Outdated '.$status['fileEnRevision'].' / '.$status['lastEnRevision']; $img = 'images/r'.($status['backward']+1).'.png'; } } else { $title = 'EN-Revision is incorrect or missing'; $img = 'images/unknown.png'; } } else { $title = 'Not translated yet'; $img = 'images/notyet.png'; } print "<a href='?path=$path&file=$fl' target=fileframe><img src='images/text.png' width=16 height=16 border=0 align=absmiddle> $fl</a> <img src='$img' border=0 align=absmiddle alt='$title'><br>"; } // Lists the user's cached files if (file_exists($user['cache']."files.txt")) { print '<hr>'; print 'Cached files:<br>'; $ff = file($user['cache']."files.txt"); foreach($ff as $f) { $fx = explode('|', $f); if (!isset($cf[$fx[2]])) { print "<a href='editxml.php?file=$fx[2]&source=upath' target=fileframe>$fx[2]</a><br>"; $cf[$fx[2]] = true; } } } } //------- Output ?> <html> <body bgcolor="#FFFFFF"> <style type="text/css"> body { font-family: Tahoma; font-size: 12px; } a:link { text-decoration: none; color: #000066; } a:hover { text-decoration: none; color: #ff0000; } a:active { text-decoration: none; color: #ff0000; } a:visited { text-decoration: none; color: #000066; } </style> <div style="width: 400px;"> Listing: <?php printPathAsLinks($path); printDirectories($dirs, $path); printFiles($files, $path); ?> <hr> <form action=login.php method=post target=_top> <?php if ($requireLogin) { ?> <input type=hidden name=email value="<?php print $user['email']; ?>"><br> <?php } ?> Switch language:<br> <select name=lang onchange="if (this.value) this.form.submit();"> <option value=''></option> <?php foreach($phpdocLangs as $lng=>$langInfo) { if ($lng==$lang) $sel = " selected"; else $sel = ''; print "<option value='$lng'$sel>$lng</option>"; } ?> </select> </form> </div> </body> </html> http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/cvsupdate.txt?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/cvsupdate.txt +++ phpdoc/scripts/online_editor/cvsupdate.txt [Last CVS Update time] http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/editxml.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/editxml.php +++ phpdoc/scripts/online_editor/editxml.php <?php //*-- The PHPDOC Online XML Editing Tool //*-- Developed by Salah Faya visualmind(@)php.net //*-- Version 1.0 - essentially developed for Arabic Translation of PHP Manual //*-- Now updated to work with all phpdoc translations //--- This is the actual xml editor //------- Initialization require 'base.php'; $user = sessionCheck('?from=editxml'); $lang = $user['phpdocLang']; $translationPath = $phpdocLangs[$lang]['DocCVSPath']; //------- Frames split if (isset($_REQUEST['split'])) { if ($_REQUEST['split']=='false' || !$_REQUEST['split']) $_REQUEST['split'] = false; $_SESSION['split'] = $_REQUEST['split']; } if ($_SESSION['split'] && !isset($_REQUEST['noframes'])) { $source = $_REQUEST['source']; $file = $_REQUEST['file']; // ToDo automatically show the translated file in one frame and the source in another print "<frameset cols=*,*><frame name=frame1 src='editxml.php?file=$file&source=$source&noframes=1'><frame name=frame2 src='editxml.php?file=$file&source=$source&noframes=1'></frameset>"; exit; } //------- File Request if (isset($_REQUEST['source']) && isset($_REQUEST['file'])) { $source = $_REQUEST['source']; $file = $_REQUEST['file']; } if (!$file || strstr($file, '..')) { exit; } $requestedFilename = $file; // Turn on/off XML as Text if ($_REQUEST['textedit'] && $_REQUEST['textedit']!='false') { $_SESSION['textedit'] = true; } elseif ($_REQUEST['textedit']=='false') { $_SESSION['textedit'] = false; } // Turn on/off Hiding XML tags when editing if ($_REQUEST['hidexml'] && $_REQUEST['hidexml']!='false') { $_SESSION['hidexml'] = true; } elseif ($_REQUEST['hidexml']=='false') { $_SESSION['hidexml'] = false; } // Turn on/off Line By Line if ($_REQUEST['par'] && $_REQUEST['par']!='false') { $_SESSION['para'] = false; } elseif ($_REQUEST['par']=='false') { $_SESSION['para'] = true; } //------- Functions // Parse XML to find editable text // this function is written poorly but it does the job function myParse($text) { $results = array(); $rc = 0; for($i=0; $i<strlen($text); $i++) { $c = substr($text, $i, 1); if ($c=='<') { // Starting tag $tagC = ''; $tag = true; } if ($tag) { $tagC .= $c; } else { if ($c=="\n") { // Advance the counter so each line is stored separately if (!$_SESSION['para']) { $rc++; } else { if (!isset($results[$rc])) { // Get position of New editable text $results[$rc] = array('index'=>$i, 'text'=>''); } $results[$rc]['text'] .= $c; } } else { if (!isset($results[$rc])) { // Get position of New editable text $results[$rc] = array('index'=>$i, 'text'=>''); } $results[$rc]['text'] .= $c; } } if ($c=='>') { // Tag ending $tagC .= $c; $tag = false; $rc++; } } // Filter editable text $resultsx = array(); foreach($results as $resline) { $res = trim($resline['text']); // Skip empty, &xx; and literals if (!$res || ($res[0]=='&' && substr($res,-1)==';') || isLiteral($res) ) continue; if ($_SESSION['para']) { // trim \n and adjust position while(substr($resline['text'], 0, 1)=="\n" || substr($resline['text'], 0, 1)=="\r") { $resline['index']++; $resline['text'] = substr($resline['text'], 1); } // recheck \n if (!strstr($resline['text'], "\n")) { // treat as one line (trim and adjust) while(substr($resline['text'], 0, 1)==' ') { $resline['index']++; $resline['text'] = substr($resline['text'], 1); } $resline['text'] = trim($resline['text']); } $res = $resline['text']; } else { // trim and adjust position while(substr($resline['text'], 0, 1)==' ') { $resline['index']++; $resline['text'] = substr($resline['text'], 1); } $res = trim($resline['text']); } $resultsx[$resline['index']] = $res; } // Return an array contains all editable texts and their positions in file contents return $resultsx; } function isLiteral($text) { // ToDo check if text is literal and don't need to be translated return false; } //------- Locate file according to the selected path $status = getTranslationStatus($file); switch($source) { case 'upath': // User cached path $file = $user['cache'].getCacheName($file); break; case 'apath': // File from translation $file = $translationPath.$file; break; case 'epath': // English source $file = $enDocCVSPath.$file; break; case 'diff': // cvs diff if ($status['distance']>0) { $url = "http://cvs.php.net/viewvc.cgi/phpdoc/en/$file?r1=$status[fileEnRevision]&r2=$status[lastEnRevision]"; $html = implode('', file($url)); preg_match_all("#(<table cellspacing=\"0\" cellpadding=\"0\">\\s*<tr class=\"vc_diff_header\">.+</table>)#s", $html, $parts); $data = '<meta name="generator" content="ViewVC 1.1-dev" /><link rel="stylesheet" href="viewvc-style.css" type="text/css" /><div style="font-family: Arial;">'; $data .= str_replace('/viewvc.cgi/', 'http://cvs.php.net/viewvc.cgi/', $parts[1][0]).'</div>'; } break; } //------- Prepare the file for editing if ($source!='diff'): // Read the file contents $data = implode('', file($file)); if (!$_SESSION['textedit']) { // Protect CDATA tags by hiding them before parsing preg_match_all("#<\!\[CDATA\[(.+)\]\]>#Us", $data, $matches); $cdataStore = array(); $cdataMarks = array(); foreach($matches[0] as $i=>$cdata) { $mark = "<CDATA-$i-></CDATA>"; $cdl = strlen($cdata)-strlen($mark); $mark = "<CDATA-$i-".str_repeat('X', $cdl).'></CDATA>'; $cdataStore[$i] = $cdata; $cdataMarks[$i] = $mark; $data = str_replace($cdata, $mark, $data); } // Parse file contents and fetch editable text $results = myParse($data); // Keep a copy of the actual contents $newdata = $data; // Replace editable text with special Marks $results = array_reverse($results, true); foreach($results as $index=>$text) { $newtext = $text; // If in saving process Put submitted text instead of current text if (isset($_POST['textAt'][$index])) { $newtext = stripslashes2($_POST['textAt'][$index]); // Fix paragraphs that lost prefix \n if (strstr($newtext, "\n") && substr($newtext, 0, 1)!="\n") { //$newtext = "\n$newtext"; } $results[$index] = $newtext; $newdata = substr_replace($newdata, $newtext, $index, strlen($text)); $updated = true; } // Put special marks if ($newtext!="'>" && $newtext!='">') { if (strstr($newtext, "\n")) { // This marks text that has new line (so we will use multiline textarea) $data = substr_replace($data, "_PMRK[$index]\{$newtext}PMRK_", $index, strlen($text)); } elseif (strstr($newtext, "'") && !strstr($newtext, '"')) { // This marks text that has single quote (so the input field will use double quote) $data = substr_replace($data, "_ZMRK[$index]\{$newtext}ZMRK_", $index, strlen($text)); } elseif (strstr($newtext, "'") && strstr($newtext, '"')) { // This marks text that has single and double quote (so we will use textarea) $data = substr_replace($data, "_YMRK[$index]\{$newtext}YMRK_", $index, strlen($text)); } else { // This marks text that can use a normal input $data = substr_replace($data, "_XMRK[$index]\{$newtext}XMRK_", $index, strlen($text)); } } } if ($_SESSION['para'] && $updated) { // Remove \r (some browsers) $newdata = str_replace("\r\n", "\r", $newdata); $newdata = str_replace("\n", "\r", $newdata); $newdata = str_replace("\r", "\n", $newdata); if (substr($newdata, -1)!="\n") { $newdata .= "\n"; } } // Put CData back $data = str_replace($cdataMarks, $cdataStore, $data); $newdata = str_replace($cdataMarks, $cdataStore, $newdata); } else { // Edit XML as Text if (isset($_POST['xmldata'])) { $newdata = stripslashes2($_POST['xmldata']); // Remove \r (some browsers) $newdata = str_replace("\r\n", "\r", $newdata); $newdata = str_replace("\n", "\r", $newdata); $newdata = str_replace("\r", "\n", $newdata); if (substr($newdata, -1)!="\n") { $newdata .= "\n"; } $updated = true; } } //------- Save or Send file when requested if ($updated || $_REQUEST['download']) { // Charset for new translated files if ($phpdocLangs[$lang]['charset']!='iso-8859-1') { $charset = $phpdocLangs[$lang]['charset']; $newdata = str_replace('<?xml version="1.0" encoding="iso-8859-1"?>', '<?xml version="1.0" encoding="'.$charset.'"?>', $newdata); } // EN-Revision for new translated files if (!stristr($newdata, 'EN-Revision:')) { $newdata = str_replace('<!-- $Revision: 1.1 $Revision: 1.1 $ -->\n<!-- EN-Revision: ", $newdata); } // Send file as is (download) if (isset($_REQUEST['download'])) { header('Content-Type: application/download'); header('Content-Disposition: attachment; filename='.basename($requestedFilename)); print $newdata; exit; } if ($requireLogin) { // Save file in user cache folder $f = fopen($user['cache'].getCacheName($requestedFilename), 'w'); fputs($f, $newdata); fclose($f); // Simple log $f = fopen($user['cache']."files.txt", 'a'); $time = getDateTimeToLog(); $ip = getUserIP(); fputs($f, "$time|$ip|$requestedFilename\r\n"); fclose($f); } exit("File has been saved in your cache folder. You can now <a href='editxml.php?file=$requestedFilename&source=$source&download=yes&noframes=1'>download it</a> or edit another file"); } if (!$_SESSION['textedit']) { // Mark XML Tags to be hidden (when hidexml is true) $hideXMLTag = $_SESSION['hidexml']; if ($hideXMLTag) { $startXMLTag = '_TMRK('; $endXMLTag = ')TMRK_'; } // Replace special marks with <input> or <textarea> $data = htmlspecialchars($data); $data = preg_replace("#_XMRK\[(\\d+)\]\{(.+)\}XMRK_#U", "$endXMLTag<input type=text class=xinput ondblclick='dblclk(this)' onmouseover='irn(\\1)' onmouseout='iro(\\1)' onkeyup='ku(\\1, event)' onkeydown='kp(\\1, event)' name=textAt[\\1] value='\\2'>$startXMLTag", $data); $data = preg_replace("#_YMRK\[(\\d+)\]\{(.+)\}YMRK_#U", "$endXMLTag<textarea rows=1 class=xinput ondblclick='dblclk(this)' onmouseover='irn(\\1)' onmouseout='iro(\\1)' onkeyup='ku(\\1, event)' onkeydown='kp(\\1, event)' name=textAt[\\1]>\\2</textarea>$startXMLTag", $data); $data = preg_replace("#_ZMRK\[(\\d+)\]\{(.+)\}ZMRK_#U", "$endXMLTag<input type=text class=xinput ondblclick='dblclk(this)' onmouseover='irn(\\1)' onmouseout='iro(\\1)' onkeyup='ku(\\1, event)' onkeydown='kp(\\1, event)' name=textAt[\\1] value=\"\\2\">$startXMLTag", $data); $data = preg_replace("#_PMRK\[(\\d+)\]\{(.+)\}PMRK_#Us", "$endXMLTag<br><textarea name=textAt[\\1] class=xinput2 ondblclick='dblclk(this)' onmouseover='irn(\\1)' onmouseout='iro(\\1)' style='width: 80%;'>\\2</textarea><br>$startXMLTag", $data); $data = $startXMLTag.$data.$endXMLTag; // Update input size according to text length foreach($results as $index=>$text) { if (!strstr($text, "\n")) { $size = strlen(utf8_decode($text)); $data = str_replace("textAt[$index]", "textAt[$index] size=$size cols=$size", $data); } else { $size = substr_count($text, "\n")+1; $data = str_replace("<textarea name=textAt[$index]", "<textarea name=textAt[$index] rows=$size", $data); } } // Hide XML Tags if ($hideXMLTag) { preg_match_all("#_TMRK\((.+)\)TMRK_#Us", $data, $matches); foreach($matches[0] as $i=>$line) { $r = ' '; if (strstr($line, "\n")) { $r = "\n"; if (substr_count($line, "\n")>3) { $r.="\n"; } } $data = str_replace($line, $r, $data); } } } endif; //------- Output ?> <html> <meta http-equiv="Content-Type" content="text/html; charset=<?php print $phpdocLangs[$lang]['charset']; ?>" /> <body bgcolor="#9999cc"> <style type="text/css"> body { font-family: Tahoma; font-size: 12px; } .xinput { font-family: <?php print $phpdocLangs[$lang]['font']; ?>; border: 0px none; color: #AA0000; border-bottom: 1px dotted gray; } .xinput2 { font-family: <?php print $phpdocLangs[$lang]['font']; ?>; color: #AA0000;; } .editbox { font-family: <?php print $phpdocLangs[$lang]['font']; ?>; color: #006600; background-color: white; border: 3px groove; width: 100%; height: 400px; overflow: auto; } .editbox-diff { font-family: <?php print $phpdocLangs[$lang]['font']; ?>; color: #006600; background-color: white; border: 3px groove; width: 100%; height: 550px; overflow: auto; } a:link { text-decoration: none; color: #000066; } a:hover { text-decoration: none; color: #ff0000; } a:active { text-decoration: none; color: #ff0000; } a:visited { text-decoration: none; color: #000066; } </style> <script language=javascript> // Highlight input on mouse over function irn(i) { var ob = document.getElementById('textAt['+i+']'); ob.style.backgroundColor = '#EEEEEE'; } // un-Highlight input on mouse over function iro(i) { var ob = document.getElementById('textAt['+i+']'); ob.style.backgroundColor = '#FFFFFF'; } var updated = false; // Switch between fields when using arrow keys and translate selection by PgdDown key function kp(i, e) { var ev= (window.event)? window.event: e; if(!ev || !ev.type) return false; var k,w; if (ev.keyCode) w=1; if (ev.charCode) w=2; if (ev.which) w=3; k = (ev.keyCode)?ev.keyCode: ((ev.charCode)? ev.charCode: ev.which); if (k==34) { // PageDown to translate dblclk(document.getElementById('textAt['+i+']')); if (w==1) e.keyCode = 0; if (w==2) e.charCode = 0; if (w==3) e.which = 0; return false; } if (k==40 || k==38) { if (w==1) e.keyCode = 9; if (w==2) e.charCode = 9; if (w==3) e.which = 9; } return true; } // Update input/textarea size when editing function ku(i, e) { updated = true; var ob = document.getElementById('textAt['+i+']'); var l = ob.value.length; if (l) { ob.size = l; ob.cols = l; } } // Translate using google API on double click function dblclk(obj) { // translate(obj); var selection = new Selection(obj); var s = selection.create(); if (s.end) { var ln = s.end - s.start; var word = obj.value.substr(s.start, ln); translate(obj, word, s.start, s.end); } } // Right To Left and Left To Right function rtl(button) { if (button.value == 'RTL') { button.value = 'LTR'; document.getElementById('editbox').dir = 'rtl'; } else { button.value = 'RTL'; document.getElementById('editbox').dir = 'ltr'; } } // Prevent Losing changes function uconfirm() { if (updated) { return confirm('This will cancel any unsaved updates, are you sure?'); } return true; } // Show hidden frame function showhframe() { document.getElementById('hframe').style.display = ''; } //------------- The following are required for Google translation // Cross Browser selectionStart/selectionEnd // Version 0.2 // Copyright (c) 2005-2007 KOSEKI Kengo // // This script is distributed under the MIT licence. // http://www.opensource.org/licenses/mit-license.php function Selection(textareaElement) { this.element = textareaElement; } Selection.prototype.create = function() { if (document.selection != null && this.element.selectionStart == null) { return this._ieGetSelection(); } else { return this._mozillaGetSelection(); } } Selection.prototype._mozillaGetSelection = function() { return { start: this.element.selectionStart, end: this.element.selectionEnd }; } Selection.prototype._ieGetSelection = function() { this.element.focus(); var range = document.selection.createRange(); var bookmark = range.getBookmark(); var contents = this.element.value; var originalContents = contents; var marker = this._createSelectionMarker(); while(contents.indexOf(marker) != -1) { marker = this._createSelectionMarker(); } var parent = range.parentElement(); if (parent == null ) { return { start: 0, end: 0 }; } range.text = marker + range.text + marker; contents = this.element.value; var result = {}; result.start = contents.indexOf(marker); contents = contents.replace(marker, ""); result.end = contents.indexOf(marker); this.element.value = originalContents; range.moveToBookmark(bookmark); range.select(); return result; } Selection.prototype._createSelectionMarker = function() { return "##SELECTION_MARKER_" + Math.random() + "##"; } //------------ </script> <script type="text/javascript" src="http://www.google.com/jsapi"></script><script type="text/javascript"> //-- Google Translation API google.load("language", "1"); var transTarget = new Array(); function translate(obj, word, s, e) { if (!word) return; if (obj.name!='xmldata') { obj.style.backgroundColor = '#22EE99'; } transTarget[0] = obj; transTarget[1] = word; transTarget[2] = s; transTarget[3] = e; google.language.translate(word, "en", "<?php print $phpdocLangs[$lang]['id']; ?>", function(result) { if (!result.error) { //var container = document.getElementById("translation"); var w = transTarget[0].value; var w1 = ''; if (transTarget[2]) { w1 = w.substr(0, transTarget[2]); } var w2 = w.substr(transTarget[2]+word.length); if (word.substr(word.length-1)==' ') w2 = ' '+w2; if (word.substr(0, 1)==' ') w1 = w1 + ' '; transTarget[0].value = w1+result.translation+w2; var l = transTarget[0].value.length; if (l) { transTarget[0].size = l; transTarget[0].cols = l; } updated = true; }}); } </script> File: <b><?php print $requestedFilename; ?></b><br> Source: <b><font color=white><?php if ($source=='upath') print "User cached version"; if ($source=='apath') print "$lang Translated version"; if ($source=='epath') print "English version"; ?></font></b><br> <?php if ($requireLogin) { print "Logged as: <b>$user[email]</b> <a href='login.php?and=logout' target=_top>logout</a><br>"; } $url = "editxml.php?file=$requestedFilename&source=$source"; if ($_SESSION['hidexml']) $hideXML = 'checked'; else $hideXML = ''; if ($_SESSION['split']) $splitFrames = 'checked'; else $splitFrames = ''; if ($_SESSION['textedit']) $textEdit = 'checked'; else $textEdit = ''; if ($_SESSION['para']) $lineByLine = ''; else $lineByLine = 'checked'; ?> <input type=checkbox name=hidexml value=1 <?php print $hideXML; ?> onClick="if (uconfirm()) document.location='<?php print $url; ?>&noframes=1&hidexml='+this.checked;" <?php if ($source=='diff') print 'disabled'; ?> /> Hide XML Tags <input type=checkbox name=split value=1 <?php print $splitFrames; ?> onClick="if (uconfirm()) top.frames['fileframe'].location='<?php print $url; ?>&split='+this.checked;"> Split frames <input type=checkbox name=textedit value=1 <?php print $textEdit; ?> onClick="if (uconfirm()) document.location='<?php print $url; ?>&noframes=1&textedit='+this.checked;" <?php if ($source=='diff') print 'disabled'; ?> /> XML Text Editor <input type=checkbox name=linebyline value=1 <?php print $lineByLine; ?> onClick="if (uconfirm()) document.location = '<?php print $url; ?>&noframes=1&par='+this.checked;" <?php if ($source=='diff') print 'disabled'; ?> /> Line by Line (no textarea) <form action=editxml.php method=post target=hframe onsubmit="showhframe();"> <?php $bs[0] = array('bcolor'=>'#CCCCCC', 'caption'=>'Latest English', 'link'=>"editxml.php?file=$requestedFilename&source=epath&noframes=1", 'tag'=>'epath', 'title'=>$status['lastEnRevision']); $bs[1] = array('bcolor'=>'#CCCCCC', 'caption'=>$lang.' version', 'link'=>"editxml.php?file=$requestedFilename&source=apath&noframes=1", 'tag'=>'apath', 'title'=>$status['fileEnRevision']); if ($requireLogin) { $bs[] = array('bcolor'=>'#CCCCCC', 'caption'=>'Cached version', 'link'=>"editxml.php?file=$requestedFilename&source=upath&noframes=1", 'tag'=>'upath'); } if ($status['distance']>0) { $bs[] = array('bcolor'=>'#CCCCCC', 'caption'=>'Diff log '.$status['fileEnRevision'].' / '.$status['lastEnRevision'], 'link'=>"editxml.php?file=$requestedFilename&source=diff&noframes=1", 'tag'=>'diff'); } foreach($bs as $i=>$b) { if ($b['tag']==$source) $b['bcolor'] = '#FFFFFF'; print "<span style='background-color: $b[bcolor]; border: 1px solid black; border-bottom: 0px none white;'><a href='$b[link]' onclick='return uconfirm();' title='$b[title]'>$b[caption]</a>"; print '</span>'; if (($i+1)<count($bs)) print '|'; } $direction = "LTR"; $directionx = "RTL"; if ($phpdocLangs[$lang]['direction']=='RTL' && ($source=='upath' || $source=='apath')) { $direction = "RTL"; $directionx = "LTR"; } if (!$_SESSION['textedit'] || $source=='diff') { ?> <div id=editbox dir=<?php print $direction; ?> class="editbox<?php if ($source=='diff') print '-diff'; ?>"> <center><img id=loading src=images/loading.gif align=absmiddle></center> <pre><?php print $data; ?></pre> </div> <?php } else { // Edit XML as Text ?> <center><img id=loading src=images/loading.gif align=absmiddle><div> <textarea name=xmldata id=editbox ondblclick="dblclk(this);" dir=<?php print $direction; ?> style="font-family: Fixedsys; background-color: white; width: 100%; height: 400px;"><?php print $data; ?></textarea></div> </center> <?php } if ($source!='diff') { ?> <input name=noframes type=hidden value=1> <input name=source type=hidden value="<?php print $source; ?>"> <input name=file type=hidden value="<?php print $requestedFilename; ?>"> <input type=button value=<?php print $directionx;?> onclick="rtl(this);"> <?php if ($requireLogin) print '<input name=save type=submit value="Save in cache">'; ?> <input name=download type=submit value=Download> </form> <!-- This frame is used to prevent losing changes if session has expired.. so login can be done inside --> <iframe id=hframe name=hframe width=100% height=100 border=0 style="display: none"></iframe> * Before working on translating this file, please make sure to send an email to <?php print $phpdocLangs[$lang]['mailing']; ?> indicating that you will translate this file, and wait for confirmation. <br> * After translating the file, please download it then: either cvs it -or- send it to <?php print $phpdocLangs[$lang]['mailing']; ?>. <b>Always remember to keep a copy of the file on your local computer</b><br> * If you have questions, contact the translation coordinator <?php print $phpdocLangs[$lang]['coordinator']; ?><br> <?php } ?> <script language=javascript> document.getElementById('loading').style.display = 'none'; </script> </body> </html> http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/index.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/index.php +++ phpdoc/scripts/online_editor/index.php <?php require 'login.php'; ?> http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/intro.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/intro.php +++ phpdoc/scripts/online_editor/intro.php <?php //*-- The PHPDOC Online XML Editing Tool //*-- Developed by Salah Faya visualmind(@)php.net //*-- Version 1.0 - essentially developed for Arabic Translation of PHP Manual //*-- Now updated to work with all phpdoc translations //--- Just an introduction // ToDo show summary of translated files (or revcheck) require 'base.php'; $user = sessionCheck(); $lang = $user['phpdocLang']; ?> <html> <body style="font-family: Tahoma; font-size: 12px;"> <h2> The PHPDOC Online XML Editing Tool </h2> Developed by Salah Faya visualmind(@)php.net<br> Version 1.0 - essentially developed for Arabic Translation of PHP Manual<br> Now updated to work with all phpdoc translations<br> <br> <b>Last CVS Update: <?php print implode('', file('cvsupdate.txt')); ?></b> <br><br> The language you are editing is <b><?php print $lang; ?></b><br> Translation coordinator: <b><?php print $phpdocLangs[$lang]['coordinator'] ?></b><br> Mailing list: <b><?php print $phpdocLangs[$lang]['mailing'] ?></b>. For Subscription email to <b><?php print $phpdocLangs[$lang]['mailingSubscribe'] ?></b><br><br> Charset used: <b><?php print $phpdocLangs[$lang]['charset'] ?></b><br> <?php // Lists the user's cached files if (file_exists($user['cache']."files.txt")) { print '<hr>'; print 'Your Cached files:<br>'; $ff = file($user['cache']."files.txt"); foreach($ff as $f) { $fx = explode('|', $f); if (!isset($cf[$fx[2]])) { print "<a href='editxml.php?file=$fx[2]&source=upath' target=fileframe>$fx[2]</a><br>"; $cf[$fx[2]] = true; } } } ?> </body> </html> http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/login.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/login.php +++ phpdoc/scripts/online_editor/login.php <?php //*-- The PHPDOC Online XML Editing Tool //*-- Developed by Salah Faya visualmind(@)php.net //*-- Version 1.0 - essentially developed for Arabic Translation of PHP Manual //*-- Now updated to work with all phpdoc translations //--- This file allows users to login using an email address (TODO we may use CVS or other way in future) //------- Initialization require 'base.php'; session_start(); // Logout &and=logout if (isset($_GET['and'])) { session_unregister('user'); unset($_SESSION['user']); } //------- Login request if (isset($_POST['lang'])) { if (isset($_POST['email'])) { $email = $_POST['email']; } $lang = $_POST['lang']; // Check selected language if (!isset($phpdocLangs[$lang])) { exit('Sorry, you have choosen an incorrect language'); } if ($requireLogin) { // Simple email validation -- ToDo some enhancements $email = trim(strtolower($email)); $p1 = preg_match("#^([a-z0-9][a-z0-9_\.]*)@[a-z0-9][a-z0-9\-]+\.[a-z]{2,6}$#", $email); $p2 = preg_match("#^([a-z0-9][a-z0-9_\.]*)@[a-z0-9][a-z0-9\-]+\.[a-z]{2,3}\.[a-z]{2}$#", $email); if (!$p1 && !$p2) { exit('That was not a valid email address'); } // This validation is required because emails are used as user folder name -- ToDO use another way if (strlen($email)>50) { exit('That was not a valid email address'); } // Do Login (create user folder) if (!file_exists($usersCachePath.$email)) { @mkdir($usersCachePath.$email, $filesChMod); } } if (is_dir($usersCachePath.$email) || !$requireLogin) { // Session setup session_register('user'); $_SESSION['user'] = array('email'=>$email, 'cache'=>$usersCachePath.$email.'/', 'phpdocLang'=>$lang); // If expired session, redo last request if ($_SESSION['redo']) { $link = $_SESSION['redo']; $_SESSION['redo'] = false; header("location: $link"); exit; } // If accidently lost session while editing if ($_REQUEST['from']=='editxml') { exit('Ok, Login is <b>successful</b>. Now retry your previous request'); } // Redirect to frameset header('location: workbench.php'); exit('<a href="workbench.php">Moved to workbench.php</a>'); } else { // If folder has not been created exit('Sorry, there was an internal error. Please contact administration'); } } //------- Login form ?> <html> <body style="font-family: Tahoma; font-size: 12px;"> <h3> The PHPDOC Online XML Editing Tool :: Login first</h3> <form action=login.php method=post> <input type=hidden name=from value="<?php print $_REQUEST['from']; ?>"> <?php if ($requireLogin) { ?> Your email address (must be valid) <input type=text name=email><br> <?php } ?> Translating PHPDOC to <select name=lang><?php foreach($phpdocLangs as $lang=>$langInfo) { print "<option value='$lang'>$lang</option>"; } ?> </select>* <input type=submit value=Login> </form> Developed by Salah Faya visualmind(@)php.net<br> Version 1.0 - essentially developed for Arabic Translation of PHP Manual<br> Now updated to work with all phpdoc translations. <br> This is a special tool to be used only by PHPDOC translators.<br> Javascript and cookies must be enabled in your browser settings.<br> <br> <b>Last CVS Update: <?php print implode('', file('cvsupdate.txt')); ?></b> </body> </html> http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/viewvc-style.css?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/viewvc-style.css +++ phpdoc/scripts/online_editor/viewvc-style.css /*******************************/ /*** ViewVC CSS Stylesheet ***/ /*******************************/ /*** Standard Tags ***/ img { border: none; } table { width: 100%; margin: 0; border: none; } table.auto { width: auto; } table.fixed { width: 100%; table-layout: fixed; } table.fixed td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } tr, td, th { vertical-align: top; } form { margin: 0; } /*** Icons ***/..vc_icon { width: 16px; height: 16px; border: none; padding: 0 1px; } /*** Navigation Headers ***/..vc_navheader { background-color: #cccccc; } /*** Table Headers ***/..vc_header { text-align: left; vertical-align: top; background-color: #cccccc; }..vc_header_sort { text-align: left; background-color: #88ff88; } /*** Table Rows ***/..vc_row_even { background-color: #ffffff; }..vc_row_odd { background-color: #efefff; } /*** Log messages ***/..vc_log { /* unfortunately, white-space: pre-wrap isn't widely supported ... */ white-space: -moz-pre-wrap; /* Mozilla based browsers */ white-space: -pre-wrap; /* Opera 4 - 6 */ white-space: -o-pre-wrap; /* Opera >= 7 */ white-space: pre-wrap; /* CSS3 */ word-wrap: break-word; /* IE 5.5+ */ } /*** Markup Summary Header ***/..vc_summary { background-color: #eeeeee; } /*** Highlight Markup Styles ***/ #vc_markup .num { color:#000000; } #vc_markup .esc { color:#bd8d8b; } #vc_markup .str { color:#bd8d8b; } #vc_markup .dstr { color:#bd8d8b; } #vc_markup .slc { color:#ac2020; font-style:italic; } #vc_markup .com { color:#ac2020; font-style:italic; } #vc_markup .dir { color:#000000; } #vc_markup .sym { color:#000000; } #vc_markup .line { color:#555555; } #vc_markup .kwa { color:#9c20ee; font-weight:bold; } #vc_markup .kwb { color:#208920; } #vc_markup .kwc { color:#0000ff; } #vc_markup .kwd { color:#000000; } /*** Line numbers outputted by highlight colorizer ***/..line { border-right-width: 1px; border-right-style: solid; border-right-color: #505050; padding: 1px; background-color: #eeeeee; color: #505050; text-decoration: none; font-weight: normal; font-style: normal; } /*** Diff Styles ***/..vc_diff_header { background-color: #ffffff; }..vc_diff_chunk_header { background-color: #99cccc; }..vc_diff_chunk_extra { font-size: smaller; }..vc_diff_empty { background-color: #cccccc; font-family: sans-serif; font-size: smaller; }..vc_diff_add { background-color: #aaffaa; font-family: sans-serif; font-size: smaller; }..vc_diff_remove { background-color: #ffaaaa; font-family: sans-serif; font-size: smaller; }..vc_diff_change { background-color: #ffff77; font-family: sans-serif; font-size: smaller; }..vc_diff_change_empty { background-color: #eeee77; font-family: sans-serif; font-size: smaller; }..vc_diff_nochange { font-family: sans-serif; font-size: smaller; }..vc_raw_diff { background-color: #cccccc; font-size: smaller; } /*** Intraline Diff Styles ***/ ..vc_idiff_add { background-color: #aaffaa; }..vc_idiff_change { background-color:#ffff77; }..vc_idiff_remove { background-color:#ffaaaa; }..vc_idiff_empty { background-color:#e0e0e0; } table.vc_idiff col.content { width: 50%; } table.vc_idiff tbody { font-family: monospace; /* unfortunately, white-space: pre-wrap isn't widely supported ... */ white-space: -moz-pre-wrap; /* Mozilla based browsers */ white-space: -pre-wrap; /* Opera 4 - 6 */ white-space: -o-pre-wrap; /* Opera >= 7 */ white-space: pre-wrap; /* CSS3 */ word-wrap: break-word; /* IE 5.5+ */ } table.vc_idiff tbody th { background-color:#e0e0e0; text-align:right; } /*** Annotate Styles ***/..vc_blame_line, .vc_blame_author, .vc_blame_rev { font-family: monospace; font-size: 1em; color: #666666; text-align: right; white-space: nowrap; padding-right: 0.5em; } ..vc_blame_rev { border-right: solid 1px black; } ..vc_blame_text { font-family: monospace; font-size: 1.2em; text-align: left; white-space: pre; width: 100%; padding-left: 0.5em; background-color: #ffffff; } /*** Query Form ***/..vc_query_form { background-color: #e6e6e6; } http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/workbench.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/workbench.php +++ phpdoc/scripts/online_editor/workbench.php <?php //*-- The PHPDOC Online XML Editing Tool //*-- Developed by Salah Faya visualmind(@)php.net //*-- Version 1.0 - essentially developed for Arabic Translation of PHP Manual //*-- Now updated to work with all phpdoc translations //--- This file is the frameset require 'base.php'; $user = sessionCheck(); ?> <frameset cols="200,*"> <frame name=listingframe src=cvslist.php> <frame name=fileframe src=intro.php> </frameset>
http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/README.txt?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/README.txt +++ phpdoc/scripts/online_editor/README.txt ============================================================================= Developed by Salah Faya visualmind(@)php.net Version 1.0 - essentially developed for Arabic Translation of PHP Manual Now updated to work with all phpdoc translations ============================================================================= This tool can be used to edit phpdoc files online. Installation requires to have it placed accessable through web. It also requires to have a cvs checkout of the phpdoc (both English and the desired language). Then edit the base.php to adjust settings and you are ready to go. CVS Update must be performed manually, same goes for cvsupdate.txt A running version can be tested online at www.php4arab.info/phpmanual/translation/editor/ ============================================================================= http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/base.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/base.php +++ phpdoc/scripts/online_editor/base.php <?php //*-- The PHPDOC Online XML Editing Tool //*-- Developed by Salah Faya visualmind(@)php.net //*-- Version 1.0 - essentially developed for Arabic Translation of PHP Manual //*-- Now updated to work with all phpdoc translations //--- base file (all other files require this to start) //------- Configuration // Root path of cvs $cvsRootPath = '/path/to/cvs/'; // Path to english xml sources from cvs $enDocCVSPath = $cvsRootPath.'phpdoc/en/'; // Require User Login by email (needed for user file saving) $requireLogin = false; if ($requireLogin) { // Users folder where their cached files are saved - must be writable $usersCachePath = '/path/to/editor/users/'; // Files Permissions Mod $filesChMod = 0777; } // Languages and paths: addLanguage('Arabic', $cvsRootPath.'phpdoc-ar/ar/', 'ar', 'utf-8', 'RTL', 'doc-ar@lists.php.net', 'doc-ar-subscribe@lists.php.net', 'Salah Faya visualmind(@)php.net'); addLanguage('Chinese-Simplified', $cvsRootPath.'phpdoc-zh/zh/', 'zh', 'gb2312', 'LTR', 'doc-zh@lists.php.net', 'doc-zh-subscribe@lists.php.net', ''); addLanguage('Chinese-Traditional', $cvsRootPath.'phpdoc-tw/tw/', 'tw', 'big5', 'LTR', 'doc-tw@lists.php.net', 'doc-tw-subscribe@lists.php.net', ''); addLanguage('Czech', $cvsRootPath.'phpdoc-cs/cs/', 'cs', 'iso-8859-2', 'LTR', 'doc-cs@lists.php.net', 'doc-cs-subscribe@lists.php.net', ''); addLanguage('French', $cvsRootPath.'phpdoc-fr/fr/', 'fr', 'iso-8859-1', 'LTR', 'doc-fr@lists.php.net', 'doc-fr-subscribe@lists.php.net', ''); addLanguage('Germany', $cvsRootPath.'phpdoc-de/de/', 'de', 'utf-8', 'LTR', 'doc-de@lists.php.net', 'doc-de-subscribe@lists.php.net', ''); //.. // Hide files (ignore) $ignoreListingFolders = array('.', '..', 'CVS'); $ignoreListingFiles = array('contributors.xml', 'contributors.ent', 'livedocs.ent'); //------- Base functions function addLanguage($lang, $cvspath, $id, $charset='utf-8', $direction='LTR', $mailing='', $mailsubscribe='', $coodinator='', $font='Fixedsys') { global $phpdocLangs; $phpdocLangs[$lang]['DocCVSPath'] = $cvspath; $phpdocLangs[$lang]['charset'] = $charset; $phpdocLangs[$lang]['direction'] = $direction; $phpdocLangs[$lang]['id'] = $id; $phpdocLangs[$lang]['mailing'] = $mailing; $phpdocLangs[$lang]['mailingSubscribe'] = $mailsubscribe; $phpdocLangs[$lang]['coordinator'] = $coordinator; $phpdocLangs[$lang]['font'] = $font; } function sessionCheck($arguments='') { session_start(); if (!isset($_SESSION['user'])) { if ($_SERVER['REQUEST_METHOD']=='GET') { $_SESSION['redo'] = $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']; } header('location: login.php'.$arguments); exit('<a href="login.php">Login first</a>'); } return $_SESSION['user']; } function getDateTimeToLog() { return date('d/m H:i [').time().']'; } function getUserIP() { return $_SERVER['REMOTE_ADDR']; } function getCacheName($filename) { // change reference/ext/file.xml to reference~ext~file.xml $filename = str_replace(array('/', '\\'), '~', $filename); return $filename; } function stripslashes2($text) { if (get_magic_quotes_gpc()) { $text = stripslashes($text); } return $text; } function getRevision($file, $en=false) { $f = fopen($file, "rb"); $data = fread($f, 200); fclose($f); // Use en-revision if ($en) { preg_match("#<!-- *EN-Revision: +([0-9\.]+)#i", $data, $result); $rev = $result[1]; } else { preg_match("#<!-- *\\$"."Revision: +([0-9\.]+)#i", $data, $result); $rev = $result[1]; } return $rev; } function getTranslationStatus($file) { global $user, $phpdocLangs, $enDocCVSPath; $lang = $user['phpdocLang']; $translationPath = $phpdocLangs[$lang]['DocCVSPath']; $trFile = $translationPath.$file; $enFile = $enDocCVSPath.$file; $status['lastEnRevision'] = getRevision($enFile); if (file_exists($trFile)) { $status['translated'] = true; $status['fileRevision'] = getRevision($trFile); $status['fileEnRevision'] = getRevision($trFile, true); if ($status['fileEnRevision'] && $status['lastEnRevision']) { $distance = round((float) $status['lastEnRevision'], 3) - round((float) $status['fileEnRevision'], 3) ; $backward = 0; if ($distance<0) { $backward = -1; } elseif ($distance && $distance<.03) { $backward = 1; } elseif ($distance && $distance<.2) { $backward = 2; } elseif ($distance && $distance<.4) { $backward = 3; } elseif ($distance && $distance<.6) { $backward = 4; } elseif ($distance && $distance>=.6) { $backward = 5; } $status['backward'] = $backward; $status['distance'] = $distance; } } else { $status['translated'] = false; } return $status; } ?> http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/cvslist.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/cvslist.php +++ phpdoc/scripts/online_editor/cvslist.php <?php //*-- The PHPDOC Online XML Editing Tool //*-- Developed by Salah Faya visualmind(@)php.net //*-- Version 1.0 - essentially developed for Arabic Translation of PHP Manual //*-- Now updated to work with all phpdoc translations //--- This file lists the folders and files in the left frame //------- Initialization require 'base.php'; $user = sessionCheck(); $lang = $user['phpdocLang']; $translationPath = $phpdocLangs[$lang]['DocCVSPath']; //------- Folder navigation vars $path = ''; $file = ''; if (isset($_REQUEST['path'])) { $path = $_REQUEST['path']; if (isset($_REQUEST['file'])) { $file = $_REQUEST['file']; } } // Prevent wrong paths if (strstr($path, '.') || $file=='..' || $file=='.') { exit; } // Path Slashes if (!$path) $path = '/'; if (substr($path, -1)!='/') $path .= '/'; // Usually, the path are based on english cvs $target = "$enDocCVSPath$path$file"; //------- Decide what to do // If file is selected, redirect to the editor.. if ($file) { // Find in user path first (editing cached file by default) $ffile = $user['cache'].getCacheName($path.$file); if (file_exists($ffile)) { header("location: editxml.php?file=$path$file&source=upath"); exit; } // Find in translated path (edit the translated file) $ffile = "$translationPath$path$file"; if (file_exists($ffile)) { header("location: editxml.php?file=$path$file&source=apath"); exit; } // So it's a new file? Use the english source if (file_exists($target)) { header("location: editxml.php?file=$path$file&source=epath"); exit; } } else { // No file selected, Listing (from english cvs) $d = opendir($target); while($f = readdir($d)) { if (is_dir($target.$f)) { if (in_array($f, $ignoreListingFolders)) continue; $dirs[] = $f; } elseif ((substr($f, -4)=='.xml' || substr($f, -4)=='.ent') && !in_array($f, $ignoreListingFiles)) { $files[] = $f; } } } //------- Functions function printPathAsLinks($path) { global $lang; $px = explode('/', $path); foreach($px as $i=>$p) { $pp .= $p.'/'; if (!$p && !$i) $p = $lang; print "<a href='?path=$pp'>$p</a>"; if ($p || !$i) print '/'; } print '<br>'; } function printDirectories($dirs, $path) { sort($dirs); foreach($dirs as $dir) { print "<a href='?path=$path$dir'><img src='images/dir.png' width=16 height=16 border=0 align=absmiddle> $dir</a> <br>"; } } function printFiles($files, $path) { global $translationPath, $user; sort($files); foreach($files as $fl) { $status = getTranslationStatus($path.$fl); if ($status['translated']) { if ($status['fileEnRevision'] && $status['lastEnRevision'] && $status['distance']>=0) { if (!$status['backward']) { $title = 'Up to date'; $img = 'images/up2date.png'; } else { $title = 'Outdated '.$status['fileEnRevision'].' / '.$status['lastEnRevision']; $img = 'images/r'.($status['backward']+1).'.png'; } } else { $title = 'EN-Revision is incorrect or missing'; $img = 'images/unknown.png'; } } else { $title = 'Not translated yet'; $img = 'images/notyet.png'; } print "<a href='?path=$path&file=$fl' target=fileframe><img src='images/text.png' width=16 height=16 border=0 align=absmiddle> $fl</a> <img src='$img' border=0 align=absmiddle alt='$title'><br>"; } // Lists the user's cached files if (file_exists($user['cache']."files.txt")) { print '<hr>'; print 'Cached files:<br>'; $ff = file($user['cache']."files.txt"); foreach($ff as $f) { $fx = explode('|', $f); if (!isset($cf[$fx[2]])) { print "<a href='editxml.php?file=$fx[2]&source=upath' target=fileframe>$fx[2]</a><br>"; $cf[$fx[2]] = true; } } } } //------- Output ?> <html> <body bgcolor="#FFFFFF"> <style type="text/css"> body { font-family: Tahoma; font-size: 12px; } a:link { text-decoration: none; color: #000066; } a:hover { text-decoration: none; color: #ff0000; } a:active { text-decoration: none; color: #ff0000; } a:visited { text-decoration: none; color: #000066; } </style> <div style="width: 400px;"> Listing: <?php printPathAsLinks($path); printDirectories($dirs, $path); printFiles($files, $path); ?> <hr> <form action=login.php method=post target=_top> <?php if ($requireLogin) { ?> <input type=hidden name=email value="<?php print $user['email']; ?>"><br> <?php } ?> Switch language:<br> <select name=lang onchange="if (this.value) this.form.submit();"> <option value=''></option> <?php foreach($phpdocLangs as $lng=>$langInfo) { if ($lng==$lang) $sel = " selected"; else $sel = ''; print "<option value='$lng'$sel>$lng</option>"; } ?> </select> </form> </div> </body> </html> http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/cvsupdate.txt?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/cvsupdate.txt +++ phpdoc/scripts/online_editor/cvsupdate.txt [Last CVS Update time] http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/editxml.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/editxml.php +++ phpdoc/scripts/online_editor/editxml.php <?php //*-- The PHPDOC Online XML Editing Tool //*-- Developed by Salah Faya visualmind(@)php.net //*-- Version 1.0 - essentially developed for Arabic Translation of PHP Manual //*-- Now updated to work with all phpdoc translations //--- This is the actual xml editor //------- Initialization require 'base.php'; $user = sessionCheck('?from=editxml'); $lang = $user['phpdocLang']; $translationPath = $phpdocLangs[$lang]['DocCVSPath']; //------- Frames split if (isset($_REQUEST['split'])) { if ($_REQUEST['split']=='false' || !$_REQUEST['split']) $_REQUEST['split'] = false; $_SESSION['split'] = $_REQUEST['split']; } if ($_SESSION['split'] && !isset($_REQUEST['noframes'])) { $source = $_REQUEST['source']; $file = $_REQUEST['file']; // ToDo automatically show the translated file in one frame and the source in another print "<frameset cols=*,*><frame name=frame1 src='editxml.php?file=$file&source=$source&noframes=1'><frame name=frame2 src='editxml.php?file=$file&source=$source&noframes=1'></frameset>"; exit; } //------- File Request if (isset($_REQUEST['source']) && isset($_REQUEST['file'])) { $source = $_REQUEST['source']; $file = $_REQUEST['file']; } if (!$file || strstr($file, '..')) { exit; } $requestedFilename = $file; // Turn on/off XML as Text if ($_REQUEST['textedit'] && $_REQUEST['textedit']!='false') { $_SESSION['textedit'] = true; } elseif ($_REQUEST['textedit']=='false') { $_SESSION['textedit'] = false; } // Turn on/off Hiding XML tags when editing if ($_REQUEST['hidexml'] && $_REQUEST['hidexml']!='false') { $_SESSION['hidexml'] = true; } elseif ($_REQUEST['hidexml']=='false') { $_SESSION['hidexml'] = false; } // Turn on/off Line By Line if ($_REQUEST['par'] && $_REQUEST['par']!='false') { $_SESSION['para'] = false; } elseif ($_REQUEST['par']=='false') { $_SESSION['para'] = true; } //------- Functions // Parse XML to find editable text // this function is written poorly but it does the job function myParse($text) { $results = array(); $rc = 0; for($i=0; $i<strlen($text); $i++) { $c = substr($text, $i, 1); if ($c=='<') { // Starting tag $tagC = ''; $tag = true; } if ($tag) { $tagC .= $c; } else { if ($c=="\n") { // Advance the counter so each line is stored separately if (!$_SESSION['para']) { $rc++; } else { if (!isset($results[$rc])) { // Get position of New editable text $results[$rc] = array('index'=>$i, 'text'=>''); } $results[$rc]['text'] .= $c; } } else { if (!isset($results[$rc])) { // Get position of New editable text $results[$rc] = array('index'=>$i, 'text'=>''); } $results[$rc]['text'] .= $c; } } if ($c=='>') { // Tag ending $tagC .= $c; $tag = false; $rc++; } } // Filter editable text $resultsx = array(); foreach($results as $resline) { $res = trim($resline['text']); // Skip empty, &xx; and literals if (!$res || ($res[0]=='&' && substr($res,-1)==';') || isLiteral($res) ) continue; if ($_SESSION['para']) { // trim \n and adjust position while(substr($resline['text'], 0, 1)=="\n" || substr($resline['text'], 0, 1)=="\r") { $resline['index']++; $resline['text'] = substr($resline['text'], 1); } // recheck \n if (!strstr($resline['text'], "\n")) { // treat as one line (trim and adjust) while(substr($resline['text'], 0, 1)==' ') { $resline['index']++; $resline['text'] = substr($resline['text'], 1); } $resline['text'] = trim($resline['text']); } $res = $resline['text']; } else { // trim and adjust position while(substr($resline['text'], 0, 1)==' ') { $resline['index']++; $resline['text'] = substr($resline['text'], 1); } $res = trim($resline['text']); } $resultsx[$resline['index']] = $res; } // Return an array contains all editable texts and their positions in file contents return $resultsx; } function isLiteral($text) { // ToDo check if text is literal and don't need to be translated return false; } //------- Locate file according to the selected path $status = getTranslationStatus($file); switch($source) { case 'upath': // User cached path $file = $user['cache'].getCacheName($file); break; case 'apath': // File from translation $file = $translationPath.$file; break; case 'epath': // English source $file = $enDocCVSPath.$file; break; case 'diff': // cvs diff if ($status['distance']>0) { $url = "http://cvs.php.net/viewvc.cgi/phpdoc/en/$file?r1=$status[fileEnRevision]&r2=$status[lastEnRevision]"; $html = implode('', file($url)); preg_match_all("#(<table cellspacing=\"0\" cellpadding=\"0\">\\s*<tr class=\"vc_diff_header\">.+</table>)#s", $html, $parts); $data = '<meta name="generator" content="ViewVC 1.1-dev" /><link rel="stylesheet" href="viewvc-style.css" type="text/css" /><div style="font-family: Arial;">'; $data .= str_replace('/viewvc.cgi/', 'http://cvs.php.net/viewvc.cgi/', $parts[1][0]).'</div>'; } break; } //------- Prepare the file for editing if ($source!='diff'): // Read the file contents $data = implode('', file($file)); if (!$_SESSION['textedit']) { // Protect CDATA tags by hiding them before parsing preg_match_all("#<\!\[CDATA\[(.+)\]\]>#Us", $data, $matches); $cdataStore = array(); $cdataMarks = array(); foreach($matches[0] as $i=>$cdata) { $mark = "<CDATA-$i-></CDATA>"; $cdl = strlen($cdata)-strlen($mark); $mark = "<CDATA-$i-".str_repeat('X', $cdl).'></CDATA>'; $cdataStore[$i] = $cdata; $cdataMarks[$i] = $mark; $data = str_replace($cdata, $mark, $data); } // Parse file contents and fetch editable text $results = myParse($data); // Keep a copy of the actual contents $newdata = $data; // Replace editable text with special Marks $results = array_reverse($results, true); foreach($results as $index=>$text) { $newtext = $text; // If in saving process Put submitted text instead of current text if (isset($_POST['textAt'][$index])) { $newtext = stripslashes2($_POST['textAt'][$index]); // Fix paragraphs that lost prefix \n if (strstr($newtext, "\n") && substr($newtext, 0, 1)!="\n") { //$newtext = "\n$newtext"; } $results[$index] = $newtext; $newdata = substr_replace($newdata, $newtext, $index, strlen($text)); $updated = true; } // Put special marks if ($newtext!="'>" && $newtext!='">') { if (strstr($newtext, "\n")) { // This marks text that has new line (so we will use multiline textarea) $data = substr_replace($data, "_PMRK[$index]\{$newtext}PMRK_", $index, strlen($text)); } elseif (strstr($newtext, "'") && !strstr($newtext, '"')) { // This marks text that has single quote (so the input field will use double quote) $data = substr_replace($data, "_ZMRK[$index]\{$newtext}ZMRK_", $index, strlen($text)); } elseif (strstr($newtext, "'") && strstr($newtext, '"')) { // This marks text that has single and double quote (so we will use textarea) $data = substr_replace($data, "_YMRK[$index]\{$newtext}YMRK_", $index, strlen($text)); } else { // This marks text that can use a normal input $data = substr_replace($data, "_XMRK[$index]\{$newtext}XMRK_", $index, strlen($text)); } } } if ($_SESSION['para'] && $updated) { // Remove \r (some browsers) $newdata = str_replace("\r\n", "\r", $newdata); $newdata = str_replace("\n", "\r", $newdata); $newdata = str_replace("\r", "\n", $newdata); if (substr($newdata, -1)!="\n") { $newdata .= "\n"; } } // Put CData back $data = str_replace($cdataMarks, $cdataStore, $data); $newdata = str_replace($cdataMarks, $cdataStore, $newdata); } else { // Edit XML as Text if (isset($_POST['xmldata'])) { $newdata = stripslashes2($_POST['xmldata']); // Remove \r (some browsers) $newdata = str_replace("\r\n", "\r", $newdata); $newdata = str_replace("\n", "\r", $newdata); $newdata = str_replace("\r", "\n", $newdata); if (substr($newdata, -1)!="\n") { $newdata .= "\n"; } $updated = true; } } //------- Save or Send file when requested if ($updated || $_REQUEST['download']) { // Charset for new translated files if ($phpdocLangs[$lang]['charset']!='iso-8859-1') { $charset = $phpdocLangs[$lang]['charset']; $newdata = str_replace('<?xml version="1.0" encoding="iso-8859-1"?>', '<?xml version="1.0" encoding="'.$charset.'"?>', $newdata); } // EN-Revision for new translated files if (!stristr($newdata, 'EN-Revision:')) { $newdata = str_replace('<!-- $Revision: 1.1 $Revision: 1.1 $ -->\n<!-- EN-Revision: ", $newdata); } // Send file as is (download) if (isset($_REQUEST['download'])) { header('Content-Type: application/download'); header('Content-Disposition: attachment; filename='.basename($requestedFilename)); print $newdata; exit; } if ($requireLogin) { // Save file in user cache folder $f = fopen($user['cache'].getCacheName($requestedFilename), 'w'); fputs($f, $newdata); fclose($f); // Simple log $f = fopen($user['cache']."files.txt", 'a'); $time = getDateTimeToLog(); $ip = getUserIP(); fputs($f, "$time|$ip|$requestedFilename\r\n"); fclose($f); } exit("File has been saved in your cache folder. You can now <a href='editxml.php?file=$requestedFilename&source=$source&download=yes&noframes=1'>download it</a> or edit another file"); } if (!$_SESSION['textedit']) { // Mark XML Tags to be hidden (when hidexml is true) $hideXMLTag = $_SESSION['hidexml']; if ($hideXMLTag) { $startXMLTag = '_TMRK('; $endXMLTag = ')TMRK_'; } // Replace special marks with <input> or <textarea> $data = htmlspecialchars($data); $data = preg_replace("#_XMRK\[(\\d+)\]\{(.+)\}XMRK_#U", "$endXMLTag<input type=text class=xinput ondblclick='dblclk(this)' onmouseover='irn(\\1)' onmouseout='iro(\\1)' onkeyup='ku(\\1, event)' onkeydown='kp(\\1, event)' name=textAt[\\1] value='\\2'>$startXMLTag", $data); $data = preg_replace("#_YMRK\[(\\d+)\]\{(.+)\}YMRK_#U", "$endXMLTag<textarea rows=1 class=xinput ondblclick='dblclk(this)' onmouseover='irn(\\1)' onmouseout='iro(\\1)' onkeyup='ku(\\1, event)' onkeydown='kp(\\1, event)' name=textAt[\\1]>\\2</textarea>$startXMLTag", $data); $data = preg_replace("#_ZMRK\[(\\d+)\]\{(.+)\}ZMRK_#U", "$endXMLTag<input type=text class=xinput ondblclick='dblclk(this)' onmouseover='irn(\\1)' onmouseout='iro(\\1)' onkeyup='ku(\\1, event)' onkeydown='kp(\\1, event)' name=textAt[\\1] value=\"\\2\">$startXMLTag", $data); $data = preg_replace("#_PMRK\[(\\d+)\]\{(.+)\}PMRK_#Us", "$endXMLTag<br><textarea name=textAt[\\1] class=xinput2 ondblclick='dblclk(this)' onmouseover='irn(\\1)' onmouseout='iro(\\1)' style='width: 80%;'>\\2</textarea><br>$startXMLTag", $data); $data = $startXMLTag.$data.$endXMLTag; // Update input size according to text length foreach($results as $index=>$text) { if (!strstr($text, "\n")) { $size = strlen(utf8_decode($text)); $data = str_replace("textAt[$index]", "textAt[$index] size=$size cols=$size", $data); } else { $size = substr_count($text, "\n")+1; $data = str_replace("<textarea name=textAt[$index]", "<textarea name=textAt[$index] rows=$size", $data); } } // Hide XML Tags if ($hideXMLTag) { preg_match_all("#_TMRK\((.+)\)TMRK_#Us", $data, $matches); foreach($matches[0] as $i=>$line) { $r = ' '; if (strstr($line, "\n")) { $r = "\n"; if (substr_count($line, "\n")>3) { $r.="\n"; } } $data = str_replace($line, $r, $data); } } } endif; //------- Output ?> <html> <meta http-equiv="Content-Type" content="text/html; charset=<?php print $phpdocLangs[$lang]['charset']; ?>" /> <body bgcolor="#9999cc"> <style type="text/css"> body { font-family: Tahoma; font-size: 12px; } .xinput { font-family: <?php print $phpdocLangs[$lang]['font']; ?>; border: 0px none; color: #AA0000; border-bottom: 1px dotted gray; } .xinput2 { font-family: <?php print $phpdocLangs[$lang]['font']; ?>; color: #AA0000;; } .editbox { font-family: <?php print $phpdocLangs[$lang]['font']; ?>; color: #006600; background-color: white; border: 3px groove; width: 100%; height: 400px; overflow: auto; } .editbox-diff { font-family: <?php print $phpdocLangs[$lang]['font']; ?>; color: #006600; background-color: white; border: 3px groove; width: 100%; height: 550px; overflow: auto; } a:link { text-decoration: none; color: #000066; } a:hover { text-decoration: none; color: #ff0000; } a:active { text-decoration: none; color: #ff0000; } a:visited { text-decoration: none; color: #000066; } </style> <script language=javascript> // Highlight input on mouse over function irn(i) { var ob = document.getElementById('textAt['+i+']'); ob.style.backgroundColor = '#EEEEEE'; } // un-Highlight input on mouse over function iro(i) { var ob = document.getElementById('textAt['+i+']'); ob.style.backgroundColor = '#FFFFFF'; } var updated = false; // Switch between fields when using arrow keys and translate selection by PgdDown key function kp(i, e) { var ev= (window.event)? window.event: e; if(!ev || !ev.type) return false; var k,w; if (ev.keyCode) w=1; if (ev.charCode) w=2; if (ev.which) w=3; k = (ev.keyCode)?ev.keyCode: ((ev.charCode)? ev.charCode: ev.which); if (k==34) { // PageDown to translate dblclk(document.getElementById('textAt['+i+']')); if (w==1) e.keyCode = 0; if (w==2) e.charCode = 0; if (w==3) e.which = 0; return false; } if (k==40 || k==38) { if (w==1) e.keyCode = 9; if (w==2) e.charCode = 9; if (w==3) e.which = 9; } return true; } // Update input/textarea size when editing function ku(i, e) { updated = true; var ob = document.getElementById('textAt['+i+']'); var l = ob.value.length; if (l) { ob.size = l; ob.cols = l; } } // Translate using google API on double click function dblclk(obj) { // translate(obj); var selection = new Selection(obj); var s = selection.create(); if (s.end) { var ln = s.end - s.start; var word = obj.value.substr(s.start, ln); translate(obj, word, s.start, s.end); } } // Right To Left and Left To Right function rtl(button) { if (button.value == 'RTL') { button.value = 'LTR'; document.getElementById('editbox').dir = 'rtl'; } else { button.value = 'RTL'; document.getElementById('editbox').dir = 'ltr'; } } // Prevent Losing changes function uconfirm() { if (updated) { return confirm('This will cancel any unsaved updates, are you sure?'); } return true; } // Show hidden frame function showhframe() { document.getElementById('hframe').style.display = ''; } //------------- The following are required for Google translation // Cross Browser selectionStart/selectionEnd // Version 0.2 // Copyright (c) 2005-2007 KOSEKI Kengo // // This script is distributed under the MIT licence. // http://www.opensource.org/licenses/mit-license.php function Selection(textareaElement) { this.element = textareaElement; } Selection.prototype.create = function() { if (document.selection != null && this.element.selectionStart == null) { return this._ieGetSelection(); } else { return this._mozillaGetSelection(); } } Selection.prototype._mozillaGetSelection = function() { return { start: this.element.selectionStart, end: this.element.selectionEnd }; } Selection.prototype._ieGetSelection = function() { this.element.focus(); var range = document.selection.createRange(); var bookmark = range.getBookmark(); var contents = this.element.value; var originalContents = contents; var marker = this._createSelectionMarker(); while(contents.indexOf(marker) != -1) { marker = this._createSelectionMarker(); } var parent = range.parentElement(); if (parent == null ) { return { start: 0, end: 0 }; } range.text = marker + range.text + marker; contents = this.element.value; var result = {}; result.start = contents.indexOf(marker); contents = contents.replace(marker, ""); result.end = contents.indexOf(marker); this.element.value = originalContents; range.moveToBookmark(bookmark); range.select(); return result; } Selection.prototype._createSelectionMarker = function() { return "##SELECTION_MARKER_" + Math.random() + "##"; } //------------ </script> <script type="text/javascript" src="http://www.google.com/jsapi"></script><script type="text/javascript"> //-- Google Translation API google.load("language", "1"); var transTarget = new Array(); function translate(obj, word, s, e) { if (!word) return; if (obj.name!='xmldata') { obj.style.backgroundColor = '#22EE99'; } transTarget[0] = obj; transTarget[1] = word; transTarget[2] = s; transTarget[3] = e; google.language.translate(word, "en", "<?php print $phpdocLangs[$lang]['id']; ?>", function(result) { if (!result.error) { //var container = document.getElementById("translation"); var w = transTarget[0].value; var w1 = ''; if (transTarget[2]) { w1 = w.substr(0, transTarget[2]); } var w2 = w.substr(transTarget[2]+word.length); if (word.substr(word.length-1)==' ') w2 = ' '+w2; if (word.substr(0, 1)==' ') w1 = w1 + ' '; transTarget[0].value = w1+result.translation+w2; var l = transTarget[0].value.length; if (l) { transTarget[0].size = l; transTarget[0].cols = l; } updated = true; }}); } </script> File: <b><?php print $requestedFilename; ?></b><br> Source: <b><font color=white><?php if ($source=='upath') print "User cached version"; if ($source=='apath') print "$lang Translated version"; if ($source=='epath') print "English version"; ?></font></b><br> <?php if ($requireLogin) { print "Logged as: <b>$user[email]</b> <a href='login.php?and=logout' target=_top>logout</a><br>"; } $url = "editxml.php?file=$requestedFilename&source=$source"; if ($_SESSION['hidexml']) $hideXML = 'checked'; else $hideXML = ''; if ($_SESSION['split']) $splitFrames = 'checked'; else $splitFrames = ''; if ($_SESSION['textedit']) $textEdit = 'checked'; else $textEdit = ''; if ($_SESSION['para']) $lineByLine = ''; else $lineByLine = 'checked'; ?> <input type=checkbox name=hidexml value=1 <?php print $hideXML; ?> onClick="if (uconfirm()) document.location='<?php print $url; ?>&noframes=1&hidexml='+this.checked;" <?php if ($source=='diff') print 'disabled'; ?> /> Hide XML Tags <input type=checkbox name=split value=1 <?php print $splitFrames; ?> onClick="if (uconfirm()) top.frames['fileframe'].location='<?php print $url; ?>&split='+this.checked;"> Split frames <input type=checkbox name=textedit value=1 <?php print $textEdit; ?> onClick="if (uconfirm()) document.location='<?php print $url; ?>&noframes=1&textedit='+this.checked;" <?php if ($source=='diff') print 'disabled'; ?> /> XML Text Editor <input type=checkbox name=linebyline value=1 <?php print $lineByLine; ?> onClick="if (uconfirm()) document.location = '<?php print $url; ?>&noframes=1&par='+this.checked;" <?php if ($source=='diff') print 'disabled'; ?> /> Line by Line (no textarea) <form action=editxml.php method=post target=hframe onsubmit="showhframe();"> <?php $bs[0] = array('bcolor'=>'#CCCCCC', 'caption'=>'Latest English', 'link'=>"editxml.php?file=$requestedFilename&source=epath&noframes=1", 'tag'=>'epath', 'title'=>$status['lastEnRevision']); $bs[1] = array('bcolor'=>'#CCCCCC', 'caption'=>$lang.' version', 'link'=>"editxml.php?file=$requestedFilename&source=apath&noframes=1", 'tag'=>'apath', 'title'=>$status['fileEnRevision']); if ($requireLogin) { $bs[] = array('bcolor'=>'#CCCCCC', 'caption'=>'Cached version', 'link'=>"editxml.php?file=$requestedFilename&source=upath&noframes=1", 'tag'=>'upath'); } if ($status['distance']>0) { $bs[] = array('bcolor'=>'#CCCCCC', 'caption'=>'Diff log '.$status['fileEnRevision'].' / '.$status['lastEnRevision'], 'link'=>"editxml.php?file=$requestedFilename&source=diff&noframes=1", 'tag'=>'diff'); } foreach($bs as $i=>$b) { if ($b['tag']==$source) $b['bcolor'] = '#FFFFFF'; print "<span style='background-color: $b[bcolor]; border: 1px solid black; border-bottom: 0px none white;'><a href='$b[link]' onclick='return uconfirm();' title='$b[title]'>$b[caption]</a>"; print '</span>'; if (($i+1)<count($bs)) print '|'; } $direction = "LTR"; $directionx = "RTL"; if ($phpdocLangs[$lang]['direction']=='RTL' && ($source=='upath' || $source=='apath')) { $direction = "RTL"; $directionx = "LTR"; } if (!$_SESSION['textedit'] || $source=='diff') { ?> <div id=editbox dir=<?php print $direction; ?> class="editbox<?php if ($source=='diff') print '-diff'; ?>"> <center><img id=loading src=images/loading.gif align=absmiddle></center> <pre><?php print $data; ?></pre> </div> <?php } else { // Edit XML as Text ?> <center><img id=loading src=images/loading.gif align=absmiddle><div> <textarea name=xmldata id=editbox ondblclick="dblclk(this);" dir=<?php print $direction; ?> style="font-family: Fixedsys; background-color: white; width: 100%; height: 400px;"><?php print $data; ?></textarea></div> </center> <?php } if ($source!='diff') { ?> <input name=noframes type=hidden value=1> <input name=source type=hidden value="<?php print $source; ?>"> <input name=file type=hidden value="<?php print $requestedFilename; ?>"> <input type=button value=<?php print $directionx;?> onclick="rtl(this);"> <?php if ($requireLogin) print '<input name=save type=submit value="Save in cache">'; ?> <input name=download type=submit value=Download> </form> <!-- This frame is used to prevent losing changes if session has expired.. so login can be done inside --> <iframe id=hframe name=hframe width=100% height=100 border=0 style="display: none"></iframe> * Before working on translating this file, please make sure to send an email to <?php print $phpdocLangs[$lang]['mailing']; ?> indicating that you will translate this file, and wait for confirmation. <br> * After translating the file, please download it then: either cvs it -or- send it to <?php print $phpdocLangs[$lang]['mailing']; ?>. <b>Always remember to keep a copy of the file on your local computer</b><br> * If you have questions, contact the translation coordinator <?php print $phpdocLangs[$lang]['coordinator']; ?><br> <?php } ?> <script language=javascript> document.getElementById('loading').style.display = 'none'; </script> </body> </html> http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/index.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/index.php +++ phpdoc/scripts/online_editor/index.php <?php require 'login.php'; ?> http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/intro.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/intro.php +++ phpdoc/scripts/online_editor/intro.php <?php //*-- The PHPDOC Online XML Editing Tool //*-- Developed by Salah Faya visualmind(@)php.net //*-- Version 1.0 - essentially developed for Arabic Translation of PHP Manual //*-- Now updated to work with all phpdoc translations //--- Just an introduction // ToDo show summary of translated files (or revcheck) require 'base.php'; $user = sessionCheck(); $lang = $user['phpdocLang']; ?> <html> <body style="font-family: Tahoma; font-size: 12px;"> <h2> The PHPDOC Online XML Editing Tool </h2> Developed by Salah Faya visualmind(@)php.net<br> Version 1.0 - essentially developed for Arabic Translation of PHP Manual<br> Now updated to work with all phpdoc translations<br> <br> <b>Last CVS Update: <?php print implode('', file('cvsupdate.txt')); ?></b> <br><br> The language you are editing is <b><?php print $lang; ?></b><br> Translation coordinator: <b><?php print $phpdocLangs[$lang]['coordinator'] ?></b><br> Mailing list: <b><?php print $phpdocLangs[$lang]['mailing'] ?></b>. For Subscription email to <b><?php print $phpdocLangs[$lang]['mailingSubscribe'] ?></b><br><br> Charset used: <b><?php print $phpdocLangs[$lang]['charset'] ?></b><br> <?php // Lists the user's cached files if (file_exists($user['cache']."files.txt")) { print '<hr>'; print 'Your Cached files:<br>'; $ff = file($user['cache']."files.txt"); foreach($ff as $f) { $fx = explode('|', $f); if (!isset($cf[$fx[2]])) { print "<a href='editxml.php?file=$fx[2]&source=upath' target=fileframe>$fx[2]</a><br>"; $cf[$fx[2]] = true; } } } ?> </body> </html> http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/login.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/login.php +++ phpdoc/scripts/online_editor/login.php <?php //*-- The PHPDOC Online XML Editing Tool //*-- Developed by Salah Faya visualmind(@)php.net //*-- Version 1.0 - essentially developed for Arabic Translation of PHP Manual //*-- Now updated to work with all phpdoc translations //--- This file allows users to login using an email address (TODO we may use CVS or other way in future) //------- Initialization require 'base.php'; session_start(); // Logout &and=logout if (isset($_GET['and'])) { session_unregister('user'); unset($_SESSION['user']); } //------- Login request if (isset($_POST['lang'])) { if (isset($_POST['email'])) { $email = $_POST['email']; } $lang = $_POST['lang']; // Check selected language if (!isset($phpdocLangs[$lang])) { exit('Sorry, you have choosen an incorrect language'); } if ($requireLogin) { // Simple email validation -- ToDo some enhancements $email = trim(strtolower($email)); $p1 = preg_match("#^([a-z0-9][a-z0-9_\.]*)@[a-z0-9][a-z0-9\-]+\.[a-z]{2,6}$#", $email); $p2 = preg_match("#^([a-z0-9][a-z0-9_\.]*)@[a-z0-9][a-z0-9\-]+\.[a-z]{2,3}\.[a-z]{2}$#", $email); if (!$p1 && !$p2) { exit('That was not a valid email address'); } // This validation is required because emails are used as user folder name -- ToDO use another way if (strlen($email)>50) { exit('That was not a valid email address'); } // Do Login (create user folder) if (!file_exists($usersCachePath.$email)) { @mkdir($usersCachePath.$email, $filesChMod); } } if (is_dir($usersCachePath.$email) || !$requireLogin) { // Session setup session_register('user'); $_SESSION['user'] = array('email'=>$email, 'cache'=>$usersCachePath.$email.'/', 'phpdocLang'=>$lang); // If expired session, redo last request if ($_SESSION['redo']) { $link = $_SESSION['redo']; $_SESSION['redo'] = false; header("location: $link"); exit; } // If accidently lost session while editing if ($_REQUEST['from']=='editxml') { exit('Ok, Login is <b>successful</b>. Now retry your previous request'); } // Redirect to frameset header('location: workbench.php'); exit('<a href="workbench.php">Moved to workbench.php</a>'); } else { // If folder has not been created exit('Sorry, there was an internal error. Please contact administration'); } } //------- Login form ?> <html> <body style="font-family: Tahoma; font-size: 12px;"> <h3> The PHPDOC Online XML Editing Tool :: Login first</h3> <form action=login.php method=post> <input type=hidden name=from value="<?php print $_REQUEST['from']; ?>"> <?php if ($requireLogin) { ?> Your email address (must be valid) <input type=text name=email><br> <?php } ?> Translating PHPDOC to <select name=lang><?php foreach($phpdocLangs as $lang=>$langInfo) { print "<option value='$lang'>$lang</option>"; } ?> </select>* <input type=submit value=Login> </form> Developed by Salah Faya visualmind(@)php.net<br> Version 1.0 - essentially developed for Arabic Translation of PHP Manual<br> Now updated to work with all phpdoc translations. <br> This is a special tool to be used only by PHPDOC translators.<br> Javascript and cookies must be enabled in your browser settings.<br> <br> <b>Last CVS Update: <?php print implode('', file('cvsupdate.txt')); ?></b> </body> </html> http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/viewvc-style.css?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/viewvc-style.css +++ phpdoc/scripts/online_editor/viewvc-style.css /*******************************/ /*** ViewVC CSS Stylesheet ***/ /*******************************/ /*** Standard Tags ***/ img { border: none; } table { width: 100%; margin: 0; border: none; } table.auto { width: auto; } table.fixed { width: 100%; table-layout: fixed; } table.fixed td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } tr, td, th { vertical-align: top; } form { margin: 0; } /*** Icons ***/..vc_icon { width: 16px; height: 16px; border: none; padding: 0 1px; } /*** Navigation Headers ***/..vc_navheader { background-color: #cccccc; } /*** Table Headers ***/..vc_header { text-align: left; vertical-align: top; background-color: #cccccc; }..vc_header_sort { text-align: left; background-color: #88ff88; } /*** Table Rows ***/..vc_row_even { background-color: #ffffff; }..vc_row_odd { background-color: #efefff; } /*** Log messages ***/..vc_log { /* unfortunately, white-space: pre-wrap isn't widely supported ... */ white-space: -moz-pre-wrap; /* Mozilla based browsers */ white-space: -pre-wrap; /* Opera 4 - 6 */ white-space: -o-pre-wrap; /* Opera >= 7 */ white-space: pre-wrap; /* CSS3 */ word-wrap: break-word; /* IE 5.5+ */ } /*** Markup Summary Header ***/..vc_summary { background-color: #eeeeee; } /*** Highlight Markup Styles ***/ #vc_markup .num { color:#000000; } #vc_markup .esc { color:#bd8d8b; } #vc_markup .str { color:#bd8d8b; } #vc_markup .dstr { color:#bd8d8b; } #vc_markup .slc { color:#ac2020; font-style:italic; } #vc_markup .com { color:#ac2020; font-style:italic; } #vc_markup .dir { color:#000000; } #vc_markup .sym { color:#000000; } #vc_markup .line { color:#555555; } #vc_markup .kwa { color:#9c20ee; font-weight:bold; } #vc_markup .kwb { color:#208920; } #vc_markup .kwc { color:#0000ff; } #vc_markup .kwd { color:#000000; } /*** Line numbers outputted by highlight colorizer ***/..line { border-right-width: 1px; border-right-style: solid; border-right-color: #505050; padding: 1px; background-color: #eeeeee; color: #505050; text-decoration: none; font-weight: normal; font-style: normal; } /*** Diff Styles ***/..vc_diff_header { background-color: #ffffff; }..vc_diff_chunk_header { background-color: #99cccc; }..vc_diff_chunk_extra { font-size: smaller; }..vc_diff_empty { background-color: #cccccc; font-family: sans-serif; font-size: smaller; }..vc_diff_add { background-color: #aaffaa; font-family: sans-serif; font-size: smaller; }..vc_diff_remove { background-color: #ffaaaa; font-family: sans-serif; font-size: smaller; }..vc_diff_change { background-color: #ffff77; font-family: sans-serif; font-size: smaller; }..vc_diff_change_empty { background-color: #eeee77; font-family: sans-serif; font-size: smaller; }..vc_diff_nochange { font-family: sans-serif; font-size: smaller; }..vc_raw_diff { background-color: #cccccc; font-size: smaller; } /*** Intraline Diff Styles ***/ ..vc_idiff_add { background-color: #aaffaa; }..vc_idiff_change { background-color:#ffff77; }..vc_idiff_remove { background-color:#ffaaaa; }..vc_idiff_empty { background-color:#e0e0e0; } table.vc_idiff col.content { width: 50%; } table.vc_idiff tbody { font-family: monospace; /* unfortunately, white-space: pre-wrap isn't widely supported ... */ white-space: -moz-pre-wrap; /* Mozilla based browsers */ white-space: -pre-wrap; /* Opera 4 - 6 */ white-space: -o-pre-wrap; /* Opera >= 7 */ white-space: pre-wrap; /* CSS3 */ word-wrap: break-word; /* IE 5.5+ */ } table.vc_idiff tbody th { background-color:#e0e0e0; text-align:right; } /*** Annotate Styles ***/..vc_blame_line, .vc_blame_author, .vc_blame_rev { font-family: monospace; font-size: 1em; color: #666666; text-align: right; white-space: nowrap; padding-right: 0.5em; } ..vc_blame_rev { border-right: solid 1px black; } ..vc_blame_text { font-family: monospace; font-size: 1.2em; text-align: left; white-space: pre; width: 100%; padding-left: 0.5em; background-color: #ffffff; } /*** Query Form ***/..vc_query_form { background-color: #e6e6e6; } http://cvs.php.net/viewvc.cgi/phpdoc/scripts/online_editor/workbench.php?view=markup&rev=1.1 Index: phpdoc/scripts/online_editor/workbench.php +++ phpdoc/scripts/online_editor/workbench.php <?php //*-- The PHPDOC Online XML Editing Tool //*-- Developed by Salah Faya visualmind(@)php.net //*-- Version 1.0 - essentially developed for Arabic Translation of PHP Manual //*-- Now updated to work with all phpdoc translations //--- This file is the frameset require 'base.php'; $user = sessionCheck(); ?> <frameset cols="200,*"> <frame name=listingframe src=cvslist.php> <frame name=fileframe src=intro.php> </frameset>