MODX MIGX data in chunk - json

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...

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:

How to keep metadata fields on one line

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!

MediaWiki: changing the label of a category at the bottom of the page

In mediawiki, is it possible to change the label of a 'Category' at the bottom of an article.
For example for the following article:
=Paris=
blablablablablabla
[[Category:place_id]]
I'd like to see something more verbose like (the example below doesn't work):
=Paris=
blablablablablabla
[[Category:place_id|France]]
Note: I don't want to use a 'redirect' and I want to keep my strange ids because they are linked to an external database.
I do not think mediawiki is supporting this feature.
However, how about using:
[[Category:France]]
in your page, and set it into the category named with your id? France would just be a subcategory of "place_id", and you could use more terms all linked to the parent category. For this, you just need to edit the category page for "France", inserting:
[[Category:place_id]]
An alternative would be to put your page in both categories, but in this case, the id would still be displayed:
[[Category:place_id]]
[[Category:France]]
You could do this with an OutputPageMakeCategoryLinks hook. Alas, the interface for that hook seems to be a bit inconvenient — as far as I can tell, it's pretty much only good for replacing the standard category link generation code entirely. Still, you could do that is you want:
function myOutputPageMakeCategoryLinks( &$out, $categories, &$links ) {
foreach ( $categories as $category => $type ) {
$title = Title::makeTitleSafe( NS_CATEGORY, $category );
$text = $title->getText();
if ( $text == 'Place id' ) {
// set $text to something else
}
$links[$type][] = Linker::link( $title, htmlspecialchars( $text ) );
}
return false; // skip default link generation
}
$wgHooks['OutputPageMakeCategoryLinks'][] = 'myOutputPageMakeCategoryLinks';
(The code above is based on the default category link generation code in OutputPage.php, somewhat simplified; I assume you're not using language variant conversion on your wiki, so I removed the parts that deal with that. Note that this code is untested! Use at your own risk.)

Perl parse links from HTML Table

I'm trying to get links from table in HTML. By using HTML::TableExtract, I'm able to parse table and get text (i.e. Ability, Abnormal in below example) but cannot get link that involves in the table. For example,
<table id="AlphabetTable">
<tr>
<td>
Ability <span class="count">2650</span>
</td>
<td>
Abnormal <span class="count">26</span>
</td>
</table>
Is there a way to get link using HTML::TableExtract ? or other module that could possibly use in this situation. Thanks
part of my code:
$mech->get($link->url());
$te->parse($mech->content);
foreach $ts ($te->tables){
foreach $row ($ts->rows){
print #$row[0]; #it only prints text part
#but I want its link
}
}
HTML::LinkExtor, passing the extracted table text to its parse method.
my $le = HTML::LinkExtor->new();
foreach $ts ($te->tables){
foreach $row ($ts->rows){
$le->parse($row->[0]);
for my $link_tag ( $le->links ) {
my ($tag, %links) = #$link_tag;
# next if $tag ne 'a'; # exclude other kinds of links?
print for values %links;
}
}
}
Use keep_html option in the constructor.
keep_html
Return the raw HTML contained in the cell, rather than just the visible text. Embedded tables are not retained in the HTML extracted from a cell. Patterns for header matches must take into account HTML in the string if this option is enabled. This option has no effect if extracting into an element tree structure.
$te = HTML::TableExtract->new( keep_html => 1, headers => [qw(field1 ... fieldN)]);

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.