Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.41 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * @package Jaya
  5.  */
  6. /*
  7. Plugin Name: Jaya PLugin
  8. Plugin URI: https://fahrulsanjaya.it.student.ac.id/plugin
  9. Description: Plugin untuk prakikum Aplikasi dan Teknologi Web
  10. Version: 1.0.0
  11. Author: Fahrulsanjaya
  12. Author URI: https://fahrulsanjaya.it.student.ac.id/plugin
  13. License: GPLv2 or later
  14. */
  15.  
  16. add_filter("the_content", "takeinput"); //
  17.  
  18. add_filter("the_content", "contentfilter");
  19.  
  20. add_filter("the_content", "tambahinput"); //
  21.  
  22. add_action("wp_head", "sendInput"); //
  23.  
  24. add_action("wp_head", "nambah_view");
  25.  
  26. add_filter("the_content", "tampilkan_jum_view");
  27.  
  28. add_filter("the_content", "eventKetik");
  29. //https://code.jquery.com/jquery-3.4.1.js
  30. function contentfilter($content)
  31. {
  32.     $newcontent .= $content;
  33.     $newcontent .= "<hr> ini tambahan contentnya: ";
  34.     $newcontent .= "<script src='https://code.jquery.com/jquery-3.4.1.js' integrity='sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU='   crossorigin='anonymous'></script>";
  35.     $newcontent .= "<a href='mailto:paxtanto@gmail.com' title='silahkan isi judul disini'>" . get_the_title() . "</a>";
  36.     return $newcontent;
  37. }
  38.  
  39. function nambah_view()
  40. {
  41.     if (is_single()) {
  42.         global $post;
  43.         $jumView = get_post_meta($post->ID, "jumView", true);
  44.         if (!isset($jumView) or empty($jumView) or !is_numeric($jumView)) {
  45.             $jumView = 0;
  46.         }
  47.         $new_jumview = $jumView + 1;
  48.         update_post_meta($post->ID, "jumView", $new_jumview);
  49.         return $new_jumview;
  50.     }
  51. }
  52. function get_jumlah_view()
  53. {
  54.     global $post;
  55.     $jumView = get_post_meta($post->ID, "jumView", true);
  56.     if (!isset($jumView) or empty($jumView) or !is_numeric($jumView)) {
  57.         $jumView = 0;
  58.     }
  59.     return $jumView;
  60. }
  61. function tampilkan_jum_view($content, $teksintro = "posting ini memiliki jumlah view sebanyak ")
  62. {
  63.     if (is_single()) {
  64.         $newcontent = $content;
  65.         $jumView = get_jumlah_view();
  66.         $iconurl = plugins_url('img/icon.jpg', __FILE__);
  67.         $teksnya = "<img title='gambar plugin' src='" . $iconurl . "'>";
  68.         $teksnya .= $teksintro . $jumView . " ";
  69.         $newcontent .= $teksnya;
  70.         echo $newcontent;
  71.     }
  72. }
  73.  
  74. //tugasku
  75. function tambahinput($content)
  76. {
  77.  
  78.     $newcontent .= $content;
  79.     $newcontent .= "
  80.        <div id='count'></div>
  81.        <form method='post'>
  82.        <textarea placeholder='masukkan sesuatu' id='komen' name='angka' maxlength='280'> </textarea>
  83.        <br>
  84.        <input type='submit' value='Komen'/>
  85.        </form>";
  86.  
  87.     return $newcontent;
  88. }
  89. function sendInput()
  90. {
  91.     global $wpdb;
  92.     $wpdb->insert('praktikum', array('inputUser' => $_POST['angka']));
  93. }
  94.  
  95. function takeinput()
  96. {
  97.     global $wpdb;
  98.     $praktikum = $wpdb->get_results("SELECT * FROM praktikum");
  99. ?>
  100.     <table>
  101.         <tr>
  102.             <th>id</th>
  103.             <th>Input</th>
  104.         </tr>
  105.         <?php
  106.         foreach ($praktikum as $val) {
  107.         ?>
  108.             <tr>
  109.                 <td><?php echo $val->id ?></td>
  110.                 <td><?php echo $val->inputUser ?></td>
  111.             </tr>
  112.         <?php
  113.  
  114.         }
  115.         ?>
  116.     </table>
  117. <?php
  118. }
  119. function eventKetik()
  120. {
  121. ?>
  122.     <script>
  123.         $(document).ready(function() {
  124.             var max = 280;
  125.             $("textarea").keyup(function(e) {
  126.                 $("#count").text("Sisa Karakter: " + (max - $(this).val().length));
  127.             });
  128.         });
  129.     </script>
  130. <?php
  131. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement