I want to use the html5 cache manifest technology with CakePHP,
but I don't know where to place the cache manifest in CakePHP,
I've searched for a solution, but I do not found anything.
Can you help me?
The best and easiest way to access one manifest file in all views is to look at your layouts, for example
View/Layouts/default.ctp
and replace <html> with
<?php echo "<html manifest='".$this->webroot."manifest.php'>"; ?>
in which manifest.php is located in
app/webroot/manifest.php
and looks something like this:
<?php
header('Content-Type: text/cache-manifest');
echo "CACHE MANIFEST\n";
echo "\n\nNETWORK:\n";
echo "*\n";
echo "\n\nCACHE:\n";
echo "# Version: 1\n";
?>
So the manifest.php is only needed once and can be used for all views.
HINT:
For a dynamic manifest-file you can use a code snippet from here:
http://nial.me/2010/01/using-the-html5-cache-manifest-with-dynamic-files/
I tried this solution, putting the manifest in default.ctp, but it causes some problems, all my pages was cached... i think it's discribed in the spec "...the page that referenced the manifest is automatically cached even if it isn't explicitly mentioned".
...couse this all my pages was being cached, manifest is checked in each page. And when another user logs in they see the last user homepage and other pages.
The final solution: create a redirect/loading page
1 - create the redirect page:
I had create the Pages/redirect.ctp file and the function redirect(){} in the Pages controller. A simple page, just with a hello message and a loading bar based on the applicationCache progress event:
var appCache = window.applicationCache;
appCache.addEventListener('progress', function(event) {
console.log(event.loaded + " of " + event.total + " files...");
//make some changes in the page' loading bar
}, false);
2 - Load manifest only in the redirect page:
In the View/Layouts/default.ctp I filtered the tag to show the manifest only in the redirect page:
<? if($this->request->params['controller']=='pages' &&
$this->request->params['action']=='redirect'): ?><html
manifest="<?=$this->webroot?>manifest.php">
<? else: ?>
<html >
<?
endif; ?>
3 - Use the redirect page in the auth component to lead my user
to redirect page after login:
In the appController a setted auth component like this
public $components = array (
'Session',
'Auth' => array (
'authError' => "user or password invalid",
'unauthorizedRedirect' => "/pages/redirect?err=login",
'loginRedirect' => "/pages/redirect",
'logoutRedirect' => "/",
'loginAction' => "/user/login",
'authorize' => array ('Controller')
)
);
now only the elements putted in the manifest will be cached. The redirect page is cached (according the spec) but the applicationCache event updates the page torning this "dinamic".
If you mean the manifest file it should go into /app/webroot, the directory that your vhost should also use for the site. besides this there is nothing really related to CakePHP with this.
Have a look at this: http://www.html5rocks.com/en/tutorials/appcache/beginner/
Related
I want to show the 404 page when user enters unknown address like on the above image.
I can control the unknown address after index.php but don't know how to do this for the part before the index.php part.
I wrote this code to control what user enters after index.php
<?php
$pageName = 'places';
if (isset($_GET['page'])) {
$pageName = $_GET['page'];
}
$pageList = array(
'places',
'places_info',
'save'
);
if (!in_array($pageName, $pageList)) {
$pageName = '404';
}
?>
It looks like you have apache on your development machine.
The way to have custom error pages is
Create/Edit the file in C:\xampp\htdocs\blit\.htaccess
Insert a line ErrorDocument 404 /blit/404.shtml
Create the file C:\xampp\htdocs\blit\404.shtml
Put whatever html you want in it.
Repeat for other errors.
If you type in localhost/blit/xxy and xxy.php and xxy.html do not exist then the error page will be shown.
I've programmed my website by Yii2. When I refresh my website it works like Ctl + F5, and all the font awesome and all the cache of my site reload again. It look likes I open the page first time.
Link of my website
Add, this in your config file. According to your need.
$linkAssets
Whether to use symbolic link to publish asset files. Defaults to
false, meaning asset files are copied to $basePath. Using symbolic
links has the benefit that the published assets will always be
consistent with the source assets and there is no copy operation
required. This is especially useful during development.
'components' => [
'assetManager' => [
'linkAssets' => true,
],
]
Or
$forceCopy
Whether the directory being published should be copied even if it is
found in the target directory. This option is used only when
publishing a directory. You may want to set this to be true during the
development stage to make sure the published directory is always
up-to-date. Do not set this to true on production servers as it will
significantly degrade the performance.
'components' => [
'assetManager' => [
'forceCopy' => true,
],
]
For more info, Please click these useful links
Link Assets - Yii2 Asset Manager
Force Copy - Yii2 Asset Manager
Assets-Clear-Cache - Yii2 (Stack Overflow)
Or,
As, I am using Yii2-App-Basic. So, My Assets are getting created in ROOT/web/assets folder. So, I manually hit this action to clear my cache. This is not a good way to clear cache. Even though, it's useful for time being.
This function, I created in SiteController.php.
And, I hit URL Like : MyWebsite.com/site/clear-cache.
<?
public function actionClearCache(){
$cacheDirPath = $_SERVER['DOCUMENT_ROOT'].'/assets';
if($this->destroy_dir($cacheDirPath, 0)){
Yii::$app->session->setFlash('success', 'Cache cleared.');
}
return $this->render('some-page');
}
private function destroy_dir($dir, $i = 1) {
if (!is_dir($dir) || is_link($dir))
return unlink($dir);
foreach (scandir($dir) as $file) {
if ($file == '.' || $file == '..') continue;
if (!$this->destroy_dir($dir . DIRECTORY_SEPARATOR . $file)) {
chmod($dir . DIRECTORY_SEPARATOR . $file, 0777);
if (!$this->destroy_dir($dir . DIRECTORY_SEPARATOR . $file))
return false;
};
}
if($i == 1)return rmdir($dir);
return true;
}
Let's say I have completed my index.html file with all the CSS and JavaScripts and I want to create some other ones like: "contact", "about us", "music" etc.
They all have to go into the same root folder as the index.html. Well this is ok with me since there's not that many, but what about sub-categories? Like in music I would like to have 10 different genres.html and inside that, 20 more artists.html and so on. This would entirely cluster my root folder. And putting them into a sub-folder doesn't work either, because then all the links to the centralized resources (like: CSS files, images, JavaScript) break. And having to manually adjust every absolute path is also a pain. I gave <base> a try but it messed other things up.
What is the best and simplest way to organize your website's page structure (preferably without a CMS)?
If PHP is an possibility, you could use an very simple script like this:
{root}/index.php
<?php
if(!isset($_GET['route'])){ // If no route is given
require_once 'pages/index.html'; // Load the default index page
}else if(!file_exists('pages/' . $_GET['route'] . '.html')){ // If an route is given, check if the page exists
require_once 'pages/404.html'; // If not, load an 404 page
}else{
require_once 'pages/' . $_GET['route'] . '.html'; // Or else load the given route
}
The url's will then be something like this:
www.yoursite.com/index.php?route=index (index.html inside the pages folder)
www.yoursite.com/index.php?route=contact (pages/contact.html)
www.yoursite.com/index.php?route=catalog/category/something/list (pages/catalog/category/something/list.html)
This is very simple and basic PHP using so called $_GET variables (More about that here )
All the requests will be handeld by the index.php inside the root of your website.
Because of that, your include link for your JS and CSS files, will always be from the root directory. Therefore, you don't need to worry about all the different paths.
If you need more help, just ask.
Update
Your folder structure could be something like this than:
root/
css/
js/
img/
pages/
music/
artist.html
something/
else/
stuff.php
index.html
contact.html
index.php
And instead of doing $_GET['route'] . 'html', you could also use just $_GET['route'] and append the file extension to the url. This way you can use all different types of file extensions. (www.yoursite.com/index.php?route=music/artist.php)
Or you could just change .html to .php. That's all up to you!
I use to design my page's structure with the help of PHP.
Here's how I would do it:
Template page
you can make your own template and only fill in the content:
<?php
$root = "";
require_once $root . 'class/page.php';
$page = new Page();
?>
<!DOCTYPE html>
<html>
<head>
<?php
$page->metaTags();
$page->metaDescription("");
$page->metaKeywords("");
$page->defaultStyles();
$page->addStyle("styleName");
$page->title("your page title");
$page->defaultScripts();
?>
</head>
<body>
<?php
$page->navigation();
$page->header();
$page->openContainer();
$page->openContentSection();
?>
Your page content
<?php
$page->closeContentSection();
$page->closeContainer();
?>
</body>
</html>
Now the page class will handle the layout and the links so you can make your changes in 1 place and still affect all the pages in your site.
Page class
class Page{
private $db;
private $root;
private $terms;
public function __construct() {
$this->db = new db();
...
}
public function metaDescription($desc){
echo '
<meta name="description" content="' . $desc . '" />';
}
public function defaultStyles(){
echo '
<link href="' . $this->root . 'css/bootstrap.min.css" rel="stylesheet" />';
}
....
}
Now, the pages can be anywhere you want them to be, you just set the $root to your absolute website url and all the includes will be correct no matter where your files are being saved.
<?php
# Alert the user that this is not a valid access point to MediaWiki if they try to access the special pages file directly.
if ( !defined( 'MEDIAWIKI' ) ) {
echo <<<EOT
To install my extension, put the following line in LocalSettings.php:
require_once "$IP/extensions/Userprofile/Userprofile.php";
EOT;
exit( 1 );
}
$wgExtensionCredits['specialpage'][] = array(
'path' => __FILE__,
'name' => 'Userprofile',
'author' => 'matsuiny2004',
'url' => 'http://localhost/mywiki/index.php/Extension:Userprofile',
'descriptionmsg' => 'userprofile-desc',
'version' => '0.0.0',
);
$wgAutoloadClasses['SpecialUserprofile'] = __DIR__ . '/SpecialUserprofile.php'; # Location of the SpecialMyExtension class (Tell MediaWiki to load this file)
$wgMessagesDirs['Userprofile'] = __DIR__ . "/i18n"; # Location of localisation files (Tell MediaWiki to load them)
$wgExtensionMessagesFiles['UserprofileAlias'] = __DIR__ . '/Userprofile.alias.php'; # Location of an aliases file (Tell MediaWiki to load it)
$wgSpecialPages['Userprofile'] = 'SpecialUserprofile'; # Tell MediaWiki about the new special page and its class name
function extensionFunction() {
# Assume $title is the title object
if( $title->isProtected( 'edit' ) ) {
# Protected from editing, do things
} else {
# Not protected from editing
}
}
//test code here
echo '<div id="navigation">Navigation</div>';
?>
<?php
echo '<div id="account">account</div>';
?>
<?php
echo '<div id="editpage">edit page</div>';
?>
<div id='border-search'>
<img src="http://s6.postimage.org/z6ixulv6l/searchbox_border.png"></img>
</div>
?php>
<div class='rectangle-box'>
<div class='rectangle-content'></div>
</div>
I am including extra php and html code from a seperate file that I load as an extension in mediawiki to create a custom layout. the problem is that the code loads before the doctype making the page render in quirks mode in IE and safari. How can i get it to load after the doctype tag?
The problem is that you have top-level echo statements all over your code (by top level I mean ones that are not included in any function). Which is why the PHP engine executes them as soon as it sees them, which is before the MediaWiki itself starts running.
MediaWiki has some good documentation explaining all kinds of hooks. What you should do is write a few functions and place all your echo-ing code there, and expect this function to be executed when the event in question occurs.
I see a good starter page here. Relevant example is:
$wgHooks['ArticleSave'][] = 'wgAddStub';
function wgAddStub( &$article, &$user, &$text, &$summary, $minor, $watchthis, $sectionanchor, &$flags, &$status ) {
$text = ( $article->exists() ? "" : "{{stub}}\n" ) . $text;
return true;
}
I can't get my Yahoo! Application Platform to run I keep getting denied access even though their policy file accepts requests from any domain.
OK: Policy file accepted: http://social.yahooapis.com/crossdomain.xml
Error: Request for resource at http://social.yahooapis.com/v1/user/<user id>/profile?oauth_signature_method=HMAC-SHA1&lang=en-US&oauth_consumer_key=<key>&oauth_token=<long ass token>&oauth_version=1.0&format=json&oauth_nonce=<blah blah>&oauth_timestamp=1262846353®ion=US&oauth_signature=<foo bar> by requestor from http://<my domain>/YOSSimple.swf is denied due to lack of policy file permissions.
The url works btw, I editted some stuff out since it has my keys and stuff.
Links to the stuff I'm trying to do
http://developer.yahoo.com/flash/yos/
http://developer.yahoo.com/flash/yos/examples/simple/YOSSimple.fla
YOSSimple properly creates the url actually since if I type it in my browser I'm prompted if I want to download the file that contains information regarding my profile.
But it just wont open it in Flash.
I'm guessing that it's not loading the policy file automatically. You should try using
Security.loadPolicyFile("http://social.yahooapis.com/crossdomain.xml");
Do you have a webproxy installed with which you can monitor what files exactly are loaded? My favorite is Charles but there are also free FF plugins like Httpfox
EDIT:
I think I know what's going wrong. It's going wrong the other way around, the swf from yahoo is trying to access your swf, but doesn't have the correct permissions. Would you try
Security.allowDomain( 'http://social.yahooapis.com/' );
http://www.ieinspector.com/httpanalyzer/
use HTTP analyzer to see whats happening?
also check your not missmatching http://www. with http:// because flash treats them as different domains
also are you running the code locally on your machine. It could be your local security settings
A simple WebProxy will fix this:
<?php
// PHP Proxy
// Loads a XML from any location. Used with Flash/Flex apps to bypass security restrictions
// usage: proxy.php?url=http://mysite.com/myxml.xml
$session = curl_init($_GET['url']); // Open the Curl session
curl_setopt($session, CURLOPT_HEADER, false); // Don't return HTTP headers
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Do return the contents of the call
$xml = curl_exec($session); // Make the call
header("Content-Type: text/xml"); // Set the content type appropriately
echo $xml; // Spit out the xml
curl_close($session); // And close the session
?>
Modify the web proxy example above to support multiple options as follows:
$sOptions = "";
foreach($_GET as $sIndex => $sValue) {
if ($sIndex == 'url') {
$url = $sValue;
}
else {
if (strlen($sIndex) > 0) {
$sOptions .= "&" . $sIndex;
}
if (strlen($sValue) > 0) {
$sOptions .= "=" . $sValue;
}
}
}
$url .= $sOptions;
$session = curl_init($url); // Open the Curl session