Advertisement
fevenili

sguSchedule-1

Apr 24th, 2022
1,397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.19 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * The plugin bootstrap file
  5.  *
  6.  * This file is read by WordPress to generate the plugin information in the plugin
  7.  * admin area. This file also includes all of the dependencies used by the plugin,
  8.  * registers the activation and deactivation functions, and defines a function
  9.  * that starts the plugin.
  10.  *
  11.  * @since             1.0.0
  12.  * @package           SguSchedule
  13.  *
  14.  * @wordpress-plugin
  15.  * Plugin Name:       sguSchedule-1
  16.  * Plugin URI:        t.me/vo1sss
  17.  * Description:       Этот плагин позволяет вам добавить на ваш сайт расписание Сыктывкарского государственного университета!
  18.  * Version:           1.0.0
  19.  * Author:            vo1s
  20.  * Author URI:        t.me/vo1sss
  21.  */
  22.  
  23.  
  24. class My_Widget extends WP_Widget {
  25.  
  26. public function __construct() {
  27.     // Запускаем родительский класс
  28.     parent::__construct(
  29.         '', // ID виджета, если не указать (оставить ''), то ID будет равен названию класса в нижнем регистре: my_widget
  30.         'Расписание1',
  31.         array('description' => 'Виджет, создающий расписание СГУ')
  32.     );
  33.         add_action('wp_head', array( $this, 'add_my_widget_style' ) );
  34. }
  35.  
  36.  
  37. // Вывод виджета
  38. public function widget( $args, $instance ){
  39.    
  40.     ?>
  41.     <form action="" method="post">
  42.         <input type="text" name="message" />
  43.         <input type="submit" name="send" value="Отправить" />
  44.       </form>
  45.  
  46.     <?php
  47.         if(isset($_POST["message"])){$message = $_POST["message"]; echo $message;}
  48.         $info = file_get_contents('https://campus.syktsu.ru/api/schedule/group/?group_name=111-%D0%9F%D0%9C%D0%BE&week_offset=0');
  49.         $info = json_decode($info, true);
  50.         $dayss = array(
  51.             "Понедельник",
  52.             "Вторник",
  53.             "Среда",
  54.             "Четверг",
  55.             "Пятница",
  56.             "Суббота",
  57.         );
  58.  
  59.         $count = 0;
  60.        
  61.         echo "<div class=\"sch\">";
  62.         foreach($info as $days){
  63.             $is_empty = true;
  64.             echo "<div class=\"lol\">";
  65.             echo "<p>".$dayss[$count]."</p>";
  66.             $count = $count + 1;
  67.             foreach($days as $subject){
  68.                 if(!empty($subject) and isset($subject)){
  69.                     echo("<span class=\"numLesson\">".($subject["lesson_num"]+1)."</span>");
  70.                     echo ' ';
  71.                     echo($subject["time"]['hours'].':'.$subject["time"]['minutes']);
  72.                     echo ' ';
  73.                     echo($subject["whole_group"]["auditory"]);
  74.                     echo ' ';
  75.                     echo($subject["whole_group"]["teacher"]);
  76.                     echo ' ';
  77.                     echo($subject["whole_group"]["subject_name"]);
  78.                     echo "<br>";
  79.                     $is_empty = false;
  80.                 }
  81.                
  82.             }
  83.            
  84.            
  85.             if($is_empty) {echo "Нет занятий!";}
  86.             echo "</div>";
  87.             echo "<br>";
  88.            
  89.         }
  90.         echo "</div>";
  91.     ?>
  92.    
  93.  
  94.  
  95.    
  96.     <?php
  97. }
  98.  
  99. // Сохранение настроек виджета (очистка)
  100. public function update( $new_instance, $old_instance ) {
  101.  return $new_instance;
  102. }
  103.  
  104. // html форма настроек виджета в Админ-панели
  105. public function form( $instance ) {
  106. }
  107.  
  108. // стили виджета
  109. function add_my_widget_style() {
  110.     // фильтр чтобы можно было отключить стили
  111.     ?>
  112.     <style>
  113.         .my_widget {background-color: black;}
  114.         .sch {
  115.             display:inline;
  116.         }
  117.         .lol{
  118.             border-bottom: 1px solid black;
  119.         }
  120.         .my_widget a{ display:inline; }
  121.         .numLesson{
  122.             font-weight: bold;
  123.         }
  124.     </style>
  125.     <?php
  126. }
  127. }
  128.  
  129. // Регистрация класса виджета
  130. add_action( 'widgets_init', 'my_register_widgets' );
  131. function my_register_widgets() {
  132. register_widget( 'My_Widget' );
  133. }
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement