<?php
if(!class_exists('pwaforwp_ptafp')){
require_once PWAFORWP_PTAFP_PLUGIN_DIR."/inc/common_authentication.php";
class pwaforwp_ptafp{
public $settings = array();
public $ptap_authentication;
public function __construct(){
add_action("admin_init", array( $this, 'init' ) );
add_action( 'plugin_action_links_' . plugin_basename( PWAFORWP_PTAFP_DIR_NAME_FILE ), array($this, 'plugin_action_links') );
if(function_exists('pwaforwp_defaultSettings')){
$this->settings = pwaforwp_defaultSettings();
}else{ $this->settings = array(); }
$this->ptap_authentication = new ptap_common_authentication();
add_action("admin_enqueue_scripts", array($this , 'script_enqueue'));
//on save
add_action( "update_option_pwaforwp_settings", array($this, 'on_options_update') ,10,3);
add_action("wp_ajax_pwa_to_apk_plugin_caller", array($this, "pwa_to_apk_plugin_gen"));
add_action("wp_ajax_pwa_to_apk_plugin_project_caller", array($this, "pwa_to_apk_plugin_project"));
add_action("wp_ajax_pwa_to_apk_assets_deeeplink", array($this, "pwa_to_apk_assets_deeeplink"));
add_action("wp_ajax_pwaforwp_apk_keystore_upload", array($this, "pwaforwp_apk_keystore_upload"));
add_action("wp_ajax_pwa_to_apk_assets_removeold", array($this, "pwa_to_apk_assets_removeold"));
}
public function on_options_update($old_value, $value, $option){
$pwa_pwatapk = get_option("pwa_pwatapk", true);
if(!is_array($pwa_pwatapk)){ $pwa_pwatapk = array(); }
if(isset($pwa_pwatapk["user_authentication"]) && $pwa_pwatapk["user_authentication"]==1){
return true;
}
if( (isset($value['ptafp_addon_license_key'])
&& isset($value['ptafp_addon_license_key_status'])
&& $value['ptafp_addon_license_key_status'] == 'active'
) && isset($value['pwa_to_apk_plugin'])
){
/*$data = array(
'license_key' => $value['ptafp_addon_license_key'],
'license_status'=> $value['ptafp_addon_license_key_status'],
'referrer'=> get_home_url()
);
$response = $this->ptap_authentication->sender_request("registerSiteUser", $data);
if($response){*/
$pwa_pwatapk["user_authentication"] = 1;
update_option("pwa_pwatapk", $pwa_pwatapk);
//}
}
}
function pwa_to_apk_plugin_gen(){
$nonce = $_POST['ref'];
if(!wp_verify_nonce($nonce, 'pwa_pwatapk_nonce_gen')){
echo json_encode(array("status"=>400, "message"=>"Request not verified"));die;
}
$pwa_pwatapk = get_option("pwa_pwatapk", true);
if( (isset($pwa_pwatapk["user_authentication"]) && $pwa_pwatapk["user_authentication"]!=1)){
echo json_encode(array("status"=>400, "message"=>"Plugin not activated"));die;
}
//PWA settings
$defaults = pwaforwp_defaultSettings();
$signingMode = 'new'; $keyPassword = $keystorePassword = ''; $keystorefile = null;
$appVersionCode = 1;
$version = "1.0.0";
if(isset($defaults['apk_type']) && $defaults['apk_type']=='mine'){
$signingMode = 'mine';
$keyPassword = isset($defaults['apk_key_password'])? $defaults['apk_key_password']: '';
$keystorePassword = isset($defaults['apk_key_store_password'])? $defaults['apk_key_store_password']: '';
if(!file_exists(PWAFORWP_PTAFP_PLUGIN_DIR."/keystore/signing.keystore")){
echo json_encode(array("status"=>400, "message"=>"Keystore File not found"));die;
}else{
$keystorefile = 'data:application/octet-stream;base64,'.base64_encode(file_get_contents(PWAFORWP_PTAFP_PLUGIN_DIR."/keystore/signing.keystore"));
}
if( empty($keyPassword) ){
echo json_encode(array("status"=>400, "message"=>"Key password is empty"));die;
}
if( empty($keystorePassword) ){
echo json_encode(array("status"=>400, "message"=>"Key store password is empty"));die;
}
if(isset($defaults['apk_app_version']) && !empty($defaults['apk_app_version'])){
$version = $defaults['apk_app_version'];
}else{
echo json_encode(array("status"=>400, "message"=>"Last APK version is empty"));die;
}
if( isset($defaults['apk_app_code']) && !empty($defaults['apk_app_code']) ) {
$appVersionCode = $defaults['apk_app_code']+1;
}else{
echo json_encode(array("status"=>400, "message"=>"Last APK code is empty, ex: 1"));die;
}
if(version_compare ( $version , "1.0.0" , '>=' ) ){
//$version = $pwa_pwatapk['last_version'];
$verArr = explode(".", $version);
if($verArr[count($verArr)-1]<=9){
$verArr[count($verArr)-1] = $verArr[count($verArr)-1]+1;
}elseif($verArr[count($verArr)-2]<=9){
$verArr[count($verArr)-1] = 0;
$verArr[count($verArr)-2] = $verArr[count($verArr)-2]+1;
}elseif($verArr[count($verArr)-3]<=9){
$verArr[count($verArr)-1] = 0;
$verArr[count($verArr)-2] = 0;
$verArr[count($verArr)-3] = $verArr[count($verArr)-3]+1;
}
$version = implode(".", $verArr);
}
}
$host = pwaforwp_home_url();
/*$host = parse_url(pwaforwp_home_url(), PHP_URL_HOST);
if(strpos($host, 'www')!==false){
$host = str_replace("www.", "", $host);
} */
$packageId = $defaults['pta_package_id'];
$data = array(
"packageId"=> $packageId,
"host"=> $host,
"name"=> esc_attr($defaults['app_blog_name']),
"launcherName"=> esc_attr($defaults['app_blog_short_name']),
"themeColor"=> sanitize_hex_color($defaults['theme_color']),
"navigationColor"=> sanitize_hex_color($defaults['background_color']),
"backgroundColor"=> sanitize_hex_color($defaults['background_color']),
"startUrl"=> "/",
"webManifestUrl"=>esc_url( pwaforwp_manifest_json_url() ),
"iconUrl"=> esc_url(pwaforwp_https($defaults['icon'])),
"maskableIconUrl"=> esc_url(pwaforwp_https($defaults['splash_icon'])),
"appVersion"=> $version,
"appVersionCode"=> $appVersionCode,
"useBrowserOnChromeOS"=> true,
"splashScreenFadeOutDuration"=> 300,
"enableNotifications"=> true,
"display"=> esc_attr($defaults['display']),
"shortcuts"=> array(array(
"name"=> esc_attr($defaults['app_blog_name']),
"short_name"=> esc_attr($defaults['app_blog_short_name']),
"url"=> "/?shortcut",
"icons"=> array( /*array(
"sizes"=> "128x128",
"src"=> "/favicon.png",
) */)
)),
"signingMode"=> $signingMode,
"signing"=> array(
"file"=> $keystorefile,
"alias"=> "my-key-alias",
"fullName"=> "PWA for wp",
"organization"=> "MAGAZINE3",
"organizationalUnit"=> "Development",
"countryCode"=> "IN",
"keyPassword"=> $keyPassword,
"storePassword"=> $keystorePassword
),
"fallbackType"=> "customtabs",
);
$headers_data = array('request_url'=>esc_url(get_home_url()), 'request_license'=>sanitize_text_field($this->settings['ptafp_addon_license_key']));
set_time_limit(500);
$response = $this->ptap_authentication->sender_request("generateApkZip", $data, $headers_data, true);
if($response){
if( $response['status'] == 200){
$host = parse_url(pwaforwp_home_url(), PHP_URL_HOST);
if(strpos($host, 'www')!==false){
$host = str_replace("www.", "", $host);
}
$upload_path = wp_upload_dir();
$file_path = $upload_path['basedir']."/pwa_to_app/";
wp_mkdir_p($file_path);
$file_name = $host."-".$version."-".$this->generate_random_string().'.zip';
$file_name_path = $file_path.'/'.$file_name;
$fp = file_put_contents($file_name_path, $response['body']);
$pwa_pwatapk["user_authentication"] = 1;
$pwa_pwatapk["last_version"] = $version;
$pwa_pwatapk["old_files"][] = array('name'=>$file_name_path, 'fname'=>$file_name, 'version'=>$version, 'time'=> time());
update_option("pwa_pwatapk", $pwa_pwatapk);
$this->pwa_to_apk_assets_deeeplink($version);
$fileUrl = $upload_path['baseurl']."/pwa_to_app/".$file_name;
echo json_encode(array("status"=>200, "message"=> "apk downloaded <a href
Lee达森
- 粉丝: 1518
- 资源: 1万+
最新资源
- Python深度强化学习方法动态规划无人机基站轨迹源码
- 峰会报告自动化生成基础教程
- 算法竞赛中的离散化 概念总结和基本操作全解
- 算法竞赛位运算(简单易懂)
- 常用一维二维 前缀和与差分算法模板总结
- SAR成像算法+后向投影(BP)算法+星载平台实测数据
- 横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横向循环焦点轮播图横
- 基于Java和HTML的留言墙、验证码、计算器基础项目设计源码
- 基于JAVA C/C++的嵌入式设备组网平台物联网框架设计源码
- 基于Java开发的高性能全文检索工具包jsearch设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈