19 changed files with 185 additions and 238 deletions
-
102app/Cache.php
-
23app/User.php
-
2app/views/page.tpl
-
6app/widgets/Blog/Blog.php
-
2app/widgets/Chat/Chat.php
-
14app/widgets/Chats/Chats.php
-
3app/widgets/CommunityPosts/CommunityPosts.php
-
9app/widgets/Config/Config.php
-
6app/widgets/Menu/Menu.php
-
4app/widgets/Notifs/Notifs.php
-
4app/widgets/Post/Post.php
-
2app/widgets/PublishBrief/PublishBrief.php
-
1app/widgets/Roster/Roster.php
-
33database/migrations/20180317185328_create_privacy_table.php
-
28database/migrations/20180318222026_create_caches_table.php
-
5src/Movim/Bootstrap.php
-
109src/Movim/Cache.php
-
3src/Movim/Template/Builder.php
-
67src/Movim/User.php
@ -0,0 +1,102 @@ |
|||
<?php |
|||
|
|||
namespace App; |
|||
|
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
class Cache extends Model |
|||
{ |
|||
private static $_instance; |
|||
protected $primaryKey = 'name'; |
|||
|
|||
public static function instanciate() |
|||
{ |
|||
if (!is_object(self::$_instance)) { |
|||
self::$_instance = new Cache; |
|||
} |
|||
|
|||
return self::$_instance; |
|||
} |
|||
|
|||
/** |
|||
* Helper function to access cache. |
|||
*/ |
|||
public static function c() |
|||
{ |
|||
$cache = self::instanciate(); |
|||
|
|||
return call_user_func_array([$cache, 'handle'], func_get_args()); |
|||
} |
|||
|
|||
/** |
|||
* Fetches or commits an object to cache with the provided key. |
|||
* |
|||
* Prototype: handle(string $key, ...) |
|||
* |
|||
* The following fetches an object from cache. |
|||
* handle('key') |
|||
* |
|||
* This commits an object to cache. |
|||
* handle('key', $object); |
|||
* |
|||
* Several objects can be commited to cache in this manner: |
|||
* handle('key', $object1, $object2, $object3); |
|||
* And retrieved as follows: |
|||
* list($object1, $object2, $object3) = handle('key'); |
|||
*/ |
|||
public function handle($key) |
|||
{ |
|||
$arglist = func_get_args(); |
|||
$key = $arglist[0]; |
|||
|
|||
if (func_num_args() == 1) { |
|||
$content = $this->_readCache($key); |
|||
|
|||
if (isset($content) && $content != '') { |
|||
return $content; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
if (func_num_args() == 2) { |
|||
return $this->_writeCache($key, $arglist[1]); |
|||
} |
|||
// Cutting a piece of the args.
|
|||
$content = array_slice($arglist, 1); |
|||
return $this->_writeCache($key, $content); |
|||
} |
|||
|
|||
/** |
|||
* Serializes data in a proper fashion. |
|||
*/ |
|||
private function _writeCache($key, $object) |
|||
{ |
|||
$data = str_replace( |
|||
"'", "\\'", |
|||
base64_encode(gzcompress(serialize($object))) |
|||
); |
|||
|
|||
$cache = Cache::firstOrNew(['user_id' => User::me()->id, 'name' => $key]); |
|||
$cache->data = $data; |
|||
$cache->save(); |
|||
} |
|||
|
|||
/** |
|||
* Unserializes data. |
|||
*/ |
|||
private function _readCache($key) |
|||
{ |
|||
$cache = $this->where('user_id', User::me()->id) |
|||
->where('name', $key) |
|||
->first(); |
|||
|
|||
if (isset($cache)) { |
|||
return unserialize( |
|||
gzuncompress(base64_decode(str_replace("\\'", "'", $cache->data))) |
|||
); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
} |
|||
@ -1,33 +0,0 @@ |
|||
<?php |
|||
|
|||
|
|||
use Phinx\Migration\AbstractMigration; |
|||
|
|||
class CreatePrivacyTable extends AbstractMigration |
|||
{ |
|||
/** |
|||
* Change Method. |
|||
* |
|||
* Write your reversible migrations using this method. |
|||
* |
|||
* More information on writing migrations is available here: |
|||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
|||
* |
|||
* The following commands can be used in this method and Phinx will |
|||
* automatically reverse them when rolling back: |
|||
* |
|||
* createTable |
|||
* renameTable |
|||
* addColumn |
|||
* renameColumn |
|||
* addIndex |
|||
* addForeignKey |
|||
* |
|||
* Remember to call "create()" or "update()" and NOT "save()" when working |
|||
* with the Table class. |
|||
*/ |
|||
public function change() |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<?php |
|||
|
|||
use Movim\Migration; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
|
|||
class CreateCachesTable extends Migration |
|||
{ |
|||
public function up() |
|||
{ |
|||
$this->schema->create('caches', function(Blueprint $table) { |
|||
$table->string('user_id', 64); |
|||
$table->string('name', 32); |
|||
$table->text('data'); |
|||
$table->timestamps(); |
|||
|
|||
$table->primary(['user_id', 'name']); |
|||
$table->foreign('user_id') |
|||
->references('id')->on('users') |
|||
->onDelete('cascade'); |
|||
}); |
|||
} |
|||
|
|||
public function down() |
|||
{ |
|||
$this->schema->drop('caches'); |
|||
} |
|||
} |
|||
|
|||
@ -1,109 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace Movim; |
|||
|
|||
/** |
|||
* A fully-static class that deals with caching. |
|||
*/ |
|||
class Cache |
|||
{ |
|||
private static $_instance; |
|||
|
|||
public static function create() |
|||
{ |
|||
if (!is_object(self::$_instance)) { |
|||
self::$_instance = new Cache; |
|||
} |
|||
|
|||
return self::$_instance; |
|||
} |
|||
|
|||
/** |
|||
* Helper function to access cache. |
|||
*/ |
|||
public static function c() |
|||
{ |
|||
$cache = self::create(); |
|||
|
|||
return call_user_func_array([$cache, 'handle'], func_get_args()); |
|||
} |
|||
|
|||
/** |
|||
* Fetches or commits an object to cache with the provided key. |
|||
* |
|||
* Prototype: handle(string $key, ...) |
|||
* |
|||
* The following fetches an object from cache. |
|||
* handle('key') |
|||
* |
|||
* This commits an object to cache. |
|||
* handle('key', $object); |
|||
* |
|||
* Several objects can be commited to cache in this manner: |
|||
* handle('key', $object1, $object2, $object3); |
|||
* And retrieved as follows: |
|||
* list($object1, $object2, $object3) = handle('key'); |
|||
*/ |
|||
public function handle($key) |
|||
{ |
|||
$arglist = func_get_args(); |
|||
$key = $arglist[0]; |
|||
|
|||
if (func_num_args() == 1) { |
|||
$content = $this->_readCache($key); |
|||
|
|||
if (isset($content) && $content != "") { |
|||
return $content; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
if (func_num_args() == 2) { |
|||
return $this->_writeCache($key, $arglist[1]); |
|||
} |
|||
// Cutting a piece of the args.
|
|||
$content = array_slice($arglist, 1); |
|||
return $this->_writeCache($key, $content); |
|||
} |
|||
|
|||
/** |
|||
* Serializes data in a proper fashion. |
|||
*/ |
|||
private function _writeCache($key, $object) |
|||
{ |
|||
$data = str_replace( |
|||
"'", "\\'", |
|||
base64_encode(gzcompress(serialize($object))) |
|||
); |
|||
$time = date(\Modl\SQL::SQL_DATE); |
|||
|
|||
$cd = new \Modl\CacheDAO; |
|||
$c = new \Modl\Cache; |
|||
|
|||
$c->data = $data; |
|||
$c->name = $key; |
|||
$c->timestamp = $time; |
|||
|
|||
$cd->set($c); |
|||
} |
|||
|
|||
/** |
|||
* Unserializes data. |
|||
*/ |
|||
private function _readCache($key) |
|||
{ |
|||
$cd = new \Modl\CacheDAO; |
|||
$var = $cd->get($key); |
|||
|
|||
if (isset($var)) { |
|||
return unserialize( |
|||
gzuncompress(base64_decode(str_replace("\\'", "'", $var->data))) |
|||
); |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
|
|||
?>
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue