-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathastrometry.php
105 lines (85 loc) · 3.58 KB
/
astrometry.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/*
Plugin Name: Astrometry
Description: Bietet einen Gutenberg-Block an, der Bilder anhand der astrometry.net API astrometrisiert
Plugin URI: https://www.explorespace.de/
Text Domain: astrometry
Domain Path: languages
Version: 0.8.0
Author: Matthias Guttmann
Author URI: https://www.explorespace.de/
*/
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
defined('ABSPATH') or die( 'No script kiddies please!' );
define('ASTROMETRY_PLUGIN_BASE', plugin_dir_path(__FILE__));
//Includes
require_once(ASTROMETRY_PLUGIN_BASE . "astrometrySearch.php");
require_once(ASTROMETRY_PLUGIN_BASE . "settings.php");
require_once(ASTROMETRY_PLUGIN_BASE . "block/editor_block.php");
//Einstellungen und Ergänzungen
$astrometry_settings_options = get_option( 'astrometry_settings' );
add_filter('jpeg_quality', function($arg) {
global $astrometry_settings_options;
return $astrometry_settings_options['image_quality'];
});
//Init
function init_astrometry() {
global $wp_query;
global $post;
if(!isset($post))
return;
//CSS
addAstrometryCss();
//Scripts
wp_enqueue_script('astrometry-javascript', plugins_url('/assets/js/astrometry.js', __FILE__), array('jquery'), '', false);
wp_localize_script('astrometry-javascript', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'postId' => $post->ID) );
//Localisation
load_plugin_textdomain( 'astrometry', false, dirname(plugin_basename(__FILE__)) . '/languages' );
}
add_filter('wp', 'init_astrometry');
//CSS
function addAstrometryCss() {
wp_register_style('astrometry-css', plugins_url('/assets/css/astrometry.css', __FILE__) );
wp_enqueue_style('astrometry-css');
}
function addAstrometryEditorCss() {
wp_enqueue_style('astrometry-editor-css', plugins_url('/assets/css/astrometry.editor.css', __FILE__), false );
addAstrometryCss();
}
add_action('enqueue_block_editor_assets', 'addAstrometryEditorCss');
//Callback for Ajax Solving
function astronomyImageStartSolve() {
require_once(ASTROMETRY_PLUGIN_BASE . "annotation/astrometryData.class.php");
$astrometryData = new AstrometryData($_POST['postId'], $_POST['mediaId']);
echo $astrometryData->Solve(get_option('astrometry_settings')['api_key']);
wp_die();
}
add_action('wp_ajax_astronomyImageStartSolve', 'astronomyImageStartSolve');
//Callback for reloading info
function astronomyRefreshAstrometryInfo() {
require_once(ASTROMETRY_PLUGIN_BASE . "annotation/astrometryData.class.php");
$astrometryData = new AstrometryData($_POST['postId'], $_POST['mediaId']);
$astrometryData->GetInfo($astrometryData->Get("submission")["jobs"][0]);
echo join($astrometryData->GetTagLinks(),", ");
wp_die();
}
add_action('wp_ajax_astronomyRefreshAstrometryInfo', 'astronomyRefreshAstrometryInfo');
//Settings
if ( is_admin() ) {
$astrometry_settings = new AstrometrySettings();
//Localisation
load_plugin_textdomain( 'astrometry', false, dirname(plugin_basename(__FILE__)) . '/languages' );
}
?>