<commit_before><?php
/*
 * Copyright (C) 2017   Splash Sync       <<EMAIL>>
 * 
 * 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 3 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

namespace Splash\Local\Objects\Core;

use Splash\Core\SplashCore      as Splash;

/**
 * Wordpress Images Access
 */
trait ImagesTrait {
    
    /**
     *      @abstract       Encode an Image Post to Splash Image Array
     *      @return         array
     */
    protected function encodeImage( $Post_Id ) {
        
        $UploadsDir     = wp_upload_dir();  
        $Post      = get_post($Post_Id);

        //====================================================================//
        // Image not Found
        if ( is_wp_error( $Post ) ) {
            return Null;
        } 
        
        $RelativePath = get_post_meta( $Post_Id , "_wp_attached_file", True );
        $Path = $UploadsDir["basedir"] . "/" . dirname( $RelativePath ) . "/";
        $Filename = basename($RelativePath);
        
        //====================================================================//
        // Insert Image in Output List
        return self::Images()->Encode(
                $Post->post_title,          // Image Title
                $Filename,                  // Image Filename
                $Path,                      // Image Path
                $Post->guid                 // Image Public Url
            );        
        
        
    }
    
    /**
     *      @abstract       Check if an Image Post has given Md5
     *      @return         array
     */
    protected function checkImageMd5( $Post , $Md5 ) {
        //====================================================================//
        // Load Post
        if ( !is_object($Post) ) {
            $Post   =   get_post($Post);
        } 
        //====================================================================//<commit_msg>BugFix : If no Image Label, use Filename Signed-off-by:BadPixxel <<EMAIL>><commit_after><?php
/*
 * Copyright (C) 2017   Splash Sync       <<EMAIL>>
 * 
 * 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 3 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

namespace Splash\Local\Objects\Core;

use Splash\Core\SplashCore      as Splash;

/**
 * Wordpress Images Access
 */
trait ImagesTrait {
    
    /**
     *      @abstract       Encode an Image Post to Splash Image Array
     *      @return         array
     */
    protected function encodeImage( $Post_Id ) {
        
        $UploadsDir     = wp_upload_dir();  
        $Post           = get_post($Post_Id);

        //====================================================================//
        // Image not Found
        if ( is_wp_error( $Post ) ) {
            return Null;
        } 
        
        $RelativePath   =   get_post_meta( $Post_Id , "_wp_attached_file", True );
        $Path           =   $UploadsDir["basedir"] . "/" . dirname( $RelativePath ) . "/";
        $Filename       =   basename($RelativePath);
        $ImageName      =   !empty($Post->post_title) ? $Post->post_title : $Filename;
        
        //====================================================================//
        // Insert Image in Output List
        return self::Images()->Encode(
                $ImageName,                 // Image Title
                $Filename,                  // Image Filename
                $Path,                      // Image Path
                $Post->guid                 // Image Public Url
            );        
        
        
    }
    
    /**
     *      @abstract       Check if an Image Post has given Md5
     *      @return         array
     */
    protected function checkImageMd5( $Post , $Md5 ) {
        //====================================================================//
        // Load Post
        if ( !is_object($Post) ) {
            $Post   =   get_post($Post);
        } 
        //====================================================================//
{'fraction_non_alphanumeric': 0.1909702209414025, 'fraction_numerical': 0.00845341018251681, 'mean_word_length': 1.9296567248171075, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1664478', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1254, 'n_words': 434}