Add php files
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
!.gitignore
|
||||
!*.php
|
||||
|
||||
# ...even if they are in subdirectories
|
||||
!*/
|
||||
|
||||
6
EcmConfig.php
Executable file
6
EcmConfig.php
Executable file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$EcmConfig = array (
|
||||
'consignments' => true,
|
||||
'consignments_label1' => 'Nr',
|
||||
);
|
||||
?>
|
||||
49
Getdata.php
Executable file
49
Getdata.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
////////////////////////////////////////////////////////
|
||||
// DATABASE.PHP
|
||||
////////////////////////////////////////////////////////
|
||||
mysql_connect("localhost", "root", "sgpmk777") or
|
||||
die("Could not connect: " . mysql_error());
|
||||
mysql_select_db("crm");
|
||||
$task = '';
|
||||
getList();
|
||||
if ( isset($_POST['task'])){
|
||||
$task = $_POST['task']; // Get this from Ext
|
||||
}
|
||||
switch($task){
|
||||
case "LISTING": // Give the entire list
|
||||
getList();
|
||||
break;
|
||||
default:
|
||||
echo "{failure:true}"; // Simple 1-dim JSON array to tell Ext the request failed.
|
||||
break;
|
||||
}
|
||||
|
||||
function getList()
|
||||
{
|
||||
$query = "SELECT * FROM PK__12__";
|
||||
$result = mysql_query($query);
|
||||
$nbrows = mysql_num_rows($result);
|
||||
if($nbrows>0){
|
||||
while($rec = mysql_fetch_array($result)){
|
||||
// render the right date format
|
||||
$rec['tookoffice']=codeDate($rec['tookoffice']);
|
||||
$rec['leftoffice']=codeDate($rec['leftoffice']);
|
||||
$arr[] = $rec;
|
||||
$jsonresult = json_encode($arr);
|
||||
echo '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '({"total":"0", "results":""})';
|
||||
}
|
||||
}
|
||||
|
||||
function codeDate ($date) {
|
||||
$tab = explode ("-", $date);
|
||||
$r = $tab[1]."/".$tab[2]."/".$tab[0];
|
||||
return $r;
|
||||
}
|
||||
|
||||
?>
|
||||
55
HandleAjaxCall.php
Executable file
55
HandleAjaxCall.php
Executable file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/**
|
||||
* Used to call a generic method in a dashlet
|
||||
*/
|
||||
require_once('include/entryPoint.php');
|
||||
require_once('ModuleInstall/PackageManager/PackageController.php');
|
||||
if(!is_admin($GLOBALS['current_user'])){
|
||||
sugar_die('Admin Only Section');
|
||||
}
|
||||
$requestedMethod = $_REQUEST['method'];
|
||||
$pmc = new PackageController();
|
||||
|
||||
if(method_exists($pmc, $requestedMethod)) {
|
||||
echo $pmc->$requestedMethod();
|
||||
}
|
||||
else {
|
||||
echo 'no method';
|
||||
}
|
||||
// sugar_cleanup();
|
||||
?>
|
||||
10
Manifest.php
Executable file
10
Manifest.php
Executable file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
'dashlets' => array (
|
||||
array(
|
||||
'name' => 'MyChartsProductsDashlet',
|
||||
'from' => '<basepath>/modules/EcmCharts/Dashlets/MyChartsProductsDashlet',
|
||||
),
|
||||
),
|
||||
|
||||
?>
|
||||
2328
ModuleInstall/ModuleInstaller.php
Executable file
2328
ModuleInstall/ModuleInstaller.php
Executable file
File diff suppressed because it is too large
Load Diff
435
ModuleInstall/ModuleScanner.php
Executable file
435
ModuleInstall/ModuleScanner.php
Executable file
@@ -0,0 +1,435 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
class ModuleScanner{
|
||||
private $manifestMap = array(
|
||||
'pre_execute'=>'pre_execute',
|
||||
'install_mkdirs'=>'mkdir',
|
||||
'install_copy'=>'copy',
|
||||
'install_images'=>'image_dir',
|
||||
'install_menus'=>'menu',
|
||||
'install_userpage'=>'user_page',
|
||||
'install_dashlets'=>'dashlets',
|
||||
'install_administration'=>'administration',
|
||||
'install_connectors'=>'connectors',
|
||||
'install_vardefs'=>'vardefs',
|
||||
'install_layoutdefs'=>'layoutdefs',
|
||||
'install_layoutfields'=>'layoutfields',
|
||||
'install_relationships'=>'relationships',
|
||||
'install_languages'=>'language',
|
||||
'install_logichooks'=>'logic_hooks',
|
||||
'post_execute'=>'post_execute',
|
||||
|
||||
);
|
||||
|
||||
private $blackListExempt = array();
|
||||
|
||||
private $validExt = array('png', 'gif', 'jpg', 'css', 'js', 'php', 'txt', 'html', 'htm', 'tpl', 'pdf', 'md5', 'xml');
|
||||
private $blackList = array(
|
||||
'eval',
|
||||
'exec',
|
||||
'system',
|
||||
'shell_exec',
|
||||
'passthru',
|
||||
'chgrp',
|
||||
'chmod',
|
||||
'chwown',
|
||||
'file_put_contents',
|
||||
'file',
|
||||
'fileatime',
|
||||
'filectime',
|
||||
'filegroup',
|
||||
'fileinode',
|
||||
'filemtime',
|
||||
'fileowner',
|
||||
'fileperms',
|
||||
'fopen',
|
||||
'is_executable',
|
||||
'is_writable',
|
||||
'is_writeable',
|
||||
'lchgrp',
|
||||
'lchown',
|
||||
'linkinfo',
|
||||
'lstat',
|
||||
'mkdir',
|
||||
'parse_ini_file',
|
||||
'rmdir',
|
||||
'stat',
|
||||
'tempnam',
|
||||
'touch',
|
||||
'unlink',
|
||||
'getimagesize',
|
||||
'call_user_func',
|
||||
'call_user_func_array',
|
||||
'create_function',
|
||||
|
||||
|
||||
//mutliple files per function call
|
||||
'copy',
|
||||
'link',
|
||||
'rename',
|
||||
'symlink',
|
||||
'move_uploaded_file',
|
||||
'chdir',
|
||||
'chroot',
|
||||
'create_cache_directory',
|
||||
'mk_temp_dir',
|
||||
'write_array_to_file',
|
||||
'write_encoded_file',
|
||||
'create_custom_directory',
|
||||
'sugar_rename',
|
||||
'sugar_chown',
|
||||
'sugar_fopen',
|
||||
'sugar_mkdir',
|
||||
'sugar_file_put_contents',
|
||||
'sugar_chgrp',
|
||||
'sugar_chmod',
|
||||
'sugar_touch',
|
||||
|
||||
);
|
||||
|
||||
public function printToWiki(){
|
||||
echo "'''Default Extensions'''<br>";
|
||||
foreach($this->validExt as $b){
|
||||
echo '#' . $b . '<br>';
|
||||
|
||||
}
|
||||
echo "'''Default Black Listed Functions'''<br>";
|
||||
foreach($this->blackList as $b){
|
||||
echo '#' . $b . '<br>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function __construct(){
|
||||
if(!empty($GLOBALS['sugar_config']['moduleInstaller']['blackListExempt'])){
|
||||
$this->blackListExempt = array_merge($this->blackListExempt, $GLOBALS['sugar_config']['moduleInstaller']['blackListExempt']);
|
||||
}
|
||||
if(!empty($GLOBALS['sugar_config']['moduleInstaller']['blackList'])){
|
||||
$this->blackList = array_merge($this->blackList, $GLOBALS['sugar_config']['moduleInstaller']['blackList']);
|
||||
}
|
||||
if(!empty($GLOBALS['sugar_config']['moduleInstaller']['validExt'])){
|
||||
$this->validExt = array_merge($this->validExt, $GLOBALS['sugar_config']['moduleInstaller']['validExt']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private $issues = array();
|
||||
private $pathToModule = '';
|
||||
|
||||
/**
|
||||
*returns a list of issues
|
||||
*/
|
||||
public function getIssues(){
|
||||
return $this->issues;
|
||||
}
|
||||
|
||||
/**
|
||||
*returns true or false if any issues were found
|
||||
*/
|
||||
public function hasIssues(){
|
||||
return !empty($this->issues);
|
||||
}
|
||||
|
||||
/**
|
||||
*Ensures that a file has a valid extension
|
||||
*/
|
||||
private function isValidExtension($file){
|
||||
$file = strtolower($file);
|
||||
|
||||
$extPos = strrpos($file, '.');
|
||||
//make sure they don't override the files.md5
|
||||
if($extPos === false || $file == 'files.md5')return false;
|
||||
$ext = substr($file, $extPos + 1);
|
||||
return in_array($ext, $this->validExt);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*Scans a directory and calls on scan file for each file
|
||||
**/
|
||||
public function scanDir($path){
|
||||
static $startPath = '';
|
||||
if(empty($startPath))$startPath = $path;
|
||||
if(!is_dir($path))return false;
|
||||
$d = dir($path);
|
||||
while($e = $d->read()){
|
||||
$next = $path . '/' . $e;
|
||||
if(is_dir($next)){
|
||||
if(substr($e, 0, 1) == '.')continue;
|
||||
$this->scanDir($next);
|
||||
}else{
|
||||
$issues = $this->scanFile($next);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given a file it will open it's contents and check if it is a PHP file (not safe to just rely on extensions) if it finds <?php tags it will use the tokenizer to scan the file
|
||||
* $var() and ` are always prevented then whatever is in the blacklist.
|
||||
* It will also ensure that all files are of valid extension types
|
||||
*
|
||||
*/
|
||||
public function scanFile($file){
|
||||
$issues = array();
|
||||
if(!$this->isValidExtension($file)){
|
||||
$issues[] = translate('ML_INVALID_EXT');
|
||||
$this->issues['file'][$file] = $issues;
|
||||
return $issues;
|
||||
}
|
||||
$contents = file_get_contents($file);
|
||||
if(stripos($contents,'<?php') === false )return $issues;
|
||||
$tokens = token_get_all($contents);
|
||||
$checkFunction = false;
|
||||
$possibleIssue = '';
|
||||
$lastToken = false;
|
||||
foreach($tokens as $index=>$token){
|
||||
if(is_string($token[0])){
|
||||
switch($token[0]){
|
||||
case '`':
|
||||
$issues['backtick'] = translate('ML_INVALID_FUNCTION') . " '`'";
|
||||
case '(':
|
||||
if($checkFunction)$issues[] = $possibleIssue;
|
||||
break;
|
||||
}
|
||||
$checkFunction = false;
|
||||
$possibleIssue = '';
|
||||
}else{
|
||||
$token['_msi'] = token_name($token[0]);
|
||||
switch($token[0]){
|
||||
case T_WHITESPACE: continue;
|
||||
case T_EVAL:
|
||||
if(in_array('eval', $this->blackList) && !in_array('eval', $this->blackListExempt))
|
||||
$issues[]= translate('ML_INVALID_FUNCTION') . ' eval()';
|
||||
break;
|
||||
case T_STRING:
|
||||
$token[1] = strtolower($token[1]);
|
||||
if(!in_array($token[1], $this->blackList))break;
|
||||
if(in_array($token[1], $this->blackListExempt))break;
|
||||
if ($lastToken !== false &&
|
||||
($lastToken[0] == T_NEW || $lastToken[0] == T_OBJECT_OPERATOR || $lastToken[0] == T_DOUBLE_COLON))
|
||||
{
|
||||
break;
|
||||
}
|
||||
case T_VARIABLE:
|
||||
$checkFunction = true;
|
||||
$possibleIssue = translate('ML_INVALID_FUNCTION') . ' ' . $token[1] . '()';
|
||||
break;
|
||||
|
||||
default:
|
||||
$checkFunction = false;
|
||||
$possibleIssue = '';
|
||||
|
||||
}
|
||||
if ($token[0] != T_WHITESPACE)
|
||||
{
|
||||
$lastToken = $token;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if(!empty($issues)){
|
||||
$this->issues['file'][$file] = $issues;
|
||||
}
|
||||
|
||||
return $issues;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* checks files.md5 file to see if the file is from sugar
|
||||
* ONLY WORKS ON FILES
|
||||
*/
|
||||
public function sugarFileExists($path){
|
||||
static $md5 = array();
|
||||
if(empty($md5)){
|
||||
include('files.md5');
|
||||
$md5 = $md5_string;
|
||||
}
|
||||
if(isset($md5['./' . $path]))return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*This function will scan the Manifest for disabled actions specified in $GLOBALS['sugar_config']['moduleInstaller']['disableActions']
|
||||
*if $GLOBALS['sugar_config']['moduleInstaller']['disableRestrictedCopy'] is set to false or not set it will call on scanCopy to ensure that it is not overriding files
|
||||
*/
|
||||
public function scanManifest($manifestPath){
|
||||
$issues = array();
|
||||
if(!file_exists($manifestPath)){
|
||||
$this->issues['manifest'][$manifestPath] = translate('ML_NO_MANIFEST');
|
||||
return $issues;
|
||||
}
|
||||
$fileIssues = $this->scanFile($manifestPath);
|
||||
//if the manifest contains malicious code do not open it
|
||||
if(!empty($fileIssues)){
|
||||
return $fileIssues;
|
||||
}
|
||||
include($manifestPath);
|
||||
|
||||
|
||||
//scan for disabled actions
|
||||
if(isset($GLOBALS['sugar_config']['moduleInstaller']['disableActions'])){
|
||||
foreach($GLOBALS['sugar_config']['moduleInstaller']['disableActions'] as $action){
|
||||
if(isset($installdefs[$this->manifestMap[$action]])){
|
||||
$issues[] = translate('ML_INVALID_ACTION_IN_MANIFEST') . $this->manifestMap[$action];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//now lets scan for files that will override our files
|
||||
if(empty($GLOBALS['sugar_config']['moduleInstaller']['disableRestrictedCopy']) && isset($installdefs['copy'])){
|
||||
foreach($installdefs['copy'] as $copy){
|
||||
$from = str_replace('<basepath>', $this->pathToModule, $copy['from']);
|
||||
$to = $copy['to'];
|
||||
if(substr_count($from, '..')){
|
||||
$this->issues['copy'][$from] = translate('ML_PATH_MAY_NOT_CONTAIN').' ".." -' . $from;
|
||||
}
|
||||
if(substr_count($to, '..')){
|
||||
$this->issues['copy'][$to] = translate('ML_PATH_MAY_NOT_CONTAIN'). ' ".." -' . $to;
|
||||
}
|
||||
while(substr_count($from, '//')){
|
||||
$from = str_replace('//', '/', $from);
|
||||
}
|
||||
while(substr_count($to, '//')){
|
||||
$to = str_replace('//', '/', $to);
|
||||
}
|
||||
$this->scanCopy($from, $to);
|
||||
}
|
||||
}
|
||||
if(!empty($issues)){
|
||||
$this->issues['manifest'][$manifestPath] = $issues;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Takes in where the file will is specified to be copied from and to
|
||||
* and ensures that there is no official sugar file there. If the file exists it will check
|
||||
* against the MD5 file list to see if Sugar Created the file
|
||||
*
|
||||
*/
|
||||
function scanCopy($from, $to){
|
||||
//if the file doesn't exist for the $to then it is not overriding anything
|
||||
if(!file_exists($to))return;
|
||||
//if $to is a dir and $from is a file then make $to a full file path as well
|
||||
if(is_dir($to) && is_file($from)){
|
||||
if(substr($to,-1) === '/'){
|
||||
$to = substr($to, 0 , strlen($to) - 1);
|
||||
}
|
||||
$to .= '/'. basename($from);
|
||||
}
|
||||
//if the $to is a file and it is found in sugarFileExists then don't allow overriding it
|
||||
if(is_file($to) && $this->sugarFileExists($to)){
|
||||
$this->issues['copy'][$from] = translate('ML_OVERRIDE_CORE_FILES') . '(' . $to . ')';
|
||||
}
|
||||
|
||||
if(is_dir($from)){
|
||||
$d = dir($from);
|
||||
while($e = $d->read()){
|
||||
if($e == '.' || $e == '..')continue;
|
||||
$this->scanCopy($from .'/'. $e, $to .'/' . $e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*Main external function that takes in a path to a package and then scans
|
||||
*that package's manifest for disabled actions and then it scans the PHP files
|
||||
*for restricted function calls
|
||||
*
|
||||
*/
|
||||
public function scanPackage($path){
|
||||
$this->pathToModule = $path;
|
||||
$this->scanManifest($path . '/manifest.php');
|
||||
if(empty($GLOBALS['sugar_config']['moduleInstaller']['disableFileScan'])){
|
||||
$this->scanDir($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*This function will take all issues of the current instance and print them to the screen
|
||||
**/
|
||||
public function displayIssues($package='Package'){
|
||||
echo '<h2>'.str_replace('{PACKAGE}' , $package ,translate('ML_PACKAGE_SCANNING')). '</h2><BR><h2 class="error">' . translate('ML_INSTALLATION_FAILED') . '</h2><br><p>' .str_replace('{PACKAGE}' , $package ,translate('ML_PACKAGE_NOT_CONFIRM')). '</p><ul><li>'. translate('ML_OBTAIN_NEW_PACKAGE') . '<li>' . translate('ML_RELAX_LOCAL').
|
||||
'</ul></p><br>' . translate('ML_SUGAR_LOADING_POLICY') . ' <a href=" http://kb.sugarcrm.com/custom/module-loader-restrictions-for-sugar-open-cloud/">' . translate('ML_SUGAR_KB') . '</a>.'.
|
||||
'<br>' . translate('ML_AVAIL_RESTRICTION'). ' <a href=" http://developers.sugarcrm.com/wordpress/2009/08/14/module-loader-restrictions/">' . translate('ML_SUGAR_DZ') . '</a>.<br><br>';
|
||||
|
||||
|
||||
foreach($this->issues as $type=>$issues){
|
||||
echo '<div class="error"><h2>'. ucfirst($type) .' ' . translate('ML_ISSUES') . '</h2> </div>';
|
||||
echo '<div id="details' . $type . '" >';
|
||||
foreach($issues as $file=>$issue){
|
||||
$file = str_replace($this->pathToModule . '/', '', $file);
|
||||
echo '<div style="position:relative;left:10px"><b>' . $file . '</b></div><div style="position:relative;left:20px">';
|
||||
if(is_array($issue)){
|
||||
foreach($issue as $i){
|
||||
echo "$i<br>";
|
||||
}
|
||||
}else{
|
||||
echo "$issue<br>";
|
||||
}
|
||||
echo "</div>";
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
echo "<br><input class='button' onclick='document.location.href=\"index.php?module=Administration&action=UpgradeWizard&view=module\"' type='button' value=\"" . translate('LBL_UW_BTN_BACK_TO_MOD_LOADER') . "\" />";
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
71
ModuleInstall/PackageManager/ListViewPackages.php
Executable file
71
ModuleInstall/PackageManager/ListViewPackages.php
Executable file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
require_once('include/ListView/ListViewSmarty.php');
|
||||
|
||||
class ListViewPackages extends ListViewSmarty{
|
||||
var $secondaryDisplayColumns;
|
||||
/**
|
||||
* Constructor Call ListViewSmarty
|
||||
*/
|
||||
function ListViewPackages(){
|
||||
parent::ListViewSmarty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the setup method in ListViewSmarty since we are not passing in a bean
|
||||
*
|
||||
* @param data the data to display on the page
|
||||
* @param file the template file to parse
|
||||
*/
|
||||
function setup($data, $file){
|
||||
$this->data = $data;
|
||||
$this->tpl = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the display method
|
||||
*/
|
||||
function display(){
|
||||
global $odd_bg, $even_bg, $app_strings;
|
||||
$this->ss->assign('rowColor', array('oddListRow', 'evenListRow'));
|
||||
$this->ss->assign('bgColor', array($odd_bg, $even_bg));
|
||||
$this->ss->assign('displayColumns', $this->displayColumns);
|
||||
$this->ss->assign('secondaryDisplayColumns', $this->secondaryDisplayColumns);
|
||||
$this->ss->assign('data', $this->data);
|
||||
return $this->ss->fetch($this->tpl);
|
||||
}
|
||||
}
|
||||
?>
|
||||
355
ModuleInstall/PackageManager/PackageController.php
Executable file
355
ModuleInstall/PackageManager/PackageController.php
Executable file
@@ -0,0 +1,355 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
require_once('ModuleInstall/PackageManager/PackageManagerDisplay.php');
|
||||
require_once('ModuleInstall/PackageManager/PackageManager.php');
|
||||
class PackageController{
|
||||
var $_pm;
|
||||
|
||||
/**
|
||||
* Constructor: this class is called from the the ajax call and handles invoking the correct
|
||||
* functionality on the server.
|
||||
*/
|
||||
function PackageController(){
|
||||
$this->_pm = new PackageManager();
|
||||
}
|
||||
|
||||
function performBasicSearch(){
|
||||
$json = getJSONobj();
|
||||
$search_term = '';
|
||||
$node_id = '';
|
||||
if(isset($_REQUEST['search_term'])) {
|
||||
$search_term = nl2br($_REQUEST['search_term']);
|
||||
}
|
||||
if(isset($_REQUEST['node_id'])) {
|
||||
$node_id = nl2br($_REQUEST['node_id']);
|
||||
}
|
||||
$xml = PackageManager::getPackages($node_id);
|
||||
echo 'result = ' . $json->encode(array('packages' => $xml));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a list of packages which belong to the corresponding category
|
||||
*
|
||||
* @param category_id this is passed via POST and is the category id of packages
|
||||
* we wish to retrieve
|
||||
* @return packages xml string consisting of the packages and releases which belong to
|
||||
* the category
|
||||
*/
|
||||
function getPackages(){
|
||||
$json = getJSONobj();
|
||||
$category_id = '';
|
||||
|
||||
if(isset($_REQUEST['category_id'])) {
|
||||
$category_id = nl2br($_REQUEST['category_id']);
|
||||
}
|
||||
$xml = PackageManager::getPackages($category_id);
|
||||
echo 'result = ' . $json->encode(array('package_output' => $xml));
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a list of releases from the server. This function is currently used for generating the patches/langpacks for upgrade wizard
|
||||
* as well as during installation
|
||||
*/
|
||||
function getReleases(){
|
||||
$json = getJSONobj();
|
||||
$category_id = '';
|
||||
$package_id = '';
|
||||
$types = '';
|
||||
if(isset($_REQUEST['category_id'])) {
|
||||
$category_id = nl2br($_REQUEST['category_id']);
|
||||
}
|
||||
if(isset($_REQUEST['package_id'])) {
|
||||
$package_id = nl2br($_REQUEST['package_id']);
|
||||
}
|
||||
if(isset($_REQUEST['types'])) {
|
||||
$types = nl2br($_REQUEST['types']);
|
||||
}
|
||||
$types = explode(',', $types);
|
||||
|
||||
$filter = array();
|
||||
$count = count($types);
|
||||
$index = 1;
|
||||
$type_str = '';
|
||||
foreach($types as $type){
|
||||
$type_str .= "'".$type."'";
|
||||
if($index < $count)
|
||||
$type_str .= ",";
|
||||
$index++;
|
||||
}
|
||||
|
||||
$filter = array('type' => $type_str);
|
||||
$filter = PackageManager::toNameValueList($filter);
|
||||
$releases = PackageManager::getReleases($category_id, $package_id, $filter);
|
||||
$nodes = array();
|
||||
$release_map = array();
|
||||
foreach($releases['packages'] as $release){
|
||||
$release = PackageManager::fromNameValueList($release);
|
||||
$nodes[] = array('description' => $release['description'], 'version' => $release['version'], 'build_number' => $release['build_number'], 'id' => $release['id']);
|
||||
$release_map[$release['id']] = array('package_id' => $release['package_id'], 'category_id' => $release['category_id']);
|
||||
}
|
||||
$_SESSION['ML_PATCHES'] = $release_map;
|
||||
echo 'result = ' . $json->encode(array('releases' => $nodes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a promotion from the depot
|
||||
*/
|
||||
function getPromotion(){
|
||||
$json = getJSONobj();
|
||||
|
||||
$header = PackageManager::getPromotion();
|
||||
|
||||
echo 'result = ' . $json->encode(array('promotion' => $header));
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the given release
|
||||
*
|
||||
* @param category_id this is passed via POST and is the category id of the release we wish to download
|
||||
* @param package_id this is passed via POST and is the package id of the release we wish to download
|
||||
* @param release_id this is passed via POST and is the release id of the release we wish to download
|
||||
* @return bool true is successful in downloading, false otherwise
|
||||
*/
|
||||
function download(){
|
||||
global $sugar_config;
|
||||
$json = getJSONobj();
|
||||
$package_id = '';
|
||||
$category_id = '';
|
||||
$release_id = '';
|
||||
if(isset($_REQUEST['package_id'])) {
|
||||
$package_id = nl2br($_REQUEST['package_id']);
|
||||
}
|
||||
if(isset($_REQUEST['category_id'])) {
|
||||
$category_id = nl2br($_REQUEST['category_id']);
|
||||
}
|
||||
if(isset($_REQUEST['release_id'])) {
|
||||
$release_id = nl2br($_REQUEST['release_id']);
|
||||
}
|
||||
$GLOBALS['log']->debug("PACKAGE ID: ".$package_id);
|
||||
$GLOBALS['log']->debug("CATEGORY ID: ".$category_id);
|
||||
$GLOBALS['log']->debug("RELEASE ID: ".$release_id);
|
||||
$result = $this->_pm->download($category_id, $package_id, $release_id, getcwd().'/'.$sugar_config['upload_dir']);
|
||||
$GLOBALS['log']->debug("RESULT: ".print_r($result,true));
|
||||
$success = 'false';
|
||||
if($result != null){
|
||||
$GLOBALS['log']->debug("Performing Setup");
|
||||
$this->_pm->performSetup($result, 'module', false);
|
||||
$GLOBALS['log']->debug("Complete Setup");
|
||||
$success = 'true';
|
||||
}
|
||||
echo 'result = ' . $json->encode(array('success' => $success));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a list of categories that are subcategories to the selected category
|
||||
*
|
||||
* @param id - the id of the parent_category, -1 if this is the root
|
||||
* @return array - a list of categories/nodes which are underneath this node
|
||||
*/
|
||||
function getCategories(){
|
||||
$json = getJSONobj();
|
||||
$node_id = '';
|
||||
if(isset($_REQUEST['category_id'])) {
|
||||
$node_id = nl2br($_REQUEST['category_id']);
|
||||
}
|
||||
$GLOBALS['log']->debug("NODE ID: ".$node_id);
|
||||
$nodes = PackageManager::getCategories($node_id);
|
||||
echo 'result = ' . $json->encode(array('nodes' => $nodes));
|
||||
}
|
||||
|
||||
function getNodes(){
|
||||
$json = getJSONobj();
|
||||
$category_id = '';
|
||||
if(isset($_REQUEST['category_id'])) {
|
||||
$category_id = nl2br($_REQUEST['category_id']);
|
||||
}
|
||||
$GLOBALS['log']->debug("CATEGORY ID: ".$category_id);
|
||||
$nodes = PackageManager::getModuleLoaderCategoryPackages($category_id);
|
||||
$GLOBALS['log']->debug(var_export($nodes, true));
|
||||
echo 'result = ' . $json->encode(array('nodes' => $nodes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the SugarDepot for updates for the given type as passed in via POST
|
||||
* @param type the type to check for
|
||||
* @return array return an array of releases for each given installed object if an update is found
|
||||
*/
|
||||
function checkForUpdates(){
|
||||
$json = getJSONobj();
|
||||
$type = '';
|
||||
if(isset($_REQUEST['type'])) {
|
||||
$type = nl2br($_REQUEST['type']);
|
||||
}
|
||||
$pm = new PackageManager();
|
||||
$updates = $pm->checkForUpdates();
|
||||
$nodes = array();
|
||||
$release_map = array();
|
||||
if(!empty($updates)){
|
||||
foreach($updates as $update){
|
||||
$update = PackageManager::fromNameValueList($update);
|
||||
$nodes[] = array('label' => $update['name'], 'description' => $update['description'], 'version' => $update['version'], 'build_number' => $update['build_number'], 'id' => $update['id'], 'type' => $update['type']);
|
||||
$release_map[$update['id']] = array('package_id' => $update['package_id'], 'category_id' => $update['category_id'], 'type' => $update['type']);
|
||||
}
|
||||
}
|
||||
//patches
|
||||
$filter = array(array('name' => 'type', 'value' => "'patch'"));
|
||||
$releases = $pm->getReleases('', '', $filter);
|
||||
if(!empty($releases['packages'])){
|
||||
foreach($releases['packages'] as $update){
|
||||
$update = PackageManager::fromNameValueList($update);
|
||||
$nodes[] = array('label' => $update['name'], 'description' => $update['description'], 'version' => $update['version'], 'build_number' => $update['build_number'], 'id' => $update['id'], 'type' => $update['type']);
|
||||
$release_map[$update['id']] = array('package_id' => $update['package_id'], 'category_id' => $update['category_id'], 'type' => $update['type']);
|
||||
}
|
||||
}
|
||||
$_SESSION['ML_PATCHES'] = $release_map;
|
||||
echo 'result = ' . $json->encode(array('updates' => $nodes));
|
||||
}
|
||||
|
||||
function getLicenseText(){
|
||||
$json = getJSONobj();
|
||||
$file = '';
|
||||
if(isset($_REQUEST['file'])) {
|
||||
$file = hashToFile($_REQUEST['file']);
|
||||
}
|
||||
$GLOBALS['log']->debug("FILE : ".$file);
|
||||
echo 'result = ' . $json->encode(array('license_display' => PackageManagerDisplay::buildLicenseOutput($file)));
|
||||
}
|
||||
|
||||
/**
|
||||
* build the list of modules that are currently in the staging area waiting to be installed
|
||||
*/
|
||||
function getPackagesInStaging(){
|
||||
$packages = $this->_pm->getPackagesInStaging('module');
|
||||
$json = getJSONobj();
|
||||
|
||||
echo 'result = ' . $json->encode(array('packages' => $packages));
|
||||
}
|
||||
|
||||
/**
|
||||
* build the list of modules that are currently in the staging area waiting to be installed
|
||||
*/
|
||||
function performInstall(){
|
||||
$file = '';
|
||||
if(isset($_REQUEST['file'])) {
|
||||
$file = hashToFile($_REQUEST['file']);
|
||||
}
|
||||
if(!empty($file)){
|
||||
$this->_pm->performInstall($file);
|
||||
}
|
||||
$json = getJSONobj();
|
||||
|
||||
echo 'result = ' . $json->encode(array('result' => 'success'));
|
||||
}
|
||||
|
||||
function authenticate(){
|
||||
$json = getJSONobj();
|
||||
$username = '';
|
||||
$password = '';
|
||||
$servername = '';
|
||||
$terms_checked = '';
|
||||
if(isset($_REQUEST['username'])) {
|
||||
$username = nl2br($_REQUEST['username']);
|
||||
}
|
||||
if(isset($_REQUEST['password'])) {
|
||||
$password = nl2br($_REQUEST['password']);
|
||||
}
|
||||
if(isset($_REQUEST['servername'])) {
|
||||
$servername = $_REQUEST['servername'];
|
||||
}
|
||||
if(isset($_REQUEST['terms_checked'])) {
|
||||
$terms_checked = $_REQUEST['terms_checked'];
|
||||
if($terms_checked == 'on')
|
||||
$terms_checked = true;
|
||||
}
|
||||
|
||||
if(!empty($username) && !empty($password)){
|
||||
$password = md5($password);
|
||||
$result = PackageManager::authenticate($username, $password, $servername, $terms_checked);
|
||||
if(!is_array($result) && $result == true)
|
||||
$status = 'success';
|
||||
else
|
||||
$status = $result['faultstring'];
|
||||
}else{
|
||||
$status = 'failed';
|
||||
}
|
||||
|
||||
echo 'result = ' . $json->encode(array('status' => $status));
|
||||
}
|
||||
|
||||
function getDocumentation(){
|
||||
$json = getJSONobj();
|
||||
$package_id = '';
|
||||
$release_id = '';
|
||||
|
||||
if(isset($_REQUEST['package_id'])) {
|
||||
$package_id = nl2br($_REQUEST['package_id']);
|
||||
}
|
||||
if(isset($_REQUEST['release_id'])) {
|
||||
$release_id = nl2br($_REQUEST['release_id']);
|
||||
}
|
||||
|
||||
$documents = PackageManager::getDocumentation($package_id, $release_id);
|
||||
$GLOBALS['log']->debug("DOCUMENTS: ".var_export($documents, true));
|
||||
echo 'result = ' . $json->encode(array('documents' => $documents));
|
||||
}
|
||||
|
||||
function downloadedDocumentation(){
|
||||
$json = getJSONobj();
|
||||
$document_id = '';
|
||||
|
||||
if(isset($_REQUEST['document_id'])) {
|
||||
$document_id = nl2br($_REQUEST['document_id']);
|
||||
}
|
||||
$GLOBALS['log']->debug("Downloading Document: ".$document_id);
|
||||
PackageManagerComm::downloadedDocumentation($document_id);
|
||||
echo 'result = ' . $json->encode(array('result' => 'true'));
|
||||
}
|
||||
|
||||
function remove(){
|
||||
$json = getJSONobj();
|
||||
$file = '';
|
||||
|
||||
if(isset($_REQUEST['file'])) {
|
||||
$file = urldecode(hashToFile($_REQUEST['file']));
|
||||
}
|
||||
$GLOBALS['log']->debug("FILE TO REMOVE: ".$file);
|
||||
if(!empty($file)){
|
||||
unlink($file);
|
||||
}
|
||||
echo 'result = ' . $json->encode(array('result' => 'true'));
|
||||
}
|
||||
}
|
||||
?>
|
||||
866
ModuleInstall/PackageManager/PackageManager.php
Executable file
866
ModuleInstall/PackageManager/PackageManager.php
Executable file
@@ -0,0 +1,866 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
define("CREDENTIAL_CATEGORY", "ml");
|
||||
define("CREDENTIAL_USERNAME", "username");
|
||||
define("CREDENTIAL_PASSWORD", "password");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
require_once('include/nusoap/nusoap.php');
|
||||
|
||||
require_once('include/utils/zip_utils.php');
|
||||
|
||||
require_once('ModuleInstall/PackageManager/PackageManagerDisplay.php');
|
||||
require_once('ModuleInstall/ModuleInstaller.php');
|
||||
|
||||
require_once('include/entryPoint.php');
|
||||
require_once('ModuleInstall/PackageManager/PackageManagerComm.php');
|
||||
|
||||
|
||||
class PackageManager{
|
||||
var $soap_client;
|
||||
|
||||
/**
|
||||
* Constructor: In this method we will initialize the nusoap client to point to the hearbeat server
|
||||
*/
|
||||
function PackageManager(){
|
||||
$this->db = & DBManagerFactory::getInstance();
|
||||
}
|
||||
|
||||
function initializeComm(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a promotion from SugarDepot
|
||||
* @return string the string from the promotion
|
||||
*/
|
||||
function getPromotion(){
|
||||
$name_value_list = PackageManagerComm::getPromotion();
|
||||
if(!empty($name_value_list)){
|
||||
$name_value_list = PackageManager::fromNameValueList($name_value_list);
|
||||
return $name_value_list['description'];
|
||||
}else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a list of category/packages/releases for use within the module loader
|
||||
*/
|
||||
function getModuleLoaderCategoryPackages($category_id = ''){
|
||||
$filter = array();
|
||||
$filter = array('type' => "'module', 'theme', 'langpack'");
|
||||
$filter = PackageManager::toNameValueList($filter);
|
||||
return PackageManager::getCategoryPackages($category_id, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the list of category_packages from SugarDepot
|
||||
* @return category_packages
|
||||
*/
|
||||
function getCategoryPackages($category_id = '', $filter = array()){
|
||||
$results = PackageManagerComm::getCategoryPackages($category_id, $filter);
|
||||
PackageManagerComm::errorCheck();
|
||||
$nodes = array();
|
||||
|
||||
$nodes[$category_id]['packages'] = array();
|
||||
if(!empty($results['categories'])){
|
||||
foreach($results['categories'] as $category){
|
||||
$mycat = PackageManager::fromNameValueList($category);
|
||||
$nodes[$mycat['id']] = array('id' => $mycat['id'], 'label' => $mycat['name'], 'description' => $mycat['description'], 'type' => 'cat', 'parent' => $mycat['parent_id']);
|
||||
$nodes[$mycat['id']]['packages'] = array();
|
||||
}
|
||||
}
|
||||
if(!empty($results['packages'])){
|
||||
$uh = new UpgradeHistory();
|
||||
foreach($results['packages'] as $package){
|
||||
$mypack = PackageManager::fromNameValueList($package);
|
||||
$nodes[$mypack['category_id']]['packages'][$mypack['id']] = array('id' => $mypack['id'], 'label' => $mypack['name'], 'description' => $mypack['description'], 'category_id' => $mypack['category_id'], 'type' => 'package');
|
||||
$releases = PackageManager::getReleases($category_id, $mypack['id'], $filter);
|
||||
$arr_releases = array();
|
||||
$nodes[$mypack['category_id']]['packages'][$mypack['id']]['releases'] = array();
|
||||
if(!empty($releases['packages'])){
|
||||
foreach($releases['packages'] as $release){
|
||||
$myrelease = PackageManager::fromNameValueList($release);
|
||||
//check to see if we already this one installed
|
||||
$result = $uh->determineIfUpgrade($myrelease['id_name'], $myrelease['version']);
|
||||
$enable = false;
|
||||
if($result == true || is_array($result))
|
||||
$enable = true;
|
||||
$nodes[$mypack['category_id']]['packages'][$mypack['id']]['releases'][$myrelease['id']] = array('id' => $myrelease['id'], 'version' => $myrelease['version'], 'label' => $myrelease['description'], 'category_id' => $mypack['category_id'], 'package_id' => $mypack['id'], 'type' => 'release', 'enable' => $enable);
|
||||
}
|
||||
}
|
||||
//array_push($nodes[$mypack['category_id']]['packages'], $package_arr);
|
||||
}
|
||||
}
|
||||
$GLOBALS['log']->debug("NODES". var_export($nodes, true));
|
||||
return $nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of categories from the SugarDepot
|
||||
* @param category_id the category id of parent to obtain
|
||||
* @param filter an array of filters to pass to limit the query
|
||||
* @return array an array of categories for display on the client
|
||||
*/
|
||||
function getCategories($category_id, $filter = array()){
|
||||
$nodes = array();
|
||||
$results = PackageManagerComm::getCategories($category_id, $filter);
|
||||
PackageManagerComm::errorCheck();
|
||||
if(!empty($results['categories'])){
|
||||
foreach($results['categories'] as $category){
|
||||
$mycat = PackageManager::fromNameValueList($category);
|
||||
$nodes[] = array('id' => $mycat['id'], 'label' => $mycat['name'], 'description' => $mycat['description'], 'type' => 'cat', 'parent' => $mycat['parent_id']);
|
||||
}
|
||||
}
|
||||
return $nodes;
|
||||
}
|
||||
|
||||
function getPackages($category_id, $filter = array()){
|
||||
$nodes = array();
|
||||
$results = PackageManagerComm::getPackages($category_id, $filter);
|
||||
PackageManagerComm::errorCheck();
|
||||
$packages = array();
|
||||
//$xml = '';
|
||||
//$xml .= '<packages>';
|
||||
if(!empty($results['packages'])){
|
||||
foreach($results['packages'] as $package){
|
||||
$mypack = PackageManager::fromNameValueList($package);
|
||||
$packages[$mypack['id']] = array('package_id' => $mypack['id'], 'name' => $mypack['name'], 'description' => $mypack['description'], 'category_id' => $mypack['category_id']);
|
||||
$releases = PackageManager::getReleases($category_id, $mypack['id']);
|
||||
$arr_releases = array();
|
||||
foreach($releases['packages'] as $release){
|
||||
$myrelease = PackageManager::fromNameValueList($release);
|
||||
$arr_releases[$myrelease['id']] = array('release_id' => $myrelease['id'], 'version' => $myrelease['version'], 'description' => $myrelease['description'], 'category_id' => $mypack['category_id'], 'package_id' => $mypack['id']);
|
||||
}
|
||||
$packages[$mypack['id']]['releases'] = $arr_releases;
|
||||
}
|
||||
}
|
||||
return $packages;
|
||||
}
|
||||
|
||||
function getReleases($category_id, $package_id, $filter = array()){
|
||||
$releases = PackageManagerComm::getReleases($category_id, $package_id, $filter);
|
||||
PackageManagerComm::errorCheck();
|
||||
return $releases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the package as specified by the $id from the heartbeat server
|
||||
*
|
||||
* @param category_id the category_id to which the release belongs
|
||||
* @param package_id the package_id to which the release belongs
|
||||
* @param release_id the release_id to download
|
||||
* @return filename - the path to which the zip file was saved
|
||||
*/
|
||||
function download($category_id, $package_id, $release_id, $save_dir = ''){
|
||||
$GLOBALS['log']->debug('RELEASE _ID: '.$release_id);
|
||||
if(!empty($release_id)){
|
||||
$filename = PackageManagerComm::addDownload($category_id, $package_id, $release_id);
|
||||
if($filename){
|
||||
$GLOBALS['log']->debug('RESULT: '.$filename);
|
||||
PackageManagerComm::errorCheck();
|
||||
$filepath = PackageManagerComm::performDownload($filename, $save_dir);
|
||||
return $filepath;
|
||||
/*if(!empty($result) && !empty($result['filename']) && !empty($save_dir)){
|
||||
$GLOBALS['log']->debug('Saving Package to: '.$save_dir);
|
||||
$GLOBALS['log']->debug('Saving package to the local file system:'.$result['filename']);
|
||||
return write_encoded_file ($result, $save_dir);
|
||||
}else{
|
||||
return null;
|
||||
}*/
|
||||
}
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the Mambo username, password, and download key attempt to authenticate, if
|
||||
* successful then store these credentials
|
||||
*
|
||||
* @param username Mambo username
|
||||
* @param password Mambo password
|
||||
* @param systemname the user's download key
|
||||
* @return true if successful, false otherwise
|
||||
*/
|
||||
function authenticate($username, $password, $systemname='', $terms_checked = true){
|
||||
PackageManager::setCredentials($username, $password, $systemname);
|
||||
PackageManagerComm::clearSession();
|
||||
$result = PackageManagerComm::login($terms_checked);
|
||||
if(is_array($result))
|
||||
return $result;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
function setCredentials($username, $password, $systemname){
|
||||
|
||||
$admin = new Administration();
|
||||
$admin->retrieveSettings();
|
||||
$admin->saveSetting(CREDENTIAL_CATEGORY, CREDENTIAL_USERNAME, $username);
|
||||
$admin->saveSetting(CREDENTIAL_CATEGORY, CREDENTIAL_PASSWORD, $password);
|
||||
if(!empty($systemname)){
|
||||
$admin->saveSetting('system', 'name', $systemname);
|
||||
}
|
||||
}
|
||||
|
||||
function getCredentials(){
|
||||
|
||||
$admin = new Administration();
|
||||
$admin->retrieveSettings(CREDENTIAL_CATEGORY, true);
|
||||
$credentials = array();
|
||||
$credentials['username'] = '';
|
||||
$credentials['password'] = '';
|
||||
$credentials['system_name'] = '';
|
||||
if(!empty($admin->settings[CREDENTIAL_CATEGORY.'_'.CREDENTIAL_USERNAME])){
|
||||
$credentials['username'] = $admin->settings[CREDENTIAL_CATEGORY.'_'.CREDENTIAL_USERNAME];
|
||||
}
|
||||
if(!empty($admin->settings[CREDENTIAL_CATEGORY.'_'.CREDENTIAL_USERNAME])){
|
||||
$credentials['password'] = $admin->settings[CREDENTIAL_CATEGORY.'_'.CREDENTIAL_PASSWORD];
|
||||
}
|
||||
if(!empty($admin->settings['system_name'])){
|
||||
$credentials['system_name'] = $admin->settings['system_name'];
|
||||
}
|
||||
return $credentials;
|
||||
}
|
||||
|
||||
function getTermsAndConditions(){
|
||||
return PackageManagerComm::getTermsAndConditions();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve documentation for the given release or package
|
||||
*
|
||||
* @param package_id the specified package to retrieve documentation
|
||||
* @param release_id the specified release to retrieve documentation
|
||||
*
|
||||
* @return documents
|
||||
*/
|
||||
function getDocumentation($package_id, $release_id){
|
||||
if(!empty($release_id) || !empty($package_id)){
|
||||
$documents = PackageManagerComm::getDocumentation($package_id, $release_id);
|
||||
return $documents;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab the list of installed modules and send that list to the depot.
|
||||
* The depot will then send back a list of modules that need to be updated
|
||||
*/
|
||||
function checkForUpdates(){
|
||||
$lists = $this->buildInstalledReleases(array('module'), true);
|
||||
$updates = array();
|
||||
if(!empty($lists)){
|
||||
$updates = PackageManagerComm::checkForUpdates($lists);
|
||||
}//fi
|
||||
return $updates;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
/////////// HELPER FUNCTIONS
|
||||
function toNameValueList($array){
|
||||
$list = array();
|
||||
foreach($array as $name=>$value){
|
||||
$list[] = array('name'=>$name, 'value'=>$value);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
function toNameValueLists($arrays){
|
||||
$lists = array();
|
||||
foreach($arrays as $array){
|
||||
$lists[] = PackageManager::toNameValueList($array);
|
||||
}
|
||||
return $lists;
|
||||
}
|
||||
|
||||
function fromNameValueList($nvl){
|
||||
$array = array();
|
||||
foreach($nvl as $list){
|
||||
$array[$list['name']] = $list['value'];
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
function buildInstalledReleases($types = array('module')){
|
||||
//1) get list of installed modules
|
||||
$installeds = $this->getInstalled($types);
|
||||
$releases = array();
|
||||
foreach($installeds as $installed){
|
||||
$releases[] = array('name' => $installed->name, 'id_name' => $installed->id_name, 'version' => $installed->version, 'filename' => $installed->filename, 'type' => $installed->type);
|
||||
}
|
||||
|
||||
$lists = array();
|
||||
$name_value_list = array();
|
||||
if(!empty($releases)){
|
||||
$lists = $this->toNameValueLists($releases);
|
||||
}//fi
|
||||
return $lists;
|
||||
}
|
||||
|
||||
function buildPackageXML($package, $releases = array()){
|
||||
$xml = '<package>';
|
||||
$xml .= '<package_id>'.$package['id'].'</package_id>';
|
||||
$xml .= '<name>'.$package['name'].'</name>';
|
||||
$xml .= '<description>'.$package['description'].'</description>';
|
||||
if(!empty($releases)){
|
||||
$xml .= '<releases>';
|
||||
foreach($releases['packages'] as $release){
|
||||
|
||||
$myrelease = PackageManager::fromNameValueList($release);
|
||||
$xml .= '<release>';
|
||||
$xml .= '<release_id>'.$myrelease['id'].'</release_id>';
|
||||
$xml .= '<version>'.$myrelease['version'].'</version>';
|
||||
$xml .= '<description>'.$myrelease['description'].'</description>';
|
||||
$xml .= '<package_id>'.$package['id'].'</package_id>';
|
||||
$xml .= '<category_id>'.$package['category_id'].'</category_id>';
|
||||
$xml .= '</release>';
|
||||
}
|
||||
$xml .= '</releases>';
|
||||
}
|
||||
$xml .= '</package>';
|
||||
return $xml;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
/////////// INSTALL SECTION
|
||||
function extractFile( $zip_file, $file_in_zip, $base_tmp_upgrade_dir){
|
||||
$my_zip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
|
||||
unzip_file( $zip_file, $file_in_zip, $my_zip_dir );
|
||||
return( "$my_zip_dir/$file_in_zip" );
|
||||
}
|
||||
|
||||
function extractManifest( $zip_file,$base_tmp_upgrade_dir ) {
|
||||
global $sugar_config;
|
||||
$base_upgrade_dir = $sugar_config['upload_dir'] . "/upgrades";
|
||||
$base_tmp_upgrade_dir = "$base_upgrade_dir/temp";
|
||||
return( $this->extractFile( $zip_file, "manifest.php",$base_tmp_upgrade_dir ) );
|
||||
}
|
||||
|
||||
function validate_manifest( $manifest ){
|
||||
// takes a manifest.php manifest array and validates contents
|
||||
global $subdirs;
|
||||
global $sugar_version;
|
||||
global $sugar_flavor;
|
||||
global $mod_strings;
|
||||
|
||||
if( !isset($manifest['type']) ){
|
||||
die($mod_strings['ERROR_MANIFEST_TYPE']);
|
||||
}
|
||||
$type = $manifest['type'];
|
||||
$GLOBALS['log']->debug("Getting InstallType");
|
||||
if( $this->getInstallType( "/$type/" ) == "" ){
|
||||
$GLOBALS['log']->debug("Error with InstallType".$type);
|
||||
die($mod_strings['ERROR_PACKAGE_TYPE']. ": '" . $type . "'." );
|
||||
}
|
||||
$GLOBALS['log']->debug("Passed with InstallType");
|
||||
if( isset($manifest['acceptable_sugar_versions']) ){
|
||||
$version_ok = false;
|
||||
$matches_empty = true;
|
||||
if( isset($manifest['acceptable_sugar_versions']['exact_matches']) ){
|
||||
$matches_empty = false;
|
||||
foreach( $manifest['acceptable_sugar_versions']['exact_matches'] as $match ){
|
||||
if( $match == $sugar_version ){
|
||||
$version_ok = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( !$version_ok && isset($manifest['acceptable_sugar_versions']['regex_matches']) ){
|
||||
$matches_empty = false;
|
||||
foreach( $manifest['acceptable_sugar_versions']['regex_matches'] as $match ){
|
||||
if( preg_match( "/$match/", $sugar_version ) ){
|
||||
$version_ok = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !$matches_empty && !$version_ok ){
|
||||
die( $mod_strings['ERROR_VERSION_INCOMPATIBLE'] . $sugar_version );
|
||||
}
|
||||
}
|
||||
|
||||
if( isset($manifest['acceptable_sugar_flavors']) && sizeof($manifest['acceptable_sugar_flavors']) > 0 ){
|
||||
$flavor_ok = false;
|
||||
foreach( $manifest['acceptable_sugar_flavors'] as $match ){
|
||||
if( $match == $sugar_flavor ){
|
||||
$flavor_ok = true;
|
||||
}
|
||||
}
|
||||
if( !$flavor_ok ){
|
||||
//die( $mod_strings['ERROR_FLAVOR_INCOMPATIBLE'] . $sugar_flavor );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getInstallType( $type_string ){
|
||||
// detect file type
|
||||
global $subdirs;
|
||||
$subdirs = array('full', 'langpack', 'module', 'patch', 'theme', 'temp');
|
||||
|
||||
|
||||
foreach( $subdirs as $subdir ){
|
||||
if( preg_match( "#/$subdir/#", $type_string ) ){
|
||||
return( $subdir );
|
||||
}
|
||||
}
|
||||
// return empty if no match
|
||||
return( "" );
|
||||
}
|
||||
|
||||
function performSetup($tempFile, $view = 'module', $display_messages = true){
|
||||
global $sugar_config;
|
||||
$base_filename = urldecode($tempFile);
|
||||
$GLOBALS['log']->debug("BaseFileName: ".$base_filename);
|
||||
$base_upgrade_dir = $sugar_config['upload_dir'] . "/upgrades";
|
||||
$base_tmp_upgrade_dir = "$base_upgrade_dir/temp";
|
||||
$manifest_file = $this->extractManifest( $base_filename,$base_tmp_upgrade_dir);
|
||||
$GLOBALS['log']->debug("Manifest: ".$manifest_file);
|
||||
if($view == 'module')
|
||||
$license_file = $this->extractFile($base_filename, 'LICENSE.txt', $base_tmp_upgrade_dir);
|
||||
if(is_file($manifest_file)){
|
||||
$GLOBALS['log']->debug("VALIDATING MANIFEST". $manifest_file);
|
||||
require_once( $manifest_file );
|
||||
$this->validate_manifest($manifest );
|
||||
$upgrade_zip_type = $manifest['type'];
|
||||
$GLOBALS['log']->debug("VALIDATED MANIFEST");
|
||||
// exclude the bad permutations
|
||||
if( $view == "module" ){
|
||||
if ($upgrade_zip_type != "module" && $upgrade_zip_type != "theme" && $upgrade_zip_type != "langpack"){
|
||||
$this->unlinkTempFiles();
|
||||
if($display_messages)
|
||||
die($mod_strings['ERR_UW_NOT_ACCEPTIBLE_TYPE']);
|
||||
}
|
||||
}elseif( $view == "default" ){
|
||||
if($upgrade_zip_type != "patch" ){
|
||||
$this->unlinkTempFiles();
|
||||
if($display_messages)
|
||||
die($mod_strings['ERR_UW_ONLY_PATCHES']);
|
||||
}
|
||||
}
|
||||
|
||||
$base_filename = preg_replace( "#\\\\#", "/", $base_filename );
|
||||
$base_filename = basename( $base_filename );
|
||||
mkdir_recursive( "$base_upgrade_dir/$upgrade_zip_type" );
|
||||
$target_path = "$base_upgrade_dir/$upgrade_zip_type/$base_filename";
|
||||
$target_manifest = remove_file_extension( $target_path ) . "-manifest.php";
|
||||
|
||||
if( isset($manifest['icon']) && $manifest['icon'] != "" ){
|
||||
$icon_location = $this->extractFile( $tempFile ,$manifest['icon'], $base_tmp_upgrade_dir );
|
||||
$path_parts = pathinfo( $icon_location );
|
||||
copy( $icon_location, remove_file_extension( $target_path ) . "-icon." . $path_parts['extension'] );
|
||||
}
|
||||
|
||||
if( copy( $tempFile , $target_path ) ){
|
||||
copy( $manifest_file, $target_manifest );
|
||||
if($display_messages)
|
||||
$messages = '<script>ajaxStatus.flashStatus("' .$base_filename.$mod_strings['LBL_UW_UPLOAD_SUCCESS'] . ', 5000");</script>';
|
||||
}else{
|
||||
if($display_messages)
|
||||
$messages = '<script>ajaxStatus.flashStatus("' .$mod_strings['ERR_UW_UPLOAD_ERROR'] . ', 5000");</script>';
|
||||
}
|
||||
}//fi
|
||||
else{
|
||||
$this->unlinkTempFiles();
|
||||
if($display_messages)
|
||||
die($mod_strings['ERR_UW_NO_MANIFEST']);
|
||||
}
|
||||
if(isset($messages))
|
||||
return $messages;
|
||||
}
|
||||
|
||||
function unlinkTempFiles() {
|
||||
global $sugar_config;
|
||||
@unlink($_FILES['upgrade_zip']['tmp_name']);
|
||||
@unlink(getcwd().'/'.$sugar_config['upload_dir'].$_FILES['upgrade_zip']['name']);
|
||||
}
|
||||
|
||||
function performInstall($file, $silent=true){
|
||||
global $sugar_config;
|
||||
global $mod_strings;
|
||||
global $current_language;
|
||||
$base_upgrade_dir = $sugar_config['upload_dir'] . "/upgrades";
|
||||
$base_tmp_upgrade_dir = "$base_upgrade_dir/temp";
|
||||
if(!file_exists($base_tmp_upgrade_dir)){
|
||||
mkdir_recursive($base_tmp_upgrade_dir, true);
|
||||
}
|
||||
|
||||
$GLOBALS['log']->debug("INSTALLING: ".$file);
|
||||
$mi = new ModuleInstaller();
|
||||
$mi->silent = $silent;
|
||||
$mod_strings = return_module_language($current_language, "Administration");
|
||||
$GLOBALS['log']->debug("ABOUT TO INSTALL: ".$file);
|
||||
if(preg_match("#.*\.zip\$#", $file)) {
|
||||
$GLOBALS['log']->debug("1: ".$file);
|
||||
// handle manifest.php
|
||||
$target_manifest = remove_file_extension( $file ) . '-manifest.php';
|
||||
include($target_manifest);
|
||||
$GLOBALS['log']->debug("2: ".$file);
|
||||
$unzip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
|
||||
unzip($file, $unzip_dir );
|
||||
$GLOBALS['log']->debug("3: ".$unzip_dir);
|
||||
$id_name = $installdefs['id'];
|
||||
$version = $manifest['version'];
|
||||
$uh = new UpgradeHistory();
|
||||
$previous_install = array();
|
||||
if(!empty($id_name) & !empty($version))
|
||||
$previous_install = $uh->determineIfUpgrade($id_name, $version);
|
||||
$previous_version = (empty($previous_install['version'])) ? '' : $previous_install['version'];
|
||||
$previous_id = (empty($previous_install['id'])) ? '' : $previous_install['id'];
|
||||
|
||||
if(!empty($previous_version)){
|
||||
$mi->install($unzip_dir, true, $previous_version);
|
||||
}else{
|
||||
$mi->install($unzip_dir);
|
||||
}
|
||||
$GLOBALS['log']->debug("INSTALLED: ".$file);
|
||||
$new_upgrade = new UpgradeHistory();
|
||||
$new_upgrade->filename = $file;
|
||||
$new_upgrade->md5sum = md5_file($file);
|
||||
$new_upgrade->type = $manifest['type'];
|
||||
$new_upgrade->version = $manifest['version'];
|
||||
$new_upgrade->status = "installed";
|
||||
//$new_upgrade->author = $manifest['author'];
|
||||
$new_upgrade->name = $manifest['name'];
|
||||
$new_upgrade->description = $manifest['description'];
|
||||
$new_upgrade->id_name = $id_name;
|
||||
$serial_manifest = array();
|
||||
$serial_manifest['manifest'] = (isset($manifest) ? $manifest : '');
|
||||
$serial_manifest['installdefs'] = (isset($installdefs) ? $installdefs : '');
|
||||
$serial_manifest['upgrade_manifest'] = (isset($upgrade_manifest) ? $upgrade_manifest : '');
|
||||
$new_upgrade->manifest = base64_encode(serialize($serial_manifest));
|
||||
//$new_upgrade->unique_key = (isset($manifest['unique_key'])) ? $manifest['unique_key'] : '';
|
||||
$new_upgrade->save();
|
||||
//unlink($file);
|
||||
}//fi
|
||||
}
|
||||
|
||||
function performUninstall($name){
|
||||
$uh = new UpgradeHistory();
|
||||
$uh->name = $name;
|
||||
$uh->id_name = $name;
|
||||
$found = $uh->checkForExisting($uh);
|
||||
if($found != null){
|
||||
|
||||
global $sugar_config;
|
||||
global $mod_strings;
|
||||
global $current_language;
|
||||
$base_upgrade_dir = $sugar_config['upload_dir'] . "/upgrades";
|
||||
$base_tmp_upgrade_dir = "$base_upgrade_dir/temp";
|
||||
if(!isset($GLOBALS['mi_remove_tables']))$GLOBALS['mi_remove_tables'] = true;
|
||||
$unzip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
|
||||
unzip($found->filename, $unzip_dir );
|
||||
$mi = new ModuleInstaller();
|
||||
$mi->silent = true;
|
||||
$mi->uninstall( "$unzip_dir");
|
||||
$found->delete();
|
||||
unlink(remove_file_extension( $found->filename ) . '-manifest.php');
|
||||
unlink($found->filename);
|
||||
}
|
||||
}
|
||||
|
||||
function getUITextForType( $type ){
|
||||
if( $type == "full" ){
|
||||
return( "Full Upgrade" );
|
||||
}
|
||||
if( $type == "langpack" ){
|
||||
return( "Language Pack" );
|
||||
}
|
||||
if( $type == "module" ){
|
||||
return( "Module" );
|
||||
}
|
||||
if( $type == "patch" ){
|
||||
return( "Patch" );
|
||||
}
|
||||
if( $type == "theme" ){
|
||||
return( "Theme" );
|
||||
}
|
||||
}
|
||||
|
||||
function getImageForType( $type ){
|
||||
|
||||
$icon = "";
|
||||
switch( $type ){
|
||||
case "full":
|
||||
$icon = SugarThemeRegistry::current()->getImage("Upgrade", "" );
|
||||
break;
|
||||
case "langpack":
|
||||
$icon = SugarThemeRegistry::current()->getImage("LanguagePacks", "" );
|
||||
break;
|
||||
case "module":
|
||||
$icon = SugarThemeRegistry::current()->getImage("ModuleLoader", "" );
|
||||
break;
|
||||
case "patch":
|
||||
$icon = SugarThemeRegistry::current()->getImage("PatchUpgrades", "" );
|
||||
break;
|
||||
case "theme":
|
||||
$icon = SugarThemeRegistry::current()->getImage("Themes", "" );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return( $icon );
|
||||
}
|
||||
|
||||
function getPackagesInStaging($view = 'module'){
|
||||
global $sugar_config;
|
||||
global $current_language;
|
||||
$uh = new UpgradeHistory();
|
||||
$base_upgrade_dir = $sugar_config['upload_dir'] . "/upgrades";
|
||||
$base_tmp_upgrade_dir = "$base_upgrade_dir/temp";
|
||||
$uContent = findAllFiles( "$base_upgrade_dir", array() , false, 'zip',$base_tmp_upgrade_dir);
|
||||
//other variations of zip file i.e. ZIP, zIp,zIP,Zip,ZIp,ZiP
|
||||
$extns = array( 'ZIP','ZIp','ZiP','Zip','zIP','zIp','ziP');
|
||||
foreach($extns as $extn){
|
||||
$uContent = array_merge($uContent,findAllFiles( "$base_upgrade_dir", array() , false, $extn,$base_tmp_upgrade_dir));
|
||||
}
|
||||
$upgrade_contents = array();
|
||||
$content_values = array_values($uContent);
|
||||
$alreadyProcessed = array();
|
||||
foreach($content_values as $val){
|
||||
if(empty($alreadyProcessed[$val])){
|
||||
$upgrade_contents[] = $val;
|
||||
$alreadyProcessed["$val"] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$upgrades_available = 0;
|
||||
$packages = array();
|
||||
$mod_strings = return_module_language($current_language, "Administration");
|
||||
foreach($upgrade_contents as $upgrade_content)
|
||||
{
|
||||
if(!preg_match("#.*\.zip\$#", strtolower($upgrade_content)) || preg_match("#.*./zips/.*#", strtolower($upgrade_content)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$upgrade_content = clean_path($upgrade_content);
|
||||
// Bug 22285 - fix for UNC paths
|
||||
if ( substr($upgrade_content,0,2) == '\\\\' )
|
||||
$upgrade_content = '\\\\'.$upgrade_content;
|
||||
$the_base = basename($upgrade_content);
|
||||
$the_md5 = md5_file($upgrade_content);
|
||||
$md5_matches = $uh->findByMd5($the_md5);
|
||||
$file_install = $upgrade_content;
|
||||
if(0 == sizeof($md5_matches))
|
||||
{
|
||||
$target_manifest = remove_file_extension( $upgrade_content ) . '-manifest.php';
|
||||
require_once($target_manifest);
|
||||
|
||||
$name = empty($manifest['name']) ? $upgrade_content : $manifest['name'];
|
||||
$version = empty($manifest['version']) ? '' : $manifest['version'];
|
||||
$published_date = empty($manifest['published_date']) ? '' : $manifest['published_date'];
|
||||
$icon = '';
|
||||
$description = empty($manifest['description']) ? 'None' : $manifest['description'];
|
||||
$uninstallable = empty($manifest['is_uninstallable']) ? 'No' : 'Yes';
|
||||
$type = $this->getUITextForType( $manifest['type'] );
|
||||
$manifest_type = $manifest['type'];
|
||||
$dependencies = array();
|
||||
if( isset( $manifest['dependencies']) ){
|
||||
$dependencies = $manifest['dependencies'];
|
||||
}
|
||||
|
||||
//check dependencies first
|
||||
if(!empty($dependencies)){
|
||||
|
||||
$uh = new UpgradeHistory();
|
||||
$not_found = $uh->checkDependencies($dependencies);
|
||||
if(!empty($not_found) && count($not_found) > 0){
|
||||
$file_install = 'errors_'.$mod_strings['ERR_UW_NO_DEPENDENCY']."[".implode(',', $not_found)."]";
|
||||
}//fi
|
||||
}
|
||||
|
||||
if($view == 'default' && $manifest_type != 'patch')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if($view == 'module'
|
||||
&& $manifest_type != 'module' && $manifest_type != 'theme' && $manifest_type != 'langpack')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(empty($manifest['icon'])){
|
||||
$icon = $this->getImageForType( $manifest['type'] );
|
||||
}else{
|
||||
$path_parts = pathinfo( $manifest['icon'] );
|
||||
$icon = "<img src=\"" . remove_file_extension( $upgrade_content ) . "-icon." . $path_parts['extension'] . "\">";
|
||||
}
|
||||
|
||||
$upgrades_available++;
|
||||
|
||||
// uploaded file in cache/upload
|
||||
$fileS = explode('/', $upgrade_content);
|
||||
$c = count($fileS);
|
||||
$fileName = (isset($fileS[$c-1]) && !empty($fileS[$c-1])) ? $fileS[$c-1] : $fileS[$c-2];
|
||||
$upload_file = $sugar_config['upload_dir'].$fileName;
|
||||
|
||||
$upgrade_content = urlencode($upgrade_content);
|
||||
$upload_content = urlencode($upload_file);
|
||||
$packages[] = array('name' => $name, 'version' => $version, 'published_date' => $published_date, 'description' => $description, 'uninstallable' =>$uninstallable, 'type' => $type, 'file_install' => fileToHash($file_install), 'file' => fileToHash($upgrade_content), 'upload_file' => $upload_content);
|
||||
}//fi
|
||||
}//rof
|
||||
return $packages;
|
||||
}
|
||||
|
||||
function getLicenseFromFile($file){
|
||||
global $sugar_config;
|
||||
$base_upgrade_dir = $sugar_config['upload_dir'] . "/upgrades";
|
||||
$base_tmp_upgrade_dir = "$base_upgrade_dir/temp";
|
||||
$license_file = $this->extractFile($file, 'LICENSE.txt', $base_tmp_upgrade_dir);
|
||||
if(is_file($license_file)){
|
||||
$fh = sugar_fopen($license_file, 'r');
|
||||
$contents = fread($fh, filesize($license_file));
|
||||
fclose($fh);
|
||||
return $contents;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the query to obtain the list of installed types as specified by the type param
|
||||
*
|
||||
* @param type an array of types you would like to search for
|
||||
* type options include (theme, langpack, module, patch)
|
||||
*
|
||||
* @return an array of installed upgrade_history objects
|
||||
*/
|
||||
function getInstalled($types = array('module')){
|
||||
$uh = new UpgradeHistory();
|
||||
$in = "";
|
||||
for($i = 0; $i < count($types); $i++){
|
||||
$in .= "'".$types[$i]."'";
|
||||
if(($i+1) < count($types)){
|
||||
$in .= ",";
|
||||
}
|
||||
}
|
||||
$query = "SELECT * FROM ".$uh->table_name." WHERE type IN (".$in.")";
|
||||
return $uh->getList($query);
|
||||
}
|
||||
|
||||
function getinstalledPackages($types = array('module', 'langpack')){
|
||||
global $sugar_config;
|
||||
$installeds = $this->getInstalled($types);
|
||||
$packages = array();
|
||||
$upgrades_installed = 0;
|
||||
$uh = new UpgradeHistory();
|
||||
$base_upgrade_dir = $sugar_config['upload_dir'] . "/upgrades";
|
||||
$base_tmp_upgrade_dir = "$base_upgrade_dir/temp";
|
||||
foreach($installeds as $installed)
|
||||
{
|
||||
$populate = false;
|
||||
$filename = from_html($installed->filename);
|
||||
$date_entered = $installed->date_entered;
|
||||
$type = $installed->type;
|
||||
$version = $installed->version;
|
||||
$uninstallable = false;
|
||||
$link = "";
|
||||
$description = $installed->description;
|
||||
$name = $installed->name;
|
||||
$enabled = true;
|
||||
$enabled_string = 'ENABLED';
|
||||
//if the name is empty then we should try to pull from manifest and populate upgrade_history_table
|
||||
if(empty($name)){
|
||||
$populate = true;
|
||||
}
|
||||
$upgrades_installed++;
|
||||
switch($type)
|
||||
{
|
||||
case "theme":
|
||||
case "langpack":
|
||||
case "module":
|
||||
case "patch":
|
||||
if($populate){
|
||||
$manifest_file = $this->extractManifest($filename, $base_tmp_upgrade_dir);
|
||||
require_once($manifest_file);
|
||||
$GLOBALS['log']->info("Filling in upgrade_history table");
|
||||
$populate = false;
|
||||
if( isset( $manifest['name'] ) ){
|
||||
$name = $manifest['name'];
|
||||
$installed->name = $name;
|
||||
}
|
||||
if( isset( $manifest['description'] ) ){
|
||||
$description = $manifest['description'];
|
||||
$installed->description = $description;
|
||||
}
|
||||
if(isset($installdefs) && isset( $installdefs['id'] ) ){
|
||||
$id_name = $installdefs['id'];
|
||||
$installed->id_name = $id_name;
|
||||
}
|
||||
|
||||
$serial_manifest = array();
|
||||
$serial_manifest['manifest'] = (isset($manifest) ? $manifest : '');
|
||||
$serial_manifest['installdefs'] = (isset($installdefs) ? $installdefs : '');
|
||||
$serial_manifest['upgrade_manifest'] = (isset($upgrade_manifest) ? $upgrade_manifest : '');
|
||||
$installed->manifest = base64_encode(serialize($serial_manifest));
|
||||
$installed->save();
|
||||
}else{
|
||||
$serial_manifest = unserialize(base64_decode($installed->manifest));
|
||||
$manifest = $serial_manifest['manifest'];
|
||||
}
|
||||
if(($upgrades_installed==0 || $uh->UninstallAvailable($installeds, $installed))
|
||||
&& is_file($filename) && !empty($manifest['is_uninstallable']))
|
||||
{
|
||||
$uninstallable = true;
|
||||
}
|
||||
$enabled = $installed->enabled;
|
||||
if(!$enabled)
|
||||
$enabled_string = 'DISABLED';
|
||||
$file_uninstall = $filename;
|
||||
if(!$uninstallable){
|
||||
$file_uninstall = 'UNINSTALLABLE';
|
||||
$enabled_string = 'UNINSTALLABLE';
|
||||
}
|
||||
$packages[] = array('name' => $name, 'version' => $version, 'type' => $type, 'published_date' => $date_entered, 'description' => $description, 'uninstallable' =>$uninstallable, 'file_install' => fileToHash($filename), 'file' => fileToHash( $file_uninstall ), 'enabled' => $enabled_string);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}//rof
|
||||
return $packages;
|
||||
}
|
||||
}
|
||||
?>
|
||||
308
ModuleInstall/PackageManager/PackageManagerComm.php
Executable file
308
ModuleInstall/PackageManager/PackageManagerComm.php
Executable file
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
require_once('include/nusoap/nusoap.php');
|
||||
require_once('ModuleInstall/PackageManager/PackageManagerDownloader.php');
|
||||
|
||||
define("HTTPS_URL", "https://depot.sugarcrm.com/depot/SugarDepotSoap.php");
|
||||
define("ACTIVE_STATUS", "ACTIVE");
|
||||
|
||||
class PackageManagerComm{
|
||||
/**
|
||||
* Initialize the soap client and store in the $GLOBALS object for use
|
||||
*
|
||||
* @param login designates whether we want to try to login after we initialize or not
|
||||
*/
|
||||
function initialize($login = true){
|
||||
if(empty($GLOBALS['SugarDepot'])){
|
||||
$GLOBALS['log']->debug('USING HTTPS TO CONNECT TO HEARTBEAT');
|
||||
$soap_client = new nusoapclient(HTTPS_URL, false);
|
||||
$ping = $soap_client->call('sugarPing', array());
|
||||
$GLOBALS['SugarDepot'] = $soap_client;
|
||||
}
|
||||
//if we do not have a session, then try to login
|
||||
if($login && empty($_SESSION['SugarDepotSessionID'])){
|
||||
PackageManagerComm::login();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for errors in the response or error_str
|
||||
*/
|
||||
function errorCheck(){
|
||||
if(!empty($GLOBALS['SugarDepot']->error_str)){
|
||||
$GLOBALS['log']->fatal($GLOBALS['SugarDepot']->error_str);
|
||||
$GLOBALS['log']->fatal($GLOBALS['SugarDepot']->response);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the credentials for use during login
|
||||
*
|
||||
* @param username Mambo username
|
||||
* @param password Mambo password
|
||||
* @param download_key User's download key
|
||||
*/
|
||||
function setCredentials($username, $password, $download_key){
|
||||
$_SESSION['SugarDepotUsername'] = $username;
|
||||
$_SESSION['SugarDepotPassword'] = $password;
|
||||
$_SESSION['SugarDepotDownloadKey'] = $download_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears out the session so we can reauthenticate.
|
||||
*/
|
||||
function clearSession(){
|
||||
$_SESSION['SugarDepotSessionID'] = null;
|
||||
unset($_SESSION['SugarDepotSessionID']);
|
||||
}
|
||||
/////////////////////////////////////////////////////////
|
||||
////////// BEGIN: Base Functions for Communicating with the depot
|
||||
/**
|
||||
* Login to the depot
|
||||
*
|
||||
* @return true if successful, false otherwise
|
||||
*/
|
||||
function login($terms_checked = true){
|
||||
if(empty($_SESSION['SugarDepotSessionID'])){
|
||||
global $license;
|
||||
$GLOBALS['log']->debug("Begin SugarDepot Login");
|
||||
PackageManagerComm::initialize(false);
|
||||
require('sugar_version.php');
|
||||
require('config.php');
|
||||
$credentials = PackageManager::getCredentials();
|
||||
if(empty($license))loadLicense();
|
||||
$info = sugarEncode('2813', serialize(getSystemInfo(true)));
|
||||
$pm = new PackageManager();
|
||||
$installed = $pm->buildInstalledReleases();
|
||||
$installed = base64_encode(serialize($installed));
|
||||
$params = array('installed_modules' => $installed, 'terms_checked' => $terms_checked, 'system_name' => $credentials['system_name']);
|
||||
$terms_version = (!empty($_SESSION['SugarDepot_TermsVersion']) ? $_SESSION['SugarDepot_TermsVersion'] : '');
|
||||
if(!empty($terms_version))
|
||||
$params['terms_version'] = $terms_version;
|
||||
|
||||
$result = $GLOBALS['SugarDepot']->call('depotLogin', array(array('user_name' => $credentials['username'], 'password' => $credentials['password']),'info'=>$info, 'params' => $params));
|
||||
PackageManagerComm::errorCheck();
|
||||
if(!is_array($result))
|
||||
$_SESSION['SugarDepotSessionID'] = $result;
|
||||
$GLOBALS['log']->debug("End SugarDepot Login");
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
return $_SESSION['SugarDepotSessionID'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout from the depot
|
||||
*/
|
||||
function logout(){
|
||||
PackageManagerComm::initialize();
|
||||
$result = $GLOBALS['SugarDepot']->call('depotLogout', array('session_id' => $_SESSION['SugarDepotSessionID']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all promotions from the depot
|
||||
*/
|
||||
function getPromotion(){
|
||||
PackageManagerComm::initialize();
|
||||
//check for fault first and then return
|
||||
$name_value_list = $GLOBALS['SugarDepot']->call('depotGetPromotion', array('session_id' => $_SESSION['SugarDepotSessionID']));
|
||||
return $name_value_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* A generic function which given a category_id some filter will
|
||||
* return an object which contains categories and packages
|
||||
*
|
||||
* @param category_id the category_id to fetch
|
||||
* @param filter a filter which will limit theh number of results returned
|
||||
* @return categories_and_packages
|
||||
* @see categories_and_packages
|
||||
*/
|
||||
function getCategoryPackages($category_id, $filter = array()){
|
||||
PackageManagerComm::initialize();
|
||||
//check for fault
|
||||
return $GLOBALS['SugarDepot']->call('depotGetCategoriesPackages', array('session_id' => $_SESSION['SugarDepotSessionID'], 'category_id' => $category_id, 'filter' => $filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of child categories to the parent specified in category_id
|
||||
*
|
||||
* @param category_id the parent category_id
|
||||
* @param filter a filter which will limit theh number of results returned
|
||||
* @return categories_and_packages
|
||||
* @see categories_and_packages
|
||||
*/
|
||||
function getCategories($category_id, $filter = array()){
|
||||
PackageManagerComm::initialize();
|
||||
//check for fault
|
||||
return $GLOBALS['SugarDepot']->call('depotGetCategories', array('session_id' => $_SESSION['SugarDepotSessionID'], 'category_id' => $category_id, 'filter' => $filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of packages which belong to the parent category_id
|
||||
*
|
||||
* @param category_id the category_id to fetch
|
||||
* @param filter a filter which will limit theh number of results returned
|
||||
* @return packages
|
||||
* @see packages
|
||||
*/
|
||||
function getPackages($category_id, $filter = array()){
|
||||
PackageManagerComm::initialize();
|
||||
//check for fault
|
||||
return $GLOBALS['SugarDepot']->call('depotGetPackages', array('session_id' => $_SESSION['SugarDepotSessionID'], 'category_id' => $category_id, 'filter' => $filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of releases belong to a package
|
||||
*
|
||||
* @param category_id the category_id to fetch
|
||||
* @param package_id the package id which the release belongs to
|
||||
* @return packages
|
||||
* @see packages
|
||||
*/
|
||||
function getReleases($category_id, $package_id, $filter = array()){
|
||||
PackageManagerComm::initialize();
|
||||
//check for fault
|
||||
return $GLOBALS['SugarDepot']->call('depotGetReleases', array('session_id' => $_SESSION['SugarDepotSessionID'], 'category_id' => $category_id, 'package_id' => $package_id, 'filter' => $filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a given release
|
||||
*
|
||||
* @param category_id the category_id to fetch
|
||||
* @param package_id the package id which the release belongs to
|
||||
* @param release_id the release we want to download
|
||||
* @return download
|
||||
* @see download
|
||||
*/
|
||||
function download($category_id, $package_id, $release_id){
|
||||
PackageManagerComm::initialize();
|
||||
//check for fault
|
||||
return $GLOBALS['SugarDepot']->call('depotDownloadRelease', array('session_id' => $_SESSION['SugarDepotSessionID'], 'category_id' => $category_id, 'package_id' => $package_id, 'release_id' => $release_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a requested download to the queue
|
||||
*
|
||||
* @param category_id the category_id to fetch
|
||||
* @param package_id the package id which the release belongs to
|
||||
* @param release_id the release we want to download
|
||||
* @return the filename to download
|
||||
*/
|
||||
function addDownload($category_id, $package_id, $release_id){
|
||||
PackageManagerComm::initialize();
|
||||
//check for fault
|
||||
return $GLOBALS['SugarDepot']->call('depotAddDownload', array('session_id' => $_SESSION['SugarDepotSessionID'], 'category_id' => $category_id, 'package_id' => $package_id, 'release_id' => $release_id, 'download_key' => '123'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the PackageManagerDownloader function which uses curl in order to download the specified file
|
||||
*
|
||||
* @param filename the file to download
|
||||
* @return path to downloaded file
|
||||
*/
|
||||
function performDownload($filename, $save_dir){
|
||||
PackageManagerComm::initialize();
|
||||
//check for fault
|
||||
$GLOBALS['log']->debug("Performing download from depot: Session ID: ".$_SESSION['SugarDepotSessionID']." Filename: ".$filename);
|
||||
return PackageManagerDownloader::download($_SESSION['SugarDepotSessionID'], $filename, $save_dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve documentation for the given release or package
|
||||
*
|
||||
* @param package_id the specified package to retrieve documentation
|
||||
* @param release_id the specified release to retrieve documentation
|
||||
*
|
||||
* @return documents
|
||||
*/
|
||||
function getDocumentation($package_id, $release_id){
|
||||
PackageManagerComm::initialize();
|
||||
//check for fault
|
||||
return $GLOBALS['SugarDepot']->call('depotGetDocumentation', array('session_id' => $_SESSION['SugarDepotSessionID'], 'package_id' => $package_id, 'release_id' => $release_id));
|
||||
}
|
||||
|
||||
function getTermsAndConditions(){
|
||||
PackageManagerComm::initialize(false);
|
||||
return $GLOBALS['SugarDepot']->call('depotTermsAndConditions',array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Log that the user has clicked on a document
|
||||
*
|
||||
* @param document_id the document the user has clicked on
|
||||
*/
|
||||
function downloadedDocumentation($document_id){
|
||||
PackageManagerComm::initialize();
|
||||
//check for fault
|
||||
$GLOBALS['log']->debug("Logging Document: ".$document_id);
|
||||
$GLOBALS['SugarDepot']->call('depotDownloadedDocumentation', array('session_id' => $_SESSION['SugarDepotSessionID'], 'document_id' => $document_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the list of installed objects, could be patches, or modules, .. to the depot and allow the depot to send back
|
||||
* a list of corresponding updates
|
||||
*
|
||||
* @param objects_to_check an array of name_value_lists which contain the appropriate values
|
||||
* which will allow the depot to check for updates
|
||||
*
|
||||
* @return array of name_value_lists of corresponding updates
|
||||
*/
|
||||
function checkForUpdates($objects_to_check){
|
||||
PackageManagerComm::initialize();
|
||||
//check for fault
|
||||
return $GLOBALS['SugarDepot']->call('depotCheckForUpdates', array('session_id' => $_SESSION['SugarDepotSessionID'], 'objects' => $objects_to_check));
|
||||
}
|
||||
/**
|
||||
* Ping the server to determine if we have established proper communication
|
||||
*
|
||||
* @return true if we can communicate with the server and false otherwise
|
||||
*/
|
||||
function isAlive(){
|
||||
PackageManagerComm::initialize(false);
|
||||
|
||||
$status = $GLOBALS['SugarDepot']->call('sugarPing', array());
|
||||
if(empty($status) || $GLOBALS['SugarDepot']->getError() || $status != ACTIVE_STATUS){
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
////////// END: Base Functions for Communicating with the depot
|
||||
////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
?>
|
||||
607
ModuleInstall/PackageManager/PackageManagerDisplay.php
Executable file
607
ModuleInstall/PackageManager/PackageManagerDisplay.php
Executable file
@@ -0,0 +1,607 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
require_once('ModuleInstall/PackageManager/PackageManager.php');
|
||||
|
||||
require_once('include/ytree/Tree.php');
|
||||
require_once('include/ytree/Node.php');
|
||||
require_once('ModuleInstall/PackageManager/ListViewPackages.php');
|
||||
|
||||
class PackageManagerDisplay{
|
||||
|
||||
/**
|
||||
* A Static method to Build the display for the package manager
|
||||
*
|
||||
* @param String form1 - the form to display for manual downloading
|
||||
* @param String hidden_fields - the hidden fields related to downloading a package
|
||||
* @param String form_action - the form_action to be used when downloading from the server
|
||||
* @param String types - the types of objects we will request from the server
|
||||
* @param String active_form - the form to display first
|
||||
* @return String - a string of html which will be used to display the forms
|
||||
*/
|
||||
function buildPackageDisplay($form1, $hidden_fields, $form_action, $types = array('module'), $active_form = 'form1', $install = false){
|
||||
global $current_language;
|
||||
|
||||
$mod_strings = return_module_language($current_language, "Administration");
|
||||
global $app_strings;
|
||||
global $sugar_version, $sugar_config;
|
||||
$app_strings = return_application_language($current_language);
|
||||
$ss = new Sugar_Smarty();
|
||||
$ss->assign('FORM_1_PLACE_HOLDER', $form1);
|
||||
$ss->assign('form_action', $form_action);
|
||||
$ss->assign('hidden_fields', $hidden_fields);
|
||||
|
||||
$result = PackageManagerDisplay::getHeader();
|
||||
$header_text = $result['text'];
|
||||
$isAlive = $result['isAlive'];
|
||||
$show_login = $result['show_login'];
|
||||
$mi_errors = ModuleInstaller::getErrors();
|
||||
$error_html = "";
|
||||
if(!empty($mi_errors)){
|
||||
$error_html = "<tr><td><span>";
|
||||
foreach($mi_errors as $error){
|
||||
$error_html .= "<font color='red'>".$error."</font><br>";
|
||||
}
|
||||
$error_html .= "</span></td></tr>";
|
||||
}
|
||||
|
||||
$form2 = "<table class='tabForm' width='100%' cellpadding='0' cellspacing='0' width='100%' border='0'>";
|
||||
$form2 .= $error_html;
|
||||
if(!$isAlive)
|
||||
$form2 .= "<tr><td><span id='span_display_html'>".$header_text."</span></td></tr>";
|
||||
$form2 .= "</table>";
|
||||
|
||||
$tree = null;
|
||||
//if($isAlive){
|
||||
$tree = PackageManagerDisplay::buildTreeView('treeview', $isAlive);
|
||||
$tree->tree_style= 'include/ytree/TreeView/css/check/tree.css';
|
||||
$ss->assign('TREEHEADER',$tree->generate_header());
|
||||
//}
|
||||
//$form2 .= PackageManagerDisplay::buildLoginPanel($mod_strings);
|
||||
$form2 .= "<table class='tabForm' cellpadding='0' cellspacing='0' width='100%' border='0'>";
|
||||
$form2 .= "<tr><td></td><td align='left'>";
|
||||
if($isAlive){
|
||||
$form2 .= "<input type='button' id='modifCredentialsBtn' class='button' onClick='PackageManager.showLoginDialog(true);' value='".$mod_strings['LBL_MODIFY_CREDENTIALS']."'>";
|
||||
}else{
|
||||
$form2 .= "<input type='button' id='modifCredentialsBtn' class='button' onClick='PackageManager.showLoginDialog(true);' value='".$mod_strings['LBL_MODIFY_CREDENTIALS']."'style='display:none;'>";
|
||||
}
|
||||
$form2 .= "</td><td align='left'><div id='workingStatusDiv' style='display:none;'>".SugarThemeRegistry::current()->getImage("sqsWait","border='0' align='bottom'")."</div></td><td align='right'>";
|
||||
if($isAlive){
|
||||
$form2 .= "<slot><a class=\"listViewTdToolsS1\" id='href_animate' onClick=\"PackageManager.toggleDiv('span_animate_server_div', 'catview');\"><span id='span_animate_server_div'><img src='".SugarThemeRegistry::current()->getImageURL('basic_search.gif')."' width='8' height='8' border='0'> Collapse</span></a></slot>";
|
||||
}else{
|
||||
$form2 .= "<slot><a class=\"listViewTdToolsS1\" id='href_animate' onClick=\"PackageManager.toggleDiv('span_animate_server_div', 'catview');\"><span id='span_animate_server_div' style='display:none;'><img src='".SugarThemeRegistry::current()->getImageURL('basic_search.gif')."' width='8' height='8' border='0'> Collapse</span></a></slot>";
|
||||
}
|
||||
$form2 .= "</td></tr></table>";
|
||||
$form2 = ''; //Commenting out the form as part of sugar depot hiding.
|
||||
$ss->assign('installation', ($install ? 'true' : 'false'));
|
||||
|
||||
|
||||
$mod_strings = return_module_language($current_language, "Administration");
|
||||
|
||||
$ss->assign('MOD', $mod_strings);
|
||||
$ss->assign('module_load', 'true');
|
||||
$ss->assign('scripts', PackageManagerDisplay::getDisplayScript($install));
|
||||
$show_login = false; //hiding install from sugar
|
||||
$ss->assign('MODULE_SELECTOR', PackageManagerDisplay::buildGridOutput($tree, $mod_strings, $isAlive, $show_login));
|
||||
$ss->assign('FORM_2_PLACE_HOLDER', $form2);
|
||||
$ss->assign('MOD', $mod_strings);
|
||||
$descItemsInstalled = $mod_strings['LBL_UW_DESC_MODULES_INSTALLED'];
|
||||
$ss->assign('INSTALLED_PACKAGES_HOLDER', PackageManagerDisplay::buildInstalledGrid($mod_strings, $types));
|
||||
|
||||
$str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageForm.tpl');
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Static method to Build the display for the package manager
|
||||
*
|
||||
* @param String form1 - the form to display for manual downloading
|
||||
* @param String hidden_fields - the hidden fields related to downloading a package
|
||||
* @param String form_action - the form_action to be used when downloading from the server
|
||||
* @param String types - the types of objects we will request from the server
|
||||
* @param String active_form - the form to display first
|
||||
* @return String - a string of html which will be used to display the forms
|
||||
*/
|
||||
function buildPatchDisplay($form1, $hidden_fields, $form_action, $types = array('module'), $active_form = 'form1'){
|
||||
global $current_language;
|
||||
$mod_strings = return_module_language($current_language, "Administration");
|
||||
$ss = new Sugar_Smarty();
|
||||
$ss->assign('FORM_1_PLACE_HOLDER', $form1);
|
||||
$ss->assign('form_action', $form_action);
|
||||
$ss->assign('hidden_fields', $hidden_fields);
|
||||
$mod_strings = return_module_language($current_language, "Administration");
|
||||
|
||||
$ss->assign('MOD', $mod_strings);
|
||||
$result = PackageManagerDisplay::getHeader();
|
||||
$header_text = $result['text'];
|
||||
$isAlive = $result['isAlive'];
|
||||
$show_login = $result['show_login'];
|
||||
$display = 'none';
|
||||
//if($isAlive){
|
||||
$display = 'block';
|
||||
//}
|
||||
$form2 = "<table class='tabForm' width='100%' cellpadding='0' cellspacing='0' width='100%' border='0'>";
|
||||
if(!$isAlive)
|
||||
$form2 .= "<tr><td><span id='span_display_html'>".$header_text."</span></td></tr>";
|
||||
$form2 .= "</table>";
|
||||
$form2 .= "<table width='100%'><tr><td align='left'>";
|
||||
if($show_login){
|
||||
$form2 .= "<input type='button' class='button' onClick='PackageManager.showLoginDialog(true);' value='".$mod_strings['LBL_MODIFY_CREDENTIALS']."'>";
|
||||
}
|
||||
$form2 .= "</td><td align='right'><div id='workingStatusDiv' style='display:none;'>".SugarThemeRegistry::current()->getImage("sqsWait","border='0' align='bottom'")."</div></td></tr><tr><td colspan='2'>";
|
||||
$loginViewStyle = ($isAlive ? 'none' : 'block');
|
||||
$selectViewStyle = ($isAlive ? 'block' : 'none');
|
||||
$form2 .= "<div id='selectView' style='display:".$selectViewStyle."'>";
|
||||
$form2 .= " <div id='patch_downloads' class='ygrid-mso' style='height:205px; display: ".$display.";'></div>";
|
||||
$form2 .= "</div>";
|
||||
if(!$show_login)
|
||||
$loginViewStyle = 'none';
|
||||
//$form2 .= "<div id='loginView' style='display:".$loginViewStyle."'>";
|
||||
//$form2 .= PackageManagerDisplay::buildLoginPanel($mod_strings, $isAlive);
|
||||
//$form2 .= "</div>";
|
||||
|
||||
$form2 .= "</td></tr></table>";
|
||||
$form2 = '';
|
||||
$packages = array();
|
||||
$releases = array();
|
||||
if($isAlive){
|
||||
$filter = array();
|
||||
$count = count($types);
|
||||
$index = 1;
|
||||
$type_str = '"';
|
||||
foreach($types as $type){
|
||||
$type_str .= "'".$type."'";
|
||||
if($index < $count)
|
||||
$type_str .= ",";
|
||||
$index++;
|
||||
}
|
||||
$type_str .= '"';
|
||||
$filter = array('type' => $type_str);
|
||||
$filter = PackageManager::toNameValueList($filter);
|
||||
$pm = new PackageManager();
|
||||
/*if(in_array('patch', $types)){
|
||||
$releases = $pm->getReleases('3', '3', $filter);
|
||||
}else{
|
||||
$releases = $pm->getReleases('', '', $filter);
|
||||
}*/
|
||||
}
|
||||
if($form_action == 'install.php' && (empty($releases) || count($releases['packages']) == 0)){
|
||||
//return false;
|
||||
}
|
||||
$tree = PackageManagerDisplay::buildTreeView('treeview', $isAlive);
|
||||
$tree->tree_style= 'include/ytree/TreeView/css/check/tree.css';
|
||||
$ss->assign('TREEHEADER',$tree->generate_header());
|
||||
$ss->assign('module_load', 'false');
|
||||
$ss->assign('MODULE_SELECTOR', PackageManagerDisplay::buildGridOutput($tree, $mod_strings, $isAlive, $show_login));
|
||||
$ss->assign('FORM_2_PLACE_HOLDER', $form2);
|
||||
$ss->assign('scripts', PackageManagerDisplay::getDisplayScript(false, 'patch', $releases, $types, $isAlive));
|
||||
$str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageForm.tpl');
|
||||
return $str;
|
||||
}
|
||||
|
||||
function buildInstalledGrid($mod_strings, $types = array('modules')){
|
||||
$descItemsInstalled = $mod_strings['LBL_UW_DESC_MODULES_INSTALLED'];
|
||||
$output = '<table width="100%" border="0" cellspacing="0" cellpadding="0" ><tr><td align="left">'.$descItemsInstalled.'</td>';
|
||||
$output .= '</td></tr></table>';
|
||||
$output .= "<table width='100%'><tr><td ><div id='installed_grid' class='ygrid-mso' style='height:205px;'></div></td></tr></table>";
|
||||
return $output;
|
||||
}
|
||||
|
||||
function buildLoginPanel($mod_strings, $display_cancel){
|
||||
$credentials = PackageManager::getCredentials();
|
||||
$output = "<div id='login_panel'><div class='hd'><b>".$mod_strings['HDR_LOGIN_PANEL']."</b></div>";
|
||||
$output .= "<div class='bd'><form><table><tr><td>".$mod_strings['LBL_USERNAME']."</td><td><input type='text' name='login_panel_username' id='login_panel_username' value='".$credentials['username']."'></td><td><a href='http://www.sugarcrm.com/crm/index.php?option=com_registration&task=register' target='blank'>".$mod_strings['LNK_NEW_ACCOUNT']."</a></td>";
|
||||
|
||||
$output .= "</tr><tr><td>".$mod_strings['LBL_PASSWORD']."</td><td><input type='password' name='login_panel_password' id='login_panel_password'></td><td><a href='http://www.sugarcrm.com/crm/component/option,com_registration/Itemid,0/task,lostPassword/' target='blank'>".$mod_strings['LNK_FORGOT_PASS']."</a></td>";
|
||||
|
||||
$terms = PackageManager::getTermsAndConditions();
|
||||
$output .= "</tr><tr><td colspan='6' valign='top'><b>".$mod_strings['LBL_TERMS_AND_CONDITIONS']."</b><br><textarea readonly cols=80 rows=8>" . $terms['terms'] . '</textarea></td>';
|
||||
$_SESSION['SugarDepot_TermsVersion'] = (!empty($terms['version']) ? $terms['version'] : '');
|
||||
|
||||
$output .= "</td></tr><tr><td colspan='6'><input class='checkbox' type='checkbox' name='cb_terms' id='cb_terms' onclick='if(this.checked){this.form.panel_login_button.disabled=false;}else{this.form.panel_login_button.disabled=true;}'>".$mod_strings['LBL_ACCEPT_TERMS']."</td></tr><tr>";
|
||||
$output .= "<td align='left'>";
|
||||
$output .= "<input type='button' id='panel_login_button' name='panel_login_button' value='Login' class='button' onClick='PackageManager.authenticate(this.form.login_panel_username.value, this.form.login_panel_password.value, \"\",\"" . $terms['version'] . "\");' disabled>";
|
||||
|
||||
if($display_cancel){
|
||||
$output .= " <input type='button' id='panel_cancel_button' value='Cancel' class='button' onClick='PackageManager.showLoginDialog(false);'>";
|
||||
}
|
||||
$output .= "</td><td></td></tr>";
|
||||
$output .= "<tr></td><td></td></tr>";
|
||||
$output .= "</table></div>";
|
||||
$output .= "<div class='ft'></div></form></div>";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build html in order to display the grids relevant for module loader
|
||||
*
|
||||
* @param Tree tree - the tree which we are using to display the categories
|
||||
* @param Array mod_strings - the local mod strings to display
|
||||
* @return String - a string of html
|
||||
*/
|
||||
function buildGridOutput($tree, $mod_strings, $display = true, $show_login = true){
|
||||
$output = "<div id='catview'>";
|
||||
$loginViewStyle = ($display ? 'none' : 'block');
|
||||
$selectViewStyle = ($display ? 'block' : 'none');
|
||||
$output .= "<div id='selectView' style='display:".$selectViewStyle."'>";
|
||||
//if($display){
|
||||
$output .= "<table border=0 width='100%' class='moduleTitle'><tr><td width='100%' valign='top'>";
|
||||
$output .= "<div id='treeview'>";
|
||||
$output .= $tree->generate_nodes_array();
|
||||
$output .= "</div>";
|
||||
$output .= "</td></tr>";
|
||||
$output .= "<tr><td width='100%'>";
|
||||
$output .= "<div id='tabs1'></div>";
|
||||
$output .= "</td></tr>";
|
||||
$output .= "<tr><td width='100%' align='left'>";
|
||||
$output .= "<input type='button' class='button' value='Download Selected' onClick='PackageManager.download();'>";
|
||||
$output .= "</td></tr></table>";
|
||||
// }
|
||||
$output .= "</div>";
|
||||
if(!$show_login)
|
||||
$loginViewStyle = 'none';
|
||||
// $output .= "<div id='loginView' style='display:".$loginViewStyle."'>";
|
||||
// jchi ,#24296 :commented code because we are currently not using depot, in the future this may change so you can put this code back in.
|
||||
//$output .= PackageManagerDisplay::buildLoginPanel($mod_strings, $display);
|
||||
//$output .= "</div>";
|
||||
//$output .= "<table width='100%' class='moduleTitle' border=1><tr><td><div id='patch_downloads' class='ygrid-mso' style='height:205px;'></div></td></tr></table>";
|
||||
$output .= "</div>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Static method used to build the initial treeview when the page is first displayed
|
||||
*
|
||||
* @param String div_id - this div in which to display the tree
|
||||
* @return Tree - the tree that is built
|
||||
*/
|
||||
function buildTreeView($div_id, $isAlive = true){
|
||||
$tree = new Tree($div_id);
|
||||
$nodes = array();
|
||||
if($isAlive)
|
||||
$nodes = PackageManager::getCategories('');
|
||||
|
||||
foreach($nodes as $arr_node){
|
||||
$node = new Node($arr_node['id'], $arr_node['label']);
|
||||
$node->dynamicloadfunction = 'PackageManager.loadDataForNodeForPackage';
|
||||
$node->expanded = false;
|
||||
$node->dynamic_load = true;
|
||||
$node->set_property('href',"javascript:PackageManager.catClick('treeview');");
|
||||
$tree->add_node($node);
|
||||
$node->set_property('description', $arr_node['description']);
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Static method used to obtain the div for the license
|
||||
*
|
||||
* @param String license_file - the path to the license file
|
||||
* @param String form_action - the form action when accepting the license file
|
||||
* @param String next_step - the value for the next step in the installation process
|
||||
* @param String zipFile - a string representing the path to the zip file
|
||||
* @param String type - module/patch....
|
||||
* @param String manifest - the path to the manifest file
|
||||
* @param String modify_field - the field to update when the radio button is changed
|
||||
* @return String - a form used to display the license
|
||||
*/
|
||||
function getLicenseDisplay($license_file, $form_action, $next_step, $zipFile, $type, $manifest, $modify_field){
|
||||
global $current_language;
|
||||
$mod_strings = return_module_language($current_language, "Administration");
|
||||
$fh = sugar_fopen($license_file, 'r');
|
||||
$contents = fread($fh, filesize($license_file));
|
||||
fclose($fh);
|
||||
$div_id = urlencode($zipFile);
|
||||
$display = "<form name='delete{$zipFile}' action='{$form_action}' method='POST'>";
|
||||
$display .= "<input type='hidden' name='current_step' value='{$next_step}'>";
|
||||
$display .= "<input type='hidden' name='languagePackAction' value='{$type}'>";
|
||||
$display .= "<input type='hidden' name='manifest' value='\".urlencode($manifest).\"'>";
|
||||
$display .= "<input type='hidden' name='zipFile' value='\".urlencode($zipFile).\"'>";
|
||||
$display .= "<table><tr>";
|
||||
$display .= "<td align=\"left\" valign=\"top\" colspan=2>";
|
||||
$display .= "<b><font color='red' >{$mod_strings['LBL_MODULE_LICENSE']}</font></b>";
|
||||
$display .= "</td>";
|
||||
$display .= "<td>";
|
||||
$display .= "<slot><a class=\"listViewTdToolsS1\" id='href_animate' onClick=\"PackageManager.toggleLowerDiv('span_animate_div_$div_id', 'span_license_div_$div_id', 350, 0);\"><span id='span_animate_div_$div_id'<img src='".SugarThemeRegistry::current()->getImageURL('advanced_search.gif')."' width='8' height='8' alt='Advanced' border='0'> Expand</span></a></slot></td>";
|
||||
$display .= "</td>";
|
||||
$display .= "</tr>";
|
||||
$display .= "</table>";
|
||||
$display .= "<div id='span_license_div_$div_id' style=\"display: none;\">";
|
||||
$display .= "<table>";
|
||||
$display .= "<tr>";
|
||||
$display .= "<td align=\"left\" valign=\"top\" colspan=2>";
|
||||
$display .= "<textarea cols=\"100\" rows=\"8\">{$contents}</textarea>";
|
||||
$display .= "</td>";
|
||||
$display .= "</tr>";
|
||||
$display .= "<tr>";
|
||||
$display .= "<td align=\"left\" valign=\"top\" colspan=2>";
|
||||
$display .= "<input type='radio' id='radio_license_agreement_accept' name='radio_license_agreement' value='accept' onClick=\"document.getElementById('$modify_field').value = 'yes';\">{$mod_strings['LBL_ACCEPT']} ";
|
||||
$display .= "<input type='radio' id='radio_license_agreement_reject' name='radio_license_agreement' value='reject' checked onClick=\"document.getElementById('$modify_field').value = 'no';\">{$mod_strings['LBL_DENY']}";
|
||||
$display .= "</td>";
|
||||
$display .= "</tr>";
|
||||
$display .= "</table>";
|
||||
$display .= "</div>";
|
||||
$display .= "</form>";
|
||||
return $display;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Static method used to generate the javascript for the page
|
||||
*
|
||||
* @return String - the javascript required for the page
|
||||
*/
|
||||
function getDisplayScript($install = false, $type = 'module', $releases = null, $types = array(), $isAlive = true){
|
||||
global $sugar_version, $sugar_config;
|
||||
global $current_language;
|
||||
|
||||
$mod_strings = return_module_language($current_language, "Administration");
|
||||
$ss = new Sugar_Smarty();
|
||||
$ss->assign('MOD', $mod_strings);
|
||||
if(!$install){
|
||||
$install = 0;
|
||||
}
|
||||
$ss->assign('INSTALLATION', $install);
|
||||
$ss->assign('WAIT_IMAGE', SugarThemeRegistry::current()->getImage("loading","border='0' align='bottom'"));
|
||||
$ss->assign('sugar_version', $sugar_version);
|
||||
$ss->assign('js_custom_version', $sugar_config['js_custom_version']);
|
||||
$ss->assign('IS_ALIVE', $isAlive);
|
||||
//if($type == 'patch' && $releases != null){
|
||||
if($type == 'patch'){
|
||||
$ss->assign('module_load', 'false');
|
||||
$patches = PackageManagerDisplay::createJavascriptPackageArray($releases);
|
||||
$ss->assign('PATCHES', $patches);
|
||||
$ss->assign('GRID_TYPE', implode(',', $types));
|
||||
}else{
|
||||
$pm = new PackageManager();
|
||||
$releases = $pm->getPackagesInStaging();
|
||||
$patches = PackageManagerDisplay::createJavascriptModuleArray($releases);
|
||||
$ss->assign('PATCHES', $patches);
|
||||
$installeds = $pm->getinstalledPackages();
|
||||
$patches = PackageManagerDisplay::createJavascriptModuleArray($installeds, 'mti_installed_data');
|
||||
$ss->assign('INSTALLED_MODULES', $patches);
|
||||
$ss->assign('UPGARDE_WIZARD_URL', 'index.php?module=UpgradeWizard&action=index');
|
||||
$ss->assign('module_load', 'true');
|
||||
}
|
||||
if(!empty($GLOBALS['ML_STATUS_MESSAGE']))
|
||||
$ss->assign('ML_STATUS_MESSAGE',$GLOBALS['ML_STATUS_MESSAGE']);
|
||||
|
||||
//Bug 24064. Checking and Defining labels since these might not be cached during Upgrade
|
||||
if(!isset($mod_strings['LBL_ML_INSTALL']) || empty($mod_strings['LBL_ML_INSTALL'])){
|
||||
$mod_strings['LBL_ML_INSTALL'] = 'Install';
|
||||
}
|
||||
if(!isset($mod_strings['LBL_ML_ENABLE_OR_DISABLE']) || empty($mod_strings['LBL_ML_ENABLE_OR_DISABLE'])) {
|
||||
$mod_strings['LBL_ML_ENABLE_OR_DISABLE'] = 'Enable/Disable';
|
||||
}
|
||||
if(!isset($mod_strings['LBL_ML_DELETE'])|| empty($mod_strings['LBL_ML_DELETE'])){
|
||||
$mod_strings['LBL_ML_DELETE'] = 'Delete';
|
||||
}
|
||||
//Add by jchi 6/23/2008 to fix the bug 21667
|
||||
$filegrid_column_ary = array(
|
||||
'Name' => $mod_strings['LBL_ML_NAME'],
|
||||
'Install' => $mod_strings['LBL_ML_INSTALL'],
|
||||
'Delete' => $mod_strings['LBL_ML_DELETE'],
|
||||
'Type' => $mod_strings['LBL_ML_TYPE'],
|
||||
'Version' => $mod_strings['LBL_ML_VERSION'],
|
||||
'Published' => $mod_strings['LBL_ML_PUBLISHED'],
|
||||
'Uninstallable' => $mod_strings['LBL_ML_UNINSTALLABLE'],
|
||||
'Description' => $mod_strings['LBL_ML_DESCRIPTION']
|
||||
);
|
||||
|
||||
$filegridinstalled_column_ary = array(
|
||||
'Name' => $mod_strings['LBL_ML_NAME'],
|
||||
'Install' => $mod_strings['LBL_ML_INSTALL'],
|
||||
'Action' => $mod_strings['LBL_ML_ACTION'],
|
||||
'Enable_Or_Disable' => $mod_strings['LBL_ML_ENABLE_OR_DISABLE'],
|
||||
'Type' => $mod_strings['LBL_ML_TYPE'],
|
||||
'Version' => $mod_strings['LBL_ML_VERSION'],
|
||||
'Date_Installed' => $mod_strings['LBL_ML_INSTALLED'],
|
||||
'Uninstallable' => $mod_strings['LBL_ML_UNINSTALLABLE'],
|
||||
'Description' => $mod_strings['LBL_ML_DESCRIPTION']
|
||||
);
|
||||
|
||||
$ss->assign('ML_FILEGRID_COLUMN',$filegrid_column_ary);
|
||||
$ss->assign('ML_FILEGRIDINSTALLED_COLUMN',$filegridinstalled_column_ary);
|
||||
//end
|
||||
|
||||
$str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageManagerScripts.tpl');
|
||||
return $str;
|
||||
}
|
||||
|
||||
function createJavascriptPackageArray($releases){
|
||||
$output = "var mti_data = [";
|
||||
$count = count($releases);
|
||||
$index = 1;
|
||||
if(!empty($releases['packages'])){
|
||||
foreach($releases['packages'] as $release){
|
||||
$release = PackageManager::fromNameValueList($release);
|
||||
$output .= "[";
|
||||
$output .= "'".$release['description']."', '".$release['version']."', '".$release['build_number']."', '".$release['id']."'";
|
||||
$output .= "]";
|
||||
if($index < $count)
|
||||
$output .= ",";
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
$output .= "]\n;";
|
||||
return $output;
|
||||
}
|
||||
|
||||
function createJavascriptModuleArray($modules, $variable_name = 'mti_data'){
|
||||
$output = "var ".$variable_name." = [";
|
||||
$count = count($modules);
|
||||
$index = 1;
|
||||
if(!empty($modules)){
|
||||
foreach($modules as $module){
|
||||
$output .= "[";
|
||||
$output .= "'".$module['name']."', '".$module['file_install']."', '".$module['file']."', '";
|
||||
if(!empty($module['enabled']))
|
||||
$output .= $module['enabled'].'_'.$module['file']."', '";
|
||||
|
||||
$description = js_escape($module['description']);
|
||||
$output .= $module['type']."', '".$module['version']."', '".$module['published_date']."', '".$module['uninstallable']."', '".$description."'".(isset($module['upload_file'])?" , '".$module['upload_file']."']":"]");
|
||||
if($index < $count)
|
||||
$output .= ",";
|
||||
$index++;
|
||||
}
|
||||
|
||||
}
|
||||
$output .= "]\n;";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is meant to be used to display the license agreement inline on the page
|
||||
* if the system would like to perform the installation on the same page via an Ajax call
|
||||
*/
|
||||
function buildLicenseOutput($file){
|
||||
global $current_language;
|
||||
|
||||
$mod_strings = return_module_language($current_language, "Administration");
|
||||
$contents = '';
|
||||
$pm = new PackageManager();
|
||||
$contents = $pm->getLicenseFromFile($file);
|
||||
$ss = new Sugar_Smarty();
|
||||
$ss->assign('MOD', $mod_strings);
|
||||
$ss->assign('LICENSE_CONTENTS', $contents);
|
||||
$ss->assign('FILE', $file);
|
||||
$str = $ss->fetch('ModuleInstall/PackageManagerLicense.tpl');
|
||||
$GLOBALS['log']->debug('LICENSE OUTPUT: '.$str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
function getHeader(){
|
||||
global $current_language;
|
||||
|
||||
$mod_strings = return_module_language($current_language, "Administration");
|
||||
$header_text = '';
|
||||
$isAlive = false;
|
||||
$show_login = false;
|
||||
if(!function_exists('curl_init') && $show_login){
|
||||
$header_text = "<font color='red'><b>".$mod_strings['ERR_ENABLE_CURL']."</b></font>";
|
||||
$show_login = false;
|
||||
}else{
|
||||
$credentials = PackageManager::getCredentials();
|
||||
if(empty($credentials['username']) || empty($credentials['password'])){
|
||||
//$header_text = "<font color='red'><b>".$mod_strings['ERR_CREDENTIALS_MISSING']."</b></font>";
|
||||
}
|
||||
else{
|
||||
$result = PackageManagerComm::login();
|
||||
if((is_array($result) && !empty($result['faultcode'])) || $result == false){
|
||||
$header_text = "<font color='red'><b>".$result['faultstring']."</b></font>";
|
||||
}else{
|
||||
$header_text = PackageManager::getPromotion();
|
||||
$isAlive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array('text' => $header_text, 'isAlive' => $isAlive, 'show_login' => $show_login);
|
||||
}
|
||||
|
||||
function buildInstallGrid($view){
|
||||
$uh = new UpgradeHistory();
|
||||
$installeds = $uh->getAll();
|
||||
$upgrades_installed = 0;
|
||||
$installed_objects = array();
|
||||
foreach($installeds as $installed)
|
||||
{
|
||||
$filename = from_html($installed->filename);
|
||||
$date_entered = $installed->date_entered;
|
||||
$type = $installed->type;
|
||||
$version = $installed->version;
|
||||
$upgrades_installed++;
|
||||
$link = "";
|
||||
|
||||
switch($type)
|
||||
{
|
||||
case "theme":
|
||||
case "langpack":
|
||||
case "module":
|
||||
case "patch":
|
||||
$manifest_file = extractManifest($filename);
|
||||
require_once($manifest_file);
|
||||
|
||||
$name = empty($manifest['name']) ? $filename : $manifest['name'];
|
||||
$description = empty($manifest['description']) ? $mod_strings['LBL_UW_NONE'] : $manifest['description'];
|
||||
if(($upgrades_installed==0 || $uh->UninstallAvailable($installeds, $installed))
|
||||
&& is_file($filename) && !empty($manifest['is_uninstallable']))
|
||||
{
|
||||
$link = urlencode( $filename );
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = 'false';
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if($view == 'default' && $type != 'patch')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if($view == 'module'
|
||||
&& $type != 'module' && $type != 'theme' && $type != 'langpack')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$target_manifest = remove_file_extension( $filename ) . "-manifest.php";
|
||||
require_once( "$target_manifest" );
|
||||
|
||||
if(isset($manifest['icon']) && $manifest['icon'] != "")
|
||||
{
|
||||
$manifest_copy_files_to_dir = isset($manifest['copy_files']['to_dir']) ? clean_path($manifest['copy_files']['to_dir']) : "";
|
||||
$manifest_copy_files_from_dir = isset($manifest['copy_files']['from_dir']) ? clean_path($manifest['copy_files']['from_dir']) : "";
|
||||
$manifest_icon = clean_path($manifest['icon']);
|
||||
$icon = "<img src=\"" . $manifest_copy_files_to_dir . ($manifest_copy_files_from_dir != "" ? substr($manifest_icon, strlen($manifest_copy_files_from_dir)+1) : $manifest_icon ) . "\">";
|
||||
}
|
||||
else
|
||||
{
|
||||
$icon = getImageForType( $manifest['type'] );
|
||||
}
|
||||
$installed_objects[] = array('icon' => $icon, 'name' => $name, 'type' => $type, 'version' => $version, 'date_entered' => $date_entered, 'description' => $description, 'file' => $link);
|
||||
//print( "<form action=\"" . $form_action . "_prepare\" method=\"post\">\n" );
|
||||
//print( "<tr><td>$icon</td><td>$name</td><td>$type</td><td>$version</td><td>$date_entered</td><td>$description</td><td>$link</td></tr>\n" );
|
||||
//print( "</form>\n" );
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
71
ModuleInstall/PackageManager/PackageManagerDownloader.php
Executable file
71
ModuleInstall/PackageManager/PackageManagerDownloader.php
Executable file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
define('PACKAGE_MANAGER_DOWNLOAD_SERVER', 'https://depot.sugarcrm.com/depot/');
|
||||
define('PACKAGE_MANAGER_DOWNLOAD_PAGE', 'download.php');
|
||||
define('PACKAGE_MANAGER_DOWNLOAD_PATH', '../'.$GLOBALS['sugar_config']['upload_dir']);
|
||||
class PackageManagerDownloader{
|
||||
|
||||
/**
|
||||
* Using curl we will download the file from the depot server
|
||||
*
|
||||
* @param session_id the session_id this file is queued for
|
||||
* @param file_name the file_name to download
|
||||
* @param save_dir (optional) if specified it will direct where to save the file once downloaded
|
||||
* @param download_sever (optional) if specified it will direct the url for the download
|
||||
*
|
||||
* @return the full path of the saved file
|
||||
*/
|
||||
function download($session_id, $file_name, $save_dir = '', $download_server = ''){
|
||||
if(empty($save_dir)){
|
||||
$save_dir = PACKAGE_MANAGER_DOWNLOAD_PATH;
|
||||
}
|
||||
if(empty($download_server)){
|
||||
$download_server = PACKAGE_MANAGER_DOWNLOAD_SERVER;
|
||||
}
|
||||
$download_server .= PACKAGE_MANAGER_DOWNLOAD_PAGE;
|
||||
$ch = curl_init($download_server . '?filename='. $file_name);
|
||||
$fp = sugar_fopen($save_dir . $file_name, 'w');
|
||||
curl_setopt($ch, CURLOPT_COOKIE, 'PHPSESSID='.$session_id. ';');
|
||||
curl_setopt($ch, CURLOPT_FILE, $fp);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_exec($ch);
|
||||
curl_close($ch);
|
||||
fclose($fp);
|
||||
return $save_dir . $file_name;
|
||||
}
|
||||
}
|
||||
?>
|
||||
63
ModuleInstall/PackageManager/metadata/listviewdefs.php
Executable file
63
ModuleInstall/PackageManager/metadata/listviewdefs.php
Executable file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
$listViewDefs['module_loader']['packages'] = array(
|
||||
'name' => array(
|
||||
'width' => '5',
|
||||
'label' => 'LBL_LIST_NAME',
|
||||
'link' => false,
|
||||
'default' => true,
|
||||
'show' => true),
|
||||
'description' => array(
|
||||
'width' => '32',
|
||||
'label' => 'LBL_ML_DESCRIPTION',
|
||||
'default' => true,
|
||||
'link' => false,
|
||||
'show' => true),
|
||||
);
|
||||
|
||||
$listViewDefs['module_loader']['releases'] = array(
|
||||
'description' => array(
|
||||
'width' => '32',
|
||||
'label' => 'LBL_LIST_SUBJECT',
|
||||
'default' => true,
|
||||
'link' => false),
|
||||
'version' => array(
|
||||
'width' => '32',
|
||||
'label' => 'LBL_LIST_SUBJECT',
|
||||
'default' => true,
|
||||
'link' => false),
|
||||
);
|
||||
?>
|
||||
193
PDFMerger.php
Executable file
193
PDFMerger.php
Executable file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
/**
|
||||
* PDFMerger created by Jarrod Nettles December 2009
|
||||
* jarrod@squarecrow.com
|
||||
*
|
||||
* v1.0
|
||||
*
|
||||
* Class for easily merging PDFs (or specific pages of PDFs) together into one. Output to a file, browser, download, or return as a string.
|
||||
* Unfortunately, this class does not preserve many of the enhancements your original PDF might contain. It treats
|
||||
* your PDF page as an image and then concatenates them all together.
|
||||
*
|
||||
* Note that your PDFs are merged in the order that you provide them using the addPDF function, same as the pages.
|
||||
* If you put pages 12-14 before 1-5 then 12-15 will be placed first in the output.
|
||||
*
|
||||
*
|
||||
* Uses FPDI 1.3.1 from Setasign
|
||||
* Uses FPDF 1.6 by Olivier Plathey with FPDF_TPL extension 1.1.3 by Setasign
|
||||
*
|
||||
* Both of these packages are free and open source software, bundled with this class for ease of use.
|
||||
* They are not modified in any way. PDFMerger has all the limitations of the FPDI package - essentially, it cannot import dynamic content
|
||||
* such as form fields, links or page annotations (anything not a part of the page content stream).
|
||||
*
|
||||
*/
|
||||
class PDFMerger
|
||||
{
|
||||
private $_files; //['form.pdf'] ["1,2,4, 5-19"]
|
||||
private $_fpdi;
|
||||
|
||||
/**
|
||||
* Merge PDFs.
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
require_once('fpdf/fpdf.php');
|
||||
require_once('fpdi/fpdi.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a PDF for inclusion in the merge with a valid file path. Pages should be formatted: 1,3,6, 12-16.
|
||||
* @param $filepath
|
||||
* @param $pages
|
||||
* @return void
|
||||
*/
|
||||
public function addPDF($filepath, $pages = 'all')
|
||||
{
|
||||
if(file_exists($filepath))
|
||||
{
|
||||
if(strtolower($pages) != 'all')
|
||||
{
|
||||
$pages = $this->_rewritepages($pages);
|
||||
}
|
||||
|
||||
$this->_files[] = array($filepath, $pages);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new exception("Could not locate PDF on '$filepath'");
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges your provided PDFs and outputs to specified location.
|
||||
* @param $outputmode
|
||||
* @param $outputname
|
||||
* @return PDF
|
||||
*/
|
||||
public function merge($outputmode = 'browser', $outputpath = 'newfile.pdf')
|
||||
{
|
||||
if(!isset($this->_files) || !is_array($this->_files)): throw new exception("No PDFs to merge."); endif;
|
||||
|
||||
$fpdi = new FPDI;
|
||||
|
||||
//merger operations
|
||||
foreach($this->_files as $file)
|
||||
{
|
||||
$filename = $file[0];
|
||||
$filepages = $file[1];
|
||||
|
||||
$count = $fpdi->setSourceFile($filename);
|
||||
|
||||
//add the pages
|
||||
if($filepages == 'all')
|
||||
{
|
||||
for($i=1; $i<=$count; $i++)
|
||||
{
|
||||
$template = $fpdi->importPage($i);
|
||||
$size = $fpdi->getTemplateSize($template);
|
||||
|
||||
$fpdi->AddPage('P', array($size['w'], $size['h']));
|
||||
$fpdi->useTemplate($template);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($filepages as $page)
|
||||
{
|
||||
if(!$template = $fpdi->importPage($page)): throw new exception("Could not load page '$page' in PDF '$filename'. Check that the page exists."); endif;
|
||||
$size = $fpdi->getTemplateSize($template);
|
||||
|
||||
$fpdi->AddPage('P', array($size['w'], $size['h']));
|
||||
$fpdi->useTemplate($template);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//output operations
|
||||
$mode = $this->_switchmode($outputmode);
|
||||
|
||||
if($mode == 'S')
|
||||
{
|
||||
return $fpdi->Output($outputpath, 'S');
|
||||
}
|
||||
else
|
||||
{
|
||||
if($fpdi->Output($outputpath, $mode))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new exception("Error outputting PDF to '$outputmode'.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* FPDI uses single characters for specifying the output location. Change our more descriptive string into proper format.
|
||||
* @param $mode
|
||||
* @return Character
|
||||
*/
|
||||
private function _switchmode($mode)
|
||||
{
|
||||
switch(strtolower($mode))
|
||||
{
|
||||
case 'download':
|
||||
return 'D';
|
||||
break;
|
||||
case 'browser':
|
||||
return 'I';
|
||||
break;
|
||||
case 'file':
|
||||
return 'F';
|
||||
break;
|
||||
case 'string':
|
||||
return 'S';
|
||||
break;
|
||||
default:
|
||||
return 'I';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes our provided pages in the form of 1,3,4,16-50 and creates an array of all pages
|
||||
* @param $pages
|
||||
* @return unknown_type
|
||||
*/
|
||||
private function _rewritepages($pages)
|
||||
{
|
||||
$pages = str_replace(' ', '', $pages);
|
||||
$part = explode(',', $pages);
|
||||
|
||||
//parse hyphens
|
||||
foreach($part as $i)
|
||||
{
|
||||
$ind = explode('-', $i);
|
||||
|
||||
if(count($ind) == 2)
|
||||
{
|
||||
$x = $ind[0]; //start page
|
||||
$y = $ind[1]; //end page
|
||||
|
||||
if($x > $y): throw new exception("Starting page, '$x' is greater than ending page '$y'."); return false; endif;
|
||||
|
||||
//add middle pages
|
||||
while($x <= $y): $newpages[] = (int) $x; $x++; endwhile;
|
||||
}
|
||||
else
|
||||
{
|
||||
$newpages[] = (int) $ind[0];
|
||||
}
|
||||
}
|
||||
|
||||
return $newpages;
|
||||
}
|
||||
|
||||
}
|
||||
5
REST/config.php
Normal file
5
REST/config.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
$restConfig = array(
|
||||
'e5Key' => '7e50a8a5-f01f-4fbc-8c1b-59f3fc474bb5',
|
||||
'twinpolKey' => 'd68dac4c-f784-4e1b-8267-9ffcfa0eda4c'
|
||||
);
|
||||
231
REST/functions.php
Normal file
231
REST/functions.php
Normal file
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
// preDb_0dcc87940d3655fa574b253df04ca1c3
|
||||
// %g7!@fG
|
||||
function createPzFromInvoice($record, $stockId) {
|
||||
global $app_list_strings;
|
||||
$db = $GLOBALS['db'];
|
||||
|
||||
if ($stockId == null) {
|
||||
die('Nie wskazano magazynu');
|
||||
} else {
|
||||
$stock = $db->fetchByAssoc($db->query("SELECT id, name FROM ecmstocks WHERE id = '".$stockId."'"));
|
||||
if ($stock == null) {
|
||||
die("Wskazano błedny magazyn");
|
||||
}
|
||||
}
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET' );
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($curl, CURLOPT_URL, "https://crm.e5.pl/REST/index.php?key=7e50a8a5-f01f-4fbc-8c1b-59f3fc474bb5&action=getInvoice&record=".$record);
|
||||
$res = curl_exec($curl);
|
||||
$inv = json_decode($res);
|
||||
$inv->position_list = json_decode($inv->position_list);
|
||||
echo 'Tworzę dokument PZ w Twinpol<br>';
|
||||
echo 'Numer faktury: '.$inv->document_no.'<br>';
|
||||
echo 'Na magazyn: '.$stock['name'].' (ID: '.$stock['id'].')<br><br>';
|
||||
|
||||
//check if PZ not exists
|
||||
$exists = $db->fetchByAssoc($db->query("SELECT id, document_no FROM ecmstockdocins WHERE name='".$inv->document_no."'"));
|
||||
if ($exists) {
|
||||
echo "Istnieje już dokument PZ przypisany do tej faktury: <a target='new' href='https://crm.twinpol.com/index.php?module=EcmStockDocIns&action=DetailView&record=".$exists['id']."'>".$exists['document_no']."</a>";
|
||||
die();
|
||||
}
|
||||
|
||||
// Create PZ
|
||||
$pz = new EcmStockDocIn();
|
||||
$pz->parent_id = 'f084e64a-4e63-a3d1-6417-58cbf730df3f';
|
||||
$pz->parent_name = 'E5 Polska Sp. z o.o.';
|
||||
$pz->parent_address_street = 'ul. Wąwozowa 11';
|
||||
$pz->parent_address_postalcode = '02-796';
|
||||
$pz->parent_address_city = 'Warszawa';
|
||||
$pz->parent_address_country = 'Polska';
|
||||
$pz->parent_nip = '525-21-73-990';
|
||||
$pz->name = $inv->document_no;
|
||||
$pz->date_entered = date('Y-m-d H:i:s');
|
||||
$pz->date_modified = date('Y-m-d H:i:s');
|
||||
$pz->modified_user_id = '86e2871a-9d00-f756-6bba-59cce0c5db59'; // magazyn@e5.pl
|
||||
$pz->assigned_user_id = '86e2871a-9d00-f756-6bba-59cce0c5db59';
|
||||
$pz->created_by = '86e2871a-9d00-f756-6bba-59cce0c5db59';
|
||||
$pz->deleted = '0';
|
||||
$pz->register_date = date('Y-m-d');
|
||||
$pz->stock_id = $stock['id'];
|
||||
$pz->total = format_number($inv->total_netto);
|
||||
$pz->date_fk = $inv->register_date;
|
||||
$pz->status = 'accepted';
|
||||
$pz->kind = 'other';
|
||||
$pz->total_netto = format_number($inv->total_netto);
|
||||
$pz->total_brutto = format_number($inv->total_brutto);
|
||||
$pz->canceled = '0';
|
||||
$pz->country_transport_val = 0;
|
||||
$pz->foreign_transport_val = 0;
|
||||
$pz->foreign_transport_cur_id = 'PLN';
|
||||
$pz->country_transport_cur_id = 'PLN';
|
||||
$pz->addition_cost_val = 0;
|
||||
$pz->addition_cost_cur_id = 'PLN';
|
||||
$pz->currency_id = 'PLN';
|
||||
$pz->currency_value = 0;
|
||||
$pz->currency_sad_value = 0;
|
||||
$pz->vats_summary = $inv->vats_summary;
|
||||
$pz->position_list = array();
|
||||
$pz->fromREST = true;
|
||||
|
||||
$gotAllProducts = true; // hope :)
|
||||
foreach ( $inv->position_list as $product ) {
|
||||
echo 'Produkt: '.$product->product_code.'<br>';
|
||||
$p = getProduct($product->product_code);
|
||||
if (!$p) {
|
||||
echo ' Produkt nie istnieje w bazie TWINPOL<br>';
|
||||
$gotAllProducts = false;
|
||||
continue;
|
||||
}
|
||||
// add to pz
|
||||
$prod = array();
|
||||
$prod['date_entered'] = date('Y-m-d H:i:s');
|
||||
$prod['date_modified'] = date('Y-m-d H:i:s');
|
||||
$prod['modified_user_id'] = '86e2871a-9d00-f756-6bba-59cce0c5db59';
|
||||
$prod['assigned_user_id'] = '86e2871a-9d00-f756-6bba-59cce0c5db59';
|
||||
$prod['created_by'] = '86e2871a-9d00-f756-6bba-59cce0c5db59';
|
||||
$prod['deleted'] = '0';
|
||||
$prod['ecmstockdocin_id'] = $pz->id;
|
||||
$prod['product_id'] = $p->id;
|
||||
$prod['position'] = $product->position;
|
||||
$prod['product_code'] = $p->code;
|
||||
$prod['name'] = $p->name;
|
||||
$prod['quantity'] = $product->quantity;
|
||||
$prod['price'] = $product->price_netto;
|
||||
$prod['price_fk'] = $product->price_netto;
|
||||
$prod['total'] = $product->total_netto;
|
||||
$prod['unit_id'] = $product->unit_id;
|
||||
$prod['unit_name'] = $product->unit_name;
|
||||
$prod['ecmproductcategory_id'] = $p->product_category_id;
|
||||
$prod['ecmvat_id'] = $p->vat_id;
|
||||
$prod['ecmvat_value'] = $p->vat_value;
|
||||
$prod['ecmvat_name'] = $p->vat_name;
|
||||
$prod['palet'] = 0;
|
||||
$prod['clo'] = 0;
|
||||
$prod['waga'] = 0;
|
||||
array_push($pz->position_list, $prod);
|
||||
}
|
||||
if (!$gotAllProducts) {
|
||||
echo 'Brak produktów w bazie Twinpol. Dokument PZ nie został utworzony';
|
||||
die();
|
||||
} else {
|
||||
$new = $pz->save(true);
|
||||
echo '<a target="new" href="https://crm.twinpol.com/index.php?module=EcmStockDocIns&action=DetailView&record='.$new.'">Utworzono PZ.</a>';
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
function sendStocks()
|
||||
{
|
||||
$db = $GLOBALS['db'];
|
||||
$stocks = array();
|
||||
$stocksRes = $db->query("SELECT id, name FROM ecmstocks WHERE deleted='0'");
|
||||
while ($row = $db->fetchByAssoc($stocksRes)) {
|
||||
$tmp = array();
|
||||
$tmp['id'] = $row['id'];
|
||||
$tmp['name'] = $row['name'];
|
||||
$stocks[] = $tmp;
|
||||
}
|
||||
echo json_encode($stocks);
|
||||
}
|
||||
function sendSale($record) {
|
||||
require_once('modules/EcmSales/EcmSale.php');
|
||||
$sale = new EcmSale();
|
||||
$sale->retrieve($record);
|
||||
$pl = $sale->getPositionList();
|
||||
$response = array (
|
||||
'document_no' => $sale->document_no,
|
||||
'name' => $sale->name,
|
||||
'parent_document_no' => $sale->parent_document_no,
|
||||
'register_date' => $sale->register_date,
|
||||
'send_date' => $sale->send_date,
|
||||
'delivery_date' => $sale->delivery_date,
|
||||
'currency_id' => $sale->currency_id,
|
||||
'total_netto' => $sale->total_netto,
|
||||
'total_brutto' => $sale->total_brutto,
|
||||
'discount' => $sale->discount,
|
||||
'parent_name' => $sale->parent_name,
|
||||
'parent_nip' => $sale->parent_nip,
|
||||
'parent_iln' => $sale->parent_iln,
|
||||
'parent_address_street' => $sale->parent_address_street,
|
||||
'parent_address_city' => $sale->parent_address_city,
|
||||
'parent_address_postalcode' => $sale->parent_address_postalcode,
|
||||
'parent_address_country' => $sale->parent_address_country,
|
||||
'shipping_address_name' => $sale->shipping_address_name,
|
||||
'shipping_address_street' => $sale->shipping_address_street,
|
||||
'shipping_address_postalcode' => $sale->shipping_address_postalcode,
|
||||
'shipping_address_city' => $sale->shipping_address_city,
|
||||
'shipping_address_country' => $sale->shipping_address_country,
|
||||
'vats_summary' => $sale->vats_summary,
|
||||
'position_list' => $pl,
|
||||
'id' => $sale->id
|
||||
);
|
||||
echo json_encode($response);
|
||||
}
|
||||
|
||||
function updateSaleE5Number($record, $e5_record, $e5_document_no) {
|
||||
$db = $GLOBALS['db'];
|
||||
$db->query("UPDATE ecmsales SET edi_zs_id='$e5_record', edi_zs_document_no='$e5_document_no' WHERE id='$record'");
|
||||
die();
|
||||
}
|
||||
|
||||
// local helpers
|
||||
function getProduct($code) {
|
||||
$db = $GLOBALS['db'];
|
||||
$res = $db->fetchByAssoc($db->query("SELECT * FROM ecmproducts WHERE code='$code' AND deleted=0"));
|
||||
if (!$res) {
|
||||
return null;
|
||||
} else {
|
||||
require_once('modules/EcmProducts/EcmProduct.php');
|
||||
$prod = new EcmProduct();
|
||||
$prod->retrieve($res['id']);
|
||||
return $prod;
|
||||
}
|
||||
}
|
||||
function createProduct($record) {
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET' );
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($curl, CURLOPT_URL, "https://crm.e5.pl/REST/index.php?key=7e50a8a5-f01f-4fbc-8c1b-59f3fc474bb5&action=getProduct&record=".$record);
|
||||
$res = curl_exec($curl);
|
||||
$prod = json_decode($res);
|
||||
require_once('modules/EcmProducts/EcmProduct.php');
|
||||
$new = new EcmProduct();
|
||||
$new->name = $prod->name;
|
||||
$new->code = $prod->code;
|
||||
$new->ean = $prod->ean;
|
||||
$new->unit_id = $prod->unit_id;
|
||||
$new->product_category_id = $prod->product_category_id;
|
||||
$new->product_category_name = $prod->product_category_name;
|
||||
$new->position_list3 = [];
|
||||
$db = $GLOBALS['db'];
|
||||
$vat = $db->fetchByAssoc($db->query("SELECT * FROM ecmvats WHERE value=$prod->vat"));
|
||||
$new->vat_id = $vat['id'];
|
||||
$new->vat_name = $vat['name'];
|
||||
$new->vat_value = $vat['value'];
|
||||
$new->assigned_user_id = '1';
|
||||
$new->modified_user_id = '1';
|
||||
$new->created_by = '1';
|
||||
$new->date_entered = date('Y-m-d H:i:s');
|
||||
$new->date_modified = date('Y-m-d H:i:s');
|
||||
$new->assigned_user_name = 'Admin System';
|
||||
$new->modified_user_name = 'Admin System';
|
||||
//$new->save();
|
||||
return $new;
|
||||
}
|
||||
function brecho($msg) {
|
||||
echo '<br><br>';
|
||||
var_dump($msg);
|
||||
echo '<br><br>';
|
||||
}
|
||||
|
||||
// mysql create table with fields id varchar, created_at datetime, and payload max text
|
||||
// create table e5_logs (id varchar(255), created_at datetime, payload text);
|
||||
39
REST/index.php
Normal file
39
REST/index.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
ini_set('display_errors', 0);
|
||||
ini_set('display_startup_errors', 0);
|
||||
// error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
|
||||
|
||||
chdir(dirname(__DIR__));
|
||||
require_once('./REST/config.php');
|
||||
|
||||
$GLOBALS['mailLog'] = '';
|
||||
|
||||
if ($_GET['key'] != $restConfig['twinpolKey']) {
|
||||
echo 'Unauthorized';
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once('./REST/functions.php');
|
||||
// Enable SugarCRM features
|
||||
if(!defined('sugarEntry'))define('sugarEntry', true);
|
||||
require_once('./include/entryPoint.php');
|
||||
require_once ('data/SugarBean.php');
|
||||
require_once ('include/utils.php');
|
||||
// fix db, but why?
|
||||
$GLOBALS['db']->query("USE preDb_0dcc87940d3655fa574b253df04ca1c3;");
|
||||
|
||||
switch ($_GET["action"]) {
|
||||
case 'createPzFromInvoice':
|
||||
createPzFromInvoice($_GET['record'], $_GET['stock_id']);
|
||||
break;
|
||||
case 'getSale':
|
||||
sendSale($_GET['record']);
|
||||
break;
|
||||
case 'getStocks':
|
||||
sendStocks();
|
||||
break;
|
||||
case 'updateSaleE5Number':
|
||||
updateSaleE5Number($_GET['record'], $_GET['e5_record'], $_GET['e5_document_no']);
|
||||
break;
|
||||
}
|
||||
?>
|
||||
37
REST/mobile.php
Normal file
37
REST/mobile.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header('Access-Control-Allow-Headers: X-Requested-With');
|
||||
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
|
||||
header('Content-Type: application/json');
|
||||
|
||||
chdir(dirname(__DIR__));
|
||||
|
||||
require_once('./REST/config.php');
|
||||
if ($_GET['key'] != $restConfig['twinpolKey']) {
|
||||
echo 'Unauthorized';
|
||||
exit;
|
||||
}
|
||||
|
||||
if(!defined('sugarEntry'))define('sugarEntry', true);
|
||||
require_once('./include/entryPoint.php');
|
||||
// fix db, but why?
|
||||
$GLOBALS['db']->query("USE preDb_0dcc87940d3655fa574b253df04ca1c3;");
|
||||
|
||||
switch ($_GET["action"]) {
|
||||
case 'getProductByEAN':
|
||||
$db = $GLOBALS['db'];
|
||||
$ean = $_GET['ean'];
|
||||
$res = $db->fetchByAssoc($db->query("SELECT id, name, code FROM ecmproducts WHERE (ean='$ean' OR ean2='$ean') AND deleted=0"));
|
||||
if ($res) {
|
||||
$r = $db->fetchByAssoc($db->query("SELECT SUM(quantity) as qty FROM ecmstockstates WHERE product_id='".$res['id']."'"));
|
||||
$res['state'] = $r['qty'] | 0;
|
||||
|
||||
$r= $db->query("SELECT stock_address FROM ecmproducts_stock_addresses WHERE ecmproduct_id='".$res['id']."';");
|
||||
$res['stock_addresses'] = "";
|
||||
while($row=$db->fetchByAssoc($r)) {
|
||||
$res['stock_addresses'] .= " ".$row['stock_address'];
|
||||
}
|
||||
}
|
||||
echo json_encode($res);
|
||||
break;
|
||||
}
|
||||
166
SugarSecurity.php
Executable file
166
SugarSecurity.php
Executable file
@@ -0,0 +1,166 @@
|
||||
<?PHP
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
class SugarSecure{
|
||||
var $results = array();
|
||||
function display(){
|
||||
echo '<table>';
|
||||
foreach($this->results as $result){
|
||||
echo '<tr><td>' . nl2br($result) . '</td></tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
function save($file=''){
|
||||
$fp = fopen($file, 'a');
|
||||
foreach($this->results as $result){
|
||||
fwrite($fp , $result);
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
function scan($path= '.', $ext = '.php'){
|
||||
$dir = dir($path);
|
||||
while($entry = $dir->read()){
|
||||
if(is_dir($path . '/' . $entry) && $entry != '.' && $entry != '..'){
|
||||
$this->scan($path .'/' . $entry);
|
||||
}
|
||||
if(is_file($path . '/'. $entry) && substr($entry, strlen($entry) - strlen($ext), strlen($ext)) == $ext){
|
||||
$contents = file_get_contents($path .'/'. $entry);
|
||||
$this->scanContents($contents, $path .'/'. $entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function scanContents($contents){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class ScanFileIncludes extends SugarSecure{
|
||||
function scanContents($contents, $file){
|
||||
$results = array();
|
||||
$found = '';
|
||||
/*preg_match_all("'(require_once\([^\)]*\\$[^\)]*\))'si", $contents, $results, PREG_SET_ORDER);
|
||||
foreach($results as $result){
|
||||
|
||||
$found .= "\n" . $result[0];
|
||||
}
|
||||
$results = array();
|
||||
preg_match_all("'include_once\([^\)]*\\$[^\)]*\)'si", $contents, $results, PREG_SET_ORDER);
|
||||
foreach($results as $result){
|
||||
$found .= "\n" . $result[0];
|
||||
}
|
||||
*/
|
||||
$results = array();
|
||||
preg_match_all("'require\([^\)]*\\$[^\)]*\)'si", $contents, $results, PREG_SET_ORDER);
|
||||
foreach($results as $result){
|
||||
$found .= "\n" . $result[0];
|
||||
}
|
||||
$results = array();
|
||||
preg_match_all("'include\([^\)]*\\$[^\)]*\)'si", $contents, $results, PREG_SET_ORDER);
|
||||
foreach($results as $result){
|
||||
$found .= "\n" . $result[0];
|
||||
}
|
||||
$results = array();
|
||||
preg_match_all("'require_once\([^\)]*\\$[^\)]*\)'si", $contents, $results, PREG_SET_ORDER);
|
||||
foreach($results as $result){
|
||||
$found .= "\n" . $result[0];
|
||||
}
|
||||
$results = array();
|
||||
preg_match_all("'fopen\([^\)]*\\$[^\)]*\)'si", $contents, $results, PREG_SET_ORDER);
|
||||
foreach($results as $result){
|
||||
$found .= "\n" . $result[0];
|
||||
}
|
||||
$results = array();
|
||||
preg_match_all("'file_get_contents\([^\)]*\\$[^\)]*\)'si", $contents, $results, PREG_SET_ORDER);
|
||||
foreach($results as $result){
|
||||
$found .= "\n" . $result[0];
|
||||
}
|
||||
if(!empty($found)){
|
||||
$this->results[] = $file . $found."\n\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class SugarSecureManager{
|
||||
var $scanners = array();
|
||||
function registerScan($class){
|
||||
$this->scanners[] = new $class();
|
||||
}
|
||||
|
||||
function scan(){
|
||||
|
||||
while($scanner = current($this->scanners)){
|
||||
$scanner->scan();
|
||||
$scanner = next($this->scanners);
|
||||
}
|
||||
reset($this->scanners);
|
||||
}
|
||||
|
||||
function display(){
|
||||
|
||||
while($scanner = current($this->scanners)){
|
||||
echo 'Scan Results: ';
|
||||
$scanner->display();
|
||||
$scanner = next($this->scanners);
|
||||
}
|
||||
reset($this->scanners);
|
||||
}
|
||||
|
||||
function save(){
|
||||
//reset($this->scanners);
|
||||
$name = 'SugarSecure'. time() . '.txt';
|
||||
while($this->scanners = next($this->scanners)){
|
||||
$scanner->save($name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$secure = new SugarSecureManager();
|
||||
$secure->registerScan('ScanFileIncludes');
|
||||
$secure->scan();
|
||||
$secure->display();
|
||||
145
TreeData.php
Executable file
145
TreeData.php
Executable file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
//Request object must have these property values:
|
||||
// Module: module name, this module should have a file called TreeData.php
|
||||
// Function: name of the function to be called in TreeData.php, the function will be called statically.
|
||||
// PARAM prefixed properties: array of these property/values will be passed to the function as parameter.
|
||||
|
||||
$ret=array();
|
||||
$params1=array();
|
||||
$nodes=array();
|
||||
|
||||
$GLOBALS['log']->debug("TreeData:session started");
|
||||
$current_language = $GLOBALS['current_language'];
|
||||
|
||||
//process request parameters. consider following parameters.
|
||||
//function, and all parameters prefixed with PARAM.
|
||||
//PARAMT_ are tree level parameters.
|
||||
//PARAMN_ are node level parameters.
|
||||
//module name and function name parameters are the only ones consumed
|
||||
//by this file..
|
||||
foreach ($_REQUEST as $key=>$value) {
|
||||
|
||||
switch ($key) {
|
||||
|
||||
case "function":
|
||||
case "call_back_function":
|
||||
$func_name=$value;
|
||||
$params1['TREE']['function']=$value;
|
||||
break;
|
||||
|
||||
default:
|
||||
$pssplit=explode('_',$key);
|
||||
if ($pssplit[0] =='PARAMT') {
|
||||
unset($pssplit[0]);
|
||||
$params1['TREE'][implode('_',$pssplit)]=$value;
|
||||
} else {
|
||||
if ($pssplit[0] =='PARAMN') {
|
||||
$depth=$pssplit[count($pssplit)-1];
|
||||
//parmeter is surrounded by PARAMN_ and depth info.
|
||||
unset($pssplit[count($pssplit)-1]);unset($pssplit[0]);
|
||||
$params1['NODES'][$depth][implode('_',$pssplit)]=$value;
|
||||
} else {
|
||||
if ($key=='module') {
|
||||
if (!isset($params1['TREE']['module'])) {
|
||||
$params1['TREE'][$key]=$value;
|
||||
}
|
||||
} else {
|
||||
$params1['REQUEST'][$key]=$value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$modulename=$params1['TREE']['module']; ///module is a required parameter for the tree.
|
||||
require('include/modules.php');
|
||||
if (!empty($modulename) && !empty($func_name) && isset($beanList[$modulename]) ) {
|
||||
require_once('modules/'.$modulename.'/TreeData.php');
|
||||
$TreeDataFunctions = array(
|
||||
'ProductTemplates' => array('get_node_data'=>'','get_categories_and_products'=>''),
|
||||
'ProductCategories' => array('get_node_data'=>'','get_product_categories'=>''),
|
||||
'KBTags' => array(
|
||||
'get_node_data'=>'',
|
||||
'get_tags_nodes'=>'',
|
||||
'get_tags_nodes_cached'=>'',
|
||||
'childNodes'=>'',
|
||||
'get_searched_tags_nodes'=>'',
|
||||
'find_peers'=>'',
|
||||
'getRootNode'=>'',
|
||||
'getParentNode'=>'',
|
||||
'get_tags_modal_nodes'=>'',
|
||||
'get_admin_browse_articles'=>'',
|
||||
'tagged_documents_count'=>'',
|
||||
'tag_count'=>'',
|
||||
'get_browse_documents'=>'',
|
||||
'get_tag_nodes_for_browsing'=>'',
|
||||
'create_browse_node'=>'',
|
||||
'untagged_documents_count'=>'',
|
||||
'check_tag_child_tags_for_articles'=>'',
|
||||
'childTagsHaveArticles'=>'',
|
||||
),
|
||||
'KBDocuments' => array(
|
||||
'get_node_data'=>'',
|
||||
'get_category_nodes'=>'',
|
||||
'get_documents'=>'',
|
||||
),
|
||||
'Forecasts' => array(
|
||||
'get_node_data'=>'',
|
||||
'get_worksheet'=>'',
|
||||
'commit_forecast'=>'',
|
||||
'save_worksheet'=>'',
|
||||
'list_nav'=>'',
|
||||
'reset_worksheet'=>'',
|
||||
'get_chart'=>'',
|
||||
),
|
||||
'Documents' => array(
|
||||
'get_node_data'=>'',
|
||||
'get_category_nodes'=>'',
|
||||
'get_documents'=>'',
|
||||
),
|
||||
);
|
||||
|
||||
if (isset($TreeDataFunctions[$modulename][$func_name])) {
|
||||
$ret=call_user_func($func_name,$params1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($ret)) {
|
||||
echo $ret;
|
||||
}
|
||||
|
||||
?>
|
||||
62
WSDL.php
Executable file
62
WSDL.php
Executable file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/****************************************************/
|
||||
//
|
||||
// PrestaShop2e5crm WSDL v1.0
|
||||
//
|
||||
//**************************************************/
|
||||
//
|
||||
// Us<55>uga wymiany danych pomiedzy sklepem a CRM
|
||||
// Author: Micha<68> Rygielski
|
||||
// Date: 2013-09-19
|
||||
//
|
||||
/****************************************************/
|
||||
|
||||
|
||||
require('WSDL/inc.variables.php');
|
||||
require('WSDL/inc.mysqli.config.php');
|
||||
//require('include/inc.mysqli.php');
|
||||
require('WSDL/pdo.db.php');
|
||||
//$db = new Database(MYSQL_API_HOST, MYSQL_API_USER, MYSQL_API_PASSWORD, MYSQL_API_PORT, MYSQL_API_DATABASE, MYSQL_API_COLLATE);
|
||||
|
||||
|
||||
//require('include/pdo.db.php');
|
||||
require('WSDL/inc.functions.php');
|
||||
// require('include/inc.ws.types.php');
|
||||
|
||||
define("sugarEntry", "true");
|
||||
|
||||
require_once('include/entryPoint.php');
|
||||
require_once('include/utils/file_utils.php');
|
||||
ob_start();
|
||||
|
||||
require_once('soap/SoapError.php');
|
||||
require_once('nusoap/nusoap.php');
|
||||
require_once('modules/Contacts/Contact.php');
|
||||
require_once('modules/Accounts/Account.php');
|
||||
require_once('modules/Opportunities/Opportunity.php');
|
||||
require_once('modules/Cases/Case.php');
|
||||
|
||||
//ignore notices
|
||||
error_reporting(E_ERROR);
|
||||
|
||||
|
||||
$namespace = full_url()."?wsdl";
|
||||
|
||||
$server = new soap_server();
|
||||
$server->configureWSDL("WSDL");
|
||||
$server->soap_defencoding = 'utf-8';
|
||||
$server->soap_http_encoding = 'utf-8';
|
||||
$server->xml_excoding = 'utf-8';
|
||||
$server->decode_utf8 = false;
|
||||
|
||||
require('WSDL/inc.ws.methods.php');
|
||||
|
||||
// Register_Types($server);
|
||||
// echo "TEST";exit;
|
||||
//Register_Methods($server, $namespace);
|
||||
|
||||
$server->service(isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '');
|
||||
exit();
|
||||
|
||||
?>
|
||||
234
WSDL/1.php
Executable file
234
WSDL/1.php
Executable file
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
|
||||
define("MYSQL_API_HOST", "localhost");
|
||||
define("MYSQL_API_PORT", "80");
|
||||
define("MYSQL_API_USER", "root");
|
||||
define("MYSQL_API_PASSWORD", "sgpmk777");
|
||||
define("MYSQL_API_DATABASE", "crm");
|
||||
define("MYSQL_API_COLLATE", "UTF8");
|
||||
|
||||
|
||||
|
||||
echo "TEST";
|
||||
|
||||
function ecm_add_order_from_shop($user_name, $password, $order, $presta, $user, $a, $b, $c, $d) {
|
||||
|
||||
|
||||
$x = "";
|
||||
$x = "S";
|
||||
$y = "false";
|
||||
|
||||
|
||||
|
||||
if(!empty($order)) {
|
||||
|
||||
$y = "ok";
|
||||
|
||||
|
||||
try {
|
||||
|
||||
$order = unserialize(base64_decode($order));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//return print_r($order);
|
||||
if(!empty($order) && is_array($order)) {
|
||||
|
||||
|
||||
|
||||
if($order['Order-Header']['OrderNumber'] == "ORDERTEST1234")
|
||||
return "IDTEST1234";
|
||||
|
||||
else {
|
||||
require_once("modules/EcmSales/EcmSale.php");
|
||||
$focus=new EcmSale();
|
||||
|
||||
|
||||
$template_id="97700b0d-fbe9-e366-4016-4b260f058a47";
|
||||
|
||||
$db = new PDODB("mysql:host=".MYSQL_API_HOST.";dbname=".MYSQL_API_DATABASE.";port=".MYSQL_API_PORT,MYSQL_API_USER,MYSQL_API_PASSWORD);
|
||||
|
||||
|
||||
|
||||
|
||||
$focus->template_id=$template_id;
|
||||
//$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select name from ecmdocumenttemplates where id='".$template_id."'"));
|
||||
//$query = $db->executeQuery(query("select name from ecmdocumenttemplates where id='".$template_id."'"));
|
||||
|
||||
$row = $db->fetchFirstRow("select name from ecmdocumenttemplates where id='".$template_id."'");
|
||||
$focus->template_name=$row['name'];
|
||||
$focus->setTemplate();
|
||||
$focus->number=$focus->generateNumber();
|
||||
$focus->document_no=$focus->formatNumber();
|
||||
$focus->currency_id="PLN";
|
||||
$focus->ecmlanguage="pl_pl";
|
||||
$focus->status="s10";
|
||||
$focus->type="sales_order";
|
||||
$focus->modified_user_id="d09b87cf-efff-2f7c-a859-4ba38402488f";
|
||||
$focus->created_by="d09b87cf-efff-2f7c-a859-4ba38402488f";
|
||||
|
||||
$pr=$order['Order-Lines'];
|
||||
$x = "ok";
|
||||
include_once("modules/Accounts/Account.php");
|
||||
//$ww=$GLOBALS['db']->query("select count(*) as c from accounts where b2clogin ='".$order['Order-Parties']['Buyer']['Login']."' and deleted='0'");
|
||||
//$ww=$GLOBALS['db']->query("select count(*) as c from accounts where `id` ='".$order['Order-Parties']['Buyer']['Login']."' and deleted='0'");
|
||||
$row = $db->fetchFirstRow("select count(*) as c from accounts where `id` ='".$order['Order-Parties']['Buyer']['Login']."' and deleted='0'");
|
||||
//$rr=$GLOBALS['db']->fetchByAssoc($ww);
|
||||
$focus->parent_id="getmir";
|
||||
$focus->description=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['Description']);
|
||||
|
||||
|
||||
// if($rr['c']==0){
|
||||
// $account=new Account();
|
||||
$account->ownership="getmir";
|
||||
// $account->name=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['Name']);
|
||||
// $account->b2clogin=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['Login']);
|
||||
// $account->billing_address_street=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['StreetAndNumber']);
|
||||
// $account->billing_address_postalcode=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['PostalCode']);
|
||||
// $account->billing_address_city=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['CityName']);
|
||||
// $account->shipping_address_street=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['DeliveryPoint']['StreetAndNumber']);
|
||||
// $account->shipping_address_postalcode=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['DeliveryPoint']['PostalCode']);
|
||||
// $account->shipping_address_city=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['DeliveryPoint']['CityName']);
|
||||
// $focus->parent_id=create_guid_2();
|
||||
// $GLOBALS['db']->query("insert into accounts set id='".$focus->parent_id."',name='".$account->name."',billing_address_street='".$account->billing_address_street."',billing_address_postalcode='".$account->billing_address_postalcode."',billing_address_city='".$account->billing_address_city."',shipping_address_street='".$account->shipping_address_street."',shipping_address_postalcode='".$account->shipping_address_postalcode."',shipping_address_city='".$account->shipping_address_city."', b2clogin='".$account->b2clogin."'");
|
||||
// }
|
||||
// else{
|
||||
|
||||
|
||||
//$w=$GLOBALS['db']->query("select id from accounts where b2clogin = '".$order['Order-Parties']['Buyer']['Login']."' and deleted='0'");
|
||||
//$w=$GLOBALS['db']->query("select `id` from `accounts` where `id` = '".$order['Order-Parties']['Buyer']['Login']."' and `deleted`='0'");
|
||||
$row = $db->fetchFirstRow("select `id` from `accounts` where `id` = '".$order['Order-Parties']['Buyer']['Login']."' and `deleted`='0'");
|
||||
//$r=$GLOBALS['db']->fetchByAssoc($w);
|
||||
$account=new Account();
|
||||
//update account, maybe sth. change
|
||||
|
||||
// $GLOBALS['db']->query("update accounts set name='".$account->name."',billing_address_street='".$account->billing_address_street."',billing_address_postalcode='".$account->billing_address_postalcode."',billing_address_city='".$account->billing_address_city."'"."',shipping_address_street='".$account->shipping_address_street."',shipping_address_postalcode='".$account->shipping_address_postalcode."',shipping_address_city='".$account->shipping_address_city."'where id='".$r['id']."'");
|
||||
|
||||
// $account->retrieve($r['id']);
|
||||
$focus->parent_id=$row['id'];
|
||||
//}
|
||||
$focus->assigned_user_id="d09b87cf-efff-2f7c-a859-4ba38402488f";
|
||||
$focus->register_date=$order['Order-Header']['OrderDate'];
|
||||
$focus->delivery_date=$order['Order-Header']['ExpectedDeliveryDate'];
|
||||
//$focus->supplier_code=3442;
|
||||
$focus->order_no=$order['Order-Header']['OrderNumber'];
|
||||
$focus->ecmlanguage="pl_pl";
|
||||
$focus->ecmpaymentcondition_id=$order['Order-Parties']['Buyer']['PaymentConditionId'];
|
||||
|
||||
$focus->parent_name=$row["name"];//$account->name;
|
||||
$focus->parent_address_street=$a;//$account->shipping_address_street;
|
||||
$focus->parent_address_city=$b;//$account->shipping_address_city;
|
||||
$focus->parent_address_postalcode=$c;//$account->shipping_address_postalcode;
|
||||
$focus->parent_address_country=$d;//$account->shipping_address_country;
|
||||
|
||||
$ra=array();
|
||||
$total=0;
|
||||
|
||||
|
||||
|
||||
if(count($pr)>0){
|
||||
foreach($pr as $prod){
|
||||
$product_id="";
|
||||
//$w=$GLOBALS['db']->query("select id as ecmproduct_id from ecmproducts where code='".$prod['Line']['Line-Item']['CODE']."' and deleted='0' and code NOT LIKE '%_w' and code NOT LIKE '%_z' and code NOT LIKE '%_W' and code NOT LIKE '%_Z'");
|
||||
//$w=$GLOBALS['db']->query("select `id` as `ecmproduct_id` from `ecmproducts` where `id`='".$prod['Line']['Line-Item']['CODE']."' and `deleted`='0' and `code` NOT LIKE '%_w' and `code` NOT LIKE '%_z' and `code` NOT LIKE '%_W' and `code` NOT LIKE '%_Z'");
|
||||
$row = $db->fetchFirstRow("select `id` as `ecmproduct_id` from `ecmproducts` where `id`='".$prod['Line']['Line-Item']['CODE']."' and `deleted`='0' and `code` NOT LIKE '%_w' and `code` NOT LIKE '%_z' and `code` NOT LIKE '%_W' and `code` NOT LIKE '%_Z'");
|
||||
// $r=$GLOBALS['db']->fetchByAssoc($w);
|
||||
$product_id=$row['ecmproduct_id'];
|
||||
|
||||
$wp=$GLOBALS['db']->query("select * from `ecmproducts` where `id`='".$product_id."'");
|
||||
$rppp=$GLOBALS['db']->fetchByAssoc($wp);
|
||||
$product_code=$rppp['code'];
|
||||
$product_name=$rppp['name'];
|
||||
$vat_id=$rppp['vat_id'];
|
||||
$vat_name=$rppp['vat_name'];
|
||||
$vat_value=$rppp['vat_value'];
|
||||
|
||||
$return_array['id'] = $product_id;
|
||||
$return_array['code'] = $product_code;
|
||||
$return_array['name'] = $product_name;
|
||||
$return_array['quantity'] = $prod['Line']['Line-Item']['OrderedQuantity'];
|
||||
$return_array['price'] = $prod['Line']['Line-Item']['OrderedUnitNetPrice'];
|
||||
$return_array['discount'] = 0;
|
||||
$return_array['total'] = $prod['Line']['Line-Item']['OrderedQuantity']*$prod['Line']['Line-Item']['OrderedUnitNetPrice'];
|
||||
$return_array['unit_id'] = 1;
|
||||
$return_array['unit_name'] = 'szt.';
|
||||
$return_array['vat_id'] = $vat_id;
|
||||
$return_array['vat_name'] = $vat_name;
|
||||
$return_array['vat_value'] = $vat_value;
|
||||
$return_array['currency_id'] = 'PLN';
|
||||
$return_array['recipient_code'] = $prod['Line']['Line-Item']['BuyerItemCode'];
|
||||
$total+=$return_array['quantity']*$return_array['price']*(1+$vat_value/100);
|
||||
$ra[]=$return_array;
|
||||
}
|
||||
}
|
||||
$focus->position_list = $ra;
|
||||
$return_id=$focus->save_from_shop($presta, $user);
|
||||
$GLOBALS['db']->query("update `ecmsales` set `total`='".$total."' where `id`='".$return_id."'");
|
||||
|
||||
|
||||
return $return_id;
|
||||
|
||||
|
||||
//return print_r(mysql_error()."mm", true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch(Exception $e) {}
|
||||
|
||||
}
|
||||
|
||||
return $y;
|
||||
|
||||
|
||||
}
|
||||
|
||||
$order_lines = array();
|
||||
$line= array(
|
||||
'Line' => array(
|
||||
'Line-Item' => array(
|
||||
'LineNumber' => 1,
|
||||
'CODE' => 33,
|
||||
'EAN' => '',
|
||||
'BuyerItemCode' => '',
|
||||
'SupplierItemCode' => '',
|
||||
'ItemDescription' => "produkt",
|
||||
'ItemType' => 'CU',
|
||||
'OrderedQuantity' => "1",
|
||||
'OrderedUnitPacksize' => 1,
|
||||
'UnitOfMeasure' => 'PCE',
|
||||
'OrderedUnitNetPrice' => 99,
|
||||
'PackageNumber' => '',
|
||||
),
|
||||
),
|
||||
);
|
||||
$order_lines[] = $line;
|
||||
|
||||
|
||||
$order = array();
|
||||
$order['Order-Summary'] = array(
|
||||
'TotalLines' => 1-1,
|
||||
'TotalOrderedAmount' => "5000",
|
||||
);
|
||||
$order['Order-Lines'] = $order_lines; // ilosc wierszy w zamowieniu
|
||||
|
||||
// echo print_r($order);
|
||||
//exit;
|
||||
|
||||
$order['Order-Parties']['Buyer']['Login'] = "777"; // login uzytkownika
|
||||
$order['Order-Parties']['Buyer']['Description'] = ""; // opis
|
||||
$order['Order-Header']['OrderDate'] = date("Y-m-d");
|
||||
$order['Order-Header']['ExpectedDeliveryDate'] = date("Y-m-d");
|
||||
|
||||
$order['Order-Header']['OrderNumber'] = "brak"; // numer zamowienia
|
||||
$order['Order-Parties']['Buyer']['PaymentConditionId'] = "23d19aa9-d63a-dd99-568c-4dff0bbc7f40"; // 7 dni na zaplate
|
||||
|
||||
$getReference = "HKKMLOPMX";
|
||||
|
||||
$order['Order-Header']['Presta'] = $getReference;
|
||||
|
||||
|
||||
|
||||
?>
|
||||
27
WSDL/inc.error.php
Executable file
27
WSDL/inc.error.php
Executable file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
////
|
||||
// Error handling
|
||||
////
|
||||
|
||||
error_reporting( E_ERROR );
|
||||
function handleError($errno, $errstr,$error_file,$error_line) { throw new Exception("Error [$errno]: $errstr - $error_file:$error_line"); }
|
||||
set_error_handler("handleError");
|
||||
|
||||
error_reporting(0);
|
||||
set_error_handler('myErrorHandler');
|
||||
register_shutdown_function('fatalErrorShutdownHandler');
|
||||
function myErrorHandler($code, $message, $file, $line)
|
||||
{
|
||||
die("Fatal Error: [$code] $message - $file:$line");
|
||||
}
|
||||
|
||||
function fatalErrorShutdownHandler()
|
||||
{
|
||||
$last_error = error_get_last();
|
||||
if ($last_error['type'] === E_ERROR)
|
||||
{
|
||||
// fatal error
|
||||
myErrorHandler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
141
WSDL/inc.functions.php
Executable file
141
WSDL/inc.functions.php
Executable file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
|
||||
function DateTimeToString($dt)
|
||||
{
|
||||
$_dt = new DateTime($dt);
|
||||
return $_dt->format(DateTime::ATOM);
|
||||
}
|
||||
|
||||
function StartTimer()
|
||||
{
|
||||
$time = microtime();$time = explode(' ', $time);$time = $time[1] + $time[0];$start = $time;
|
||||
return $start;
|
||||
}
|
||||
|
||||
function StopTimer($start)
|
||||
{
|
||||
$time = microtime();$time = explode(' ', $time);$time = $time[1] + $time[0];$finish = $time; //$total_time = round(($finish - $start), 4);
|
||||
return round(($finish - $start), 4);
|
||||
}
|
||||
|
||||
function startsWith($haystack, $needle)
|
||||
{
|
||||
return !strncmp($haystack, $needle, strlen($needle));
|
||||
}
|
||||
|
||||
function endsWith($haystack, $needle)
|
||||
{
|
||||
$length = strlen($needle);
|
||||
if ($length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (substr($haystack, -$length) === $needle);
|
||||
}
|
||||
|
||||
function strrtrim($message, $strip) {
|
||||
// break message apart by strip string
|
||||
$lines = explode($strip, $message);
|
||||
$last = '';
|
||||
// pop off empty strings at the end
|
||||
do {
|
||||
$last = array_pop($lines);
|
||||
} while (empty($last) && (count($lines)));
|
||||
// re-assemble what remains
|
||||
return implode($strip, array_merge($lines, array($last)));
|
||||
}
|
||||
|
||||
|
||||
function full_url()
|
||||
{
|
||||
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
|
||||
$sp = strtolower($_SERVER["SERVER_PROTOCOL"]);
|
||||
$protocol = substr($sp, 0, strpos($sp, "/")) . $s;
|
||||
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
|
||||
return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI'];
|
||||
}
|
||||
|
||||
function md5_hash_encode($source)
|
||||
{
|
||||
$base_string = md5($source); // kodowanie stringa standardowym MD5()
|
||||
|
||||
// dzielenie stringa na 3 kawałki
|
||||
$begin = substr($base_string, 0, 4);
|
||||
$in = substr($base_string, 4,20);
|
||||
$end = substr($base_string, 20, strlen($base_string));
|
||||
|
||||
$base_string = $begin.rand(0,8).$in.rand(0,8).$end; // dodawanie dodatkowego hasha
|
||||
$base_string = strrev($base_string); // odwracanie kolejności znaków w stringu
|
||||
|
||||
return $base_string;
|
||||
}
|
||||
|
||||
function md5_hash_decode($source)
|
||||
{
|
||||
$base_string = strrev($source); // odwracanie kolejności znaków w stringu
|
||||
|
||||
// pobieranie prawidłowych elementów stringa
|
||||
$begin = substr($base_string, 0, 4);
|
||||
$in = substr($base_string, 5, 20);
|
||||
$end = substr($base_string, 30, strlen($base_string));
|
||||
|
||||
$base_string = $begin.$in.$end;
|
||||
|
||||
return $base_string;
|
||||
}
|
||||
|
||||
function base64_hash_encode($source, $base = false)
|
||||
{
|
||||
if ($base) $base_string = base64_encode($source); else $base_string = $source;
|
||||
|
||||
if (strlen($source) > 24) {
|
||||
// dzielenie stringa na 3 kawałki
|
||||
$begin = substr($base_string, 0, 4);
|
||||
$in = substr($base_string, 4,20);
|
||||
$end = substr($base_string, 24, strlen($base_string));
|
||||
|
||||
$base_string = $begin.rand(0, 8).$in.rand(0, 8).$end; // dodawanie dodatkowego hasha
|
||||
}
|
||||
|
||||
$base_string = strrev($base_string); // odwracanie kolejności znaków w stringu
|
||||
|
||||
for ($i = 0; $i < strlen($base_string); $i++) $base_string[$i] = chr(ord($base_string[$i]) + ($i * 3));
|
||||
|
||||
// zamiana treści na HEX
|
||||
$encode_result = "";
|
||||
foreach(str_split($base_string) as $c) $encode_result .= sprintf("%02X", ord($c));
|
||||
|
||||
return strtolower($encode_result);
|
||||
|
||||
}
|
||||
|
||||
function base64_hash_decode($source, $base = false)
|
||||
{
|
||||
// odwracanie treści z HEX
|
||||
$source_decode = "";
|
||||
foreach(explode("\n", trim(chunk_split(strtoupper($source), 2))) as $h) $source_decode .= chr(hexdec($h));
|
||||
|
||||
for ($i = 0; $i < strlen($source_decode); $i++) $source_decode[$i] = chr(ord($source_decode[$i]) - ($i * 3));
|
||||
|
||||
$base_string = strrev($source_decode); // odwracanie kolejności znaków w stringu
|
||||
|
||||
if (strlen($base_string) > 24) {
|
||||
// pobieranie prawidłowych elementów stringa
|
||||
$begin = substr($base_string, 0, 4);
|
||||
$in = substr($base_string, 5, 20);
|
||||
$end = substr($base_string, 26, strlen($base_string));
|
||||
|
||||
$base_string = $begin.$in.$end;
|
||||
}
|
||||
|
||||
if ($base) $base_string = base64_decode($base_string);
|
||||
|
||||
return $base_string;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// echo md5('passowrd!!!!787').'<BR>';
|
||||
// echo md5_hash_decode('912e198bd3876d387bd8846228375303036951').'<BR>';
|
||||
?>
|
||||
12
WSDL/inc.mysqli.config.php
Executable file
12
WSDL/inc.mysqli.config.php
Executable file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
define("MYSQL_API_HOST", "localhost");
|
||||
define("MYSQL_API_PORT", "80");
|
||||
define("MYSQL_API_USER", "root");
|
||||
define("MYSQL_API_PASSWORD", "sgpmk777");
|
||||
define("MYSQL_API_DATABASE", "crm");
|
||||
define("MYSQL_API_COLLATE", "UTF8");
|
||||
|
||||
define("sugarEntry", "true");
|
||||
|
||||
?>
|
||||
100
WSDL/inc.mysqli.php
Executable file
100
WSDL/inc.mysqli.php
Executable file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
// Wrapper do łatwej obsługi MySQL poprzez mysqli
|
||||
|
||||
|
||||
class Database {
|
||||
|
||||
public $link = NULL;
|
||||
public $errors = array();
|
||||
|
||||
public function __construct($server = '',$user='',$pass='',$port='',$dbname='',$collation='') {
|
||||
|
||||
if(!empty($server)) $this->connect($server, $user, $pass, $port, $dbname, $collation);
|
||||
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
|
||||
$this->close();
|
||||
|
||||
}
|
||||
|
||||
public function connect($server, $user, $pass, $port, $dbname, $collation) {
|
||||
|
||||
$this->link = mysqli_connect($server, $user, $pass, $dbname, $port) or $errors[] = 'Database Error: '.mysqli_connect_error();
|
||||
$this->link->set_charset($collation);
|
||||
//$this->nonquery("SET NAMES 'utf8';");
|
||||
|
||||
}
|
||||
|
||||
public function close() {
|
||||
|
||||
//$this->link->close();
|
||||
|
||||
}
|
||||
|
||||
public function info() {
|
||||
|
||||
return mysqli_get_host_info($this->link);
|
||||
|
||||
}
|
||||
|
||||
public function es($text) {
|
||||
|
||||
return $this->link->real_escape_string($text);
|
||||
|
||||
}
|
||||
|
||||
function prepareQuery($string, $vars = array()) {
|
||||
|
||||
if(!is_array($vars)) $vars = array_slice(func_get_args(),1);
|
||||
|
||||
foreach($vars as $var) {
|
||||
if(!isset($v)) $v = 0;
|
||||
++$v;
|
||||
$string = str_replace('{'.$v.'}',$this->es($var),$string);
|
||||
}
|
||||
return $string;
|
||||
|
||||
}
|
||||
|
||||
public function query($command) {
|
||||
|
||||
$result = $this->link->query($command);
|
||||
if ($result == NULL) throw new Exception("Query Error: ".$this->link->error." Query:".$command."");
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public function nonquery($command) {
|
||||
|
||||
if ($this->link->query($command) == NULL) throw new Exception("NonQuery Error: ".$this->link->error." Query:".$command."");
|
||||
|
||||
}
|
||||
|
||||
public function fetchfirst($command) {
|
||||
|
||||
$result = $this->fetcharray($command);
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public function fetcharray($command) {
|
||||
|
||||
$query = $this->link->query($command);
|
||||
$result = $query->fetch_array(MYSQLI_BOTH);
|
||||
$query->close();
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public function LastInsertId() {
|
||||
|
||||
$result = $this->fetchfirst("SELECT LAST_INSERT_ID();");
|
||||
return $result[0];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
7
WSDL/inc.variables.php
Executable file
7
WSDL/inc.variables.php
Executable file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
define("WEBSERVICE_NAME", "WSDL");
|
||||
define("DEBUG", false);
|
||||
define("ROOT_URL", "https://e5.2dev.pl/");
|
||||
|
||||
?>
|
||||
824
WSDL/inc.ws.methods.php
Executable file
824
WSDL/inc.ws.methods.php
Executable file
@@ -0,0 +1,824 @@
|
||||
<?php
|
||||
|
||||
$methodName = "";
|
||||
$db = null;
|
||||
|
||||
// aktualizuje oferte o status
|
||||
// w pole `type` nalezy podac `id_presta` zamowienia z CRM
|
||||
|
||||
function create_guid_2() {
|
||||
$microTime = microtime();
|
||||
list($a_dec, $a_sec) = explode(" ", $microTime);
|
||||
|
||||
$dec_hex = dechex($a_dec* 1000000);
|
||||
$sec_hex = dechex($a_sec);
|
||||
|
||||
ensure_length_2($dec_hex, 5);
|
||||
ensure_length_2($sec_hex, 6);
|
||||
|
||||
$guid = "";
|
||||
$guid .= $dec_hex;
|
||||
$guid .= create_guid_section_2(3);
|
||||
$guid .= '-';
|
||||
$guid .= create_guid_section_2(4);
|
||||
$guid .= '-';
|
||||
$guid .= create_guid_section_2(4);
|
||||
$guid .= '-';
|
||||
$guid .= create_guid_section_2(4);
|
||||
$guid .= '-';
|
||||
$guid .= $sec_hex;
|
||||
$guid .= create_guid_section_2(6);
|
||||
|
||||
return $guid;
|
||||
|
||||
}
|
||||
function create_guid_section_2($characters)
|
||||
{
|
||||
$return = "";
|
||||
for($i=0; $i<$characters; $i++)
|
||||
{
|
||||
$return .= dechex(mt_rand(0,15));
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function ensure_length_2(&$string, $length)
|
||||
{
|
||||
$strlen = strlen($string);
|
||||
if($strlen < $length)
|
||||
{
|
||||
$string = str_pad($string,$length,"0");
|
||||
}
|
||||
else if($strlen > $length)
|
||||
{
|
||||
$string = substr($string, 0, $length);
|
||||
}
|
||||
}
|
||||
|
||||
//*******************************CATEGORIES*
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmcategories',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'id' => array('name'=>'id','type'=>'xsd:string'),
|
||||
'name' => array('name'=>'name', 'type'=>'xsd:string'),
|
||||
'name_en' => array('name'=>'name_en', 'type'=>'xsd:string'),
|
||||
'ilosc' => array('name'=>'ilosc', 'type'=>'xsd:int'),
|
||||
'deleted' => array('name'=>'deleted', 'type'=>'xsd:int'),
|
||||
'description' => array('name'=>'description', 'type'=>'xsd:string')
|
||||
)
|
||||
);
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmcategories_array',
|
||||
'complexType',
|
||||
'array',
|
||||
'',
|
||||
'SOAP-ENC:Array',
|
||||
array(),
|
||||
array(
|
||||
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:ecmcategories[]')
|
||||
),
|
||||
'tns:ecmcategories'
|
||||
);
|
||||
$server->register(
|
||||
'ecm_get_categories',
|
||||
array('user_name'=>'xsd:string', 'password'=>'xsd:string', 'pricelist' => 'xsd:string'),
|
||||
array('return'=>'tns:ecmcategories_array'),
|
||||
$NAMESPACE);
|
||||
|
||||
function ecm_get_categories($user_name, $password, $pricelist) {
|
||||
|
||||
//$GLOBALS['db']->query("INSERT INTO log VALUES ('!!!!!')");
|
||||
|
||||
$return_array = array();
|
||||
|
||||
$db = new PDODB("mysql:host=".MYSQL_API_HOST.";dbname=".MYSQL_API_DATABASE.";port=".MYSQL_API_PORT,MYSQL_API_USER,MYSQL_API_PASSWORD);
|
||||
|
||||
|
||||
$query = $db->executeQuery("SELECT `c`.`id`, `c`.`name`, `c`.`name_en`, `c`.`description`, `c`.`deleted`, (SELECT count(`p`.`id`) FROM `crm`.`ecmproducts` `p` JOIN `crm`.`ecmpricebooks_ecmproducts` `pbp` ON
|
||||
`pbp`.`ecmpricebook_id`='".$pricelist."' AND `pbp`.`ecmproduct_id`=`p`.`id`
|
||||
WHERE `p`.`product_category_id`=`c`.`id`
|
||||
AND `pbp`.`deleted`='0') as `ilosc` FROM `crm`.`ecmproductcategories` `c`");
|
||||
foreach($db->executeReader($query) as $r) {
|
||||
$return_array[]=array("id"=>$r['id'],
|
||||
"name"=>$r['name'],
|
||||
"name_en"=>$r['name_en'],
|
||||
"ilosc"=>$r['ilosc'],
|
||||
"deleted"=>$r['deleted'],
|
||||
"description"=>$r['description']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* $query = $db->executeQuery("SELECT `c`.`id`, `c`.`name`, `c`.`name_en`, `c`.`description` FROM `ecmproductcategories` `c` where (SELECT count(`p`.`id`) FROM `ecmproducts` `p` JOIN `ecmpricebooks_ecmproducts` `pbp` ON `pbp`.`ecmpricebook_id`='".$pricelist."' AND `pbp`.`ecmproduct_id`=`p`.`id` WHERE `p`.`product_category_id`=`c`.`id` AND `pbp`.`deleted`='0') > 0 AND `c`.`deleted`='0'");
|
||||
foreach($db->executeReader($query) as $r) {
|
||||
|
||||
$return_array[]=array("id"=>$r['id'],
|
||||
"name"=>$r['name'],
|
||||
"name_en"=>$r['name_en'],
|
||||
"description"=>$r['description']);
|
||||
}*/
|
||||
|
||||
|
||||
return $return_array;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***********************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////
|
||||
|
||||
|
||||
|
||||
//
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmcategories_a',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'id' => array('name'=>'id','type'=>'xsd:string'),
|
||||
'name' => array('name'=>'name', 'type'=>'xsd:string'),
|
||||
'description' => array('name'=>'description', 'type'=>'xsd:string'),
|
||||
'ecmpricebook_id' => array('name'=>'ecmpricebook_id', 'type'=>'xsd:string'),
|
||||
'billing_address_street' => array('name'=>'billing_address_street', 'type'=>'xsd:string'),
|
||||
'billing_address_postalcode' => array('name'=>'billing_address_postalcode', 'type'=>'xsd:string'),
|
||||
'billing_address_city' => array('name'=>'billing_address_city', 'type'=>'xsd:string'),
|
||||
'phone_office' => array('name'=>'phone_office', 'type'=>'xsd:string')
|
||||
)
|
||||
);
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmcategories_a_array',
|
||||
'complexType',
|
||||
'array',
|
||||
'',
|
||||
'SOAP-ENC:Array',
|
||||
array(),
|
||||
array(
|
||||
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:ecmcategories[]')
|
||||
),
|
||||
'tns:ecmcategories_a'
|
||||
);
|
||||
$server->register(
|
||||
'ecm_get_categories_a',
|
||||
array('user_name'=>'xsd:string', 'password'=>'xsd:string', 'pricelist' => 'xsd:string'),
|
||||
array('return'=>'tns:ecmcategories_a_array'),
|
||||
$NAMESPACE);
|
||||
|
||||
function ecm_get_categories_a($user_name, $password, $date = "") {
|
||||
|
||||
|
||||
$return_array = array();
|
||||
|
||||
//$w = $GLOBALS['db']->query("SELECT `c`.`id`, `c`.`name`, `c`.`description` FROM `ecmproductcategories` `c` where `c`.`local_transportation`!='0' AND (SELECT count(`p`.`id`) FROM `ecmproducts` `p` JOIN `ecmpricebooks_ecmproducts` `pbp` ON `pbp`.`ecmpricebook_id`='".$pricelist."' AND `pbp`.`ecmproduct_id`=`p`.`id` WHERE `p`.`product_category_id`=`c`.`id` AND `pbp`.`deleted`='0') > 0 AND `c`.`deleted`='0'");
|
||||
|
||||
|
||||
$db = new PDODB("mysql:host=".MYSQL_API_HOST.";dbname=".MYSQL_API_DATABASE.";port=".MYSQL_API_PORT,MYSQL_API_USER,MYSQL_API_PASSWORD);
|
||||
|
||||
$query = $db->executeQuery("SELECT `a`.`ecmpricebook_id`, `a`.`shop_user`, `a`.`id`, `a`.`name`, `a`.`deleted`, `a`.`billing_address_street`, `a`.`billing_address_postalcode`, `a`.`billing_address_city`, `a`.`phone_office`, `a`.`vatid`, `a`.`is_vat_free` FROM `accounts` `a` ".($date != "" ? " WHERE `a`.`date_modified`>'".$date."'" : ""));
|
||||
foreach($db->executeReader($query) as $r) {
|
||||
|
||||
$return_array[]=array("id"=>$r['id'],
|
||||
"name"=>$r['name'],
|
||||
"description"=>$r['description'],
|
||||
"ecmpricebook_id"=>$r['ecmpricebook_id'],
|
||||
"billing_address_street"=>$r['billing_address_street'],
|
||||
"billing_address_postalcode"=>$r['billing_address_postalcode'],
|
||||
"billing_address_city"=>$r['billing_address_city'],
|
||||
"phone_office"=>$r['phone_office']
|
||||
);
|
||||
}
|
||||
return $return_array;
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
|
||||
//*******************************PRODUCTS*
|
||||
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmproducts',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'id' => array('name'=>'id','type'=>'xsd:string'),
|
||||
'name' => array('name'=>'name', 'type'=>'xsd:string'),
|
||||
'name_en' => array('name'=>'name_en', 'type'=>'xsd:string'),
|
||||
'description' => array('name'=>'description', 'type'=>'xsd:string'),
|
||||
'description_en' => array('name'=>'description_en', 'type'=>'xsd:string'),
|
||||
'deleted' => array('name'=>'deleted', 'type'=>'xsd:int'),
|
||||
'code' => array('name'=>'code', 'type'=>'xsd:string'),
|
||||
'manufacturer_id' => array('name'=>'manufacturer_id', 'type'=>'xsd:string'),
|
||||
'srp_price' => array('name'=>'srp_price', 'type'=>'xsd:float'),
|
||||
'srp_price_eur' => array('name'=>'srp_price_eur', 'type'=>'xsd:float'),
|
||||
'pl_vat' => array('name'=>'pl_vat', 'type'=>'xsd:float'),
|
||||
'image' => array('name'=>'image', 'type'=>'xsd:string'),
|
||||
'popular' => array('name'=>'popular', 'type'=>'xsd:string'),
|
||||
'stock_value' => array('name'=>'stock_value', 'type'=>'xsd:int')
|
||||
)
|
||||
);
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmproducts_array',
|
||||
'complexType',
|
||||
'array',
|
||||
'',
|
||||
'SOAP-ENC:Array',
|
||||
array(),
|
||||
array(
|
||||
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:ecmproducts[]')
|
||||
),
|
||||
'tns:ecmproducts'
|
||||
);
|
||||
$server->register(
|
||||
'ecm_get_products2',
|
||||
array('user_name'=>'xsd:string', 'password'=>'xsd:string', 'category' => 'xsd:string', 'lang' => 'xsd:int'),
|
||||
array('return'=>'tns:ecmproducts_array'),
|
||||
$NAMESPACE);
|
||||
|
||||
function ecm_get_products2($user_name, $password, $category, $lang, $pricebook, $stock = "", $date = "") {
|
||||
|
||||
|
||||
if ($lang == 1) $lang = "pl";
|
||||
if ($lang == 2) $lang = "en";
|
||||
|
||||
$return_array = array();
|
||||
|
||||
$db = new PDODB("mysql:host=".MYSQL_API_HOST.";dbname=".MYSQL_API_DATABASE.";port=".MYSQL_API_PORT,MYSQL_API_USER,MYSQL_API_PASSWORD);
|
||||
|
||||
$query = $db->executeQuery("SELECT `stock`.`quantity`, `p`.`id`, `p`.`name`, `l`.`long_description`,
|
||||
`l_en`.`short_description` as `name_en`, `l_en`.`long_description` as `long_description_en`,
|
||||
`pbp`.`deleted`,
|
||||
`p`.`code`, `p`.`manufacturer_id`, `p`.`srp_price`, `p`.`srp_price_eur`,
|
||||
`v`.`value`, `p`.`product_picture`, `pbp`.`popular` FROM `crm`.`ecmproducts` `p`
|
||||
JOIN `crm`.`ecmvats` `v` ON `v`.`id`=`p`.`vat_id` AND `v`.`deleted`='0'
|
||||
JOIN `crm`.`ecmpricebooks_ecmproducts` `pbp` ON `pbp`.`ecmproduct_id`=`p`.`id`
|
||||
AND `pbp`.`product_category_id`='".$category."' JOIN `crm`.`ecmproduct_language` `l`
|
||||
ON `l`.`ecmproduct_id`=`p`.`id` AND `l`.`language`='pl'
|
||||
JOIN `crm`.`ecmproduct_language` `l_en`
|
||||
ON `l_en`.`ecmproduct_id`=`p`.`id` AND `l_en`.`language`='en'
|
||||
|
||||
LEFT JOIN `crm`.`ecmstockstates` `stock` ON `stock`.`stock_id`='".$stock."' and `stock`.`product_id`=`p`.`id`
|
||||
|
||||
".($date != "" ? "WHERE `p`.`date_modified`>'".$date."'" : "")." group by `p`.`id`");
|
||||
foreach($db->executeReader($query) as $r) {
|
||||
|
||||
|
||||
|
||||
$return_array[]=array("id"=>$r['id'],
|
||||
"name"=>$r['name'],
|
||||
"name_en"=>$r['name_en'],
|
||||
"description"=>$r['long_description'],
|
||||
"description_en"=>$r['long_description_en'],
|
||||
"deleted"=>$r['deleted'],
|
||||
"code"=>$r['code'],
|
||||
"manufacturer_id"=>$r['manufacturer_id'],
|
||||
"srp_price"=>$r['srp_price'],
|
||||
"srp_price_eur"=>$r['srp_price_eur'],
|
||||
"pl_vat"=>$r['value'],
|
||||
"image"=>$r['product_picture'],
|
||||
"popular"=>$r['popular'],
|
||||
"stock_value"=>$r['quantity']
|
||||
);
|
||||
}
|
||||
return $return_array;
|
||||
|
||||
}
|
||||
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmproducts',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'id' => array('name'=>'id','type'=>'xsd:string'),
|
||||
'name' => array('name'=>'name', 'type'=>'xsd:string'),
|
||||
'name_en' => array('name'=>'name_en', 'type'=>'xsd:string'),
|
||||
'description' => array('name'=>'description', 'type'=>'xsd:string'),
|
||||
'description_en' => array('name'=>'description_en', 'type'=>'xsd:string'),
|
||||
'deleted' => array('name'=>'deleted', 'type'=>'xsd:int'),
|
||||
'code' => array('name'=>'code', 'type'=>'xsd:string'),
|
||||
'manufacturer_id' => array('name'=>'manufacturer_id', 'type'=>'xsd:string'),
|
||||
'srp_price' => array('name'=>'srp_price', 'type'=>'xsd:float'),
|
||||
'srp_price_eur' => array('name'=>'srp_price_eur', 'type'=>'xsd:float'),
|
||||
'pl_vat' => array('name'=>'pl_vat', 'type'=>'xsd:float'),
|
||||
'image' => array('name'=>'image', 'type'=>'xsd:string'),
|
||||
'popular' => array('name'=>'popular', 'type'=>'xsd:string'),
|
||||
'stock_value' => array('name'=>'stock_value', 'type'=>'xsd:int')
|
||||
)
|
||||
);
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmproducts_array',
|
||||
'complexType',
|
||||
'array',
|
||||
'',
|
||||
'SOAP-ENC:Array',
|
||||
array(),
|
||||
array(
|
||||
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:ecmproducts[]')
|
||||
),
|
||||
'tns:ecmproducts'
|
||||
);
|
||||
$server->register(
|
||||
'ecm_get_products',
|
||||
array('user_name'=>'xsd:string', 'password'=>'xsd:string', 'category' => 'xsd:string', 'lang' => 'xsd:int'),
|
||||
array('return'=>'tns:ecmproducts_array'),
|
||||
$NAMESPACE);
|
||||
|
||||
function ecm_get_products($user_name, $password, $category, $lang, $pricebook, $stock, $date = "") {
|
||||
|
||||
|
||||
if ($lang == 1) $lang = "pl";
|
||||
if ($lang == 2) $lang = "en";
|
||||
|
||||
$return_array = array();
|
||||
|
||||
$db = new PDODB("mysql:host=".MYSQL_API_HOST.";dbname=".MYSQL_API_DATABASE.";port=".MYSQL_API_PORT,MYSQL_API_USER,MYSQL_API_PASSWORD);
|
||||
|
||||
$query = $db->executeQuery("SELECT `stock`.`quantity`, `p`.`id`, `p`.`name`, `l`.`long_description`, `l_en`.`short_description` as `name_en`, `l_en`.`long_description` as `long_description_en`, `pbp`.`deleted`, `p`.`code`, `p`.`manufacturer_id`, `p`.`srp_price`, `p`.`srp_price_eur`, `v`.`value`, `p`.`product_picture`, `pbp`.`popular` FROM `ecmproducts` `p` JOIN `ecmvats` `v` ON `v`.`id`=`p`.`vat_id` AND `v`.`deleted`='0' JOIN `ecmpricebooks_ecmproducts` `pbp` ON `pbp`.`ecmproduct_id`=`p`.`id` AND `pbp`.`ecmpricebook_id`='".$pricebook."' JOIN `ecmproduct_language` `l` ON `l`.`ecmproduct_id`=`p`.`id` AND `l`.`language`='pl' JOIN `ecmproduct_language` `l_en` ON `l_en`.`ecmproduct_id`=`p`.`id` AND `l_en`.`language`='en'
|
||||
LEFT JOIN `ecmstockstates` `stock` ON `stock`.`stock_id`='".$stock."' and `stock`.`product_id`=`p`.`id`
|
||||
WHERE `p`.`product_category_id`='".$category."'".($date != "" ? " AND `p`.`date_modified`>'".$date."'" : "")." group by `p`.`id`");
|
||||
foreach($db->executeReader($query) as $r) {
|
||||
|
||||
|
||||
$return_array[]=array("id"=>$r['id'],
|
||||
"name"=>$r['name'],
|
||||
"name_en"=>$r['name_en'],
|
||||
"description"=>$r['long_description'],
|
||||
"description_en"=>$r['long_description'],
|
||||
"deleted"=>$r['deleted'],
|
||||
"code"=>$r['code'],
|
||||
"manufacturer_id"=>$r['manufacturer_id'],
|
||||
"srp_price"=>$r['srp_price'],
|
||||
"srp_price_eur"=>$r['srp_price_eur'],
|
||||
"pl_vat"=>$r['value'],
|
||||
"image"=>$r['product_picture'],
|
||||
"popular"=>$r['popular'],
|
||||
"stock_value"=>$r['quantity']
|
||||
);
|
||||
}
|
||||
return $return_array;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//*******************************PRICEBOOK PRODUCTS*
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmpricebook_products',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'ecmproduct_id' => array('name'=>'ecmproduct_id', 'type'=>'xsd:string'),
|
||||
'price' => array('name'=>'price', 'type'=>'xsd:float'),
|
||||
'popular' => array('name'=>'popular', 'type'=>'xsd:int'),
|
||||
'deleted' => array('name'=>'deleted', 'type'=>'xsd:int'),
|
||||
'vat' => array('name'=>'vat', 'type'=>'xsd:int')
|
||||
)
|
||||
);
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmpricebook_products_array',
|
||||
'complexType',
|
||||
'array',
|
||||
'',
|
||||
'SOAP-ENC:Array',
|
||||
array(),
|
||||
array(
|
||||
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:ecmpricebook_products[]')
|
||||
),
|
||||
'tns:ecmpricebook_products'
|
||||
);
|
||||
$server->register(
|
||||
'ecm_get_pricebook_products',
|
||||
array('user_name'=>'xsd:string', 'password'=>'xsd:string'),
|
||||
array('return'=>'tns:ecmpricebook_products_array'),
|
||||
$NAMESPACE);
|
||||
|
||||
function ecm_get_pricebook_products($user_name, $password, $pricebook) {
|
||||
|
||||
|
||||
$return_array = array();
|
||||
//$w=$GLOBALS['db']->query("SELECT `ecmproduct_id`, `price`, `popular`, `deleted` FROM `ecmpricebooks_ecmproducts` WHERE `ecmpricebook_id`='".$pricebook."'".($date != "" ? " AND `date_modified`>'".$date."'" : ""));
|
||||
//$w=$GLOBALS['db']->query("SELECT `ecmproduct_id`, `price`, `popular`, `deleted` FROM `ecmpricebooks_ecmproducts` WHERE `ecmpricebook_id`='".$pricebook."'");
|
||||
|
||||
|
||||
$db = new PDODB("mysql:host=".MYSQL_API_HOST.";dbname=".MYSQL_API_DATABASE.";port=".MYSQL_API_PORT,MYSQL_API_USER,MYSQL_API_PASSWORD);
|
||||
|
||||
$query = $db->executeQuery("SELECT `pp`.`ecmproduct_id`, `pp`.`price`, `pp`.`popular`, `pp`.`deleted`, `p`.`vat_value` FROM
|
||||
`crm`.`ecmpricebooks_ecmproducts` `pp`
|
||||
JOIN `crm`.`ecmproducts` `p` ON `p`.`id`=`pp`.`ecmproduct_id`
|
||||
WHERE `pp`.`ecmpricebook_id`='".$pricebook."'");
|
||||
foreach($db->executeReader($query) as $r) {
|
||||
|
||||
|
||||
$return_array[]=array("id"=>$r['id'],
|
||||
"ecmproduct_id"=>$r['ecmproduct_id'],
|
||||
"price"=>$r['price'],
|
||||
"popular"=>$r['popular'],
|
||||
"deleted"=>$r['deleted'],
|
||||
"vat"=>$r['vat_value']
|
||||
);
|
||||
}
|
||||
return $return_array;
|
||||
|
||||
}
|
||||
|
||||
//*******************************PRICEBOOKS*
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmpricebooks',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'id' => array('name'=>'id', 'type'=>'xsd:string'),
|
||||
'name' => array('name'=>'name', 'type'=>'xsd:string')
|
||||
)
|
||||
);
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmpricebooks_array',
|
||||
'complexType',
|
||||
'array',
|
||||
'',
|
||||
'SOAP-ENC:Array',
|
||||
array(),
|
||||
array(
|
||||
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:ecmpricebooks[]')
|
||||
),
|
||||
'tns:ecmpricebooks'
|
||||
);
|
||||
$server->register(
|
||||
'ecm_get_pricebooks',
|
||||
array('user_name'=>'xsd:string', 'password'=>'xsd:string'),
|
||||
array('return'=>'tns:ecmpricebooks_array'),
|
||||
$NAMESPACE);
|
||||
|
||||
function ecm_get_pricebooks($user_name, $password, $pricebook) {
|
||||
|
||||
|
||||
$return_array = array();
|
||||
//$w=$GLOBALS['db']->query("SELECT `id`, `name` FROM `ecmpricebooks` WHERE `id`='".$pricebook."'");
|
||||
|
||||
$db = new PDODB("mysql:host=".MYSQL_API_HOST.";dbname=".MYSQL_API_DATABASE.";port=".MYSQL_API_PORT,MYSQL_API_USER,MYSQL_API_PASSWORD);
|
||||
|
||||
$query = $db->executeQuery("SELECT `id`, `name` FROM `ecmpricebooks`");
|
||||
foreach($db->executeReader($query) as $r) {
|
||||
$return_array[]=array("id"=>$r['id'],
|
||||
"name"=>$r['name']
|
||||
);
|
||||
}
|
||||
return $return_array;
|
||||
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
/**************************************/
|
||||
/* potwierdzenie sprzedazy */
|
||||
|
||||
|
||||
$server->register(
|
||||
'ecm_add_order_from_shop',
|
||||
array('user_name'=>'xsd:string', 'password'=>'xsd:string', 'order' => 'xsd:string'),
|
||||
array('return'=>'xsd:string'),
|
||||
$NAMESPACE);
|
||||
|
||||
|
||||
|
||||
function ecm_add_order_from_shop($user_name, $password, $order, $presta, $user, $a, $b, $c, $d) {
|
||||
|
||||
|
||||
$x = "";
|
||||
$x = "S";
|
||||
$y = "false";
|
||||
|
||||
|
||||
|
||||
if(!empty($order)) {
|
||||
|
||||
$y = "ok";
|
||||
|
||||
|
||||
try {
|
||||
|
||||
$order = unserialize(base64_decode($order));
|
||||
|
||||
|
||||
|
||||
//return print_r($order);
|
||||
if(!empty($order) && is_array($order)) {
|
||||
|
||||
|
||||
|
||||
if($order['Order-Header']['OrderNumber'] == "ORDERTEST1234")
|
||||
return "IDTEST1234";
|
||||
|
||||
else {
|
||||
require_once("modules/EcmSales/EcmSale.php");
|
||||
$focus=new EcmSale();
|
||||
|
||||
|
||||
|
||||
$template_id="97700b0d-fbe9-e366-4016-4b260f058a47";
|
||||
|
||||
$db = new PDODB("mysql:host=".MYSQL_API_HOST.";dbname=".MYSQL_API_DATABASE.";port=".MYSQL_API_PORT,MYSQL_API_USER,MYSQL_API_PASSWORD);
|
||||
|
||||
|
||||
|
||||
|
||||
$focus->template_id=$template_id;
|
||||
//$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select name from ecmdocumenttemplates where id='".$template_id."'"));
|
||||
//$query = $db->executeQuery(query("select name from ecmdocumenttemplates where id='".$template_id."'"));
|
||||
|
||||
$row = $db->fetchFirstRow("select name from ecmdocumenttemplates where id='".$template_id."'");
|
||||
$focus->template_name=$row['name'];
|
||||
$focus->setTemplate();
|
||||
$focus->number=$focus->generateNumber();
|
||||
$focus->document_no=$focus->formatNumber();
|
||||
$focus->currency_id="PLN";
|
||||
$focus->ecmlanguage="pl_pl";
|
||||
$focus->status="s10";
|
||||
$focus->type="sales_order";
|
||||
$focus->modified_user_id="d09b87cf-efff-2f7c-a859-4ba38402488f";
|
||||
$focus->created_by="d09b87cf-efff-2f7c-a859-4ba38402488f";
|
||||
|
||||
$pr=$order['Order-Lines'];
|
||||
$x = "ok";
|
||||
include_once("modules/Accounts/Account.php");
|
||||
//$ww=$GLOBALS['db']->query("select count(*) as c from accounts where b2clogin ='".$order['Order-Parties']['Buyer']['Login']."' and deleted='0'");
|
||||
//$ww=$GLOBALS['db']->query("select count(*) as c from accounts where `id` ='".$order['Order-Parties']['Buyer']['Login']."' and deleted='0'");
|
||||
$row = $db->fetchFirstRow("select count(*) as c from accounts where `id` ='".$order['Order-Parties']['Buyer']['Login']."' and deleted='0'");
|
||||
//$rr=$GLOBALS['db']->fetchByAssoc($ww);
|
||||
$focus->parent_id="getmir";
|
||||
$focus->description=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['Description']);
|
||||
|
||||
|
||||
// if($rr['c']==0){
|
||||
// $account=new Account();
|
||||
$account->ownership="getmir";
|
||||
// $account->name=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['Name']);
|
||||
// $account->b2clogin=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['Login']);
|
||||
// $account->billing_address_street=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['StreetAndNumber']);
|
||||
// $account->billing_address_postalcode=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['PostalCode']);
|
||||
// $account->billing_address_city=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['CityName']);
|
||||
// $account->shipping_address_street=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['DeliveryPoint']['StreetAndNumber']);
|
||||
// $account->shipping_address_postalcode=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['DeliveryPoint']['PostalCode']);
|
||||
// $account->shipping_address_city=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['DeliveryPoint']['CityName']);
|
||||
// $focus->parent_id=create_guid_2();
|
||||
// $GLOBALS['db']->query("insert into accounts set id='".$focus->parent_id."',name='".$account->name."',billing_address_street='".$account->billing_address_street."',billing_address_postalcode='".$account->billing_address_postalcode."',billing_address_city='".$account->billing_address_city."',shipping_address_street='".$account->shipping_address_street."',shipping_address_postalcode='".$account->shipping_address_postalcode."',shipping_address_city='".$account->shipping_address_city."', b2clogin='".$account->b2clogin."'");
|
||||
// }
|
||||
// else{
|
||||
|
||||
|
||||
//$w=$GLOBALS['db']->query("select id from accounts where b2clogin = '".$order['Order-Parties']['Buyer']['Login']."' and deleted='0'");
|
||||
//$w=$GLOBALS['db']->query("select `id` from `accounts` where `id` = '".$order['Order-Parties']['Buyer']['Login']."' and `deleted`='0'");
|
||||
$row = $db->fetchFirstRow("select `id` from `accounts` where `id` = '".$order['Order-Parties']['Buyer']['Login']."' and `deleted`='0'");
|
||||
//$r=$GLOBALS['db']->fetchByAssoc($w);
|
||||
$account=new Account();
|
||||
//update account, maybe sth. change
|
||||
|
||||
// $GLOBALS['db']->query("update accounts set name='".$account->name."',billing_address_street='".$account->billing_address_street."',billing_address_postalcode='".$account->billing_address_postalcode."',billing_address_city='".$account->billing_address_city."'"."',shipping_address_street='".$account->shipping_address_street."',shipping_address_postalcode='".$account->shipping_address_postalcode."',shipping_address_city='".$account->shipping_address_city."'where id='".$r['id']."'");
|
||||
|
||||
// $account->retrieve($r['id']);
|
||||
$focus->parent_id=$row['id'];
|
||||
//}
|
||||
$focus->assigned_user_id="d09b87cf-efff-2f7c-a859-4ba38402488f";
|
||||
$focus->register_date=$order['Order-Header']['OrderDate'];
|
||||
$focus->delivery_date=$order['Order-Header']['ExpectedDeliveryDate'];
|
||||
//$focus->supplier_code=3442;
|
||||
$focus->order_no=$order['Order-Header']['OrderNumber'];
|
||||
$focus->ecmlanguage="pl_pl";
|
||||
$focus->ecmpaymentcondition_id=$order['Order-Parties']['Buyer']['PaymentConditionId'];
|
||||
|
||||
$focus->parent_name=$row["name"];//$account->name;
|
||||
$focus->parent_address_street=$a;//$account->shipping_address_street;
|
||||
$focus->parent_address_city=$b;//$account->shipping_address_city;
|
||||
$focus->parent_address_postalcode=$c;//$account->shipping_address_postalcode;
|
||||
$focus->parent_address_country=$d;//$account->shipping_address_country;
|
||||
|
||||
$ra=array();
|
||||
$total=0;
|
||||
|
||||
|
||||
|
||||
if(count($pr)>0){
|
||||
foreach($pr as $prod){
|
||||
$product_id="";
|
||||
//$w=$GLOBALS['db']->query("select id as ecmproduct_id from ecmproducts where code='".$prod['Line']['Line-Item']['CODE']."' and deleted='0' and code NOT LIKE '%_w' and code NOT LIKE '%_z' and code NOT LIKE '%_W' and code NOT LIKE '%_Z'");
|
||||
//$w=$GLOBALS['db']->query("select `id` as `ecmproduct_id` from `ecmproducts` where `id`='".$prod['Line']['Line-Item']['CODE']."' and `deleted`='0' and `code` NOT LIKE '%_w' and `code` NOT LIKE '%_z' and `code` NOT LIKE '%_W' and `code` NOT LIKE '%_Z'");
|
||||
$row = $db->fetchFirstRow("select `id` as `ecmproduct_id` from `ecmproducts` where `id`='".$prod['Line']['Line-Item']['CODE']."' and `deleted`='0' and `code` NOT LIKE '%_w' and `code` NOT LIKE '%_z' and `code` NOT LIKE '%_W' and `code` NOT LIKE '%_Z'");
|
||||
// $r=$GLOBALS['db']->fetchByAssoc($w);
|
||||
$product_id=$row['ecmproduct_id'];
|
||||
|
||||
$wp=$GLOBALS['db']->query("select * from `ecmproducts` where `id`='".$product_id."'");
|
||||
$rppp=$GLOBALS['db']->fetchByAssoc($wp);
|
||||
$product_code=$rppp['code'];
|
||||
$product_name=$rppp['name'];
|
||||
$vat_id=$rppp['vat_id'];
|
||||
$vat_name=$rppp['vat_name'];
|
||||
$vat_value=$rppp['vat_value'];
|
||||
|
||||
$return_array['id'] = $product_id;
|
||||
$return_array['code'] = $product_code;
|
||||
$return_array['name'] = $product_name;
|
||||
$return_array['quantity'] = $prod['Line']['Line-Item']['OrderedQuantity'];
|
||||
$return_array['price'] = $prod['Line']['Line-Item']['OrderedUnitNetPrice'];
|
||||
$return_array['discount'] = 0;
|
||||
$return_array['total'] = $prod['Line']['Line-Item']['OrderedQuantity']*$prod['Line']['Line-Item']['OrderedUnitNetPrice'];
|
||||
$return_array['unit_id'] = 1;
|
||||
$return_array['unit_name'] = 'szt.';
|
||||
$return_array['vat_id'] = $vat_id;
|
||||
$return_array['vat_name'] = $vat_name;
|
||||
$return_array['vat_value'] = $vat_value;
|
||||
$return_array['currency_id'] = 'PLN';
|
||||
$return_array['recipient_code'] = $prod['Line']['Line-Item']['BuyerItemCode'];
|
||||
$total+=$return_array['quantity']*$return_array['price']*(1+$vat_value/100);
|
||||
$ra[]=$return_array;
|
||||
}
|
||||
}
|
||||
$focus->position_list = $ra;
|
||||
$return_id=$focus->save_from_shop($presta, $user);
|
||||
$GLOBALS['db']->query("update `ecmsales` set `total`='".$total."' where `id`='".$return_id."'");
|
||||
|
||||
|
||||
return $return_id;
|
||||
|
||||
|
||||
//return print_r(mysql_error()."mm", true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch(Exception $e) {}
|
||||
|
||||
}
|
||||
|
||||
return $y;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**************************************/
|
||||
|
||||
|
||||
//*******************************accounts_shop*
|
||||
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmcustomer_add',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'status' => array('name'=>'status','type'=>'xsd:string')
|
||||
)
|
||||
);
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmcustomer_add_array',
|
||||
'complexType',
|
||||
'array',
|
||||
'',
|
||||
'SOAP-ENC:Array',
|
||||
array(),
|
||||
array(
|
||||
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:ecmcategories[]')
|
||||
),
|
||||
'tns:ecmcustomer_add'
|
||||
);
|
||||
$server->register(
|
||||
'ecm_get_customer_add',
|
||||
array('user_name'=>'xsd:string', 'password'=>'xsd:string', 'pricelist' => 'xsd:string'),
|
||||
array('return'=>'tns:ecmcustomer_add_array'),
|
||||
$NAMESPACE);
|
||||
|
||||
function ecm_get_customer_add($user_name, $password, $fullname = "", $pricebook = "", $shop_user = "", $email = "", $edit = false, $id = "", $street = "", $company="", $city = "", $code = "", $nip = "", $phone = "") {
|
||||
|
||||
$return_array = array();
|
||||
|
||||
if (!$edit) {
|
||||
$db = new PDODB("mysql:host=".MYSQL_API_HOST.";dbname=".MYSQL_API_DATABASE.";port=".MYSQL_API_PORT,MYSQL_API_USER,MYSQL_API_PASSWORD);
|
||||
$getID = create_guid();
|
||||
$query = $db->executeQuery("INSERT INTO `accounts` SET `id`='".$getID."', `name`='".$fullname."', `date_entered`='".date("Y-m-d H:i:s")."', `date_modified`='".date("Y-m-d H:i:s")."', `ecmpricebook_id`='".$pricebook."', `shop_user`='".$shop_user."', `email`='".$email."'");
|
||||
|
||||
$return_array[]=array("status"=>$getID);
|
||||
|
||||
} else {
|
||||
|
||||
if ($company != "") $fullname = $company;
|
||||
$db = new PDODB("mysql:host=".MYSQL_API_HOST.";dbname=".MYSQL_API_DATABASE.";port=".MYSQL_API_PORT,MYSQL_API_USER,MYSQL_API_PASSWORD);
|
||||
$query = $db->executeQuery("UPDATE `accounts` SET `name`='".$fullname."', `shipping_address_postalcode`='".$code."', `shipping_address_street`='".$street."', `shipping_address_city`='".$city."', `billing_address_postalcode`='".$code."', `billing_address_street`='".$street."', `billing_address_city`='".$city."', `vatid`='".$nip."', `phone_office`='".$phone."', `date_modified`='".date("Y-m-d H:i:s")."' WHERE `id`='".$id."'");
|
||||
|
||||
$return_array[]=array("status"=>'ok');
|
||||
|
||||
}
|
||||
return $return_array;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmcategories2',
|
||||
'complexType',
|
||||
'struct',
|
||||
'all',
|
||||
'',
|
||||
array(
|
||||
'id' => array('name'=>'id','type'=>'xsd:string')
|
||||
// 'name' => array('name'=>'name', 'type'=>'xsd:string'),
|
||||
// 'name_en' => array('name'=>'name_en', 'type'=>'xsd:string'),
|
||||
// 'description' => array('name'=>'description', 'type'=>'xsd:string'),
|
||||
)
|
||||
);
|
||||
|
||||
$server->wsdl->addComplexType(
|
||||
'ecmcategories_array2',
|
||||
'complexType',
|
||||
'array',
|
||||
'',
|
||||
'SOAP-ENC:Array',
|
||||
array(),
|
||||
array(
|
||||
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:ecmcategories2[]')
|
||||
),
|
||||
'tns:ecmcategories2'
|
||||
);
|
||||
$server->register(
|
||||
'ecm_get_categories2',
|
||||
array('user_name'=>'xsd:string', 'password'=>'xsd:string', 'pricelist' => 'xsd:string'),
|
||||
array('return'=>'tns:ecmcategories_array2'),
|
||||
$NAMESPACE);
|
||||
|
||||
function ecm_get_categories2($user_name, $password, $pricelist) {
|
||||
|
||||
|
||||
$return_array = array();
|
||||
|
||||
$db = new PDODB("mysql:host=".MYSQL_API_HOST.";dbname=".MYSQL_API_DATABASE.";port=".MYSQL_API_PORT,MYSQL_API_USER,MYSQL_API_PASSWORD);
|
||||
|
||||
$query = $db->executeQuery("SELECT `id` FROM `ecmproducts` LIMIT 10");
|
||||
foreach($db->executeReader($query) as $row) {
|
||||
|
||||
//echo $row[0]."<br>";
|
||||
|
||||
$return_array[]=array("id"=>$row[0]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return $return_array;
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
25
WSDL/inc.ws.types.php
Executable file
25
WSDL/inc.ws.types.php
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
function Register_Types($server) {
|
||||
|
||||
$server->wsdl->addComplexType('UpdateOrder','complexType','struct','sequence','',
|
||||
array (
|
||||
|
||||
'outputInfo' => array('type' => 'tns:OutputInfo')
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
$server->wsdl->addComplexType('Aktualizuj','complexType','struct','sequence','',
|
||||
array (
|
||||
|
||||
'data'=>array('name'=>'data','type'=>'xsd:int'),
|
||||
|
||||
'outputInfo' => array('type' => 'tns:OutputInfo')
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
159
WSDL/pdo.db.php
Executable file
159
WSDL/pdo.db.php
Executable file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
class PDODB extends PDO
|
||||
{
|
||||
private $error;
|
||||
private $lastQuery;
|
||||
private $numRows;
|
||||
|
||||
|
||||
public function __construct($dsn, $user="", $passwd="", $timeout=30000)
|
||||
{
|
||||
$options = array(
|
||||
//PDO::ATTR_PERSISTENT => true,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_TIMEOUT => $timeout,
|
||||
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' );
|
||||
|
||||
try
|
||||
{
|
||||
parent::__construct($dsn, $user, $passwd, $options);
|
||||
$this->error = null;
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
$this->error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function getLastQuery()
|
||||
{
|
||||
return $this->lastQuery;
|
||||
}
|
||||
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
public function rowCount()
|
||||
{
|
||||
return $this->numRows;
|
||||
}
|
||||
|
||||
|
||||
public function executeQuery($query, $params=array())
|
||||
{
|
||||
try
|
||||
{
|
||||
$_query = $this->prepare($query);
|
||||
$_query->execute($params);
|
||||
$this->numRows = $_query->rowCount();
|
||||
$this->error = null;
|
||||
$this->lastQuery = $_query->queryString;
|
||||
return $_query;
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
$this->error = $e->getMessage();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function executeReader($executed_query)
|
||||
{
|
||||
try
|
||||
{
|
||||
$results = $executed_query->fetchAll(PDO::FETCH_BOTH);
|
||||
$this->error = null;
|
||||
return $results;
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
$this->error = $e->getMessage();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchFirstRow($query, $params=array())
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
$executed_query = $this->executeQuery($query, $params);
|
||||
$this->lastQuery = $query;
|
||||
|
||||
$results = $executed_query->fetch(PDO::FETCH_BOTH);
|
||||
$this->error = null;
|
||||
return $results;
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
$this->error = $e->getMessage();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function executeNonQuery($query)
|
||||
{
|
||||
try
|
||||
{
|
||||
$_rows = $this->exec($query);
|
||||
$this->error = null;
|
||||
$this->lastQuery = $query;
|
||||
return $_rows;
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
$this->error = $e->getMessage();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
// nonquery
|
||||
//$query = $db->executeQuery("INSERT INTO pdo_test VALUES (null,now(), :v);",array('v' => 'ABC'.rand().'X'));
|
||||
$query = $db->executeQuery("INSERT INTO pdo_test VALUES (null,now(), ?);",array('ABC'.rand().'X'));
|
||||
print("<pre>getLastQuery: ".$db->getLastQuery()."\nError: ".$db->GetError()."</pre><br>");
|
||||
print("inserted id: ".$db->lastInsertId()."<hr>");
|
||||
|
||||
// select
|
||||
$query = $db->executeQuery("SELECT * FROM pdo_test WHERE val like :v LIMIT 10;",array('v'=>'%5%'));
|
||||
foreach($db->executeReader($query) as $row)
|
||||
{
|
||||
echo "ROW: ".$row['created']." ".$row['val']."<br>";
|
||||
}
|
||||
print("<pre>getLastQuery: ".$db->getLastQuery()."\nError: ".$db->GetError()."</pre><hr>");
|
||||
|
||||
|
||||
//procedura
|
||||
$query = $db->executeQuery("CALL `pdo_test_proc`();");
|
||||
foreach($db->executeReader($query) as $row)
|
||||
{
|
||||
echo "ROW: ".$row['result']."<br>";
|
||||
}
|
||||
print("<pre>getLastQuery: ".$db->getLastQuery()."\nError: ".$db->GetError()."</pre><hr>");
|
||||
|
||||
//procedura drugi raz
|
||||
$firstRow = $db->fetchFirstRow("CALL `pdo_test_proc`();");
|
||||
echo "ROW: ".$firstRow['result']."<br>";
|
||||
print("<pre>getLastQuery: ".$db->getLastQuery()."\nError: ".$db->GetError()."</pre><hr>");
|
||||
|
||||
|
||||
//prosty select
|
||||
$firstRow = $db->fetchFirstRow("SELECT count(*) FROM `pdo_test`;");
|
||||
echo "ROW: ".$firstRow[0]."<br>";
|
||||
print("<pre>getLastQuery: ".$db->getLastQuery()."\nError: ".$db->GetError()."</pre><hr>");
|
||||
*
|
||||
* */
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
46
WebToLeadCapture.php
Executable file
46
WebToLeadCapture.php
Executable file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*********************************************************************************
|
||||
|
||||
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________..
|
||||
********************************************************************************/
|
||||
|
||||
header('HTTP/1.1 301 Moved Permanently');
|
||||
header('Location: index.php?entryPoint=WebToLeadCapture&'.$_SERVER["QUERY_STRING"]);
|
||||
?>
|
||||
474
XTemplate/xtpl.php
Executable file
474
XTemplate/xtpl.php
Executable file
@@ -0,0 +1,474 @@
|
||||
<?php
|
||||
|
||||
class XTemplate {
|
||||
|
||||
/*
|
||||
xtemplate class 0.2.4-3
|
||||
html generation with templates - fast & easy
|
||||
copyright (c) 2000 barnab<61>s debreceni [cranx@users.sourceforge.net]
|
||||
code optimization by Ivar Smolin <okul@linux.ee> 14-march-2001
|
||||
latest stable & CVS version always available @ http://sourceforge.net/projects/xtpl
|
||||
|
||||
tested with php 3.0.11 and 4.0.4pl1
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public License
|
||||
version 2.1 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details at
|
||||
http://www.gnu.org/copyleft/lgpl.html
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/***[ variables ]***********************************************************/
|
||||
|
||||
var $filecontents=""; /* raw contents of template file */
|
||||
var $blocks=array(); /* unparsed blocks */
|
||||
var $parsed_blocks=array(); /* parsed blocks */
|
||||
var $block_parse_order=array(); /* block parsing order for recursive parsing (sometimes reverse:) */
|
||||
var $sub_blocks=array(); /* store sub-block names for fast resetting */
|
||||
var $VARS=array(); /* variables array */
|
||||
var $alternate_include_directory = "";
|
||||
|
||||
var $file_delim="/\{FILE\s*\"([^\"]+)\"\s*\}/m"; /* regexp for file includes */
|
||||
var $block_start_delim="<!-- "; /* block start delimiter */
|
||||
var $block_end_delim="-->"; /* block end delimiter */
|
||||
var $block_start_word="BEGIN:"; /* block start word */
|
||||
var $block_end_word="END:"; /* block end word */
|
||||
|
||||
/* this makes the delimiters look like: <!-- BEGIN: block_name --> if you use my syntax. */
|
||||
|
||||
var $NULL_STRING=array(""=>""); /* null string for unassigned vars */
|
||||
var $NULL_BLOCK=array(""=>""); /* null string for unassigned blocks */
|
||||
var $mainblock="";
|
||||
var $ERROR="";
|
||||
var $AUTORESET=1; /* auto-reset sub blocks */
|
||||
|
||||
/***[ constructor ]*********************************************************/
|
||||
|
||||
function XTemplate ($file, $alt_include = "", $mainblock="main") {
|
||||
$this->alternate_include_directory = $alt_include;
|
||||
$this->mainblock=$mainblock;
|
||||
$this->filecontents=$this->r_getfile($file); /* read in template file */
|
||||
//if(substr_count($file, 'backup') == 1)_ppd($this->filecontents);
|
||||
$this->blocks=$this->maketree($this->filecontents,$mainblock); /* preprocess some stuff */
|
||||
//$this->scan_globals();
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/***[ public stuff ]********************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
/***[ assign ]**************************************************************/
|
||||
/*
|
||||
assign a variable
|
||||
*/
|
||||
|
||||
function assign ($name,$val="") {
|
||||
if (is_array($name)) {
|
||||
foreach ($name as $k => $v) {
|
||||
$this->VARS[$k] = $v;
|
||||
}
|
||||
} else {
|
||||
$this->VARS[$name]=$val;
|
||||
}
|
||||
}
|
||||
|
||||
function append ($varname, $name,$val="") {
|
||||
if(!isset($this->VARS[$varname])){
|
||||
$this->VARS[$varname] = array();
|
||||
}
|
||||
if(is_array($this->VARS[$varname])){
|
||||
$this->VARS[$varname][$name] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
/***[ parse ]***************************************************************/
|
||||
/*
|
||||
parse a block
|
||||
*/
|
||||
|
||||
function parse ($bname) {
|
||||
global $sugar_version, $sugar_config;
|
||||
|
||||
$this->assign('SUGAR_VERSION', $GLOBALS['js_version_key']);
|
||||
$this->assign('JS_CUSTOM_VERSION', $sugar_config['js_custom_version']);
|
||||
|
||||
if(empty($this->blocks[$bname]))
|
||||
return;
|
||||
|
||||
$copy=$this->blocks[$bname];
|
||||
if (!isset($this->blocks[$bname]))
|
||||
$this->set_error ("parse: blockname [$bname] does not exist");
|
||||
preg_match_all("/\{([A-Za-z0-9\._]+?)}/",$this->blocks[$bname],$var_array);
|
||||
$var_array=$var_array[1];
|
||||
foreach ($var_array as $k => $v) {
|
||||
$sub=explode(".",$v);
|
||||
if ($sub[0]=="_BLOCK_") {
|
||||
unset($sub[0]);
|
||||
$bname2=implode(".",$sub);
|
||||
|
||||
if(isset($this->parsed_blocks[$bname2]))
|
||||
{
|
||||
$var=$this->parsed_blocks[$bname2];
|
||||
}
|
||||
else
|
||||
{
|
||||
$var = null;
|
||||
}
|
||||
|
||||
$nul=(!isset($this->NULL_BLOCK[$bname2])) ? $this->NULL_BLOCK[""] : $this->NULL_BLOCK[$bname2];
|
||||
$var=(empty($var))?$nul:trim($var);
|
||||
// Commented out due to regular expression issue with '$' in replacement string.
|
||||
//$copy=preg_replace("/\{".$v."\}/","$var",$copy);
|
||||
// This should be faster and work better for '$'
|
||||
$copy=str_replace("{".$v."}",$var,$copy);
|
||||
} else {
|
||||
$var=$this->VARS;
|
||||
|
||||
foreach ($sub as $k1 => $v1)
|
||||
{
|
||||
if(is_array($var) && isset($var[$v1]))
|
||||
{
|
||||
$var=$var[$v1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$var = null;
|
||||
}
|
||||
}
|
||||
|
||||
$nul=(!isset($this->NULL_STRING[$v])) ? ($this->NULL_STRING[""]) : ($this->NULL_STRING[$v]);
|
||||
$var=(!isset($var))?$nul:$var;
|
||||
// Commented out due to regular expression issue with '$' in replacement string.
|
||||
//$copy=preg_replace("/\{$v\}/","$var",$copy);
|
||||
// This should be faster and work better for '$'
|
||||
|
||||
// this was periodically returning an array to string conversion error....
|
||||
if(!is_array($var))
|
||||
{
|
||||
$copy=str_replace("{".$v."}",$var,$copy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($this->parsed_blocks[$bname]))
|
||||
{
|
||||
$this->parsed_blocks[$bname].=$copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->parsed_blocks[$bname]=$copy;
|
||||
}
|
||||
|
||||
// reset sub-blocks
|
||||
if ($this->AUTORESET && (!empty($this->sub_blocks[$bname]))) {
|
||||
reset($this->sub_blocks[$bname]);
|
||||
foreach ($this->sub_blocks[$bname] as $v)
|
||||
$this->reset($v);
|
||||
}
|
||||
}
|
||||
|
||||
/***[ exists ]**************************************************************/
|
||||
/*
|
||||
returns true if a block exists otherwise returns false.
|
||||
*/
|
||||
function exists($bname){
|
||||
return (!empty($this->parsed_blocks[$bname])) || (!empty($this->blocks[$bname]));
|
||||
}
|
||||
|
||||
|
||||
/***[ var_exists ]**************************************************************/
|
||||
/*
|
||||
returns true if a block exists otherwise returns false.
|
||||
*/
|
||||
function var_exists($bname,$vname){
|
||||
if(!empty($this->blocks[$bname])){
|
||||
return substr_count($this->blocks[$bname], '{'. $vname . '}') >0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/***[ rparse ]**************************************************************/
|
||||
/*
|
||||
returns the parsed text for a block, including all sub-blocks.
|
||||
*/
|
||||
|
||||
function rparse($bname) {
|
||||
if (!empty($this->sub_blocks[$bname])) {
|
||||
reset($this->sub_blocks[$bname]);
|
||||
while (list($k,$v)=each($this->sub_blocks[$bname]))
|
||||
if (!empty($v))
|
||||
$this->rparse($v,$indent."\t");
|
||||
}
|
||||
$this->parse($bname);
|
||||
}
|
||||
|
||||
/***[ insert_loop ]*********************************************************/
|
||||
/*
|
||||
inserts a loop ( call assign & parse )
|
||||
*/
|
||||
|
||||
function insert_loop($bname,$var,$value="") {
|
||||
$this->assign($var,$value);
|
||||
$this->parse($bname);
|
||||
}
|
||||
|
||||
/***[ text ]****************************************************************/
|
||||
/*
|
||||
returns the parsed text for a block
|
||||
*/
|
||||
|
||||
function text($bname) {
|
||||
|
||||
if(!empty($this->parsed_blocks)){
|
||||
return $this->parsed_blocks[isset($bname) ? $bname :$this->mainblock];
|
||||
}else{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/***[ out ]*****************************************************************/
|
||||
/*
|
||||
prints the parsed text
|
||||
*/
|
||||
|
||||
function out ($bname) {
|
||||
global $focus;
|
||||
|
||||
if(isset($focus)){
|
||||
global $action;
|
||||
|
||||
if($focus && is_subclass_of($focus, 'SugarBean') && !$focus->ACLAccess($action)){
|
||||
|
||||
ACLController::displayNoAccess(true);
|
||||
|
||||
sugar_die('');
|
||||
return;
|
||||
}}
|
||||
|
||||
echo $this->text($bname);
|
||||
}
|
||||
|
||||
/***[ reset ]***************************************************************/
|
||||
/*
|
||||
resets the parsed text
|
||||
*/
|
||||
|
||||
function reset ($bname) {
|
||||
$this->parsed_blocks[$bname]="";
|
||||
}
|
||||
|
||||
/***[ parsed ]**************************************************************/
|
||||
/*
|
||||
returns true if block was parsed, false if not
|
||||
*/
|
||||
|
||||
function parsed ($bname) {
|
||||
return (!empty($this->parsed_blocks[$bname]));
|
||||
}
|
||||
|
||||
/***[ SetNullString ]*******************************************************/
|
||||
/*
|
||||
sets the string to replace in case the var was not assigned
|
||||
*/
|
||||
|
||||
function SetNullString($str,$varname="") {
|
||||
$this->NULL_STRING[$varname]=$str;
|
||||
}
|
||||
|
||||
/***[ SetNullBlock ]********************************************************/
|
||||
/*
|
||||
sets the string to replace in case the block was not parsed
|
||||
*/
|
||||
|
||||
function SetNullBlock($str,$bname="") {
|
||||
$this->NULL_BLOCK[$bname]=$str;
|
||||
}
|
||||
|
||||
/***[ set_autoreset ]*******************************************************/
|
||||
/*
|
||||
sets AUTORESET to 1. (default is 1)
|
||||
if set to 1, parse() automatically resets the parsed blocks' sub blocks
|
||||
(for multiple level blocks)
|
||||
*/
|
||||
|
||||
function set_autoreset() {
|
||||
$this->AUTORESET=1;
|
||||
}
|
||||
|
||||
/***[ clear_autoreset ]*****************************************************/
|
||||
/*
|
||||
sets AUTORESET to 0. (default is 1)
|
||||
if set to 1, parse() automatically resets the parsed blocks' sub blocks
|
||||
(for multiple level blocks)
|
||||
*/
|
||||
|
||||
function clear_autoreset() {
|
||||
$this->AUTORESET=0;
|
||||
}
|
||||
|
||||
/***[ scan_globals ]********************************************************/
|
||||
/*
|
||||
scans global variables
|
||||
*/
|
||||
|
||||
function scan_globals() {
|
||||
reset($GLOBALS);
|
||||
while (list($k,$v)=each($GLOBALS))
|
||||
$GLOB[$k]=$v;
|
||||
$this->assign("PHP",$GLOB); /* access global variables as {PHP.HTTP_HOST} in your template! */
|
||||
}
|
||||
|
||||
/******
|
||||
|
||||
WARNING
|
||||
PUBLIC FUNCTIONS BELOW THIS LINE DIDN'T GET TESTED
|
||||
|
||||
******/
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/***[ private stuff ]*******************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
/***[ maketree ]************************************************************/
|
||||
/*
|
||||
generates the array containing to-be-parsed stuff:
|
||||
$blocks["main"],$blocks["main.table"],$blocks["main.table.row"], etc.
|
||||
also builds the reverse parse order.
|
||||
*/
|
||||
|
||||
|
||||
function maketree($con,$block) {
|
||||
$con2=explode($this->block_start_delim,$con);
|
||||
$level=0;
|
||||
$block_names=array();
|
||||
$blocks=array();
|
||||
reset($con2);
|
||||
while(list($k,$v)=each($con2)) {
|
||||
$patt="($this->block_start_word|$this->block_end_word)\s*(\w+)\s*$this->block_end_delim(.*)";
|
||||
if (preg_match_all("/$patt/ims",$v,$res, PREG_SET_ORDER)) {
|
||||
// $res[0][1] = BEGIN or END
|
||||
// $res[0][2] = block name
|
||||
// $res[0][3] = kinda content
|
||||
if ($res[0][1]==$this->block_start_word) {
|
||||
$parent_name=implode(".",$block_names);
|
||||
$block_names[++$level]=$res[0][2]; /* add one level - array("main","table","row")*/
|
||||
$cur_block_name=implode(".",$block_names); /* make block name (main.table.row) */
|
||||
$this->block_parse_order[]=$cur_block_name; /* build block parsing order (reverse) */
|
||||
|
||||
if(array_key_exists($cur_block_name, $blocks))
|
||||
{
|
||||
$blocks[$cur_block_name].=$res[0][3]; /* add contents */
|
||||
}
|
||||
else
|
||||
{
|
||||
$blocks[$cur_block_name]=$res[0][3]; /* add contents */
|
||||
}
|
||||
|
||||
/* add {_BLOCK_.blockname} string to parent block */
|
||||
if(array_key_exists($parent_name, $blocks))
|
||||
{
|
||||
$blocks[$parent_name].="{_BLOCK_.$cur_block_name}";
|
||||
}
|
||||
else
|
||||
{
|
||||
$blocks[$parent_name]="{_BLOCK_.$cur_block_name}";
|
||||
}
|
||||
|
||||
$this->sub_blocks[$parent_name][]=$cur_block_name; /* store sub block names for autoresetting and recursive parsing */
|
||||
$this->sub_blocks[$cur_block_name][]=""; /* store sub block names for autoresetting */
|
||||
} else if ($res[0][1]==$this->block_end_word) {
|
||||
unset($block_names[$level--]);
|
||||
$parent_name=implode(".",$block_names);
|
||||
$blocks[$parent_name].=$res[0][3]; /* add rest of block to parent block */
|
||||
}
|
||||
} else { /* no block delimiters found */
|
||||
$index = implode(".",$block_names);
|
||||
if(array_key_exists($index, $blocks))
|
||||
{
|
||||
$blocks[].=$this->block_start_delim.$v;
|
||||
}
|
||||
else
|
||||
{
|
||||
$blocks[]=$this->block_start_delim.$v;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***[ error stuff ]*********************************************************/
|
||||
/*
|
||||
sets and gets error
|
||||
*/
|
||||
|
||||
function get_error() {
|
||||
return ($this->ERROR=="")?0:$this->ERROR;
|
||||
}
|
||||
|
||||
|
||||
function set_error($str) {
|
||||
$this->ERROR=$str;
|
||||
}
|
||||
|
||||
/***[ getfile ]*************************************************************/
|
||||
/*
|
||||
returns the contents of a file
|
||||
*/
|
||||
|
||||
function getfile($file) {
|
||||
if (!isset($file)) {
|
||||
$this->set_error("!isset file name!");
|
||||
return "";
|
||||
}
|
||||
|
||||
// Pick which folder we should include from
|
||||
// Prefer the local directory, then try the theme directory.
|
||||
if (!is_file($file))
|
||||
$file = $this->alternate_include_directory.$file;
|
||||
|
||||
if(is_file($file))
|
||||
{
|
||||
$file_text=file_get_contents($file);
|
||||
|
||||
} else {
|
||||
$this->set_error("[$file] does not exist");
|
||||
$file_text="<b>__XTemplate fatal error: file [$file] does not exist__</b>";
|
||||
}
|
||||
|
||||
return $file_text;
|
||||
}
|
||||
|
||||
/***[ r_getfile ]***********************************************************/
|
||||
/*
|
||||
recursively gets the content of a file with {FILE "filename.tpl"} directives
|
||||
*/
|
||||
|
||||
|
||||
function r_getfile($file) {
|
||||
$text=$this->getfile($file);
|
||||
while (preg_match($this->file_delim,$text,$res)) {
|
||||
$text2=$this->getfile($res[1]);
|
||||
$text=preg_replace("'".preg_quote($res[0])."'",$text2,$text);
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
} /* end of XTemplate class. */
|
||||
|
||||
?>
|
||||
167
Zend/Crypt.php
Executable file
167
Zend/Crypt.php
Executable file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt
|
||||
{
|
||||
|
||||
const TYPE_OPENSSL = 'openssl';
|
||||
const TYPE_HASH = 'hash';
|
||||
const TYPE_MHASH = 'mhash';
|
||||
|
||||
protected static $_type = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $_supportedAlgosOpenssl = array(
|
||||
'md2',
|
||||
'md4',
|
||||
'mdc2',
|
||||
'rmd160',
|
||||
'sha',
|
||||
'sha1',
|
||||
'sha224',
|
||||
'sha256',
|
||||
'sha384',
|
||||
'sha512'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $_supportedAlgosMhash = array(
|
||||
'adler32',
|
||||
'crc32',
|
||||
'crc32b',
|
||||
'gost',
|
||||
'haval128',
|
||||
'haval160',
|
||||
'haval192',
|
||||
'haval256',
|
||||
'md4',
|
||||
'md5',
|
||||
'ripemd160',
|
||||
'sha1',
|
||||
'sha256',
|
||||
'tiger',
|
||||
'tiger128',
|
||||
'tiger160'
|
||||
);
|
||||
|
||||
/**
|
||||
* @param string $algorithm
|
||||
* @param string $data
|
||||
* @param bool $binaryOutput
|
||||
* @return unknown
|
||||
*/
|
||||
public static function hash($algorithm, $data, $binaryOutput = false)
|
||||
{
|
||||
$algorithm = strtolower($algorithm);
|
||||
if (function_exists($algorithm)) {
|
||||
return $algorithm($data, $binaryOutput);
|
||||
}
|
||||
self::_detectHashSupport($algorithm);
|
||||
$supportedMethod = '_digest' . ucfirst(self::$_type);
|
||||
$result = self::$supportedMethod($algorithm, $data, $binaryOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $algorithm
|
||||
* @throws Zend_Crypt_Exception
|
||||
*/
|
||||
protected static function _detectHashSupport($algorithm)
|
||||
{
|
||||
if (function_exists('hash')) {
|
||||
self::$_type = self::TYPE_HASH;
|
||||
if (in_array($algorithm, hash_algos())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (function_exists('mhash')) {
|
||||
self::$_type = self::TYPE_MHASH;
|
||||
if (in_array($algorithm, self::$_supportedAlgosMhash)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (function_exists('openssl_digest')) {
|
||||
if ($algorithm == 'ripemd160') {
|
||||
$algorithm = 'rmd160';
|
||||
}
|
||||
self::$_type = self::TYPE_OPENSSL;
|
||||
if (in_array($algorithm, self::$_supportedAlgosOpenssl)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @see Zend_Crypt_Exception
|
||||
*/
|
||||
require_once 'Zend/Crypt/Exception.php';
|
||||
throw new Zend_Crypt_Exception('\'' . $algorithm . '\' is not supported by any available extension or native function');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $algorithm
|
||||
* @param string $data
|
||||
* @param bool $binaryOutput
|
||||
* @return string
|
||||
*/
|
||||
protected static function _digestHash($algorithm, $data, $binaryOutput)
|
||||
{
|
||||
return hash($algorithm, $data, $binaryOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $algorithm
|
||||
* @param string $data
|
||||
* @param bool $binaryOutput
|
||||
* @return string
|
||||
*/
|
||||
protected static function _digestMhash($algorithm, $data, $binaryOutput)
|
||||
{
|
||||
$constant = constant('MHASH_' . strtoupper($algorithm));
|
||||
$binary = mhash($constant, $data);
|
||||
if ($binaryOutput) {
|
||||
return $binary;
|
||||
}
|
||||
return bin2hex($binary);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $algorithm
|
||||
* @param string $data
|
||||
* @param bool $binaryOutput
|
||||
* @return string
|
||||
*/
|
||||
protected static function _digestOpenssl($algorithm, $data, $binaryOutput)
|
||||
{
|
||||
if ($algorithm == 'ripemd160') {
|
||||
$algorithm = 'rmd160';
|
||||
}
|
||||
return openssl_digest($data, $algorithm, $binaryOutput);
|
||||
}
|
||||
|
||||
}
|
||||
380
Zend/Crypt/DiffieHellman.php
Executable file
380
Zend/Crypt/DiffieHellman.php
Executable file
@@ -0,0 +1,380 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage DiffieHellman
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* PHP implementation of the Diffie-Hellman public key encryption algorithm.
|
||||
* Allows two unassociated parties to establish a joint shared secret key
|
||||
* to be used in encrypting subsequent communications.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_DiffieHellman
|
||||
{
|
||||
|
||||
/**
|
||||
* Static flag to select whether to use PHP5.3's openssl extension
|
||||
* if available.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public static $useOpenssl = true;
|
||||
|
||||
/**
|
||||
* Default large prime number; required by the algorithm.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_prime = null;
|
||||
|
||||
/**
|
||||
* The default generator number. This number must be greater than 0 but
|
||||
* less than the prime number set.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_generator = null;
|
||||
|
||||
/**
|
||||
* A private number set by the local user. It's optional and will
|
||||
* be generated if not set.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_privateKey = null;
|
||||
|
||||
/**
|
||||
* BigInteger support object courtesy of Zend_Crypt_Math
|
||||
*
|
||||
* @var Zend_Crypt_Math_BigInteger
|
||||
*/
|
||||
private $_math = null;
|
||||
|
||||
/**
|
||||
* The public key generated by this instance after calling generateKeys().
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_publicKey = null;
|
||||
|
||||
/**
|
||||
* The shared secret key resulting from a completed Diffie Hellman
|
||||
* exchange
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_secretKey = null;
|
||||
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const BINARY = 'binary';
|
||||
const NUMBER = 'number';
|
||||
const BTWOC = 'btwoc';
|
||||
|
||||
/**
|
||||
* Constructor; if set construct the object using the parameter array to
|
||||
* set values for Prime, Generator and Private.
|
||||
* If a Private Key is not set, one will be generated at random.
|
||||
*
|
||||
* @param string $prime
|
||||
* @param string $generator
|
||||
* @param string $privateKey
|
||||
* @param string $privateKeyType
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($prime, $generator, $privateKey = null, $privateKeyType = self::NUMBER)
|
||||
{
|
||||
$this->setPrime($prime);
|
||||
$this->setGenerator($generator);
|
||||
if ($privateKey !== null) {
|
||||
$this->setPrivateKey($privateKey, $privateKeyType);
|
||||
}
|
||||
$this->setBigIntegerMath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate own public key. If a private number has not already been
|
||||
* set, one will be generated at this stage.
|
||||
*
|
||||
* @return Zend_Crypt_DiffieHellman
|
||||
*/
|
||||
public function generateKeys()
|
||||
{
|
||||
if (function_exists('openssl_dh_compute_key') && self::$useOpenssl !== false) {
|
||||
$details = array();
|
||||
$details['p'] = $this->getPrime();
|
||||
$details['g'] = $this->getGenerator();
|
||||
if ($this->hasPrivateKey()) {
|
||||
$details['priv_key'] = $this->getPrivateKey();
|
||||
}
|
||||
$opensslKeyResource = openssl_pkey_new( array('dh' => $details) );
|
||||
$data = openssl_pkey_get_details($opensslKeyResource);
|
||||
$this->setPrivateKey($data['dh']['priv_key'], self::BINARY);
|
||||
$this->setPublicKey($data['dh']['pub_key'], self::BINARY);
|
||||
} else {
|
||||
// Private key is lazy generated in the absence of PHP 5.3's ext/openssl
|
||||
$publicKey = $this->_math->powmod($this->getGenerator(), $this->getPrivateKey(), $this->getPrime());
|
||||
$this->setPublicKey($publicKey);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the value of the public number
|
||||
*
|
||||
* @param string $number
|
||||
* @param string $type
|
||||
* @return Zend_Crypt_DiffieHellman
|
||||
*/
|
||||
public function setPublicKey($number, $type = self::NUMBER)
|
||||
{
|
||||
if ($type == self::BINARY) {
|
||||
$number = $this->_math->fromBinary($number);
|
||||
}
|
||||
if (!preg_match("/^\d+$/", $number)) {
|
||||
require_once('Zend/Crypt/DiffieHellman/Exception.php');
|
||||
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number');
|
||||
}
|
||||
$this->_publicKey = (string) $number;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns own public key for communication to the second party to this
|
||||
* transaction.
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public function getPublicKey($type = self::NUMBER)
|
||||
{
|
||||
if ($this->_publicKey === null) {
|
||||
require_once 'Zend/Crypt/DiffieHellman/Exception.php';
|
||||
throw new Zend_Crypt_DiffieHellman_Exception('A public key has not yet been generated using a prior call to generateKeys()');
|
||||
}
|
||||
if ($type == self::BINARY) {
|
||||
return $this->_math->toBinary($this->_publicKey);
|
||||
} elseif ($type == self::BTWOC) {
|
||||
return $this->_math->btwoc($this->_math->toBinary($this->_publicKey));
|
||||
}
|
||||
return $this->_publicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the shared secret key based on the public key received from the
|
||||
* the second party to this transaction. This should agree to the secret
|
||||
* key the second party computes on our own public key.
|
||||
* Once in agreement, the key is known to only to both parties.
|
||||
* By default, the function expects the public key to be in binary form
|
||||
* which is the typical format when being transmitted.
|
||||
*
|
||||
* If you need the binary form of the shared secret key, call
|
||||
* getSharedSecretKey() with the optional parameter for Binary output.
|
||||
*
|
||||
* @param string $publicKey
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function computeSecretKey($publicKey, $type = self::NUMBER, $output = self::NUMBER)
|
||||
{
|
||||
if ($type == self::BINARY) {
|
||||
$publicKey = $this->_math->fromBinary($publicKey);
|
||||
}
|
||||
if (!preg_match("/^\d+$/", $publicKey)) {
|
||||
require_once('Zend/Crypt/DiffieHellman/Exception.php');
|
||||
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number');
|
||||
}
|
||||
if (function_exists('openssl_dh_compute_key') && self::$useOpenssl !== false) {
|
||||
$this->_secretKey = openssl_dh_compute_key($publicKey, $this->getPublicKey());
|
||||
} else {
|
||||
$this->_secretKey = $this->_math->powmod($publicKey, $this->getPrivateKey(), $this->getPrime());
|
||||
}
|
||||
return $this->getSharedSecretKey($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the computed shared secret key from the DiffieHellman transaction
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public function getSharedSecretKey($type = self::NUMBER)
|
||||
{
|
||||
if (!isset($this->_secretKey)) {
|
||||
require_once('Zend/Crypt/DiffieHellman/Exception.php');
|
||||
throw new Zend_Crypt_DiffieHellman_Exception('A secret key has not yet been computed; call computeSecretKey()');
|
||||
}
|
||||
if ($type == self::BINARY) {
|
||||
return $this->_math->toBinary($this->_secretKey);
|
||||
} elseif ($type == self::BTWOC) {
|
||||
return $this->_math->btwoc($this->_math->toBinary($this->_secretKey));
|
||||
}
|
||||
return $this->_secretKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the value of the prime number
|
||||
*
|
||||
* @param string $number
|
||||
* @return Zend_Crypt_DiffieHellman
|
||||
*/
|
||||
public function setPrime($number)
|
||||
{
|
||||
if (!preg_match("/^\d+$/", $number) || $number < 11) {
|
||||
require_once('Zend/Crypt/DiffieHellman/Exception.php');
|
||||
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number or too small: should be a large natural number prime');
|
||||
}
|
||||
$this->_prime = (string) $number;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the value of the prime number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrime()
|
||||
{
|
||||
if (!isset($this->_prime)) {
|
||||
require_once('Zend/Crypt/DiffieHellman/Exception.php');
|
||||
throw new Zend_Crypt_DiffieHellman_Exception('No prime number has been set');
|
||||
}
|
||||
return $this->_prime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setter for the value of the generator number
|
||||
*
|
||||
* @param string $number
|
||||
* @return Zend_Crypt_DiffieHellman
|
||||
*/
|
||||
public function setGenerator($number)
|
||||
{
|
||||
if (!preg_match("/^\d+$/", $number) || $number < 2) {
|
||||
require_once('Zend/Crypt/DiffieHellman/Exception.php');
|
||||
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number greater than 1');
|
||||
}
|
||||
$this->_generator = (string) $number;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the value of the generator number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getGenerator()
|
||||
{
|
||||
if (!isset($this->_generator)) {
|
||||
require_once('Zend/Crypt/DiffieHellman/Exception.php');
|
||||
throw new Zend_Crypt_DiffieHellman_Exception('No generator number has been set');
|
||||
}
|
||||
return $this->_generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the value of the private number
|
||||
*
|
||||
* @param string $number
|
||||
* @param string $type
|
||||
* @return Zend_Crypt_DiffieHellman
|
||||
*/
|
||||
public function setPrivateKey($number, $type = self::NUMBER)
|
||||
{
|
||||
if ($type == self::BINARY) {
|
||||
$number = $this->_math->fromBinary($number);
|
||||
}
|
||||
if (!preg_match("/^\d+$/", $number)) {
|
||||
require_once('Zend/Crypt/DiffieHellman/Exception.php');
|
||||
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number');
|
||||
}
|
||||
$this->_privateKey = (string) $number;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the value of the private number
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public function getPrivateKey($type = self::NUMBER)
|
||||
{
|
||||
if (!$this->hasPrivateKey()) {
|
||||
$this->setPrivateKey($this->_generatePrivateKey(), self::BINARY);
|
||||
}
|
||||
if ($type == self::BINARY) {
|
||||
return $this->_math->toBinary($this->_privateKey);
|
||||
} elseif ($type == self::BTWOC) {
|
||||
return $this->_math->btwoc($this->_math->toBinary($this->_privateKey));
|
||||
}
|
||||
return $this->_privateKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a private key currently exists.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasPrivateKey()
|
||||
{
|
||||
return isset($this->_privateKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter to pass an extension parameter which is used to create
|
||||
* a specific BigInteger instance for a specific extension type.
|
||||
* Allows manual setting of the class in case of an extension
|
||||
* problem or bug.
|
||||
*
|
||||
* @param string $extension
|
||||
* @return void
|
||||
*/
|
||||
public function setBigIntegerMath($extension = null)
|
||||
{
|
||||
/**
|
||||
* @see Zend_Crypt_Math
|
||||
*/
|
||||
require_once 'Zend/Crypt/Math.php';
|
||||
$this->_math = new Zend_Crypt_Math($extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* In the event a private number/key has not been set by the user,
|
||||
* or generated by ext/openssl, a best attempt will be made to
|
||||
* generate a random key. Having a random number generator installed
|
||||
* on linux/bsd is highly recommended! The alternative is not recommended
|
||||
* for production unless without any other option.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _generatePrivateKey()
|
||||
{
|
||||
$rand = $this->_math->rand($this->getGenerator(), $this->getPrime());
|
||||
return $rand;
|
||||
}
|
||||
|
||||
}
|
||||
36
Zend/Crypt/DiffieHellman/Exception.php
Executable file
36
Zend/Crypt/DiffieHellman/Exception.php
Executable file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage DiffieHellman
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Exception
|
||||
*/
|
||||
require_once 'Zend/Crypt/Exception.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_DiffieHellman_Exception extends Zend_Crypt_Exception
|
||||
{
|
||||
}
|
||||
35
Zend/Crypt/Exception.php
Executable file
35
Zend/Crypt/Exception.php
Executable file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_Exception extends Zend_Exception
|
||||
{
|
||||
}
|
||||
181
Zend/Crypt/Hmac.php
Executable file
181
Zend/Crypt/Hmac.php
Executable file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage Hmac
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt
|
||||
*/
|
||||
require_once 'Zend/Crypt.php';
|
||||
|
||||
/**
|
||||
* PHP implementation of the RFC 2104 Hash based Message Authentication Code
|
||||
* algorithm.
|
||||
*
|
||||
* @todo Patch for refactoring failed tests (key block sizes >80 using internal algo)
|
||||
* @todo Check if mhash() is a required alternative (will be PECL-only soon)
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_Hmac extends Zend_Crypt
|
||||
{
|
||||
|
||||
/**
|
||||
* The key to use for the hash
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $_key = null;
|
||||
|
||||
/**
|
||||
* pack() format to be used for current hashing method
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $_packFormat = null;
|
||||
|
||||
/**
|
||||
* Hashing algorithm; can be the md5/sha1 functions or any algorithm name
|
||||
* listed in the output of PHP 5.1.2+ hash_algos().
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $_hashAlgorithm = 'md5';
|
||||
|
||||
/**
|
||||
* List of algorithms supported my mhash()
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $_supportedMhashAlgorithms = array('adler32',' crc32', 'crc32b', 'gost',
|
||||
'haval128', 'haval160', 'haval192', 'haval256', 'md4', 'md5', 'ripemd160',
|
||||
'sha1', 'sha256', 'tiger', 'tiger128', 'tiger160');
|
||||
|
||||
/**
|
||||
* Constants representing the output mode of the hash algorithm
|
||||
*/
|
||||
const STRING = 'string';
|
||||
const BINARY = 'binary';
|
||||
|
||||
/**
|
||||
* Performs a HMAC computation given relevant details such as Key, Hashing
|
||||
* algorithm, the data to compute MAC of, and an output format of String,
|
||||
* Binary notation or BTWOC.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $hash
|
||||
* @param string $data
|
||||
* @param string $output
|
||||
* @param boolean $internal
|
||||
* @return string
|
||||
*/
|
||||
public static function compute($key, $hash, $data, $output = self::STRING)
|
||||
{
|
||||
// set the key
|
||||
if (!isset($key) || empty($key)) {
|
||||
require_once 'Zend/Crypt/Hmac/Exception.php';
|
||||
throw new Zend_Crypt_Hmac_Exception('provided key is null or empty');
|
||||
}
|
||||
self::$_key = $key;
|
||||
|
||||
// set the hash
|
||||
self::_setHashAlgorithm($hash);
|
||||
|
||||
// perform hashing and return
|
||||
return self::_hash($data, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the hash method.
|
||||
*
|
||||
* @param string $hash
|
||||
* @return Zend_Crypt_Hmac
|
||||
*/
|
||||
protected static function _setHashAlgorithm($hash)
|
||||
{
|
||||
if (!isset($hash) || empty($hash)) {
|
||||
require_once 'Zend/Crypt/Hmac/Exception.php';
|
||||
throw new Zend_Crypt_Hmac_Exception('provided hash string is null or empty');
|
||||
}
|
||||
|
||||
$hash = strtolower($hash);
|
||||
$hashSupported = false;
|
||||
|
||||
if (function_exists('hash_algos') && in_array($hash, hash_algos())) {
|
||||
$hashSupported = true;
|
||||
}
|
||||
|
||||
if ($hashSupported === false && function_exists('mhash') && in_array($hash, self::$_supportedAlgosMhash)) {
|
||||
$hashSupported = true;
|
||||
}
|
||||
|
||||
if ($hashSupported === false) {
|
||||
require_once 'Zend/Crypt/Hmac/Exception.php';
|
||||
throw new Zend_Crypt_Hmac_Exception('hash algorithm provided is not supported on this PHP installation; please enable the hash or mhash extensions');
|
||||
}
|
||||
self::$_hashAlgorithm = $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform HMAC and return the keyed data
|
||||
*
|
||||
* @param string $data
|
||||
* @param string $output
|
||||
* @param bool $internal Option to not use hash() functions for testing
|
||||
* @return string
|
||||
*/
|
||||
protected static function _hash($data, $output = self::STRING, $internal = false)
|
||||
{
|
||||
if (function_exists('hash_hmac')) {
|
||||
if ($output == self::BINARY) {
|
||||
return hash_hmac(self::$_hashAlgorithm, $data, self::$_key, 1);
|
||||
}
|
||||
return hash_hmac(self::$_hashAlgorithm, $data, self::$_key);
|
||||
}
|
||||
|
||||
if (function_exists('mhash')) {
|
||||
if ($output == self::BINARY) {
|
||||
return mhash(self::_getMhashDefinition(self::$_hashAlgorithm), $data, self::$_key);
|
||||
}
|
||||
$bin = mhash(self::_getMhashDefinition(self::$_hashAlgorithm), $data, self::$_key);
|
||||
return bin2hex($bin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Since MHASH accepts an integer constant representing the hash algorithm
|
||||
* we need to make a small detour to get the correct integer matching our
|
||||
* algorithm's name.
|
||||
*
|
||||
* @param string $hashAlgorithm
|
||||
* @return integer
|
||||
*/
|
||||
protected static function _getMhashDefinition($hashAlgorithm)
|
||||
{
|
||||
for ($i = 0; $i <= mhash_count(); $i++)
|
||||
{
|
||||
$types[mhash_get_hash_name($i)] = $i;
|
||||
}
|
||||
return $types[strtoupper($hashAlgorithm)];
|
||||
}
|
||||
|
||||
}
|
||||
36
Zend/Crypt/Hmac/Exception.php
Executable file
36
Zend/Crypt/Hmac/Exception.php
Executable file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage Hmac
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Exception
|
||||
*/
|
||||
require_once 'Zend/Crypt/Exception.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_Hmac_Exception extends Zend_Crypt_Exception
|
||||
{
|
||||
}
|
||||
102
Zend/Crypt/Math.php
Executable file
102
Zend/Crypt/Math.php
Executable file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage Math
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Math_BigInteger
|
||||
*/
|
||||
require_once 'Zend/Crypt/Math/BigInteger.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_Math extends Zend_Crypt_Math_BigInteger
|
||||
{
|
||||
|
||||
/**
|
||||
* Generate a pseudorandom number within the given range.
|
||||
* Will attempt to read from a systems RNG if it exists or else utilises
|
||||
* a simple random character to maximum length process. Simplicity
|
||||
* is a factor better left for development...
|
||||
*
|
||||
* @param string|int $minimum
|
||||
* @param string|int $maximum
|
||||
* @return string
|
||||
*/
|
||||
public function rand($minimum, $maximum)
|
||||
{
|
||||
if (file_exists('/dev/urandom')) {
|
||||
$frandom = fopen('/dev/urandom', 'r');
|
||||
if ($frandom !== false) {
|
||||
return fread($frandom, strlen($maximum) - 1);
|
||||
}
|
||||
}
|
||||
if (strlen($maximum) < 4) {
|
||||
return mt_rand($minimum, $maximum - 1);
|
||||
}
|
||||
$rand = '';
|
||||
$i2 = strlen($maximum) - 1;
|
||||
for ($i = 1;$i < $i2;$i++) {
|
||||
$rand .= mt_rand(0,9);
|
||||
}
|
||||
$rand .= mt_rand(0,9);
|
||||
return $rand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the big endian two's complement of a given big integer in
|
||||
* binary notation
|
||||
*
|
||||
* @param string $long
|
||||
* @return string
|
||||
*/
|
||||
public function btwoc($long) {
|
||||
if (ord($long[0]) > 127) {
|
||||
return "\x00" . $long;
|
||||
}
|
||||
return $long;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a binary form into a big integer string
|
||||
*
|
||||
* @param string $binary
|
||||
* @return string
|
||||
*/
|
||||
public function fromBinary($binary) {
|
||||
return $this->_math->binaryToInteger($binary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a big integer string into a binary form
|
||||
*
|
||||
* @param string $integer
|
||||
* @return string
|
||||
*/
|
||||
public function toBinary($integer)
|
||||
{
|
||||
return $this->_math->integerToBinary($integer);
|
||||
}
|
||||
|
||||
}
|
||||
117
Zend/Crypt/Math/BigInteger.php
Executable file
117
Zend/Crypt/Math/BigInteger.php
Executable file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage Math
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Support for arbitrary precision mathematics in PHP.
|
||||
*
|
||||
* Zend_Crypt_Math_BigInteger is a wrapper across three PHP extensions: bcmath, gmp
|
||||
* and big_int. Since each offer similar functionality, but availability of
|
||||
* each differs across installations of PHP, this wrapper attempts to select
|
||||
* the fastest option available and encapsulate a subset of its functionality
|
||||
* which all extensions share in common.
|
||||
*
|
||||
* This class requires one of the three extensions to be available. BCMATH
|
||||
* while the slowest, is available by default under Windows, and under Unix
|
||||
* if PHP is compiled with the flag "--enable-bcmath". GMP requires the gmp
|
||||
* library from http://www.swox.com/gmp/ and PHP compiled with the "--with-gmp"
|
||||
* flag. BIG_INT support is available from a big_int PHP library available from
|
||||
* only from PECL (a Windows port is not available).
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_Math_BigInteger
|
||||
{
|
||||
|
||||
/**
|
||||
* Holds an instance of one of the three arbitrary precision wrappers.
|
||||
*
|
||||
* @var Zend_Crypt_Math_BigInteger_Interface
|
||||
*/
|
||||
protected $_math = null;
|
||||
|
||||
/**
|
||||
* Constructor; a Factory which detects a suitable PHP extension for
|
||||
* arbitrary precision math and instantiates the suitable wrapper
|
||||
* object.
|
||||
*
|
||||
* @param string $extension
|
||||
* @throws Zend_Crypt_Math_BigInteger_Exception
|
||||
*/
|
||||
public function __construct($extension = null)
|
||||
{
|
||||
if ($extension !== null && !in_array($extension, array('bcmath', 'gmp', 'bigint'))) {
|
||||
require_once('Zend/Crypt/Math/BigInteger/Exception.php');
|
||||
throw new Zend_Crypt_Math_BigInteger_Exception('Invalid extension type; please use one of bcmath, gmp or bigint');
|
||||
}
|
||||
$this->_loadAdapter($extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect all public method calls to the wrapped extension object.
|
||||
*
|
||||
* @param string $methodName
|
||||
* @param array $args
|
||||
* @throws Zend_Crypt_Math_BigInteger_Exception
|
||||
*/
|
||||
public function __call($methodName, $args)
|
||||
{
|
||||
if(!method_exists($this->_math, $methodName)) {
|
||||
require_once 'Zend/Crypt/Math/BigInteger/Exception.php';
|
||||
throw new Zend_Crypt_Math_BigInteger_Exception('invalid method call: ' . get_class($this->_math) . '::' . $methodName . '() does not exist');
|
||||
}
|
||||
return call_user_func_array(array($this->_math, $methodName), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $extension
|
||||
* @throws Zend_Crypt_Math_BigInteger_Exception
|
||||
*/
|
||||
protected function _loadAdapter($extension = null)
|
||||
{
|
||||
if ($extension === null) {
|
||||
if (extension_loaded('gmp')) {
|
||||
$extension = 'gmp';
|
||||
//} elseif (extension_loaded('big_int')) {
|
||||
// $extension = 'big_int';
|
||||
} else {
|
||||
$extension = 'bcmath';
|
||||
}
|
||||
}
|
||||
if($extension == 'gmp' && extension_loaded('gmp')) {
|
||||
require_once 'Zend/Crypt/Math/BigInteger/Gmp.php';
|
||||
$this->_math = new Zend_Crypt_Math_BigInteger_Gmp();
|
||||
//} elseif($extension == 'bigint' && extension_loaded('big_int')) {
|
||||
// require_once 'Zend/Crypt_Math/BigInteger/Bigint.php';
|
||||
// $this->_math = new Zend_Crypt_Math_BigInteger_Bigint();
|
||||
} elseif ($extension == 'bcmath') {
|
||||
require_once 'Zend/Crypt/Math/BigInteger/Bcmath.php';
|
||||
$this->_math = new Zend_Crypt_Math_BigInteger_Bcmath();
|
||||
} else {
|
||||
require_once 'Zend/Crypt/Math/BigInteger/Exception.php';
|
||||
throw new Zend_Crypt_Math_BigInteger_Exception($extension . ' big integer precision math support not detected');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
203
Zend/Crypt/Math/BigInteger/Bcmath.php
Executable file
203
Zend/Crypt/Math/BigInteger/Bcmath.php
Executable file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage Math
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Math_BigInteger_Interface
|
||||
*/
|
||||
require_once 'Zend/Crypt/Math/BigInteger/Interface.php';
|
||||
|
||||
/**
|
||||
* Support for arbitrary precision mathematics in PHP.
|
||||
*
|
||||
* Zend_Crypt_Math_BigInteger_Bcmath is a wrapper across the PHP BCMath
|
||||
* extension.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_Math_BigInteger_Bcmath implements Zend_Crypt_Math_BigInteger_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Initialise a big integer into an extension specific type. This is not
|
||||
* applicable to BCMath.
|
||||
* @param string $operand
|
||||
* @param int $base
|
||||
* @return string
|
||||
*/
|
||||
public function init($operand, $base = 10)
|
||||
{
|
||||
return $operand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds two arbitrary precision numbers
|
||||
*
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function add($left_operand, $right_operand)
|
||||
{
|
||||
return bcadd($left_operand, $right_operand);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function subtract($left_operand, $right_operand)
|
||||
{
|
||||
return bcsub($left_operand, $right_operand);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two big integers and returns result as an integer where 0 means
|
||||
* both are identical, 1 that left_operand is larger, or -1 that
|
||||
* right_operand is larger.
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return int
|
||||
*/
|
||||
public function compare($left_operand, $right_operand)
|
||||
{
|
||||
return bccomp($left_operand, $right_operand);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide two big integers and return result or NULL if the denominator
|
||||
* is zero.
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string|null
|
||||
*/
|
||||
public function divide($left_operand, $right_operand)
|
||||
{
|
||||
return bcdiv($left_operand, $right_operand);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function modulus($left_operand, $modulus)
|
||||
{
|
||||
return bcmod($left_operand, $modulus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function multiply($left_operand, $right_operand)
|
||||
{
|
||||
return bcmul($left_operand, $right_operand);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function pow($left_operand, $right_operand)
|
||||
{
|
||||
return bcpow($left_operand, $right_operand);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function powmod($left_operand, $right_operand, $modulus)
|
||||
{
|
||||
return bcpowmod($left_operand, $right_operand, $modulus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function sqrt($operand)
|
||||
{
|
||||
return bcsqrt($operand);
|
||||
}
|
||||
|
||||
|
||||
public function binaryToInteger($operand)
|
||||
{
|
||||
$result = '0';
|
||||
while (strlen($operand)) {
|
||||
$ord = ord(substr($operand, 0, 1));
|
||||
$result = bcadd(bcmul($result, 256), $ord);
|
||||
$operand = substr($operand, 1);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function integerToBinary($operand)
|
||||
{
|
||||
$cmp = bccomp($operand, 0);
|
||||
$return = '';
|
||||
if ($cmp == 0) {
|
||||
return "\0";
|
||||
}
|
||||
while (bccomp($operand, 0) > 0) {
|
||||
$return = chr(bcmod($operand, 256)) . $return;
|
||||
$operand = bcdiv($operand, 256);
|
||||
}
|
||||
if (ord($return[0]) > 127) {
|
||||
$return = "\0" . $return;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**public function integerToBinary($operand)
|
||||
{
|
||||
$return = '';
|
||||
while(bccomp($operand, '0')) {
|
||||
$return .= chr(bcmod($operand, '256'));
|
||||
$operand = bcdiv($operand, '256');
|
||||
}
|
||||
return $return;
|
||||
}**/ // Prior version for referenced offset
|
||||
|
||||
|
||||
public function hexToDecimal($operand)
|
||||
{
|
||||
$return = '0';
|
||||
while(strlen($hex)) {
|
||||
$hex = hexdec(substr($operand, 0, 4));
|
||||
$dec = bcadd(bcmul($return, 65536), $hex);
|
||||
$operand = substr($operand, 4);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
36
Zend/Crypt/Math/BigInteger/Exception.php
Executable file
36
Zend/Crypt/Math/BigInteger/Exception.php
Executable file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage Math
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Math_Exception
|
||||
*/
|
||||
require_once 'Zend/Crypt/Math/Exception.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_Math_BigInteger_Exception extends Zend_Crypt_Math_Exception
|
||||
{
|
||||
}
|
||||
196
Zend/Crypt/Math/BigInteger/Gmp.php
Executable file
196
Zend/Crypt/Math/BigInteger/Gmp.php
Executable file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage Math
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Math_BigInteger_Interface
|
||||
*/
|
||||
require_once 'Zend/Crypt/Math/BigInteger/Interface.php';
|
||||
|
||||
/**
|
||||
* Support for arbitrary precision mathematics in PHP.
|
||||
*
|
||||
* Zend_Crypt_Math_BigInteger_Bcmath is a wrapper across the PHP BCMath
|
||||
* extension.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_Math_BigInteger_Gmp implements Zend_Crypt_Math_BigInteger_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Initialise a big integer into an extension specific type.
|
||||
* @param string $operand
|
||||
* @param int $base
|
||||
* @return string
|
||||
*/
|
||||
public function init($operand, $base = 10)
|
||||
{
|
||||
return $operand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds two arbitrary precision numbers
|
||||
*
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function add($left_operand, $right_operand)
|
||||
{
|
||||
$result = gmp_add($left_operand, $right_operand);
|
||||
return gmp_strval($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function subtract($left_operand, $right_operand)
|
||||
{
|
||||
$result = gmp_sub($left_operand, $right_operand);
|
||||
return gmp_strval($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two big integers and returns result as an integer where 0 means
|
||||
* both are identical, 1 that left_operand is larger, or -1 that
|
||||
* right_operand is larger.
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return int
|
||||
*/
|
||||
public function compare($left_operand, $right_operand)
|
||||
{
|
||||
$result = gmp_cmp($left_operand, $right_operand);
|
||||
return gmp_strval($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide two big integers and return result or NULL if the denominator
|
||||
* is zero.
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string|null
|
||||
*/
|
||||
public function divide($left_operand, $right_operand)
|
||||
{
|
||||
$result = gmp_div($left_operand, $right_operand);
|
||||
return gmp_strval($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function modulus($left_operand, $modulus)
|
||||
{
|
||||
$result = gmp_mod($left_operand, $modulus);
|
||||
return gmp_strval($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function multiply($left_operand, $right_operand)
|
||||
{
|
||||
$result = gmp_mul($left_operand, $right_operand);
|
||||
return gmp_strval($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function pow($left_operand, $right_operand)
|
||||
{
|
||||
$result = gmp_pow($left_operand, $right_operand);
|
||||
return gmp_strval($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function powmod($left_operand, $right_operand, $modulus)
|
||||
{
|
||||
$result = gmp_powm($left_operand, $right_operand, $modulus);
|
||||
return gmp_strval($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $left_operand
|
||||
* @param string $right_operand
|
||||
* @return string
|
||||
*/
|
||||
public function sqrt($operand)
|
||||
{
|
||||
$result = gmp_sqrt($operand);
|
||||
return gmp_strval($result);
|
||||
}
|
||||
|
||||
|
||||
public function binaryToInteger($operand)
|
||||
{
|
||||
$result = '0';
|
||||
while (strlen($operand)) {
|
||||
$ord = ord(substr($operand, 0, 1));
|
||||
$result = gmp_add(gmp_mul($result, 256), $ord);
|
||||
$operand = substr($operand, 1);
|
||||
}
|
||||
return gmp_strval($result);
|
||||
}
|
||||
|
||||
|
||||
public function integerToBinary($operand)
|
||||
{
|
||||
$bigInt = gmp_strval($operand, 16);
|
||||
if (strlen($bigInt) % 2 != 0) {
|
||||
$bigInt = '0' . $bigInt;
|
||||
} else if ($bigInt[0] > '7') {
|
||||
$bigInt = '00' . $bigInt;
|
||||
}
|
||||
$return = pack("H*", $bigInt);
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
public function hexToDecimal($operand)
|
||||
{
|
||||
$return = '0';
|
||||
while(strlen($hex)) {
|
||||
$hex = hexdec(substr($operand, 0, 4));
|
||||
$dec = gmp_add(gmp_mul($return, 65536), $hex);
|
||||
$operand = substr($operand, 4);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
51
Zend/Crypt/Math/BigInteger/Interface.php
Executable file
51
Zend/Crypt/Math/BigInteger/Interface.php
Executable file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage Math
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Support for arbitrary precision mathematics in PHP.
|
||||
*
|
||||
* Interface for a wrapper across any PHP extension supporting arbitrary
|
||||
* precision maths.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Crypt_Math_BigInteger_Interface
|
||||
{
|
||||
|
||||
public function init($operand, $base = 10);
|
||||
public function add($left_operand, $right_operand);
|
||||
public function subtract($left_operand, $right_operand);
|
||||
public function compare($left_operand, $right_operand);
|
||||
public function divide($left_operand, $right_operand);
|
||||
public function modulus($left_operand, $modulus);
|
||||
public function multiply($left_operand, $right_operand);
|
||||
public function pow($left_operand, $right_operand);
|
||||
public function powmod($left_operand, $right_operand, $modulus);
|
||||
public function sqrt($operand);
|
||||
public function binaryToInteger($operand);
|
||||
public function integerToBinary($operand);
|
||||
public function hexToDecimal($operand);
|
||||
|
||||
}
|
||||
36
Zend/Crypt/Math/Exception.php
Executable file
36
Zend/Crypt/Math/Exception.php
Executable file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage Math
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Exception
|
||||
*/
|
||||
require_once 'Zend/Crypt/Exception.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_Math_Exception extends Zend_Crypt_Exception
|
||||
{
|
||||
}
|
||||
309
Zend/Crypt/Rsa.php
Executable file
309
Zend/Crypt/Rsa.php
Executable file
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage Rsa
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Rsa_Key_Private
|
||||
*/
|
||||
require_once 'Zend/Crypt/Rsa/Key/Private.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Rsa_Key_Public
|
||||
*/
|
||||
require_once 'Zend/Crypt/Rsa/Key/Public.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_Rsa
|
||||
{
|
||||
|
||||
const BINARY = 'binary';
|
||||
const BASE64 = 'base64';
|
||||
|
||||
protected $_privateKey = null;
|
||||
|
||||
protected $_publicKey = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_pemString = null;
|
||||
|
||||
protected $_pemPath = null;
|
||||
|
||||
protected $_certificateString = null;
|
||||
|
||||
protected $_certificatePath = null;
|
||||
|
||||
protected $_hashAlgorithm = OPENSSL_ALGO_SHA1;
|
||||
|
||||
protected $_passPhrase = null;
|
||||
|
||||
public function __construct(array $options = null)
|
||||
{
|
||||
if (isset($options)) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
}
|
||||
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
if (isset($options['passPhrase'])) {
|
||||
$this->_passPhrase = $options['passPhrase'];
|
||||
}
|
||||
foreach ($options as $option=>$value) {
|
||||
switch ($option) {
|
||||
case 'pemString':
|
||||
$this->setPemString($value);
|
||||
break;
|
||||
case 'pemPath':
|
||||
$this->setPemPath($value);
|
||||
break;
|
||||
case 'certificateString':
|
||||
$this->setCertificateString($value);
|
||||
break;
|
||||
case 'certificatePath':
|
||||
$this->setCertificatePath($value);
|
||||
break;
|
||||
case 'hashAlgorithm':
|
||||
$this->setHashAlgorithm($value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getPrivateKey()
|
||||
{
|
||||
return $this->_privateKey;
|
||||
}
|
||||
|
||||
public function getPublicKey()
|
||||
{
|
||||
return $this->_publicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @param Zend_Crypt_Rsa_Key_Private $privateKey
|
||||
* @param string $format
|
||||
* @return string
|
||||
*/
|
||||
public function sign($data, Zend_Crypt_Rsa_Key_Private $privateKey = null, $format = null)
|
||||
{
|
||||
$signature = '';
|
||||
if (isset($privateKey)) {
|
||||
$opensslKeyResource = $privateKey->getOpensslKeyResource();
|
||||
} else {
|
||||
$opensslKeyResource = $this->_privateKey->getOpensslKeyResource();
|
||||
}
|
||||
$result = openssl_sign(
|
||||
$data, $signature,
|
||||
$opensslKeyResource,
|
||||
$this->getHashAlgorithm()
|
||||
);
|
||||
if ($format == self::BASE64) {
|
||||
return base64_encode($signature);
|
||||
}
|
||||
return $signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @param string $signature
|
||||
* @param string $format
|
||||
* @return string
|
||||
*/
|
||||
public function verifySignature($data, $signature, $format = null)
|
||||
{
|
||||
if ($format == self::BASE64) {
|
||||
$signature = base64_decode($signature);
|
||||
}
|
||||
$result = openssl_verify($data, $signature,
|
||||
$this->getPublicKey()->getOpensslKeyResource(),
|
||||
$this->getHashAlgorithm());
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @param Zend_Crypt_Rsa_Key $key
|
||||
* @param string $format
|
||||
* @return string
|
||||
*/
|
||||
public function encrypt($data, Zend_Crypt_Rsa_Key $key, $format = null)
|
||||
{
|
||||
$encrypted = '';
|
||||
$function = 'openssl_public_encrypt';
|
||||
if ($key instanceof Zend_Crypt_Rsa_Key_Private) {
|
||||
$function = 'openssl_private_encrypt';
|
||||
}
|
||||
$function($data, $encrypted, $key->getOpensslKeyResource());
|
||||
if ($format == self::BASE64) {
|
||||
return base64_encode($encrypted);
|
||||
}
|
||||
return $encrypted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @param Zend_Crypt_Rsa_Key $key
|
||||
* @param string $format
|
||||
* @return string
|
||||
*/
|
||||
public function decrypt($data, Zend_Crypt_Rsa_Key $key, $format = null)
|
||||
{
|
||||
$decrypted = '';
|
||||
if ($format == self::BASE64) {
|
||||
$data = base64_decode($data);
|
||||
}
|
||||
$function = 'openssl_private_decrypt';
|
||||
if ($key instanceof Zend_Crypt_Rsa_Key_Public) {
|
||||
$function = 'openssl_public_decrypt';
|
||||
}
|
||||
$function($data, $decrypted, $key->getOpensslKeyResource());
|
||||
return $decrypted;
|
||||
}
|
||||
|
||||
public function generateKeys(array $configargs = null)
|
||||
{
|
||||
$config = null;
|
||||
$passPhrase = null;
|
||||
if ($configargs !== null) {
|
||||
if (isset($configargs['passPhrase'])) {
|
||||
$passPhrase = $configargs['passPhrase'];
|
||||
unset($configargs['passPhrase']);
|
||||
}
|
||||
$config = $this->_parseConfigArgs($configargs);
|
||||
}
|
||||
$privateKey = null;
|
||||
$publicKey = null;
|
||||
$resource = openssl_pkey_new($config);
|
||||
// above fails on PHP 5.3
|
||||
openssl_pkey_export($resource, $private, $passPhrase);
|
||||
$privateKey = new Zend_Crypt_Rsa_Key_Private($private, $passPhrase);
|
||||
$details = openssl_pkey_get_details($resource);
|
||||
$publicKey = new Zend_Crypt_Rsa_Key_Public($details['key']);
|
||||
$return = new ArrayObject(array(
|
||||
'privateKey'=>$privateKey,
|
||||
'publicKey'=>$publicKey
|
||||
), ArrayObject::ARRAY_AS_PROPS);
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
public function setPemString($value)
|
||||
{
|
||||
$this->_pemString = $value;
|
||||
try {
|
||||
$this->_privateKey = new Zend_Crypt_Rsa_Key_Private($this->_pemString, $this->_passPhrase);
|
||||
$this->_publicKey = $this->_privateKey->getPublicKey();
|
||||
} catch (Zend_Crypt_Exception $e) {
|
||||
$this->_privateKey = null;
|
||||
$this->_publicKey = new Zend_Crypt_Rsa_Key_Public($this->_pemString);
|
||||
}
|
||||
}
|
||||
|
||||
public function setPemPath($value)
|
||||
{
|
||||
$this->_pemPath = $value;
|
||||
$this->setPemString(file_get_contents($this->_pemPath));
|
||||
}
|
||||
|
||||
public function setCertificateString($value)
|
||||
{
|
||||
$this->_certificateString = $value;
|
||||
$this->_publicKey = new Zend_Crypt_Rsa_Key_Public($this->_certificateString, $this->_passPhrase);
|
||||
}
|
||||
|
||||
public function setCertificatePath($value)
|
||||
{
|
||||
$this->_certificatePath = $value;
|
||||
$this->setCertificateString(file_get_contents($this->_certificatePath));
|
||||
}
|
||||
|
||||
public function setHashAlgorithm($name)
|
||||
{
|
||||
switch (strtolower($name)) {
|
||||
case 'md2':
|
||||
$this->_hashAlgorithm = OPENSSL_ALGO_MD2;
|
||||
break;
|
||||
case 'md4':
|
||||
$this->_hashAlgorithm = OPENSSL_ALGO_MD4;
|
||||
break;
|
||||
case 'md5':
|
||||
$this->_hashAlgorithm = OPENSSL_ALGO_MD5;
|
||||
break;
|
||||
case 'sha1':
|
||||
$this->_hashAlgorithm = OPENSSL_ALGO_SHA1;
|
||||
break;
|
||||
case 'dss1':
|
||||
$this->_hashAlgorithm = OPENSSL_ALGO_DSS1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPemString()
|
||||
{
|
||||
return $this->_pemString;
|
||||
}
|
||||
|
||||
public function getPemPath()
|
||||
{
|
||||
return $this->_pemPath;
|
||||
}
|
||||
|
||||
public function getCertificateString()
|
||||
{
|
||||
return $this->_certificateString;
|
||||
}
|
||||
|
||||
public function getCertificatePath()
|
||||
{
|
||||
return $this->_certificatePath;
|
||||
}
|
||||
|
||||
public function getHashAlgorithm()
|
||||
{
|
||||
return $this->_hashAlgorithm;
|
||||
}
|
||||
|
||||
protected function _parseConfigArgs(array $config = null)
|
||||
{
|
||||
$configs = array();
|
||||
if (isset($config['privateKeyBits'])) {
|
||||
$configs['private_key_bits'] = $config['privateKeyBits'];
|
||||
}
|
||||
if (!empty($configs)) {
|
||||
return $configs;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
95
Zend/Crypt/Rsa/Key.php
Executable file
95
Zend/Crypt/Rsa/Key.php
Executable file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage Rsa
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_Rsa_Key implements Countable
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_pemString = null;
|
||||
|
||||
/**
|
||||
* Bits, key string and type of key
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_details = array();
|
||||
|
||||
/**
|
||||
* Key Resource
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $_opensslKeyResource = null;
|
||||
|
||||
/**
|
||||
* Retrieves key resource
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
public function getOpensslKeyResource()
|
||||
{
|
||||
return $this->_opensslKeyResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws Zend_Crypt_Exception
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
if (!empty($this->_pemString)) {
|
||||
return $this->_pemString;
|
||||
} elseif (!empty($this->_certificateString)) {
|
||||
return $this->_certificateString;
|
||||
}
|
||||
/**
|
||||
* @see Zend_Crypt_Exception
|
||||
*/
|
||||
require_once 'Zend/Crypt/Exception.php';
|
||||
throw new Zend_Crypt_Exception('No public key string representation is available');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->toString();
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return $this->_details['bits'];
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->_details['type'];
|
||||
}
|
||||
}
|
||||
75
Zend/Crypt/Rsa/Key/Private.php
Executable file
75
Zend/Crypt/Rsa/Key/Private.php
Executable file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage Rsa
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Rsa_Key
|
||||
*/
|
||||
require_once 'Zend/Crypt/Rsa/Key.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_Rsa_Key_Private extends Zend_Crypt_Rsa_Key
|
||||
{
|
||||
|
||||
protected $_publicKey = null;
|
||||
|
||||
public function __construct($pemString, $passPhrase = null)
|
||||
{
|
||||
$this->_pemString = $pemString;
|
||||
$this->_parse($passPhrase);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $passPhrase
|
||||
* @throws Zend_Crypt_Exception
|
||||
*/
|
||||
protected function _parse($passPhrase)
|
||||
{
|
||||
$result = openssl_get_privatekey($this->_pemString, $passPhrase);
|
||||
if (!$result) {
|
||||
/**
|
||||
* @see Zend_Crypt_Exception
|
||||
*/
|
||||
require_once 'Zend/Crypt/Exception.php';
|
||||
throw new Zend_Crypt_Exception('Unable to load private key');
|
||||
}
|
||||
$this->_opensslKeyResource = $result;
|
||||
$this->_details = openssl_pkey_get_details($this->_opensslKeyResource);
|
||||
}
|
||||
|
||||
public function getPublicKey()
|
||||
{
|
||||
if ($this->_publicKey === null) {
|
||||
/**
|
||||
* @see Zend_Crypt_Rsa_Key_Public
|
||||
*/
|
||||
require_once 'Zend/Crypt/Rsa/Key/Public.php';
|
||||
$this->_publicKey = new Zend_Crypt_Rsa_Key_Public($this->_details['key']);
|
||||
}
|
||||
return $this->_publicKey;
|
||||
}
|
||||
|
||||
}
|
||||
74
Zend/Crypt/Rsa/Key/Public.php
Executable file
74
Zend/Crypt/Rsa/Key/Public.php
Executable file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @subpackage Rsa
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Rsa_Key
|
||||
*/
|
||||
require_once 'Zend/Crypt/Rsa/Key.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Crypt
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Crypt_Rsa_Key_Public extends Zend_Crypt_Rsa_Key
|
||||
{
|
||||
|
||||
protected $_certificateString = null;
|
||||
|
||||
public function __construct($string)
|
||||
{
|
||||
$this->_parse($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @throws Zend_Crypt_Exception
|
||||
*/
|
||||
protected function _parse($string)
|
||||
{
|
||||
if (preg_match("/^-----BEGIN CERTIFICATE-----/", $string)) {
|
||||
$this->_certificateString = $string;
|
||||
} else {
|
||||
$this->_pemString = $string;
|
||||
}
|
||||
$result = openssl_get_publickey($string);
|
||||
if (!$result) {
|
||||
/**
|
||||
* @see Zend_Crypt_Exception
|
||||
*/
|
||||
require_once 'Zend/Crypt/Exception.php';
|
||||
throw new Zend_Crypt_Exception('Unable to load public key');
|
||||
}
|
||||
//openssl_pkey_export($result, $public);
|
||||
//$this->_pemString = $public;
|
||||
$this->_opensslKeyResource = $result;
|
||||
$this->_details = openssl_pkey_get_details($this->_opensslKeyResource);
|
||||
}
|
||||
|
||||
public function getCertificate()
|
||||
{
|
||||
return $this->_certificateString;
|
||||
}
|
||||
|
||||
}
|
||||
95
Zend/Exception.php
Executable file
95
Zend/Exception.php
Executable file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Exception extends Exception
|
||||
{
|
||||
/**
|
||||
* @var null|Exception
|
||||
*/
|
||||
private $_previous = null;
|
||||
|
||||
/**
|
||||
* Construct the exception
|
||||
*
|
||||
* @param string $msg
|
||||
* @param int $code
|
||||
* @param Exception $previous
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($msg = '', $code = 0, Exception $previous = null)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
|
||||
parent::__construct($msg, (int) $code);
|
||||
$this->_previous = $previous;
|
||||
} else {
|
||||
parent::__construct($msg, (int) $code, $previous);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloading
|
||||
*
|
||||
* For PHP < 5.3.0, provides access to the getPrevious() method.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, array $args)
|
||||
{
|
||||
if ('getprevious' == strtolower($method)) {
|
||||
return $this->_getPrevious();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* String representation of the exception
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
|
||||
if (null !== ($e = $this->getPrevious())) {
|
||||
return $e->__toString()
|
||||
. "\n\nNext "
|
||||
. parent::__toString();
|
||||
}
|
||||
}
|
||||
return parent::__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns previous Exception
|
||||
*
|
||||
* @return Exception|null
|
||||
*/
|
||||
protected function _getPrevious()
|
||||
{
|
||||
return $this->_previous;
|
||||
}
|
||||
}
|
||||
241
Zend/Gdata.php
Executable file
241
Zend/Gdata.php
Executable file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage Gdata
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Gdata_App
|
||||
*/
|
||||
require_once 'Zend/Gdata/App.php';
|
||||
|
||||
/**
|
||||
* Provides functionality to interact with Google data APIs
|
||||
* Subclasses exist to implement service-specific features
|
||||
*
|
||||
* As the Google data API protocol is based upon the Atom Publishing Protocol
|
||||
* (APP), Gdata functionality extends the appropriate Zend_Gdata_App classes
|
||||
*
|
||||
* @link http://code.google.com/apis/gdata/overview.html
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage Gdata
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata extends Zend_Gdata_App
|
||||
{
|
||||
|
||||
/**
|
||||
* Service name for use with Google's authentication mechanisms
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const AUTH_SERVICE_NAME = 'xapi';
|
||||
|
||||
/**
|
||||
* Default URI to which to POST.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_defaultPostUri = null;
|
||||
|
||||
/**
|
||||
* Packages to search for classes when using magic __call method, in order.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_registeredPackages = array(
|
||||
'Zend_Gdata_Kind',
|
||||
'Zend_Gdata_Extension',
|
||||
'Zend_Gdata',
|
||||
'Zend_Gdata_App_Extension',
|
||||
'Zend_Gdata_App');
|
||||
|
||||
/**
|
||||
* Namespaces used for Gdata data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $namespaces = array(
|
||||
array('gd', 'http://schemas.google.com/g/2005', 1, 0),
|
||||
array('openSearch', 'http://a9.com/-/spec/opensearchrss/1.0/', 1, 0),
|
||||
array('openSearch', 'http://a9.com/-/spec/opensearch/1.1/', 2, 0),
|
||||
array('rss', 'http://blogs.law.harvard.edu/tech/rss', 1, 0)
|
||||
);
|
||||
|
||||
/**
|
||||
* Client object used to communicate
|
||||
*
|
||||
* @var Zend_Gdata_HttpClient
|
||||
*/
|
||||
protected $_httpClient;
|
||||
|
||||
/**
|
||||
* Client object used to communicate in static context
|
||||
*
|
||||
* @var Zend_Gdata_HttpClient
|
||||
*/
|
||||
protected static $_staticHttpClient = null;
|
||||
|
||||
/**
|
||||
* Create Gdata object
|
||||
*
|
||||
* @param Zend_Http_Client $client
|
||||
* @param string $applicationId The identity of the app in the form of
|
||||
* Company-AppName-Version
|
||||
*/
|
||||
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
|
||||
{
|
||||
parent::__construct($client, $applicationId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports a feed located at $uri.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param Zend_Http_Client $client The client used for communication
|
||||
* @param string $className The class which is used as the return type
|
||||
* @throws Zend_Gdata_App_Exception
|
||||
* @return string|Zend_Gdata_App_Feed Returns string only if the object
|
||||
* mapping has been disabled explicitly
|
||||
* by passing false to the
|
||||
* useObjectMapping() function.
|
||||
*/
|
||||
public static function import($uri, $client = null,
|
||||
$className='Zend_Gdata_Feed')
|
||||
{
|
||||
$app = new Zend_Gdata($client);
|
||||
$requestData = $app->decodeRequest('GET', $uri);
|
||||
$response = $app->performHttpRequest($requestData['method'], $requestData['url']);
|
||||
|
||||
$feedContent = $response->getBody();
|
||||
|
||||
$feed = self::importString($feedContent, $className);
|
||||
if ($client != null) {
|
||||
$feed->setHttpClient($client);
|
||||
}
|
||||
return $feed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve feed as string or object
|
||||
*
|
||||
* @param mixed $location The location as string or Zend_Gdata_Query
|
||||
* @param string $className The class type to use for returning the feed
|
||||
* @throws Zend_Gdata_App_InvalidArgumentException
|
||||
* @return string|Zend_Gdata_App_Feed Returns string only if the object
|
||||
* mapping has been disabled explicitly
|
||||
* by passing false to the
|
||||
* useObjectMapping() function.
|
||||
*/
|
||||
public function getFeed($location, $className='Zend_Gdata_Feed')
|
||||
{
|
||||
if (is_string($location)) {
|
||||
$uri = $location;
|
||||
} elseif ($location instanceof Zend_Gdata_Query) {
|
||||
$uri = $location->getQueryUrl();
|
||||
} else {
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'You must specify the location as either a string URI ' .
|
||||
'or a child of Zend_Gdata_Query');
|
||||
}
|
||||
return parent::getFeed($uri, $className);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve entry as string or object
|
||||
*
|
||||
* @param mixed $location The location as string or Zend_Gdata_Query
|
||||
* @throws Zend_Gdata_App_InvalidArgumentException
|
||||
* @return string|Zend_Gdata_App_Entry Returns string only if the object
|
||||
* mapping has been disabled explicitly
|
||||
* by passing false to the
|
||||
* useObjectMapping() function.
|
||||
*/
|
||||
public function getEntry($location, $className='Zend_Gdata_Entry')
|
||||
{
|
||||
if (is_string($location)) {
|
||||
$uri = $location;
|
||||
} elseif ($location instanceof Zend_Gdata_Query) {
|
||||
$uri = $location->getQueryUrl();
|
||||
} else {
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'You must specify the location as either a string URI ' .
|
||||
'or a child of Zend_Gdata_Query');
|
||||
}
|
||||
return parent::getEntry($uri, $className);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a HTTP request using the specified method.
|
||||
*
|
||||
* Overrides the definition in the parent (Zend_Gdata_App)
|
||||
* and uses the Zend_Gdata_HttpClient functionality
|
||||
* to filter the HTTP requests and responses.
|
||||
*
|
||||
* @param string $method The HTTP method for the request -
|
||||
* 'GET', 'POST', 'PUT', 'DELETE'
|
||||
* @param string $url The URL to which this request is being performed,
|
||||
* or null if found in $data
|
||||
* @param array $headers An associative array of HTTP headers
|
||||
* for this request
|
||||
* @param string $body The body of the HTTP request
|
||||
* @param string $contentType The value for the content type of the
|
||||
* request body
|
||||
* @param int $remainingRedirects Number of redirects to follow
|
||||
* if requests results in one
|
||||
* @return Zend_Http_Response The response object
|
||||
*/
|
||||
public function performHttpRequest($method, $url, $headers = array(), $body = null, $contentType = null, $remainingRedirects = null)
|
||||
{
|
||||
if ($this->_httpClient instanceof Zend_Gdata_HttpClient) {
|
||||
$filterResult = $this->_httpClient->filterHttpRequest($method, $url, $headers, $body, $contentType);
|
||||
$method = $filterResult['method'];
|
||||
$url = $filterResult['url'];
|
||||
$body = $filterResult['body'];
|
||||
$headers = $filterResult['headers'];
|
||||
$contentType = $filterResult['contentType'];
|
||||
return $this->_httpClient->filterHttpResponse(parent::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects));
|
||||
} else {
|
||||
return parent::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether service object is authenticated.
|
||||
*
|
||||
* @return boolean True if service object is authenticated, false otherwise.
|
||||
*/
|
||||
public function isAuthenticated()
|
||||
{
|
||||
$client = parent::getHttpClient();
|
||||
if ($client->getClientLoginToken() ||
|
||||
$client->getAuthSubToken()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
1234
Zend/Gdata/App.php
Executable file
1234
Zend/Gdata/App.php
Executable file
File diff suppressed because it is too large
Load Diff
41
Zend/Gdata/App/AuthException.php
Executable file
41
Zend/Gdata/App/AuthException.php
Executable file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Exception
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
|
||||
/**
|
||||
* Gdata exceptions
|
||||
*
|
||||
* Class to represent exceptions that occur during Gdata operations.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_AuthException extends Zend_Gdata_App_Exception
|
||||
{
|
||||
}
|
||||
42
Zend/Gdata/App/BadMethodCallException.php
Executable file
42
Zend/Gdata/App/BadMethodCallException.php
Executable file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Gdata_App_Exception
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
|
||||
/**
|
||||
* Gdata APP exceptions
|
||||
*
|
||||
* Class to represent exceptions that occur during Gdata APP operations.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_BadMethodCallException extends Zend_Gdata_App_Exception
|
||||
{
|
||||
}
|
||||
572
Zend/Gdata/App/Base.php
Executable file
572
Zend/Gdata/App/Base.php
Executable file
@@ -0,0 +1,572 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Util
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Util.php';
|
||||
|
||||
/**
|
||||
* Abstract class for all XML elements
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Gdata_App_Base
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string The XML element name, including prefix if desired
|
||||
*/
|
||||
protected $_rootElement = null;
|
||||
|
||||
/**
|
||||
* @var string The XML namespace prefix
|
||||
*/
|
||||
protected $_rootNamespace = 'atom';
|
||||
|
||||
/**
|
||||
* @var string The XML namespace URI - takes precedence over lookup up the
|
||||
* corresponding URI for $_rootNamespace
|
||||
*/
|
||||
protected $_rootNamespaceURI = null;
|
||||
|
||||
/**
|
||||
* @var array Leftover elements which were not handled
|
||||
*/
|
||||
protected $_extensionElements = array();
|
||||
|
||||
/**
|
||||
* @var array Leftover attributes which were not handled
|
||||
*/
|
||||
protected $_extensionAttributes = array();
|
||||
|
||||
/**
|
||||
* @var string XML child text node content
|
||||
*/
|
||||
protected $_text = null;
|
||||
|
||||
/**
|
||||
* @var array Memoized results from calls to lookupNamespace() to avoid
|
||||
* expensive calls to getGreatestBoundedValue(). The key is in the
|
||||
* form 'prefix-majorVersion-minorVersion', and the value is the
|
||||
* output from getGreatestBoundedValue().
|
||||
*/
|
||||
protected static $_namespaceLookupCache = array();
|
||||
|
||||
/**
|
||||
* List of namespaces, as a three-dimensional array. The first dimension
|
||||
* represents the namespace prefix, the second dimension represents the
|
||||
* minimum major protocol version, and the third dimension is the minimum
|
||||
* minor protocol version. Null keys are NOT allowed.
|
||||
*
|
||||
* When looking up a namespace for a given prefix, the greatest version
|
||||
* number (both major and minor) which is less than the effective version
|
||||
* should be used.
|
||||
*
|
||||
* @see lookupNamespace()
|
||||
* @see registerNamespace()
|
||||
* @see registerAllNamespaces()
|
||||
* @var array
|
||||
*/
|
||||
protected $_namespaces = array(
|
||||
'atom' => array(
|
||||
1 => array(
|
||||
0 => 'http://www.w3.org/2005/Atom'
|
||||
)
|
||||
),
|
||||
'app' => array(
|
||||
1 => array(
|
||||
0 => 'http://purl.org/atom/app#'
|
||||
),
|
||||
2 => array(
|
||||
0 => 'http://www.w3.org/2007/app'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the child text node of this element
|
||||
* This represents any raw text contained within the XML element
|
||||
*
|
||||
* @return string Child text node
|
||||
*/
|
||||
public function getText($trim = true)
|
||||
{
|
||||
if ($trim) {
|
||||
return trim($this->_text);
|
||||
} else {
|
||||
return $this->_text;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the child text node of this element
|
||||
* This represents any raw text contained within the XML element
|
||||
*
|
||||
* @param string $value Child text node
|
||||
* @return Zend_Gdata_App_Base Returns an object of the same type as 'this' to provide a fluent interface.
|
||||
*/
|
||||
public function setText($value)
|
||||
{
|
||||
$this->_text = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all elements not matched to data model classes
|
||||
* during the parsing of the XML
|
||||
*
|
||||
* @return array All elements not matched to data model classes during parsing
|
||||
*/
|
||||
public function getExtensionElements()
|
||||
{
|
||||
return $this->_extensionElements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an array of all elements not matched to data model classes
|
||||
* during the parsing of the XML. This method can be used to add arbitrary
|
||||
* child XML elements to any data model class.
|
||||
*
|
||||
* @param array $value All extension elements
|
||||
* @return Zend_Gdata_App_Base Returns an object of the same type as 'this' to provide a fluent interface.
|
||||
*/
|
||||
public function setExtensionElements($value)
|
||||
{
|
||||
$this->_extensionElements = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all extension attributes not transformed into data
|
||||
* model properties during parsing of the XML. Each element of the array
|
||||
* is a hashed array of the format:
|
||||
* array('namespaceUri' => string, 'name' => string, 'value' => string);
|
||||
*
|
||||
* @return array All extension attributes
|
||||
*/
|
||||
public function getExtensionAttributes()
|
||||
{
|
||||
return $this->_extensionAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an array of all extension attributes not transformed into data
|
||||
* model properties during parsing of the XML. Each element of the array
|
||||
* is a hashed array of the format:
|
||||
* array('namespaceUri' => string, 'name' => string, 'value' => string);
|
||||
* This can be used to add arbitrary attributes to any data model element
|
||||
*
|
||||
* @param array $value All extension attributes
|
||||
* @return Zend_Gdata_App_Base Returns an object of the same type as 'this' to provide a fluent interface.
|
||||
*/
|
||||
public function setExtensionAttributes($value)
|
||||
{
|
||||
$this->_extensionAttributes = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a DOMElement which corresponds to this element and all
|
||||
* child properties. This is used to build an entry back into a DOM
|
||||
* and eventually XML text for sending to the server upon updates, or
|
||||
* for application storage/persistence.
|
||||
*
|
||||
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
|
||||
* @return DOMElement The DOMElement representing this element and all
|
||||
* child properties.
|
||||
*/
|
||||
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
||||
{
|
||||
if ($doc === null) {
|
||||
$doc = new DOMDocument('1.0', 'utf-8');
|
||||
}
|
||||
if ($this->_rootNamespaceURI != null) {
|
||||
$element = $doc->createElementNS($this->_rootNamespaceURI, $this->_rootElement);
|
||||
} elseif ($this->_rootNamespace !== null) {
|
||||
if (strpos($this->_rootElement, ':') === false) {
|
||||
$elementName = $this->_rootNamespace . ':' . $this->_rootElement;
|
||||
} else {
|
||||
$elementName = $this->_rootElement;
|
||||
}
|
||||
$element = $doc->createElementNS($this->lookupNamespace($this->_rootNamespace), $elementName);
|
||||
} else {
|
||||
$element = $doc->createElement($this->_rootElement);
|
||||
}
|
||||
if ($this->_text != null) {
|
||||
$element->appendChild($element->ownerDocument->createTextNode($this->_text));
|
||||
}
|
||||
foreach ($this->_extensionElements as $extensionElement) {
|
||||
$element->appendChild($extensionElement->getDOM($element->ownerDocument));
|
||||
}
|
||||
foreach ($this->_extensionAttributes as $attribute) {
|
||||
$element->setAttribute($attribute['name'], $attribute['value']);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a child DOMNode, tries to determine how to map the data into
|
||||
* object instance members. If no mapping is defined, Extension_Element
|
||||
* objects are created and stored in an array.
|
||||
*
|
||||
* @param DOMNode $child The DOMNode needed to be handled
|
||||
*/
|
||||
protected function takeChildFromDOM($child)
|
||||
{
|
||||
if ($child->nodeType == XML_TEXT_NODE) {
|
||||
$this->_text = $child->nodeValue;
|
||||
} else {
|
||||
$extensionElement = new Zend_Gdata_App_Extension_Element();
|
||||
$extensionElement->transferFromDOM($child);
|
||||
$this->_extensionElements[] = $extensionElement;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a DOMNode representing an attribute, tries to map the data into
|
||||
* instance members. If no mapping is defined, the name and value are
|
||||
* stored in an array.
|
||||
*
|
||||
* @param DOMNode $attribute The DOMNode attribute needed to be handled
|
||||
*/
|
||||
protected function takeAttributeFromDOM($attribute)
|
||||
{
|
||||
$arrayIndex = ($attribute->namespaceURI != '')?(
|
||||
$attribute->namespaceURI . ':' . $attribute->name):
|
||||
$attribute->name;
|
||||
$this->_extensionAttributes[$arrayIndex] =
|
||||
array('namespaceUri' => $attribute->namespaceURI,
|
||||
'name' => $attribute->localName,
|
||||
'value' => $attribute->nodeValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers each child and attribute into member variables.
|
||||
* This is called when XML is received over the wire and the data
|
||||
* model needs to be built to represent this XML.
|
||||
*
|
||||
* @param DOMNode $node The DOMNode that represents this object's data
|
||||
*/
|
||||
public function transferFromDOM($node)
|
||||
{
|
||||
foreach ($node->childNodes as $child) {
|
||||
$this->takeChildFromDOM($child);
|
||||
}
|
||||
foreach ($node->attributes as $attribute) {
|
||||
$this->takeAttributeFromDOM($attribute);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the provided XML text and generates data model classes for
|
||||
* each know element by turning the XML text into a DOM tree and calling
|
||||
* transferFromDOM($element). The first data model element with the same
|
||||
* name as $this->_rootElement is used and the child elements are
|
||||
* recursively parsed.
|
||||
*
|
||||
* @param string $xml The XML text to parse
|
||||
*/
|
||||
public function transferFromXML($xml)
|
||||
{
|
||||
if ($xml) {
|
||||
// Load the feed as an XML DOMDocument object
|
||||
@ini_set('track_errors', 1);
|
||||
$doc = new DOMDocument();
|
||||
$success = @$doc->loadXML($xml);
|
||||
@ini_restore('track_errors');
|
||||
if (!$success) {
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
throw new Zend_Gdata_App_Exception("DOMDocument cannot parse XML: $php_errormsg");
|
||||
}
|
||||
$element = $doc->getElementsByTagName($this->_rootElement)->item(0);
|
||||
if (!$element) {
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
throw new Zend_Gdata_App_Exception('No root <' . $this->_rootElement . '> element');
|
||||
}
|
||||
$this->transferFromDOM($element);
|
||||
} else {
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
throw new Zend_Gdata_App_Exception('XML passed to transferFromXML cannot be null');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts this element and all children into XML text using getDOM()
|
||||
*
|
||||
* @return string XML content
|
||||
*/
|
||||
public function saveXML()
|
||||
{
|
||||
$element = $this->getDOM();
|
||||
return $element->ownerDocument->saveXML($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for saveXML() returns XML content for this element and all
|
||||
* children
|
||||
*
|
||||
* @return string XML content
|
||||
*/
|
||||
public function getXML()
|
||||
{
|
||||
return $this->saveXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for saveXML()
|
||||
*
|
||||
* Can be overridden by children to provide more complex representations
|
||||
* of entries.
|
||||
*
|
||||
* @return string Encoded string content
|
||||
*/
|
||||
public function encode()
|
||||
{
|
||||
return $this->saveXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full version of a namespace prefix
|
||||
*
|
||||
* Looks up a prefix (atom:, etc.) in the list of registered
|
||||
* namespaces and returns the full namespace URI if
|
||||
* available. Returns the prefix, unmodified, if it's not
|
||||
* registered.
|
||||
*
|
||||
* @param string $prefix The namespace prefix to lookup.
|
||||
* @param integer $majorVersion The major protocol version in effect.
|
||||
* Defaults to '1'.
|
||||
* @param integer $minorVersion The minor protocol version in effect.
|
||||
* Defaults to null (use latest).
|
||||
* @return string
|
||||
*/
|
||||
public function lookupNamespace($prefix,
|
||||
$majorVersion = 1,
|
||||
$minorVersion = null)
|
||||
{
|
||||
// Check for a memoized result
|
||||
$key = $prefix . ' ' .
|
||||
(is_null($majorVersion) ? 'NULL' : $majorVersion) .
|
||||
' '. (is_null($minorVersion) ? 'NULL' : $minorVersion);
|
||||
if (array_key_exists($key, self::$_namespaceLookupCache))
|
||||
return self::$_namespaceLookupCache[$key];
|
||||
// If no match, return the prefix by default
|
||||
$result = $prefix;
|
||||
|
||||
// Find tuple of keys that correspond to the namespace we should use
|
||||
if (isset($this->_namespaces[$prefix])) {
|
||||
// Major version search
|
||||
$nsData = $this->_namespaces[$prefix];
|
||||
$foundMajorV = Zend_Gdata_App_Util::findGreatestBoundedValue(
|
||||
$majorVersion, $nsData);
|
||||
// Minor version search
|
||||
$nsData = $nsData[$foundMajorV];
|
||||
$foundMinorV = Zend_Gdata_App_Util::findGreatestBoundedValue(
|
||||
$minorVersion, $nsData);
|
||||
// Extract NS
|
||||
$result = $nsData[$foundMinorV];
|
||||
}
|
||||
|
||||
// Memoize result
|
||||
self::$_namespaceLookupCache[$key] = $result;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a namespace and prefix to the registered list
|
||||
*
|
||||
* Takes a prefix and a full namespace URI and adds them to the
|
||||
* list of registered namespaces for use by
|
||||
* $this->lookupNamespace().
|
||||
*
|
||||
* WARNING: Currently, registering a namespace will NOT invalidate any
|
||||
* memoized data stored in $_namespaceLookupCache. Under normal
|
||||
* use, this behavior is acceptable. If you are adding
|
||||
* contradictory data to the namespace lookup table, you must
|
||||
* call flushNamespaceLookupCache().
|
||||
*
|
||||
* @param string $prefix The namespace prefix
|
||||
* @param string $namespaceUri The full namespace URI
|
||||
* @param integer $majorVersion The major protocol version in effect.
|
||||
* Defaults to '1'.
|
||||
* @param integer $minorVersion The minor protocol version in effect.
|
||||
* Defaults to null (use latest).
|
||||
* @return void
|
||||
*/
|
||||
public function registerNamespace($prefix,
|
||||
$namespaceUri,
|
||||
$majorVersion = 1,
|
||||
$minorVersion = 0)
|
||||
{
|
||||
$this->_namespaces[$prefix][$majorVersion][$minorVersion] =
|
||||
$namespaceUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush namespace lookup cache.
|
||||
*
|
||||
* Empties the namespace lookup cache. Call this function if you have
|
||||
* added data to the namespace lookup table that contradicts values that
|
||||
* may have been cached during a previous call to lookupNamespace().
|
||||
*/
|
||||
public static function flushNamespaceLookupCache()
|
||||
{
|
||||
self::$_namespaceLookupCache = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an array of namespaces to the registered list.
|
||||
*
|
||||
* Takes an array in the format of:
|
||||
* namespace prefix, namespace URI, major protocol version,
|
||||
* minor protocol version and adds them with calls to ->registerNamespace()
|
||||
*
|
||||
* @param array $namespaceArray An array of namespaces.
|
||||
* @return void
|
||||
*/
|
||||
public function registerAllNamespaces($namespaceArray)
|
||||
{
|
||||
foreach($namespaceArray as $namespace) {
|
||||
$this->registerNamespace(
|
||||
$namespace[0], $namespace[1], $namespace[2], $namespace[3]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Magic getter to allow access like $entry->foo to call $entry->getFoo()
|
||||
* Alternatively, if no getFoo() is defined, but a $_foo protected variable
|
||||
* is defined, this is returned.
|
||||
*
|
||||
* TODO Remove ability to bypass getFoo() methods??
|
||||
*
|
||||
* @param string $name The variable name sought
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
$method = 'get'.ucfirst($name);
|
||||
if (method_exists($this, $method)) {
|
||||
return call_user_func(array(&$this, $method));
|
||||
} else if (property_exists($this, "_${name}")) {
|
||||
return $this->{'_' . $name};
|
||||
} else {
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'Property ' . $name . ' does not exist');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic setter to allow acces like $entry->foo='bar' to call
|
||||
* $entry->setFoo('bar') automatically.
|
||||
*
|
||||
* Alternatively, if no setFoo() is defined, but a $_foo protected variable
|
||||
* is defined, this is returned.
|
||||
*
|
||||
* TODO Remove ability to bypass getFoo() methods??
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function __set($name, $val)
|
||||
{
|
||||
$method = 'set'.ucfirst($name);
|
||||
if (method_exists($this, $method)) {
|
||||
return call_user_func(array(&$this, $method), $val);
|
||||
} else if (isset($this->{'_' . $name}) || ($this->{'_' . $name} === null)) {
|
||||
$this->{'_' . $name} = $val;
|
||||
} else {
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'Property ' . $name . ' does not exist');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic __isset method
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function __isset($name)
|
||||
{
|
||||
$rc = new ReflectionClass(get_class($this));
|
||||
$privName = '_' . $name;
|
||||
if (!($rc->hasProperty($privName))) {
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'Property ' . $name . ' does not exist');
|
||||
} else {
|
||||
if (isset($this->{$privName})) {
|
||||
if (is_array($this->{$privName})) {
|
||||
if (count($this->{$privName}) > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic __unset method
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function __unset($name)
|
||||
{
|
||||
if (isset($this->{'_' . $name})) {
|
||||
if (is_array($this->{'_' . $name})) {
|
||||
$this->{'_' . $name} = array();
|
||||
} else {
|
||||
$this->{'_' . $name} = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic toString method allows using this directly via echo
|
||||
* Works best in PHP >= 4.2.0
|
||||
*
|
||||
* @return string The text representation of this object
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getText();
|
||||
}
|
||||
|
||||
}
|
||||
179
Zend/Gdata/App/BaseMediaSource.php
Executable file
179
Zend/Gdata/App/BaseMediaSource.php
Executable file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_MediaSource
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/MediaSource.php';
|
||||
|
||||
/**
|
||||
* Concrete class to use a file handle as an attachment within a MediaEntry.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Gdata_App_BaseMediaSource implements Zend_Gdata_App_MediaSource
|
||||
{
|
||||
|
||||
/**
|
||||
* The content type for the attached file (example image/png)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_contentType = null;
|
||||
|
||||
/**
|
||||
* The slug header value representing the attached file title, or null if
|
||||
* no slug should be used. The slug header is only necessary in some cases,
|
||||
* usually when a multipart upload is not being performed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_slug = null;
|
||||
|
||||
/**
|
||||
* The content type for the attached file (example image/png)
|
||||
*
|
||||
* @return string The content type
|
||||
*/
|
||||
public function getContentType()
|
||||
{
|
||||
return $this->_contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content type for the file attached (example image/png)
|
||||
*
|
||||
* @param string $value The content type
|
||||
* @return Zend_Gdata_App_MediaFileSource Provides a fluent interface
|
||||
*/
|
||||
public function setContentType($value)
|
||||
{
|
||||
$this->_contentType = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Slug header value. Used by some services to determine the
|
||||
* title for the uploaded file. Returns null if no slug should be used.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSlug(){
|
||||
return $this->_slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Slug header value. Used by some services to determine the
|
||||
* title for the uploaded file. A null value indicates no slug header.
|
||||
*
|
||||
* @var string The slug value
|
||||
* @return Zend_Gdata_App_MediaSource Provides a fluent interface
|
||||
*/
|
||||
public function setSlug($value){
|
||||
$this->_slug = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Magic getter to allow acces like $source->foo to call $source->getFoo()
|
||||
* Alternatively, if no getFoo() is defined, but a $_foo protected variable
|
||||
* is defined, this is returned.
|
||||
*
|
||||
* TODO Remove ability to bypass getFoo() methods??
|
||||
*
|
||||
* @param string $name The variable name sought
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
$method = 'get'.ucfirst($name);
|
||||
if (method_exists($this, $method)) {
|
||||
return call_user_func(array(&$this, $method));
|
||||
} else if (property_exists($this, "_${name}")) {
|
||||
return $this->{'_' . $name};
|
||||
} else {
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'Property ' . $name . ' does not exist');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic setter to allow acces like $source->foo='bar' to call
|
||||
* $source->setFoo('bar') automatically.
|
||||
*
|
||||
* Alternatively, if no setFoo() is defined, but a $_foo protected variable
|
||||
* is defined, this is returned.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function __set($name, $val)
|
||||
{
|
||||
$method = 'set'.ucfirst($name);
|
||||
if (method_exists($this, $method)) {
|
||||
return call_user_func(array(&$this, $method), $val);
|
||||
} else if (isset($this->{'_' . $name}) || ($this->{'_' . $name} === null)) {
|
||||
$this->{'_' . $name} = $val;
|
||||
} else {
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'Property ' . $name . ' does not exist');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic __isset method
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function __isset($name)
|
||||
{
|
||||
$rc = new ReflectionClass(get_class($this));
|
||||
$privName = '_' . $name;
|
||||
if (!($rc->hasProperty($privName))) {
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'Property ' . $name . ' does not exist');
|
||||
} else {
|
||||
if (isset($this->{$privName})) {
|
||||
if (is_array($this->{$privName})) {
|
||||
if (count($this->{$privName}) > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
94
Zend/Gdata/App/CaptchaRequiredException.php
Executable file
94
Zend/Gdata/App/CaptchaRequiredException.php
Executable file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_CaptchaRequiredException
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/AuthException.php';
|
||||
|
||||
/**
|
||||
* Gdata exceptions
|
||||
*
|
||||
* Class to represent an exception that occurs during the use of ClientLogin.
|
||||
* This particular exception happens when a CAPTCHA challenge is issued. This
|
||||
* challenge is a visual puzzle presented to the user to prove that they are
|
||||
* not an automated system.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_CaptchaRequiredException extends Zend_Gdata_App_AuthException
|
||||
{
|
||||
/**
|
||||
* The Google Accounts URL prefix.
|
||||
*/
|
||||
const ACCOUNTS_URL = 'https://www.google.com/accounts/';
|
||||
|
||||
/**
|
||||
* The token identifier from the server.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $captchaToken;
|
||||
|
||||
/**
|
||||
* The URL of the CAPTCHA image.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $captchaUrl;
|
||||
|
||||
/**
|
||||
* Constructs the exception to handle a CAPTCHA required response.
|
||||
*
|
||||
* @param string $captchaToken The CAPTCHA token ID provided by the server.
|
||||
* @param string $captchaUrl The URL to the CAPTCHA challenge image.
|
||||
*/
|
||||
public function __construct($captchaToken, $captchaUrl) {
|
||||
$this->captchaToken = $captchaToken;
|
||||
$this->captchaUrl = Zend_Gdata_App_CaptchaRequiredException::ACCOUNTS_URL . $captchaUrl;
|
||||
parent::__construct('CAPTCHA challenge issued by server');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the token identifier as provided by the server.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCaptchaToken() {
|
||||
return $this->captchaToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the URL CAPTCHA image as provided by the server.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCaptchaUrl() {
|
||||
return $this->captchaUrl;
|
||||
}
|
||||
|
||||
}
|
||||
389
Zend/Gdata/App/Entry.php
Executable file
389
Zend/Gdata/App/Entry.php
Executable file
@@ -0,0 +1,389 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_FeedEntryParent
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/FeedEntryParent.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Content
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Content.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Edited
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Edited.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Published
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Published.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Source
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Source.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Summary
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Summary.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Control
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Control.php';
|
||||
|
||||
/**
|
||||
* Concrete class for working with Atom entries.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Entry extends Zend_Gdata_App_FeedEntryParent
|
||||
{
|
||||
|
||||
/**
|
||||
* Root XML element for Atom entries.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_rootElement = 'entry';
|
||||
|
||||
/**
|
||||
* Class name for each entry in this feed*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_entryClassName = 'Zend_Gdata_App_Entry';
|
||||
|
||||
/**
|
||||
* atom:content element
|
||||
*
|
||||
* @var Zend_Gdata_App_Extension_Content
|
||||
*/
|
||||
protected $_content = null;
|
||||
|
||||
/**
|
||||
* atom:published element
|
||||
*
|
||||
* @var Zend_Gdata_App_Extension_Published
|
||||
*/
|
||||
protected $_published = null;
|
||||
|
||||
/**
|
||||
* atom:source element
|
||||
*
|
||||
* @var Zend_Gdata_App_Extension_Source
|
||||
*/
|
||||
protected $_source = null;
|
||||
|
||||
/**
|
||||
* atom:summary element
|
||||
*
|
||||
* @var Zend_Gdata_App_Extension_Summary
|
||||
*/
|
||||
protected $_summary = null;
|
||||
|
||||
/**
|
||||
* app:control element
|
||||
*
|
||||
* @var Zend_Gdata_App_Extension_Control
|
||||
*/
|
||||
protected $_control = null;
|
||||
|
||||
/**
|
||||
* app:edited element
|
||||
*
|
||||
* @var Zend_Gdata_App_Extension_Edited
|
||||
*/
|
||||
protected $_edited = null;
|
||||
|
||||
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
||||
{
|
||||
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
||||
if ($this->_content != null) {
|
||||
$element->appendChild($this->_content->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_published != null) {
|
||||
$element->appendChild($this->_published->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_source != null) {
|
||||
$element->appendChild($this->_source->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_summary != null) {
|
||||
$element->appendChild($this->_summary->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_control != null) {
|
||||
$element->appendChild($this->_control->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_edited != null) {
|
||||
$element->appendChild($this->_edited->getDOM($element->ownerDocument));
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
protected function takeChildFromDOM($child)
|
||||
{
|
||||
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
|
||||
switch ($absoluteNodeName) {
|
||||
case $this->lookupNamespace('atom') . ':' . 'content':
|
||||
$content = new Zend_Gdata_App_Extension_Content();
|
||||
$content->transferFromDOM($child);
|
||||
$this->_content = $content;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'published':
|
||||
$published = new Zend_Gdata_App_Extension_Published();
|
||||
$published->transferFromDOM($child);
|
||||
$this->_published = $published;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'source':
|
||||
$source = new Zend_Gdata_App_Extension_Source();
|
||||
$source->transferFromDOM($child);
|
||||
$this->_source = $source;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'summary':
|
||||
$summary = new Zend_Gdata_App_Extension_Summary();
|
||||
$summary->transferFromDOM($child);
|
||||
$this->_summary = $summary;
|
||||
break;
|
||||
case $this->lookupNamespace('app') . ':' . 'control':
|
||||
$control = new Zend_Gdata_App_Extension_Control();
|
||||
$control->transferFromDOM($child);
|
||||
$this->_control = $control;
|
||||
break;
|
||||
case $this->lookupNamespace('app') . ':' . 'edited':
|
||||
$edited = new Zend_Gdata_App_Extension_Edited();
|
||||
$edited->transferFromDOM($child);
|
||||
$this->_edited = $edited;
|
||||
break;
|
||||
default:
|
||||
parent::takeChildFromDOM($child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads changes in this entry to the server using Zend_Gdata_App
|
||||
*
|
||||
* @param string|null $uri The URI to send requests to, or null if $data
|
||||
* contains the URI.
|
||||
* @param string|null $className The name of the class that should we
|
||||
* deserializing the server response. If null, then
|
||||
* 'Zend_Gdata_App_Entry' will be used.
|
||||
* @param array $extraHeaders Extra headers to add to the request, as an
|
||||
* array of string-based key/value pairs.
|
||||
* @return Zend_Gdata_App_Entry The updated entry.
|
||||
* @throws Zend_Gdata_App_Exception
|
||||
*/
|
||||
public function save($uri = null, $className = null, $extraHeaders = array())
|
||||
{
|
||||
return $this->getService()->updateEntry($this,
|
||||
$uri,
|
||||
$className,
|
||||
$extraHeaders);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes this entry to the server using the referenced
|
||||
* Zend_Http_Client to do a HTTP DELETE to the edit link stored in this
|
||||
* entry's link collection.
|
||||
*
|
||||
* @return void
|
||||
* @throws Zend_Gdata_App_Exception
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$this->getService()->delete($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the current entry. Returns a new copy of the entry as returned
|
||||
* by the server, or null if no changes exist. This does not
|
||||
* modify the current entry instance.
|
||||
*
|
||||
* @param string|null The URI to send requests to, or null if $data
|
||||
* contains the URI.
|
||||
* @param string|null The name of the class that should we deserializing
|
||||
* the server response. If null, then 'Zend_Gdata_App_Entry' will
|
||||
* be used.
|
||||
* @param array $extraHeaders Extra headers to add to the request, as an
|
||||
* array of string-based key/value pairs.
|
||||
* @return mixed A new instance of the current entry with updated data, or
|
||||
* null if the server reports that no changes have been made.
|
||||
* @throws Zend_Gdata_App_Exception
|
||||
*/
|
||||
public function reload($uri = null, $className = null, $extraHeaders = array())
|
||||
{
|
||||
// Get URI
|
||||
$editLink = $this->getEditLink();
|
||||
if (($uri === null) && $editLink != null) {
|
||||
$uri = $editLink->getHref();
|
||||
}
|
||||
|
||||
// Set classname to current class, if not otherwise set
|
||||
if ($className === null) {
|
||||
$className = get_class($this);
|
||||
}
|
||||
|
||||
// Append ETag, if present (Gdata v2 and above, only) and doesn't
|
||||
// conflict with existing headers
|
||||
if ($this->_etag != null
|
||||
&& !array_key_exists('If-Match', $extraHeaders)
|
||||
&& !array_key_exists('If-None-Match', $extraHeaders)) {
|
||||
$extraHeaders['If-None-Match'] = $this->_etag;
|
||||
}
|
||||
|
||||
// If an HTTP 304 status (Not Modified)is returned, then we return
|
||||
// null.
|
||||
$result = null;
|
||||
try {
|
||||
$result = $this->service->importUrl($uri, $className, $extraHeaders);
|
||||
} catch (Zend_Gdata_App_HttpException $e) {
|
||||
if ($e->getResponse()->getStatus() != '304')
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the atom:content element
|
||||
*
|
||||
* @return Zend_Gdata_App_Extension_Content
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the atom:content element
|
||||
*
|
||||
* @param Zend_Gdata_App_Extension_Content $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setContent($value)
|
||||
{
|
||||
$this->_content = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the atom:published element
|
||||
* This represents the publishing date for an entry
|
||||
*
|
||||
* @return Zend_Gdata_App_Extension_Published
|
||||
*/
|
||||
public function getPublished()
|
||||
{
|
||||
return $this->_published;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the atom:published element
|
||||
* This represents the publishing date for an entry
|
||||
*
|
||||
* @param Zend_Gdata_App_Extension_Published $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setPublished($value)
|
||||
{
|
||||
$this->_published = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the atom:source element
|
||||
*
|
||||
* @return Zend_Gdata_App_Extension_Source
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return $this->_source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the atom:source element
|
||||
*
|
||||
* @param Zend_Gdata_App_Extension_Source $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setSource($value)
|
||||
{
|
||||
$this->_source = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the atom:summary element
|
||||
* This represents a textual summary of this entry's content
|
||||
*
|
||||
* @return Zend_Gdata_App_Extension_Summary
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
return $this->_summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the atom:summary element
|
||||
* This represents a textual summary of this entry's content
|
||||
*
|
||||
* @param Zend_Gdata_App_Extension_Summary $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setSummary($value)
|
||||
{
|
||||
$this->_summary = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the app:control element
|
||||
*
|
||||
* @return Zend_Gdata_App_Extension_Control
|
||||
*/
|
||||
public function getControl()
|
||||
{
|
||||
return $this->_control;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the app:control element
|
||||
*
|
||||
* @param Zend_Gdata_App_Extension_Control $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setControl($value)
|
||||
{
|
||||
$this->_control = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
43
Zend/Gdata/App/Exception.php
Executable file
43
Zend/Gdata/App/Exception.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* Gdata App exceptions
|
||||
*
|
||||
* Class to represent exceptions that occur during Gdata App operations.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Exception extends Zend_Exception
|
||||
{
|
||||
}
|
||||
40
Zend/Gdata/App/Extension.php
Executable file
40
Zend/Gdata/App/Extension.php
Executable file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Base
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Base.php';
|
||||
|
||||
/**
|
||||
* Gdata App extensions
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Gdata_App_Extension extends Zend_Gdata_App_Base
|
||||
{
|
||||
}
|
||||
43
Zend/Gdata/App/Extension/Author.php
Executable file
43
Zend/Gdata/App/Extension/Author.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Person.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:author element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Author extends Zend_Gdata_App_Extension_Person
|
||||
{
|
||||
|
||||
protected $_rootElement = 'author';
|
||||
|
||||
}
|
||||
140
Zend/Gdata/App/Extension/Category.php
Executable file
140
Zend/Gdata/App/Extension/Category.php
Executable file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:category element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Category extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = 'category';
|
||||
protected $_term = null;
|
||||
protected $_scheme = null;
|
||||
protected $_label = null;
|
||||
|
||||
public function __construct($term = null, $scheme = null, $label=null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_term = $term;
|
||||
$this->_scheme = $scheme;
|
||||
$this->_label = $label;
|
||||
}
|
||||
|
||||
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
||||
{
|
||||
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
||||
if ($this->_term !== null) {
|
||||
$element->setAttribute('term', $this->_term);
|
||||
}
|
||||
if ($this->_scheme !== null) {
|
||||
$element->setAttribute('scheme', $this->_scheme);
|
||||
}
|
||||
if ($this->_label !== null) {
|
||||
$element->setAttribute('label', $this->_label);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
protected function takeAttributeFromDOM($attribute)
|
||||
{
|
||||
switch ($attribute->localName) {
|
||||
case 'term':
|
||||
$this->_term = $attribute->nodeValue;
|
||||
break;
|
||||
case 'scheme':
|
||||
$this->_scheme = $attribute->nodeValue;
|
||||
break;
|
||||
case 'label':
|
||||
$this->_label = $attribute->nodeValue;
|
||||
break;
|
||||
default:
|
||||
parent::takeAttributeFromDOM($attribute);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTerm()
|
||||
{
|
||||
return $this->_term;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $value
|
||||
* @return Zend_Gdata_App_Extension_Category Provides a fluent interface
|
||||
*/
|
||||
public function setTerm($value)
|
||||
{
|
||||
$this->_term = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getScheme()
|
||||
{
|
||||
return $this->_scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $value
|
||||
* @return Zend_Gdata_App_Extension_Category Provides a fluent interface
|
||||
*/
|
||||
public function setScheme($value)
|
||||
{
|
||||
$this->_scheme = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->_label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $value
|
||||
* @return Zend_Gdata_App_Extension_Category Provides a fluent interface
|
||||
*/
|
||||
public function setLabel($value)
|
||||
{
|
||||
$this->_label = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
88
Zend/Gdata/App/Extension/Content.php
Executable file
88
Zend/Gdata/App/Extension/Content.php
Executable file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Text
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Text.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:content element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Content extends Zend_Gdata_App_Extension_Text
|
||||
{
|
||||
|
||||
protected $_rootElement = 'content';
|
||||
protected $_src = null;
|
||||
|
||||
public function __construct($text = null, $type = 'text', $src = null)
|
||||
{
|
||||
parent::__construct($text, $type);
|
||||
$this->_src = $src;
|
||||
}
|
||||
|
||||
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
||||
{
|
||||
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
||||
if ($this->_src !== null) {
|
||||
$element->setAttribute('src', $this->_src);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
protected function takeAttributeFromDOM($attribute)
|
||||
{
|
||||
switch ($attribute->localName) {
|
||||
case 'src':
|
||||
$this->_src = $attribute->nodeValue;
|
||||
break;
|
||||
default:
|
||||
parent::takeAttributeFromDOM($attribute);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSrc()
|
||||
{
|
||||
return $this->_src;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setSrc($value)
|
||||
{
|
||||
$this->_src = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
43
Zend/Gdata/App/Extension/Contributor.php
Executable file
43
Zend/Gdata/App/Extension/Contributor.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Person.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:contributor element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Contributor extends Zend_Gdata_App_Extension_Person
|
||||
{
|
||||
|
||||
protected $_rootElement = 'contributor';
|
||||
|
||||
}
|
||||
98
Zend/Gdata/App/Extension/Control.php
Executable file
98
Zend/Gdata/App/Extension/Control.php
Executable file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Draft
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Draft.php';
|
||||
|
||||
/**
|
||||
* Represents the app:control element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Control extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootNamespace = 'app';
|
||||
protected $_rootElement = 'control';
|
||||
protected $_draft = null;
|
||||
|
||||
public function __construct($draft = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_draft = $draft;
|
||||
}
|
||||
|
||||
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
||||
{
|
||||
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
||||
if ($this->_draft != null) {
|
||||
$element->appendChild($this->_draft->getDOM($element->ownerDocument));
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
protected function takeChildFromDOM($child)
|
||||
{
|
||||
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
|
||||
switch ($absoluteNodeName) {
|
||||
case $this->lookupNamespace('app') . ':' . 'draft':
|
||||
$draft = new Zend_Gdata_App_Extension_Draft();
|
||||
$draft->transferFromDOM($child);
|
||||
$this->_draft = $draft;
|
||||
break;
|
||||
default:
|
||||
parent::takeChildFromDOM($child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_App_Extension_Draft
|
||||
*/
|
||||
public function getDraft()
|
||||
{
|
||||
return $this->_draft;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Gdata_App_Extension_Draft $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setDraft($value)
|
||||
{
|
||||
$this->_draft = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
50
Zend/Gdata/App/Extension/Draft.php
Executable file
50
Zend/Gdata/App/Extension/Draft.php
Executable file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Represents the app:draft element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Draft extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootNamespace = 'app';
|
||||
protected $_rootElement = 'draft';
|
||||
|
||||
public function __construct($text = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_text = $text;
|
||||
}
|
||||
|
||||
}
|
||||
49
Zend/Gdata/App/Extension/Edited.php
Executable file
49
Zend/Gdata/App/Extension/Edited.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Represents the app:edited element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Edited extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = 'edited';
|
||||
|
||||
public function __construct($text = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_text = $text;
|
||||
}
|
||||
|
||||
}
|
||||
58
Zend/Gdata/App/Extension/Element.php
Executable file
58
Zend/Gdata/App/Extension/Element.php
Executable file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Class that represents elements which were not handled by other parsing
|
||||
* code in the library.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Element extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
public function __construct($rootElement=null, $rootNamespace=null, $rootNamespaceURI=null, $text=null){
|
||||
parent::__construct();
|
||||
$this->_rootElement = $rootElement;
|
||||
$this->_rootNamespace = $rootNamespace;
|
||||
$this->_rootNamespaceURI = $rootNamespaceURI;
|
||||
$this->_text = $text;
|
||||
}
|
||||
|
||||
public function transferFromDOM($node)
|
||||
{
|
||||
parent::transferFromDOM($node);
|
||||
$this->_rootNamespace = null;
|
||||
$this->_rootNamespaceURI = $node->namespaceURI;
|
||||
$this->_rootElement = $node->localName;
|
||||
}
|
||||
|
||||
}
|
||||
49
Zend/Gdata/App/Extension/Email.php
Executable file
49
Zend/Gdata/App/Extension/Email.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:email element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Email extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = 'email';
|
||||
|
||||
public function __construct($text = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_text = $text;
|
||||
}
|
||||
|
||||
}
|
||||
115
Zend/Gdata/App/Extension/Generator.php
Executable file
115
Zend/Gdata/App/Extension/Generator.php
Executable file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:generator element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Generator extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = 'generator';
|
||||
protected $_uri = null;
|
||||
protected $_version = null;
|
||||
|
||||
public function __construct($text = null, $uri = null, $version = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_text = $text;
|
||||
$this->_uri = $uri;
|
||||
$this->_version = $version;
|
||||
}
|
||||
|
||||
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
||||
{
|
||||
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
||||
if ($this->_uri !== null) {
|
||||
$element->setAttribute('uri', $this->_uri);
|
||||
}
|
||||
if ($this->_version !== null) {
|
||||
$element->setAttribute('version', $this->_version);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
protected function takeAttributeFromDOM($attribute)
|
||||
{
|
||||
switch ($attribute->localName) {
|
||||
case 'uri':
|
||||
$this->_uri = $attribute->nodeValue;
|
||||
break;
|
||||
case 'version':
|
||||
$this->_version= $attribute->nodeValue;
|
||||
break;
|
||||
default:
|
||||
parent::takeAttributeFromDOM($attribute);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_App_Extension_Uri
|
||||
*/
|
||||
public function getUri()
|
||||
{
|
||||
return $this->_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Gdata_App_Extension_Uri $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setUri($value)
|
||||
{
|
||||
$this->_uri = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_App_Extension_Version
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Gdata_App_Extension_Version $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setVersion($value)
|
||||
{
|
||||
$this->_version = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
49
Zend/Gdata/App/Extension/Icon.php
Executable file
49
Zend/Gdata/App/Extension/Icon.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:icon element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Icon extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = 'icon';
|
||||
|
||||
public function __construct($text = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_text = $text;
|
||||
}
|
||||
|
||||
}
|
||||
49
Zend/Gdata/App/Extension/Id.php
Executable file
49
Zend/Gdata/App/Extension/Id.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:id element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Id extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = 'id';
|
||||
|
||||
public function __construct($text = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_text = $text;
|
||||
}
|
||||
|
||||
}
|
||||
219
Zend/Gdata/App/Extension/Link.php
Executable file
219
Zend/Gdata/App/Extension/Link.php
Executable file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/Extension.php';
|
||||
|
||||
/**
|
||||
* Data model for representing an atom:link element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Link extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = 'link';
|
||||
protected $_href = null;
|
||||
protected $_rel = null;
|
||||
protected $_type = null;
|
||||
protected $_hrefLang = null;
|
||||
protected $_title = null;
|
||||
protected $_length = null;
|
||||
|
||||
public function __construct($href = null, $rel = null, $type = null,
|
||||
$hrefLang = null, $title = null, $length = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_href = $href;
|
||||
$this->_rel = $rel;
|
||||
$this->_type = $type;
|
||||
$this->_hrefLang = $hrefLang;
|
||||
$this->_title = $title;
|
||||
$this->_length = $length;
|
||||
}
|
||||
|
||||
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
||||
{
|
||||
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
||||
if ($this->_href !== null) {
|
||||
$element->setAttribute('href', $this->_href);
|
||||
}
|
||||
if ($this->_rel !== null) {
|
||||
$element->setAttribute('rel', $this->_rel);
|
||||
}
|
||||
if ($this->_type !== null) {
|
||||
$element->setAttribute('type', $this->_type);
|
||||
}
|
||||
if ($this->_hrefLang !== null) {
|
||||
$element->setAttribute('hreflang', $this->_hrefLang);
|
||||
}
|
||||
if ($this->_title !== null) {
|
||||
$element->setAttribute('title', $this->_title);
|
||||
}
|
||||
if ($this->_length !== null) {
|
||||
$element->setAttribute('length', $this->_length);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
protected function takeAttributeFromDOM($attribute)
|
||||
{
|
||||
switch ($attribute->localName) {
|
||||
case 'href':
|
||||
$this->_href = $attribute->nodeValue;
|
||||
break;
|
||||
case 'rel':
|
||||
$this->_rel = $attribute->nodeValue;
|
||||
break;
|
||||
case 'type':
|
||||
$this->_type = $attribute->nodeValue;
|
||||
break;
|
||||
case 'hreflang':
|
||||
$this->_hrefLang = $attribute->nodeValue;
|
||||
break;
|
||||
case 'title':
|
||||
$this->_title = $attribute->nodeValue;
|
||||
break;
|
||||
case 'length':
|
||||
$this->_length = $attribute->nodeValue;
|
||||
break;
|
||||
default:
|
||||
parent::takeAttributeFromDOM($attribute);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getHref()
|
||||
{
|
||||
return $this->_href;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setHref($value)
|
||||
{
|
||||
$this->_href = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRel()
|
||||
{
|
||||
return $this->_rel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setRel($value)
|
||||
{
|
||||
$this->_rel = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setType($value)
|
||||
{
|
||||
$this->_type = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getHrefLang()
|
||||
{
|
||||
return $this->_hrefLang;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setHrefLang($value)
|
||||
{
|
||||
$this->_hrefLang = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->_title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setTitle($value)
|
||||
{
|
||||
$this->_title = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLength()
|
||||
{
|
||||
return $this->_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setLength($value)
|
||||
{
|
||||
$this->_length = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
49
Zend/Gdata/App/Extension/Logo.php
Executable file
49
Zend/Gdata/App/Extension/Logo.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:logo element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Logo extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = 'logo';
|
||||
|
||||
public function __construct($text = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_text = $text;
|
||||
}
|
||||
|
||||
}
|
||||
48
Zend/Gdata/App/Extension/Name.php
Executable file
48
Zend/Gdata/App/Extension/Name.php
Executable file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:name element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Name extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = 'name';
|
||||
|
||||
public function __construct($text = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_text = $text;
|
||||
}
|
||||
}
|
||||
163
Zend/Gdata/App/Extension/Person.php
Executable file
163
Zend/Gdata/App/Extension/Person.php
Executable file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Name
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Name.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Email
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Email.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Uri
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Uri.php';
|
||||
|
||||
/**
|
||||
* Base class for people (currently used by atom:author, atom:contributor)
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Gdata_App_Extension_Person extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = null;
|
||||
protected $_name = null;
|
||||
protected $_email = null;
|
||||
protected $_uri = null;
|
||||
|
||||
public function __construct($name = null, $email = null, $uri = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_name = $name;
|
||||
$this->_email = $email;
|
||||
$this->_uri = $uri;
|
||||
}
|
||||
|
||||
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
||||
{
|
||||
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
||||
if ($this->_name != null) {
|
||||
$element->appendChild($this->_name->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_email != null) {
|
||||
$element->appendChild($this->_email->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_uri != null) {
|
||||
$element->appendChild($this->_uri->getDOM($element->ownerDocument));
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
protected function takeChildFromDOM($child)
|
||||
{
|
||||
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
|
||||
switch ($absoluteNodeName) {
|
||||
case $this->lookupNamespace('atom') . ':' . 'name':
|
||||
$name = new Zend_Gdata_App_Extension_Name();
|
||||
$name->transferFromDOM($child);
|
||||
$this->_name = $name;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'email':
|
||||
$email = new Zend_Gdata_App_Extension_Email();
|
||||
$email->transferFromDOM($child);
|
||||
$this->_email = $email;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'uri':
|
||||
$uri = new Zend_Gdata_App_Extension_Uri();
|
||||
$uri->transferFromDOM($child);
|
||||
$this->_uri = $uri;
|
||||
break;
|
||||
default:
|
||||
parent::takeChildFromDOM($child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_App_Extension_Name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Gdata_App_Extension_Name $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setName($value)
|
||||
{
|
||||
$this->_name = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_App_Extension_Email
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->_email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Gdata_App_Extension_Email $value
|
||||
* @return Zend_Gdata_App_Extension_Person Provides a fluent interface
|
||||
*/
|
||||
public function setEmail($value)
|
||||
{
|
||||
$this->_email = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_App_Extension_Uri
|
||||
*/
|
||||
public function getUri()
|
||||
{
|
||||
return $this->_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Gdata_App_Extension_Uri $value
|
||||
* @return Zend_Gdata_App_Extension_Person Provides a fluent interface
|
||||
*/
|
||||
public function setUri($value)
|
||||
{
|
||||
$this->_uri = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
49
Zend/Gdata/App/Extension/Published.php
Executable file
49
Zend/Gdata/App/Extension/Published.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:published element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Published extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = 'published';
|
||||
|
||||
public function __construct($text = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_text = $text;
|
||||
}
|
||||
|
||||
}
|
||||
49
Zend/Gdata/App/Extension/Rights.php
Executable file
49
Zend/Gdata/App/Extension/Rights.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Text
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Text.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:rights element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Rights extends Zend_Gdata_App_Extension_Text
|
||||
{
|
||||
|
||||
protected $_rootElement = 'rights';
|
||||
|
||||
public function __construct($text = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_text = $text;
|
||||
}
|
||||
|
||||
}
|
||||
46
Zend/Gdata/App/Extension/Source.php
Executable file
46
Zend/Gdata/App/Extension/Source.php
Executable file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Entry
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Entry.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_FeedSourceParent
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/FeedSourceParent.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Source extends Zend_Gdata_App_FeedSourceParent
|
||||
{
|
||||
|
||||
protected $_rootElement = 'source';
|
||||
|
||||
}
|
||||
43
Zend/Gdata/App/Extension/Subtitle.php
Executable file
43
Zend/Gdata/App/Extension/Subtitle.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Text
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Text.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:subtitle element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Subtitle extends Zend_Gdata_App_Extension_Text
|
||||
{
|
||||
|
||||
protected $_rootElement = 'subtitle';
|
||||
|
||||
}
|
||||
43
Zend/Gdata/App/Extension/Summary.php
Executable file
43
Zend/Gdata/App/Extension/Summary.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Text
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Text.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:summary element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Summary extends Zend_Gdata_App_Extension_Text
|
||||
{
|
||||
|
||||
protected $_rootElement = 'summary';
|
||||
|
||||
}
|
||||
90
Zend/Gdata/App/Extension/Text.php
Executable file
90
Zend/Gdata/App/Extension/Text.php
Executable file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Abstract class for data models that require only text and type-- such as:
|
||||
* title, summary, etc.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Gdata_App_Extension_Text extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = null;
|
||||
protected $_type = 'text';
|
||||
|
||||
public function __construct($text = null, $type = 'text')
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_text = $text;
|
||||
$this->_type = $type;
|
||||
}
|
||||
|
||||
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
||||
{
|
||||
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
||||
if ($this->_type !== null) {
|
||||
$element->setAttribute('type', $this->_type);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
protected function takeAttributeFromDOM($attribute)
|
||||
{
|
||||
switch ($attribute->localName) {
|
||||
case 'type':
|
||||
$this->_type = $attribute->nodeValue;
|
||||
break;
|
||||
default:
|
||||
parent::takeAttributeFromDOM($attribute);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @return Zend_Gdata_App_Extension_Type
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_type;
|
||||
}
|
||||
|
||||
/*
|
||||
* @param string $value
|
||||
* @return Zend_Gdata_App_Extension_Text Provides a fluent interface
|
||||
*/
|
||||
public function setType($value)
|
||||
{
|
||||
$this->_type = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
43
Zend/Gdata/App/Extension/Title.php
Executable file
43
Zend/Gdata/App/Extension/Title.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Text
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Text.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:title element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Title extends Zend_Gdata_App_Extension_Text
|
||||
{
|
||||
|
||||
protected $_rootElement = 'title';
|
||||
|
||||
}
|
||||
49
Zend/Gdata/App/Extension/Updated.php
Executable file
49
Zend/Gdata/App/Extension/Updated.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:updated element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Updated extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = 'updated';
|
||||
|
||||
public function __construct($text = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_text = $text;
|
||||
}
|
||||
|
||||
}
|
||||
49
Zend/Gdata/App/Extension/Uri.php
Executable file
49
Zend/Gdata/App/Extension/Uri.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an uri
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension.php';
|
||||
|
||||
/**
|
||||
* Represents the atom:uri element
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Extension_Uri extends Zend_Gdata_App_Extension
|
||||
{
|
||||
|
||||
protected $_rootElement = 'uri';
|
||||
|
||||
public function __construct($text = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_text = $text;
|
||||
}
|
||||
|
||||
}
|
||||
352
Zend/Gdata/App/Feed.php
Executable file
352
Zend/Gdata/App/Feed.php
Executable file
@@ -0,0 +1,352 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Entry
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Entry.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_FeedSourceParent
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/FeedSourceParent.php';
|
||||
|
||||
/**
|
||||
* Atom feed class
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Feed extends Zend_Gdata_App_FeedSourceParent
|
||||
implements Iterator, ArrayAccess
|
||||
{
|
||||
|
||||
/**
|
||||
* The root xml element of this data element
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_rootElement = 'feed';
|
||||
|
||||
/**
|
||||
* Cache of feed entries.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_entry = array();
|
||||
|
||||
/**
|
||||
* Current location in $_entry array
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_entryIndex = 0;
|
||||
|
||||
/**
|
||||
* Make accessing some individual elements of the feed easier.
|
||||
*
|
||||
* Special accessors 'entry' and 'entries' are provided so that if
|
||||
* you wish to iterate over an Atom feed's entries, you can do so
|
||||
* using foreach ($feed->entries as $entry) or foreach
|
||||
* ($feed->entry as $entry).
|
||||
*
|
||||
* @param string $var The property to get.
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($var)
|
||||
{
|
||||
switch ($var) {
|
||||
case 'entries':
|
||||
return $this;
|
||||
default:
|
||||
return parent::__get($var);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the DOM model representing this object and all children
|
||||
*
|
||||
* @param DOMDocument $doc
|
||||
* @return DOMElement
|
||||
*/
|
||||
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
||||
{
|
||||
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
||||
foreach ($this->_entry as $entry) {
|
||||
$element->appendChild($entry->getDOM($element->ownerDocument));
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates individual Entry objects of the appropriate type and
|
||||
* stores them in the $_entry array based upon DOM data.
|
||||
*
|
||||
* @param DOMNode $child The DOMNode to process
|
||||
*/
|
||||
protected function takeChildFromDOM($child)
|
||||
{
|
||||
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
|
||||
switch ($absoluteNodeName) {
|
||||
case $this->lookupNamespace('atom') . ':' . 'entry':
|
||||
$newEntry = new $this->_entryClassName($child);
|
||||
$newEntry->setHttpClient($this->getHttpClient());
|
||||
$newEntry->setMajorProtocolVersion($this->getMajorProtocolVersion());
|
||||
$newEntry->setMinorProtocolVersion($this->getMinorProtocolVersion());
|
||||
$this->_entry[] = $newEntry;
|
||||
break;
|
||||
default:
|
||||
parent::takeChildFromDOM($child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of entries in this feed object.
|
||||
*
|
||||
* @return integer Entry count.
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->_entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by the Iterator interface.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
$this->_entryIndex = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by the Iterator interface.
|
||||
*
|
||||
* @return mixed The current row, or null if no rows.
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return $this->_entry[$this->_entryIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by the Iterator interface.
|
||||
*
|
||||
* @return mixed The current row number (starts at 0), or NULL if no rows
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return $this->_entryIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by the Iterator interface.
|
||||
*
|
||||
* @return mixed The next row, or null if no more rows.
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
++$this->_entryIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by the Iterator interface.
|
||||
*
|
||||
* @return boolean Whether the iteration is valid
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return 0 <= $this->_entryIndex && $this->_entryIndex < $this->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array of atom:entry elements contained within this
|
||||
* atom:feed representation
|
||||
*
|
||||
* @return array Zend_Gdata_App_Entry array
|
||||
*/
|
||||
public function getEntry()
|
||||
{
|
||||
return $this->_entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the array of atom:entry elements contained within this
|
||||
* atom:feed representation
|
||||
*
|
||||
* @param array $value The array of Zend_Gdata_App_Entry elements
|
||||
* @return Zend_Gdata_App_Feed Provides a fluent interface
|
||||
*/
|
||||
public function setEntry($value)
|
||||
{
|
||||
$this->_entry = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an entry representation to the array of entries
|
||||
* contained within this feed
|
||||
*
|
||||
* @param Zend_Gdata_App_Entry An individual entry to add.
|
||||
* @return Zend_Gdata_App_Feed Provides a fluent interface
|
||||
*/
|
||||
public function addEntry($value)
|
||||
{
|
||||
$this->_entry[] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by the ArrayAccess interface
|
||||
*
|
||||
* @param int $key The index to set
|
||||
* @param Zend_Gdata_App_Entry $value The value to set
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($key, $value)
|
||||
{
|
||||
$this->_entry[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by the ArrayAccess interface
|
||||
*
|
||||
* @param int $key The index to get
|
||||
* @param Zend_Gdata_App_Entry $value The value to set
|
||||
*/
|
||||
public function offsetGet($key)
|
||||
{
|
||||
if (array_key_exists($key, $this->_entry)) {
|
||||
return $this->_entry[$key];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by the ArrayAccess interface
|
||||
*
|
||||
* @param int $key The index to set
|
||||
* @param Zend_Gdata_App_Entry $value The value to set
|
||||
*/
|
||||
public function offsetUnset($key)
|
||||
{
|
||||
if (array_key_exists($key, $this->_entry)) {
|
||||
unset($this->_entry[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by the ArrayAccess interface
|
||||
*
|
||||
* @param int $key The index to check for existence
|
||||
* @return boolean
|
||||
*/
|
||||
public function offsetExists($key)
|
||||
{
|
||||
return (array_key_exists($key, $this->_entry));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the next set of results from this feed.
|
||||
*
|
||||
* @throws Zend_Gdata_App_Exception
|
||||
* @return mixed|null Returns the next set of results as a feed of the same
|
||||
* class as this feed, or null if no results exist.
|
||||
*/
|
||||
public function getNextFeed()
|
||||
{
|
||||
$nextLink = $this->getNextLink();
|
||||
if (!$nextLink) {
|
||||
require_once 'Zend/Gdata/App/HttpException.php';
|
||||
throw new Zend_Gdata_App_Exception('No link to next set ' .
|
||||
'of results found.');
|
||||
}
|
||||
$nextLinkHref = $nextLink->getHref();
|
||||
$service = new Zend_Gdata_App($this->getHttpClient());
|
||||
|
||||
return $service->getFeed($nextLinkHref, get_class($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the previous set of results from this feed.
|
||||
*
|
||||
* @throws Zend_Gdata_App_Exception
|
||||
* @return mixed|null Returns the previous set of results as a feed of
|
||||
* the same class as this feed, or null if no results exist.
|
||||
*/
|
||||
public function getPreviousFeed()
|
||||
{
|
||||
$previousLink = $this->getPreviousLink();
|
||||
if (!$previousLink) {
|
||||
require_once 'Zend/Gdata/App/HttpException.php';
|
||||
throw new Zend_Gdata_App_Exception('No link to previous set ' .
|
||||
'of results found.');
|
||||
}
|
||||
$previousLinkHref = $previousLink->getHref();
|
||||
$service = new Zend_Gdata_App($this->getHttpClient());
|
||||
|
||||
return $service->getFeed($previousLinkHref, get_class($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the major protocol version that should be used. Values < 1 will
|
||||
* cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
|
||||
*
|
||||
* This value will be propogated to all child entries.
|
||||
*
|
||||
* @see _majorProtocolVersion
|
||||
* @param (int|NULL) $value The major protocol version to use.
|
||||
* @throws Zend_Gdata_App_InvalidArgumentException
|
||||
*/
|
||||
public function setMajorProtocolVersion($value)
|
||||
{
|
||||
parent::setMajorProtocolVersion($value);
|
||||
foreach ($this->entries as $entry) {
|
||||
$entry->setMajorProtocolVersion($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minor protocol version that should be used. If set to NULL, no
|
||||
* minor protocol version will be sent to the server. Values < 0 will
|
||||
* cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
|
||||
*
|
||||
* This value will be propogated to all child entries.
|
||||
*
|
||||
* @see _minorProtocolVersion
|
||||
* @param (int|NULL) $value The minor protocol version to use.
|
||||
* @throws Zend_Gdata_App_InvalidArgumentException
|
||||
*/
|
||||
public function setMinorProtocolVersion($value)
|
||||
{
|
||||
parent::setMinorProtocolVersion($value);
|
||||
foreach ($this->entries as $entry) {
|
||||
$entry->setMinorProtocolVersion($value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
681
Zend/Gdata/App/FeedEntryParent.php
Executable file
681
Zend/Gdata/App/FeedEntryParent.php
Executable file
@@ -0,0 +1,681 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Element
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Element.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Author
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Author.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Category
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Category.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Contributor
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Contributor.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Id
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Id.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Link
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Link.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Rights
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Rights.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Title
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Title.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Updated
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Updated.php';
|
||||
|
||||
/**
|
||||
* Zend_Version
|
||||
*/
|
||||
require_once 'Zend/Version.php';
|
||||
|
||||
/**
|
||||
* Abstract class for common functionality in entries and feeds
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Gdata_App_FeedEntryParent extends Zend_Gdata_App_Base
|
||||
{
|
||||
/**
|
||||
* Service instance used to make network requests.
|
||||
*
|
||||
* @see setService(), getService()
|
||||
*/
|
||||
protected $_service = null;
|
||||
|
||||
/**
|
||||
* The HTTP ETag associated with this entry. Used for optimistic
|
||||
* concurrency in protoco v2 or greater.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $_etag = NULL;
|
||||
|
||||
protected $_author = array();
|
||||
protected $_category = array();
|
||||
protected $_contributor = array();
|
||||
protected $_id = null;
|
||||
protected $_link = array();
|
||||
protected $_rights = null;
|
||||
protected $_title = null;
|
||||
protected $_updated = null;
|
||||
|
||||
/**
|
||||
* Indicates the major protocol version that should be used.
|
||||
* At present, recognized values are either 1 or 2. However, any integer
|
||||
* value >= 1 is considered valid.
|
||||
*
|
||||
* @see setMajorProtocolVersion()
|
||||
* @see getMajorProtocolVersion()
|
||||
*/
|
||||
protected $_majorProtocolVersion = 1;
|
||||
|
||||
/**
|
||||
* Indicates the minor protocol version that should be used. Can be set
|
||||
* to either an integer >= 0, or NULL if no minor version should be sent
|
||||
* to the server.
|
||||
*
|
||||
* @see setMinorProtocolVersion()
|
||||
* @see getMinorProtocolVersion()
|
||||
*/
|
||||
protected $_minorProtocolVersion = null;
|
||||
|
||||
/**
|
||||
* Constructs a Feed or Entry
|
||||
*/
|
||||
public function __construct($element = null)
|
||||
{
|
||||
if (!($element instanceof DOMElement)) {
|
||||
if ($element) {
|
||||
$this->transferFromXML($element);
|
||||
}
|
||||
} else {
|
||||
$this->transferFromDOM($element);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the HTTP client instance
|
||||
*
|
||||
* Sets the HTTP client object to use for retrieving the feed.
|
||||
*
|
||||
* @deprecated Deprecated as of Zend Framework 1.7. Use
|
||||
* setService() instead.
|
||||
* @param Zend_Http_Client $httpClient
|
||||
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
|
||||
*/
|
||||
public function setHttpClient(Zend_Http_Client $httpClient)
|
||||
{
|
||||
if (!$this->_service) {
|
||||
$this->_service = new Zend_Gdata_App();
|
||||
}
|
||||
$this->_service->setHttpClient($httpClient);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP client object. If none is set, a new Zend_Http_Client
|
||||
* will be used.
|
||||
*
|
||||
* @deprecated Deprecated as of Zend Framework 1.7. Use
|
||||
* getService() instead.
|
||||
* @return Zend_Http_Client_Abstract
|
||||
*/
|
||||
public function getHttpClient()
|
||||
{
|
||||
if (!$this->_service) {
|
||||
$this->_service = new Zend_Gdata_App();
|
||||
}
|
||||
$client = $this->_service->getHttpClient();
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the active service instance for this object. This will be used to
|
||||
* perform network requests, such as when calling save() and delete().
|
||||
*
|
||||
* @param Zend_Gdata_App $instance The new service instance.
|
||||
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface.
|
||||
*/
|
||||
public function setService($instance)
|
||||
{
|
||||
$this->_service = $instance;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active service instance for this object. This will be used to
|
||||
* perform network requests, such as when calling save() and delete().
|
||||
*
|
||||
* @return Zend_Gdata_App|null The current service instance, or null if
|
||||
* not set.
|
||||
*/
|
||||
public function getService()
|
||||
{
|
||||
return $this->_service;
|
||||
}
|
||||
|
||||
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
||||
{
|
||||
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
||||
foreach ($this->_author as $author) {
|
||||
$element->appendChild($author->getDOM($element->ownerDocument));
|
||||
}
|
||||
foreach ($this->_category as $category) {
|
||||
$element->appendChild($category->getDOM($element->ownerDocument));
|
||||
}
|
||||
foreach ($this->_contributor as $contributor) {
|
||||
$element->appendChild($contributor->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_id != null) {
|
||||
$element->appendChild($this->_id->getDOM($element->ownerDocument));
|
||||
}
|
||||
foreach ($this->_link as $link) {
|
||||
$element->appendChild($link->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_rights != null) {
|
||||
$element->appendChild($this->_rights->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_title != null) {
|
||||
$element->appendChild($this->_title->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_updated != null) {
|
||||
$element->appendChild($this->_updated->getDOM($element->ownerDocument));
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
protected function takeChildFromDOM($child)
|
||||
{
|
||||
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
|
||||
switch ($absoluteNodeName) {
|
||||
case $this->lookupNamespace('atom') . ':' . 'author':
|
||||
$author = new Zend_Gdata_App_Extension_Author();
|
||||
$author->transferFromDOM($child);
|
||||
$this->_author[] = $author;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'category':
|
||||
$category = new Zend_Gdata_App_Extension_Category();
|
||||
$category->transferFromDOM($child);
|
||||
$this->_category[] = $category;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'contributor':
|
||||
$contributor = new Zend_Gdata_App_Extension_Contributor();
|
||||
$contributor->transferFromDOM($child);
|
||||
$this->_contributor[] = $contributor;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'id':
|
||||
$id = new Zend_Gdata_App_Extension_Id();
|
||||
$id->transferFromDOM($child);
|
||||
$this->_id = $id;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'link':
|
||||
$link = new Zend_Gdata_App_Extension_Link();
|
||||
$link->transferFromDOM($child);
|
||||
$this->_link[] = $link;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'rights':
|
||||
$rights = new Zend_Gdata_App_Extension_Rights();
|
||||
$rights->transferFromDOM($child);
|
||||
$this->_rights = $rights;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'title':
|
||||
$title = new Zend_Gdata_App_Extension_Title();
|
||||
$title->transferFromDOM($child);
|
||||
$this->_title = $title;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'updated':
|
||||
$updated = new Zend_Gdata_App_Extension_Updated();
|
||||
$updated->transferFromDOM($child);
|
||||
$this->_updated = $updated;
|
||||
break;
|
||||
default:
|
||||
parent::takeChildFromDOM($child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_App_Extension_Author
|
||||
*/
|
||||
public function getAuthor()
|
||||
{
|
||||
return $this->_author;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the list of the authors of this feed/entry. In an atom feed, each
|
||||
* author is represented by an atom:author element
|
||||
*
|
||||
* @param array $value
|
||||
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
|
||||
*/
|
||||
public function setAuthor($value)
|
||||
{
|
||||
$this->_author = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array of categories that classify this feed/entry. Each
|
||||
* category is represented in an atom feed by an atom:category element.
|
||||
*
|
||||
* @return array Array of Zend_Gdata_App_Extension_Category
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->_category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the array of categories that classify this feed/entry. Each
|
||||
* category is represented in an atom feed by an atom:category element.
|
||||
*
|
||||
* @param array $value Array of Zend_Gdata_App_Extension_Category
|
||||
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
|
||||
*/
|
||||
public function setCategory($value)
|
||||
{
|
||||
$this->_category = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array of contributors to this feed/entry. Each contributor
|
||||
* is represented in an atom feed by an atom:contributor XML element
|
||||
*
|
||||
* @return array An array of Zend_Gdata_App_Extension_Contributor
|
||||
*/
|
||||
public function getContributor()
|
||||
{
|
||||
return $this->_contributor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the array of contributors to this feed/entry. Each contributor
|
||||
* is represented in an atom feed by an atom:contributor XML element
|
||||
*
|
||||
* @param array $value
|
||||
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
|
||||
*/
|
||||
public function setContributor($value)
|
||||
{
|
||||
$this->_contributor = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_App_Extension_Id
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Gdata_App_Extension_Id $value
|
||||
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
|
||||
*/
|
||||
public function setId($value)
|
||||
{
|
||||
$this->_id = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a particular 'rel' value, this method returns a matching
|
||||
* Zend_Gdata_App_Extension_Link element. If the 'rel' value
|
||||
* is not provided, the full array of Zend_Gdata_App_Extension_Link
|
||||
* elements is returned. In an atom feed, each link is represented
|
||||
* by an atom:link element. The 'rel' value passed to this function
|
||||
* is the atom:link/@rel attribute. Example rel values include 'self',
|
||||
* 'edit', and 'alternate'.
|
||||
*
|
||||
* @param string $rel The rel value of the link to be found. If null,
|
||||
* the array of Zend_Gdata_App_Extension_link elements is returned
|
||||
* @return mixed Either a single Zend_Gdata_App_Extension_link element,
|
||||
* an array of the same or null is returned depending on the rel value
|
||||
* supplied as the argument to this function
|
||||
*/
|
||||
public function getLink($rel = null)
|
||||
{
|
||||
if ($rel == null) {
|
||||
return $this->_link;
|
||||
} else {
|
||||
foreach ($this->_link as $link) {
|
||||
if ($link->rel == $rel) {
|
||||
return $link;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Zend_Gdata_App_Extension_Link element which represents
|
||||
* the URL used to edit this resource. This link is in the atom feed/entry
|
||||
* as an atom:link with a rel attribute value of 'edit'.
|
||||
*
|
||||
* @return Zend_Gdata_App_Extension_Link The link, or null if not found
|
||||
*/
|
||||
public function getEditLink()
|
||||
{
|
||||
return $this->getLink('edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Zend_Gdata_App_Extension_Link element which represents
|
||||
* the URL used to retrieve the next chunk of results when paging through
|
||||
* a feed. This link is in the atom feed as an atom:link with a
|
||||
* rel attribute value of 'next'.
|
||||
*
|
||||
* @return Zend_Gdata_App_Extension_Link The link, or null if not found
|
||||
*/
|
||||
public function getNextLink()
|
||||
{
|
||||
return $this->getLink('next');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Zend_Gdata_App_Extension_Link element which represents
|
||||
* the URL used to retrieve the previous chunk of results when paging
|
||||
* through a feed. This link is in the atom feed as an atom:link with a
|
||||
* rel attribute value of 'previous'.
|
||||
*
|
||||
* @return Zend_Gdata_App_Extension_Link The link, or null if not found
|
||||
*/
|
||||
public function getPreviousLink()
|
||||
{
|
||||
return $this->getLink('previous');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_App_Extension_Link
|
||||
*/
|
||||
public function getLicenseLink()
|
||||
{
|
||||
return $this->getLink('license');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Zend_Gdata_App_Extension_Link element which represents
|
||||
* the URL used to retrieve the entry or feed represented by this object
|
||||
* This link is in the atom feed/entry as an atom:link with a
|
||||
* rel attribute value of 'self'.
|
||||
*
|
||||
* @return Zend_Gdata_App_Extension_Link The link, or null if not found
|
||||
*/
|
||||
public function getSelfLink()
|
||||
{
|
||||
return $this->getLink('self');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Zend_Gdata_App_Extension_Link element which represents
|
||||
* the URL for an alternate view of the data represented by this feed or
|
||||
* entry. This alternate view is commonly a user-facing webpage, blog
|
||||
* post, etc. The MIME type for the data at the URL is available from the
|
||||
* returned Zend_Gdata_App_Extension_Link element.
|
||||
* This link is in the atom feed/entry as an atom:link with a
|
||||
* rel attribute value of 'self'.
|
||||
*
|
||||
* @return Zend_Gdata_App_Extension_Link The link, or null if not found
|
||||
*/
|
||||
public function getAlternateLink()
|
||||
{
|
||||
return $this->getLink('alternate');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $value The array of Zend_Gdata_App_Extension_Link elements
|
||||
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
|
||||
*/
|
||||
public function setLink($value)
|
||||
{
|
||||
$this->_link = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_AppExtension_Rights
|
||||
*/
|
||||
public function getRights()
|
||||
{
|
||||
return $this->_rights;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Gdata_App_Extension_Rights $value
|
||||
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
|
||||
*/
|
||||
public function setRights($value)
|
||||
{
|
||||
$this->_rights = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the title of this feed or entry. The title is an extremely
|
||||
* short textual representation of this resource and is found as
|
||||
* an atom:title element in a feed or entry
|
||||
*
|
||||
* @return Zend_Gdata_App_Extension_Title
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->_title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the title of this feed or entry.
|
||||
* The title is an extremely short textual representation of this
|
||||
* resource and is found as an atom:title element in a feed or entry
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitleValue()
|
||||
{
|
||||
if (($titleObj = $this->getTitle()) != null) {
|
||||
return $titleObj->getText();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the title of this feed or entry. The title is an extremely
|
||||
* short textual representation of this resource and is found as
|
||||
* an atom:title element in a feed or entry
|
||||
*
|
||||
* @param Zend_Gdata_App_Extension_Title $value
|
||||
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
|
||||
*/
|
||||
public function setTitle($value)
|
||||
{
|
||||
$this->_title = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_App_Extension_Updated
|
||||
*/
|
||||
public function getUpdated()
|
||||
{
|
||||
return $this->_updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Gdata_App_Extension_Updated $value
|
||||
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
|
||||
*/
|
||||
public function setUpdated($value)
|
||||
{
|
||||
$this->_updated = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Etag for the current entry to $value. Setting $value to null
|
||||
* unsets the Etag.
|
||||
*
|
||||
* @param string|null $value
|
||||
* @return Zend_Gdata_App_Entry Provides a fluent interface
|
||||
*/
|
||||
public function setEtag($value) {
|
||||
$this->_etag = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Etag for the current entry, or null if not set.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getEtag() {
|
||||
return $this->_etag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the major protocol version that should be used. Values < 1
|
||||
* (excluding NULL) will cause a Zend_Gdata_App_InvalidArgumentException
|
||||
* to be thrown.
|
||||
*
|
||||
* @see _majorProtocolVersion
|
||||
* @param (int|NULL) $value The major protocol version to use.
|
||||
* @throws Zend_Gdata_App_InvalidArgumentException
|
||||
*/
|
||||
public function setMajorProtocolVersion($value)
|
||||
{
|
||||
if (!($value >= 1) && ($value !== null)) {
|
||||
require_once('Zend/Gdata/App/InvalidArgumentException.php');
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'Major protocol version must be >= 1');
|
||||
}
|
||||
$this->_majorProtocolVersion = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the major protocol version that is in use.
|
||||
*
|
||||
* @see _majorProtocolVersion
|
||||
* @return (int|NULL) The major protocol version in use.
|
||||
*/
|
||||
public function getMajorProtocolVersion()
|
||||
{
|
||||
return $this->_majorProtocolVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minor protocol version that should be used. If set to NULL, no
|
||||
* minor protocol version will be sent to the server. Values < 0 will
|
||||
* cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
|
||||
*
|
||||
* @see _minorProtocolVersion
|
||||
* @param (int|NULL) $value The minor protocol version to use.
|
||||
* @throws Zend_Gdata_App_InvalidArgumentException
|
||||
*/
|
||||
public function setMinorProtocolVersion($value)
|
||||
{
|
||||
if (!($value >= 0)) {
|
||||
require_once('Zend/Gdata/App/InvalidArgumentException.php');
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'Minor protocol version must be >= 0 or null');
|
||||
}
|
||||
$this->_minorProtocolVersion = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minor protocol version that is in use.
|
||||
*
|
||||
* @see _minorProtocolVersion
|
||||
* @return (int|NULL) The major protocol version in use, or NULL if no
|
||||
* minor version is specified.
|
||||
*/
|
||||
public function getMinorProtocolVersion()
|
||||
{
|
||||
return $this->_minorProtocolVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full version of a namespace prefix
|
||||
*
|
||||
* Looks up a prefix (atom:, etc.) in the list of registered
|
||||
* namespaces and returns the full namespace URI if
|
||||
* available. Returns the prefix, unmodified, if it's not
|
||||
* registered.
|
||||
*
|
||||
* The current entry or feed's version will be used when performing the
|
||||
* namespace lookup unless overridden using $majorVersion and
|
||||
* $minorVersion. If the entry/fee has a null version, then the latest
|
||||
* protocol version will be used by default.
|
||||
*
|
||||
* @param string $prefix The namespace prefix to lookup.
|
||||
* @param integer $majorVersion The major protocol version in effect.
|
||||
* Defaults to null (auto-select).
|
||||
* @param integer $minorVersion The minor protocol version in effect.
|
||||
* Defaults to null (auto-select).
|
||||
* @return string
|
||||
*/
|
||||
public function lookupNamespace($prefix,
|
||||
$majorVersion = null,
|
||||
$minorVersion = null)
|
||||
{
|
||||
// Auto-select current version
|
||||
if ($majorVersion === null) {
|
||||
$majorVersion = $this->getMajorProtocolVersion();
|
||||
}
|
||||
if ($minorVersion === null) {
|
||||
$minorVersion = $this->getMinorProtocolVersion();
|
||||
}
|
||||
|
||||
// Perform lookup
|
||||
return parent::lookupNamespace($prefix, $majorVersion, $minorVersion);
|
||||
}
|
||||
|
||||
}
|
||||
267
Zend/Gdata/App/FeedSourceParent.php
Executable file
267
Zend/Gdata/App/FeedSourceParent.php
Executable file
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Entry
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Entry.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_FeedSourceParent
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/FeedEntryParent.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Generator
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Generator.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Icon
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Icon.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Logo
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Logo.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Extension_Subtitle
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Extension/Subtitle.php';
|
||||
|
||||
/**
|
||||
* Atom feed class
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Gdata_App_FeedSourceParent extends Zend_Gdata_App_FeedEntryParent
|
||||
{
|
||||
|
||||
/**
|
||||
* The classname for individual feed elements.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_entryClassName = 'Zend_Gdata_App_Entry';
|
||||
|
||||
/**
|
||||
* Root XML element for Atom entries.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_rootElement = null;
|
||||
|
||||
protected $_generator = null;
|
||||
protected $_icon = null;
|
||||
protected $_logo = null;
|
||||
protected $_subtitle = null;
|
||||
|
||||
/**
|
||||
* Set the HTTP client instance
|
||||
*
|
||||
* Sets the HTTP client object to use for retrieving the feed.
|
||||
*
|
||||
* @deprecated Deprecated as of Zend Framework 1.7. Use
|
||||
* setService() instead.
|
||||
* @param Zend_Http_Client $httpClient
|
||||
* @return Zend_Gdata_App_FeedSourceParent Provides a fluent interface
|
||||
*/
|
||||
public function setHttpClient(Zend_Http_Client $httpClient)
|
||||
{
|
||||
parent::setHttpClient($httpClient);
|
||||
foreach ($this->_entry as $entry) {
|
||||
$entry->setHttpClient($httpClient);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the active service instance for this feed and all enclosed entries.
|
||||
* This will be used to perform network requests, such as when calling
|
||||
* save() and delete().
|
||||
*
|
||||
* @param Zend_Gdata_App $instance The new service instance.
|
||||
* @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface.
|
||||
*/
|
||||
public function setService($instance)
|
||||
{
|
||||
parent::setService($instance);
|
||||
foreach ($this->_entry as $entry) {
|
||||
$entry->setService($instance);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make accessing some individual elements of the feed easier.
|
||||
*
|
||||
* Special accessors 'entry' and 'entries' are provided so that if
|
||||
* you wish to iterate over an Atom feed's entries, you can do so
|
||||
* using foreach ($feed->entries as $entry) or foreach
|
||||
* ($feed->entry as $entry).
|
||||
*
|
||||
* @param string $var The property to access.
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($var)
|
||||
{
|
||||
switch ($var) {
|
||||
default:
|
||||
return parent::__get($var);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
||||
{
|
||||
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
||||
if ($this->_generator != null) {
|
||||
$element->appendChild($this->_generator->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_icon != null) {
|
||||
$element->appendChild($this->_icon->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_logo != null) {
|
||||
$element->appendChild($this->_logo->getDOM($element->ownerDocument));
|
||||
}
|
||||
if ($this->_subtitle != null) {
|
||||
$element->appendChild($this->_subtitle->getDOM($element->ownerDocument));
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates individual Entry objects of the appropriate type and
|
||||
* stores them in the $_entry array based upon DOM data.
|
||||
*
|
||||
* @param DOMNode $child The DOMNode to process
|
||||
*/
|
||||
protected function takeChildFromDOM($child)
|
||||
{
|
||||
$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
|
||||
switch ($absoluteNodeName) {
|
||||
case $this->lookupNamespace('atom') . ':' . 'generator':
|
||||
$generator = new Zend_Gdata_App_Extension_Generator();
|
||||
$generator->transferFromDOM($child);
|
||||
$this->_generator = $generator;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'icon':
|
||||
$icon = new Zend_Gdata_App_Extension_Icon();
|
||||
$icon->transferFromDOM($child);
|
||||
$this->_icon = $icon;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'logo':
|
||||
$logo = new Zend_Gdata_App_Extension_Logo();
|
||||
$logo->transferFromDOM($child);
|
||||
$this->_logo = $logo;
|
||||
break;
|
||||
case $this->lookupNamespace('atom') . ':' . 'subtitle':
|
||||
$subtitle = new Zend_Gdata_App_Extension_Subtitle();
|
||||
$subtitle->transferFromDOM($child);
|
||||
$this->_subtitle = $subtitle;
|
||||
break;
|
||||
default:
|
||||
parent::takeChildFromDOM($child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_AppExtension_Generator
|
||||
*/
|
||||
public function getGenerator()
|
||||
{
|
||||
return $this->_generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Gdata_App_Extension_Generator $value
|
||||
* @return Zend_Gdata_App_FeedSourceParent Provides a fluent interface
|
||||
*/
|
||||
public function setGenerator($value)
|
||||
{
|
||||
$this->_generator = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_AppExtension_Icon
|
||||
*/
|
||||
public function getIcon()
|
||||
{
|
||||
return $this->_icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Gdata_App_Extension_Icon $value
|
||||
* @return Zend_Gdata_App_FeedSourceParent Provides a fluent interface
|
||||
*/
|
||||
public function setIcon($value)
|
||||
{
|
||||
$this->_icon = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_AppExtension_logo
|
||||
*/
|
||||
public function getlogo()
|
||||
{
|
||||
return $this->_logo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Gdata_App_Extension_logo $value
|
||||
* @return Zend_Gdata_App_FeedSourceParent Provides a fluent interface
|
||||
*/
|
||||
public function setlogo($value)
|
||||
{
|
||||
$this->_logo = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Gdata_AppExtension_Subtitle
|
||||
*/
|
||||
public function getSubtitle()
|
||||
{
|
||||
return $this->_subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Gdata_App_Extension_Subtitle $value
|
||||
* @return Zend_Gdata_App_FeedSourceParent Provides a fluent interface
|
||||
*/
|
||||
public function setSubtitle($value)
|
||||
{
|
||||
$this->_subtitle = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
121
Zend/Gdata/App/HttpException.php
Executable file
121
Zend/Gdata/App/HttpException.php
Executable file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Gdata_App_Exception
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
|
||||
/**
|
||||
* Zend_Http_Client_Exception
|
||||
*/
|
||||
require_once 'Zend/Http/Client/Exception.php';
|
||||
|
||||
/**
|
||||
* Gdata exceptions
|
||||
*
|
||||
* Class to represent exceptions that occur during Gdata operations.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_HttpException extends Zend_Gdata_App_Exception
|
||||
{
|
||||
|
||||
protected $_httpClientException = null;
|
||||
protected $_response = null;
|
||||
|
||||
/**
|
||||
* Create a new Zend_Gdata_App_HttpException
|
||||
*
|
||||
* @param string $message Optionally set a message
|
||||
* @param Zend_Http_Client_Exception Optionally pass in a Zend_Http_Client_Exception
|
||||
* @param Zend_Http_Response Optionally pass in a Zend_Http_Response
|
||||
*/
|
||||
public function __construct($message = null, $e = null, $response = null)
|
||||
{
|
||||
$this->_httpClientException = $e;
|
||||
$this->_response = $response;
|
||||
parent::__construct($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Zend_Http_Client_Exception.
|
||||
*
|
||||
* @return Zend_Http_Client_Exception
|
||||
*/
|
||||
public function getHttpClientException()
|
||||
{
|
||||
return $this->_httpClientException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Zend_Http_Client_Exception.
|
||||
*
|
||||
* @param Zend_Http_Client_Exception $value
|
||||
*/
|
||||
public function setHttpClientException($value)
|
||||
{
|
||||
$this->_httpClientException = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Zend_Http_Response.
|
||||
*
|
||||
* @param Zend_Http_Response $response
|
||||
*/
|
||||
public function setResponse($response)
|
||||
{
|
||||
$this->_response = $response;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Zend_Http_Response.
|
||||
*
|
||||
* @return Zend_Http_Response
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the body of the Zend_Http_Response
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawResponseBody()
|
||||
{
|
||||
if ($this->getResponse()) {
|
||||
$response = $this->getResponse();
|
||||
return $response->getRawBody();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
43
Zend/Gdata/App/IOException.php
Executable file
43
Zend/Gdata/App/IOException.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Zend_Gdata_App_Exception
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
|
||||
/**
|
||||
* Gdata App IO exceptions.
|
||||
*
|
||||
* Class to represent IO exceptions that occur during Gdata App operations.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_IOException extends Zend_Gdata_App_Exception
|
||||
{
|
||||
}
|
||||
42
Zend/Gdata/App/InvalidArgumentException.php
Executable file
42
Zend/Gdata/App/InvalidArgumentException.php
Executable file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Gdata_App_Exception
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
|
||||
/**
|
||||
* Gdata exceptions
|
||||
*
|
||||
* Class to represent exceptions that occur during Gdata operations.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_InvalidArgumentException extends Zend_Gdata_App_Exception
|
||||
{
|
||||
}
|
||||
119
Zend/Gdata/App/LoggingHttpClientAdapterSocket.php
Executable file
119
Zend/Gdata/App/LoggingHttpClientAdapterSocket.php
Executable file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Http_Client_Adapter_Socket
|
||||
*/
|
||||
require_once 'Zend/Http/Client/Adapter/Socket.php';
|
||||
|
||||
/**
|
||||
* Overrides the traditional socket-based adapter class for Zend_Http_Client to
|
||||
* enable logging of requests. All requests are logged to a location specified
|
||||
* in the config as $config['logfile']. Requests and responses are logged after
|
||||
* they are sent and received/processed, thus an error could prevent logging.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_LoggingHttpClientAdapterSocket extends Zend_Http_Client_Adapter_Socket
|
||||
{
|
||||
|
||||
/**
|
||||
* The file handle for writing logs
|
||||
*
|
||||
* @var resource|null
|
||||
*/
|
||||
protected $log_handle = null;
|
||||
|
||||
/**
|
||||
* Log the given message to the log file. The log file is configured
|
||||
* as the config param 'logfile'. This method opens the file for
|
||||
* writing if necessary.
|
||||
*
|
||||
* @param string $message The message to log
|
||||
*/
|
||||
protected function log($message)
|
||||
{
|
||||
if ($this->log_handle == null) {
|
||||
$this->log_handle = fopen($this->config['logfile'], 'a');
|
||||
}
|
||||
fwrite($this->log_handle, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the remote server
|
||||
*
|
||||
* @param string $host
|
||||
* @param int $port
|
||||
* @param boolean $secure
|
||||
* @param int $timeout
|
||||
*/
|
||||
public function connect($host, $port = 80, $secure = false)
|
||||
{
|
||||
$this->log("Connecting to: ${host}:${port}");
|
||||
return parent::connect($host, $port, $secure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send request to the remote server
|
||||
*
|
||||
* @param string $method
|
||||
* @param Zend_Uri_Http $uri
|
||||
* @param string $http_ver
|
||||
* @param array $headers
|
||||
* @param string $body
|
||||
* @return string Request as string
|
||||
*/
|
||||
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
|
||||
{
|
||||
$request = parent::write($method, $uri, $http_ver, $headers, $body);
|
||||
$this->log("\n\n" . $request);
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read response from server
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
$response = parent::read();
|
||||
$this->log("${response}\n\n");
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection to the server
|
||||
*
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$this->log("Closing socket\n\n");
|
||||
parent::close();
|
||||
}
|
||||
|
||||
}
|
||||
119
Zend/Gdata/App/MediaEntry.php
Executable file
119
Zend/Gdata/App/MediaEntry.php
Executable file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_Entry
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Entry.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_MediaSource
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/MediaSource.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_MediaMimeStream
|
||||
*/
|
||||
require_once 'Zend/Gdata/MediaMimeStream.php';
|
||||
|
||||
/**
|
||||
* Concrete class for working with Atom entries containing multi-part data.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_MediaEntry extends Zend_Gdata_App_Entry
|
||||
{
|
||||
/**
|
||||
* The attached MediaSource/file
|
||||
*
|
||||
* @var Zend_Gdata_App_MediaSource
|
||||
*/
|
||||
protected $_mediaSource = null;
|
||||
|
||||
/**
|
||||
* Constructs a new MediaEntry, representing XML data and optional
|
||||
* file to upload
|
||||
*
|
||||
* @param DOMElement $element (optional) DOMElement from which this
|
||||
* object should be constructed.
|
||||
*/
|
||||
public function __construct($element = null, $mediaSource = null)
|
||||
{
|
||||
parent::__construct($element);
|
||||
$this->_mediaSource = $mediaSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MIME multipart representation of this MediaEntry.
|
||||
*
|
||||
* @return string|Zend_Gdata_MediaMimeStream The MIME multipart
|
||||
* representation of this MediaEntry. If the entry consisted only
|
||||
* of XML, a string is returned.
|
||||
*/
|
||||
public function encode()
|
||||
{
|
||||
$xmlData = $this->saveXML();
|
||||
$mediaSource = $this->getMediaSource();
|
||||
if ($mediaSource === null) {
|
||||
// No attachment, just send XML for entry
|
||||
return $xmlData;
|
||||
} else {
|
||||
return new Zend_Gdata_MediaMimeStream($xmlData,
|
||||
$mediaSource->getFilename(), $mediaSource->getContentType());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MediaSource object representing the file attached to this
|
||||
* MediaEntry.
|
||||
*
|
||||
* @return Zend_Gdata_App_MediaSource The attached MediaSource/file
|
||||
*/
|
||||
public function getMediaSource()
|
||||
{
|
||||
return $this->_mediaSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the MediaSource object (file) for this MediaEntry
|
||||
*
|
||||
* @param Zend_Gdata_App_MediaSource $value The attached MediaSource/file
|
||||
* @return Zend_Gdata_App_MediaEntry Provides a fluent interface
|
||||
*/
|
||||
public function setMediaSource($value)
|
||||
{
|
||||
if ($value instanceof Zend_Gdata_App_MediaSource) {
|
||||
$this->_mediaSource = $value;
|
||||
} else {
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'You must specify the media data as a class that conforms to Zend_Gdata_App_MediaSource.');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
146
Zend/Gdata/App/MediaFileSource.php
Executable file
146
Zend/Gdata/App/MediaFileSource.php
Executable file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_App_MediaData
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/BaseMediaSource.php';
|
||||
|
||||
/**
|
||||
* Concrete class to use a file handle as an attachment within a MediaEntry.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_MediaFileSource extends Zend_Gdata_App_BaseMediaSource
|
||||
{
|
||||
/**
|
||||
* The filename which is represented
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_filename = null;
|
||||
|
||||
/**
|
||||
* The content type for the file attached (example image/png)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_contentType = null;
|
||||
|
||||
/**
|
||||
* Create a new Zend_Gdata_App_MediaFileSource object.
|
||||
*
|
||||
* @param string $filename The name of the file to read from.
|
||||
*/
|
||||
public function __construct($filename)
|
||||
{
|
||||
$this->setFilename($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MIME multipart representation of this MediaEntry.
|
||||
*
|
||||
* @return string
|
||||
* @throws Zend_Gdata_App_IOException
|
||||
*/
|
||||
public function encode()
|
||||
{
|
||||
if ($this->getFilename() !== null &&
|
||||
is_readable($this->getFilename())) {
|
||||
|
||||
// Retrieves the file, using the include path
|
||||
$fileHandle = fopen($this->getFilename(), 'r', true);
|
||||
$result = fread($fileHandle, filesize($this->getFilename()));
|
||||
if ($result === false) {
|
||||
require_once 'Zend/Gdata/App/IOException.php';
|
||||
throw new Zend_Gdata_App_IOException("Error reading file - " .
|
||||
$this->getFilename() . '. Read failed.');
|
||||
}
|
||||
fclose($fileHandle);
|
||||
return $result;
|
||||
} else {
|
||||
require_once 'Zend/Gdata/App/IOException.php';
|
||||
throw new Zend_Gdata_App_IOException("Error reading file - " .
|
||||
$this->getFilename() . '. File is not readable.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filename associated with this reader.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFilename()
|
||||
{
|
||||
return $this->_filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filename which is to be read.
|
||||
*
|
||||
* @param string $value The desired file handle.
|
||||
* @return Zend_Gdata_App_MediaFileSource Provides a fluent interface.
|
||||
*/
|
||||
public function setFilename($value)
|
||||
{
|
||||
$this->_filename = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The content type for the file attached (example image/png)
|
||||
*
|
||||
* @return string The content type
|
||||
*/
|
||||
public function getContentType()
|
||||
{
|
||||
return $this->_contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content type for the file attached (example image/png)
|
||||
*
|
||||
* @param string $value The content type
|
||||
* @return Zend_Gdata_App_MediaFileSource Provides a fluent interface
|
||||
*/
|
||||
public function setContentType($value)
|
||||
{
|
||||
$this->_contentType = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for getFilename().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getFilename();
|
||||
}
|
||||
|
||||
}
|
||||
73
Zend/Gdata/App/MediaSource.php
Executable file
73
Zend/Gdata/App/MediaSource.php
Executable file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for defining data that can be encoded and sent over the network.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Gdata_App_MediaSource
|
||||
{
|
||||
/**
|
||||
* Return a byte stream representation of this object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function encode();
|
||||
|
||||
/**
|
||||
* Set the content type for the file attached (example image/png)
|
||||
*
|
||||
* @param string $value The content type
|
||||
* @return Zend_Gdata_App_MediaFileSource Provides a fluent interface
|
||||
*/
|
||||
public function setContentType($value);
|
||||
|
||||
/**
|
||||
* The content type for the file attached (example image/png)
|
||||
*
|
||||
* @return string The content type
|
||||
*/
|
||||
public function getContentType();
|
||||
|
||||
/**
|
||||
* Sets the Slug header value. Used by some services to determine the
|
||||
* title for the uploaded file. A null value indicates no slug header.
|
||||
*
|
||||
* @var string The slug value
|
||||
* @return Zend_Gdata_App_MediaSource Provides a fluent interface
|
||||
*/
|
||||
public function setSlug($value);
|
||||
|
||||
/**
|
||||
* Returns the Slug header value. Used by some services to determine the
|
||||
* title for the uploaded file. Returns null if no slug should be used.
|
||||
*
|
||||
* @return string The slug value
|
||||
*/
|
||||
public function getSlug();
|
||||
}
|
||||
112
Zend/Gdata/App/Util.php
Executable file
112
Zend/Gdata/App/Util.php
Executable file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility class for static functions needed by Zend_Gdata_App
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_Util
|
||||
{
|
||||
|
||||
/**
|
||||
* Convert timestamp into RFC 3339 date string.
|
||||
* 2005-04-19T15:30:00
|
||||
*
|
||||
* @param int $timestamp
|
||||
* @throws Zend_Gdata_App_InvalidArgumentException
|
||||
*/
|
||||
public static function formatTimestamp($timestamp)
|
||||
{
|
||||
$rfc3339 = '/^(\d{4})\-?(\d{2})\-?(\d{2})((T|t)(\d{2})\:?(\d{2})' .
|
||||
'\:?(\d{2})(\.\d{1,})?((Z|z)|([\+\-])(\d{2})\:?(\d{2})))?$/';
|
||||
|
||||
if (ctype_digit($timestamp)) {
|
||||
return gmdate('Y-m-d\TH:i:sP', $timestamp);
|
||||
} elseif (preg_match($rfc3339, $timestamp) > 0) {
|
||||
// timestamp is already properly formatted
|
||||
return $timestamp;
|
||||
} else {
|
||||
$ts = strtotime($timestamp);
|
||||
if ($ts === false) {
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException("Invalid timestamp: $timestamp.");
|
||||
}
|
||||
return date('Y-m-d\TH:i:s', $ts);
|
||||
}
|
||||
}
|
||||
|
||||
/** Find the greatest key that is less than or equal to a given upper
|
||||
* bound, and return the value associated with that key.
|
||||
*
|
||||
* @param integer|null $maximumKey The upper bound for keys. If null, the
|
||||
* maxiumum valued key will be found.
|
||||
* @param array $collection An two-dimensional array of key/value pairs
|
||||
* to search through.
|
||||
* @returns mixed The value corresponding to the located key.
|
||||
* @throws Zend_Gdata_App_Exception Thrown if $collection is empty.
|
||||
*/
|
||||
public static function findGreatestBoundedValue($maximumKey, $collection)
|
||||
{
|
||||
$found = false;
|
||||
$foundKey = $maximumKey;
|
||||
|
||||
// Sanity check: Make sure that the collection isn't empty
|
||||
if (sizeof($collection) == 0) {
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
throw new Zend_Gdata_App_Exception("Empty namespace collection encountered.");
|
||||
}
|
||||
|
||||
if ($maximumKey === null) {
|
||||
// If the key is null, then we return the maximum available
|
||||
$keys = array_keys($collection);
|
||||
sort($keys);
|
||||
$found = true;
|
||||
$foundKey = end($keys);
|
||||
} else {
|
||||
// Otherwise, we optimistically guess that the current version
|
||||
// will have a matching namespce. If that fails, we decrement the
|
||||
// version until we find a match.
|
||||
while (!$found && $foundKey >= 0) {
|
||||
if (array_key_exists($foundKey, $collection))
|
||||
$found = true;
|
||||
else
|
||||
$foundKey--;
|
||||
}
|
||||
}
|
||||
|
||||
// Guard: A namespace wasn't found. Either none were registered, or
|
||||
// the current protcol version is lower than the maximum namespace.
|
||||
if (!$found) {
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
throw new Zend_Gdata_App_Exception("Namespace compatible with current protocol not found.");
|
||||
}
|
||||
|
||||
return $foundKey;
|
||||
}
|
||||
|
||||
}
|
||||
42
Zend/Gdata/App/VersionException.php
Executable file
42
Zend/Gdata/App/VersionException.php
Executable file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Gdata_App_Exception
|
||||
*/
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
|
||||
/**
|
||||
* Gdata APP exceptions
|
||||
*
|
||||
* Class to represent version exceptions that occur during Gdata APP operations.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage App
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_App_VersionException extends Zend_Gdata_App_Exception
|
||||
{
|
||||
}
|
||||
246
Zend/Gdata/AuthSub.php
Executable file
246
Zend/Gdata/AuthSub.php
Executable file
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage Gdata
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Gdata_HttpClient
|
||||
*/
|
||||
require_once 'Zend/Gdata/HttpClient.php';
|
||||
|
||||
/**
|
||||
* Zend_Version
|
||||
*/
|
||||
require_once 'Zend/Version.php';
|
||||
|
||||
/**
|
||||
* Wrapper around Zend_Http_Client to facilitate Google's "Account Authentication
|
||||
* Proxy for Web-Based Applications".
|
||||
*
|
||||
* @see http://code.google.com/apis/accounts/AuthForWebApps.html
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage Gdata
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_AuthSub
|
||||
{
|
||||
|
||||
const AUTHSUB_REQUEST_URI = 'https://www.google.com/accounts/AuthSubRequest';
|
||||
|
||||
const AUTHSUB_SESSION_TOKEN_URI = 'https://www.google.com/accounts/AuthSubSessionToken';
|
||||
|
||||
const AUTHSUB_REVOKE_TOKEN_URI = 'https://www.google.com/accounts/AuthSubRevokeToken';
|
||||
|
||||
const AUTHSUB_TOKEN_INFO_URI = 'https://www.google.com/accounts/AuthSubTokenInfo';
|
||||
|
||||
/**
|
||||
* Creates a URI to request a single-use AuthSub token.
|
||||
*
|
||||
* @param string $next (required) URL identifying the service to be
|
||||
* accessed.
|
||||
* The resulting token will enable access to the specified service only.
|
||||
* Some services may limit scope further, such as read-only access.
|
||||
* @param string $scope (required) URL identifying the service to be
|
||||
* accessed. The resulting token will enable
|
||||
* access to the specified service only.
|
||||
* Some services may limit scope further, such
|
||||
* as read-only access.
|
||||
* @param int $secure (optional) Boolean flag indicating whether the
|
||||
* authentication transaction should issue a secure
|
||||
* token (1) or a non-secure token (0). Secure tokens
|
||||
* are available to registered applications only.
|
||||
* @param int $session (optional) Boolean flag indicating whether
|
||||
* the one-time-use token may be exchanged for
|
||||
* a session token (1) or not (0).
|
||||
* @param string $request_uri (optional) URI to which to direct the
|
||||
* authentication request.
|
||||
*/
|
||||
public static function getAuthSubTokenUri($next, $scope, $secure=0, $session=0,
|
||||
$request_uri = self::AUTHSUB_REQUEST_URI)
|
||||
{
|
||||
$querystring = '?next=' . urlencode($next)
|
||||
. '&scope=' . urldecode($scope)
|
||||
. '&secure=' . urlencode($secure)
|
||||
. '&session=' . urlencode($session);
|
||||
return $request_uri . $querystring;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Upgrades a single use token to a session token
|
||||
*
|
||||
* @param string $token The single use token which is to be upgraded
|
||||
* @param Zend_Http_Client $client (optional) HTTP client to use to
|
||||
* make the request
|
||||
* @param string $request_uri (optional) URI to which to direct
|
||||
* the session token upgrade
|
||||
* @return string The upgraded token value
|
||||
* @throws Zend_Gdata_App_AuthException
|
||||
* @throws Zend_Gdata_App_HttpException
|
||||
*/
|
||||
public static function getAuthSubSessionToken(
|
||||
$token, $client = null,
|
||||
$request_uri = self::AUTHSUB_SESSION_TOKEN_URI)
|
||||
{
|
||||
$client = self::getHttpClient($token, $client);
|
||||
|
||||
if ($client instanceof Zend_Gdata_HttpClient) {
|
||||
$filterResult = $client->filterHttpRequest('GET', $request_uri);
|
||||
$url = $filterResult['url'];
|
||||
$headers = $filterResult['headers'];
|
||||
$client->setHeaders($headers);
|
||||
$client->setUri($url);
|
||||
} else {
|
||||
$client->setUri($request_uri);
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $client->request('GET');
|
||||
} catch (Zend_Http_Client_Exception $e) {
|
||||
require_once 'Zend/Gdata/App/HttpException.php';
|
||||
throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
|
||||
}
|
||||
|
||||
// Parse Google's response
|
||||
if ($response->isSuccessful()) {
|
||||
$goog_resp = array();
|
||||
foreach (explode("\n", $response->getBody()) as $l) {
|
||||
$l = chop($l);
|
||||
if ($l) {
|
||||
list($key, $val) = explode('=', chop($l), 2);
|
||||
$goog_resp[$key] = $val;
|
||||
}
|
||||
}
|
||||
return $goog_resp['Token'];
|
||||
} else {
|
||||
require_once 'Zend/Gdata/App/AuthException.php';
|
||||
throw new Zend_Gdata_App_AuthException(
|
||||
'Token upgrade failed. Reason: ' . $response->getBody());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke a token
|
||||
*
|
||||
* @param string $token The token to revoke
|
||||
* @param Zend_Http_Client $client (optional) HTTP client to use to make the request
|
||||
* @param string $request_uri (optional) URI to which to direct the revokation request
|
||||
* @return boolean Whether the revokation was successful
|
||||
* @throws Zend_Gdata_App_HttpException
|
||||
*/
|
||||
public static function AuthSubRevokeToken($token, $client = null,
|
||||
$request_uri = self::AUTHSUB_REVOKE_TOKEN_URI)
|
||||
{
|
||||
$client = self::getHttpClient($token, $client);
|
||||
|
||||
if ($client instanceof Zend_Gdata_HttpClient) {
|
||||
$filterResult = $client->filterHttpRequest('GET', $request_uri);
|
||||
$url = $filterResult['url'];
|
||||
$headers = $filterResult['headers'];
|
||||
$client->setHeaders($headers);
|
||||
$client->setUri($url);
|
||||
$client->resetParameters();
|
||||
} else {
|
||||
$client->setUri($request_uri);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
try {
|
||||
$response = $client->request('GET');
|
||||
} catch (Zend_Http_Client_Exception $e) {
|
||||
require_once 'Zend/Gdata/App/HttpException.php';
|
||||
throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
|
||||
}
|
||||
ob_end_clean();
|
||||
// Parse Google's response
|
||||
if ($response->isSuccessful()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get token information
|
||||
*
|
||||
* @param string $token The token to retrieve information about
|
||||
* @param Zend_Http_Client $client (optional) HTTP client to use to
|
||||
* make the request
|
||||
* @param string $request_uri (optional) URI to which to direct
|
||||
* the information request
|
||||
*/
|
||||
public static function getAuthSubTokenInfo(
|
||||
$token, $client = null, $request_uri = self::AUTHSUB_TOKEN_INFO_URI)
|
||||
{
|
||||
$client = self::getHttpClient($token, $client);
|
||||
|
||||
if ($client instanceof Zend_Gdata_HttpClient) {
|
||||
$filterResult = $client->filterHttpRequest('GET', $request_uri);
|
||||
$url = $filterResult['url'];
|
||||
$headers = $filterResult['headers'];
|
||||
$client->setHeaders($headers);
|
||||
$client->setUri($url);
|
||||
} else {
|
||||
$client->setUri($request_uri);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
try {
|
||||
$response = $client->request('GET');
|
||||
} catch (Zend_Http_Client_Exception $e) {
|
||||
require_once 'Zend/Gdata/App/HttpException.php';
|
||||
throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
|
||||
}
|
||||
ob_end_clean();
|
||||
return $response->getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a HTTP client object with AuthSub credentials attached
|
||||
* as the Authorization header
|
||||
*
|
||||
* @param string $token The token to retrieve information about
|
||||
* @param Zend_Gdata_HttpClient $client (optional) HTTP client to use to make the request
|
||||
*/
|
||||
public static function getHttpClient($token, $client = null)
|
||||
{
|
||||
if ($client == null) {
|
||||
$client = new Zend_Gdata_HttpClient();
|
||||
}
|
||||
if (!$client instanceof Zend_Http_Client) {
|
||||
require_once 'Zend/Gdata/App/HttpException.php';
|
||||
throw new Zend_Gdata_App_HttpException('Client is not an instance of Zend_Http_Client.');
|
||||
}
|
||||
$useragent = 'Zend_Framework_Gdata/' . Zend_Version::VERSION;
|
||||
$client->setConfig(array(
|
||||
'strictredirects' => true,
|
||||
'useragent' => $useragent
|
||||
)
|
||||
);
|
||||
$client->setAuthSubToken($token);
|
||||
return $client;
|
||||
}
|
||||
|
||||
}
|
||||
204
Zend/Gdata/Books.php
Executable file
204
Zend/Gdata/Books.php
Executable file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage Books
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata
|
||||
*/
|
||||
require_once 'Zend/Gdata.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_DublinCore
|
||||
*/
|
||||
require_once 'Zend/Gdata/DublinCore.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_Books_CollectionEntry
|
||||
*/
|
||||
require_once 'Zend/Gdata/Books/CollectionEntry.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_Books_CollectionFeed
|
||||
*/
|
||||
require_once 'Zend/Gdata/Books/CollectionFeed.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_Books_VolumeEntry
|
||||
*/
|
||||
require_once 'Zend/Gdata/Books/VolumeEntry.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Gdata_Books_VolumeFeed
|
||||
*/
|
||||
require_once 'Zend/Gdata/Books/VolumeFeed.php';
|
||||
|
||||
/**
|
||||
* Service class for interacting with the Books service
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage Books
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Gdata_Books extends Zend_Gdata
|
||||
{
|
||||
const VOLUME_FEED_URI = 'http://books.google.com/books/feeds/volumes';
|
||||
const MY_LIBRARY_FEED_URI = 'http://books.google.com/books/feeds/users/me/collections/library/volumes';
|
||||
const MY_ANNOTATION_FEED_URI = 'http://books.google.com/books/feeds/users/me/volumes';
|
||||
const AUTH_SERVICE_NAME = 'print';
|
||||
|
||||
/**
|
||||
* Namespaces used for Zend_Gdata_Books
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $namespaces = array(
|
||||
array('gbs', 'http://schemas.google.com/books/2008', 1, 0),
|
||||
array('dc', 'http://purl.org/dc/terms', 1, 0)
|
||||
);
|
||||
|
||||
/**
|
||||
* Create Zend_Gdata_Books object
|
||||
*
|
||||
* @param Zend_Http_Client $client (optional) The HTTP client to use when
|
||||
* when communicating with the Google servers.
|
||||
* @param string $applicationId The identity of the app in the form of Company-AppName-Version
|
||||
*/
|
||||
public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
|
||||
{
|
||||
$this->registerPackage('Zend_Gdata_Books');
|
||||
$this->registerPackage('Zend_Gdata_Books_Extension');
|
||||
parent::__construct($client, $applicationId);
|
||||
$this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a feed of volumes.
|
||||
*
|
||||
* @param Zend_Gdata_Query|string|null $location (optional) The URL to
|
||||
* query or a Zend_Gdata_Query object from which a URL can be
|
||||
* determined.
|
||||
* @return Zend_Gdata_Books_VolumeFeed The feed of volumes found at the
|
||||
* specified URL.
|
||||
*/
|
||||
public function getVolumeFeed($location = null)
|
||||
{
|
||||
if ($location == null) {
|
||||
$uri = self::VOLUME_FEED_URI;
|
||||
} else if ($location instanceof Zend_Gdata_Query) {
|
||||
$uri = $location->getQueryUrl();
|
||||
} else {
|
||||
$uri = $location;
|
||||
}
|
||||
return parent::getFeed($uri, 'Zend_Gdata_Books_VolumeFeed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a specific volume entry.
|
||||
*
|
||||
* @param string|null $volumeId The volumeId of interest.
|
||||
* @param Zend_Gdata_Query|string|null $location (optional) The URL to
|
||||
* query or a Zend_Gdata_Query object from which a URL can be
|
||||
* determined.
|
||||
* @return Zend_Gdata_Books_VolumeEntry The feed of volumes found at the
|
||||
* specified URL.
|
||||
*/
|
||||
public function getVolumeEntry($volumeId = null, $location = null)
|
||||
{
|
||||
if ($volumeId !== null) {
|
||||
$uri = self::VOLUME_FEED_URI . "/" . $volumeId;
|
||||
} else if ($location instanceof Zend_Gdata_Query) {
|
||||
$uri = $location->getQueryUrl();
|
||||
} else {
|
||||
$uri = $location;
|
||||
}
|
||||
return parent::getEntry($uri, 'Zend_Gdata_Books_VolumeEntry');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a feed of volumes, by default the User library feed.
|
||||
*
|
||||
* @param Zend_Gdata_Query|string|null $location (optional) The URL to
|
||||
* query.
|
||||
* @return Zend_Gdata_Books_VolumeFeed The feed of volumes found at the
|
||||
* specified URL.
|
||||
*/
|
||||
public function getUserLibraryFeed($location = null)
|
||||
{
|
||||
if ($location == null) {
|
||||
$uri = self::MY_LIBRARY_FEED_URI;
|
||||
} else {
|
||||
$uri = $location;
|
||||
}
|
||||
return parent::getFeed($uri, 'Zend_Gdata_Books_VolumeFeed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a feed of volumes, by default the User annotation feed
|
||||
*
|
||||
* @param Zend_Gdata_Query|string|null $location (optional) The URL to
|
||||
* query.
|
||||
* @return Zend_Gdata_Books_VolumeFeed The feed of volumes found at the
|
||||
* specified URL.
|
||||
*/
|
||||
public function getUserAnnotationFeed($location = null)
|
||||
{
|
||||
if ($location == null) {
|
||||
$uri = self::MY_ANNOTATION_FEED_URI;
|
||||
} else {
|
||||
$uri = $location;
|
||||
}
|
||||
return parent::getFeed($uri, 'Zend_Gdata_Books_VolumeFeed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a Volume / Annotation
|
||||
*
|
||||
* @param Zend_Gdata_Books_VolumeEntry $entry
|
||||
* @param Zend_Gdata_Query|string|null $location (optional) The URL to
|
||||
* query
|
||||
* @return Zend_Gdata_Books_VolumeEntry The inserted volume entry.
|
||||
*/
|
||||
public function insertVolume($entry, $location = null)
|
||||
{
|
||||
if ($location == null) {
|
||||
$uri = self::MY_LIBRARY_FEED_URI;
|
||||
} else {
|
||||
$uri = $location;
|
||||
}
|
||||
return parent::insertEntry(
|
||||
$entry, $uri, 'Zend_Gdata_Books_VolumeEntry');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a Volume
|
||||
*
|
||||
* @param Zend_Gdata_Books_VolumeEntry $entry
|
||||
* @return void
|
||||
*/
|
||||
public function deleteVolume($entry)
|
||||
{
|
||||
$entry->delete();
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user