예제 #1
0
파일: distributed.php 프로젝트: uinerd/Code
 function __construct()
 {
     $sa = LG_STANDALONE ? ' (standalone)' : '';
     $ip = $_SERVER['REMOTE_ADDR'];
     lgDebug("Request started for {$ip}{$sa}: " . join(',', array_keys($_REQUEST)));
     // Make singleton available if we need it
     self::$instance = $this;
     // Check that the local distributed database table exists and has a matching structure
     $this->checkTable();
     // Delete any objects that have reached their expiry time
     $this->expire();
     // Instantiate the main global objects
     LigminchaGlobalServer::getMaster();
     $server = LigminchaGlobalServer::getCurrent();
     LigminchaGlobalUser::checkAll();
     LigminchaGlobalSSO::makeSessionFromCookie();
     // If this is a changes request,
     if (array_key_exists(self::$cmd, $_REQUEST)) {
         // Commit the data (and re-route if master)
         $data = $_REQUEST[self::$cmd];
         if ($data) {
             print self::recvQueue($data);
         } elseif ($server->isMaster) {
             print self::encodeData($this->initialTableData());
         }
         // If we're the master, always send queue incase any re-routing
         if ($server->isMaster) {
             self::sendQueue();
         }
         exit;
     } elseif ($server->isMaster && array_key_exists('fakeinfo', $_REQUEST)) {
         $actions = array('edited', 'created', 'booked', 'posted');
         $titles = array('Alguma Coisa', 'Outra Coisa', 'Muitas Coisas', 'Mais ou Menos');
         $users = LigminchaGlobalUser::select();
         $user = $users[rand(0, count($users) - 1)]->data['realname'];
         $action = $actions[rand(0, count($actions) - 1)];
         $title = $titles[rand(0, count($titles) - 1)];
         new LigminchaGlobalLog("{$user} {$action} {$title}", 'Info', time() + 1000);
         self::sendToWebSocket(array(0, $server->id, 0, LigminchaGlobalSync::select()[0]), 0);
         self::sendQueue();
         exit;
     }
 }
예제 #2
0
파일: index.php 프로젝트: uinerd/Code
<?php

// Load the code common to standalone functionality
include __DIR__ . '/standalone.php';
// These are the global objects made initially available to the app (only server objects are available if not logged in)
$types = array(LG_SERVER, LG_LOG);
if ($session) {
    $types[] = LG_USER;
    $types[] = LG_SESSION;
}
$objects = LigminchaGlobalObject::select(array('type' => $types));
$wgOut->addJsConfigVars('GlobalObjects', $objects);
$wgOut->addJsConfigVars('toolbar', false);
// Make the ID of the master server known to the client-side
$wgOut->addJsConfigVars('masterServer', LigminchaGlobalServer::getMaster()->id);
// Get the list of tags from the Github repo
$config = JFactory::getConfig();
$auth = $config->get('lgRepoAuth');
$repoTags = array();
//json_decode( LigminchaGlobalDistributed::get( 'https://api.github.com/repos/Ligmincha/Code/tags', $auth ) );
$tags = array();
foreach ($repoTags as $tag) {
    if (preg_match('/^v([0-9.]+)/', $tag->name)) {
        $tags[$tag->name] = $tag->tarball_url;
    }
}
$wgOut->addJsConfigVars('tags', $tags);
?>
<!DOCTYPE html>
<html lang="en">
	<head>
예제 #3
0
파일: sync.php 프로젝트: uinerd/Code
 /**
  * Create outgoing sync objects(s) from local changes or for re-routing
  * 
  * Make one or more sync objects depending on the context of this change
  * - The sync re-routing logic is in here
  * - $origin is the server the change came from if set
  * - $private is the owner's server if set
  */
 public static function create($crud, $fields, $origin, $private = false)
 {
     $server = LigminchaGlobalServer::getCurrent();
     // Origin is set if this change is the result of a received foreign sync object
     if ($origin) {
         // This is the only condition for which re-routing ever occurs
         if ($server->isMaster && $private === false) {
             // Create targetted sync objects for all except self and origin
             foreach (LigminchaGlobalServer::select() as $s) {
                 if ($s->id != $server->id && $s->id != $origin) {
                     new LigminchaGlobalSync($crud, $fields, $s);
                 }
             }
         }
     } else {
         // If this is the master, then targets depend whether its private or not
         if ($server->isMaster) {
             // If private then we just have a single targetted sync object to the owner
             if ($private) {
                 new LigminchaGlobalSync($crud, $fields, $private);
             } else {
                 foreach (LigminchaGlobalServer::select() as $s) {
                     if ($s->id != $server->id) {
                         new LigminchaGlobalSync($crud, $fields, $s);
                     }
                 }
             }
         } else {
             new LigminchaGlobalSync($crud, $fields, LigminchaGlobalServer::getMaster());
         }
     }
 }