1
0

Improved Euler Blogpost:

- Better links to problems
   - Show Abbreviated code message
   - Download link to github
   - More prominent download button
This commit is contained in:
Mike Schwörer 2014-10-14 14:13:25 +02:00
parent a83b746f9d
commit 8d84152726
5 changed files with 27 additions and 8 deletions

View File

@ -9,5 +9,4 @@ defined('YII_DEBUG') or define('YII_DEBUG',true);
// dev or prod - merges settings with respective file // dev or prod - merges settings with respective file
defined('YII_CUSTOM_ENV') or define('YII_CUSTOM_ENV', 'dev'); defined('YII_CUSTOM_ENV') or define('YII_CUSTOM_ENV', 'dev');
require_once($yii); require_once($yii);
Yii::createWebApplication($config)->run();

View File

@ -100,6 +100,8 @@ return ArrayX::merge(
'blog/<id>' => 'blogPost/view/id/<id>', 'blog/<id>' => 'blogPost/view/id/<id>',
'blog/<id>/<name>' => 'blogPost/view/id/<id>', 'blog/<id>/<name>' => 'blogPost/view/id/<id>',
'blog/1/<name>/<problem>' => 'blogPost/view/id/1',
'eulerproblem/' => 'eulerproblem/index', 'eulerproblem/' => 'eulerproblem/index',
'Highscores/list.php' => 'Highscores/list', // Compatibility 'Highscores/list.php' => 'Highscores/list', // Compatibility

View File

@ -244,8 +244,9 @@ class BlogPostController extends MSController
$problems = EulerProblem::model()->findAll(['order'=>'Problemnumber']); $problems = EulerProblem::model()->findAll(['order'=>'Problemnumber']);
$problemnumber = 0; $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=new CDbCriteria;
$criteria->condition='Problemnumber = ' . $problemnumber; $criteria->condition='Problemnumber = ' . $problemnumber;

View File

@ -124,6 +124,11 @@ class EulerProblem extends CActiveRecord
return parent::model($className); 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) public function getSourcecodefile($absolute = true)
{ {
return ($absolute ? '/' : '') . 'data/blog/Befunge/Euler_Problem-' . str_pad($this->Problemnumber, 3, '0', STR_PAD_LEFT) . '.b93'; 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; 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() public function generateMarkdown()
{ {
$num_padded = str_pad($this->Problemnumber, 3, '0', STR_PAD_LEFT); $num_padded = str_pad($this->Problemnumber, 3, '0', STR_PAD_LEFT);
@ -165,13 +175,20 @@ class EulerProblem extends CActiveRecord
'```befunge' . PHP_EOL . '```befunge' . PHP_EOL .
$this->Code . PHP_EOL . $this->Code . PHP_EOL .
'```' . 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
) : '').
'<a class="btn btn-primary" href="' . $this->getRawGithubLink() . '">Download</a>' . PHP_EOL .
'' . PHP_EOL . '' . PHP_EOL .
$this->Explanation . PHP_EOL . $this->Explanation . PHP_EOL .
'' . PHP_EOL . '' . PHP_EOL .
'**Interpreter steps:** `' . number_format($this->SolutionSteps, 0, null, ',') . '` ' . 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 . '**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, ',') . '` '; '**Solution:** `' . number_format($this->SolutionValue, 0, null, ',') . '` ';
} }
} }

View File

@ -75,7 +75,7 @@ array_push($this->css_files, "/css/blogpost_ProjectEulerBefunge_style.css");
echo '<tr class="PEB_tablerowProblems">' . "\r\n"; echo '<tr class="PEB_tablerowProblems">' . "\r\n";
echo '<td class="PEB_tablecellProblems PEB_TC_Number">' . $problem->Problemnumber . "</td>\r\n"; echo '<td class="PEB_tablecellProblems PEB_TC_Number">' . $problem->Problemnumber . "</td>\r\n";
echo '<td class="PEB_tablecellProblems PEB_TC_Title"><a href="?problem=' . $problems[$i]->Problemnumber . '">' . $problem->Problemtitle . "</a></td>\r\n"; echo '<td class="PEB_tablecellProblems PEB_TC_Title"><a href="' . $problems[$i]->getBlogLink() . '">' . $problem->Problemtitle . "</a></td>\r\n";
echo '<td class="PEB_tablecellProblems"><div class="PEB_TC_Time PEB_TC_Timelevel_' . $problem->getTimeScore() . '">' . MsHelper::formatMilliseconds($problem->SolutionTime) . "</div></td>\r\n"; echo '<td class="PEB_tablecellProblems"><div class="PEB_TC_Time PEB_TC_Timelevel_' . $problem->getTimeScore() . '">' . MsHelper::formatMilliseconds($problem->SolutionTime) . "</div></td>\r\n";
if ($problem->isBefunge93()) if ($problem->isBefunge93())
@ -118,7 +118,7 @@ array_push($this->css_files, "/css/blogpost_ProjectEulerBefunge_style.css");
array_push($pagination, array_push($pagination,
[ [
'label' => str_pad($problems[$i]->Problemnumber, 3, '0', STR_PAD_LEFT), 'label' => str_pad($problems[$i]->Problemnumber, 3, '0', STR_PAD_LEFT),
'url' => '?problem=' . $problems[$i]->Problemnumber, 'url' => $problems[$i]->getBlogLink(),
'disabled' => false, 'disabled' => false,
'active' => $currproblemID == $i, 'active' => $currproblemID == $i,
]); ]);