Skip to content

Instantly share code, notes, and snippets.

@tguruslan
Created February 12, 2024 12:31
Show Gist options
  • Save tguruslan/5f79d22205d9690b150d9aa0085eaa83 to your computer and use it in GitHub Desktop.
Save tguruslan/5f79d22205d9690b150d9aa0085eaa83 to your computer and use it in GitHub Desktop.
udpu folder tree
<?php
/*
Plugin Name: udpu folder tree
Plugin URI: #
Description: для додавання використайте: [udpu_folder_tree path=""]
Author: Tgu
Version: 1.0.0
Author URI: #
*/
add_shortcode("udpu_folder_tree", function($atts, $content = null) {
extract(shortcode_atts(array("path" => ''), $atts));
$req = wp_remote_get('https://udpu.edu.ua/index.php?option=com_ajax&module=listdir&method=iframe&format=raw&path='.$path);
if(is_wp_error($req)){
return;
}else{
$dom = new DOMDocument;
$dom->loadHTML('<meta charset="utf-8">' .$req['body']);
$style = $dom->saveHTML($dom->getElementsByTagName('head')->item(0)->getElementsByTagName('style')->item(0));
add_action('wp_footer', function(){
?>
<script type="text/javascript">
(function($){
$(document).ready(function(){
$(document).find('.rs_dir').on('click',function(){
$(this).find('>folder').toggleClass('open');
});
});
})(jQuery);
</script>
<?php
});
return $style.$dom->saveHTML($dom->getElementsByTagName('body')->item(0));
}
});
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment