From 8d84152726df2bce052fca4950cddc973f9984cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Tue, 14 Oct 2014 14:13:25 +0200 Subject: [PATCH] Improved Euler Blogpost: - Better links to problems - Show Abbreviated code message - Download link to github - More prominent download button --- www/index.php | 3 +-- www/protected/config/main.php | 2 ++ .../controllers/BlogpostController.php | 5 +++-- www/protected/models/EulerProblem.php | 21 +++++++++++++++++-- .../blogpost/view_ProjectEulerBefunge.php | 4 ++-- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/www/index.php b/www/index.php index fc9fc7f..42a47db 100644 --- a/www/index.php +++ b/www/index.php @@ -9,5 +9,4 @@ defined('YII_DEBUG') or define('YII_DEBUG',true); // dev or prod - merges settings with respective file defined('YII_CUSTOM_ENV') or define('YII_CUSTOM_ENV', 'dev'); -require_once($yii); -Yii::createWebApplication($config)->run(); \ No newline at end of file +require_once($yii); \ No newline at end of file diff --git a/www/protected/config/main.php b/www/protected/config/main.php index cccc39a..403cf59 100644 --- a/www/protected/config/main.php +++ b/www/protected/config/main.php @@ -100,6 +100,8 @@ return ArrayX::merge( 'blog/' => 'blogPost/view/id/', 'blog//' => 'blogPost/view/id/', + 'blog/1//' => 'blogPost/view/id/1', + 'eulerproblem/' => 'eulerproblem/index', 'Highscores/list.php' => 'Highscores/list', // Compatibility diff --git a/www/protected/controllers/BlogpostController.php b/www/protected/controllers/BlogpostController.php index 564fd57..dde7ea1 100644 --- a/www/protected/controllers/BlogpostController.php +++ b/www/protected/controllers/BlogpostController.php @@ -244,8 +244,9 @@ class BlogPostController extends MSController $problems = EulerProblem::model()->findAll(['order'=>'Problemnumber']); $problemnumber = 0; - if (isset($_GET['problem']) AND is_numeric($_GET['problem'])) - $problemnumber = $_GET['problem']; + + if (isset($_GET['problem']) AND is_numeric(preg_replace('/^[Pp]roblem-/', '', $_GET['problem']))) + $problemnumber = preg_replace('/^[Pp]roblem-/', '', $_GET['problem']); $criteria=new CDbCriteria; $criteria->condition='Problemnumber = ' . $problemnumber; diff --git a/www/protected/models/EulerProblem.php b/www/protected/models/EulerProblem.php index 25796d1..200fd97 100644 --- a/www/protected/models/EulerProblem.php +++ b/www/protected/models/EulerProblem.php @@ -124,6 +124,11 @@ class EulerProblem extends CActiveRecord return parent::model($className); } + public function getBlogLink() + { + return '/blog/1/Project_Euler_with_Befunge/problem-' . str_pad($this->Problemnumber, 3, '0', STR_PAD_LEFT); + } + public function getSourcecodefile($absolute = true) { return ($absolute ? '/' : '') . 'data/blog/Befunge/Euler_Problem-' . str_pad($this->Problemnumber, 3, '0', STR_PAD_LEFT) . '.b93'; @@ -152,6 +157,11 @@ class EulerProblem extends CActiveRecord return $this->SolutionWidth <= 80 AND $this->SolutionHeight <= 25; } + public function getRawGithubLink() + { + return 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-' . str_pad($this->Problemnumber, 3, '0', STR_PAD_LEFT) . '.b93'; + } + public function generateMarkdown() { $num_padded = str_pad($this->Problemnumber, 3, '0', STR_PAD_LEFT); @@ -165,13 +175,20 @@ class EulerProblem extends CActiveRecord '```befunge' . PHP_EOL . $this->Code . PHP_EOL . '```' . PHP_EOL . - '[Download](/data/blog/Befunge/Euler_Problem-' . $num_padded . '.b93)' . PHP_EOL . + + ($this->AbbreviatedCode ? + ( + '> **NOTE** ' . PHP_EOL . + '> This program is too big to display here, click **[download]** to see the full program. ' . PHP_EOL . PHP_EOL + ) : ''). + + 'Download' . PHP_EOL . '' . PHP_EOL . $this->Explanation . PHP_EOL . '' . PHP_EOL . '**Interpreter steps:** `' . number_format($this->SolutionSteps, 0, null, ',') . '` ' . PHP_EOL . '**Execution time** ([BefunExec](/programs/view/BefunGen)): `' . number_format($this->SolutionTime, 0, null, ',') . '` ms' . (($this->SolutionTime < 1000) ? (' ') : (' *(= ' . MsHelper::formatMilliseconds($this->SolutionTime) . ')* ')) . PHP_EOL . - '**Program size:** `' . $this->SolutionWidth . 'x' . $this->SolutionHeight . '` ' . PHP_EOL . + '**Program size:** `' . $this->SolutionWidth . 'x' . $this->SolutionHeight . '` ' . ($this->isBefunge93() ? '*(fully valid Befunge-93)*' : '') . ' ' . PHP_EOL . '**Solution:** `' . number_format($this->SolutionValue, 0, null, ',') . '` '; } } diff --git a/www/protected/views/blogpost/view_ProjectEulerBefunge.php b/www/protected/views/blogpost/view_ProjectEulerBefunge.php index 091e1a1..05cd4a8 100644 --- a/www/protected/views/blogpost/view_ProjectEulerBefunge.php +++ b/www/protected/views/blogpost/view_ProjectEulerBefunge.php @@ -75,7 +75,7 @@ array_push($this->css_files, "/css/blogpost_ProjectEulerBefunge_style.css"); echo '' . "\r\n"; echo '' . $problem->Problemnumber . "\r\n"; - echo '' . $problem->Problemtitle . "\r\n"; + echo '' . $problem->Problemtitle . "\r\n"; echo '
' . MsHelper::formatMilliseconds($problem->SolutionTime) . "
\r\n"; if ($problem->isBefunge93()) @@ -118,7 +118,7 @@ array_push($this->css_files, "/css/blogpost_ProjectEulerBefunge_style.css"); array_push($pagination, [ 'label' => str_pad($problems[$i]->Problemnumber, 3, '0', STR_PAD_LEFT), - 'url' => '?problem=' . $problems[$i]->Problemnumber, + 'url' => $problems[$i]->getBlogLink(), 'disabled' => false, 'active' => $currproblemID == $i, ]);