Changing the description of a MP3 file? - php

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";
}

Related

Rackspace - php-opencloud filters - Documentation for valid ObjectList filters?

Anyone know if/where there is documentation for valid ObjectList filter arrays?
The project's entry on github has a tiny blurb on it directing me to the API documentation, but that also fails to have a comprehensive list, and a search on 'filters' talks about containers only, not the object themselves.
I have a list of videos, each in four different formats named the same thing (sans filetype). Using the php-opencloud API, I want to GET only one of those video formats (to grab the unique filename rather than all its different formats).
I figured using a filter is the way to go, but I can't find any solid documentation.
Someone has got to have done this before. Help a noob out?
Most of the links on this page are dead now. Here's a current link to the php-opencloud documentation, which includes an example of using a prefix to filter the objectList results:
http://docs.php-opencloud.com/en/latest/services/object-store/objects.html#list-objects-in-a-container
I didn't find documentation of this, but apparently when the Rackspace Cloud Files documentation mentions arguments in a query string, those translate to arguments in an objectList method call like this:
GET /v1/MossoCloudFS_0672d7fa-9f85-4a81-a3ab-adb66a880123/AppleType?limit=2&marker=grannysmith
equals
$container->objectList(array('limit'=>'2', 'marker'=>'grannysmith'));
As Glen's pointed out, there isn't support (at the moment) for the service to apply filters on objects. The only thing which you might be interested in is supplying a prefix, which allows you to refine the objects returned based on how the filenames start. So if you sent 'bobcatscuddling' as the prefix, you'd get back all associated video formats for that one recording.
Your only option, it seems, is to get back all objects and iterate over the collection:
use OpenCloud\Rackspace;
$connection = new Rackspace(RACKSPACE_US, array(
'username' => 'foo',
'apiKey' => 'bar'
));
$service = $connection->objectStore('cloudFiles', 'DFW', 'publicURL');
$container = $service->container('CONTAINER_NAME');
$processedObjects = array();
$marker = '';
while ($marker !== null) {
$objects = $container->objectList('marker' => $marker);
$total = $objects->count();
$count = 0;
while ($object = $objects->next()) {
// Extract the filename
$filename = pathinfo($object->name, PATHINFO_FILENAME);
// Make sure you only deal with the filename once (i.e. to ignore different extensions)
if (!in_array($processedObjects, $filename)) {
// You can do your DB check here...
// Stock the array
$processedObjects[] = $filename;
}
$count++;
$marker = ($count == $total) ? $object->name : null;
}
}
What you'll notice is that you're incrementing the marker and making a new request for each 10,000 objects. I haven't tested this, but it'll probably lead you in the right direction.
Unfortunately, the underlying API doesn't support filtering for objects in Swift/Cloud Files containers (cf. http://docs.rackspace.com/files/api/v1/cf-devguide/content/List_Objects-d1e1284.html). The $filter parameter is supported as part of the shared code, but it doesn't actually do anything with Cloud Files here.
I'll see if I can get the docs updated to reflect that.

Internationalization in CakePHP JavaScript files

I'm wrapping up a project using Cakes internationalization features to allow our application to be translated into different languages. That's worked great.
A problem I've noticed though is there are a few places where text is added via JavaScript and this text does not currently come from the server at all. It's for things like dialogue boxes and a few pieces of text that change based on a users selection.
How have you handled this in your own applications? How would you handle this? Is there a library or component that handles this. What about any jQuery libraries?
You can also do it using JavaScript translation files with this format:
lang = {
no: "No",
yes: "Ja",
agreed: "Akkoord"
}
One file per language, for example: lang.nl.js, lang.es.js, lang.en.js...
Then, you can check the current language and, depending on it, load one or another file:
if($this->Session->read('Config.language') == 'es'){
$this->Html->script('lang.es', array('inline' => false));
}else{
$this->Html->script('lang.en', array('inline' => false));
}
And inside your javascripts, instead of using something like this:
alert("Yes");
You should use this:
alert(lang.yes);
And that's it :)
CakePHP does not have a built-in / standard way of localizing JavaScript. It does offer various ways to localize strings 'in general'. See Internationalization & Localization
To localize strings that are output by JavaScript, consider;
For 'static' strings (i.e. strings that are not depending on the content of your website), create localization files for your scripts.
Many plugins use this approach
For example, see this page on localizing the JQuery-UI date picker UI/Datepicker/Localization
If you're already localizing strings in your website via .po files, and want to use the same translations in your JavaScript, you may consider to dynamically create the translation-files as mentioned in 1.), for example;
In your app/Config/routes.php, enable parsextensions, see File Extensions
Router::parseExtensions('json');
Create a controller that will output strings localized as JavaScript/JSON
http://example.com/localized/strings/eng.json
class LocalizedController extends AppController {
public function strings($lang)
{
if('json' !== $this->request->ext) {
throw new NotFoundException();
}
// Switch to the requested language
Configure::write('Config.language', $lang);
$strings = array(
'hello',
'world',
);
//translated the strings
$translations = array();
foreach ($strings as $string) {
$translations[$string] = __($string);
}
// build and send a JSON response
$this->autoRender = false;
$this->response->type('json');
$this->response->body(json_encode($translations));
return $this->response;
}
}
This json file should now be accessible via http://example.com/localized/strings/eng.json and can be loaded from within your javascripts at runtime
note
Just to clarify; the example is untested and just to illustrate the idea of dynamically creating JSON (or JavaScript) files containing localized strings. The code is far from efficient and (at least part of) the code should not be inside the controller, but (for example) inside a model.
For translating JavaScript inside my CakePHP applications, I use this library : https://github.com/wikimedia/jquery.i18n , it's the one used in Wikipedia.
You have all the necessary files inside the src folder. It's quite easy to set up and use. Of course it works with any kind of application, not only CakePHP !
Here's a solution i'm using for cakePHP 3 :
in your layout file ( mine is default.ctp ) :
if( isset( $translated_js ) && !empty( $translated_js ) ){
$this->Html->scriptStart($block_render);
echo "var translated_js = " . json_encode( $translated_js ) . ";";
$this->Html->scriptEnd();
}
Now in any controller add a beforeRender method :
public function beforeRender(Event $event){
parent::beforeRender( $event );
$translated_js = [
'reinit_map' => __('Reinit map to default'),
];
$this->set( 'translated_js' , $translated_js );
}
This way you can use the gettext instructions.
In your JS files you can now use the translated eelements this way :
translated_js.reinit_map
Hope it helps someone searching a way to translate texts and pass to JS
I had the same problem like you and i found this link very helpful: http://jamnite.blogspot.de/2009/05/cakephp-form-validation-with-ajax-using.html
It's not up to date, but the main principle should be clear.
Checkout this CakePHP plugin: https://github.com/wvdongen/CakePHP-I18nJs
It uses the functionality of Drupal 8 JavaScript translations. It has CakePHP console functions to generate .po file(s) (exactly as you're used with Cake), and to generate your translated .po files to JavaScript.
I use a more straightforward method. ( I do not know if it is the best, but it works ).
Inside the template file I define a series of hidden fields with the messages that js might need.
echo( $this->Form->hidden( 'msg-select-promotion-items', [ 'value' => __( 'Select promotion items' ) ] ) );
Here we take advantage of cake's own localization system.
And then in the js file :
alert( $('input[name=msg-select-promotion-items]').val() );
Hope this helps.
Regards.
Facundo.
I took the easier path:
alert( "<?php echo __('This is my translated string'); ?>" )
This way you can keep all translations in a single place: the .po file

How to mail to a static list segment with mailchimp API

Once I've identified identified the email addresses of my list segment (using get_emails() custom function, I am setting up my list segment as follows:
$batch = get_emails();
//now create my list segment:
$api->listStaticSegmentAdd(WEDDING_LIST_ID, 'new_wedding_guests');
$api->listStaticSegmentMembersAdd(WEDDING_LIST_ID, 'new_wedding_guests', $batch);
//do I build vars for a campaign?
$options = array (
'list_id' => WEDDING_LIST_ID, //What value id's my list segment?
'subject' => 'Alpha testing.',
'from_email' => 'wedding#juicywatermelon.com',
'from_name' => 'Pam & Kellzo',
'to_name' => $account->name,
);
From here can I use a basic campaign and send it?
$content['text'] = "Some text.";
$content['html'] = get_link($account);
$cid = $api->campaignCreate('regular', $options, $content);
$result = $api->campaignSendNow($cid);
I'm not sure if I'm understanding the api documentation correctly. I also tried 'list_id' => 'new_wedding_guests'; which failed to create a campaign.
Thanks!
I'll assume this is test code and just make the cursory mention of how you probably don't need to be creating a new Static Segment every time. However, your call to add members is not going to work. Per the listStaticSegmentMembersAdd documentation, you should be passing the static segment id, not the name of it. Also note that the docs cross-reference themselves when input params can come from other calls - that parameter there is a good example (it also happens to be returned by listStaticSegmentAdd).
Your options for campaignCreate look like a good start. The documentation for it has examples below - those examples are included in the PHP MCAPI wrapper you likely downloaded. As per above, the list_id you need is the one for the list you used in the listStaticSegment calls (also linked in the documentation).
Now the real key - further down in the campaignCreate docs is the segment_opts parameter - that is how you control segmentation. Follow the link it gives you and you'll find tons of info on the ways you can do segmentation, including using a static_segment.
Hopefully all of that made sense, if not, take a step back and check out these links (and play with segmentation in the app), then it should:
Introduction to MailChimp List Management
How can I send to a segment of my list?
Our Release Info on how Static Segments are used

How do I set up an RSS feed for my hard-coded php & mysql site?

I have absolutely no idea how to start one. Every tutorial I find assumes I have a cms or blog of some sort. Mine's not exactly. I upload everything and coded all my css, html, mysql, php, and such. So how do I create an RSS feed?
I'm guessing I need to use a php include right?
Also I want my RSS feed to be automated if possible. Like all it'll need to know is the title of my page, and then the RSS will send it out to all my subscribers with the link of the page as the only description.
Please post any info you have though, as beggars can't be choosers.
Thanks!
Generate a list of filenames, order them by timestamp, read them, extract title and content snippets, and finally print out an RSS document. Example:
// list + sort
$files = glob("pages/*.html");
$files = array_combine($files, array_map("filemtime", $files));
arsort($files);
// loop + read
foreach ($files as $fn=>$mtime) {
$html = file_get_contents($fn);
preg_match('#<title>([^<]+)', $html, $title) and $title=$title[1];
$rss[] = array(
"link" => $fn,
"pubDate" => $mtime,
"title" => $title,
"description" => substr(strip_tags($html), 0, 100),
);
}
// write RSS
foreach ($rss ...)
Manually create a file containing the RSS XML referencing the pages from your site that you want in your feed. As you add new pages to your site, update that RSS file. The file should be stored along with other files comprising your site.
See the example on Wikipedia for the format: http://en.wikipedia.org/wiki/RSS#Example
Read up on RSS (http://www.w3schools.com/rss/default.asp). you don't have to send anything out; just update the RSS feed, and if they are subscribed the change will propagate through to the end-user. This can either be a semi-automated process that pulls in information as you update your page (why tutorials presuppose a blog or cms), or you can update the feed manually.

Best way to manage text displayed to users in PHP

Ok for sure this has been asked and answered already but i somehow can't find a proper tutorial.
I want to keep the text displayed to users somewhere else and to prevent my code from becoming too large and unreadable.
My site won't be internationalized. I just want to have some kind of file with key-value structure and get the text from there. I want to keep the text in files, not in the database as some tutorials suggest.
I found a solution which will work but i am not sure whether this is a good approach.
I am thinking of using parse_ini_file and to keep my texts in .ini file. Is there something wrong with this approach? Could you suggest something better?
I put all language data in arrays. Its easy and also we can add multi-language support
lang/en.php
<?php
return array(
'index' => 'Homepage',
'feedback' => 'Feedback'
'logout' => 'Logout from profile',
)
?>
lang/ru.php
<?php
return array(
'logout' => 'Выйти из профиля',
)
?>
Then we can load languages:
$lang = include('lang/en.php');
if(isset($_GET['lang']))
{
$lang = array_merge($lang, include('lang/ru.php'));
}
After all it $lang will look like:
Array
(
[index] => Homepage
[feedback] => Feedback
[logout] => Выйти из профиля
)
And we can very simple use it:
function __($name) {
global $lang;
return $lang[$name];
}
Somewhere in the site template:
...
<title><?=__('index')?></title>
</head>
<body>
<?=__('feedback')?>
why not use a plain text file with commas or some uncommon character to hold this data? you can read it and parse it into an array with
$file = file_get_contents("/path/to/file");
$lines = explode('\r', $file);
foreach($lines as $line) $message[substr($line, 0, strpos($line, ','))] = substr($line, strpos($line, ','));
then you should have an array like $messages[3] = "No soup for you!";
the file might look like:
1,The site is down.
2,Try again.
3,No soup for you!
4,Signs point to yes.
(I probably have some of the arguments misplaced in those functions - i always forget which is the needle and which the haystack.)
You can process your data in a script. In this script, you call a certain source (e.g. the ini file you suggest). Then you use a template engine. For this engine, you point towards a template file and give the template all the variables.
The template generates the html and inserts the variables at the right place. This way, you keep you php (business logic) code clean, away from the presentation (the template). Also you can manage the variables in one file (ini/xml but this can be something completely different).
For template engines, Smarty is the most known of all. There are also pure php-based template systems, just Google for them to find one that suits your needs.
I do like this:
$defaultLang = array('Home','Logout',etc)
$otherLang=array( 'ru' => array('Home_in_ru','logout_in_ru',etc);
you translate like this:
echo translate('Home');
function is:
function translate($msg) {
if ($_GET['lang']=='en')
return $msg;
return $otherLang[$_GET['lang']][array_search($msg,$defaultLang)];
}
// Note the function is simplified up there
As you can see the default case deosnt' need to load anything or do any operation, the function just returns back the argument passed
i like the answer with the lang/en.php file. but instead of a file for each language, i use a file for each web page (or class, etc). this keeps file sizes lower and i create a 3D array:
`return array( "EN" => array( "title" => "Welcome - Good Morning", ...),
"TG" => array( "title" => "Mabuhay - Magandang Umaga Po", ...)
);'
Real easy to add new language strings too...
This makes it real easy for language translation contractors since they can see the native language in close proximity to the foreign in 1 editor,,,

Categories