How to switch the (single/double) quotes for a Tweet me button - quotes

I spent about 2 hours trying to make a blending of 2 codes work, and feeling the weakness of my code skills, I am reaching out here for some help.
I think the problem lies in the single/double quotes. I tried many, many times to reformat the quotations (and both ways ie reformatting both scripts to accommodate each other).
The image (which should be linked) is added to the page in the functions.php -- the image is path/image.png in this example:
! is_admin() && add_filter( 'the_content', function( $content )
{
if( in_the_loop() ) // <-- Target the main loop
{
$prepend = "<div style='color:#808080 ; border:1px solid #909090 ; border-radius:5px; float:left; padding-top:1px;'> <**img src='/path/image.png' alt='Tweet this' style='margin-bottom: -4px; '**>Tweet this  </div> ";
$content = $prepend . $content;
}
return $content;
}, 9 );
This is the link -- When the user clicks the image, I want them to access this link:
<a href='https://twitter.com/share?url=<?php echo $post_url ?>&text=<?php echo $post_title ?>' onclick='window.open(this.href,"popupwindow", "width=800,height=500,left=200,top=5,scrollbars,toolbar=0,resizable"); return false;' Target='_blank' >twitter</a>
What I want to end up with is: Click the image on the page, (it opens the Twitter link,) user gets to Tweet (share) the post they are on on Twitter.
So user clicks image (path/image.png) and opens link (twitter.com...etc).

Still not sure of anything: you should realize that your question lacks clarity.
Notably because you don't say where $post_url and $post_title comes from, nor explain what are $prepend and $content, and don't explain at all your function's use and context.
But I'll talk about what I believe to have understood.
Your goal seems to result in this kind of HTML part:
<div style="color:#808080; border:1px solid #909090; border-radius:5px; float:left; padding-top:1px;">
<a href="https://twitter.com/share?url=the-post_url&text=the-post_title"
onclick="window.open(this.href,'popupwindow','width=800,height=500,left=200,top=5,scrollbars,toolbar=0,resizable'); return false;"
target="_blank">
<img src="/path/image.png" alt="Tweet this" style="margin-bottom:-4px;">
Tweet this  
</a>
</div>
(you'll notice that I've returned back to arbitrary give precedence to double-quotes, which is the most standard choice)
Say we call $div, $a, and $img the source main components, to output the desired block we simply have to write something like:
echo $div . $a . $img . 'Tweet this  </a></div';
I suppose the issue you're reporting comes from you have to define those components as strings, while they already include simple and double quotes.
So the answer is using the PHP heredoc syntax:
Heredoc text behaves just like a double-quoted string, without the double quotes. This means that quotes in a heredoc do not need to be escaped, but the escape codes listed above can still be used. Variables are expanded, but the same care must be taken when expressing complex variables inside a heredoc as with strings.
And the components definition should look like:
$div = <<<EOT
<div style="color:#808080; border:1px solid #909090; border-radius:5px; float:left; padding-top:1px;">
EOT;
$a = <<<EOT
<a href="https://twitter.com/share?url=$post_url&text=$post_title" onclick="window.open(this.href,'popupwindow','width=800,height=500,left=200,top=5,scrollbars,toolbar=0,resizable'); return false;" target="_blank">
EOT;
$img = <<<EOT
<img src="/path/image.png" alt="Tweet this" style="margin-bottom:-4px;">
EOT;
In fact many other variations may be considered, notably directly using a unique variable for the whole part...
EDIT:
Here is a working whole snippet, after integrating a value for $post_urland $post_title and corrected a typo in echo...:
$post_url="the-post-url";
$post_title="the-post-title";
$div = <<<EOT
<div style="color:#808080; border:1px solid #909090; border-radius:5px; float:left; padding-top:1px;">
EOT;
$a = <<<EOT
<a href="https://twitter.com/share?url=$post_url&text=$post_title" onclick="window.open(this.href,'popupwindow','width=800,height=500,left=200,top=5,scrollbars,toolbar=0,resizable'); return false;" target="_blank">
EOT;
$img = <<<EOT
<img src="/path/image.png" alt="Tweet this" style="margin-bottom:-4px;" />
EOT;
echo $div . $a . $img . 'Tweet this  </a></div>';

Related

How to loop an image to represent a number

i was able to display repuations in a tab but i want an image to represent the reputation number.
<i class="fa fa-star-half-o"></i> {{$artists->reputations}} </a></li>
For instance if the reputation is 5 i want an image to repeat 5 times,
if the reputation is 1 i want the image to repeat once and so on.
the image is located in my 'assets/images' folder
i tired doing something like this below
<?php
$j = artists->reputations;
#for($j=1;$j<=5;$j++)
<i class="fa fa-star-half-o"></i> <img src="assets/images/star.png" style="height:60px;"></a></li>
;?>
You are overwriting $j in your loop condition.
So you always get 5 images.
it should be looking like this if you only want 3 stars if $artists->reputations = 3.
<?php
$j = artists->reputations;
for($i=1;$i<=$j;$i++){
<i class="fa fa-star-half-o"></i> <img src="assets/images/star.png"style="height:60px;"></a></li>
}
?>

How get text right floating and right as a center?

How get text right floating and right as a center?
$text = "The epic finale that will live foreve";
$newtext = wordwrap($text, 20, "<br />\n");
echo $newtext;
Just guessing what is the question:
$text = "The epic finale that will live foreve";
$newtext = wordwrap($text, 20, "<br />\n");
echo '<div style="float: right; width:50%; text-align: center;">'.$newtext.'</div>';

My WebPages not consistent with Firefox and Chrome

I have made a website.It worked all fine during the whole development and testing phase of over 20 days during which I viewed the pages always in firefox and they were all fine.But today suddenly I encountered a problem with firefox. The table data are not centered and the borders are not rounded as they used to be earlier.But they are all fine in Google Chrome..You can view the screenshots :
Mozilla Firefox (It not used to be like this !)
Google Chrome
Please tell me how to fix it..I have cleared all the cache and session of firefox but still its the same
UPD
Ok so I am providing the codes as well:
The Php code (only snippet) of the table
$result = mysql_query("SELECT username,rating,contests,rank from users order by (rating) desc limit 10");
echo '<table id="problems">
<thead><tr>
<th colspan="3" align="center" ><font color="red" ><h2>Top Rated</h2></font></th>
</tr></thead>
<tr>
<th>#</th>
<th>Username</th>
<th >Rating </th>
</tr>';
while($row = mysql_fetch_array($result))
{
require_once("color_gen.php");
require_once("rankings.php");
ranker_rater();
$color=ColorGen($row['rating'],$row['contests']);
$uname=$row['username'];
$rank=$row['rank'];
echo "<tr>";
echo "<td>" . $rank. "</td>";
echo '<td><font color="'.$color.'">'.$uname.'</font></td>';
echo "<td>" . $row['rating'] . "</td>";
echo "</tr>";
}
echo "</table>";
And the corresponding CSS
#problems
{
text-align:centre;
border:solid;
border-width:2px;
border-color:#CCC;
width : 100%;
}
#problems th,td
{
padding: 4px;
font-weight: normal;
border:solid;
border-width:1px;
border-color:#CCC;
font-size: 15px;
color: #039;
//background: #b9c9fe;
text-align:center;
}
Know that different browsers have different default functions. This is the fundamental manner in which I attack this problem. Google chrome typically is more kind to web developers and is better at correcting errors. But, if you want something to be consistent throughout all browsers, ensure that the values are stated explicitly.
Problem 1 - Text not centered: I notice that in your CSS, your first line assigns text-align to "centre." The internet was founded by Americans, and all browsers will support the American spelling of "center." The problem is probably that Firefox does not support the British spelling of the word. I won't know until its tried, though.
Problem 2 - Corners not rounded: Since I am not a very skilled web developer, this is a problem I do not know how to solve. However, I've found a blog post by someone who does.

Download images from website

I want to have a local copy of a gallery on a website. The gallery shows the pictures at domain.com/id/1 (id increases in increments of 1) and then the image is stored at pics.domain.com/pics/original/image.format. The exact line that the images have in the HTML are
<div id="bigwall" class="right">
<img border=0 src='http://pics.domain.com/pics/original/image.jpg' name='pic' alt='' style='top: 0px; left: 0px; margin-top: 50px; height: 85%;'>
</div>
So I want to write a script that does something like this (in pseudo-code):
for(id = 1; id <= 151468; id++) {
page = "http://domain.com/id/" + id.toString();
src = returnSrc(); // Searches the html for img with name='pic' and saves the image location as a string
getImg(); // Downloads the file named in src
}
I'm not sure exactly how to do this though. I suppose I could do it in bash, using wget to download the html and then search the html manually for http://pics.domain.com/pics/original/. then use wget again to save the file, remove the html file, increment the id and repeat. The only thing is I'm not good at handling strings, so if anyone could tell me how to search for the url and replace the *s with the file name and format I should be able to get the rest going. Or if my method is stupid and you have a better one please share.
# get all pages
curl 'http://domain.com/id/[1-151468]' -o '#1.html'
# get all images
grep -oh 'http://pics.domain.com/pics/original/.*jpg' *.html >urls.txt
# download all images
sort -u urls.txt | wget -i-

Joomla Question: How to have different image in Intro Text and Main Text

Joomla Question: Is there a way to have a different image in intro text? I plan to place a different and smaller image in the introtext.
Could one not duplicate the the opening paragraph/content above the [Read More] line, except with whatever changes are needed? Then, in the article's Advanced Parameters, set the [Intro Text] value to "Hide" so the intro doesn't appear when the article is displayed normally?
look here:
http://www.theartofjoomla.com/home/5-commentary/81-joomlas-hidden-feature-hiding-intro-text.html
I added these code and it works well in my case
<?php
$text = $article->introtext;
if(preg_match('/<\s*img[^>]+>/Ui', $text, $matches)){
$image=$matches[0];
$text = str_replace($image,'',$text);
}
if ($matches) {
$image = str_replace('img src="','img width="100px" src="',$image);
$image = str_replace("caption","", $image);
echo '' . $image . '';
}
else {echo '<img width="100px" src="/images/defaultarticleimage.jpg"
class="defaultArticleImage" />';}
?>
add to the file components/com-contents/view/category/tmpl/default_articles.php (copy this file to your template first)
It's not possible with the current Joomla code.
The intro text is used to display a brief intro the article (usually on the main page) and then once the user opens the article, the intro text is displayed at the top before the rest of the text

Resources