PluginProbe ʕ •ᴥ•ʔ
Custom Twitter Feeds – A Tweets Widget or X Feed Widget / 2.7.0
Custom Twitter Feeds – A Tweets Widget or X Feed Widget v2.7.0
2.8.0 2.7.0 2.6.1 2.6.0 1.0 1.0.1 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.2 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.4 1.4.1 1.5 1.5.1 1.6 1.6.1 1.7 1.8 1.8.1 1.8.2 1.8.3 1.8.4 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1 2.1.1 2.1.2 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.5.4 2.5.5 trunk
custom-twitter-feeds / admin / assets / js / settings.js
custom-twitter-feeds / admin / assets / js Last commit date
about.js 1 month ago admin-notifications.js 1 month ago settings.js 1 month ago smash-usage-session.js 1 month ago support.js 1 month ago
settings.js
1208 lines
1 var ctfSettings;
2
3 // Declaring as global variable for quick prototyping
4 var settings_data = {
5 adminUrl: ctf_settings.admin_url,
6 nonce: ctf_settings.nonce,
7 ajaxHandler: ctf_settings.ajax_handler,
8 model: ctf_settings.model,
9 feeds: ctf_settings.feeds,
10 links: ctf_settings.links,
11 tooltipName: null,
12 sourcesList : ctf_settings.sources,
13 dialogBoxPopupScreen : ctf_settings.dialogBoxPopupScreen,
14 selectSourceScreen : ctf_settings.selectSourceScreen,
15 ctfRebrand : ctf_settings.ctfRebrand,
16 socialWallActivated: ctf_settings.socialWallActivated,
17 socialWallLinks: ctf_settings.socialWallLinks,
18 exportFeed: 'none',
19 locales: ctf_settings.locales,
20 timezones: ctf_settings.timezones,
21 genericText: ctf_settings.genericText,
22 generalTab: ctf_settings.generalTab,
23 feedsTab: ctf_settings.feedsTab,
24 translationTab: ctf_settings.translationTab,
25 advancedTab: ctf_settings.advancedTab,
26 footerUpgradeUrl: ctf_settings.footerUpgradeUrl,
27 upgradeUrl: ctf_settings.upgradeUrl,
28 supportPageUrl: ctf_settings.supportPageUrl,
29 isDevSite: ctf_settings.isDevSite,
30 licenseKey: ctf_settings.licenseKey,
31 pluginItemName: ctf_settings.pluginItemName,
32 licenseType: 'free',
33 licenseStatus: ctf_settings.licenseStatus,
34 licenseErrorMsg: ctf_settings.licenseErrorMsg,
35 extensionsLicense: ctf_settings.extensionsLicense,
36 extensionsLicenseKey: ctf_settings.extensionsLicenseKey,
37 extensionFieldHasError: false,
38 cronNextCheck: ctf_settings.nextCheck,
39 currentView: null,
40 selected: null,
41 current: 0,
42 sections: ["General", "Feeds", "Translation", "Advanced"],
43 indicator_width: 0,
44 indicator_pos: 0,
45 forwards: true,
46 currentTab: null,
47 import_file: null,
48 gdprInfoTooltip: null,
49 loaderSVG: ctf_settings.loaderSVG,
50 checkmarkSVG: ctf_settings.checkmarkSVG,
51 uploadSVG: ctf_settings.uploadSVG,
52 exportSVG: ctf_settings.exportSVG,
53 reloadSVG: ctf_settings.reloadSVG,
54 tooltipHelpSvg: ctf_settings.tooltipHelpSvg,
55 tooltip : {
56 text : '',
57 hover : false
58 },
59
60 cogSVG: ctf_settings.cogSVG,
61 deleteSVG: ctf_settings.deleteSVG,
62 svgIcons : ctf_settings.svgIcons,
63 accountDetails : ctf_settings.accountDetails,
64 newAccountData : ctf_settings.newAccountData,
65
66
67 appCredentials : ctf_settings.appCredentials,
68 connectAccountScreen : ctf_settings.connectAccountScreen,
69 appOAUTH : ctf_settings.appOAUTH,
70 testConnectionStatus: null,
71 recheckLicenseStatus: null,
72 btnStatus: null,
73 uploadStatus: null,
74 clearCacheStatus: null,
75 optimizeCacheStatus: null,
76 persistentCacheStatus: null,
77 twittercardCacheStatus: null,
78
79 dpaResetStatus: null,
80 pressedBtnName: null,
81 loading: false,
82 hasError: ctf_settings.hasError,
83 manualAccountResp : false,
84
85 dialogBox : {
86 active : false,
87 type : null,
88 heading : null,
89 description : null,
90 customButtons : undefined
91 },
92 sourceToDelete : {},
93 viewsActive : {
94 sourcePopup : false,
95 sourcePopupScreen : 'redirect_1',
96 sourcePopupType : 'creation',
97 instanceSourceActive : null,
98 connectAccountPopup : false,
99 connectAccountStep : 'step_1',
100 accountDetailsActive : false,
101 appDetailsActive : false,
102 },
103 //Add New Source
104 newSourceData : ctf_settings.newSourceData ? ctf_settings.newSourceData : null,
105 sourceConnectionURLs : ctf_settings.sourceConnectionURLs,
106 returnedApiSourcesList : [],
107 addNewSource : {
108 typeSelected : 'page',
109 manualSourceID : null,
110 manualSourceToken : null
111 },
112 selectedFeed : 'none',
113 expandedFeedID : null,
114 notificationElement : {
115 type : 'success', // success, error, warning, message
116 text : '',
117 shown : null
118 },
119 selectedSourcesToConnect : [],
120
121 //Loading Bar
122 fullScreenLoader : false,
123 appLoaded : false,
124 previewLoaded : false,
125 loadingBar : true,
126 loadingAjax : false,
127
128 notificationElement : {
129 type : 'success', // success, error, warning, message
130 text : '',
131 shown : null
132 }
133 };
134
135 // The tab component
136 Vue.component("tab", {
137 props: ["section", "index"],
138 template: `
139 <a class='tab' :id='section.toLowerCase().trim()' @click='emitWidth($el);changeComponent(index);activeTab(section)'>{{section}}</a>
140 `,
141 created: () => {
142 let urlParams = new URLSearchParams(window.location.search);
143 let view = urlParams.get('view');
144 if ( view === null ) {
145 view = 'general';
146 }
147 settings_data.currentView = view;
148 settings_data.currentTab = settings_data.sections[0];
149 settings_data.selected = "app-1";
150 },
151 methods: {
152
153
154 emitWidth: function(el) {
155 settings_data.indicator_width = jQuery(el).outerWidth();
156 settings_data.indicator_pos = jQuery(el).position().left;
157 },
158 changeComponent: function(index) {
159 var prev = settings_data.current;
160 if (prev < index) {
161 settings_data.forwards = false;
162 } else if (prev > index) {
163 settings_data.forwards = true;
164 }
165 settings_data.selected = "app-" + (index + 1);
166 settings_data.current = index;
167 },
168 activeTab: function(section) {
169 this.setView(section.toLowerCase().trim());
170 settings_data.currentTab = section;
171 },
172 setView: function(section) {
173 history.replaceState({}, null, settings_data.adminUrl + 'admin.php?page=ctf-settings&view=' + section);
174 }
175 }
176 });
177
178 var ctfSettings = new Vue({
179 el: "#ctf-settings",
180 http: {
181 emulateJSON: true,
182 emulateHTTP: true
183 },
184 data: settings_data,
185 created: function() {
186 this.$nextTick(function() {
187 let tabEl = document.querySelector('.tab');
188 settings_data.indicator_width = tabEl.offsetWidth;
189 });
190 setTimeout(function(){
191 settings_data.appLoaded = true;
192 },350);
193 },
194 mounted: function(){
195 var self = this;
196 // set the current view page on page load
197 let activeEl = document.querySelector('a.tab#' + settings_data.currentView);
198 // we have to uppercase the first letter
199 let currentView = settings_data.currentView.charAt(0).toUpperCase() + settings_data.currentView.slice(1);
200 let viewIndex = settings_data.sections.indexOf(currentView) + 1;
201 settings_data.indicator_width = activeEl.offsetWidth;
202 settings_data.indicator_pos = activeEl.offsetLeft;
203 settings_data.selected = "app-" + viewIndex;
204 settings_data.current = viewIndex;
205 settings_data.currentTab = currentView;
206
207 setTimeout(function(){
208 settings_data.appLoaded = true;
209 },350);
210
211 },
212 computed: {
213 getStyle: function() {
214 return {
215 position: "absolute",
216 bottom: "0px",
217 left: settings_data.indicator_pos + "px",
218 width: settings_data.indicator_width + "px",
219 height: "2px"
220 };
221 },
222 chooseDirection: function() {
223 if (settings_data.forwards == true) {
224 return "slide-fade";
225 } else {
226 return "slide-fade";
227 }
228 }
229 },
230 methods: {
231 activateLicense: function() {
232 if (this.licenseType === 'free') {
233 this.runOneClickUpgrade();
234 } else {
235 this.activateProLicense();
236 }
237 },
238 activateProLicense: function() {
239 this.hasError = false;
240 this.loading = true;
241 this.pressedBtnName = 'ctf';
242
243 let data = new FormData();
244 data.append( 'action', 'ctf_activate_license' );
245 data.append( 'license_key', this.licenseKey );
246 data.append( 'nonce', this.nonce );
247 fetch(this.ajaxHandler, {
248 method: "POST",
249 credentials: 'same-origin',
250 body: data
251 })
252 .then(response => response.json())
253 .then(data => {
254 if ( data.success == false ) {
255 this.licenseStatus = 'inactive';
256 this.hasError = true;
257 this.loading = false;
258 return;
259 }
260 if ( data.success == true ) {
261 let licenseData = data.data.licenseData;
262 this.licenseStatus = data.data.licenseStatus;
263 this.loading = false;
264 this.pressedBtnName = null;
265
266 if (
267 data.data.licenseStatus == 'inactive' ||
268 data.data.licenseStatus == 'invalid' ||
269 data.data.licenseStatus == 'expired'
270 ) {
271 this.hasError = true;
272 if( licenseData.error ) {
273 this.licenseErrorMsg = licenseData.errorMsg
274 }
275 }
276 }
277 return;
278 });
279 },
280 deactivateLicense: function() {
281 this.loading = true;
282 this.pressedBtnName = 'ctf';
283 let data = new FormData();
284 data.append( 'action', 'ctf_deactivate_license' );
285 data.append( 'nonce', this.nonce );
286 fetch(this.ajaxHandler, {
287 method: "POST",
288 credentials: 'same-origin',
289 body: data
290 })
291 .then(response => response.json())
292 .then(data => {
293 if ( data.success == true ) {
294 this.licenseStatus = data.data.licenseStatus ;
295 this.loading = false;
296 this.pressedBtnName = null;
297 }
298 return;
299 });
300 },
301 licenseActiveAction: function(extension) {
302 extension = typeof extension !== 'undefined' ? extension : false;
303 if (this.licenseType === 'free') {
304 this.runOneClickUpgrade();
305 } else {
306 if (typeof extension !== 'undefined') {
307 this.deactivateExtensionLicense(extension);
308 } else {
309 this.deactivateLicense();
310 }
311 }
312
313 },
314
315 runOneClickUpgrade: function() {
316 this.hasError = false;
317 this.loading = true;
318 this.pressedBtnName = 'ctf';
319
320 let data = new FormData();
321 data.append( 'action', 'ctf_maybe_upgrade_redirect' );
322 data.append( 'license_key', this.licenseKey );
323 data.append( 'nonce', this.nonce );
324 fetch(this.ajaxHandler, {
325 method: "POST",
326 credentials: 'same-origin',
327 body: data
328 })
329 .then(response => response.json())
330 .then(data => {
331 if ( data.success === false ) {
332 this.licenseStatus = 'invalid';
333 this.hasError = true;
334 this.loading = false;
335 if( typeof data.data !== 'undefined' ) {
336 this.licenseErrorMsg = data.data.message
337 }
338 return;
339 }
340 if ( data.success === true ) {
341 window.location.href = data.data.url
342 }
343 return;
344 });
345 },
346
347 /**
348 * Activate Extensions License
349 *
350 * @since 2.0
351 *
352 * @param {object} extension
353 */
354 activateExtensionLicense: function( extension ) {
355 let licenseKey = this.extensionsLicenseKey[extension.name];
356 this.extensionFieldHasError = false;
357 this.loading = true;
358 this.pressedBtnName = extension.name;
359 if ( ! licenseKey ) {
360 this.loading = false;
361 this.extensionFieldHasError = true;
362 return;
363 }
364 let data = new FormData();
365 data.append( 'action', 'ctf_activate_extension_license' );
366 data.append( 'license_key', licenseKey );
367 data.append( 'extension_name', extension.name );
368 data.append( 'extension_item_name', extension.itemName );
369 data.append( 'nonce', this.nonce );
370 fetch(this.ajaxHandler, {
371 method: "POST",
372 credentials: 'same-origin',
373 body: data
374 })
375 .then(response => response.json())
376 .then(data => {
377 this.loading = false;
378 if ( data.success == true ) {
379 this.extensionFieldHasError = false;
380 this.pressedBtnName = null;
381 if ( data.data.licenseStatus == 'invalid' ) {
382 this.extensionFieldHasError = true;
383 this.notificationElement = {
384 type : 'error',
385 text : this.genericText.invalidLicenseKey,
386 shown : "shown"
387 };
388 }
389 if ( data.data.licenseStatus == 'valid' ) {
390 this.notificationElement = {
391 type : 'success',
392 text : this.genericText.licenseActivated,
393 shown : "shown"
394 };
395 }
396 extension.licenseStatus = data.data.licenseStatus;
397 extension.licenseKey = licenseKey;
398
399 setTimeout(function(){
400 this.notificationElement.shown = "hidden";
401 }.bind(this), 3000);
402 }
403 return;
404 });
405 },
406
407 /**
408 * Deactivate Extensions License
409 *
410 * @since 2.0
411 *
412 * @param {object} extension
413 */
414 deactivateExtensionLicense: function( extension ) {
415 let licenseKey = this.extensionsLicenseKey[extension.name];
416 this.extensionFieldHasError = false;
417 this.loading = true;
418 this.pressedBtnName = extension.name;
419 let data = new FormData();
420 data.append( 'action', 'ctf_deactivate_extension_license' );
421 data.append( 'extension_name', extension.name );
422 data.append( 'extension_item_name', extension.itemName );
423 data.append( 'nonce', this.nonce );
424 fetch(this.ajaxHandler, {
425 method: "POST",
426 credentials: 'same-origin',
427 body: data
428 })
429 .then(response => response.json())
430 .then(data => {
431 this.loading = false;
432 if ( data.success == true ) {
433 this.extensionFieldHasError = false;
434 this.pressedBtnName = null;
435 if ( data.data.licenseStatus == 'deactivated' ) {
436 this.notificationElement = {
437 type : 'success',
438 text : this.genericText.licenseDeactivated,
439 shown : "shown"
440 };
441 }
442 extension.licenseStatus = data.data.licenseStatus;
443 extension.licenseKey = licenseKey;
444
445 setTimeout(function(){
446 this.notificationElement.shown = "hidden";
447 }.bind(this), 3000);
448 }
449 return;
450 });
451 },
452 testConnection: function() {
453 this.testConnectionStatus = 'loading';
454 let data = new FormData();
455 data.append( 'action', 'ctf_test_connection' );
456 data.append( 'nonce', this.nonce );
457 fetch(this.ajaxHandler, {
458 method: "POST",
459 credentials: 'same-origin',
460 body: data
461 })
462 .then(response => response.json())
463 .then(data => {
464 if ( data.success == false ) {
465 this.testConnectionStatus = 'error';
466 }
467 if ( data.success == true ) {
468 this.testConnectionStatus = 'success';
469
470 setTimeout(function() {
471 this.testConnectionStatus = null;
472 }.bind(this), 3000);
473 }
474 return;
475 });
476 },
477 recheckLicense: function( licenseKey, itemName, optionName = null ) {
478 this.recheckLicenseStatus = 'loading';
479 this.pressedBtnName = optionName;
480 let data = new FormData();
481 data.append( 'action', 'ctf_recheck_connection' );
482 data.append( 'license_key', licenseKey );
483 data.append( 'item_name', itemName );
484 data.append( 'option_name', optionName );
485 data.append( 'nonce', this.nonce );
486 fetch(this.ajaxHandler, {
487 method: "POST",
488 credentials: 'same-origin',
489 body: data
490 })
491 .then(response => response.json())
492 .then(data => {
493 if ( data.success == true ) {
494 if ( data.data.license == 'valid' ) {
495 this.recheckLicenseStatus = 'success';
496 }
497 if ( data.data.license == 'expired' ) {
498 this.recheckLicenseStatus = 'error';
499 }
500
501 // if the api license status has changed from old stored license status
502 // then reload the page to show proper error message and notices
503 // or hide error messages and notices
504 if ( data.data.licenseChanged == true ) {
505 location.reload();
506 }
507
508 setTimeout(function() {
509 this.pressedBtnName = null;
510 this.recheckLicenseStatus = null;
511 }.bind(this), 3000);
512 }
513 return;
514 });
515 },
516 recheckLicenseIcon: function() {
517 if ( this.recheckLicenseStatus == null ) {
518 return this.generalTab.licenseBox.recheckLicense;
519 } else if ( this.recheckLicenseStatus == 'loading' ) {
520 return this.loaderSVG;
521 } else if ( this.recheckLicenseStatus == 'success' ) {
522 return '<i class="fa fa-check-circle"></i> ' + this.generalTab.licenseBox.licenseValid;
523 } else if ( this.recheckLicenseStatus == 'error' ) {
524 return '<i class="fa fa-times-circle"></i> ' + this.generalTab.licenseBox.licenseExpired;
525 }
526 },
527 recheckBtnText: function( btnName ) {
528 if ( this.recheckLicenseStatus == null || this.pressedBtnName != btnName ) {
529 return this.generalTab.licenseBox.recheckLicense;
530 } else if ( this.recheckLicenseStatus == 'loading' && this.pressedBtnName == btnName ) {
531 return this.loaderSVG;
532 } else if ( this.recheckLicenseStatus == 'success' ) {
533 return '<i class="fa fa-check-circle"></i> ' + this.generalTab.licenseBox.licenseValid;
534 } else if ( this.recheckLicenseStatus == 'error' ) {
535 return '<i class="fa fa-times-circle"></i> ' + this.generalTab.licenseBox.licenseExpired;
536 }
537 },
538 testConnectionIcon: function() {
539 if ( this.testConnectionStatus == 'loading' ) {
540 return this.loaderSVG;
541 } else if ( this.testConnectionStatus == 'success' ) {
542 return '<i class="fa fa-check-circle"></i> ' + this.generalTab.licenseBox.connectionSuccessful;
543 } else if ( this.testConnectionStatus == 'error' ) {
544 return `<i class="fa fa-times-circle"></i> ${this.generalTab.licenseBox.connectionFailed} <a href="#">${this.generalTab.licenseBox.viewError}</a>`;
545 }
546 },
547 importFile: function() {
548 document.getElementById("import_file").click();
549 },
550 uploadFile: function( event ) {
551 this.uploadStatus = 'loading';
552 let file = this.$refs.file.files[0];
553 let data = new FormData();
554 data.append( 'action', 'ctf_import_settings_json' );
555 data.append( 'file', file );
556 data.append( 'nonce', this.nonce );
557 fetch(this.ajaxHandler, {
558 method: "POST",
559 credentials: 'same-origin',
560 body: data
561 })
562 .then(response => response.json())
563 .then(data => {
564 this.uploadStatus = null;
565 this.$refs.file.files[0] = null;
566 if ( data.success == false ) {
567 this.notificationElement = {
568 type : 'error',
569 text : this.genericText.failedToImportFeed,
570 shown : "shown"
571 };
572 }
573 if ( data.success == true ) {
574 this.feeds = data.data.feeds;
575 this.notificationElement = {
576 type : 'success',
577 text : this.genericText.feedImported,
578 shown : "shown"
579 };
580 }
581 setTimeout(function(){
582 this.notificationElement.shown = "hidden";
583 }.bind(this), 3000);
584 });
585 },
586 exportFeedSettings: function() {
587 // return if no feed is selected
588 if ( this.exportFeed === 'none' ) {
589 return;
590 }
591
592 let url = this.ajaxHandler + '?action=ctf_export_settings_json&feed_id=' + this.exportFeed;
593 window.location = url;
594 },
595 saveSettings: function() {
596 this.btnStatus = 'loading';
597 this.pressedBtnName = 'saveChanges';
598 let data = new FormData();
599 data.append( 'action', 'ctf_save_settings' );
600 data.append( 'model', JSON.stringify( this.model ) );
601 data.append( 'ctf_license_key', this.licenseKey );
602 data.append( 'extensions_license_key', JSON.stringify( this.extensionsLicenseKey ) );
603 data.append( 'nonce', this.nonce );
604 fetch(this.ajaxHandler, {
605 method: "POST",
606 credentials: 'same-origin',
607 body: data
608 })
609 .then(response => response.json())
610 .then(data => {
611 if ( data.success == false ) {
612 this.btnStatus = 'error';
613 return;
614 }
615
616 this.cronNextCheck = data.data.cronNextCheck;
617 this.btnStatus = 'success';
618 setTimeout(function() {
619 this.btnStatus = null;
620 this.pressedBtnName = null;
621 }.bind(this), 3000);
622 });
623 },
624 clearCache: function() {
625 this.clearCacheStatus = 'loading';
626 let data = new FormData();
627 data.append( 'action', 'ctf_clear_cache_settings' );
628 data.append( 'model', JSON.stringify( this.model ) );
629 data.append( 'nonce', this.nonce );
630 fetch(this.ajaxHandler, {
631 method: "POST",
632 credentials: 'same-origin',
633 body: data
634 })
635 .then(response => response.json())
636 .then(data => {
637 if ( data.success == false ) {
638 this.clearCacheStatus = 'error';
639 return;
640 }
641 this.cronNextCheck = data.data.cronNextCheck;
642 this.clearCacheStatus = 'success';
643 setTimeout(function() {
644 this.clearCacheStatus = null;
645 }.bind(this), 3000);
646 });
647 },
648 showTooltip: function( tooltipName ) {
649 this.tooltipName = tooltipName;
650 },
651 hideTooltip: function() {
652 this.tooltipName = null;
653 },
654 gdprOptions: function() {
655 this.gdprInfoTooltip = null;
656 },
657 gdprLimited: function() {
658 this.gdprInfoTooltip = this.gdprInfoTooltip == null ? true : null;
659 },
660 clearImageResizeCache: function() {
661 this.optimizeCacheStatus = 'loading';
662 let data = new FormData();
663 data.append( 'action', 'ctf_clear_image_resize_cache' );
664 data.append( 'nonce', this.nonce );
665 fetch(this.ajaxHandler, {
666 method: "POST",
667 credentials: 'same-origin',
668 body: data
669 })
670 .then(response => response.json())
671 .then(data => {
672 if ( data.success == false ) {
673 this.optimizeCacheStatus = 'error';
674 return;
675 }
676 this.optimizeCacheStatus = 'success';
677 setTimeout(function() {
678 this.optimizeCacheStatus = null;
679 }.bind(this), 3000);
680 });
681 },
682 clearPersistentCache: function() {
683 this.persistentCacheStatus = 'loading';
684 let data = new FormData();
685 data.append( 'action', 'ctf_clear_persistent_cache' );
686 data.append( 'nonce', this.nonce );
687 fetch(this.ajaxHandler, {
688 method: "POST",
689 credentials: 'same-origin',
690 body: data
691 })
692 .then(response => response.json())
693 .then(data => {
694 if ( data.success == false ) {
695 this.persistentCacheStatus = 'error';
696 return;
697 }
698 this.persistentCacheStatus = 'success';
699 setTimeout(function() {
700 this.persistentCacheStatus = null;
701 }.bind(this), 3000);
702 });
703 },
704 clearTwittercardCache: function() {
705 this.twittercardCacheStatus = 'loading';
706 let data = new FormData();
707 data.append( 'action', 'ctf_clear_twittercard_cache' );
708 data.append( 'nonce', this.nonce );
709 fetch(this.ajaxHandler, {
710 method: "POST",
711 credentials: 'same-origin',
712 body: data
713 })
714 .then(response => response.json())
715 .then(data => {
716 if ( data.success == false ) {
717 this.twittercardCacheStatus = 'error';
718 return;
719 }
720 this.twittercardCacheStatus = 'success';
721 setTimeout(function() {
722 this.twittercardCacheStatus = null;
723 }.bind(this), 3000);
724 });
725 },
726 dpaReset: function() {
727 this.dpaResetStatus = 'loading';
728 let data = new FormData();
729 data.append( 'action', 'ctf_dpa_reset' );
730 data.append( 'nonce', this.nonce );
731 fetch(this.ajaxHandler, {
732 method: "POST",
733 credentials: 'same-origin',
734 body: data
735 })
736 .then(response => response.json())
737 .then(data => {
738 if ( data.success == false ) {
739 this.dpaResetStatus = 'error';
740 return;
741 }
742 this.dpaResetStatus = 'success';
743 setTimeout(function() {
744 this.dpaResetStatus = null;
745 }.bind(this), 3000);
746 });
747 },
748 saveChangesIcon: function() {
749 if ( this.btnStatus == 'loading' ) {
750 return this.loaderSVG;
751 } else if ( this.btnStatus == 'success' ) {
752 return this.checkmarkSVG;
753 } else if ( this.btnStatus == 'error' ) {
754 return `<i class="fa fa-times-circle"></i>`;
755 }
756 },
757 importBtnIcon: function() {
758 if ( this.uploadStatus === null ) {
759 return this.uploadSVG;
760 }
761 if ( this.uploadStatus == 'loading' ) {
762 return this.loaderSVG;
763 } else if ( this.uploadStatus == 'success' ) {
764 return this.checkmarkSVG;
765 } else if ( this.uploadStatus == 'error' ) {
766 return `<i class="fa fa-times-circle"></i>`;
767 }
768 },
769 clearCacheIcon: function() {
770 if ( this.clearCacheStatus === null ) {
771 return this.reloadSVG;
772 }
773 if ( this.clearCacheStatus == 'loading' ) {
774 return this.loaderSVG;
775 } else if ( this.clearCacheStatus == 'success' ) {
776 return this.checkmarkSVG;
777 } else if ( this.clearCacheStatus == 'error' ) {
778 return `<i class="fa fa-times-circle"></i>`;
779 }
780 },
781 clearImageResizeCacheIcon: function() {
782 if ( this.optimizeCacheStatus === null ) {
783 return;
784 }
785 if ( this.optimizeCacheStatus == 'loading' ) {
786 return this.loaderSVG;
787 } else if ( this.optimizeCacheStatus == 'success' ) {
788 return this.checkmarkSVG;
789 } else if ( this.optimizeCacheStatus == 'error' ) {
790 return `<i class="fa fa-times-circle"></i>`;
791 }
792 },
793 clearPersistentCacheIcon: function() {
794 if ( this.persistentCacheStatus === null ) {
795 return;
796 }
797 if ( this.persistentCacheStatus == 'loading' ) {
798 return this.loaderSVG;
799 } else if ( this.persistentCacheStatus == 'success' ) {
800 return this.checkmarkSVG;
801 } else if ( this.persistentCacheStatus == 'error' ) {
802 return `<i class="fa fa-times-circle"></i>`;
803 }
804 },
805 clearTwittercardCacheIcon: function() {
806 if ( this.twittercardCacheStatus === null ) {
807 return;
808 }
809 if ( this.twittercardCacheStatus == 'loading' ) {
810 return this.loaderSVG;
811 } else if ( this.twittercardCacheStatus == 'success' ) {
812 return this.checkmarkSVG;
813 } else if ( this.twittercardCacheStatus == 'error' ) {
814 return `<i class="fa fa-times-circle"></i>`;
815 }
816 },
817
818 dpaResetStatusIcon: function() {
819 if ( this.dpaResetStatus === null ) {
820 return;
821 }
822 if ( this.dpaResetStatus == 'loading' ) {
823 return this.loaderSVG;
824 } else if ( this.dpaResetStatus == 'success' ) {
825 return this.checkmarkSVG;
826 } else if ( this.dpaResetStatus == 'error' ) {
827 return `<i class="fa fa-times-circle"></i>`;
828 }
829 },
830
831 printUsedInText: function( usedInNumber ){
832 if(usedInNumber == 0){
833 return this.genericText.sourceNotUsedYet;
834 }
835 return this.genericText.usedIn + ' ' + usedInNumber + ' ' +(usedInNumber == 1 ? this.genericText.feed : this.genericText.feeds);
836 },
837
838 /**
839 * Delete Source Ajax
840 *
841 * @since 2.0
842 */
843 deleteSource : function(sourceToDelete){
844 var self = this;
845 let data = new FormData();
846 data.append( 'action', 'ctf_feed_saver_manager_delete_source' );
847 data.append( 'source_id', sourceToDelete.id);
848 data.append( 'nonce', this.nonce );
849 fetch(self.ajaxHandler, {
850 method: "POST",
851 credentials: 'same-origin',
852 body: data
853 })
854 .then(response => response.json())
855 .then(data => {
856 if (sourceToDelete.just_added) {
857 window.location.href = window.location.href.replace('ctf_access_token','ctf_null');
858 }
859 self.sourcesList = data;
860 });
861 },
862
863 /**
864 * Check if Value is Empty
865 *
866 * @since 2.0
867 *
868 * @return boolean
869 */
870 checkNotEmpty : function(value){
871 return value != null && value.replace(/ /gi,'') != '';
872 },
873
874 /**
875 * Activate View
876 *
877 * @since 2.0
878 */
879 activateView : function(viewName, sourcePopupType = 'creation', ajaxAction = false){
880 var self = this;
881 self.viewsActive[viewName] = (self.viewsActive[viewName] == false ) ? true : false;
882 if(viewName == 'sourcePopup' && sourcePopupType == 'creationRedirect'){
883 setTimeout(function(){
884 self.$refs.addSourceRef.processIFConnect()
885 },3500);
886 }
887
888 },
889
890 /**
891 * Switch & Change Feed Screens
892 *
893 * @since 2.0
894 */
895 switchScreen: function(screenType, screenName){
896 this.viewsActive[screenType] = screenName;
897 },
898
899 /**
900 * Parse JSON
901 *
902 * @since 2.0
903 *
904 * @return jsonObject / Boolean
905 */
906 jsonParse : function(jsonString){
907 try {
908 return JSON.parse(jsonString);
909 } catch(e) {
910 return false;
911 }
912 },
913
914
915 /**
916 * Ajax Post Action
917 *
918 * @since 2.0
919 */
920 ajaxPost : function(data, callback){
921 var self = this;
922 self.$http.post(self.ajaxHandler,data).then(callback);
923 },
924
925 /**
926 * Check if Object has Nested Property
927 *
928 * @since 2.0
929 *
930 * @return boolean
931 */
932 hasOwnNestedProperty : function(obj,propertyPath) {
933 if (!propertyPath){return false;}var properties = propertyPath.split('.');
934 for (var i = 0; i < properties.length; i++) {
935 var prop = properties[i];
936 if (!obj || !obj.hasOwnProperty(prop)) {
937 return false;
938 } else {
939 obj = obj[prop];
940 }
941 }
942 return true;
943 },
944
945 /**
946 * Show Tooltip on Hover
947 *
948 * @since 2.0
949 */
950 toggleElementTooltip : function(tooltipText, type, align = 'center'){
951 var self = this,
952 target = window.event.currentTarget,
953 tooltip = (target != undefined && target != null) ? document.querySelector('.sb-control-elem-tltp-content') : null;
954 if(tooltip != null && type == 'show'){
955 self.tooltip.text = tooltipText;
956 var position = target.getBoundingClientRect(),
957 left = position.left + 10,
958 top = position.top - 10;
959 tooltip.style.left = left + 'px';
960 tooltip.style.top = top + 'px';
961 tooltip.style.textAlign = align;
962 self.tooltip.hover = true;
963 }
964 if(type == 'hide'){
965 self.tooltip.hover = false;
966 }
967 },
968
969 /**
970 * Hover Tooltip
971 *
972 * @since 2.0
973 */
974 hoverTooltip : function(type){
975 this.tooltip.hover = type;
976 },
977
978 /**
979 * Open Dialog Box
980 *
981 * @since 2.0
982 */
983 openDialogBox : function(type, args = []){
984 var self = this,
985 heading = self.dialogBoxPopupScreen[type].heading,
986 description = self.dialogBoxPopupScreen[type].description,
987 customButtons = self.dialogBoxPopupScreen[type].customButtons;
988
989
990 switch (type) {
991 case "deleteSource":
992 self.sourceToDelete = args;
993 heading = heading.replace("#", self.sourceToDelete.username);
994 break;
995 }
996 self.dialogBox = {
997 active : true,
998 type : type,
999 heading : heading,
1000 description : description,
1001 customButtons : customButtons
1002 };
1003 },
1004
1005
1006 /**
1007 * Confirm Dialog Box Actions
1008 *
1009 * @since 2.0
1010 */
1011 confirmDialogAction : function(){
1012 var self = this;
1013 switch (self.dialogBox.type) {
1014 case 'deleteSource':
1015 self.deleteSource(self.sourceToDelete);
1016 break;
1017 case 'deleteAccount':
1018 self.deleteAccount();
1019 break;
1020 case 'deleteApp':
1021 self.deleteAccount(true);
1022 break;
1023 }
1024 },
1025
1026 /**
1027 * Display Feed Sources Settings
1028 *
1029 * @since 2.0
1030 *
1031 * @param {object} source
1032 * @param {int} sourceIndex
1033 */
1034 displayFeedSettings: function(source, sourceIndex) {
1035 this.expandedFeedID = sourceIndex + 1;
1036 },
1037
1038 /**
1039 * Hide Feed Sources Settings
1040 *
1041 * @since 2.0
1042 *
1043 * @param {object} source
1044 * @param {int} sourceIndex
1045 */
1046 hideFeedSettings: function() {
1047 this.expandedFeedID = null;
1048 },
1049
1050 /**
1051 * Copy text to clipboard
1052 *
1053 * @since 2.0
1054 */
1055 copyToClipBoard : function(value){
1056 var self = this;
1057 const el = document.createElement('textarea');
1058 el.className = 'ctf-fb-cp-clpboard';
1059 el.value = value;
1060 document.body.appendChild(el);
1061 el.select();
1062 document.execCommand('copy');
1063 document.body.removeChild(el);
1064 self.notificationElement = {
1065 type : 'success',
1066 text : this.genericText.copiedClipboard,
1067 shown : "shown"
1068 };
1069 setTimeout(function(){
1070 self.notificationElement.shown = "hidden";
1071 }, 3000);
1072 },
1073
1074
1075 /**
1076 * View Source Instances
1077 *
1078 * @since 2.0
1079 */
1080 viewSourceInstances : function(source){
1081 var self = this;
1082 self.viewsActive.instanceSourceActive = source;
1083 },
1084
1085 /**
1086 * Return Page/Group Avatar
1087 *
1088 * @since 2.0
1089 *
1090 * @return string
1091 */
1092 returnAccountAvatar : function(source){
1093 if (typeof source.local_avatar_url !== "undefined" && source.local_avatar_url !== '') {
1094 return source.local_avatar_url;
1095 }
1096 if (typeof source.avatar_url !== "undefined" && source.avatar_url !== '') {
1097 return source.avatar_url;
1098 }
1099
1100 return false;
1101 },
1102
1103 checkManualEmpty : function(){
1104 var self = this;
1105 return self.checkNotEmpty(self.appCredentials.access_token) && self.checkNotEmpty(self.appCredentials.access_token_secret);
1106 },
1107
1108 closeConnectAccountPopup : function(){
1109 var self = this;
1110 self.appCredentials = {
1111 app_name : '',
1112 consumer_key : '',
1113 consumer_secret : '',
1114 access_token : '',
1115 access_token_secret : ''
1116 };
1117 self.viewsActive.connectAccountPopup = false;
1118 },
1119
1120 checkNewAccount : function(){
1121 var self = this;
1122 if( self.newAccountData !== undefined ){
1123 if( self.newAccountData['error'] !== undefined ){
1124 self.accountDetails = self.newAccountData;
1125 }
1126 }
1127 },
1128 checkAccountDetails : function(){
1129 var self = this;
1130 return self.accountDetails !== undefined &&
1131 self?.accountDetails?.access_token !== undefined &&
1132 self?.accountDetails?.access_token_secret !== undefined &&
1133 self.checkNotEmpty(self?.accountDetails?.access_token) &&
1134 self.checkNotEmpty(self?.accountDetails?.access_token_secret);
1135
1136 },
1137
1138 checkAppData : function(){
1139 var self = this;
1140 return self?.accountDetails?.app_name !== undefined &&
1141 self?.accountDetails?.consumer_key !== undefined &&
1142 self?.accountDetails?.consumer_secret !== undefined &&
1143 self.checkNotEmpty(self?.accountDetails?.app_name) &&
1144 self.checkNotEmpty(self?.accountDetails?.consumer_key) &&
1145 self.checkNotEmpty(self?.accountDetails?.consumer_secret);
1146 },
1147
1148 deleteAccount : function(deleteApp = false){
1149 var self = this;
1150 self.loadingAjax = true;
1151 var deleteData = {
1152 action : 'ctf_feed_saver_manager_delete_account',
1153 'nonce' : self.nonce,
1154 deleteApp : deleteApp
1155 };
1156 self.ajaxPost(deleteData, function(_ref){
1157 var data = _ref.data;
1158 self.accountDetails = data;
1159 self.loadingAjax = false;
1160 });
1161 },
1162
1163 connectAccountLink : function(){
1164 window.location = this.appOAUTH;
1165 },
1166
1167 /**
1168 * Connect Twitter Account Manually
1169 *
1170 * @since 2.0
1171 */
1172 connectManualAccount : function(){
1173 var self = this;
1174 if( self.checkManualEmpty() ){
1175 self.loadingAjax = true;
1176 var connectManualAccountData = {
1177 action : 'ctf_feed_saver_manager_connect_manual_account',
1178 'nonce' : self.nonce,
1179 app_name : self.appCredentials.app_name,
1180 consumer_key : self.appCredentials.consumer_key,
1181 consumer_secret : self.appCredentials.consumer_secret,
1182 access_token : self.appCredentials.access_token,
1183 access_token_secret : self.appCredentials.access_token_secret
1184 };
1185 self.ajaxPost(connectManualAccountData, function(_ref){
1186 var data = _ref.data;
1187 if(data['error'] === undefined){
1188 self.accountDetails = data;
1189 self.manualAccountResp = 'success';
1190 setTimeout(function(){
1191 self.viewsActive['connectAccountPopup'] = false;
1192 self.manualAccountResp = false;
1193 }, 1000)
1194 }else{
1195 self.manualAccountResp = 'error';
1196 setTimeout(function(){
1197 self.manualAccountResp = false;
1198 }, 3000)
1199 }
1200 self.loadingAjax = false;
1201 });
1202 }
1203 },
1204
1205 }
1206 });
1207
1208