예제 #1
0
 function data_make()
 {
     switch ($this->method) {
         case 'get':
         case 'head':
             return null;
         case 'post':
             $data = $_POST;
             foreach ($_FILES as $key => $info) {
                 $data[$key] = so_file::make($info['tmp_name']);
             }
             return so_query::make($data);
         default:
             $raw = '';
             $input = fopen('php://input', 'r');
             while ($chunk = fread($input, 1024)) {
                 $raw .= $chunk;
             }
             fclose($input);
             $type = preg_replace('~;.*$~', '', so_value::make($_SERVER['CONTENT_TYPE']) ?: '');
             switch ($type) {
                 case 'application/x-www-form-urlencoded':
                     return so_query::make($raw);
                     break;
                 case 'text/xml':
                 case 'application/xml':
                     return so_dom::make($raw);
                 case 'text/json':
                 case 'application/json':
                     return json_decode($raw);
                 default:
                     return $raw;
             }
     }
 }
예제 #2
0
파일: so_gist.php 프로젝트: nin-jin/hyoo.ru
 function link_make()
 {
     if (!$this->version) {
         return $this->model;
     }
     return so_dom::make(array('so_gist' => array('@so_gist_title' => (string) $this->title, '@so_gist_uri' => (string) $this->uri, '@so_uri_external' => (string) $this->storage->uri)));
 }
예제 #3
0
파일: so_page.php 프로젝트: nin-jin/hyoo.ru
 static function make($data)
 {
     $page = array();
     $moduleMix = so_package::make()['-mix']->dir;
     $page[] = array('?xml-stylesheet' => array('href' => (string) $moduleMix[static::$mode . '.xsl']->uriVersioned, 'type' => 'text/xsl'));
     $page[] = array('so_page' => array('@so_page_styles' => (string) $moduleMix[static::$mode . '.css']->uriVersioned, '@so_page_script' => (string) $moduleMix[static::$mode . '.js']->uriVersioned, '@so_page_icon' => (string) so_file::make('icon.png')->uriVersioned, $data));
     return so_dom::make($page)->doc;
 }
예제 #4
0
 function model_make()
 {
     $subsribers = array();
     foreach ($this->database->dump as $sub) {
         $subsribers[] = array('so_subscriber' => $sub);
     }
     return so_dom::make(array('so_subscriber_list' => array('@so_uri' => (string) $this->uri, $subsribers)));
 }
예제 #5
0
 function get_resource()
 {
     ob_start();
     phpinfo();
     $html = ob_get_clean();
     $doc = new \DOMDocument('1.0', 'utf-8');
     $doc->loadHTML($html . '<style> .v{ background: #eee } a:link { background: none } </style>');
     $dom = so_dom::make($doc)->select('/*/*');
     return so_output::ok()->content(array('html' => $dom));
 }
예제 #6
0
 function offsetGet($key)
 {
     if (is_int($key)) {
         return $this->list_value[$key] = so_dom::make($this->list[$key]);
     }
     $list = array();
     foreach ($this as $item) {
         if ($item->name != $key) {
             continue;
         }
         $list[] = $item;
     }
     return so_dom_collection::make($list);
 }
예제 #7
0
 function image_make()
 {
     if ($this->storage->version) {
         return so_dom::make($this->storage->content);
     }
     $query = so_query_compatible::make(array('v' => '1.0', 'q' => $this->search, 'rsz' => 1, 'imgsz' => 'xlarge', 'safe' => 'off'));
     $json = json_decode(so_uri_compatible::make('http://ajax.googleapis.com/ajax/services/search/images?' . $query)->content);
     $image = so_dom::make(array('hyoo_image_search' => null));
     foreach ($json->responseData->results[0] as $prop => $value) {
         $image['@hyoo_image_search_' . $prop] = $value;
     }
     $this->storage->content = $image;
     return $image;
 }
예제 #8
0
 function post_resource($data)
 {
     $result = eval($data['code']);
     $lang = 'text';
     if ($result instanceof \DOMNode) {
         $result = so_dom::make($result);
     }
     if ($result instanceof so_dom) {
         $lang = 'sgml';
     }
     if (is_array($result) || is_bool($result) || is_null($result)) {
         $result = var_export($result, true);
         $lang = 'php';
     }
     return so_output::ok()->content(array('so_console_result' => array('@so_console_lang' => $lang, '@so_console_content' => (string) $result)));
 }
예제 #9
0
 function process($doc)
 {
     $doc = so_dom::make($doc);
     $doc = $this->processor->transformToDoc($doc->DOMNode);
     return so_dom::make($doc);
 }
예제 #10
0
파일: so_uri.php 프로젝트: nin-jin/hyoo.ru
 function content_make()
 {
     $curl = curl_init($this->string);
     ob_start();
     curl_exec($curl);
     $data = ob_get_clean();
     $info = curl_getinfo($curl);
     curl_close($curl);
     switch (preg_replace('~;.*$~', '', $info['content_type'])) {
         case 'text/xml':
         case 'application/xml':
             return so_dom::make($data);
         case 'text/json':
         case 'application/json':
             return json_decode($data);
     }
     return $data;
 }
예제 #11
0
파일: so_dom.php 프로젝트: nin-jin/hyoo.ru
 function offsetSet($key, $value)
 {
     if (!$key) {
         if (!isset($value)) {
             return $this;
         }
         $DOMNode = $this->DOMNode;
         if (is_scalar($value)) {
             $value = $this->DOMDocument->createTextNode($value);
             $DOMNode->appendChild($value);
             return $this;
         }
         if (is_object($value)) {
             if ($value instanceof SimpleXMLElement) {
                 $value = dom_import_simplexml($value);
                 $DOMNode->appendChild($value);
                 return $this;
             }
             if (isset($value->DOMNode)) {
                 $value = $value->DOMNode;
             }
             if ($value instanceof \DOMDocument) {
                 foreach ($value->childNodes as $node) {
                     $this[] = $node;
                 }
                 return $this;
             }
             if ($value instanceof \DOMNode) {
                 $value = $this->DOMDocument->importNode($value->cloneNode(true), true);
                 $DOMNode->appendChild($value);
                 return $this;
             }
         }
         foreach ($value as $key => $value) {
             if (is_int($key)) {
                 $this[] = $value;
                 continue 1;
             }
             if ($key[0] === '#') {
                 if (!is_scalar($value)) {
                     $value = (string) so_dom::make($value);
                 }
                 if ($key === '#text') {
                     $value = $this->DOMDocument->createTextNode($value);
                     $DOMNode->appendChild($value);
                     continue 1;
                 }
                 if ($key === '#comment') {
                     $value = $this->DOMDocument->createComment($value);
                     $DOMNode->appendChild($value);
                     continue 1;
                 }
                 if ($key === '#html') {
                     $doc = new \DOMDocument('1.0');
                     $errors = libxml_use_internal_errors(true);
                     $doc->loadHTML($value);
                     libxml_use_internal_errors($errors);
                     $DOMNode->appendChild($this->DOMDocument->importNode($doc->documentElement, true));
                     continue 1;
                 }
                 throw new \Exception("Wrong special element name [{$key}]");
             }
             if ($key[0] === '@') {
                 $name = substr($key, 1);
                 if (!is_scalar($value)) {
                     $value = (string) so_dom::make($value);
                 }
                 $DOMNode->setAttribute($name, $value);
                 continue 1;
             }
             if ($key[0] === '?') {
                 $name = substr($key, 1);
                 if (is_array($value)) {
                     $valueList = array();
                     foreach ($value as $k => $v) {
                         $valueList[] = htmlspecialchars($k) . '="' . htmlspecialchars($v) . '"';
                     }
                     $value = implode(" ", $valueList);
                 }
                 $content = $this->DOMDocument->createProcessingInstruction($name, $value);
                 $DOMNode->appendChild($content);
                 continue 1;
             }
             if ($key === '!DOCTYPE') {
                 $name = substr($key, 1);
                 if (!$value) {
                     $value = array();
                 }
                 $public =& $value['public'];
                 $system =& $value['system'];
                 $implementation = $this->DOMDocument->implementation;
                 $content = $implementation->createDocumentType($value['name'], $public, $system);
                 $DOMNode->appendChild($content);
                 // FIXME: не работает =(
                 continue 1;
             }
             $keys = explode('/', $key);
             while (count($keys) > 1) {
                 $value = array(array_pop($keys) => $value);
             }
             $key = $keys[0];
             $element = $this->DOMDocument->createElement($key);
             so_dom::make($element)[] = $value;
             $DOMNode->appendChild($element);
         }
         return $this;
     }
     if ($key[0] === '@') {
         $name = substr($key, 1);
         $this->DOMNode->setAttribute($name, $value);
         return $this;
     }
     $this->childs[$key]->parent = null;
     $this[] = array($key => $value);
     return $this;
 }
예제 #12
0
 function modelBase_make()
 {
     return so_dom::make(array('hyoo_author' => array('@so_uri' => (string) $this->uri, '@hyoo_author_name' => (string) $this->name, '@hyoo_author_article-list' => (string) $this->articleList)));
 }
예제 #13
0
 function get_dom($dom)
 {
     if (isset($dom)) {
         return $dom;
     }
     $dom = $this->storage->version ? so_dom::make($this->storage->content) : $this->contentDefault;
     return $dom;
 }
예제 #14
0
 function model_make()
 {
     return so_dom::make(array('hyoo_image' => array('@so_uri' => (string) $this->uri, '@hyoo_image_original' => (string) $this->fileOrinal->uri, '@hyoo_image_maximal' => (string) $this->fileMaximal->uri, '@hyoo_image_preview' => (string) $this->filePreview->uri)));
 }
예제 #15
0
파일: index.php 프로젝트: nin-jin/hyoo.ru
<?php

header('content-type: text/plain', true);
require_once '../../../so/autoload/so_autoload.php';
$dom = so_dom::create();
$dom['?xml-stylesheet'] = array('href' => 'my.xsl', 'type' => 'text/xsl');
$dom['html'] = '';
$dom->root[] = array('@id' => 'id of root', 'head' => so_dom::create('<title>example</title>'));
// $dom[' html / body / #text ']= '</html>'; // TODO
$dom['#comment'] = $dom->root;
echo "{$dom}\n";
foreach ($dom as $key => $child) {
    echo "{$key} | {$child->value}\n";
}
$dom->DOMNode;
// cast to DOMNode
예제 #16
0
 function content_make()
 {
     return so_dom::make($this->file->content);
 }
예제 #17
0
 function minify()
 {
     $target = $this->target;
     $minifiedJS = $target['library.js']->content;
     $minifiedJS = preg_replace('~^\\s+~m', '', $minifiedJS);
     $minifiedJS = preg_replace('~^//.*$\\n~m', '', $minifiedJS);
     $minifiedJS = preg_replace('~\\n/\\*[\\w\\W]*?\\*/~', '', $minifiedJS);
     $minifiedCSS = $target['release.css']->content;
     $minifiedCSS = preg_replace('~/\\*[\\w\\W]*?\\*/~', '', $minifiedCSS);
     $minifiedCSS = preg_replace('~^\\s+~m', '', $minifiedCSS);
     $minifiedCSS = preg_replace('~[\\r\\n]~', '', $minifiedCSS);
     $minifiedXSL = null;
     if ($target['release.xsl']->exists) {
         $minifiedXSL = $target['release.xsl']->content;
         $doc = new \DOMDocument();
         $doc->formatOutput = false;
         $doc->preserveWhiteSpace = false;
         $doc->loadXML((string) $minifiedXSL);
         $minifiedXSL = $doc->C14N();
     }
     $minifiedPHP = $target['release.php']->content;
     if ($minifiedJS) {
         $target['minified.js']->content = $minifiedJS;
     }
     if ($minifiedCSS) {
         $target['minified.css']->content = $minifiedCSS;
     }
     if ($minifiedXSL) {
         $target['minified.xsl']->content = so_dom::make($minifiedXSL);
     }
     if ($minifiedPHP) {
         $target['minified.php']->content = $minifiedPHP;
     }
     return $this;
 }