php WonderSlack.php

WonderSlack.php
<?php

namespace App\Notifications;

use Illuminate\Notifications\Notifiable;

class WonderSlack
{
    use Notifiable;

    /**
     * SlackチャンネルのWebhookURLを返す
     *
     * @return string
     */
    public function routeNotificationForSlack()
    {
        return config('slack.webhookurl.dm_created');
    }
}

php SendSlack.php

SendSlack.php
<?php

use App\Notifications\WonderSlack;
use App\Notifications\DmCreated;

(new WonderSlack())->notify(new DmCreated('DMデータが作成されました。'));

php 数据挖掘

数据挖掘

data_mining.php
<?php require __DIR__ . '/vendor/autoload.php';

use GuzzleHttp\Client;
use Symfony\Component\DomCrawler\Crawler;

$video = [
    'url' => 'https://www.youtube.com/watch?v=CwpARGF4Zmk'
];

$client = new Client;

$response = $client->request('GET', $video['url']);

if($response->getStatusCode() == 200) {

    // Let's play

    $crawler = new Crawler;
    $crawler->addHtmlContent($response->getBody()->getContents());

    // Title
    // DOM:    <title>%value%</title>
    // filter: title
    try {
        $video['title'] = trim($crawler->filter('title')->first()->text());
    } catch (InvalidArgumentException $e) {
        // this video doesn't have a title?..
        $video['title'] = 'unknown';
    }

    // Description:
    // DOM:    <meta property="og:description" content="%value%">
    // filter: meta[property="og:description"]
    try {
        $video['description'] = $crawler->filter('meta[property="og:description"]')->first()->attr('content');
        // we didn't use a *trim*, for attribute we don't need to use it :D ..
    } catch (InvalidArgumentException $e) {
        // this video doesn't have a description?..
        $video['description'] = 'none';
    }

    // Thumbnail
    // DOM:    <meta property="og:image" content="%value%">
    // filter: meta[property="og:image"]
    try {
        $video['thumbnail'] = $crawler->filter('meta[property="og:image"]')->first()->attr('content');
    } catch (InvalidArgumentException $e) {
        // this video doesn't have a thumbnail?..
        // we can do someting like filter the first image, but for this tut we will use a placeholder
        $video['thumbnail'] = 'http://via.placeholder.com/350x150';
    }

    // View Count
    // DOM:    <meta itemprop="interactionCount" content="%value%">
    // filter: meta[itemprop="interactionCount"]
    try {
        $video['view_count'] = $crawler->filter('meta[itemprop="interactionCount"]')->first()->attr('content');
    } catch (InvalidArgumentException $e) {
        // this video doesn't have a view count?..
        $video['view_count'] = -1;
    }

    var_dump($video); // dump the video

} else {

    print("Houston, we have a problem");

}

php webscrapping示例

webscrapping示例

index.php
<?php

// mkdir webscrapping folder
// cd webscrapping
// Then run composer require fabpot/goutte
// then create index.php with below content

require __DIR__ . '/vendor/autoload.php';



use Goutte\Client;

$client = new Client();
$uri = 'http://www.goal.com/es/partido/deportivo-la-coru%C3%B1a-v-sevilla/comentario-resultados/b07sxrrw4roi1qsjvhdumagyy';
$crawler = $client->request('GET', $uri);
$comment = $crawler->filter("[class='widget-match-commentary clearfix']");
$commentTitle = $comment->filter("[class='card-title']");
//print $commentTitle->text();
$commentDescription = $comment->filter("[class='comment-desc']")->text();
//print_r($commentDescription);


$client = new Client();
$uri = 'https://hdfull.tv/';
$crawler = $client->request('GET', $uri);
$contentVideos = $crawler->filter("[class='breakaway-wrapper-dark']");
$videos = [];
$contentVideosHtml = $contentVideos->filter("[class='flickr item left home-thumb-item']")->each(function ($nodeVideo) {
  print $nodeVideo->html();
});
//print $contentVideosHtml->html();
//print_r($contentVideosHtml);

print $contentVideos->filter("[class='section-title']")->children()->first()->html();

php 数据库根据某一天24小时分组查询

数据库根据某一天24小时分组查询

mysql to Date
select count(*), substring(scanning_time,12,2) from warning_results where scanning_time between '2017-08-10 00:00:00' and '2017-08-10 23:59:59' group by substring(scanning_time,12,2);

php XSSProtection中间件

XSSProtection中间件

XSSProtection.php
<?php

namespace App\Http\Middleware;

use Closure;

class XSSProtection
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!in_array(strtolower($request->method()), ['put', 'post'])) {
            return $next($request);
        }

        $input = $request->all();

        array_walk_recursive($input, function (&$input) {
            if (is_string($input)) {
                $input = htmlspecialchars($input);
            }
        });

        $request->merge($input);

        return $next($request);
    }
}

php ШаблонуведомленийдляTelegram

ШаблонуведомленийдляTelegram

telegram
https://api.telegram.org/bot429949902:AAHFuG3I9COy54yMQeCmA6HI9vl6woCd-E8/sendMessage?chat_id=41402415&text=ES HondroCream: {clickid} - {status}

php 使用一个用于JavaScript地图显示的Google Maps API密钥(活动日历)和用于场地地理位置查找的不同API密钥(事件

使用一个用于JavaScript地图显示的Google Maps API密钥(活动日历)和用于场地地理位置查找的不同API密钥(Events Calendar PRO)。

functions.php
<?php
/**
 * Use one Google Maps API Key for JavaScript Map displays (The Events Calendar)
 * and a different API Key for venue geolocation lookups (Events Calendar PRO).
 *
 * You need this in order to have API Key restrictions.
 * Your "Maps JavaScript API" key should select "HTTP referrers (web sites)" restriction.
 * Your "Geocoding API" key should select "IP addresses (web servers, cron jobs, etc.)" restriction.
 * Screenshot: https://cl.ly/300k2I1s321N
 *
 * @link https://gist.github.com/cliffordp/a2ec320313afbc1ffb5f0e5ac654b7fb This snippet.
 **/
add_filter( 'tribe_events_pro_geocode_request_url', 'ecp_separate_gmaps_api_key_for_geocoding' );
function ecp_separate_gmaps_api_key_for_geocoding( $api_url ) {
	// TODO: !!! CHANGE THIS !!!
	$geo_api_key = 'ABCxyz123';

	$js_api_key = tribe_get_option( 'google_maps_js_api_key' );

	$api_url = str_replace( 'key=' . $js_api_key, 'key=' . $geo_api_key, $api_url );

	// esc_url() will break it so esc_url_raw() or don't escape at all
	return esc_url_raw( $api_url );
}

php 获取由ACF过滤的自定义帖子

functions.php
$args = array(
    'meta_key' => 'editor_type',
    'meta_value' => 2,
    'post_type' => 'editor',
    'post_status' => 'publish',
    'posts_per_page' => -1
);
posts = get_posts($args);

php Laravel文件验证mime类型

laravel_mime_types

https://laracasts.com/discuss/channels/general-discussion/mine-type-validation-rules
https://stackoverflow.com/questions/23625672/laravel-file-upload-validation

<?php

use Illuminate\Foundation\Http\FormRequest;
class ProfileValidator extends FormRequest {
    public function rules() {
        return [
            'pseudonym' => 'required|min:6',
            'email' => 'required|email',
            'avatar' => 'required|mimes:jpeg,png',
        ];
    }
    public function authorize() {return true;}
}


// FOr PDFs only:
        
        $this->validate($request, [
        //    'news_date_id'  => 'required',
            'title'         => 'required',
            'pdf_filename'  => 'required|mimes:pdf',
        //    'uploaded_date' => 'required'
        ]);