Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2020-07-10 13:03:04

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,064
Website GitHub Mastodon Twitter

Re: Media shortcode. Requests accepted

I like youtube’s correlation between the url and the video image. As such the particular code can be amended to:

<txp:hide>YouTube</txp:hide>
<txp:if_yield name="from" value="yt">
	<txp:if_yield name="media">
		<txp:oui_cookie name='<txp:site_name trim="/\s+/" replace="_" />_youtube_cookie' duration="+1 year" values="yes" />
			<txp:oui_if_cookie name='<txp:site_name trim="/\s+/" replace="_" />_youtube_cookie'>
				<div class="embed-container" id="m_<txp:yield name="media" />"><iframe src="https://www.youtube.com/embed/<txp:yield name="media" />?rel=0" frameborder="0" allowfullscreen></iframe></div>
			<txp:else />
				<div class="gdpr">
					<img src="https://i3.ytimg.com/vi/<txp:yield name="media" />/hqdefault.jpg" <txp:if_yield name="title">alt="<txp:yield name="title" />"</txp:if_yield> />
					<txp:if_yield name="title"><txp:yield name="title" escape="textile" /></txp:if_yield>
					<p>Hosted by YouTube on <a rel="external noopener" href="https://youtube.com/<txp:yield name="media" />">youtube.com/<txp:yield name="media" /></a>.</p>
					<p><a rel="external noopener" href="https://youtube.com/privacy">YouTube&#8217;s private policy</a>.</p>
					<p class="accept"><a rel="nofollow noindex" href="?<txp:site_name trim="/\s+/" replace="_" />_youtube_cookie=yes#m_<txp:yield name="media" />">View it here</a></p>
				</div>
		</txp:oui_if_cookie>
	</txp:if_yield>
</txp:if_yield>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#26 2020-07-10 16:17:17

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,064
Website GitHub Mastodon Twitter

Re: Media shortcode. Requests accepted

I’m not sure if they cover if the cookie names I have constructed cover most site_names as I am thinking that site names with an ampersand or other special characters, including non Latin ones may not produce a valid result.

Sample code

<txp:oui_cookie name='<txp:site_name trim="/\s+/" replace="_" />_soundcloud_cookie' duration="+1 year" values="yes" />

Could someone provide some advice here?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#27 2020-07-10 16:37:59

etc
Developer
Registered: 2010-11-11
Posts: 5,132
Website GitHub

Re: Media shortcode. Requests accepted

To replace everything non-alphanumeric:

<txp:site_name trim="/\W+/" replace="_" />

or

<txp:site_name trim="/[^a-zA-Z]+/" replace="_" />

to keep only Latin characters.

Offline

#28 2020-07-10 17:23:00

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,064
Website GitHub Mastodon Twitter

Re: Media shortcode. Requests accepted

Hi Oleg, Thanks but it does not solve the problem. I changed the site name to 文字模式 岩石 and I understandably only get one underscore. I’m now thinking that trimming the site url from its http(s)://, www, extension, subdomain, and/or sub-directory might be a safer idea or even just set a user defined variable for the cookie prefix which is simpler. nope:) It’s not simpler:)

Last edited by colak (2020-07-10 17:50:24)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#29 2020-07-10 18:45:39

etc
Developer
Registered: 2010-11-11
Posts: 5,132
Website GitHub

Re: Media shortcode. Requests accepted

You can register md5 function for use in <txp:evaluate /> and call your cookies

<txp:evaluate query='md5("<txp:site_name />")' />_whatever_cookie

Offline

#30 2020-07-11 05:08:24

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,064
Website GitHub Mastodon Twitter

Re: Media shortcode. Requests accepted

It’s a good idea Oleg, but is is too abstract. I am trying to make that prefix more descriptive so, for the first time, plunging myself into the joys of regex with the help of regex101.com/ and www.phpliveregex.com/. I expected the following to work for any domain.tld or domain.xx.yy and it behaves well in the regex site although I am yet to figure out how to include an optional s after the http, as well as an optional anything for the subdomain. (dev is a subdomain I am working on).

Regardless, it does not behave in txp as it returns domain.tld instead of just the expected domain. Does anyone have any idea of how it could be adapted for our cms?

<txp:site_url trim="http:\/\/(?:dev\.)?([a-z0-9\-]+)(?:\.[a-z\.]+[\/]?).[^ ]/i" />

> and minutes after posting this, I remembered that there are domain names using non-Latin characters:)… But I do not remember any txp sites running under such domains.

Last edited by colak (2020-07-11 05:34:00)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#31 2020-07-16 00:22:30

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Media shortcode. Requests accepted

I spent some time experimenting with the latest version. I ran into a few problems.

Internet Archive Audio – http://demo.cmsstyles.com/datebasedarchives/2020/07/15/internet-archive-dj-spooky-s-quantopia

I had to remove the .mk4 extension.

Giphy – http://demo.cmsstyles.com/datebasedarchives/2020/07/15/welcome-to-the-internet

I had to remove the /video.

Neither the local video or audio would work because this is in a subdirectory. I changed the code to:

<source src="<txp:site_url />files/<txp:yield name="media" />.mp4" type="video/mp4">

and this alleviated the issue.

You can see all of them here: http://demo.cmsstyles.com/datebasedarchives/category/media-shortcodes/

Offline

#32 2020-07-16 05:07:30

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,064
Website GitHub Mastodon Twitter

Re: Media shortcode. Requests accepted

Thanks so much for testing this Michael. The issue you left out for Souncloud is because of the missing url attribute. (Example 3). I have changed the code per your recommendations.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#33 2020-07-16 05:42:20

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,064
Website GitHub Mastodon Twitter

Re: Media shortcode. Requests accepted

It also appears that for the internet archive I could replace ‘embed’ with ‘details’ in the cookie warning url. My tests returned no issues.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#34 2020-07-16 06:55:47

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,064
Website GitHub Mastodon Twitter

Re: Media shortcode. Requests accepted

I also spotted a difference in the urls for video and gif files in giffy.

Michael, in your example, the pre-cookie-acceptance url returns a blank page. I’ll see how this could be corrected simply


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#35 2020-07-16 11:04:28

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Media shortcode. Requests accepted

colak wrote #324563:

I have changed the code per your recommendations.

<source src="<txp:site_url />files/<txp:yield name="media" />.mp4" type="video/mp4">

You took out the “files/” portion of the URL. I had to put that back in.

Offline

#36 2020-07-16 14:49:50

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,064
Website GitHub Mastodon Twitter

Re: Media shortcode. Requests accepted

michaelkpate wrote #324575:

<source src="<txp:site_url />files/<txp:yield name="media" />.mp4" type="video/mp4">...

You took out the “files/” portion of the URL. I had to put that back in.

whoops. :) I did that in between meetings. Thanks for the heads up!


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB