Skip to content

Instantly share code, notes, and snippets.

@guoxiangke
guoxiangke / preg
Created November 9, 2015 03:09
匹配到最后一个括号里的内容 preg (
[\((][\s\S]*[\))]
@guoxiangke
guoxiangke / views_agax
Last active October 23, 2015 09:08
drupal views Ajax get views update
<div id="views">views!!!begin!!!
<?php
print views_embed_view('foodbanks', 'block', $state);
?>
<a href="##" id= "freash" >freash!!!</a>
<script type="text/javascript">
(function($) {
function getInfo(args) {
$.ajax({
@guoxiangke
guoxiangke / print block in template with contextual-links
Created September 11, 2015 08:49
print block in template with contextual-links 在模板中打印block 带有编辑连接!
@guoxiangke
guoxiangke / Geolocation maxmind
Created September 7, 2015 07:46
Geolocation maxmind
/**
* Geolocation
*/
$ip = $_SERVER['REMOTE_ADDR'];
$result = db_select('ip_geolocation', 'g')
->fields('g')
->condition('ip', $ip, '=')
->execute()
->fetchAssoc();
@guoxiangke
guoxiangke / preg get URL parameter
Created June 30, 2015 03:54
//正则表达式获取URL参数 preg get URL parameter
//正则表达式获取URL参数 preg get URL parameter
//http://stackoverflow.com/questions/11706986/php-getting-url-variable-with-preg-match
$subject = "http://www.mysite.com?id=05&name=johnny";
$pattern = '/id=[0-9A-Za-z]*/'; //$pattern = '/id=[0-9]*/'; if it is only numeric.
preg_match($pattern, $subject, $matches);
print_r($matches);
@guoxiangke
guoxiangke / Multiple cURL Requests with PHP
Created March 17, 2015 08:03
Multiple cURL Requests with PHP
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Multiple cURL Requests with PHP</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.min.css">
@guoxiangke
guoxiangke / wordpress ajax comment
Created September 15, 2014 04:05
wordpress ajax comment! getCommentHTML???
<?php
// Method to handle comment submission
function ajaxComment($comment_ID, $comment_status) {
// If it's an AJAX-submitted comment
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
// Get the comment data
$comment = get_comment($comment_ID);
// Allow the email to the author to be sent
wp_notify_postauthor($comment_ID, $comment->comment_type);
// Get the comment HTML from my custom comment HTML function
@guoxiangke
guoxiangke / wp-members-core.php
Last active August 29, 2015 14:05
wordpress 邮箱验证前禁止注册用户登陆
<?php
/**
* 需求:User can register using email and user name, then log in later after receiving the validation email. All the users share the same avatar.
* 即 邮箱验证前禁止注册用户登陆
* 本需求可以使用Pie Register的验证link 并参照 http://wordpress.org/plugins/wp-members/ 的 wp-members-core.php 代码 进行实现
* Step 1: Enable plugin Pie Register http://wordpress.org/plugins/pie-register/
* Step 2: Go Pie Register -> General Settings (wp-admin/admin.php?page=pie-general-settings) set User Verification => Email Verification.
* Step 3: Add flow code in your theme functions.php
*/
/** initialize **/
@guoxiangke
guoxiangke / jcrop_form_element_plus.module
Created July 9, 2014 04:57
默认对用户头像 剪切
//https://www.drupal.org/project/jcrop_form_element
/**
* Implements hook_form_alter().
*/
function jcrop_fapi_form_alter(&$form, &$form_state, $form_id) {
$form['picture']['picture_upload']['#type'] = 'jcrop_image';
$libraries = libraries_load('jcrop', $variant = NULL);
libraries_load_files($libraries);
array_unshift($form['#submit'], 'jcrop_form_submit');
}
@guoxiangke
guoxiangke / weixin node create book!
Created May 30, 2014 22:58
weixin node create book!
$books = array(
'0'=>'http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NjQwMDE2Mw==&appmsgid=10000251&itemidx=1&sign=52b2980fca36785ca3671575fa1cb098#wechat_redirect',
'1'=>'http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NjQwMDE2Mw==&appmsgid=10000251&itemidx=2&sign=b7e8cc04c531fc07a953d39c62411c08#wechat_redirect',
'2'=>'http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NjQwMDE2Mw==&appmsgid=10000251&itemidx=3&sign=df465908982990d92306ac649b9a663e#wechat_redirect',
'3'=>'http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NjQwMDE2Mw==&appmsgid=10000251&itemidx=4&sign=7d98347febbe2707d887f49bf8cddfff#wechat_redirect',
'4'=>'http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NjQwMDE2Mw==&appmsgid=10000251&itemidx=5&sign=547baf5c8b15297f80b4737a04f9ccf7#wechat_redirect',
'5'=>'http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NjQwMDE2Mw==&appmsgid=10000251&itemidx=6&sign=e7e45471b60e5ab7a0624f8b99b2e3a6#wechat_redirect',
'6'=>'http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NjQwMDE2Mw==&appmsgid=10000251&itemidx=7&