preg_match search pattern and insert - preg-match

Hi can any one help me I try to insert one image or text from one variable using preg_match
First I record the Variable in one file and I call:
function bbanner_fetch($a) {
$bannerUrl = get_config('bbanner','bannerUrl');
Follow by:
$url = $_SERVER['REQUEST_URI'];
switch($url){
case "/";
if(preg_match("/^(\Social)/", strtolower($line)))
{
echo 'SEE DETAILS FOUND';
$a->page['htmlhead'] .= "$bannerUrl" . "\r\n";
break;
}
That is a test using the word Social is In the Url /
But I not find or insert nothing My idea is insert a text or image embed
after the code "<script type="text/javascript"> $(document).ready(function() { $("#id_username").focus();} );</script>"
from the variable bannerUrl
Any one have please any idea how is solve?
Thanks

Related

Custom intro text in joomla 3.5

I am trying to make the intro text is seperated and isn't extracted from the full text of Joomla 3.5.
To do that: I make a
<div class="intro-custom">the content that i need to show as intro-text</div>
,
put this at the top position of each article and use CSS to hide in display content.
But i dont know how to bring
<div class="intro-custom">
this to the front.
I found this file components/com-contents/view/category/tmpl/default_articles.php
<?php
$text = $article->introtext;
$text = preg_replace('#<div[^>]*class=(["\'])mosimage_caption\\1[^>]*>[^>]* </div>#', '', $text );
$preserv = "";
$text = strip_tags($text, /* exclude */ $preserv );
$text = preg_replace("#<script[^>]*?>.*?</script>#si","",$text);
$text = preg_replace('/{.+?}/','',$text);
$text = preg_replace('/(( )|( ))+/',' ',$text);
$text = preg_replace('/"/',' ',$text);
$text = str_replace(array("\r\n", "\n", "\r"), "", $text);
$text = str_replace("caption","", $text);
$shorttext = substr($text,0,300);
echo '<p>' . $shorttext . '...</p><p>Read more</p>';
?>
I just know CSS and HTML, any help?
Template override
First thing, use template override so that your changes will not be overwritten at next Joomla update. In your case, this means that you need to create a folder:
/templates/[YOUR TEMPLATE]/html/com_content/category/
and copy the file default_articles.php in this folder.
Edit template
If I understood your question correctly, you want to show always the same intro text for all articles, instead of using the intro text from the article themselves.
So you can remove all the code in the file and replace it with:
<div class="intro-custom">
<p>>the content that i need to show as intro-text</p>
<p>Read more</p>
</div>
You can then adapt HTML / CSS as you like.

how to put <b> tag in string in smarty template

I am using SMARTY and I need to put <b> tag in string in the following php code i can put tag in string
$search = 'this is my sample strangŲ§';
$dbContent = 'this strang is for sample hello world';
$search = explode( ' ' , $search );
function wrapTag($inVal){
return '<b>'.$inVal.'</b>';
}
$replace = array_map( 'wrapTag' , $search );
$dbContent = str_replace( $search , $replace , $dbContent );
echo $dbContent;
how to use this code in smarty template or how to convert this code for smarty
In my opinion there's no need put such code into Smarty template, so the only thing you should do is
$smarty->assign('dbContent', $dbContent);
and in Smarty template file:
{$dbContent}
You should separate logic and display. In this case you shouldn't rather move this code to Smarty. If Your wrapTag function contained a lot of HTML you could do it this way ( I know global is not nice solution but probably it could be done also in the other way):
function wrapTag($inVal){
global $smarty;
$smarty->assign('inVal', $inVal);
return $smarty->fetch('bold_template.tpl');
}
and inside bold_template.tpl you could have:
<b>{$inVal}</b>
But if you only add <b> tags there's no point to put it in Smarty template

How to redirect WORDPRESS hotlinked image ( for exp : Image.jpg) to post/page where it is?

Recently google change image search and as a result most of the traffic click over view original image and it send them to direct image file.
I have changed my .htaccess and stop all hot linking and redirect to my homepage if they click over image file.
Recently I've also tried if it is possible to redirect to post or page where image is.
By the following code
<?php
require('../wp-blog-header.php');
$imageURL = strip_tags( $_GET['id'] );
if imageURL!== "") {
$query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment'AND post_parent > '0' AND guid = '$imageURL'";
$linkedImage = $wpdb-get_row($query);
$attachmentUrl = get_attachment_link($linkedImage->ID);
if($attachmentUrl !== "" && !is_numeric(stripos($attachmentUrl, "attachment_id=0"))) {
header("HTTP/1.1 302 Found");
header("Location: ". $attachmentUrl);
exit;
}
}
$newUrl = get_site_url() . "/image-not-found";
header("HTTP/1.0 404 Not Found");
header("Location: " . $newUrl);
exit;
?>
But it redirect to http://www.mydomain.com/?attachment_id=
id is nil or can't fetch the proper id
My website in Wordpress CMS version 3.5.1
can anyone help how to redirect to proper attachment page for .jpg file direct request.
Thanks in advance
Your code would only work if there was an ID parameter on the requested URL that would be an exact match with the image URL, for instance http://www.example.com/?id=http://www.example.com/uploads/Some-Image.jpg
Is this the case? Even so, you shouldn't use id since it's a reserved parameter for other things in WP. In your .htaccess, you should redirect http://www.example.com/uploads/Some-Image.jpg to, for example, http://www.example.com/?image_redirect=http://www.example.com/uploads/Some-Image.jpg. Then use $imageURL = $_GET['image_redirect'].
Other notes: strip_tags doesn't make a string safe to use as a SQL query. In WordPress, you have esc_sql($string) for that. Also, you should rather use if ( $imageUrl != '' ), not with !==. And there's an error on line 5, it should say $wpdb->get_row, you currently have a minus sign. I assume these are typos. And finally, you shouldn't use Location: header with a status code 404.

html is pass using jquery ajax but pdf is not generating in mpdf for codeigniter

I want to create a PDF in codeigniter using mPDF. My html is passed to the controller using jQuery AJAX. Data is coming to the $html But it is not working. It works fine when html is hard coded. Can any one help me please?
public function pdf($paper='A4')
{
$html = '';
$html = $this->input->POST('content');
$this->load->library('mpdf54/mpdf');
$CI->mpdf = new mPDF('utf-8',$paper);
$mpdf->debug = true;
$this->mpdf->WriteHTML($html);
$this->mpdf->Output();
exit;
}
Try grabbing all the POST vars by using
$html = $this->input->POST();
then echo those out to yourself before moving farther to be sure they are getting set.
public function pdf($paper='A4')
{
print_r($this->input->POST());
return;
}
This of course is only for testing but might help you to see why your $html var isn't getting set. Try that out and give us the results.

How to use jQuery's formatItem, formatMatch, and formatResult options for .autocomplete?

I am making use of jQuery's .autocomplete plugin, and I would appreciate some assistance formating the results that show up in the dropdown menu that populates when text is written into the input field.
In order to get the data to populate the autocomplete, I pull from mySQL using this PHP:
$sql = ( 'SELECT tag, title, author, content, id FROM labels' );
$result = mysql_query( $sql );
$Response = array();
while( $row = mysql_fetch_object( $result ) ){
$Response[] = array(
"id" => $row->id,
"name" => $row->tag . ": " . $row->title . ": " . $row->content .""
);
}
When a user selects the option from the autocomplete that is best for them, I convert the "name" above into the "id" using this method:
var AllTagData = ;
var Tags = [];
for(var i in AllTagData){
Tags.push(AllTagData[i].name);
}
function getIdFromTag(_name){
for(var i in AllTagData){
if(_name == AllTagData[i].name){
return AllTagData[i].id;
}
}
}
So far, so good. Finally, I use the jQuery autocomplete plugin to output the data for the user:
$(document).ready(function(){
$("#Responses").autocomplete({
source: Tags,
matchContains: true,
autoFill: true,
select: function(e, ui){
$("#hidden_tags").val( getIdFromTags($("#Responses").val()) );
}});
});
This final portion of the code is where I need help implementing the formatItem, formatMatch, and formatResult options.
From the PHP given above, I output Tags, Title, and Content all in the "name". The way that I would like to format my autocomplete options for the user is
Show Tags & Title
Hide Content
Search through Tags, Title, and Content for possible matches
Therefore, even though I want the autocomplete to search through Content, I don't want Content showing up in the populated autocomplete list. I only want the Tags and Title to show.
I've been having a lot of trouble with this and have searched quite extensively to find an answer and would really appreciate any help you can give on how to accomplish this. Please ask any follow up questions if you need further clarification.
Thanks!
I think you are using a different version of the plugin, but if you look at this one:
http://code.google.com/p/jquery-autocomplete/
You will find a file index.html with the examples you ask for, for example:
showResult: function(value, data) {
return '<span style="color:red">' + value + '</span>';
},
Good luck!

Resources