From 35a9a468ceeb7b8e8b5ae2f026d3bdd76dff68be Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 28 Jan 2016 15:23:42 -0800 Subject: widget_item - provide ability to use the page title instead of the message_id to locate the desired item. You can use either, but the page title is often easier to use and discover. --- include/widgets.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'include/widgets.php') diff --git a/include/widgets.php b/include/widgets.php index 891e9c018..7e502e4c2 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -817,7 +817,7 @@ function widget_item($arr) { return ''; - if(! $arr['mid']) + if((! $arr['mid']) && (! $arr['title'])) return ''; if(! perm_is_allowed($channel_id, get_observer_hash(), 'view_pages')) @@ -826,10 +826,20 @@ function widget_item($arr) { require_once('include/security.php'); $sql_extra = item_permissions_sql($channel_id); - $r = q("select * from item where mid = '%s' and uid = %d and item_type = " . intval(ITEM_TYPE_WEBPAGE) . " $sql_extra limit 1", - dbesc($arr['mid']), - intval($channel_id) - ); + if($arr['title']) { + $r = q("select item.* from item left join item_id on item.id = item_id.iid + where item.uid = %d and sid = '%s' and service = 'WEBPAGE' and item_type = %d $sql_options $revision limit 1", + intval($channel_id), + dbesc($arr['title']), + intval(ITEM_TYPE_WEBPAGE) + ); + } + else { + $r = q("select * from item where mid = '%s' and uid = %d and item_type = " . intval(ITEM_TYPE_WEBPAGE) . " $sql_extra limit 1", + dbesc($arr['mid']), + intval($channel_id) + ); + } if(! $r) return ''; -- cgit v1.2.3