Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 0a36bd36a371eccbee623c6e36c21cca9c9607e0 0 parents
@EvanDotPro EvanDotPro authored
Showing with 3,157 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +3 −0  .gitmodules
  3. +279 −0 GPL-LICENSE.txt
  4. +20 −0 MIT-LICENSE.txt
  5. +1 −0  README
  6. +43 −0 application/ClientBootstrap.php
  7. +24 −0 application/ServerBootstrap.php
  8. +30 −0 application/configs/all.ini
  9. +37 −0 application/configs/client.ini
  10. +25 −0 application/configs/server.ini
  11. +11 −0 application/configs/sites/backend.cosmos.ini
  12. +9 −0 application/configs/sites/cosmos.ini
  13. +96 −0 application/init.php
  14. +4 −0 application/modules/api/Bootstrap.php
  15. +4 −0 application/modules/backend/Bootstrap.php
  16. +35 −0 application/modules/backend/controllers/ErrorController.php
  17. +14 −0 application/modules/backend/controllers/IndexController.php
  18. +18 −0 application/modules/backend/controllers/LoginController.php
  19. +23 −0 application/modules/backend/views/layouts/layout.phtml
  20. +24 −0 application/modules/backend/views/layouts/login.phtml
  21. +16 −0 application/modules/backend/views/scripts/error/error.phtml
  22. +1 −0  application/modules/backend/views/scripts/index/index.phtml
  23. +24 −0 application/modules/backend/views/scripts/login/index.phtml
  24. +4 −0 application/modules/checkout/Bootstrap.php
  25. +35 −0 application/modules/checkout/controllers/ErrorController.php
  26. +7 −0 application/modules/checkout/controllers/IndexController.php
  27. +26 −0 application/modules/checkout/views/layouts/layout.phtml
  28. +1 −0  application/modules/checkout/views/scripts/account/login.phtml
  29. +16 −0 application/modules/checkout/views/scripts/error/error.phtml
  30. +2 −0  application/modules/checkout/views/scripts/index/index.phtml
  31. +4 −0 application/modules/storefront/Bootstrap.php
  32. +7 −0 application/modules/storefront/controllers/AccountController.php
  33. +35 −0 application/modules/storefront/controllers/ErrorController.php
  34. +14 −0 application/modules/storefront/controllers/IndexController.php
  35. +26 −0 application/modules/storefront/views/layouts/layout.phtml
  36. +1 −0  application/modules/storefront/views/scripts/account/login.phtml
  37. +16 −0 application/modules/storefront/views/scripts/error/error.phtml
  38. +2 −0  application/modules/storefront/views/scripts/index/index.phtml
  39. +66 −0 application/services/1.0/Calculator.php
  40. +2 −0  application/services/1.0/services.ini
  41. +9 −0 httpdocs/.htaccess
  42. +9 −0 httpdocs/api/.htaccess
  43. +6 −0 httpdocs/api/index.php
  44. +6 −0 httpdocs/index.php
  45. BIN  httpdocs/theme/backend/default/key.png
  46. BIN  httpdocs/theme/backend/test/key.png
  47. +29 −0 library/Cosmos/Api.php
  48. +171 −0 library/Cosmos/Api/Client.php
  49. +2 −0  library/Cosmos/Api/Client/Exception.php
  50. +55 −0 library/Cosmos/Api/Client/JsonRpc.php
  51. +28 −0 library/Cosmos/Api/Client/JsonRpc/Request.php
  52. +70 −0 library/Cosmos/Api/Client/Local.php
  53. +99 −0 library/Cosmos/Api/Client/ServerProxy.php
  54. +16 −0 library/Cosmos/Api/Client/XmlRpc.php
  55. +2 −0  library/Cosmos/Api/Exception.php
  56. +361 −0 library/Cosmos/Api/Request.php
  57. +161 −0 library/Cosmos/Api/Request/Http.php
  58. +109 −0 library/Cosmos/Api/Response.php
  59. +5 −0 library/Cosmos/Api/Response/Http.php
  60. +214 −0 library/Cosmos/Api/Server.php
  61. +2 −0  library/Cosmos/Api/Server/Exception.php
  62. +24 −0 library/Cosmos/Api/Server/JsonRpc.php
  63. +76 −0 library/Cosmos/Api/Server/Local.php
  64. +20 −0 library/Cosmos/Api/Server/XmlRpc.php
  65. +46 −0 library/Cosmos/Bootstrap.php
  66. +6 −0 library/Cosmos/Cart.php
  67. +237 −0 library/Cosmos/Profiler.php
  68. +82 −0 library/Cosmos/Sso.php
  69. +1 −0  library/Zend
  70. +102 −0 library/ZendC/Application.php
  71. +167 −0 library/ZendC/Json/Client.php
  72. +20 −0 library/ZendC/Json/Server/Request/Http.php
  73. +13 −0 library/ZendC/Layout/ModularLayoutDirectory.php
  74. 0  tests/.gitignore
4 .gitignore
@@ -0,0 +1,4 @@
+application/data/cache
+application/data/logs
+application/data/sessions
+!.gitignore
3  .gitmodules
@@ -0,0 +1,3 @@
+[submodule "library/Zend"]
+ path = library/Zend
+ url = git://github.com/cosmoscommerce/zf-library.git
279 GPL-LICENSE.txt
@@ -0,0 +1,279 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
20 MIT-LICENSE.txt
@@ -0,0 +1,20 @@
+Copyright (c) 2010 Cosmos Team, http://cosmoscommerce.org/
+
+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 AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1  README
@@ -0,0 +1 @@
+COSMOS COMMERCE README GOES HERE
43 application/ClientBootstrap.php
@@ -0,0 +1,43 @@
+<?php
+class ClientBootstrap extends Cosmos_Bootstrap
+{
+ protected function _initDatabase()
+ {
+ $this->initDatabase();
+ }
+
+ protected function _initLog()
+ {
+ $this->initLog();
+ }
+
+ protected function _initClientSession()
+ {
+ $this->bootstrap('session');
+ $options = $this->getOptions();
+
+ Cosmos_Sso::initiate($options['cosmos']['namespace']);
+ }
+
+ protected function _initTheme()
+ {
+ $options = $this->getOptions();
+ defined('COSMOS_THEME')
+ || define('COSMOS_THEME',
+ (isset($options['cosmos']['theme']) ? $options['cosmos']['theme']
+ : 'default'));
+ }
+
+ protected function _initApiClient()
+ {
+ $options = $this->getOptions();
+ try {
+// if(Zend_Registry::get('csession')->apiToken){
+ $client = new Cosmos_Api_Client($options['cosmos']['api']);
+ Zend_Registry::set('api',$client->getProxy());
+// }
+ } catch (Exception $e){
+ Zend_Registry::get('log')->err($e);
+ }
+ }
+}
24 application/ServerBootstrap.php
@@ -0,0 +1,24 @@
+<?php
+class ServerBootstrap extends Cosmos_Bootstrap
+{
+ protected function _initDatabase()
+ {
+ $this->initDatabase();
+ }
+
+ protected function _initApiServer()
+ {
+ $server = new Cosmos_Api_Server(new Cosmos_Api_Request_Http());
+ var_dump($server->handle()); die('done');
+ }
+
+ protected function _initApiSession()
+ {
+ $this->initSession();
+ }
+
+ protected function _initLogger()
+ {
+ $this->initLog();
+ }
+}
30 application/configs/all.ini
@@ -0,0 +1,30 @@
+[production]
+phpsettings.display_startup_errors = 0
+phpsettings.display_errors = 0
+phpsettings.date.timezone = "America/Phoenix"
+
+autoloadernamespaces[] = "Cosmos"
+autoloadernamespaces[] = "ZendC"
+
+resources.session.name = "cosmos"
+
+resources.multidb.master.adapter = "pdo_mysql"
+resources.multidb.master.host = "localdev"
+resources.multidb.master.username = "cosmos"
+resources.multidb.master.password = "cosmos"
+resources.multidb.master.dbname = "cosmos"
+resources.multidb.master.isDefaultTableAdapter = true
+resources.multidb.master.default = true
+
+config[] = APPLICATION_PATH "/configs/" APPLICATION_MODE ".ini";
+config[] = APPLICATION_PATH "/configs/sites/" APPLICATION_HOST ".ini";
+
+[staging : production]
+
+[testing : production]
+phpSettings.display_startup_errors = 1
+phpSettings.display_errors = 1
+
+[development : production]
+phpsettings.display_startup_errors = 1
+phpsettings.display_errors = 1
37 application/configs/client.ini
@@ -0,0 +1,37 @@
+[production]
+bootstrap.path = APPLICATION_PATH "/ClientBootstrap.php"
+bootstrap.class = "ClientBootstrap"
+
+resources.modules =
+resources.layout.pluginclass = "ZendC_Layout_ModularLayoutDirectory"
+resources.frontcontroller.moduledirectory = APPLICATION_PATH "/modules"
+resources.frontcontroller.defaultmodule = "storefront"
+resources.frontcontroller.throwexceptions = false
+resources.frontcontroller.returnresponse = true
+resources.frontcontroller.prefixDefaultModule = true
+
+resources.session.save_path = APPLICATION_PATH "/data/sessions"
+
+resources.log.stream.writerName = "Stream"
+resources.log.stream.writerParams.stream = APPLICATION_PATH "/data/logs/client.log"
+resources.log.stream.writerParams.mode = "a"
+resources.log.stream.filterName = "Priority"
+resources.log.stream.filterParams.priority = 4
+
+cosmos.namespace = "cosmos"
+
+resources.multidb.master.profiler.enabled = true
+resources.multidb.master.profiler.class = Zend_Db_Profiler_Firebug
+
+cosmos.api.version = "1.0"
+cosmos.api.requestFormat = "local"
+;cosmos.api.responseFormat = "jsonrpc"
+;cosmos.api.url = "http://cosmos/api/1.0/xmlrpc"
+;cosmos.api.url = "http://cosmos/api/1.0/jsonrpc"
+
+[staging : production]
+
+[testing : production]
+
+[development : production]
+cosmos.logToFirebug = true
25 application/configs/server.ini
@@ -0,0 +1,25 @@
+[production]
+phpsettings.session.use_cookies = false
+
+bootstrap.path = APPLICATION_PATH "/ServerBootstrap.php"
+bootstrap.class = "ServerBootstrap"
+
+resources.log.stream.writerName = "Stream"
+resources.log.stream.writerParams.stream = APPLICATION_PATH "/data/logs/server.log"
+resources.log.stream.writerParams.mode = "a"
+resources.log.stream.filterName = "Priority"
+resources.log.stream.filterParams.priority = 4
+
+;resources.session.savehandler.class = "Zend_Session_SaveHandler_DbTable"
+;resources.session.savehandler.options.name = "api_session"
+;resources.session.savehandler.options.primary = "session_id"
+;resources.session.savehandler.options.modifiedcolumn = "modified"
+;resources.session.savehandler.options.lifetimecolumn = "lifetime"
+;resources.session.savehandler.options.datacolumn = "session_data"
+;resources.session.savehandler.options.lifetime = 2592000
+
+[staging : production]
+
+[testing : production]
+
+[development : production]
11 application/configs/sites/backend.cosmos.ini
@@ -0,0 +1,11 @@
+[production]
+cosmos.api.consumerKey = "4fed8ae0543f91b37f0372f9f27134c"
+resources.frontcontroller.defaultmodule = "backend"
+
+;cosmos.theme = "default"
+
+[staging : production]
+
+[testing : production]
+
+[development : production]
9 application/configs/sites/cosmos.ini
@@ -0,0 +1,9 @@
+[production]
+cosmos.api.consumerKey = "4fed8ae0543f91b37f0372f9f27134c"
+;cosmos.api.consumerSecret = "3948t5uhaeiurth3478t5hi87a45y745"
+
+[staging : production]
+
+[testing : production]
+
+[development : production]
96 application/init.php
@@ -0,0 +1,96 @@
+<?php
+/**
+ * Cosmos Commerce
+ *
+ * LICENSE
+ *
+ * This source file is dual licensed under the MIT or GPL Version 2
+ * licenses that are bundled with this package in the files
+ * GPL-LICENSE.txt and MIT-LICENSE.txt.
+ * A copy is also available through the world-wide-web at this URL:
+ * http://cosmoscommerce.org/license
+ * If you did not receive a copy of these licenses and are unable
+ * to obtain a copy through the world-wide-web, please send an email
+ * to license@cosmoscommerce.org so we can send you a copy immediately.
+ *
+ * @category Cosmos
+ * @package Cosmos_Bootstrap
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ */
+
+// Define path to application directory
+defined('APPLICATION_PATH')
+ || define('APPLICATION_PATH',
+ realpath(dirname(__FILE__) . '/../application'));
+
+// Define path to library directory
+defined('LIBRARY_PATH')
+ || define('LIBRARY_PATH',
+ realpath(dirname(__FILE__) . '/../library'));
+
+// Define application environment
+defined('APPLICATION_ENV')
+ || define('APPLICATION_ENV',
+ (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV')
+ : 'production'));
+
+// Define application environment
+defined('APPLICATION_MODE')
+ || define('APPLICATION_MODE',
+ (getenv('APPLICATION_MODE') ? getenv('APPLICATION_MODE')
+ : 'local'));
+// Define the host name requested
+defined('APPLICATION_HOST')
+ || define('APPLICATION_HOST',
+ (getenv('APPLICATION_HOST') ? getenv('APPLICATION_HOST')
+ : $_SERVER['HTTP_HOST']));
+
+// Set the include path
+set_include_path(implode(PATH_SEPARATOR, array(LIBRARY_PATH,'.')));
+
+// Start up the profiler
+require_once 'Cosmos/Profiler.php';
+Cosmos_Profiler::enable();
+Cosmos_Profiler::start('app');
+
+// Bootsrap
+Cosmos_Profiler::start('bootstrap');
+try {
+ require_once 'ZendC/Application.php';
+ $application = new ZendC_Application(
+ APPLICATION_ENV,
+ APPLICATION_PATH . '/configs/all.ini'
+ );
+ $application->bootstrap();
+} catch(Zend_Config_Exception $e){
+ if($e instanceof Zend_Config_Exception){
+ // This is a bit sloppy, but the front controller won't catch these otherwise
+ $exceptionMessage = strtolower($e->getMessage());
+ if(strpos($exceptionMessage, 'syntax error') !== false){
+ $message = 'Configuration Error - Invalid Syntax';
+ } elseif(strpos($exceptionMessage, 'no such file') !== false){
+ $message = 'Configuration Error - Invalid Host';
+ } else {
+ $message = 'Configuration Error - Unknown Error';
+ }
+ } else {
+ var_dump($e);
+ $message = 'hello';
+ }
+ die($message);
+}
+Cosmos_Profiler::stop('bootstrap');
+
+// Run
+Cosmos_Profiler::start('run');
+$response = $application->run();
+Cosmos_Profiler::stop('run');
+
+// Stop the profiler and send output to browser
+Cosmos_Profiler::stop('app');
+
+if(APPLICATION_MODE != 'server'){
+ Cosmos_Profiler::_toFirebug();
+ $response->sendResponse();
+}
4 application/modules/api/Bootstrap.php
@@ -0,0 +1,4 @@
+<?php
+class Api_Bootstrap extends Zend_Application_Module_Bootstrap
+{
+}
4 application/modules/backend/Bootstrap.php
@@ -0,0 +1,4 @@
+<?php
+class Backend_Bootstrap extends Zend_Application_Module_Bootstrap
+{
+}
35 application/modules/backend/controllers/ErrorController.php
@@ -0,0 +1,35 @@
+<?php
+class Backend_ErrorController extends Zend_Controller_Action {
+
+ public function errorAction()
+ {
+ //error_reporting(0);
+
+ $errors = $this->_getParam('error_handler');
+
+ Zend_Registry::get('log')->err($errors['exception']);
+
+ switch ($errors->type) {
+ case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
+ case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
+ // 404 error -- controller or action not found
+ $this->getResponse()->setHttpResponseCode(404);
+ $this->view->errorType = 404;
+ // Uncomment these lines to force showing of debug info
+// $this->_helper->layout->disableLayout();
+// var_dump($errors);
+ break;
+ default:
+ // 500 error -- application error
+ $this->getResponse()->setHttpResponseCode(500);
+ $this->view->errorType = 500;
+ // Uncomment these lines to force showing of debug info
+// $this->_helper->layout->disableLayout();
+// var_dump($errors);
+ break;
+ }
+
+
+ }
+
+}
14 application/modules/backend/controllers/IndexController.php
@@ -0,0 +1,14 @@
+<?php
+class Backend_IndexController extends Zend_Controller_Action
+{
+ public function init()
+ {
+ if (!Zend_Auth::getInstance()->hasIdentity()){
+ return $this->_helper->redirector('index','login','backend');
+ }
+ }
+
+ public function indexAction()
+ {
+ }
+}
18 application/modules/backend/controllers/LoginController.php
@@ -0,0 +1,18 @@
+<?php
+class Backend_LoginController extends Zend_Controller_Action
+{
+ public function init()
+ {
+ $this->_helper->layout->setLayout('login');
+ }
+
+ public function indexAction()
+ {
+
+ }
+
+ public function authenticateAction()
+ {
+ print_r($_POST);die();
+ }
+}
23 application/modules/backend/views/layouts/layout.phtml
@@ -0,0 +1,23 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
+<head>
+ <title>TEST Admin Module / Store Management</title>
+</head>
+<body>
+
+<div id="header">
+ <h3>FOUND ME!</h3>
+</div>
+
+<div class="clearfix">
+ <div id="content">
+ <?= $this->layout()->content; ?>
+ </div>
+</div>
+
+<div id="footer">
+&copy; <?= date('Y'); ?> CosmosCommerce.com
+</div>
+
+</body>
+</html>
24 application/modules/backend/views/layouts/login.phtml
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Cosmos Commerce Ecommerce Operations Center &raquo; Login</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+<meta name="robots" content="noindex, nofollow" />
+<script type="text/javascript" src="http://cosmos/sso?csid=<?= Zend_Session::getId(); ?>"></script>
+<link rel="icon" href="http://www.southwestmedical.com/favicon.ico" type="image/x-icon" />
+<link rel="shortcut icon" href="http://www.southwestmedical.com/favicon.ico" type="image/ico" />
+<style type="text/css">
+body { font-family: tahoma,Arial,Helvetica,sans-serif; font-size: 11px; }
+fieldset { width: 250px; margin: 50px auto; }
+legend { font-size: 1.5em; font-weight: bold; }
+table { margin: 0px auto; }
+</style>
+</head>
+<body>
+<?= $this->layout()->content; ?>
+&copy; <?= date('Y'); ?> CosmosCommerce.com<br/>
+(SESSION: <?= Zend_Session::getId(); ?>)<br/>
+</body>
+</html>
+
+
16 application/modules/backend/views/scripts/error/error.phtml
@@ -0,0 +1,16 @@
+<div id="error-wrapper">
+<? if($this->errorType == 404): ?>
+ <p>Unfortunately the page you are looking for does not exist.</p>
+ <p>This may have been caused by one of the following:</p>
+ <ul>
+ <li>If you typed the URL in manually, you may have made a minor mistake when typing in in, check the URL and try again.</li>
+ <li>If you were linked to this site from another page, they may have gotten the link wrong or the linked page may no longer exists.</li>
+ <li>The page may have moved, you may find it elsewhere on the site.</li>
+ </ul>
+<? elseif($this->errorType == 500): ?>
+ <p>There was a temporary problem on the server.</p>
+ <p>We are working to resolve this issue. Please try again shortly.</p>
+<? else: ?>
+ <p>Oh no......</p>
+<? endif; ?>
+</div>
1  application/modules/backend/views/scripts/index/index.phtml
@@ -0,0 +1 @@
+admin module
24 application/modules/backend/views/scripts/login/index.phtml
@@ -0,0 +1,24 @@
+ <form method="post" action="/login/authenticate">
+ <fieldset id="login">
+
+ <legend><img src="/theme/backend/<?=COSMOS_THEME;?>/key.png"/> Authorization Required</legend>
+ <table width="190">
+ <tr>
+ <td colspan="2">
+ <ul class="messages"></ul>
+ </td>
+ </tr>
+ <tr>
+ <td align="right">Username:</td>
+ <td align="right"><input type="text" name="username" /></td>
+ </tr>
+ <tr>
+ <td align="right">Password:</td>
+ <td align="right"><input type="password" name="password" /></td>
+ </tr>
+ <tr>
+ <td colspan="2" align="right"><input type="submit" value="Login" /></td>
+ </tr>
+ </table>
+ </fieldset>
+</form>
4 application/modules/checkout/Bootstrap.php
@@ -0,0 +1,4 @@
+<?php
+class Checkout_Bootstrap extends Zend_Application_Module_Bootstrap
+{
+}
35 application/modules/checkout/controllers/ErrorController.php
@@ -0,0 +1,35 @@
+<?php
+class Checkout_ErrorController extends Zend_Controller_Action {
+
+ public function errorAction()
+ {
+ //error_reporting(0);
+
+ $errors = $this->_getParam('error_handler');
+
+ Zend_Registry::get('log')->err($errors['exception']);
+
+ switch ($errors->type) {
+ case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
+ case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
+ // 404 error -- controller or action not found
+ $this->getResponse()->setHttpResponseCode(404);
+ $this->view->errorType = 404;
+ // Uncomment these lines to force showing of debug info
+// $this->_helper->layout->disableLayout();
+// var_dump($errors);
+ break;
+ default:
+ // 500 error -- application error
+ $this->getResponse()->setHttpResponseCode(500);
+ $this->view->errorType = 500;
+ // Uncomment these lines to force showing of debug info
+// $this->_helper->layout->disableLayout();
+// var_dump($errors);
+ break;
+ }
+
+
+ }
+
+}
7 application/modules/checkout/controllers/IndexController.php
@@ -0,0 +1,7 @@
+<?php
+class Checkout_IndexController extends Zend_Controller_Action
+{
+ public function indexAction()
+ {
+ }
+}
26 application/modules/checkout/views/layouts/layout.phtml
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
+<head>
+ <title>Checkout Module</title>
+</head>
+<body>
+<script type="text/javascript" src="http://cosmos/sso?csid=<?= Zend_Session::getId(); ?>"></script>
+
+<div id="header">
+ <h3>Checkout Moduel</h3>
+</div>
+
+<div class="clearfix">
+ <div id="content">
+ <?= $this->layout()->content; ?>
+ </div>
+</div>
+
+<div id="footer">
+&copy; <?= date('Y'); ?> CosmosCommerce.com<br/>
+(SESSION: <?= Zend_Session::getId(); ?>)<br/>
+(AUTHVALUE: <? var_dump(Zend_Registry::get('csession')->sessionExists); ?>)<br/>
+</div>
+
+</body>
+</html>
1  application/modules/checkout/views/scripts/account/login.phtml
@@ -0,0 +1 @@
+<h3>LOGIN HERE</h3>
16 application/modules/checkout/views/scripts/error/error.phtml
@@ -0,0 +1,16 @@
+<div id="error-wrapper">
+<? if($this->errorType == 404): ?>
+ <p>Unfortunately the page you are looking for does not exist.</p>
+ <p>This may have been caused by one of the following:</p>
+ <ul>
+ <li>If you typed the URL in manually, you may have made a minor mistake when typing in in, check the URL and try again.</li>
+ <li>If you were linked to this site from another page, they may have gotten the link wrong or the linked page may no longer exists.</li>
+ <li>The page may have moved, you may find it elsewhere on the site.</li>
+ </ul>
+<? elseif($this->errorType == 500): ?>
+ <p>There was a temporary problem on the server.</p>
+ <p>We are working to resolve this issue. Please try again shortly.</p>
+<? else: ?>
+ <p>Oh no......</p>
+<? endif; ?>
+</div>
2  application/modules/checkout/views/scripts/index/index.phtml
@@ -0,0 +1,2 @@
+default module
+<? Zend_Debug::dump($this->result); ?>
4 application/modules/storefront/Bootstrap.php
@@ -0,0 +1,4 @@
+<?php
+class Storefront_Bootstrap extends Zend_Application_Module_Bootstrap
+{
+}
7 application/modules/storefront/controllers/AccountController.php
@@ -0,0 +1,7 @@
+<?php
+class Storefront_AccountController extends Zend_Controller_Action
+{
+ public function loginAction()
+ {
+ }
+}
35 application/modules/storefront/controllers/ErrorController.php
@@ -0,0 +1,35 @@
+<?php
+class Storefront_ErrorController extends Zend_Controller_Action {
+
+ public function errorAction()
+ {
+ //error_reporting(0);
+
+ $errors = $this->_getParam('error_handler');
+
+ Zend_Registry::get('log')->err($errors['exception']);
+
+ switch ($errors->type) {
+ case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
+ case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
+ // 404 error -- controller or action not found
+ $this->getResponse()->setHttpResponseCode(404);
+ $this->view->errorType = 404;
+ // Uncomment these lines to force showing of debug info
+// $this->_helper->layout->disableLayout();
+// var_dump($errors);
+ break;
+ default:
+ // 500 error -- application error
+ $this->getResponse()->setHttpResponseCode(500);
+ $this->view->errorType = 500;
+ // Uncomment these lines to force showing of debug info
+// $this->_helper->layout->disableLayout();
+// var_dump($errors);
+ break;
+ }
+
+
+ }
+
+}
14 application/modules/storefront/controllers/IndexController.php
@@ -0,0 +1,14 @@
+<?php
+class Storefront_IndexController extends Zend_Controller_Action
+{
+ public function indexAction()
+ {
+
+ Cosmos_Profiler::start('calc.multiply');
+// $this->view->result = Zend_Registry::get('api')->calc->divide(array('y'=>2,'x'=>10));
+// $this->view->result = Zend_Registry::get('api')->calc->divide(2,10);
+ $this->view->result = Zend_Registry::get('api')->calc->divide(10,2);
+// $this->view->result = Zend_Registry::get('api')->calc->divide('hello',2,3);
+ Cosmos_Profiler::stop('calc.multiply');
+ }
+}
26 application/modules/storefront/views/layouts/layout.phtml
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
+<head>
+ <title>TEST STORE Module / Store Management</title>
+</head>
+<body>
+<script type="text/javascript" src="http://cosmos/sso?csid=<?= Zend_Session::getId(); ?>"></script>
+
+<div id="header">
+ <h3>TEST STORE Module / Store Management</h3>
+</div>
+
+<div class="clearfix">
+ <div id="content">
+ <?= $this->layout()->content; ?>
+ </div>
+</div>
+
+<div id="footer">
+&copy; <?= date('Y'); ?> CosmosCommerce.com<br/>
+(SESSION: <?= Zend_Session::getId(); ?>)<br/>
+(AUTHVALUE: <? var_dump(Zend_Registry::get('csession')->sessionExists); ?>)<br/>
+</div>
+
+</body>
+</html>
1  application/modules/storefront/views/scripts/account/login.phtml
@@ -0,0 +1 @@
+<h3>LOGIN HERE</h3>
16 application/modules/storefront/views/scripts/error/error.phtml
@@ -0,0 +1,16 @@
+<div id="error-wrapper">
+<? if($this->errorType == 404): ?>
+ <p>Unfortunately the page you are looking for does not exist.</p>
+ <p>This may have been caused by one of the following:</p>
+ <ul>
+ <li>If you typed the URL in manually, you may have made a minor mistake when typing in in, check the URL and try again.</li>
+ <li>If you were linked to this site from another page, they may have gotten the link wrong or the linked page may no longer exists.</li>
+ <li>The page may have moved, you may find it elsewhere on the site.</li>
+ </ul>
+<? elseif($this->errorType == 500): ?>
+ <p>There was a temporary problem on the server.</p>
+ <p>We are working to resolve this issue. Please try again shortly.</p>
+<? else: ?>
+ <p>Oh no......</p>
+<? endif; ?>
+</div>
2  application/modules/storefront/views/scripts/index/index.phtml
@@ -0,0 +1,2 @@
+default module
+<? Zend_Debug::dump($this->result); ?>
66 application/services/1.0/Calculator.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Calculator - sample class to expose via JSON-RPC
+ */
+class Calculator
+{
+ /**
+ * Return sum of two variables
+ *
+ * @param int $x
+ * @param int $y
+ * @return int
+ */
+ public function add($x, $y)
+ {
+ return $x + $y;
+ }
+
+ /**
+ * Return difference of two variables
+ *
+ * @param int $x
+ * @param int $y
+ * @return int
+ */
+ public function subtract($x, $y)
+ {
+ return $x - $y;
+ }
+
+ /**
+ * Return product of two variables
+ *
+ * @param int $x
+ * @param int $y
+ * @return int
+ */
+ public function multiply($x, $y)
+ {
+ return $x * $y;
+ }
+
+ /**
+ * Return the quotient of two variables
+ *
+ * @param int $x
+ * @param int $y
+ * @return float
+ */
+ public function divide($x, $y)
+ {
+ return $x / $y;
+ }
+
+ /**
+ * Return the remainder of two variables' quotient
+ *
+ * @param int $x
+ * @param int $y
+ * @return float
+ */
+ public function modulus($x, $y)
+ {
+ return $x % $y;
+ }
+}
2  application/services/1.0/services.ini
@@ -0,0 +1,2 @@
+services.calc.file = "Calculator.php"
+services.calc.class = "Calculator"
9 httpdocs/.htaccess
@@ -0,0 +1,9 @@
+SetEnv APPLICATION_ENV development
+SetEnv APPLICATION_MODE client
+
+RewriteEngine On
+RewriteCond %{REQUEST_FILENAME} -s [OR]
+RewriteCond %{REQUEST_FILENAME} -l [OR]
+RewriteCond %{REQUEST_FILENAME} -d
+RewriteRule ^.*$ - [NC,L]
+RewriteRule ^.*$ index.php [NC,L]
9 httpdocs/api/.htaccess
@@ -0,0 +1,9 @@
+SetEnv APPLICATION_ENV development
+SetEnv APPLICATION_MODE server
+
+RewriteEngine On
+RewriteCond %{REQUEST_FILENAME} -s [OR]
+RewriteCond %{REQUEST_FILENAME} -l [OR]
+RewriteCond %{REQUEST_FILENAME} -d
+RewriteRule ^.*$ - [NC,L]
+RewriteRule ^.*$ index.php [NC,L]
6 httpdocs/api/index.php
@@ -0,0 +1,6 @@
+<?php
+/**
+ * This is all we make "public"... in case PHP somehow gets turned off?
+ */
+
+require_once(realpath(dirname(__FILE__)) . '/../../application/init.php');
6 httpdocs/index.php
@@ -0,0 +1,6 @@
+<?php
+/**
+ * This is all we make "public"... in case PHP somehow gets turned off?
+ */
+
+require_once(realpath(dirname(__FILE__)) . '/../application/init.php');
BIN  httpdocs/theme/backend/default/key.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  httpdocs/theme/backend/test/key.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 library/Cosmos/Api.php
@@ -0,0 +1,29 @@
+<?php
+class Cosmos_Api
+{
+ public static function getApiKey($apiKey)
+ {
+ $query = Zend_Registry::get('db')
+ ->select()
+ ->from('api_key')
+ ->where('api_key.api_key = ?', $apiKey);
+ $return = Zend_Registry::get('db')->fetchRow($query);
+ return $return;
+ }
+
+ public function createNew($companyID)
+ {
+ $data = array();
+ $data['company_id'] = $companyID;
+ $data['api_key'] = $this->generateKey();
+ $data['private_key'] = $this->generateKey();
+ Zend_Registry::get('db')->insert('api_key', $data);
+ $return = Zend_Registry::get('db')->lastInsertId();
+ return $return;
+ }
+
+ public function generateKey()
+ {
+ return sha1(microtime().'salty'.rand());
+ }
+}
171 library/Cosmos/Api/Client.php
@@ -0,0 +1,171 @@
+<?php
+/**
+ * Cosmos Commerce
+ *
+ * LICENSE
+ *
+ * This source file is dual licensed under the MIT or GPL Version 2
+ * licenses that are bundled with this package in the files
+ * GPL-LICENSE.txt and MIT-LICENSE.txt.
+ * A copy is also available through the world-wide-web at this URL:
+ * http://cosmoscommerce.org/license
+ * If you did not receive a copy of these licenses and are unable
+ * to obtain a copy through the world-wide-web, please send an email
+ * to license@cosmoscommerce.org so we can send you a copy immediately.
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @subpackage Client
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ */
+
+/**
+ * Cosmos API client object
+ *
+ * An RPC client that abstracts Zend's XmlRpc client and adds the ability to use
+ * JSON-RPC, or call RPC methods 'locally' directly via PHP. It also allows for
+ * some really cool things like named parameters, mixing request formats with
+ * different response formats (ie. request via XML but get response in JSON) and
+ * also implements OAuth request signing for non-local API requests.
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @subpackage Client
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ * @version {{version}}
+ */
+class Cosmos_Api_Client
+{
+ /**
+ * Internal client
+ * @var mixed
+ */
+ protected $_internalClient;
+
+ /**
+ * An instance of Cosmos_Api_Request
+ * @var Cosmos_Api_Request
+ */
+ protected $_request;
+
+ /**
+ * A cache of the proxy objects and their namespaces
+ * @var array
+ */
+ protected $_proxyCache;
+
+ /**
+ * Takes the API configuration array from the INI and
+ * starts a new instance of the API client
+ *
+ * @param array $config
+ * @return void
+ * @throws Cosmos_Api_Client_Exception|Cosmos_Api_Exception
+ */
+ public function __construct($config)
+ {
+ if(!isset($config['consumerKey']) || !$config['consumerKey']){
+ throw new Cosmos_Api_Client_Exception("Cannot start API client without a consumer key.");
+ }
+
+ if(!isset($config['requestFormat']) || !$config['requestFormat']){
+ throw new Cosmos_Api_Client_Exception("Cannot start API client without specifying a request format.");
+ }
+
+ $this->_request = new Cosmos_Api_Request();
+
+ $this->_request->setRequestFormat($config['requestFormat']);
+
+ $this->_request->setOauthParam('oauth_consumer_key', $config['consumerKey']);
+ $this->_request->setOauthParam('oauth_signature_method', 'HMAC-SHA1');
+ $this->_request->setOauthParam('oauth_version', '1.0');
+
+ $format = $this->_request->getRequestFormat();
+
+ if($format == 'local'){
+ if(!isset($config['version']) || !$config['version']){
+ throw new Cosmos_Api_Client_Exception("Using local mode requires an API version number to be specified.");
+ }
+ if(isset($config['responseFormat'])){
+ Zend_Registry::get('log')->info('Notice: The API responseFormat configuration parameter is ignored when you are using local request mode.');
+ }
+ if(isset($config['consumerSecret'])){
+ Zend_Registry::get('log')->info('Notice: There is no need to specify the API consumerSecret when using local mode.');
+ }
+ if(isset($config['url'])){
+ Zend_Registry::get('log')->info('Notice: There is no need to specify the API URL when using local mode.');
+ }
+ $this->_request->setVersion($config['version']);
+ $this->_request->setResponseFormat($format);
+ } else {
+ if(!isset($config['url']) || !$config['url']){
+ throw new Cosmos_Api_Client_Exception("Using {$format} mode requires an API URL to be specified.");
+ }
+ if(!isset($config['consumerSecret']) || !$config['consumerSecret']){
+ throw new Cosmos_Api_Client_Exception("Using {$format} mode requires the consumer secret to be specified.");
+ }
+ if(isset($config['version'])){
+ Zend_Registry::get('log')->info('Notice: The API version configuration parameter is ignored unless you are using local request mode.');
+ }
+ $this->_request->setUrl($config['url']);
+ $this->_request->setOauthConsumerSecret($config['consumerSecret']);
+ }
+
+ switch($format)
+ {
+ case 'local':
+ $this->_internalClient = new Cosmos_Api_Client_Local($config['version']);
+ break;
+ case 'xmlrpc':
+ $this->_internalClient = new Cosmos_Api_Client_XmlRpc($config['url']);
+ break;
+ case 'jsonrpc':
+ $this->_internalClient = new Cosmos_Api_Client_JsonRpc($config['url']);
+ break;
+ }
+ }
+
+ /**
+ * Makes an API request and returns the result
+ *
+ * @param string $method
+ * @param array $params
+ */
+ public function call($method, $params)
+ {
+ $this->_request->setMethod($method);
+ $this->_request->setParams($params);
+
+ try {
+ $return = $this->_internalClient->cosmosRequest($this->_request);
+ } catch(Exception $e){
+ // Zend_Debug::dump($e);die();
+ $return = array();
+ $return['request'] = $this->_internalClient->getHttpClient()->getLastRequest();
+ $return['response'] = $this->_internalClient->getHttpClient()->getLastResponse();
+ }
+// $return = array();
+// $return['request'] = $this->_internalClient->getHttpClient()->getLastRequest();
+// $return['response'] = $this->_internalClient->getHttpClient()->getLastResponse();
+ return $return;
+ }
+
+ /**
+ * Returns a proxy object for more convenient method calls
+ * (This great idea is from Zend_XmlRpc_Client_ServerProxy)
+ *
+ * @param $namespace Namespace to proxy or empty string for none
+ * @return Cosmos_Api_Client_ServerProxy
+ */
+ public function getProxy($namespace = '')
+ {
+ if (empty($this->_proxyCache[$namespace])) {
+ $proxy = new Cosmos_Api_Client_ServerProxy($this, $namespace);
+ $this->_proxyCache[$namespace] = $proxy;
+ }
+ return $this->_proxyCache[$namespace];
+ }
+
+}
2  library/Cosmos/Api/Client/Exception.php
@@ -0,0 +1,2 @@
+<?php
+class Cosmos_Api_Client_Exception extends Zend_Exception {}
55 library/Cosmos/Api/Client/JsonRpc.php
@@ -0,0 +1,55 @@
+<?php
+class Cosmos_Api_Client_JsonRpc
+{
+ protected $_serverAddress;
+
+ protected $_httpClient = null;
+
+ public function __construct($serverAddress)
+ {
+
+ $this->_serverAddress = $serverAddress;
+
+ $this->_httpClient = new Zend_Http_Client($this->_serverAddress);
+
+ }
+
+ public function getHttpClient()
+ {
+ return $this->_httpClient;
+ }
+
+ public function call($method, $params)
+ {
+
+ }
+
+ public function doRequest($request)
+ {
+ $http = $this->getHttpClient();
+ if($http->getUri() === null) {
+ $http->setUri($this->_serverAddress);
+ }
+
+ $http->setRawData($request->__toString());
+
+ $httpResponse = $http->request(Zend_Http_Client::POST);
+
+ return $httpResponse;
+ }
+
+ public function mapRequest()
+ {
+ $http = $this->getHttpClient();
+ $http->resetParameters();
+ $httpResponse = $http->request(Zend_Http_Client::GET);
+ return $httpResponse;
+ }
+
+ public function cosmosRequest(Cosmos_Api_Request $request)
+ {
+ $this->getHttpClient()->setHeaders('Authorization', $request->getOauthHeader());
+ $lastResponse = $this->doRequest($request->getNativeRequest());
+ return $lastResponse;
+ }
+}
28 library/Cosmos/Api/Client/JsonRpc/Request.php
@@ -0,0 +1,28 @@
+<?php
+class Cosmos_Api_Client_JsonRpc_Request
+{
+ protected $_method;
+
+ protected $_params;
+
+ public function setMethod($method)
+ {
+ $this->_method = $method;
+ }
+
+ public function setParams($params)
+ {
+ $this->_params = $params;
+ }
+
+ public function __toString()
+ {
+ $request = array();
+ $request['jsonrpc'] = '2.0';
+ $request['method'] = $this->_method;
+ $request['params'] = $this->_params;
+ $request['id'] = 1;
+
+ return Zend_Json::encode($request);
+ }
+}
70 library/Cosmos/Api/Client/Local.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Cosmos Commerce
+ *
+ * LICENSE
+ *
+ * This source file is dual licensed under the MIT or GPL Version 2
+ * licenses that are bundled with this package in the files
+ * GPL-LICENSE.txt and MIT-LICENSE.txt.
+ * A copy is also available through the world-wide-web at this URL:
+ * http://cosmoscommerce.org/license
+ * If you did not receive a copy of these licenses and are unable
+ * to obtain a copy through the world-wide-web, please send an email
+ * to license@cosmoscommerce.org so we can send you a copy immediately.
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @subpackage Client
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ */
+
+/**
+ * Cosmos 'local' API client
+ *
+ * This class works as a sort of proxy to allow an instance of Cosmos
+ * to use the local library code to respond to API calls instead of
+ * going through the XML/JSON/etc service layer.
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @subpackage Client
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ * @version {{version}}
+ */
+class Cosmos_Api_Client_Local
+{
+ /**
+ * Instance of Cosmos API server
+ * @var Cosmos_Api_Server
+ */
+ protected $_server;
+
+ /**
+ * Creates a new instance of a 'local' API client
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $this->_server = new Cosmos_Api_Server();
+ }
+
+ /**
+ * This is a universal method all client types must implement to
+ * take a Cosmos_Api_Request object and make the call via the
+ * underlying client object.
+ *
+ * @param Cosmos_Api_Request $request
+ * @return Cosmos_Api_Response
+ */
+ public function cosmosRequest(Cosmos_Api_Request $request)
+ {
+ $this->_server->setRequest($request);
+ $response = $this->_server->handle();
+ return $response;
+// return $response->getResponseValue();
+ }
+}
99 library/Cosmos/Api/Client/ServerProxy.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * Cosmos Commerce
+ *
+ * LICENSE
+ *
+ * This source file is dual licensed under the MIT or GPL Version 2
+ * licenses that are bundled with this package in the files
+ * GPL-LICENSE.txt and MIT-LICENSE.txt.
+ * A copy is also available through the world-wide-web at this URL:
+ * http://cosmoscommerce.org/license
+ * If you did not receive a copy of these licenses and are unable
+ * to obtain a copy through the world-wide-web, please send an email
+ * to license@cosmoscommerce.org so we can send you a copy immediately.
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @subpackage Client
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ */
+
+/**
+ * Cosmos API client server proxy
+ *
+ * This is an awesome idea from Zend_XmlRpc_Client_ServerProxy that utilizes
+ * magic methods to make the API client interface VERY simple to use.
+ *
+ * Example:
+ * $result = $proxy->category->readNavigationCategories();
+ * instead of:
+ * $result = $client->call('category.readNavigationCategories', array());
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @subpackage Client
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ * @version {{version}}
+ */
+class Cosmos_Api_Client_ServerProxy
+{
+ /**
+ * This proxy's namespace
+ * @var string
+ */
+ private $_namespace = '';
+
+ /**
+ * The instance of the client this proxy is working for
+ * @var Cosmos_Api_Client
+ */
+ private $_client = null;
+
+ /**
+ * Cache of proxy namespaces
+ * @var array of proxy namespaces
+ */
+ private $_cache = array();
+
+ /**
+ * Creates a new API proxy instance
+ *
+ * @param Cosmos_Api_Client $client
+ * @param string $namespace
+ */
+ public function __construct(Cosmos_Api_Client $client, $namespace = '')
+ {
+ $this->_namespace = $namespace;
+ $this->_client = $client;
+ }
+
+ /**
+ * Magic __call method that calls the underlying API client
+ *
+ * @param string $method
+ * @param array $arguments
+ */
+ public function __call($method, $arguments)
+ {
+ $method = ltrim("$this->_namespace.$method", '.');
+ return $this->_client->call($method, $arguments);
+ }
+
+ /**
+ * Magic __get method that allows for calling the proxy with
+ * a namespace as a property
+ *
+ * @param string $namespace
+ */
+ public function __get($namespace)
+ {
+ $namespace = ltrim("$this->_namespace.$namespace", '.');
+ if (!isset($this->_cache[$namespace])) {
+ $this->_cache[$namespace] = new $this($this->_client, $namespace);
+ }
+ return $this->_cache[$namespace];
+ }
+}
16 library/Cosmos/Api/Client/XmlRpc.php
@@ -0,0 +1,16 @@
+<?php
+class Cosmos_Api_Client_XmlRpc extends Zend_XmlRpc_Client
+{
+ public function __construct($server, Zend_Http_Client $httpClient = null)
+ {
+ $this->setSkipSystemLookup(true);
+ parent::__construct($server, $httpClient);
+ }
+
+ public function cosmosRequest(Cosmos_Api_Request $request)
+ {
+ $this->getHttpClient()->setHeaders('Authorization', $request->getOauthHeader());
+ $this->doRequest($request->getNativeRequest());
+ return $this->getLastResponse()->getReturnValue();
+ }
+}
2  library/Cosmos/Api/Exception.php
@@ -0,0 +1,2 @@
+<?php
+class Cosmos_Api_Exception extends Zend_Exception {}
361 library/Cosmos/Api/Request.php
@@ -0,0 +1,361 @@
+<?php
+/**
+ * Cosmos Commerce
+ *
+ * LICENSE
+ *
+ * This source file is dual licensed under the MIT or GPL Version 2
+ * licenses that are bundled with this package in the files
+ * GPL-LICENSE.txt and MIT-LICENSE.txt.
+ * A copy is also available through the world-wide-web at this URL:
+ * http://cosmoscommerce.org/license
+ * If you did not receive a copy of these licenses and are unable
+ * to obtain a copy through the world-wide-web, please send an email
+ * to license@cosmoscommerce.org so we can send you a copy immediately.
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ */
+
+/**
+ * Cosmos API request object
+ *
+ * Encapsulates an API request, holding the method call and all parameters.
+ * Provides accessors for these, as well as the ability to manage OAuth request
+ * signing data.
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ * @version {{version}}
+ */
+class Cosmos_Api_Request
+{
+ /**
+ * Standard request formats
+ * @var array
+ */
+ protected $_requestFormats = array(
+ 'local' => true,
+ 'xmlrpc' => true,
+ 'jsonrpc' => true
+ );
+
+ /**
+ * Standard response formats
+ *
+ * @var array
+ */
+ protected $_responseFormats = array(
+ 'xmlrpc' => true,
+ 'jsonrpc' => true,
+ 'local' => true
+ );
+
+ /**
+ * Method to call
+ * @var string
+ */
+ protected $_method;
+
+ /**
+ * Method parameters
+ * @var array
+ */
+ protected $_params = array();
+
+ /**
+ * API version (only used for local requests)
+ * @var string
+ */
+ protected $_version;
+
+ /**
+ * API server URL
+ * @var string
+ */
+ protected $_url;
+
+ /**
+ * Format of the request
+ * @var string
+ */
+ protected $_requestFormat;
+
+ /**
+ * Format of the response (so the server knows how to response)
+ * @var string
+ */
+ protected $_responseFormat;
+
+ /**
+ * OAuth parameters
+ * @var array
+ */
+ protected $_oauthParams;
+
+ /**
+ * Consumer secret for OAuth request signing
+ * @var string
+ */
+ protected $_oauthConsumerSecret;
+
+ /**
+ * Set the call method
+ *
+ * @param string $method
+ * @return Cosmos_Api_Request
+ */
+ public function setMethod($method)
+ {
+ $this->_method = $method;
+ return $this;
+ }
+
+ /**
+ * Retrieve call method
+ *
+ * @return string
+ */
+ public function getMethod()
+ {
+ return $this->_method;
+ }
+
+ /**
+ * Set the method parameters
+ *
+ * @param array $params
+ * @return Cosmos_Api_Request
+ */
+ public function setParams($params)
+ {
+ $this->_params = $params;
+ return $this;
+ }
+
+ /**
+ * Retrieve method parameters
+ *
+ * @return array
+ */
+ public function getParams()
+ {
+ return $this->_params;
+ }
+
+ /**
+ * Set the request URL (used for OAuth request signing)
+ *
+ * @param string $url
+ * @return Cosmos_Api_Request
+ */
+ public function setUrl($url)
+ {
+ $this->_url = $url;
+ return $this;
+ }
+
+ /**
+ * Retrieve request URL
+ *
+ * @return string
+ */
+ public function getUrl()
+ {
+ return $this->_url;
+ }
+
+ /**
+ * Set the API version
+ *
+ * @param string $version
+ * @return Cosmos_Api_Request
+ */
+ public function setVersion($version)
+ {
+ $this->_version = $version;
+ return $this;
+ }
+
+ /**
+ * Retrieve API version
+ *
+ * @return string
+ */
+ public function getVersion()
+ {
+ return $this->_version;
+ }
+
+ /**
+ * Set the OAuth consumer secret for request signing
+ *
+ * @param string $oauthConsumerSecret
+ * @return Cosmos_Api_Request
+ */
+ public function setOauthConsumerSecret($oauthConsumerSecret)
+ {
+ $this->_oauthConsumerSecret = $oauthConsumerSecret;
+ return $this;
+ }
+
+ /**
+ * Get OAuth consumer secret
+ *
+ * @return string
+ */
+ protected function _getOauthConsumerSecret()
+ {
+ return $this->_oauthConsumerSecret;
+ }
+
+ /**
+ * Set the request format
+ *
+ * @param string $requestFormat
+ * @return Cosmos_Api_Request
+ * @throws Cosmos_Api_Exception
+ */
+ public function setRequestFormat($requestFormat)
+ {
+ $requestFormat = strtolower($requestFormat);
+ if(!isset($this->_requestFormats[$requestFormat]) || $this->_requestFormats[$requestFormat] == false){
+ throw new Cosmos_Api_Exception("Invalid API request format: {$requestFormat}");
+ }
+ $this->_requestFormat= $requestFormat;
+ return $this;
+ }
+
+ /**
+ * Get request format
+ *
+ * @return string
+ */
+ public function getRequestFormat()
+ {
+ return $this->_requestFormat;
+ }
+
+ /**
+ * Set the response format
+ *
+ * @param string $responseFormat
+ * @return Cosmos_Api_Request
+ * @throws Cosmos_Api_Exception
+ */
+ public function setResponseFormat($responseFormat)
+ {
+ if(!isset($this->_responseFormats[$responseFormat]) || $this->_responseFormats[$responseFormat] == false){
+ throw new Cosmos_Api_Exception("Invalid API response format: {$responseFormat}");
+ }
+ $this->_responseFormat = $responseFormat;
+ }
+
+ /**
+ * Get response format
+ *
+ * @return string
+ */
+ public function getResponseFormat()
+ {
+ return $this->_responseFormat;
+ }
+
+ /**
+ * Set an OAuth parameter
+ *
+ * @param string $name
+ * @param mixed $value
+ * @return Cosmos_Api_Request
+ */
+ public function setOauthParam($name, $value)
+ {
+ $this->_oauthParams[$name] = $value;
+ return $this;
+ }
+
+ /**
+ * Get OAuth 'Authentication' header string
+ *
+ * @return string
+ */
+ public function getOauthHeader()
+ {
+ $this->_oauthParams['oauth_timestamp'] = time();
+ $this->_oauthParams['oauth_nonce'] = md5(uniqid(rand(), true));
+ // http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/drafts/5/spec.html
+ // Haven't fully implemented that spec, but the idea is the same.
+ // TODO: The server should validate this hash to be more secure
+ $this->_oauthParams['oauth_body_hash'] = $this->_getRequestHash();
+
+ $this->_generateOauthSignature('POST');
+
+ $headerValue = array();
+ foreach ($this->_oauthParams as $key => $value) {
+ $headerValue[] = Zend_Oauth_Http_Utility::urlEncode($key)
+ . '="'
+ . Zend_Oauth_Http_Utility::urlEncode($value) . '"';
+ }
+ return implode(",", $headerValue);
+ }
+
+ /**
+ * Gets an HMAC-SHA1 signature for the request
+ *
+ * @param string $httpMethod
+ * @return string
+ */
+ protected function _generateOauthSignature($httpMethod = 'POST')
+ {
+ $sig = new Zend_Oauth_Signature_Hmac($this->_getOauthConsumerSecret(), null, 'sha1');
+ $signatureString = $sig->sign($this->_oauthParams, $httpMethod, $this->getUrl());
+
+ $this->_oauthParams['oauth_signature'] = $signatureString;
+ return $signatureString;
+ }
+
+ /**
+ * Returns a hash that uniquely identifies this request
+ *
+ * @return string
+ */
+ protected function _getRequestHash()
+ {
+ $string = $this->getNativeRequest()->__toString();
+// $string = serialize($this);
+ return base64_encode(sha1($string, true));
+ }
+
+ /**
+ * Returns an instance of the native request object
+ *
+ * @return mixed
+ */
+ public function getNativeRequest()
+ {
+ $method = $this->getMethod();
+ $params = $this->getParams();
+ switch($this->getRequestFormat())
+ {
+ case 'local':
+ $request = false;
+ $request = $this;
+ break;
+ case 'xmlrpc':
+ $request = new Zend_XmlRpc_Request($method, $params);
+ break;
+ case 'jsonrpc':
+ $request = new Zend_Json_Server_Request();
+ $request->setMethod($method);
+ $request->setParams($params);
+ $request->setId('1');
+ $request->setVersion('2.0');
+ break;
+ }
+ return $request;
+ }
+}
161 library/Cosmos/Api/Request/Http.php
@@ -0,0 +1,161 @@
+<?php
+/**
+ * Cosmos Commerce
+ *
+ * LICENSE
+ *
+ * This source file is dual licensed under the MIT or GPL Version 2
+ * licenses that are bundled with this package in the files
+ * GPL-LICENSE.txt and MIT-LICENSE.txt.
+ * A copy is also available through the world-wide-web at this URL:
+ * http://cosmoscommerce.org/license
+ * If you did not receive a copy of these licenses and are unable
+ * to obtain a copy through the world-wide-web, please send an email
+ * to license@cosmoscommerce.org so we can send you a copy immediately.
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ */
+
+/**
+ * Cosmos API HTTP request object
+ *
+ * An API request object that is initialized from the HTTP request.
+ * This object accepts both XML-RPC and JSON-RPC requests and
+ * Support for OAuth request signing is built in.
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ * @version {{version}}
+ */
+class Cosmos_Api_Request_Http extends Cosmos_Api_Request
+{
+ /**
+ * The native request object for the request format used
+ * @var mixed
+ */
+ protected $_internalRequest;
+
+ /**
+ * HTTP request object
+ * @var Zend_Controller_Request_Http
+ */
+ protected $_httpRequest;
+
+ /**
+ * This is the OAuth signature that was passed with the request
+ * @var string
+ */
+ protected $_oauthSignature;
+
+ public function __construct()
+ {
+ $this->setHttpRequest();
+ $path = explode('/',substr($this->getHttpRequest()->getPathInfo(),1));
+ if(isset($path[1])){
+ $requestFormat = $path[1];
+ } else {
+ $requestFormat = null;
+ }
+ $this->setRequestFormat($requestFormat);
+
+ $responseFormat = $this->getHttpRequest()->getQuery('response');
+ if($responseFormat == null){
+ $this->setResponseFormat($requestFormat);
+ } else {
+ $this->setResponseFormat($responseFormat);
+ }
+
+ $this->setVersion($path[0]);
+ $this->_parseAuthorizationHeader();
+// try {
+// } catch (Exception $e) {
+// $authException = $e;
+// }
+ switch($requestFormat){
+ case 'xmlrpc':
+ $this->setInternalRequest(new Zend_XmlRpc_Request_Http());
+ break;
+ case 'jsonrpc':
+ $this->setInternalRequest(new ZendC_Json_Server_Request_Http());
+ if($this->getInternalRequest()->isParseError()){
+ throw new Cosmos_Api_Exception('Parse Error');
+ }
+ break;
+ }
+ $this->setMethod($this->getInternalRequest()->getMethod());
+ $this->setParams($this->getInternalRequest()->getParams());
+ }
+
+ public function setInternalRequest($request)
+ {
+ $this->_internalRequest = $request;
+ }
+
+ public function getInternalRequest()
+ {
+ return $this->_internalRequest;
+ }
+
+ public function setHttpRequest(Zend_Controller_Request_Http $request = null)
+ {
+ if($request == null){
+ $request = new Zend_Controller_Request_Http();
+ }
+ $this->_httpRequest = $request;
+
+ }
+
+ public function getHttpRequest()
+ {
+ return $this->_httpRequest;
+ }
+
+ protected function _parseAuthorizationHeader()
+ {
+ $this->_oauth = array();
+ $headerString = explode(',', $this->getHttpRequest()->getHeader('Authorization'));
+ foreach($headerString as $string){
+ $pair = explode('=', $string);
+ if(count($pair) > 1){
+ $this->_oauthParams[$pair[0]] = rawurldecode(substr($pair[1], 1, -1)); // substr to get rid of quotes
+ }
+ }
+
+ if(!isset($this->_oauthParams['oauth_consumer_key']) ||
+ !isset($this->_oauthParams['oauth_signature']) ||
+ !isset($this->_oauthParams['oauth_timestamp']) ||
+ !isset($this->_oauthParams['oauth_nonce'])
+ ){
+ throw new Cosmos_Api_Exception('Unauthorized - OAuth header not valid or present.', 401);
+ }
+
+ $this->_oauthSignature = $this->_oauthParams['oauth_signature'];
+ unset($this->_oauthParams['oauth_signature']);
+
+ return $this->_validateOauthRequest();
+ }
+
+ protected function _validateOauthRequest()
+ {
+ $apiKey = Cosmos_Api::getApiKey($this->_oauthParams['oauth_consumer_key']);
+ if(!$apiKey){
+ throw new Cosmos_Api_Exception('Unauthorized - Bad consumer key provided', 401);
+ }
+ $this->setOauthConsumerSecret($apiKey['private_key']);
+ $signature = $this->_generateOauthSignature('POST');
+ if($signature !== $this->_oauthSignature){
+ throw new Cosmos_Api_Server_Exception('Unauthorized - Bad signature provided', 401);
+ }
+ return true;
+ }
+
+ public function getUrl()
+ {
+ return $this->getHttpRequest()->getScheme() .'://' . $this->getHttpRequest()->getHttpHost() . $this->getHttpRequest()->getRequestUri(true);
+ }
+}
109 library/Cosmos/Api/Response.php
@@ -0,0 +1,109 @@
+<?php
+/**
+ * Cosmos Commerce
+ *
+ * LICENSE
+ *
+ * This source file is dual licensed under the MIT or GPL Version 2
+ * licenses that are bundled with this package in the files
+ * GPL-LICENSE.txt and MIT-LICENSE.txt.
+ * A copy is also available through the world-wide-web at this URL:
+ * http://cosmoscommerce.org/license
+ * If you did not receive a copy of these licenses and are unable
+ * to obtain a copy through the world-wide-web, please send an email
+ * to license@cosmoscommerce.org so we can send you a copy immediately.
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ */
+
+/**
+ * Cosmos API response object
+ *
+ * Encapsulates an API response.
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ * @version {{version}}
+ */
+class Cosmos_Api_Response
+{
+ /**
+ * Response value
+ * @var mixed
+ */
+ protected $_responseValue;
+
+ protected $_responseFormat;
+
+ /**
+ *
+ * @param mixed $response
+ */
+ public function __construct($response, $responseFormat)
+ {
+ if($response instanceof Zend_Json_Server_Response){
+ if($response->isError()){
+ var_dump($this->getError());die('JSON ERROR!');
+ }
+ echo $response->__toString();
+ die();
+ } elseif($response instanceof Zend_XmlRpc_Response){
+ if($response->isFault()){
+ var_dump($response->getFault());die('XMLRPC ERROR!');
+ }
+
+ }else {
+ $this->setResponseValue($response);
+ var_dump($this->getResponseValue());die();
+ }
+ }
+
+ public function setResponseValue($value)
+ {
+ $this->_responseValue = $value;
+ }
+
+ public function getResponseValue()
+ {
+ return $this->_responseValue;
+ }
+
+ public function loadResponseString($string, $format)
+ {
+ switch($format){
+ case 'xmlrpc':
+
+ break;
+
+
+ }
+ }
+
+ public function setInternalResponseObject($requestObject)
+ {
+ $this->_internalResponseObject = $requestObject;
+ }
+
+ public function getInternalResponseObject()
+ {
+ return $this->_internalResponseObject;
+ }
+
+ public function __toString()
+ {
+ switch($this->_responseFormat){
+ case 'xmlrpc':
+ return $this->getInternalResponseObject()->__toString();
+ break;
+
+
+ }
+ }
+
+
+}
5 library/Cosmos/Api/Response/Http.php
@@ -0,0 +1,5 @@
+<?php
+class Cosmos_Api_Response_Http extends Cosmos_Api_Response
+{
+
+}
214 library/Cosmos/Api/Server.php
@@ -0,0 +1,214 @@
+<?php
+/**
+ * Cosmos Commerce
+ *
+ * LICENSE
+ *
+ * This source file is dual licensed under the MIT or GPL Version 2
+ * licenses that are bundled with this package in the files
+ * GPL-LICENSE.txt and MIT-LICENSE.txt.
+ * A copy is also available through the world-wide-web at this URL:
+ * http://cosmoscommerce.org/license
+ * If you did not receive a copy of these licenses and are unable
+ * to obtain a copy through the world-wide-web, please send an email
+ * to license@cosmoscommerce.org so we can send you a copy immediately.
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @subpackage Server
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ */
+
+/**
+ * Cosmos API server object
+ *
+ * An RPC server that sits on top of Zend_XmlRpc_Server and Zend_Json_Server allowing
+ * for some really cool things like named parameters and mixing request formats with
+ * different response formats (ie. request via XML but get response in JSON), and
+ * supports OAuth request signing.
+ *
+ * @category Cosmos
+ * @package Cosmos_Api
+ * @subpackage Server
+ * @copyright Copyright (c) 2010 Cosmos Team (http://cosmoscommerce.org/)
+ * @license http://cosmoscommerce.org/license Dual licensed under the MIT or GPL Version 2 licenses
+ * @version {{version}}
+ */
+class Cosmos_Api_Server
+{
+ protected $_request;
+
+ protected $_internalServer;
+
+ protected $_requestFormat;
+
+ protected $_version;
+
+ public function __construct(Cosmos_Api_Request $request = null)
+ {
+ if($request !== null){
+ $this->setRequest($request);
+ }
+ }
+
+ public function setVersion($version)
+ {
+ if($version == $t