-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
photopress.php
161 lines (124 loc) · 3.79 KB
/
photopress.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/*
Plugin Name: PhotoPress
Plugin URI: http://www.photopressdev.com
Description: Making WordPress work for photographers with beautiful image galleries, slideshows, meta-data tools, and more.
Author: Peter Adams
Author URI: http://www.photopressdev.com
License: GPL v3
Version: 1.5.0
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
// require the composer autoloader
require_once('vendor/autoload.php');
// Define the path to this plugin
if ( ! defined( 'PHOTOPRESS_CORE_PATH' ) ) {
define('PHOTOPRESS_CORE_PATH', plugin_dir_path( __FILE__ ) );
}
// Define the path to the PhotoPress Framework. This is used by other plugins
if ( ! defined( 'PHOTOPRESS_FRAMEWORK_PATH' ) ) {
define('PHOTOPRESS_FRAMEWORK_PATH', PHOTOPRESS_CORE_PATH . 'framework/' );
}
// Hook for plugin package creation
add_action('plugins_loaded', [ 'photopress_plugin', 'getInstance' ], 1 );
register_activation_hook(__FILE__, [ 'photopress_plugin', 'activate' ] );
/**
* PhotoPress Core Plugin
*
* Adds core framework classes to PhotoPress.
*
* @link http://photopressdev.com
* @since 1.0.0
* @package photopress_core
*
*/
class photopress_plugin {
/**
* Static instance
*/
static $instance;
/**
* Get instance of the plugin's package.
*
* Since everything within the package is registered via hooks,
* kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
*/
public static function getInstance() {
if ( defined('PHOTOPRESS_FRAMEWORK_PATH') ) {
if ( ! self::$instance ) {
self::$instance = pp_api::factory(
'photopress_core_package',
PHOTOPRESS_CORE_PATH . 'includes/class-photopress-core-package.php',
array(
'package_name' => 'core',
'package_label' => 'PhotoPress',
'version' => '1.5.0',
'modules' => ['base', 'childpages', 'gallery', 'slideshow', 'metadata'],
'dependencies' => []
)
);
self::$instance->activate();
}
}
}
/**
* move this to the gallery plugin
*/
public function random_gallery_taxonomy_query( $attachments, $attr ) {
// discard any attachments we might get.
$attachments = array();
if ( ! $attr ) {
$attr = array();
}
extract( $attr );
// if there are taxonomy oriented attrs then do an image taxonomy query
if ( ! empty( $taxonomy ) && ! empty( $term ) && $post_type === 'attachment' && $query === 'random') {
$term = strtolower( $term );
$taxonomy = strtolower( $taxonomy );
$paged = (get_query_var('page')) ? (int) get_query_var('page') : 1;
// setup taxonomy query
$args = array(
'tax_query' => array(),
//'showposts' => $num_posts,
'posts_per_page' => $numberposts,
'post_type' => 'attachment',
'paged' => $paged,
'post_status' => 'inherit',
'offset' => '',
'orderby' => 'rand'
);
$args['tax_query'][] = array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $term
);
// perform taxonomy query
$attachment_query = new WP_Query( $args );
$r_attachments = $attachment_query->get_posts();
if ( $r_attachments ) {
foreach ($r_attachments as $a) {
$attachments[$a->ID] = $a;
}
}
}
// always return something so downstream plugins can operate.
return $attachments;
}
public static function activate() {
$exiftool_path = PHOTOPRESS_CORE_PATH . 'vendor/philharvey/exiftool/exiftool ';
if ( function_exists( 'chmod' ) ) {
photopress_util::debug( $exiftool_path );
$ret = chmod( trim($exiftool_path), 0755 );
photopress_util::debug( $ret );
} else {
photopress_util::debug('cannot set executable permission on exiftool. please manually change to 755.');
}
}
}
?>