Index: flag.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.module,v retrieving revision 1.1.2.63 diff -u -F^[^a-z]*function -r1.1.2.63 flag.module --- flag.module 9 Nov 2008 09:46:09 -0000 1.1.2.63 +++ flag.module 11 Nov 2008 12:27:57 -0000 @@ -1223,3 +1223,122 @@ function flag_get_token($nid) { function flag_check_token($token, $seed) { return drupal_get_token($seed) == $token; } + +/** + * Implementation of hook_panels_content_types + */ +function flag_panels_content_types() { + $items['flag_link'] = array( + 'title' => t('Flag link'), + 'single' => FALSE, + 'title callback' => 'flag_panels_link_title', + 'content_types' => 'flag_panels_link_content_types', + 'add callback' => 'flag_panels_link_add', + 'edit callback' => 'flag_panels_link_edit', + 'render callback' => 'flag_panels_link_render', + ); + return $items; +} + +/** + * Returns an administrative title for the link. + */ +function flag_panels_link_title($conf, $context) { + $flag_name = $conf['flag_name']; + $flag = flag_get_flag($flag_name); + if ($flag) { + return t('"@s" flag/unflag link', array('@s' => $flag->get_title())); + } + else { + return t('Error: Flag "@s" is not defined.', array('@s' => $flag_name)); + } +} + +/* + * Returns the form for a new link. + */ +function flag_panels_link_add($id, $parents, $conf = array()) { + $conf['flag_name'] = substr($id, strlen('flag_link_')); + return flag_panels_link_edit($id, $parents, $conf); +} + +/** + * Returns an edit form for a link. + */ +function flag_panels_link_edit($id, $parents, $conf) { + $form['flag_name'] = array( + '#type' => 'value', + '#value' => $conf['flag_name'], + ); + $form['flag_reminder_message'] = array( + '#type' => 'markup', + '#value' => '

' . t("A reminder: the flag (or unflag) link won't show unless in the flag's settings page you have enabled this flag for this object. For example, if the flag is used to flag nodes, then if the object being displayed is a node of type 'story' but you've enabled the flag for nodes of type 'page' only, the link won't show.", array('@flag-settings-url' => url('admin/build/flags/edit/'. $conf['flag_name']))) . '

', + ); + return $form; +} + +/** + * Returns all flag links available, each as a "content type". + */ +function flag_panels_link_content_types() { + $items = array(); + $flags = flag_get_flags(); + foreach ($flags as $flag) { + $info = array( + 'title' => t('Flag link (@flag-title)', array('@flag-title' => $flag->get_title())), + // For the time being, let's borrow Views' icon. + 'icon' => 'icon_views_page.png', + 'path' => panels_get_path('content_types/views'), + ); + switch ($flag->content_type) { + case 'node': + $info += array( + 'description' => t('A link to flag, or unflag, a node.'), + 'required context' => new panels_required_context(t('Node'), 'node'), + 'category' => t('Node context'), + ); + break; + case 'user': + $info += array( + 'description' => t('A link to flag, or unflag, a user.'), + 'required context' => new panels_required_context(t('User'), 'user'), + 'category' => t('User context'), + ); + break; + case 'term': + $info += array( + 'description' => t('A link to flag, or unflag, a taxonomy term.'), + 'required context' => new panels_required_context(t('Term'), 'term'), + 'category' => t('Term context'), + ); + break; + default: + $info = array(); + } + if ($info) { + $items['flag_link_' . $flag->name] = $info; + } + } + return $items; +} + +/** + * Renders a flag link + */ +function flag_panels_link_render($conf, $panel_args, $context) { + if (!empty($context) && empty($context->data)) { + return; + } + $flag_name = $conf['flag_name']; + $flag = flag_get_flag($flag_name); + if ($flag) { + $link->title = $flag->get_title(); + $link->content = flag_create_link($flag_name, $flag->get_content_id($context->data)); + } + else { + $link->title = t('Flag "@flag-name" is not defined.', array('@flag-name' => $flag_name)); + $link->content = $link->title; + } + return $link; +} +