This repository has been archived by the owner on Jan 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e33cdbf
Showing
21 changed files
with
1,021 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
|
||
before_script: | ||
- curl -s http://getcomposer.org/installer | php | ||
- php composer.phar install --dev | ||
|
||
script: phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#Visitor | ||
============== | ||
|
||
Register your visitors, Page hists, and count for Laravel 5 | ||
|
||
for laravel 4 use ver v1.0.0 | ||
|
||
### Installation | ||
|
||
|
||
The recommended way to install Winput is through composer. | ||
|
||
## Step 1 | ||
|
||
Just add to `composer.json` file: | ||
|
||
``` json | ||
{ | ||
"require": { | ||
"weboap/visitor": "dev-master" | ||
} | ||
} | ||
``` | ||
|
||
then run | ||
``` php | ||
php composer.phar update | ||
``` | ||
|
||
## Step 2 | ||
|
||
Add | ||
``` php | ||
'Weboap\Visitor\VisitorServiceProvider' | ||
``` | ||
|
||
to the list of service providers in app/config/app.php | ||
|
||
## Step 3 | ||
|
||
Migrate the Visitor Table | ||
Run | ||
|
||
``` php | ||
php artisan vendor:publish | ||
``` | ||
then | ||
|
||
``` php | ||
php artisan migrate | ||
``` | ||
to migrate visitor table | ||
|
||
the config.php will be copied to /config at the same time | ||
|
||
``` php | ||
/config/visitor.php | ||
``` | ||
|
||
costumize it accordinly | ||
|
||
|
||
|
||
## Step 5 (Optional) | ||
|
||
Visit | ||
http://dev.maxmind.com/geoip/geoip2/geolite2/ | ||
|
||
download GeoLite2-City.mmdb | ||
|
||
place it in (create the geo directory) | ||
|
||
``` php | ||
storage/geo/ | ||
``` | ||
or where ever you want just adjust the package config to reflect the new location, | ||
it's used to geo locate visitors | ||
|
||
|
||
|
||
|
||
### Usage | ||
|
||
|
||
|
||
``` php | ||
|
||
|
||
Visitor::log(); //log in db visitor ip, geo location, hit counter | ||
|
||
|
||
Visitor::get(); | ||
Visitor::get( $ip ); //fetch ip record | ||
|
||
|
||
|
||
Visitor::forget( $ip ); //delete ip from log | ||
|
||
|
||
Visitor::has( $ip ); // checkk if visitor ip exist in log | ||
|
||
|
||
Visitor::count() // return count of all site registred unique visitors | ||
|
||
|
||
Visitor::all(); // all records | ||
|
||
|
||
Visitor::clicks(); //total of all clicks | ||
|
||
|
||
Visitor::range($date_start, $date_end); // visitors count in a date range; | ||
|
||
|
||
``` | ||
###Credits | ||
This product Uses GeoLite2 data created by MaxMind, whenever available. | ||
|
||
Enjoy! | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "weboap/visitor", | ||
"description": "log your visitors in db, page hits, and generate visit counter for Laravel 5", | ||
"keywords": ["framework", "laravel","visitors", "counter", "log", "hits", "clicks"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "WeboAp", | ||
"email": "weboap@gmail.com" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"illuminate/support": "~5.0", | ||
"jalle19/php-whitelist-check": "1.0.4", | ||
"geoip2/geoip2": "2.1.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Weboap\\Visitor\\": "src" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"require-dev": { | ||
"phpspec/phpspec": "~2.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php namespace Weboap\Visitor\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class VisitorFacade extends Facade { | ||
|
||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() { return 'visitor'; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php namespace Weboap\Visitor; | ||
|
||
|
||
|
||
use Illuminate\Http\Request as Request; | ||
|
||
|
||
class Ip { | ||
|
||
protected $ip = null; | ||
|
||
protected $request; | ||
|
||
|
||
public function __construct(Request $request, array $validators = array()) | ||
{ | ||
$this->request = $request; | ||
$this->validators = $validators; | ||
|
||
} | ||
|
||
public function get() | ||
{ | ||
$ip = $this->request->getClientIp(); | ||
|
||
if($ip == '::1') { | ||
$ip = '127.0.0.1'; | ||
} | ||
|
||
return $ip; | ||
|
||
} | ||
|
||
public function isValid( $ip = null ) | ||
{ | ||
if( ! isset( $ip ) ) | ||
{ | ||
return false; | ||
} | ||
|
||
foreach ($this->validators as $validator) | ||
{ | ||
if( ! $validator->validate( $ip ) ) return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php namespace Weboap\Visitor\Services\Cache; | ||
|
||
|
||
|
||
use Illuminate\Cache\CacheManager as Cache; | ||
|
||
|
||
class CacheClass implements CacheInterface { | ||
|
||
protected $cache; | ||
|
||
public function __construct(Cache $cache) | ||
{ | ||
$this->cache = $cache; | ||
|
||
} | ||
|
||
|
||
|
||
|
||
public function destroy( $key ) | ||
{ | ||
$this->cache->forget( $key ); | ||
} | ||
|
||
|
||
public function rememberForever( $key, $data ) | ||
{ | ||
|
||
return $this->cache->rememberForever( $key, function() use ( $data ) | ||
{ | ||
return $data; | ||
}); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php namespace Weboap\Visitor\Services\Cache; | ||
|
||
|
||
|
||
interface CacheInterface { | ||
|
||
public function destroy( $key ); | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php namespace Weboap\Visitor\Services\Geo; | ||
|
||
|
||
|
||
interface GeoInterface { | ||
|
||
public function locate(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php namespace Weboap\Visitor\Services\Geo; | ||
|
||
use GeoIp2\Database\Reader; | ||
use GeoIp2\Exception\AddressNotFoundException; | ||
use Illuminate\Config\Repository as Config; | ||
use Illuminate\Http\Request as Request; | ||
use Weboap\Visitor\Ip; | ||
|
||
|
||
class MaxMind implements GeoInterface{ | ||
|
||
|
||
protected $reader; | ||
|
||
protected $config; | ||
|
||
protected $ip; | ||
|
||
public function __construct( Config $config, Ip $ip ) | ||
{ | ||
$this->config = $config; | ||
$this->ip = $ip; | ||
} | ||
|
||
|
||
|
||
public function locate() | ||
{ | ||
// | ||
$ip = $this->ip->get(); | ||
$db = $this->config->get('visitor.maxmind_db_path'); | ||
|
||
if( !is_string($db) || ! file_exists( $db )|| ! $this->ip->isValid( $ip ) ) return []; | ||
|
||
|
||
$this->reader = new Reader( $db ); | ||
|
||
try{ | ||
|
||
$record = $this->reader->city( $ip ); | ||
|
||
return [ | ||
'country_code' => $record->country->isoCode, | ||
'country_name' => $record->country->name, | ||
'state_code' => $record->mostSpecificSubdivision->isoCode, | ||
'state' => $record->mostSpecificSubdivision->name, | ||
'city' => $record->city->name, | ||
'postale_code' => $record->postal->code | ||
|
||
]; | ||
|
||
} | ||
catch (AddressNotFoundException $e) { | ||
|
||
return []; | ||
}; | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
|
Oops, something went wrong.