初始化合并后的信息平台代码
commit
07eeb74c21
@ -0,0 +1,3 @@
|
||||
.svn/*
|
||||
*/logs/log*
|
||||
/web.config
|
@ -0,0 +1,12 @@
|
||||
staging:
|
||||
script:
|
||||
- curl -sSf http://202.103.68.144:8888/please_dont_delete_this_file_4a4f500ae61d9e44b931d9f72fb14aaf95517b7e.php?branch=develop
|
||||
only:
|
||||
- develop
|
||||
|
||||
production:
|
||||
script:
|
||||
- curl -sSf http://202.103.68.144:8888/please_dont_delete_this_file_4a4f500ae61d9e44b931d9f72fb14aaf95517b7e.php?branch=master
|
||||
only:
|
||||
- master
|
||||
- /^deploy-.*$/
|
@ -0,0 +1,6 @@
|
||||
<IfModule mod_php4.c>
|
||||
php_value engine off
|
||||
</IfModule>
|
||||
<IfModule mod_php5.c>
|
||||
php_value engine off
|
||||
</IfModule>
|
@ -0,0 +1 @@
|
||||
Deny from all
|
@ -0,0 +1 @@
|
||||
deny from all
|
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1 @@
|
||||
Deny from all
|
@ -0,0 +1,116 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| AUTO-LOADER
|
||||
| -------------------------------------------------------------------
|
||||
| This file specifies which systems should be loaded by default.
|
||||
|
|
||||
| In order to keep the framework as light-weight as possible only the
|
||||
| absolute minimal resources are loaded by default. For example,
|
||||
| the database is not connected to automatically since no assumption
|
||||
| is made regarding whether you intend to use it. This file lets
|
||||
| you globally define which systems you would like loaded with every
|
||||
| request.
|
||||
|
|
||||
| -------------------------------------------------------------------
|
||||
| Instructions
|
||||
| -------------------------------------------------------------------
|
||||
|
|
||||
| These are the things you can load automatically:
|
||||
|
|
||||
| 1. Packages
|
||||
| 2. Libraries
|
||||
| 3. Helper files
|
||||
| 4. Custom config files
|
||||
| 5. Language files
|
||||
| 6. Models
|
||||
|
|
||||
*/
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Packges
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['packages'] = array(APPPATH.'third_party', '/usr/local/shared');
|
||||
|
|
||||
*/
|
||||
|
||||
$autoload['packages'] = array(APPPATH.'third_party');
|
||||
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Libraries
|
||||
| -------------------------------------------------------------------
|
||||
| These are the classes located in the system/libraries folder
|
||||
| or in your application/libraries folder.
|
||||
|
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['libraries'] = array('database', 'session', 'xmlrpc');
|
||||
*/
|
||||
|
||||
$autoload['libraries'] = array('Form_validation','session','permission');
|
||||
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Helper Files
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['helper'] = array('url', 'file');
|
||||
*/
|
||||
|
||||
$autoload['helper'] = array('url','info');
|
||||
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Config files
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['config'] = array('config1', 'config2');
|
||||
|
|
||||
| NOTE: This item is intended for use ONLY if you have created custom
|
||||
| config files. Otherwise, leave it blank.
|
||||
|
|
||||
*/
|
||||
|
||||
$autoload['config'] = array();
|
||||
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Language files
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['language'] = array('lang1', 'lang2');
|
||||
|
|
||||
| NOTE: Do not include the "_lang" part of your file. For example
|
||||
| "codeigniter_lang.php" would be referenced as array('codeigniter');
|
||||
|
|
||||
*/
|
||||
|
||||
$autoload['language'] = array('form_validation');
|
||||
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| Auto-load Models
|
||||
| -------------------------------------------------------------------
|
||||
| Prototype:
|
||||
|
|
||||
| $autoload['model'] = array('model1', 'model2');
|
||||
|
|
||||
*/
|
||||
|
||||
$autoload['model'] = array();
|
||||
|
||||
|
||||
/* End of file autoload.php */
|
||||
/* Location: ./application/config/autoload.php */
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,41 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| File and Directory Modes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These prefs are used when checking and setting modes when working
|
||||
| with the file system. The defaults are fine on servers with proper
|
||||
| security, but you may wish (or even need) to change the values in
|
||||
| certain environments (Apache running a separate process for each
|
||||
| user, PHP under CGI with Apache suEXEC, etc.). Octal values should
|
||||
| always be used to set the mode correctly.
|
||||
|
|
||||
*/
|
||||
define('FILE_READ_MODE', 0644);
|
||||
define('FILE_WRITE_MODE', 0666);
|
||||
define('DIR_READ_MODE', 0755);
|
||||
define('DIR_WRITE_MODE', 0777);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| File Stream Modes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These modes are used when working with fopen()/popen()
|
||||
|
|
||||
*/
|
||||
|
||||
define('FOPEN_READ', 'rb');
|
||||
define('FOPEN_READ_WRITE', 'r+b');
|
||||
define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care
|
||||
define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care
|
||||
define('FOPEN_WRITE_CREATE', 'ab');
|
||||
define('FOPEN_READ_WRITE_CREATE', 'a+b');
|
||||
define('FOPEN_WRITE_CREATE_STRICT', 'xb');
|
||||
define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b');
|
||||
|
||||
|
||||
/* End of file constants.php */
|
||||
/* Location: ./application/config/constants.php */
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| DATABASE CONNECTIVITY SETTINGS
|
||||
| -------------------------------------------------------------------
|
||||
| This file will contain the settings needed to access your database.
|
||||
|
|
||||
| For complete instructions please consult the 'Database Connection'
|
||||
| page of the User Guide.
|
||||
|
|
||||
| -------------------------------------------------------------------
|
||||
| EXPLANATION OF VARIABLES
|
||||
| -------------------------------------------------------------------
|
||||
|
|
||||
| ['hostname'] The hostname of your database server.
|
||||
| ['username'] The username used to connect to the database
|
||||
| ['password'] The password used to connect to the database
|
||||
| ['database'] The name of the database you want to connect to
|
||||
| ['dbdriver'] The database type. ie: mysql. Currently supported:
|
||||
mysql, mysqli, postgre, odbc, mssql, sqlite, oci8
|
||||
| ['dbprefix'] You can add an optional prefix, which will be added
|
||||
| to the table name when using the Active Record class
|
||||
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
|
||||
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
|
||||
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
|
||||
| ['cachedir'] The path to the folder where cache files should be stored
|
||||
| ['char_set'] The character set used in communicating with the database
|
||||
| ['dbcollat'] The character collation used in communicating with the database
|
||||
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
|
||||
| ['autoinit'] Whether or not to automatically initialize the database.
|
||||
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
|
||||
| - good for ensuring strict SQL while developing
|
||||
|
|
||||
| The $active_group variable lets you choose which connection group to
|
||||
| make active. By default there is only one group (the 'default' group).
|
||||
|
|
||||
| The $active_record variables lets you determine whether or not to load
|
||||
| the active record class
|
||||
*/
|
||||
|
||||
//选择数据库
|
||||
$active_group = 'HT';
|
||||
//是否加载
|
||||
$active_record = TRUE;
|
||||
|
||||
require 'C:/database_conn.php';
|
||||
|
||||
/* End of file database.php */
|
||||
/* Location: ./application/config/database.php */
|
@ -0,0 +1,15 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
$_doctypes = array(
|
||||
'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
|
||||
'xhtml1-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
|
||||
'xhtml1-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
||||
'xhtml1-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
|
||||
'html5' => '<!DOCTYPE html>',
|
||||
'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
|
||||
'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
|
||||
'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'
|
||||
);
|
||||
|
||||
/* End of file doctypes.php */
|
||||
/* Location: ./application/config/doctypes.php */
|
@ -0,0 +1,16 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| Hooks
|
||||
| -------------------------------------------------------------------------
|
||||
| This file lets you define "hooks" to extend CI without hacking the core
|
||||
| files. Please see the user guide for info:
|
||||
|
|
||||
| http://codeigniter.com/user_guide/general/hooks.html
|
||||
|
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* End of file hooks.php */
|
||||
/* Location: ./application/config/hooks.php */
|
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,106 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| MIME TYPES
|
||||
| -------------------------------------------------------------------
|
||||
| This file contains an array of mime types. It is used by the
|
||||
| Upload class to help identify allowed file types.
|
||||
|
|
||||
*/
|
||||
|
||||
$mimes = array( 'hqx' => 'application/mac-binhex40',
|
||||
'cpt' => 'application/mac-compactpro',
|
||||
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
|
||||
'bin' => 'application/macbinary',
|
||||
'dms' => 'application/octet-stream',
|
||||
'lha' => 'application/octet-stream',
|
||||
'lzh' => 'application/octet-stream',
|
||||
'exe' => array('application/octet-stream', 'application/x-msdownload'),
|
||||
'class' => 'application/octet-stream',
|
||||
'psd' => 'application/x-photoshop',
|
||||
'so' => 'application/octet-stream',
|
||||
'sea' => 'application/octet-stream',
|
||||
'dll' => 'application/octet-stream',
|
||||
'oda' => 'application/oda',
|
||||
'pdf' => array('application/pdf', 'application/x-download'),
|
||||
'ai' => 'application/postscript',
|
||||
'eps' => 'application/postscript',
|
||||
'ps' => 'application/postscript',
|
||||
'smi' => 'application/smil',
|
||||
'smil' => 'application/smil',
|
||||
'mif' => 'application/vnd.mif',
|
||||
'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),
|
||||
'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'),
|
||||
'wbxml' => 'application/wbxml',
|
||||
'wmlc' => 'application/wmlc',
|
||||
'dcr' => 'application/x-director',
|
||||
'dir' => 'application/x-director',
|
||||
'dxr' => 'application/x-director',
|
||||
'dvi' => 'application/x-dvi',
|
||||
'gtar' => 'application/x-gtar',
|
||||
'gz' => 'application/x-gzip',
|
||||
'php' => 'application/x-httpd-php',
|
||||
'php4' => 'application/x-httpd-php',
|
||||
'php3' => 'application/x-httpd-php',
|
||||
'phtml' => 'application/x-httpd-php',
|
||||
'phps' => 'application/x-httpd-php-source',
|
||||
'js' => 'application/x-javascript',
|
||||
'swf' => 'application/x-shockwave-flash',
|
||||
'sit' => 'application/x-stuffit',
|
||||
'tar' => 'application/x-tar',
|
||||
'tgz' => array('application/x-tar', 'application/x-gzip-compressed'),
|
||||
'xhtml' => 'application/xhtml+xml',
|
||||
'xht' => 'application/xhtml+xml',
|
||||
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'),
|
||||
'mid' => 'audio/midi',
|
||||
'midi' => 'audio/midi',
|
||||
'mpga' => 'audio/mpeg',
|
||||
'mp2' => 'audio/mpeg',
|
||||
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
|
||||
'aif' => 'audio/x-aiff',
|
||||
'aiff' => 'audio/x-aiff',
|
||||
'aifc' => 'audio/x-aiff',
|
||||
'ram' => 'audio/x-pn-realaudio',
|
||||
'rm' => 'audio/x-pn-realaudio',
|
||||
'rpm' => 'audio/x-pn-realaudio-plugin',
|
||||
'ra' => 'audio/x-realaudio',
|
||||
'rv' => 'video/vnd.rn-realvideo',
|
||||
'wav' => 'audio/x-wav',
|
||||
'bmp' => 'image/bmp',
|
||||
'gif' => 'image/gif',
|
||||
'jpeg' => array('image/jpeg', 'image/pjpeg'),
|
||||
'jpg' => array('image/jpeg', 'image/pjpeg'),
|
||||
'jpe' => array('image/jpeg', 'image/pjpeg'),
|
||||
'png' => array('image/png', 'image/x-png'),
|
||||
'tiff' => 'image/tiff',
|
||||
'tif' => 'image/tiff',
|
||||
'css' => 'text/css',
|
||||
'html' => 'text/html',
|
||||
'htm' => 'text/html',
|
||||
'shtml' => 'text/html',
|
||||
'txt' => 'text/plain',
|
||||
'text' => 'text/plain',
|
||||
'log' => array('text/plain', 'text/x-log'),
|
||||
'rtx' => 'text/richtext',
|
||||
'rtf' => 'text/rtf',
|
||||
'xml' => 'text/xml',
|
||||
'xsl' => 'text/xml',
|
||||
'mpeg' => 'video/mpeg',
|
||||
'mpg' => 'video/mpeg',
|
||||
'mpe' => 'video/mpeg',
|
||||
'qt' => 'video/quicktime',
|
||||
'mov' => 'video/quicktime',
|
||||
'avi' => 'video/x-msvideo',
|
||||
'movie' => 'video/x-sgi-movie',
|
||||
'doc' => 'application/msword',
|
||||
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'word' => array('application/msword', 'application/octet-stream'),
|
||||
'xl' => 'application/excel',
|
||||
'eml' => 'message/rfc822',
|
||||
'json' => array('application/json', 'text/json')
|
||||
);
|
||||
|
||||
|
||||
/* End of file mimes.php */
|
||||
/* Location: ./application/config/mimes.php */
|
@ -0,0 +1,17 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| Profiler Sections
|
||||
| -------------------------------------------------------------------------
|
||||
| This file lets you determine whether or not various sections of Profiler
|
||||
| data are displayed when the Profiler is enabled.
|
||||
| Please see the user guide for info:
|
||||
|
|
||||
| http://codeigniter.com/user_guide/general/profiling.html
|
||||
|
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* End of file profiler.php */
|
||||
/* Location: ./application/config/profiler.php */
|
@ -0,0 +1,50 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| URI ROUTING
|
||||
| -------------------------------------------------------------------------
|
||||
| This file lets you re-map URI requests to specific controller functions.
|
||||
|
|
||||
| Typically there is a one-to-one relationship between a URL string
|
||||
| and its corresponding controller class/method. The segments in a
|
||||
| URL normally follow this pattern:
|
||||
|
|
||||
| example.com/class/method/id/
|
||||
|
|
||||
| In some instances, however, you may want to remap this relationship
|
||||
| so that a different class/function is called than the one
|
||||
| corresponding to the URL.
|
||||
|
|
||||
| Please see the user guide for complete details:
|
||||
|
|
||||
| http://codeigniter.com/user_guide/general/routing.html
|
||||
|
|
||||
| -------------------------------------------------------------------------
|
||||
| RESERVED ROUTES
|
||||
| -------------------------------------------------------------------------
|
||||
|
|
||||
| There area two reserved routes:
|
||||
|
|
||||
| $route['default_controller'] = 'welcome';
|
||||
|
|
||||
| This route indicates which controller class should be loaded if the
|
||||
| URI contains no data. In the above example, the "welcome" class
|
||||
| would be loaded.
|
||||
|
|
||||
| $route['404_override'] = 'errors/page_missing';
|
||||
|
|
||||
| This route will tell the Router what URI segments to use if those provided
|
||||
| in the URL cannot be matched to a valid route.
|
||||
|
|
||||
*/
|
||||
|
||||
$route['default_controller'] = "welcome";
|
||||
$route['404_override'] = '';
|
||||
$route['country/(:num)'] = '/country/index/$1';
|
||||
$route['province/(:num)'] = '/province/index/$1';
|
||||
$route['city/(:num)'] = '/city/index/$1';
|
||||
$route['special/(:num)'] = '/special/index/$1';
|
||||
|
||||
|
||||
/* End of file routes.php */
|
||||
/* Location: ./application/config/routes.php */
|
@ -0,0 +1,66 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| SMILEYS
|
||||
| -------------------------------------------------------------------
|
||||
| This file contains an array of smileys for use with the emoticon helper.
|
||||
| Individual images can be used to replace multiple simileys. For example:
|
||||
| :-) and :) use the same image replacement.
|
||||
|
|
||||
| Please see user guide for more info:
|
||||
| http://codeigniter.com/user_guide/helpers/smiley_helper.html
|
||||
|
|
||||
*/
|
||||
|
||||
$smileys = array(
|
||||
|
||||
// smiley image name width height alt
|
||||
|
||||
':-)' => array('grin.gif', '19', '19', 'grin'),
|
||||
':lol:' => array('lol.gif', '19', '19', 'LOL'),
|
||||
':cheese:' => array('cheese.gif', '19', '19', 'cheese'),
|
||||
':)' => array('smile.gif', '19', '19', 'smile'),
|
||||
';-)' => array('wink.gif', '19', '19', 'wink'),
|
||||
';)' => array('wink.gif', '19', '19', 'wink'),
|
||||
':smirk:' => array('smirk.gif', '19', '19', 'smirk'),
|
||||
':roll:' => array('rolleyes.gif', '19', '19', 'rolleyes'),
|
||||
':-S' => array('confused.gif', '19', '19', 'confused'),
|
||||
':wow:' => array('surprise.gif', '19', '19', 'surprised'),
|
||||
':bug:' => array('bigsurprise.gif', '19', '19', 'big surprise'),
|
||||
':-P' => array('tongue_laugh.gif', '19', '19', 'tongue laugh'),
|
||||
'%-P' => array('tongue_rolleye.gif', '19', '19', 'tongue rolleye'),
|
||||
';-P' => array('tongue_wink.gif', '19', '19', 'tongue wink'),
|
||||
':P' => array('raspberry.gif', '19', '19', 'raspberry'),
|
||||
':blank:' => array('blank.gif', '19', '19', 'blank stare'),
|
||||
':long:' => array('longface.gif', '19', '19', 'long face'),
|
||||
':ohh:' => array('ohh.gif', '19', '19', 'ohh'),
|
||||
':grrr:' => array('grrr.gif', '19', '19', 'grrr'),
|
||||
':gulp:' => array('gulp.gif', '19', '19', 'gulp'),
|
||||
'8-/' => array('ohoh.gif', '19', '19', 'oh oh'),
|
||||
':down:' => array('downer.gif', '19', '19', 'downer'),
|
||||
':red:' => array('embarrassed.gif', '19', '19', 'red face'),
|
||||
':sick:' => array('sick.gif', '19', '19', 'sick'),
|
||||
':shut:' => array('shuteye.gif', '19', '19', 'shut eye'),
|
||||
':-/' => array('hmm.gif', '19', '19', 'hmmm'),
|
||||
'>:(' => array('mad.gif', '19', '19', 'mad'),
|
||||
':mad:' => array('mad.gif', '19', '19', 'mad'),
|
||||
'>:-(' => array('angry.gif', '19', '19', 'angry'),
|
||||
':angry:' => array('angry.gif', '19', '19', 'angry'),
|
||||
':zip:' => array('zip.gif', '19', '19', 'zipper'),
|
||||
':kiss:' => array('kiss.gif', '19', '19', 'kiss'),
|
||||
':ahhh:' => array('shock.gif', '19', '19', 'shock'),
|
||||
':coolsmile:' => array('shade_smile.gif', '19', '19', 'cool smile'),
|
||||
':coolsmirk:' => array('shade_smirk.gif', '19', '19', 'cool smirk'),
|
||||
':coolgrin:' => array('shade_grin.gif', '19', '19', 'cool grin'),
|
||||
':coolhmm:' => array('shade_hmm.gif', '19', '19', 'cool hmm'),
|
||||
':coolmad:' => array('shade_mad.gif', '19', '19', 'cool mad'),
|
||||
':coolcheese:' => array('shade_cheese.gif', '19', '19', 'cool cheese'),
|
||||
':vampire:' => array('vampire.gif', '19', '19', 'vampire'),
|
||||
':snake:' => array('snake.gif', '19', '19', 'snake'),
|
||||
':exclaim:' => array('exclaim.gif', '19', '19', 'excaim'),
|
||||
':question:' => array('question.gif', '19', '19', 'question') // no comma after last item
|
||||
|
||||
);
|
||||
|
||||
/* End of file smileys.php */
|
||||
/* Location: ./application/config/smileys.php */
|
@ -0,0 +1,178 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| USER AGENT TYPES
|
||||
| -------------------------------------------------------------------
|
||||
| This file contains four arrays of user agent data. It is used by the
|
||||
| User Agent Class to help identify browser, platform, robot, and
|
||||
| mobile device data. The array keys are used to identify the device
|
||||
| and the array values are used to set the actual name of the item.
|
||||
|
|
||||
*/
|
||||
|
||||
$platforms = array (
|
||||
'windows nt 6.0' => 'Windows Longhorn',
|
||||
'windows nt 5.2' => 'Windows 2003',
|
||||
'windows nt 5.0' => 'Windows 2000',
|
||||
'windows nt 5.1' => 'Windows XP',
|
||||
'windows nt 4.0' => 'Windows NT 4.0',
|
||||
'winnt4.0' => 'Windows NT 4.0',
|
||||
'winnt 4.0' => 'Windows NT',
|
||||
'winnt' => 'Windows NT',
|
||||
'windows 98' => 'Windows 98',
|
||||
'win98' => 'Windows 98',
|
||||
'windows 95' => 'Windows 95',
|
||||
'win95' => 'Windows 95',
|
||||
'windows' => 'Unknown Windows OS',
|
||||
'os x' => 'Mac OS X',
|
||||
'ppc mac' => 'Power PC Mac',
|
||||
'freebsd' => 'FreeBSD',
|
||||
'ppc' => 'Macintosh',
|
||||
'linux' => 'Linux',
|
||||
'debian' => 'Debian',
|
||||
'sunos' => 'Sun Solaris',
|
||||
'beos' => 'BeOS',
|
||||
'apachebench' => 'ApacheBench',
|
||||
'aix' => 'AIX',
|
||||
'irix' => 'Irix',
|
||||
'osf' => 'DEC OSF',
|
||||
'hp-ux' => 'HP-UX',
|
||||
'netbsd' => 'NetBSD',
|
||||
'bsdi' => 'BSDi',
|
||||
'openbsd' => 'OpenBSD',
|
||||
'gnu' => 'GNU/Linux',
|
||||
'unix' => 'Unknown Unix OS'
|
||||
);
|
||||
|
||||
|
||||
// The order of this array should NOT be changed. Many browsers return
|
||||
// multiple browser types so we want to identify the sub-type first.
|
||||
$browsers = array(
|
||||
'Flock' => 'Flock',
|
||||
'Chrome' => 'Chrome',
|
||||
'Opera' => 'Opera',
|
||||
'MSIE' => 'Internet Explorer',
|
||||
'Internet Explorer' => 'Internet Explorer',
|
||||
'Shiira' => 'Shiira',
|
||||
'Firefox' => 'Firefox',
|
||||
'Chimera' => 'Chimera',
|
||||
'Phoenix' => 'Phoenix',
|
||||
'Firebird' => 'Firebird',
|
||||
'Camino' => 'Camino',
|
||||
'Netscape' => 'Netscape',
|
||||
'OmniWeb' => 'OmniWeb',
|
||||
'Safari' => 'Safari',
|
||||
'Mozilla' => 'Mozilla',
|
||||
'Konqueror' => 'Konqueror',
|
||||
'icab' => 'iCab',
|
||||
'Lynx' => 'Lynx',
|
||||
'Links' => 'Links',
|
||||
'hotjava' => 'HotJava',
|
||||
'amaya' => 'Amaya',
|
||||
'IBrowse' => 'IBrowse'
|
||||
);
|
||||
|
||||
$mobiles = array(
|
||||
// legacy array, old values commented out
|
||||
'mobileexplorer' => 'Mobile Explorer',
|
||||
// 'openwave' => 'Open Wave',
|
||||
// 'opera mini' => 'Opera Mini',
|
||||
// 'operamini' => 'Opera Mini',
|
||||
// 'elaine' => 'Palm',
|
||||
'palmsource' => 'Palm',
|
||||
// 'digital paths' => 'Palm',
|
||||
// 'avantgo' => 'Avantgo',
|
||||
// 'xiino' => 'Xiino',
|
||||
'palmscape' => 'Palmscape',
|
||||
// 'nokia' => 'Nokia',
|
||||
// 'ericsson' => 'Ericsson',
|
||||
// 'blackberry' => 'BlackBerry',
|
||||
// 'motorola' => 'Motorola'
|
||||
|
||||
// Phones and Manufacturers
|
||||
'motorola' => "Motorola",
|
||||
'nokia' => "Nokia",
|
||||
'palm' => "Palm",
|
||||
'iphone' => "Apple iPhone",
|
||||
'ipad' => "iPad",
|
||||
'ipod' => "Apple iPod Touch",
|
||||
'sony' => "Sony Ericsson",
|
||||
'ericsson' => "Sony Ericsson",
|
||||
'blackberry' => "BlackBerry",
|
||||
'cocoon' => "O2 Cocoon",
|
||||
'blazer' => "Treo",
|
||||
'lg' => "LG",
|
||||
'amoi' => "Amoi",
|
||||
'xda' => "XDA",
|
||||
'mda' => "MDA",
|
||||
'vario' => "Vario",
|
||||
'htc' => "HTC",
|
||||
'samsung' => "Samsung",
|
||||
'sharp' => "Sharp",
|
||||
'sie-' => "Siemens",
|
||||
'alcatel' => "Alcatel",
|
||||
'benq' => "BenQ",
|
||||
'ipaq' => "HP iPaq",
|
||||
'mot-' => "Motorola",
|
||||
'playstation portable' => "PlayStation Portable",
|
||||
'hiptop' => "Danger Hiptop",
|
||||
'nec-' => "NEC",
|
||||
'panasonic' => "Panasonic",
|
||||
'philips' => "Philips",
|
||||
'sagem' => "Sagem",
|
||||
'sanyo' => "Sanyo",
|
||||
'spv' => "SPV",
|
||||
'zte' => "ZTE",
|
||||
'sendo' => "Sendo",
|
||||
|
||||
// Operating Systems
|
||||
'symbian' => "Symbian",
|
||||
'SymbianOS' => "SymbianOS",
|
||||
'elaine' => "Palm",
|
||||
'palm' => "Palm",
|
||||
'series60' => "Symbian S60",
|
||||
'windows ce' => "Windows CE",
|
||||
|
||||
// Browsers
|
||||
'obigo' => "Obigo",
|
||||
'netfront' => "Netfront Browser",
|
||||
'openwave' => "Openwave Browser",
|
||||
'mobilexplorer' => "Mobile Explorer",
|
||||
'operamini' => "Opera Mini",
|
||||
'opera mini' => "Opera Mini",
|
||||
|
||||
// Other
|
||||
'digital paths' => "Digital Paths",
|
||||
'avantgo' => "AvantGo",
|
||||
'xiino' => "Xiino",
|
||||
'novarra' => "Novarra Transcoder",
|
||||
'vodafone' => "Vodafone",
|
||||
'docomo' => "NTT DoCoMo",
|
||||
'o2' => "O2",
|
||||
|
||||
// Fallback
|
||||
'mobile' => "Generic Mobile",
|
||||
'wireless' => "Generic Mobile",
|
||||
'j2me' => "Generic Mobile",
|
||||
'midp' => "Generic Mobile",
|
||||
'cldc' => "Generic Mobile",
|
||||
'up.link' => "Generic Mobile",
|
||||
'up.browser' => "Generic Mobile",
|
||||
'smartphone' => "Generic Mobile",
|
||||
'cellphone' => "Generic Mobile"
|
||||
);
|
||||
|
||||
// There are hundreds of bots but these are the most common.
|
||||
$robots = array(
|
||||
'googlebot' => 'Googlebot',
|
||||
'msnbot' => 'MSNBot',
|
||||
'slurp' => 'Inktomi Slurp',
|
||||
'yahoo' => 'Yahoo',
|
||||
'askjeeves' => 'AskJeeves',
|
||||
'fastcrawler' => 'FastCrawler',
|
||||
'infoseek' => 'InfoSeek Robot 1.0',
|
||||
'lycos' => 'Lycos'
|
||||
);
|
||||
|
||||
/* End of file user_agents.php */
|
||||
/* Location: ./application/config/user_agents.php */
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Airline extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
//航空公司
|
||||
public function index()
|
||||
{
|
||||
$airline_id=1;
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('l', $airline_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', 'Airline', 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $airline_id, 'l', 0,
|
||||
'','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Airport extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
//机场
|
||||
public function index()
|
||||
{
|
||||
$airport_id=1;
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('a', $airport_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', 'Airport', 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $airport_id, 'a', 0,
|
||||
'','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,364 @@
|
||||
<?php
|
||||
|
||||
class Analytics extends CI_Controller
|
||||
{
|
||||
|
||||
private $view_data = array();
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
// $this->output->enable_profiler(TRUE);
|
||||
// 载入Model
|
||||
$this->load->model("Analytics_visits_model");
|
||||
$this->load->model("Analytics_pages_model");
|
||||
$this->load->model('Analytics_historys_model');
|
||||
|
||||
$this->load->model('Orders_model');
|
||||
|
||||
// 载入helper
|
||||
$this->load->helper('url');
|
||||
|
||||
// 所有该类页面都使用了菜单栏
|
||||
$this->_menu();
|
||||
}
|
||||
|
||||
// public function test(){
|
||||
// $this->load->model('Analytics_visits_model');
|
||||
// $this->load->model('Analytics_historys_model');
|
||||
// $this->load->model('Analytics_pages_model');
|
||||
// $this->Analytics_vists_model->test();
|
||||
// $this->Analytics_pages_model->test();
|
||||
// var_dump('OK');
|
||||
// }
|
||||
|
||||
public function index()
|
||||
{
|
||||
$page = $this->input->get('per_page');
|
||||
$site_code = $this->input->get('site_code');
|
||||
$author = $this->input->get('author');
|
||||
$order = $this->input->get('order');
|
||||
$url = $this->input->get('url');
|
||||
// 时间段
|
||||
$start = $this->input->get('start');
|
||||
if (strpos($start, '-') > 0)
|
||||
{
|
||||
$start = strtotime($start);
|
||||
}
|
||||
$end = $this->input->get('end');
|
||||
if (strpos($end, '-') > 0)
|
||||
{
|
||||
$end = strtotime($end);
|
||||
}
|
||||
// 获取订单最多的页面ID数组
|
||||
$rs = $this->Analytics_visits_model->get_pids_order_top($page, $site_code, $author, $start, $end);
|
||||
|
||||
if (!empty($rs))
|
||||
{
|
||||
// 数据存在的话继续查询
|
||||
// 输出数据
|
||||
$this->view_data['count'] = $rs->count;
|
||||
$this->view_data['count_all'] = $rs->count_all;
|
||||
// 获取页面列表
|
||||
$this->view_data['list'] = $this->Analytics_pages_model->get_by_ids($rs->page_ids, $site_code, $author, $order, $url);
|
||||
// var_dump($this->view_data['list'][0]);exit();
|
||||
|
||||
$this->view_data['cur_page'] = $page;
|
||||
|
||||
// 加载配置
|
||||
$sites_config = $this->config->item('site');
|
||||
$authors = array();
|
||||
foreach ($sites_config as $value)
|
||||
{
|
||||
$sites[] = $value['site_code'];
|
||||
$authors = array_merge($authors, $value['site_authors']);
|
||||
}
|
||||
$this->view_data['authors'] = $authors;
|
||||
$this->view_data['sites'] = $sites;
|
||||
|
||||
// 分页
|
||||
$page_url = site_url('analytics/index') . "?site_code=$site_code&start=$start&end=$end&author=$author&order=$order&url=$url";
|
||||
$this->view_data['pages'] = $this->_page($page_url, $this->view_data['count_all']);
|
||||
}
|
||||
// var_dump($rs);exit;
|
||||
// 参数传递
|
||||
$this->load->view('header', array('meta_title' => '统计分析'));
|
||||
|
||||
$this->load->view('analytics/index', $this->view_data);
|
||||
$this->load->view('footer');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单列表
|
||||
*/
|
||||
public function order()
|
||||
{
|
||||
$url = $this->input->get('url');
|
||||
$page = $this->Analytics_pages_model->get_one_page($url);
|
||||
|
||||
$this->view_data['page'] = $page;
|
||||
$this->view_data['list'] = '';
|
||||
if (!empty($page))
|
||||
{
|
||||
$this->view_data["list"] = $this->Analytics_visits_model->get_page_orders($page->p_id);
|
||||
}
|
||||
$this->load->view('header');
|
||||
$this->load->view('analytics/order', $this->view_data);
|
||||
$this->load->view('footer');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单信息
|
||||
* @param type $order_num
|
||||
*/
|
||||
public function order_detail($order_num = '')
|
||||
{
|
||||
if (!$order_num)
|
||||
{
|
||||
show_404();
|
||||
}
|
||||
|
||||
$detail = $this->Analytics_visits_model->get_order_detail($order_num);
|
||||
if ($detail === FALSE)
|
||||
{
|
||||
show_404();
|
||||
}
|
||||
|
||||
// 更多的信息
|
||||
// $this->output->enable_profiler(TRUE);
|
||||
$confirm_info = $this->Orders_model->get_detail_confirm($order_num);
|
||||
$this->view_data['confirm_info'] = $confirm_info;
|
||||
|
||||
$this->view_data['detail'] = $detail;
|
||||
|
||||
// 页面信息
|
||||
$this->view_data['page'] = $this->Analytics_pages_model->get_one($detail->v_first_page_id);
|
||||
|
||||
// 访问记录
|
||||
$this->view_data['history'] = $this->Analytics_historys_model->get_visit_history($detail->v_id);
|
||||
|
||||
$this->load->view('header');
|
||||
$this->load->view('analytics/order_detail', $this->view_data);
|
||||
$this->load->view('footer');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成统计代码
|
||||
*/
|
||||
public function code()
|
||||
{
|
||||
$sites_config = $this->config->item('site');
|
||||
foreach ($sites_config as $value)
|
||||
{
|
||||
$sites[] = $value['site_code'];
|
||||
}
|
||||
$this->view_data['sites'] = $sites;
|
||||
$this->view_data['cur_site'] = $this->input->get('site');
|
||||
|
||||
if (in_array($this->view_data['cur_site'], $this->view_data['sites']))
|
||||
{
|
||||
// 生成代码
|
||||
// $url = site_url();
|
||||
$url = 'http://i.chtcdn.com/info.php';
|
||||
$this->view_data['code'] = <<<EOF
|
||||
<script language="javascript">
|
||||
(function() {
|
||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
||||
ga.src = '{$url}/website_analytics?'+'site_code={$this->view_data['cur_site']}&page_title='+document.title+'&page_referer='+escape(document.referrer);
|
||||
var s = document.getElementsByTagName('script')[0];
|
||||
s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
</script>
|
||||
EOF;
|
||||
}
|
||||
$this->load->view('header');
|
||||
$this->load->view('analytics/code', $this->view_data);
|
||||
$this->load->view('footer');
|
||||
}
|
||||
|
||||
/**
|
||||
* 最近访客列表
|
||||
*/
|
||||
public function visit()
|
||||
{
|
||||
$page = $this->input->get('per_page');
|
||||
$page = $page ? $page : 0;
|
||||
$site_code = $this->input->get('site_code');
|
||||
$order_status = $this->input->get('order_status');
|
||||
// 时间段
|
||||
$start = intval(strtotime($this->input->get('start')));
|
||||
$end = intval(strtotime($this->input->get('end')));
|
||||
|
||||
// 获取访客列表
|
||||
$visits_list = $this->Analytics_visits_model->get_visits($page, $site_code, $start, $end, $order_status);
|
||||
if ($visits_list === FALSE || empty($visits_list))
|
||||
{
|
||||
// 居然乱码...
|
||||
header('content-type:text/html;charset=utf-8');
|
||||
show_error('数据不存在或查询数据过大(超过10W)');
|
||||
}
|
||||
|
||||
$this->view_data['list'] = $visits_list['list'];
|
||||
$this->view_data['count'] = $visits_list['count'];
|
||||
|
||||
$this->view_data['cur_site_code'] = $site_code;
|
||||
$this->view_data['cur_start'] = $start ? date('Y-m-d', $start) : '';
|
||||
$this->view_data['cur_end'] = $end ? date('Y-m-d', $end) : '';
|
||||
$this->view_data['cur_order_status'] = $order_status;
|
||||
$this->view_data['cur_page'] = $page;
|
||||
|
||||
// 加载配置
|
||||
$sites_config = $this->config->item('site');
|
||||
$authors = array();
|
||||
foreach ($sites_config as $value)
|
||||
{
|
||||
$sites[] = $value['site_code'];
|
||||
$authors = array_merge($authors, $value['site_authors']);
|
||||
}
|
||||
$this->view_data['authors'] = $authors;
|
||||
$this->view_data['sites'] = $sites;
|
||||
|
||||
// 分页
|
||||
$page_url = site_url('analytics/visit') . "?site_code=$site_code&start=$start&end=$end&order_status=$order_status";
|
||||
$this->view_data['pages'] = $this->_page($page_url, $visits_list['count']);
|
||||
|
||||
$this->load->view('header');
|
||||
$this->load->view('analytics/visit', $this->view_data);
|
||||
$this->load->view('footer');
|
||||
}
|
||||
|
||||
/**
|
||||
* 常见的退出界面
|
||||
*/
|
||||
public function leave()
|
||||
{
|
||||
$this->view_data['list'] = array();
|
||||
|
||||
$page_ids = $this->Analytics_visits_model->get_top_leave_pids();
|
||||
if ($page_ids !== FALSE)
|
||||
{
|
||||
$this->view_data['list'] = $this->Analytics_pages_model->get_by_ids($page_ids);
|
||||
}
|
||||
$this->load->view('header');
|
||||
$this->load->view('analytics/leave', $this->view_data);
|
||||
$this->load->view('footer');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示某个访客的访问历史
|
||||
* @param type $id
|
||||
*/
|
||||
public function history($id)
|
||||
{
|
||||
$id = intval($id);
|
||||
// 获取访客信息
|
||||
$visit = $this->Analytics_visits_model->get_visit($id);
|
||||
if ($visit == FALSE)
|
||||
{
|
||||
show_404();
|
||||
}
|
||||
|
||||
// 访问记录
|
||||
$history = $this->Analytics_historys_model->get_visit_history($id);
|
||||
|
||||
$this->view_data['visit'] = $visit;
|
||||
$this->view_data['history'] = $history;
|
||||
|
||||
$this->load->view('header');
|
||||
$this->load->view('analytics/history', $this->view_data);
|
||||
$this->load->view('footer');
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的统计
|
||||
*/
|
||||
public function mine()
|
||||
{
|
||||
$admin_info = $this->session->userdata('session_admin');
|
||||
$my_code = $admin_info['OPI_Code'];
|
||||
|
||||
$year = date("Y");
|
||||
$month = date("m");
|
||||
$day = date("d");
|
||||
|
||||
$data = array(
|
||||
'author' => $my_code,
|
||||
'count_order_day' => 0,
|
||||
'count_order_month' => 0,
|
||||
'count_order_year' => 0,
|
||||
'day_begin' => mktime(0, 0, 0, $month, $day, $year),
|
||||
'day_end' => mktime(0, 0, 0, $month, $day + 1, $year),
|
||||
'month_begin' => mktime(0, 0, 0, $month, 1, $year),
|
||||
'month_end' => mktime(0, 0, 0, $month + 1, 1, $year),
|
||||
'year_begin' => mktime(0, 0, 0, 1, 1, $year),
|
||||
'year_end' => mktime(0, 0, 0, 1, 1, $year + 1),
|
||||
);
|
||||
|
||||
$auhor_analytics = $this->Analytics_visits_model->get_auhor_analytics($my_code);
|
||||
|
||||
$data = array_merge($data, $auhor_analytics);
|
||||
$this->view_data = array_merge($this->view_data, $data);
|
||||
|
||||
$this->load->view('header');
|
||||
|
||||
$this->load->view('analytics/mine', $this->view_data);
|
||||
$this->load->view('footer');
|
||||
}
|
||||
|
||||
private function _menu()
|
||||
{
|
||||
$data['cur_site_code'] = $this->input->get('site_code');
|
||||
$data['cur_author'] = $this->input->get('author');
|
||||
$data['cur_order'] = $this->input->get('order');
|
||||
$data['cur_url'] = $this->input->get('url');
|
||||
$data['cur_start'] = $this->input->get('start');
|
||||
$data['cur_end'] = $this->input->get('end');
|
||||
|
||||
// 加载配置
|
||||
$sites_config = $this->config->item('site');
|
||||
$sites = array();
|
||||
$authors = array();
|
||||
if (!empty($sites_config))
|
||||
{
|
||||
foreach ($sites_config as $value)
|
||||
{
|
||||
$sites[] = $value['site_code'];
|
||||
$authors = array_merge($authors, $value['site_authors']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['authors'] = $authors;
|
||||
$data['sites'] = $sites;
|
||||
|
||||
$this->view_data['menu'] = $this->load->view('analytics/menu', $data, TRUE);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
* @param type $page_url
|
||||
* @param type $total_rows
|
||||
* @param type $per_page
|
||||
* @return type
|
||||
*/
|
||||
private function _page($page_url, $total_rows, $per_page = 50)
|
||||
{
|
||||
// 分页
|
||||
$this->load->library('pagination'); #加载分页的对象
|
||||
|
||||
$config['base_url'] = $page_url; #前后页链接
|
||||
$config['total_rows'] = $total_rows; #辅助函数的一个方法
|
||||
$config['per_page'] = $per_page;
|
||||
$config['page_query_string'] = TRUE;
|
||||
$config['anchor_class'] = "class='btn' ";
|
||||
$config['first_link'] = '第一页';
|
||||
$config['last_link'] = FALSE; // 由于最后的分页查询可能达到7-9s, 且查询意义不大, 隐藏分页last链接
|
||||
|
||||
$this->pagination->initialize($config);
|
||||
|
||||
return $this->pagination->create_links(); #丢到数组里面呆会渲染用
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
*
|
||||
* 模块机制类
|
||||
*
|
||||
*/
|
||||
class Apps extends CI_Controller
|
||||
{
|
||||
//重映射方法,系统函数
|
||||
public function _remap($app,$param)
|
||||
{
|
||||
//第三方应用存放目录
|
||||
$third_party = 'third_party';
|
||||
|
||||
//请求的应用、制器、方法
|
||||
$app_name = strtolower($app)!='index'?$app:'partners';
|
||||
$controller_name = isset($param[0])?strtolower($param[0]):'index';
|
||||
$action_name = isset($param[1])?strtolower($param[1]):'index';
|
||||
|
||||
//加载应用包
|
||||
|
||||
$app_path=APPPATH.$third_party."/".$app_name."/"; //存放模块的目录
|
||||
$view_cascade=TRUE; //允许加载模块内、外的视图
|
||||
$this->load->add_package_path($app_path,$view_cascade);
|
||||
|
||||
//加载控制器
|
||||
if ( ! file_exists($app_path.'controllers/'.$controller_name.'.php')) {
|
||||
echo 'Controller file is not exists!';
|
||||
return false;
|
||||
}
|
||||
require_once($app_path.'controllers/'.$controller_name.'.php');
|
||||
$controller_name = ucfirst($controller_name);
|
||||
|
||||
//实例化控制器并调用请求的方法
|
||||
if (class_exists($controller_name,false))
|
||||
{
|
||||
$controllerHandler = new $controller_name();
|
||||
if(method_exists($controllerHandler,$action_name)) {
|
||||
call_user_func_array(array($controllerHandler, $action_name), array_slice($param, 2));
|
||||
}else{
|
||||
echo 'Method is not exists!';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo 'Controller is not exists!';
|
||||
}
|
||||
|
||||
//停止加载应用包
|
||||
$this->load->remove_package_path($app_path);
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Citizen extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$citizen_id=1;
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('z', $citizen_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', 'Citizen Travel', 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $citizen_id, 'z', 0,
|
||||
'','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class City extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
public function index($city_id)
|
||||
{
|
||||
//查询不到城市信息则显示错误
|
||||
$data['city'] = $this->Area_model->get_city($city_id);
|
||||
if ($data['city'] == FALSE)
|
||||
{
|
||||
show_404();
|
||||
}
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('c', $city_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', $data['city']->CII2_Name, 'root', '', '', '', '', '', '', 0, 0, '', '',0,0, '', '', $city_id, 'c', 0, '','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Country extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
public function index($country_id=0)
|
||||
{
|
||||
//查询不到国家信息则显示错误
|
||||
$data['country'] = $this->Area_model->get_country($country_id);
|
||||
if ($data['country'] == FALSE)
|
||||
{
|
||||
show_404();
|
||||
}
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('n', $country_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', $data['country']->COI2_Country, 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $country_id, 'n', 0,
|
||||
'','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,167 @@
|
||||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Coupon extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Coupon_model');
|
||||
$this->load->library('pagination');
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
echo 'hello';
|
||||
exit;
|
||||
}
|
||||
|
||||
//生肖促销订单列表
|
||||
function zodiac($page=1)
|
||||
{
|
||||
$sumOrders = $this->Coupon_model->get_count('zodiac');
|
||||
$config['base_url'] = site_url('coupon/zodiac');
|
||||
$config['total_rows'] = $sumOrders;
|
||||
$config['per_page'] = 20;
|
||||
$config['num_links'] = 4;
|
||||
$config['first_link'] = '‹ First';
|
||||
$config['prev_link'] = '« Prev';
|
||||
$config['next_link'] = 'Next »';
|
||||
$config['last_link'] = 'Last ›';
|
||||
$config['use_page_numbers'] = TRUE;
|
||||
$this->pagination->initialize($config);
|
||||
|
||||
$data['menu'] = $this->menu();
|
||||
$data['coupon'] = $this->Coupon_model->getlist('zodiac',$page,20);
|
||||
$data['sumno'] = ($page-1) * 20; //页序号
|
||||
$data['sumOrders'] = $sumOrders; //订单总数
|
||||
//$data['used'] = $this->Coupon_model->get_count('used');
|
||||
//$data['invalid'] = $this->Coupon_model->get_count('invalid');
|
||||
$this->load->view('bootstrap/header', $data);
|
||||
$this->load->view('bootstrap/coupon');
|
||||
$this->load->view('bootstrap/footer');
|
||||
}
|
||||
|
||||
function lottery($page=1)
|
||||
{
|
||||
|
||||
$sumOrders = $this->Coupon_model->get_count('lottery');
|
||||
$config['base_url'] = site_url('coupon/lottery');
|
||||
$config['total_rows'] = $sumOrders;
|
||||
$config['per_page'] = 20;
|
||||
$config['num_links'] = 4;
|
||||
$config['first_link'] = '‹ First';
|
||||
$config['prev_link'] = '« Prev';
|
||||
$config['next_link'] = 'Next »';
|
||||
$config['last_link'] = 'Last ›';
|
||||
$config['use_page_numbers'] = TRUE;
|
||||
$this->pagination->initialize($config);
|
||||
|
||||
$data['menu'] = $this->menu();
|
||||
$data['lottery'] = $this->Coupon_model->getlist('lottery',$page,20);
|
||||
$data['sumno'] = ($page-1) * 20; //页序号
|
||||
$data['sumOrders'] = $sumOrders; //订单总数
|
||||
//$data['used'] = $this->Coupon_model->get_count('used');
|
||||
//$data['invalid'] = $this->Coupon_model->get_count('invalid');
|
||||
$this->load->view('bootstrap/header', $data);
|
||||
$this->load->view('bootstrap/lottery');
|
||||
$this->load->view('bootstrap/footer');
|
||||
}
|
||||
|
||||
//更新
|
||||
function doupdate()
|
||||
{
|
||||
$aid = $this->input->post('aid');
|
||||
$doact = $this->input->post('doact');
|
||||
$statu = $this->input->post('status');
|
||||
switch ($doact)
|
||||
{
|
||||
case 'isuse':
|
||||
$field='is_use';
|
||||
$this->Coupon_model->zodiac_updatestatu($aid,$statu,$field);
|
||||
echo 'ok';
|
||||
break;
|
||||
|
||||
case 'isvalid':
|
||||
$field='is_valid';
|
||||
$this->Coupon_model->zodiac_updatestatu($aid,$statu,$field);
|
||||
echo 'ok';
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$this->Coupon_model->zodiac_dodel($aid);
|
||||
echo 'ok';
|
||||
break;
|
||||
|
||||
default:
|
||||
echo 'error';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//搜索
|
||||
function search()
|
||||
{
|
||||
$kwd=$this->input->post('kwds');
|
||||
$data['kwds']=$kwd;
|
||||
$searchlist = $this->Coupon_model->get_zodiac_search($kwd);
|
||||
$data['coupon'] = $searchlist;
|
||||
$data['sumno'] = 0; //页序号
|
||||
$data['sumOrders'] = count($searchlist); //订单总数
|
||||
$this->load->view('bootstrap/header', $data);
|
||||
$this->load->view('bootstrap/coupon');
|
||||
$this->load->view('bootstrap/footer');
|
||||
}
|
||||
|
||||
public function menu()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'url' =>'coupon/zodiac',
|
||||
'name' =>'生肖促销'
|
||||
),
|
||||
array(
|
||||
'url' =>'coupon/lottery',
|
||||
'name' =>'转盘抽奖'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
//导出邮件列表
|
||||
function load_email_list($page=1)
|
||||
{
|
||||
$sumOrders = $this->Coupon_model->get_count('zodiac');
|
||||
$config['base_url'] = site_url('coupon/zodiac');
|
||||
$config['total_rows'] = $sumOrders;
|
||||
$config['per_page'] = 300;
|
||||
$config['num_links'] = 4;
|
||||
$config['first_link'] = '‹ First';
|
||||
$config['prev_link'] = '« Prev';
|
||||
$config['next_link'] = 'Next »';
|
||||
$config['last_link'] = 'Last ›';
|
||||
$config['use_page_numbers'] = TRUE;
|
||||
$this->pagination->initialize($config);
|
||||
|
||||
$data = $this->Coupon_model->getlist('zodiac',$page,300);
|
||||
$this->_excel($data);
|
||||
}
|
||||
|
||||
//导出数据到excel
|
||||
//$output要填充到excel的数据
|
||||
public function _excel($output=array()){
|
||||
header("Content-Type: application/vnd.ms-excel;");
|
||||
header("Content-Disposition:attachment;filename=".time().".cvs");
|
||||
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
|
||||
header('Expires:0');
|
||||
header('Pragma:public');
|
||||
$excel_str="";
|
||||
foreach ($output as $item) {
|
||||
$excel_str.=$item->useremail.",";//设置某一单元格的值
|
||||
$excel_str.="\n";//添加行结束符
|
||||
}
|
||||
//if($filetype==2) $excel_str=iconv('UTF-8','GB2312',$excel_str);//excel简体中文版使用gb2312编码
|
||||
echo "$excel_str";
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Embassy extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
//大使馆
|
||||
public function index()
|
||||
{
|
||||
$embassy_id=1;
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('y', $embassy_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', 'Embassy', 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $embassy_id, 'y', 0,
|
||||
'','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Encryption extends CI_Controller {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('mail_accounts_model');
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$data = array();
|
||||
//随机几次,让随机因子滚动一下
|
||||
$this->make_password(8);
|
||||
$this->make_password(12);
|
||||
$this->make_password(10);
|
||||
$data['password'] = $this->make_password(12);
|
||||
//$this->load->view('bootstrap/header' );
|
||||
|
||||
$show = $this->input->get('show');
|
||||
if ($show == 'true') {
|
||||
//$data['low_list'] = $this->mail_accounts_model->get_list();
|
||||
}
|
||||
$this->load->view('bootstrap/encryption', $data);
|
||||
//$this->load->view('bootstrap/footer');
|
||||
}
|
||||
|
||||
public function make_password($length = 8) {
|
||||
// 密码字符集,可任意添加你需要的字符
|
||||
$chars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
|
||||
't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
|
||||
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!',
|
||||
'@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_',
|
||||
'[', ']', '{', '}', '<', '>', '~', '`', '+', '=', ',',
|
||||
'.', ';', ':', '/', '?', '|');
|
||||
|
||||
// 在 $chars 中随机取 $length 个数组元素键名
|
||||
$keys = array_rand($chars, $length);
|
||||
|
||||
$password = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
// 将 $length 个数组元素连接成字符串
|
||||
$password .= $chars[$keys[$i]];
|
||||
}
|
||||
|
||||
return $password;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
*
|
||||
* FAQ
|
||||
*
|
||||
*/
|
||||
class Faq extends CI_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
$this->load->model('Import_adv_model');
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$link_id=1;
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('q', $link_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', 'FAQ', 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $link_id, 'q', 0,
|
||||
'','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* FAQ
|
||||
*
|
||||
*/
|
||||
public function import()
|
||||
{
|
||||
$site_code = $this->config->item('site_code');
|
||||
$site_lgc = $this->config->item('site_lgc');
|
||||
|
||||
//取出FAQ列表
|
||||
$data['faq'] = $this->Import_adv_model->get_faq($site_code, $site_lgc);
|
||||
|
||||
//取出FAQ的根节点的is_id
|
||||
$faq_root_isid = $this->Import_adv_model->get_faq_root_isid($site_code);
|
||||
|
||||
//取出所有FAQ类型
|
||||
$data['faq_type'] = array();
|
||||
$data['faq_type_en'] = array();
|
||||
foreach ($data['faq'] as $it)
|
||||
{
|
||||
$data['faq_type_en'][] = $it->SFC2_Byname;
|
||||
$data['faq_type'][] = $it->SFC2_Title;
|
||||
}
|
||||
$data['faq_type'] = array_unique($data['faq_type']);
|
||||
$data['faq_type_en'] = array_unique($data['faq_type_en']);
|
||||
|
||||
//插入根节点 -- 已完成 -- 注释掉
|
||||
/*
|
||||
foreach ($data['faq_type'] as $key=>$it)
|
||||
{
|
||||
//写url
|
||||
if (strtolower($site_code)=='jp' || strtolower($site_code)=='ru')
|
||||
{
|
||||
$url_m = '/feedback/'.$this->parseToUrlString($data['faq_type_en'][$key]).'/';
|
||||
}
|
||||
else
|
||||
{
|
||||
$url_m = '/feedback/'.$this->parseToUrlString($it).'/';
|
||||
}
|
||||
$this->InfoContents_model->add(
|
||||
$url_m,//$ic_url
|
||||
$it,//$ic_url_title
|
||||
'',//$ic_type
|
||||
$it,//$ic_title
|
||||
'',//$ic_content
|
||||
'',//$ic_summary
|
||||
'',//$ic_seo_title
|
||||
'',//$ic_seo_description
|
||||
'',//$ic_seo_keywords
|
||||
'',//$ic_show_bread_crumbs
|
||||
1,//$ic_status
|
||||
'',//$ic_template
|
||||
'',//$ic_photo
|
||||
'',//$ic_photo_width
|
||||
'',//$ic_photo_height
|
||||
'',//$ic_recommend_tours
|
||||
'',//$ic_recommend_packages
|
||||
'',//$ic_ht_area_id
|
||||
'q',//$ic_ht_area_type
|
||||
'',//$ic_ht_product_id
|
||||
'',//$ic_ht_product_type
|
||||
''//$ic_author
|
||||
);
|
||||
$this->InfoStructures_model->Add($faq_root_isid, $this->InfoContents_model->insert_id);
|
||||
$insert_is_id = $this->InfoStructures_model->insert_id;
|
||||
|
||||
//插入二级节点
|
||||
foreach ($data['faq'] as $it2)
|
||||
{
|
||||
if ($it2->SFC2_Title == $it)
|
||||
{
|
||||
//写url
|
||||
$it2->WSN_Title = mb_substr($it2->WSN_Title,0,240);
|
||||
$seo_des = strip_tags(mb_substr($it2->WSN_Memo,0,240).'...');
|
||||
$url_s = $url_m.$it2->WSN_ID.'.htm';
|
||||
$this->InfoContents_model->add(
|
||||
$url_s,//$ic_url
|
||||
$it2->WSN_Title,//$ic_url_title
|
||||
'',//$ic_type
|
||||
$it2->WSN_Title,//$ic_title
|
||||
$it2->WSN_Memo,//$ic_content
|
||||
'',//$ic_summary
|
||||
$it2->WSN_Title,//$ic_seo_title
|
||||
$seo_des,//$ic_seo_description
|
||||
'',//$ic_seo_keywords
|
||||
'',//$ic_show_bread_crumbs
|
||||
1,//$ic_status
|
||||
'',//$ic_template
|
||||
'',//$ic_photo
|
||||
'',//$ic_photo_width
|
||||
'',//$ic_photo_height
|
||||
'',//$ic_recommend_tours
|
||||
'',//$ic_recommend_packages
|
||||
'',//$ic_ht_area_id
|
||||
'q',//$ic_ht_area_type
|
||||
'',//$ic_ht_product_id
|
||||
'',//$ic_ht_product_type
|
||||
''//$ic_author
|
||||
);
|
||||
$this->InfoStructures_model->Add($insert_is_id, $this->InfoContents_model->insert_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
$this->rp($data['faq_type']);
|
||||
$this->rp($data['faq_type_en']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 打印测试
|
||||
*
|
||||
*/
|
||||
private function rp($array)
|
||||
{
|
||||
echo('<pre>'.print_r($array, true).'</pre>');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 字符串转成URL形式.
|
||||
*
|
||||
* @param $str String
|
||||
* @return String
|
||||
*/
|
||||
function parseToUrlString($str)
|
||||
{
|
||||
return mb_strtolower(trim(str_replace(" ", "-", $str)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Festival extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
//节庆信息
|
||||
public function index()
|
||||
{
|
||||
$festival_id=1;
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('f', $festival_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', 'Festival', 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $festival_id, 'f', 0,
|
||||
'','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Groupon extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
//团购信息
|
||||
public function index()
|
||||
{
|
||||
$groupon_id=1;
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('g', $groupon_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', 'Groupon', 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $groupon_id, 'g', 0,
|
||||
'','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Import extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Import_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
//@set_time_limit(0);
|
||||
ini_set('max_execution_time', '0');
|
||||
// $this->Import_model->import_from_other_database(69690,63564);
|
||||
//$this->Import_model->import_clear();
|
||||
//$this->Import_model->import_info();
|
||||
//$this->Import_model->import_xxoo();
|
||||
//$this->Import_model->update_root();
|
||||
/*$data = $this->Import_model->import_test();
|
||||
foreach ($data as $item)
|
||||
{
|
||||
for ($i = 0; $i <= $item->is_level; $i++)
|
||||
{
|
||||
echo ' ';
|
||||
}
|
||||
echo $item->ic_url_title . '<br/>';
|
||||
}*/
|
||||
}
|
||||
|
||||
public function clear_site(){
|
||||
$this->Import_model->import_clear_site();echo 'clear_site';
|
||||
}
|
||||
|
||||
public function reset_path()
|
||||
{
|
||||
@set_time_limit(0);
|
||||
return false;
|
||||
$this->Import_model->reset_all_path();
|
||||
}
|
||||
|
||||
public function to_sqlite()
|
||||
{
|
||||
$this->load->driver('cache', array('adapter' => 'file', 'backup' => 'file'));
|
||||
$this->HT = $this->load->database('HT', TRUE);
|
||||
$sql_array = array();
|
||||
$sql_ht = "SELECT ic.ic_id, \n"
|
||||
. " ic.ic_url, \n"
|
||||
. " ic.ic_url_title, \n"
|
||||
. " ic.ic_type, \n"
|
||||
. " ic.ic_title, \n"
|
||||
. " ic.ic_content, \n"
|
||||
. " ic.ic_summary, \n"
|
||||
. " ic.ic_seo_title, \n"
|
||||
. " ic.ic_seo_description, \n"
|
||||
. " ic.ic_seo_keywords, \n"
|
||||
. " ic.ic_show_bread_crumbs, \n"
|
||||
. " ic.ic_status, \n"
|
||||
. " ic.ic_template, \n"
|
||||
. " ic.ic_photo, \n"
|
||||
. " ic.ic_photo_width, \n"
|
||||
. " ic.ic_photo_height, \n"
|
||||
. " ic.ic_sitecode, \n"
|
||||
. " ic.ic_recommend_tours, \n"
|
||||
. " ic.ic_recommend_packages, \n"
|
||||
. " ic.ic_datetime, \n"
|
||||
. " ic.ic_ht_area_id, \n"
|
||||
. " ic.ic_ht_area_type, \n"
|
||||
. " ic.ic_ht_product_id, \n"
|
||||
. " ic.ic_ht_product_type, \n"
|
||||
. " is1.is_id, \n"
|
||||
. " is1.is_parent_id, \n"
|
||||
. " is1.is_path, \n"
|
||||
. " is1.is_level, \n"
|
||||
. " is1.is_sort, \n"
|
||||
. " is1.is_sitecode, \n"
|
||||
. " is1.is_datetime, \n"
|
||||
. " is1.is_ic_id \n"
|
||||
. "FROM infoContents ic \n"
|
||||
. " INNER JOIN infoStructures is1 ON is1.is_ic_id = ic.ic_id \n"
|
||||
. " AND is1.is_sitecode = 'cht' \n"
|
||||
. "WHERE ic.ic_ht_area_type = 'c' \n"
|
||||
. " AND ic.ic_ht_area_id IN (177, 54, 1, 3, 7)";
|
||||
$sql_ht_query = $this->HT->query($sql_ht);
|
||||
foreach ($sql_ht_query->result() as $item)
|
||||
{
|
||||
$sql_content = "INSERT INTO information \n"
|
||||
. " ( \n"
|
||||
. " ic_id, ic_url_title, ic_type,ic_content, ic_title, \n"
|
||||
. " ic_show_bread_crumbs,ic_status, ic_template,ic_photo, ic_photo_width, \n"
|
||||
. " ic_photo_height,ic_datetime,ic_ht_area_id, ic_ht_area_type, \n"
|
||||
. " is_id, is_parent_id, is_path, is_level, is_sort \n"
|
||||
. " ) \n"
|
||||
. "VALUES \n"
|
||||
. " ( \n"
|
||||
. $this->HT->escape($item->ic_id) . ' , '
|
||||
. $this->HT->escape($item->ic_url_title) . ' , '
|
||||
. $this->HT->escape($item->ic_type) . ' , '
|
||||
. $this->HT->escape($item->ic_content) . ' , '
|
||||
. $this->HT->escape($item->ic_title) . ' , '
|
||||
. $this->HT->escape($item->ic_show_bread_crumbs) . ' , '
|
||||
. $this->HT->escape($item->ic_status) . ' , '
|
||||
. $this->HT->escape($item->ic_template) . ' , '
|
||||
. $this->HT->escape($item->ic_photo) . ' , '
|
||||
. $this->HT->escape($item->ic_photo_width) . ' , '
|
||||
. $this->HT->escape($item->ic_photo_height) . ' , '
|
||||
. $this->HT->escape($item->ic_datetime) . ' , '
|
||||
. $this->HT->escape($item->ic_ht_area_id) . ' , '
|
||||
. $this->HT->escape($item->ic_ht_area_type) . ' , '
|
||||
. $this->HT->escape($item->is_id) . ' , '
|
||||
. $this->HT->escape($item->is_parent_id) . ' , '
|
||||
. $this->HT->escape($item->is_path) . ' , '
|
||||
. $this->HT->escape($item->is_level) . ' , '
|
||||
. $this->HT->escape($item->is_sort)
|
||||
. " );";
|
||||
$sql_array[] = $sql_content;
|
||||
// echo $sql_content.';';
|
||||
//$this->cache->save(md5($item->ic_id), $item->ic_content, 60 * 60 * 24 * 30);
|
||||
}
|
||||
file_put_contents('import.sql', implode("\n", $sql_array));
|
||||
//print_r($sql_array);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
*
|
||||
* 数据导入
|
||||
*
|
||||
* 功能:
|
||||
* 1.根据文件目录导入信息
|
||||
*
|
||||
*/
|
||||
class Import_adv extends CI_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
$this->load->model('Import_adv_model');
|
||||
$this->output->enable_profiler(TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* index
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//专题根节点
|
||||
echo('index');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* FAQ
|
||||
*
|
||||
*/
|
||||
public function faq($site_code='jp', $site_lgc='3')
|
||||
{
|
||||
//取出FAQ列表
|
||||
$data['faq'] = $this->Import_adv_model->get_faq($site_code, $site_lgc);
|
||||
|
||||
//取出FAQ的根节点的is_id
|
||||
$faq_root_isid = $this->Import_adv_model->get_faq_root_isid($site_code);
|
||||
|
||||
//取出所有FAQ类型
|
||||
$data['faq_type'] = array();
|
||||
foreach ($data['faq'] as $it)
|
||||
{
|
||||
$data['faq_type'][] = $it->SFC2_Title;
|
||||
}
|
||||
$data['faq_type'] = array_unique($data['faq_type']);
|
||||
|
||||
//插入根节点
|
||||
$this->InfoContents_model->add('','');
|
||||
|
||||
$this->rp($data['faq_type']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 打印测试
|
||||
*
|
||||
*/
|
||||
private function rp($array)
|
||||
{
|
||||
echo('<pre>'.print_r($array, true).'</pre>');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// end of Import_adv
|
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Look_order extends CI_Controller {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
//$this->permission->is_admin();
|
||||
// $this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Orders_model');
|
||||
$this->load->model('Logs_model');
|
||||
}
|
||||
|
||||
//订单情况
|
||||
public function index() {
|
||||
//$data['order_list'] = $this->Orders_model->all();
|
||||
$data = array();
|
||||
$data['start_date'] = $this->input->post('order_startdate');
|
||||
$data['end_date'] = $this->input->post('order_enddate');
|
||||
if (empty($data['start_date']) || empty($data['end_date'])) {
|
||||
$data['start_date'] = date('Y-m-d', time());
|
||||
$data['end_date'] = date('Y-m-d', strtotime('+1 day'));
|
||||
} else {
|
||||
$data['order_list'] = $this->Orders_model->get_test_order($data['start_date'], $data['end_date']);
|
||||
}
|
||||
|
||||
$this->load->view('bootstrap/header', $data);
|
||||
$this->load->view('bootstrap/order_list');
|
||||
$this->load->view('bootstrap/footer');
|
||||
}
|
||||
|
||||
//显示订单数量,如果大于阈值就显示错误
|
||||
public function status() {
|
||||
$data = array();
|
||||
$data['tour_count'] = $this->Orders_model->tour_count();
|
||||
if ($data['tour_count'] >= 550) {
|
||||
$this->output->set_status_header(500);
|
||||
}
|
||||
$data['insert_id']=$this->Logs_model->write_test();
|
||||
if (empty($data['insert_id'])) {
|
||||
$this->output->set_status_header(500);
|
||||
}
|
||||
$this->load->view('welcome_message', $data);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class News extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
//新闻
|
||||
public function index()
|
||||
{
|
||||
$news_id=1;
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('s', $news_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', 'News', 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $news_id, 's', 0,
|
||||
'','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Payment extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data=array();
|
||||
if ($this->input->post('price')) {
|
||||
$data['payurl']='
|
||||
<a href="https://www.chinahighlightstravel.com/payment/payment-center.asp?'.
|
||||
'Site_Language=en_us&'.
|
||||
'Site_CurrencyType=USD&'.
|
||||
'Site_ACD=100-200-300&'.
|
||||
'Site_OnlyPaymentType=0-1&'.
|
||||
'Order_ID=&'.
|
||||
'Order_TotalCost='.trim($this->input->post('price')).'&'.
|
||||
'Order_Name='.urlencode($this->input->post('description')).'&'.
|
||||
'Order_PaymentType=Motopay&'.
|
||||
'ToEmail=davidyang@chinahighlights.net">'.
|
||||
'<img border="0" alt="Pay now" src="http://www.chinahighlights.com/pic/pay-button.png" width="354" height="85" />'.
|
||||
'</a>';
|
||||
}
|
||||
$this->load->view('bootstrap/header',$data);
|
||||
$this->load->view('bootstrap/payment');
|
||||
$this->load->view('bootstrap/footer');
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
<?php // 代码各服务器已经同步 2016.06.01 ycc ?>
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Product extends CI_Controller {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
//产品管理
|
||||
public function index() {
|
||||
$product_id = 1;
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('pd', $product_id);
|
||||
if ($rootStructure == FALSE) {
|
||||
$this->InfoContents_model->Add('', 'Product', 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $product_id, 'pd', 0, '', '');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
} else {
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Province extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
public function index($province_id=0)
|
||||
{
|
||||
$this->load->library('Accesscheck');
|
||||
$this->accesscheck->check_access();
|
||||
//查询不到省份信息则显示错误
|
||||
$data['province'] = $this->Area_model->get_province($province_id);
|
||||
if ($data['province'] == FALSE)
|
||||
{
|
||||
show_404();
|
||||
}
|
||||
|
||||
$data['countryList'] = $this->Area_model->get_country_list();
|
||||
$data['cityList'] = $this->Area_model->get_city_list($province_id);
|
||||
$data['city_list'] = $this->Area_model->get_municipalities_list();
|
||||
$data['provinceList'] = $this->Area_model->get_province_list();
|
||||
$this->load->view('bootstrap/header', $data);
|
||||
$this->load->view('bootstrap/welcome');
|
||||
$this->load->view('bootstrap/footer');
|
||||
}
|
||||
|
||||
public function edit($province_id=0)
|
||||
{
|
||||
//查询不到省份信息则显示错误
|
||||
$data['province'] = $this->Area_model->get_province($province_id);
|
||||
if ($data['province'] == FALSE)
|
||||
{
|
||||
show_404();
|
||||
}
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('p', $province_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', $data['province']->PRI2_Name, 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $province_id, 'p', 0,
|
||||
'','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Railway extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
//火车站信息
|
||||
public function index()
|
||||
{
|
||||
$railway_id=1;
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('r', $railway_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', 'railway', 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $railway_id, 'r', 0,
|
||||
'','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Seo extends CI_Controller {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
$this->load->model('InfoSEOs_model');
|
||||
$this->load->library('Accesscheck');
|
||||
$this->accesscheck->check_access();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$data = array();
|
||||
$data['seo_list'] = $this->InfoSEOs_model->all();
|
||||
$this->load->view('bootstrap3/header', $data);
|
||||
$this->load->view('bootstrap3/seo');
|
||||
$this->load->view('bootstrap3/footer');
|
||||
}
|
||||
|
||||
public function search() {
|
||||
$seo_url = $this->input->post('url_keyword');
|
||||
$data['url_list'] = $this->InfoSEOs_model->search($seo_url);
|
||||
$url_list_view = $this->load->view('seo_select_url', $data, true);
|
||||
$data = array();
|
||||
$data[] = array('name' => 'ok', 'value' => $url_list_view);
|
||||
echo json_encode($data);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function detail($seo_id = FALSE) {
|
||||
$data = array();
|
||||
if (!empty($seo_id)) {
|
||||
$data['seo_detail'] = $this->InfoSEOs_model->get_detail($seo_id);
|
||||
}
|
||||
$data['seo_list'] = $this->InfoSEOs_model->all();
|
||||
|
||||
$this->load->view('bootstrap3/header', $data);
|
||||
$this->load->view('bootstrap3/seo');
|
||||
$this->load->view('bootstrap3/footer');
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$this->InfoSEOs_model->add('新的SEO信息', '//新的SEO信息', '', '', '', '');
|
||||
redirect(site_url('seo/detail/' . $this->InfoSEOs_model->insert_id));
|
||||
}
|
||||
|
||||
public function edit_save() {
|
||||
$this->form_validation->set_rules('seo_url', 'lang:seo_url', 'callback_seo_url_check|required');
|
||||
$this->form_validation->set_rules('seo_title', 'lang:ic_seo_title', 'required');
|
||||
$this->form_validation->set_rules('seo_h1', 'lang:seo_h1', 'required|max_length[50]');
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$data = array();
|
||||
foreach ($this->form_validation->_error_array as $key => $value) {
|
||||
$data[] = array('name' => $key, 'value' => $value);
|
||||
}
|
||||
echo json_encode($data);
|
||||
} else {
|
||||
$seo_detail = $this->InfoSEOs_model->get_detail($this->input->post('seo_id'));
|
||||
|
||||
if ($seo_detail) {
|
||||
$this->InfoSEOs_model->update($this->input->post('seo_id'), $this->input->post('seo_h1'), $this->input->post('seo_url'), $this->input->post('seo_title'), $this->input->post('seo_keywords'), $this->input->post('seo_description'), $this->input->post('seo_summary'));
|
||||
} else {
|
||||
$this->InfoSEOs_model->add($this->input->post('seo_h1'), $this->input->post('seo_url'), $this->input->post('seo_title'), $this->input->post('seo_keywords'), $this->input->post('seo_description'), $this->input->post('seo_summary'));
|
||||
}
|
||||
$data[] = array('name' => 'ok', 'value' => $this->lang->line('seo_save_success'));
|
||||
echo json_encode($data);
|
||||
}
|
||||
}
|
||||
|
||||
//URL重复检测
|
||||
public function seo_url_check($url) {
|
||||
$seo_id = $this->input->post('seo_id');
|
||||
if ($this->InfoSEOs_model->url_check($seo_id, $url)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($seo_id) {
|
||||
if (!empty($seo_id)) {
|
||||
$detail_seo = $this->InfoSEOs_model->get_detail($seo_id);
|
||||
if ($detail_seo) {
|
||||
$this->InfoSEOs_model->delete($seo_id);
|
||||
}
|
||||
}
|
||||
redirect(site_url('seo'));
|
||||
//想办法做提示
|
||||
// $data[] = array('name' => 'ok_go', 'value' => site_url('seo'));
|
||||
// echo json_encode($data);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Setting extends CI_Controller {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoMetas_model');
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$data = array();
|
||||
$data['active'] = 'home';
|
||||
$data['setting_body'] = '各种系统选项的设置,请选择左侧栏目';
|
||||
$this->load->view('bootstrap3/header', $data);
|
||||
$this->load->view('bootstrap3/setting');
|
||||
$this->load->view('bootstrap3/footer');
|
||||
}
|
||||
|
||||
public function website_nav() {
|
||||
$data = array();
|
||||
$data['active'] = 'website_nav';
|
||||
$data['nav_list'] = $this->InfoMetas_model->get_list(0, 'setting_website_nav_' . strtolower($this->config->item('site_code')));
|
||||
$data['setting_body'] = $this->load->view('bootstrap3/setting_website_nav', $data, true);
|
||||
$this->load->view('bootstrap3/header', $data);
|
||||
$this->load->view('bootstrap3/setting');
|
||||
$this->load->view('bootstrap3/footer');
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$im_ic_id = $this->input->post('im_ic_id');
|
||||
$im_key = $this->input->post('im_key');
|
||||
$im_value = $this->input->post('im_value');
|
||||
$return_url = $this->input->post('return_url');
|
||||
if (!empty($im_key) && !empty($im_value)) {
|
||||
$this->InfoMetas_model->add($im_ic_id, $im_key, $im_value);
|
||||
if (!empty($return_url)) {
|
||||
$data[] = array('name' => 'ok_go', 'value' => $return_url);
|
||||
} else {
|
||||
$data[] = array('name' => 'ok', 'value' => '添加成功!');
|
||||
}
|
||||
} else {
|
||||
$data[] = array('name' => 'no', 'value' => '添加失败!');
|
||||
}
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
public function save() {
|
||||
$im_id = $this->input->post('im_id');
|
||||
$im_value = $this->input->post('im_value');
|
||||
if (!empty($im_id) && !empty($im_value)) {
|
||||
$this->InfoMetas_model->update_by_id($im_id, $im_value);
|
||||
$data[] = array('name' => 'ok', 'value' => '保存成功!');
|
||||
} else {
|
||||
$data[] = array('name' => 'no', 'value' => '保存失败!');
|
||||
}
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$im_id = $this->input->post('im_id');
|
||||
$return_url = $this->input->post('return_url');
|
||||
if (!empty($im_id)) {
|
||||
$this->InfoMetas_model->delete_by_id($im_id);
|
||||
if (!empty($return_url)) {
|
||||
$data[] = array('name' => 'ok_go', 'value' => $return_url);
|
||||
} else {
|
||||
$data[] = array('name' => 'ok', 'value' => '删除成功!');
|
||||
}
|
||||
} else {
|
||||
$data[] = array('name' => 'no', 'value' => '保存失败!');
|
||||
}
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Sitemap extends CI_Controller {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('Coupon_model');
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$this->permission->is_admin();
|
||||
$this->create($this->config->item('site_url'));
|
||||
}
|
||||
|
||||
public function save($site_code) {
|
||||
$site_array = $this->config->item('site');
|
||||
$site = $site_array[$site_code];
|
||||
$site_url = $site['site_url'];
|
||||
$sitemap_name = $site['site_sitemap'];
|
||||
if (!empty($sitemap_name)) {
|
||||
$this->create($site_url, $sitemap_name);
|
||||
} else {
|
||||
echo 'no set sitemap name';
|
||||
}
|
||||
}
|
||||
|
||||
public function create($site_url, $site_sitemap = false) {
|
||||
@set_time_limit(0);
|
||||
$data = array();
|
||||
$sitemap_string = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> ';
|
||||
$data['lastEditList'] = $this->Information_model->get_last_edit_list(false);
|
||||
foreach ($data['lastEditList'] as $item) {
|
||||
if ($item->ic_status == 1 && $item->ic_url != '' && strlen($item->ic_content)>50 ) {
|
||||
$sitemap_string.='<url><loc>' . $site_url . $item->ic_url . '</loc><lastmod>' . date('c', strtotime($item->ic_datetime)) . '</lastmod></url>';
|
||||
}
|
||||
}
|
||||
$sitemap_string.='</urlset> ';
|
||||
|
||||
if ($site_sitemap) {
|
||||
$this->load->helper('file');
|
||||
if (!write_file($site_sitemap, $sitemap_string)) {
|
||||
echo 'Unable to write the file';
|
||||
} else {
|
||||
echo 'File written!';
|
||||
}
|
||||
} else {
|
||||
$this->load->helper('download');
|
||||
force_download('sitemap.xml', $sitemap_string);
|
||||
}
|
||||
//echo $sitemap_string;die();
|
||||
// $this->load->view('bootstrap/header', $data);
|
||||
//$this->load->view('bootstrap/sitemap');
|
||||
// $this->load->view('bootstrap/footer');
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Special extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$special_id=1;
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('t', $special_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', 'special area', 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $special_id, 't', 0,
|
||||
'','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
*
|
||||
* 模块机制类
|
||||
*
|
||||
*/
|
||||
class Thirdparty extends CI_Controller {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
}
|
||||
|
||||
/*public function action()
|
||||
{
|
||||
$third_party = 'third_party';
|
||||
$segment_array = $this->uri->segment_array();
|
||||
$module_key = array_search('thirdparty',$segment_array);
|
||||
$segment_count = count($segment_array);
|
||||
//组装传递参数
|
||||
$parameter = array();
|
||||
for ($i=6; $i <= $segment_count; $i++) {
|
||||
$parameter[]=$this->uri->segment($i);
|
||||
}
|
||||
//获取模块名
|
||||
$module_name = $this->uri->segment(($module_key+2));
|
||||
if (!$module_name) {
|
||||
send_404($this);
|
||||
return false;
|
||||
}
|
||||
//模块控制器名
|
||||
$controller_name = strtolower($this->uri->segment(($module_key+3), 'index'));
|
||||
//模块控制器调用的方法名
|
||||
$action_name = $this->uri->segment(($module_key+4), 'index');
|
||||
|
||||
//加载指定模块(独立应用)
|
||||
$module_path=APPPATH.$third_party."/".$module_name; //存放模块的目录
|
||||
$view_cascade=TRUE; //允许加载模块内、外的视图
|
||||
$this->load->add_package_path($module_path."/",$view_cascade);
|
||||
|
||||
//加载指定的模块控制器文件
|
||||
if ( ! file_exists($module_path.'/controllers/'.$controller_name.'.php')) {
|
||||
return false;
|
||||
}
|
||||
require_once($module_path.'/controllers/'.$controller_name.'.php');
|
||||
$controller_name = ucfirst($controller_name);
|
||||
|
||||
//实例化指定模块de控制器
|
||||
if (!class_exists($controller_name,false)) {
|
||||
return false;
|
||||
}
|
||||
$ctrl_object = new $controller_name();
|
||||
|
||||
//调用指定模块的控制器方法,并传递参数
|
||||
if (!method_exists($ctrl_object,$action_name)) {
|
||||
return false;
|
||||
}
|
||||
call_user_func_array(array($ctrl_object, $action_name), $parameter);
|
||||
|
||||
//停止加载该模块
|
||||
$this->load->remove_package_path($module_path."/");
|
||||
}*/
|
||||
|
||||
public function _remap($app,$param)
|
||||
{
|
||||
//第三方应用存放目录
|
||||
$third_party = 'third_party';
|
||||
|
||||
//请求的应用、制器、方法
|
||||
$app_name = strtolower($app);
|
||||
$controller_name = isset($param[0])?strtolower($param[0]):'index';
|
||||
$action_name = isset($param[1])?strtolower($param[1]):'index';
|
||||
|
||||
//加载应用包
|
||||
$app_path=APPPATH.$third_party."/".$app_name."/"; //存放模块的目录
|
||||
$view_cascade=TRUE; //允许加载模块内、外的视图
|
||||
$this->load->add_package_path($app_path,$view_cascade);
|
||||
|
||||
//加载控制器
|
||||
if ( ! file_exists($app_path.'controllers/'.$controller_name.'.php')) {
|
||||
echo 'Controller file is not exists!';
|
||||
return false;
|
||||
}
|
||||
require_once($app_path.'controllers/'.$controller_name.'.php');
|
||||
$controller_name = ucfirst($controller_name);
|
||||
|
||||
//实例化控制器并调用请求的方法
|
||||
if (class_exists($controller_name,false))
|
||||
{
|
||||
$controllerHandler = new $controller_name();
|
||||
if(method_exists($controllerHandler,$action_name)) {
|
||||
call_user_func_array(array($controllerHandler, $action_name), array_slice($param, 2));
|
||||
}else{
|
||||
echo 'Method is not exists!';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo 'Controller is not exists!';
|
||||
}
|
||||
|
||||
//停止加载应用包
|
||||
$this->load->remove_package_path($app_path);
|
||||
}
|
||||
}
|
@ -0,0 +1,420 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Translate extends CI_Controller
|
||||
{
|
||||
var $per_page;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Translate_model');
|
||||
$this->per_page = 30;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->library('pagination');
|
||||
$recordcount = 0;
|
||||
$page = $this->uri->segment(3);
|
||||
$opiid =0;
|
||||
$userid =0;
|
||||
|
||||
if($this->input->post('Submit')){
|
||||
$key = $this->input->post('search');
|
||||
} else {
|
||||
$key = unserialize($this->input->cookie('search'));
|
||||
}
|
||||
$cookie = array(
|
||||
'name' => 'search',
|
||||
'value' => serialize($key),
|
||||
'expire' => '86500',
|
||||
'path' => '/'
|
||||
);
|
||||
$searchdata=$key;
|
||||
if($searchdata['tli_userid']=='')unset($searchdata['tli_userid']);
|
||||
if($searchdata['tli_opi_sn']=='')unset($searchdata['tli_opi_sn']);
|
||||
if($searchdata['tli_title']=='')unset($searchdata['tli_title']);
|
||||
if($searchdata['tli_checktime_f']==''|| !$this->is_date($searchdata['tli_checktime_f']) )unset($searchdata['tli_checktime_f']);
|
||||
if($searchdata['tli_checktime_t']==''|| !$this->is_date($searchdata['tli_checktime_t']) )unset($searchdata['tli_checktime_t']);
|
||||
|
||||
$this->input->set_cookie($cookie);
|
||||
$data['translateList'] = $this->Translate_model->getList($searchdata,$opiid,$userid,$searchdata['tli_status'],$recordcount,$page,$this->per_page);
|
||||
$config['base_url'] = site_url("translate/listall/");
|
||||
$config['total_rows'] = $recordcount;
|
||||
$config['per_page'] = $this->per_page;
|
||||
$config['uri_segment'] = 3;
|
||||
$this->pagination->initialize($config);
|
||||
|
||||
$data['userList'] = $this->Translate_model->getuserList();
|
||||
$data['OpiList'] = $this->Translate_model->getOpiList();
|
||||
$data['search'] = $key;
|
||||
$this->load->view('header',$data);
|
||||
$this->load->view('translate');
|
||||
$this->load->view('footer');
|
||||
|
||||
}
|
||||
|
||||
public function is_date($d){
|
||||
// date formate is 01/04/2012
|
||||
// or else return false
|
||||
if (preg_match ("/^\d{2}\/\d{2}\/\d{4}$/i",$d)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function publication($tid=0){
|
||||
$this->load->helper('date');
|
||||
if($this->input->post('submit')){
|
||||
$info = $this->input->post('info');
|
||||
$msg = '';$ispass = false;
|
||||
/*
|
||||
if(strlen($info['tli_content'])<10){
|
||||
$msg = '<div>翻译内容不能为空.</div>';
|
||||
$ispass = true;
|
||||
}
|
||||
*/
|
||||
if(strlen($info['tli_title'])<1){
|
||||
$msg .= '<div>任务标题不能为空.</div>';
|
||||
$ispass = true;
|
||||
}
|
||||
/*
|
||||
if(!is_numeric($info['tli_userid'])){
|
||||
$msg .= '<div>必须指定翻译人员.</div>';
|
||||
$ispass = true;
|
||||
}
|
||||
*/
|
||||
if(!preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/",$info['tli_deadline'])){
|
||||
$msg .= '<div>有效期日期格式不正确.</div>';
|
||||
$ispass = true;
|
||||
}
|
||||
|
||||
if(strtotime($info['tli_deadline']) < time()){
|
||||
$info['tli_deadline'] = time()+3600*24*10;
|
||||
}
|
||||
|
||||
if($ispass){
|
||||
$data[] = array('name'=>'ok','value'=>$msg);
|
||||
echo json_encode($data);
|
||||
exit();
|
||||
}
|
||||
if($tid>0){//更新任务新信息
|
||||
$result = $this->Translate_model->updatetranslat($info,$tid);
|
||||
} else {//新增新任务
|
||||
$result = $this->Translate_model->addTranslate($info);
|
||||
}
|
||||
if($result){
|
||||
$data[] = array('name'=>'go','value'=>site_url('translate/listall'));
|
||||
} else {
|
||||
$data[] = array('name'=>'no','value'=>'系统错误请重试!');
|
||||
}
|
||||
echo json_encode($data);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$data['userList'] = $this->Translate_model->getuserList();
|
||||
$this->load->view('header',$data);
|
||||
$this->load->view('translate_publish');
|
||||
$this->load->view('footer');
|
||||
}
|
||||
//全部列表同部调用function index
|
||||
public function listall(){
|
||||
$this->index();
|
||||
}
|
||||
//修改任务表单
|
||||
public function editiem($tid){
|
||||
$data['userList'] = $this->Translate_model->getuserList();
|
||||
$data['translateInfo'] = $this->Translate_model->getTranslateInfo($tid);
|
||||
$this->load->view('header',$data);
|
||||
$this->load->view('translate_edit');
|
||||
$this->load->view('footer');
|
||||
}
|
||||
/*删除任务*/
|
||||
public function deletetranslate($tid){
|
||||
$this->Translate_model->deletetranslation($tid);
|
||||
redirect(site_url('translate/listall'));
|
||||
}
|
||||
/*操作表单*/
|
||||
//操作表单可用字段有:
|
||||
// 管理备注
|
||||
// 信息应用地址,
|
||||
// 翻译总字数
|
||||
// 已经付款总数
|
||||
// 状态
|
||||
public function opater($tid,$action=''){
|
||||
if(!in_array($action,array('check','pay','public')))
|
||||
{
|
||||
exit();
|
||||
}
|
||||
|
||||
$data['translateinfo']=$this->Translate_model->getTranslateInfo($tid);
|
||||
switch ($action){
|
||||
case "check":
|
||||
break;
|
||||
default:
|
||||
|
||||
}
|
||||
if($this->input->post('action') == 'check'){
|
||||
$this->opatercheck($tid);
|
||||
}else if($this->input->post('action') == 'pay'){
|
||||
if($data['translateinfo']['tli_status'] < 4){
|
||||
$data[]=array('name'=>'no','value'=>'审核未通过不能结算任务!');
|
||||
exit(json_encode($data));
|
||||
}
|
||||
$this->opaterpay($tid);
|
||||
}else if($this->input->post('action') == 'public'){
|
||||
$this->opaterpublic($tid);
|
||||
}
|
||||
|
||||
|
||||
$data['action']=$action;
|
||||
$data['tid']=$tid;
|
||||
$this->load->view('header',$data);
|
||||
$this->load->view('opater');
|
||||
$this->load->view('footer');
|
||||
}
|
||||
|
||||
private function opatercheck($tid){
|
||||
$r = $this->input->post('opater');
|
||||
$this->form_validation->set_rules('opater[tli_charcount]', 'tli_charcount', 'required|numeric');
|
||||
if ($this->form_validation->run() == FALSE){
|
||||
$data[]=array('name'=>'no','value'=>'请输入翻译总字数,必须为数字');
|
||||
} else {
|
||||
|
||||
$r['tli_status'] = ($r['tli_status']==1)?4:3;
|
||||
$r['tli_checktime'] = date('Y-m-d H:i:s',time());//审核时间
|
||||
|
||||
if($this->Translate_model->updatetranslat($r,$tid)==false){
|
||||
$data[]=array('name'=>'no','value'=>'审核操作失败,请重试');
|
||||
}else{
|
||||
$data[]=array('name'=>'ok','value'=>'操作成功执行');
|
||||
}
|
||||
}
|
||||
echo json_encode($data);
|
||||
exit();
|
||||
}
|
||||
private function opaterpay($tid){
|
||||
$r = $this->input->post('opater');
|
||||
$this->form_validation->set_rules('opater[tli_charge]', 'tli_charge', 'required|numeric');
|
||||
$this->form_validation->set_rules('opater[tli_chargeunit]', 'tli_chargeunit', 'required');
|
||||
if ($this->form_validation->run() == FALSE){
|
||||
$data[]=array('name'=>'no','value'=>'支付金额必须为数字,单位币种不能为空');
|
||||
} else {
|
||||
$r['tli_status'] = 5;
|
||||
if($this->Translate_model->updatetranslat($r,$tid)==false){
|
||||
$data[]=array('name'=>'no','value'=>'审核操作失败,请重试');
|
||||
} else {
|
||||
$data[]=array('name'=>'ok','value'=>'操作成功执行');
|
||||
}
|
||||
}
|
||||
echo json_encode($data);
|
||||
exit();
|
||||
}
|
||||
private function opaterpublic($tid){
|
||||
$r = $this->input->post('opater');
|
||||
$r['tli_status'] = 6;
|
||||
if($this->Translate_model->updatetranslat($r,$tid)==false){
|
||||
$data[]=array('name'=>'no','value'=>'发布操作失败,请重试');
|
||||
}else{
|
||||
$data[]=array('name'=>'ok','value'=>'操作成功执行');
|
||||
}
|
||||
exit(json_encode($data));
|
||||
}
|
||||
//操作表单结束//
|
||||
|
||||
/*以上部分为翻译内容*/
|
||||
/*以下部分为用户管理部分*/
|
||||
//用户管理部分以小写u开头
|
||||
public function listuser(){
|
||||
$this->load->library('pagination');
|
||||
$page = $this->uri->segment(3);
|
||||
$recordcount = 0;
|
||||
|
||||
$data['translateUserList'] = $this->Translate_model->uList($recordcount,$page,$this->per_page);
|
||||
$config['base_url'] = site_url("translate/listuser/");
|
||||
$config['total_rows'] = $recordcount;
|
||||
$config['per_page'] = $this->per_page;
|
||||
$config['uri_segment'] = 3;
|
||||
$this->pagination->initialize($config);
|
||||
|
||||
$this->load->view('header',$data);
|
||||
$this->load->view('translate_userlist');
|
||||
$this->load->view('footer');
|
||||
}
|
||||
/*编辑*/
|
||||
public function uedit($uid){
|
||||
$msg='';
|
||||
if($this->input->post('Submit') && $uid>0){
|
||||
$userinfo= $this->input->post('userinfo1');
|
||||
$passwordInfo = $this->input->post('userinfo');
|
||||
$msg ='用户信息更新成功.';
|
||||
if($passwordInfo['tlui_password']!='' ){
|
||||
$newpassword = $this->Translate_model->randomkeys(6);
|
||||
$userinfo['tlui_password']=md5($newpassword);
|
||||
$msg .="您初始化了密码新密码为:<strong>$newpassword</strong>";
|
||||
}
|
||||
$this->Translate_model->update_user($userinfo,$uid);
|
||||
}
|
||||
|
||||
$data = $this->Translate_model->getUserInfo($uid);
|
||||
$data->msg=$msg;
|
||||
$this->load->view('header',$data);
|
||||
$this->load->view('translate_userform');
|
||||
$this->load->view('footer');
|
||||
}
|
||||
/*删除*/
|
||||
public function udelete($uid){
|
||||
$this->Translate_model->deleteuser($uid);
|
||||
redirect(site_url('translate/listuser'));
|
||||
}
|
||||
|
||||
/*公告*/
|
||||
public function announc($page=0){
|
||||
$data['action'] = 'list';
|
||||
$page = $this->uri->segment(2);
|
||||
$data['announcList'] = $this->Translate_model->getAnnouncList($this->per_page,$page);
|
||||
$this->load->view('header',$data);
|
||||
$this->load->view('announc');
|
||||
$this->load->view('footer');
|
||||
}
|
||||
public function announcadd(){
|
||||
$data['action'] = 'add';
|
||||
//$data['announc'] = $this->Translate_model->getAnnounc($id);
|
||||
$this->load->view('header',$data);
|
||||
$this->load->view('announc');
|
||||
$this->load->view('footer');
|
||||
}
|
||||
public function editannounc($id=''){
|
||||
$data['action'] = 'edit';
|
||||
if($this->input->post('submit') == 'true'){
|
||||
//保存
|
||||
$msg['tlm_title'] = $this->input->post('tlm_title');
|
||||
$msg['tlm_content'] = $this->input->post('tlm_content');
|
||||
$msg['tlm_id'] = $this->input->post('tlm_id');
|
||||
//unset($msg['tlm_id']);
|
||||
if($msg['tlm_id']==""){//新建
|
||||
unset($msg['tlm_id']);
|
||||
$msg['tlm_dateline'] = date('Y-m-d H:i:s',time());
|
||||
$this->Translate_model->inertAnnounc($msg);
|
||||
$data[]=array('name'=>'go','value'=>site_url('translate/announc'));
|
||||
} else { //修改
|
||||
unset($msg['tlm_id']);
|
||||
$this->Translate_model->updateAnnounc($msg,$id);
|
||||
$data[]=array('name'=>'go','value'=>site_url('translate/announc'));
|
||||
}
|
||||
exit(json_encode($data));
|
||||
}
|
||||
|
||||
$data['announc'] = $this->Translate_model->getAnnounc($id);
|
||||
$this->load->view('header',$data);
|
||||
$this->load->view('announc');
|
||||
$this->load->view('footer');
|
||||
}
|
||||
|
||||
public function deletennounc($id=''){
|
||||
$this->Translate_model->deleteAnnounc($id);
|
||||
redirect(site_url('translate/announc'));
|
||||
}
|
||||
|
||||
//修改后的函数
|
||||
//检测是否存在这样一个翻译信息
|
||||
public function checktranslate($ic_id){
|
||||
$data['result'] = $this->Translate_model->checktranslate($ic_id);
|
||||
echo json_encode($data);
|
||||
}
|
||||
public function gettranslateInfo($ic_id){
|
||||
|
||||
if(!$this->Translate_model->checktranslate($ic_id)){
|
||||
$tmpinfo['tli_content']=$this->input->post("ic_content");
|
||||
$tmpinfo['tli_tagetlgc'] = "";
|
||||
$tmpinfo['tli_otherquest'] = "";
|
||||
$tmpinfo['tli_title'] = "";
|
||||
$tmpinfo['tli_userid'] = 0;
|
||||
$tmpinfo['tli_ic_id'] = $ic_id;
|
||||
$this->Translate_model->addTranslate($tmpinfo);
|
||||
}
|
||||
|
||||
$data['translateInfo'] = $this->Translate_model->getTranslateInfo(0,$ic_id);
|
||||
$data['userList'] = $this->Translate_model->getuserList();
|
||||
$data['cp'] = "checktranslate";
|
||||
$this->load->view('translate_form',$data);
|
||||
}
|
||||
|
||||
public function updateTranslate(){
|
||||
|
||||
$this->load->helper('date');
|
||||
$info = $this->input->post('info');
|
||||
$msg = '';$ispass = false;
|
||||
/*
|
||||
if(strlen($info['tli_content'])<10){
|
||||
$msg = '<div>翻译内容不能为空.</div>';
|
||||
$ispass = true;
|
||||
}
|
||||
*/
|
||||
|
||||
if(strlen($info['tli_title'])<1){
|
||||
$msg .= '<div>任务标题不能为空.</div>';
|
||||
$ispass = true;
|
||||
}/*
|
||||
if(!is_numeric($info['tli_userid'])){
|
||||
$msg .= '<div>必须指定翻译人员.</div>';
|
||||
$ispass = true;
|
||||
}
|
||||
*/
|
||||
if(!preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/",$info['tli_deadline'])){
|
||||
$msg .= '<div>有效期日期格式不正确.</div>';
|
||||
$ispass = true;
|
||||
}
|
||||
if(!preg_match("/^[0-9]+$/",$info['tli_id'])){
|
||||
$msg .= '<div>系统错误,错误代码 #1.</div>';
|
||||
$ispass = true;
|
||||
}
|
||||
if(!preg_match("/^[0-9]+$/",$info['tli_ic_id'])){
|
||||
$msg .= '<div>系统错误,错误代码 #2.</div>';
|
||||
$ispass = true;
|
||||
}
|
||||
|
||||
if($ispass){
|
||||
$data[] = array('name'=>'no','value'=>$msg);
|
||||
echo json_encode($data);
|
||||
exit();
|
||||
}
|
||||
$tid = $info['tli_id'];
|
||||
unset($info['tli_charcount']);
|
||||
unset($info['tli_charge']);
|
||||
unset($info['tli_id']);
|
||||
unset($info['tli_info']);
|
||||
|
||||
$result = $this->Translate_model->updatetranslat($info,$tid);
|
||||
if($result){
|
||||
$data[] = array('name'=>'ok','value'=>'翻译信息内容更新成功');
|
||||
} else {
|
||||
$data[] = array('name'=>'no','value'=>'系统错误请重试!');
|
||||
}
|
||||
echo json_encode($data);
|
||||
exit();
|
||||
}
|
||||
|
||||
public function opaterajax($tid,$action=''){
|
||||
$data['cp'] = $action;
|
||||
$data['translateInfo'] = $this->Translate_model->getTranslateInfo($tid, 0);
|
||||
$str = $this->load->view('translate_form',$data,true);
|
||||
$data[] = array('name'=>'ok','value'=>$str);
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
public function viewcon($tid){
|
||||
$data['cp'] = 'viewcon';
|
||||
$data['translateInfo'] = $this->Translate_model->getTranslateInfo($tid, 0);
|
||||
$str = $this->load->view('translate_form',$data);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Video extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
//$this->output->enable_profiler(TRUE);
|
||||
$this->load->model('Area_model');
|
||||
$this->load->model('Information_model');
|
||||
$this->load->model('InfoContents_model');
|
||||
$this->load->model('InfoStructures_model');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$video_id=1;
|
||||
//查询结构根节点,当为空则建立
|
||||
$rootStructure = $this->Information_model->GetRoot('v', $video_id);
|
||||
if ($rootStructure == FALSE)
|
||||
{
|
||||
$this->InfoContents_model->Add('', 'video', 'root', '', '', '', '', '', '', 0, 0, '', '', 0, 0, '', '', $video_id, 'v', 0,
|
||||
'','');
|
||||
$this->InfoStructures_model->Add(0, $this->InfoContents_model->insert_id);
|
||||
$is_id = $this->InfoStructures_model->insert_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$is_id = $rootStructure->is_id;
|
||||
}
|
||||
redirect(site_url('information/edit/' . $is_id));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,34 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>404 Page Not Found</title>
|
||||
<style type="text/css">
|
||||
|
||||
body {
|
||||
background-color: #fff;
|
||||
margin: 40px;
|
||||
font-family: Lucida Grande, Verdana, Sans-serif;
|
||||
font-size: 12px;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#content {
|
||||
border: #999 1px solid;
|
||||
background-color: #fff;
|
||||
padding: 20px 20px 12px 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-weight: normal;
|
||||
font-size: 14px;
|
||||
color: #990000;
|
||||
margin: 0 0 4px 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<h1><?php echo $heading; ?></h1>
|
||||
<?php echo $message; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,36 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Database Error</title>
|
||||
<style type="text/css">
|
||||
|
||||
body {
|
||||
background-color: #fff;
|
||||
margin: 40px;
|
||||
font-family: Lucida Grande, Verdana, Sans-serif;
|
||||
font-size: 12px;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#content {
|
||||
border: #999 1px solid;
|
||||
background-color: #fff;
|
||||
padding: 20px 20px 12px 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-weight: normal;
|
||||
font-size: 14px;
|
||||
color: #990000;
|
||||
margin: 0 0 4px 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<h1><?php echo $heading; ?></h1>
|
||||
<?php echo $message; ?>
|
||||
<?php print_r(sqlsrv_errors()); ?>
|
||||
<?php print_r(mysql_error()); ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,34 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Error</title>
|
||||
<style type="text/css">
|
||||
|
||||
body {
|
||||
background-color: #fff;
|
||||
margin: 40px;
|
||||
font-family: Lucida Grande, Verdana, Sans-serif;
|
||||
font-size: 12px;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#content {
|
||||
border: #999 1px solid;
|
||||
background-color: #fff;
|
||||
padding: 20px 20px 12px 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-weight: normal;
|
||||
font-size: 14px;
|
||||
color: #990000;
|
||||
margin: 0 0 4px 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<h1><?php echo $heading; ?></h1>
|
||||
<?php echo $message; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,10 @@
|
||||
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
|
||||
|
||||
<h4>A PHP Error was encountered</h4>
|
||||
|
||||
<p>Severity: <?php echo $severity; ?></p>
|
||||
<p>Message: <?php echo $message; ?></p>
|
||||
<p>Filename: <?php echo $filepath; ?></p>
|
||||
<p>Line Number: <?php echo $line; ?></p>
|
||||
|
||||
</div>
|
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0"?>
|
||||
<BCPFORMAT
|
||||
xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<RECORD>
|
||||
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR="|@|" MAX_LENGTH="8000" />
|
||||
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR="|@|" MAX_LENGTH="50" />
|
||||
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR="|@|" MAX_LENGTH="50" />
|
||||
<FIELD ID="4" xsi:type="CharTerm" TERMINATOR="|@|" MAX_LENGTH="8000" />
|
||||
<FIELD ID="5" xsi:type="CharTerm" TERMINATOR="|@|" MAX_LENGTH="50" />
|
||||
<FIELD ID="6" xsi:type="CharTerm" TERMINATOR="|@|" MAX_LENGTH="8000" />
|
||||
<FIELD ID="7" xsi:type="CharTerm" TERMINATOR="|@|" MAX_LENGTH="8000"/>
|
||||
<FIELD ID="8" xsi:type="CharTerm" TERMINATOR="|@|" MAX_LENGTH="8000" />
|
||||
<FIELD ID="9" xsi:type="CharTerm" TERMINATOR="|@|" MAX_LENGTH="50" />
|
||||
<FIELD ID="10" xsi:type="CharTerm" TERMINATOR="|@|" MAX_LENGTH="8000" />
|
||||
<FIELD ID="11" xsi:type="CharTerm" TERMINATOR="\r\n" MAX_LENGTH="8000" />
|
||||
</RECORD>
|
||||
<ROW>
|
||||
<COLUMN SOURCE="1" NAME="kwa_source" xsi:type="SQLNVARCHAR"/>
|
||||
<COLUMN SOURCE="2" NAME="kwa_pageviews" xsi:type="SQLBIGINT"/>
|
||||
<COLUMN SOURCE="3" NAME="kwa_uniquepageviews" xsi:type="SQLBIGINT"/>
|
||||
<COLUMN SOURCE="4" NAME="kwa_avgtimeonpage" xsi:type="SQLNVARCHAR"/>
|
||||
<COLUMN SOURCE="5" NAME="kwa_entrances" xsi:type="SQLBIGINT"/>
|
||||
<COLUMN SOURCE="6" NAME="kwa_exitrate" xsi:type="SQLNVARCHAR"/>
|
||||
<COLUMN SOURCE="7" NAME="kwa_conversionrate" xsi:type="SQLNVARCHAR"/>
|
||||
<COLUMN SOURCE="8" NAME="kwa_datetime" xsi:type="SQLNVARCHAR"/>
|
||||
<COLUMN SOURCE="9" NAME="kwa_sitecode" xsi:type="SQLNVARCHAR"/>
|
||||
<COLUMN SOURCE="10" NAME="kwa_pagepath" xsi:type="SQLNVARCHAR"/>
|
||||
<COLUMN SOURCE="11" NAME="kwa_keyword" xsi:type="SQLNVARCHAR"/>
|
||||
</ROW>
|
||||
</BCPFORMAT>
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
//查询两地之间的距离
|
||||
function get_city_distance($start_city,$destination_city)
|
||||
{
|
||||
$CI = & get_instance();
|
||||
$CI->lang->load('city_distance');
|
||||
$result=$CI->lang->line('c_distance');
|
||||
$str1=$start_city.$destination_city;//拼接数组键
|
||||
$str2=$destination_city.$start_city;//拼接数组键
|
||||
|
||||
if(isset($result[$str1])){
|
||||
return $result[$str1];
|
||||
}
|
||||
|
||||
if(isset($result[$str2])){
|
||||
return $result[$str2];
|
||||
}
|
||||
log_message('info',"查询失败");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,290 @@
|
||||
<?php
|
||||
|
||||
//获取项目类型名称
|
||||
function get_project_typename($type)
|
||||
{
|
||||
$CI = & get_instance();
|
||||
$type_list=$CI->config->item('project_types');
|
||||
return $type_list[$type];
|
||||
}
|
||||
|
||||
function GetAreaName($HT_areaType, $HT_areaID) {
|
||||
$CI = & get_instance();
|
||||
$CI->load->model('Area_model');
|
||||
return $CI->Area_model->get_area_name($HT_areaType, $HT_areaID);
|
||||
}
|
||||
|
||||
//查找作者名称,根据参数类型判断查作者表还是翰特表
|
||||
function get_author_name($author_code_id) {
|
||||
$CI = & get_instance();
|
||||
if (is_numeric($author_code_id)) {
|
||||
$CI->load->model('Infoauthors_model');
|
||||
$user = $CI->Infoauthors_model->detail_by_id($author_code_id);
|
||||
if ($user) {
|
||||
return $user->a_name;
|
||||
}
|
||||
} else {
|
||||
$CI->load->model('Operator_model');
|
||||
$user = $CI->Operator_model->get_user($author_code_id);
|
||||
if ($user) {
|
||||
return $user['OPI_Name'];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//根据站点id获取站点名称
|
||||
function get_sitecode($site_id, $site_array) {
|
||||
foreach ($site_array as $item) {
|
||||
if ($item['site_id'] == $site_id) {
|
||||
return $item['site_code'];
|
||||
}
|
||||
}
|
||||
return 'FALSE';
|
||||
}
|
||||
|
||||
/*
|
||||
* 递归创建文件夹
|
||||
*/
|
||||
|
||||
function create_folder_by_path($dir, $mode = 0777) {
|
||||
if (!is_dir($dir)) {
|
||||
return @mkdir($dir, $mode, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取iis rewrite之前的原始url
|
||||
*/
|
||||
function get_origin_url() {
|
||||
$CI = & get_instance();
|
||||
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
|
||||
$origin_url = str_replace($CI->config->item('index_page'), '/', $_SERVER['HTTP_X_REWRITE_URL']);
|
||||
} else {
|
||||
$origin_url = str_replace($CI->config->item('index_page'), '/', $_SERVER['REQUEST_URI']);
|
||||
}
|
||||
return str_replace('//', '/', urldecode($origin_url));
|
||||
}
|
||||
|
||||
//是否是系列站
|
||||
function is_series_site() {
|
||||
$CI = & get_instance();
|
||||
$sitecode = $CI->config->item('site_code');
|
||||
if ($sitecode == 'vc' || $sitecode == 'ru' || $sitecode == 'jp' || $sitecode == 'vac' || $sitecode == 'it') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//是否是子站点
|
||||
function is_sub_site() {
|
||||
$CI = & get_instance();
|
||||
$sitecode = $CI->config->item('site_code');
|
||||
if ($sitecode == 'yz' || $sitecode == 'tbt' || $sitecode == 'mbj' || $sitecode == 'sht' || $sitecode == 'gl') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function add_meta($im_ic_id, $im_key, $im_value) {
|
||||
$CI = & get_instance();
|
||||
$CI->load->model('InfoMetas_model');
|
||||
return $CI->InfoMetas_model->add($im_ic_id, $im_key, $im_value);
|
||||
}
|
||||
|
||||
function get_meta($im_ic_id, $im_key) {
|
||||
$CI = & get_instance();
|
||||
$CI->load->model('InfoMetas_model');
|
||||
return $CI->InfoMetas_model->get($im_ic_id, $im_key);
|
||||
}
|
||||
|
||||
function update_meta($im_ic_id, $im_key, $im_value) {
|
||||
$CI = & get_instance();
|
||||
$CI->load->model('InfoMetas_model');
|
||||
return $CI->InfoMetas_model->update($im_ic_id, $im_key, $im_value);
|
||||
}
|
||||
|
||||
function delete_meta($im_ic_id, $im_key) {
|
||||
$CI = & get_instance();
|
||||
$CI->load->model('InfoMetas_model');
|
||||
return $CI->InfoMetas_model->delete($im_ic_id, $im_key);
|
||||
}
|
||||
|
||||
//检查是否有短消息
|
||||
function have_unread_sms($m_object_type,$m_object_id)
|
||||
{
|
||||
$CI = & get_instance();
|
||||
$CI->load->model('InfoSMS_model');
|
||||
$sms_list=$CI->InfoSMS_model->unread_sms($m_object_type,$m_object_id);
|
||||
$admin_info=$CI->session->userdata('session_admin');
|
||||
if(empty($sms_list))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sender=get_author_name($sms_list[0]->m_sender);
|
||||
if($admin_info['OPI_Name']==$sender){
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//截取字符串
|
||||
function get_text_short($str, $length = 40, $ext = '',$only_content=false) {
|
||||
$str = strip_tags($str);
|
||||
$str = htmlspecialchars_decode($str);
|
||||
$strlenth = 0;
|
||||
$out = '';
|
||||
$output = '';
|
||||
$is_length = false;
|
||||
preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/", $str, $match);
|
||||
foreach($match[0] as $v){
|
||||
preg_match("/[\xe0-\xef][\x80-\xbf]{2}/",$v, $matchs);
|
||||
if(!empty($matchs[0])){
|
||||
$strlenth += 1;
|
||||
}elseif(is_numeric($v)){
|
||||
$strlenth += 0.5; // 字符字节长度比例 汉字为1
|
||||
}else{
|
||||
$strlenth += 0.5; // 字符字节长度比例 汉字为1
|
||||
}
|
||||
if ($strlenth > $length) {
|
||||
$output .= $ext;
|
||||
$is_length=true;
|
||||
break;
|
||||
}
|
||||
$output .= $v;
|
||||
}
|
||||
$data['content']=$output;
|
||||
$data['length']=$is_length;
|
||||
if ($only_content) {
|
||||
return $data['content'];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
//平台头部展示所有未读消息数量
|
||||
function get_all_unread_sms($type='author',$author=false)
|
||||
{
|
||||
$CI = & get_instance();
|
||||
$CI->load->model('InfoSMS_model');
|
||||
if(!$author){
|
||||
$admin_info=$CI->session->userdata('session_admin');
|
||||
$author=$admin_info['OPI_Code'];
|
||||
}
|
||||
|
||||
if ($type=='info') {
|
||||
$unread_sms=$CI->InfoSMS_model->info_unread_sms($author,'info');
|
||||
}else{
|
||||
$unread_sms=$CI->InfoSMS_model->all_unread_sms($author,'task');
|
||||
}
|
||||
return $unread_sms;
|
||||
}
|
||||
|
||||
//获取不同任务状态的任务数量
|
||||
function get_task_count_by_status(){
|
||||
$CI = & get_instance();
|
||||
$CI->load->model('Infotasks_model');
|
||||
$task_count_by_status=$CI->Infotasks_model->get_task_count_by_status();
|
||||
return $task_count_by_status;
|
||||
}
|
||||
|
||||
//获取作者头像
|
||||
function get_author_photo($author_code_id=false)
|
||||
{
|
||||
$CI = & get_instance();
|
||||
$root_url='';//'http://data.chtcdn.com';
|
||||
$avatar=$root_url.'/css/images/avatar.jpg';
|
||||
if($author_code_id && is_numeric($author_code_id))
|
||||
{
|
||||
$CI->load->model('Infoauthors_model');
|
||||
$user=$CI->Infoauthors_model->detail_by_id($author_code_id);
|
||||
if(isset($user->a_photo) && $user->a_photo!='')
|
||||
{
|
||||
$avatar = $root_url.'/author/document/profile_photo/'.$user->a_photo;
|
||||
}
|
||||
}
|
||||
return $avatar;
|
||||
}
|
||||
|
||||
//补全图片路径
|
||||
function get_photo_url($photo){
|
||||
$root_url='';//'http://data.chtcdn.com';
|
||||
if ($photo=='') {
|
||||
$avatar = $root_url.'/css/images/uploadPic.jpg';
|
||||
}else{
|
||||
$avatar = $root_url.'/author/document/profile_photo/'.$photo;
|
||||
}
|
||||
return $avatar;
|
||||
}
|
||||
|
||||
//获取待审核作者数量
|
||||
function un_active_count(){
|
||||
$CI = & get_instance();
|
||||
$CI->load->model('Infoauthors_model');
|
||||
$num=$CI->Infoauthors_model->un_active_count();
|
||||
return $num;
|
||||
}
|
||||
|
||||
//分页函数
|
||||
function show_page($page){
|
||||
$pageSize = $page['pageSize'];
|
||||
$total = $page['total'];
|
||||
$url = $page['url'];
|
||||
$pageNumber = ceil($total / $pageSize);
|
||||
$currentPage = $page['current'] ? $page['current'] : 1;
|
||||
$startPage = ($currentPage - 1) * $pageSize;
|
||||
|
||||
$befor = $after = 0;
|
||||
$nowview=ceil(($currentPage+1)/10);
|
||||
$befor = $nowview==1?($nowview-1)*10+1:($nowview-1)*10;
|
||||
if($pageNumber>=$nowview*10){
|
||||
$after = $nowview*10;
|
||||
}else{
|
||||
$after = $pageNumber;
|
||||
}
|
||||
|
||||
$html='';
|
||||
if($nowview>1) $befor--;
|
||||
if ($pageSize <= $total) {
|
||||
for ($i = $befor; $i <= $after; $i++) {
|
||||
if ($i == $currentPage) {
|
||||
$html .= "<li class=\"active\"><a href=\"javascript:void(0)\">{$i}</a></li>";
|
||||
}else {
|
||||
$html .= "<li><a href=\"{$url}/{$i}\">$i</a></li>";
|
||||
}
|
||||
}
|
||||
}
|
||||
$res['htmls']=$html;
|
||||
$res['prepage']=$currentPage - 1;
|
||||
$res['nextpage']=$currentPage + 1;
|
||||
$res['totalpage']=$pageNumber;
|
||||
return $res;
|
||||
}
|
||||
|
||||
//请求URL并返回数组数据
|
||||
function get_content_by_url($url) {
|
||||
//echo $url;
|
||||
$httpInfo = array();
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22');
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
$response = curl_exec($ch);
|
||||
if ($response === FALSE) {
|
||||
#echo "cURL Error: " . curl_error($ch);
|
||||
return false;
|
||||
}
|
||||
return $response;
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,664 @@
|
||||
<?php
|
||||
/*
|
||||
* 两个城市之间的距离数据
|
||||
* author:mjs
|
||||
* 创建时间:2016.3.29
|
||||
*
|
||||
*/
|
||||
$lang['c_distance']=array(
|
||||
"BUDPEK"=>7593,
|
||||
"HAKURC"=>4254,
|
||||
"HAKHRC"=>3911,
|
||||
"NGBURC"=>3910,
|
||||
"URCCAN"=>3836,
|
||||
"CANHEK"=>3741,
|
||||
"URCHKG"=>3653,
|
||||
"SHAURC"=>3649,
|
||||
"HAKKUL"=>3500,
|
||||
"SYXKUL"=>3300,
|
||||
"ICNSYX"=>3160,
|
||||
"HAKSHE"=>3142,
|
||||
"JILSZX"=>3080,
|
||||
"HAKICN"=>3060,
|
||||
"HRBSZX"=>3034,
|
||||
"CGQSZX"=>2983,
|
||||
"CANCGQ"=>2971,
|
||||
"HAKKIX"=>2965,
|
||||
"DLCHAK"=>2920,
|
||||
"PEKURC"=>2842,
|
||||
"HAKHET"=>2809,
|
||||
"HAKWEH"=>2717,
|
||||
"PEKSYX"=>2710,
|
||||
"SHECAN"=>2672,
|
||||
"SHESZX"=>2671,
|
||||
"JHGTSN"=>2660,
|
||||
"PEKWUA"=>2650,
|
||||
"HAKPUS"=>2600,
|
||||
"URCCKG"=>2560,
|
||||
"HAKSIN"=>2500,
|
||||
"SYXTYN"=>2500,
|
||||
"HAKPEK"=>2493,
|
||||
"HAKTAO"=>2435,
|
||||
"HAKLHW"=>2410,
|
||||
"ZHAPEK"=>2409,
|
||||
"KWLSHE"=>2382,
|
||||
"HAKTSN"=>2370,
|
||||
"DLCSZX"=>2368,
|
||||
"URCXIY"=>2352,
|
||||
"HAKSJW"=>2349,
|
||||
"CGQFOC"=>2326,
|
||||
"CANDLC"=>2285,
|
||||
"ZUHSHE"=>2273,
|
||||
"HAKTNA"=>2272,
|
||||
"HAKTYN"=>2270,
|
||||
"KMGPEK"=>2266,
|
||||
"CTUURC"=>2258,
|
||||
"NNGPEK"=>2250,
|
||||
"LYGXMN"=>2247,
|
||||
"LHWXMN"=>2244,
|
||||
"SHEXMN"=>2242,
|
||||
"KMGTSN"=>2210,
|
||||
"HETSZX"=>2206,
|
||||
"SZXXNN"=>2185,
|
||||
"LHWSZX"=>2185,
|
||||
"SWAXIY"=>2165,
|
||||
"XNNCAN"=>2150,
|
||||
"LHWWNZ"=>2133,
|
||||
"CANYNT"=>2132,
|
||||
"CGOSYX"=>2120,
|
||||
"CANWEH"=>2112,
|
||||
"PEKZUH"=>2098,
|
||||
"CANWEF"=>2093,
|
||||
"CANINC"=>2088,
|
||||
"KMGTNA"=>2080,
|
||||
"PEKSZX"=>2077,
|
||||
"SYXXIY"=>2067,
|
||||
"PVGSYX"=>2050,
|
||||
"PVGNDG"=>2049,
|
||||
"XNNSHA"=>2047,
|
||||
"KMGSHA"=>2042,
|
||||
"KWEPEK"=>2039,
|
||||
"NKGSYX"=>2030,
|
||||
"HRBXIY"=>2028,
|
||||
"SZXTSN"=>2021,
|
||||
"CGOJHG"=>2020,
|
||||
"CGQHGQ"=>2010,
|
||||
"SHEXNN"=>2009,
|
||||
"PVGMDG"=>2003,
|
||||
"NGBSHE"=>1994,
|
||||
"HAKHKG"=>1990,
|
||||
"CGQXIY"=>1979,
|
||||
"CANPEK"=>1967,
|
||||
"HGHSYX"=>1950,
|
||||
"KMGNGB"=>1948,
|
||||
"XIYXMN"=>1932,
|
||||
"NGBSYX"=>1920,
|
||||
"CANTSN"=>1910,
|
||||
"LHWURC"=>1895,
|
||||
"LAXPVG"=>1890,
|
||||
"CANENY"=>1889,
|
||||
"KWLPEK"=>1887,
|
||||
"CANDAT"=>1887,
|
||||
"HAKXUZ"=>1880,
|
||||
"AATKHG"=>1877,
|
||||
"CGOHAK"=>1873,
|
||||
"KMGTYN"=>1871,
|
||||
"CANTAO"=>1867,
|
||||
"HAKXIY"=>1860,
|
||||
"SIAHAK"=>1860,
|
||||
"HGHSHE"=>1849,
|
||||
"HAKHFE"=>1840,
|
||||
"NNGXIY"=>1832,
|
||||
"SZXTNA"=>1828,
|
||||
"CANSJW"=>1822,
|
||||
"CTUNGB"=>1803,
|
||||
"SYXWNZ"=>1802,
|
||||
"PEKXMN"=>1800,
|
||||
"KWLTSN"=>1800,
|
||||
"PEKTPE"=>1800,
|
||||
"SZXTYN"=>1796,
|
||||
"KWLTYN"=>1791,
|
||||
"XNNPEK"=>1780,
|
||||
"PEKKHV"=>1780,
|
||||
"HAKPVG"=>1762,
|
||||
"SHAHAK"=>1762,
|
||||
"CTUHAK"=>1757,
|
||||
"HRBNKG"=>1756,
|
||||
"SHEWNZ"=>1753,
|
||||
"NNGSHA"=>1750,
|
||||
"KMGLHW"=>1749,
|
||||
"HGHINC"=>1746,
|
||||
"HAKXFN"=>1733,
|
||||
"CANTYN"=>1722,
|
||||
"FOCTYN"=>1721,
|
||||
"HRBTYN"=>1714,
|
||||
"SYXWUH"=>1700,
|
||||
"CTUPEK"=>1697,
|
||||
"FOCXIY"=>1693,
|
||||
"FOCPEK"=>1681,
|
||||
"KMGXMN"=>1680,
|
||||
"CANXIY"=>1674,
|
||||
"PVGBHY"=>1670,
|
||||
"CANTNA"=>1664,
|
||||
"HAKYIW"=>1655,
|
||||
"LHWNKG"=>1654,
|
||||
"KWLLHW"=>1651,
|
||||
"SHEXIY"=>1648,
|
||||
"CKGPEK"=>1640,
|
||||
"CTUTSN"=>1640,
|
||||
"ENYSHA"=>1639,
|
||||
"SZXXIY"=>1635,
|
||||
"NKGSHE"=>1630,
|
||||
"TYNWNZ"=>1629,
|
||||
"FOCTSN"=>1622,
|
||||
"HAKNGB"=>1620,
|
||||
"HAKNGB"=>1620,
|
||||
"WNZXIY"=>1601,
|
||||
"BKKHAK"=>1600,
|
||||
"NZHPEK"=>1600,
|
||||
"INCDLC"=>1574,
|
||||
"CGOKMG"=>1570,
|
||||
"CSXJHG"=>1566,
|
||||
"CANLYG"=>1560,
|
||||
"PEKHEK"=>1552,
|
||||
"CKGNGB"=>1550,
|
||||
"TSNWNZ"=>1545,
|
||||
"NKGZUH"=>1544,
|
||||
"CGQNKG"=>1533,
|
||||
"HAKWNZ"=>1526,
|
||||
"NKGSZX"=>1526,
|
||||
"HYNXIY"=>1523,
|
||||
"NGBXIY"=>1520,
|
||||
"DNHXIY"=>1518,
|
||||
"URCXNN"=>1518,
|
||||
"CKGSYX"=>1517,
|
||||
"CKGWNZ"=>1505,
|
||||
"PEKWNZ"=>1500,
|
||||
"XIYLXA"=>1500,
|
||||
"ZUHPVG"=>1497,
|
||||
"PEKYIH"=>1483,
|
||||
"CANLYA"=>1480,
|
||||
"HAKYIH"=>1479,
|
||||
"CGOSZX"=>1465,
|
||||
"HRBSJW"=>1464,
|
||||
"WUHXNN"=>1460,
|
||||
"WNZYNT"=>1454,
|
||||
"CTUSZX"=>1446,
|
||||
"CSXPEK"=>1466,
|
||||
"MDGPEK"=>1439,
|
||||
"CSXTAO"=>1437,
|
||||
"WUSPEK"=>1426,
|
||||
"TNAHRB"=>1425,
|
||||
"JUZPEK"=>1406,
|
||||
"KHNTNA"=>1404,
|
||||
"HETHLD"=>1402,
|
||||
"XUZCAN"=>1400,
|
||||
"KHNPEK"=>1398,
|
||||
"PEKJMU"=>1398,
|
||||
"CSXSYX"=>1398,
|
||||
"HETCTU"=>1392,
|
||||
"CANCTU"=>1390,
|
||||
"KWLSHA"=>1389,
|
||||
"PEKDYG"=>1385,
|
||||
"SZXXUZ"=>1380,
|
||||
"HAKWUH"=>1379,
|
||||
"HETHLH"=>1372,
|
||||
"DLCHEK"=>1372,
|
||||
"SHEPVG"=>1364,
|
||||
"NTGCAN"=>1363,
|
||||
"CTUSJW"=>1357,
|
||||
"CANKMG"=>1357,
|
||||
"PEKLHW"=>1356,
|
||||
"LAXPEK"=>1356,
|
||||
"CSXTSN"=>1353,
|
||||
"SHAXIY"=>1351,
|
||||
"PVGXIY"=>1351,
|
||||
"PVGSZX"=>1343,
|
||||
"CGOSHE"=>1339,
|
||||
"NGBPEK"=>1338,
|
||||
"KWLNGB"=>1327,
|
||||
"TYNDYG"=>1326,
|
||||
"HLDTSN"=>1323,
|
||||
"HLDPEK"=>1313,
|
||||
"CGOXMN"=>1312,
|
||||
"KHGURC"=>1311,
|
||||
"CANSHA"=>1308,
|
||||
"CGDPEK"=>1300,
|
||||
"DYGTNA"=>1296,
|
||||
"INCTAO"=>1295,
|
||||
"CKGSZX"=>1290,
|
||||
"JDZPEK"=>1290,
|
||||
"HGHSWA"=>1280,
|
||||
"WUSXIY"=>1275,
|
||||
"KWEXMN"=>1268,
|
||||
"INCWUH"=>1263,
|
||||
"JGNXIY"=>1260,
|
||||
"NGBTSN"=>1260,
|
||||
"TYNXMN"=>1258,
|
||||
"CANNKG"=>1255,
|
||||
"CKGHAK"=>1253,
|
||||
"CANCGO"=>1250,
|
||||
"SJWCSX"=>1249,
|
||||
"KMGSZX"=>1245,
|
||||
"CGOWNZ"=>1245,
|
||||
"YNTMDG"=>1239,
|
||||
"SHATYN"=>1238,
|
||||
"PVGTYN"=>1238,
|
||||
"NGBSZX"=>1237,
|
||||
"SZXXFN"=>1237,
|
||||
"FOCHAK"=>1234,
|
||||
"CSXTNA"=>1228,
|
||||
"BAVSHE"=>1228,
|
||||
"KMGXIY"=>1228,
|
||||
"HGHXIY"=>1215,
|
||||
"TAOXIY"=>1215,
|
||||
"CTUINC"=>1207,
|
||||
"HAKKHN"=>1204,
|
||||
"XIYKWL"=>1204,
|
||||
"HAKCGD"=>1204,
|
||||
"HGHPEK"=>1200,
|
||||
"PEKYNJ"=>1192,
|
||||
"CGOFOC"=>1192,
|
||||
"KWLNKG"=>1192,
|
||||
"HFESZX"=>1191,
|
||||
"HRBTSN"=>1190,
|
||||
"CANNGB"=>1189,
|
||||
"CANCKG"=>1188,
|
||||
"CANXFN"=>1185,
|
||||
"DLCHET"=>1184,
|
||||
"TXNXIY"=>1183,
|
||||
"HGHTYN"=>1180,
|
||||
"MIGTYN"=>1180,
|
||||
"HFESWA"=>1180,
|
||||
"HGHSZX"=>1179,
|
||||
"PEKSHA"=>1178,
|
||||
"LYGXIY"=>1178,
|
||||
"PEKPVG"=>1178,
|
||||
"CSXTYN"=>1174,
|
||||
"CTUTYN"=>1173,
|
||||
"SHETYN"=>1171,
|
||||
"DLCNGB"=>1170,
|
||||
"TNAWNZ"=>1170,
|
||||
"CKGINC"=>1163,
|
||||
"KWESYX"=>1160,
|
||||
"PVGTSN"=>1133,
|
||||
"PEKWUH"=>1133,
|
||||
"SHATSN"=>1133,
|
||||
"HGHTSN"=>1133,
|
||||
"SJWSHA"=>1130,
|
||||
"CKGTYN"=>1129,
|
||||
"CTUXNN"=>1124,
|
||||
"CKGLHW"=>1117,
|
||||
"CSXKMG"=>1116,
|
||||
"CGDSHA"=>1111,
|
||||
"SHAYIH"=>1111,
|
||||
"HRBTAO"=>1111,
|
||||
"DOYSHA"=>1110,
|
||||
"CANYIW"=>1107,
|
||||
"INCPEK"=>1107,
|
||||
"CANHFE"=>1105,
|
||||
"NKGXIY"=>1104,
|
||||
"TAOWNZ"=>1102,
|
||||
"CKGXNN"=>1100,
|
||||
"CSXHAK"=>1100,
|
||||
"HAKXMN"=>1100,
|
||||
"HGHCAN"=>1099,
|
||||
"YNTHRB"=>1093,
|
||||
"HETTGO"=>1090,
|
||||
"LHWTYN"=>1087,
|
||||
"AQGPEK"=>1082,
|
||||
"HETXNN"=>1082,
|
||||
"TSNWUH"=>1082,
|
||||
"PEKNDG"=>1080,
|
||||
"XIYKHN"=>1078,
|
||||
"DNHLHW"=>1068,
|
||||
"CGONGB"=>1060,
|
||||
"CZXTYN"=>1053,
|
||||
"DLCPVG"=>1051,
|
||||
"HETSHE"=>1051,
|
||||
"WNZXFN"=>1051,
|
||||
"CIHSHA"=>1050,
|
||||
"DLCXIY"=>1050,
|
||||
"CTUWUH"=>1047,
|
||||
"HAKKMG"=>1046,
|
||||
"SWASHA"=>1046,
|
||||
"BHYCSX"=>1042,
|
||||
"PEKXIY"=>1034,
|
||||
"SZXYIH"=>1032,
|
||||
"KWEXIY"=>1028,
|
||||
"LHWCGO"=>1024,
|
||||
"ENYWUH"=>1019,
|
||||
"TAOWUH"=>1017,
|
||||
"CZXPEK"=>1016,
|
||||
"CANWNZ"=>1015,
|
||||
"NNGCTU"=>1014,
|
||||
"HRBPEK"=>1010,
|
||||
"LYASHA"=>1009,
|
||||
"SZXWNZ"=>1009,
|
||||
"HEKSHE"=>1005,
|
||||
"LYGWNZ"=>1000,
|
||||
"CGOINC"=>1000,
|
||||
"TSNXIY"=>993,
|
||||
"CSXXIY"=>990,
|
||||
"CGODLC"=>988,
|
||||
"NKGPEK"=>981,
|
||||
"CANYIH"=>980,
|
||||
"CGOCKG"=>980,
|
||||
"KOWWNZ"=>977,
|
||||
"CTUKWL"=>975,
|
||||
"SHESJW"=>974,
|
||||
"NKGTYN"=>974,
|
||||
"HRBSHP"=>963,
|
||||
"HFEXIY"=>960,
|
||||
"HFEPEK"=>959,
|
||||
"AATYIN"=>955,
|
||||
"LYAPVG"=>953,
|
||||
"CANTXN"=>951,
|
||||
"YNZWNZ"=>945,
|
||||
"CSXCTU"=>940,
|
||||
"SZXWUH"=>938,
|
||||
"PEKJIL"=>935,
|
||||
"CGQPEK"=>933,
|
||||
"NKGXMN"=>929,
|
||||
"KWEKHN"=>928,
|
||||
"KWLSYX"=>926,
|
||||
"KWESSZX"=>926,
|
||||
"KWEWUH"=>925,
|
||||
"KHGYIN"=>922,
|
||||
"CSXENH"=>918,
|
||||
"XIYXUZ"=>917,
|
||||
"HAKLLF"=>915,
|
||||
"HLHPEK"=>913,
|
||||
"DLCTYN"=>913,
|
||||
"HLDXIL"=>913,
|
||||
"HAKKWE"=>910,
|
||||
"WUHXMN"=>910,
|
||||
"DLCNKG"=>910,
|
||||
"HAKSWA"=>907,
|
||||
"NKGTSN"=>907,
|
||||
"HFETSN"=>906,
|
||||
"WUAXIY"=>904,
|
||||
"NGBSWA"=>902,
|
||||
"TNASHE"=>900,
|
||||
"TNAXIY"=>900,
|
||||
"CGQTSN"=>900,
|
||||
"HFEXMN"=>900,
|
||||
"SWAWUH"=>900,
|
||||
"HETXIY"=>894,
|
||||
"TYNXUZ"=>893,
|
||||
"CANDYG"=>890,
|
||||
"TNAWUH"=>890,
|
||||
"CKGLYA"=>882,
|
||||
"KWLXMN"=>881,
|
||||
"SHAXMN"=>878,
|
||||
"WUHCAN"=>873,
|
||||
"CANKWE"=>872,
|
||||
"SJWWUH"=>872,
|
||||
"CKGENY"=>870,
|
||||
"CGKENY"=>870,
|
||||
"TYNWUH"=>866,
|
||||
"TYNWUA"=>866,
|
||||
"JJNNKG"=>863,
|
||||
"KMGKWL"=>859,
|
||||
"CKGNNG"=>858,
|
||||
"DLCHRB"=>857,
|
||||
"SJWNKG"=>857,
|
||||
"PEKUYN"=>857,
|
||||
"CSXNNG"=>856,
|
||||
"TYNXIL"=>853,
|
||||
"TNASHA"=>852,
|
||||
"TNAHGH"=>850,
|
||||
"DNHURC"=>847,
|
||||
"YNTSHA"=>846,
|
||||
"CGOHGH"=>841,
|
||||
"SYXSZX"=>837,
|
||||
"INCSJW"=>833,
|
||||
"CSXNGB"=>830,
|
||||
"LZHWUH"=>830,
|
||||
"ENYPEK"=>829,
|
||||
"SHETSN"=>829,
|
||||
"CGOCSX"=>828,
|
||||
"NGBXMN"=>822,
|
||||
"KHNKWL"=>820,
|
||||
"CSXWNZ"=>810,
|
||||
"HFETYN"=>808,
|
||||
"SHAWEF"=>807,
|
||||
"KWLSWA"=>802,
|
||||
"CKGWUH"=>801,
|
||||
"NGBTAO"=>800,
|
||||
"KWLWUH"=>795,
|
||||
"HGHTAO"=>792,
|
||||
"KOWSHA"=>790,
|
||||
"HYNWUH"=>788,
|
||||
"DNHXNN"=>787,
|
||||
"NKGYNT"=>787,
|
||||
"LYAPEK"=>785,
|
||||
"JJNNGB"=>780,
|
||||
"FOCWUH"=>780,
|
||||
"CANCGD"=>780,
|
||||
"HAKKWL"=>773,
|
||||
"KWEMIG"=>763,
|
||||
"CANFOC"=>763,
|
||||
"SHAWUH"=>761,
|
||||
"DLCTSN"=>759,
|
||||
"CGQTAO"=>759,
|
||||
"NGBWUH"=>754,
|
||||
"KHNSZX"=>753,
|
||||
"LYINGB"=>750,
|
||||
"AKUURC"=>750,
|
||||
"KCACRC"=>750,
|
||||
"CSXJJN"=>748,
|
||||
"BAVLHW"=>747,
|
||||
"CANSYX"=>747,
|
||||
"XIYYIH"=>747,
|
||||
"FOCNKG"=>747,
|
||||
"HFEWNZ"=>745,
|
||||
"DLCJIL"=>743,
|
||||
"SJWDLC"=>741,
|
||||
"WUHXIY"=>735,
|
||||
"PEKTGO"=>735,
|
||||
"KHVHRB"=>735,
|
||||
"BAVXIY"=>734,
|
||||
"CSXHFE"=>732,
|
||||
"JZHXIY"=>732,
|
||||
"FOCHFE"=>730,
|
||||
"NNGCAN"=>728,
|
||||
"XIYXNN"=>721,
|
||||
"SHETAO"=>721,
|
||||
"JGNLHW"=>718,
|
||||
"LHAJGN"=>718,
|
||||
"HGHXMN"=>717,
|
||||
"KHNSHA"=>711,
|
||||
"AQGXMN"=>710,
|
||||
"TAOTYN"=>710,
|
||||
"LYGPEK"=>710,
|
||||
"FUGSHA"=>700,
|
||||
"YINURC"=>700,
|
||||
"CIHPEK"=>700,
|
||||
"SJWXIY"=>696,
|
||||
"CGOHET"=>695,
|
||||
"CKGCSX"=>695,
|
||||
"HRBHLD"=>695,
|
||||
"DYGXIY"=>693,
|
||||
"SHATAO"=>693,
|
||||
"PEKCGO"=>690,
|
||||
"JUZXMN"=>690,
|
||||
"HFETAO"=>690,
|
||||
"NNGZUH"=>689,
|
||||
"BHYKWE"=>680,
|
||||
"SHPTYN"=>680,
|
||||
"CZXWNZ"=>667,
|
||||
"KHNCAN"=>665,
|
||||
"CSXSZX"=>658,
|
||||
"HGHWUH"=>656,
|
||||
"NKGWNZ"=>655,
|
||||
"NNGSZX"=>651,
|
||||
"CANWUS"=>650,
|
||||
"PEKXUZ"=>650,
|
||||
"CGQJMU"=>650,
|
||||
"PEKSHE"=>649,
|
||||
"SWAWNZ"=>649,
|
||||
"CGODOY"=>649,
|
||||
"CTUXIY"=>647,
|
||||
"CGQDLC"=>647,
|
||||
"PEKTAO"=>646,
|
||||
"KHNPVG"=>644,
|
||||
"CIHXIY"=>640,
|
||||
"CIFHET"=>639,
|
||||
"CGONKG"=>630,
|
||||
"SHEMDG"=>630,
|
||||
"HRBYNJ"=>630,
|
||||
"JDZXMN"=>630,
|
||||
"PEKWEF"=>630,
|
||||
"CGOTSN"=>629,
|
||||
"XMNZUH"=>629,
|
||||
"FOCNGB"=>621,
|
||||
"CSXCAN"=>620,
|
||||
"JDZSHA"=>620,
|
||||
"TXNWNZ"=>620,
|
||||
"BHYCAN"=>606,
|
||||
"CKGXIY"=>603,
|
||||
"HAKSZX"=>603,
|
||||
"WEFXUZ"=>603,
|
||||
"XMNYIW"=>600,
|
||||
"LZHCAN"=>595,
|
||||
"MIGXIY"=>593,
|
||||
"YNTSHE"=>593,
|
||||
"KHNNGB"=>592,
|
||||
"HYNXMN"=>585,
|
||||
"INCTYN"=>585,
|
||||
"KHNWNZ"=>583,
|
||||
"DLCPEK"=>579,
|
||||
"BAVPEK"=>579,
|
||||
"NKGTNA"=>579,
|
||||
"WNZXMN"=>577,
|
||||
"PEKYNT"=>575,
|
||||
"HEKHRB"=>574,
|
||||
"DLCLYG"=>570,
|
||||
"CANXMN"=>567,
|
||||
"HGHXUZ"=>561,
|
||||
"INCXIY"=>560,
|
||||
"XIYICN"=>560,
|
||||
"HRBSHE"=>556,
|
||||
"SHALYG"=>556,
|
||||
"LHWXIY"=>550,
|
||||
"SZXXMN"=>549,
|
||||
"CANHAK"=>548,
|
||||
"YINKRL"=>542,
|
||||
"KHNXMN"=>542,
|
||||
"TYNXIY"=>537,
|
||||
"SIATYN"=>537,
|
||||
"CTUKWE"=>531,
|
||||
"KWLSZX"=>525,
|
||||
"PEKTYN"=>522,
|
||||
"SHPSJW"=>520,
|
||||
"CGOWUH"=>520,
|
||||
"CKGDYG"=>519,
|
||||
"FOCHGH"=>519,
|
||||
"NKGWUH"=>504,
|
||||
"HETXIL"=>501,
|
||||
"HFENGB"=>501,
|
||||
"KWENNG"=>500,
|
||||
"XIYLHA"=>500,
|
||||
"AQGSHA"=>500,
|
||||
"XUZSHA"=>500,
|
||||
"CGOHFE"=>486,
|
||||
"UYNXIY"=>480,
|
||||
"JILJMU"=>480,
|
||||
"ENHWUH"=>479,
|
||||
"TAOTSN"=>477,
|
||||
"HFEHGH"=>476,
|
||||
"CGOXIY"=>474,
|
||||
"SWAFOC"=>472,
|
||||
"IQNLHW"=>472,
|
||||
"NNGWUZ"=>469,
|
||||
"CSXKWL"=>462,
|
||||
"PEKYNZ"=>462,
|
||||
"DLUJHG"=>461,
|
||||
"HAKZUH"=>460,
|
||||
"ZHASZX"=>460,
|
||||
"AKUKHG"=>454,
|
||||
"ZHACAN"=>454,
|
||||
"CANKWL"=>452,
|
||||
"TCGURC"=>452,
|
||||
"JHGKNG"=>450,
|
||||
"AATURC"=>450,
|
||||
"DOYPEK"=>450,
|
||||
"KWEKMG"=>449,
|
||||
"TXNWUH"=>448,
|
||||
"WXNXIY"=>445,
|
||||
"CSXTEN"=>444,
|
||||
"HETPEK"=>444,
|
||||
"GYSXIY"=>438,
|
||||
"BHYKWL"=>435,
|
||||
"TSNTYN"=>435,
|
||||
"JNZPEK"=>430,
|
||||
"HAKLZH"=>425,
|
||||
"HAKWUZ"=>425,
|
||||
"KWELZO"=>424,
|
||||
"PEKXIL"=>421,
|
||||
"HETWUA"=>420,
|
||||
"DLCWEF"=>420,
|
||||
"SHAWNZ"=>418,
|
||||
"PVGWNZ"=>418,
|
||||
"HGHWNZ"=>416,
|
||||
"TNAYNT"=>415,
|
||||
"CKGTEN"=>413,
|
||||
"PEKTNA"=>412,
|
||||
"HAKNNG"=>411,
|
||||
"HETSJW"=>404,
|
||||
"TSNYNT"=>402,
|
||||
"KOWXMN"=>400,
|
||||
"WEFWEH"=>395,
|
||||
"CGOTNA"=>392,
|
||||
"CTUWXN"=>382,
|
||||
"SWACAN"=>380,
|
||||
"CSXYIH"=>379,
|
||||
"WEHTAO"=>376,
|
||||
"NGBNKG"=>373,
|
||||
"KRLURC"=>373,
|
||||
"HRBJMU"=>372,
|
||||
"ZHAZUH"=>371,
|
||||
"FOCHYN"=>370,
|
||||
"HETTYN"=>370,
|
||||
"SYXZHA"=>367,
|
||||
"PEKSJW"=>364,
|
||||
"CSXLLF"=>361,
|
||||
"LYAXIY"=>353,
|
||||
"CGOTYN"=>346,
|
||||
"KMGLJG"=>346,
|
||||
"YNTCGO"=>346,
|
||||
"CTUGYS"=>344,
|
||||
"KHNWUH"=>343,
|
||||
"CIFPEK"=>338,
|
||||
"INCLHW"=>333,
|
||||
"XUZYNZ"=>333,
|
||||
"CSXWUH"=>332,
|
||||
"DLCSHP"=>323,
|
||||
"NGBTXN"=>320,
|
||||
"HZGXIY"=>315,
|
||||
"KHNKOW"=>314,
|
||||
"CKGCTU"=>313,
|
||||
"ENYXIY"=>312,
|
||||
"NGBWNZ"=>309,
|
||||
"ENYINC"=>300,
|
||||
"AKUKCA"=>300,
|
||||
"HRBMDG"=>300,
|
||||
"KWETEN"=>291,
|
||||
"WUHYIH"=>285,
|
||||
"DLUKMG"=>262,
|
||||
"ENHYIH"=>259,
|
||||
"IQNXIY"=>259,
|
||||
"CIHTYN"=>250,
|
||||
"AOGDLC"=>250,
|
||||
"HAKSYX"=>234,
|
||||
"FOCXMN"=>219,
|
||||
"AKAXIY"=>208,
|
||||
"BHYHAK"=>205,
|
||||
"AQGJDZ"=>204,
|
||||
"NGBPVG"=>160,
|
||||
"NGBSHA"=>160,
|
||||
"HAKZHA"=>146,
|
||||
"LYGXUZ"=>140
|
||||
);
|
||||
?>
|
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,471 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Check for the json extension, the Google APIs PHP Client won't function
|
||||
// without it.
|
||||
if (! function_exists('json_decode')) {
|
||||
throw new Exception('Google PHP API Client requires the JSON PHP extension');
|
||||
}
|
||||
|
||||
if (! function_exists('http_build_query')) {
|
||||
throw new Exception('Google PHP API Client requires http_build_query()');
|
||||
}
|
||||
|
||||
if (! ini_get('date.timezone') && function_exists('date_default_timezone_set')) {
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
|
||||
// hack around with the include paths a bit so the library 'just works'
|
||||
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
require_once "config.php";
|
||||
// If a local configuration file is found, merge it's values with the default configuration
|
||||
if (file_exists(dirname(__FILE__) . '/local_config.php')) {
|
||||
$defaultConfig = $apiConfig;
|
||||
require_once (dirname(__FILE__) . '/local_config.php');
|
||||
$apiConfig = array_merge($defaultConfig, $apiConfig);
|
||||
}
|
||||
|
||||
// Include the top level classes, they each include their own dependencies
|
||||
require_once 'service/Google_Model.php';
|
||||
require_once 'service/Google_Service.php';
|
||||
require_once 'service/Google_ServiceResource.php';
|
||||
require_once 'auth/Google_AssertionCredentials.php';
|
||||
require_once 'auth/Google_Signer.php';
|
||||
require_once 'auth/Google_P12Signer.php';
|
||||
require_once 'service/Google_BatchRequest.php';
|
||||
require_once 'external/URITemplateParser.php';
|
||||
require_once 'auth/Google_Auth.php';
|
||||
require_once 'cache/Google_Cache.php';
|
||||
require_once 'io/Google_IO.php';
|
||||
require_once('service/Google_MediaFileUpload.php');
|
||||
|
||||
/**
|
||||
* The Google API Client
|
||||
* http://code.google.com/p/google-api-php-client/
|
||||
*
|
||||
* @author Chris Chabot <chabotc@google.com>
|
||||
* @author Chirag Shah <chirags@google.com>
|
||||
*/
|
||||
class Google_Client {
|
||||
/**
|
||||
* @static
|
||||
* @var Google_Auth $auth
|
||||
*/
|
||||
static $auth;
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @var Google_IO $io
|
||||
*/
|
||||
static $io;
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @var Google_Cache $cache
|
||||
*/
|
||||
static $cache;
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @var boolean $useBatch
|
||||
*/
|
||||
static $useBatch = false;
|
||||
|
||||
/** @var array $scopes */
|
||||
protected $scopes = array();
|
||||
|
||||
/** @var bool $useObjects */
|
||||
protected $useObjects = false;
|
||||
|
||||
// definitions of services that are discovered.
|
||||
protected $services = array();
|
||||
|
||||
// Used to track authenticated state, can't discover services after doing authenticate()
|
||||
private $authenticated = false;
|
||||
|
||||
public function __construct($config = array()) {
|
||||
global $apiConfig;
|
||||
$apiConfig = array_merge($apiConfig, $config);
|
||||
self::$cache = new $apiConfig['cacheClass']();
|
||||
self::$auth = new $apiConfig['authClass']();
|
||||
self::$io = new $apiConfig['ioClass']();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a service
|
||||
*/
|
||||
public function addService($service, $version = false) {
|
||||
global $apiConfig;
|
||||
if ($this->authenticated) {
|
||||
throw new Google_Exception('Cant add services after having authenticated');
|
||||
}
|
||||
$this->services[$service] = array();
|
||||
if (isset($apiConfig['services'][$service])) {
|
||||
// Merge the service descriptor with the default values
|
||||
$this->services[$service] = array_merge($this->services[$service], $apiConfig['services'][$service]);
|
||||
}
|
||||
}
|
||||
|
||||
public function authenticate($code = null) {
|
||||
$service = $this->prepareService();
|
||||
$this->authenticated = true;
|
||||
return self::$auth->authenticate($service, $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @visible For Testing
|
||||
*/
|
||||
public function prepareService() {
|
||||
$service = array();
|
||||
$scopes = array();
|
||||
if ($this->scopes) {
|
||||
$scopes = $this->scopes;
|
||||
} else {
|
||||
foreach ($this->services as $key => $val) {
|
||||
if (isset($val['scope'])) {
|
||||
if (is_array($val['scope'])) {
|
||||
$scopes = array_merge($val['scope'], $scopes);
|
||||
} else {
|
||||
$scopes[] = $val['scope'];
|
||||
}
|
||||
} else {
|
||||
$scopes[] = 'https://www.googleapis.com/auth/' . $key;
|
||||
}
|
||||
unset($val['discoveryURI']);
|
||||
unset($val['scope']);
|
||||
$service = array_merge($service, $val);
|
||||
}
|
||||
}
|
||||
$service['scope'] = implode(' ', $scopes);
|
||||
return $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the OAuth 2.0 access token using the string that resulted from calling authenticate()
|
||||
* or Google_Client#getAccessToken().
|
||||
* @param string $accessToken JSON encoded string containing in the following format:
|
||||
* {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer",
|
||||
* "expires_in":3600, "id_token":"TOKEN", "created":1320790426}
|
||||
*/
|
||||
public function setAccessToken($accessToken) {
|
||||
if ($accessToken == null || 'null' == $accessToken) {
|
||||
$accessToken = null;
|
||||
}
|
||||
self::$auth->setAccessToken($accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of Auth class the client should use.
|
||||
* @param string $authClassName
|
||||
*/
|
||||
public function setAuthClass($authClassName) {
|
||||
self::$auth = new $authClassName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the OAuth 2.0 authorization request URI.
|
||||
* @return string
|
||||
*/
|
||||
public function createAuthUrl() {
|
||||
$service = $this->prepareService();
|
||||
return self::$auth->createAuthUrl($service['scope']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the OAuth 2.0 access token.
|
||||
* @return string $accessToken JSON encoded string in the following format:
|
||||
* {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer",
|
||||
* "expires_in":3600,"id_token":"TOKEN", "created":1320790426}
|
||||
*/
|
||||
public function getAccessToken() {
|
||||
$token = self::$auth->getAccessToken();
|
||||
return (null == $token || 'null' == $token) ? null : $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the access_token is expired.
|
||||
* @return bool Returns True if the access_token is expired.
|
||||
*/
|
||||
public function isAccessTokenExpired() {
|
||||
return self::$auth->isAccessTokenExpired();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the developer key to use, these are obtained through the API Console.
|
||||
* @see http://code.google.com/apis/console-help/#generatingdevkeys
|
||||
* @param string $developerKey
|
||||
*/
|
||||
public function setDeveloperKey($developerKey) {
|
||||
self::$auth->setDeveloperKey($developerKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set OAuth 2.0 "state" parameter to achieve per-request customization.
|
||||
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-22#section-3.1.2.2
|
||||
* @param string $state
|
||||
*/
|
||||
public function setState($state) {
|
||||
self::$auth->setState($state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessType Possible values for access_type include:
|
||||
* {@code "offline"} to request offline access from the user. (This is the default value)
|
||||
* {@code "online"} to request online access from the user.
|
||||
*/
|
||||
public function setAccessType($accessType) {
|
||||
self::$auth->setAccessType($accessType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $approvalPrompt Possible values for approval_prompt include:
|
||||
* {@code "force"} to force the approval UI to appear. (This is the default value)
|
||||
* {@code "auto"} to request auto-approval when possible.
|
||||
*/
|
||||
public function setApprovalPrompt($approvalPrompt) {
|
||||
self::$auth->setApprovalPrompt($approvalPrompt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the application name, this is included in the User-Agent HTTP header.
|
||||
* @param string $applicationName
|
||||
*/
|
||||
public function setApplicationName($applicationName) {
|
||||
global $apiConfig;
|
||||
$apiConfig['application_name'] = $applicationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the OAuth 2.0 Client ID.
|
||||
* @param string $clientId
|
||||
*/
|
||||
public function setClientId($clientId) {
|
||||
global $apiConfig;
|
||||
$apiConfig['oauth2_client_id'] = $clientId;
|
||||
self::$auth->clientId = $clientId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the OAuth 2.0 Client ID.
|
||||
*/
|
||||
public function getClientId() {
|
||||
return self::$auth->clientId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the OAuth 2.0 Client Secret.
|
||||
* @param string $clientSecret
|
||||
*/
|
||||
public function setClientSecret($clientSecret) {
|
||||
global $apiConfig;
|
||||
$apiConfig['oauth2_client_secret'] = $clientSecret;
|
||||
self::$auth->clientSecret = $clientSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the OAuth 2.0 Client Secret.
|
||||
*/
|
||||
public function getClientSecret() {
|
||||
return self::$auth->clientSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the OAuth 2.0 Redirect URI.
|
||||
* @param string $redirectUri
|
||||
*/
|
||||
public function setRedirectUri($redirectUri) {
|
||||
global $apiConfig;
|
||||
$apiConfig['oauth2_redirect_uri'] = $redirectUri;
|
||||
self::$auth->redirectUri = $redirectUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the OAuth 2.0 Redirect URI.
|
||||
*/
|
||||
public function getRedirectUri() {
|
||||
return self::$auth->redirectUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a fresh OAuth 2.0 access token with the given refresh token.
|
||||
* @param string $refreshToken
|
||||
* @return void
|
||||
*/
|
||||
public function refreshToken($refreshToken) {
|
||||
self::$auth->refreshToken($refreshToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke an OAuth2 access token or refresh token. This method will revoke the current access
|
||||
* token, if a token isn't provided.
|
||||
* @throws Google_AuthException
|
||||
* @param string|null $token The token (access token or a refresh token) that should be revoked.
|
||||
* @return boolean Returns True if the revocation was successful, otherwise False.
|
||||
*/
|
||||
public function revokeToken($token = null) {
|
||||
self::$auth->revokeToken($token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify an id_token. This method will verify the current id_token, if one
|
||||
* isn't provided.
|
||||
* @throws Google_AuthException
|
||||
* @param string|null $token The token (id_token) that should be verified.
|
||||
* @return Google_LoginTicket Returns an apiLoginTicket if the verification was
|
||||
* successful.
|
||||
*/
|
||||
public function verifyIdToken($token = null) {
|
||||
return self::$auth->verifyIdToken($token);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Google_AssertionCredentials $creds
|
||||
* @return void
|
||||
*/
|
||||
public function setAssertionCredentials(Google_AssertionCredentials $creds) {
|
||||
self::$auth->setAssertionCredentials($creds);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function allows you to overrule the automatically generated scopes,
|
||||
* so that you can ask for more or less permission in the auth flow
|
||||
* Set this before you call authenticate() though!
|
||||
* @param array $scopes, ie: array('https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/moderator')
|
||||
*/
|
||||
public function setScopes($scopes) {
|
||||
$this->scopes = is_string($scopes) ? explode(" ", $scopes) : $scopes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of scopes set on the client
|
||||
* @return array the list of scopes
|
||||
*
|
||||
*/
|
||||
public function getScopes() {
|
||||
return $this->scopes;
|
||||
}
|
||||
|
||||
/**
|
||||
* If 'plus.login' is included in the list of requested scopes, you can use
|
||||
* this method to define types of app activities that your app will write.
|
||||
* You can find a list of available types here:
|
||||
* @link https://developers.google.com/+/api/moment-types
|
||||
*
|
||||
* @param array $requestVisibleActions Array of app activity types
|
||||
*/
|
||||
public function setRequestVisibleActions($requestVisibleActions) {
|
||||
self::$auth->requestVisibleActions =
|
||||
join(" ", $requestVisibleActions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare if objects should be returned by the api service classes.
|
||||
*
|
||||
* @param boolean $useObjects True if objects should be returned by the service classes.
|
||||
* False if associative arrays should be returned (default behavior).
|
||||
* @experimental
|
||||
*/
|
||||
public function setUseObjects($useObjects) {
|
||||
global $apiConfig;
|
||||
$apiConfig['use_objects'] = $useObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare if objects should be returned by the api service classes.
|
||||
*
|
||||
* @param boolean $useBatch True if the experimental batch support should
|
||||
* be enabled. Defaults to False.
|
||||
* @experimental
|
||||
*/
|
||||
public function setUseBatch($useBatch) {
|
||||
self::$useBatch = $useBatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @return Google_Auth the implementation of apiAuth.
|
||||
*/
|
||||
public static function getAuth() {
|
||||
return Google_Client::$auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @return Google_IO the implementation of apiIo.
|
||||
*/
|
||||
public static function getIo() {
|
||||
return Google_Client::$io;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Google_Cache the implementation of apiCache.
|
||||
*/
|
||||
public function getCache() {
|
||||
return Google_Client::$cache;
|
||||
}
|
||||
}
|
||||
|
||||
// Exceptions that the Google PHP API Library can throw
|
||||
class Google_Exception extends Exception {}
|
||||
class Google_AuthException extends Google_Exception {}
|
||||
class Google_CacheException extends Google_Exception {}
|
||||
class Google_IOException extends Google_Exception {}
|
||||
class Google_ServiceException extends Google_Exception {
|
||||
/**
|
||||
* Optional list of errors returned in a JSON body of an HTTP error response.
|
||||
*/
|
||||
protected $errors = array();
|
||||
|
||||
/**
|
||||
* Override default constructor to add ability to set $errors.
|
||||
*
|
||||
* @param string $message
|
||||
* @param int $code
|
||||
* @param Exception|null $previous
|
||||
* @param [{string, string}] errors List of errors returned in an HTTP
|
||||
* response. Defaults to [].
|
||||
*/
|
||||
public function __construct($message, $code = 0, Exception $previous = null,
|
||||
$errors = array()) {
|
||||
if(version_compare(PHP_VERSION, '5.3.0') >= 0) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
} else {
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
|
||||
$this->errors = $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* An example of the possible errors returned.
|
||||
*
|
||||
* {
|
||||
* "domain": "global",
|
||||
* "reason": "authError",
|
||||
* "message": "Invalid Credentials",
|
||||
* "locationType": "header",
|
||||
* "location": "Authorization",
|
||||
* }
|
||||
*
|
||||
* @return [{string, string}] List of errors return in an HTTP response or [].
|
||||
*/
|
||||
public function getErrors() {
|
||||
return $this->errors;
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Credentials object used for OAuth 2.0 Signed JWT assertion grants.
|
||||
*
|
||||
* @author Chirag Shah <chirags@google.com>
|
||||
*/
|
||||
class Google_AssertionCredentials {
|
||||
const MAX_TOKEN_LIFETIME_SECS = 3600;
|
||||
|
||||
public $serviceAccountName;
|
||||
public $scopes;
|
||||
public $privateKey;
|
||||
public $privateKeyPassword;
|
||||
public $assertionType;
|
||||
public $sub;
|
||||
/**
|
||||
* @deprecated
|
||||
* @link http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
|
||||
*/
|
||||
public $prn;
|
||||
|
||||
/**
|
||||
* @param $serviceAccountName
|
||||
* @param $scopes array List of scopes
|
||||
* @param $privateKey
|
||||
* @param string $privateKeyPassword
|
||||
* @param string $assertionType
|
||||
* @param bool|string $sub The email address of the user for which the
|
||||
* application is requesting delegated access.
|
||||
*/
|
||||
public function __construct(
|
||||
$serviceAccountName,
|
||||
$scopes,
|
||||
$privateKey,
|
||||
$privateKeyPassword = 'notasecret',
|
||||
$assertionType = 'http://oauth.net/grant_type/jwt/1.0/bearer',
|
||||
$sub = false) {
|
||||
$this->serviceAccountName = $serviceAccountName;
|
||||
$this->scopes = is_string($scopes) ? $scopes : implode(' ', $scopes);
|
||||
$this->privateKey = $privateKey;
|
||||
$this->privateKeyPassword = $privateKeyPassword;
|
||||
$this->assertionType = $assertionType;
|
||||
$this->sub = $sub;
|
||||
$this->prn = $sub;
|
||||
}
|
||||
|
||||
public function generateAssertion() {
|
||||
$now = time();
|
||||
|
||||
$jwtParams = array(
|
||||
'aud' => Google_OAuth2::OAUTH2_TOKEN_URI,
|
||||
'scope' => $this->scopes,
|
||||
'iat' => $now,
|
||||
'exp' => $now + self::MAX_TOKEN_LIFETIME_SECS,
|
||||
'iss' => $this->serviceAccountName,
|
||||
);
|
||||
|
||||
if ($this->sub !== false) {
|
||||
$jwtParams['sub'] = $this->sub;
|
||||
} else if ($this->prn !== false) {
|
||||
$jwtParams['prn'] = $this->prn;
|
||||
}
|
||||
|
||||
return $this->makeSignedJwt($jwtParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a signed JWT.
|
||||
* @param array $payload
|
||||
* @return string The signed JWT.
|
||||
*/
|
||||
private function makeSignedJwt($payload) {
|
||||
$header = array('typ' => 'JWT', 'alg' => 'RS256');
|
||||
|
||||
$segments = array(
|
||||
Google_Utils::urlSafeB64Encode(json_encode($header)),
|
||||
Google_Utils::urlSafeB64Encode(json_encode($payload))
|
||||
);
|
||||
|
||||
$signingInput = implode('.', $segments);
|
||||
$signer = new Google_P12Signer($this->privateKey, $this->privateKeyPassword);
|
||||
$signature = $signer->sign($signingInput);
|
||||
$segments[] = Google_Utils::urlSafeB64Encode($signature);
|
||||
|
||||
return implode(".", $segments);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once "Google_AuthNone.php";
|
||||
require_once "Google_OAuth2.php";
|
||||
|
||||
/**
|
||||
* Abstract class for the Authentication in the API client
|
||||
* @author Chris Chabot <chabotc@google.com>
|
||||
*
|
||||
*/
|
||||
abstract class Google_Auth {
|
||||
abstract public function authenticate($service);
|
||||
abstract public function sign(Google_HttpRequest $request);
|
||||
abstract public function createAuthUrl($scope);
|
||||
|
||||
abstract public function getAccessToken();
|
||||
abstract public function setAccessToken($accessToken);
|
||||
abstract public function setDeveloperKey($developerKey);
|
||||
abstract public function refreshToken($refreshToken);
|
||||
abstract public function revokeToken();
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Do-nothing authentication implementation, use this if you want to make un-authenticated calls
|
||||
* @author Chris Chabot <chabotc@google.com>
|
||||
* @author Chirag Shah <chirags@google.com>
|
||||
*/
|
||||
class Google_AuthNone extends Google_Auth {
|
||||
public $key = null;
|
||||
|
||||
public function __construct() {
|
||||
global $apiConfig;
|
||||
if (!empty($apiConfig['developer_key'])) {
|
||||
$this->setDeveloperKey($apiConfig['developer_key']);
|
||||
}
|
||||
}
|
||||
|
||||
public function setDeveloperKey($key) {$this->key = $key;}
|
||||
public function authenticate($service) {/*noop*/}
|
||||
public function setAccessToken($accessToken) {/* noop*/}
|
||||
public function getAccessToken() {return null;}
|
||||
public function createAuthUrl($scope) {return null;}
|
||||
public function refreshToken($refreshToken) {/* noop*/}
|
||||
public function revokeToken() {/* noop*/}
|
||||
|
||||
public function sign(Google_HttpRequest $request) {
|
||||
if ($this->key) {
|
||||
$request->setUrl($request->getUrl() . ((strpos($request->getUrl(), '?') === false) ? '?' : '&')
|
||||
. 'key='.urlencode($this->key));
|
||||
}
|
||||
return $request;
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold information about an authenticated login.
|
||||
*
|
||||
* @author Brian Eaton <beaton@google.com>
|
||||
*/
|
||||
class Google_LoginTicket {
|
||||
const USER_ATTR = "id";
|
||||
|
||||
// Information from id token envelope.
|
||||
private $envelope;
|
||||
|
||||
// Information from id token payload.
|
||||
private $payload;
|
||||
|
||||
/**
|
||||
* Creates a user based on the supplied token.
|
||||
*
|
||||
* @param string $envelope Header from a verified authentication token.
|
||||
* @param string $payload Information from a verified authentication token.
|
||||
*/
|
||||
public function __construct($envelope, $payload) {
|
||||
$this->envelope = $envelope;
|
||||
$this->payload = $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the numeric identifier for the user.
|
||||
* @throws Google_AuthException
|
||||
* @return
|
||||
*/
|
||||
public function getUserId() {
|
||||
if (array_key_exists(self::USER_ATTR, $this->payload)) {
|
||||
return $this->payload[self::USER_ATTR];
|
||||
}
|
||||
throw new Google_AuthException("No user_id in token");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns attributes from the login ticket. This can contain
|
||||
* various information about the user session.
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes() {
|
||||
return array("envelope" => $this->envelope, "payload" => $this->payload);
|
||||
}
|
||||
}
|
@ -0,0 +1,453 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2008 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once "Google_Verifier.php";
|
||||
require_once "Google_LoginTicket.php";
|
||||
require_once "service/Google_Utils.php";
|
||||
|
||||
/**
|
||||
* Authentication class that deals with the OAuth 2 web-server authentication flow
|
||||
*
|
||||
* @author Chris Chabot <chabotc@google.com>
|
||||
* @author Chirag Shah <chirags@google.com>
|
||||
*
|
||||
*/
|
||||
class Google_OAuth2 extends Google_Auth {
|
||||
public $clientId;
|
||||
public $clientSecret;
|
||||
public $developerKey;
|
||||
public $token;
|
||||
public $redirectUri;
|
||||
public $state;
|
||||
public $accessType = 'offline';
|
||||
public $approvalPrompt = 'force';
|
||||
public $requestVisibleActions;
|
||||
|
||||
/** @var Google_AssertionCredentials $assertionCredentials */
|
||||
public $assertionCredentials;
|
||||
|
||||
const OAUTH2_REVOKE_URI = 'https://accounts.google.com/o/oauth2/revoke';
|
||||
const OAUTH2_TOKEN_URI = 'https://accounts.google.com/o/oauth2/token';
|
||||
const OAUTH2_AUTH_URL = 'https://accounts.google.com/o/oauth2/auth';
|
||||
const OAUTH2_FEDERATED_SIGNON_CERTS_URL = 'https://www.googleapis.com/oauth2/v1/certs';
|
||||
const CLOCK_SKEW_SECS = 300; // five minutes in seconds
|
||||
const AUTH_TOKEN_LIFETIME_SECS = 300; // five minutes in seconds
|
||||
const MAX_TOKEN_LIFETIME_SECS = 86400; // one day in seconds
|
||||
|
||||
/**
|
||||
* Instantiates the class, but does not initiate the login flow, leaving it
|
||||
* to the discretion of the caller (which is done by calling authenticate()).
|
||||
*/
|
||||
public function __construct() {
|
||||
global $apiConfig;
|
||||
|
||||
if (! empty($apiConfig['developer_key'])) {
|
||||
$this->developerKey = $apiConfig['developer_key'];
|
||||
}
|
||||
|
||||
if (! empty($apiConfig['oauth2_client_id'])) {
|
||||
$this->clientId = $apiConfig['oauth2_client_id'];
|
||||
}
|
||||
|
||||
if (! empty($apiConfig['oauth2_client_secret'])) {
|
||||
$this->clientSecret = $apiConfig['oauth2_client_secret'];
|
||||
}
|
||||
|
||||
if (! empty($apiConfig['oauth2_redirect_uri'])) {
|
||||
$this->redirectUri = $apiConfig['oauth2_redirect_uri'];
|
||||
}
|
||||
|
||||
if (! empty($apiConfig['oauth2_access_type'])) {
|
||||
$this->accessType = $apiConfig['oauth2_access_type'];
|
||||
}
|
||||
|
||||
if (! empty($apiConfig['oauth2_approval_prompt'])) {
|
||||
$this->approvalPrompt = $apiConfig['oauth2_approval_prompt'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $service
|
||||
* @param string|null $code
|
||||
* @throws Google_AuthException
|
||||
* @return string
|
||||
*/
|
||||
public function authenticate($service, $code = null) {
|
||||
if (!$code && isset($_GET['code'])) {
|
||||
$code = $_GET['code'];
|
||||
}
|
||||
|
||||
if ($code) {
|
||||
// We got here from the redirect from a successful authorization grant, fetch the access token
|
||||
$request = Google_Client::$io->makeRequest(new Google_HttpRequest(self::OAUTH2_TOKEN_URI, 'POST', array(), array(
|
||||
'code' => $code,
|
||||
'grant_type' => 'authorization_code',
|
||||
'redirect_uri' => $this->redirectUri,
|
||||
'client_id' => $this->clientId,
|
||||
'client_secret' => $this->clientSecret
|
||||
)));
|
||||
|
||||
if ($request->getResponseHttpCode() == 200) {
|
||||
$this->setAccessToken($request->getResponseBody());
|
||||
$this->token['created'] = time();
|
||||
return $this->getAccessToken();
|
||||
} else {
|
||||
$response = $request->getResponseBody();
|
||||
$decodedResponse = json_decode($response, true);
|
||||
if ($decodedResponse != null && $decodedResponse['error']) {
|
||||
$response = $decodedResponse['error'];
|
||||
}
|
||||
throw new Google_AuthException("Error fetching OAuth2 access token, message: '$response'", $request->getResponseHttpCode());
|
||||
}
|
||||
}
|
||||
|
||||
$authUrl = $this->createAuthUrl($service['scope']);
|
||||
header('Location: ' . $authUrl);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a URL to obtain user authorization.
|
||||
* The authorization endpoint allows the user to first
|
||||
* authenticate, and then grant/deny the access request.
|
||||
* @param string $scope The scope is expressed as a list of space-delimited strings.
|
||||
* @return string
|
||||
*/
|
||||
public function createAuthUrl($scope) {
|
||||
$params = array(
|
||||
'response_type=code',
|
||||
'redirect_uri=' . urlencode($this->redirectUri),
|
||||
'client_id=' . urlencode($this->clientId),
|
||||
'scope=' . urlencode($scope),
|
||||
'access_type=' . urlencode($this->accessType),
|
||||
'approval_prompt=' . urlencode($this->approvalPrompt),
|
||||
);
|
||||
|
||||
// if the list of scopes contains plus.login, add request_visible_actions
|
||||
// to auth URL
|
||||
if(strpos($scope, 'plus.login') && count($this->requestVisibleActions) > 0) {
|
||||
$params[] = 'request_visible_actions=' .
|
||||
urlencode($this->requestVisibleActions);
|
||||
}
|
||||
|
||||
if (isset($this->state)) {
|
||||
$params[] = 'state=' . urlencode($this->state);
|
||||
}
|
||||
$params = implode('&', $params);
|
||||
return self::OAUTH2_AUTH_URL . "?$params";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $token
|
||||
* @throws Google_AuthException
|
||||
*/
|
||||
public function setAccessToken($token) {
|
||||
$token = json_decode($token, true);
|
||||
if ($token == null) {
|
||||
throw new Google_AuthException('Could not json decode the token');
|
||||
}
|
||||
if (! isset($token['access_token'])) {
|
||||
throw new Google_AuthException("Invalid token format");
|
||||
}
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
public function getAccessToken() {
|
||||
return json_encode($this->token);
|
||||
}
|
||||
|
||||
public function setDeveloperKey($developerKey) {
|
||||
$this->developerKey = $developerKey;
|
||||
}
|
||||
|
||||
public function setState($state) {
|
||||
$this->state = $state;
|
||||
}
|
||||
|
||||
public function setAccessType($accessType) {
|
||||
$this->accessType = $accessType;
|
||||
}
|
||||
|
||||
public function setApprovalPrompt($approvalPrompt) {
|
||||
$this->approvalPrompt = $approvalPrompt;
|
||||
}
|
||||
|
||||
public function setAssertionCredentials(Google_AssertionCredentials $creds) {
|
||||
$this->assertionCredentials = $creds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include an accessToken in a given apiHttpRequest.
|
||||
* @param Google_HttpRequest $request
|
||||
* @return Google_HttpRequest
|
||||
* @throws Google_AuthException
|
||||
*/
|
||||
public function sign(Google_HttpRequest $request) {
|
||||
// add the developer key to the request before signing it
|
||||
if ($this->developerKey) {
|
||||
$requestUrl = $request->getUrl();
|
||||
$requestUrl .= (strpos($request->getUrl(), '?') === false) ? '?' : '&';
|
||||
$requestUrl .= 'key=' . urlencode($this->developerKey);
|
||||
$request->setUrl($requestUrl);
|
||||
}
|
||||
|
||||
// Cannot sign the request without an OAuth access token.
|
||||
if (null == $this->token && null == $this->assertionCredentials) {
|
||||
return $request;
|
||||
}
|
||||
|
||||
// Check if the token is set to expire in the next 30 seconds
|
||||
// (or has already expired).
|
||||
if ($this->isAccessTokenExpired()) {
|
||||
if ($this->assertionCredentials) {
|
||||
$this->refreshTokenWithAssertion();
|
||||
} else {
|
||||
if (! array_key_exists('refresh_token', $this->token)) {
|
||||
throw new Google_AuthException("The OAuth 2.0 access token has expired, "
|
||||
. "and a refresh token is not available. Refresh tokens are not "
|
||||
. "returned for responses that were auto-approved.");
|
||||
}
|
||||
$this->refreshToken($this->token['refresh_token']);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the OAuth2 header to the request
|
||||
$request->setRequestHeaders(
|
||||
array('Authorization' => 'Bearer ' . $this->token['access_token'])
|
||||
);
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a fresh access token with the given refresh token.
|
||||
* @param string $refreshToken
|
||||
* @return void
|
||||
*/
|
||||
public function refreshToken($refreshToken) {
|
||||
$this->refreshTokenRequest(array(
|
||||
'client_id' => $this->clientId,
|
||||
'client_secret' => $this->clientSecret,
|
||||
'refresh_token' => $refreshToken,
|
||||
'grant_type' => 'refresh_token'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a fresh access token with a given assertion token.
|
||||
* @param Google_AssertionCredentials $assertionCredentials optional.
|
||||
* @return void
|
||||
*/
|
||||
public function refreshTokenWithAssertion($assertionCredentials = null) {
|
||||
if (!$assertionCredentials) {
|
||||
$assertionCredentials = $this->assertionCredentials;
|
||||
}
|
||||
|
||||
$this->refreshTokenRequest(array(
|
||||
'grant_type' => 'assertion',
|
||||
'assertion_type' => $assertionCredentials->assertionType,
|
||||
'assertion' => $assertionCredentials->generateAssertion(),
|
||||
));
|
||||
}
|
||||
|
||||
private function refreshTokenRequest($params) {
|
||||
$http = new Google_HttpRequest(self::OAUTH2_TOKEN_URI, 'POST', array(), $params);
|
||||
$request = Google_Client::$io->makeRequest($http);
|
||||
|
||||
$code = $request->getResponseHttpCode();
|
||||
$body = $request->getResponseBody();
|
||||
if (200 == $code) {
|
||||
$token = json_decode($body, true);
|
||||
if ($token == null) {
|
||||
throw new Google_AuthException("Could not json decode the access token");
|
||||
}
|
||||
|
||||
if (! isset($token['access_token']) || ! isset($token['expires_in'])) {
|
||||
throw new Google_AuthException("Invalid token format");
|
||||
}
|
||||
|
||||
$this->token['access_token'] = $token['access_token'];
|
||||
$this->token['expires_in'] = $token['expires_in'];
|
||||
$this->token['created'] = time();
|
||||
} else {
|
||||
throw new Google_AuthException("Error refreshing the OAuth2 token, message: '$body'", $code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke an OAuth2 access token or refresh token. This method will revoke the current access
|
||||
* token, if a token isn't provided.
|
||||
* @throws Google_AuthException
|
||||
* @param string|null $token The token (access token or a refresh token) that should be revoked.
|
||||
* @return boolean Returns True if the revocation was successful, otherwise False.
|
||||
*/
|
||||
public function revokeToken($token = null) {
|
||||
if (!$token) {
|
||||
$token = $this->token['access_token'];
|
||||
}
|
||||
$request = new Google_HttpRequest(self::OAUTH2_REVOKE_URI, 'POST', array(), "token=$token");
|
||||
$response = Google_Client::$io->makeRequest($request);
|
||||
$code = $response->getResponseHttpCode();
|
||||
if ($code == 200) {
|
||||
$this->token = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the access_token is expired.
|
||||
* @return bool Returns True if the access_token is expired.
|
||||
*/
|
||||
public function isAccessTokenExpired() {
|
||||
if (null == $this->token) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the token is set to expire in the next 30 seconds.
|
||||
$expired = ($this->token['created']
|
||||
+ ($this->token['expires_in'] - 30)) < time();
|
||||
|
||||
return $expired;
|
||||
}
|
||||
|
||||
// Gets federated sign-on certificates to use for verifying identity tokens.
|
||||
// Returns certs as array structure, where keys are key ids, and values
|
||||
// are PEM encoded certificates.
|
||||
private function getFederatedSignOnCerts() {
|
||||
// This relies on makeRequest caching certificate responses.
|
||||
$request = Google_Client::$io->makeRequest(new Google_HttpRequest(
|
||||
self::OAUTH2_FEDERATED_SIGNON_CERTS_URL));
|
||||
if ($request->getResponseHttpCode() == 200) {
|
||||
$certs = json_decode($request->getResponseBody(), true);
|
||||
if ($certs) {
|
||||
return $certs;
|
||||
}
|
||||
}
|
||||
throw new Google_AuthException(
|
||||
"Failed to retrieve verification certificates: '" .
|
||||
$request->getResponseBody() . "'.",
|
||||
$request->getResponseHttpCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies an id token and returns the authenticated apiLoginTicket.
|
||||
* Throws an exception if the id token is not valid.
|
||||
* The audience parameter can be used to control which id tokens are
|
||||
* accepted. By default, the id token must have been issued to this OAuth2 client.
|
||||
*
|
||||
* @param $id_token
|
||||
* @param $audience
|
||||
* @return Google_LoginTicket
|
||||
*/
|
||||
public function verifyIdToken($id_token = null, $audience = null) {
|
||||
if (!$id_token) {
|
||||
$id_token = $this->token['id_token'];
|
||||
}
|
||||
|
||||
$certs = $this->getFederatedSignonCerts();
|
||||
if (!$audience) {
|
||||
$audience = $this->clientId;
|
||||
}
|
||||
return $this->verifySignedJwtWithCerts($id_token, $certs, $audience);
|
||||
}
|
||||
|
||||
// Verifies the id token, returns the verified token contents.
|
||||
// Visible for testing.
|
||||
function verifySignedJwtWithCerts($jwt, $certs, $required_audience) {
|
||||
$segments = explode(".", $jwt);
|
||||
if (count($segments) != 3) {
|
||||
throw new Google_AuthException("Wrong number of segments in token: $jwt");
|
||||
}
|
||||
$signed = $segments[0] . "." . $segments[1];
|
||||
$signature = Google_Utils::urlSafeB64Decode($segments[2]);
|
||||
|
||||
// Parse envelope.
|
||||
$envelope = json_decode(Google_Utils::urlSafeB64Decode($segments[0]), true);
|
||||
if (!$envelope) {
|
||||
throw new Google_AuthException("Can't parse token envelope: " . $segments[0]);
|
||||
}
|
||||
|
||||
// Parse token
|
||||
$json_body = Google_Utils::urlSafeB64Decode($segments[1]);
|
||||
$payload = json_decode($json_body, true);
|
||||
if (!$payload) {
|
||||
throw new Google_AuthException("Can't parse token payload: " . $segments[1]);
|
||||
}
|
||||
|
||||
// Check signature
|
||||
$verified = false;
|
||||
foreach ($certs as $keyName => $pem) {
|
||||
$public_key = new Google_PemVerifier($pem);
|
||||
if ($public_key->verify($signed, $signature)) {
|
||||
$verified = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$verified) {
|
||||
throw new Google_AuthException("Invalid token signature: $jwt");
|
||||
}
|
||||
|
||||
// Check issued-at timestamp
|
||||
$iat = 0;
|
||||
if (array_key_exists("iat", $payload)) {
|
||||
$iat = $payload["iat"];
|
||||
}
|
||||
if (!$iat) {
|
||||
throw new Google_AuthException("No issue time in token: $json_body");
|
||||
}
|
||||
$earliest = $iat - self::CLOCK_SKEW_SECS;
|
||||
|
||||
// Check expiration timestamp
|
||||
$now = time();
|
||||
$exp = 0;
|
||||
if (array_key_exists("exp", $payload)) {
|
||||
$exp = $payload["exp"];
|
||||
}
|
||||
if (!$exp) {
|
||||
throw new Google_AuthException("No expiration time in token: $json_body");
|
||||
}
|
||||
if ($exp >= $now + self::MAX_TOKEN_LIFETIME_SECS) {
|
||||
throw new Google_AuthException(
|
||||
"Expiration time too far in future: $json_body");
|
||||
}
|
||||
|
||||
$latest = $exp + self::CLOCK_SKEW_SECS;
|
||||
if ($now < $earliest) {
|
||||
throw new Google_AuthException(
|
||||
"Token used too early, $now < $earliest: $json_body");
|
||||
}
|
||||
if ($now > $latest) {
|
||||
throw new Google_AuthException(
|
||||
"Token used too late, $now > $latest: $json_body");
|
||||
}
|
||||
|
||||
// TODO(beaton): check issuer field?
|
||||
|
||||
// Check audience
|
||||
$aud = $payload["aud"];
|
||||
if ($aud != $required_audience) {
|
||||
throw new Google_AuthException("Wrong recipient, $aud != $required_audience: $json_body");
|
||||
}
|
||||
|
||||
// All good.
|
||||
return new Google_LoginTicket($envelope, $payload);
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Signs data.
|
||||
*
|
||||
* Only used for testing.
|
||||
*
|
||||
* @author Brian Eaton <beaton@google.com>
|
||||
*/
|
||||
class Google_P12Signer extends Google_Signer {
|
||||
// OpenSSL private key resource
|
||||
private $privateKey;
|
||||
|
||||
// Creates a new signer from a .p12 file.
|
||||
function __construct($p12, $password) {
|
||||
if (!function_exists('openssl_x509_read')) {
|
||||
throw new Exception(
|
||||
'The Google PHP API library needs the openssl PHP extension');
|
||||
}
|
||||
|
||||
// This throws on error
|
||||
$certs = array();
|
||||
if (!openssl_pkcs12_read($p12, $certs, $password)) {
|
||||
throw new Google_AuthException("Unable to parse the p12 file. " .
|
||||
"Is this a .p12 file? Is the password correct? OpenSSL error: " .
|
||||
openssl_error_string());
|
||||
}
|
||||
// TODO(beaton): is this part of the contract for the openssl_pkcs12_read
|
||||
// method? What happens if there are multiple private keys? Do we care?
|
||||
if (!array_key_exists("pkey", $certs) || !$certs["pkey"]) {
|
||||
throw new Google_AuthException("No private key found in p12 file.");
|
||||
}
|
||||
$this->privateKey = openssl_pkey_get_private($certs["pkey"]);
|
||||
if (!$this->privateKey) {
|
||||
throw new Google_AuthException("Unable to load private key in ");
|
||||
}
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
if ($this->privateKey) {
|
||||
openssl_pkey_free($this->privateKey);
|
||||
}
|
||||
}
|
||||
|
||||
function sign($data) {
|
||||
if(version_compare(PHP_VERSION, '5.3.0') < 0) {
|
||||
throw new Google_AuthException(
|
||||
"PHP 5.3.0 or higher is required to use service accounts.");
|
||||
}
|
||||
if (!openssl_sign($data, $signature, $this->privateKey, "sha256")) {
|
||||
throw new Google_AuthException("Unable to sign data");
|
||||
}
|
||||
return $signature;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Verifies signatures using PEM encoded certificates.
|
||||
*
|
||||
* @author Brian Eaton <beaton@google.com>
|
||||
*/
|
||||
class Google_PemVerifier extends Google_Verifier {
|
||||
private $publicKey;
|
||||
|
||||
/**
|
||||
* Constructs a verifier from the supplied PEM-encoded certificate.
|
||||
*
|
||||
* $pem: a PEM encoded certificate (not a file).
|
||||
* @param $pem
|
||||
* @throws Google_AuthException
|
||||
* @throws Google_Exception
|
||||
*/
|
||||
function __construct($pem) {
|
||||
if (!function_exists('openssl_x509_read')) {
|
||||
throw new Google_Exception('Google API PHP client needs the openssl PHP extension');
|
||||
}
|
||||
$this->publicKey = openssl_x509_read($pem);
|
||||
if (!$this->publicKey) {
|
||||
throw new Google_AuthException("Unable to parse PEM: $pem");
|
||||
}
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
if ($this->publicKey) {
|
||||
openssl_x509_free($this->publicKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the signature on data.
|
||||
*
|
||||
* Returns true if the signature is valid, false otherwise.
|
||||
* @param $data
|
||||
* @param $signature
|
||||
* @throws Google_AuthException
|
||||
* @return bool
|
||||
*/
|
||||
function verify($data, $signature) {
|
||||
$status = openssl_verify($data, $signature, $this->publicKey, "sha256");
|
||||
if ($status === -1) {
|
||||
throw new Google_AuthException('Signature verification error: ' . openssl_error_string());
|
||||
}
|
||||
return $status === 1;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once "Google_P12Signer.php";
|
||||
|
||||
/**
|
||||
* Signs data.
|
||||
*
|
||||
* @author Brian Eaton <beaton@google.com>
|
||||
*/
|
||||
abstract class Google_Signer {
|
||||
/**
|
||||
* Signs data, returns the signature as binary data.
|
||||
*/
|
||||
abstract public function sign($data);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once "Google_PemVerifier.php";
|
||||
|
||||
/**
|
||||
* Verifies signatures.
|
||||
*
|
||||
* @author Brian Eaton <beaton@google.com>
|
||||
*/
|
||||
abstract class Google_Verifier {
|
||||
/**
|
||||
* Checks a signature, returns true if the signature is correct,
|
||||
* false otherwise.
|
||||
*/
|
||||
abstract public function verify($data, $signature);
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A persistent storage class based on the APC cache, which is not
|
||||
* really very persistent, as soon as you restart your web server
|
||||
* the storage will be wiped, however for debugging and/or speed
|
||||
* it can be useful, kinda, and cache is a lot cheaper then storage.
|
||||
*
|
||||
* @author Chris Chabot <chabotc@google.com>
|
||||
*/
|
||||
class Google_APCCache extends Google_Cache {
|
||||
|
||||
public function __construct() {
|
||||
if (! function_exists('apc_add')) {
|
||||
throw new Google_CacheException("Apc functions not available");
|
||||
}
|
||||
}
|
||||
|
||||
private function isLocked($key) {
|
||||
if ((@apc_fetch($key . '.lock')) === false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function createLock($key) {
|
||||
// the interesting thing is that this could fail if the lock was created in the meantime..
|
||||
// but we'll ignore that out of convenience
|
||||
@apc_add($key . '.lock', '', 5);
|
||||
}
|
||||
|
||||
private function removeLock($key) {
|
||||
// suppress all warnings, if some other process removed it that's ok too
|
||||
@apc_delete($key . '.lock');
|
||||
}
|
||||
|
||||
private function waitForLock($key) {
|
||||
// 20 x 250 = 5 seconds
|
||||
$tries = 20;
|
||||
$cnt = 0;
|
||||
do {
|
||||
// 250 ms is a long time to sleep, but it does stop the server from burning all resources on polling locks..
|
||||
usleep(250);
|
||||
$cnt ++;
|
||||
} while ($cnt <= $tries && $this->isLocked($key));
|
||||
if ($this->isLocked($key)) {
|
||||
// 5 seconds passed, assume the owning process died off and remove it
|
||||
$this->removeLock($key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($key, $expiration = false) {
|
||||
|
||||
if (($ret = @apc_fetch($key)) === false) {
|
||||
return false;
|
||||
}
|
||||
if (!$expiration || (time() - $ret['time'] > $expiration)) {
|
||||
$this->delete($key);
|
||||
return false;
|
||||
}
|
||||
return unserialize($ret['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function set($key, $value) {
|
||||
if (@apc_store($key, array('time' => time(), 'data' => serialize($value))) == false) {
|
||||
throw new Google_CacheException("Couldn't store data");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param String $key
|
||||
*/
|
||||
public function delete($key) {
|
||||
@apc_delete($key);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2008 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once "Google_FileCache.php";
|
||||
require_once "Google_MemcacheCache.php";
|
||||
|
||||
/**
|
||||
* Abstract storage class
|
||||
*
|
||||
* @author Chris Chabot <chabotc@google.com>
|
||||
*/
|
||||
abstract class Google_Cache {
|
||||
|
||||
/**
|
||||
* Retrieves the data for the given key, or false if they
|
||||
* key is unknown or expired
|
||||
*
|
||||
* @param String $key The key who's data to retrieve
|
||||
* @param boolean|int $expiration Expiration time in seconds
|
||||
*
|
||||
*/
|
||||
abstract function get($key, $expiration = false);
|
||||
|
||||
/**
|
||||
* Store the key => $value set. The $value is serialized
|
||||
* by this function so can be of any type
|
||||
*
|
||||
* @param string $key Key of the data
|
||||
* @param string $value data
|
||||
*/
|
||||
abstract function set($key, $value);
|
||||
|
||||
/**
|
||||
* Removes the key/data pair for the given $key
|
||||
*
|
||||
* @param String $key
|
||||
*/
|
||||
abstract function delete($key);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2008 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This class implements a basic on disk storage. While that does
|
||||
* work quite well it's not the most elegant and scalable solution.
|
||||
* It will also get you into a heap of trouble when you try to run
|
||||
* this in a clustered environment. In those cases please use the
|
||||
* MySql back-end
|
||||
*
|
||||
* @author Chris Chabot <chabotc@google.com>
|
||||
*/
|
||||
class Google_FileCache extends Google_Cache {
|
||||
private $path;
|
||||
|
||||
public function __construct() {
|
||||
global $apiConfig;
|
||||
$this->path = $apiConfig['ioFileCache_directory'];
|
||||
}
|
||||
|
||||
private function isLocked($storageFile) {
|
||||
// our lock file convention is simple: /the/file/path.lock
|
||||
return file_exists($storageFile . '.lock');
|
||||
}
|
||||
|
||||
private function createLock($storageFile) {
|
||||
$storageDir = dirname($storageFile);
|
||||
if (! is_dir($storageDir)) {
|
||||
// @codeCoverageIgnoreStart
|
||||
if (! @mkdir($storageDir, 0755, true)) {
|
||||
// make sure the failure isn't because of a concurrency issue
|
||||
if (! is_dir($storageDir)) {
|
||||
throw new Google_CacheException("Could not create storage directory: $storageDir");
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
@touch($storageFile . '.lock');
|
||||
}
|
||||
|
||||
private function removeLock($storageFile) {
|
||||
// suppress all warnings, if some other process removed it that's ok too
|
||||
@unlink($storageFile . '.lock');
|
||||
}
|
||||
|
||||
private function waitForLock($storageFile) {
|
||||
// 20 x 250 = 5 seconds
|
||||
$tries = 20;
|
||||
$cnt = 0;
|
||||
do {
|
||||
// make sure PHP picks up on file changes. This is an expensive action but really can't be avoided
|
||||
clearstatcache();
|
||||
// 250 ms is a long time to sleep, but it does stop the server from burning all resources on polling locks..
|
||||
usleep(250);
|
||||
$cnt ++;
|
||||
} while ($cnt <= $tries && $this->isLocked($storageFile));
|
||||
if ($this->isLocked($storageFile)) {
|
||||
// 5 seconds passed, assume the owning process died off and remove it
|
||||
$this->removeLock($storageFile);
|
||||
}
|
||||
}
|
||||
|
||||
private function getCacheDir($hash) {
|
||||
// use the first 2 characters of the hash as a directory prefix
|
||||
// this should prevent slowdowns due to huge directory listings
|
||||
// and thus give some basic amount of scalability
|
||||
return $this->path . '/' . substr($hash, 0, 2);
|
||||
}
|
||||
|
||||
private function getCacheFile($hash) {
|
||||
return $this->getCacheDir($hash) . '/' . $hash;
|
||||
}
|
||||
|
||||
public function get($key, $expiration = false) {
|
||||
$storageFile = $this->getCacheFile(md5($key));
|
||||
// See if this storage file is locked, if so we wait up to 5 seconds for the lock owning process to
|
||||
// complete it's work. If the lock is not released within that time frame, it's cleaned up.
|
||||
// This should give us a fair amount of 'Cache Stampeding' protection
|
||||
if ($this->isLocked($storageFile)) {
|
||||
$this->waitForLock($storageFile);
|
||||
}
|
||||
if (file_exists($storageFile) && is_readable($storageFile)) {
|
||||
$now = time();
|
||||
if (! $expiration || (($mtime = @filemtime($storageFile)) !== false && ($now - $mtime) < $expiration)) {
|
||||
if (($data = @file_get_contents($storageFile)) !== false) {
|
||||
$data = unserialize($data);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function set($key, $value) {
|
||||
$storageDir = $this->getCacheDir(md5($key));
|
||||
$storageFile = $this->getCacheFile(md5($key));
|
||||
if ($this->isLocked($storageFile)) {
|
||||
// some other process is writing to this file too, wait until it's done to prevent hiccups
|
||||
$this->waitForLock($storageFile);
|
||||
}
|
||||
if (! is_dir($storageDir)) {
|
||||
if (! @mkdir($storageDir, 0755, true)) {
|
||||
throw new Google_CacheException("Could not create storage directory: $storageDir");
|
||||
}
|
||||
}
|
||||
// we serialize the whole request object, since we don't only want the
|
||||
// responseContent but also the postBody used, headers, size, etc
|
||||
$data = serialize($value);
|
||||
$this->createLock($storageFile);
|
||||
if (! @file_put_contents($storageFile, $data)) {
|
||||
$this->removeLock($storageFile);
|
||||
throw new Google_CacheException("Could not store data in the file");
|
||||
}
|
||||
$this->removeLock($storageFile);
|
||||
}
|
||||
|
||||
public function delete($key) {
|
||||
$file = $this->getCacheFile(md5($key));
|
||||
if (! @unlink($file)) {
|
||||
throw new Google_CacheException("Cache file could not be deleted");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2008 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A persistent storage class based on the memcache, which is not
|
||||
* really very persistent, as soon as you restart your memcache daemon
|
||||
* the storage will be wiped, however for debugging and/or speed
|
||||
* it can be useful, kinda, and cache is a lot cheaper then storage.
|
||||
*
|
||||
* @author Chris Chabot <chabotc@google.com>
|
||||
*/
|
||||
class Google_MemcacheCache extends Google_Cache {
|
||||
private $connection = false;
|
||||
|
||||
public function __construct() {
|
||||
global $apiConfig;
|
||||
if (! function_exists('memcache_connect')) {
|
||||
throw new Google_CacheException("Memcache functions not available");
|
||||
}
|
||||
$this->host = $apiConfig['ioMemCacheCache_host'];
|
||||
$this->port = $apiConfig['ioMemCacheCache_port'];
|
||||
if (empty($this->host) || empty($this->port)) {
|
||||
throw new Google_CacheException("You need to supply a valid memcache host and port");
|
||||
}
|
||||
}
|
||||
|
||||
private function isLocked($key) {
|
||||
$this->check();
|
||||
if ((@memcache_get($this->connection, $key . '.lock')) === false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function createLock($key) {
|
||||
$this->check();
|
||||
// the interesting thing is that this could fail if the lock was created in the meantime..
|
||||
// but we'll ignore that out of convenience
|
||||
@memcache_add($this->connection, $key . '.lock', '', 0, 5);
|
||||
}
|
||||
|
||||
private function removeLock($key) {
|
||||
$this->check();
|
||||
// suppress all warnings, if some other process removed it that's ok too
|
||||
@memcache_delete($this->connection, $key . '.lock');
|
||||
}
|
||||
|
||||
private function waitForLock($key) {
|
||||
$this->check();
|
||||
// 20 x 250 = 5 seconds
|
||||
$tries = 20;
|
||||
$cnt = 0;
|
||||
do {
|
||||
// 250 ms is a long time to sleep, but it does stop the server from burning all resources on polling locks..
|
||||
usleep(250);
|
||||
$cnt ++;
|
||||
} while ($cnt <= $tries && $this->isLocked($key));
|
||||
if ($this->isLocked($key)) {
|
||||
// 5 seconds passed, assume the owning process died off and remove it
|
||||
$this->removeLock($key);
|
||||
}
|
||||
}
|
||||
|
||||
// I prefer lazy initialization since the cache isn't used every request
|
||||
// so this potentially saves a lot of overhead
|
||||
private function connect() {
|
||||
if (! $this->connection = @memcache_pconnect($this->host, $this->port)) {
|
||||
throw new Google_CacheException("Couldn't connect to memcache server");
|
||||
}
|
||||
}
|
||||
|
||||
private function check() {
|
||||
if (! $this->connection) {
|
||||
$this->connect();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($key, $expiration = false) {
|
||||
$this->check();
|
||||
if (($ret = @memcache_get($this->connection, $key)) === false) {
|
||||
return false;
|
||||
}
|
||||
if (is_numeric($expiration) && (time() - $ret['time'] > $expiration)) {
|
||||
$this->delete($key);
|
||||
return false;
|
||||
}
|
||||
return $ret['data'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @throws Google_CacheException
|
||||
*/
|
||||
public function set($key, $value) {
|
||||
$this->check();
|
||||
// we store it with the cache_time default expiration so objects will at least get cleaned eventually.
|
||||
if (@memcache_set($this->connection, $key, array('time' => time(),
|
||||
'data' => $value), false) == false) {
|
||||
throw new Google_CacheException("Couldn't store data in cache");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param String $key
|
||||
*/
|
||||
public function delete($key) {
|
||||
$this->check();
|
||||
@memcache_delete($this->connection, $key);
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
global $apiConfig;
|
||||
$apiConfig = array(
|
||||
// True if objects should be returned by the service classes.
|
||||
// False if associative arrays should be returned (default behavior).
|
||||
'use_objects' => false,
|
||||
|
||||
// The application_name is included in the User-Agent HTTP header.
|
||||
'application_name' => '',
|
||||
|
||||
// OAuth2 Settings, you can get these keys at https://code.google.com/apis/console
|
||||
'oauth2_client_id' => '',
|
||||
'oauth2_client_secret' => '',
|
||||
'oauth2_redirect_uri' => '',
|
||||
|
||||
// The developer key, you get this at https://code.google.com/apis/console
|
||||
'developer_key' => '',
|
||||
|
||||
// Site name to show in the Google's OAuth 1 authentication screen.
|
||||
'site_name' => 'www.example.org',
|
||||
|
||||
// Which Authentication, Storage and HTTP IO classes to use.
|
||||
'authClass' => 'Google_OAuth2',
|
||||
'ioClass' => 'Google_CurlIO',
|
||||
'cacheClass' => 'Google_FileCache',
|
||||
|
||||
// Don't change these unless you're working against a special development or testing environment.
|
||||
'basePath' => 'https://www.googleapis.com',
|
||||
|
||||
// IO Class dependent configuration, you only have to configure the values
|
||||
// for the class that was configured as the ioClass above
|
||||
'ioFileCache_directory' =>
|
||||
(function_exists('sys_get_temp_dir') ?
|
||||
sys_get_temp_dir() . '/Google_Client' :
|
||||
'/tmp/Google_Client'),
|
||||
|
||||
// Definition of service specific values like scopes, oauth token URLs, etc
|
||||
'services' => array(
|
||||
'analytics' => array('scope' => 'https://www.googleapis.com/auth/analytics.readonly'),
|
||||
'calendar' => array(
|
||||
'scope' => array(
|
||||
"https://www.googleapis.com/auth/calendar",
|
||||
"https://www.googleapis.com/auth/calendar.readonly",
|
||||
)
|
||||
),
|
||||
'books' => array('scope' => 'https://www.googleapis.com/auth/books'),
|
||||
'latitude' => array(
|
||||
'scope' => array(
|
||||
'https://www.googleapis.com/auth/latitude.all.best',
|
||||
'https://www.googleapis.com/auth/latitude.all.city',
|
||||
)
|
||||
),
|
||||
'moderator' => array('scope' => 'https://www.googleapis.com/auth/moderator'),
|
||||
'oauth2' => array(
|
||||
'scope' => array(
|
||||
'https://www.googleapis.com/auth/userinfo.profile',
|
||||
'https://www.googleapis.com/auth/userinfo.email',
|
||||
)
|
||||
),
|
||||
'plus' => array('scope' => 'https://www.googleapis.com/auth/plus.login'),
|
||||
'siteVerification' => array('scope' => 'https://www.googleapis.com/auth/siteverification'),
|
||||
'tasks' => array('scope' => 'https://www.googleapis.com/auth/tasks'),
|
||||
'urlshortener' => array('scope' => 'https://www.googleapis.com/auth/urlshortener')
|
||||
)
|
||||
);
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright (c) 2010 Kevin M Burns Jr, http://kevburnsjr.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A URI Template Parser which is used by the apiREST class to resolve the REST requests
|
||||
* Blogpost: http://lab.kevburnsjr.com/php-uri-template-parser
|
||||
* Source: http://github.com/KevBurnsJr/php-uri-template-parser
|
||||
*/
|
||||
class URI_Template_Parser {
|
||||
|
||||
public static $operators = array('+', ';', '?', '/', '.');
|
||||
public static $reserved_operators = array('|', '!', '@');
|
||||
public static $explode_modifiers = array('+', '*');
|
||||
public static $partial_modifiers = array(':', '^');
|
||||
|
||||
public static $gen_delims = array(':', '/', '?', '#', '[', ']', '@');
|
||||
public static $gen_delims_pct = array('%3A', '%2F', '%3F', '%23', '%5B', '%5D', '%40');
|
||||
public static $sub_delims = array('!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=');
|
||||
public static $sub_delims_pct = array('%21', '%24', '%26', '%27', '%28', '%29', '%2A', '%2B', '%2C', '%3B', '%3D');
|
||||
public static $reserved;
|
||||
public static $reserved_pct;
|
||||
|
||||
public function __construct($template) {
|
||||
self::$reserved = array_merge(self::$gen_delims, self::$sub_delims);
|
||||
self::$reserved_pct = array_merge(self::$gen_delims_pct, self::$sub_delims_pct);
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
public function expand($data) {
|
||||
// Modification to make this a bit more performant (since gettype is very slow)
|
||||
if (! is_array($data)) {
|
||||
$data = (array)$data;
|
||||
}
|
||||
/*
|
||||
// Original code, which uses a slow gettype() statement, kept in place for if the assumption that is_array always works here is incorrect
|
||||
switch (gettype($data)) {
|
||||
case "boolean":
|
||||
case "integer":
|
||||
case "double":
|
||||
case "string":
|
||||
case "object":
|
||||
$data = (array)$data;
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
// Resolve template vars
|
||||
preg_match_all('/\{([^\}]*)\}/', $this->template, $em);
|
||||
|
||||
foreach ($em[1] as $i => $bare_expression) {
|
||||
preg_match('/^([\+\;\?\/\.]{1})?(.*)$/', $bare_expression, $lm);
|
||||
$exp = new StdClass();
|
||||
$exp->expression = $em[0][$i];
|
||||
$exp->operator = $lm[1];
|
||||
$exp->variable_list = $lm[2];
|
||||
$exp->varspecs = explode(',', $exp->variable_list);
|
||||
$exp->vars = array();
|
||||
foreach ($exp->varspecs as $varspec) {
|
||||
preg_match('/^([a-zA-Z0-9_]+)([\*\+]{1})?([\:\^][0-9-]+)?(\=[^,]+)?$/', $varspec, $vm);
|
||||
$var = new StdClass();
|
||||
$var->name = $vm[1];
|
||||
$var->modifier = isset($vm[2]) && $vm[2] ? $vm[2] : null;
|
||||
$var->modifier = isset($vm[3]) && $vm[3] ? $vm[3] : $var->modifier;
|
||||
$var->default = isset($vm[4]) ? substr($vm[4], 1) : null;
|
||||
$exp->vars[] = $var;
|
||||
}
|
||||
|
||||
// Add processing flags
|
||||
$exp->reserved = false;
|
||||
$exp->prefix = '';
|
||||
$exp->delimiter = ',';
|
||||
switch ($exp->operator) {
|
||||
case '+':
|
||||
$exp->reserved = 'true';
|
||||
break;
|
||||
case ';':
|
||||
$exp->prefix = ';';
|
||||
$exp->delimiter = ';';
|
||||
break;
|
||||
case '?':
|
||||
$exp->prefix = '?';
|
||||
$exp->delimiter = '&';
|
||||
break;
|
||||
case '/':
|
||||
$exp->prefix = '/';
|
||||
$exp->delimiter = '/';
|
||||
break;
|
||||
case '.':
|
||||
$exp->prefix = '.';
|
||||
$exp->delimiter = '.';
|
||||
break;
|
||||
}
|
||||
$expressions[] = $exp;
|
||||
}
|
||||
|
||||
// Expansion
|
||||
$this->expansion = $this->template;
|
||||
|
||||
foreach ($expressions as $exp) {
|
||||
$part = $exp->prefix;
|
||||
$exp->one_var_defined = false;
|
||||
foreach ($exp->vars as $var) {
|
||||
$val = '';
|
||||
if ($exp->one_var_defined && isset($data[$var->name])) {
|
||||
$part .= $exp->delimiter;
|
||||
}
|
||||
// Variable present
|
||||
if (isset($data[$var->name])) {
|
||||
$exp->one_var_defined = true;
|
||||
$var->data = $data[$var->name];
|
||||
|
||||
$val = self::val_from_var($var, $exp);
|
||||
|
||||
// Variable missing
|
||||
} else {
|
||||
if ($var->default) {
|
||||
$exp->one_var_defined = true;
|
||||
$val = $var->default;
|
||||
}
|
||||
}
|
||||
$part .= $val;
|
||||
}
|
||||
if (! $exp->one_var_defined) $part = '';
|
||||
$this->expansion = str_replace($exp->expression, $part, $this->expansion);
|
||||
}
|
||||
|
||||
return $this->expansion;
|
||||
}
|
||||
|
||||
private function val_from_var($var, $exp) {
|
||||
$val = '';
|
||||
if (is_array($var->data)) {
|
||||
$i = 0;
|
||||
if ($exp->operator == '?' && ! $var->modifier) {
|
||||
$val .= $var->name . '=';
|
||||
}
|
||||
foreach ($var->data as $k => $v) {
|
||||
$del = $var->modifier ? $exp->delimiter : ',';
|
||||
$ek = rawurlencode($k);
|
||||
$ev = rawurlencode($v);
|
||||
|
||||
// Array
|
||||
if ($k !== $i) {
|
||||
if ($var->modifier == '+') {
|
||||
$val .= $var->name . '.';
|
||||
}
|
||||
if ($exp->operator == '?' && $var->modifier || $exp->operator == ';' && $var->modifier == '*' || $exp->operator == ';' && $var->modifier == '+') {
|
||||
$val .= $ek . '=';
|
||||
} else {
|
||||
$val .= $ek . $del;
|
||||
}
|
||||
|
||||
// List
|
||||
} else {
|
||||
if ($var->modifier == '+') {
|
||||
if ($exp->operator == ';' && $var->modifier == '*' || $exp->operator == ';' && $var->modifier == '+' || $exp->operator == '?' && $var->modifier == '+') {
|
||||
$val .= $var->name . '=';
|
||||
} else {
|
||||
$val .= $var->name . '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
$val .= $ev . $del;
|
||||
$i ++;
|
||||
}
|
||||
$val = trim($val, $del);
|
||||
|
||||
// Strings, numbers, etc.
|
||||
} else {
|
||||
if ($exp->operator == '?') {
|
||||
$val = $var->name . (isset($var->data) ? '=' : '');
|
||||
} else if ($exp->operator == ';') {
|
||||
$val = $var->name . ($var->data ? '=' : '');
|
||||
}
|
||||
$val .= rawurlencode($var->data);
|
||||
if ($exp->operator == '+') {
|
||||
$val = str_replace(self::$reserved_pct, self::$reserved, $val);
|
||||
}
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
public function match($uri) {}
|
||||
|
||||
public function __toString() {
|
||||
return $this->template;
|
||||
}
|
||||
}
|
@ -0,0 +1,173 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Implement the caching directives specified in rfc2616. This
|
||||
* implementation is guided by the guidance offered in rfc2616-sec13.
|
||||
* @author Chirag Shah <chirags@google.com>
|
||||
*/
|
||||
class Google_CacheParser {
|
||||
public static $CACHEABLE_HTTP_METHODS = array('GET', 'HEAD');
|
||||
public static $CACHEABLE_STATUS_CODES = array('200', '203', '300', '301');
|
||||
|
||||
private function __construct() {}
|
||||
|
||||
/**
|
||||
* Check if an HTTP request can be cached by a private local cache.
|
||||
*
|
||||
* @static
|
||||
* @param Google_HttpRequest $resp
|
||||
* @return bool True if the request is cacheable.
|
||||
* False if the request is uncacheable.
|
||||
*/
|
||||
public static function isRequestCacheable (Google_HttpRequest $resp) {
|
||||
$method = $resp->getRequestMethod();
|
||||
if (! in_array($method, self::$CACHEABLE_HTTP_METHODS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't cache authorized requests/responses.
|
||||
// [rfc2616-14.8] When a shared cache receives a request containing an
|
||||
// Authorization field, it MUST NOT return the corresponding response
|
||||
// as a reply to any other request...
|
||||
if ($resp->getRequestHeader("authorization")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an HTTP response can be cached by a private local cache.
|
||||
*
|
||||
* @static
|
||||
* @param Google_HttpRequest $resp
|
||||
* @return bool True if the response is cacheable.
|
||||
* False if the response is un-cacheable.
|
||||
*/
|
||||
public static function isResponseCacheable (Google_HttpRequest $resp) {
|
||||
// First, check if the HTTP request was cacheable before inspecting the
|
||||
// HTTP response.
|
||||
if (false == self::isRequestCacheable($resp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$code = $resp->getResponseHttpCode();
|
||||
if (! in_array($code, self::$CACHEABLE_STATUS_CODES)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The resource is uncacheable if the resource is already expired and
|
||||
// the resource doesn't have an ETag for revalidation.
|
||||
$etag = $resp->getResponseHeader("etag");
|
||||
if (self::isExpired($resp) && $etag == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// [rfc2616-14.9.2] If [no-store is] sent in a response, a cache MUST NOT
|
||||
// store any part of either this response or the request that elicited it.
|
||||
$cacheControl = $resp->getParsedCacheControl();
|
||||
if (isset($cacheControl['no-store'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Pragma: no-cache is an http request directive, but is occasionally
|
||||
// used as a response header incorrectly.
|
||||
$pragma = $resp->getResponseHeader('pragma');
|
||||
if ($pragma == 'no-cache' || strpos($pragma, 'no-cache') !== false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// [rfc2616-14.44] Vary: * is extremely difficult to cache. "It implies that
|
||||
// a cache cannot determine from the request headers of a subsequent request
|
||||
// whether this response is the appropriate representation."
|
||||
// Given this, we deem responses with the Vary header as uncacheable.
|
||||
$vary = $resp->getResponseHeader('vary');
|
||||
if ($vary) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param Google_HttpRequest $resp
|
||||
* @return bool True if the HTTP response is considered to be expired.
|
||||
* False if it is considered to be fresh.
|
||||
*/
|
||||
public static function isExpired(Google_HttpRequest $resp) {
|
||||
// HTTP/1.1 clients and caches MUST treat other invalid date formats,
|
||||
// especially including the value “0”, as in the past.
|
||||
$parsedExpires = false;
|
||||
$responseHeaders = $resp->getResponseHeaders();
|
||||
if (isset($responseHeaders['expires'])) {
|
||||
$rawExpires = $responseHeaders['expires'];
|
||||
// Check for a malformed expires header first.
|
||||
if (empty($rawExpires) || (is_numeric($rawExpires) && $rawExpires <= 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// See if we can parse the expires header.
|
||||
$parsedExpires = strtotime($rawExpires);
|
||||
if (false == $parsedExpires || $parsedExpires <= 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the freshness of an http response.
|
||||
$freshnessLifetime = false;
|
||||
$cacheControl = $resp->getParsedCacheControl();
|
||||
if (isset($cacheControl['max-age'])) {
|
||||
$freshnessLifetime = $cacheControl['max-age'];
|
||||
}
|
||||
|
||||
$rawDate = $resp->getResponseHeader('date');
|
||||
$parsedDate = strtotime($rawDate);
|
||||
|
||||
if (empty($rawDate) || false == $parsedDate) {
|
||||
$parsedDate = time();
|
||||
}
|
||||
if (false == $freshnessLifetime && isset($responseHeaders['expires'])) {
|
||||
$freshnessLifetime = $parsedExpires - $parsedDate;
|
||||
}
|
||||
|
||||
if (false == $freshnessLifetime) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Calculate the age of an http response.
|
||||
$age = max(0, time() - $parsedDate);
|
||||
if (isset($responseHeaders['age'])) {
|
||||
$age = max($age, strtotime($responseHeaders['age']));
|
||||
}
|
||||
|
||||
return $freshnessLifetime <= $age;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a cache entry should be revalidated with by the origin.
|
||||
*
|
||||
* @param Google_HttpRequest $response
|
||||
* @return bool True if the entry is expired, else return false.
|
||||
*/
|
||||
public static function mustRevalidate(Google_HttpRequest $response) {
|
||||
// [13.3] When a cache has a stale entry that it would like to use as a
|
||||
// response to a client's request, it first has to check with the origin
|
||||
// server to see if its cached entry is still usable.
|
||||
return self::isExpired($response);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue