User talk:Badmadevil: Difference between revisions
m (→Not Implemented Tasks by Language: php version, hopefully the final version) |
m (→Not Implemented Tasks by Language: bugs fix) |
||
Line 9: | Line 9: | ||
== Not Implemented Tasks by Language == |
== Not Implemented Tasks by Language == |
||
Hello. IIRC, it has been mentioned an idea to display a page of tasks not implemented by a specific language (It is from [[User:IanOsgood|Ian Osgood]]'s [[Rosetta_Code:Wiki_Wishlist|wishlist]]), it seems no such page at Rosetta Code yet. I've coded a dirty hack of such page using PHP. <br /><br />This version should preserve Rosetta Code's pages look and feel, and may be better integrated into RC site.<br /><br /> |
Hello. IIRC, it has been mentioned an idea to display a page of tasks not implemented by a specific language (It is from [[User:IanOsgood|Ian Osgood]]'s [[Rosetta_Code:Wiki_Wishlist|wishlist]]), it seems no such page at Rosetta Code yet. I've coded a dirty hack of such page using PHP. <br /><br />This version should preserve Rosetta Code's pages look and feel, and may be better integrated into RC site.<br /><br /> |
||
''Bugs fix notes :'' |
|||
*When PHP flag <i>allow_url_fopen</i> is enabled, it is possible to read contents from RC Site via local server. Then, by directly testing with RC Site, many bugs were found; |
|||
*''fixed'', it seems that articles in tasks or languages' pages have at least 3 version of url. In most cases, they refer to the same file, but it seems some are not (may be re-direction?). Previously, some url can be accessed while other cannot, if only using one version of url; now all 3 version is tried. The version of '/w/index.php?title=' has highest priority, so that page like C++ will not mistaken by C page; |
|||
*''fixed'', previously, required link nodes to be got by xpath are assumed to be inside a table, but it is found that language page having 7 or less task completed didn't use a table; the later case is dealing with another proper xpath; |
|||
*some pages have not any task completed, eg. assembler, pike, JoCaml. They are treated as error loading page, rather than display all tasks from Task-list page; |
|||
*''unsolved'', there are unknown errors on parsing pages of ''JScript.NET'' & ''Visual Basic.NET'' as DOM. They can be load as DOMDocument (so that it is not a problem of url, eg.wrong encoding of url string), but can't get the required Node by getElementById inside the DOMDoc; |
|||
*''Usage'', this version need not config, as long as allow_url_fopen is enabled. Place this script in a server (local server or RC Site) some where can be access from www, and that is it. |
|||
*Tested with PHP 5.2.1 |
|||
<br /><br />''Sources'': |
|||
{||- |
{||- |
||
| style="height:36em;float:left;clear:both;overflow:auto;" | |
| style="height:36em;float:left;clear:both;overflow:auto;" | |
||
<php><?php |
<php><?php |
||
// may be need to enable allow_url_fopen, or change it to local file path |
|||
define('Prefix', 'http://www.lynx.ran/wiki/') ; |
|||
define('RCHost' , 'rosettacode.org') ; |
|||
define(' |
define('ROSETTA', 'http://' . RCHost) ; |
||
//define('SafeURL', TRUE) ; |
|||
define('SafePath', '/w/index.php?title=') ; |
|||
define('ROSETTA', 'http://rosettacode.org') ; |
|||
// 3 version of url prefix, when loading the Specific Language Page, |
|||
define('NoWarning', TRUE) ; |
|||
// they will be tried one by one |
|||
//define('NoWarning', FALSE) ; |
|||
define('SafeURL', ROSETTA . '/w/index.php?title=') ; |
|||
define('Prefix', ROSETTA . '/wiki/Category:') ; |
|||
define('LastTry', ROSETTA . '/wiki/') ; |
|||
define(' |
define('PAGENAME', 'PAGENAME') ; // if use as a query string key-value pair |
||
define('NA', 'Not Avaliable') ; |
define('NA', 'Not Avaliable') ; |
||
Line 31: | Line 40: | ||
$langID = LangId() ; |
$langID = LangId() ; |
||
$ |
$IDLang = rawurldecode($langID) ; |
||
// this control how to access this scrtpt |
// this control how to access this scrtpt |
||
$scriptURL = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER[' |
$scriptURL = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['URL'] ; |
||
function ScriptURL($langId = NA){ |
function ScriptURL($langId = NA){ |
||
global $langID, $scriptURL ; |
global $langID, $scriptURL ; |
||
if($langId == NA) $langId = $langID ; |
if($langId == NA) $langId = $langID ; |
||
return $scriptURL . ($langId == NA ? "" : '?' . $langId) ; |
return $scriptURL . ($langId == NA ? "" : '?' . rawurlencode($langId)) ; |
||
} |
|||
// use only by the specifuc language page, use SafeURL to reach C++ pages |
|||
function LangURL($langId = NA){ |
|||
global $langID ; |
|||
if($langId == NA) $langId = $langID ; |
|||
if($langId == NA) |
|||
return "http://" ; // if $langID is NA, this url will not be used anyway. |
|||
return SafeURL ? ROSETTA . SafePath . $langId : Prefix . $langId ; |
|||
} |
} |
||
class Page extends DOMDocument { |
class Page extends DOMDocument { |
||
public $lnk |
public $lnk , $id , $hdr, $msg , $tds ; |
||
public $ |
public $dict = array() , $ok = FALSE ; |
||
public $cnt = 0 , $notCnt = 0 ; // $notCnt = count of not implemented tasks |
|||
public $dict = array() ; |
|||
public $ |
public $context ; |
||
public $cnt , $notCnt = 0 ; // $notCnt = count of not implemented tasks |
|||
function __construct($url,$id,$ |
function __construct($url, $id, $isLangFile = FALSE) { |
||
global $langID ; |
|||
if($this->loadHTMLFile($url)) { |
|||
$this->id = $id ; |
|||
if($isLangFile) { |
|||
if($this->langURL(SafeURL)) // try one by one |
|||
if($this->langURL(Prefix)) |
|||
$this->langURL(LastTry) ; |
|||
} else { |
|||
@$this->loadHTMLFile($url) ; |
|||
$this->context = $this->getElementById($this->id) ; |
|||
} |
|||
if($this->context) { |
|||
$xpath = new DOMXPath($this) ; |
$xpath = new DOMXPath($this) ; |
||
$this-> |
$this->hdr = $xpath->query('h2', $this->context)->item(0) ; |
||
$this->msg = $xpath->query('p', $this->context)->item(0) ; |
|||
$this->lnk = $xpath->query('table/tr/td/ul/li', $this->context) ; |
|||
if($this->lnk && $this->lnk->length > 0) { |
if($this->lnk && $this->lnk->length > 0) { |
||
$this->hdr = $xpath->query('h2', $context)->item(0) ; |
|||
$this->msg = $xpath->query('p', $context)->item(0) ; |
|||
if($isLangPage) |
|||
$this->tds = $xpath->query('table/tr/td', $context) ; |
|||
$this->cnt = $this->lnk->length ; |
$this->cnt = $this->lnk->length ; |
||
$this->ok = TRUE ; |
$this->ok = TRUE ; |
||
} else { // not inside a table |
|||
$this->lnk = $xpath->query('ul/li', $this->context) ; |
|||
if($this->lnk) { // may be zero task completed? |
|||
$this->cnt = $this->lnk->length ; |
|||
$this->ok = TRUE ; |
|||
} |
|||
} |
} |
||
} |
} |
||
} |
|||
function langURL($prefix) { |
|||
global $langID ; |
|||
$FAIL = TRUE ; |
|||
if(@$this->loadHTMLFile($prefix . $langID)) |
|||
if($this->context = $this->getElementById($this->id)) |
|||
$FAIL = FALSE ; |
|||
return $FAIL ; |
|||
} |
|||
function toHTML() { |
|||
// not need if this script is inside RC site |
|||
if(stristr($_SERVER['HTTP_HOST'], RCHost) === FALSE) { |
|||
$head = $this->getElementsByTagName("head")->item(0) ; |
|||
$base = $this->createElement("base") ; |
|||
$base->setAttribute("href", ROSETTA) ; |
|||
$head->insertBefore($base, $head->firstChild) ; |
|||
} |
|||
return $this->saveHTML() ; |
|||
} |
} |
||
function makeDict(&$taskList) { |
function makeDict(&$taskList) { |
||
global $scriptURL ; |
|||
$temp = array() ; |
$temp = array() ; |
||
// collect lang's task list |
|||
for($i = 0 ; $i < $this->lnk->length ; $i++) { |
for($i = 0 ; $i < $this->lnk->length ; $i++) { |
||
$alink = $this->lnk->item($i)->getElementsByTagName("a")->item(0) ; |
$alink = $this->lnk->item($i)->getElementsByTagName("a")->item(0) ; |
||
$href = $alink->getAttribute("href") ; |
$href = $alink->getAttribute("href") ; |
||
$temp[$href] = TRUE ; |
$temp[$href] = TRUE ; |
||
} |
} |
||
// set diff : total tasks - lang's tasks => not completed tasks |
|||
for($i = 0 ; $i < $taskList->length ; $i++) { |
for($i = 0 ; $i < $taskList->length ; $i++) { |
||
$alink = $taskList->item($i)->getElementsByTagName("a")->item(0) ; |
$alink = $taskList->item($i)->getElementsByTagName("a")->item(0) ; |
||
$href = $alink->getAttribute("href") ; |
$href = $alink->getAttribute("href") ; |
||
if(array_key_exists($href, $temp) == FALSE) |
if(array_key_exists($href, $temp) === FALSE) |
||
$this->dict[$this->notCnt++] = |
$this->dict[$this->notCnt++] = // import from Tasks to Lang |
||
$this->importNode($taskList->item($i),true) ; |
|||
} |
} |
||
// clone hdr, msg |
|||
$hdr = $this->hdr->cloneNode(TRUE) ; |
|||
$msg = $this->msg->cloneNode(TRUE) ; |
|||
// clear All nodes under $this->context(id)'s node |
|||
$context = $this->context ; |
|||
$this->context = $context->cloneNode() ; // shallow copy, remove all child |
|||
$context->parentNode->replaceChild($this->context, $context) ; |
|||
// append hdr, msg back |
|||
$this->hdr = $this->context->appendChild($hdr) ; |
|||
$this->msg = $this->context->appendChild($msg) ; |
|||
// make table |
|||
$table = $this->createElement("table") ; |
|||
$tr = $this->createElement("tr") ; |
|||
for($i = 0 ; $i < 3 ; $i++) |
|||
$tr->appendChild($this->createElement("td")) ; |
|||
$table->appendChild($tr) ; |
|||
$this->context->appendChild($table) ; |
|||
// get tds later work with |
|||
$xpath = new DOMXPath($this) ; |
|||
$this->tds = $xpath->query('table/tr/td', $this->context) ; |
|||
// insert a languages list link |
|||
$alink = $this->createElement("a", "Other Languages") ; |
|||
$alink->setAttribute("href", $scriptURL) ; |
|||
$alink->setAttribute("title", "Not completed tasks by other languages") ; |
|||
$style = 'float:right;clear:right;position:relative;top:8px;' . |
|||
'background-color:#eec;padding:2px 8px 2px 8px;'; |
|||
$alink->setAttribute("style", $style) ; |
|||
$this->context->insertBefore($alink, $this->hdr) ; |
|||
} |
} |
||
} |
} |
||
Line 97: | Line 162: | ||
"total completed tasks, some implementations and puzzles may be " . |
"total completed tasks, some implementations and puzzles may be " . |
||
"not yet completed )." ; |
"not yet completed )." ; |
||
// no more tasks below, add a height to the table to look like a void. |
|||
$lang->tds->item(0)->setAttribute("height", "100px") ; |
|||
} else { |
} else { |
||
$lang->msg->nodeValue = |
$lang->msg->nodeValue = |
||
Line 102: | Line 169: | ||
"out of {$task->cnt} total tasks ( {$lang->cnt} " . |
"out of {$task->cnt} total tasks ( {$lang->cnt} " . |
||
"completed tasks, implementations and puzzles etc.)." ; |
"completed tasks, implementations and puzzles etc.)." ; |
||
$curr = 0 ; |
$curr = 0 ; |
||
$splitMax = intval(($lang->notCnt + 2) / 3) ; |
$splitMax = intval(($lang->notCnt + 2) / 3) ; |
||
if($splitMax < 5) $splitMax = 5 ; |
if($splitMax < 5) $splitMax = 5 ; |
||
$capital = ' |
$capital = '' ; |
||
$heading = '' ; |
|||
$lang->lnk = null ; // release node ref. to be remove |
$lang->lnk = null ; // release node ref. to be remove |
||
for($i = 0 ; $i < $lang->tds->length ; $i++) { |
for($i = 0 ; $i < $lang->tds->length ; $i++) { |
||
$td = $lang->tds->item($i) ; |
$td = $lang->tds->item($i) ; |
||
// clear old content |
|||
while ($td->childNodes->length) |
|||
$td->removeChild($td->childNodes->item(0)); |
|||
$td->setAttribute("width", "33%") ; |
$td->setAttribute("width", "33%") ; |
||
$td->setAttribute("valign", "top") ; |
|||
$ul = NULL ; |
|||
$ul = NULL ; |
|||
$splitCnt = 0 ; |
$splitCnt = 0 ; |
||
while($curr < $lang->notCnt && $splitCnt < $splitMax) { |
while($curr < $lang->notCnt && $splitCnt < $splitMax) { |
||
$li = $lang->dict[$curr] ; |
$li = $lang->dict[$curr] ; |
||
$heading = $capital ; |
$heading = $capital ; |
||
$title = $li->getElementsByTagName("a")->item(0)->getAttribute("title") ; |
$title = $li->getElementsByTagName("a")->item(0)->getAttribute("title") ; |
||
$capital = strtoupper(substr($title, 0, 1)) ; |
$capital = strtoupper(substr($title, 0, 1)) ; |
||
if($splitCnt == 0) { |
if($splitCnt == 0) { |
||
if($capital == $heading) |
if($capital == $heading) |
||
$h3 = $lang->createElement("h3", $capital . " cont.") ; |
$h3 = $lang->createElement("h3", $capital . " cont.") ; |
||
else |
else |
||
Line 135: | Line 199: | ||
$td->appendChild($ul) ; |
$td->appendChild($ul) ; |
||
$h3 = $lang->createElement("h3", $capital) ; |
$h3 = $lang->createElement("h3", $capital) ; |
||
$td->appendChild($h3) ; |
$td->appendChild($h3) ; |
||
$ul = $lang->createElement("ul") ; |
$ul = $lang->createElement("ul") ; |
||
} |
} |
||
Line 141: | Line 205: | ||
$curr++ ; |
$curr++ ; |
||
$splitCnt++ ; |
$splitCnt++ ; |
||
} |
} |
||
if($ul) $td->appendChild($ul) ; |
if($ul) $td->appendChild($ul) ; |
||
} |
} |
||
} |
} |
||
} |
} |
||
Line 160: | Line 224: | ||
$langId = NA ; |
$langId = NA ; |
||
if(count($_GET) > 0) { |
if(count($_GET) > 0) { |
||
if(array_key_exists( |
if(array_key_exists(PAGENAME, $_GET) && strlen($_GET[PAGENAME]) > 0) |
||
$langId = $_GET[ |
$langId = $_GET[PAGENAME] ; |
||
else { |
else { |
||
$keys = array_keys($_GET) ; |
$keys = array_keys($_GET) ; |
||
Line 174: | Line 238: | ||
* Main Body |
* Main Body |
||
*/ |
*/ |
||
if(NoWarning) { |
|||
$error_flag = ini_get("error_reporting") ; |
|||
ini_set("error_reporting",$error_flag & ~(E_WARNING|E_NOTICE) ) ; |
|||
} |
|||
if($langID != NA) { |
if($langID != NA) { |
||
$lang = new Page($ |
$lang = new Page($langID, 'mw-pages', TRUE) ; |
||
if($lang->ok) { |
if($lang->ok) { |
||
$task = new Page(TaskURL, 'mw-pages') ; |
$task = new Page(TaskURL, 'mw-pages') ; |
||
Line 190: | Line 249: | ||
if($langID != NA && $lang->ok && $task->ok) { |
if($langID != NA && $lang->ok && $task->ok) { |
||
$lang->hdr->nodeValue = 'Not Completed Tasks by ' . $ |
$lang->hdr->nodeValue = 'Not Completed Tasks by ' . $IDLang ; |
||
process_task() ; |
process_task() ; |
||
echo $lang-> |
echo $lang->toHTML() ; |
||
} else { |
} else { |
||
$list = new Page(ListURL, 'mw-subcategories') ; |
$list = new Page(ListURL, 'mw-subcategories') ; |
||
if($list->ok) { |
if($list->ok) { |
||
if($langID == NA) |
if($langID == NA) |
||
$list->hdr->nodeValue = 'Not Completed Tasks by |
$list->hdr->nodeValue = 'Not Completed Tasks by Languages' ; |
||
else |
else |
||
$list->hdr->nodeValue = 'Not Completed Tasks by |
$list->hdr->nodeValue = 'Not Completed Tasks by Languages ( "' |
||
. $ |
. $IDLang . '" has no task completed or page error) ' ; |
||
process_list() ; |
process_list() ; |
||
echo $list-> |
echo $list->toHTML() ; |
||
} |
} |
||
else |
else |
||
Line 218: | Line 277: | ||
} |
} |
||
if(NoWarning) ini_set("error_reporting",$error_flag) ; |
|||
?></php> |
?></php> |
||
|} |
|} |
||
Hope it can be a temporary solution. -- [[User:Badmadevil|badmadevil]] |
Hope it can be a temporary solution. -- [[User:Badmadevil|badmadevil]] 06:01, 16 June 2008 (MDT) |
Revision as of 12:01, 16 June 2008
Welcome to Rosetta Code! I founded RC around a year ago, and still do most of the administrative work. Thanks for your code contributions. I'm curious, though, how did you hear about RC? --Short Circuit 10:44, 23 February 2008 (MST)
- Hi, thanks. I heard from a forward message posted at Digital Mars D newsgroup about a month ago. -badmadevil 03:03, 24 February 2008 (MST)
Mylang
Good job with the mylang templates. I had done as well as I could before, but these are better. --Mwn3d 13:52, 22 March 2008 (MDT)
- thank for appreciation :) --badmadevil 07:54, 23 March 2008 (MDT)
Not Implemented Tasks by Language
Hello. IIRC, it has been mentioned an idea to display a page of tasks not implemented by a specific language (It is from Ian Osgood's wishlist), it seems no such page at Rosetta Code yet. I've coded a dirty hack of such page using PHP.
This version should preserve Rosetta Code's pages look and feel, and may be better integrated into RC site.
Bugs fix notes :
- When PHP flag allow_url_fopen is enabled, it is possible to read contents from RC Site via local server. Then, by directly testing with RC Site, many bugs were found;
- fixed, it seems that articles in tasks or languages' pages have at least 3 version of url. In most cases, they refer to the same file, but it seems some are not (may be re-direction?). Previously, some url can be accessed while other cannot, if only using one version of url; now all 3 version is tried. The version of '/w/index.php?title=' has highest priority, so that page like C++ will not mistaken by C page;
- fixed, previously, required link nodes to be got by xpath are assumed to be inside a table, but it is found that language page having 7 or less task completed didn't use a table; the later case is dealing with another proper xpath;
- some pages have not any task completed, eg. assembler, pike, JoCaml. They are treated as error loading page, rather than display all tasks from Task-list page;
- unsolved, there are unknown errors on parsing pages of JScript.NET & Visual Basic.NET as DOM. They can be load as DOMDocument (so that it is not a problem of url, eg.wrong encoding of url string), but can't get the required Node by getElementById inside the DOMDoc;
- Usage, this version need not config, as long as allow_url_fopen is enabled. Place this script in a server (local server or RC Site) some where can be access from www, and that is it.
- Tested with PHP 5.2.1
Sources:
<php><?php // may be need to enable allow_url_fopen, or change it to local file path define('RCHost' , 'rosettacode.org') ; define('ROSETTA', 'http://' . RCHost) ; // 3 version of url prefix, when loading the Specific Language Page, // they will be tried one by one define('SafeURL', ROSETTA . '/w/index.php?title=') ; define('Prefix', ROSETTA . '/wiki/Category:') ; define('LastTry', ROSETTA . '/wiki/') ; define('PAGENAME', 'PAGENAME') ; // if use as a query string key-value pair define('NA', 'Not Avaliable') ; define('TaskURL', Prefix . 'Solutions_by_Programming_Task') ; define('ListURL', Prefix . 'Solutions_by_Programming_Language') ; $langID = LangId() ; $IDLang = rawurldecode($langID) ; // this control how to access this scrtpt $scriptURL = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['URL'] ; function ScriptURL($langId = NA){ global $langID, $scriptURL ; if($langId == NA) $langId = $langID ; return $scriptURL . ($langId == NA ? "" : '?' . rawurlencode($langId)) ; } class Page extends DOMDocument { public $lnk , $id , $hdr, $msg , $tds ; public $dict = array() , $ok = FALSE ; public $cnt = 0 , $notCnt = 0 ; // $notCnt = count of not implemented tasks public $context ; function __construct($url, $id, $isLangFile = FALSE) { global $langID ; $this->id = $id ; if($isLangFile) { if($this->langURL(SafeURL)) // try one by one if($this->langURL(Prefix)) $this->langURL(LastTry) ; } else { @$this->loadHTMLFile($url) ; $this->context = $this->getElementById($this->id) ; } if($this->context) { $xpath = new DOMXPath($this) ; $this->hdr = $xpath->query('h2', $this->context)->item(0) ; $this->msg = $xpath->query('p', $this->context)->item(0) ; $this->lnk = $xpath->query('table/tr/td/ul/li', $this->context) ; if($this->lnk && $this->lnk->length > 0) { $this->cnt = $this->lnk->length ; $this->ok = TRUE ; } else { // not inside a table $this->lnk = $xpath->query('ul/li', $this->context) ; if($this->lnk) { // may be zero task completed? $this->cnt = $this->lnk->length ; $this->ok = TRUE ; } } } } function langURL($prefix) { global $langID ; $FAIL = TRUE ; if(@$this->loadHTMLFile($prefix . $langID)) if($this->context = $this->getElementById($this->id)) $FAIL = FALSE ; return $FAIL ; } function toHTML() { // not need if this script is inside RC site if(stristr($_SERVER['HTTP_HOST'], RCHost) === FALSE) { $head = $this->getElementsByTagName("head")->item(0) ; $base = $this->createElement("base") ; $base->setAttribute("href", ROSETTA) ; $head->insertBefore($base, $head->firstChild) ; } return $this->saveHTML() ; } function makeDict(&$taskList) { global $scriptURL ; $temp = array() ; // collect lang's task list for($i = 0 ; $i < $this->lnk->length ; $i++) { $alink = $this->lnk->item($i)->getElementsByTagName("a")->item(0) ; $href = $alink->getAttribute("href") ; $temp[$href] = TRUE ; } // set diff : total tasks - lang's tasks => not completed tasks for($i = 0 ; $i < $taskList->length ; $i++) { $alink = $taskList->item($i)->getElementsByTagName("a")->item(0) ; $href = $alink->getAttribute("href") ; if(array_key_exists($href, $temp) === FALSE) $this->dict[$this->notCnt++] = // import from Tasks to Lang $this->importNode($taskList->item($i),true) ; } // clone hdr, msg $hdr = $this->hdr->cloneNode(TRUE) ; $msg = $this->msg->cloneNode(TRUE) ; // clear All nodes under $this->context(id)'s node $context = $this->context ; $this->context = $context->cloneNode() ; // shallow copy, remove all child $context->parentNode->replaceChild($this->context, $context) ; // append hdr, msg back $this->hdr = $this->context->appendChild($hdr) ; $this->msg = $this->context->appendChild($msg) ; // make table $table = $this->createElement("table") ; $tr = $this->createElement("tr") ; for($i = 0 ; $i < 3 ; $i++) $tr->appendChild($this->createElement("td")) ; $table->appendChild($tr) ; $this->context->appendChild($table) ; // get tds later work with $xpath = new DOMXPath($this) ; $this->tds = $xpath->query('table/tr/td', $this->context) ; // insert a languages list link $alink = $this->createElement("a", "Other Languages") ; $alink->setAttribute("href", $scriptURL) ; $alink->setAttribute("title", "Not completed tasks by other languages") ; $style = 'float:right;clear:right;position:relative;top:8px;' . 'background-color:#eec;padding:2px 8px 2px 8px;'; $alink->setAttribute("style", $style) ; $this->context->insertBefore($alink, $this->hdr) ; } } function process_task(){ global $task, $lang ; if($lang->notCnt == 0) { $lang->msg->nodeValue = "All {$task->cnt} simpler tasks are completed ( {$lang->cnt} " . "total completed tasks, some implementations and puzzles may be " . "not yet completed )." ; // no more tasks below, add a height to the table to look like a void. $lang->tds->item(0)->setAttribute("height", "100px") ; } else { $lang->msg->nodeValue = "There are {$lang->notCnt} not completed tasks " . "out of {$task->cnt} total tasks ( {$lang->cnt} " . "completed tasks, implementations and puzzles etc.)." ; $curr = 0 ; $splitMax = intval(($lang->notCnt + 2) / 3) ; if($splitMax < 5) $splitMax = 5 ; $capital = ; $lang->lnk = null ; // release node ref. to be remove for($i = 0 ; $i < $lang->tds->length ; $i++) { $td = $lang->tds->item($i) ; $td->setAttribute("width", "33%") ; $td->setAttribute("valign", "top") ; $ul = NULL ; $splitCnt = 0 ; while($curr < $lang->notCnt && $splitCnt < $splitMax) { $li = $lang->dict[$curr] ; $heading = $capital ; $title = $li->getElementsByTagName("a")->item(0)->getAttribute("title") ; $capital = strtoupper(substr($title, 0, 1)) ; if($splitCnt == 0) { if($capital == $heading) $h3 = $lang->createElement("h3", $capital . " cont.") ; else $h3 = $lang->createElement("h3", $capital) ; $td->appendChild($h3) ; $ul = $lang->createElement("ul") ; } else if($capital != $heading) { $td->appendChild($ul) ; $h3 = $lang->createElement("h3", $capital) ; $td->appendChild($h3) ; $ul = $lang->createElement("ul") ; } $ul->appendChild($li) ; $curr++ ; $splitCnt++ ; } if($ul) $td->appendChild($ul) ; } } } function process_list(){ // replace languages link with corresponding scriptURL global $list ; for($i = 0 ; $i < $list->lnk->length ; $i++) { $alink = $list->lnk->item($i)->getElementsByTagName("a")->item(0) ; $href = $alink->getAttribute("href") ; $idLang = substr($href, 1 + strrpos($href,":")) ; $alink->setAttribute("href", ScriptURL($idLang)) ; } } function LangId(){ $langId = NA ; if(count($_GET) > 0) { if(array_key_exists(PAGENAME, $_GET) && strlen($_GET[PAGENAME]) > 0) $langId = $_GET[PAGENAME] ; else { $keys = array_keys($_GET) ; if(count($keys) > 0 && strlen($keys[0]) > 0) $langId = $keys[0] ; } } return $langId ; } /* * Main Body */ if($langID != NA) { $lang = new Page($langID, 'mw-pages', TRUE) ; if($lang->ok) { $task = new Page(TaskURL, 'mw-pages') ; if($task->ok) $lang->makeDict($task->lnk) ; } } if($langID != NA && $lang->ok && $task->ok) { $lang->hdr->nodeValue = 'Not Completed Tasks by ' . $IDLang ; process_task() ; echo $lang->toHTML() ; } else { $list = new Page(ListURL, 'mw-subcategories') ; if($list->ok) { if($langID == NA) $list->hdr->nodeValue = 'Not Completed Tasks by Languages' ; else $list->hdr->nodeValue = 'Not Completed Tasks by Languages ( "' . $IDLang . '" has no task completed or page error) ' ; process_list() ; echo $list->toHTML() ; } else echo ' <html><body> Unknown Error, <a href="' . ROSETTA . '">Return Rosetta Code Main Page</a> or <a href="javascript:history.go(-1) ;">Go Back</a>.</body></html>' ; } ?></php> |
Hope it can be a temporary solution. -- badmadevil 06:01, 16 June 2008 (MDT)