Skip to main content

Blogs

if($device->getCapability('is_wireless_device') == 'true') { print 'This is a mobile device';
} else { print 'This is NOT a mobile device';
}
function wpp_change_search_url_rewrite() {
    if ( is_search() && ! empty( $_GET['s'] ) ) {
        wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
        exit();
    }    
}
add_action( 'template_redirect', 'wpp_change_search_url_rewrite' );

write this line at the top of settings.php file:

header('P3P: CP="CAO PSA OUR"');

This line allows IE to accept 3rd party cookies.

In this code snippet, I'll show how you can parse a (large) CSV file using Drupal's Batch API. The purpose of batching an operation is to avoid PHP memory limits and time outs. Before you begin, I recommend reviewing the following two articles. Be sure to review the additional batch parameters outlined in the documentation, you might need to use them.

function MYMODULE_callback_csv_import() {
// define path to CSV file
$csv_file_path = file_directory_path() . '/import_path/myfile.csv';
// define a redirect path upon batch completion
$redirect_path = 'admin/import-csv';
// define batch array structure
// NOTE: minimal parameters defined to simplify code
$batch = array( 'title' => t('Reading File'),
  'operations' =>array(
  array( '_MYMODULE_batch_read', array($csv_file_path), )
  , )
  , );
// set batch
batch_set($batch);
// process batch
batch_process($redirect_path);
}

Next, we'll define the batch callback function. This function will be called repeatedly until the $context['finished'] variable is set to "1".

function _MYMODULE_batch_read ($csv_file_path, &$context) {
// define batch limit  
$batch_limit = 100;
// assume the batch process has not completed
$context['finished'] = 0;
// open the file for reading
$file_handle = fopen($csv_file_path, 'r');
// check if file pointer position exists in the sandbox, and jump to location in file
if ($context['sandbox']['file_pointer_position']) {
fseek($file_handle, $context['sandbox']['file_pointer_position']);
} // loop through the file and stop at batch limit
for ($i = 0; $i < $batch_limit; $i++) {
// get file line as csv
$csv_line = fgetcsv($file_handle);
// NOTE: at this point, do what ever you'd like with the CSV array data!
if (is_array($csv_line)) {
// db_query(), etc } // retain current file pointer position
$context['sandbox']['file_pointer_position'] = ftell($file_handle);
// check for EOF
if (feof($file_handle)) { // complete the batch process
$context['finished'] = 1;
// end loop
break; } }
}
global $custom_theme;
$custom_theme = 'garland';
init_theme();
print theme('sexybookmarks', $node);

You can try this inside your module. This works for me:

return drupal_json(utf8_encode($output));

and use the following solution for JavaScript to decode UTF8

 

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/geral/utf-8 [v1.0]UTF8 = {
    encode: function(s){
        for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
            s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
        );
        return s.join("");
    },
    decode: function(s){
        for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
            ((a = s[i][c](0)) & 0x80) &&
            (s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
            o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
        );
        return s.join("");
    }
};
var s = "aáéíóúe";
document.write(
    ('UTF8.encode("' + s + '") = ').bold(), UTF8.encode(s), "<br />",
    ('UTF8.decode(UTF8.encode("' + s + '"))) = ').bold(), UTF8.decode(UTF8.encode(s))
);

You can find the original post here http://snippets.dzone.com/posts/show/5294

<script type="text/javascript">
  <!--
jQuery.each(jQuery.browser, function(i, val) {
      alert("<div>" + i + " : <span>" + val + "</span>");
    });
    
  //-->
  </script>
print fivestar_widget_form($node);
$(document).ajaxError(function(e, xhr, settings, exception) {
alert('error in: ' + settings.url + ' \\n'+'error:\\n' + exception);
});