phpQueryObject::whois PHP Méthode

whois() public méthode

HELPERS
public whois ( $oneNode = null )
    public function whois($oneNode = null)
    {
        $return = array();
        $loop = $oneNode ? array($oneNode) : $this->elements;
        foreach ($loop as $node) {
            if (isset($node->tagName)) {
                $tag = in_array($node->tagName, array('php', 'js')) ? strtoupper($node->tagName) : $node->tagName;
                $return[] = $tag . ($node->getAttribute('id') ? '#' . $node->getAttribute('id') : '') . ($node->getAttribute('class') ? '.' . implode('.', split(' ', $node->getAttribute('class'))) : '') . ($node->getAttribute('name') ? '[name="' . $node->getAttribute('name') . '"]' : '') . ($node->getAttribute('value') && strpos($node->getAttribute('value'), '<' . '?php') === false ? '[value="' . substr(str_replace("\n", '', $node->getAttribute('value')), 0, 15) . '"]' : '') . ($node->getAttribute('value') && strpos($node->getAttribute('value'), '<' . '?php') !== false ? '[value=PHP]' : '') . ($node->getAttribute('selected') ? '[selected]' : '') . ($node->getAttribute('checked') ? '[checked]' : '');
            } elseif ($node instanceof DOMTEXT) {
                if (trim($node->textContent)) {
                    $return[] = 'Text:' . substr(str_replace("\n", ' ', $node->textContent), 0, 15);
                }
            } else {
            }
        }
        return $oneNode && isset($return[0]) ? $return[0] : $return;
    }

Usage Example

 /**
  * Trigger a type of event on every matched element.
  *
  * @param DOMNode|phpQueryObject|string $document
  * @param unknown_type $type
  * @param unknown_type $data
  *
  * @TODO exclusive events (with !)
  * @TODO global events (test)
  * @TODO support more than event in $type (space-separated)
  */
 public static function trigger($document, $type, $data = array(), $node = null)
 {
     // trigger: function(type, data, elem, donative, extra) {
     $documentID = phpQuery::getDocumentID($document);
     $namespace = null;
     if (strpos($type, '.') !== false) {
         list($name, $namespace) = explode('.', $type);
     } else {
         $name = $type;
     }
     if (!$node) {
         if (self::issetGlobal($documentID, $type)) {
             $pq = phpQuery::getDocument($documentID);
             // TODO check add($pq->document)
             $pq->find('*')->add($pq->document)->trigger($type, $data);
         }
     } else {
         if (isset($data[0]) && $data[0] instanceof DOMEvent) {
             $event = $data[0];
             $event->relatedTarget = $event->target;
             $event->target = $node;
             $data = array_slice($data, 1);
         } else {
             $event = new DOMEvent(array('type' => $type, 'target' => $node, 'timeStamp' => time()));
         }
         while ($node) {
             phpQuery::debug("Triggering event '{$type}' on node " . phpQueryObject::whois($node) . "\n");
             $event->currentTarget = $node;
             $eventNode = self::getNode($documentID, $node);
             if (isset($eventNode->eventHandlers)) {
                 foreach ($eventNode->eventHandlers as $eventType => $handlers) {
                     $eventNamespace = null;
                     if (strpos($type, '.') !== false) {
                         list($eventName, $eventNamespace) = explode('.', $eventType);
                     } else {
                         $eventName = $eventType;
                     }
                     if ($name != $eventName) {
                         continue;
                     }
                     if ($namespace && $eventNamespace && $namespace != $eventNamespace) {
                         continue;
                     }
                     foreach ($handlers as $handler) {
                         $event->data = $handler['data'] ? $handler['data'] : null;
                         $params = array_merge(array($event), $data);
                         $return = phpQuery::callbackRun($handler['callback'], $params);
                         if ($return === false) {
                             $event->bubbles = false;
                         }
                     }
                 }
             }
             // to bubble or not to bubble...
             if (!$event->bubbles) {
                 break;
             }
             $node = $node->parentNode;
         }
     }
 }