Joomla TinyMCE editor do not save inserted image - joomla

We are building joomla component. And we use joomla editor in which we insert content.
But there is a problem, because when we add image to editor and save it, it do not add image to database and when we opening this element to edit it again, there is only text in editor, image disappears.
This is how we use it:
$editor =& JFactory::getEditor();
echo $editor->display('text', $this->hello->text, '800', '300', '20', '20');
Maybe there is need to supply aditional parameters to display method?

Problem solved.
The standard way of getting the form data $post = JRequest::get('post'); is not enough in the case of using a editor. This will filter the content, hence losing line breaks and paragraps. So we need to add an extra line to get the editor contents in a raw unfiltered way. This data will be passed to the model to save into the database.

To get HTML form post data you need to get this data in following way
$data = JRequest::getVar( 'editorName', 'defaultValue', 'post', 'string', JREQUEST_ALLOWRAW );
And need to add a javascript for the view(tmpl file)
function submitbutton(action) {
var form = document.adminForm;
switch(action)
{
case 'save':case 'apply':
<?php
$editor =& JFactory::getEditor();
echo $editor->save( 'editorName' );
?>
case 'publish':
case 'unpublish':
case 'cancel':
default:
submitform( action );
}
}

Related

PHPExcel style text to center

I'm using PHPExcel with codeigniter to generate .xlx, .xlxs file, Every thing is working perfect except text formatting. Here is the screenshot of html view that I'm passing to PHPExcel library to generate .xlx file.
And Here is the output.
As you can see that text indentation and styles are removed. Here is my code used to generate output.
public function html_to_excel_download($filename, $data=null){
if ($data != null) {
// proper encoding of data UTF-8 for unicode characters
$data = chr(255).chr(254).iconv("UTF-8", "UTF-16LE//IGNORE", $data);
// Put the data into a temporary file
$tmpfile = time().'.html';
file_put_contents($tmpfile, $data);
// Read the contents of the file into PHPExcel Reader class
$reader = new PHPExcel_Reader_HTML;
$content = $reader->load($tmpfile);
// Excel Writer
$objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007');
// Download File
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
unlink($tmpfile);
exit();
}
}
How can I indent title text to center?
you may try another way to do that...
Step 1) Define "$this->excel->setActiveSheetIndex(0);" at the top of function
step 2) Define style array and add it as a variable with excel object like,
$styleArray = array(
'font' => array(
'bold' => true,
'color' => array('rgb' => '2F4F4F')
),
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
)
);
Step 3) $this->excel->getActiveSheet()->getStyle('A3:Z3')->applyFromArray($styleArray);
Note: You have to use getStyle() in your code to apply specific styles on column/row
// single column A, setting e.g. horizontal alignment
$objWorksheet->getStyle('A')->getAlignment()->setHorizontal(...);
// range of columns A to K
$objWorksheet->getStyle('A:K')->getAlignment()->setHorizontal(...);
AND you can see full documentation on this site for formatting SHEET
HERE
There are two ways you can get rid of this issue, one is without json array:
$doc->getActiveSheet()->getStyle('A1:H1')->getAlignment()
->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
where $doc = new PHPExcel(); or a PHPExcel object
The second is using the json array as described here
I'm pretty confident that you'll find all instructions about this library in the official documentation

codeigniter - How to get embed data in my case

i load data in my controller like
$name['name'] = "some text!";
$data['header'] = $this->load->view('header_view', $name, TRUE);
$this->load->view('myView', $data);
and in my view file: myView.php
echo $header;
how can i get data in $name ? thanks
Try:
$data['name'] = "some text!";
$data['header'] = $this->load->view('header_view', $data['name'], TRUE);
$this->load->view('myView', $data);
You can't because when it comes to myView, the header view is allready processed and so data is allready incoroporated into the output string.
The only way is to copy (merge) the contents of $name into $data.
You can get embed data by parsing the content of $data['header'] but it is a really bad solution.
To solve this issue you can generate header and footer along the content inside your controller like that:
$this->load->view('header');
$this->load->view('content');
$this->load->view('footer');
Or you can use a template engine to include header/footer automaticly with the content template.
Infortunately, there is no buildin way to add an header easily in codeigniter. You'll have to come up with your own functions to do that in a helper or library (but you'll not be able to share data between header and content).

codeigniter : using flash data but no new page load?

Usually, I just set a $feedback var or array and then check for that to display in my views.
However, it occurred to me I should perhaps use flashdata instead.
The problem is sometimes - for say an edit record form, I may simply want to reload the form and display feedback - not redirect. when i use flashdata, it shows but then it shows on the next request as well.
What would be the best practice to use here?
CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared.
u use hidden field for that
I would use the validation errors from the Form validation class and load those directly to the view in its 2nd argument.
$this->form_validation->set_error_delimiters('<p>', '</p>');
$content_data = array();
if (!$this->form_validation->run()) {
$content_data['errors'] = validation_errors();
}
$this->load->view('output_page', $content_data);
Then check in your view whether $errors isset.
Controller:
$data['message'] = 'some message you want to see on the form';
$this->load->view('yourView', $data);
View:
if (isset ($message)) : echo $message; endif;
...

Yii Displaying Image dynamically dependent on dropdown

I'm trying to display an image but is dependent on a dropdown list in Yii. I can get the image from the database and display it, but how to do it dynamically depending on the choice from the dropdown?
Here is the reference: http://www.yiiframework.com/wiki/24/creating-a-dependent-dropdown#hh0 but, let me show you how to do it.
First all all, we need a div where the image will be displayed; I'll create one whose id will be 'img'. Then, the ajax request is specified inside the dropdownlist() as follows:
<?php echo $form->labelEx($model,'attribue'); ?>
<?php echo $form->dropDownList($model,'attribute',
array(/*The options in the DropDownList*/),
array(
'ajax'=>array(
'type'=>'POST',
'url'=>CController::createUrl('YourController/actionWhichEchoesTheImage'),
'update'=>'#img',
)));
?>
<div id="img"> // <---- the result of the ajax call will be displayed here
</div>
In the 'url' attribute we specify the function which will be called when the ajax request triggers. In the 'update' attribute we specified the div where will be displayed the result of calling that function (the image).
Finally, we have to declare the action actionWhichEchoesTheImage(). Let's declare it in the current controller. It would look something like this:
public function actionWhichEchoesTheImage()
{
if(isset($_POST['ModelName']['attribute']))
/*Here goes your code to load the image*/
echo CHtml::image(//Check the reference to see how to set this function);
}
Check CHtml::image() here: http://www.yiiframework.com/doc/api/1.1/CHtml/#image-detail

The url from an image via custom field (wordpress)

Am not even sure if this can be done but...
Ive added a feed from my forums to wordpress it works great but I need it to auto add the url of the image in a custom field from the images in the post (feed) first image would be fine as its only ahve a slider
Is there any way to do this?
Details
Ok I think I did not explain this very well so made a few screen shots
This is my slider at the minute with my
This is an imported post one other feed I was using
On this image you can see the custom field (which I have to fill in after every import)
Adding the image url into the custom field
and finaly a view of the slider working
This is what am trying to do (auto) so my feed from my booru / forums / 2 other of my sites and (2 other peoples) sites make my home page on a new site
Hope this explain it alot more
This uses the external Simple Pie library built into WordPress to fetch the feed, get the image url and create a new post for each item and save the image url as a custom field.
To activate the process we have to hook into wp_cron. The code below does it daily but it would probably be better to do it weekly to prevent overlap. Some overlap will probably occur so this still needs a way to check if we have already imported the image
First we need a function to save the custom field after the post has been created. This section comes from another answer I found on WordPress Answers.
Edit:
This needs to be wrapped in a plugin to schedule the cron event and the cron event was missing the action to make it fire.
Edit:
Final version below tested and it works but the feed the OP is getting is using relative url's so the domain name needs to be added somewhere in the output code.
<?php
/*
Plugin Name: Fetch The Feed Image
Version: 0.1
Plugin URI: http://c3mdigital.com
Description: Sample plugin code to fetch feed image from rss and save it in a post
Author: Chris Olbekson
Author URI: http://c3mdigital.com
License: Unlicense For more information, please refer to <http://unlicense.org/>
*/
//Register the cron event on plugin activation and remove it on deactivation
register_activation_hook(__FILE__, 'c3m_activation_hook');
register_deactivation_hook(__FILE__, 'c3m_deactivation_hook');
add_action( 'c3m_scheduled_event', 'create_rss_feed_image_post');
function c3m_activation_hook() {
wp_schedule_event(time(), 'weekly', 'c3m_scheduled_event');
}
function c3m_deactivation_hook() {
wp_clear_scheduled_hook('c3m_scheduled_event');
}
function create_rss_feed_image_post() {
if(function_exists('fetch_feed')) {
include_once(ABSPATH . WPINC . '/feed.php'); // include the required file
$feed = fetch_feed('http://animelon.com/booru/rss/images'); // specify the source feed
}
foreach ($feed->get_items() as $item) :
// global $user_ID;
$new_post = array(
'post_title' => $item->get_title(),
'post_status' => 'published',
'post_date' => date('Y-m-d H:i:s'),
//'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0)
);
$post_id = wp_insert_post($new_post);
if ($enclosure = $item->get_enclosure() )
update_post_meta( $post_id, 'feed_image_url', $enclosure->get_link() );
endforeach;
}

Resources