Get page Body contents in MODX - php

My MODX site needs to grab the first image from all pages for Open Graph Meta tags, which will be plugged into the Head chunk for all templates.
The problem with this is that not all images are located in the content part of a page. Some are located inside Chunks and others inside TVs. (Finding an image tag from the content is not an issue.)
It might be possible to get all Chunks and TVs and loop through their values to check for images.
But is there a way to get the <body> contents of the resource?

Probably several ways, you can try writing a plugin to parse through the entire content of a page, looks like the OnWebPageComplete event may be the one to use (take a look at the different events to see if one is more appropriate}
You can try and grab the resource from the cache, keeping in mind that any chnks/snippets/TVs called in the page un-cached will not show up in the resource cache file.
You can get a list of TVs once you have loaded a resource & then use getTVValue to get the value.
If you have an image in a chunk, getChunk might work [might, I've never tried to use it that way] to get it's contents but I would image that the image in a chunk would come from a TV ~ so you should be able to retrieve it with getTVValue.
You could also just setup a TV for the OpenGraph image and explicitly set it on a page by page basis.
Probably writing a plugin & some regex is going to be the least painful way of going about it.

Related

get URL from XML enclosure

http://paultan.org/feed/
In above feed I can get the img ur like http://s2.paultan.org/image/2014/12/Theo-top-10-fave-renders-108x108.jpg
but in feedly.com I'm seeing other link of image, which have bigger size. I wonder how feedly can retrieve the 's content since it's not in the feed's DOM.
Would this link represent the large image that you see?
http://s1.paultan.org/image/2014/12/top-10-posts.jpg
feedly.com may be reading the destination page once and save it in their database. From the header you have a Facebook entry as follow:
<meta content="http://s1.paultan.org/image/2014/12/top-10-posts.jpg"
property="og:image">
which feedly.com would be using to present the image. This, of course, means a lot more bandwidth used in order to be able to display such information. They may also limit it to websites that have such headers (so they test once or twice, if the website does not offer a link like the og:image, they stop testing that website altogether, at least for a while...)

Fetch Images from URL - Like Facebook Thumbnail

I am building a "Reddit" like site.
The User can post an URL from which I want to get the correct image with PHP.
What I would need is a script which sites like Facebook or Tumblr use to fetch the Images.
I saw already scripts which get the images by getting the HTML Content and searching for "img" tags.
Are there any better methods/scripts available?
Maybe even scripts which will order the images by the size: The bigger the image the more important it is.
Thanks for answers
You may want to check out PHPQuery, it will allow you easily iterate through all images on a given website. You can then work out the areas of each image and sort them accordingly.
It depends a bit for what you're looking for and what the image is that the user would like to have with his post. To give you an example: I once wrote a method that searches for a logo of a company on the company's website. To do so, I searched for, indeed, the img-tags using simple_html_dom and filtered those tags on the existence of logo in the alt-tag. The results are displayed to the user to select the right image; it could be that you find multiple images fitting your purpose.
I would indeed, as you proposed, have a look at the size and skip small images (e.g. smaller dan lets say 50 px).

Adding a prev and next functionality to a random image page

A script I've inherited is showing a random image on the homepage. The random image is currently determined (ugh) by grabbing an array of all of the images, then
$rand_keys = array_rand($array_photoid, 2);
$photoid = $photo_rows[$rand_keys[0]];
No doubt this worked swell when there were only a few dozen images, but now there are 5000 and this needs fixing.
While rewriting this I'd like to add in some functionality that allows users to go to the Previous and Next image. Going forward is easy enough, just draw up another random ID from the table.
How would I allow users to go back over previously shown random images? Is this even possible without resorting to a hack like above (storing all id's in a session array).
You might want to use jQuery for this instead and use the image slider plugin that supports ajax. So you load the next image via ajax request. When going back to previous image, its already loaded before so don't need to worry about the 'prev' function. (https://www.google.com.sg/search?q=photo+slider).
And then you load the page to a random image on the slideshow.

Is there a way to include a playlist as a variable or link to an external file in Flowplayer?

I am wondering if there is a way to include a playlist as a variable or link to an external file in Flowplayer. I know that you can use RSS playlists, but I need to use the start and duration parameters to combine clips into a single stream and am not sure that those can be used with RSS playlists.
I would like to be able to keep my playlist external from the player if possible, so that it is easier to manage. What I am trying to do is have a player and several buttons on my page. The buttons each cause a different playlist to be played. I have everything worked out up until the point of actually inserting the playlist.
Right now I am simply writing the content of my playlist file to the player page using a search and replace, but I am hoping there is a better way.
Thank you for reading my post.
You can use an array of JSON objects that can be loaded even by AJAX.
You can also use an external configuration file, that can be generated by PHP itself.
Here are some help links:
http://flowplayer.org/demos/configuration/external.html
http://flowplayer.org/documentation/configuration/playlists.html
http://flowplayer.org/plugins/javascript/playlist.html

How to load image in order?

I am working with php. I have images kept in order. When i do query the images comes in order but when they load they does not load in order. The small images load first and then big images. For example I have 5 images. These images should be loaded in order(1,2,3,4,5). But here its not happening. Image 4 loads first, then 2, 1 and so on. So what can i do for this problem? Hope to get solution.
Thanks in advance.
If you are speaking about the order images are displayed by a web browser, you do not have much control over that, as long as you have several <img> tag on your page :
the browser will request the images from the server in the order it wants (most probably, the first <img> tag encountered will be the first image requested)
each image takes some time to download ; and each image is displayed when it's downloaded ; considering small images should be downloaded faster, small images should be displayed first... depending on the order they were requested -- see previous point.
In the end, if you want absolute control on the order the images are displayed, your initial HTML should probably not contain all the <img> tags: a solution would be to add those, in the right order, when the previous image is downloaded.
This can probably be done with some JavaScript code, to detect when an image is loaded (event "load") ; and when an image is loaded, just add a new <img> tag to the page, for the next one; and so on.
But I wouldn't go with such an idea: it won't work if JS is disabled, your images will not be seen by search engines.
You can control everything on your web server, but nothing on network or browser sides.
A possible solution is to build a single image containing your five images and display each relevant portion to its dedicated position.
Have you tried preloading them with a JavaScript library?
Not sure how you would implement this in PHP, but in the past I have usually had the a 'order' field for each image, then the images were added dynamically according to the 'order' field.
As you should have guessed, image is loaded according to their sizes. Ofcourse, the smaller ones will load before the bigger ones. And yeah, as eyze said, wat about you preload them with a javascript preloader and display them in the right order?

Categories