This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get URI parameter. | |
* | |
* @param string $str | |
* Example to use $str urldecode(drupal_get_destination()). | |
* @return array | |
*/ | |
function _more_node_buttons_get_params($str) { | |
$chunks = explode("?", $str); | |
$params = explode("&", $chunks[1]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_url_outbound_alter() - from URL Alter module | |
*/ | |
function YOURMODULE_url_outbound_alter(&$path, &$options, $original_path) { | |
// Rewrite paths for rices4peru.com | |
if ($_SERVER['HTTP_HOST'] == "www.rices4peru.com") { | |
$options['absolute'] = TRUE; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query = db_select('users', 'u'); | |
$query | |
->condition('u.uid', 0, '<>') | |
->fields('u', array('uid', 'name', 'status', 'created', 'access')) | |
->range(0, 50); | |
$result = $query->execute(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$values = array( | |
array( | |
'title' => 'Example', | |
'uid' => 1, | |
'created' => REQUEST_TIME, | |
), | |
array( | |
'title' => 'Example 2', | |
'uid' => 1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$sql = "SELECT n.nid, n.vid, n.title, n.uid, u.name, n.created | |
FROM {node} n | |
INNER JOIN {users} u | |
ON u.uid = n.uid | |
WHERE n.type = 'quiz'"; | |
if ($uid != 0) { | |
$sql .= " AND n.uid = %d"; | |
$args[] = $uid; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
db_merge('example') | |
->key(array('name' => $name)) | |
->fields(array( | |
'field1' => $value1, | |
'field2' => $value2, | |
)) | |
->expression('field1', 'field1 + :inc', array(':inc' => 1)) | |
->execute(); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Old code. | |
$result = db_query("SELECT nid FROM {node} n WHERE n.type = '%s' AND n.status = %d", array('page', 1)); | |
// DBTNG. Note that multiple | |
$result = db_query("SELECT nid FROM {node} n WHERE n.type = :type AND n.status = :status", array( | |
':type' => 'page', | |
':status' => 1, | |
)); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Old code, loop over a result. | |
while ($row = db_fetch_object($result)) { | |
} | |
// DBTNG. | |
foreach ($result as $row) { | |
} | |
// Old code, fetch a single field directly from a query. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Old code. | |
db_query("UPDATE {profile_field} SET weight = %d, category = '%s' WHERE fid = %d", $weight, $category, $fid); | |
// DBTNG. | |
db_update('profile_field') | |
->fields(array( | |
'weight' => $weight, | |
'category' => $category, | |
)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// $Id$ | |
function reflection_menu() { | |
$items = array(); | |
$items['reflection-page'] = array( | |
'page callback' => 'reflection_page', | |
'title' => 'Reflection test', | |
'access arguments' => array('access content'), |
OlderNewer