How to keep metadata fields on one line - html

I am trying to customize the metadata for my posts. Specifically, I want to change the separator from the default forward slash (/) to a vertical line (|). I also want to add the word "Updated" before the date displayed. And, I want to keep the option to display reading time. (*FYI: I know basically nothing about coding, just trying to override the metadata output from Astra)
I used this code to change the separator (found in a post about how to customize post meta in Astra theme):
add_filter('astra_single_post_meta', 'custom_post_meta');
function custom_post_meta($old_meta)
{
$post_meta = astra_get_option('blog-single-meta');
if (!$post_meta) return $old_meta;
$new_output = astra_get_post_meta($post_meta, "|");
if (!$new_output) return $old_meta;
return "<div class='entry-meta'>$new_output</div>";
}
See the output in image 1 - looks great!
output of new code for separator
This is close, but still needed to add "Updated" before the date. So, I used this code (from same post mentioned above):
function astra_post_date()
{
$format = apply_filters('astra_post_date_format', '');
$published = esc_html(get_the_date($format));
$modified = esc_html(get_the_modified_date($format));
$output = '<p class="posted-on">';
$output .= 'Updated: <span class="published" ';
$output .= 'itemprop="datePublished">' . $published;
$output .= '</span>';
$output .= '</p>';
return apply_filters('astra_post_date', $output);
}
See output in image 2 - content is perfect, but formatting is wrong. Can't figure out how to edit the code to get all 3 fields on the same line.
output of new code for adding "Update"
What do I need to change in the 2nd block of code to keep everything on one line like the 1st block of code?
Thanks for any help!

Related

Load one of multiple items from API result that has a "list / set"

I have a API result that contains multiple photo's in a set / list / childs (I do not know the right term), the result looks like this.
"photos":[{"small":"https:\/\/pararius-office-prod.global.ssl.fastly.net\/10379\/files\/photos\/api-little\/52016521.1667319824-357.jpeg?fit=crop&width=100&height=100",
"big":"https:\/\/pararius-office-prod.global.ssl.fastly.net\/10379\/files\/photos\/api-export\/52016521.1667319824-357.jpeg?width=600",
"huge":"https:\/\/pararius-office-prod.global.ssl.fastly.net\/10379\/files\/photos\/api-huge\/52016521.1667319824-357.jpeg?width=1000&fit=bounds",
"middle":"https:\/\/pararius-office-prod.global.ssl.fastly.net\/10379\/files\/photos\/api-middle\/52016521.1667319824-357.jpeg?width=1000&fit=bounds",
"category":"photo"}]
I want to shot the big photo but I don't know how.
The rest is working fine.
I tried to load it with '. $property->city . ' but that does not work.
I assume you need to get the 'big' photo from "photos".
I start by copying your photo data into $results.
echo '<pre>';
$results = '"photos":[{"small":"https:\/\/pararius-office-prod.global.ssl.fastly.net\/10379\/files\/photos\/api-little\/52016521.1667319824-357.jpeg?fit=crop&width=100&height=100",
"big":"https:\/\/pararius-office-prod.global.ssl.fastly.net\/10379\/files\/photos\/api-export\/52016521.1667319824-357.jpeg?width=600",
"huge":"https:\/\/pararius-office-prod.global.ssl.fastly.net\/10379\/files\/photos\/api-huge\/52016521.1667319824-357.jpeg?width=1000&fit=bounds",
"middle":"https:\/\/pararius-office-prod.global.ssl.fastly.net\/10379\/files\/photos\/api-middle\/52016521.1667319824-357.jpeg?width=1000&fit=bounds",
"category":"photo"}]';
echo "$results\n\n";
I then get a substring from the 10th character, removing photos:[
Remove the slashes.
And trim the trailing ].
We now have valid JSON.
$results = stripslashes(trim(substr($results,10),']'));
echo "$results\n\n";
To confirm the JSON is now valid I convert it to an array.
$results = json_decode($results,1);
var_export($results);
I then get the 'big' photo src.
$src = $results['big'];
echo "\n\nsrc = $src\n\n";
echo '</pre>';
Then show the photo:
echo "<img src=\"$src\" />";
The Result:

creating table from 2-Dimensional array in perl has different outputs

Hi I am generating table from a 2-Dimensional array in perl.
But the output of my program is different if viewed in browser and viewing page source using developers tool in chrome:
Let me explain-
I have a subroutine to print the table from #RESULT array, the code is below
sub printTableFormattedEmpty {
my #array= #_ ;
print "<table border='0' cellspacing='0' bgcolor='#cfcfcf' cellpadding='0'>\n";
for(my $row_i = 0; $row_i < #array; $row_i++) {
print "<tr style='background-color:#B39DB3;'>\n";
for(my $column_i = 0; $column_i < #{ $array[$row_i] }; $column_i++) {
my $th = ($row_i == 0) ? "th" : "td";
print "</$th>";
print "$array[$row_i][$column_i]";
my $close = ($row_i == 0) ? 'th' : 'td';
print "</$close> \n";
}
print "</tr> \n";
}
print "</table> \n";
}
and i am calling the subroutine as
{
print "Table starts here!\n";
#$RESULT[0]- is array of many elements. u can see in output image
$RESULT[1][0]= 'No Active bookings available for you !';
$RESULT[2][0]= 'Click here to create new Booking !';
&printTableFormattedEmpty(#RESULT);
}
Now here i am not getting the expected output in a table , i am getting different output as shown in 2 figure:
when i inspect element and inspect the table i get:
But when i view page source of the page iam getting output formatted as table as shown in the fig:
I am really confused with this two types of Output, the both images are of the same page without refreshing.
How is this possible!
Did i do any mistake in my program or its something else.
Please Help me with This.
This is a typo!
There is a slash / in your opening HTML tag output.
for(my $column_i = 0; $column_i < #{ $array[$row_i] }; $column_i++) {
my $th = ($row_i == 0) ? "th" : "td";
# V HERE
print "</$th>";
print "$array[$row_i][$column_i]";
my $close = ($row_i == 0) ? 'th' : 'td';
print "</$close> \n";
}
Remove that slash and it will be fine.
As to why your two outputs are different: The HTML inspector shows the DOM structure after it has been parsed by the browser. It does not include invalid elements. Since stray closing elements are not valid, it's likely the parser just omitted them, so they are gone.
Viewing the source code on the other hand shows the real, unparsed code, which contains the wrong markup with the faulty HTML tags included. That is also where I saw the extra slashes. (read: your variable names are badly chosen. You would have seen it yourself had it been something like $open_tag and $closing_tag).

MODX MIGX data in chunk

I have created similar table to this one
http://rtfm.modx.com/display/ADDON/MIGX.Simple+opening+hours+table
I have successfully exported data to resource, but i want to show it in a chunk so i can display it in getresources.
I use getresources to display resources and besides title and intro text i would like to show datesTV data.
I use template chunk for migx:
[[+date:notempty=`<td>[[+date:strtotime:date=`%d.%m.%Y, %H.%M`]]</td>`:default=`<td colspan="2">No show!</td>`]]
If i use this in other chunk for getresources [[+tv.datesTV]] i get this array out:
[{"MIGX_id":"1","date":"2012-10-28 21:00:00"},{"MIGX_id":"2","date":"2012-10-28 01:45:00"},{"MIGX_id":"3","date":"2012-10-30 02:45:00"}]
How can I display this data as it should be in a chunk.
Ok here you can se how my snippet looks like..
<?php
$strJSON = $modx->resource->getTVValue('spored');
$arrJSON = $modx->fromJSON($strJSON);
foreach($arrJSON as $arrJSONDataSet)
{
foreach($arrJSONDataSet as $key => $value)
{
echo $key . ' => ';
echo $value;
echo '<br />';
}
}
With MIGX you need a snippet to parse and format the raw TV data as it's stored as JSON.
For a rough example of how to do this, refer back to the link you mentioned and try the getImageList snippet:
http://rtfm.modx.com/display/ADDON/MIGX.Simple+opening+hours+table#MIGX.Simpleopeninghourstable-ParsingtheData
You'll need to include that snippet call in your getResources chunk which is going to be really inefficient; it would be better to code up a custom snippet to retrieve the necessary data.
But see how that goes first...

downloading Blob file in cakephp

i am using this query to get image saved in medium blob in mysql which calls download function in brands controller
SELECT *,CONCAT(\"<img src='../../brands/download/?file_id=\",id,
\"&name=\",logo_name,\"'/>\") AS file
FROM c_brands WHERE merchant_id=" .$merchant_session;
DOWN LOAD FUNCTION
function download()
{
//$this->view = 'Media';
Configure::write('debug', 1);
$id = $_GET["file_id"];
$file = $this->Brand->findById($id);
header('Content-type: ' . $file['Brand']['logo_type']);
header('Content-length: ' . $file['Brand']['logo_size']);
header('Content-Disposition: inline; filename='.$file['Brand']['logo_name']);
echo $file['Brand']['logo'];
exit();
}
But somehow it is just displaying the placeholder for image.
Can you explain more? I mean, what's the relation between the first query (the one with Concat) and the download() action, plus how are you using this query? Also, I notice that you are putting <img src='../../brands/download/?file_id=\", and that relative path is wrong. It must be src="/brands/download".
Still, your question is not clear.

PHP: Inject iframe right after body tag

I would like to place an iframe right below the start of the body tag. This has some issues since the body tag can have various attributes and odd whitespace. My guess is this will will require regular expressions to do correctly.
EDIT: This solution has to work with php 4 & performance is a concern of mine. It's for this http://drupal.org/node/586210#comment-2567398
You can use DOMDocument and friends. Assuming you have a variable html containing the existing HTML document as a string, the basic code is:
$doc = new DOMDocument();
$doc->loadHTML(html);
$body = $doc->getElementsByTagName('body')->item(0);
$iframe = $doc->createElement('iframe');
$body->insertBefore($iframe, $body->firstChild);
To retrieve the modified HTML text, use
$html = $doc->saveHTML();
EDIT: For PHP4, you can try DOM XML.
Both PHP 4 and PHP 5 should be happy with preg_split():
/* split the string contained in $html in three parts:
* everything before the <body> tag
* the body tag with any attributes in it
* everything following the body tag
*/
$matches = preg_split('/(<body.*?>)/i', $html, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
/* assemble the HTML output back with the iframe code in it */
$injectedHTML = $matches[0] . $matches[1] . $iframeCode . $matches[2];
Using regular expressions brings up performance concerns... This is what I'm going for
<?php
$html = file_get_contents('http://www.yahoo.com/');
$start = stripos($html, '<body');
$end = stripos($html, '>', $start);
$body = substr_replace($html, '<IFRAME INSERT>', $end+1, 0);
echo htmlentities($body);
?>
Thoughts?