diff --git a/.gitignore b/.gitignore index e9b2c8ce9..609a28f73 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ conf/app.* conf/installed install/cache/* install/installed +lib/vendor diff --git a/apps/designer/forms/installer.php b/apps/designer/forms/installer.php index 39f4ae2c4..6bc627a28 100644 --- a/apps/designer/forms/installer.php +++ b/apps/designer/forms/installer.php @@ -11,4 +11,8 @@ skip_if_empty = 1 callback = github_is_valid_url +[composer] + +skip_if_empty = 1 + ; */ ?> \ No newline at end of file diff --git a/apps/designer/handlers/installer.php b/apps/designer/handlers/installer.php index ce0ebcffa..4e0ae2f1d 100644 --- a/apps/designer/handlers/installer.php +++ b/apps/designer/handlers/installer.php @@ -50,7 +50,7 @@ $page->installer_error = GithubInstaller::$error; return false; } - + // App/theme successfully installed $page->title = __ ('Install completed'); echo $tpl->render ('designer/installed', $res); @@ -71,6 +71,26 @@ ZipInstaller::clean (); $page->title = __ ('Install completed'); echo $tpl->render ('designer/installed', $res); + } elseif (! empty ($_POST['composer'])) { + $elefantApp = $_POST['composer']; + putenv('COMPOSER_HOME=' . $_SERVER['DOCUMENT_ROOT']); + + $response = array(); + $composer = '/usr/local/bin/composer'; + $command = $composer . ' require '; + $package = '"elefant/app-' . $elefantApp . '":"dev-master"'; + exec($command . $package, $response, $status); + $responsePara = ($response) ? implode("< /br>\n", $response) :""; + //this is too brute force + if (strpos($responsePara,"failed")) { + $form->failed = array ('composer-install'); + $page->installer_error = $responsePara; + return false; + } + //this should use the $conf validation stuff from ZipInstaller::install + $res = json_decode (file_get_contents ("apps/$elefantApp/elefant.json")); + $page->title = __ ('Install completed'); + echo $tpl->render ('designer/installed', $res); } else { $form->failed = array ('other'); return false; diff --git a/apps/designer/views/installer.html b/apps/designer/views/installer.html index 16dc69521..3eb981a9f 100644 --- a/apps/designer/views/installer.html +++ b/apps/designer/views/installer.html @@ -19,6 +19,35 @@ {" Please upload a zip file. "}

+

- {"or"} -

+

{"Install from Composer"}:
+ +{" Not valid composer app. "}

{" Please enter a link or upload a file. "}

{% if page.installer_error %} @@ -29,6 +58,7 @@

{"Github installation failed"}.

{"Zip file was invalid or could not be installed."}

+

{"Composer couldn't load the specified package."}

{% end %}

diff --git a/composer.json b/composer.json index 1e4fb1b23..2b44b1f5e 100644 --- a/composer.json +++ b/composer.json @@ -6,10 +6,21 @@ "license": "MIT", "version": "1.3.5-beta", "require": { - "php": ">=5.3.2" + "php": ">=5.3.2", + "analog/analog": "dev-master", + "jbroadway/urlify": "dev-master", + "phpactiveresource/phpactiveresource": "dev-master", + "pimple/pimple": "dev-master" }, "config": { "process-timeout": 600, "vendor-dir": "lib/vendor" + }, + "scripts": { + "post-install-cmd": [ + "chmod -R 755 cache conf css files install lang layouts lib/vendor/composer", + "chmod 755 apps lib/vendor", + "chmod 755 composer.json composer.lock lib/vendor/autoload.php" + ] } } diff --git a/lib/Autoloader.php b/lib/Autoloader.php index f8e34260d..4c60bb9dc 100644 --- a/lib/Autoloader.php +++ b/lib/Autoloader.php @@ -4,17 +4,17 @@ * Elefant CMS - http://www.elefantcms.com/ * * Copyright (c) 2011 Johnny Broadway - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -89,4 +89,7 @@ function elefant_autoloader ($class) { spl_autoload_register ('elefant_autoloader'); +//and now we include the composer autoloader +require "vendor/autoload.php"; + ?> \ No newline at end of file diff --git a/lib/vendor/ActiveResource.php b/lib/vendor/ActiveResource.php deleted file mode 100644 index 4f4630156..000000000 --- a/lib/vendor/ActiveResource.php +++ /dev/null @@ -1,706 +0,0 @@ - 'Joe Cocker', 'title' => 'A Little Help From My Friends')); - * $song->save (); - * - * // fetch and update an item - * $song->find (44)->set ('title', 'The River')->save (); - * - * // line by line - * $song->find (44); - * $song->title = 'The River'; - * $song->save (); - * - * // get all songs - * $songs = $song->find ('all'); - * - * // delete a song - * $song->find (44); - * $song->destroy (); - * - * // custom method - * $songs = $song->get ('by_year', array ('year' => 1999)); - * - * ?> - * - * @author John Luxford - * @version 0.14 beta - * @license http://opensource.org/licenses/lgpl-2.1.php - */ -class ActiveResource { - /** - * The REST site address, e.g., `http://user:pass@domain:port/` - */ - public $site = false; - - /** - * Add any extra params to the end of the url eg: API key - */ - public $extra_params = false; - - /** - * HTTP Basic Authentication user - */ - public $user = null; - - /** - * HTTP Basic Authentication password - */ - public $password = null; - - /** - * The remote collection, e.g., person or thing - */ - public $element_name = false; - - /** - * Pleural form of the element name, e.g., people or things - */ - public $element_name_plural = ''; - - /** - * The data of the current object, accessed via the anonymous get/set methods. - */ - private $_data = array (); - - /** - * An error message if an error occurred. - */ - public $error = false; - - /** - * The error number if an error occurred. - */ - public $errno = false; - - /** - * The request that was sent to the server. - */ - public $request_body = ''; - - /** - * The request headers that was sent to the server. - */ - public $request_headers = array (); - - /** - * The complete URL that the request was sent to. - */ - public $request_uri = ''; - - /** - * The request method sent to the server. - */ - public $request_method = ''; - - /** - * The response code returned from the server. - */ - public $response_code = false; - - /** - * The raw response headers sent from the server. - */ - public $response_headers = ''; - - /** - * The response body sent from the server. - */ - public $response_body = ''; - - /** - * The format requests should use to send data (url or xml). - */ - public $request_format = 'url'; - - /** - * Corrections to improper pleuralizations. - */ - public $pleural_corrections = array ( - 'persons' => 'people', - 'peoples' => 'people', - 'mans' => 'men', - 'mens' => 'men', - 'womans' => 'women', - 'womens' => 'women', - 'childs' => 'children', - 'childrens' => 'children', - 'sheeps' => 'sheep', - 'octopuses' => 'octopi', - 'quizs' => 'quizzes', - 'axises' => 'axes', - 'buffalos' => 'buffaloes', - 'tomatos' => 'tomatoes', - 'potatos' => 'potatoes', - 'oxes' => 'oxen', - 'mouses' => 'mice', - 'matrixes' => 'matrices', - 'vertexes' => 'vertices', - 'indexes' => 'indices', - ); - - /** - * Constructor method. - */ - public function __construct ($data = array ()) { - $this->_data = $data; - // Allow class-defined element name or use class name if not defined - $this->element_name = $this->element_name ? $this->element_name : strtolower (get_class ($this)); - - // Detect for namespaces, and take just the class name - if (stripos ($this->element_name, '\\')) { - $classItems = explode ('\\', $this->element_name); - $this->element_name = end ($classItems); - } - - // Get the plural name after removing namespaces - $this->element_name_plural = $this->pluralize ($this->element_name); - - // If configuration file (`config.ini.php`) exists use it (overwrite class properties/attribute values). - $config_file_path = dirname (__FILE__) . '/' . 'config.ini.php'; - if (file_exists ($config_file_path)) { - $properties = parse_ini_file ($config_file_path); - foreach ($properties as $property => $value ) - $this->{$property} = $value; - } - } - - /** - * Pluralize the element name. - */ - public function pluralize ($word) { - $word .= 's'; - $word = preg_replace ('/(x|ch|sh|ss])s$/', '\1es', $word); - $word = preg_replace ('/ss$/', 'ses', $word); - $word = preg_replace ('/([ti])ums$/', '\1a', $word); - $word = preg_replace ('/sises$/', 'ses', $word); - $word = preg_replace ('/([^aeiouy]|qu)ys$/', '\1ies', $word); - $word = preg_replace ('/(?:([^f])fe|([lr])f)s$/', '\1\2ves', $word); - $word = preg_replace ('/ieses$/', 'ies', $word); - if (isset ($this->pleural_corrections[$word])) { - return $this->pleural_corrections[$word]; - } - return $word; - } - - /** - * For backwards-compatibility. - */ - public function pleuralize ($word) { - return $this->pluralize ($word); - } - - /** - * Saves a new record or updates an existing one via: - * - * POST /collection.xml - * PUT /collection/id.xml - */ - public function save () { - if (isset ($this->_data['id'])) { - return $this->_send_and_receive ($this->site . $this->element_name_plural . '/' . $this->_data['id'] . '.xml', 'PUT', $this->_data); // update - } - return $this->_send_and_receive ($this->site . $this->element_name_plural . '.xml', 'POST', $this->_data); // Create - } - - /** - * Deletes a record via: - * - * DELETE /collection/id.xml - */ - public function destroy () { - return $this->_send_and_receive ($this->site . $this->element_name_plural . '/' . $this->_data['id'] . '.xml', 'DELETE'); - } - - /** - * Finds a record or records via: - * - * GET /collection/id.xml - * GET /collection.xml - */ - public function find ($id = false, $options = array ()) { - if (! $id) { - $id = $this->_data['id']; - } - $options_string = ''; - if (count ($options) > 0) { - $options_string = '?' . http_build_query ($options); - } - if ($id === 'all') { - $url = $this->site . $this->element_name_plural . '.xml'; - return $this->_send_and_receive ($url . $options_string, 'GET'); - } - return $this->_send_and_receive ($this->site . $this->element_name_plural . '/' . $id . '.xml' . $options_string, 'GET'); - } - - /** - * Gets a specified custom method on the current object via: - * - * GET /collection/id/method.xml - * GET /collection/id/method.xml?attr=value - */ - public function get ($method, $options = array ()) { - $req = $this->site . $this->element_name_plural; - if (isset ($this->_data['id']) && $this->_data['id']) { - $req .= '/' . $this->_data['id']; - } - $req .= '/' . $method . '.xml'; - if (count ($options) > 0) { - $req .= '?' . http_build_query ($options); - } - return $this->_send_and_receive ($req, 'GET'); - } - - /** - * Posts to a specified custom method on the current object via: - * - * POST /collection/id/method.xml - */ - function post ($method, $options = array (), $start_tag = false) { - $req = $this->site . $this->element_name_plural; - if ($this->_data['id']) { - $req .= '/' . $this->_data['id']; - } - $req .= '/' . $method . '.xml'; - return $this->_send_and_receive ($req, 'POST', $options, $start_tag); - } - - /** - * Puts to a specified custom method on the current object via: - * - * PUT /collection/id/method.xml - */ - public function put ($method, $options = array (), $options_as_xml = false, $start_tag = false) { - $req = $this->site . $this->element_name_plural; - if ($this->_data['id']) { - $req .= '/' . $this->_data['id']; - } - $req .= '/' . $method . '.xml'; - if ($options_as_xml) { - return $this->_send_and_receive ($req, 'PUT', $options, $start_tag); - } - if (count ($options) > 0) { - $req .= '?' . http_build_query ($options); - } - return $this->_send_and_receive ($req, 'PUT'); - } - - /** - * Simple recursive function to build an XML response. - */ - public function _build_xml ($k, $v) { - if (is_object ($v) && strtolower (get_class ($v)) === 'simplexmlelement') { - return preg_replace ('/<\?xml(.*?)\?>\n*/', '', $v->asXML ()); - } - $res = ''; - $attrs = ''; - if (! is_numeric ($k)) { - $res = '<' . $k . '{{attributes}}>'; - } - if (is_object ($v)) { - $v = (array) $v; - } - if (is_array ($v)) { - foreach ($v as $key => $value) { - // handle attributes of repeating tags - if (is_numeric ($key) && is_array ($value)) { - foreach ($value as $sub_key => $sub_value) { - if (strpos ($sub_key, '@') === 0) { - $attrs .= ' ' . substr ($sub_key, 1) . '="' . $this->_xml_entities ($sub_value) . '"'; - unset ($value[$sub_key]); - continue; - } - } - } - - if (strpos ($key, '@') === 0) { - $attrs .= ' ' . substr ($key, 1) . '="' . $this->_xml_entities ($value) . '"'; - continue; - } - $res .= $this->_build_xml ($key, $value); - $keys = array_keys ($v); - if (is_numeric ($key) && $key !== array_pop ($keys)) { - // reset attributes on repeating tags - if (is_array ($value)) { - $res = str_replace ('<' . $k . '{{attributes}}>', '<' . $k . $attrs . '>', $res); - $attrs = ''; - } - $res .= '\n<" . $k . '{{attributes}}>'; - } - } - } else { - $res .= $this->_xml_entities ($v); - } - if (! is_numeric ($k)) { - $res .= '\n"; - } - $res = str_replace ('<' . $k . '{{attributes}}>', '<' . $k . $attrs . '>', $res); - return $res; - } - - /** - * Returns the unicode value of the string - * - * @param string $c The source string - * @param integer $i The index to get the char from (passed by reference for use in a loop) - * @return integer The value of the char at $c[$i] - * @author kerry at shetline dot com - * @author Dom Hastings - modified to suit my needs - * @see http://www.php.net/manual/en/function.ord.php#78032 - */ - private function _unicode_ord (&$c, &$i = 0) { - // get the character length - $l = strlen($c); - // copy the offset - $index = $i; - - // check it's a valid offset - if ($index >= $l) { - return false; - } - - // check the value - $o = ord($c[$index]); - - // if it's ascii - if ($o <= 0x7F) { - return $o; - - // not sure what it is... - } elseif ($o < 0xC2) { - return false; - - // if it's a two-byte character - } elseif ($o <= 0xDF && $index < $l - 1) { - $i += 1; - return ($o & 0x1F) << 6 | (ord($c[$index + 1]) & 0x3F); - - // three-byte - } elseif ($o <= 0xEF && $index < $l - 2) { - $i += 2; - return ($o & 0x0F) << 12 | (ord($c[$index + 1]) & 0x3F) << 6 | (ord($c[$index + 2]) & 0x3F); - - // four-byte - } elseif ($o <= 0xF4 && $index < $l - 3) { - $i += 3; - return ($o & 0x0F) << 18 | (ord($c[$index + 1]) & 0x3F) << 12 | (ord($c[$index + 2]) & 0x3F) << 6 | (ord($c[$index + 3]) & 0x3F); - - // not sure what it is... - } else { - return false; - } - } - - /** - * Makes the specified string XML-safe - * - * @param string $s - * @param boolean $hex Whether or not to make hexadecimal entities (as opposed to decimal) - * @return string The XML-safe result - * @author Dom Hastings - * @see http://www.w3.org/TR/REC-xml/#sec-predefined-ent - */ - public function _xml_entities ($s, $hex = true) { - // if the string is empty - if (empty($s)) { - // just return it - return $s; - } - $s = (string) $s; - - // create the return string - $r = ''; - // get the length - $l = strlen($s); - - // iterate the string - for ($i = 0; $i < $l; $i++) { - // get the value of the character - $o = $this->_unicode_ord($s, $i); - - // valid characters - $v = ( - // \t \n

\r - ($o >= 9 && $o <= 13) || - // ! - ($o === 32) || ($o === 33) || - // # $ % - ($o >= 35 && $o <= 37) || - // ( ) * + , - . / - ($o >= 40 && $o <= 47) || - // numbers - ($o >= 48 && $o <= 57) || - // : ; - ($o === 58) || ($o === 59) || - // = ? - ($o === 61) || ($o === 63) || - // @ - ($o === 64) || - // uppercase - ($o >= 65 && $o <= 90) || - // [ \ ] ^ _ ` - ($o >= 91 && $o <= 96) || - // lowercase - ($o >= 97 && $o <= 122) || - // { | } ~ - ($o >= 123 && $o <= 126) - ); - - // if it's valid, just keep it - if ($v) { - $r .= $s[$i]; - - // & - } elseif ($o === 38) { - $r .= '&'; - - // < - } elseif ($o === 60) { - $r .= '<'; - - // > - } elseif ($o === 62) { - $r .= '>'; - - // ' - } elseif ($o === 39) { - $r .= '''; - - // " - } elseif ($o === 34) { - $r .= '"'; - - // unknown, add it as a reference - } elseif ($o > 0) { - if ($hex) { - $r .= '&#x'.strtoupper(dechex($o)).';'; - - } else { - $r .= '&#'.$o.';'; - } - } - } - - return $r; - } - - /** - * Build the request, call `_fetch()` and parse the results. - */ - private function _send_and_receive ($url, $method, $data = array (), $start_tag = false) { - $params = ''; - $el = $start_tag ? $start_tag : $this->element_name; // Singular this time - if ($this->request_format === 'url') { - foreach ($data as $k => $v) { - if ($k !== 'id' && $k !== 'created-at' && $k !== 'updated-at') { - $params .= '&' . $el . '[' . str_replace ('-', '_', $k) . ']=' . rawurlencode ($v); - } - } - $params = substr ($params, 1); - } elseif ($this->request_format === 'xml') { - $params = '<' . $el . ">\n"; - foreach ($data as $k => $v) { - if ($k !== 'id' && $k !== 'created-at' && $k !== 'updated-at') { - $params .= $this->_build_xml ($k, $v); - } - } - $params .= ''; - } - - if ($this->extra_params !== false) { - $url = $url . $this->extra_params; - } - - $this->request_body = $params; - $this->request_uri = $url; - $this->request_method = $method; - - $res = $this->_fetch ($url, $method, $params); - - if ($res === false) { - return $this; - } - - // Keep splitting off any top headers until we get to the (XML) body: - while (strpos($res, "HTTP/") === 0) { - list ($headers, $res) = explode ("\r\n\r\n", $res, 2); - $this->response_headers = $headers; - $this->response_body = $res; - if (preg_match ('/HTTP\/[0-9]\.[0-9] ([0-9]+)/', $headers, $regs)) { - $this->response_code = $regs[1]; - } else { - $this->response_code = false; - } - - if (! $res) { - return $this; - } elseif ($res === ' ') { - $this->error = 'Empty reply'; - return $this; - } - } - - // Parse XML response - $xml = new SimpleXMLElement ($res); - - // Normalize xml element name in case rails ressource contains an underscore - if (str_replace ('-', '_', $xml->getName ()) === $this->element_name_plural) { - // Multiple - $res = array (); - $cls = get_class ($this); - foreach ($xml->children () as $child) { - $obj = new $cls; - foreach ((array) $child as $k => $v) { - $k = str_replace ('-', '_', $k); - if (isset ($v['nil']) && $v['nil'] === 'true') { - continue; - } else { - $obj->_data[$k] = $v; - } - } - $res[] = $obj; - } - return $res; - } elseif ($xml->getName () === 'errors') { - // Parse error message - $this->error = $xml->error; - $this->errno = $this->response_code; - return false; - } - - foreach ((array) $xml as $k => $v) { - $k = str_replace ('-', '_', $k); - if (isset ($v['nil']) && $v['nil'] === 'true') { - continue; - } else { - $this->_data[$k] = $v; - } - } - return $this; - } - - /** - * Fetch the specified request via cURL. - */ - private function _fetch ($url, $method, $params) { - if (! extension_loaded ('curl')) { - $this->error = 'cURL extension not loaded.'; - return false; - } - - $ch = curl_init (); - curl_setopt ($ch, CURLOPT_URL, $url); - curl_setopt ($ch, CURLOPT_MAXREDIRS, 3); - curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); - curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt ($ch, CURLOPT_VERBOSE, 0); - curl_setopt ($ch, CURLOPT_HEADER, 1); - curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10); - curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); - curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); - - // HTTP Basic Authentication - if ($this->user && $this->password) { - curl_setopt ($ch, CURLOPT_USERPWD, $this->user . ":" . $this->password); - } - - if ($this->request_format === 'xml') { - $this->request_headers = array_merge ($this->request_headers, array ("Expect:", "Content-Type: text/xml", "Length: " . strlen ($params))); - } - switch ($method) { - case 'POST': - curl_setopt ($ch, CURLOPT_POST, 1); - curl_setopt ($ch, CURLOPT_POSTFIELDS, $params); - break; - case 'DELETE': - curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); - break; - case 'PUT': - curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); - curl_setopt ($ch, CURLOPT_POSTFIELDS, $params); - break; - case 'GET': - default: - break; - } - - if (count ($this->request_headers)) { - curl_setopt ($ch, CURLOPT_HTTPHEADER, $this->request_headers); - } - - $res = curl_exec ($ch); - - // Check HTTP status code for denied access - $http_code = curl_getinfo ($ch, CURLINFO_HTTP_CODE); - if ($http_code === 401) { - $this->errno = $http_code; - $this->error = "HTTP Basic: Access denied."; - curl_close ($ch); - return false; - } - - if (! $res) { - $this->errno = curl_errno ($ch); - $this->error = curl_error ($ch); - curl_close ($ch); - return false; - } - - curl_close ($ch); - return $res; - } - - /** - * Getter for internal object data. - */ - public function __get ($k) { - if (isset ($this->_data[$k])) { - return $this->_data[$k]; - } - return $this->{$k}; - } - - /** - * Setter for internal object data. - */ - public function __set ($k, $v) { - if (isset ($this->_data[$k])) { - $this->_data[$k] = $v; - return; - } - $this->{$k} = $v; - } - - /** - * Quick setter for chaining methods. - */ - public function set ($k, $v = false) { - if (! $v && is_array ($k)) { - foreach ($k as $key => $value) { - $this->_data[$key] = $value; - } - } else { - $this->_data[$k] = $v; - } - return $this; - } -} - -?> \ No newline at end of file diff --git a/lib/vendor/Analog.php b/lib/vendor/Analog.php deleted file mode 100644 index 7f083f825..000000000 --- a/lib/vendor/Analog.php +++ /dev/null @@ -1,22 +0,0 @@ -values[$id] = $value; - } - - /** - * Gets a parameter or an object. - * - * @param string $id The unique identifier for the parameter or object - * - * @return mixed The value of the parameter or an object - * - * @throws InvalidArgumentException if the identifier is not defined - */ - function offsetGet($id) - { - if (!array_key_exists($id, $this->values)) { - throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id)); - } - - return $this->values[$id] instanceof Closure ? $this->values[$id]($this) : $this->values[$id]; - } - - /** - * Checks if a parameter or an object is set. - * - * @param string $id The unique identifier for the parameter or object - * - * @return Boolean - */ - function offsetExists($id) - { - return isset($this->values[$id]); - } - - /** - * Unsets a parameter or an object. - * - * @param string $id The unique identifier for the parameter or object - */ - function offsetUnset($id) - { - unset($this->values[$id]); - } - - /** - * Returns a closure that stores the result of the given closure for - * uniqueness in the scope of this instance of Pimple. - * - * @param Closure $callable A closure to wrap for uniqueness - * - * @return Closure The wrapped closure - */ - function share(Closure $callable) - { - return function ($c) use ($callable) { - static $object; - - if (is_null($object)) { - $object = $callable($c); - } - - return $object; - }; - } - - /** - * Protects a callable from being interpreted as a service. - * - * This is useful when you want to store a callable as a parameter. - * - * @param Closure $callable A closure to protect from being evaluated - * - * @return Closure The protected closure - */ - function protect(Closure $callable) - { - return function ($c) use ($callable) { - return $callable; - }; - } - - /** - * Gets a parameter or the closure defining an object. - * - * @param string $id The unique identifier for the parameter or object - * - * @return mixed The value of the parameter or the closure defining an object - * - * @throws InvalidArgumentException if the identifier is not defined - */ - function raw($id) - { - if (!array_key_exists($id, $this->values)) { - throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id)); - } - - return $this->values[$id]; - } -} \ No newline at end of file diff --git a/lib/vendor/URLify.php b/lib/vendor/URLify.php deleted file mode 100644 index 72a051bb7..000000000 --- a/lib/vendor/URLify.php +++ /dev/null @@ -1,188 +0,0 @@ - array ( - 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'AE', 'Ç' => - 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', - 'Ï' => 'I', 'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => - 'O', 'Ő' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ű' => 'U', - 'Ý' => 'Y', 'Þ' => 'TH', 'ß' => 'ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => - 'a', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', - 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'd', 'ñ' => 'n', 'ò' => 'o', 'ó' => - 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ő' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', - 'û' => 'u', 'ü' => 'u', 'ű' => 'u', 'ý' => 'y', 'þ' => 'th', 'ÿ' => 'y' - ), - 'latin_symbols_map' => array ( - '©' => '(c)' - ), - 'greek_map' => array ( - 'α' => 'a', 'β' => 'b', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'ζ' => 'z', 'η' => 'h', 'θ' => '8', - 'ι' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => '3', 'ο' => 'o', 'π' => 'p', - 'ρ' => 'r', 'σ' => 's', 'τ' => 't', 'υ' => 'y', 'φ' => 'f', 'χ' => 'x', 'ψ' => 'ps', 'ω' => 'w', - 'ά' => 'a', 'έ' => 'e', 'ί' => 'i', 'ό' => 'o', 'ύ' => 'y', 'ή' => 'h', 'ώ' => 'w', 'ς' => 's', - 'ϊ' => 'i', 'ΰ' => 'y', 'ϋ' => 'y', 'ΐ' => 'i', - 'Α' => 'A', 'Β' => 'B', 'Γ' => 'G', 'Δ' => 'D', 'Ε' => 'E', 'Ζ' => 'Z', 'Η' => 'H', 'Θ' => '8', - 'Ι' => 'I', 'Κ' => 'K', 'Λ' => 'L', 'Μ' => 'M', 'Ν' => 'N', 'Ξ' => '3', 'Ο' => 'O', 'Π' => 'P', - 'Ρ' => 'R', 'Σ' => 'S', 'Τ' => 'T', 'Υ' => 'Y', 'Φ' => 'F', 'Χ' => 'X', 'Ψ' => 'PS', 'Ω' => 'W', - 'Ά' => 'A', 'Έ' => 'E', 'Ί' => 'I', 'Ό' => 'O', 'Ύ' => 'Y', 'Ή' => 'H', 'Ώ' => 'W', 'Ϊ' => 'I', - 'Ϋ' => 'Y' - ), - 'turkish_map' => array ( - 'ş' => 's', 'Ş' => 'S', 'ı' => 'i', 'İ' => 'I', 'ç' => 'c', 'Ç' => 'C', 'ü' => 'u', 'Ü' => 'U', - 'ö' => 'o', 'Ö' => 'O', 'ğ' => 'g', 'Ğ' => 'G' - ), - 'russian_map' => array ( - 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'yo', 'ж' => 'zh', - 'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', - 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', - 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sh', 'ъ' => '', 'ы' => 'y', 'ь' => '', 'э' => 'e', 'ю' => 'yu', - 'я' => 'ya', - 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'Yo', 'Ж' => 'Zh', - 'З' => 'Z', 'И' => 'I', 'Й' => 'J', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O', - 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', - 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sh', 'Ъ' => '', 'Ы' => 'Y', 'Ь' => '', 'Э' => 'E', 'Ю' => 'Yu', - 'Я' => 'Ya' - ), - 'ukrainian_map' => array ( - 'Є' => 'Ye', 'І' => 'I', 'Ї' => 'Yi', 'Ґ' => 'G', 'є' => 'ye', 'і' => 'i', 'ї' => 'yi', 'ґ' => 'g' - ), - 'czech_map' => array ( - 'č' => 'c', 'ď' => 'd', 'ě' => 'e', 'ň' => 'n', 'ř' => 'r', 'š' => 's', 'ť' => 't', 'ů' => 'u', - 'ž' => 'z', 'Č' => 'C', 'Ď' => 'D', 'Ě' => 'E', 'Ň' => 'N', 'Ř' => 'R', 'Š' => 'S', 'Ť' => 'T', - 'Ů' => 'U', 'Ž' => 'Z' - ), - 'polish_map' => array ( - 'ą' => 'a', 'ć' => 'c', 'ę' => 'e', 'ł' => 'l', 'ń' => 'n', 'ó' => 'o', 'ś' => 's', 'ź' => 'z', - 'ż' => 'z', 'Ą' => 'A', 'Ć' => 'C', 'Ę' => 'e', 'Ł' => 'L', 'Ń' => 'N', 'Ó' => 'o', 'Ś' => 'S', - 'Ź' => 'Z', 'Ż' => 'Z' - ), - 'latvian_map' => array ( - 'ā' => 'a', 'č' => 'c', 'ē' => 'e', 'ģ' => 'g', 'ī' => 'i', 'ķ' => 'k', 'ļ' => 'l', 'ņ' => 'n', - 'š' => 's', 'ū' => 'u', 'ž' => 'z', 'Ā' => 'A', 'Č' => 'C', 'Ē' => 'E', 'Ģ' => 'G', 'Ī' => 'i', - 'Ķ' => 'k', 'Ļ' => 'L', 'Ņ' => 'N', 'Š' => 'S', 'Ū' => 'u', 'Ž' => 'Z' - ) - ); - - /** - * List of words to remove from URLs. - */ - public static $remove_list = array ( - 'a', 'an', 'as', 'at', 'before', 'but', 'by', 'for', 'from', - 'is', 'in', 'into', 'like', 'of', 'off', 'on', 'onto', 'per', - 'since', 'than', 'the', 'this', 'that', 'to', 'up', 'via', - 'with' - ); - - /** - * The character map. - */ - private static $map = array (); - - /** - * The character list as a string. - */ - private static $chars = ''; - - /** - * The character list as a regular expression. - */ - private static $regex = ''; - - /** - * Initializes the character map. - */ - private static function init () { - if (count (self::$map) > 0) { - return; - } - - foreach (self::$maps as $map) { - foreach ($map as $orig => $conv) { - self::$map[$orig] = $conv; - self::$chars .= $orig; - } - } - - self::$regex = '/[' . self::$chars . ']/u'; - } - - /** - * Add new characters to the list. `$map` should be a hash. - */ - public static function add_chars ($map) { - if (! is_array ($map)) { - throw new LogicException ('$map must be an associative array.'); - } - self::$maps[] = $map; - self::$map = array (); - self::$chars = ''; - } - - /** - * Append words to the remove list. Accepts either single words - * or an array of words. - */ - public static function remove_words ($words) { - $words = is_array ($words) ? $words : array ($words); - self::$remove_list = array_merge (self::$remove_list, $words); - } - - /** - * Transliterates characters to their ASCII equivalents. - */ - public static function downcode ($text) { - self::init (); - - if (preg_match_all (self::$regex, $text, $matches)) { - for ($i = 0; $i < count ($matches[0]); $i++) { - $char = $matches[0][$i]; - if (isset (self::$map[$char])) { - $text = str_replace ($char, self::$map[$char], $text); - } - } - } - return $text; - } - - /** - * Filters a string, e.g., "Petty theft" to "petty-theft" - */ - public static function filter ($text, $length = 60) { - $text = self::downcode ($text); - - // remove all these words from the string before urlifying - $text = preg_replace ('/\b(' . join ('|', self::$remove_list) . ')\b/i', '', $text); - - // if downcode doesn't hit, the char will be stripped here - $text = preg_replace ('/[^-\w\s]/', '', $text); // remove unneeded chars - $text = preg_replace ('/^\s+|\s+$/', '', $text); // trim leading/trailing spaces - $text = preg_replace ('/[-\s]+/', '-', $text); // convert spaces to hyphens - $text = strtolower ($text); // convert to lowercase - return trim (substr ($text, 0, $length), '-'); // trim to first $length chars - } - - /** - * Alias of `URLify::downcode()`. - */ - public static function transliterate ($text) { - return self::downcode ($text); - } -} - -?> \ No newline at end of file