summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuriy Babenko2013-01-18 23:03:52 (GMT)
committer Yuriy Babenko2013-01-18 23:03:52 (GMT)
commit1ad06fc1ec2078a8e7fe1fa2114c53f74d12f38e (patch)
tree63bef6a150d4ab8d14562a78c3084b2cfdeb5c6b
parent63f223d902016b10f64bc8b681c9808237040417 (diff)
misc updates
-rw-r--r--components/debug/debug.inc24
-rw-r--r--components/field/field.inc67
-rw-r--r--components/string/string.inc28
-rw-r--r--components/views/views.inc5
4 files changed, 118 insertions, 6 deletions
diff --git a/components/debug/debug.inc b/components/debug/debug.inc
index c83e555..1c7748c 100644
--- a/components/debug/debug.inc
+++ b/components/debug/debug.inc
@@ -47,3 +47,27 @@ function dsmm($data) {
drupal_set_message(print_rr($data, 1));
}
}
+
+/**
+ * Wrapper for debug_backtrace();
+ * @param boolean $remove_args [description]
+ * @return [type] [description]
+ */
+function bt($remove_args = FALSE) {
+ list($handler, $handler_data) = devtools_func_handler(__FUNCTION__, func_get_args());
+
+ if ($handler) {
+ return $handler_data;
+ }
+ else {
+ $bt = debug_backtrace();
+
+ if ($remove_args) {
+ foreach ($bt as &$item) {
+ unset($item['args']);
+ }
+ }
+
+ return $bt;
+ }
+}
diff --git a/components/field/field.inc b/components/field/field.inc
index b8c7970..efdcc70 100644
--- a/components/field/field.inc
+++ b/components/field/field.inc
@@ -52,4 +52,71 @@ function field_del_instance($field_name, $entity_type, $bundle) {
$instance = field_info_instance($entity_type, $field_name, $bundle);
field_delete_instance($instance);
}
+}
+
+/**
+ * Checks that the specified field has a set value, and (optionally) that
+ * the value is greater than a minimum.
+ *
+ * @param [type] $entity [description]
+ * @param [type] $field [description]
+ * @param string $source [description]
+ * @param [type] $min [description]
+ * @return [type] [description]
+ */
+function field_has_value($entity, $field, $source = 'value', $min = NULL) {
+ list($handler, $handler_data) = devtools_func_handler(__FUNCTION__, func_get_args());
+
+ if ($handler) {
+ return $handler_data;
+ }
+ else {
+ if (!is_array($entity)) {
+ $entity = (array) $entity;
+ }
+
+ $lang = LANGUAGE_NONE;
+ if (isset($entity['language'])) {
+ $lang = $entity['language'];
+ }
+
+ if (isset($entity[$field][$lang][0][$source])) {
+ if (!is_null($min)) {
+ return (bool) ($entity[$field][$lang][0][$source] > $min);
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+ }
+}
+
+/**
+ * Returns first value for specified field.
+ * @param [type] $entity [description]
+ * @param [type] $field [description]
+ * @param [type] $source [description]
+ * @return [type] [description]
+ */
+function field_get_value($entity, $field, $source = 'value') {
+ list($handler, $handler_data) = devtools_func_handler(__FUNCTION__, func_get_args());
+
+ if ($handler) {
+ return $handler_data;
+ }
+ else {
+ $entity = (array) $entity;
+
+ $lang = LANGUAGE_NONE;
+ if (isset($entity['language'])) {
+ $lang = $entity['language'];
+ }
+
+ if (field_has_value($entity, $field, $source)) {
+ return $entity[$field][$lang][0][$source];
+ }
+
+ return FALSE;
+ }
} \ No newline at end of file
diff --git a/components/string/string.inc b/components/string/string.inc
index 04af472..95b6dab 100644
--- a/components/string/string.inc
+++ b/components/string/string.inc
@@ -1,12 +1,12 @@
<?php
/**
- * Truncates a string to specified length.
+ * Truncates a string to a maximum specified length on the last space character.
* @param [type] $input [description]
* @param [type] $length [description]
* @return [type] [description]
*/
-function truncate($input, $length = 140) {
+function truncate_old($input, $length = 140) {
list($handler, $handler_data) = devtools_func_handler(__FUNCTION__, func_get_args());
if ($handler) {
@@ -22,6 +22,30 @@ function truncate($input, $length = 140) {
}
}
+function truncate($input, $length = 140) {
+ list($handler, $handler_data) = devtools_func_handler(__FUNCTION__, func_get_args());
+
+ if ($handler) {
+ return $handler_data;
+ }
+ else {
+ $output = $input;
+
+ if (strlen($output) > $length) {
+ $output = check_markup(strip_tags($output), 'plain_text');
+ $output = substr($output, 0, $length);
+
+ if ($space = strrpos($output, ' ')) {
+ $output = substr($output, 0, $space);
+ }
+
+ $output .= '...';
+ }
+
+ return $output;
+ }
+}
+
/**
* Runs the specified text value/format through check_markup().
* @param [type] $text [description]
diff --git a/components/views/views.inc b/components/views/views.inc
index 4a0224d..8b5139c 100644
--- a/components/views/views.inc
+++ b/components/views/views.inc
@@ -19,10 +19,7 @@ function build_views_block($view_id, $display, $subject = '', $arguments = array
if ($view = views_get_view($view_id)) {
if ($view->access($display)) {
- $view->set_display($display);
- $view->set_arguments($arguments);
-
- $view_output = $view->preview();
+ $view_output = $view->preview($display, $arguments);
if (!empty($view->result) || $view->display_handler->get_option('empty') || !empty($view->style_plugin->definition['even empty'])) {
$view_title = $view->get_title();
if (empty($subject) && !empty($view_title)) {