Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * The plugin bootstrap file
- *
- * This file is read by WordPress to generate the plugin information in the plugin
- * admin area. This file also includes all of the dependencies used by the plugin,
- * registers the activation and deactivation functions, and defines a function
- * that starts the plugin.
- *
- * @since 1.0.0
- * @package SguSchedule
- *
- * @wordpress-plugin
- * Plugin Name: sguSchedule-1
- * Plugin URI: t.me/vo1sss
- * Description: Этот плагин позволяет вам добавить на ваш сайт расписание Сыктывкарского государственного университета!
- * Version: 1.0.0
- * Author: vo1s
- * Author URI: t.me/vo1sss
- */
- class My_Widget extends WP_Widget {
- public function __construct() {
- // Запускаем родительский класс
- parent::__construct(
- '', // ID виджета, если не указать (оставить ''), то ID будет равен названию класса в нижнем регистре: my_widget
- 'Расписание1',
- array('description' => 'Виджет, создающий расписание СГУ')
- );
- add_action('wp_head', array( $this, 'add_my_widget_style' ) );
- }
- // Вывод виджета
- public function widget( $args, $instance ){
- ?>
- <form action="" method="post">
- <input type="text" name="message" />
- <input type="submit" name="send" value="Отправить" />
- </form>
- <?php
- if(isset($_POST["message"])){$message = $_POST["message"]; echo $message;}
- $info = file_get_contents('https://campus.syktsu.ru/api/schedule/group/?group_name=111-%D0%9F%D0%9C%D0%BE&week_offset=0');
- $info = json_decode($info, true);
- $dayss = array(
- "Понедельник",
- "Вторник",
- "Среда",
- "Четверг",
- "Пятница",
- "Суббота",
- );
- $count = 0;
- echo "<div class=\"sch\">";
- foreach($info as $days){
- $is_empty = true;
- echo "<div class=\"lol\">";
- echo "<p>".$dayss[$count]."</p>";
- $count = $count + 1;
- foreach($days as $subject){
- if(!empty($subject) and isset($subject)){
- echo("<span class=\"numLesson\">".($subject["lesson_num"]+1)."</span>");
- echo ' ';
- echo($subject["time"]['hours'].':'.$subject["time"]['minutes']);
- echo ' ';
- echo($subject["whole_group"]["auditory"]);
- echo ' ';
- echo($subject["whole_group"]["teacher"]);
- echo ' ';
- echo($subject["whole_group"]["subject_name"]);
- echo "<br>";
- $is_empty = false;
- }
- }
- if($is_empty) {echo "Нет занятий!";}
- echo "</div>";
- echo "<br>";
- }
- echo "</div>";
- ?>
- <?php
- }
- // Сохранение настроек виджета (очистка)
- public function update( $new_instance, $old_instance ) {
- return $new_instance;
- }
- // html форма настроек виджета в Админ-панели
- public function form( $instance ) {
- }
- // стили виджета
- function add_my_widget_style() {
- // фильтр чтобы можно было отключить стили
- ?>
- <style>
- .my_widget {background-color: black;}
- .sch {
- display:inline;
- }
- .lol{
- border-bottom: 1px solid black;
- }
- .my_widget a{ display:inline; }
- .numLesson{
- font-weight: bold;
- }
- </style>
- <?php
- }
- }
- // Регистрация класса виджета
- add_action( 'widgets_init', 'my_register_widgets' );
- function my_register_widgets() {
- register_widget( 'My_Widget' );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement