/** * Bootstraps the application. * * This method is called after all services are registers * and should be used for "dynamic" configuration (whenever * a service must be requested). */ public function boot(Application $app) { if (isset($app['translator'])) { $paths = getPaths($app); $app['translator']->addLoader('yml', new TranslationLoader\YamlFileLoader()); // Directory to look for translation file(s) $translationDir = $paths['apppath'] . '/resources/translations/' . $app['locale']; if (is_dir($translationDir)) { $iterator = new \DirectoryIterator($translationDir); /** * @var \SplFileInfo $fileInfo */ foreach ($iterator as $fileInfo) { if ($fileInfo->isFile() && getExtension($fileInfo->getFilename()) == "yml") { $fnameParts = explode(".", $fileInfo->getFilename()); $domain = $fnameParts[0]; $app['translator']->addResource('yml', $fileInfo->getRealPath(), $app['locale'], $domain); } } } // Load fallback for infos domain $infosfilename = dirname(dirname(dirname(__DIR__))) . '/resources/translations/en/infos.en.yml'; if (is_readable($infosfilename)) { $app['translator']->addResource('yml', $infosfilename, 'en', 'infos'); } } }
function autoLoad($className) { foreach (getPaths($className) as $path) { if (file_exists($path)) { require_once $path; return; } } }
/** * Print a 'low level' error page, and quit. The user has to fix something. * * @param string $message */ private function lowlevelError($message) { $paths = getPaths(); $html = <<<EOM <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Bolt - Error</title> <link rel="stylesheet" type="text/css" href="%path%view/css/bootstrap.min.css" /> </head> <body style="padding: 20px;"> <div style="max-width: 530px; margin: auto;"> <h1>Bolt - Error.</h1> <p><strong>%error%</strong></p> <p>This is a fatal error. Please fix the error, and refresh the page. Bolt can not run, until this error has been corrected. <br> Make sure you've read the instructions in the documentation for help. If you can't get it to work, post a message on our forum, and we'll try to help you out. Be sure to include the exact error message you're getting!</p> <ul> <li><a href="http://docs.bolt.cm/setup">Bolt documentation - Setup</a></li> <li><a href="http://forum.pivotx.net/viewforum.php?f=17">Bolt discussion forum</a></li> </ul> </div> <hr> </body> </html> EOM; $html = str_replace("%error%", $message, $html); $html = str_replace("%path%", $paths['app'], $html); echo $html; die; }
protected function execute(InputInterface $input, OutputInterface $output) { $deps = $this->getApplication()->getDependancies(); $client = $deps['openphoto']; $logger = $deps['logger']; $dir = $input->getArgument('folder'); ini_set('memory_limit', '1G'); $hashs = getHashs($client, $logger); $paths = getPaths($dir); $cpt = 0; $logger->log(sprintf('%s photos on openphoto', count($hashs))); $logger->setTotal(count($paths)); foreach ($paths as $pathName) { $cpt++; $logger->setPosition($cpt); uploadFile($client, $logger, $deps['exiftran.path'], $hashs, $pathName); } $logger->setTotal(null); $newHashs = getHashs($client, $logger); $logger->log(sprintf('%s photos added', count($newHashs) - count($hashs))); $logger->log(sprintf('%s photos now on openphoto', count($hashs))); }
public static function record(Silex\Application $app, $contenttypeslug, $slug) { $contenttype = $app['storage']->getContentType($contenttypeslug); $slug = makeSlug($slug, -1); // First, try to get it by slug. $content = $app['storage']->getContent($contenttype['slug'], array('slug' => $slug, 'returnsingle' => true)); if (!$content && is_numeric($slug)) { // And otherwise try getting it by ID $content = $app['storage']->getContent($contenttype['slug'], array('id' => $slug, 'returnsingle' => true)); } // No content, no page! if (!$content) { // There's one special edge-case we check for: if the request is for the backend, without trailing // slash and it is intercepted by custom routing, we forward the client to that location. if ($slug == trim($app['config']->get('general/branding/path'), "/")) { simpleredirect($app['config']->get('general/branding/path') . "/"); } $app->abort(404, "Page {$contenttypeslug}/{$slug} not found."); } // Then, select which template to use, based on our 'cascading templates rules' $template = $content->template(); // Fallback: If file is not OK, show an error page $filename = $app['paths']['themepath'] . "/" . $template; if (!file_exists($filename) || !is_readable($filename)) { $error = sprintf("No template for '%s' defined. Tried to use '%s/%s'.", $content->getTitle(), basename($app['config']->get('general/theme')), $template); $app['log']->setValue('templateerror', $error); $app->abort(404, $error); } // Setting the canonical path and the editlink. $app['canonicalpath'] = $content->link(); $app['paths'] = getPaths($app); $app['editlink'] = path('editcontent', array('contenttypeslug' => $contenttype['slug'], 'id' => $content->id)); $app['edittitle'] = $content->getTitle(); // Make sure we can also access it as {{ page.title }} for pages, etc. We set these in the global scope, // So that they're also available in menu's and templates rendered by extensions. $app['twig']->addGlobal('record', $content); $app['twig']->addGlobal($contenttype['singular_slug'], $content); // Render the template and return. return $app['render']->render($template); }
return array($fullFile, $oldFile, $isFull); } function doInc($fullFile, $oldFile, $isFull, $chunkSize) { $dUtil = new DiffUtil(); //echo("isFull::$isFull\n"); if ($isFull) { if (file_exists($fullFile)) { $content = $dUtil->readFile($fullFile); echo $content; } else { header('HTTP/1.1 404 Not Found'); echo "not found!"; } } else { if (file_exists($fullFile)) { $resultFile = $dUtil->makeIncDataFromFile($oldFile, $fullFile, $chunkSize); //var_dump($resultFile); $content = json_encode($resultFile); echo $content; } else { header('HTTP/1.1 404 Not Found'); echo "not found!"; } } } list($newFile, $oldFile, $isFull) = getPaths(); doInc($newFile, $oldFile, $isFull, 12); //echo("newFile: $newFile\n"); //echo("oldFile: $oldFile\n"); // echo("isFull: $isFull\n");
}); } $app->after(function (Request $request, Response $response) use($app) { $end = !empty($app['end']) ? $app['end'] : false; if ($end == "frontend") { $html = $response->getContent(); // Insert our 'generator' after the last <meta ..> tag. $app['extensions']->insertSnippet('aftermeta', '<meta name="generator" content="Bolt">'); $html = $app['extensions']->processSnippetQueue($html); $response->setContent($html); } }); /** * Error page. */ $app->error(function (Exception $e) use($app) { $twigvars = array(); $twigvars['class'] = get_class($e); $twigvars['message'] = $e->getMessage(); $twigvars['code'] = $e->getCode(); $twigvars['paths'] = getPaths($app['config']); $trace = $e->getTrace(); foreach ($trace as $key => $value) { if (!empty($value['file']) && strpos($value['file'], "/vendor/") > 0) { unset($trace[$key]['args']); } } $twigvars['trace'] = $trace; $twigvars['title'] = "An error has occured!"; return $app['twig']->render('error.twig', $twigvars); });
$app->register(new Silex\Provider\SwiftmailerServiceProvider()); $app->register(new Silex\Provider\UrlGeneratorServiceProvider()); $app->register(new Silex\Provider\FormServiceProvider()); $app->register(new Silex\Provider\ValidatorServiceProvider()); $app->register(new Silex\Provider\TranslationServiceProvider(), array('translator.messages' => array())); // Loading stub functions for when intl / IntlDateFormatter isn't available. if (!function_exists('intl_get_error_code')) { require_once __DIR__ . '/../vendor/symfony/Locale/Symfony/Component/Locale/Resources/stubs/functions.php'; require_once __DIR__ . '/../vendor/symfony/Locale/Symfony/Component/Locale/Resources/stubs/IntlDateFormatter.php'; } $app->register(new Bolt\LogServiceProvider(), array()); $app->register(new Bolt\StorageServiceProvider(), array()); $app->register(new Bolt\UsersServiceProvider(), array()); $app->register(new Bolt\CacheServiceProvider(), array()); $app->register(new Bolt\ExtensionServiceProvider(), array()); $app['paths'] = getPaths($config); $app['editlink'] = ""; // Add the Bolt Twig functions, filters and tags. $app['twig']->addExtension(new Bolt\TwigExtension()); $app['twig']->addTokenParser(new Bolt\SetcontentTokenParser()); // If debug is set, we set up the custom error handler.. if ($app['debug']) { ini_set("display_errors", "1"); error_reporting(E_ALL); $old_error_handler = set_error_handler("userErrorHandler"); } else { error_reporting(E_ALL ^ E_NOTICE); // error_reporting( E_ALL ^ E_NOTICE ^ E_WARNING ); } require_once __DIR__ . '/app_backend.php'; require_once __DIR__ . '/app_asynchronous.php';
function getPaths($graph, $current, $end, $currentPath) { if ($end == $current) { global $allPaths; $allPaths[] = $currentPath; return; } foreach ($graph[$current] as $key => $value) { if (checkNodePresentMoreThen2($currentPath, $value)) { $currentPath[] = $value; getPaths($graph, $value, $end, $currentPath); } } return; }
/** * Handle errors thrown in the application. Set up whoops, if set in conf * * @param \Exception $exception * @return Response */ public function ErrorHandler(\Exception $exception) { // If we are in maintenance mode and current user is not logged in, show maintenance notice. // @see /app/src/Bolt/Controllers/Frontend.php, Frontend::before() if ($this['config']->get('general/maintenance_mode')) { $user = $this['users']->getCurrentUser(); if ($user['userlevel'] < 2) { $template = $this['config']->get('general/maintenance_template'); $body = $this['render']->render($template); return new Response($body, 503); } } $paths = getPaths($this['config']); $twigvars = array(); $twigvars['class'] = get_class($exception); $twigvars['message'] = $exception->getMessage(); $twigvars['code'] = $exception->getCode(); $twigvars['paths'] = $paths; $this['log']->add($twigvars['message'], 2, '', 'abort'); $end = $this['config']->getWhichEnd(); $trace = $exception->getTrace(); foreach ($trace as $key => $value) { if (!empty($value['file']) && strpos($value['file'], '/vendor/') > 0) { unset($trace[$key]['args']); } // Don't display the full path.. if (isset($trace[$key]['file'])) { $trace[$key]['file'] = str_replace(BOLT_PROJECT_ROOT_DIR, '[root]', $trace[$key]['file']); } } $twigvars['trace'] = $trace; $twigvars['title'] = 'An error has occurred!'; if ($exception instanceof HttpException && $end == 'frontend') { $content = $this['storage']->getContent($this['config']->get('general/notfound'), array('returnsingle' => true)); // Then, select which template to use, based on our 'cascading templates rules' if ($content instanceof \Bolt\Content && !empty($content->id)) { $template = $content->template(); return $this['render']->render($template, $content->getTemplateContext()); } $twigvars['message'] = "The page could not be found, and there is no 'notfound' set in 'config.yml'. Sorry about that."; } return $this['render']->render('error.twig', $twigvars); }
function getNode($path, $language = "") { path_db_load(); //if (isset($_SESSION['murrix']['pathcache_node'][$path])) // return $_SESSION['murrix']['pathcache_node'][$path]; // We have a cachemiss, resolve manually global $db_prefix, $root_id; // Nothing found i cache if (empty($path)) // We are att the root return -2; $parent_id = getNode(GetParentPath($path), $language); if ($parent_id == -2) return $root_id; else if ($parent_id == -1) return -1; $name = basename($path); if (empty($language)) $language = $_SESSION['murrix']['language']; $query = "SELECT objects.node_id AS node_id FROM `".$db_prefix."objects` AS `objects`, `".$db_prefix."links` AS `links` WHERE objects.name = '$name' AND links.type = 'sub' AND links.node_top = '$parent_id' AND links.node_bottom = objects.node_id ORDER BY objects.version ASC LIMIT 1"; $result = mysql_query($query) or die("getNode: " . mysql_errno() . " " . mysql_error()); if (mysql_num_rows($result) == 0) return -1; else { $row = mysql_fetch_array($result, MYSQL_ASSOC); $node_id = $row['node_id']; } if ($language == $_SESSION['murrix']['language']) { // We want to cache all paths getPaths($node_id, $name); } return $node_id; }
<table class="table table-striped"> <tbody> <?php if (isset($_GET['path'])) { $line = $_GET['line']; $poids = recupData($line, $_GET['path'], $bdd); } else { if (isset($_GET['line'])) { $path = getPaths($bdd, $_GET['line']); viewPath($path, $_GET['line']); } else { $lines = getLines($bdd); viewLines2($lines); } } ?> </tbody> </table>
if ($end == "frontend") { $html = $response->getContent(); // Insert our 'generator' after the last <meta ..> tag. // @todo Find a neat solution for this if (stripos($response->headers->get('Content-Type'), 'xml') === false) { $app['extensions']->insertSnippet('aftermeta', '<meta name="generator" content="Bolt">'); } $html = $app['extensions']->processSnippetQueue($html); $response->setContent($html); } }); /** * Error page. */ $app->error(function (Exception $e) use($app) { $paths = getPaths($app['config']); $twigvars = array(); $twigvars['class'] = get_class($e); $twigvars['message'] = $e->getMessage(); $twigvars['code'] = $e->getCode(); $twigvars['paths'] = $paths; $trace = $e->getTrace(); foreach ($trace as $key => $value) { if (!empty($value['file']) && strpos($value['file'], "/vendor/") > 0) { unset($trace[$key]['args']); } // Don't display the full path.. $trace[$key]['file'] = str_replace($paths['rootpath'], "[root]", $trace[$key]['file']); } $twigvars['trace'] = $trace; $twigvars['title'] = "An error has occured!";
/** * Get an associative array with the correct options for the chosen database type. * * @return array */ public function getDBOptions() { $configdb = $this->data['general']['database']; if (isset($configdb['driver']) && in_array($configdb['driver'], array('pdo_sqlite', 'sqlite'))) { $basename = isset($configdb['databasename']) ? basename($configdb['databasename']) : 'bolt'; if (getExtension($basename) != 'db') { $basename .= '.db'; } if (isset($configdb["path"])) { $configpaths = getPaths(); if (substr($configdb['path'], 0, 1) !== "/") { $configdb["path"] = $configpaths["rootpath"] . "/" . $configdb["path"]; } } $dboptions = array('driver' => 'pdo_sqlite', 'path' => isset($configdb['path']) ? realpath($configdb["path"]) . "/" . $basename : __DIR__ . '/../../database/' . $basename, 'randomfunction' => 'RANDOM()'); } else { // Assume we configured it correctly. Yeehaa! if (empty($configdb['password'])) { $configdb['password'] = ''; } $driver = isset($configdb['driver']) ? $configdb['driver'] : 'pdo_mysql'; $randomfunction = ''; if (in_array($driver, array('mysql', 'mysqli'))) { $driver = 'pdo_mysql'; $randomfunction = 'RAND()'; } if (in_array($driver, array('postgres', 'postgresql'))) { $driver = 'pdo_pgsql'; $randomfunction = 'RANDOM()'; } $dboptions = array('driver' => $driver, 'host' => isset($configdb['host']) ? $configdb['host'] : 'localhost', 'dbname' => $configdb['databasename'], 'user' => $configdb['username'], 'password' => $configdb['password'], 'randomfunction' => $randomfunction); $dboptions['charset'] = isset($configdb['charset']) ? $configdb['charset'] : 'utf8'; } switch ($dboptions['driver']) { case 'pdo_mysql': $dboptions['port'] = isset($configdb['port']) ? $configdb['port'] : '3306'; $dboptions['reservedwords'] = explode(',', 'accessible,add,all,alter,analyze,and,as,asc,asensitive,before,between,' . 'bigint,binary,blob,both,by,call,cascade,case,change,char,character,check,collate,column,condition,constraint,' . 'continue,convert,create,cross,current_date,current_time,current_timestamp,current_user,cursor,database,databases,' . 'day_hour,day_microsecond,day_minute,day_second,dec,decimal,declare,default,delayed,delete,desc,describe,' . 'deterministic,distinct,distinctrow,div,double,drop,dual,each,else,elseif,enclosed,escaped,exists,exit,explain,' . 'false,fetch,float,float4,float8,for,force,foreign,from,fulltext,get,grant,group,having,high_priority,hour_microsecond,' . 'hour_minute,hour_second,if,ignore,in,index,infile,inner,inout,insensitive,insert,int,int1,int2,int3,int4,int8,' . 'integer,interval,into,io_after_gtids,io_before_gtids,is,iterate,join,key,keys,kill,leading,leave,left,like,limit,' . 'linear,lines,load,localtime,localtimestamp,lock,long,longblob,longtext,loop,low_priority,master_bind,' . 'master_ssl_verify_server_cert,match,maxvalue,mediumblob,mediumint,mediumtext,middleint,minute_microsecond,' . 'minute_second,mod,modifies,natural,nonblocking,not,no_write_to_binlog,null,numeric,on,optimize,option,optionally,' . 'or,order,out,outer,outfile,partition,precision,primary,procedure,purge,range,read,reads,read_write,real,references,' . 'regexp,release,rename,repeat,replace,require,resignal,restrict,return,revoke,right,rlike,schema,schemas,' . 'second_microsecond,select,sensitive,separator,set,show,signal,smallint,spatial,specific,sql,sqlexception,sqlstate,' . 'sqlwarning,sql_big_result,sql_calc_found_rows,sql_small_result,ssl,starting,straight_join,table,terminated,then,' . 'tinyblob,tinyint,tinytext,to,trailing,trigger,true,undo,union,unique,unlock,unsigned,update,usage,use,using,utc_date,' . 'utc_time,utc_timestamp,values,varbinary,varchar,varcharacter,varying,when,where,while,with,write,xor,year_month,' . 'zerofill,nonblocking'); break; case 'pdo_sqlite': $dboptions['reservedwords'] = explode(',', 'abort,action,add,after,all,alter,analyze,and,as,asc,attach,autoincrement,' . 'before,begin,between,by,cascade,case,cast,check,collate,column,commit,conflict,constraint,create,cross,current_date,' . 'current_time,current_timestamp,database,default,deferrable,deferred,delete,desc,detach,distinct,drop,each,else,end,' . 'escape,except,exclusive,exists,explain,fail,for,foreign,from,full,glob,group,having,if,ignore,immediate,in,index,' . 'indexed,initially,inner,insert,instead,intersect,into,is,isnull,join,key,left,like,limit,match,natural,no,not,' . 'notnull,null,of,offset,on,or,order,outer,plan,pragma,primary,query,raise,references,regexp,reindex,release,rename,' . 'replace,restrict,right,rollback'); break; case 'pdo_pgsql': $dboptions['port'] = isset($configdb['port']) ? $configdb['port'] : '5432'; $dboptions['reservedwords'] = explode(',', 'all,analyse,analyze,and,any,as,asc,authorization,between,bigint,binary,bit,' . 'boolean,both,case,cast,char,character,check,coalesce,collate,column,constraint,convert,create,cross,current_date,' . 'current_time,current_timestamp,current_user,dec,decimal,default,deferrable,desc,distinct,do,else,end,except,exists,' . 'extract,float,for,foreign,freeze,from,full,grant,group,having,ilike,in,initially,inner,int,integer,intersect,interval,' . 'into,is,isnull,join,leading,left,like,limit,localtime,localtimestamp,natural,nchar,new,none,not,notnull,null,nullif,' . 'numeric,off,offset,old,on,only,or,order,outer,overlaps,overlay,placing,position,primary,real,references,right,row,' . 'select,session_user,setof,similar,smallint,some,substring,table,then,time,timestamp,to,trailing,treat,trim,union,' . 'unique,user,using,varchar,verbose,when,where,false,true'); } return $dboptions; }
private function setCKPath() { $this->paths = getPaths($this); // Make sure the paths for CKeditor config are always set correctly.. $this->set('general/wysiwyg/ck/contentsCss', array($this->paths['app'] . 'view/lib/ckeditor/contents.css', $this->paths['app'] . 'view/css/ckeditor.css')); $this->set('general/wysiwyg/filebrowser/browseUrl', $this->paths['async'] . "filebrowser/"); $this->set('general/wysiwyg/filebrowser/imageBrowseUrl', $this->paths['bolt'] . "files/files"); }