Merge branch 'feature/783' of github.com:tainacan/tainacan into feature/783

This commit is contained in:
mateuswetah 2023-10-09 15:14:10 -03:00
commit f6a5a67f94
8 changed files with 50 additions and 26 deletions

View File

@ -7,10 +7,11 @@ namespace Tainacan;
class Media {
private static $instance = null;
private static $file_handle = null;
private static $file_name = null;
private $attachment_html_url_base = 'tainacan_attachment_html';
public static $content_index_meta = 'document_content_index';
public static function get_instance() {
if(!isset(self::$instance)) {
self::$instance = new self();
@ -246,10 +247,8 @@ class Media {
return;
}
$content_index_meta = 'document_content_index';
if ($file == null) {
$meta_id = update_post_meta( $item_id, $content_index_meta, null );
update_post_meta( $item_id, SELF::$content_index_meta, null );
return true;
}
@ -274,9 +273,8 @@ class Media {
$wp_charset = get_bloginfo('charset');
$content_charset = mb_detect_encoding($content);
$content = mb_convert_encoding($content, $wp_charset, $content_charset);
$meta_id = update_post_meta( $item_id, $content_index_meta, $content );
} catch(Exception $e) {
update_post_meta( $item_id, SELF::$content_index_meta, $content );
} catch(\Exception $e) {
error_log('Caught exception: ' . $e->getMessage() . "\n");
return false;
}

View File

@ -191,7 +191,7 @@ class Private_Files {
$upload_dir = wp_get_upload_dir();
$base_upload_url = preg_replace('/^https?:\/\//', '', $upload_dir['baseurl']);
$requested_uri = sanitize_text_field($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
$requested_uri = ($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
if ( strpos($requested_uri, $base_upload_url) === false ) {
// Not uploads
@ -228,7 +228,7 @@ class Private_Files {
if ( !$existing_file && \file_exists( $prefixed_both ) ) {
$existing_file = $prefixed_both;
}
echo "-----------> $file <br> $prefixed_file <br> $prefixed_collection $prefixed_both: $existing_file";
if ($existing_file) {
$item = \Tainacan\Repositories\Items::get_instance()->fetch( (int) $item_id, (int) $collection_id );

View File

@ -177,9 +177,15 @@ class Search_Engine {
}
if ( empty($search_meta_query) ) return '';
$content_index_meta = '';
if ( defined('TAINACAN_INDEX_PDF_CONTENT') && true === TAINACAN_INDEX_PDF_CONTENT ) {
$content_index_meta_meta_key = \TAINACAN\Media::$content_index_meta;
$content_index_meta = "OR (m.meta_key='{$content_index_meta_meta_key}')";
}
$join = \is_user_logged_in()
? ''
: " INNER JOIN $wpdb->posts pmeta ON m.meta_key = pmeta.ID AND pmeta.post_status = 'publish'";
: " INNER JOIN $wpdb->posts pmeta ON (m.meta_key = pmeta.ID AND pmeta.post_status = 'publish') $content_index_meta";
return "EXISTS (
SELECT m.post_id
FROM $wpdb->postmeta m $join

View File

@ -307,7 +307,9 @@ class Item extends Entity {
* @return string "open"|"closed"
*/
public function get_comment_status() {
return apply_filters('tainacan-item-comments_open', $this->get_mapped_property('comment_status'), $this->get_id());
$comment_status = $this->get_mapped_property('comment_status');
$comment_status_filtered = apply_filters('comments_open', $comment_status == 'open', $this->get_id()) == true ? 'open' : 'closed';
return $comment_status_filtered;
}
/**
@ -1183,13 +1185,15 @@ class Item extends Entity {
if ( $metadata_section->is_conditional_section() ) {
$rules = $metadata_section->get_conditional_section_rules();
$item_id = $this->get_id();
if( !empty($rules) ) {
$item_id = $this->get_id();
foreach ( $rules as $meta_id => $meta_values_conditional ) {
foreach ( $rules as $meta_id => $meta_values_conditional ) {
$meta_values = get_post_meta( $item_id, $meta_id );
if (!array_intersect($meta_values, $meta_values_conditional))
return $return;
$meta_values = get_post_meta( $item_id, $meta_id );
if (!array_intersect($meta_values, $meta_values_conditional))
return $return;
}
}
}

View File

@ -26,7 +26,7 @@ class Items extends Repository {
protected function __construct() {
parent::__construct();
add_filter( 'tainacan-item-comments_open', [$this, 'hook_comments_open'], 10, 2);
add_filter( 'comments_open', [$this, 'hook_comments_open'], 10, 2);
add_action( 'tainacan-api-item-updated', array( &$this, 'hook_api_updated_item' ), 10, 2 );
add_filter( 'map_meta_cap', array( $this, 'map_meta_cap' ), 10, 4 );
}
@ -582,19 +582,19 @@ class Items extends Repository {
/**
* Return if comment are open for this item (post_id) and the collection too
*
* @param string $open_comment
* @param bool $comments_open
* @param integer $post_id Item id
* @return string
* @return bool
*/
public function hook_comments_open($open_comment, $post_id) {
public function hook_comments_open($comments_open, $post_id) {
$item = self::get_entity_by_post($post_id);
if($item != false && $item instanceof Entities\Item) {
$collection = $item->get_collection();
if( $collection != null && $collection->get_allow_comments() !== 'open' ) return 'closed';
if( $collection != null && $collection->get_allow_comments() !== 'open' ) return false;
}
return $open_comment;
return $comments_open;
}
/**

View File

@ -1019,7 +1019,15 @@ function tainacan_get_the_mime_type_icon($mime_type, $image_size = 'medium') {
$icon_file = 'placeholder_square';
}
return $images_path . $icon_file . $image_size . '.png';
/**
* Filter the image source for the empty thumbnail placeholder.
*
* @param string src The image source for the empty thumbnail placeholder.
* Default is 'placeholder_square'.
* @param string mime_type The document type of the item.
* @param string image_size The size of the image to be loaded.
*/
return apply_filters('tainacan-get-the-mime-type-icon', $images_path . $icon_file . $image_size . '.png', $mime_type, $image_size);
}
/**

View File

@ -72,7 +72,15 @@ export const ThumbnailHelperFunctions = () => {
imageSrc = 'placeholder_square';
}
return this.getEmptyThumbnailPlaceholderBySize(imageSrc, tainacanSize);
/**
* Filter the image source for the empty thumbnail placeholder.
*
* @param string imageSrc The image source for the empty thumbnail placeholder.
* Default is 'placeholder_square'.
* @param string documentType The document type of the item.
* @param string size The size of the image to be loaded.
*/
return wp.hooks.applyFilters('tainacan_get_the_mime_type_icon', this.getEmptyThumbnailPlaceholderBySize(imageSrc, tainacanSize), documentType, tainacanSize);
},
getEmptyThumbnailPlaceholderBySize(imageSrc, tainacanSize) {
switch(tainacanSize) {

View File

@ -151,8 +151,8 @@
}
}
.search-control .search-control-item .search-area {
min-width: 13.75%;
min-width: 13.75vw;
min-width: calc(min(13.75%, 280px));
min-width: calc(min(13.75vw, 280px));
}
}