Skip to content

Commit

Permalink
Initial work on openlab-exif-tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
boonebgorges committed Nov 14, 2024
1 parent 77eddbe commit a50e085
Show file tree
Hide file tree
Showing 187 changed files with 38,500 additions and 0 deletions.
18 changes: 18 additions & 0 deletions wp-content/plugins/openlab-exif-tools/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "openlab-at-city-tech/openlab-exif-tools",
"type": "project",
"autoload": {
"psr-4": {
"OpenLab\\EXIF\\": "src/"
}
},
"authors": [
{
"name": "Boone B Gorges",
"email": "[email protected]"
}
],
"require": {
"fileeye/pel": "^0.10.0"
}
}
82 changes: 82 additions & 0 deletions wp-content/plugins/openlab-exif-tools/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions wp-content/plugins/openlab-exif-tools/openlab-exif-tools.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Plugin Name: OpenLab EXIF tools
* Plugin URI: https://openlab.citytech.cuny.edu/
* Description:
* Version: 1.0.0-alpha
* Requires at least: 6.0
* Requires PHP: 7.3
* Author: OpenLab at City Tech
* Author URI: https://openlab.citytech.cuny.edu/
* License: GPL-3.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: openlab-modules
* Domain Path: /languages
*
* @package openlab-modules
*/

namespace OpenLab\EXIF;

const ROOT_DIR = __DIR__;
const ROOT_FILE = __FILE__;

require ROOT_DIR . '/vendor/autoload.php';

add_action(
'plugins_loaded',
function () {
App::init();
}
);
43 changes: 43 additions & 0 deletions wp-content/plugins/openlab-exif-tools/src/App.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace OpenLab\EXIF;

class App {
private $cli;

private function __construct() {
add_action( 'bp_core_pre_avatar_handle_crop', [ $this, 'delete_gps_data_prior_to_avatar_crop' ], 10, 2 );
}

public static function get_instance() {
static $instance = null;

if ( null === $instance ) {
$instance = new self();
}

return $instance;
}

public static function init() {
$instance = self::get_instance();

if ( defined( 'WP_CLI' ) && WP_CLI ) {
$instance->cli = CLI::get_instance();
$instance->cli::init();
}
}

public function delete_gps_data_prior_to_avatar_crop( $retval, $r ) {
$image_path = bp_core_avatar_upload_path() . $r['original_file'];

if ( ! file_exists( $image_path ) ) {
return $retval;
}

$image = new Image( $image_path );
$image->delete_gps_data();

return $retval;
}
}
37 changes: 37 additions & 0 deletions wp-content/plugins/openlab-exif-tools/src/CLI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace OpenLab\EXIF;

use WP_CLI;

class CLI {
protected $commands = [
'exif' => 'Exif',
];

private function __construct() {}

public static function get_instance() {
static $instance = null;

if ( null === $instance ) {
$instance = new self();
}

return $instance;
}

public static function init() {
$instance = self::get_instance();

$instance->add_commands();
}

private function add_commands() {
foreach ( $this->commands as $cli_command => $class ) {
$command = __NAMESPACE__ . '\\Command\\' . $class;

WP_CLI::add_command( $cli_command, $command );
}
}
}
57 changes: 57 additions & 0 deletions wp-content/plugins/openlab-exif-tools/src/Command/Exif.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace OpenLab\EXIF\Command;

use OpenLab\EXIF\Image;

use WP_CLI;

class Exif {
/**
* Delete GPS-related EXIF data from one or more images.
*
* ## options
*
* [<path>]
* : Path to the image file.
*
* @subcommand delete-gps-data
*/
public function delete_gps_data( $args, $assoc_args ) {
$path = isset( $args[0] ) ? $args[0] : null;

if ( null !== $path ) {

// If this is a directory, recurse.
if ( is_dir( $path ) ) {
$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator( $path )
);

foreach ( $files as $file ) {
if ( $file->isFile() ) {
$this->delete_gps_data( [ $file->getPathname() ], $assoc_args );
}
}
} else {

if ( false === strpos( $path, '/103/' ) ) {
return;
}

$image = new Image( $path );

if ( $image->has_gps_data() ) {
$deleted = $image->delete_gps_data();
if ( $deleted ) {
WP_CLI::log( "Deleted GPS data from {$path}" );
} else {
WP_CLI::log( "Failed to delete GPS data from {$path}" );
}
} else {
WP_CLI::log( "No GPS data found in {$path}" );
}
}
}
}
}
Loading

0 comments on commit a50e085

Please sign in to comment.