Esempio n. 1
0
 public static function getDefaultFrom()
 {
     if (empty(static::$defaultFrom)) {
         static::$defaultFrom = 'hello@' . Site::getConfig('primary_hostname');
     }
     return static::$defaultFrom;
 }
 public function getName()
 {
     if ($parentHostname = \Site::getConfig('parent_hostname')) {
         return static::$handle . ' (' . $parentHostname . ')';
     } else {
         return false;
     }
 }
Esempio n. 3
0
 /**
  * Constructs a Page that will render a given component class
  */
 public static function createComponentPage($class)
 {
     $config = Site::getConfig();
     $component = self::getInstance($class);
     $page = new HTMLPage(Site::Site());
     $page->component = $component;
     return $page;
 }
Esempio n. 4
0
 static function __classLoaded()
 {
     if (empty(static::$siteName)) {
         static::$siteName = Site::getConfig('label');
     }
     if (empty(static::$siteAbbr)) {
         static::$siteAbbr = preg_replace('/[^A-Z]/', '', static::$siteName);
     }
 }
Esempio n. 5
0
 public function testPoweredByHeader()
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, sprintf('http://%s/api/test-api-status/v1', \Site::getConfig('primary_hostname')));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_HEADER, 1);
     $response = curl_exec($ch);
     $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
     $header = substr($response, 0, $header_size);
     $this->assertRegExp('/^X-Powered-By:\\s*' . preg_quote(ApiRequestHandler::$poweredByHeader) . '\\s*$/m', $header);
 }
Esempio n. 6
0
 public static function __classLoaded()
 {
     parent::__classLoaded();
     // generate cookie name
     if (!static::$cookieName) {
         static::$cookieName = 's_' . Site::getConfig('handle');
     }
     // auto-detect cookie domain by trimming leading www. from current hostname
     if (!static::$cookieDomain) {
         static::$cookieDomain = preg_replace('/^www\\.([^.]+\\.[^.]+)$/i', '$1', $_SERVER['HTTP_HOST']);
     }
 }
 public static function handleRequest()
 {
     if (extension_loaded('newrelic')) {
         newrelic_disable_autorum();
     }
     // retrieve authentication attempt
     if ($GLOBALS['Session']->hasAccountLevel('Developer')) {
         $User = $GLOBALS['Session']->Person;
     } else {
         $authEngine = new \Sabre\HTTP\BasicAuth();
         $authEngine->setRealm('Develop ' . \Site::$title);
         $authUserPass = $authEngine->getUserPass();
         // try to get user
         $userClass = \User::$defaultClass;
         $User = $userClass::getByLogin($authUserPass[0], $authUserPass[1]);
         // send auth request if login is inadiquate
         if (!$User || !$User->hasAccountLevel('Developer')) {
             $authEngine->requireLogin();
             die("You must login using a " . \Site::getConfig('primary_hostname') . " account with Developer access\n");
         }
     }
     // store login to session
     if (isset($GLOBALS['Session'])) {
         $GLOBALS['Session'] = $GLOBALS['Session']->changeClass('UserSession', array('PersonID' => $User->ID));
     }
     // detect base path
     $basePath = array_slice(\Site::$requestPath, 0, count(\Site::$resolvedPath));
     // switch to JSON response mode
     if (static::peekPath() == 'json') {
         $basePath[] = static::$responseMode = static::shiftPath();
     }
     // handle /develop request
     if ($_SERVER['REQUEST_METHOD'] == 'GET' && static::getResponseMode() == 'html' && !static::peekPath()) {
         \RequestHandler::respond('app/ext', array('App' => \Sencha_App::getByName('EmergenceEditor'), 'mode' => 'production', 'title' => 'EmergenceEditor'));
     }
     // initial and configure SabreDAV
     $server = new \Sabre\DAV\Server(new RootCollection());
     $server->setBaseUri('/' . join('/', $basePath));
     // The lock manager is reponsible for making sure users don't overwrite each others changes. Change 'data' to a different
     // directory, if you're storing your data somewhere else.
     #       $lockBackend = new Sabre_DAV_Locks_Backend_FS('/tmp/dav-lock');
     #       $lockPlugin = new Sabre_DAV_Locks_Plugin($lockBackend);
     #       $server->addPlugin($lockPlugin);
     // filter temporary files
     $server->addPlugin(new \Sabre\DAV\TemporaryFileFilterPlugin('/tmp/dav-tmp'));
     // ?mount support
     $server->addPlugin(new \Sabre\DAV\Mount\Plugin());
     // emergence :)
     $server->addPlugin(new \Emergence\DAV\ServerPlugin());
     // All we need to do now, is to fire up the server
     $server->exec();
 }
Esempio n. 8
0
function Dwoo_Plugin_versioned_url(Dwoo_Core $dwoo, $path, $source = 'site-root', $includeHost = false)
{
    $trimmedPath = ltrim($path, '/');
    if ($source == 'site-root') {
        $url = Site::getVersionedRootUrl($trimmedPath);
        if ($includeHost) {
            $url = (Site::getConfig('ssl') ? 'https' : 'http') . '://' . Site::getConfig('primary_hostname') . $url;
        }
        return $url;
    } else {
        return $path;
    }
}
<?php

use Emergence\Database\PostgresConnection;
if (!PostgresConnection::hasDefaultInstance() && ($postgresConfig = Site::getConfig('postgres'))) {
    PostgresConnection::setDefaultInstance($postgresConfig);
}
<?php

use Emergence\Database\MysqlConnection;
if (!MysqlConnection::hasDefaultInstance() && ($mysqlConfig = Site::getConfig('mysql'))) {
    MysqlConnection::setDefaultInstance($mysqlConfig);
}
 public static function resolveCollectionFromParent($path)
 {
     if (!Site::getConfig('parent_hostname')) {
         return false;
     }
     $fp = fopen('php://memory', 'w+');
     $ch = curl_init(static::buildUrl($path));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, $fp);
     $responseText = curl_exec($ch);
     $responseStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $responseType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
     if ($responseText === false || curl_errno($ch)) {
         throw new Exception('Failed to query parent site for collection: ' . curl_error($ch));
     }
     if ($responseStatus != 300 || $responseType != 'application/vnd.emergence.tree+json') {
         return false;
     }
     return json_decode($responseText, true);
 }
Esempio n. 12
0
 public static function getMysqli()
 {
     if (!isset(self::$_mysqli)) {
         $config = array_merge(array('host' => 'localhost', 'port' => 3306), Site::getConfig('mysql'));
         // connect to mysql database
         self::$_mysqli = @new mysqli($config['host'], $config['username'], $config['password'], $config['database'], $config['port'], $config['socket']);
         self::$_mysqli->set_charset('utf8');
         // check for failure or connection error
         if (mysqli_connect_error()) {
             self::handleError('connect');
         }
         // set timezone to match PHP
         self::nonQuery('SET time_zone = "%s"', self::escape(date('P')));
     }
     return self::$_mysqli;
 }
Esempio n. 13
0
 public static function getDefaultFrom()
 {
     return Mailer::$defaultFrom ? Mailer::$defaultFrom : \Site::getConfig('label') . ' <support@' . \Site::getConfig('primary_hostname') . '>';
 }
Esempio n. 14
0
 public static function getKeyPrefix()
 {
     return Site::getConfig('handle') . ':';
 }
Esempio n. 15
0
<?php

$GLOBALS['Session']->requireAccountLevel('Developer');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $templateDir = Emergence\Dwoo\Engine::$pathCompile . '/' . Site::getConfig('handle');
    exec("find {$templateDir} -name \"*.d*.php\" -type f -delete");
    die('Templates cleared');
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Clear Templates Cache</title>
    <style>
        * {
            font-size: xx-large;
            text-align: center;
        }

        input {
            cursor: pointer;
            margin: 1em;
        }
    </style>
</head>
<body>
<form method="POST">
	<input type="submit" value="Clear Templates Cache">
</form>
</body>
Esempio n. 16
0
<?php

Git::$repositories['Gatekeeper'] = ['remote' => 'git@github.com:JarvusInnovations/Gatekeeper.git', 'originBranch' => 'master', 'workingBranch' => 'instances/' . Site::getConfig('primary_hostname'), 'localOnly' => true, 'trees' => ['dwoo-plugins', 'event-handlers', 'html-templates', 'php-classes', 'php-config' => ['exclude' => '#^/Git\\.config\\.php$#'], 'php-migrations', 'phpunit-tests', 'sencha-workspace/pages', 'site-root' => ['exclude' => ['#^/css(/|$)#', '#^/js/pages(/|$)#']]]];
Git::$repositories['symfony-yaml'] = ['remote' => 'https://github.com/symfony/Yaml.git', 'originBranch' => 'master', 'workingBranch' => 'master', 'trees' => ['php-classes/Symfony/Component/Yaml' => ['path' => '.', 'exclude' => ['#\\.gitignore$#', '#^/Tests#', '#\\.md$#', '#composer\\.json#', '#phpunit\\.xml\\.dist#']]]];
Git::$repositories['jarvus-highlighter'] = ['remote' => "https://github.com/JarvusInnovations/jarvus-highlighter.git", 'originBranch' => 'master', 'workingBranch' => 'master', 'trees' => ["sencha-workspace/packages/jarvus-highlighter" => '.']];
Esempio n. 17
0
<?php

$GLOBALS['Session']->requireAccountLevel('Developer');
$config = Site::getConfig();
Debug::dump($config, false, 'current config');
// set a degredation
if (is_array($_REQUEST['degredations'])) {
    if (!is_array($config['degredations'])) {
        $config['degredations'] = array();
    }
    foreach ($_REQUEST['degredations'] as $degredation => $value) {
        $config['degredations'][$degredation] = $value == 'on';
    }
    Debug::dump($config['degredations'], false, 'updated degredations map');
    // save to config cache for all hostnames
    $hostnames = $config['hostnames'];
    array_unshift($hostnames, $config['primary_hostname']);
    foreach ($hostnames as $hostname) {
        apc_store($hostname, $config);
    }
    Debug::dump($hostnames, false, 'saved new degredations to hostnames');
    Debug::dump($config, false, 'final config');
}
Esempio n. 18
0
<?php

use Gatekeeper\Metrics\Metrics;
use Gatekeeper\Metrics\MetricSample;
$cronKey = Site::getConfig('cron_key');
if (!$cronKey) {
    header('HTTP/1.0 501 Not Implemented');
    die('Host does not have a cron_key configured');
}
if (empty($_GET['cron_key'])) {
    header('HTTP/1.0 401 Unauthorized');
    die('cron_key required');
}
if ($_GET['cron_key'] != $cronKey) {
    header('HTTP/1.0 401 Unauthorized');
    die('cron_key is incorrect');
}
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
    header('HTTP/1.0 405 Method Not Allowed');
    die('POST method required');
}
$cacheKeyPrefix = Cache::getKeyPrefix();
$currentSampleIndex = Metrics::getCurrentSampleIndex();
$flushed = 0;
foreach (Cache::getIterator('|^metrics/|') as $cacheEntry) {
    if (!preg_match('|^' . preg_quote($cacheKeyPrefix) . '(metrics/(.*)/(\\d+))$|', $cacheEntry['key'], $matches)) {
        continue;
    }
    $cacheKey = $matches[1];
    $metricKey = $matches[2];
    $sampleIndex = (int) $matches[3];
Esempio n. 19
0
<?php

global $dbs;
try {
    $conf = Site::getConfig('host', 'host');
    $dbs = new PDO("mysql:host={$conf['db_host']};dbname={$conf['db_mysql_db']}", $conf['db_mysql_user'], $conf['db_mysql_pwd']);
} catch (Exception $e) {
    throw new Exception("Unable to connect to local store database", 0, $e);
}
Esempio n. 20
0
    _extractStrings($patternPHPValidators, $contents, $path, $strings);
}
// write pot file
foreach ($strings as $string => $sources) {
    fwrite($pot, '#: ' . implode(' ', $sources) . PHP_EOL);
    // switch output format if embedded newlines found (see https://www.gnu.org/software/gettext/manual/html_node/Normalizing.html)
    if (preg_match('/[^\\n]\\n+[^\\n]/', $string)) {
        // multiline output format
        fwrite($pot, 'msgid ""' . PHP_EOL);
        fwrite($pot, str_replace('\\n', '\\n"' . PHP_EOL . '"', _encodeString($string)) . PHP_EOL);
    } else {
        fwrite($pot, 'msgid ' . _encodeString($string) . PHP_EOL);
    }
    fwrite($pot, 'msgstr ""' . PHP_EOL . PHP_EOL);
}
rewind($pot);
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="' . Site::getConfig('handle') . '.pot"');
fpassthru($pot);
// utility methods
function _extractStrings($pattern, $contents, $fileVirtualPath, &$strings)
{
    preg_match_all($pattern, $contents, $matches, PREG_OFFSET_CAPTURE);
    foreach ($matches[3] as list($string, $offset)) {
        $strings[stripslashes($string)][] = $fileVirtualPath . ':' . (substr_count(substr($contents, 0, $offset), "\n") + 1);
    }
}
function _encodeString($string)
{
    return '"' . str_replace(PHP_EOL, '\\n', addcslashes($string, '"\\')) . '"';
}