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!
Related
I'm totally new to php, and I'm having a hard time changing the src attribute of img tags.
I have a website that pulls a part of a page using Simple Html Dom php, here is the code:
<?php
include_once('simple_html_dom.php');
$html = file_get_html('http://www.tabuademares.com/br/bahia/morro-de-sao-paulo');
foreach($html ->find('img') as $item) {
$item->outertext = '';
}
$html->save();
$elem = $html->find('table[id=tabla_mareas]', 0);
echo $elem;
?>
This code correctly returns the part of the page I want. But when I do this the img tags comes with the src of the original page: /assets/svg/icon_name.svg
What I want to do is change the original src so that it looks like this: http://www.mywebsite.com/wp-content/themes/mytheme/assets/svg/icon_name.svg
I want to put the url of my site in front of assets / svg / icon_name.svg
I already tried some tutorials, but I could not make any work.
Could someone please kind of help a noob in php?
i could make it work. So if someone have the same question, here is how i managed to get the code working.
<?php
// Note you must download the php files simple_html_dom.php from
// this link https://sourceforge.net/projects/simplehtmldom/files/
//than include them
include_once('simple_html_dom.php');
//target the website
$html = file_get_html('http://the_target_website.com');
//loop thru all images of the html dom
foreach($html ->find('img') as $item) {
// Get a attribute ( If the attribute is non-value attribute (eg. checked, selected...), it will returns true or false)
$value = $item->src;
// Set a attribute
$item->src = 'http://yourwebsite.com/'.$value;
}
//save the variable
$html->save();
//findo on html the div you want to get the content
$elem = $html->find('div[id=container]', 0);
//output it using echo
echo $elem;
?>
That's it!
did you read the documentation for read and modify attributes
As per that
// Get a attribute ( If the attribute is non-value attribute (eg. checked, selected...), it will returns true or false)
$value = $e->href;
// Set a attribute
$e->href = 'ursitename'.$value;
i am trying to make a page that allows me to grab and save images from another link , so here's what i want to add on my page:
text box (to enter url that i want to get images from).
save dialog box to specify the path to save images.
but what i am trying to do here i want to save images only from that url and from inside specific element.
for example on my code i say go to example.com and from inside of element class="images" grab all images.
notes: not all images from the page, just from inside the element
whether element has 3 images in it or 50 or 100 i don't care.
here's what i tried and worked using php
<?php
$html = file_get_contents('http://www.tgo-tv.net');
preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i',$html, $matches );
echo $matches[ 1 ][ 0 ];
?>
this gets image name and path but what i am trying to make is a save dialog box and the code must save image directly into that path instead of echo it out
hope you understand
Edit 2
it's ok of Not having save dialog box. i must specify save path from the code
If you want something generic, you can use:
<?php
$the_site = "http://somesite.com";
$the_tag = "div"; #
$the_class = "images";
$html = file_get_contents($the_site);
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
foreach ($xpath->query('//'.$the_tag.'[contains(#class,"'.$the_class.'")]/img') as $item) {
$img_src = $item->getAttribute('src');
print $img_src."\n";
}
Usage:
Change the site, tag, which can be a div, span, a, etc. also change the class name.
For example, change the values to:
$the_site = "https://stackoverflow.com/questions/23674744/what-is-the-equivalent-of-python-any-and-all-functions-in-javascript";
$the_tag = "div"; #
$the_class = "gravatar-wrapper-32";
Output:
https://www.gravatar.com/avatar/67d8ca039ee1ffd5c6db0d29aeb4b168?s=32&d=identicon&r=PG
https://www.gravatar.com/avatar/24da669dda96b6f17a802bdb7f6d429f?s=32&d=identicon&r=PG
https://www.gravatar.com/avatar/24780fb6df85a943c7aea0402c843737?s=32&d=identicon&r=PG
Maybe you should try HTML DOM Parser for PHP. I've found this tool recently and to be honest it works pretty well. It was JQuery-like selectors as you can see on the site. I suggest you to take a look and try something like:
<?php
require_once("./simple_html_dom.php");
foreach ($html->find("<tag>") as $<tag>) //Start from the root (<html></html>) find the the parent tag you want to search in instead of <tag> (e.g "div" if you want to search in all divs)
{
foreach ($<tag>->find("img") as $img) //Start searching for img tag in all (divs) you found
{
echo $img->src . "<br>"; //Output the information from the img's src attribute (if the found tag is <img src="www.example.com/cat.png"> you will get www.example.com/cat.png as result)
}
}
?>
I hope i helped you less or more.
I have a site running Typo3.
If I add an element of the type image or textpic, I want the <img>-tag to be surrounded by a couple of divs. So, i thought, i have to use typoscript for that.
So I added:
tt_content {
image.20.wrap = <div class="hello">|</div>
}
I can see it in the object-browser, but it isn't displayed in the frontend. From what i got so far, is, that for image and textpic I have to override this image.20.
Typoscript:
tt_content {
uploads.wrap = <div class="tro-uploads-wrap">|</div>
}
tt_content {
table.wrap = <div class="tro-table-wrap">|</div>
}
tt_content.image.20.imageStdWrap.wrap = <div>|</div>
Adding a wrap around the whole element can be done via:
tt_content.image.20.stdWrap.wrap = <div>|</div>
If you just want to wrap the image it self, use
tt_content.image.20.imageStdWrap.wrap = <div>|</div>
I wrote a code so as in manual with treeview.
div id="treview-back">
<?php
$treeview = new \Kendo\UI\TreeView('treeview');
// helper function that creates TreeViewItem with imageUrl
function ImageTreeViewItem($text) {
$item = new \Kendo\UI\TreeViewItem($text);
return $item;
}
$msg = ImageTreeViewItem('Message');
$msg->addItem(
ImageTreeViewItem('New Message'),
ImageTreeViewItem('Replay')
);
$msg->expanded(true);
$inbox = ImageTreeViewItem('Home');
$inbox->expanded(TRUE);
$inbox->addItem($msg);
$dataSource = new \Kendo\Data\HierarchicalDataSource();
// add root-level nodes as datasource data
$dataSource->data(array($inbox));
$treeview->dataSource($dataSource);
echo $treeview->render();
?></div>
I need to add a Splitter widget, how do I have to do it? I didn't find it at manual.
Why, if I add this code
<script type="text/javascript">$("#treeview").kendoTreeView({
checkboxes: true
});</script>
The TreeView disappears.
The structure of the code is pretty much the same that you were doing for a tree.
<div id="outer-splitter">
<?php
$treeview = new \Kendo\UI\TreeView('treeview');
// helper function that creates TreeViewItem with imageUrl
function ImageTreeViewItem($text) {
$item = new \Kendo\UI\TreeViewItem($text);
return $item;
}
$msg = ImageTreeViewItem('Message');
$msg->addItem(ImageTreeViewItem('New Message'), ImageTreeViewItem('Replay'));
$msg->expanded(true);
$inbox = ImageTreeViewItem('Home');
$inbox->expanded(TRUE);
$inbox->addItem($msg);
$dataSource = new \Kendo\Data\HierarchicalDataSource();
// add root-level nodes as datasource data
$dataSource->data(array($inbox));
$treeview->dataSource($dataSource);
// Create Left Pane
$leftPane = new \Kendo\UI\SplitterPane();
$leftPane->attr("id", "left-pane")->collapsible(true)->size(220)->content($treeview->render());
// Create Right Pane
$rightPane = new \Kendo\UI\SplitterPane();
$rightPane->attr("id", "right-pane")->collapsible(true)->size(220)->startContent();
?>
<div>
Right pane
</div>
<?php
$rightPane->endContent();
// create outer splitter
$splitter = new \Kendo\UI\Splitter('splitter');
$splitter->orientation("horizontal");
$splitter->addPane($leftPane);
$splitter->addPane($rightPane);
echo $splitter->render();
?>
</div>
You need to use \Kendo\UI\Splitter for configuring the Splitter, setting itscontent`. Here I used:
orientation for setting the orientation of the pane. horizontal means that they are tiled horizontally.
addPane Allows you to add \Kendo\Ui\SplitterPane.
In \Kendo\Ui\SplitterPane, I've used content for adding the another widget definition inside and startContent and endContent for delimiting the begin and end of an HTML block.
You can find very good information in here.
Your code makes the splitter disappear since that's a different way of using Kendo UI widgets (pure-JavaScript, not using PHP wrappers) and in that piece of code you are not defining the content of the new TreeView.
I'm trying to use zend pdf to load multiple pdfs from file (each a 1 page pdf) then draw text, images etc. onto each one. Ideally the drawn text and images would be added within a function. However when I try to do some basic draw it comes back with an error in the pdf. The code works perfectly fine until I try draw text onto the page.
require_once 'zendframework/library/Zend/Loader/Autoloader.php';
include 'form-structures.php'; //
$loader = Zend_Loader_Autoloader::getInstance();
$pdfMerged = new Zend_Pdf();
//load pdf
$loadedpdf = Zend_Pdf::load("form-url.pdf");
//clone pdf
$page1 = clone $loadedpdf->pages[0];
// add text etc.
$page1->drawText('Some text...', 400, 500);
drawmore($page1);
//merge pdf
$pdfMerged->pages[] = $page1;
// do again
$loadedpdf = Zend_Pdf::load("form-url.pdf");
$page = clone $loadedpdf->pages[0];
$pdfMerged->pages[] = $page;
echo $pdfMerged->render();
The form-structure.php file is below with a function to draw something extra on the page:
function drawmore($page)
{
$page->drawText("Height is: 600px", 300,800);
return $page;
}
Resolved.
Zend PDF can't draw text on the screen unless you already specified the font.
I just added:
$page1->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 20);
and it fixed the error.