8460cf2aab85b9580d3e2e5e3c951e67f257fR14">14
+    ],
15
+    client: {
16
+      jasmine: {
17
+        // you can add configuration options for Jasmine here
18
+        // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19
+        // for example, you can disable the random execution with `random: false`
20
+        // or set a specific seed with `seed: 4321`
21
+      },
22
+      clearContext: false // leave Jasmine Spec Runner output visible in browser
23
+    },
24
+    jasmineHtmlReporter: {
25
+      suppressAll: true // removes the duplicated traces
26
+    },
27
+    coverageReporter: {
28
+      dir: require('path').join(__dirname, './coverage/ngv'),
29
+      subdir: '.',
30
+      reporters: [
31
+        { type: 'html' },
32
+        { type: 'text-summary' }
33
+      ]
34
+    },
35
+    reporters: ['progress', 'kjhtml'],
36
+    port: 9876,
37
+    colors: true,
38
+    logLevel: config.LOG_INFO,
39
+    autoWatch: true,
40
+    browsers: ['Chrome'],
41
+    singleRun: false,
42
+    restartOnFileChange: true
43
+  });
44
+};

binární
my-release-key.keystore


File diff suppressed because it is too large
+ 18344 - 0
package-lock.json


+ 180 - 0
package.json

@@ -0,0 +1,180 @@
1
+{
2
+  "name": "hp",
3
+  "version": "0.0.1",
4
+  "author": "Ionic Framework",
5
+  "homepage": "https://ionicframework.com/",
6
+  "scripts": {
7
+    "ng": "ng",
8
+    "start": "ng serve",
9
+    "build": "ng build",
10
+    "test": "ng test",
11
+    "lint": "ng lint",
12
+    "e2e": "ng e2e"
13
+  },
14
+  "private": true,
15
+  "dependencies": {
16
+    "@angular/common": "~13.0.3",
17
+    "@angular/compiler": "~13.0.3",
18
+    "@angular/core": "~13.0.3",
19
+    "@angular/forms": "~13.0.3",
20
+    "@angular/platform-browser": "~13.0.3",
21
+    "@angular/platform-browser-dynamic": "~13.0.3",
22
+    "@angular/router": "~13.0.3",
23
+    "@awesome-cordova-plugins/barcode-scanner": "^5.37.1",
24
+    "@awesome-cordova-plugins/core": "^5.37.1",
25
+    "@awesome-cordova-plugins/file-transfer": "^5.37.1",
26
+    "@awesome-cordova-plugins/push": "^5.37.1",
27
+    "@awesome-cordova-plugins/status-bar": "^5.37.2",
28
+    "@awesome-cordova-plugins/stripe": "^5.37.1",
29
+    "@capacitor/app": "1.0.6",
30
+    "@capacitor/core": "3.3.2",
31
+    "@capacitor/haptics": "1.1.3",
32
+    "@capacitor/ios": "^3.3.2",
33
+    "@capacitor/keyboard": "1.1.3",
34
+    "@capacitor/status-bar": "1.0.6",
35
+    "@fortawesome/angular-fontawesome": "^0.10.1",
36
+    "@fortawesome/fontawesome-free": "^5.15.4",
37
+    "@fortawesome/fontawesome-svg-core": "^1.2.36",
38
+    "@fortawesome/free-brands-svg-icons": "^5.15.4",
39
+    "@fortawesome/free-regular-svg-icons": "^5.15.4",
40
+    "@fortawesome/free-solid-svg-icons": "^5.15.4",
41
+    "@ionic-native/android-permissions": "^5.30.0",
42
+    "@ionic-native/call-number": "^5.36.0",
43
+    "@ionic-native/core": "^5.36.0",
44
+    "@ionic-native/device": "^5.30.0",
45
+    "@ionic-native/email-composer": "^5.36.0",
46
+    "@ionic-native/facebook": "^5.36.0",
47
+    "@ionic-native/geolocation": "^5.36.0",
48
+    "@ionic-native/http": "^5.36.0",
49
+    "@ionic-native/in-app-browser": "^5.36.0",
50
+    "@ionic-native/native-geocoder": "^5.36.0",
51
+    "@ionic-native/paypal": "^5.30.0",
52
+    "@ionic-native/push": "^5.36.0",
53
+    "@ionic-native/sign-in-with-apple": "^5.36.0",
54
+    "@ionic-native/uid": "^5.30.0",
55
+    "@ionic/angular": "^5.9.1",
56
+    "@ionic/storage": "^3.0.6",
57
+    "@ionic/storage-angular": "^3.0.6",
58
+    "abbrev": "^1.1.1",
59
+    "cordova-plugin-device": "2.0.3",
60
+    "cordova-plugin-ionic-webview": "5.0.0",
61
+    "cordova-plugin-splashscreen": "6.0.0",
62
+    "cordova-plugin-whitelist": "1.3.5",
63
+    "ionic-img-viewer": "^2.9.0",
64
+    "lru-cache": "^6.0.0",
65
+    "mimic-fn": "^4.0.0",
66
+    "onetime": "^6.0.0",
67
+    "osenv": "^0.1.5",
68
+    "resolve-url": "^0.2.1",
69
+    "rxjs": "~7.4.0",
70
+    "sharp": "^0.29.3",
71
+    "string.prototype.codepointat": "^1.0.0",
72
+    "tslib": "^2.3.1",
73
+    "yallist": "^4.0.0",
74
+    "zone.js": "~0.11.4"
75
+  },
76
+  "devDependencies": {
77
+    "@angular-devkit/build-angular": "~13.0.4",
78
+    "@angular-eslint/builder": "~13.0.1",
79
+    "@angular-eslint/eslint-plugin": "~13.0.1",
80
+    "@angular-eslint/eslint-plugin-template": "~13.0.1",
81
+    "@angular-eslint/template-parser": "~13.0.1",
82
+    "@angular/cli": "^13.0.4",
83
+    "@angular/compiler": "~13.0.3",
84
+    "@angular/compiler-cli": "~13.0.3",
85
+    "@angular/language-service": "~13.0.3",
86
+    "@capacitor/cli": "3.3.2",
87
+    "@ionic/angular-toolkit": "^5.0.3",
88
+    "@types/jasmine": "~3.10.2",
89
+    "@types/jasminewd2": "~2.0.10",
90
+    "@types/node": "^16.11.11",
91
+    "@typescript-eslint/eslint-plugin": "4.16.1",
92
+    "@typescript-eslint/parser": "4.16.1",
93
+    "call-number": "^1.0.1",
94
+    "card.io.cordova.mobilesdk": "^2.1.0",
95
+    "com.paypal.cordova.mobilesdk": "^3.5.0",
96
+    "cordova-android": "^9.1.0",
97
+    "cordova-ios": "^6.2.0",
98
+    "cordova-plugin-add-swift-support": "^2.0.2",
99
+    "cordova-plugin-advanced-http": "^3.2.2",
100
+    "cordova-plugin-android-permissions": "^1.1.2",
101
+    "cordova-plugin-androidx": "^3.0.0",
102
+    "cordova-plugin-androidx-adapter": "^1.1.3",
103
+    "cordova-plugin-email-composer": "^0.10.0",
104
+    "cordova-plugin-facebook-connect": "^3.2.0",
105
+    "cordova-plugin-file": "^6.0.2",
106
+    "cordova-plugin-file-transfer": "^1.7.1",
107
+    "cordova-plugin-geolocation": "^4.1.0",
108
+    "cordova-plugin-googlemaps": "^2.7.1",
109
+    "cordova-plugin-googlemaps-sdk": "github:mapsplugin/cordova-plugin-googlemaps-sdk",
110
+    "cordova-plugin-inappbrowser": "^5.0.0",
111
+    "cordova-plugin-ionic-keyboard": "^2.2.0",
112
+    "cordova-plugin-nativegeocoder": "^3.4.1",
113
+    "cordova-plugin-sign-in-with-apple": "^0.1.2",
114
+    "cordova-plugin-stripe": "^1.5.3",
115
+    "cordova-plugin-uid": "^1.3.0",
116
+    "cordova-support-google-services": "^1.4.1",
117
+    "eslint": "^8.3.0",
118
+    "eslint-plugin-import": "2.25.3",
119
+    "eslint-plugin-jsdoc": "37.1.0",
120
+    "eslint-plugin-prefer-arrow": "1.2.3",
121
+    "jasmine-core": "~3.10.1",
122
+    "jasmine-spec-reporter": "~7.0.0",
123
+    "karma": "~6.3.9",
124
+    "karma-chrome-launcher": "~3.1.0",
125
+    "karma-coverage": "~2.1.0",
126
+    "karma-coverage-istanbul-reporter": "~3.0.3",
127
+    "karma-jasmine": "~4.0.1",
128
+    "karma-jasmine-html-reporter": "^1.7.0",
129
+    "mx.ferreyra.callnumber": "0.0.2",
130
+    "phonegap-plugin-multidex": "^1.0.0",
131
+    "phonegap-plugin-push": "^2.3.0",
132
+    "protractor": "~7.0.0",
133
+    "ts-node": "~10.4.0",
134
+    "typescript": "~4.2.4"
135
+  },
136
+  "description": "An Ionic project",
137
+  "cordova": {
138
+    "plugins": {
139
+      "cordova-plugin-ionic-keyboard": {},
140
+      "cordova-plugin-geolocation": {},
141
+      "cordova-plugin-nativegeocoder": {
142
+        "LOCATION_WHEN_IN_USE_DESCRIPTION": "Use geocoder service"
143
+      },
144
+      "mx.ferreyra.callnumber": {},
145
+      "cordova-plugin-email-composer": {},
146
+      "call-number": {},
147
+      "cordova-plugin-inappbrowser": {},
148
+      "cordova-plugin-sign-in-with-apple": {},
149
+      "cordova-plugin-androidx": {},
150
+      "cordova-plugin-androidx-adapter": {},
151
+      "phonegap-plugin-push": {},
152
+      "cordova-plugin-file-transfer": {},
153
+      "cordova-plugin-stripe": {},
154
+      "com.paypal.cordova.mobilesdk": {},
155
+      "cordova-plugin-whitelist": {},
156
+      "cordova-plugin-device": {},
157
+      "cordova-plugin-splashscreen": {},
158
+      "cordova-plugin-ionic-webview": {},
159
+      "cordova-plugin-facebook-connect": {
160
+        "APP_ID": "4746807965342529",
161
+        "APP_NAME": "FarmSter",
162
+        "FACEBOOK_URL_SCHEME_SUFFIX": " ",
163
+        "OTHER_APP_SCHEMES": " ",
164
+        "FACEBOOK_AUTO_LOG_APP_EVENTS": "true",
165
+        "FACEBOOK_HYBRID_APP_EVENTS": "false",
166
+        "FACEBOOK_ADVERTISER_ID_COLLECTION": "true",
167
+        "FACEBOOK_ANDROID_SDK_VERSION": "11.3.0",
168
+        "FACEBOOK_IOS_SDK_VERSION": "11.1.0",
169
+        "FACEBOOK_BROWSER_SDK_VERSION": "v11.0"
170
+      },
171
+      "cordova-plugin-statusbar": {},
172
+      "cordova-plugin-android-permissions": {},
173
+      "cordova-plugin-dreamover-uid": {}
174
+    },
175
+    "platforms": [
176
+      "ios",
177
+      "android"
178
+    ]
179
+  }
180
+}

+ 8 - 0
resources/README.md

@@ -0,0 +1,8 @@
1
+These are Cordova resources. You can replace icon.png and splash.png and run
2
+`ionic cordova resources` to generate custom icons and splash screens for your
3
+app. See `ionic cordova resources --help` for details.
4
+
5
+Cordova reference documentation:
6
+
7
+- Icons: https://cordova.apache.org/docs/en/latest/config_ref/images.html
8
+- Splash Screens: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-splashscreen/

binární
resources/android/icon/drawable-hdpi-icon.png


binární
resources/android/icon/drawable-ldpi-icon.png


binární
resources/android/icon/drawable-mdpi-icon.png


binární
resources/android/icon/drawable-xhdpi-icon.png


binární
resources/android/icon/drawable-xxhdpi-icon.png


binární
resources/android/icon/drawable-xxxhdpi-icon.png


binární
resources/android/splash/drawable-land-hdpi-screen.png


binární
resources/android/splash/drawable-land-ldpi-screen.png


binární
resources/android/splash/drawable-land-mdpi-screen.png


binární
resources/android/splash/drawable-land-xhdpi-screen.png


binární
resources/android/splash/drawable-land-xxhdpi-screen.png


binární
resources/android/splash/drawable-land-xxxhdpi-screen.png


binární
resources/android/splash/drawable-port-hdpi-screen.png


binární
resources/android/splash/drawable-port-ldpi-screen.png


binární
resources/android/splash/drawable-port-mdpi-screen.png


binární
resources/android/splash/drawable-port-xhdpi-screen.png


binární
resources/android/splash/drawable-port-xxhdpi-screen.png


binární
resources/android/splash/drawable-port-xxxhdpi-screen.png


+ 7 - 0
resources/android/xml/network_security_config.xml

@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<network-security-config>
3
+    <domain-config cleartextTrafficPermitted="true">
4
+        <domain includeSubdomains="true">localhost</domain>
5
+        <domain includeSubdomains="true">tamtime.iamarray.xyz</domain>
6
+    </domain-config>
7
+</network-security-config>

binární
resources/icon.png


binární
resources/ios/icon/icon-1024.png


binární
resources/ios/icon/icon-108@2x.png


binární
resources/ios/icon/icon-20.png


binární
resources/ios/icon/icon-20@2x.png


binární
resources/ios/icon/icon-20@3x.png


binární
resources/ios/icon/icon-24@2x.png


binární
resources/ios/icon/icon-27.5@2x.png


binární
resources/ios/icon/icon-29.png


binární
resources/ios/icon/icon-29@2x.png


binární
resources/ios/icon/icon-29@3x.png


binární
resources/ios/icon/icon-40.png


binární
resources/ios/icon/icon-40@2x.png


binární
resources/ios/icon/icon-40@3x.png


binární
resources/ios/icon/icon-44@2x.png


binární
resources/ios/icon/icon-50.png


binární
resources/ios/icon/icon-50@2x.png


binární
resources/ios/icon/icon-60.png


binární
resources/ios/icon/icon-60@2x.png


binární
resources/ios/icon/icon-60@3x.png


binární
resources/ios/icon/icon-72.png


binární
resources/ios/icon/icon-72@2x.png


binární
resources/ios/icon/icon-76.png


binární
resources/ios/icon/icon-76@2x.png


binární
resources/ios/icon/icon-83.5@2x.png


binární
resources/ios/icon/icon-86@2x.png


binární
resources/ios/icon/icon-98@2x.png


binární
resources/ios/icon/icon.png


binární
resources/ios/icon/icon@2x.png


binární
resources/ios/splash/Default-1792h~iphone.png


binární
resources/ios/splash/Default-2436h.png


binární
resources/ios/splash/Default-2688h~iphone.png


binární
resources/ios/splash/Default-568h@2x~iphone.png


binární
resources/ios/splash/Default-667h.png


binární
resources/ios/splash/Default-736h.png


binární
resources/ios/splash/Default-Landscape-1792h~iphone.png


binární
resources/ios/splash/Default-Landscape-2436h.png


binární
resources/ios/splash/Default-Landscape-2688h~iphone.png


binární
resources/ios/splash/Default-Landscape-736h.png


binární
resources/ios/splash/Default-Landscape@2x~ipad.png


binární
resources/ios/splash/Default-Landscape@~ipadpro.png


binární
resources/ios/splash/Default-Landscape~ipad.png


binární
resources/ios/splash/Default-Portrait@2x~ipad.png


binární
resources/ios/splash/Default-Portrait@~ipadpro.png


binární
resources/ios/splash/Default-Portrait~ipad.png


binární
resources/ios/splash/Default@2x~iphone.png


binární
resources/ios/splash/Default@2x~universal~anyany.png


binární
resources/ios/splash/Default~iphone.png


binární
resources/splash.png


+ 92 - 0
src/app/app-routing.module.ts

@@ -0,0 +1,92 @@
1
+import { NgModule } from '@angular/core';
2
+import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
3
+
4
+const routes: Routes = [
5
+  {
6
+    path: '',
7
+    loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule)
8
+  },
9
+  {
10
+    path: 'home',
11
+    loadChildren: () => import('./home/home.module').then( m => m.HomePageModule)
12
+  },
13
+  {
14
+    path: 'register',
15
+    loadChildren: () => import('./register/register.module').then( m => m.RegisterPageModule)
16
+  },
17
+  {
18
+    path: 'login',
19
+    loadChildren: () => import('./login/login.module').then( m => m.LoginPageModule)
20
+  },
21
+  {
22
+    path: 'forgot-password',
23
+    loadChildren: () => import('./forgot-password/forgot-password.module').then( m => m.ForgotPasswordPageModule)
24
+  },
25
+  {
26
+    path: 'register-form',
27
+    loadChildren: () => import('./register-form/register-form.module').then( m => m.RegisterFormPageModule)
28
+  },
29
+  {
30
+    path: 'profile',
31
+    loadChildren: () => import('./profile/profile.module').then( m => m.ProfilePageModule)
32
+  },
33
+  {
34
+    path: 'reset-password',
35
+    loadChildren: () => import('./reset-password/reset-password.module').then( m => m.ResetPasswordPageModule)
36
+  },
37
+  {
38
+    path: 'placedetail',
39
+    loadChildren: () => import('./placedetail/placedetail.module').then( m => m.PlacedetailPageModule)
40
+  },
41
+  {
42
+    path: 'place',
43
+    loadChildren: () => import('./place/place.module').then( m => m.PlacePageModule)
44
+  },
45
+  {
46
+    path: 'province',
47
+    loadChildren: () => import('./province/province.module').then( m => m.ProvincePageModule)
48
+  },
49
+  {
50
+    path: 'gmap',
51
+    loadChildren: () => import('./gmap/gmap.module').then( m => m.GmapPageModule)
52
+  },
53
+  {
54
+    path: 'nearme',
55
+    loadChildren: () => import('./nearme/nearme.module').then( m => m.NearmePageModule)
56
+  },
57
+  {
58
+    path: 'sample',
59
+    loadChildren: () => import('./sample/sample.module').then( m => m.SamplePageModule)
60
+  },
61
+  {
62
+    path: 'product',
63
+    loadChildren: () => import('./product/product.module').then( m => m.ProductPageModule)
64
+  },
65
+  {
66
+    path: 'product-detail',
67
+    loadChildren: () => import('./product-detail/product-detail.module').then( m => m.ProductDetailPageModule)
68
+  },
69
+  {
70
+    path: 'tracking',
71
+    loadChildren: () => import('./tracking/tracking.module').then( m => m.TrackingPageModule)
72
+  },
73
+  {
74
+    path: 'news',
75
+    loadChildren: () => import('./news/news.module').then( m => m.NewsPageModule)
76
+  },
77
+  {
78
+    path: 'checkout',
79
+    loadChildren: () => import('./checkout/checkout.module').then( m => m.CheckoutPageModule)
80
+  },
81
+  {
82
+    path: 'pay',
83
+    loadChildren: () => import('./pay/pay.module').then( m => m.PayPageModule)
84
+  }
85
+];
86
+@NgModule({
87
+  imports: [
88
+    RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
89
+  ],
90
+  exports: [RouterModule]
91
+})
92
+export class AppRoutingModule {}

+ 3 - 0
src/app/app.component.html

@@ -0,0 +1,3 @@
1
+<ion-app>
2
+  <ion-router-outlet></ion-router-outlet>
3
+</ion-app>

+ 4 - 0
src/app/app.component.scss

@@ -0,0 +1,4 @@
1
+.product-title {
2
+    font-weight:bold;
3
+    font-size:20px;
4
+}

+ 23 - 0
src/app/app.component.spec.ts

@@ -0,0 +1,23 @@
1
+import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
2
+import { TestBed, waitForAsync } from '@angular/core/testing';
3
+
4
+import { AppComponent } from './app.component';
5
+
6
+describe('AppComponent', () => {
7
+
8
+  beforeEach(waitForAsync(() => {
9
+
10
+    TestBed.configureTestingModule({
11
+      declarations: [AppComponent],
12
+      schemas: [CUSTOM_ELEMENTS_SCHEMA],
13
+    }).compileComponents();
14
+  }));
15
+
16
+  it('should create the app', () => {
17
+    const fixture = TestBed.createComponent(AppComponent);
18
+    const app = fixture.debugElement.componentInstance;
19
+    expect(app).toBeTruthy();
20
+  });
21
+  // TODO: add more tests!
22
+
23
+});

+ 52 - 0
src/app/app.component.ts

@@ -0,0 +1,52 @@
1
+import { Component } from '@angular/core';
2
+import { Storage } from '@ionic/storage-angular';
3
+import { StatusBar } from '@awesome-cordova-plugins/status-bar/ngx';
4
+import { Uid } from '@ionic-native/uid/ngx';
5
+import { AndroidPermissions } from '@ionic-native/android-permissions/ngx';
6
+
7
+
8
+@Component({
9
+  selector: 'app-root',
10
+  templateUrl: 'app.component.html',
11
+  styleUrls: ['app.component.scss'],
12
+})
13
+export class AppComponent {
14
+    constructor(private storage: Storage, private statusBar:StatusBar, private uid: Uid, private androidPermissions: AndroidPermissions) {
15
+
16
+        this.statusBar.overlaysWebView(true);
17
+
18
+
19
+    }
20
+    openQRCode() {
21
+        console.log("open QR Code");
22
+    }
23
+    async ngOnInit() {
24
+        // If using a custom driver:
25
+        // await this.storage.defineDriver(MyCustomDriver)
26
+        await this.storage.create();
27
+        //await this.getImei();
28
+    }
29
+    async getImei() {
30
+        const { hasPermission } = await this.androidPermissions.checkPermission(
31
+            this.androidPermissions.PERMISSION.READ_PHONE_STATE
32
+        );
33
+        console.log(hasPermission);
34
+
35
+        if (!hasPermission) {
36
+            const result = await this.androidPermissions.requestPermission(
37
+                this.androidPermissions.PERMISSION.READ_PHONE_STATE
38
+            );
39
+
40
+            if (!result.hasPermission) {
41
+                throw new Error('Permissions required');
42
+            }
43
+
44
+            // ok, a user gave us permission, we can get him identifiers after restart app
45
+            return;
46
+        }
47
+        console.log("UUID");
48
+        console.log(this.uid.UUID);
49
+        await this.storage.set('uid', this.uid.UUID);
50
+        return this.uid.IMEI
51
+    }
52
+}

+ 77 - 0
src/app/app.module.ts

@@ -0,0 +1,77 @@
1
+import { NgModule } from '@angular/core';
2
+import { BrowserModule } from '@angular/platform-browser';
3
+import { RouteReuseStrategy } from '@angular/router';
4
+
5
+import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
6
+
7
+import { AppRoutingModule } from './app-routing.module';
8
+import { AppComponent } from './app.component';
9
+
10
+import { HttpClientModule, HttpClient} from '@angular/common/http';
11
+
12
+// import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
13
+// import { library } from '@fortawesome/fontawesome-svg-core';
14
+import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome';
15
+import { fas } from '@fortawesome/free-solid-svg-icons';
16
+import { far } from '@fortawesome/free-regular-svg-icons';
17
+import { fab } from '@fortawesome/free-brands-svg-icons';
18
+
19
+import { Geolocation } from '@ionic-native/geolocation/ngx';
20
+import { NativeGeocoder } from '@ionic-native/native-geocoder/ngx';
21
+
22
+import { CallNumber } from '@ionic-native/call-number/ngx';
23
+import { EmailComposer } from '@ionic-native/email-composer/ngx';
24
+import { HTTP } from '@ionic-native/http/ngx';
25
+import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
26
+
27
+import { IonicStorageModule } from '@ionic/storage-angular';
28
+import { SignInWithApple } from '@ionic-native/sign-in-with-apple/ngx';
29
+
30
+import { PipeModule } from './pipe/pipe.module';
31
+import { Facebook } from '@ionic-native/facebook/ngx';
32
+
33
+import { BarcodeScanner } from '@awesome-cordova-plugins/barcode-scanner/ngx';
34
+import { PayPal } from '@ionic-native/paypal/ngx';
35
+import { StatusBar } from '@awesome-cordova-plugins/status-bar/ngx';
36
+import { Uid } from '@ionic-native/uid/ngx';
37
+import { AndroidPermissions } from '@ionic-native/android-permissions/ngx';
38
+import { Device } from '@ionic-native/device/ngx';
39
+
40
+//import { Stripe } from '@awesome-cordova-plugins/stripe/ngx';
41
+
42
+
43
+// import { IonicImageViewerModule } from 'ionic-img-viewer';
44
+
45
+
46
+// library.add(fas,far,fab);
47
+
48
+@NgModule({
49
+    declarations: [AppComponent],
50
+    entryComponents: [],
51
+    imports: [HttpClientModule, BrowserModule, PipeModule,IonicModule.forRoot({_forceStatusbarPadding: true}), AppRoutingModule, FontAwesomeModule,   IonicStorageModule.forRoot()],
52
+    providers: [
53
+        Geolocation,
54
+        NativeGeocoder,
55
+        CallNumber,
56
+        EmailComposer,
57
+        InAppBrowser,
58
+        HTTP,
59
+        Facebook, 
60
+        StatusBar,
61
+        BarcodeScanner,
62
+        SignInWithApple,
63
+        PayPal,
64
+        AndroidPermissions,
65
+        Uid,
66
+        Device,
67
+        //Stripe,
68
+        { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
69
+    ],
70
+    bootstrap: [AppComponent],
71
+})
72
+export class AppModule {
73
+    constructor(library: FaIconLibrary) {
74
+        library.addIconPacks(fas, fab, far);
75
+    }
76
+
77
+}

+ 17 - 0
src/app/checkout/checkout-routing.module.ts

@@ -0,0 +1,17 @@
1
+import { NgModule } from '@angular/core';
2
+import { Routes, RouterModule } from '@angular/router';
3
+
4
+import { CheckoutPage } from './checkout.page';
5
+
6
+const routes: Routes = [
7
+  {
8
+    path: '',
9
+    component: CheckoutPage
10
+  }
11
+];
12
+
13
+@NgModule({
14
+  imports: [RouterModule.forChild(routes)],
15
+  exports: [RouterModule],
16
+})
17
+export class CheckoutPageRoutingModule {}

+ 20 - 0
src/app/checkout/checkout.module.ts

@@ -0,0 +1,20 @@
1
+import { NgModule } from '@angular/core';
2
+import { CommonModule } from '@angular/common';
3
+import { FormsModule } from '@angular/forms';
4
+
5
+import { IonicModule } from '@ionic/angular';
6
+
7
+import { CheckoutPageRoutingModule } from './checkout-routing.module';
8
+
9
+import { CheckoutPage } from './checkout.page';
10
+
11
+@NgModule({
12
+  imports: [
13
+    CommonModule,
14
+    FormsModule,
15
+    IonicModule,
16
+    CheckoutPageRoutingModule
17
+  ],
18
+  declarations: [CheckoutPage]
19
+})
20
+export class CheckoutPageModule {}

+ 0 - 0
src/app/checkout/checkout.page.html


Some files were not shown because too many files changed in this diff

tum/whitesports - Gogs: Simplico Git Service

暂无描述

handler.php 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. <?php
  2. /**
  3. * Copy & Delete Posts – Post requests handler file.
  4. *
  5. * @package CDP
  6. * @subpackage PostHandler
  7. * @author CopyDeletePosts
  8. * @since 1.0.0
  9. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  10. /** –– **\
  11. * Main handler + It will also sanitize and verify that request a little bit.
  12. * @since 1.0.0
  13. */
  14. add_action('wp_ajax_cdp_action_handling', function () {
  15. if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
  16. if (isset($_POST['token']) && $_POST['token'] == 'cdp' && isset($_POST['f']) && is_admin()) {
  17. // Expand execution time
  18. if (intval(ini_get('max_execution_time')) < 7200)
  19. set_time_limit(0);
  20. // Get WP-Plugin path
  21. $premium_plugin = 'copy-delete-posts-premium/copy-delete-posts-premium.php';
  22. $premium_dir = WP_PLUGIN_DIR . '/' . 'copy-delete-posts-premium';
  23. $pplugin_path = $premium_dir . '/handler/premium.php';
  24. // Load premium content if the plugin is here
  25. if (is_dir($premium_dir) && is_plugin_active($premium_plugin))
  26. require_once($pplugin_path);
  27. // Is premium function
  28. $areWePro = is_plugin_active($premium_plugin);
  29. // Get user roles and check if the role is permmited to use plugin
  30. $access = false;
  31. $current_user = wp_get_current_user();
  32. $access_roles = get_option('_cdp_globals');
  33. if (!isset($access_roles['roles']))
  34. $access_roles = array();
  35. foreach ($current_user->roles as $role => $name)
  36. if ($name == 'administrator' || (isset($access_roles['roles'][$name]) && $access_roles['roles'][$name] == 'true')) {
  37. $access = true;
  38. break;
  39. }
  40. // Check user permission
  41. if ($access === true) {
  42. // Pointers
  43. if ($_POST['f'] == 'no_intro')
  44. cdp_add_new_no_intro();
  45. else if ($_POST['f'] == 'intro_again')
  46. cdp_add_new_intro();
  47. else if ($_POST['f'] == 'save_options')
  48. cdp_save_plugin_options($areWePro);
  49. else if ($_POST['f'] == 'copy_post')
  50. cdp_insert_new_post($areWePro);
  51. else if ($_POST['f'] == 'get_settings')
  52. cdp_get_profile();
  53. else if ($_POST['f'] == 'get_all_settings')
  54. cdp_get_all_profiles();
  55. else if ($_POST['f'] == 'save_profiles' && $areWePro)
  56. cdp_save_profile_set();
  57. else if ($_POST['f'] == 'get_all_posts')
  58. cdp_get_all_posts();
  59. else if ($_POST['f'] == 'delete_them')
  60. cdp_delete_posts();
  61. else if ($_POST['f'] == 'get_formatted_time' && $areWePro)
  62. cdp_formatted_time();
  63. else if ($_POST['f'] == 'set_default_profile')
  64. cdp_set_default_profile();
  65. else if ($_POST['f'] == 'get_default_profile')
  66. cdp_get_default_profile();
  67. else if ($_POST['f'] == 'clear_crons')
  68. cdp_clear_all_crons();
  69. else if ($_POST['f'] == 'i_saw_this_noti')
  70. cdp_set_noti_as_seen();
  71. else if ($_POST['f'] == 'try_to_hide_the_tasks')
  72. cdp_just_hide_task();
  73. else if ($_POST['f'] == 'try_to_kill_the_tasks')
  74. cdp_just_kill_task();
  75. else if ($_POST['f'] == 'give_me_current_tasks')
  76. cdp_just_get_tasks();
  77. else if ($_POST['f'] == 'hide_cron_notice')
  78. cdp_hide_perf_notice();
  79. else if ($_POST['f'] == 'review_dismiss')
  80. cdp_review();
  81. else if ($_POST['f'] == 'debug_function')
  82. cdp_debug_function();
  83. else if ($_POST['f'] == 'delete_success_img')
  84. delete_option('_cdp_show_copy');
  85. else if ($_POST['f'] == 'save_redi_state' && $areWePro)
  86. cdpp_save_redi_state();
  87. else if ($_POST['f'] == 'multi_redi_importer' && $areWePro)
  88. cdpp_redis_importer();
  89. else if ($_POST['f'] == 'save_redirections' && $areWePro)
  90. cdpp_save_redirections();
  91. else if ($_POST['f'] == 'delete_redirect' && $areWePro)
  92. cdpp_delete_redirection();
  93. else if ($_POST['f'] == 'switch_redirects' && $areWePro)
  94. cdpp_switch_redirects();
  95. else if ($_POST['f'] == 'get_authors' && $areWePro)
  96. cdpp_get_authors();
  97. else if ($_POST['f'] == 'get_curr_time' && $areWePro)
  98. cdpp_get_curr_s_time();
  99. else if ($_POST['f'] == 'get_post_export' && $areWePro)
  100. cdpp_get_for_export();
  101. else if ($_POST['f'] == 'import_posts' && $areWePro)
  102. cdpp_take_for_import();
  103. else if ($_POST['f'] == 'save_aci' && $areWePro)
  104. cdpp_save_cleanup_settings();
  105. else if ($_POST['f'] == 'get_aci' && $areWePro)
  106. cdpp_get_cleanup_settings();
  107. else if ($_POST['f'] == 'turn_off_aci' && $areWePro)
  108. cdpp_turn_the_acii_off();
  109. else if ($_POST['f'] == 'i_love_squirrels' && $areWePro)
  110. cdpp_squirrel();
  111. else
  112. echo 'error';
  113. } else
  114. echo 'error';
  115. } else
  116. echo 'no_access';
  117. } else
  118. echo 'no_access';
  119. wp_die();
  120. });
  121. /** –– * */
  122. /** –– **\
  123. * This function will be fired when user don't want to see intro – never again.
  124. * @since 1.0.6
  125. */
  126. function cdp_review() {
  127. // Option
  128. $method = sanitize_text_field($_POST['decision']);
  129. // Get user id and array from db
  130. $user_id = get_current_user_id();
  131. $already = get_option('_cdp_review', false);
  132. // Create if not exists
  133. if ($already == false)
  134. $already = array('installed' => time(), 'users' => array());
  135. // Set dismiss
  136. $already['users'][$user_id] = array();
  137. $already['users'][$user_id]['dismiss'] = (($method == 'remind') ? time() : true);
  138. // Add option to datbase if not exit.
  139. $opt = update_option('_cdp_review', $already);
  140. // Return success
  141. echo json_encode(array('status' => 'success'));
  142. }
  143. /** –– * */
  144. /** –– **\
  145. * This function will be fired when user don't want to see intro – never again.
  146. * @since 1.0.0
  147. */
  148. function cdp_add_new_no_intro() {
  149. // Get user id and array from db
  150. $user_id = get_current_user_id();
  151. $already = get_option('_cdp_no_intro');
  152. // Check if it's first time that user checked this option.
  153. if (!$already)
  154. $already = array($user_id);
  155. // If it already exists just add another user.
  156. else if (!in_array($user_id, $already))
  157. array_push($already, $user_id);
  158. // If the user already exists exit.
  159. else
  160. exit;
  161. // Add option to datbase if not exit.
  162. $opt = update_option('_cdp_no_intro', $already);
  163. }
  164. /** –– * */
  165. /** –– **\
  166. * This function will be fired when user want to see intro – again.
  167. * @since 1.0.0
  168. */
  169. function cdp_add_new_intro() {
  170. // Get user id and array from db
  171. $user_id = get_current_user_id();
  172. $already = get_option('_cdp_no_intro');
  173. // Check if it's first time that user checked this option.
  174. if ($already && in_array($user_id, $already))
  175. unset($already[array_search($user_id, $already, true)]);
  176. // If the user no exists exit.
  177. else
  178. exit;
  179. // Add option to database if not exit.
  180. $opt = update_option('_cdp_no_intro', $already);
  181. }
  182. /** –– * */
  183. /** –– **\
  184. * This function will be fired when user want to save plugin options – again.
  185. * @since 1.0.0
  186. */
  187. function cdp_save_plugin_options($areWePro) {
  188. // Get the info about our professionalness
  189. $areWePro = $areWePro;
  190. // Get new options and current profile.
  191. $options = ((isset($_POST['options'])) ? cdp_sanitize_array($_POST['options']) : false);
  192. $entire = ((isset($_POST['entire'])) ? cdp_sanitize_array($_POST['entire']) : false);
  193. $profile = ((isset($_POST['profile'])) ? sanitize_text_field($_POST['profile']) : false);
  194. // Get current options and profiles.
  195. $a_or = get_option('_cdp_profiles');
  196. $already = get_option('_cdp_profiles');
  197. $g_or = get_option('_cdp_globals');
  198. $globals = get_option('_cdp_globals');
  199. // Check if it's first time – create array.
  200. if (!is_array($already))
  201. $already = array();
  202. if (!is_array($globals))
  203. $globals = array();
  204. // Add display name for this profile
  205. $profile = preg_replace('/\s+/', '_', trim(strtolower($profile)));
  206. // Write new settings for this profile.
  207. $already[$profile] = $options;
  208. $already[$profile]['usmplugin'] = 'false';
  209. $already[$profile]['yoast'] = 'false';
  210. $already[$profile]['woo'] = 'false';
  211. if ($areWePro)
  212. $already[$profile] = cdpp_filter_premium_opts($already, $options, $profile);
  213. if (!isset($already[$profile]['names']['display']) || (strlen(trim($already[$profile]['names']['display'])) <= 0))
  214. $already[$profile]['names']['display'] = $profile;
  215. $globals = $entire;
  216. // Check if there is default profile
  217. if (!array_key_exists('default', $already) || !array_key_exists('title', $already['default'])) {
  218. $already['default'] = array();
  219. if (function_exists('cdp_default_options'))
  220. $already['default'] = cdp_default_options();
  221. if (function_exists('cdp_default_global_options'))
  222. $globals['others'] = cdp_default_global_options();
  223. }
  224. // Add new options to database.
  225. $s1 = update_option('_cdp_globals', $globals);
  226. $s2 = update_option('_cdp_profiles', $already);
  227. // Check if success while uploading
  228. if (($s1 || $s2) || ($globals == $g_or) || ($already == $a_or))
  229. echo 'success';
  230. else
  231. echo 'error';
  232. }
  233. /** –– * */
  234. /** –– **\
  235. * This function will be fired when user want to save plugin options – again.
  236. * @since 1.0.0
  237. */
  238. function cdp_insert_new_post($areWePro = false) {
  239. // Performance copy time start
  240. $timein = microtime(true);
  241. // Create output array which will be returned to requester
  242. $output = array('status' => 'success');
  243. // Get ID(s) of post(s)
  244. $ids = ((isset($_POST['id'])) ? cdp_sanitize_array($_POST['id']) : false);
  245. // Get all important pieces of information from requester
  246. $data = ((isset($_POST['data'])) ? cdp_sanitize_array($_POST['data']) : false);
  247. $site = isset($_POST['data']['site']) ? sanitize_text_field($_POST['data']['site']) : false;
  248. $times = isset($_POST['data']['times']) ? sanitize_text_field($_POST['data']['times']) : 1;
  249. $swap = isset($_POST['data']['swap']) ? sanitize_text_field($_POST['data']['swap']) : false;
  250. $profile = isset($_POST['data']['profile']) ? sanitize_text_field($_POST['data']['profile']) : 'default';
  251. $origin = isset($_POST['origin']) ? sanitize_text_field($_POST['origin']) : false;
  252. $custom = isset($_POST['data']['custom']) ? cdp_sanitize_array($_POST['data']['custom']) : false;
  253. // Load default options for selected profile
  254. $defaults = get_option('_cdp_profiles')[$profile];
  255. // Settings for this copy
  256. $settings = (($data['type'] != 'copy-quick' && $custom != false) ? $custom : $defaults);
  257. if (!isset($settings['names']))
  258. $settings['names'] = $defaults['names'];
  259. // Convert string to boolean – only for much less code later
  260. foreach ($settings as $setting => $val)
  261. if ($setting != 'names')
  262. $settings[$setting] = (($val == 'true') ? true : false);
  263. /**
  264. * This local function filters post data by user settings
  265. * @param $post (array of wordpress post/page data)
  266. * @param $settings (array of preselected settings of profile or by user)
  267. * @return array with insert ready values for wordpress post || false on wrong $post
  268. */
  269. function cdp_filter_post($post, $swap, $opt, $settings, $taxonomies = false, $areWePro) {
  270. // If $post has wrong format return false
  271. if (!(is_array($post) || is_object($post)))
  272. return false;
  273. // Array for formatted and prepared taxonomy
  274. $ft = array();
  275. $buin = array('link_category', 'nav_menu', 'post_tag', 'category', 'post_format');
  276. // Loop thorugh all taxonomies from post
  277. foreach ($taxonomies as $taxonomy) {
  278. // Set the name to shorted variable
  279. $tn = $taxonomy->taxonomy;
  280. // Check if it's private taxonomy and if it's set in options
  281. if ($tn == 'link_category' && !$settings['link_category'])
  282. continue;
  283. if ($tn == 'nav_menu' && !$settings['nav_menu'])
  284. continue;
  285. if ($tn == 'post_tag' && !$settings['post_tag'])
  286. continue;
  287. if ($tn == 'category' && !$settings['category'])
  288. continue;
  289. if ($tn == 'post_format' && !$settings['format'])
  290. continue;
  291. // Don't copy custom taxonomy if it's not checked
  292. if (!in_array($tn, $buin) && !$settings['taxonomy'])
  293. continue;
  294. // Push next term of existing taxonomy
  295. if (isset($ft[$tn]))
  296. array_push($ft[$tn], $taxonomy->term_id);
  297. // Create new taxonomy and push new term
  298. else {
  299. $ft[$tn] = array();
  300. array_push($ft[$tn], $taxonomy->term_id);
  301. }
  302. }
  303. // Create array with required values and contant values
  304. $new = array(
  305. 'post_title' => ($settings['title'] ? cdp_create_title($post['post_title'], $settings['names'], $post['ID'], $areWePro) : __('Untitled Copy', 'copy-delete-posts')),
  306. 'post_date' => ($settings['date'] ? $post['post_date'] : current_time('mysql')),
  307. 'post_status' => ($settings['status'] ? $post['post_status'] : 'draft'),
  308. 'post_author' => ($settings['author'] ? $post['post_author'] : wp_get_current_user()->ID),
  309. 'post_content' => ($settings['content']) ? $post['post_content'] : ' ',
  310. 'comment_status' => $post['comment_status'], // that's additional element which cannot be edited by user
  311. 'post_parent' => $post['post_parent'] // that's additional element which cannot be edited by user
  312. );
  313. // Converter
  314. if ((($opt == '2' && $swap == 'true') || $swap == 'true') && $areWePro && function_exists('cdpp_post_converter'))
  315. $new['post_type'] = cdpp_post_converter($post['post_type']);
  316. else
  317. $new['post_type'] = $post['post_type'];
  318. // Add optional values of post – depending on settings
  319. if ($settings['slug'])
  320. $new['post_name'] = $post['post_name'];
  321. if ($settings['excerpt'])
  322. $new['post_excerpt'] = $post['post_excerpt'];
  323. if ($settings['template'])
  324. $new['page_template'] = $post['page_template'];
  325. if ($settings['password'])
  326. $new['post_password'] = $post['post_password'];
  327. if ($settings['menu_order'])
  328. $new['menu_order'] = $post['menu_order'];
  329. if ($settings['category'])
  330. $new['post_category'] = $post['post_category'];
  331. if ($settings['post_tag'])
  332. $new['tags_input'] = $post['tags_input'];
  333. if ($taxonomies != false)
  334. $new['tax_input'] = $ft;
  335. // Return filtered data of current post
  336. return $new;
  337. }
  338. /**
  339. * This local function filters post data by user settings
  340. * @param $metas (array of wordpress post/page meta data)
  341. * @param $settings (array of preselected settings of profile or by user)
  342. * @return array with metadata values for post || false on wrong $metas
  343. */
  344. function cdp_filter_meta($metas, $settings, $id, $areWePro, $site, $title) {
  345. // If $metas has wrong format return false
  346. if (!(is_array($metas) || is_object($metas)))
  347. return false;
  348. // Create empty array for filtered meta data
  349. $prepared = array(
  350. // Add or replace ours copy tracker
  351. array('_cdp_origin' => $id),
  352. array('_cdp_origin_site' => $site),
  353. array('_cdp_origin_title' => $title),
  354. array('_cdp_counter' => '0')
  355. );
  356. // Iterate through every meta index
  357. foreach ($metas as $meta => $vals) {
  358. // Conditions
  359. $a = ($areWePro && function_exists('cdpp_check_yoast')) ? cdpp_check_yoast($settings, $meta) : false;
  360. $b = ($areWePro && function_exists('cdpp_check_usm')) ? cdpp_check_usm($settings, $meta) : false;
  361. $c = ($areWePro && function_exists('cdpp_check_woo')) ? cdpp_check_woo($settings, $meta, $id) : false;
  362. $d = ($settings['f_image'] && $meta == '_thumbnail_id') ? true : false;
  363. $e = (mb_substr($meta, 0, 4) == '_wp_') ? true : false;
  364. $f = ($meta == '_thumbnail_id' && $settings['f_image']) ? true : false;
  365. $g = ($meta == '_cdp_origin') ? true : false;
  366. $h = (mb_substr($meta, 0, 11) == '_elementor_') ? true : false;
  367. // $i = (isset($settings['all_metadata']) && $settings['all_metadata'] == 'true') ? true : false;
  368. // If any of above condition is true pass the meta tag
  369. if ($a || $b || $c || $d || $e || $f || $g || $h /*|| $i*/) {
  370. // Prepare data and insert filtered to results
  371. foreach ($vals as $val)
  372. array_push($prepared, array($meta => $val));
  373. } else {
  374. // error_log(print_r($vals, true));
  375. }
  376. }
  377. // Return results
  378. return $prepared;
  379. }
  380. /**
  381. * This local function format title by user settings
  382. * @param $title (string)
  383. * @param $settings (array of name settings preselected in profile)
  384. * @return string formated title
  385. */
  386. function cdp_create_title($title, $settings, $id, $areWePro) {
  387. // Date formats
  388. $date_format = intval($settings['format']);
  389. // Get right format
  390. if ($date_format == 1)
  391. $date_format = 'm/d/Y';
  392. else if ($date_format == 2)
  393. $date_format = 'd/m/Y';
  394. else {
  395. if ($areWePro && function_exists('cdpp_custom_date'))
  396. $date_format = cdpp_custom_date($settings);
  397. else
  398. $date_format = 'd/m/Y';
  399. }
  400. // Create date and time replacements
  401. $curr = current_time('timestamp', true);
  402. $date = date($date_format, $curr);
  403. $time = date('H:i:s', $curr);
  404. // Concat whole title with prefix and suffix
  405. $new_title = $settings['prefix'] . ' ' . $title . ' ' . $settings['suffix'];
  406. // Make replace of placeholders
  407. $new_title = str_replace('[CurrentDate]', $date, $new_title);
  408. $new_title = str_replace('[CurrentTime]', $time, $new_title);
  409. // Return formatted title
  410. return $new_title;
  411. }
  412. /**
  413. * This local function inserts whole post into database
  414. * @param $data (array prepared by cdp_filter_post function)
  415. * @param $times (int how many times should this function copy post)
  416. * @return array of new inserted post(s) and error status
  417. * Structure of return array: { ids: [$ids], error: (count of errors) }
  418. */
  419. function cdp_insert_post($id, $data, $times, $areWePro, $isChild = false, $p_ids = null, $site) {
  420. // Get Wordpress database
  421. global $wpdb;
  422. // Create empty array for new id(s) and error(s)
  423. $results = array('ids' => array(), 'error' => 0, 'counter' => 0);
  424. // Prevent SQL injection
  425. if (!is_numeric($id)) {
  426. echo json_encode(array('status' => 'error', 'message' => __('Invalid ID argument.', 'copy-delete-posts')));
  427. exit;
  428. }
  429. // And just in case
  430. $id = esc_sql(intval($id));
  431. // Get Counter value
  432. $prefix = (($site != -1) ? $wpdb->get_blog_prefix($site) : $wpdb->get_blog_prefix());
  433. $newestId = $wpdb->get_results("SELECT post_id FROM {$prefix}postmeta WHERE meta_key = '_cdp_origin' AND meta_value = {$id} ORDER BY post_id DESC LIMIT 1", ARRAY_A);
  434. $newestId = ((array_key_exists(0, $newestId)) ? (intval($newestId[0]['post_id'])) : false);
  435. if (isset($newestId) && $newestId != false && $newestId > 0)
  436. $counter = $wpdb->get_results("SELECT meta_value AS 'Counter' FROM {$prefix}postmeta WHERE meta_key = '_cdp_counter' AND post_id = {$newestId} ORDER BY post_id DESC", ARRAY_A)[0]['Counter'];
  437. else
  438. $counter = 1;
  439. $base_title = $data['post_title'];
  440. $counter = intval($counter) + 1;
  441. // Handle multisite for premium
  442. if ($areWePro && function_exists('cdpp_handle_multisite'))
  443. cdpp_handle_multisite($site);
  444. // Loop for each post iteration
  445. for ($i = 0; $i < $times; ++$i) {
  446. // Change parent if it's child
  447. if ($isChild)
  448. $data['post_parent'] = $p_ids['posts'][$i];
  449. // Replace title with Counter if multiple copies
  450. $data['post_title'] = str_replace('[Counter]', ($counter + $i), $base_title);
  451. // Insert post with filtered data
  452. $new = wp_insert_post($data, true);
  453. // Check if the post is inserted successfully and append array
  454. if (is_numeric($new))
  455. array_push($results['ids'], $new);
  456. else
  457. $results['error'] ++;
  458. }
  459. // Handle multisite for premium fix
  460. if ($areWePro && function_exists('cdpp_handle_multisite_after'))
  461. cdpp_handle_multisite_after($site);
  462. // Set first counter number for future
  463. $results['counter'] = $counter;
  464. // Return array with results
  465. return $results;
  466. }
  467. /**
  468. * This local function filter and adds missing meta to added post
  469. * @param $ids (array of post ids)
  470. * @param $metas (filtered meta data with cdp_filter_meta function)
  471. * @return array structure below
  472. * { ids: { [id] => [failed times]}, error: { [id] => [failed times]} }
  473. */
  474. function cdp_insert_post_meta($ids, $metas, $areWePro, $counter, $site) {
  475. // Handle multisite for premium
  476. if ($areWePro && function_exists('cdpp_handle_multisite'))
  477. cdpp_handle_multisite($site);
  478. // Create empty array for new id(s) and error(s)
  479. $results = array('ids' => array(), 'error' => array());
  480. // Iterate through every inserted post
  481. foreach ($ids as $id) {
  482. // Iterate through every meta tag
  483. foreach ($metas as $meta_id => $meta) {
  484. // Get individual data from metas array
  485. foreach ($meta as $key => $val) {
  486. // Replace the counter with dynamic value
  487. if ($key == '_cdp_counter')
  488. $val = $counter;
  489. // Insert meta tag
  490. $res = add_post_meta($id, $key, $val);
  491. // Check if the insert was successfull
  492. if ($res != false) {
  493. if (!isset($results['ids'][$id]))
  494. $results['ids'][$id] = [];
  495. array_push($results['ids'][$id], array($key, $val));
  496. } else {
  497. if (!isset($results['error'][$id]))
  498. $results['error'][$id] = [];
  499. array_push($results['error'][$id], array($key, $val));
  500. }
  501. }
  502. }
  503. // Iterate the counter
  504. $counter++;
  505. }
  506. // Fix multisite handler
  507. if ($areWePro && function_exists('cdpp_handle_multisite_after'))
  508. cdpp_handle_multisite_after($site);
  509. // Return the results
  510. return $results;
  511. }
  512. /**
  513. * This local function search for childs and catch their IDs
  514. * @param $id string/int (post id)
  515. * @return array of child(s) ID(s)
  516. */
  517. function cdp_check_childs($id) {
  518. $childs = [];
  519. $childrens = get_children(array('post_parent' => $id));
  520. foreach ($childrens as $i => $child)
  521. array_push($childs, $child->ID);
  522. return $childs;
  523. }
  524. /**
  525. * This local function copies original attachments
  526. * @param $path string (path to original file)
  527. * @return string path to new file
  528. */
  529. function cdp_copy_attachment($path = '', $destination) {
  530. if ($path == '')
  531. return false;
  532. $dirname = $destination;
  533. $name = basename($path);
  534. $actual_name = pathinfo($name, PATHINFO_FILENAME);
  535. $original_name = $actual_name;
  536. $extension = pathinfo($name, PATHINFO_EXTENSION);
  537. $i = 1;
  538. while (file_exists($dirname . '/' . $actual_name . "." . $extension)) {
  539. $actual_name = (string) $original_name . '-' . $i;
  540. $name = $actual_name . '.' . $extension;
  541. $i++;
  542. }
  543. copy($path, $dirname . '/' . $name);
  544. return $dirname . '/' . $name;
  545. }
  546. /**
  547. * This local function gets copy and insert attachments
  548. * @param $id int/string of post
  549. * @return array of inserted attachments
  550. */
  551. function cdp_insert_attachments($id, $inserted_posts, $areWePro, $site) {
  552. $inserts = array();
  553. $media = get_attached_media('', $id);
  554. // Handle multisite for premium
  555. if ($areWePro && function_exists('cdpp_handle_multisite'))
  556. cdpp_handle_multisite($site);
  557. // Fix wordpress multisite path
  558. add_filter('upload_dir', 'cdp_fix_upload_paths');
  559. $wp_upload_dir = wp_upload_dir();
  560. remove_filter('upload_dir', 'cdp_fix_upload_paths');
  561. // Handle multisite for premium fix
  562. if ($areWePro && function_exists('cdpp_handle_multisite_after'))
  563. cdpp_handle_multisite_after($site);
  564. foreach ($media as $i => $m) {
  565. if (get_attached_file($m->ID) == '')
  566. continue;
  567. $path = cdp_copy_attachment(get_attached_file($m->ID), $wp_upload_dir['path']);
  568. $filename = $path;
  569. $parent_post_id = $inserted_posts['ids'][0];
  570. $filetype = wp_check_filetype(basename($filename), null);
  571. // Handle multisite for premium
  572. if ($areWePro && function_exists('cdpp_handle_multisite'))
  573. cdpp_handle_multisite($site);
  574. $attachment = array(
  575. 'guid' => $wp_upload_dir['url'] . '/' . basename($filename),
  576. 'post_mime_type' => $filetype['type'],
  577. 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
  578. 'post_content' => '',
  579. 'post_status' => 'inherit'
  580. );
  581. $attach_id = wp_insert_attachment($attachment, $filename, $parent_post_id);
  582. array_push($inserts, array('url' => wp_get_attachment_url($attach_id), 'id' => $attach_id));
  583. $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
  584. wp_update_attachment_metadata($attach_id, $attach_data);
  585. // Handle multisite for premium fix
  586. if ($areWePro && function_exists('cdpp_handle_multisite_after'))
  587. cdpp_handle_multisite_after($site);
  588. }
  589. return $inserts;
  590. }
  591. /**
  592. * This local function gets comments and copy them
  593. * @param $id int/string of base post
  594. * @param $dests array of post ids where the comms from $id should be copied
  595. * @return array of inserted comments
  596. */
  597. function cdp_copy_comments($id, $dests) {
  598. $comments = get_comments(array('post_id' => $id));
  599. $curr = current_time('mysql');
  600. $all_inserts = array();
  601. $all_inserts['fix_try'] = array();
  602. $all_inserts['olds'] = '';
  603. foreach ($dests as $dest) {
  604. $p = 0;
  605. $olds = array();
  606. $cm1 = $comments;
  607. foreach ($cm1 as $i => $c) {
  608. $c = $c->to_array();
  609. $old_id = $c['comment_ID'];
  610. $parent = $c['comment_parent'];
  611. $c['comment_date'] = $curr;
  612. $c['comment_date_gmt'] = $curr;
  613. $c['comment_post_ID'] = $dest;
  614. $c['comment_parent'] = 0;
  615. if ($parent != "0")
  616. $p++;
  617. $new_id = @wp_insert_comment($c);
  618. $olds[$old_id] = array('new' => $new_id, 'old_parent_id' => $parent);
  619. array_push($all_inserts, array('old' => $old_id, 'new' => $new_id, 'parent' => $parent));
  620. }
  621. if ($p != 0) {
  622. $cm2 = $comments;
  623. foreach ($cm2 as $j => $m) {
  624. if ($m->comment_parent != "0" && $olds[$m->comment_ID]['old_parent_id'] == $m->comment_parent) {
  625. $post = get_comment($olds[$m->comment_ID]['new']);
  626. $post = $post->to_array();
  627. $post['comment_parent'] = $olds[$m->comment_parent]['new'];
  628. wp_update_comment($post);
  629. }
  630. }
  631. }
  632. }
  633. return $all_inserts;
  634. }
  635. // Main code for this duplication – for each id (post) do whole process
  636. function cdp_process_ids($ids, $swap, $settings, $times, $site, $areWePro, $g, $isChild = false, $p_ids = null) {
  637. // Make it clear
  638. $globals = cdp_default_global_options();
  639. if ($g != false)
  640. $globals = $g;
  641. $g = $globals['others'];
  642. // Return data storage
  643. $output = [];
  644. $new_posts = array('parents' => array(), 'childs' => array(), 'ids' => array());
  645. // Iterate each id
  646. foreach ($ids as $id) {
  647. // Get post data and meta data
  648. $post = get_post($id)->to_array();
  649. $meta = get_post_custom($id);
  650. $taxonomies = wp_get_object_terms($id, get_taxonomies());
  651. // Check if this post type is allowed to copy
  652. $type = $post['post_type'];
  653. if ($g['cdp-content-pages'] == 'false' && $type == 'page')
  654. continue;
  655. if ($g['cdp-content-posts'] == 'false' && $type == 'post')
  656. continue;
  657. if ($g['cdp-content-custom'] == 'false' && ($type != 'page' && $type != 'post'))
  658. continue;
  659. // Post converting?
  660. $pConv = false;
  661. if (array_key_exists('postConverter', $globals))
  662. $pConv = $globals['postConverter'];
  663. // Run process and validate response
  664. $childrens = cdp_check_childs($id); // if sizeof($this) == has childs
  665. $post_data = cdp_filter_post($post, $swap, $pConv, $settings, $taxonomies, $areWePro, $swap); // can be false
  666. $meta_data = cdp_filter_meta($meta, $settings, $id, $areWePro, $site, $post_data['post_title']); // can be false
  667. $inserted_posts = cdp_insert_post($id, $post_data, $times, $areWePro, $isChild, $p_ids, $site); // $res['error'] must be == 0
  668. $inserted_metas = cdp_insert_post_meta($inserted_posts['ids'], $meta_data, $areWePro, $inserted_posts['counter'], $site); // sizeof($res['error']) must be == 0
  669. // Comments copy
  670. if ($settings['comments'])
  671. $inserted_comments = cdp_copy_comments($id, $inserted_posts['ids']);
  672. $cms = get_comments(array('post_id' => $id));
  673. // Post format
  674. if ($settings['format'])
  675. foreach ($inserted_posts['ids'] as $i => $tid)
  676. $isReFormat = set_post_format($tid, get_post_format($id));
  677. // Featured image copy
  678. if ($settings['attachments'])
  679. $inserted_attachments = cdp_insert_attachments($id, $inserted_posts, $areWePro, $site);
  680. else
  681. $inserted_attachments = false;
  682. // Copy childrens recursively if exist
  683. if ($settings['children'] && sizeof($childrens) > 0) {
  684. $child_helpers = array('posts' => $inserted_posts['ids']);
  685. $inserted_childs = cdp_process_ids($childrens, $swap, $settings, $times, $site, $areWePro, $globals, true, $child_helpers);
  686. array_push($new_posts['childs'], array($id => $inserted_childs['$new_posts']['ids']));
  687. }
  688. // Add new inserted IDs
  689. foreach ($inserted_posts['ids'] as $i_id)
  690. array_push($new_posts['parents'], $i_id);
  691. // Merge for easier read
  692. $new_posts['ids'] = array_merge($new_posts['ids'], $new_posts['parents'], $new_posts['childs']);
  693. }
  694. // Return all data to main request
  695. return array('$output' => $output, '$new_posts' => $new_posts);
  696. }
  697. // Run the machine for selected post(s)
  698. $g = get_option('_cdp_globals', false);
  699. $new_insertions = cdp_process_ids($ids, $swap, $settings, $times, $site, $areWePro, $g);
  700. // Handle multisite for premium
  701. if ($areWePro && function_exists('cdpp_handle_multisite'))
  702. cdpp_handle_multisite($site);
  703. $pConv = false;
  704. if (array_key_exists('postConverter', $g) && $areWePro)
  705. $pConv = (($g['postConverter'] === '2' || $g['postConverter'] === 2) ? true : false);
  706. // Output link if it's edited post
  707. $aCop = ((array_key_exists('afterCopy', $g)) ? $g['afterCopy'] : '1');
  708. if (($data['type'] == 'copy-custom-link' || $aCop == '2'))
  709. $output['link'] = get_edit_post_link($new_insertions['$new_posts']['parents'][0], 'x');
  710. if ($pConv == true && !($data['type'] == 'copy-custom-link' || $aCop == '2'))
  711. $output['link'] = 'pConv';
  712. else
  713. update_option('_cdp_show_copy', true);
  714. // Handle multisite for premium fix
  715. if ($areWePro && function_exists('cdpp_handle_multisite_after'))
  716. cdpp_handle_multisite_after($site);
  717. // Check performance by time
  718. $copyTime = microtime(true) - $timein;
  719. $copyTimePerOne = $copyTime / $times;
  720. // Set only if had good performance all the time
  721. $isSlowPerf = true;
  722. if (get_option('cdp_latest_slow_performance', false) == false) {
  723. $isSlowPerf = false;
  724. }
  725. // Check if the copy time of one page was slower than 0.051 of second
  726. if ($copyTimePerOne > 0.051) {
  727. $isSlowPerf = true;
  728. }
  729. // Set the performance status
  730. update_option('cdp_latest_slow_performance', $isSlowPerf);
  731. // Update history with logs
  732. $logs = get_option('cdp_copy_logs_times', array());
  733. if (sizeof($logs) >= 50) {
  734. $logs = array_slice($logs, 0, 48);
  735. }
  736. $logs = array_values($logs);
  737. array_unshift($logs, array('amount' => $times, 'time' => $copyTime, 'perOne' => $copyTimePerOne, 'data' => time(), 'memory' => memory_get_usage(), 'peak' => memory_get_peak_usage(true)));
  738. update_option('cdp_copy_logs_times', $logs);
  739. echo json_encode(cdp_sanitize_array($output));
  740. }
  741. /** –– * */
  742. /** –– **\
  743. * This function will return profile information for presets.
  744. * @return object of settings by requested profile
  745. * @since 1.0.0
  746. */
  747. function cdp_get_profile() {
  748. if (function_exists('cdpp_get_all_profiles'))
  749. cdpp_get_profile();
  750. else {
  751. // Search for the settings of profile
  752. $settings = get_option('_cdp_profiles')['default'];
  753. // Display those settings
  754. echo json_encode(cdp_sanitize_array($settings));
  755. }
  756. }
  757. /** –– * */
  758. /** –– **\
  759. * This function will return all profile information for manager.
  760. * @return object of settings by requested profile
  761. * @since 1.0.0
  762. */
  763. function cdp_get_all_profiles() {
  764. if (function_exists('cdpp_get_all_profiles'))
  765. cdpp_get_all_profiles();
  766. else
  767. cdp_get_profile();
  768. }
  769. /** –– * */
  770. /** –– **\
  771. * This function will return all not trashed posts
  772. * @return object of posts and success or fail message
  773. */
  774. function cdp_get_all_posts() {
  775. $output = array();
  776. $args = array(
  777. 'numberposts' => -1,
  778. 'post_type' => 'post',
  779. 'post_status' => 'publish,private,draft,future,pending,inherit,sticky'
  780. );
  781. $output['posts'] = get_posts($args);
  782. $args['post_type'] = 'page';
  783. $output['pages'] = get_posts($args);
  784. $output['custom'] = array();
  785. $post_types = get_post_types(array('public' => true, '_builtin' => false));
  786. if (sizeof($post_types) > 0)
  787. $output['custom'] = get_posts(array(
  788. 'post_type' => $post_types,
  789. 'numberposts' => -1,
  790. 'post_status' => 'publish,private,draft,future,pending,inherit,sticky'
  791. ));
  792. $output['meta'] = array();
  793. foreach ($output['posts'] as $k => $p)
  794. $output['meta'][$p->ID] = get_post_meta($p->ID);
  795. foreach ($output['pages'] as $k => $p)
  796. $output['meta'][$p->ID] = get_post_meta($p->ID);
  797. foreach ($output['custom'] as $k => $p)
  798. $output['meta'][$p->ID] = get_post_meta($p->ID);
  799. echo json_encode(cdp_sanitize_array($output));
  800. }
  801. /** –– * */
  802. /** –– **\
  803. * This function will delete all posts in array PERMANENTLY!
  804. * @return object of success message or error
  805. */
  806. function cdp_delete_posts() {
  807. $ids = ((isset($_POST['ids'])) ? cdp_sanitize_array($_POST['ids']) : false); // ids to delete
  808. $throttling = sanitize_text_field($_POST['throttling']); // throttling if enabeld
  809. $thc = sanitize_text_field($_POST['thc']); // throttling count if enabeld
  810. $thrs = sanitize_text_field($_POST['thrs']) == 'true' ? true : false; // trash or not?
  811. $redi = sanitize_text_field($_POST['redi']) == 'true' ? true : false; // redirect if enabled
  812. $auit = sanitize_text_field($_POST['auit']) == 'true' ? true : false; // auit if enabled
  813. $auitd = ((isset($_POST['auitd'])) ? cdp_sanitize_array($_POST['auitd']) : false); // auitd if auit enabled
  814. $prepared_ids = array();
  815. $inGroup = 0;
  816. $curr = current_time('timestamp');
  817. $token = uniqid($curr, true);
  818. $cdp_cron = get_option('_cdp_crons');
  819. $site = is_multisite() ? get_current_blog_id() : '-1';
  820. if ($cdp_cron == false)
  821. $cdp_cron = array();
  822. $cdp_cron[$token] = array(
  823. 'start' => $curr,
  824. 'ids' => $ids,
  825. 'done' => false,
  826. 'shown' => false,
  827. 'f' => 'delete',
  828. 'del_size' => sizeof($ids),
  829. 'handler' => 'cdp_cron_delete',
  830. 'auit' => $auit,
  831. 'auitd' => $auitd
  832. );
  833. $cdp_cron[$token]['tasks'] = array();
  834. $cdp_cron[$token]['args'] = array();
  835. if ($throttling == '1' && $thc && intval($thc) >= 1 && intval($thc) <= 10240) {
  836. $inGroup = ceil(intval($thc) / 30);
  837. for ($i = 0, $k = 2; $i < sizeof($ids); $i = $i + $inGroup, $k++)
  838. $cdp_cron[$token]['tasks']["-$k"] = false;
  839. update_option('_cdp_crons', $cdp_cron);
  840. for ($i = 0, $k = 2; $i < sizeof($ids); $i = $i + $inGroup, $k++) {
  841. $tg = array();
  842. $tt = array('tsk' => "-" . $k, 'token' => $token);
  843. for ($j = $i; $j < ($i + $inGroup); $j++)
  844. if (isset($ids[$j]))
  845. array_push($tg, $ids[$j]);
  846. array_push($prepared_ids, $tg);
  847. $time = $k * 2;
  848. $args = array(array('ids' => $tg, 'site' => $site, 'trash' => $thrs, 'token' => $tt));
  849. wp_schedule_single_event(strtotime("+$time seconds"), 'cdp_cron_delete', $args);
  850. array_push($cdp_cron[$token]['args'], $args);
  851. }
  852. } else {
  853. $cdp_cron[$token]['tasks']["-0"] = false;
  854. update_option('_cdp_crons', $cdp_cron);
  855. $tt = array('tsk' => "-0", 'token' => $token);
  856. $args = array(array('ids' => $ids, 'site' => $site, 'trash' => $thrs, 'token' => $tt));
  857. wp_schedule_single_event(strtotime('+2 seconds'), 'cdp_cron_delete', $args);
  858. array_push($cdp_cron[$token]['args'], $args);
  859. }
  860. echo json_encode(array('status' => 'success', 'token' => cdp_sanitize_array($token)));
  861. }
  862. /** –– * */
  863. /** –– **\
  864. * This function will delete all posts in array PERMANENTLY!
  865. * @return object of success message or error
  866. */
  867. function cdp_clear_all_crons() {
  868. $cdp_cron = get_option('_cdp_crons');
  869. foreach ($cdp_cron as $cron => $val) {
  870. if (array_key_exists('done', $val)) {
  871. if ($val['done'] != true) {
  872. echo json_encode(array(
  873. 'status' => 'fail',
  874. 'type' => 'warning',
  875. 'msg' => __('You can\'t clear messages when tasks are in progress, please firstly kill tasks or wait till the end.', 'copy-delete-posts')
  876. ));
  877. return;
  878. }
  879. }
  880. }
  881. $cdp_cron = delete_option('_cdp_crons');
  882. echo json_encode(array('status' => 'success'));
  883. }
  884. /** –– * */
  885. /** –– **\
  886. * Local function which sets default profile for user
  887. * @return Boolean
  888. */
  889. function cdp_set_default_profile() {
  890. $curr = get_option('_cdp_preselections');
  891. $id = get_current_user_id();
  892. $new = array();
  893. $selection = ((isset($_POST['selection'])) ? cdp_sanitize_array($_POST['selection']) : false);
  894. if ($curr && !is_object($curr) || $curr == false)
  895. $new = array($id => $selection);
  896. else {
  897. $new = $curr;
  898. $new[$id] = $selection;
  899. }
  900. $stat = update_option('_cdp_preselections', $new);
  901. echo cdp_sanitize_array($stat);
  902. }
  903. /** –– * */
  904. /** –– **\
  905. * Local function which gets default profile for user
  906. * @return String
  907. */
  908. function cdp_get_default_profile() {
  909. echo(esc_html(get_option('_cdp_preselections')[get_current_user_id()]));
  910. }
  911. /** –– * */
  912. /** –– **\
  913. * This function will set as seen notification!
  914. * @return object of success message — WARNING: ALWAYS
  915. */
  916. function cdp_set_noti_as_seen() {
  917. if (wp_doing_cron())
  918. return;
  919. $token = ((isset($_POST['noti_token'])) ? sanitize_text_field($_POST['noti_token']) : false);
  920. $cdp_cron = get_option('_cdp_crons', array());
  921. $cdp_cron[$token]['shown'] = true;
  922. update_option('_cdp_crons', $cdp_cron);
  923. echo json_encode(array('status' => 'success'));
  924. }
  925. /** –– * */
  926. /** –– **\
  927. * This function will delete task from the history!
  928. * @return object of success message or fail
  929. */
  930. function cdp_just_hide_task() {
  931. $token = ((isset($_POST['task'])) ? sanitize_text_field($_POST['task']) : false);
  932. $cdp_cron = get_option('_cdp_crons', array());
  933. unset($cdp_cron[$token]);
  934. $res = update_option('_cdp_crons', $cdp_cron);
  935. if ($res)
  936. echo json_encode(array('status' => 'success'));
  937. else
  938. echo json_encode(array('status' => 'fail', 'type' => 'error', 'msg' => __('We can\'t hide this task now, – maybe it\'t already hidden. Please try again later.', 'copy-delete-posts')));
  939. }
  940. /** –– * */
  941. /** –– **\
  942. * This function will kill task from the cron!
  943. * @return object of success message or fail
  944. */
  945. function cdp_just_kill_task() {
  946. $token = ((isset($_POST['task'])) ? sanitize_text_field($_POST['task']) : false);
  947. $cdp_cron = get_option('_cdp_crons', array());
  948. $handler = $cdp_cron[$token]['handler'];
  949. $args = (array_key_exists('args', $cdp_cron[$token]) ? $cdp_cron[$token]['args'] : array());
  950. if ($cdp_cron[$token]['done'] != false) {
  951. echo json_encode(array('status' => 'fail', 'type' => 'error', 'msg' => __('This task has already ended this work, please wait for list refresh and try again.', 'copy-delete-posts')));
  952. return;
  953. }
  954. $status = true;
  955. $res = false;
  956. foreach ($args as $arg => $val) {
  957. $sres = wp_clear_scheduled_hook($handler, $val);
  958. if ($sres == false)
  959. $status = false;
  960. }
  961. if ($cdp_cron[$token]['done'] != false)
  962. $status = true;
  963. if ($status == true) {
  964. unset($cdp_cron[$token]);
  965. $res = update_option('_cdp_crons', $cdp_cron);
  966. }
  967. if ($status || $res)
  968. echo json_encode(array('status' => 'success'));
  969. else
  970. echo json_encode(array('status' => 'fail', 'type' => 'error', 'msg' => __('We can\'t confirm that we killed this task now, please try again later or check if it\'t killed.', 'copy-delete-posts')));
  971. }
  972. /** –– * */
  973. /** –– **\
  974. * This function will catch current cron tasks!
  975. * @return object of tasks or fail
  976. */
  977. function cdp_just_get_tasks() {
  978. $cdp_cron = get_option('_cdp_crons', false);
  979. if ($cdp_cron)
  980. echo json_encode(array('status' => 'success', 'tasks' => cdp_sanitize_array($cdp_cron)));
  981. else
  982. echo json_encode(array('status' => 'fail', 'type' => 'error', 'msg' => __('We couldn\'t catch current tasks, please try again later.', 'copy-delete-posts')));
  983. }
  984. /** –– * */
  985. /** –– **\
  986. * This function will remove performance notice
  987. * @return void
  988. */
  989. function cdp_hide_perf_notice() {
  990. update_option('cdp_dismiss_perf_notice', true);
  991. update_option('cdp_latest_slow_performance', false);
  992. echo json_encode(array('status' => 'success'));
  993. }
  994. /** –– * */
  995. /** –– **\
  996. * This function is just for debug have fun with it!
  997. * It can be fired by function cdp_totally_know_what_i_am_doing('really');
  998. * It won't work in production mode so dont even try it, if you're not me ~ Mikołaj :P
  999. * @return mixed
  1000. */
  1001. function cdp_debug_function() {
  1002. // require_once('C:/Developer/Web/wordpress/wp-content/plugins/copy-delete-posts-premium/classes/methods.php');
  1003. // $settings = get_option('cdpp_aci_settings', false);
  1004. // $meth = new CDP_Premium($settings);
  1005. // $posts = $meth->load_posts($settings['scan']);
  1006. // $filtred = $meth->filter_posts($posts);
  1007. $cdp_cron = get_option('_cdp_crons', false);
  1008. $things_to_debug = array(
  1009. '$cdp_cron' => $cdp_cron
  1010. );
  1011. var_export($things_to_debug);
  1012. }
  1013. /** –– **/