I am getting the LargeImage URL using Amazon's advertising API. I want to modify the URL to replace
.jpg
with
._SS300_.jpg
to show the correct size I need for my template. I am using Wordpress and a plugin called AmazonSimpleAdmin.
I believe this is the part of the plugin code I need to do something to:
$replace = array(
// ...
($item->LargeImage != null) ? $item->LargeImage->Url->getUri() :
get_bloginfo('wpurl') . $this->plugin_dir . '/img/no_image.gif',
I don't know much PHP, but as far as I can tell the large image URL is part of the array, and I know the part I need to change is
$item->LargeImage->Url->getUri()
but that's as much as I've been able to figure out. Any help is appreciated.
$string = '.jpg';
$string = str_replace('.jpg', '._SS300_.jpg', $string);
// Do something with $string.
Related
I am currently using simple_html_dom to parse some MP3 files from another website, and store them onto my own server. However I've noticed that some of them contain a tag which indicates the location they originated from within the comment portion of the ID3 properties.
I need to make this website, say my own websites name. However, the only solution that I've found to doing this with PHP is beyond complicated using something called GETID3.php You can view the github link by clicking the name.
I don't really understand the documentation can someone help me find an easier way of doing this please?
Here's the part of my code that matters, I guess.
$mp3title = ''.$thetitle.' - Oursite.com';
file_put_contents($DPATH.'/temp/'.$mp3title.'.mp3',file_get_contents($filepath));
$file = $DPATH.'/temp/'.$mp3title.'.mp3';
Provided you're not interested in also updating the image of the file, you can look into just using something simple like the default php function id3_set_tag however for more complex usages like updating the artwork then you're going to have to use the library you mentioned before.
$data = array(
"title" => "Re:Start",
"artist" => "Re:\Legion",
"comment" => "YourWebsiteName.com"
);
$result = id3_set_tag($DPATH.'/temp/'.$mp3title.'.mp3', $data, ID3_V1_0 );
if ($result === true) {
echo "Tag successfully updated\n";
}
In my website I need to customise the url ,
I done it some way ,everything is working fine .I got what I need ,but I want to do it in a proper way .
Below is my code
$route['admin/lessons'] = 'admin/admin/lessons';
$route['admin/lesson_mgmt'] = 'admin/admin/lesson_mgmt';
$route['admin/labs'] = 'admin/admin/labs';
$route['admin/tools'] = 'admin/admin/tools';
Here in this way I am managing the custom url section .
I want to make this url dynamic so that ,the code will not be longer ,there are other section .
If i will do it in this way ,I have to write a lot .
Here i want to replace everything in a single line.
Can anyone suggest me anything ?
Thank you in advance.
Try like this...
In your application/config/routes.php
$route['admin/([a-zA-Z0-9_-]+)'] = 'admin/admin/$1';
Hope it will work fine..
In above code.. [a-zA-Z0-9_-]+) this is regular expression having combination of one or more alphanumeric characters(alphabets+numbers).If route gets admin/characters...it redirect to admin/admin/characters.
I'd like to know which is the cleanest way to insert an url in an email sent by Moodle module.
So far I'm using this formula, what IMHO I don't think is the cleanest way:
$url = $CFG->wwwroot.'/mod/<mymodulename>/view.php?id='.$cm->id;
The things I don't like here are:
Using $CFG->wwwroot
/mod/<mymodulename> needs to be provided always. (Assume here that I'm using a constant instead of a hardcoded string).
I expected Moodle to have a function to provide this out of the box just when providing module script. I've tried moodle_url but this function doesn't provide the path to the php script when used this way:
new moodle_url('view.php?id='.$cm->id);
I just get:
view.php?id=XX
Thanks in advance.
I would do it like this
$url = new moodle_url('/mod/<mymodulename>/view.php', array('id' => $cm->id));
echo html_writer::link($url, get_string('linktitle', 'mod_mymodulename'));
You can use following statement:
This is Absolute path of file
$url = new moodle_url($CFG->wwwroot.'/mod//view.php', array('id' => $cm->id));
my question a little complicated.
I want to share a featured image which is in a post on my wordpress site to twitter.
But there a important point. i want to share a picture with twitpic because of people can see this image in twitter without open my web site.
i get api from twitpic, and i use this code (link)
but twitpic or this code cannot accept a url to upload twitpic and get a link.
$resp = $twitpic->upload(array('media'=>'$a2', 'message'=>'get_the_title()'));
if i wrote $a2 = "ex.jpg" its working,
if i wrote $a2 = "http://www.ex.com/ex.jpg" not working
then i try that;
<?php
$a1 = $_SERVER['DOCUMENT_ROOT'];
// ex image remove 18 chr from begining http://*******.com/wp-content/uploads/2013/04/2012-10-17-23.48.34.jpg
$kisalt1 = $imageshare[0]; // wordpress featured image fxn ex: http://*******.com/wp-content/uploads/2013/04/2012-10-17-23.48.34.jpg
$kisalmis = substr($kisalt1,18,9999);
$a2 = $a1.$kisalmis;
// echo $a2; => /home/*******/public_html/wp-content/uploads/2013/04/bu-terste-bir-islik-var-panpa.jpg
?>
but it stil give same error.
Unable to find or read file
how can i get ride of this?
summary => i want to this => wordpres featured image to twitpic for share twitter like image which can open without click a link.
Edit: I just tried deleting this because I saw that you said that http://www.ex.com/ex.jpg doesn't work for you. But then I thought this might still be helpful (to someone), and for some reason the comments option didn't show up for me, so here it is again. Sorry if it doesn't help though.
What you need is just the post_thumbnail url, not the full image tag.
http://wordpress.org/support/topic/getting-post-thumbnail-url
The relevant post is the one with this code block:
$a2 = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
Does it work if you add that?
-Andrew
Another edit...I just came across this post on the Wordpress StackExchange site: https://wordpress.stackexchange.com/questions/83137/post-thumbnail-relative-link-and-html-modify
Does it work if you provide TwitPic with a relative link location?
I have a custom component I'm working on and I'm writing an import script which is running in the administration area. I have the following code:
$newUrl = ContentHelperRoute::getArticleRoute($import->article_id.':'.$import->alias, $import->catid);
$newUrl = JRoute::_($newUrl);
the first part works returning similiar to this:
index.php?option=com_content&view=article&id=45:joomla-sociable-and-sharethis-module&catid=18
the second part shows it like this:
/administrator/index.php?option=com_content&view=article&id=45:joomla-sociable-and-sharethis-module&catid=18
Both of the above urls are as you'd expect the component com_content to render these urls as if I wanted to use them within the administration area.
Any idea how to force JRoute to work as it would when used in the frontend?
NB: This is being used within a controller of my component, if it makes any difference and I'm including require_once (JPATH_SITE . '/components/com_content/helpers/route.php');
For those who find this on Google and struggle with using JRoute::_() and contentHelper::getArticleRoute().
$newUrl = ContentHelperRoute::getArticleRoute($import->article_id.':'.$import->alias, $import->catid);
// better will be check if SEF option is enable!
$router = new JRouterSite(array('mode'=>JROUTER_MODE_SEF));
$newUrl = $router->build($newUrl)->toString(array('path', 'query', 'fragment'));
// SEF URL !
$newUrl = str_replace('/administrator/', '', $newUrl);
//and now the tidying, as Joomlas JRoute makes a cockup of the urls.
$newUrl = str_replace('component/content/article/', '', $newUrl);
Here's a snippet that will work for Joomla 3.6
$routerOptions = [];
if (JFactory::getConfig()->get('sef')) {
$routerOptions['mode'] = JROUTER_MODE_SEF;
}
$siteRouter = JRouter::getInstance('site', $routerOptions);
$link = $siteRouter->build($yourRoute)->toString();
$link = preg_replace('#^/administrator#', '', $link);
A nicer solution would be to create a new router instance, so, the code will be something like this:
$app = JApplication::getInstance('site');
$router = &$app->getRouter();
$newUrl = ContentHelperRoute::getArticleRoute($import->article_id.':'.$import->alias, $import->catid);
$newUrl = $router->build($newUrl);
$parsed_url = $newUrl->toString();
$parsed_url = str_replace('/administrator', '', $parsed_url);
This way you will always obtain the right URL for the item, no matter if it is a joomla article, K2 article, etc...
** Notice that depending on the type of the item ( k2, joomla, etc) , $newUrl should be obtained with the consequent method.
I think that this one would be an easier solution:
$newUrl = JRoute::_(ContentHelperRoute::getArticleRoute($import->id.':'.$import->alias, $import->catid));
This will give you the same result as the other two previous answers but with less coding.
Hope this helps.
In Joomla 3.9 they extended the JRoute class (now called Route class) to include a link() static method which solves this problem.
use Joomla\CMS\Router\Route;
$newUrl = ContentHelperRoute::getArticleRoute($import->article_id.':'.$import->alias, $import->catid);
$newUrl = Route::link("site", $newUrl);
Route::link() works just the same as Route::_() except that you can must provide the additional first parameter to specify the client you want the URL built for. See https://api.joomla.org/cms-3/classes/Joomla.CMS.Router.Route.html#method_link.