예제 #1
0
 static function init(\Db\Connection $db)
 {
     // set up the event handlers
     /**
      * Set up metrics-capturing events.
      */
     if (Config::get('metrics_enabled', true)) {
         self::$instance = new MetricsHandler($db);
         if (Config::get('metrics_db_enabled', true)) {
             Events::on('db_prepare_start', array(self::$instance, 'db_prepare_start'));
             Events::on('db_prepare_end', array(self::$instance, 'db_prepare_end'));
             Events::on('db_prepare_master', array(self::$instance, 'db_prepare_master'));
             Events::on('db_prepare_slave', array(self::$instance, 'db_prepare_slave'));
             Events::on('db_execute_start', array(self::$instance, 'db_execute_start'));
             Events::on('db_execute_end', array(self::$instance, 'db_execute_end'));
             Events::on('db_fetch_start', array(self::$instance, 'db_fetch_start'));
             Events::on('db_fetch_end', array(self::$instance, 'db_fetch_end'));
             Events::on('db_fetch_all_start', array(self::$instance, 'db_fetch_all_start'));
             Events::on('db_fetch_all_end', array(self::$instance, 'db_fetch_all_end'));
         }
         if (Config::get('metrics_page_enabled', true)) {
             Events::on('page_start', array(self::$instance, 'page_start'));
             Events::on('page_end', array(self::$instance, 'page_end'));
         }
         if (Config::get('metrics_templates_enabled', true)) {
             Events::on('pages_template_start', array(self::$instance, 'template_start'));
             Events::on('pages_template_end', array(self::$instance, 'template_end'));
         }
         if (Config::get('metrics_curl_enabled', true)) {
             Events::on('curl_start', array(self::$instance, 'curl_start'));
             Events::on('curl_end', array(self::$instance, 'curl_end'));
         }
     }
 }
예제 #2
0
 /**
  * We can bind and then unbind.
  */
 function testBindThenUnbind()
 {
     $bind = Events::on('test_simple', array($this, 'onTestSimple'));
     try {
         Events::trigger('test_simple', "cat");
         $this->assertEquals(array("cat"), $this->last_simple_data);
     } finally {
         Events::unbind($bind);
     }
     Events::trigger('test_simple', "dog");
     $this->assertEquals(array("cat"), $this->last_simple_data);
     // hasn't changed
 }
예제 #3
0
    }
    foreach (get_blockchain_currencies() as $explorer => $currencies) {
        foreach ($currencies as $cur) {
            if ($cur == $currency) {
                return "<span class=\"address " . $currency . "_address\"><code>" . htmlspecialchars($address) . "</code>\n          <a class=\"inspect\" href=\"" . htmlspecialchars(sprintf(get_site_config($currency . "_address_url"), $address)) . "\" title=\"Inspect with " . htmlspecialchars($explorer) . "\">?</a>\n        </span>";
            }
        }
    }
    return htmlspecialchars($address);
}
/**
 * Set up page load events
 */
\Openclerk\Events::on('pages_header_start', function ($data) {
    define('PAGE_RENDER_START', microtime(true));
});
/**
 * Set up page load events
 */
\Openclerk\Events::on('pages_footer_end', function ($data) {
    if (defined('PAGE_RENDER_START')) {
        $end_time = microtime(true);
        $time_diff = ($end_time - PAGE_RENDER_START) * 1000;
        echo "<!-- rendered in " . number_format($time_diff, 2) . " ms -->";
    }
    performance_metrics_page_end();
    echo "\n<!--\n" . print_r(Openclerk\MetricsHandler::getInstance()->printResults(), true) . "\n-->";
    if (is_admin()) {
        echo "\n<!-- " . print_r($_SESSION, true) . "\n-->";
    }
});
예제 #4
0
        // only supports GET relogins; TODO support POST relogins
        redirect(url_for('login', array('need_admin' => 1, 'destination' => $_SERVER['REQUEST_URI'])));
    }
}
function has_required_admin()
{
    global $has_required_admin;
    return $has_required_admin;
}
class SecurityException extends Exception
{
}
function require_user($user)
{
    global $errors;
    if (!$user) {
        if (!$errors) {
            $errors = array();
        }
        $errors[] = t("Could not find your profile on the system. You will need to login or signup again.");
        set_temporary_errors($errors);
        redirect(url_for('login'));
    }
}
// set up heavy request checks
\Openclerk\Events::on('openid_validate', function ($lightopenid) {
    check_heavy_request();
});
\Openclerk\Events::on('oauth2_auth', function ($oauth2) {
    check_heavy_request();
});
예제 #5
0
    {
        return $this->title;
    }
    function load()
    {
        require __DIR__ . "/../locale/" . $this->key . ".php";
        return $result;
    }
}
$locales = array('de' => 'German', 'fr' => 'French', 'jp' => 'Japanese', 'ru' => 'Russian', 'zh' => 'Chinese');
foreach ($locales as $locale => $title) {
    I18n::addAvailableLocale(new GenericLocale($locale, $title));
}
I18n::addDefaultKeys(array(':site_name' => get_site_config('site_name')));
// set locale as necessary
if (isset($_COOKIE["locale"]) && in_array($_COOKIE["locale"], array_keys(I18n::getAvailableLocales()))) {
    I18n::setLocale($_COOKIE["locale"]);
}
\Openclerk\Events::on('i18n_missing_string', function ($data) {
    $locale = $data['locale'];
    $key = $data['key'];
    log_uncaught_exception(new LocaleException("Locale '{$locale}': Missing key '{$key}'"));
});
/**
 * Helper function to mark strings that need to be translated on the client-side.
 */
function ct($s)
{
    // do not do any translation here - we have to do it on the client side!
    return $s;
}
예제 #6
0
 /**
  * However we can capture missing strings using the event framework.
  */
 function testEventIsThrown()
 {
     global $_test_event_is_thrown;
     $_test_event_is_thrown = false;
     $handler = \Openclerk\Events::on('i18n_missing_string', function ($string) {
         global $_test_event_is_thrown;
         $_test_event_is_thrown = $string;
     });
     t("a missing string");
     $this->assertEquals(array("locale" => "fr", "key" => "a missing string"), $_test_event_is_thrown);
     // and be a good events citizen
     \Openclerk\Events::unbind($handler);
 }