Upload:

Command:

logicielcomptabilite@18.191.235.182: ~ $
<?php 
/*
Plugin Name: MediaLab API
Description: API endpoint.
Version: 1.0.3
Author: MediaLab Factory
Author URI: 
Plugin URI: 
*/


require 'plugin-update-checker/plugin-update-checker.php';
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;

$myUpdateChecker = PucFactory::buildUpdateChecker(
    'http://factory.creation-site.info/plugins/medialab-api/medialab-api.json',
    __FILE__,
    'medialab-api'
);


function get_number_post($data){
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $count_posts = wp_count_posts($post_type = $data['post_type']);
        return wp_send_json_success($count_posts,200);
    }else{
        return wp_send_json_error('Access denied', 403);
    }
}


function get_postby_slug($data){ 
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $args = array(
          'name'        => $data['slug'],
          'post_type'   => 'post',
          'post_status' => array('future','publish'),
          'numberposts' => 1
        );
        $my_posts = get_posts($args);
        if( $my_posts ) :
            if(isset($my_posts[0])){
            $my_posts[0]->post_thumb = get_the_post_thumbnail_url($my_posts[0]->ID); 
            $my_posts[0]->post_content = wpautop($my_posts[0]->post_content);
            return wp_send_json_success($my_posts[0],200);
            }else{
              return wp_send_json_error('Post not found !', 404);  
            }
        endif;
    } else {
        return wp_send_json_error('Access denied', 403);
    }  
}

function get_postby_id($data){ 
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $my_post = get_post($data['id']);
        if( $my_post ){
                return wp_send_json_success($my_post,200);
            }else{
                return wp_send_json_error('Post not found !', 404);  
            }
    } else {
        return wp_send_json_error('Access denied', 403);
    }        
}


function get_posts_api($data){
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $args = array(
            'numberposts' => $data['number'],
            'post_type'   => $data['post-type']
        );
        $latest_books = get_posts($args);
        return wp_send_json_success($latest_books);
    } else {
        return wp_send_json_error('Access denied', 403);
    }    
}

function add_post_by_app($data)
{
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $userdata = array('user_login' => 'netlinking_user', 'role' => 'editor', 'user_pass' => uniqid());
        if (username_exists('netlinking_user')) {
            $find_user = get_user_by('login', 'netlinking_user');
            $contributor_id = $find_user->ID;
        } else {
            $user_id = wp_insert_user($userdata);
            if (!is_wp_error($user_id)) {
                $contributor_id = $user_id;
            } else {
                $contributor_id = null;
            }
        }

        $my_post = array(
            'post_title' => wp_strip_all_tags($data['title']),
            'post_type'=> $data['post_type'],
            'post_name' => $data['slug'],
            'post_content' => $data['content'],
            'post_date' => $data['date'],
            'post_status' => $data['status'],
            'post_author' => $contributor_id,
            'post_category' => array($data['category_id']),
            '_thumbnail_id' => $data['thumbnail_id'],
            'meta_input' => array("_aioseo_title" => $data['meta_title'], "_aioseo_description" => $data['meta_description'],'post_link' => $data['annuaire_link'])
        );

        $save_post = wp_insert_post($my_post);
        

        if (!is_wp_error($save_post)) {
            $post = get_post($save_post);
            return wp_send_json_success(array('post_url' => "/" . $post->post_name, 'post_id' => $save_post), 200);
        } else {
            return wp_send_json_error($save_post->get_error_message());
        }
    } else {
        return wp_send_json_error('Access denied', 403);
    }
}


function update_post_by_app($data)
{
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
    
        $my_post = array(
            'ID' => $data['id'],
            'post_title' => wp_strip_all_tags($data['title']),
            'post_name' => $data['slug'],
            'post_content' => $data['content'],
            'post_date' => $data['date'],
            'post_status' => $data['status'],
            'post_category' => array($data['category_id']),
            '_thumbnail_id' => $data['thumbnail_id'],
            'meta_input' => array("_aioseo_title" => $data['meta_title'], "_aioseo_description" => $data['meta_description'],'post_link' => $data['annuaire_link'])
        );
        $save_post = wp_update_post($my_post);


        if (!is_wp_error($save_post)) {
            $post = get_post($save_post);
            return wp_send_json_success(array('post_url' => "/" . $post->post_name, 'post_id' => $save_post), 200);
        } else {
            return wp_send_json_error($save_post->get_error_message());
        }
    } else {
        return wp_send_json_error('Access denied', 403);
    }
}

function set_taxonomy($data){
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $set_post = wp_set_post_terms($data['id'], $data['category_id'], 'categories');
        if (!empty($set_post)) {
           return wp_send_json_success('Success !',200); 
        }else {
            return wp_send_json_error('Error !');
        }
    } else {
        return wp_send_json_error('Access denied', 403);
    }    
        
}


function delete_post($data){
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $delete_post = wp_delete_post($data['id']);
        if(is_null($delete_post)){
            wp_send_json_error('ERROR');
        }else{
            wp_send_json_success('success');
        }
    } else {
        return wp_send_json_error('Access denied', 403);
    }
}


function get_the_categories(){
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
       if(!is_wp_error(get_categories())){
            return wp_send_json_success(get_categories(array('hide_empty' => false)),200);
        }else{
            return null;
        } 
    }else{
       return wp_send_json_error('Access denied', 403);
    }  
}


function get_all_taxonomies(){
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
       if(!is_wp_error(get_categories())){
            $terms = get_terms( array(
            'taxonomy' => 'categories',
            'hide_empty' => false,
            ));
            return wp_send_json_success($terms,200);
        }else{
            return null;
        } 
    }else{
       return wp_send_json_error('Access denied', 403);
    }  
}


function create_update_category($data){
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        require_once( ABSPATH . '/wp-admin/includes/taxonomy.php');
        $wpdocs_cat = array(
            'cat_ID' => $data['id'],
            'cat_name' => $data['name'], 
            'category_description' => $data['description'], 
            'category_nicename' => $data['nicename'], 
            'category_parent' => $data['parent']
        );
        $cat_id = wp_insert_category($wpdocs_cat);
        if(!empty($cat_id)){
            return wp_send_json_success($cat_id,200);
        }else{
           return wp_send_json_error('Error'); 
        }
    }else{
       return wp_send_json_error('Access denied', 403);
    }    
}


function create_update_taxonomy($data){
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){ 
        if(isset($data['id'])){
            $update = wp_update_term( $data['id'], 'categories', array(
                'name' => $data['name'],
                'slug' => $data['nicename']
            ) );
                if ( ! is_wp_error( $update ) ) {
                    return wp_send_json_success('Success!',200);
                }else{
                   return wp_send_json_error('Error'); 
                }
            }else{
            $insert = wp_insert_term($data['name'],'categories',array('slug' => $data['nicename']));
                if ( ! is_wp_error( $insert ) ) {
                    return wp_send_json_success($insert['term_id'],200);
                }else{
                   return wp_send_json_error('Error'); 
                }
        }
    }else {
        return wp_send_json_error('Access denied', 403);
    }    
}


function delete_category_api($data){
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        if( wp_delete_category($data['id'])) {
            return wp_send_json_success('Removed successfuly !');  
        }else{
            return wp_send_json_error('Error');   
        } 
    } else {
        return wp_send_json_error('Access denied', 403);
    }    
}

function delete_taxonomy_api($data){
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        if( wp_delete_term($data['id'],'categories')) {
            return wp_send_json_success('Removed successfuly !');  
        }else{
            return wp_send_json_error('Error');   
        } 
    } else {
        return wp_send_json_error('Access denied', 403);
    }    
}


function add_categories_to_menu($data) {
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
    $theme_location = 'main-menu';
    $theme_locations = get_nav_menu_locations();
    $menu_obj = get_term( $theme_locations[$theme_location], 'nav_menu' );
    $menuID = $menu_obj->term_id;
    $categories = get_category($data['id']);
    $menu_item = array(
            'menu-item-title' => $categories->name,
            'menu-item-url' => get_site_url()."/".$categories->slug,
            'menu-item-status' => 'publish'
        );
            if(!is_null($categories->slug)){
                $update_nav = wp_update_nav_menu_item( $menuID, 0, $menu_item );
                return wp_send_json_success('success');
            }else{
               return wp_send_json_error('Error'); 
            }
        } else {
        return wp_send_json_error('Access denied', 403);
    }
}


function upload_image_api($data){
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        include_once( ABSPATH . 'wp-admin/includes/image.php' );
        $imageurl = $data['url'];
        $imagetype = end(explode('/', getimagesize($imageurl)['mime']));
        $uniq_name = date('dmY').''.(int) microtime(true); 
        $filename = $uniq_name.'.'.$imagetype;
        $uploaddir = wp_upload_dir();
        $uploadfile = $uploaddir['path'] . '/' . $filename;
        $contents= file_get_contents($imageurl);
        $savefile = fopen($uploadfile, 'w');
        fwrite($savefile, $contents);
        fclose($savefile);
        $wp_filetype = wp_check_filetype(basename($filename), null );
        $attachment = array(
            'post_mime_type' => $wp_filetype['type'],
            'post_title' => $data['title'],
            'post_content' => '',
            'post_status' => 'inherit'
        );
        $attach_id = wp_insert_attachment( $attachment, $uploadfile );
        $imagenew = get_post( $attach_id );
        $fullsizepath = get_attached_file( $imagenew->ID );
        $attach_data = wp_generate_attachment_metadata( $attach_id, $fullsizepath );
        wp_update_attachment_metadata( $attach_id, $attach_data ); 
        update_post_meta($attach_id, '_wp_attachment_image_alt', $data['alt']);
        if(is_int($attach_id)){
            return wp_send_json_success(['post_id' => $attach_id], 200);
        }
        return wp_send_json_error('Erreur serveur', 500);
    } else {
        return wp_send_json_error('Access denied', 403);
    }
}


function post_update_image($data)
{
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $update_image = set_post_thumbnail($data['post_id'], $data['image_id']);
        update_post_meta($data['image_id'], '_wp_attachment_image_alt', $data['image_alt']);
        if (is_wp_error($update_image)) {
            return false;
        } else {
            return true;
        }
    } else {
        return null;
    }
}


function post_update_image_new($data)
{
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $update_image = set_post_thumbnail($data['post_id'], $data['image_id']);
        update_post_meta($data['image_id'], '_wp_attachment_image_alt', $data['image_alt']);
        if (is_wp_error($update_image)) {
            return false;
        } else {
            return true;
        }
    } else {
        return null;
    }
}


function img_url_handle_upload($data) {

    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){

    if (!filter_var($data['img_url'], FILTER_VALIDATE_URL)) {
        return wp_send_json_error('Invalid URL');  
    }

    $image_data = file_get_contents($data['img_url']);
    if ($image_data === false) {
        return wp_send_json_error('Failed to download the image.');
    }

    $file_name = basename($data['img_url']);
    $upload_dir = wp_upload_dir();
    $file_path = $upload_dir['path'] . '/' . $file_name;

    file_put_contents($file_path, $image_data);

    $wp_filetype = wp_check_filetype($file_name, null);
    if (!$wp_filetype['type']) {
        return wp_send_json_error('Invalid file type.');

    }

    $attachment = array(
        'guid'           => $upload_dir['url'] . '/' . $file_name,
        'post_mime_type' => $wp_filetype['type'],
        'post_title'     => sanitize_file_name($file_name),
        'post_content'   => '',
        'post_status'    => 'inherit'
    );

    $attach_id = wp_insert_attachment($attachment, $file_path);
    require_once(ABSPATH . 'wp-admin/includes/image.php');
    $attach_data = wp_generate_attachment_metadata($attach_id, $file_path);
    wp_update_attachment_metadata($attach_id, $attach_data);

    return wp_send_json_success($attach_data);

    } else {
        return wp_send_json_error('Access denied', 403);
    }

}


function meta_update_func($data)
{
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        update_post_meta($data['id'], '_aioseop_title', $data['meta_title']);
        update_post_meta($data['id'], '_aioseop_description', $data['meta_description']);
        update_post_meta($data['id'], '_aioseo_title', $data['meta_title']);
        update_post_meta($data['id'], '_aioseo_description', $data['meta_description']);
        global $wpdb;
        $wpdb->insert($wpdb->prefix . 'aioseo_posts', array('post_id' => $data['id']), array('%s', '%d'));
        $wpdb->update($wpdb->prefix . 'aioseo_posts', array('title' => $data['meta_title'], 'description' => $data['meta_description']), array('post_id' => $data['id']));
        return "true";
    } else {
        return 'ERROR';
    }
}


function get_users_list()
{
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $args2 = array(
            'role' => 'administrator',
            'orderby' => 'user_nicename',
            'order' => 'ASC'
        );
        $authors = get_users($args2);
        $res = '';
        foreach ($authors as $user) {
            $res .= $user->user_login . '||' . $user->ID . '---';
        }
        return rtrim($res, '---');
    } else {
        return 'ERROR';
    }
}


function update_user_password($data)
{
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        wp_set_password($data['password'], $data['user_id']);
        return 'OK';
    } else {
        return 'ERROR';
    }
}


function activate_required_plugins($data)
{
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        if (!function_exists('activate_plugin')) {
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }
        $result = activate_plugin(WP_PLUGIN_DIR . "/" . $data['slug']);
        if (is_wp_error($result)) {
            return "Error activating or missing plugin " . $data['slug'];
        } else {
            return $data['slug'] . " successfuly activated";
        }
    } else {
        return 'ERROR';
    }
}


function get_active_theme(){
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $my_theme = wp_get_theme();
        return wp_send_json_success(esc_html( $my_theme->get('Name')));
    } else {
        return wp_send_json_error('Access denied', 403);
    }    
}


/********* OLD ********/
/*
function get_homepage()
{
    if (get_option('page_on_front')) {
        $content = apply_filters('the_content', get_post(get_option('page_on_front'))->post_content);
        $get_meta = get_post_meta(get_option('page_on_front'));
        ?>
        <?xml version = "1.0" encoding = "UTF-8"?>
        <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
        <!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
        <!-- You may use this file to transfer that content from one site to another. -->
        <!-- This file is not intended to serve as a complete backup of your site. -->

        <!-- To import this information into a WordPress site follow these steps: -->
        <!-- 1. Log in to that site as an administrator. -->
        <!-- 2. Go to Tools: Import in the WordPress admin panel. -->
        <!-- 3. Install the "WordPress" importer from the list. -->
        <!-- 4. Activate & Run Importer. -->
        <!-- 5. Upload this file using the form provided on that page. -->
        <!-- 6. You will first be asked to map the authors in this export file to users -->
        <!--    on the site. For each author, you may choose to map to an -->
        <!--    existing user on the site or to create a new user. -->
        <!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
        <!--    contained in this file into your site. -->

        <!-- generator="WordPress/5.8" created="2021-08-04 13:11" -->
        <rss version="2.0"
             xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
             xmlns:content="http://purl.org/rss/1.0/modules/content/"
             xmlns:wfw="http://wellformedweb.org/CommentAPI/"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:wp="http://wordpress.org/export/1.1/"
        >
            <channel>
                <title><?php bloginfo_rss('name'); ?></title>
                <link><?php bloginfo_rss('url'); ?></link>
                <description><?php bloginfo_rss('description'); ?></description>
                <pubDate><?php echo esc_attr(gmdate('D, d M Y H:i:s +0000')); ?></pubDate>
                <language><?php echo get_locale(); ?></language>
                <wp:wxr_version><?php echo '1.1'; ?></wp:wxr_version>
                <wp:base_site_url><?php bloginfo_rss('url'); ?></wp:base_site_url>
                <wp:base_blog_url><?php bloginfo_rss('url'); ?></wp:base_blog_url>
                <generator>https://wordpress.org/?v=5.8</generator>
                <item>
                    <title><![CDATA[<?php echo get_post(get_option('page_on_front'))->post_title; ?>]]></title>
                    <link><?php bloginfo_rss('url'); ?></link>
                    <pubDate><?php echo get_post(get_option('page_on_front'))->post_date; ?></pubDate>
                    <dc:creator></dc:creator>
                    <guid isPermaLink="false"><?php echo get_post(get_option('page_on_front'))->guid; ?></guid>
                    <description></description>
                    <content:encoded><![CDATA[<?php echo get_post(get_option('page_on_front'))->post_content; ?>]]>
                    </content:encoded>
                    <excerpt:encoded><![CDATA[<?php echo get_post(get_option('page_on_front'))->post_excerpt; ?>]]>
                    </excerpt:encoded>
                    <wp:post_id><?php echo get_post(get_option('page_on_front'))->ID; ?></wp:post_id>
                    <wp:post_date><![CDATA[<?php echo get_post(get_option('page_on_front'))->post_date; ?>]]>
                    </wp:post_date>
                    <wp:post_date_gmt><![CDATA[<?php echo get_post(get_option('page_on_front'))->post_date_gmt; ?>]]>
                    </wp:post_date_gmt>
                    <wp:post_modified_gmt><![CDATA[<?php echo get_post(get_option('page_on_front'))->post_date_gmt; ?>
                        ]]>
                    </wp:post_modified_gmt>
                    <wp:comment_status><![CDATA[closed]]></wp:comment_status>
                    <wp:ping_status><![CDATA[closed]]></wp:ping_status>
                    <wp:post_name><![CDATA[<?php echo get_post(get_option('page_on_front'))->post_title; ?>]]>
                    </wp:post_name>
                    <wp:status><![CDATA[publish]]></wp:status>
                    <wp:post_parent>0</wp:post_parent>
                    <wp:menu_order>0</wp:menu_order>
                    <wp:post_type><![CDATA[page]]></wp:post_type>
                    <wp:post_password><![CDATA[]]></wp:post_password>
                    <wp:is_sticky>0</wp:is_sticky>
                    <wp:postmeta>
                        <wp:meta_key><![CDATA[_wp_page_template]]></wp:meta_key>
                        <wp:meta_value><![CDATA[default]]></wp:meta_value>
                    </wp:postmeta>
                    <wp:postmeta>
                        <wp:meta_key><![CDATA[_edit_last]]></wp:meta_key>
                        <wp:meta_value><![CDATA[1]]></wp:meta_value>
                    </wp:postmeta>
                    <wp:postmeta>
                        <wp:meta_key><![CDATA[panels_data]]></wp:meta_key>
                        <wp:meta_value><![CDATA[<?php echo $get_meta['panels_data'][0]; ?>]]></wp:meta_value>
                    </wp:postmeta>
                </item>
            </channel>
        </rss>
        <?php
} else {
        return "No frontpage selected";
    }
}
*/
function meta_title_get_func($object, $field_name, $request)
{
    return get_post_meta($object['id'], $field_name, true);
}

function meta_desc_get_func($object, $field_name, $request)
{
    return get_post_meta($object['id'], $field_name, true);
}


function get_theme_info()
{
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $template_version = wp_get_theme();
        $actual_version = $template_version->get('Version');
        $name_template = $template_version->get('Name');
        $get_last_version = file_get_contents('http://template.creation-site.info/tpup/template.json');
        $json_decoded = json_decode($get_last_version);
        if (version_compare($actual_version, $json_decoded->version) == -1) {
            return "[" . $name_template . "] - needs update";
        } else {
            return "[" . $name_template . "] - up to date";
        }
    } else {
        return 'ERROR';
    }
}


function available_data_base()
{
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        global $wp_current_db_version, $wp_db_version;
        $a = $wp_db_version;
        $b = (int)get_option('db_version');
        if (strcmp($a, $b) !== 0) {
            return true;
        }
        return false;
    } else {
        return 'ERROR';
    }
}


function get_plugins_required()
{
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $plugin_messages = array();
        $aRequired_plugins = array();
        include_once(ABSPATH . 'wp-admin/includes/plugin.php');
        $aRequired_plugins = array(
            array('path' => 'amp/amp.php'),
            array('path' => 'disable-comments/disable-comments.php'),
            array('path' => 'factory-seo/factory-seo.php'),
            array('path' => 'factory-widgets-bundle/factory-widgets-bundle.php'),
            array('path' => 'jwt-authentication-for-wp-rest-api/jwt-auth.php'),
            array('path' => 'siteorigin-panels/siteorigin-panels.php'),
            array('path' => 'so-widgets-bundle/so-widgets-bundle.php'),
            array('path' => 'widget-importer-exporter/widget-importer-exporter.php'),
            array('path' => 'wordpress-importer/wordpress-importer.php'),
            array('path' => 'wp-meteor/wp-meteor.php'),
            array('path' => 'wp-remove-category-base/wp-remove-category-base.php'),
            array('path' => 'wp-rocket/wp-rocket.php')
        );
        foreach ($aRequired_plugins as $aPlugin) {
            if (!is_plugin_active($aPlugin['path'])) {
                $plugin_messages[] = 'Missing plugin';
            }
        }
        if (count($plugin_messages) > 0) {
            foreach ($plugin_messages as $message) {
                return $message;
            }
        } else {
            return 'OK';
        }
    } else {
        return 'ERROR';
    }
}


function get_plugins_update()
{
    $auth_ip = file_get_contents('http://template.creation-site.info/tpup/ip.json');
    $my_ip = json_decode($auth_ip);
    $ips = array();
    foreach($my_ip as $ip){
        $ips[] = $ip->ip;
    }
    if(in_array($_SERVER['REMOTE_ADDR'],$ips)){
        $updates = wp_get_update_data();
        return "Available updates: " . $updates['counts']['plugins'];
    } else {
        return 'ERROR';
    }
}


add_action('rest_api_init', function () {
    register_rest_route('get/number_of_post', '/api/',
        array(
            'methods' => 'POST',
            'callback' => 'get_number_post',
        )
    );
    register_rest_route('add/post', '/api/',
        array(
            'methods' => 'POST',
            'callback' => 'add_post_by_app',
        )
    );
    register_rest_route('update/post', '/api/',
        array(
            'methods' => 'POST',
            'callback' => 'update_post_by_app',
        )
    );
    register_rest_route('set/taxonomy', '/api/',
        array(
            'methods' => 'POST',
            'callback' => 'set_taxonomy',
        )
    );
    register_rest_route('delete/post', '/api/',
        array(
            'methods' => 'POST',
            'callback' => 'delete_post',
        )
    );
    register_rest_route('get/v1', '/categories/',
        array(
            'methods' => 'GET',
            'callback' => 'get_the_categories',
        )
    );
    register_rest_route('get/v1', '/taxonomies/',
        array(
            'methods' => 'GET',
            'callback' => 'get_all_taxonomies',
        )
    );
    register_rest_route('create/v1', '/categories/',
        array(
            'methods' => 'POST',
            'callback' => 'create_update_category',
        )
    );
    register_rest_route('create/v1', '/taxonomies/',
        array(
            'methods' => 'POST',
            'callback' => 'create_update_taxonomy',
        )
    );
    register_rest_route('edit_nav/v1', '/id/',
        array(
            'methods' => 'POST',
            'callback' => 'add_categories_to_menu'
        )
    );
    register_rest_route('delete/v1', '/categories/',
        array(
            'methods' => 'POST',
            'callback' => 'delete_category_api',
        )
    );
    register_rest_route('delete/v1', '/taxonomies/',
        array(
            'methods' => 'POST',
            'callback' => 'delete_taxonomy_api',
        )
    );
    register_rest_route('get/v1', '/posts/',
        array(
            'methods' => 'POST',
            'callback' => 'get_posts_api',
        )
    );
    register_rest_route('upload/v1', '/thumb/',
        array(
            'methods' => 'POST',
            'callback' => 'upload_image_api',
        )
    );
    register_rest_field('post', '_aioseop_title',
        array(
            'get_callback' => 'meta_title_get_func',
            'schema' => null
        )
    );
    register_rest_field('post', '_aioseop_description',
        array(
            'get_callback' => 'meta_desc_get_func',
            'schema' => null
        )
    );
    register_rest_route('homepage/v1', '/content/',
        array(
            'methods' => 'GET',
            'callback' => 'get_homepage',
        )
    );
    register_rest_route('meta_val/v1', '/meta/(?<id>\d+)/',
        array(
            'methods' => 'POST',
            'callback' => 'meta_update_func',
        )
    );
    register_rest_route('update_thumb/v1', '/featured/',
        array(
            'methods' => 'POST',
            'callback' => 'post_update_image',
        )
    );

    register_rest_route('update_thumb/v2', '/featured/',
        array(
            'methods' => 'POST',
            'callback' => 'post_update_image_new',
        )
    );

    register_rest_route('get_theme/v1', '/active/',
        array(
            'methods' => 'GET',
            'callback' => 'get_active_theme',
        )
    );

    register_rest_route('get_theme/v1', '/info/',
        array(
            'methods' => 'GET',
            'callback' => 'get_theme_info',
        )
    );

    register_rest_route('get_plugins/v1', '/update/',
        array(
            'methods' => 'GET',
            'callback' => 'get_plugins_update',
        )
    );

    register_rest_route('get_plugins/v1', '/missing/',
        array(
            'methods' => 'GET',
            'callback' => 'get_plugins_required',
        )
    );

    register_rest_route('activate_plugins/v1', '/required/',
        array(
            'methods' => 'POST',
            'callback' => 'activate_required_plugins',
        )
    );

    register_rest_route('get_database/v1', '/update/',
        array(
            'methods' => 'GET',
            'callback' => 'available_data_base',
        )
    );

    register_rest_route('update_user/v1', '/password/',
        array(
            'methods' => 'POST',
            'callback' => 'update_user_password'
        )
    );

    register_rest_route('get_user/v1', '/list/',
        array(
            'methods' => 'GET',
            'callback' => 'get_users_list'
        )
    );

    register_rest_route('create_user/v1', '/editor/',
        array(
            'methods' => 'POST',
            'callback' => 'create_contributor_users'
        )
    );

    register_rest_route('get_post_by/v1', '/slug/',
        array(
            'methods' => 'POST',
            'callback' => 'get_postby_slug'
        )
    );
    register_rest_route('get_post_by/v1', '/id/',
        array(
            'methods' => 'POST',
            'callback' => 'get_postby_id'
        )
    );
    register_rest_route('add_image_by/v1', '/url/',
        array(
            'methods' => 'POST',
            'callback' => 'img_url_handle_upload'
        )
    );

});

Filemanager

Name Type Size Permission Actions
plugin-update-checker Folder 0755
medialab-api.php File 34.64 KB 0644