diff --git a/.gitignore b/.gitignore index 56119a3..a87012e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea demos #www/images/programs -workspace.xml \ No newline at end of file +workspace.xml +*.secret \ No newline at end of file diff --git a/www/protected/commands/EGH_RefreshCommand.php b/www/protected/commands/EGH_RefreshCommand.php new file mode 100644 index 0000000..45c2691 --- /dev/null +++ b/www/protected/commands/EGH_RefreshCommand.php @@ -0,0 +1,30 @@ +setSessionOutput(false); + $v->setRawDataPath('/var/www/website/www/protected/data/git_graph_raw.dat'); + $v->setFinDataPath('/var/www/website/www/protected/data/git_graph_data.dat'); + $v->setToken(file_get_contents('/var/www/website/www/protected/commands/github.token.secret')); + + //########################################################## + + $v->addSecondaryUsername("Sam-Development"); + $v->addSecondaryRepository("Anastron/ColorRunner"); + + //########################################################## + + //$v->setToken(file_get_contents('api_token.secret')); + $v->collect(); + + //########################################################## + + $v->generateAndSave(); + } +} \ No newline at end of file diff --git a/www/protected/components/extendedgitgraph/ExtendedGitGraph.php b/www/protected/components/extendedgitgraph/ExtendedGitGraph.php index 751d775..5673163 100644 --- a/www/protected/components/extendedgitgraph/ExtendedGitGraph.php +++ b/www/protected/components/extendedgitgraph/ExtendedGitGraph.php @@ -30,6 +30,12 @@ class ExtendedGitGraph { private $startdate = null; private $enddate = null; + private $sessionOutput = true; + private $basicAuth = null; + + private $FILE_RAW_DATA = 'protected/data/git_graph_raw.dat'; + private $FILE_FINISHED_DATA = 'protected/data/git_graph_data.dat'; + public function __construct($usr_name) { $this->username = $usr_name; } @@ -44,6 +50,14 @@ class ExtendedGitGraph { setToken($result); } + public function setSessionOutput($sout) { $this->sessionOutput = $sout; } + + public function setRawDataPath($rdp) { $this->FILE_RAW_DATA = $rdp; } + + public function setFinDataPath($fdp) { $this->FILE_FINISHED_DATA = $fdp; } + + public function setBasicAuthentication($usr, $passw) { $this->basicAuth = "Authorization: Basic " . base64_encode($usr . ":" . $passw); } + public function setToken($token) { $this->token = $token; $this->tokenHeader = 'access_token=' . $token . '&token_type=bearer'; @@ -117,7 +131,23 @@ class ExtendedGitGraph { } private function getJSON($url) { - $options = array('http' => array('user_agent'=> $_SERVER['HTTP_USER_AGENT'])); + if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) { + $options = ['http' => ['user_agent'=> $_SERVER['HTTP_USER_AGENT']]]; + } else { + $options = ['http' => ['user_agent'=> 'ExtendedGitGraph_for_mikescher.com']]; + } + + if ($this->basicAuth != null) { + $options = + [ + 'http' => + [ + 'user_agent' => $options['http']['user_agent'], + 'header' => $this->basicAuth, + ] + ]; + } + $context = stream_context_create($options); $response = @file_get_contents($url, false, $context); @@ -214,29 +244,36 @@ class ExtendedGitGraph { 'commits' => $this->commits, ]); - file_put_contents(self::FILE_RAW_DATA, $save); + file_put_contents($this->FILE_RAW_DATA, $save); $this->output_flushed('Finished saving data'); } public function output_flushed_clear() { - if (session_status() !== PHP_SESSION_ACTIVE) session_start(); + if ($this->sessionOutput) { + if (session_status() !== PHP_SESSION_ACTIVE) session_start(); - $_SESSION[self::PROGRESS_SESSION_COOKIE] = ''; - session_commit(); + $_SESSION[self::PROGRESS_SESSION_COOKIE] = ''; + session_commit(); + } } public function output_flushed($txt) { - if (session_status() !== PHP_SESSION_ACTIVE) session_start(); + if ($this->sessionOutput) { + if (session_status() !== PHP_SESSION_ACTIVE) session_start(); - $_SESSION[self::PROGRESS_SESSION_COOKIE] .= '[' . date('H:i.s') . '] ' . $txt . "\r\n"; - session_commit(); + $_SESSION[self::PROGRESS_SESSION_COOKIE] .= '[' . date('H:i.s') . '] ' . $txt . "\r\n"; + session_commit(); + } else { + print $txt; + print "\n"; + } } public function loadData() { - $data = unserialize(file_get_contents(self::FILE_RAW_DATA)); + $data = unserialize(file_get_contents($this->FILE_RAW_DATA)); $this->repositories = $data['repositories']; $this->commits = $data['commits']; @@ -265,7 +302,7 @@ class ExtendedGitGraph { $this->generateCommitMap(); - file_put_contents(self::FILE_FINISHED_DATA, + file_put_contents($this->FILE_FINISHED_DATA, serialize( [ 'creation' => new DateTime(), @@ -490,12 +527,12 @@ class ExtendedGitGraph { } public function loadFinishedContent() { - $data = unserialize(file_get_contents(self::FILE_FINISHED_DATA)); + $data = unserialize(file_get_contents($this->FILE_FINISHED_DATA)); return $data['content']; } public function loadFinishedData() { - $data = unserialize(file_get_contents(self::FILE_FINISHED_DATA)); + $data = unserialize(file_get_contents($this->FILE_FINISHED_DATA)); return $data; } diff --git a/www/protected/config/console.php b/www/protected/config/console.php index 346a976..2e0be5e 100644 --- a/www/protected/config/console.php +++ b/www/protected/config/console.php @@ -1,37 +1,64 @@ dirname(__FILE__).DIRECTORY_SEPARATOR.'..', - 'name'=>'My Console Application', +return [ + 'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..', + 'name' => 'Mikescher.com - Console', - // preloading 'log' component - 'preload'=>array('log'), + // preloading 'log' component + 'preload' => + [ + 'log' + ], - // application components - 'components'=>array( - 'db'=>array( - 'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db', - ), - // uncomment the following to use a MySQL database - /* - 'db'=>array( - 'connectionString' => 'mysql:host=localhost;dbname=testdrive', - 'emulatePrepare' => true, - 'username' => 'root', - 'password' => '', - 'charset' => 'utf8', - ), - */ - 'log'=>array( - 'class'=>'CLogRouter', - 'routes'=>array( - array( - 'class'=>'CFileLogRoute', - 'levels'=>'error, warning', - ), - ), - ), - ), -); \ No newline at end of file + 'aliases' => + [ + 'bootstrap' => realpath(__DIR__ . '/../extensions/bootstrap'), // change this if necessary + ], + + // autoloading model and component classes + 'import' => + [ + 'application.models.*', + 'application.extensions.*', + 'application.components.*', + 'application.components.widgets.*', + 'application.components.extendedgitgraph.*', + 'application.components.parsedown.*', + 'bootstrap.components.*', + 'bootstrap.behaviors.*', + 'bootstrap.helpers.*', + 'bootstrap.widgets.*', + ], + + 'modules' => + [ + // + ], + + // application components + 'components' => + [ + 'log' => + [ + 'class' => 'CLogRouter', + 'routes' => + [ + [ + 'class' => 'CFileLogRoute', + 'levels' => 'error, warning', + ], + ], + ], + ], + + // application-level parameters that can be accessed + // using Yii::app()->params['paramName'] + 'params' => + [ + 'yii.debug' => defined('YII_DEBUG'), + 'yii.traceLevel' => 3, + 'yii.handleErrors' => defined('YII_DEBUG'), + // this is used in contact page + 'adminEmail' => 'kundenservice@mikescher.de', + ], + ]; \ No newline at end of file diff --git a/www/protected/config/main.php b/www/protected/config/main.php index d7140be..28008c3 100644 --- a/www/protected/config/main.php +++ b/www/protected/config/main.php @@ -140,9 +140,10 @@ return ArrayX::merge( 'tablePrefix' => 'ms4_', ], - 'counter' => array( - 'class' => 'UserCounter', - ), + 'counter' => + [ + 'class' => 'UserCounter', + ], ], // application-level parameters that can be accessed diff --git a/www/protected/views/msmain/admin_egh_ajaxReload.php b/www/protected/views/msmain/admin_egh_ajaxReload.php index 1e7e0dc..6a052eb 100644 --- a/www/protected/views/msmain/admin_egh_ajaxReload.php +++ b/www/protected/views/msmain/admin_egh_ajaxReload.php @@ -3,11 +3,11 @@ include 'extendedGitGraph.php'; $v = new ExtendedGitGraph('Mikescher'); +$v->setSessionOutput(true); //########################################################## $v->addSecondaryUsername("Sam-Development"); - $v->addSecondaryRepository("Anastron/ColorRunner"); //##########################################################