落地页下载页优化

master
ELF 5 years ago
parent fc1cef9ec1
commit 89b243930d

81
1

@ -0,0 +1,81 @@
111111101001100000110010111001110100011110010111101110111111100110101000001111111
100000101101110101010010000011011000001010010110100011101011011000000111101000001
101110101001101100000101011111100000101011111111110000000000000110001010101011101
101110100011011110100101111010001110000000101111111111101000000001101010101011101
101110100110010010000110111110101101000101101101111110100100000010010000001011101
100000101010001101110100100010110100010011011110100010101110000001001001001000001
111111101010101010101010101010101010101010101010101010101010101010101010101111111
000000001010000100100001100011110100101001001010100010101001000110001111000000000
001110101001010000010001111110001111111111110111111111101010101100000011011100111
111101000000010101101110111000000001100010111011111010001100110110001110111001111
100011100101100001101001100011001000001000101100000011000110100100000100000111010
010001010010110101000011010011110101011111101110111110011010000110111100000100011
110111100001111111000001101111011010111101100100100011000100111111101010110100111
000101011000011000111111110101001110011101001000011100110101010100010000001001110
101001101000011110011110101010110011000111001100100000001111011011010010111010000
000011011101001000010001000000000111010110000101000100001011000001111110101001000
101001100011101011011011000111000010010110000110101110001001111111010111000101000
110001001110001100100101111100001001010100111000000000011110000100011110001111101
000011101001100111111010011101111110111001100100000001000000001110000011111100010
111011011100000110000101011110000011000100000010011100111110000010101100111101110
100110110010000011111010101000000100000100100100110001100110111111100111000000110
001110011011111100101011001001101001100001101000000100110111000100111100110010010
100010110010000111000111111001111001111111101000111111001010001111001100100000110
111111000101011011000011101011101100100101000010110000101000001001110101000001001
011111111010111101010101111111101000011101100010111110100111110101001001111111100
101110001011110010101001100010010010101000100100100010000111001100111100100010011
001010101011110001010100101011001010101011011110101010010010011110000110101010110
110010001001111100111101100010111001010111001000100010111110100011000010100011110
000111111001010110010010111111010110001101111110111111000101111101000110111110111
001101001101001110101000000100000110011011110110010110000111001011100100110100001
000000111011101000000111101111000110010000010011010010001100111010000110000101110
001100000100010010000011001011011100101000100101101110101111000001110011110111101
100011111000110101000000010001110010001100111010111111100100011101000101000001110
011101000011111110110111010110111010001110111001001000101111100000010100110000010
000011111111110000100101111101110111100010000000010000001010111011111010000101110
011000011100110111111000010100000111001010001110011110001100000110100011110111111
101001101000001100000000011100001101110100011111011010101011101100101011111000110
111011000101000101111111011111101010110001111010100000000001000010100101100111100
011000110010111000011001111011011101100000000101100011011011101110000010111110010
011000010111101110011010101011101111100111100011100110101101000110001011100101101
010111110010110010110010100001011110001110101000100001101010001101101110011001010
110011001100001110110001011011100101101100110111001110010101100111011101101010110
101001110011011001111010010010111001100101011000001011111110111100001011001101110
010011001010011111110011001000111000001101100000100111001110000110001110110100101
000011101111000011101110111100000010001100011001000111100010000111101110010001001
000110011111111110100101110011011011000111101011101000110010101111100100111100011
100111110101101101010100110000111100000110111001001110000100101111010110001100000
100111010001000000111101010011101100111100100101010101100101001000001101110001110
100011111000010111101001111110011011100001111000111111010110000110001100111111001
110110001101000000101100100010010000101111011110100011111100100000000111100010011
100110101100111100000010101011011010010101110111101010001010011111010110101010100
011110001100011000001010100010110101010001011110100011111010010101111011100011110
100111111010111111001010111110100101010111001000111110010010100000001100111111010
111000010110001000110101010101110000111011000001101000110100000010001100000000001
001100110110001111100010010001010001110100011110001001101110111111111010101000110
001000010101011010101100101001010001001011100111000011111111000010001100011001101
101000111110011010110101111001000101000001100100100111110110110000001110100110001
001001011101111100011110000001100001001100101011100101010101101000000100011000000
001101100110101000101110000111011010101001000010001000000110001101010010000100011
000111011100101110100111000110110110110000101110010011001001001110011011001000100
101100110001001100101100010110000100111100111001100000100000000100000010100111000
110111001110111100111010100001011101001011100010010100111100001100111001011001111
011010111000101001110100101100011111001010001111011010000111100000000111110101011
000100011101001011101000101111111101011110011000010111111001011010011100010100101
111000111101110101110001000100101110000011011010110111000110011111001100110111010
000010010110000010111011011001100111111000010100101000101100001010100100010000100
011001101101110111111101001011001111110010001101101100110010111010011001100100110
000110010101100111000001101011000011111100101001101011001110000101101111011001100
100110110001011010001000010110110101001001111010001110110000010111101100100100010
100010010110111111010101111110011000010001001000110100111100001100100110111010110
011100101111111010000111110011101011010101111010000000111010000100001101111111010
010001010011001111011111111111000101101111110000011011110111101010101101001011101
011100100011110000101010111110101111000001001101111110000010011111000000111111010
000000001001100101111100100011110101101011110001100011101100110110001010100010101
111111100101011111011000101010100001111011101001101010001110111111001010101010010
100000100011101011011100100010011111100011001111100010110011001001000110100011000
101110101011111001001001111111110111011011000101111110000100011110010010111110001
101110101000001010000011111011000011001001101111101000101111000110000100111001100
101110101101010111111101000000011001110010001011000001001000001011100100100001000
100000100110110011111111101011001101100110101010011011011110000111000111010111100
111111100111010110110100111000000100011101111011110011001111101100101011100001010

@ -0,0 +1,26 @@
<?php
namespace Base\Facade;
use Base\Tool\Request as BaseRequest;
/**
* @author elf<360197197@qq.com>
*/
class Request {
private static $instance;
public static function getInstance()
{
if (self::$instance == null) {
self::$instance = new BaseRequest();
}
return self::$instance;
}
public static function __callStatic($name, $arguments)
{
$instance = self::getInstance();
return call_user_func_array([$instance, $name], $arguments);
}
}

@ -3,15 +3,51 @@ namespace Base\Service;
use Base\Model\PromoteModel;
use Base\Model\ApplyModel;
use Base\Tool\Request;
use Base\Facade\Request;
class ApplyService {
private $model;
const ENCRYPT_METHOD = 'AES-256-ECB';
const ENCRYPT_KEY = 'WmtX1@#Landing&Download2048';
const ENCRYPT_TYPE_DOWNLOAD = 1;
const ENCRYPT_TYPE_LANDING_PAGE = 2;
public static $enableStatusList = [
'-1' => '打包失败',
'0' => '打包失败',
'1' => '打包成功 ',
'2' => '准备打包 ',
'3' => '打包中',
];
public function __construct()
{
$this->model = new ApplyModel();
}
public function checkApplyStatus($apply)
{
if ($apply['status'] == 0) {
return [
'status' => false,
'message' => '游戏未审核',
];
}
if ($apply['offline_status'] == 1) {
return [
'status' => false,
'message' => '游戏已下架',
];
}
if ($apply['enable_status'] != 1) {
return [
'status' => false,
'message' => self::$enableStatusList[$apply['enable_status']] ?? '未知错误',
];
}
return [
'status' => true,
'message' => '游戏打包成功',
];
}
public function cancelGame($gameId, $promoteId) {
@ -24,28 +60,70 @@ class ApplyService {
M('apply', 'tab_')->where(['game_id' => $gameId, 'promote_id' => ['in', $ids]])->save($save);
}
public function getDownloadUrl($apply, $game = null)
public function getDownloadUrl($apply)
{
$host = Request::getHost();
if(empty($apply['dow_url'])) {
if ($game == null) {
$columns = ['sdk_version', 'add_game_address', 'and_dow_address', 'ios_game_address', 'ios_dow_address'];
$game = M('game','tab_')->field($columns)->where(['id' => $apply['game_id']])->find();
$code = $this->encodeApplyCode($apply, self::ENCRYPT_TYPE_DOWNLOAD);
return $host . '/index.php?s=/Home/Download/index/code/' . $code;
}
if($game['sdk_version'] == 1){
if($game['add_game_address'] != '') {
return $game['add_game_address'];
}else{
return $host . substr($game['and_dow_address'], 1);
public function getLandingPageUrl($apply)
{
$host = Request::getHost();
$code = $this->encodeApplyCode($apply, self::ENCRYPT_TYPE_LANDING_PAGE);
return $host . '/index.php?s=/Home/Home/landingPage/code/' . $code;
}
} else {
if($game['ios_game_address'] != ''){
return $game['ios_game_address'];
}else{
return $host . substr($game['ios_dow_address'], 1);
public function encodeApplyCode($apply, $type)
{
$expiresIn = 0;
$data = [
'promote_id' => $apply['promote_id'],
'game_id' => $apply['game_id'],
'expires_in' => $expiresIn,
'created_at' => date('Y-m-d H:i:s'),
'type' => $type
];
$jsonStr = json_encode($data);
return base64_encode(openssl_encrypt($jsonStr, self::ENCRYPT_METHOD, self::ENCRYPT_KEY));
}
public function decodeApplyCode($code)
{
$decryptStr = openssl_decrypt(base64_decode($code), self::ENCRYPT_METHOD, self::ENCRYPT_KEY);
return json_decode($decryptStr, true);
}
public function checkApplyCode($data, $type)
{
if (
!isset($data['promote_id']) ||
!isset($data['game_id']) ||
!isset($data['expires_in']) ||
!isset($data['created_at']) ||
!isset($data['type'])
) {
return [
'status' => false,
'message' => '参数异常',
];
}
if ($data['type'] != $type) {
return [
'status' => false,
'message' => '参数异常',
];
}
if ($data['expires_in'] > 0 && time() > (strtotime($data['created_at']) + $data['expires_in'])) {
return [
'status' => false,
'message' => '链接已过期',
];
}
return $host . $apply['dow_url'];
return [
'status' => true,
'message' => '验证成功',
];
}
}

@ -6,24 +6,14 @@ namespace Base\Tool;
*/
class Request {
private static $instance;
private $serverInfo;
private $scheme;
private function __construct()
public function __construct()
{
$this->serverInfo = $_SERVER;
}
public static function getInstance()
{
if (self::$instance == null) {
self::$instance = new static();
}
return self::$instance;
}
public function isWechat()
{
$userAgent = $this->getUserAgent();
@ -129,10 +119,4 @@ class Request {
}
return $this->scheme;
}
public static function __callStatic($name, $arguments)
{
$instance = self::getInstance();
return call_user_func_array([$instance, $name], $arguments);
}
}

@ -5,6 +5,8 @@ namespace Home\Controller;
use OT\DataDictionary;
use Admin\Model\ApplyModel;
use Think\Model;
use Base\Facade\Request;
use Base\Service\ApplyService;
/**
@ -633,9 +635,7 @@ class ApplyController extends BaseController
if ($_REQUEST['pattern'] != null) {
$map['tab_apply.pattern'] = $_REQUEST['pattern'];
}
// $map['tab_apply.status'] = 1;
// $map['tab_game.game_status'] = 1;//游戏状态
// empty(I('sdk_version')) || $map['tab_game.sdk_version'] = I('sdk_version');
$page = intval(I('get.p', 0));
$page = $page ? $page : 1; //默认显示第一页数据
@ -1750,7 +1750,80 @@ class ApplyController extends BaseController
$this->ajaxReturn($result);
}
}
public function getDownloadUrl()
{
$gameId = I('game_id', 0);
$promote = $this->getLoginPromote();
$apply = M('apply', 'tab_')->where(['promote_id' => $promote['id'], 'game_id' => $gameId])->find();
$game = M('game', 'tab_')->field(['icon'])->where(['game_id' => $gameId])->find();
if ($apply == null) {
$this->ajaxReturn([
'status' => 0,
'message' => '游戏不存在',
'data' => [
]
]);
}
$icon = Request::getHost() . '/' . get_cover($game['icon'], 'path');
$applyService = new ApplyService();
$result = $applyService->checkApplyStatus($apply);
if (!$result['status']) {
$this->ajaxReturn([
'status' => 0,
'message' => $result['message'],
'data' => [
]
]);
}
$url = $applyService->getDownloadUrl($apply);
$this->ajaxReturn([
'status' => 1,
'message' => '获取成功',
'data' => [
'url' => $url,
]
]);
}
public function getLandingPageUrl()
{
$gameId = I('game_id', 0);
$promote = $this->getLoginPromote();
$apply = M('apply', 'tab_')->where(['promote_id' => $promote['id'], 'game_id' => $gameId])->find();
$game = M('game', 'tab_')->field(['icon'])->where(['game_id' => $gameId])->find();
if ($apply == null) {
$this->ajaxReturn([
'status' => 1,
'message' => '游戏不存在',
'data' => [
]
]);
}
$icon = Request::getHost() . '/' . get_cover($game['icon'], 'path');
$applyService = new ApplyService();
$result = $applyService->checkApplyStatus($apply);
if (!$result['status']) {
$this->ajaxReturn([
'status' => 0,
'message' => $result['message'],
'data' => [
]
]);
}
$url = $applyService->getLandingPageUrl($apply);
$this->ajaxReturn([
'status' => 1,
'message' => '获取成功',
'data' => [
'url' => $url,
]
]);
}
}

@ -2,327 +2,82 @@
namespace Home\Controller;
use Think\Controller;
use App\Model\GameModel;
use Base\Facade\Request;
use Base\Service\ApplyService;
/**
* @author elf<360197197@qq.com>
*/
class DownloadController extends Controller {
public function down_error($message='')
public function downloadError($message)
{
$this->assign("message",$message);
$this->display();
$this->assign('message', $message);
$this->display('error');
}
public function index($game_id=0,$promote_id=0){
$applyModel = M('Apply','tab_');
$map['status'] = 1;
$map['enable_status'] = 1;
$data = $applyModel
->field('game_id,tab_apply.game_name,promote_id,promote_account,relation_game_id,pack_url,plist_url,`status`,enable_status,tab_apply.sdk_version')
->join("tab_game ON tab_apply.game_id = tab_game.id AND promote_id = $promote_id AND game_id = $game_id ")
->where($map)
->find();
$system_type = 1;
if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
$system_type = 2;
}
$gamemodel = new GameModel();
$source = $gamemodel->getGameDownInfo($game_id);
$pack_url = $this->package($source['packet'],$promote_id);
M('Game','tab_')->where('id='.$data['game_id'])->setInc('dow_num');
if(is_mobile_request()){
if($data['sdk_version'] == 1 && get_devices_type()==2)$this->redirect("Down/down_error",array('message'=>"请使用安卓浏览器下载"));
// if($data['sdk_version'] == 1 && is_weixin()) $this->redirect("Down/down_error",array('message'=>"请使用安卓浏览器下载"));
if($data['sdk_version'] == 2 && get_devices_type()==1)$this->redirect("Down/down_error",array('message'=>"请使用ios浏览器下载"));
}
switch ($data['sdk_version']) {
case 1:
if(!empty($pack_url)){
if(preg_match("/oss/", $pack_url)){
$url=str_replace('-internal', '', $pack_url);
echo "<script>window.location.href='$url';</script>";
}elseif(preg_match("/clouddn/", $pack_url)){
$url = "http://".$pack_url;
redirect($url);
}elseif(preg_match("/myqcloud/", $pack_url)){
redirect($pack_url);
}elseif(preg_match("/bcebos/", $pack_url)){
redirect($pack_url);
}else{
if (!file_exists($pack_url)){
$this->error('文件不存在哦 亲!');
}else{
redirect("http://".$_SERVER['HTTP_HOST'].ltrim($pack_url,'.'));
}
}
}else{
$this->error('原包地址不存在');
}
break;
default:
switch ($system_type) {
case 1:
if(!empty($pack_url)){
if(preg_match("/oss/", $pack_url)){
$url=str_replace('-internal', '', $pack_url);
echo "<script>window.location.href='$url';</script>";
}elseif(preg_match("/clouddn/", $pack_url)){
$url = "http://".$pack_url;
redirect($url);
}elseif(preg_match("/myqcloud/", $pack_url)){
redirect($pack_url);
}elseif(preg_match("/bcebos/", $pack_url)){
redirect($pack_url);
}else{
$this->down($pack_url);
}
}else{
$this->error('原包地址不存在');
}
break;
default:
$plist_url = substr($data['plist_url'],'1',strlen($data['plist_url']));
Header("HTTP/1.1 303 See Other");
Header("Location: "."itms-services://?action=download-manifest&url="."https://".$_SERVER["HTTP_HOST"]."/".$plist_url);
break;
}
break;
}
}
/**
* 投放包下载
* @param
* @author 鹿文学
*/
public function launch_down_file($game_id=0,$promote_id=0,$platform_id=0,$position=1) {
/* 检查游戏是否存在 */
//$game = M('game','tab_')->field('id,game_name')->where(['id'=>$game_id])->find();
//if(!is_array($game)) {$this->error('游戏不存在');}
/* 检查渠道包是否存在或更改 */
$applymodel = M('apply','tab_');
$apply = $applymodel->field('id,sdk_version,pack_url,plist_url')
->where(['game_id'=>$game_id,'promote_id'=>$promote_id])->find();
//if(!is_array($apply)) {$this->error('渠道不存在');}
$launchmodel = M('apply_launch','tab_');
$map = array(
'platform_id'=>$platform_id,
'apply_id'=>$apply['id'],
'position'=>$position,
);
$launch = $launchmodel->where($map)->find();
//if(!is_array($launch)) {$this->error('游戏包不存在');}
/* 检查原包是否存在或更改 */
$gamesource = M('game_source','tab_')->field('id,file_name,source_version')->where(['game_id'=>$game_id])->find();
if(!is_array($gamesource)) {$this->error('文件不存在哦');}
if($gamesource['file_name'] == $launch['game_source_filename']) {
$system_type = 1;
if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
$system_type = 2;
}
$pack_url = $launch['launch_down_url'];
M('Game','tab_')->where(['id'=>$game_id])->setInc('dow_num');
if(is_mobile_request()){
if($apply['sdk_version'] == 1 && get_devices_type()==2)$this->redirect("Down/down_error",array('message'=>"请使用安卓浏览器下载"));
if($apply['sdk_version'] == 1 && is_weixin())$this->redirect("Home/promotionofregistration",array('pid'=>$promote_id,'gid'=>$game_id,'lid'=>$platform_id,'p'=>$position,'message'=>"请使用安卓浏览器下载"));
if($apply['sdk_version'] == 2 && get_devices_type()==1)$this->redirect("Down/down_error",array('message'=>"请使用ios浏览器下载"));
}
switch ($apply['sdk_version']) {
case 1:
if(!empty($pack_url)){
if(preg_match("/oss/", $pack_url)){
$url=str_replace('-internal', '', $pack_url);
echo "<script>window.location.href='$url';</script>";
}elseif(preg_match("/clouddn/", $pack_url)){
$url = "http://".$pack_url;
redirect($url);
}elseif(preg_match("/myqcloud/", $pack_url)){
redirect($pack_url);
}elseif(preg_match("/bcebos/", $pack_url)){
redirect($pack_url);
}else{
$url = ROOTTT . substr($pack_url,stripos($pack_url,'uploads'));
if (!file_exists($url)){
$this->error('文件不存在哦 亲!');
}else{
redirect($pack_url);
}
}
}else{
$this->error('原包地址不存在');
}
break;
default:
switch ($system_type) {
case 1:
if(!empty($pack_url)){
if(preg_match("/oss/", $pack_url)){
$url=str_replace('-internal', '', $pack_url);
echo "<script>window.location.href='$url';</script>";
}elseif(preg_match("/clouddn/", $pack_url)){
$url = "http://".$pack_url;
redirect($url);
}elseif(preg_match("/myqcloud/", $pack_url)){
redirect($pack_url);
}elseif(preg_match("/bcebos/", $pack_url)){
redirect($pack_url);
}else{
$this->down($pack_url);
}
}else{
$this->error('原包地址不存在');
}
break;
default:
$plist_url = $launch['launch_plist_url'];
if(stripos($plist_url,'https://') === false) {
$plist_url = 'https://'.$_SERVER['HTTP_HOST'].str_replace('./','/',$plist_url);
}
Header("HTTP/1.1 303 See Other");
Header("Location: "."itms-services://?action=download-manifest&url=".$plist_url);
break;
}
break;
}
} else {
$applymodel->where(['id'=>$apply['id']])->setField('enable_status',2);
$this->error('游戏正在打包,请稍候');
public function index()
{
$code = I('code', '');
if ($code == '') {
$this->redirect("download/downloadError", ['message' => '访问错误']);
}
$applyService = new ApplyService();
$data = $applyService->decodeApplyCode($code);
$result = $applyService->checkApplyCode($data, ApplyService::ENCRYPT_TYPE_DOWNLOAD);
if (!$result['status']) {
$this->error($result['message']);
}
$gameId = $data['game_id'];
$promoteId = $data['promote_id'];
public function media_down_file($game_id=0,$type=1){
$model = M('Game','tab_');
$map['tab_game.id'] = $game_id;
$map['file_type'] = $type;
$data = $model
->field('tab_game_source.*,tab_game.game_name,tab_game.add_game_address,tab_game.ios_game_address')
->join("left join tab_game_source on tab_game.id = tab_game_source.game_id")->where($map)->find();
if($type==1){
if($data['file_url']!=''||!varify_url($data['add_game_address'])){
$this->down($data['file_url']);
}
else{
Header("HTTP/1.1 303 See Other");
Header("Location: ".$data['add_game_address']);
}
}else{
if($data['file_url']!=''||!varify_url($data['ios_game_address'])){
$this->down($data['file_url']);
}
else{
Header("HTTP/1.1 303 See Other");
Header("Location: ".$data['ios_game_address']);
}
}
}
$map = [];
$map['status'] = 1;
$map['enable_status'] = 1;
$columns = ['game_id', 'promote_id', 'promote_account', 'pack_url', 'plist_url', 'status', 'enable_status'];
$apply = M('apply','tab_')->field($columns)->where($map)->find();
$game = M('game','tab_')->field(['id', 'game_name', 'sdk_version'])->where(['id' => $apply['game_id']])->find();
public function down($file, $isLarge = false, $rename = NULL)
{
if(headers_sent())return false;
if(!$file) {
$this->error('文件不存在哦 亲!');
if (Request::isMobile()) {
if (!Request::isAndroid() && $game['sdk_version'] == 1) {
$this->redirect("download/downloadError", ['message' => '请使用安卓浏览器下载']);
}
if($rename==NULL){
if(strpos($file, '/')===false && strpos($file, '\\')===false)
$filename = $file;
else{
$filename = basename($file);
if (!Request::isIOS() && $game['sdk_version'] == 2) {
$this->redirect("download/downloadError", ['message' => '请使用ios浏览器下载']);
}
}else{
$filename = $rename;
}
header('Content-Description: File Transfer');
header("Content-Type: application/force-download;");
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=\"$filename\"");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: '.filesize($file));//$_SERVER['DOCUMENT_ROOT'].
header("Pragma: no-cache"); //不缓存页面
ob_clean();
flush();
if($isLarge)
self::readfileChunked($file);
else
readfile($file);
}
$packageUrl = $game['sdk_version'] == 1 ? $apply['pack_url'] : $apply['plist_url'];
public function down_material($game_id){
$map['status'] = 1;
$game = M("game",'tab_')->where($map)->find($game_id);
$material = $game['material_url'];
if(file_exists($material) && is_file($material)){
clearstatcache();
$this->down($material);
M('game','tab_')->where(['id' => $game['id']])->setInc('dow_num');
if (Request::isAndroid()) {
$this->gotoPkgUrl($packageUrl);
} else if (Request::isIOS()) {
$plistUrl = substr($packageUrl, 1, strlen($packageUrl));
header("HTTP/1.1 303 See Other");
header("Location: "."itms-services://?action=download-manifest&url=" . "https://" . Request::getHost() . "/" . $plistUrl);
} else {
clearstatcache();
$this->error('下载地址错误');
$this->gotoPkgUrl($packageUrl);
}
}
/**
* 安卓打包渠道信息
* @param $source_info 原包信息
* @param $promote_id
* @return string
* author: xmy 280564871@qq.com
*/
public function package($source_info, $promote_id)
private function gotoPkgUrl($packageUrl)
{
$file_path = $source_info['file_url'];
//验证原包是否存在
if (!varify_url($file_path)) {
$this->error("未上传原包");
if (preg_match("/oss/", $packageUrl)) {
$url = str_replace('-internal', '', $packageUrl);
echo "<script>window.location.href='$url';</script>";
} elseif (preg_match("/clouddn/", $packageUrl)) {
$url = "http://".$packageUrl;
redirect($url);
} elseif (preg_match("/myqcloud/", $packageUrl)) {
redirect($packageUrl);
} elseif(preg_match("/bcebos/", $packageUrl)) {
redirect($packageUrl);
} else {
$result = M('apply', 'tab_')
->alias('a')
->field('id, pack_url, plist_url')
->where(['a.game_id'=>$source_info['game_id'],'a.promote_id'=>$promote_id])
->find();
if(empty($result)) {
$this->error('此游戏不存在');
}
if(GameModel::ANDROID == $source_info['sdk_version']){
if(varify_url($result['pack_url'])) {
return $result['pack_url'];
}
}elseif(GameModel::IOS == $source_info['sdk_version']){
if(varify_url($result['plist_url'])) {
return $result['plist_url'];
}
if (!file_exists($packageUrl)) {
$this->error('文件不存在哦,亲!');
}else{
$this->error('游戏版本错误');
redirect(Request::getHost() . ltrim($packageUrl, '.'));
}
}
}

@ -3,7 +3,8 @@ namespace Home\Controller;
use Think\Controller;
use User\Api\MemberApi;
use Base\Tool\Request;
use Base\Facade\Request;
use Base\Service\ApplyService;
/**
* 前台公共控制器
@ -130,7 +131,15 @@ class HomeController extends Controller
public function landingPage()
{
$code = I('code', '');
$data = [];
if ($code == '') {
$this->redirect("download/downloadError", ['message' => '访问错误']);
}
$applyService = new ApplyService();
$data = $applyService->decodeApplyCode($code);
$result = $applyService->checkApplyCode($data, ApplyService::ENCRYPT_TYPE_LANDING_PAGE);
if (!$result['status']) {
$this->error($result['message']);
}
$isWechat = Request::isWechat();
$isIOS = Request::isIOS();
@ -160,20 +169,25 @@ class HomeController extends Controller
$map['sdk_version'] = 1;
$game = M('game', 'tab_')->field($columns)->where($map)->find();
}
$apply = M('apply', 'tab_')->field(['game_id', 'enable_status'])
$apply = M('apply', 'tab_')->field(['game_id', 'enable_status', 'promote_id'])
->where(['promote_id' => $data['promote_id'], 'game_id' => $game['id']])
->find();
$game['flooring_page_imgs'] = explode(',', $game['flooring_page_imgs']);
$game['icon'] = get_cover($game['icon'], 'path');
$imageIds = explode(',', $game['flooring_page_imgs']) ?? [];
$imageUrls = [];
foreach ($imageIds as $imageId) {
$imageUrls[] = get_cover($imageId, 'path');
}
$game['flooring_page_imgs'] = $imageUrls;
$downloadUrl = '';
if ($isIOS13) {
$gameSource = M('GameSource', 'tab_')->where(array('game_id' => $gameId))->getField('org_plist_url');
$downloadUrl = 'itms-services://?action=download-manifest&url=' . Request::getHost() . ltrim($gameSource['org_plist_url'], '.');
} else {
$applyService = new ApplyService();
$downloadUrl = $applyService->getDownloadUrl($apply, $game);
$downloadUrl = $applyService->getDownloadUrl($apply);
}
$this->assign('downloadUrl', $downloadUrl);

@ -3,89 +3,10 @@
<link href="__CSS__/20180207/data.css" rel="stylesheet">
<link href="__CSS__/20180207/game.css" rel="stylesheet">
<link href="__CSS__/game_detailed.css" rel="stylesheet">
<link href="__CSS__/my_game.css" rel="stylesheet">
<link href="__STATIC__/icons_alibaba/iconfont.css" rel="stylesheet">
<link href="__STATIC__/jqueryselect/css/layui.css" rel="stylesheet">
<script src="__STATIC__/jqueryselect/js/MySearch.js" type="text/javascript" charset="utf-8"></script>
<style>
body {
font: 400 14px/1.5 'Microsoft YaHei','微软雅黑',Tahoma,Verdana,Arial,'宋体',sans-serif;
}
.zclip embed {
margin-top: -14px;
}
.trunk-list {
position: relative;
min-height: 66vh;
}
.pagenation {
position: relative;
text-align: center;
line-height: 5vh;
bottom: 1%;
}
.pic-prev:hover, .pic-next:hover {
background-color: #4ac5c3;
}
</style>
<style>
.layui-btn{
background-color: #5fb878;
}
.label{
padding: 2px 5px;
background: #5FB878;
border-radius: 2px;
color: #fff;
display: block;
line-height: 20px;
height: 20px;
margin: 2px 5px 2px 0;
float: left;
}
i{
display: inline-block;
width: 18px;
height: 18px;
line-height: 18px;
text-align: center
}
.label:hover{color: white;}
.label i:hover {
background-color: #009E94;
border-radius: 2px;
}
.layui-form-select dl dd:hover {
background-color: #5FB878;
color: white;
}
.AD{
width: 210px;
margin-left: 40px;
overflow-y: auto;
max-height: 200px;
border: 2px solid #5fb878;
border-radius: 6px;
padding: 1px 2px;
}
#add_promote_data label {
width: 70px;
margin-right: 0;
padding-left: 0;
text-align: left;
}
#add_promote_data .AD {
white-space: nowrap;
margin-bottom: 2px;
overflow:scroll;
}
</style>
</block>
<block name="body">
@ -104,15 +25,7 @@
<a href="{:U($game, array('type' => 2))}" class="">IOS游戏</a>
<a href="{:U($game, array('type' => 1))}" class="">Android游戏</a>
<a href="javascript:;" class="current">我的游戏</a>
<!-- <a href="javascript:void(0);" title="集成推广多款游戏,生成游戏大全推广页" style="background:#ffffff;width:68px;height:68px; position:relative" onmouseover="this.style.background='#E3E5E4'" onmouseout="this.style.background='#ffffff'" class="spread"><img src="/Public/Home/images/generalization.png" />
<img src="/Public/Home/images/hot.png" style="width: 20px;
height: 20px;
position: absolute;
right: 2px;top:0" />
</a>
-->
</div>
<div class="clearfix"></div>
<div class="tab marg_top20" style="clear:both;display: flex;">
<div style="display: flex;">
@ -151,13 +64,6 @@
</eq>
</div>
</div>
<!-- <div class="zwm_examinediv">-->
<!-- <a class="btn_calc" href="javascript:;">审核通过</a>-->
<!-- <a class="btn_calc examine_a" href="{:U('my_game_ch')}">审核中</a>-->
<!-- </div>-->
<!-- <form class="marg_top20" action="{:U($myGame,array('row'=>I('get.row')))}" method="post"-->
<!-- enctype="multipart/form-data">-->
<div class="form-group normal_space fr">
<input type="submit" class="submit" id='submit' url="{:U($myGame,array('model'=>$model['name'],'type'=>$type),false)}"
value="查询">
@ -236,20 +142,6 @@
<span>游戏类型:<span>{$vo.game_type_name}</span>&nbsp;&nbsp;</span>
</p>
</div>
<?php
$qrcode = get_cover($vo['icon'],'path');
if (stripos($qrcode,'http') === false) {
if (stripos($qrcode,'.com') === false) {
$qrcode = 'http://'.C('APPLY_DOWN_DOMAIN').$qrcode;
} else {
$qrcode = 'http://'.$qrcode;
}
}
$qrcodes = $qrcode;
$qrcode = base64_encode(base64_encode($qrcode));
?>
<div class="game-operating" data-url="{$qrcodes}" style="width: 35%;">
<if condition="$promoteRole == 1">
<if condition="$parentPromoteId == 0">
@ -257,10 +149,8 @@
</if>
<span class="add-game" game-id="{$vo.id}" promote-type="3" style="cursor: pointer;margin-right: 10px;"><u>添加推广员游戏</u></span>
</if>
<?php $downloadUrl = get_apply_dow_url($vo['id'],$vo['promote_id']);?>
<span class="game-link" data-qrcode="{:U('Apply/qrcode',['url'=>base64_encode(base64_encode($downloadUrl)),'logo'=>$qrcode])}" data-url="{$downloadUrl}" data-clipboard-text="{$downloadUrl}" data-apply-id="{$vo.applyid}" style="cursor: pointer;margin-right: 10px;"><u>复制下载链接</u></span>
<?php $flooringPageUrl = 'http://'.C('APPLY_DOWN_DOMAIN').U('Home/promitionofregestion',array('gid'=>$vo['id'],'pid'=>$vo['promote_id']));?>
<span class="game-link" data-qrcode="{:U('Apply/qrcode',['url'=>base64_encode(base64_encode($flooringPageUrl)),'logo'=>$qrcode])}" data-url="{$flooringPageUrl}" data-clipboard-text="{$flooringPageUrl}" data-apply-id="{$vo.applyid}" style="cursor: pointer;margin-right: 10px;"><u>落地页链接</u></span>
<span class="game-link" data-type="download" data-game-id="{$vo.id}" style="cursor: pointer;margin-right: 10px;"><u>复制下载链接</u></span>
<span class="game-link" data-type="landing-page" data-game-id="{$vo.id}" style="cursor: pointer;margin-right: 10px;"><u>落地页链接</u></span>
<span class="down-game-btn" data-id="{$vo.id}" style="cursor: pointer;margin-right: 10px;color: #999"><u>下架</u></span>
</div>
</div>
@ -347,16 +237,11 @@
<div class="game-window-content" style="text-align: center;width: auto;padding-bottom: 0px;">
<div class="game-window-content-eveyone" style="display: block;color: #3A97FF;font-size: 1.1rem;">
<label style="margin-right: 20px;">下载地址:</label>
<span id="game_link_address"></span>
<span id="game_link_address" style="word-wrap: break-word;white-space: normal;"></span>
<button id="clipboard-btn" style="display: none;" data-text="">复制</button>
</div>
</div>
<!-- <div class="game-window-btns" style="margin-top: 10px;">-->
<!-- <div class="game-window-btn-box">-->
<!-- <input class="game-window-btn btn-blue" type="button" id="download_copy" data-url="" value="复制">-->
<!-- </div>-->
<!-- </div>-->
<div class="game-window-content" style="text-align: center;width: auto;padding-top: 5px;">
<div class="game-window-content-eveyone" style="display: block;color: #999;font-size: 1.1rem;">
<span>复制成功,ctrl+v粘贴即可</span>
@ -364,8 +249,8 @@
</div>
<div class="game-window-content" style="text-align: center;width: auto;padding-bottom: 5px;">
<div class="game-window-content-eveyone" style="display: block;color: #999;font-size: 1.1rem;">
<img id="game_link_ercode" style="width: 200px;height: 200px;">
<div id="game_link_ercode" class="game-window-content-eveyone" style="display: block;color: #999;font-size: 1.1rem;">
<!-- <img id="game_link_ercode" style="width: 200px;height: 200px;"> -->
</div>
</div>
@ -426,68 +311,16 @@
</div>
</div>
</div>
<!-- <div class="game-detail-right fr">-->
<!-- <div class="detail-con game-date panel panel-bordered">-->
<!-- <div class="panel-heading"><h3 class="panel-title">游戏开服</h3></div>-->
<!-- <div class="date-box ">-->
<!-- <ul class="date-tit">-->
<!-- <li>时间</li>-->
<!-- <li>服务器名称</li>-->
<!-- </ul>-->
<!-- <div class="list-outer ">-->
<!-- <ul class="date-list">-->
<!-- <li><span class="android"></span></li>-->
<!-- </ul>-->
<!-- <ul class="date-list">-->
<!-- <li><span>09-06 16:00</span></li>-->
<!-- <li>天宫73区</li>-->
<!-- </ul>-->
<!-- <ul class="date-list">-->
<!-- <li><span>09-07 16:00</span></li>-->
<!-- <li>天宫74区</li>-->
<!-- </ul>-->
<!-- <ul class="date-list">-->
<!-- <li><span>09-09 16:00</span></li>-->
<!-- <li>天宫75区</li>-->
<!-- </ul>-->
<!-- <ul class="date-list">-->
<!-- <li><span>09-10 16:00</span></li>-->
<!-- <li>天宫76区</li>-->
<!-- </ul>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="detail-con game-pack panel panel-bordered">-->
<!-- <div class="panel-heading"><h3 class="panel-title">游戏礼包</h3></div>-->
<!-- <div class="pack-box ">-->
<!-- <ul id="GamePackInfo">-->
<!-- <li class="">-->
<!-- <div class="pack-inner">-->
<!-- <p class="pack-tit">《天宫计》新手礼包</p>-->
<!-- <p class="pack-word">天女礼物礼包*1、悬赏令*1、铜币*5000</p>-->
<!-- <p class="pack-num">剩余:<b>82.2%</b></p>-->
<!-- </div>-->
<!-- </li>-->
<!-- <li class="current">-->
<!-- <div class="pack-inner">-->
<!-- <p class="pack-tit">《天宫计》媒体礼包</p>-->
<!-- <p class="pack-word">技能书礼包*1、宠物经验丹*1、铜币*5000</p>-->
<!-- <p class="pack-num">剩余:<b>83.3%</b></p>-->
<!-- </div>-->
<!-- </li>-->
<!-- </ul>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
</div>
</div>
</div>
</div>
</block>
<block name='script'>
<script src="__STATIC__/clipboard/clipboard.min.js"></script>
<script src="__STATIC__/clipboard.min.js"></script>
<script src="__STATIC__/layer/layer.js"></script>
<script type="text/javascript" src="__JS__/20170831/select2.min.js"></script>
<script type="text/javascript" src="__JS__/jquery.qrcode.min.js"></script>
<script type="text/javascript">
highlight_subnav("{:U('Apply/'.$game)}");
setValue('type', {$Think.request.type |default = '""'});
@ -515,7 +348,6 @@
if (!thisElement.hasClass('highlight')) {
var promoteRole = thisElement.attr('promote-role');
console.log(promoteRole);
setValue('promote_role', promoteRole);
@ -816,12 +648,11 @@
dataType: "json",
data: {'game_id': gameId,'promote_type':promoteType},
success: function (data) {
console.log(data);
$('#add_game_name').text(data.game_data.game_name);
$('#add_game_id').val(data.game_data.id);
$('#add_game_features').text(data.game_data.features);
$('#add_sdk_version').text(data.game_data.sdk_name);
console.log(data.game_data.sdk_version);
var tagData = [];
if (data.promote_data.length > 0) {
@ -893,7 +724,6 @@
} else {
layer.msg(data.msg, {icon: 5});
}
console.log(data);
},
error: function (result) {
layer.msg('网络异常', {icon: 5});
@ -973,47 +803,51 @@
});
$('.game-link').on('click', function () {
var url = $(this).attr('data-url');
var qrcode = $(this).attr('data-qrcode');
var applyId = parseInt($(this).attr('data-apply-id'));
var linkTag = this
var gameId = parseInt($(this).attr('data-game-id'))
var type = $(this).attr('data-type')
var url = ''
if (type == 'download') {
url = "__URL__/getDownloadUrl"
} else if (type == 'landing-page') {
url = "__URL__/getLandingPageUrl"
}
$.ajax({
type: "post",
url: "__URL__/getEnableStatus",
url: url,
type: 'post',
dataType: "json",
data: {'apply_id': applyId},
success: function (data) {
if (data.status == 0) {
layer.msg(data.msg, {icon: 5});
return false;
}
var enableStatus = parseInt(data.data);
if (enableStatus == 1) {
$('#game_link_ercode').attr('src',qrcode);
$('#game_link_address').text(url);
data: {game_id: gameId},
success: function (response) {
if (response.status == 1) {
var qrcodeWidth = 200
var qrcodeHeight = 200
var logoWidth = qrcodeWidth/4
var logoHeight = qrcodeHeight/4
var options = {
render: 'canvas',
ecLevel: 'H',//识别度
fill: '#000',//二维码颜色
background: '#ffffff',//背景颜色
quiet: 2,//边距
width: 200,//宽度
height: 200,
text: response.data.url,//二维码内容
label: 'jQuery.qrcode',
fontname: 'Ubuntu',
fontcolor: '#ff9818',
};
var logo = $(linkTag).parents('.game-li').eq(0).find('.img-box').children('img')[0]
$('#game_link_ercode').empty().qrcode(options);
$("#game_link_ercode canvas")[0].getContext('2d').drawImage(logo, (qrcodeWidth - logoWidth) / 2, (qrcodeHeight - logoHeight) / 2, logoWidth, logoHeight);
$('#clipboard-btn').attr('data-text', response.data.url)
$('#clipboard-btn').click()
$('#game_link_address').text(response.data.url);
$('#game_link').show();
$('.game-window-bg').show();
} else {
var iconIndex = 7;
var enableStatusName = '';
switch (enableStatus) {
case 0:
enableStatusName = '未打包';
break;
case 2:
case 3:
enableStatusName = '打包中';
break;
case -1:
iconIndex = 5;
enableStatusName = '打包失败';
break;
}
layer.alert(enableStatusName, {icon: iconIndex});
return false;
layer.alert(response.message, {icon: 7});
}
},
error: function (result) {
@ -1022,20 +856,14 @@
});
});
var btn = document.getElementsByClassName('game-link');
var clipboard = new Clipboard(btn);
clipboard.on('success', function(e) {
// console.log(e);
});
clipboard.on('error', function(e) {
// console.log(e);
});
new ClipboardJS('#clipboard-btn', {
text: function(trigger) {
return trigger.getAttribute('data-text');
}
})
$('#submit').click(function () {
var url = $(this).attr('url');
console.log(url);
var query = $('.jssearch').find('input').serialize();
query += "&" + $('.jssearch').find('select').serialize();
query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<link href="{:get_cover(C('CH_SET_ICO'),'path')}" type="image/x-icon" rel="shortcut icon">
<title>下载失败</title>
<link rel="stylesheet" href="__CSS__/20180207/promition.css">
<link rel="stylesheet" href="__CSS__/20180207/game.css">
</head>
<body class="main_bg">
<div class="h_wrap p_t_30 p_lr_10" style="padding-top:15px;">
<p>{$message}</p>
</div>
</body>
</html>

@ -33,9 +33,9 @@
<div id="data-2">
<volist name="game['flooring_page_imgs']" id="item">
<?php if ($downloadUrl == 'https://'.$_SERVER['HTTP_HOST']) :?>
<a href="#" class="no-package"><img src="{$item|get_cover='path'}" style="width: 100%;"/></a>
<a href="#" class="no-package"><img src="{$item}" style="width: 100%;"/></a>
<?php else :?>
<a href="javascript:;" class="down-link" down-link="{$dowUrl}"><img src="{$vo|get_cover='path'}" style="width: 100%;"/></a>
<a href="javascript:;" class="down-link" down-link="{$downloadUrl}"><img src="{$item}" style="width: 100%;"/></a>
<?php endif ;?>
</volist>
</div>

@ -0,0 +1,76 @@
body {
font: 400 14px/1.5 'Microsoft YaHei','微软雅黑',Tahoma,Verdana,Arial,'宋体',sans-serif;
}
.zclip embed {
margin-top: -14px;
}
.trunk-list {
position: relative;
min-height: 66vh;
}
.pagenation {
position: relative;
text-align: center;
line-height: 5vh;
bottom: 1%;
}
.pic-prev:hover, .pic-next:hover {
background-color: #4ac5c3;
}
.layui-btn{
background-color: #5fb878;
}
.label{
padding: 2px 5px;
background: #5FB878;
border-radius: 2px;
color: #fff;
display: block;
line-height: 20px;
height: 20px;
margin: 2px 5px 2px 0;
float: left;
}
i{
display: inline-block;
width: 18px;
height: 18px;
line-height: 18px;
text-align: center
}
.label:hover{color: white;}
.label i:hover {
background-color: #009E94;
border-radius: 2px;
}
.layui-form-select dl dd:hover {
background-color: #5FB878;
color: white;
}
.AD{
width: 210px;
margin-left: 40px;
overflow-y: auto;
max-height: 200px;
border: 2px solid #5fb878;
border-radius: 6px;
padding: 1px 2px;
}
#add_promote_data label {
width: 70px;
margin-right: 0;
padding-left: 0;
text-align: left;
}
#add_promote_data .AD {
white-space: nowrap;
margin-bottom: 2px;
overflow:scroll;
}

@ -0,0 +1,28 @@
(function(r){r.fn.qrcode=function(h){var s;function u(a){this.mode=s;this.data=a}function o(a,c){this.typeNumber=a;this.errorCorrectLevel=c;this.modules=null;this.moduleCount=0;this.dataCache=null;this.dataList=[]}function q(a,c){if(void 0==a.length)throw Error(a.length+"/"+c);for(var d=0;d<a.length&&0==a[d];)d++;this.num=Array(a.length-d+c);for(var b=0;b<a.length-d;b++)this.num[b]=a[b+d]}function p(a,c){this.totalCount=a;this.dataCount=c}function t(){this.buffer=[];this.length=0}u.prototype={getLength:function(){return this.data.length},
write:function(a){for(var c=0;c<this.data.length;c++)a.put(this.data.charCodeAt(c),8)}};o.prototype={addData:function(a){this.dataList.push(new u(a));this.dataCache=null},isDark:function(a,c){if(0>a||this.moduleCount<=a||0>c||this.moduleCount<=c)throw Error(a+","+c);return this.modules[a][c]},getModuleCount:function(){return this.moduleCount},make:function(){if(1>this.typeNumber){for(var a=1,a=1;40>a;a++){for(var c=p.getRSBlocks(a,this.errorCorrectLevel),d=new t,b=0,e=0;e<c.length;e++)b+=c[e].dataCount;
for(e=0;e<this.dataList.length;e++)c=this.dataList[e],d.put(c.mode,4),d.put(c.getLength(),j.getLengthInBits(c.mode,a)),c.write(d);if(d.getLengthInBits()<=8*b)break}this.typeNumber=a}this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(a,c){this.moduleCount=4*this.typeNumber+17;this.modules=Array(this.moduleCount);for(var d=0;d<this.moduleCount;d++){this.modules[d]=Array(this.moduleCount);for(var b=0;b<this.moduleCount;b++)this.modules[d][b]=null}this.setupPositionProbePattern(0,0);this.setupPositionProbePattern(this.moduleCount-
7,0);this.setupPositionProbePattern(0,this.moduleCount-7);this.setupPositionAdjustPattern();this.setupTimingPattern();this.setupTypeInfo(a,c);7<=this.typeNumber&&this.setupTypeNumber(a);null==this.dataCache&&(this.dataCache=o.createData(this.typeNumber,this.errorCorrectLevel,this.dataList));this.mapData(this.dataCache,c)},setupPositionProbePattern:function(a,c){for(var d=-1;7>=d;d++)if(!(-1>=a+d||this.moduleCount<=a+d))for(var b=-1;7>=b;b++)-1>=c+b||this.moduleCount<=c+b||(this.modules[a+d][c+b]=
0<=d&&6>=d&&(0==b||6==b)||0<=b&&6>=b&&(0==d||6==d)||2<=d&&4>=d&&2<=b&&4>=b?!0:!1)},getBestMaskPattern:function(){for(var a=0,c=0,d=0;8>d;d++){this.makeImpl(!0,d);var b=j.getLostPoint(this);if(0==d||a>b)a=b,c=d}return c},createMovieClip:function(a,c,d){a=a.createEmptyMovieClip(c,d);this.make();for(c=0;c<this.modules.length;c++)for(var d=1*c,b=0;b<this.modules[c].length;b++){var e=1*b;this.modules[c][b]&&(a.beginFill(0,100),a.moveTo(e,d),a.lineTo(e+1,d),a.lineTo(e+1,d+1),a.lineTo(e,d+1),a.endFill())}return a},
setupTimingPattern:function(){for(var a=8;a<this.moduleCount-8;a++)null==this.modules[a][6]&&(this.modules[a][6]=0==a%2);for(a=8;a<this.moduleCount-8;a++)null==this.modules[6][a]&&(this.modules[6][a]=0==a%2)},setupPositionAdjustPattern:function(){for(var a=j.getPatternPosition(this.typeNumber),c=0;c<a.length;c++)for(var d=0;d<a.length;d++){var b=a[c],e=a[d];if(null==this.modules[b][e])for(var f=-2;2>=f;f++)for(var i=-2;2>=i;i++)this.modules[b+f][e+i]=-2==f||2==f||-2==i||2==i||0==f&&0==i?!0:!1}},setupTypeNumber:function(a){for(var c=
j.getBCHTypeNumber(this.typeNumber),d=0;18>d;d++){var b=!a&&1==(c>>d&1);this.modules[Math.floor(d/3)][d%3+this.moduleCount-8-3]=b}for(d=0;18>d;d++)b=!a&&1==(c>>d&1),this.modules[d%3+this.moduleCount-8-3][Math.floor(d/3)]=b},setupTypeInfo:function(a,c){for(var d=j.getBCHTypeInfo(this.errorCorrectLevel<<3|c),b=0;15>b;b++){var e=!a&&1==(d>>b&1);6>b?this.modules[b][8]=e:8>b?this.modules[b+1][8]=e:this.modules[this.moduleCount-15+b][8]=e}for(b=0;15>b;b++)e=!a&&1==(d>>b&1),8>b?this.modules[8][this.moduleCount-
b-1]=e:9>b?this.modules[8][15-b-1+1]=e:this.modules[8][15-b-1]=e;this.modules[this.moduleCount-8][8]=!a},mapData:function(a,c){for(var d=-1,b=this.moduleCount-1,e=7,f=0,i=this.moduleCount-1;0<i;i-=2)for(6==i&&i--;;){for(var g=0;2>g;g++)if(null==this.modules[b][i-g]){var n=!1;f<a.length&&(n=1==(a[f]>>>e&1));j.getMask(c,b,i-g)&&(n=!n);this.modules[b][i-g]=n;e--; -1==e&&(f++,e=7)}b+=d;if(0>b||this.moduleCount<=b){b-=d;d=-d;break}}}};o.PAD0=236;o.PAD1=17;o.createData=function(a,c,d){for(var c=p.getRSBlocks(a,
c),b=new t,e=0;e<d.length;e++){var f=d[e];b.put(f.mode,4);b.put(f.getLength(),j.getLengthInBits(f.mode,a));f.write(b)}for(e=a=0;e<c.length;e++)a+=c[e].dataCount;if(b.getLengthInBits()>8*a)throw Error("code length overflow. ("+b.getLengthInBits()+">"+8*a+")");for(b.getLengthInBits()+4<=8*a&&b.put(0,4);0!=b.getLengthInBits()%8;)b.putBit(!1);for(;!(b.getLengthInBits()>=8*a);){b.put(o.PAD0,8);if(b.getLengthInBits()>=8*a)break;b.put(o.PAD1,8)}return o.createBytes(b,c)};o.createBytes=function(a,c){for(var d=
0,b=0,e=0,f=Array(c.length),i=Array(c.length),g=0;g<c.length;g++){var n=c[g].dataCount,h=c[g].totalCount-n,b=Math.max(b,n),e=Math.max(e,h);f[g]=Array(n);for(var k=0;k<f[g].length;k++)f[g][k]=255&a.buffer[k+d];d+=n;k=j.getErrorCorrectPolynomial(h);n=(new q(f[g],k.getLength()-1)).mod(k);i[g]=Array(k.getLength()-1);for(k=0;k<i[g].length;k++)h=k+n.getLength()-i[g].length,i[g][k]=0<=h?n.get(h):0}for(k=g=0;k<c.length;k++)g+=c[k].totalCount;d=Array(g);for(k=n=0;k<b;k++)for(g=0;g<c.length;g++)k<f[g].length&&
(d[n++]=f[g][k]);for(k=0;k<e;k++)for(g=0;g<c.length;g++)k<i[g].length&&(d[n++]=i[g][k]);return d};s=4;for(var j={PATTERN_POSITION_TABLE:[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,
78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],G15:1335,G18:7973,G15_MASK:21522,getBCHTypeInfo:function(a){for(var c=a<<10;0<=j.getBCHDigit(c)-j.getBCHDigit(j.G15);)c^=j.G15<<j.getBCHDigit(c)-j.getBCHDigit(j.G15);return(a<<10|c)^j.G15_MASK},getBCHTypeNumber:function(a){for(var c=a<<12;0<=j.getBCHDigit(c)-
j.getBCHDigit(j.G18);)c^=j.G18<<j.getBCHDigit(c)-j.getBCHDigit(j.G18);return a<<12|c},getBCHDigit:function(a){for(var c=0;0!=a;)c++,a>>>=1;return c},getPatternPosition:function(a){return j.PATTERN_POSITION_TABLE[a-1]},getMask:function(a,c,d){switch(a){case 0:return 0==(c+d)%2;case 1:return 0==c%2;case 2:return 0==d%3;case 3:return 0==(c+d)%3;case 4:return 0==(Math.floor(c/2)+Math.floor(d/3))%2;case 5:return 0==c*d%2+c*d%3;case 6:return 0==(c*d%2+c*d%3)%2;case 7:return 0==(c*d%3+(c+d)%2)%2;default:throw Error("bad maskPattern:"+
a);}},getErrorCorrectPolynomial:function(a){for(var c=new q([1],0),d=0;d<a;d++)c=c.multiply(new q([1,l.gexp(d)],0));return c},getLengthInBits:function(a,c){if(1<=c&&10>c)switch(a){case 1:return 10;case 2:return 9;case s:return 8;case 8:return 8;default:throw Error("mode:"+a);}else if(27>c)switch(a){case 1:return 12;case 2:return 11;case s:return 16;case 8:return 10;default:throw Error("mode:"+a);}else if(41>c)switch(a){case 1:return 14;case 2:return 13;case s:return 16;case 8:return 12;default:throw Error("mode:"+
a);}else throw Error("type:"+c);},getLostPoint:function(a){for(var c=a.getModuleCount(),d=0,b=0;b<c;b++)for(var e=0;e<c;e++){for(var f=0,i=a.isDark(b,e),g=-1;1>=g;g++)if(!(0>b+g||c<=b+g))for(var h=-1;1>=h;h++)0>e+h||c<=e+h||0==g&&0==h||i==a.isDark(b+g,e+h)&&f++;5<f&&(d+=3+f-5)}for(b=0;b<c-1;b++)for(e=0;e<c-1;e++)if(f=0,a.isDark(b,e)&&f++,a.isDark(b+1,e)&&f++,a.isDark(b,e+1)&&f++,a.isDark(b+1,e+1)&&f++,0==f||4==f)d+=3;for(b=0;b<c;b++)for(e=0;e<c-6;e++)a.isDark(b,e)&&!a.isDark(b,e+1)&&a.isDark(b,e+
2)&&a.isDark(b,e+3)&&a.isDark(b,e+4)&&!a.isDark(b,e+5)&&a.isDark(b,e+6)&&(d+=40);for(e=0;e<c;e++)for(b=0;b<c-6;b++)a.isDark(b,e)&&!a.isDark(b+1,e)&&a.isDark(b+2,e)&&a.isDark(b+3,e)&&a.isDark(b+4,e)&&!a.isDark(b+5,e)&&a.isDark(b+6,e)&&(d+=40);for(e=f=0;e<c;e++)for(b=0;b<c;b++)a.isDark(b,e)&&f++;a=Math.abs(100*f/c/c-50)/5;return d+10*a}},l={glog:function(a){if(1>a)throw Error("glog("+a+")");return l.LOG_TABLE[a]},gexp:function(a){for(;0>a;)a+=255;for(;256<=a;)a-=255;return l.EXP_TABLE[a]},EXP_TABLE:Array(256),
LOG_TABLE:Array(256)},m=0;8>m;m++)l.EXP_TABLE[m]=1<<m;for(m=8;256>m;m++)l.EXP_TABLE[m]=l.EXP_TABLE[m-4]^l.EXP_TABLE[m-5]^l.EXP_TABLE[m-6]^l.EXP_TABLE[m-8];for(m=0;255>m;m++)l.LOG_TABLE[l.EXP_TABLE[m]]=m;q.prototype={get:function(a){return this.num[a]},getLength:function(){return this.num.length},multiply:function(a){for(var c=Array(this.getLength()+a.getLength()-1),d=0;d<this.getLength();d++)for(var b=0;b<a.getLength();b++)c[d+b]^=l.gexp(l.glog(this.get(d))+l.glog(a.get(b)));return new q(c,0)},mod:function(a){if(0>
this.getLength()-a.getLength())return this;for(var c=l.glog(this.get(0))-l.glog(a.get(0)),d=Array(this.getLength()),b=0;b<this.getLength();b++)d[b]=this.get(b);for(b=0;b<a.getLength();b++)d[b]^=l.gexp(l.glog(a.get(b))+c);return(new q(d,0)).mod(a)}};p.RS_BLOCK_TABLE=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],
[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,
116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,
43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,
3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,
55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,
45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]];p.getRSBlocks=function(a,c){var d=p.getRsBlockTable(a,c);if(void 0==d)throw Error("bad rs block @ typeNumber:"+a+"/errorCorrectLevel:"+c);for(var b=d.length/3,e=[],f=0;f<b;f++)for(var h=d[3*f+0],g=d[3*f+1],j=d[3*f+2],l=0;l<h;l++)e.push(new p(g,j));return e};p.getRsBlockTable=function(a,c){switch(c){case 1:return p.RS_BLOCK_TABLE[4*(a-1)+0];case 0:return p.RS_BLOCK_TABLE[4*(a-1)+1];case 3:return p.RS_BLOCK_TABLE[4*
(a-1)+2];case 2:return p.RS_BLOCK_TABLE[4*(a-1)+3]}};t.prototype={get:function(a){return 1==(this.buffer[Math.floor(a/8)]>>>7-a%8&1)},put:function(a,c){for(var d=0;d<c;d++)this.putBit(1==(a>>>c-d-1&1))},getLengthInBits:function(){return this.length},putBit:function(a){var c=Math.floor(this.length/8);this.buffer.length<=c&&this.buffer.push(0);a&&(this.buffer[c]|=128>>>this.length%8);this.length++}};"string"===typeof h&&(h={text:h});h=r.extend({},{render:"canvas",width:256,height:256,typeNumber:-1,
correctLevel:2,background:"#ffffff",foreground:"#000000"},h);return this.each(function(){var a;if("canvas"==h.render){a=new o(h.typeNumber,h.correctLevel);a.addData(h.text);a.make();var c=document.createElement("canvas");c.width=h.width;c.height=h.height;for(var d=c.getContext("2d"),b=h.width/a.getModuleCount(),e=h.height/a.getModuleCount(),f=0;f<a.getModuleCount();f++)for(var i=0;i<a.getModuleCount();i++){d.fillStyle=a.isDark(f,i)?h.foreground:h.background;var g=Math.ceil((i+1)*b)-Math.floor(i*b),
j=Math.ceil((f+1)*b)-Math.floor(f*b);d.fillRect(Math.round(i*b),Math.round(f*e),g,j)}}else{a=new o(h.typeNumber,h.correctLevel);a.addData(h.text);a.make();c=r("<table></table>").css("width",h.width+"px").css("height",h.height+"px").css("border","0px").css("border-collapse","collapse").css("background-color",h.background);d=h.width/a.getModuleCount();b=h.height/a.getModuleCount();for(e=0;e<a.getModuleCount();e++){f=r("<tr></tr>").css("height",b+"px").appendTo(c);for(i=0;i<a.getModuleCount();i++)r("<td></td>").css("width",
d+"px").css("background-color",a.isDark(e,i)?h.foreground:h.background).appendTo(f)}}a=c;jQuery(a).appendTo(this)})}})(jQuery);

File diff suppressed because one or more lines are too long

@ -1,745 +0,0 @@
/*!
* clipboard.js v1.5.5
* https://zenorocha.github.io/clipboard.js
*
* Licensed MIT © Zeno Rocha
*/
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var matches = require('matches-selector')
module.exports = function (element, selector, checkYoSelf) {
var parent = checkYoSelf ? element : element.parentNode
while (parent && parent !== document) {
if (matches(parent, selector)) return parent;
parent = parent.parentNode
}
}
},{"matches-selector":2}],2:[function(require,module,exports){
/**
* Element prototype.
*/
var proto = Element.prototype;
/**
* Vendor function.
*/
var vendor = proto.matchesSelector
|| proto.webkitMatchesSelector
|| proto.mozMatchesSelector
|| proto.msMatchesSelector
|| proto.oMatchesSelector;
/**
* Expose `match()`.
*/
module.exports = match;
/**
* Match `el` to `selector`.
*
* @param {Element} el
* @param {String} selector
* @return {Boolean}
* @api public
*/
function match(el, selector) {
if (vendor) return vendor.call(el, selector);
var nodes = el.parentNode.querySelectorAll(selector);
for (var i = 0; i < nodes.length; ++i) {
if (nodes[i] == el) return true;
}
return false;
}
},{}],3:[function(require,module,exports){
var closest = require('closest');
/**
* Delegates event to a selector.
*
* @param {Element} element
* @param {String} selector
* @param {String} type
* @param {Function} callback
* @return {Object}
*/
function delegate(element, selector, type, callback) {
var listenerFn = listener.apply(this, arguments);
element.addEventListener(type, listenerFn);
return {
destroy: function() {
element.removeEventListener(type, listenerFn);
}
}
}
/**
* Finds closest match and invokes callback.
*
* @param {Element} element
* @param {String} selector
* @param {String} type
* @param {Function} callback
* @return {Function}
*/
function listener(element, selector, type, callback) {
return function(e) {
e.delegateTarget = closest(e.target, selector, true);
if (e.delegateTarget) {
callback.call(element, e);
}
}
}
module.exports = delegate;
},{"closest":1}],4:[function(require,module,exports){
/**
* Check if argument is a HTML element.
*
* @param {Object} value
* @return {Boolean}
*/
exports.node = function(value) {
return value !== undefined
&& value instanceof HTMLElement
&& value.nodeType === 1;
};
/**
* Check if argument is a list of HTML elements.
*
* @param {Object} value
* @return {Boolean}
*/
exports.nodeList = function(value) {
var type = Object.prototype.toString.call(value);
return value !== undefined
&& (type === '[object NodeList]' || type === '[object HTMLCollection]')
&& ('length' in value)
&& (value.length === 0 || exports.node(value[0]));
};
/**
* Check if argument is a string.
*
* @param {Object} value
* @return {Boolean}
*/
exports.string = function(value) {
return typeof value === 'string'
|| value instanceof String;
};
/**
* Check if argument is a function.
*
* @param {Object} value
* @return {Boolean}
*/
exports.function = function(value) {
var type = Object.prototype.toString.call(value);
return type === '[object Function]';
};
},{}],5:[function(require,module,exports){
var is = require('./is');
var delegate = require('delegate');
/**
* Validates all params and calls the right
* listener function based on its target type.
*
* @param {String|HTMLElement|HTMLCollection|NodeList} target
* @param {String} type
* @param {Function} callback
* @return {Object}
*/
function listen(target, type, callback) {
if (!target && !type && !callback) {
throw new Error('Missing required arguments');
}
if (!is.string(type)) {
throw new TypeError('Second argument must be a String');
}
if (!is.function(callback)) {
throw new TypeError('Third argument must be a Function');
}
if (is.node(target)) {
return listenNode(target, type, callback);
}
else if (is.nodeList(target)) {
return listenNodeList(target, type, callback);
}
else if (is.string(target)) {
return listenSelector(target, type, callback);
}
else {
throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
}
}
/**
* Adds an event listener to a HTML element
* and returns a remove listener function.
*
* @param {HTMLElement} node
* @param {String} type
* @param {Function} callback
* @return {Object}
*/
function listenNode(node, type, callback) {
node.addEventListener(type, callback);
return {
destroy: function() {
node.removeEventListener(type, callback);
}
}
}
/**
* Add an event listener to a list of HTML elements
* and returns a remove listener function.
*
* @param {NodeList|HTMLCollection} nodeList
* @param {String} type
* @param {Function} callback
* @return {Object}
*/
function listenNodeList(nodeList, type, callback) {
Array.prototype.forEach.call(nodeList, function(node) {
node.addEventListener(type, callback);
});
return {
destroy: function() {
Array.prototype.forEach.call(nodeList, function(node) {
node.removeEventListener(type, callback);
});
}
}
}
/**
* Add an event listener to a selector
* and returns a remove listener function.
*
* @param {String} selector
* @param {String} type
* @param {Function} callback
* @return {Object}
*/
function listenSelector(selector, type, callback) {
return delegate(document.body, selector, type, callback);
}
module.exports = listen;
},{"./is":4,"delegate":3}],6:[function(require,module,exports){
function select(element) {
var selectedText;
if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
element.focus();
element.setSelectionRange(0, element.value.length);
selectedText = element.value;
}
else {
if (element.hasAttribute('contenteditable')) {
element.focus();
}
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
selectedText = selection.toString();
}
return selectedText;
}
module.exports = select;
},{}],7:[function(require,module,exports){
function E () {
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
}
E.prototype = {
on: function (name, callback, ctx) {
var e = this.e || (this.e = {});
(e[name] || (e[name] = [])).push({
fn: callback,
ctx: ctx
});
return this;
},
once: function (name, callback, ctx) {
var self = this;
function listener () {
self.off(name, listener);
callback.apply(ctx, arguments);
};
listener._ = callback
return this.on(name, listener, ctx);
},
emit: function (name) {
var data = [].slice.call(arguments, 1);
var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
var i = 0;
var len = evtArr.length;
for (i; i < len; i++) {
evtArr[i].fn.apply(evtArr[i].ctx, data);
}
return this;
},
off: function (name, callback) {
var e = this.e || (this.e = {});
var evts = e[name];
var liveEvents = [];
if (evts && callback) {
for (var i = 0, len = evts.length; i < len; i++) {
if (evts[i].fn !== callback && evts[i].fn._ !== callback)
liveEvents.push(evts[i]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
(liveEvents.length)
? e[name] = liveEvents
: delete e[name];
return this;
}
};
module.exports = E;
},{}],8:[function(require,module,exports){
'use strict';
exports.__esModule = true;
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _select = require('select');
var _select2 = _interopRequireDefault(_select);
/**
* Inner class which performs selection from either `text` or `target`
* properties and then executes copy or cut operations.
*/
var ClipboardAction = (function () {
/**
* @param {Object} options
*/
function ClipboardAction(options) {
_classCallCheck(this, ClipboardAction);
this.resolveOptions(options);
this.initSelection();
}
/**
* Defines base properties passed from constructor.
* @param {Object} options
*/
ClipboardAction.prototype.resolveOptions = function resolveOptions() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
this.action = options.action;
this.emitter = options.emitter;
this.target = options.target;
this.text = options.text;
this.trigger = options.trigger;
this.selectedText = '';
};
/**
* Decides which selection strategy is going to be applied based
* on the existence of `text` and `target` properties.
*/
ClipboardAction.prototype.initSelection = function initSelection() {
if (this.text && this.target) {
throw new Error('Multiple attributes declared, use either "target" or "text"');
} else if (this.text) {
this.selectFake();
} else if (this.target) {
this.selectTarget();
} else {
throw new Error('Missing required attributes, use either "target" or "text"');
}
};
/**
* Creates a fake textarea element, sets its value from `text` property,
* and makes a selection on it.
*/
ClipboardAction.prototype.selectFake = function selectFake() {
var _this = this;
this.removeFake();
this.fakeHandler = document.body.addEventListener('click', function () {
return _this.removeFake();
});
this.fakeElem = document.createElement('textarea');
this.fakeElem.style.position = 'absolute';
this.fakeElem.style.left = '-9999px';
this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
this.fakeElem.setAttribute('readonly', '');
this.fakeElem.value = this.text;
document.body.appendChild(this.fakeElem);
this.selectedText = _select2['default'](this.fakeElem);
this.copyText();
};
/**
* Only removes the fake element after another click event, that way
* a user can hit `Ctrl+C` to copy because selection still exists.
*/
ClipboardAction.prototype.removeFake = function removeFake() {
if (this.fakeHandler) {
document.body.removeEventListener('click');
this.fakeHandler = null;
}
if (this.fakeElem) {
document.body.removeChild(this.fakeElem);
this.fakeElem = null;
}
};
/**
* Selects the content from element passed on `target` property.
*/
ClipboardAction.prototype.selectTarget = function selectTarget() {
this.selectedText = _select2['default'](this.target);
this.copyText();
};
/**
* Executes the copy operation based on the current selection.
*/
ClipboardAction.prototype.copyText = function copyText() {
var succeeded = undefined;
try {
succeeded = document.execCommand(this.action);
} catch (err) {
succeeded = false;
}
this.handleResult(succeeded);
};
/**
* Fires an event based on the copy operation result.
* @param {Boolean} succeeded
*/
ClipboardAction.prototype.handleResult = function handleResult(succeeded) {
if (succeeded) {
this.emitter.emit('success', {
action: this.action,
text: this.selectedText,
trigger: this.trigger,
clearSelection: this.clearSelection.bind(this)
});
} else {
this.emitter.emit('error', {
action: this.action,
trigger: this.trigger,
clearSelection: this.clearSelection.bind(this)
});
}
};
/**
* Removes current selection and focus from `target` element.
*/
ClipboardAction.prototype.clearSelection = function clearSelection() {
if (this.target) {
this.target.blur();
}
window.getSelection().removeAllRanges();
};
/**
* Sets the `action` to be performed which can be either 'copy' or 'cut'.
* @param {String} action
*/
/**
* Destroy lifecycle.
*/
ClipboardAction.prototype.destroy = function destroy() {
this.removeFake();
};
_createClass(ClipboardAction, [{
key: 'action',
set: function set() {
var action = arguments.length <= 0 || arguments[0] === undefined ? 'copy' : arguments[0];
this._action = action;
if (this._action !== 'copy' && this._action !== 'cut') {
throw new Error('Invalid "action" value, use either "copy" or "cut"');
}
},
/**
* Gets the `action` property.
* @return {String}
*/
get: function get() {
return this._action;
}
/**
* Sets the `target` property using an element
* that will be have its content copied.
* @param {Element} target
*/
}, {
key: 'target',
set: function set(target) {
if (target !== undefined) {
if (target && typeof target === 'object' && target.nodeType === 1) {
this._target = target;
} else {
throw new Error('Invalid "target" value, use a valid Element');
}
}
},
/**
* Gets the `target` property.
* @return {String|HTMLElement}
*/
get: function get() {
return this._target;
}
}]);
return ClipboardAction;
})();
exports['default'] = ClipboardAction;
module.exports = exports['default'];
},{"select":6}],9:[function(require,module,exports){
'use strict';
exports.__esModule = true;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _clipboardAction = require('./clipboard-action');
var _clipboardAction2 = _interopRequireDefault(_clipboardAction);
var _tinyEmitter = require('tiny-emitter');
var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter);
var _goodListener = require('good-listener');
var _goodListener2 = _interopRequireDefault(_goodListener);
/**
* Base class which takes one or more elements, adds event listeners to them,
* and instantiates a new `ClipboardAction` on each click.
*/
var Clipboard = (function (_Emitter) {
_inherits(Clipboard, _Emitter);
/**
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger
* @param {Object} options
*/
function Clipboard(trigger, options) {
_classCallCheck(this, Clipboard);
_Emitter.call(this);
this.resolveOptions(options);
this.listenClick(trigger);
}
/**
* Helper function to retrieve attribute value.
* @param {String} suffix
* @param {Element} element
*/
/**
* Defines if attributes would be resolved using internal setter functions
* or custom functions that were passed in the constructor.
* @param {Object} options
*/
Clipboard.prototype.resolveOptions = function resolveOptions() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
this.text = typeof options.text === 'function' ? options.text : this.defaultText;
};
/**
* Adds a click event listener to the passed trigger.
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger
*/
Clipboard.prototype.listenClick = function listenClick(trigger) {
var _this = this;
this.listener = _goodListener2['default'](trigger, 'click', function (e) {
return _this.onClick(e);
});
};
/**
* Defines a new `ClipboardAction` on each click event.
* @param {Event} e
*/
Clipboard.prototype.onClick = function onClick(e) {
var trigger = e.delegateTarget || e.currentTarget;
if (this.clipboardAction) {
this.clipboardAction = null;
}
this.clipboardAction = new _clipboardAction2['default']({
action: this.action(trigger),
target: this.target(trigger),
text: this.text(trigger),
trigger: trigger,
emitter: this
});
};
/**
* Default `action` lookup function.
* @param {Element} trigger
*/
Clipboard.prototype.defaultAction = function defaultAction(trigger) {
return getAttributeValue('action', trigger);
};
/**
* Default `target` lookup function.
* @param {Element} trigger
*/
Clipboard.prototype.defaultTarget = function defaultTarget(trigger) {
var selector = getAttributeValue('target', trigger);
if (selector) {
return document.querySelector(selector);
}
};
/**
* Default `text` lookup function.
* @param {Element} trigger
*/
Clipboard.prototype.defaultText = function defaultText(trigger) {
return getAttributeValue('text', trigger);
};
/**
* Destroy lifecycle.
*/
Clipboard.prototype.destroy = function destroy() {
this.listener.destroy();
if (this.clipboardAction) {
this.clipboardAction.destroy();
this.clipboardAction = null;
}
};
return Clipboard;
})(_tinyEmitter2['default']);
function getAttributeValue(suffix, element) {
var attribute = 'data-clipboard-' + suffix;
if (!element.hasAttribute(attribute)) {
return;
}
return element.getAttribute(attribute);
}
exports['default'] = Clipboard;
module.exports = exports['default'];
},{"./clipboard-action":8,"good-listener":5,"tiny-emitter":7}]},{},[9])(9)
});

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save