|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00012 require_once(dirname(__FILE__) . '/page.php'); 00013 require_once(dirname(__FILE__) . '/user_agent.php'); 00024 class SimpleFrameset { 00025 var $_frameset; 00026 var $_frames; 00027 var $_focus; 00028 var $_names; 00029 00035 function SimpleFrameset(&$page) { 00036 $this->_frameset = &$page; 00037 $this->_frames = array(); 00038 $this->_focus = false; 00039 $this->_names = array(); 00040 } 00041 00048 function addFrame(&$page, $name = false) { 00049 $this->_frames[] = &$page; 00050 if ($name) { 00051 $this->_names[$name] = count($this->_frames) - 1; 00052 } 00053 } 00054 00063 function setFrame($path, &$page) { 00064 $name = array_shift($path); 00065 if (isset($this->_names[$name])) { 00066 $index = $this->_names[$name]; 00067 } else { 00068 $index = $name - 1; 00069 } 00070 if (count($path) == 0) { 00071 $this->_frames[$index] = &$page; 00072 return; 00073 } 00074 $this->_frames[$index]->setFrame($path, $page); 00075 } 00076 00084 function getFrameFocus() { 00085 if ($this->_focus === false) { 00086 return array(); 00087 } 00088 return array_merge( 00089 array($this->_getPublicNameFromIndex($this->_focus)), 00090 $this->_frames[$this->_focus]->getFrameFocus()); 00091 } 00092 00101 function _getPublicNameFromIndex($subject) { 00102 foreach ($this->_names as $name => $index) { 00103 if ($subject == $index) { 00104 return $name; 00105 } 00106 } 00107 return $subject + 1; 00108 } 00109 00118 function setFrameFocusByIndex($choice) { 00119 if (is_integer($this->_focus)) { 00120 if ($this->_frames[$this->_focus]->hasFrames()) { 00121 return $this->_frames[$this->_focus]->setFrameFocusByIndex($choice); 00122 } 00123 } 00124 if (($choice < 1) || ($choice > count($this->_frames))) { 00125 return false; 00126 } 00127 $this->_focus = $choice - 1; 00128 return true; 00129 } 00130 00139 function setFrameFocus($name) { 00140 if (is_integer($this->_focus)) { 00141 if ($this->_frames[$this->_focus]->hasFrames()) { 00142 return $this->_frames[$this->_focus]->setFrameFocus($name); 00143 } 00144 } 00145 if (in_array($name, array_keys($this->_names))) { 00146 $this->_focus = $this->_names[$name]; 00147 return true; 00148 } 00149 return false; 00150 } 00151 00156 function clearFrameFocus() { 00157 $this->_focus = false; 00158 $this->_clearNestedFramesFocus(); 00159 } 00160 00165 function _clearNestedFramesFocus() { 00166 for ($i = 0; $i < count($this->_frames); $i++) { 00167 $this->_frames[$i]->clearFrameFocus(); 00168 } 00169 } 00170 00176 function hasFrames() { 00177 return true; 00178 } 00179 00187 function getFrames() { 00188 $report = array(); 00189 for ($i = 0; $i < count($this->_frames); $i++) { 00190 $report[$this->_getPublicNameFromIndex($i)] = 00191 $this->_frames[$i]->getFrames(); 00192 } 00193 return $report; 00194 } 00195 00202 function getRaw() { 00203 if (is_integer($this->_focus)) { 00204 return $this->_frames[$this->_focus]->getRaw(); 00205 } 00206 $raw = ''; 00207 for ($i = 0; $i < count($this->_frames); $i++) { 00208 $raw .= $this->_frames[$i]->getRaw(); 00209 } 00210 return $raw; 00211 } 00212 00219 function getText() { 00220 if (is_integer($this->_focus)) { 00221 return $this->_frames[$this->_focus]->getText(); 00222 } 00223 $raw = ''; 00224 for ($i = 0; $i < count($this->_frames); $i++) { 00225 $raw .= ' ' . $this->_frames[$i]->getText(); 00226 } 00227 return trim($raw); 00228 } 00229 00235 function getTransportError() { 00236 if (is_integer($this->_focus)) { 00237 return $this->_frames[$this->_focus]->getTransportError(); 00238 } 00239 return $this->_frameset->getTransportError(); 00240 } 00241 00247 function getMethod() { 00248 if (is_integer($this->_focus)) { 00249 return $this->_frames[$this->_focus]->getMethod(); 00250 } 00251 return $this->_frameset->getMethod(); 00252 } 00253 00259 function getUrl() { 00260 if (is_integer($this->_focus)) { 00261 $url = $this->_frames[$this->_focus]->getUrl(); 00262 $url->setTarget($this->_getPublicNameFromIndex($this->_focus)); 00263 } else { 00264 $url = $this->_frameset->getUrl(); 00265 } 00266 return $url; 00267 } 00268 00274 function getBaseUrl() { 00275 if (is_integer($this->_focus)) { 00276 $url = $this->_frames[$this->_focus]->getBaseUrl(); 00277 } else { 00278 $url = $this->_frameset->getBaseUrl(); 00279 } 00280 return $url; 00281 } 00282 00290 function expandUrl($url) { 00291 return $this->_frameset->expandUrl($url); 00292 } 00293 00299 function getRequestData() { 00300 if (is_integer($this->_focus)) { 00301 return $this->_frames[$this->_focus]->getRequestData(); 00302 } 00303 return $this->_frameset->getRequestData(); 00304 } 00305 00311 function getMimeType() { 00312 if (is_integer($this->_focus)) { 00313 return $this->_frames[$this->_focus]->getMimeType(); 00314 } 00315 return $this->_frameset->getMimeType(); 00316 } 00317 00323 function getResponseCode() { 00324 if (is_integer($this->_focus)) { 00325 return $this->_frames[$this->_focus]->getResponseCode(); 00326 } 00327 return $this->_frameset->getResponseCode(); 00328 } 00329 00336 function getAuthentication() { 00337 if (is_integer($this->_focus)) { 00338 return $this->_frames[$this->_focus]->getAuthentication(); 00339 } 00340 return $this->_frameset->getAuthentication(); 00341 } 00342 00349 function getRealm() { 00350 if (is_integer($this->_focus)) { 00351 return $this->_frames[$this->_focus]->getRealm(); 00352 } 00353 return $this->_frameset->getRealm(); 00354 } 00355 00361 function getRequest() { 00362 if (is_integer($this->_focus)) { 00363 return $this->_frames[$this->_focus]->getRequest(); 00364 } 00365 return $this->_frameset->getRequest(); 00366 } 00367 00373 function getHeaders() { 00374 if (is_integer($this->_focus)) { 00375 return $this->_frames[$this->_focus]->getHeaders(); 00376 } 00377 return $this->_frameset->getHeaders(); 00378 } 00379 00385 function getTitle() { 00386 return $this->_frameset->getTitle(); 00387 } 00388 00394 function getUrls() { 00395 if (is_integer($this->_focus)) { 00396 return $this->_frames[$this->_focus]->getUrls(); 00397 } 00398 $urls = array(); 00399 foreach ($this->_frames as $frame) { 00400 $urls = array_merge($urls, $frame->getUrls()); 00401 } 00402 return array_values(array_unique($urls)); 00403 } 00404 00412 function getUrlsByLabel($label) { 00413 if (is_integer($this->_focus)) { 00414 return $this->_tagUrlsWithFrame( 00415 $this->_frames[$this->_focus]->getUrlsByLabel($label), 00416 $this->_focus); 00417 } 00418 $urls = array(); 00419 foreach ($this->_frames as $index => $frame) { 00420 $urls = array_merge( 00421 $urls, 00422 $this->_tagUrlsWithFrame( 00423 $frame->getUrlsByLabel($label), 00424 $index)); 00425 } 00426 return $urls; 00427 } 00428 00438 function getUrlById($id) { 00439 foreach ($this->_frames as $index => $frame) { 00440 if ($url = $frame->getUrlById($id)) { 00441 if (! $url->gettarget()) { 00442 $url->setTarget($this->_getPublicNameFromIndex($index)); 00443 } 00444 return $url; 00445 } 00446 } 00447 return false; 00448 } 00449 00457 function _tagUrlsWithFrame($urls, $frame) { 00458 $tagged = array(); 00459 foreach ($urls as $url) { 00460 if (! $url->getTarget()) { 00461 $url->setTarget($this->_getPublicNameFromIndex($frame)); 00462 } 00463 $tagged[] = $url; 00464 } 00465 return $tagged; 00466 } 00467 00476 function &getFormBySubmit($selector) { 00477 $form = &$this->_findForm('getFormBySubmit', $selector); 00478 return $form; 00479 } 00480 00491 function &getFormByImage($selector) { 00492 $form = &$this->_findForm('getFormByImage', $selector); 00493 return $form; 00494 } 00495 00506 function &getFormById($id) { 00507 $form = &$this->_findForm('getFormById', $id); 00508 return $form; 00509 } 00510 00519 function &_findForm($method, $attribute) { 00520 if (is_integer($this->_focus)) { 00521 $form = &$this->_findFormInFrame( 00522 $this->_frames[$this->_focus], 00523 $this->_focus, 00524 $method, 00525 $attribute); 00526 return $form; 00527 } 00528 for ($i = 0; $i < count($this->_frames); $i++) { 00529 $form = &$this->_findFormInFrame( 00530 $this->_frames[$i], 00531 $i, 00532 $method, 00533 $attribute); 00534 if ($form) { 00535 return $form; 00536 } 00537 } 00538 $null = null; 00539 return $null; 00540 } 00541 00552 function &_findFormInFrame(&$page, $index, $method, $attribute) { 00553 $form = &$this->_frames[$index]->$method($attribute); 00554 if (isset($form)) { 00555 $form->setDefaultTarget($this->_getPublicNameFromIndex($index)); 00556 } 00557 return $form; 00558 } 00559 00568 function setField($selector, $value) { 00569 if (is_integer($this->_focus)) { 00570 $this->_frames[$this->_focus]->setField($selector, $value); 00571 } else { 00572 for ($i = 0; $i < count($this->_frames); $i++) { 00573 $this->_frames[$i]->setField($selector, $value); 00574 } 00575 } 00576 } 00577 00586 function getField($selector) { 00587 for ($i = 0; $i < count($this->_frames); $i++) { 00588 $value = $this->_frames[$i]->getField($selector); 00589 if (isset($value)) { 00590 return $value; 00591 } 00592 } 00593 return null; 00594 } 00595 } 00596 ?>