How to display data in ckeditor from mysql in PHP - php

I am new in this field, I used ckeditor but I don't know how to display data in ckeditor through mysql..
My code is
$CKeditor = new CKeditor();
$CKeditor->BasePath = 'manage-site/';
$CKeditor->config['filebrowserBrowseUrl'] = 'ckfinder/ckfinder.html';
$CKeditor->config['filebrowserImageBrowseUrl'] = 'browser/browser.php?type=Images';
$CKeditor->config['filebrowserFlashBrowseUrl'] = 'ckfinder/ckfinder.html?type=Flash';
$CKeditor->config['filebrowserUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
$CKeditor->config['filebrowserImageUploadUrl'] = 'uploader/uploader.php?type=Images';
$CKeditor->config['filebrowserFlashUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
$CKeditor->editor('page_desc','**page_desc**');
For display content I use
<?php echo stripslashes($details[0]["page_desc"]); ?>
I wanted to display on the place of Page_desc(last Line of Code). How to do that?

You can simply download the ckeditor package and do this simple 2 step
Step 1 : Include the ckeditor.js from your file
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
Step 2 : Include the class name as ckeditor to your textarea
Then you can see the ckeditor with simple step
Note : Make sure the ckeditor.js is in the proper path
Hope this helps you

Related

how to put jpgraph into PDF using dompdf-0.5.1

It took me 12 hours still no improvement. I try displaying different images from my computer stored in the server and the result was successful. however when displaying the reports pie graph, it wont read every time the system tries to convert to pdf. It gives a blank pdf file. On the other hand, I can view the pie graph I created by using echo''; in the reports.php. I used the same concept in dompdf file but its not working.
DOMPDF
<html>
<head>
<title></title>
</head>
<body>
<?php echo'<img src="reports-display.php"/>';?>
</body>
</html>
<?php
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
?>
JPGRAPH Drawing
<?php
require('dbcon.php');
require_once('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_pie.php');
require_once ('jpgraph/src/jpgraph_pie3d.php');
//LEGEND
//YELLOW=LIVE BLUE=WAITING GREEN=DONE
//sql query for live
$live = mysql_query("Select count(*) as count1 from tbl_display_ads where status LIKE '%Live%'") or die(mysql_error());
//sql query for waiting
$waiting = mysql_query("Select count(*) as count2 from tbl_display_ads where status LIKE '%Waiting%'") or die(mysql_error());
//sql query for done/posted advertisement
$done = mysql_query("Select count(*) as count3 from tbl_display_ads where status LIKE '%Done%'") or die(mysql_error());
//While loop for live
while($resultlive = mysql_fetch_array($live))
{
$totallive = $resultlive['count1'];
}
//While loop for waiting
while($resultwaiting = mysql_fetch_array($waiting))
{
$totalwaiting = $resultwaiting['count2'];
}
//While loop for done
while($resultdone = mysql_fetch_array($done))
{
$totaldone = $resultdone['count3'];
}
// Some data
$data = array($totallive,$totalwaiting,$totaldone);
// Create the Pie Graph.
$graph = new PieGraph(500,450);
$theme_class= new VividTheme;
$graph->SetTheme($theme_class);
// Set A title for the plot
$graph->title->Set("Figure 1.1: Totality of Display Advertisement");
// Create
$p1 = new PiePlot3D($data);
$p1->SetCenter(0.5,0.55);
$p1->SetLegends(array("Live","Waiting","Done"));
$graph->legend->SetPos(0.5,0.100,'center','bottom');
$graph->Add($p1);
$p1->ShowBorder();
$p1->SetColor('black');
$p1->ExplodeSlice(1);
$graph->Stroke();
// Get the handler to prevent the library from sending the
// image to the browser
$gdImgHandler = $graph->Stroke(_IMG_HANDLER);
// Stroke image to a file and browser
// Default is PNG so use ".png" as suffix
$fileName = "/tmp/imagefile.png";
$graph->img->Stream($fileName);
// Send it back to browser
$graph->img->Headers();
$graph->img->Stream();
?>
I finally found out the solution. in the report-display.php I set the extension name of the graph to .png and save to the directory folder for reports.
DEFINE("DEFAULT_GFORMAT","auto");
$graph->img->SetImgFormat("png");
if(file_exists("Reports/reports-display.png")) unlink("Reports/reports-display.png");
$graph->Stroke("Reports/reports-display.png");
The problem is that you're essentially asking dompdf to grab an image file called "reports-display.php" from the local filesystem. When you use $dompdf->load_html() dompdf has no idea where the content arrives from. Any resource references in the HTML that lack a full URL are pulled in via the local filesystem. Since dompdf does not parse the PHP the source will be read in, which is obviously not a valid image document.
You're found a valid solution in saving the file locally. There are two other possibilities:
1) Point to the jpgraph script through your web server.
<html>
<head>
<title></title>
</head>
<body>
<img src="http://example.com/reports-display.php"/>
</body>
</html>
2) Capture the jpgraph output and insert into the document as a data-uri.
<html>
<head>
<title></title>
</head>
<body>
<img src="data:image/png;base64,<?php echo base64_encode(include_once('reports-display.php');?>"/>
</body>
</html>
With this method reports-deplay.php would have to be updated to return the image rather than stream it. Something like:
$graph = new PieGraph(500,450);
// snip steps that generate the content
return $graph->Stroke();

How to get a php variable in jquery function?

I want to pass a php variable in jquery function. Actually i m generating a dynamic php variable .
$imageslider = "imageslider_".$convertcode;
$imageslider is div of image gallery slider which i want to show on click on an icon.
Icon div is also generated dyanamically by the following code
$paletlyicon = "paletlyicon_".$convertcode;
Now i have a jquery function as follows
jQuery('<?php echo '.'.$paletlyicon ; ?> ').hover(function()
{
jQuery('<?php echo '.'.$imageslider ; ?>').show();
});
This is not working somehow ..i tried to alert the dynamic variables but they r showing nothing..
Plz look into it..
Hey what are the dom you define to ?
a class or a id ?Change to :
$imageslider = ".imageslider_".$convertcode; //Add '.' add first
and
$paletlyicon = ".paletlyicon_".$convertcode; //Add '.' add first
So if you don't add '.' or '#', you define to manipulate the dom named paletlyicon_".$convertcode
Good luck

how to display an array content inside CKeditor?

I need to display the content of doc file inside CKeditor.
I read the content of doc file & passing it into an array line by line :
$rs = fopen("text.doc", "r");
while ($line = fgets($rs, 1024)) {
$this->data[] = $line . "<BR>";
}
then I create an instance of CKeditor:
include_once("ckeditor/ckeditor.php");
$CKeditor = new CKeditor();
$CKeditor->basePath = '/ckeditor/';
foreach ($this->data as $value) {
//what should I write here
}
$CKeditor->editor('editor1');
the CKeditor work right now & appear on my webpage .. but without any content ?
what should I right inside the foreach to passing array content into the editor ?
please help =(
.doc files are zipped up and cannot be read like this, by line. Consider using PHPWord to get access to the contents inside.
EDIT: Looks like PHPDoc can only write and not read, upon further investigation.
PHP tools are very deficient in this area. Your best bet is to use something like DocVert to do your file conversions on the command line. THEN you could load that document inside CKEditor.
EDIT: after OP's comment:
let's consider it's a txt file ... I need the Ckeditor method
Load your decoded HTML content into a Textarea, and give this textarea an HTML ID or class:
$textarea_content = htmlspecialchars_decode(file_get_contents('text.doc'));
Then, in your HTML, call the CKEditor inside a JavaScript tag to replace the textarea with the editor:
<html>
<head>
<!-- include CKEditor in a <script> tag first -->
<script type="text/javascript">
window.onload = function()
{
CKEDITOR.replace( 'editor1' );
};
</script>
</head>
<body>
<textarea id="editor1" name="editor1"><?php echo $textarea_content ?></textarea>
</body>
The documentation page has a lot more details.

CKEditor PHP integration

I am using CKEditor with PHP.
Using the sample PHP where the $code variable gets echoed printing the code that triggers the CKEditor to show. I do the same only in a real layout and the what happens is the Editor engulfs the surroding HTML inside it as if it was the initialValue for it.
Any idea why I am getting this, please?
Here is the code:
// Include CKEditor class.
#require_once("ckeditor/ckeditor.php");
// Create class instance.
$CKEditor = new CKEditor();
// Do not print the code directly to the browser, return it instead
$CKEditor->returnOutput = true;
// Path to CKEditor directory, ideally instead of relative dir, use an absolute path:
// $CKEditor->basePath = '/ckeditor/'
// If not set, CKEditor will try to detect the correct path.
$CKEditor->basePath = 'ckeditor/';
// Set global configuration (will be used by all instances of CKEditor).
$CKEditor->config['width'] = 600;
// Change default textarea attributes
//$CKEditor->textareaAttributes = array("cols" => 80, "rows" => 10);
//Set formatting options
$config['toolbar'] = array(
array( 'Source','-',
'NewPage','Preview','Templates','-',
'Cut','Copy','Paste','PasteText','PasteFromWord','-',
'Undo','Redo','-',
'Find','Replace','-',
'SelectAll','RemoveFormat','-',
'Maximize', 'ShowBlocks'),
'/',
array('Bold','Italic','Underline','Strike','-',
'Subscript','Superscript','-',
'NumberedList','BulletedList','-',
'Outdent','Indent','Blockquote','-',
'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-',
'Link','Unlink','Anchor','-',
'Image','Flash','Table','HorizontalRule','SpecialChar'
),
'/',
array('Format','Font','FontSize','-',
'TextColor','BGColor')
);
//Set skin
//$config['skin'] = 'kama';//kama si defailt skin for 3.4
//Set language and UI Color
$config['language']='ro';
//$config['uiColor']='#AADC6E';
//Remove the html tags in the status bar (e.g. body p strong for when cursor is in a strong tag within a p tag within the body)
$config['removePlugins']='elementspath';
//Allow / deny resizing of editor from dragging the bottom-right corner. Maximize will still work.
$config['removePlugins']='resize';//Remove resize image
$config['resize_enabled ']=false;//Disallow resizing
//Remove the collapse formatting area button (arrow on the middle-right part of the editor
//$config['toolbarCanCollapse']=false;
// The initial value to be displayed in the editor.
$initialValue = '';
//Add the CKFinder for upload of files directly from the `Add Image` / `Add Flash` buttons.
include_once($CKEditor->basePath.'ckfinder/ckfinder.php');
// You can use the "CKFinder" class to render CKFinder in a page:
$finder = new CKFinder();
$finder->BasePath = 'ckeditor/ckfinder/'; // The path for the installation of CKFinder (default = "/ckfinder/").
//$finder->SetupCKEditor($CKEditor,$CKEditor->basePath.'/ckfinder/');
// Create first instance.
$CKEditorOutput = $CKEditor->editor("continut",$initialValue,$config);
Afterwards, I just do: $output.='<div>'.$CKEditorOutput.'</div>;
Of course, the layout around the div in which the CKEditor resides is larger.
Thank you!
Ah, got it...
This line: $CKEditorOutput = $CKEditor->editor("continut",$initialValue,$config);
The layout contains a div with an ID selector of "continut", so <div id="continut">. Thus messing everything up and turning that div and all inner HTML into the RTE Textarea.
Sorry and thanks everyone!

Call TinyMCE in a WordPress plugin

Is there a way to add TinyMCE into my own WordPress plugin?
I have a textarea in my back end script and want to make this area into a TinyMCE WYSIWYG editable field. Is there a way to do that?
This code does not work for me:
<?php
wp_tiny_mce(false,array("editor_selector" => "test"));
?>
<textarea class="test" id="test" name="test"></textarea>
It shows the javascript error
f is undefined
Firebug screenshot:
This didn't work either:
<textarea class="theEditor" id="videogalerie-add_description" name="videogalerie-add_description"></textarea>
This is much easier to do in WordPress 3.3 using the wp_editor() function.
I'm working on a plugin that will add a TinyMCE instance to a theme options page. Here's what it looks like:
// Add TinyMCE visual editor
wp_editor( $content, $id );
Where $content is the stored content and $id is the name of the field. Options can also be passed to customize the TinyMCE functionality, check out the WordPress Codex for more details.
Camden already answered this, but in case somebody needs the full code... Be sure to hook in admin_head, hooking into admin_enqueue_scripts will cause it to load before other scripts, such as jQuery, so it will not work.
add_action("admin_head","load_custom_wp_tiny_mce");
function load_custom_wp_tiny_mce() {
if (function_exists('wp_tiny_mce')) {
add_filter('teeny_mce_before_init', create_function('$a', '
$a["theme"] = "advanced";
$a["skin"] = "wp_theme";
$a["height"] = "200";
$a["width"] = "800";
$a["onpageload"] = "";
$a["mode"] = "exact";
$a["elements"] = "intro";
$a["editor_selector"] = "mceEditor";
$a["plugins"] = "safari,inlinepopups,spellchecker";
$a["forced_root_block"] = false;
$a["force_br_newlines"] = true;
$a["force_p_newlines"] = false;
$a["convert_newlines_to_brs"] = true;
return $a;'));
wp_tiny_mce(true);
}
}
Then somewhere in your template insert a regular textarea:
<textarea id="intro"></textarea>
The following example works for me. Just make sure to use the id of the textarea you want to select in the $a["elements"] variable.
Assuming you have a textarea with the id of 'intro':
// attach the tiny mce editor to this textarea
if (function_exists('wp_tiny_mce')) {
add_filter('teeny_mce_before_init', create_function('$a', '
$a["theme"] = "advanced";
$a["skin"] = "wp_theme";
$a["height"] = "200";
$a["width"] = "800";
$a["onpageload"] = "";
$a["mode"] = "exact";
$a["elements"] = "intro";
$a["editor_selector"] = "mceEditor";
$a["plugins"] = "safari,inlinepopups,spellchecker";
$a["forced_root_block"] = false;
$a["force_br_newlines"] = true;
$a["force_p_newlines"] = false;
$a["convert_newlines_to_brs"] = true;
return $a;'));
wp_tiny_mce(true);
}
?>
The tiny mce function wp_tiny_mce is now depricated. For Latest wordpress you want to use wp_editor
$initial_data='What you want to appear in the text box initially';
$settings = array(
'quicktags' => array('buttons' => 'em,strong,link',),
'text_area_name'=>'extra_content',//name you want for the textarea
'quicktags' => true,
'tinymce' => true
);
$id = 'editor-test';//has to be lower case
wp_editor($initial_data,$id,$settings);
for more instructions just go through the documentation in wordpress
http://codex.wordpress.org/Function_Reference/wp_editor
Following guides from here and there (found thanks to this), here's how I've managed to make something work on wordpress 3.0.5 :
<?php
add_action("admin_print_scripts", "js_libs");
function js_libs() {
wp_enqueue_script('tiny_mce');
}
wp_tiny_mce( false , // true makes the editor "teeny"
array(
"editor_selector" => "tinymce_data"
)
);
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('a.toggleVisual').click(function() {
console.log(tinyMCE.execCommand('mceAddControl', false, 'tinymce_data'));
});
$('a.toggleHTML').click(function() {
console.log(tinyMCE.execCommand('mceRemoveControl', false, 'tinymce_data'));
});
});
</script>
<form method="post" action="">
<ul>
<li>
<span id="submit"><input class="button" type="submit"></span>
<p id="toggle" align="right"><a class="button toggleVisual">Visual</a><a class="button toggleHTML">HTML</a></p>
</li>
<li><textarea style="width:100%;" class="tinymce_data" id="tinymce_data" name="tinymce_data"></textarea></li>
</ul>
</form>
I had a similar problem, and class="theEditor" didn't help me either (at first). I was using a custom post type which didn't include the default editor (ie the supports argument didn't include 'editor').
That meant WordPress didn't include the TinyMCE code. Once I added
add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 25 );
to my functions.php (based on the code in the the_editor function in general-template.php) it worked fine (with class="theEditor").
Tested and working on wordpress 3.3.1
add to functions or plugin file.
<?php
add_filter('admin_head','ShowTinyMCE');
function ShowTinyMCE() {
// conditions here
wp_enqueue_script( 'common' );
wp_enqueue_script( 'jquery-color' );
wp_print_scripts('editor');
if (function_exists('add_thickbox')) add_thickbox();
wp_print_scripts('media-upload');
if (function_exists('wp_tiny_mce')) wp_tiny_mce();
wp_admin_css();
wp_enqueue_script('utils');
do_action("admin_print_styles-post-php");
do_action('admin_print_styles');
}
?>
for Adding new content..
<?php the_editor($id='content');?>
for editing my content
<?php the_editor($mySavedContent); ?>
this will include the entire rage of scripts / css and code needed to produce a tinyMCE textarea within either your plugin or template files..
hope this helps..
M
I had quite a bit of trouble with this. After searching all day and trying dozens of code examples, I couldn't get Wordpress theme options to save MCE values to database. I tried everything, the jQuery answers, the hidden fields, etc etc. None of that would work for me, probably because I was missing a step somewhere.
Finally I found this page: http://wptheming.com/options-framework-theme/
Download from Github & install as directed (easy). Once installed, the last tab in your theme options has an MCE editor. Enter some test paragraphs. Now open the index.php file in the download to see the examples of how to include each thingy in your page. For example, I open footer.php and add a bit of code.
The only edit I needed to make was:
<?php
$ft = of_get_option('example_editor', 'no entry');
$format_ft = wpautop( $ft, false );
echo ($format_ft);
?>
The function wpautop() from Wordpress adds in paragraph tags, since they aren't ever saved in the wp database. I put that code in my footer to display the contents of the MCE.

Categories