When I use:
Inflector::slug("My Lovely & long slug");
On my local server I get:
My_Lovely_long_slug
When I use it on my server I get:
Lo_l_lo_lu
What gives? This issue is also affecting all my cache names which I assume are using the Inflector class. Any help appreciated.
looks like to different versions of cake? ive seen this reported before but dont have any references for you. Tested on my server for ~ 1.3.6/7 and it works as expected.
if the versions of cake are the same try and do a 'git bisect' which will give you an answer pretty quick
update:
seems to do with your PCRE libraries installed on the server that are older etc. give them an update and all should be fine
So I made my own slug for now.
function permalink ($string = '',$length = false)
{
$string = strtolower($string); // All lowercase
$string = preg_replace('/[^%a-z0-9]/',' ', $string); // Remove garbage
$string = preg_replace('/\s+/','_', $string);
$string = preg_replace('|-+|','_', $string);
if ($length) $string = substr($string,0,$length); // Limit string length?
$parsed = trim($string,'_'); // Trim pre and post trailing delims
return $parsed;
}
Related
http://example.com/api/transfer/transfers/code/456/code/234
When using $this->get('code') on a url like above I expect the REST library to return an array or a list of the codes.
Instead it returns the last one.
Is there a way to return both values in a list, or is there another recommandation for formating the URL.
Thank you
I know it has been long since you posted the question. However it could help other people looking for the same thing.
Assuming that transfer is your controller and transfers is the function, another way to format your url could be:
http://example.com/api/transfer/transfers?code[]=456&code[]=234
This was you perform $this->get('code') you'll get an array back.
If you are creating the url via code then you may use http_build_query(). It handles the necessary escaping. It means it will replace [ for %5B and ] for %5D, in this case.
The code would be like:
$codes = array(456, 234);
$query = http_build_query(array('code' => $data));
$url = 'http://example.com/api/transfer/transfers?' . $query;
I have a node, with nid. i.e. 78 and it's on French language (main language is English) so local name to it is:
fr/node/78
or just
node/78
?
Also that page has some alias, i.e. "hello" so it's relative path would be:
/fr/hello
How can I get that relative path?
Yes, I know that:
$alias = drupal_get_path_alias('node/78');
should give me my page alias, but it's not working, probably because of different language?!? Or that should be:
$alias = drupal_get_path_alias('fr/node/78');
I tried both, but none of them is working?!? I can't believe that there is no simple function available, which would take node id as parameter and return SEO (with alias) page path?!?
Please help. What is the easiest way to get node seo path on multi lingual website if I have nid?
Finally I got it. In case somebody else strugles with this:
// Returns root relative path
function get_node_url_ml ($nid, $language){
$defaultLanguage = language_default();
$local_path = 'node/' . $nid;
$url = drupal_lookup_path('alias', $local_path, $language);
if (!$url) $url = 'node/' . $nid;
if ($language != $defaultLanguage->language) $url = $language.'/'.$url;
return '/'.$url;
}
I'm running a script that extracts links from a webpage but the webpage outputs a different number of correct urls everytime something on the webpage changes, which happens very often for the purpose of this script. My 'constraint' is the $tco it makes sure that the urls onyl start with http://t.co
$tconike = (grep /$tco/, #links);
print "$tconike\n";
This determines the number of urls that satifsy my needs, this prints '2'.
my #found = (grep /$tco/, #links);
if (#found) {
for my $url (#found) {
print "$found[0]\n";
print "$found[1]\n";
}
}
This prints the accual urls in this case there is two. ex
http://t.co/5
http://t.co/r
Can I have the perl script recignize the number of urls starting with t.co and add more varaibles (the $found[0] and $found[1]) based on what $tconike (the number of useable urls) outputs?
I NEED TO ACCESS THE URLS LATER WHEN I USE WWW::Mechanize TO FILL OUT FORMS ON THE URLS.
As choroba said, you don't need to do that. You can just use print "$url\n" instead of each array element individually, because it will call the block of the loop for each element inside #found.
If you still want more variables based on the number of urls, you could do the following. But this is not code that you should use in production. In fact, don't use it. It works, but it's intended as a joke. :)
my $code;
my #found = (grep /$tco/, #links);
if (#found) {
for (my $i=0; $i<= $#found; $i++) {
$code .= q{print "$found[$i]\n"} . qq{\n};
}
eval $code for #found; # this is very evil
}
I have set up a module with custom node type (I called jquizme, after the javascript jQuizMe that I really like using). I set up two fields for the javascript files I need to supply to make it work (after the general jQuizMe-2.2.js file you need to add another two javascript files - one for settings and one for the quiz content).
Drupal saves the files as myjavascriptfile.js.txt - I tested them and they still work to make the jQuizMe interface - ok. the problem is, I want to add these files on the node page... the files will be different for each node. how can I access the files for the drupal_add_js() function so they will load the files for the node in question?
I tried setting up custom field formatters, but I don't know how to access the uri for the files of a given node automatically to put in the drupal_add_js() function (I can add a static file and it loads fine ... I did this with hook_node_view ( jquizme_node_view ).
So I just need a way to access the info for the files... how are they linked to each node? I can't find the connection.
As you probably noticed, I am a module writing newbie, and I probably won't understand much related to object oriented programming sorry, haven;t progressed to that level yet), but I am open to any answer. I am sure I left out important info, but this it already getting too long.
I also set up a special page earlier on to just see if I could get jQuizMe to work in Drupal so that is still in the code.
I have tried many answers (last six hours or so... too much to say here), the latest of which is using tokens, but that is not working. Here is what I have so far:
function jquizme_node_view($node, $view_mode, $langcode) {
switch ($node->type) {
case 'jquizme':
$items = field_get_items('node', $node, 'field_myfield', $node->language);
drupal_add_css(drupal_get_path('module', 'jquizme') . '/jQuizMe.css', >array('scope' => 'header'));
drupal_add_js(drupal_get_path('module', 'jquizme') . '/alert.js');
drupal_add_js(drupal_get_path('module', 'jquizme') . '/jQuizMe-2.2.js', >array('scope' => 'header'));
//drupal_add_js($tokens['node']['jquizme_js1_field'], array('scope' => >'header'));
//drupal_add_js($tokens['node']['jquizme_js2'], array('scope' => 'header'));
break;
}
}
Thanks in advance!
Can you try this?
// Let me assume that the field names of your two file fields
// are jquizme_js1_field and jquizme_js2_field for convenience..
function jquizme_node_view($node, $view_mode, $language) {
$items = field_get_items('node', $node, 'jquizme_js1_field');
_jquizme_add_js_from_filefield($items);
$items = field_get_items('node', $node, 'jquizme_js2_field');
_jquizme_add_js_from_filefield($items);
}
// Given the values of a filefield attached to some entity,
// adds them as JS files to the page.
function _jquizme_add_js_from_filefield($items = array()) {
foreach ($items as $item) {
$fid = &$item['fid'];
$file = file_load($fid);
if (!$file) {
continue; // Maybe the file got deleted..
}
$wrapper = file_stream_wrapper_get_instance_by_uri($file->uri);
$path = $wrapper->realpath();
// Ensure that the path exists and that it is a Javascript file..
if (file_exists($path) && preg_match('\.js$', $path)) {
drupal_add_js($path, array('type' => 'file'));
}
}
}
Is it possible to craft a wildcard WHERE query with Doctrine, like so:
->where('this_field = ?', ANYTHING);
I'd be using this to build a search query dynamically out of unknown user-selected parameters and therefore would need to have the condition in place but capable of accepting the value "anything".
To add, I can get this to work:
$field = 'this_field = ?';
$value = 5;
...
->where($field, $value);
... but it's still doesn't allow me to use "anything" as value or to eliminate the entire query condition. The following fails:
$field = NULL;
$value = NULL;
...
->where($field, $value);
Thanks
If you build the query dynamically you can also check wther $value has a value or not and then add the where part if necessary. E.g.
$q; // Your query object.
if(isset($value)) { // or empty() or maybe just if($value) depending on your needs.
$q->where('this_field = ?', $value);
}
This is easier to understand and easier to debug imo.
[Answer to own question]
After playing around with this, found a solution that works, posting here for others.
Using ->whereIn allows Doctrine to ignore a query condition completely:
$empty = array();
...
->andWhereIn('this_field', $empty)
The above condition doesn't get included in the resulting SQL at all.