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 .= '' . $k . ">\n<" . $k . '{{attributes}}>';
- }
- }
- } else {
- $res .= $this->_xml_entities ($v);
- }
- if (! is_numeric ($k)) {
- $res .= '' . $k . ">\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