예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function buildFrom(ServerRequestInterface $request, HttpResource $definition) : SpecificationInterface
 {
     $specification = null;
     foreach ($request->query() as $parameter) {
         if ($parameter->name() === 'range') {
             /*
             range is used in QueryExtractor to determine the range of the
             resources to return and thus can't be used as a filter
             */
             continue;
         }
         if (!$definition->properties()->contains($parameter->name())) {
             throw new FilterNotApplicableException($parameter->name());
         }
         if ($specification === null) {
             $specification = new Filter($parameter->name(), $parameter->value());
         } else {
             $specification = $specification->and(new Filter($parameter->name(), $parameter->value()));
         }
     }
     if ($specification === null) {
         throw new NoFilterFoundException();
     }
     return $specification;
 }
    /**
     *
     * @param HttpResource $asset 
     */
    public function accept($asset)
    {
        $url = $asset->url();
        $url = str_replace('http://', '', $url);
        $url = str_replace('https://', '', $url);

        $domain = reset(split('/', $url));
        return strpos($domain, 'google.com/calendar') !== false;
    }
예제 #3
0
 private function resolveName(PropertyDefinition $property, HttpResource $resource) : string
 {
     return $property->variants()->reduce($property->name(), function (string $usedName, string $variant) use($resource) : string {
         if ($resource->properties()->contains($variant)) {
             return $variant;
         }
         return $usedName;
     });
 }
    /**
     *
     * @param HttpResource $asset 
     */
    public function accept($asset)
    {
        $url = $asset->url();
        $url = str_replace('http://', '', $url);
        $url = str_replace('https://', '', $url);

        $domain = reset(explode('/', $url));
        return strpos($domain, 'maps.google') !== false;
    }
 /**
  *
  * @param HttpResource $asset 
  */
 public function accept($asset)
 {
     if ($asset->is_video())
     {
         return true;
     }
     
     //swf mime type is application/x-shockwave-flash
     return $asset->has_ext('swf');
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function build(SetInterface $identities, ServerRequestInterface $request, HttpResource $definition, SpecificationInterface $specification = null, Range $range = null) : MapInterface
 {
     $map = new Map('string', HeaderInterface::class);
     if (!$definition->isRangeable()) {
         return $map;
     }
     $map = $map->put('Accept-Ranges', new AcceptRanges(new AcceptRangesValue('resources')));
     if (!$range instanceof Range) {
         return $map;
     }
     $length = $range->lastPosition() - $range->firstPosition();
     return $map->put('Content-Range', new ContentRange(new ContentRangeValue('resources', $range->firstPosition(), $last = $range->firstPosition() + $identities->size(), $identities->size() < $length ? $last : $last + $length)));
 }
 protected function do_get()
 {
     // Call the parent
     parent::do_get();
     if ($_GET["id"] == "*") {
         if (isset($_GET["team_owner_id"])) {
             if (is_numeric($_GET["team_owner_id"])) {
                 $this::getTeamsByOwnerId();
             } else {
                 $this->exit_error(400, "idNotPositiveInteger");
             }
         } else {
             if (isset($_GET["project_id"])) {
                 if (is_numeric($_GET["project_id"])) {
                     $this::getTeamsByProjectId();
                 } else {
                     $this->exit_error(400, "project_idNotPositiveInteger");
                 }
             } else {
                 if (isset($_GET["team_member_id"])) {
                     if (is_numeric($_GET["team_member_id"])) {
                         $this::getTeamsByMemberId();
                     } else {
                         $this->exit_error(400, "team_member_idNotPositiveInteger");
                     }
                 }
             }
         }
     } else {
         $this::getTeamByTeamId();
     }
 }
 protected function do_get()
 {
     // Call the parent
     parent::do_get();
     try {
         $db = DemoDB::getConnection();
         $sql = "SELECT person_id, name FROM person WHERE person_id=:person_id";
         $stmt = $db->prepare($sql);
         $stmt->bindValue(":person_id", $this->id);
         $ok = $stmt->execute();
         if ($ok) {
             $row = $stmt->fetch(PDO::FETCH_ASSOC);
             if ($row != null) {
                 $this->statusCode = 200;
                 // Produce utf8 encoded json
                 $this->headers[] = "Content-type: text/json; charset=utf-8";
                 $this->body = json_encode($row);
             } else {
                 $this->exit_error(404);
             }
         } else {
             $this->exit_error(500, print_r($db->errorInfo(), true));
         }
     } catch (PDOException $e) {
         $this->exit_error(500, $e->getMessage());
     }
 }
    /**
     *
     * @param HttpResource $asset 
     */
    public function render($asset)
    {
        if (!$this->accept($asset))
        {
            return;
        }

        $width = (int) $asset->config('size');
        $width = (24 <= $width && $width <= 800) ? $width : 300;
        
        $url = $asset->url();
        
        $oembed = self::API_ENDPOINT . '?url=' . urlencode($url) . '&maxwidth=' . $width;

        $data = HttpResource::fetch_json($oembed); 
        if (empty($data))
        {
            return false;
        }

        $result[self::THUMBNAIL] = isset($data['thumbnail_url']) ? $data['thumbnail_url'] : '';
        $result[self::TITLE] = isset($data['title']) ? $data['title'] : '';
        $result[self::EMBED_SNIPPET] = isset($data['html']) ? $data['html'] : '';

        return $result;
    }
 protected function do_post()
 {
     parent::do_post();
     // TODO: Change the autogenerated stub
     $var = $_POST["title"];
     echo $var;
 }
 protected function do_get()
 {
     // Call the parent
     parent::do_get();
     if ($_GET["id"] == "*") {
         if (isset($_GET["owner_id"])) {
             if (is_numeric($_GET["owner_id"])) {
                 //  $this->getAllProjectsByOwnerIdOrClassId(null);
                 return;
             } else {
                 $this->exit_error(400, "owner_idNotPositiveInteger");
             }
         }
         if (isset($_GET["class_id"])) {
             if (is_numeric($_GET["class_id"])) {
                 $this->getStudentsByClassId($_GET["class_id"]);
                 return;
             } else {
                 $this->exit_error(400, "class_idNotPositiveInteger");
             }
         }
         $this->getAllStudents();
     } else {
         $this->getStudentById();
     }
 }
    /**
     *
     * @param HttpResource $asset 
     */
    public function render($asset)
    {
        $url = $asset->url();
        $id = self::get_user_id($url);
        if (empty($id))
        {
            return false;
        }

        $data = get_record('usr', 'id', $id);

        $result = array();
        safe_require('blocktype', 'ple/person');
        $result[self::EMBED_SNIPPET] = PluginBlocktypePerson::render_preview($id);
        $result[self::THUMBNAIL] = PluginBlocktypePerson::get_thumbnail($id);
        $result[self::TITLE] = $data->prefferedname ? $data->prefferedname : $data->firstname . ' ' . $data->lastname;
        $result[self::DESCRIPTION] = isset($data->description) ? $data->description : '';

        return $result;
    }
    /**
     *
     * @param HttpResource $asset 
     */
    public function render($asset)
    {
        $url = $asset->url();
        $group_id = self::get_group_id($url);
        if (empty($group_id))
        {
            return false;
        }

        $data = get_record('group', 'id', $group_id);

        $result = array();
        safe_require('blocktype', 'ple/group');
        $result[self::EMBED_SNIPPET] = PluginBlocktypeGroup::render_preview($group_id);
        $result[self::THUMBNAIL] = PluginBlocktypeGroup::get_thumbnail($group_id);
        $result[self::TITLE] = $data->name;
        $result[self::DESCRIPTION] = $data->description;

        return $result;
    }
    /**
     *
     * @param HttpResource $asset 
     */
    public function render($asset)
    {
        if (! $asset->is_image())
        {
            return false;
        }
        
        global $THEME;
        $url = $asset->url();
        $title = $asset->title();
        $title = $title ? $title : $asset->name();
        
        $size = (int) $asset->config('size');
        $size = (24 <= $size && $size <= 800) ? $size : 300;
        
        $embed = <<<EOT
        <div style="text-align:center"><a href="$url"><img src="{$url}" width="$size" alt="{$title}" title="{$title}"></a></div>
EOT;

        $result = array();
        $result[self::URL] = $url;
        $result[self::EMBED_SNIPPET] = $embed;
        $result[self::TITLE] = $title;
        $result[self::THUMBNAIL] = $url;
        return $result;
    }
    /**
     *
     * @param HttpResource $asset 
     */
    public function render($asset)
    {
        $link = $asset->get_link('type', 'application/json+oembed');
        if (empty($link))
        {
            return false;
        }

        $width = (int) $asset->config('size');
        $width = (24 <= $width && $width <= 800) ? $width : 300;

        $href = $link['href'];
        $data = HttpResource::fetch_json("$href&maxwidth=$width"); //&maxheight=$height
        if (empty($data))
        {
            return false;
        }

        $data['title'] = isset($data['title']) ? $data['title'] : '';
        $data['width'] = isset($data['width']) ? intval($data['width']) : '';
        $data['height'] = isset($data['height']) ? intval($data['height']) : '';

        $type = $data['type'];
        $f = array($this, "render_$type");
        if (is_callable($f))
        {
            $result = call_user_func($f, $asset, $data);
        }
        else
        {
            $result = array();
        }
        $result[self::THUMBNAIL] = isset($data['thumbnail_url']) ? $data['thumbnail_url'] : '';
        $result[self::TITLE] = isset($data['title']) ? $data['title'] : '';

        return $result;
    }
    /**
     *
     * @param HttpResource $asset 
     */
    public function render($asset)
    {
        global $THEME;
        $url = $asset->url();
        $title = $asset->title();
        $title = $title ? $title : $asset->name();
        $description = $asset->get_meta('description');
        $description = $description;

        $keywords = $asset->get_meta('keywords');

        $image_src = $asset->get_link('rel', 'image_src');
        $image_src = $image_src ? $image_src['href'] : false;

        if (empty($image_src))
        {
            $image_src = $this->get_icon($asset);
        }

        $icon = $this->get_icon($asset);
        
        $image_src = $asset->canonic_url($image_src);
        $icon = $asset->canonic_url($icon);

        $embed = <<<EOT
        <a href="$url">
            <img src="{$image_src}" alt="{$title}" title="{$title}" style="float:left; margin-right:5px; margin-bottom:5px; " >
        </a>
        $description
        <span style="clear:both;"></span>
EOT;


        $result = array();
        $result[self::EMBED_SNIPPET] = $embed;
        $result[self::TITLE] = $title;
        $result[self::THUMBNAIL] = $image_src;
        $result[self::DESCRIPTION] = $description;
        $result[self::ICON] = $icon;
        $result[self::TAGS] = $keywords;
        return $result;
    }
예제 #17
0
 public function update(IdentityInterface $identity, HttpResource $resource) : ServerInterface
 {
     $definition = $this->capabilities->get($resource->name());
     $this->transport->fulfill(new Request($this->resolveUrl($definition->url(), $identity), new Method(Method::PUT), new ProtocolVersion(1, 1), new Headers((new Map('string', HeaderInterface::class))->put('Content-Type', new ContentType(new ContentTypeValue('application', 'json', new Map('string', ParameterInterface::class))))), new StringStream($this->serializer->serialize($resource, 'json', ['definition' => $definition, 'access' => new Access((new Set('string'))->add(Access::UPDATE))]))));
     return $this;
 }
 protected function do_get()
 {
     parent::do_get();
     // TODO: Change the autogenerated stub
 }
    /**
     *
     * @param HttpResource $asset 
     */
    public function render($asset)
    {
        if (!$asset->is_rss())
        {
            return;
        }

        $url = $asset->url();
        $title = $asset->title();
        $id = 'a' . md5($url);

        $embed = <<<EOT
        <style type="text/css">
            .gfg-root {
                border: none;
                font-family: inherit;
            }
        </style>
        <script type="text/javascript" src="http://www.google.com/jsapi"></script>
        <script src="http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js" type="text/javascript"></script> 
        <script type="text/javascript">
        
            function init()
            {
                if (typeof this.has_run == 'undefined' )
                {
                    this.has_run = true;
                }
                else
                {
                    return;
                }
                var head = document.getElementsByTagName('head')[0];
        
                var element = document.createElement('link');
                element.type = 'text/css';
                element.rel = 'stylesheet';
                element.href = 'http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.css';
                head.appendChild(element);
            }

            function load_$id() {
                var feeds = [
                    {
                    title: ' ',
                    url: '$url'
                    }
                ];

                var options = {
                    stacked : false,
                    horizontal : false,
                    title : '',
                    numResults : 10
                };

                new GFdynamicFeedControl(feeds, '$id', options);
                document.getElementById('content').style.width = "500px";
            }
        
        
            init();
            google.load('feeds', '1');
            google.setOnLoadCallback(load_$id);
       </script>        
       <div id="$id" style="min-height:271px;">Loading...</div>
EOT;


        $result = array();
        $result[self::EMBED_SNIPPET] = $embed;
        $result[self::TITLE] = $title;
        return $result;
    }
    /**
     * @param HttpResource $asset
     * @return array
     */
    protected function render_image($asset)
    {
        $size = (int) $asset->config('size');
        $size = (24 <= $size && $size <= 800) ? $size : 300;

        $title = $data['title'];
        $width = $data['width'];
        $height = $data['height'];
        $ratio = $height / $width;
        $base = min($size, $width);
        $width = $base;
        $height = $ratio * $base;

        $url = $data['url'];

        $embed = <<<EOT
        <a href="$url"><img src="{$url}" width="{$width}" height="{$height} "alt="{$title}" title="{$title}"></a>
EOT;
    }
 /**
  *
  * @param HttpResource $asset 
  */
 public function accept($asset)
 {       
     return $asset->url_match('wikipedia.org/wiki', 'mediawiki.org/wiki');
 }
 /**
  *
  * @param HttpResource $asset 
  */
 public function accept($asset)
 {       
     $url = $asset->url();
     
     return strpos($url, 'docs.google.com/document/pub') !== false;
 }
 /**
  *
  * @param HttpResource $asset 
  */
 public function accept($asset)
 {
     return $asset->url_match('http://scratch.mit.edu/projects/');
 }
 protected function do_get()
 {
     // Call the parent
     parent::do_get();
     if (isset($_GET["id"])) {
         if (is_numeric($_GET["id"])) {
             try {
                 $db = DemoDB::getConnection();
                 $sql = "SELECT * FROM Class where id=:id;";
                 $stmt = $db->prepare($sql);
                 $stmt->bindValue(":id", $_GET["id"], PDO::PARAM_INT);
                 $ok = $stmt->execute();
                 if ($ok) {
                     $nb = $stmt->rowCount();
                     if ($nb == 0) {
                         $this->exit_error(404);
                     }
                     if (isset($this->statusCode)) {
                         $this->statusCode = 200;
                     }
                     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                         if ($row != null) {
                             if (isset($this->headers)) {
                                 $this->headers[] = "Content-type: text/json; charset=utf-8";
                             }
                             // Produce utf8 encoded json
                             $this->body = json_encode($row);
                         } else {
                             $this->exit_error(404);
                         }
                     }
                 } else {
                     $this->exit_error(500, print_r($db->errorInfo(), true));
                 }
             } catch (PDOException $e) {
                 $this->exit_error(500, $e->getMessage());
             }
         } else {
             if ($_GET["id"] == "*") {
                 try {
                     $db = DemoDB::getConnection();
                     $sql = "SELECT * FROM Class";
                     $stmt = $db->prepare($sql);
                     $ok = $stmt->execute();
                     if ($ok) {
                         $sbody = "{";
                         $nb = $stmt->rowCount();
                         if ($nb == 0) {
                             $this->exit_error(404);
                         }
                         if (isset($this->statusCode)) {
                             $this->statusCode = 200;
                         }
                         while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                             if ($row != null) {
                                 if (isset($this->headers)) {
                                     $this->headers[] = "Content-type: text/json; charset=utf-8";
                                 }
                                 // Produce utf8 encoded json
                                 $sbody .= "\"" . $row["id"] . "\":" . json_encode($row) . ",";
                             } else {
                                 $this->exit_error(404);
                             }
                         }
                         $sbody = rtrim($sbody, ",");
                         $this->body = $sbody . "}";
                     } else {
                         $this->exit_error(500, print_r($db->errorInfo(), true));
                     }
                 } catch (PDOException $e) {
                     $this->exit_error(500, $e->getMessage());
                 }
             } else {
                 $this->exit_error(400, "idNotPositiveInteger");
             }
         }
     } else {
         $this->exit_error(400, "idRequired");
     }
 }
    /**
     *
     * @param HttpResource $asset 
     */
    public function render($asset)
    {
        
        if ($asset->url_match('gmodules.com/ig/') && $asset->url_param('url') != false)
        {
            $url = $asset->url();
            $title = $asset->url_param('title');
            $title = ($title == '__MSG_title__') ? '' : $title;
            
            $embed = <<<EOT
                <script src="$url"></script>
EOT;
            
            $result = array();
            $result[self::EMBED_SNIPPET] = $embed;
            $result[self::TITLE] = $title;
            return $result;
        }

        if (!$asset->is_gadget())
        {
            $url = $asset->url();

            if (!$asset->url_match('google.com/ig/directory'))
            {
                return false;
            }
            if (!$asset->url_match('type=gadgets'))
            {
                return false;
            }

            $url = $asset->url_param('url');
            if (empty($url))
            {
                return false;
            }
            $asset = new HttpResource($url);
            if (!$asset->is_gadget())
            {
                return false;
            }
        }

        $url = $asset->url();
        if (strpos($url, 'http') !== 0)
        {
            $url = "http://$url";
        }
        $url = urlencode($url);
        $title = $asset->title();
        $title = $title ? $title : $asset->name();
        
        $size = (int) $asset->config('size');
        $size = (24 <= $size && $size <= 800) ? $size : 300;

        $embed = <<<EOT
        <script src="//www.gmodules.com/ig/ifr?url=$url&amp;w=$size&amp;output=js"></script>
EOT;

        $result = array();
        $result[self::EMBED_SNIPPET] = $embed;
        $result[self::TITLE] = $title;
        return $result;
    }
 /**
  *
  * @param HttpResource $asset 
  */
 public function accept($asset)
 {
     $supported_extentions = array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'pages', 'ai', 'psd', 'tiff', 'dxf', 'svg', 'eps', 'ps', 'eps', 'ttf', 'zip', 'rar');
     return $asset->has_ext($supported_extentions);
 }
예제 #27
0
 /**
  * Méthode permettant de récupérer un contenu texte sur le le web.
  */
 private static function getFile($resourceName)
 {
     return HttpResource::getFichierDistant(self::$SERVEUR_CELCAT, $resourceName);
 }