ie wont support dtds in feed cakephp - cakephp

Ok I'm trying to create a rss feed with cakephp rss helper for some post of an app. I followed the cakephp book to the letter and it wont work with internet explorer... When I open it with Opera it work but with ie it says "Internet Explorer does not support feeds with DTDs."...
I know microsoft is not supporting dtds because a security thread but how can I fix this issue? The company where I work uses ie by standard so changing the browser is not an option...
here is the code... So you can see there is not a mayor modification in it...
default.ctp
echo $this->Rss->header();
if (!isset($documentData)) {
$documentData = array();
}
if (!isset($channelData)) {
$channelData = array();
}
if (!isset($channelData['title'])) {
$channelData['title'] = $title_for_layout;
}
$channel = $this->Rss->channel(array(), $channelData, $content_for_layout);
echo $this->Rss->document($documentData,$channel);
index.ctp
$this->set('documentData', array(
'xmlns:dc' => 'http://purl.org/dc/elements/1.1/'));
$this->set('channelData', array(
'title' => __("Most Recent Hitos", true),
'link' => $this->Html->url('/', true),
'description' => __("Most recent Hitos.", true),
'language' => 'en-us'));
foreach ($posts as $post) {
$postLink = array(
'controller' => 'soportes',
'action' => 'view',
$post['Soporte']['id']);
// You should import Sanitize
App::import('Sanitize');
// This is the part where we clean the body text for output as the description
// of the rss item, this needs to have only text to make sure the feed validates
$bodyText = preg_replace('=\(.*?\)=is', '', $post['Hito']['actividad']);
$bodyText = $this->Text->stripLinks($bodyText);
$bodyText = Sanitize::stripAll($bodyText);
$bodyText = $this->Text->truncate($bodyText, 400, array(
'ending' => '...',
'exact' => true,
'html' => true,
));
echo $this->Rss->item(array(), array(
'title' => $post['Hito']['actividad'],
'link' => $postLink,
'guid' => array('url' => $postLink, 'isPermaLink' => 'true'),
'description' => $bodyText,
'dc:creator' => $post['Hito']['user_id'],
'pubDate' => $post['Hito']['fecha_sugerida']));
}

On a very basic level it might be because of the debug level in core.php - cake outputs the render time I think - you could try setting Configure::write('debug', 0); in your controller action to see if it renders in IE? I've had issues with XML / RSS and IE due to this before.

Related

cakephp 2.6.1 ajax login not working

Having issues logging in with ajax. Can anyone direct me to some documentation that makes sense. This sounds worrying.
In 2.x $this->Auth->login($this->request->data) will log the user in
with whatever data is posted, whereas in 1.3
$this->Auth->login($this->data) would try to identify the user first
and only log in when successful.
$data['User']['email'] = "this";
$data['User']['password'] = "that";
$data = $this->request->input('json_decode', true);
$this->autoRender = false;
$this->response->type('json');
if ($this->Auth->login($data)){
echo "access";
} else {
echo "access denied";
}
It always prints "access".
In AppController.php
'Auth' => array(
'loginRedirect' => array(
'controller' => 'posts',
'action' => 'index'
),
'logoutRedirect' => array(
'controller' => 'pages',
'action' => 'display',
'home'
),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email'),
'passwordHasher' => 'Blowfish'
),
)
),
Use AuthComponent::identify() instead. But this can (and clearly should) be done better. Your code tells me that you don't have much experience with json in CakePHP.
Check this page of the manual. Also your request should be made with "Accept: application/json" then your data should automatically end up in $this->request->data and then login() should pick it up automatically. The proper way is to send the Accept header and not just rely on the extension, this is general and not just specific to CakePHP.

Why doesn't Cakephp Html::link() work as I expect it to?

Using this code:
$sitemap = 4;
$link = $this->Html->link( $sitemap . '.xml', null,
array('plugin' => $this->request->plugin,
'controller' => $this->request->controller,
'action' => 'view',
'admin' => false));
I expect to get a link that looks like this:
http://www.domain.com/vreb_listings/vreb_listing_feeds/view/4.xml
Instead, I get this:
/admin/vreb_listings/vreb_listing_feeds/4.xml
What gives? The action => view is having no effect, as view doesn't show up in the url, and the admin => false isn't working either, as admin does show up. This code is in the admin area.
I haven't even looked up how to include the full domain path in the url. Also, I want the title text to be the same as the url.
According to docs, the second parameter is the url one, so in your code it should be
$link = $this->Html->link( $sitemap . '.xml',
array('plugin' => $this->request->plugin,
'controller' => $this->request->controller,
'action' => 'view',
'admin' => false));
(remove the null second parameter)
Oh, and for title text, that is the third parameter, so
$link = $this->Html->link( $sitemap . '.xml',
array('plugin' => $this->request->plugin,
'controller' => $this->request->controller,
'action' => 'view',
'admin' => false),
array('title' => $sitemap.'.xml'));
should do the trick

CakePHP Uploader Plugin only works on one Model

I've installed Miles Johnson's Uploader plugin and set it up with one of my models and got it working perfectly. Very nice.
Then I went and set it up on another model with almost identical code [the only difference is the upload path] and it won't work on the second model. When I submit the form the plugin doesn't seem to notice; I get an SQL error from an attempt to insert the POST file array straight into the DB.
Here is the code. [Other than this the plugin is imported in the bootstrap]
public $actsAs = array(
'Uploader.Attachment' => array(
'photo' => array(
'name' => 'formatFileName',
'uploadDir' => '/uploads/uses/img/',
'dbColumn' => 'photo',
'maxNameLength' => 30,
'overwrite' => true,
'stopSave' => true,
'allowEmpty' => false,
'transforms' => array(
array('method' => 'resize', 'width' => 240, 'dbColumn' => 'photo_thumb'))
)
),
'Uploader.FileValidation' => array(
'fileName' => array(
'extension' => array('gif', 'jpg', 'png', 'jpeg'),
'required' => true
)
)
);
This is on the model that is not uploading and the only difference is the uploadDir.
Does the plugin only work on one model? Any clues? thnx :}
Edit for extra clarity
Here is my view code:
echo $this->Form->create('Use', array('type' => 'file'));
echo $this->Form->input('Use.photo', array('type' => 'file'));
echo $this->Form->input('Use.desc', array('rows' => '3', 'label' => 'Description'));
echo $this->Form->end('Add to Gallery');
And here is my controller code:
public function add() {
if ($this->request->is('post')) {
$this->Use->set('user_id', $this->Auth->user('id'));
if ($this->Use->save($this->request->data)) {
$this->Session->setFlash('Your Use has been saved.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to add your Use.');
}
}
}
The plugin doesn't work in only one model. You can add more uploader into your site.
The model seems to be good, I suggest you to see into your form to see if you have create the form in the right way into your view (is imporant to put into your form: 'type' => 'file'
example:
echo $this->Form->create('Product', array ('class' => 'form', 'type' => 'file'));
echo $this->Form->input('ModelImage.filename', array('type' => 'file'));
echo $this->Form->submit('Add Image', array('id'=>'add_image'));
echo $this->Form->end();
Or the problem is the name Use try to change the name with another
After checking thru the code with Alessandro [thank you :)] I found the problem.
If you look in the View and Controller code you can see that the model is named 'Use'. This was the problem, as Use is a loaded word in PHP and I shouldn't have used it for a model name.
I renamed the model to Outcome and now the Uploader works perfectly.

Cakephp Error using Miles J Uploader plugin

I am currently trying to use Miles J plugin located here http://milesj.me/code/cakephp/uploader Although I have made great progress learning CakePhp, I am currently having a problem using the plugin and I would appreciate any help provided.
I have followed all the necessary steps to use the plugin. It has been downloaded put on Plugin folder, I bootstrapped with CakePlugin::loadAll().
So far so good.
Next I have proceed to set up the table as indicated by the plugin developer.
Ok, now back to my own code. I have the following set up:
images_controller.php , image.php and their views.
My goal now is to use the plugin inside those files as such:
App::import('Vendor', 'Uploader.Uploader');
Class ImagesController extends AppController {
var $components = array('Auth');
var $helpers = array('Design');
var $uses = array('Image', 'Uploader.Upload');
function manage(){
//here I show a simple upload form that uses the action saveimage
}
function saveimage(){
$this->Uploader = new Uploader();
if(!empty($this->data)){
$this->Upload->save($this->data);
}
}
}
Now, my model is set as follows
Class Image extends AppModel {
public $useTable = 'uploads';
public $actsAs = array(
'Uploader.FileValidation' => array(
'file' => array(
'extension' => array(
'value' => array('gif', 'jpg', 'jpeg'),
'error' => 'Only gif, jpg and jpeg images are allowed!'
),
'minWidth' => 500,
'minHeight' => 500,
'required' => true
),
'import' => array(
'required' => false
)
),
'Uploader.Attachment' => array(
'file' => array(
'name' => 'uploaderFilename',
'uploadDir' => '/files/uploads/',
'dbColumn' => 'path',
'maxNameLength' => 30,
'overwrite' => true,
'stopSave' => false,
'transforms' => array(
// Save additional images in the databases after transforming
array(
'method' => 'resize',
'width' => 100,
'height' => 100,
'dbColumn' => 'path_alt'
)
),
'metaColumns' => array(
'size' => 'filesize', // The size value will be saved to the filesize column
'type' => 'type' // And the same for the mimetype
)
),
'import' => array(
'uploadDir' => '/files/uploads/',
'name' => 'uploaderFilename',
'dbColumn' => 'path',
'overwrite' => true,
'stopSave' => false,
'transforms' => array(
array(
'method' => 'scale',
'percent' => .5,
'dbColumn' => 'path' // Overwrite the original image
)
)
)
)
);
}
}
On my model for testing purposes I have not changed anything but just copied and pasted the very same array as shown in the the Test/Model folder inside the plugin, which is meant to show the functionality of the plugin.
The following confusion, errors or lack of understanding is taking place:
My file is not being uploaded to the webroot/files/uploads folder
My data is being inserted in the database, but not in a complete manner by leaving empty as shown:
id | caption | path | path_alt | created |
4 | | | |2012:02:..|
Above, I expect the path to be saved, but it doesn't.
I have to admit my confusion comes mainly from my inexperience using plugins, so I am aware I might be doing something wrong regarding my models or my configuration.
Any prompt help would be appreciated greatly as I have tried to work this out on my own without any success.
A few things:
1 - In your controller you do not need to import the Uploader class. You also don't need to use the Uploader.Upload model (it's merely an example test case). All you need to do in the controller is call $this->Image->save() which will upload the file and save the path as a row into the database (if you defined the Attachment in Image).
2 - In your view, create the file input. Pay attention to the input name.
echo $this->Form->input('FILE_INPUT_NAME', array('type' => 'file'));
3 - In your Image model, setup the AttachmentBehavior and its options for that specific input field:
'Uploader.Attachment' => array(
'FILE_INPUT_NAME' => array(
'uploadDir' => '/files/uploads/',
'dbColumn' => 'path'
),
'ANOTHER_INPUT' => array()
);
Be sure that the column "path" exists in your images table. And thats it.
For more information on what each option does, check out the following: http://milesj.me/code/cakephp/uploader#uploading-files-through-the-model

Can't delete posts in forum. (CakePHP)

I'm using the Cupcake Forum plugin within CakePHP. There's a form for selecting the desired posts, and then submitting the form to delete the posts. The form data is apparently being sent to the 'moderate' function within the 'topics' controller using POST and GET methods simultaneously. The function first checks to see if the data sent in is POST. However, when the data is received, it shows that it's GET. A fellow programmer and I don't want to completely change someone else's internal code, but we can't figure out how the data is being sent by both methods and being received as GET. The code from the plugin is below:
--------------moderate.ctp (view)---------------------
<?php echo $form->create('Post', array('url' => array('controller' => 'topics', 'action' => 'moderate', $topic['Topic']['slug']))); ?>
-------------topics_controller.php (controller)-------
public function moderate($id) {
if ($this->RequestHandler->isGet()){
$this->log('Is GET!');
}
$user_id = $this->Auth->user('id');
$topic = $this->Topic->getTopicForViewing($id, $user_id, 'id');
// Access
$this->Toolbar->verifyAccess(array(
'exists' => $topic,
'permission' => $topic['ForumCategory']['accessRead'],
'moderate' => $topic['Topic']['forum_category_id']
));
$this->log('ID: '.$id.'\n');
if ($this->RequestHandler->isPost()){
$this->log('Is POST!');
}
if ($this->RequestHandler->isGet()){
$this->log('Is GET!');
}
$this->log($this->RequestHandler->getReferer());
$this->log(serialize($this->data));
// Processing
if ($this->RequestHandler->isPost()) {
$this->log('INSIDE POST!');
if (!empty($this->data['Post']['items'])) {
$items = $this->data['Post']['items'];
$action = $this->data['Post']['action'];
foreach ($items as $post_id) {
$this->log('Action: '.$action.'\n');
$this->log('PostID: '.$post_id.'\n');
if (is_numeric($post_id)) {
if ($action == 'delete') {
$this->Topic->Post->destroy($post_id);
$this->Session->setFlash(sprintf(__d('forum', 'A total of %d post(s) have been permanently deleted', true), count($items)));
}
}
}
}
}
We added the log checks, which show the result of 'Is GET!' in Cake's log file. Since the method is GET, the statement 'if ($this->RequestHandler->isPost())' is never true; therefore, the submitted posts aren't deleted. What are we missing?
Try changing moderate.ctp to
<?php
echo $form->create('Post', array(
'url' => array(
'controller' => 'topics',
'action' => 'moderate',
$topic['Topic']['slug'],
),
'type' => 'post',
));
?>

Resources