Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mark Deepwell
committed
Nov 17, 2011
1 parent
fb2b5c1
commit 295f88d
Showing
9 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
cache/* | |||
data/sfWebBrowserPlugin/* | |||
log/* | |||
web/uploads/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,40 @@ | |||
<?php | |||
|
|||
/** | |||
* home actions. | |||
* | |||
* @package sf_sandbox | |||
* @subpackage home | |||
* @author Your name here | |||
* @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ | |||
*/ | |||
class homeActions extends sfActions | |||
{ | |||
/** | |||
* Executes index action | |||
* | |||
* @param sfRequest $request A request object | |||
*/ | |||
public function executeIndex(sfWebRequest $request) | |||
{ | |||
// get list of files | |||
$files = array(); | |||
$upload_directory = sfConfig::get('sf_upload_dir'); | |||
if ($handle = opendir($upload_directory)) | |||
{ | |||
while (false !== ($file = readdir($handle))) | |||
{ | |||
if (substr($file, -4) == 'html') | |||
{ | |||
$files[] = $file; | |||
} | |||
} | |||
closedir($handle); | |||
} | |||
|
|||
// sort by newest on top | |||
rsort($files); | |||
|
|||
$this->files = $files; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
<h2>Cached files</h2> | |||
|
|||
<ul> | |||
<?php foreach ($files as $file): ?> | |||
<li><a href="/uploads/<?php echo $file ?>"><?php echo $file ?></a></li> | |||
<?php endforeach ?> | |||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,7 +1,7 @@ | |||
all: | all: | ||
doctrine: | # doctrine: | ||
class: sfDoctrineDatabase | # class: sfDoctrineDatabase | ||
param: | # param: | ||
dsn: 'sqlite:/tmp/sf_sandbox/data/sandbox.db' | # dsn: 'sqlite:/tmp/sf_sandbox/data/sandbox.db' | ||
username: root | # username: root | ||
password: null | # password: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,4 +1,4 @@ | |||
[symfony] | [symfony] | ||
name=sf_sandbox | name=Cache Tumblr | ||
author=Your name here | author=Mark Deepwell | ||
orm=Doctrine | orm=Doctrine |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,58 @@ | |||
<?php | |||
/** | |||
* Cache tumbler admin homepage. | |||
*/ | |||
class tumblrCacheTask extends sfBaseTask | |||
{ | |||
public function configure() | |||
{ | |||
// use frontend app so we get app.yml config params | |||
$this->addOptions(array( | |||
new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'frontend'), | |||
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'prod'), | |||
)); | |||
|
|||
$this->namespace = 'tumblr'; | |||
$this->name = 'cache'; | |||
} | |||
|
|||
public function execute($arguments = array(), $options = array()) | |||
{ | |||
// load config | |||
$blog_name = sfConfig::get('app_tumblr_blog_name'); | |||
$email = sfConfig::get('app_tumblr_email'); | |||
$password = sfConfig::get('app_tumblr_password'); | |||
$cache_directory = sfConfig::get('sf_upload_dir'); | |||
|
|||
// sanity check | |||
if (empty($blog_name) || empty($email) || empty($password)) | |||
{ | |||
echo "Blog name, email, and password must be configured in app.yml\n"; | |||
echo "Stopped on errors\n"; | |||
return; | |||
} | |||
|
|||
// Run | |||
$b = new sfWebBrowser(array(), 'sfCurlAdapter', array('cookies' => true)); | |||
|
|||
// Login | |||
echo "Attempting to login...\n"; | |||
$res = $b->post('https://www.tumblr.com/login', array('email'=>$email, 'password'=>$password)); | |||
if ($res->responseIsError()) | |||
{ | |||
echo "Login Failed\n"; | |||
} | |||
|
|||
// get the blog | |||
$blog = $b->get('http://www.tumblr.com/blog/'.$blog_name); | |||
|
|||
// cache to a file | |||
$filename = $cache_directory.DIRECTORY_SEPARATOR.$blog_name.'-'.date('Y-m-d_H:i:s').'.html'; | |||
if (!file_put_contents($filename, $blog->getResponseText())) | |||
{ | |||
echo "Failed to save cache file\n"; | |||
} | |||
|
|||
echo "Done\n"; | |||
} | |||
} |