[system] / trunk / wwmoodle / wwquestion / locallib.php Repository:
ViewVC logotype

View of /trunk/wwmoodle/wwquestion/locallib.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5477 - (download) (as text) (annotate)
Sun Sep 9 02:53:16 2007 UTC (12 years, 5 months ago) by mleventi
File size: 23588 byte(s)
*** empty log message ***

    1 <?php
    2 
    3 require_once("$CFG->dirroot/question/type/webwork/config.php");
    4 require_once("$CFG->libdir/soap/nusoap.php");
    5 require_once("$CFG->libdir/filelib.php");
    6 require_once("$CFG->libdir/setuplib.php");
    7 require_once("$CFG->libdir/formslib.php");
    8 
    9 /**
   10 * @desc Gets derived questions from a webworkquestion record object by calling the SOAP server.
   11 * @param $webworkquestion The record to create from
   12 * @return $response The recordset from the WeBWorK Question Server.
   13 */
   14 function webwork_get_derivations($wwquestion) {
   15     //parameters needed from the webworkquestion object
   16     $code = $wwquestion->code;
   17     $seed = $wwquestion->seed;
   18     $trials = $wwquestion->trials;
   19     $files = $wwquestion->files;
   20 
   21     //problem to be generated
   22     $problem = array();
   23     $problem['code'] = $code;
   24     $problem['seed'] = $seed;
   25     $problem['files'] = $files;
   26 
   27     //requested # times for generation
   28     $request = array();
   29     $request['trials'] = $trials;
   30     $request['problem'] = $problem;
   31 
   32     //SOAP CALL
   33     $params = array($request);
   34     $client = new webwork_client();
   35     $response = $client->handler('generateProblem',$params);
   36     return $response;
   37 }
   38 
   39 /**
   40 * @desc Deletes a wwquestion directory
   41 * @param integer $wwquestionid The id of the wwquestion.
   42 * @return bool true
   43 */
   44 function webwork_delete_wwquestion_dir($wwquestionid) {
   45     global $CFG;
   46     fulldelete($CFG->dataroot . WWQUESTION_ROOTDIR . '/' . $wwquestionid . '/');
   47     return true;
   48 }
   49 
   50 /**
   51 * @desc Deletes derivation db records for a wwquestion
   52 * @param integer $wwquestionid The id of the wwquestion.
   53 * @return bool true
   54 */
   55 function webwork_delete_derivations_db($wwquestionid) {
   56     delete_records("question_webwork_derived", "question_webwork", $wwquestionid);
   57     return true;
   58 }
   59 
   60 /**
   61 * @desc Deletes all derivations of a wwquestion.
   62 * @param integer $wwquestionid The id of the wwquestion.
   63 * @return bool true
   64 */
   65 function webwork_delete_derivations($wwquestionid) {
   66     $recordset = get_records('question_webwork_derived','question_webwork',$wwquestionid);
   67     foreach($recordset as $record) {
   68         $derivationid = $record->id;
   69         webwork_delete_derivation_dir($wwquestionid,$derivationid);
   70     }
   71     delete_records("question_webwork_derived", "question_webwork", $wwquestionid);
   72     return true;
   73 }
   74 
   75 /**
   76 * @desc Deletes a derivation db record
   77 * @param integer $derivationid The derivation id.
   78 * @return bool true
   79 */
   80 function webwork_delete_derivation_db($derivationid) {
   81     delete_records('question_webwork_derived','id',$derivationid);
   82     return true;
   83 }
   84 
   85 /**
   86 * @desc Deletes a derivation's directory.
   87 * @param integer $wwquestionid The wwquestion id.
   88 * @param integer $derivationid The derivation's id.
   89 * @return bool true.
   90 */
   91 function webwork_delete_derivation_dir($wwquestionid, $derivationid) {
   92     global $CFG;
   93     $dirpath = $CFG->dataroot . webwork_get_derivation_path($wwquestionid, $derivationid);
   94     fulldelete($dirpath);
   95     return true;
   96 }
   97 
   98 /**
   99 * @desc Parses an answer's preview html to change the image src path. Copies images into user data on a derivation.
  100 * @param string $html The preview answer html.
  101 * @param string $replacer The new src url path.
  102 * @param string $copyto The place to copy the image to.
  103 */
  104 function webwork_parse_change_ans($html,$replacer,$copyto) {
  105     $parsedhtml = "";
  106     $parser = new HtmlParser($html);
  107     while($parser->parse()) {
  108         if($parser->iNodeType == NODE_TYPE_ELEMENT) {
  109             $name = $parser->iNodeName;
  110             if(strcasecmp($name,'img') == 0) {
  111                 $src = $parser->iNodeAttributes['src'];
  112                 //an equation, need to copy
  113                 $srccapture = strrchr($src,'/');
  114                 webwork_copy_file($src,$copyto . $srccapture);
  115                 $parser->iNodeAttributes['src'] = $replacer . $srccapture;
  116             }
  117         }
  118         $parsedhtml .= $parser->printTag();
  119     }
  120     return $parsedhtml;
  121 }
  122 
  123 /**
  124 * @desc Parses a derivation record. This changes all paths of external entities. Copies all external entities to local data folder.
  125 * @param object $derivation The derivation object.
  126 * @return bool true.
  127 */
  128 function webwork_parse_change_derivation(&$derivation) {
  129     //webwork question id
  130     $wwquestionid = $derivation->question_webwork;
  131     //assign paths
  132     $wwquestioncopyto = webwork_get_wwquestion_path_full($wwquestionid);
  133     $wwquestionreplacer = webwork_get_wwquestion_url($wwquestionid);
  134     $derivationcopyto = webwork_get_derivation_path_full($wwquestionid,$derivation->id);
  135     $derivationreplacer = webwork_get_derivation_url($wwquestionid,$derivation->id);
  136     $parsedhtml = "";
  137     $html = base64_decode($derivation->html);
  138     $parser = new HtmlParser($html);
  139     while($parser->parse()) {
  140         if($parser->iNodeType == NODE_TYPE_ELEMENT) {
  141             $nodename = $parser->iNodeName;
  142             if(strcasecmp($nodename,'img') == 0) {
  143                 //image, path fixing
  144                 if(isset($parser->iNodeAttributes['src'])) {
  145                     $src = $parser->iNodeAttributes['src'];
  146                     if(!(strstr($src,'/tmp/') == false)) {
  147                         //image produced by the server
  148                         $srccapture = strrchr($src,'/');
  149                         webwork_copy_file($src,$derivationcopyto . $srccapture);
  150                         $parser->iNodeAttributes['src'] = $derivationreplacer . $srccapture;
  151                     }
  152                 }
  153             } else if(strcasecmp($nodename,'a') == 0) {
  154                 //hyperlink, path fixing
  155                 if(isset($parser->iNodeAttributes['href'])) {
  156                     $href = $parser->iNodeAttributes['href'];
  157                     $hrefcapture = strrchr($href,'/');
  158                     webwork_copy_file($href,$derivationcopyto . $hrefcapture);
  159                     $parser->iNodeAttributes['href'] = $derivationreplacer . $hrefcapture;
  160                 }
  161             }
  162         }
  163         $parsedhtml .= $parser->printTag();
  164     }
  165     $derivation->html = base64_encode($parsedhtml);
  166     return true;
  167 }
  168 
  169 //////////////////////////////////////////////////////////////////////////////////
  170 //WEBWORK FILE RESOLVERS
  171 //////////////////////////////////////////////////////////////////////////////////
  172 
  173 //These functions return paths to different resources in the filesystem
  174 
  175 
  176     function webwork_get_derivation_user_url($wwquestionid,$derivationid,$userid) {
  177         return webwork_get_filehandler_path() . webwork_get_derivation_user_path($wwquestionid,$derivationid,$userid);
  178     }
  179 
  180     function webwork_get_derivation_user_path_full($wwquestionid,$derivationid,$userid) {
  181         global $CFG;
  182         return $CFG->dataroot . webwork_get_derivation_user_path($wwquestionid,$derivationid,$userid);
  183     }
  184 
  185     function webwork_get_derivation_user_path($wwquestionid,$derivationid,$userid) {
  186         return webwork_get_derivation_path($wwquestionid,$derivationid) . '/users/' . $userid;
  187     }
  188 
  189     function webwork_get_derivation_url($wwquestionid, $derivationid) {
  190         return webwork_get_filehandler_path() . webwork_get_derivation_path($wwquestionid,$derivationid);
  191     }
  192 
  193     function webwork_get_derivation_path_full($wwquestionid, $derivationid) {
  194         global $CFG;
  195         return $CFG->dataroot . webwork_get_derivation_path($wwquestionid, $derivationid);
  196     }
  197 
  198     function webwork_get_derivation_path($wwquestionid, $derivationid) {
  199         return WWQUESTION_ROOTDIR . '/' . $wwquestionid . '/derivations/' . $derivationid;
  200     }
  201 
  202     function webwork_get_wwquestion_url($wwquestionid) {
  203         return webwork_get_filehandler_path() . webwork_get_wwquestion_path($wwquestionid);
  204     }
  205 
  206     function webwork_get_wwquestion_path_full($wwquestionid) {
  207         global $CFG;
  208         return $CFG->dataroot . webwork_get_wwquestion_path($wwquestionid);
  209     }
  210 
  211     function webwork_get_wwquestion_path($wwquestionid) {
  212         return WWQUESTION_ROOTDIR . '/' . $wwquestionid;
  213     }
  214 
  215     function webwork_get_filemanager_url($wwquestionid) {
  216         global $CFG;
  217         return $CFG->wwwroot . "/question/type/webwork/files.php?id=".SITEID.'&qid='.$wwquestionid;
  218     }
  219 
  220     function webwork_get_tmp_path_full() {
  221         global $CFG;
  222         return $CFG->dataroot . webwork_get_tmp_path();
  223     }
  224 
  225     function webwork_get_tmp_path() {
  226         global $USER;
  227         return WWQUESTION_ROOTDIR . '/tmp' . $USER->id;
  228     }
  229 
  230     function webwork_get_filehandler_path() {
  231         global $CFG;
  232         return $CFG->wwwroot . "/question/type/webwork/file.php";
  233     }
  234 
  235     function webwork_make_tmp_dir() {
  236         return make_upload_directory(webwork_get_tmp_path());
  237     }
  238 
  239     /**
  240     * @desc Copies a file if needed from $srcpath to $dstpath.
  241     * @param $srcpath string The source.
  242     * @param $dstpath string The destination.
  243     * @return bool true
  244     */
  245     function webwork_copy_file($srcpath,$dstpath) {
  246         if(!file_exists($dstpath)) {
  247             $err = copy($srcpath,$dstpath);
  248             if($err == false) {
  249                 print_error("Copy Failed for: '".$srcpath."' to '".$dstpath."'");
  250                 return false;
  251             }
  252         }
  253         return true;
  254     }
  255 
  256     /**
  257     * @desc Makes a directory for a derivation.
  258     * @param $wwquestionid integer The id of a webwork_question.
  259     * @param $derivationid integer The id of a derivation.
  260     * @return bool true.
  261     */
  262     function webwork_make_derivation_dir($wwquestionid,$derivationid) {
  263         return make_upload_directory(webwork_get_derivation_path($wwquestionid,$derivationid));
  264     }
  265 
  266     /**
  267     * @desc Makes a directory for a derivation for a specific user.
  268     * @param $wwquestionid integer The id of a webwork_question.
  269     * @param $derivationid integer The id of a derivation.
  270     * @param $userid integer The id of a user.
  271     * @return bool true.
  272     */
  273     function webwork_make_derivation_user_dir($wwquestionid,$derivationid,$userid) {
  274         return make_upload_directory(webwork_get_derivation_user_path($wwquestionid,$derivationid,$userid));
  275     }
  276 
  277     /**
  278     * @desc Makes a directory for a wwquestion.
  279     * @param integer $wwquestionid The wwquestion id.
  280     * @return bool directory creation.
  281     */
  282     function webwork_make_wwquestion_dir($wwquestionid) {
  283         return make_upload_directory(webwork_get_wwquestion_path($wwquestionid));
  284     }
  285 
  286 //////////////////////////////////////////////////////////////////////////////////
  287 //WEBWORK CLIENT
  288 //////////////////////////////////////////////////////////////////////////////////
  289 
  290 /**
  291 * @desc Singleton class that contains function for communication to the WeBWorK Question Server.
  292 */
  293 class webwork_client {
  294     var $client;
  295 
  296     /**
  297     * @desc Constructs a singleton problemserver_client. Uses nusoap libraries php(4 & 5)
  298     */
  299     function webwork_client() {
  300         //static associative array containing the real objects, key is classname
  301         static $instances=array();
  302         //get classname
  303         $class = get_class($this);
  304         if (!array_key_exists($class, $instances)) {
  305             //does not yet exist, save in array
  306             $this->client = new soap_client(WWQUESTION_WSDL,'wsdl',false,false,false,false,0,WWQUESTION_RESPONSE_TIMEOUT);
  307             $err = $this->client->getError();
  308             if ($err) {
  309                 print_error($err . " " . get_string('error_client_construction','qtype_webwork'));
  310             }
  311             $instances[$class] = $this;
  312         }
  313         foreach (get_class_vars($class) as $var => $value) {
  314             $this->$var =& $instances[$class]->$var;
  315         }
  316     }
  317 
  318     /**
  319     * @desc Calls a SOAP function on the server.
  320     * @param string $functioncall The function to call
  321     * @param array $params The parameters to the function.
  322     * @return Result of the soap function.
  323     */
  324     function handler($functioncall,$params=array()) {
  325         if(!is_array($params)) {
  326             $params = array($params);
  327         }
  328         $result = $this->client->call($functioncall,$params);
  329         //$result = call_user_func_array(array(&$this->client,$functioncall),$params);
  330         if($err = $this->client->getError()) {
  331             //print_error(get_string("rpc_fault","wwassignment') . " " . $functioncall. " ". $err);
  332             print_error($err . " " . get_string('error_client_call','qtype_webwork'));
  333         }
  334         return $result;
  335     }
  336 }
  337 
  338 //////////////////////////////////////////////////////////////////////////////////
  339 //HTML PARSER
  340 //////////////////////////////////////////////////////////////////////////////////
  341 
  342 /*
  343  * Copyright (c) 2003 Jose Solorzano.  All rights reserved.
  344  * Redistribution of source must retain this copyright notice.
  345  *
  346  * Jose Solorzano (http://jexpert.us) is a software consultant.
  347  *
  348  * Contributions by:
  349  * - Leo West (performance improvements)
  350  */
  351 
  352 define ("NODE_TYPE_START",0);
  353 define ("NODE_TYPE_ELEMENT",1);
  354 define ("NODE_TYPE_ENDELEMENT",2);
  355 define ("NODE_TYPE_TEXT",3);
  356 define ("NODE_TYPE_COMMENT",4);
  357 define ("NODE_TYPE_DONE",5);
  358 
  359 /**
  360  * Class HtmlParser.
  361  * To use, create an instance of the class passing
  362  * HTML text. Then invoke parse() until it's false.
  363  * When parse() returns true, $iNodeType, $iNodeName
  364  * $iNodeValue and $iNodeAttributes are updated.
  365  *
  366  * To create an HtmlParser instance you may also
  367  * use convenience functions HtmlParser_ForFile
  368  * and HtmlParser_ForURL.
  369  */
  370 class HtmlParser {
  371 
  372     /**
  373      * Field iNodeType.
  374      * May be one of the NODE_TYPE_* constants above.
  375      */
  376     var $iNodeType;
  377 
  378     /**
  379      * Field iNodeName.
  380      * For elements, it's the name of the element.
  381      */
  382     var $iNodeName = "";
  383 
  384     /**
  385      * Field iNodeValue.
  386      * For text nodes, it's the text.
  387      */
  388     var $iNodeValue = "";
  389 
  390     /**
  391      * Field iNodeAttributes.
  392      * A string-indexed array containing attribute values
  393      * of the current node. Indexes are always lowercase.
  394      */
  395     var $iNodeAttributes;
  396 
  397     // The following fields should be
  398     // considered private:
  399 
  400     var $iHtmlText;
  401     var $iHtmlTextLength;
  402     var $iHtmlTextIndex = 0;
  403     var $iHtmlCurrentChar;
  404     var $BOE_ARRAY;
  405     var $B_ARRAY;
  406     var $BOS_ARRAY;
  407 
  408     /**
  409      * Constructor.
  410      * Constructs an HtmlParser instance with
  411      * the HTML text given.
  412      */
  413     function HtmlParser ($aHtmlText) {
  414         $this->iHtmlText = $aHtmlText;
  415         $this->iHtmlTextLength = strlen($aHtmlText);
  416         $this->iNodeAttributes = array();
  417         $this->setTextIndex (0);
  418 
  419         $this->BOE_ARRAY = array (" ", "\t", "\r", "\n", "=" );
  420         $this->B_ARRAY = array (" ", "\t", "\r", "\n" );
  421         $this->BOS_ARRAY = array (" ", "\t", "\r", "\n", "/" );
  422     }
  423 
  424     /**
  425      * Method parse.
  426      * Parses the next node. Returns false only if
  427      * the end of the HTML text has been reached.
  428      * Updates values of iNode* fields.
  429      */
  430     function parse() {
  431         $text = $this->skipToElement();
  432         if ($text != "") {
  433             $this->iNodeType = NODE_TYPE_TEXT;
  434             $this->iNodeName = "Text";
  435             $this->iNodeValue = $text;
  436             return true;
  437         }
  438         return $this->readTag();
  439     }
  440 
  441     function printTag() {
  442         if($this->iNodeType == NODE_TYPE_ELEMENT) {
  443             $temp = "<";
  444             $temp .= $this->iNodeName;
  445             if(isset($this->iNodeAttributes['selected'])) {
  446                 $temp .= " selected";
  447             }
  448             foreach($this->iNodeAttributes as $key => $value) {
  449                 if($key == 'selected') {
  450                 } else {
  451                     $temp .= " " . $key . "=" . '"' . $value . '"';
  452                 }
  453             }
  454             $temp .= ">";
  455         } else if($this->iNodeType == NODE_TYPE_ENDELEMENT) {
  456             $temp = "</" . $this->iNodeName . ">";
  457         } else if($this->iNodeType == NODE_TYPE_TEXT) {
  458             $temp = $this->iNodeValue;
  459         } else {
  460         }
  461         return $temp;
  462 
  463 
  464     }
  465 
  466     function clearAttributes() {
  467         $this->iNodeAttributes = array();
  468     }
  469 
  470     function readTag() {
  471         if ($this->iCurrentChar != "<") {
  472             $this->iNodeType = NODE_TYPE_DONE;
  473             return false;
  474         }
  475         $this->clearAttributes();
  476         $this->skipMaxInTag ("<", 1);
  477         if ($this->iCurrentChar == '/') {
  478             $this->moveNext();
  479             $name = $this->skipToBlanksInTag();
  480             $this->iNodeType = NODE_TYPE_ENDELEMENT;
  481             $this->iNodeName = $name;
  482             $this->iNodeValue = "";
  483             $this->skipEndOfTag();
  484             return true;
  485         }
  486         $name = $this->skipToBlanksOrSlashInTag();
  487         if (!$this->isValidTagIdentifier ($name)) {
  488                 $comment = false;
  489                 if (strpos($name, "!--") === 0) {
  490                     $ppos = strpos($name, "--", 3);
  491                     if (strpos($name, "--", 3) === (strlen($name) - 2)) {
  492                         $this->iNodeType = NODE_TYPE_COMMENT;
  493                         $this->iNodeName = "Comment";
  494                         $this->iNodeValue = "<" . $name . ">";
  495                         $comment = true;
  496                     }
  497                     else {
  498                         $rest = $this->skipToStringInTag ("-->");
  499                         if ($rest != "") {
  500                             $this->iNodeType = NODE_TYPE_COMMENT;
  501                             $this->iNodeName = "Comment";
  502                             $this->iNodeValue = "<" . $name . $rest;
  503                             $comment = true;
  504                             // Already skipped end of tag
  505                             return true;
  506                         }
  507                     }
  508                 }
  509                 if (!$comment) {
  510                     $this->iNodeType = NODE_TYPE_TEXT;
  511                     $this->iNodeName = "Text";
  512                     $this->iNodeValue = "<" . $name;
  513                     return true;
  514                 }
  515         }
  516         else {
  517                 $this->iNodeType = NODE_TYPE_ELEMENT;
  518                 $this->iNodeValue = "";
  519                 $this->iNodeName = $name;
  520                 while ($this->skipBlanksInTag()) {
  521                     $attrName = $this->skipToBlanksOrEqualsInTag();
  522                     if ($attrName != "" && $attrName != "/") {
  523                         $this->skipBlanksInTag();
  524                         if ($this->iCurrentChar == "=") {
  525                             $this->skipEqualsInTag();
  526                             $this->skipBlanksInTag();
  527                             $value = $this->readValueInTag();
  528                             $this->iNodeAttributes[strtolower($attrName)] = $value;
  529                         }
  530                         else {
  531                             $this->iNodeAttributes[strtolower($attrName)] = "";
  532                         }
  533                     }
  534                 }
  535         }
  536         $this->skipEndOfTag();
  537         return true;
  538     }
  539 
  540     function isValidTagIdentifier ($name) {
  541         return ereg ("^[A-Za-z0-9_\\-]+$", $name);
  542     }
  543 
  544     function skipBlanksInTag() {
  545         return "" != ($this->skipInTag ($this->B_ARRAY));
  546     }
  547 
  548     function skipToBlanksOrEqualsInTag() {
  549         return $this->skipToInTag ($this->BOE_ARRAY);
  550     }
  551 
  552     function skipToBlanksInTag() {
  553         return $this->skipToInTag ($this->B_ARRAY);
  554     }
  555 
  556     function skipToBlanksOrSlashInTag() {
  557         return $this->skipToInTag ($this->BOS_ARRAY);
  558     }
  559 
  560     function skipEqualsInTag() {
  561         return $this->skipMaxInTag ("=", 1);
  562     }
  563 
  564     function readValueInTag() {
  565         $ch = $this->iCurrentChar;
  566         $value = "";
  567         if ($ch == "\"") {
  568             $this->skipMaxInTag ("\"", 1);
  569             $value = $this->skipToInTag ("\"");
  570             $this->skipMaxInTag ("\"", 1);
  571         }
  572         else if ($ch == "'") {
  573             $this->skipMaxInTag ("'", 1);
  574             $value = $this->skipToInTag ("'");
  575             $this->skipMaxInTag ("'", 1);
  576         }
  577         else {
  578             $value = $this->skipToBlanksInTag();
  579         }
  580         return $value;
  581     }
  582 
  583     function setTextIndex ($index) {
  584         $this->iHtmlTextIndex = $index;
  585         if ($index >= $this->iHtmlTextLength) {
  586             $this->iCurrentChar = -1;
  587         }
  588         else {
  589             $this->iCurrentChar = $this->iHtmlText{$index};
  590         }
  591     }
  592 
  593     function moveNext() {
  594         if ($this->iHtmlTextIndex < $this->iHtmlTextLength) {
  595             $this->setTextIndex ($this->iHtmlTextIndex + 1);
  596             return true;
  597         }
  598         else {
  599             return false;
  600         }
  601     }
  602 
  603     function skipEndOfTag() {
  604         while (($ch = $this->iCurrentChar) !== -1) {
  605             if ($ch == ">") {
  606                 $this->moveNext();
  607                 return;
  608             }
  609             $this->moveNext();
  610         }
  611     }
  612 
  613     function skipInTag ($chars) {
  614         $sb = "";
  615         while (($ch = $this->iCurrentChar) !== -1) {
  616             if ($ch == ">") {
  617                 return $sb;
  618             } else {
  619                 $match = false;
  620                 for ($idx = 0; $idx < count($chars); $idx++) {
  621                     if ($ch == $chars[$idx]) {
  622                         $match = true;
  623                         break;
  624                     }
  625                 }
  626                 if (!$match) {
  627                     return $sb;
  628                 }
  629                 $sb .= $ch;
  630                 $this->moveNext();
  631             }
  632         }
  633         return $sb;
  634     }
  635 
  636     function skipMaxInTag ($chars, $maxChars) {
  637         $sb = "";
  638         $count = 0;
  639         while (($ch = $this->iCurrentChar) !== -1 && $count++ < $maxChars) {
  640             if ($ch == ">") {
  641                 return $sb;
  642             } else {
  643                 $match = false;
  644                 for ($idx = 0; $idx < count($chars); $idx++) {
  645                     if ($ch == $chars[$idx]) {
  646                         $match = true;
  647                         break;
  648                     }
  649                 }
  650                 if (!$match) {
  651                     return $sb;
  652                 }
  653                 $sb .= $ch;
  654                 $this->moveNext();
  655             }
  656         }
  657         return $sb;
  658     }
  659 
  660     function skipToInTag ($chars) {
  661         $sb = "";
  662         while (($ch = $this->iCurrentChar) !== -1) {
  663             $match = $ch == ">";
  664             if (!$match) {
  665                 for ($idx = 0; $idx < count($chars); $idx++) {
  666                     if ($ch == $chars[$idx]) {
  667                         $match = true;
  668                         break;
  669                     }
  670                 }
  671             }
  672             if ($match) {
  673                 return $sb;
  674             }
  675             $sb .= $ch;
  676             $this->moveNext();
  677         }
  678         return $sb;
  679     }
  680 
  681     function skipToElement() {
  682         $sb = "";
  683         while (($ch = $this->iCurrentChar) !== -1) {
  684             if ($ch == "<") {
  685                 return $sb;
  686             }
  687             $sb .= $ch;
  688             $this->moveNext();
  689         }
  690         return $sb;
  691     }
  692 
  693     /**
  694      * Returns text between current position and $needle,
  695      * inclusive, or "" if not found. The current index is moved to a point
  696      * after the location of $needle, or not moved at all
  697      * if nothing is found.
  698      */
  699     function skipToStringInTag ($needle) {
  700         $pos = strpos ($this->iHtmlText, $needle, $this->iHtmlTextIndex);
  701         if ($pos === false) {
  702             return "";
  703         }
  704         $top = $pos + strlen($needle);
  705         $retvalue = substr ($this->iHtmlText, $this->iHtmlTextIndex, $top - $this->iHtmlTextIndex);
  706         $this->setTextIndex ($top);
  707         return $retvalue;
  708     }
  709 }
  710 
  711 ?>

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9