Пример моего кода на PHP... И не только.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * @package ChiefRedCom
  4. * @version 1.0
  5. */
  6. /*
  7. Plugin Name: API v1 ChiefRed.com
  8. Description: Подключение к API v1 сервиса наполнения сайтов статьями <a href="https://chiefred.com">ChiefRed.com</a>
  9. Version: 1.0
  10. Author: ChiefRed.com
  11. Author URI: https://ChiefRed.com/
  12. */
  13. if ( ! defined( 'ABSPATH' ) ) exit;
  14. define( 'CHIEFRED_VERSION', '1.0' );
  15. define( 'CHIEFRED_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
  16. define( 'CHIEFRED_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
  17. define( 'CHIEFRED_LOCAL_DEBUG', getenv('DEV_LOCAL') );
  18. define( 'CHIEFRED_LOCAL_BASE', 'https://chiefred.dev' );
  19. define('CHIEFRED_LL_OFF', 0);
  20. define('CHIEFRED_LL_ERROR', 1);
  21. define('CHIEFRED_LL_WARNING', 2);
  22. define('CHIEFRED_LL_INFO', 3);
  23. define('CHIEFRED_LL_DEBUG', 4);
  24. define('CHIEFRED_LOG_LEVEL', CHIEFRED_LL_INFO);
  25. if(CHIEFRED_LOG_LEVEL > CHIEFRED_LL_OFF) {
  26. define('CHIEFRED_LOG_FILE', fopen(CHIEFRED_PLUGIN_DIR.'/logs/chiefred.log', 'a+'));
  27. }
  28. define( 'CHIEFRED_MEDIUM_IMG_WIDTH_LIMIT', 400 );
  29. define( 'CHIEFRED_SMALL_IMG_WIDTH_LIMIT', 200 );
  30. register_activation_hook(__FILE__, 'chiefred_plugin_activation');
  31. function chiefred_plugin_activation()
  32. {
  33. add_option('chiefred_site_id', '', '', 'no');
  34. add_option('chiefred_api_ip', '', '', 'no');
  35. add_option('chiefred_api_port', '', '', 'no');
  36. add_option('chiefred_sync_lock', '0', '', 'no');
  37. add_option('chiefred_article_parent_link', '1', '', 'yes');
  38. add_option('chiefred_article_creators', '1', '', 'yes');
  39. add_option('chiefred_article_childrens', '1', '', 'yes');
  40. add_option('chiefred_article_was_useful', '1', '', 'yes');
  41. add_option('chiefred_illustration_size', 'medium', '', 'yes');
  42. add_option('chiefred_illustration_class', '', '', 'yes');
  43. add_option('chiefred_illustration_link', '1', '', 'yes');
  44. add_option('chiefred_illustration_link_class', 'photo', '', 'yes');
  45. add_option('chiefred_illustration_link_rel', 'lightbox', '', 'yes');
  46. add_option('chiefred_illustration_link_target', '_blank', '', 'yes');
  47. if (! wp_next_scheduled ( 'chiefred_every4hours_synchronize' )) {
  48. wp_schedule_event(time(), 'every4hours', 'chiefred_every4hours_synchronize');
  49. }
  50. }
  51. register_deactivation_hook(__FILE__, 'chiefred_plugin_deactivation');
  52. function chiefred_plugin_deactivation()
  53. {
  54. wp_clear_scheduled_hook('chiefred_synchronize');
  55. wp_clear_scheduled_hook('chiefred_every4hours_synchronize');
  56. }
  57. require_once( CHIEFRED_PLUGIN_DIR . 'class.chiefred.php' );
  58. add_action( 'init', array( 'ChiefRed', 'init' ) );
  59. if ( is_admin() ) {
  60. require_once( CHIEFRED_PLUGIN_DIR . 'class.chiefred-admin.php' );
  61. add_action( 'init', array( 'ChiefRed_Admin', 'init' ) );
  62. }
  63. function chiefred_log_e($msg=null, $var=null)
  64. {
  65. if (CHIEFRED_LOG_LEVEL >= CHIEFRED_LL_ERROR) chiefred_logger('ERROR', $msg, $var);
  66. }
  67. function chiefred_log_w($msg=null, $var=null)
  68. {
  69. if (CHIEFRED_LOG_LEVEL >= CHIEFRED_LL_WARNING) chiefred_logger('WARNING', $msg, $var);
  70. }
  71. function chiefred_log_i($msg=null, $var=null)
  72. {
  73. if (CHIEFRED_LOG_LEVEL >= CHIEFRED_LL_INFO) chiefred_logger('INFO', $msg, $var);
  74. }
  75. function chiefred_log_d($msg=null, $var=null)
  76. {
  77. if (CHIEFRED_LOG_LEVEL >= CHIEFRED_LL_DEBUG) chiefred_logger('DEBUG', $msg, $var);
  78. }
  79. function chiefred_logger($level='debug', $msg=null, $var=null)
  80. {
  81. if (CHIEFRED_LOG_FILE && $msg) {
  82. if ($var !== null) $msg .= ': '.var_export($var, true);
  83. $level = str_pad("[{$level}]", 9, ' ');
  84. fwrite(CHIEFRED_LOG_FILE, date( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) )." {$level} {$msg}\n");
  85. }
  86. }