http://groups.google.com/group/php-standards/web/psr-0-final-proposal?pli=1
Example which loads classes for the Doctrine Common package in the
Doctrine\Common namespace.
$classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine');
$classLoader->register();
* 14 of the GNU General Public License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * @package phpBB * @author Nils Adermann <*****@*****.**> * @copyright 2010 phpBB Ltd. * @license http://www.gnu.org/licenses/gpl.txt * GNU General Public License * @version Release: @package_version@ */ // set up include path set_include_path(__DIR__ . '/lib/' . PATH_SEPARATOR . get_include_path() . PATH_SEPARATOR); if (!defined('PHP_EXT')) { define('PHP_EXT', strrchr(__FILE__, '.')); } require 'SplClassLoader' . PHP_EXT; // phpBB's autoloader $phpBBClassLoader = new SplClassLoader('phpBB'); $phpBBClassLoader->setFileExtension(PHP_EXT); $phpBBClassLoader->register(); // symfony autoloader $symfonyClassLoader = new SplClassLoader('Symfony', 'symfony/src/'); $symfonyClassLoader->setFileExtension(PHP_EXT); $symfonyClassLoader->register();
public function UpdateStatus() { $contract = DataObject::get_one('Contract', 'ID = ' . $_GET['id'] . " and EchosignID = '" . $_GET['documentKey'] . "'"); $contract->Status = $_GET['status']; $contract->write(); mail('*****@*****.**', 'Contract Update' . $contract->EchosignID, json_encode($_GET)); die; $ESLoader = new SplClassLoader('EchoSign', realpath(__DIR__ . '/../../')); $ESLoader->register(); $client = new SoapClient(EchoSign\API::getWSDL()); $api = new EchoSign\API($client, 'PGRUY64K6T664Z'); $data = $api->getDocumentInfo($contract->EchosignID); mail('*****@*****.**', 'Contract Update' . $contract->EchosignID, json_encode($data)); }
public function __construct() { ini_set('display_errors', 1); error_reporting(E_ALL); require __DIR__ . '/lib/SplClassLoader.php'; $classLoader = new SplClassLoader('WebSocket', __DIR__ . '/lib'); $classLoader->register(); $this->server = new \WebSocket\Server('127.0.0.1', 7000, false); // host,port,ssl // server settings: $this->server->setCheckOrigin(true); $this->server->setAllowedOrigin('foo.lh'); $this->server->setMaxClients(100); $this->server->setMaxConnectionsPerIp(20); $this->server->setMaxRequestsPerMinute(1000); $this->server->registerApplication('demo', \WebSocket\Application\DemoApplication::getInstance()); $this->server->run(); }
<?php require_once 'Lib/Autoloader.php'; $autoloader = new SplClassLoader('FrontController'); $autoloader->register(); $request = \FrontController\HttpRequest::createFromGlobals(); $testRoute = new \FrontController\HttpRoute('/', 'IndexController', 'index'); $testRoute2 = new \FrontController\HttpRoute('/foo', 'IndexController', 'foo'); $router = new \FrontController\HttpRouter(array($testRoute, $testRoute2)); $dispatcher = new \FrontController\HttpDispatcher(); $front = new FrontController\Front($router, $dispatcher); $front->run($request, new \FrontController\HttpResponse());
* * sysMonDash is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * sysMonDash is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with sysMonDash. If not, see <http://www.gnu.org/licenses/>. * */ defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo')); define('XML_CONFIG_FILE', DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'sysMonDash' . DIRECTORY_SEPARATOR . 'config.xml'); define('CONSTANTS_FILE', __DIR__ . DIRECTORY_SEPARATOR . 'constants.php'); define('MODEL_PATH', __DIR__ . DIRECTORY_SEPARATOR . 'SMD'); define('LOCALES_PATH', __DIR__ . DIRECTORY_SEPARATOR . 'locales'); define('CSS_PATH', __DIR__ . DIRECTORY_SEPARATOR . APP_ROOT . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'styles.css'); define('TPL_PATH', __DIR__ . DIRECTORY_SEPARATOR . 'tpl'); define('DEBUG', false); // Empezar a calcular el tiempo y memoria utilizados $time_start = microtime(true); $memInit = memory_get_usage(); require CONSTANTS_FILE; require 'SplClassLoader.php'; $ClassLoader = new SplClassLoader(); $ClassLoader->setFileExtension('.class.php'); $ClassLoader->register();
<?php set_include_path(__DIR__ . PATH_SEPARATOR . __DIR__ . DIRECTORY_SEPARATOR . 'lib' . PATH_SEPARATOR . get_include_path()); include 'SplClassLoaderUser.php'; $v1 = new SplClassLoaderUser('vendor0'); $v1->register(); $v2 = new SplClassLoaderUser('vendor1'); $v2->register(); $v3 = new SplClassLoaderUser('vendor2'); $v3->register(); //$v4 = new SplClassLoaderUser('vendor3'); //$v4->register(); $g = new SplClassLoader(); $g->register(); include 'batch_instances.php'; echo 'done';
/** * Run an Akismet check for spam * @param array $comment Message data. Required keys: * permalink - the permanent location of the entry the comment was submitted to * comment_type - may be blank, comment, trackback, pingback, or a made up value like "registration" * comment_author - name submitted with the comment * comment_author_email - email address submitted with the comment * comment_author_url - URL submitted with comment * comment_content - the content that was submitted * @return bool true if spam */ public function akismetCheck($comment) { $loader = new SplClassLoader('Rzeka', __DIR__ . '/vendor/'); $loader->register(); $connector = new Rzeka\Service\Akismet\Connector\Curl(); $akismet = new Rzeka\Service\Akismet($connector); $api_key = $this->config['akismet_api_key']; $site_url = Config::get('site_url'); if (!$akismet->keyCheck($api_key, $site_url)) { Log::error('Invalid Akismet API key', 'raven'); return false; } return $akismet->check($comment); }
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ // show errors error_reporting(E_ALL); // lets stop the time $start = microtime(true); // enable autoloading of classes require_once('../lib/MwbExporter/Core/SplClassLoader.php'); $classLoader = new SplClassLoader(); $classLoader->setIncludePath('../lib'); $classLoader->register(); // show a simple text box with the output echo '<textarea cols="100" rows="50">'; $setup = array(); // create a formatter $formatter = new \MwbExporter\Formatter\Doctrine2\Annotation\Loader($setup); // parse the mwb file $mwb = new \MwbExporter\Core\Workbench\Document('data/test.mwb', $formatter); // show the export output of the mwb file
| */ require_once __DIR__ . '/vendor/Slim/Slim.php'; require_once __DIR__ . '/vendor/SplClassLoader.php'; \Slim\Slim::registerAutoloader(); /* |-------------------------------------------------------------------------- | Vendor libraries |------------------------------------------------------------------------- | | Load miscellaneous third-party dependencies. | */ $packages = array('Buzz', 'Carbon', 'emberlabs', 'Intervention', 'Michelf', 'Netcarver', 'Stampie', 'Symfony', 'Whoops', 'Zeuxisoo', 'erusev', 'Propel'); foreach ($packages as $package) { $loader = new SplClassLoader($package, __DIR__ . '/vendor/'); $loader->register(); } require_once __DIR__ . '/vendor/PHPMailer/PHPMailerAutoload.php'; require_once __DIR__ . '/vendor/Spyc/Spyc.php'; /* |-------------------------------------------------------------------------- | The Template Parser |-------------------------------------------------------------------------- | | Statamic uses a *highly* modified fork of the Lex parser, created by | Dan Horrigan. Kudos Dan! | */ require_once __DIR__ . '/vendor/Lex/Parser.php'; /*
<?php /** * Spellchecker class * * @package jQuery Spellchecker (https://github.com/badsyntax/jquery-spellchecker) * @author Richard Willis * @copyright (c) Richard Willis * @license https://github.com/badsyntax/jquery-spellchecker/blob/master/LICENSE-MIT */ ini_set('display_errors', 1); require_once 'SplClassLoader.php'; $classLoader = new SplClassLoader('SpellChecker', 'SpellChecker'); $classLoader->setIncludePathLookup(true); $classLoader->register(); new \SpellChecker\Request();
* furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ set_include_path(get_include_path() . PATH_SEPARATOR . realpath(__DIR__ . '/../src')); require_once 'SplClassLoader.php'; $l = new SplClassLoader('MaxTsepkov'); $l->register(); use MaxTsepkov\Markdown\Text; class BenchmarkTest extends PHPUnit_Framework_TestCase { const MD_SIZE = 1048576; // 1M protected static $_markdown; protected static $_timings = array(); /** * Generate a large markdown document. * */ public static function setUpBeforeClass() { $charset = "\n\t";
function prepareExchangedData($data, $type) { //Load AES $aes = new SplClassLoader('Encryption\\Crypt', '../includes/libraries'); $aes->register(); if ($type == "encode") { if (isset($_SESSION['settings']['encryptClientServer']) && $_SESSION['settings']['encryptClientServer'] == 0) { return json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); } else { return Encryption\Crypt\aesctr::encrypt(json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP), $_SESSION['key'], 256); } } elseif ($type == "decode") { if (isset($_SESSION['settings']['encryptClientServer']) && $_SESSION['settings']['encryptClientServer'] == 0) { return json_decode($data, true); } else { return json_decode(Encryption\Crypt\aesctr::decrypt($data, $_SESSION['key'], 256), true); } } }
/** * updateCacheTable() * * Update the CACHE table */ function updateCacheTable($action, $id = "") { global $db, $server, $user, $pass, $database, $pre, $port; require_once $_SESSION['settings']['cpassman_dir'] . '/sources/SplClassLoader.php'; //Connect to DB require_once $_SESSION['settings']['cpassman_dir'] . '/includes/libraries/Database/Meekrodb/db.class.php'; DB::$host = $server; DB::$user = $user; DB::$password = $pass; DB::$dbName = $database; DB::$port = $port; DB::$error_handler = 'db_error_handler'; $link = mysqli_connect($server, $user, $pass, $database, $port); //Load Tree $tree = new SplClassLoader('Tree\\NestedTree', '../includes/libraries'); $tree->register(); $tree = new Tree\NestedTree\NestedTree($pre . 'nested_tree', 'id', 'parent_id', 'title'); // Rebuild full cache table if ($action == "reload") { // truncate table DB::query("TRUNCATE TABLE " . $pre . "cache"); // reload date $rows = DB::query("SELECT *\n FROM " . $pre . "items as i\n INNER JOIN " . $pre . "log_items as l ON (l.id_item = i.id)\n AND l.action = %s\n AND i.inactif = %i", 'at_creation', 0); foreach ($rows as $record) { // Get all TAGS $tags = ""; $itemTags = DB::query("SELECT tag FROM " . $pre . "tags WHERE item_id=%i", $record['id']); foreach ($itemTags as $itemTag) { if (!empty($itemTag['tag'])) { $tags .= $itemTag['tag'] . " "; } } // form id_tree to full foldername $folder = ""; $arbo = $tree->getPath($record['id_tree'], true); foreach ($arbo as $elem) { if ($elem->title == $_SESSION['user_id'] && $elem->nlevel == 1) { $elem->title = $_SESSION['login']; } if (empty($folder)) { $folder = stripslashes($elem->title); } else { $folder .= " » " . stripslashes($elem->title); } } // store data DB::insert($pre . "cache", array('id' => $record['id'], 'label' => $record['label'], 'description' => $record['description'], 'tags' => $tags, 'id_tree' => $record['id_tree'], 'perso' => $record['perso'], 'restricted_to' => $record['restricted_to'], 'login' => $record['login'] == null ? "" : $record['login'], 'folder' => $folder, 'author' => $record['id_user'])); } // UPDATE an item } elseif ($action == "update_value") { // get new value from db $data = DB::queryfirstrow("SELECT label, description, id_tree, perso, restricted_to, login\n FROM " . $pre . "items\n WHERE id=%i", $id); // Get all TAGS $tags = ""; $itemTags = DB::query("SELECT tag FROM " . $pre . "tags WHERE item_id=%i", $id); foreach ($itemTags as $itemTag) { if (!empty($itemTag['tag'])) { $tags .= $itemTag['tag'] . " "; } } // form id_tree to full foldername $folder = ""; $arbo = $tree->getPath($data['id_tree'], true); foreach ($arbo as $elem) { if ($elem->title == $_SESSION['user_id'] && $elem->nlevel == 1) { $elem->title = $_SESSION['login']; } if (empty($folder)) { $folder = stripslashes($elem->title); } else { $folder .= " » " . stripslashes($elem->title); } } // finaly update DB::update($pre . "cache", array('label' => $data['label'], 'description' => $data['description'], 'tags' => $tags, 'id_tree' => $data['id_tree'], 'perso' => $data['perso'], 'restricted_to' => $data['restricted_to'], 'login' => $data['login'], 'folder' => $folder, 'author' => $_SESSION['user_id']), "id = %i", $id); // ADD an item } elseif ($action == "add_value") { // get new value from db $data = DB::queryFirstRow("SELECT i.label, i.description, i.id_tree as id_tree, i.perso, i.restricted_to, i.id, i.login\n FROM " . $pre . "items as i\n INNER JOIN " . $pre . "log_items as l ON (l.id_item = i.id)\n WHERE i.id = %i\n AND l.action = %s", $id, 'at_creation'); // Get all TAGS $tags = ""; $itemTags = DB::query("SELECT tag FROM " . $pre . "tags WHERE item_id = %i", $id); foreach ($itemTags as $itemTag) { if (!empty($itemTag['tag'])) { $tags .= $itemTag['tag'] . " "; } } // form id_tree to full foldername $folder = ""; $arbo = $tree->getPath($data['id_tree'], true); foreach ($arbo as $elem) { if ($elem->title == $_SESSION['user_id'] && $elem->nlevel == 1) { $elem->title = $_SESSION['login']; } if (empty($folder)) { $folder = stripslashes($elem->title); } else { $folder .= " » " . stripslashes($elem->title); } } // finaly update DB::insert($pre . "cache", array('id' => $data['id'], 'label' => $data['label'], 'description' => $data['description'], 'tags' => $tags, 'id_tree' => $data['id_tree'], 'perso' => $data['perso'], 'restricted_to' => $data['restricted_to'], 'login' => $data['login'], 'folder' => $folder, 'author' => $_SESSION['user_id'])); // DELETE an item } elseif ($action == "delete_value") { DB::delete($pre . "cache", "id = %i", $id); } }
* Licensed under the MIT license * */ /******************************* * General Set-up *******************************/ // check to see if json_decode exists. might be disabled in installs of PHP 5.5 if (!function_exists("json_decode")) { print "Please check that your version of PHP includes the JSON extension. It's required for Pattern Lab to run. Aborting.\n"; exit; } // auto-load classes require __DIR__ . "/lib/SplClassLoader.php"; $loader = new SplClassLoader('PatternLab', __DIR__ . '/lib'); $loader->register(); $loader = new SplClassLoader('Mustache', __DIR__ . '/lib'); $loader->setNamespaceSeparator("_"); $loader->register(); /******************************* * Console Set-up *******************************/ $console = new PatternLab\Console(); // set-up the generate command and options $console->setCommand("g", "generate", "Generate Pattern Lab", "The generate command generates an entire site a single time. By default it removes old content in public/, compiles the patterns and moves content from source/ into public/"); $console->setCommandOption("g", "p", "patternsonly", "Generate only the patterns. Does NOT clean public/.", "To generate only the patterns:"); $console->setCommandOption("g", "n", "nocache", "Set the cacheBuster value to 0.", "To turn off the cacheBuster:"); $console->setCommandOption("g", "c", "enablecss", "Generate CSS for each pattern. Resource intensive.", "To run and generate the CSS for each pattern:"); // set-up an alias for the generate command $console->setCommand("b", "build", "Alias for the generate command", "Alias for the generate command. Please refer to it's help for full options."); // set-up the watch command and options $console->setCommand("w", "watch", "Watch for changes and regenerate", "The watch command builds Pattern Lab, watches for changes in source/ and regenerates Pattern Lab when there are any.");
/** * Cargar las clases de las extensiones de sysPass */ private static function loadExtensions() { // Utilizar un cargador de clases PSR-0 require EXTENSIONS_PATH . DIRECTORY_SEPARATOR . 'SplClassLoader.php'; $phpSecLoader = new \SplClassLoader('phpseclib', EXTENSIONS_PATH); $phpSecLoader->register(); }
<?php require_once './vendor/autoload.php'; $helperLoader = new SplClassLoader('Helpers', './vendor'); $helperLoader->register(); use Helpers\Config; $config = new Config(); $config->load('./config/config.php'); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Ajax contact form</title> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="jumbotron"> <div class="container"> <h1>Ajax Contact Form</h1> <p>A simple ajax based contact form using pure JavaScript and PHP.</p> <p><a class="btn btn-primary btn-lg" href="https://github.com/pinceladasdaweb/Ajax-Contact-Form" role="button">Learn more »</a></p> </div> </div> <div class="col-md-6 col-md-offset-3"> <form enctype="application/x-www-form-urlencoded;" id="contact-form" class="form-horizontal" role="form" method="post"> <div class="form-group" id="name-field"> <label for="form-name" class="col-lg-2 control-label"><?php
/** * Loads the CSS from source/css/ into CSS Rule Saver to be used for code view */ protected function initializeCSSRuleSaver() { $loader = new \SplClassLoader('CSSRuleSaver', __DIR__ . '/../../lib'); $loader->register(); $this->cssRuleSaver = new \CSSRuleSaver\CSSRuleSaver(); foreach (glob($this->sd . "/css/*.css") as $filename) { $this->cssRuleSaver->loadCSS($filename); } }
<?php require_once '../vendor/autoload.php'; $helperLoader = new SplClassLoader('Helpers', '../vendor'); $youtubeLoader = new SplClassLoader('Youtube', '../vendor'); $templateLoader = new SplClassLoader('Broculo', '../vendor'); $helperLoader->register(); $youtubeLoader->register(); $templateLoader->register(); use Helpers\Config; use Youtube\Youtube; use Broculo\Template; $config = new Config(); $config->load('../config/config.php'); $youtube = new Youtube($config->get('youtube.apiKey')); $profile = $youtube->getUserProfile($config->get('youtube.user')); $playlist = $youtube->getUserVideos($profile['playlist'], $config->get('youtube.maxResults')); $featured = $youtube->getVideoInfo($playlist['ids'][0]); $featuredId = json_decode($featured); $videos = ''; unset($playlist['ids'][0]); $brandedTpl = new Template("../tpl/branded.tpl"); $featuredTpl = new Template("../tpl/featured.tpl"); $videosTpl = new Template("../tpl/shelf-items.tpl"); $brandedTpl->set("src", $profile['banner']); $brandedTpl->set("title", $profile['title']); $brandedTpl->set("img_profile", $profile['img_profile']); $brandedTpl->set("subscribers", $profile['subscribers']); $brandedTpl->set("videos", $profile['videos']); $featuredTpl->set("id", $featuredId->items[0]->id); $videosId = $playlist['ids'];
<?php require_once __DIR__ . "/SplClassLoader.php"; $splClassLoader = new SplClassLoader("Peach", __DIR__); $splClassLoader->register();
<?php // This is for my examples require '_system/config.php'; $relevant_code = array('\\PHPGoogleMaps\\Overlay\\Marker'); // Autoload stuff require '../PHPGoogleMaps/Core/Autoloader.php'; $map_loader = new SplClassLoader('PHPGoogleMaps', '../'); $map_loader->register(); $map = new \PHPGoogleMaps\Map(); $marker1 = \PHPGoogleMaps\Overlay\Marker::createFromLocation('New York, NY', array('title' => 'New York, NY', 'content' => 'New York marker')); $marker2 = \PHPGoogleMaps\Overlay\Marker::createFromPosition(new \PHPGoogleMaps\Core\LatLng(32.7153292, -117.1572551), array('title' => 'San Diego, CA', 'content' => 'San Diego marker')); $marker3 = \PHPGoogleMaps\Overlay\Marker::createFromLocation('Dallas, TX', array('title' => 'Dallas, TX', 'content' => 'Dallas marker')); $map->addObjects(array($marker1, $marker2, $marker3)); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Simple Sidebar - <?php echo PAGE_TITLE; ?> </title> <link rel="stylesheet" type="text/css" href="_css/style.css"> <style type="text/css"> #map, #map_sidebar { float: left } .sidebar { list-style:none; margin:0 0 0 10px;padding:0;width: 200px; } .sidebar li { margin-bottom: 2px; } .sidebar p { background-color: #eee;margin:0; padding: 5px;cursor: pointer; } .sidebar p:hover { background-color: #ddd; }
/** * register autoloader * * @return void */ public static function register() { $loader = new \SplClassLoader('Selfish', __DIR__ . '/..'); $loader->register(); }
<?php error_reporting(E_ALL); require __DIR__ . '/lib/SplClassLoader.php'; $classLoader = new SplClassLoader('WebSocket', __DIR__ . '/lib'); $classLoader->register(); $server = new \WebSocket\Server('localhost', 8000); $server->registerApplication('echo', \WebSocket\Application\EchoApplication::getInstance()); $server->run();
header("Content-type: text/html; charset=utf-8"); require_once 'main.functions.php'; require_once $_SESSION['settings']['cpassman_dir'] . '/sources/SplClassLoader.php'; //Connect to DB require_once $_SESSION['settings']['cpassman_dir'] . '/includes/libraries/Database/Meekrodb/db.class.php'; DB::$host = $server; DB::$user = $user; DB::$password = $pass; DB::$dbName = $database; DB::$port = $port; DB::$encoding = $encoding; DB::$error_handler = 'db_error_handler'; $link = mysqli_connect($server, $user, $pass, $database, $port); $link->set_charset($encoding); //Build tree $tree = new SplClassLoader('Tree\\NestedTree', $_SESSION['settings']['cpassman_dir'] . '/includes/libraries'); $tree->register(); $tree = new Tree\NestedTree\NestedTree($pre . 'nested_tree', 'id', 'parent_id', 'title'); if (!empty($_POST['type'])) { switch ($_POST['type']) { #CASE adding a new role case "add_new_role": //Check if role already exist : No similar roles $tmp = DB::query("SELECT * FROM " . prefix_table("roles_title") . " WHERE title = %s", stripslashes($_POST['name'])); $counter = DB::count(); if ($counter == 0) { DB::insert(prefix_table("roles_title"), array('title' => stripslashes($_POST['name']), 'complexity' => $_POST['complexity'], 'creator_id' => $_SESSION['user_id'])); $role_id = DB::insertId(); if ($role_id != 0) { //Actualize the variable $_SESSION['nb_roles']++;
// Make sure we have the necessary config $necessaryConfigValues = array('jcr.url', 'jcr.user', 'jcr.pass', 'jcr.workspace', 'jcr.transport'); foreach ($necessaryConfigValues as $val) { if (empty($GLOBALS[$val])) { die('Please set ' . $val . ' in your phpunit.xml.' . "\n"); } } require_once dirname(__FILE__) . '/../SplClassLoader.php'; // Midgard2CR is in the src dir $midgard2crAutoloader = new SplClassLoader('Midgard2CR', dirname(__FILE__) . '/../src'); $midgard2crAutoloader->register(); // Midgard2CR\Query $midgard2crQAutoloader = new SplClassLoader('Midgard2CR\\Query', dirname(__FILE__) . '/../src/Midgard2CR/Query'); $midgard2crQAutoloader->register(); // PHPCR is in a submodule in lib/PHPCR $phpcrAutoloader = new SplClassLoader('PHPCR', dirname(__FILE__) . '/../lib/PHPCR/src'); $phpcrAutoloader->register(); function getRepository($config) { $factory = new Midgard2CR\RepositoryFactory(); return $factory->getRepository(); } /** * @param user The user name for the credentials * @param password The password for the credentials * @return the simple credentials instance for this implementation with the specified username/password */ function getSimpleCredentials($user, $password) { return new \PHPCR\SimpleCredentials($user, $password); }
function identifyUser($sentData) { global $debugLdap, $debugDuo, $k; include $_SESSION['settings']['cpassman_dir'] . '/includes/settings.php'; header("Content-type: text/html; charset=utf-8"); error_reporting(E_ERROR); require_once $_SESSION['settings']['cpassman_dir'] . '/sources/main.functions.php'; require_once $_SESSION['settings']['cpassman_dir'] . '/sources/SplClassLoader.php'; if ($debugDuo == 1) { $dbgDuo = fopen($_SESSION['settings']['path_to_files_folder'] . "/duo.debug.txt", "a"); } /* if (empty($sentData) && isset($_COOKIE['TeamPassC'])) { $sentData = prepareExchangedData($_COOKIE['TeamPassC'], "encode"); setcookie('TeamPassC', "", time()-3600); } */ if ($debugDuo == 1) { fputs($dbgDuo, "Content of data sent '" . $sentData . "'\n"); } // connect to the server require_once $_SESSION['settings']['cpassman_dir'] . '/includes/libraries/Database/Meekrodb/db.class.php'; DB::$host = $server; DB::$user = $user; DB::$password = $pass; DB::$dbName = $database; DB::$port = $port; DB::$encoding = $encoding; DB::$error_handler = 'db_error_handler'; $link = mysqli_connect($server, $user, $pass, $database, $port); $link->set_charset($encoding); //Load AES $aes = new SplClassLoader('Encryption\\Crypt', '../includes/libraries'); $aes->register(); // load passwordLib library $pwdlib = new SplClassLoader('PasswordLib', '../includes/libraries'); $pwdlib->register(); $pwdlib = new PasswordLib\PasswordLib(); // User's language loading $k['langage'] = @$_SESSION['user_language']; require_once $_SESSION['settings']['cpassman_dir'] . '/includes/language/' . $_SESSION['user_language'] . '.php'; // decrypt and retreive data in JSON format $dataReceived = prepareExchangedData($sentData, "decode"); // Prepare variables $passwordClear = htmlspecialchars_decode($dataReceived['pw']); $passwordOldEncryption = encryptOld(htmlspecialchars_decode($dataReceived['pw'])); $username = htmlspecialchars_decode($dataReceived['login']); $logError = ""; if ($debugDuo == 1) { fputs($dbgDuo, "Starting authentication of '" . $username . "'\n"); } // GET SALT KEY LENGTH if (strlen(SALT) > 32) { $_SESSION['error']['salt'] = true; } $_SESSION['user_language'] = $k['langage']; $ldapConnection = false; /* LDAP connection */ if ($debugLdap == 1) { // create temp file $dbgLdap = fopen($_SESSION['settings']['path_to_files_folder'] . "/ldap.debug.txt", "w"); fputs($dbgLdap, "Get all LDAP params : \n" . 'mode : ' . $_SESSION['settings']['ldap_mode'] . "\n" . 'type : ' . $_SESSION['settings']['ldap_type'] . "\n" . 'base_dn : ' . $_SESSION['settings']['ldap_domain_dn'] . "\n" . 'search_base : ' . $_SESSION['settings']['ldap_search_base'] . "\n" . 'bind_dn : ' . $_SESSION['settings']['ldap_bind_dn'] . "\n" . 'bind_passwd : ' . $_SESSION['settings']['ldap_bind_passwd'] . "\n" . 'user_attribute : ' . $_SESSION['settings']['ldap_user_attribute'] . "\n" . 'account_suffix : ' . $_SESSION['settings']['ldap_suffix'] . "\n" . 'domain_controllers : ' . $_SESSION['settings']['ldap_domain_controler'] . "\n" . 'use_ssl : ' . $_SESSION['settings']['ldap_ssl'] . "\n" . 'use_tls : ' . $_SESSION['settings']['ldap_tls'] . "\n*********\n\n"); } if ($debugDuo == 1) { fputs($dbgDuo, "LDAP status: " . $_SESSION['settings']['ldap_mode'] . "\n"); } if (isset($_SESSION['settings']['ldap_mode']) && $_SESSION['settings']['ldap_mode'] == 1 && $username != "admin") { //Multiple Domain Names if (strpos(html_entity_decode($username), '\\') == true) { $ldap_suffix = "@" . substr(html_entity_decode($username), 0, strpos(html_entity_decode($username), '\\')); $username = substr(html_entity_decode($username), strpos(html_entity_decode($username), '\\') + 1); } if ($_SESSION['settings']['ldap_type'] == 'posix-search') { $ldapconn = ldap_connect($_SESSION['settings']['ldap_domain_controler']); if ($debugLdap == 1) { fputs($dbgLdap, "LDAP connection : " . ($ldapconn ? "Connected" : "Failed") . "\n"); } ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); if ($ldapconn) { $ldapbind = ldap_bind($ldapconn, $_SESSION['settings']['ldap_bind_dn'], $_SESSION['settings']['ldap_bind_passwd']); if ($debugLdap == 1) { fputs($dbgLdap, "LDAP bind : " . ($ldapbind ? "Bound" : "Failed") . "\n"); } if ($ldapbind) { $filter = "(&(" . $_SESSION['settings']['ldap_user_attribute'] . "={$username})(objectClass=posixAccount))"; $result = ldap_search($ldapconn, $_SESSION['settings']['ldap_search_base'], $filter, array('dn')); if ($debugLdap == 1) { fputs($dbgLdap, 'Search filter : ' . $filter . "\n" . 'Results : ' . print_r(ldap_get_entries($ldapconn, $result), true) . "\n"); } if (ldap_count_entries($ldapconn, $result)) { // try auth $result = ldap_get_entries($ldapconn, $result); $user_dn = $result[0]['dn']; $ldapbind = ldap_bind($ldapconn, $user_dn, $passwordClear); if ($ldapbind) { $ldapConnection = true; } else { $ldapConnection = false; } } } else { $ldapConnection = false; } } else { $ldapConnection = false; } } else { if ($debugLdap == 1) { fputs($dbgLdap, "Get all ldap params : \n" . 'base_dn : ' . $_SESSION['settings']['ldap_domain_dn'] . "\n" . 'account_suffix : ' . $_SESSION['settings']['ldap_suffix'] . "\n" . 'domain_controllers : ' . $_SESSION['settings']['ldap_domain_controler'] . "\n" . 'use_ssl : ' . $_SESSION['settings']['ldap_ssl'] . "\n" . 'use_tls : ' . $_SESSION['settings']['ldap_tls'] . "\n*********\n\n"); } $adldap = new SplClassLoader('LDAP\\adLDAP', '../includes/libraries'); $adldap->register(); // Posix style LDAP handles user searches a bit differently if ($_SESSION['settings']['ldap_type'] == 'posix') { $ldap_suffix = ',' . $_SESSION['settings']['ldap_suffix'] . ',' . $_SESSION['settings']['ldap_domain_dn']; } elseif ($_SESSION['settings']['ldap_type'] == 'windows' and $ldap_suffix == '') { //Multiple Domain Names $ldap_suffix = $_SESSION['settings']['ldap_suffix']; } $adldap = new LDAP\adLDAP\adLDAP(array('base_dn' => $_SESSION['settings']['ldap_domain_dn'], 'account_suffix' => $ldap_suffix, 'domain_controllers' => explode(",", $_SESSION['settings']['ldap_domain_controler']), 'use_ssl' => $_SESSION['settings']['ldap_ssl'], 'use_tls' => $_SESSION['settings']['ldap_tls'])); if ($debugLdap == 1) { fputs($dbgLdap, "Create new adldap object : " . $adldap->get_last_error() . "\n\n\n"); //Debug } // openLDAP expects an attribute=value pair if ($_SESSION['settings']['ldap_type'] == 'posix') { $auth_username = $_SESSION['settings']['ldap_user_attribute'] . '=' . $username; } else { $auth_username = $username; } // authenticate the user if ($adldap->authenticate($auth_username, html_entity_decode($passwordClear))) { $ldapConnection = true; //update user's password $data['pw'] = $pwdlib->createPasswordHash($passwordClear); DB::update(prefix_table('users'), array('pw' => $data['pw']), "login=%s", $username); } else { $ldapConnection = false; } if ($debugLdap == 1) { fputs($dbgLdap, "After authenticate : " . $adldap->get_last_error() . "\n\n\n" . "ldap status : " . $ldapConnection . "\n\n\n"); //Debug } } } else { if (isset($_SESSION['settings']['ldap_mode']) && $_SESSION['settings']['ldap_mode'] == 2) { // nothing } } // Check if user exists $data = DB::queryFirstRow("SELECT * FROM " . prefix_table("users") . " WHERE login=%s_login", array('login' => $username)); $counter = DB::count(); if ($debugDuo == 1) { fputs($dbgDuo, "USer exists: " . $counter . "\n"); } // Check PSK if (isset($_SESSION['settings']['psk_authentication']) && $_SESSION['settings']['psk_authentication'] == 1 && $data['admin'] != 1) { $psk = htmlspecialchars_decode($dataReceived['psk']); $pskConfirm = htmlspecialchars_decode($dataReceived['psk_confirm']); if (empty($psk)) { echo '[{"value" : "psk_required"}]'; exit; } elseif (empty($data['psk'])) { if (empty($pskConfirm)) { echo '[{"value" : "bad_psk_confirmation"}]'; exit; } else { $_SESSION['my_sk'] = $psk; } } elseif ($pwdlib->verifyPasswordHash($psk, $data['psk']) === true) { echo '[{"value" : "bad_psk"}]'; exit; } } $proceedIdentification = false; if ($counter > 0) { $proceedIdentification = true; } elseif ($counter == 0 && $ldapConnection == true && isset($_SESSION['settings']['ldap_elusers']) && $_SESSION['settings']['ldap_elusers'] == 0) { // If LDAP enabled, create user in CPM if doesn't exist $data['pw'] = $pwdlib->createPasswordHash($passwordClear); // create passwordhash DB::insert(prefix_table('users'), array('login' => $username, 'pw' => $data['pw'], 'email' => "", 'admin' => '0', 'gestionnaire' => '0', 'personal_folder' => $_SESSION['settings']['enable_pf_feature'] == "1" ? '1' : '0', 'fonction_id' => '0', 'groupes_interdits' => '0', 'groupes_visibles' => '0', 'last_pw_change' => time(), 'user_language' => $_SESSION['settings']['default_language'])); $newUserId = DB::insertId(); // Create personnal folder if ($_SESSION['settings']['enable_pf_feature'] == "1") { DB::insert(prefix_table("nested_tree"), array('parent_id' => '0', 'title' => $newUserId, 'bloquer_creation' => '0', 'bloquer_modification' => '0', 'personal_folder' => '1')); } // Get info for user //$sql = "SELECT * FROM ".prefix_table("users")." WHERE login = '******'"; //$row = $db->query($sql); $proceedIdentification = true; } // Check if user exists (and has been created in case of new LDAP user) $data = DB::queryFirstRow("SELECT * FROM " . prefix_table("users") . " WHERE login=%s_login", array('login' => $username)); $counter = DB::count(); if ($counter == 0) { echo '[{"value" : "user_not_exists", "text":""}]'; exit; } if ($debugDuo == 1) { fputs($dbgDuo, "USer exists (confirm): " . $counter . "\n"); } // check GA code if (isset($_SESSION['settings']['2factors_authentication']) && $_SESSION['settings']['2factors_authentication'] == 1 && $username != "admin") { if (isset($dataReceived['GACode']) && !empty($dataReceived['GACode'])) { include_once $_SESSION['settings']['cpassman_dir'] . "/includes/libraries/Authentication/GoogleAuthenticator/FixedBitNotation.php"; include_once $_SESSION['settings']['cpassman_dir'] . "/includes/libraries/Authentication/GoogleAuthenticator/GoogleAuthenticator.php"; $g = new Authentication\GoogleAuthenticator\GoogleAuthenticator(); if ($g->checkCode($data['ga'], $dataReceived['GACode'])) { $proceedIdentification = true; } else { $proceedIdentification = false; $logError = "ga_code_wrong"; } } else { $proceedIdentification = false; $logError = "ga_code_wrong"; } } if ($debugDuo == 1) { fputs($dbgDuo, "Proceed with Ident: " . $proceedIdentification . "\n"); } if ($proceedIdentification === true) { // User exists in the DB //$data = $db->fetchArray($row); //v2.1.17 -> change encryption for users password if ($passwordOldEncryption == $data['pw'] && !empty($data['pw'])) { //update user's password $data['pw'] = bCrypt($passwordClear, COST); DB::update(prefix_table('users'), array('pw' => $data['pw']), "id=%i", $data['id']); } if (crypt($passwordClear, $data['pw']) == $data['pw'] && !empty($data['pw'])) { //update user's password $data['pw'] = $pwdlib->createPasswordHash($passwordClear); DB::update(prefix_table('users'), array('pw' => $data['pw']), "id=%i", $data['id']); } // check the given password if ($pwdlib->verifyPasswordHash($passwordClear, $data['pw']) === true) { $userPasswordVerified = true; } else { $userPasswordVerified = false; } if ($debugDuo == 1) { fputs($dbgDuo, "User's password verified: " . $userPasswordVerified . "\n"); } // Can connect if // 1- no LDAP mode + user enabled + pw ok // 2- LDAP mode + user enabled + ldap connection ok + user is not admin // 3- LDAP mode + user enabled + pw ok + usre is admin // This in order to allow admin by default to connect even if LDAP is activated if (isset($_SESSION['settings']['ldap_mode']) && $_SESSION['settings']['ldap_mode'] == 0 && $userPasswordVerified == true && $data['disabled'] == 0 || isset($_SESSION['settings']['ldap_mode']) && $_SESSION['settings']['ldap_mode'] == 1 && $ldapConnection == true && $data['disabled'] == 0 && $username != "admin" || isset($_SESSION['settings']['ldap_mode']) && $_SESSION['settings']['ldap_mode'] == 2 && $ldapConnection == true && $data['disabled'] == 0 && $username != "admin" || isset($_SESSION['settings']['ldap_mode']) && $_SESSION['settings']['ldap_mode'] == 1 && $username == "admin" && $userPasswordVerified == true && $data['disabled'] == 0) { $_SESSION['autoriser'] = true; // Generate a ramdom ID $key = $pwdlib->getRandomToken(50); if ($debugDuo == 1) { fputs($dbgDuo, "User's token: " . $key . "\n"); } // Log into DB the user's connection if (isset($_SESSION['settings']['log_connections']) && $_SESSION['settings']['log_connections'] == 1) { logEvents('user_connection', 'connection', $data['id']); } // Save account in SESSION $_SESSION['login'] = stripslashes($username); $_SESSION['name'] = stripslashes($data['name']); $_SESSION['lastname'] = stripslashes($data['lastname']); $_SESSION['user_id'] = $data['id']; $_SESSION['user_admin'] = $data['admin']; $_SESSION['user_manager'] = $data['gestionnaire']; $_SESSION['user_read_only'] = $data['read_only']; $_SESSION['last_pw_change'] = $data['last_pw_change']; $_SESSION['last_pw'] = $data['last_pw']; $_SESSION['can_create_root_folder'] = $data['can_create_root_folder']; $_SESSION['key'] = $key; $_SESSION['personal_folder'] = $data['personal_folder']; $_SESSION['user_language'] = $data['user_language']; $_SESSION['user_email'] = $data['email']; $_SESSION['user_ga'] = $data['ga']; $_SESSION['user_avatar'] = $data['avatar']; $_SESSION['user_avatar_thumb'] = $data['avatar_thumb']; $_SESSION['user_upgrade_needed'] = $data['upgrade_needed']; // manage session expiration $serverTime = time(); if ($dataReceived['TimezoneOffset'] > 0) { $userTime = $serverTime + $dataReceived['TimezoneOffset']; } else { $userTime = $serverTime; } $_SESSION['fin_session'] = $userTime + $dataReceived['duree_session'] * 60; /* If this option is set user password MD5 is used as personal SALTKey */ if (isset($_SESSION['settings']['use_md5_password_as_salt']) && $_SESSION['settings']['use_md5_password_as_salt'] == 1) { $_SESSION['my_sk'] = md5($passwordClear); setcookie("TeamPass_PFSK_" . md5($_SESSION['user_id']), encrypt($_SESSION['my_sk'], ""), time() + 60 * 60 * 24 * $_SESSION['settings']['personal_saltkey_cookie_duration'], '/'); } @syslog(LOG_WARNING, "User logged in - " . $_SESSION['user_id'] . " - " . date("Y/m/d H:i:s") . " {$_SERVER['REMOTE_ADDR']} ({$_SERVER['HTTP_USER_AGENT']})"); if (empty($data['last_connexion'])) { $_SESSION['derniere_connexion'] = time(); } else { $_SESSION['derniere_connexion'] = $data['last_connexion']; } if (!empty($data['latest_items'])) { $_SESSION['latest_items'] = explode(';', $data['latest_items']); } else { $_SESSION['latest_items'] = array(); } if (!empty($data['favourites'])) { $_SESSION['favourites'] = explode(';', $data['favourites']); } else { $_SESSION['favourites'] = array(); } if (!empty($data['groupes_visibles'])) { $_SESSION['groupes_visibles'] = @implode(';', $data['groupes_visibles']); } else { $_SESSION['groupes_visibles'] = array(); } if (!empty($data['groupes_interdits'])) { $_SESSION['groupes_interdits'] = @implode(';', $data['groupes_interdits']); } else { $_SESSION['groupes_interdits'] = array(); } // User's roles $_SESSION['fonction_id'] = $data['fonction_id']; $_SESSION['user_roles'] = explode(";", $data['fonction_id']); // build array of roles $_SESSION['user_pw_complexity'] = 0; $_SESSION['arr_roles'] = array(); foreach (array_filter(explode(';', $_SESSION['fonction_id'])) as $role) { $resRoles = DB::queryFirstRow("SELECT title, complexity FROM " . prefix_table("roles_title") . " WHERE id=%i", $role); $_SESSION['arr_roles'][$role] = array('id' => $role, 'title' => $resRoles['title']); // get highest complexity if ($_SESSION['user_pw_complexity'] < $resRoles['complexity']) { $_SESSION['user_pw_complexity'] = $resRoles['complexity']; } } // build complete array of roles $_SESSION['arr_roles_full'] = array(); $rows = DB::query("SELECT id, title FROM " . prefix_table("roles_title") . " ORDER BY title ASC"); foreach ($rows as $record) { $_SESSION['arr_roles_full'][$record['id']] = array('id' => $record['id'], 'title' => $record['title']); } // Set some settings $_SESSION['user']['find_cookie'] = false; $_SESSION['settings']['update_needed'] = ""; // Update table DB::update(prefix_table('users'), array('key_tempo' => $_SESSION['key'], 'last_connexion' => time(), 'timestamp' => time(), 'disabled' => 0, 'no_bad_attempts' => 0, 'session_end' => $_SESSION['fin_session'], 'psk' => $pwdlib->createPasswordHash(htmlspecialchars_decode($psk))), "id=%i", $data['id']); if ($debugDuo == 1) { fputs($dbgDuo, "Preparing to identify the user rights\n"); } // Get user's rights identifyUserRights($data['groupes_visibles'], $_SESSION['groupes_interdits'], $data['admin'], $data['fonction_id'], false); // Get some more elements $_SESSION['screenHeight'] = $dataReceived['screenHeight']; // Get last seen items $_SESSION['latest_items_tab'][] = ""; foreach ($_SESSION['latest_items'] as $item) { if (!empty($item)) { $data = DB::queryFirstRow("SELECT id,label,id_tree FROM " . prefix_table("items") . " WHERE id=%i", $item); $_SESSION['latest_items_tab'][$item] = array('id' => $item, 'label' => $data['label'], 'url' => 'index.php?page=items&group=' . $data['id_tree'] . '&id=' . $item); } } // send back the random key $return = $dataReceived['randomstring']; // Send email if (isset($_SESSION['settings']['enable_send_email_on_user_login']) && $_SESSION['settings']['enable_send_email_on_user_login'] == 1 && $_SESSION['user_admin'] != 1) { // get all Admin users $receivers = ""; $rows = DB::query("SELECT email FROM " . prefix_table("users") . " WHERE admin = %i", 1); foreach ($rows as $record) { if (empty($receivers)) { $receivers = $record['email']; } else { $receivers = "," . $record['email']; } } // Add email to table DB::insert(prefix_table("emails"), array('timestamp' => time(), 'subject' => $LANG['email_subject_on_user_login'], 'body' => str_replace(array('#tp_user#', '#tp_date#', '#tp_time#'), array(" " . $_SESSION['login'], date($_SESSION['settings']['date_format'], $_SESSION['derniere_connexion']), date($_SESSION['settings']['time_format'], $_SESSION['derniere_connexion'])), $LANG['email_body_on_user_login']), 'receivers' => $receivers, 'status' => "not sent")); } } elseif ($data['disabled'] == 1) { // User and password is okay but account is locked $return = "user_is_locked"; } else { // User exists in the DB but Password is false // check if user is locked $userIsLocked = 0; $nbAttempts = intval($data['no_bad_attempts'] + 1); if ($_SESSION['settings']['nb_bad_authentication'] > 0 && intval($_SESSION['settings']['nb_bad_authentication']) < $nbAttempts) { $userIsLocked = 1; // log it if (isset($_SESSION['settings']['log_connections']) && $_SESSION['settings']['log_connections'] == 1) { logEvents('user_locked', 'connection', $data['id']); } } DB::update(prefix_table('users'), array('key_tempo' => $_SESSION['key'], 'last_connexion' => time(), 'disabled' => $userIsLocked, 'no_bad_attempts' => $nbAttempts), "id=%i", $data['id']); // What return shoulb we do if ($userIsLocked == 1) { $return = "user_is_locked"; } elseif ($_SESSION['settings']['nb_bad_authentication'] == 0) { $return = "false"; } else { $return = $nbAttempts; } } } else { $return = "false"; } if ($debugDuo == 1) { fputs($dbgDuo, "\n\n----\n" . "Identified : " . $return . "\n"); } echo '[{"value" : "' . $return . '", "user_admin":"', isset($_SESSION['user_admin']) ? $_SESSION['user_admin'] : "", '", "initial_url" : "' . @$_SESSION['initial_url'] . '", "error" : "' . $logError . '"}]'; $_SESSION['initial_url'] = ""; if ($_SESSION['settings']['cpassman_dir'] == "..") { $_SESSION['settings']['cpassman_dir'] = "."; } }
require_once $_SESSION['settings']['cpassman_dir'] . '/includes/libraries/Database/Meekrodb/db.class.php'; DB::$host = $server; DB::$user = $user; DB::$password = $pass; DB::$dbName = $database; DB::$port = $port; DB::$encoding = $encoding; DB::$error_handler = 'db_error_handler'; $link = mysqli_connect($server, $user, $pass, $database, $port); $link->set_charset($encoding); //Load Tree $tree = new SplClassLoader('Tree\\NestedTree', '../includes/libraries'); $tree->register(); $tree = new Tree\NestedTree\NestedTree($pre . 'nested_tree', 'id', 'parent_id', 'title'); //Load AES $aes = new SplClassLoader('Encryption\\Crypt', '../includes/libraries'); $aes->register(); if (!empty($_POST['type'])) { switch ($_POST['type']) { case "groupes_visibles": case "groupes_interdits": $val = explode(';', $_POST['valeur']); $valeur = $_POST['valeur']; // Check if id folder is already stored $data = DB::queryfirstrow("SELECT " . $_POST['type'] . " FROM " . prefix_table("users") . " WHERE id = %i", $val[0]); $new_groupes = $data[$_POST['type']]; if (!empty($data[$_POST['type']])) { $groupes = explode(';', $data[$_POST['type']]); if (in_array($val[1], $groupes)) { $new_groupes = str_replace($val[1], "", $new_groupes); } else {
<?php include_once "autoloader.php"; $autoload = new SplClassLoader(); $autoload->register(); /* * TMP PART * FOR FRAMEWORK DEV */ $tests = new \Test\Test(); $tests->call(0);
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ session_start(); global $k, $settings; header("Content-type: text/html; charset=utf-8"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <?php error_reporting(E_ERROR); include '../includes/include.php'; include '../includes/settings.php'; //Class loader require_once '../sources/SplClassLoader.php'; if (empty($_SESSION['key'])) { $pwgen = new SplClassLoader('Encryption\\PwGen', '../includes/libraries'); $pwgen->register(); $pwgen = new Encryption\PwGen\pwgen(); $pwgen->setLength(20); $pwgen->setSecure(true); $pwgen->setSymbols(true); $pwgen->setCapitalize(true); $pwgen->setNumerals(true); $_SESSION['key'] = $pwgen->generate(); } $_SESSION['prefix_length'] = "15"; // connect to the server require_once '../includes/libraries/Database/Meekrodb/db.class.php'; DB::$host = $server; DB::$user = $user; DB::$password = $pass;
<?php /** * @author: Nicolas Levée * @version 070320141527 */ error_reporting(true); require_once "SplClassLoader.php"; // declaration des autoload SplClassLoader::AutoloadRegister("POM", __DIR__ . "/../src"); SplClassLoader::AutoloadRegister("Exemple", __DIR__ . "/"); // decalaration de l'adapter $adapter = new \POM\Service\Mysql\Adapter("mysql:host=gary.idobs;dbname=nlevee", "nlevee", "devine"); $adapter->connect(); $cursor = $adapter->fetch("SELECT * FROM server_http_config"); foreach ($cursor as $idx => $row) { var_dump($idx, $row); } unset($cursor); $cursor = $adapter->fetch("SELECT * FROM server_http_config WHERE description LIKE :desc", [':desc' => '%CMS%']); foreach ($cursor as $idx => $row) { var_dump($idx, $row); } unset($cursor); $cursor = $adapter->fetch("SELECT * FROM server_http_config WHERE description LIKE :desc", [':desc' => '%WEB%']); foreach ($cursor as $idx => $row) { var_dump($idx, $row); } unset($cursor); var_dump($adapter->fetchOne("SELECT * FROM server_http_config")); $cursor = $adapter->fetchColumn(2, "SELECT * FROM server_http_config");
<?php const DEFAULT_APP = 'Frontend'; // Si l'application n'est pas valide, on va charger l'application par défaut qui se chargera de générer une erreur 404 if (!isset($_GET['app']) || !file_exists(__DIR__ . '/../App/' . $_GET['app'])) { $_GET['app'] = DEFAULT_APP; } // On commence par inclure la classe nous permettant d'enregistrer nos autoload require __DIR__ . '/../lib/OCFram/SplClassLoader.php'; // On va ensuite enregistrer les autoloads correspondant à chaque vendor (OCFram, App, Model, etc.) $OCFramLoader = new SplClassLoader('OCFram', __DIR__ . '/../lib'); $OCFramLoader->register(); $appLoader = new SplClassLoader('App', __DIR__ . '/..'); $appLoader->register(); $modelLoader = new SplClassLoader('Model', __DIR__ . '/../lib/vendors'); $modelLoader->register(); $entityLoader = new SplClassLoader('Entity', __DIR__ . '/../lib/vendors'); $entityLoader->register(); $formBuilderLoader = new SplClassLoader('FormBuilder', __DIR__ . '/../lib/vendors'); $formBuilderLoader->register(); // Il ne nous suffit plus qu'à déduire le nom de la classe et de l'instancier $appClass = 'App\\' . $_GET['app'] . '\\' . $_GET['app'] . 'Application'; $app = new $appClass(); $app->run();