Skip to content

Commit

Permalink
Merge pull request #34 from Kredeum/nameSpaces
Browse files Browse the repository at this point in the history
Name spaces
  • Loading branch information
zapaz authored May 14, 2021
2 parents d5e18b6 + d76836c commit 967ec38
Show file tree
Hide file tree
Showing 25 changed files with 117 additions and 100 deletions.
1 change: 1 addition & 0 deletions docker/kredeum/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
WORDPRESS_DB_NAME: wp
WORDPRESS_DB_USER: wp
WORDPRESS_DB_PASSWORD: ${DB_WORDPRESS_PASSWORD}
WORDPRESS_DEBUG: 1
ports:
- 8000:80

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @package kredeum/nfts
*/

namespace \Admin\Ipfs;
/**
* IPFS add file function
*
Expand All @@ -13,7 +14,7 @@
*
* @return string CID hash
*/
function ipfs_add( $attachment_id, $version = IPFS_CID_VERSION ) {
function add( $attachment_id, $version = IPFS_CID_VERSION ) {
$api = new RestClient( array( 'base_url' => IPFS_API ) );

$boundary = md5( time() );
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"sub-codegen": "cd thegraph && graph codegen",
"sub-build": "cd thegraph && graph build",
"sub-deploy": "cd thegraph && graph deploy zapaz/matic-open-nft --ipfs https://api.subgraph.com/ipfs/ --node https://api.subgraph.com/deploy/",
"sub-deploy-mumbai": "cd thegraph && graph deploy zapaz/mumbai-open-nft --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/"
"sub-deploy-mumbai": "cd thegraph && graph deploy zapaz/mumbai-open-nft --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
"start": "sirv app"
},
"devDependencies": {
"@metamask/detect-provider": "^1.2.0",
Expand Down
2 changes: 2 additions & 0 deletions wordpress/kredeum-nfts/admin/ajax/ajax-token.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* @package kredeum/nfts
*/

namespace KredeumNFTs\Ajax;

/**
* Add action enqueue
*/
Expand Down
2 changes: 2 additions & 0 deletions wordpress/kredeum-nfts/admin/ajax/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @package kredeum/nfts
*/

namespace KredeumNFTs\Ajax;

/**
* Add actions
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package kredeum/nfts
*/

namespace KredeumNFTs\Ipfs;

/**
* Multipart
*
Expand Down
8 changes: 5 additions & 3 deletions wordpress/kredeum-nfts/admin/ipfs/nft-storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package kredeum/nfts
*/

namespace KredeumNFTs\Ipfs;

/**
* IPFS add and pin file with NFT Storage
*
Expand All @@ -13,12 +15,12 @@
*
* @return string CID hash
*/
function ipfs_add_and_pin_nft_storage( $attachment_id, $version = IPFS_CID_VERSION ) {
$api = new RestClient( array( 'base_url' => 'https://api.nft.storage' ) );
function nft_storage_add_and_pin( $attachment_id, $version = IPFS_CID_VERSION ) {
$api = new \RestClient( array( 'base_url' => 'https://api.nft.storage' ) );

$boundary = md5( time() );
$file = file_get_contents( get_attached_file( $attachment_id ) );
$filename = ipfs_get_attached_file_meta( $attachment_id )->filename;
$filename = get_attached_file_meta( $attachment_id )->filename;
$parts = array(
array(
'type' => 'file',
Expand Down
8 changes: 5 additions & 3 deletions wordpress/kredeum-nfts/admin/ipfs/pinata.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package kredeum/nfts
*/

namespace KredeumNFTs\Ipfs;

/**
* IPFS add and pin file with PINATA
*
Expand All @@ -13,12 +15,12 @@
*
* @return string CID hash
*/
function ipfs_add_and_pin_pinata( $attachment_id, $version = IPFS_CID_VERSION ) {
$api = new RestClient( array( 'base_url' => 'https://api.pinata.cloud' ) );
function pinata_add_and_pin( $attachment_id, $version = IPFS_CID_VERSION ) {
$api = new \RestClient( array( 'base_url' => 'https://api.pinata.cloud' ) );

$boundary = md5( time() );
$file = file_get_contents( get_attached_file( $attachment_id ) );
$filename = ipfs_get_attached_file_meta( $attachment_id )->filename;
$filename = get_attached_file_meta( $attachment_id )->filename;
$parts = array(
array(
'type' => 'file',
Expand Down
18 changes: 10 additions & 8 deletions wordpress/kredeum-nfts/admin/ipfs/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
* @package kredeum/nfts
*/

namespace KredeumNFTs\Ipfs;

/**
* IPFS upsert file
*
* @param string $post_id Id post.
*
* @return string CID hash
*/
function ipfs_upsert( $post_id ) {
$file = ipfs_get_attached_file_meta( $post_id );
function upsert( $post_id ) {
$file = get_attached_file_meta( $post_id );
if ( '' === $file->cid ) {
$cid = ipfs_insert( $post_id, $file->filename );
$cid = insert( $post_id, $file->filename );
}
return $cid;
}
Expand All @@ -27,15 +29,15 @@ function ipfs_upsert( $post_id ) {
*
* @return string CID hash
*/
function ipfs_insert( $post_id ) {
function insert( $post_id ) {
if ( defined( 'IPFS_NFT_STORAGE_KEY' ) ) {
$cid = ipfs_add_and_pin_nft_storage( $post_id );
$cid = nft_storageadd_and_pin( $post_id );
} elseif ( defined( 'IPFS_PINATA_SECRET' ) ) {
$cid = ipfs_add_and_pin_pinata( $post_id );
$cid = pinata_add_and_pin( $post_id );
}
// else {
// $cid = ipfs_add( $post_id );
// ipfs_pin( $cid );
// $cid = add( $post_id );
// pin( $cid );
// } .
update_post_meta( $post_id, 'cid', $cid );
return $cid;
Expand Down
15 changes: 0 additions & 15 deletions wordpress/kredeum-nfts/admin/media/delete.php

This file was deleted.

11 changes: 7 additions & 4 deletions wordpress/kredeum-nfts/admin/media/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package kredeum/nfts
*/

namespace KredeumNFTs\Ipfs;

/**
* IPFS meta_boxes action
* affiche box avec CID
Expand All @@ -18,7 +20,8 @@ function () {
function ( $post ) {
$cid = $post->cid;
if ( $cid ) {
echo esc_html( __( 'Archive link', 'kredeum-nfts' ) ) . ' : ' . wp_kses( ipfs_link( $cid ), array( 'a' => array( 'href' => array() ) ) );
echo esc_html( __( 'Archive link', 'kredeum-nfts' ) ) . ' : ' .
wp_kses( link( $cid ), array( 'a' => array( 'href' => array() ) ) );
}
}
);
Expand All @@ -31,7 +34,7 @@ function ( $post ) {
add_filter(
'attachment_fields_to_edit',
function ( $form_fields, $post ) {
$file = ipfs_get_attached_file_meta( $post->ID );
$file = get_attached_file_meta( $post->ID );

if ( ! $file->cid ) {
$form_fields['cid'] = array(
Expand All @@ -49,14 +52,14 @@ function ( $form_fields, $post ) {
);

/**
* IPFS edit attechement action
* IPFS edit attachement action
*/
add_action(
'edit_attachment',
function ( $attachment_id ) {
if ( isset( $_REQUEST['attachments'][ $attachment_id ]['ipfs'] )
&& sanitize_text_field( wp_unslash( $_REQUEST['attachments'][ $attachment_id ]['ipfs'] ) ) ) {
ipfs_insert( $attachment_id );
insert( $attachment_id );
}
}
);
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
/**
* IPFS new
* IPFS auto upload
*
* @package kredeum/nfts
*/

namespace KredeumNFTs\Ipfs;

/**
* IPFS new action
* archive IPFS on media upload
Expand All @@ -13,7 +15,7 @@
add_action(
'add_attachment',
function ( $post_id ) {
return ipfs_upsert( $post_id );
return upsert( $post_id );
}
);
}
6 changes: 4 additions & 2 deletions wordpress/kredeum-nfts/admin/media_list/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package kredeum/nfts
*/

namespace KredeumNFTs\Ipfs;

/**
* IPFS bulk archive action
*/
Expand All @@ -27,8 +29,8 @@ function ( $redirect_url, $action, $post_ids ) {
$nu = 0; // number of unchanged files.
if ( 'archive' === $action ) {
foreach ( $post_ids as $post_id ) {
$file = ipfs_get_attached_file_meta( $post_id );
$cid = ipfs_insert( $post_id );
$file = get_attached_file_meta( $post_id );
$cid = insert( $post_id );
if ( $file->cid ) {
if ( $file->cid === $cid ) {
$nu++;
Expand Down
11 changes: 7 additions & 4 deletions wordpress/kredeum-nfts/admin/media_list/column.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package kredeum/nfts
*/

namespace KredeumNFTs\Ipfs;

/**
* IPFS 2 columns filter
*/
Expand All @@ -26,15 +28,16 @@ function ( $name ) {
global $post;
if ( $post->cid ) {
if ( 'cid' === $name ) {
echo wp_kses( ipfs_link( $post->cid, substr( $post->cid, 0, 12 ) . '...' ), array( 'a' => array( 'href' => array() ) ) );
echo wp_kses( link( $post->cid, substr( $post->cid, 0, 12 ) . '...' ), array( 'a' => array( 'href' => array() ) ) );
} elseif ( 'nft' === $name ) {
if ( get_post_meta( $post->ID, 'tokenId' )[0] ) {
printf( '<a href="/wp-admin/admin.php?page=nfts" krd-nft=' . esc_attr( get_post_meta( $post->ID, 'tokenId' )[0] ) . '>NFT created</a>' );
$token_id = get_post_meta( $post->ID, 'tokenId' );
if ( isset( $token_id[0] ) ) {
printf( '<a href="/wp-admin/admin.php?page=nfts" krd-nft=' . esc_attr( $token_id[0] ) . '>NFT created</a>' );
} else {
printf(
'<kredeum-nft-mint minted'
. ' pid="' . esc_attr( $post->ID ) . '"'
. ' src="' . esc_url( ipfs_url( $post->cid ) ) . '"'
. ' src="' . esc_url( url( $post->cid ) ) . '"'
. ' alt="' . esc_attr( $post->post_title ) . '"/>'
);
}
Expand Down
53 changes: 24 additions & 29 deletions wordpress/kredeum-nfts/admin/nfts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,28 @@
* @package kredeum/nfts
*/

add_action( 'admin_menu', 'nfts_menu' );
namespace KredeumNFTs\Menu;

/**
* NFTs menu action
*/
function nfts_menu() {
add_menu_page(
__( 'NFTs Kredeum', 'kredeum-nfts' ),
__( 'NFTs', 'kredeum-nfts' ),
'edit_posts',
'nfts',
'nfts_options',
'dashicons-format-gallery',
11
);
add_submenu_page(
'nfts',
__( 'NFTs Kredeum', 'kredeum-nfts' ),
__( 'NFTs Kredeum', 'kredeum-nfts' ),
'edit_posts',
'nfts'
);
}

/**
* NFTs menu options
*/
function nfts_options() {
echo '<kredeum-nft/>';
}
add_action(
'admin_menu',
function () {
add_menu_page(
__( 'NFTs Kredeum', 'kredeum-nfts' ),
__( 'NFTs', 'kredeum-nfts' ),
'edit_posts',
'nfts',
function () {
echo '<kredeum-nft/>';
},
'dashicons-format-gallery',
11
);
add_submenu_page(
'nfts',
__( 'NFTs Kredeum', 'kredeum-nfts' ),
__( 'NFTs Kredeum', 'kredeum-nfts' ),
'edit_posts',
'nfts'
);
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
* @package kredeum/nfts
*/

namespace KredeumNFTs\Settings;

/**
* Class Kredeum_Nfts_Settings
*
* @variable string $slug Settings slug
*/
class Kredeum_Nfts_Settings {
class Settings {

/**
* Slug
Expand Down Expand Up @@ -104,7 +106,7 @@ public function section_callback( $arguments ) {
* Fields Create
*/
public function fields_create() {
$fields = kredeum_nfts_fields( $this->slug );
$fields = fields( $this->slug );

foreach ( $fields as $field ) {
add_settings_field( $field['uid'], $field['label'], array( $this, 'field_callback' ), $this->slug, $field['section'], $field );
Expand Down Expand Up @@ -192,4 +194,4 @@ public function field_callback( $arguments ) {
}
}
}
new Kredeum_Nfts_Settings();
new Settings();
Loading

0 comments on commit 967ec38

Please sign in to comment.