function content_content_load
Search API
7.x content.module | content_content_load(&$content) |
6.x content.module | content_content_load(&$content) |
4.x content.module | content_content_load(&$content) |
5.x content.module | content_content_load(&$content) |
Implementation of content's hook_content_load
We simply wish to load from our db table. The cid is in $content->cid.
Parameters
unknown_type $content:
File
- modules/
content/ content.module, line 2110
Code
function content_content_load(&$content) {
$res = db_query("SELECT * FROM content WHERE cid = ?
ORDER BY vid DESC
LIMIT 1", array($content->cid));
$content = db_fetch_object($res);
if (!$content) {
return FALSE;
}
// Populate our field values in the content object
$res = db_query("SELECT * FROM content__$content->type WHERE vid = ?", array($content->vid));
$fieldvals = db_fetch_array($res);
$types = content_get_types();
// This condition can occur if we have content from a module which is no longer enables.
if (!isset($types [$content->type])) {
return;
}
foreach ($types [$content->type]['fields'] as $fieldname => $details) {
if ($details ['type'] != 'cfieldset') {
$val = (string) @$fieldvals ['field__' . $fieldname];
if (is_serialized_string($val)) {
$val = unserialize($val);
}
$content->{'field__' . $fieldname} = array('value' => $val, 'field' => $details);
$display_value = $val;
// Figure out or clean up the "display_value" for this field.
if (isset($details ['filter']) && $details ['filter'] != 'plain') {
$display_value = filter_markup(trim($display_value), $details ['filter']);
}
else {
// Always assumed to be "plain" if no filter is set.
if (is_string($display_value)) {
$display_value = filter_markup($display_value, "plain");
// Need to add in line breaks if this was plain.
$display_value = nl2br(trim($display_value));
}
}
// If this is a datetime-local field, then the value needs to be adjusted for it to work correctly.
if ($details ['type'] == 'datetime-local') {
if (trim($display_value) != '') {
//$value = date('Y-m-d\TH:i', strtotime($value));
$format = 'standard';
if (isset($details ['format_date'])) {
$format = $details ['format_date'];
}
$display_value = format_date(convert_time(strtotime($display_value)), $format);
}
}
// if this is a "time" field, then similar to datetime-local, it needs to be adjusted. That's because
// in the database we saved it as UTC. We ned to now convert into the user's timezone.
if ($details ['type'] == 'time') {
if (trim($display_value) != '') {
$format = 'standard';
if (isset($details ['format_date'])) {
$format = $details ['format_date'];
}
$display_value = format_date(convert_time(strtotime("2001-01-01 $display_value")), 'custom', 'g:ia');
}
}
// if this is a select list, we want to display the option label this value went with.
if ($details ['type'] == 'select' || $details ['type'] == 'radios') {
$temp = @$details ['options'][$val];
if ($temp != "") {
$display_value = $temp;
}
}
// If this is a single checkbox, then the possible values are 1 or blank. Let's make the display_value a little more interesting
if ($details ['type'] == 'checkbox') {
$val = intval($val);
if ($val === 1) {
$display_value = t("Yes / Checked");
}
else {
$display_value = t("No / Unchecked");
}
}
// If this was a set of checkboxes ($val is an array), we want to display the label the values went to.
if ($details ['type'] == 'checkboxes') {
$display_value = "<div class='checkbox-values checkbox-values-field__$fieldname'>";
// Convert val into an array. It will look like: ~~key~~key~~key~~ etc.
// Only do this if it is not ALREADY an array.
if (is_string($val)) {
@$temp = explode("~~", $val);
if (!is_array($temp)) {
$temp = array();
}
$val = array();
foreach ($temp as $k) {
if (trim($k) == "") {
continue;
}
$val [$k] = $k;
}
}
if (is_array($val)) {
foreach ($val as $k => $v) {
$temp = @$details ['options'][$v];
if ($temp != "") {
$display_value .= "<div class='checkbox-val'>$temp</div>";
}
}
}
$display_value .= "</div>";
$content->{'field__' . $fieldname}['value'] = $val;
}
if ($details ['type'] == 'file') {
if ($val != "") {
$display_value = "";
$fids = explode(",", $val);
foreach ($fids as $fid) {
if ($fid == '') {
continue;
}
$fid = intval($fid);
$file = content_get_uploaded_file($fid);
if ($file) {
$url = $file ['url'];
$display_value .= "<div class='field-file-attachment-wrapper'><a href='$url'>" . $file ['original_filename'] . "</a></div>";
}
}
}
}
$content->{'field__' . $fieldname}['display_value'] = $display_value;
} // type != cfieldset
else {
// This is a fieldset, so we need to go into all its elements.
foreach ($details ['elements'] as $c => $v) {
foreach ($details ['elements'][$c] as $fieldname => $edetails) {
$val = @$fieldvals ['field__' . $fieldname];
if (is_serialized_string($val)) {
$val = unserialize($val);
}
$content->{'field__' . $fieldname} = array('value' => $val, 'field' => $details);
$display_value = $val;
if (isset($edetails ['filter']) && $edetails ['filter'] != 'plain') {
$display_value = filter_markup(trim($display_value), $edetails ['filter']);
}
else {
// Always assumed to be "plain" if no filter is set.
$display_value = filter_markup($display_value, "plain");
// Need to add in line breaks if this was plain.
$display_value = nl2br(trim($display_value));
}
// If this is a datetime-local field, then the value needs to be adjusted for it to work correctly.
if ($edetails ['type'] == 'datetime-local') {
if (trim($display_value) != '') {
//$value = date('Y-m-d\TH:i', strtotime($value));
$format = 'standard';
if (isset($details ['format_date'])) {
$format = $details ['format_date'];
}
$display_value = format_date(convert_time(strtotime($display_value)), $format);
}
}
// if this is a "time" field, then similar to datetime-local, it needs to be adjusted. That's because
// in the database we saved it as UTC. We ned to now convert into the user's timezone.
if ($edetails ['type'] == 'time') {
if (trim($display_value) != '') {
$format = 'standard';
if (isset($details ['format_date'])) {
$format = $details ['format_date'];
}
$display_value = format_date(convert_time(strtotime("2001-01-01 $display_value")), 'custom', 'g:ia');
}
}
// if this is a select list, we want to display the option label this value went with.
if ($edetails ['type'] == 'select') {
$temp = @$edetails ['options'][$val];
if ($temp != "") {
$display_value = $temp;
}
}
if ($edetails ['type'] == 'file') {
$fid = intval($val);
$file = content_get_uploaded_file($fid);
if ($file) {
$url = $file ['url'];
$display_value = "<a href='$url'>" . $file ['original_filename'] . "</a>";
}
}
// If this was a set of checkboxes ($val is an array), we want to display the label the values went to.
if ($edetails ['type'] == 'checkboxes') {
$display_value = "<div class='checkbox-values checkbox-values-field__$fieldname'>";
// Convert val into an array. It will look like: ~~key~~key~~key~~ etc.
$temp = explode("~~", $val);
$val = array();
foreach ($temp as $k) {
if (trim($k) == "") {
continue;
}
$val [$k] = $k;
}
if (is_array($val)) {
foreach ($val as $k => $v) {
$temp = @$details ['options'][$v];
if ($temp != "") {
$display_value .= "<div class='checkbox-val'>$temp</div>";
}
}
}
$display_value .= "</div>";
$content->{'field__' . $fieldname}['value'] = $val;
}
$content->{'field__' . $fieldname}['display_value'] = $display_value;
}
}
} // else type == cfielset
} // foreach
}