123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844 |
- <?php
- function ctools_content_process(&$plugin, $info) {
- $function_base = $plugin['module'] . '_' . $plugin['name'] . '_content_type_';
- if (empty($plugin['render callback']) && function_exists($function_base . 'render')) {
- $plugin['render callback'] = $function_base . 'render';
- }
- if (empty($plugin['admin title'])) {
- if (function_exists($function_base . 'admin_title')) {
- $plugin['admin title'] = $function_base . 'admin_title';
- }
- else {
- $plugin['admin title'] = $plugin['title'];
- }
- }
- if (empty($plugin['admin info']) && function_exists($function_base . 'admin_info')) {
- $plugin['admin info'] = $function_base . 'admin_info';
- }
- if (!isset($plugin['edit form']) && function_exists($function_base . 'edit_form')) {
- $plugin['edit form'] = $function_base . 'edit_form';
- }
- if (!isset($plugin['add form']) && function_exists($function_base . 'add_form')) {
- $plugin['add form'] = $function_base . 'add_form';
- }
- if (!isset($plugin['add form']) && function_exists($function_base . 'edit_form')) {
- $plugin['add form'] = $function_base . 'edit_form';
- }
- if (!isset($plugin['description'])) {
- $plugin['description'] = '';
- }
- if (!isset($plugin['icon'])) {
- $plugin['icon'] = ctools_content_admin_icon($plugin);
- }
-
- if (!isset($plugin['content types'])) {
-
- if (function_exists($function_base . 'content_types')) {
- $plugin['content types'] = $function_base . 'content_types';
- }
- else {
- $type = array(
- 'title' => $plugin['title'],
- 'description' => $plugin['description'],
- 'icon' => ctools_content_admin_icon($plugin),
- 'category' => $plugin['category'],
- );
- if (isset($plugin['required context'])) {
- $type['required context'] = $plugin['required context'];
- }
- if (isset($plugin['top level'])) {
- $type['top level'] = $plugin['top level'];
- }
- $plugin['content types'] = array($plugin['name'] => $type);
- if (!isset($plugin['single'])) {
- $plugin['single'] = TRUE;
- }
- }
- }
- }
- function ctools_get_content_type($content_type) {
- ctools_include('context');
- ctools_include('plugins');
- return ctools_get_plugins('ctools', 'content_types', $content_type);
- }
- function ctools_get_content_types() {
- ctools_include('context');
- ctools_include('plugins');
- return ctools_get_plugins('ctools', 'content_types');
- }
- function ctools_content_get_subtypes($type) {
- static $cache = array();
- $subtypes = array();
- if (is_array($type)) {
- $plugin = $type;
- }
- else {
- $plugin = ctools_get_content_type($type);
- }
- if (empty($plugin) || empty($plugin['name'])) {
- return;
- }
- if (isset($cache[$plugin['name']])) {
- return $cache[$plugin['name']];
- }
- if (isset($plugin['content types'])) {
- $function = $plugin['content types'];
- if (is_array($function)) {
- $subtypes = $function;
- }
- else if (function_exists($function)) {
-
- $subtypes = (array) $function($plugin);
- }
- }
-
-
- foreach ($subtypes as $id => $subtype) {
-
- ctools_content_prepare_subtype($subtypes[$id], $plugin);
- }
- $cache[$plugin['name']] = $subtypes;
- return $subtypes;
- }
- function ctools_content_get_subtype($type, $subtype_id) {
- $subtype = array();
- if (is_array($type)) {
- $plugin = $type;
- }
- else {
- $plugin = ctools_get_content_type($type);
- }
- $function = ctools_plugin_get_function($plugin, 'content type');
- if ($function) {
- $subtype = $function($subtype_id, $plugin);
- }
- else {
- $subtypes = ctools_content_get_subtypes($type);
- if (isset($subtypes[$subtype_id])) {
- $subtype = $subtypes[$subtype_id];
- }
-
-
- if (empty($subtype) && !empty($plugin['single'])) {
- $subtype = current($subtypes);
- }
- }
- if ($subtype) {
- ctools_content_prepare_subtype($subtype, $plugin);
- }
- return $subtype;
- }
- function ctools_content_prepare_subtype(&$subtype, $plugin) {
- foreach (array('path', 'js', 'css') as $key) {
- if (!isset($subtype[$key]) && isset($plugin[$key])) {
- $subtype[$key] = $plugin[$key];
- }
- }
- drupal_alter('ctools_content_subtype', $subtype, $plugin);
- }
- function ctools_content_render($type, $subtype, $conf, $keywords = array(), $args = array(), $context = array(), $incoming_content = '') {
- if (is_array($type)) {
- $plugin = $type;
- }
- else {
- $plugin = ctools_get_content_type($type);
- }
- $subtype_info = ctools_content_get_subtype($plugin, $subtype);
- $function = ctools_plugin_get_function($subtype_info, 'render callback');
- if (!$function) {
- $function = ctools_plugin_get_function($plugin, 'render callback');
- }
- if ($function) {
- $pane_context = ctools_content_select_context($plugin, $subtype, $conf, $context);
- if ($pane_context === FALSE) {
- return;
- }
- $content = $function($subtype, $conf, $args, $pane_context, $incoming_content);
- if (empty($content)) {
- return;
- }
-
-
- if (!isset($content->type)) {
- $content->type = $plugin['name'];
- }
- if (!isset($content->subtype)) {
- $content->subtype = $subtype;
- }
-
- if (!empty($conf['override_title'])) {
-
- $keywords['%title'] = empty($content->title) ? '' : $content->title;
- $content->original_title = $keywords['%title'];
- $content->title = $conf['override_title_text'];
- $content->title_heading = isset($conf['override_title_heading']) ? $conf['override_title_heading'] : 'h2';
- }
- if (!empty($content->title)) {
-
- if (!empty($keywords) || !empty($context)) {
- $content->title = ctools_context_keyword_substitute($content->title, $keywords, $context);
- }
-
- $content->title = filter_xss_admin($content->title);
-
- if (!empty($content->title_link)) {
- if (!is_array($content->title_link)) {
- $url = array('href' => $content->title_link);
- }
- else {
- $url = $content->title_link;
- }
-
- $url += array('href' => '', 'attributes' => array(), 'query' => array(), 'fragment' => '', 'absolute' => NULL, 'html' => TRUE);
- $content->title = l($content->title, $url['href'], $url);
- }
- }
- return $content;
- }
- }
- function ctools_content_editable($type, $subtype, $conf) {
- if (empty($type['edit form']) && empty($subtype['edit form'])) {
- return FALSE;
- }
- if ($function = ctools_plugin_get_function($subtype, 'check editable')) {
- return $function($type, $subtype, $conf);
- }
- return TRUE;
- }
- function ctools_content_admin_title($type, $subtype, $conf, $context = NULL) {
- if (is_array($type)) {
- $plugin = $type;
- }
- else if (is_string($type)) {
- $plugin = ctools_get_content_type($type);
- }
- else {
- return;
- }
- if ($function = ctools_plugin_get_function($plugin, 'admin title')) {
- $pane_context = ctools_content_select_context($plugin, $subtype, $conf, $context);
- if ($pane_context === FALSE) {
- if ($plugin['name'] == $subtype) {
- return t('@type will not display due to missing context', array('@type' => $plugin['name']));
- }
- return t('@type:@subtype will not display due to missing context', array('@type' => $plugin['name'], '@subtype' => $subtype));
- }
- return $function($subtype, $conf, $pane_context);
- }
- else if (isset($plugin['admin title'])) {
- return $plugin['admin title'];
- }
- else if (isset($plugin['title'])) {
- return $plugin['title'];
- }
- }
- function ctools_content_admin_icon($subtype) {
- $icon = '';
- if (isset($subtype['icon'])) {
- $icon = $subtype['icon'];
- if (!file_exists($icon)) {
- $icon = $subtype['path'] . '/' . $icon;
- }
- }
- if (empty($icon) || !file_exists($icon)) {
- $icon = ctools_image_path('no-icon.png');
- }
- return $icon;
- }
- function ctools_content_get_defaults($plugin, $subtype) {
- if (isset($plugin['defaults'])) {
- $defaults = $plugin['defaults'];
- }
- else if (isset($subtype['defaults'])) {
- $defaults = $subtype['defaults'];
- }
- if (isset($defaults)) {
- if (is_string($defaults) && function_exists($defaults)) {
- if ($return = $defaults($pane)) {
- return $return;
- }
- }
- else if (is_array($defaults)) {
- return $defaults;
- }
- }
- return array();
- }
- function ctools_content_admin_info($type, $subtype, $conf, $context = NULL) {
- if (is_array($type)) {
- $plugin = $type;
- }
- else {
- $plugin = ctools_get_content_type($type);
- }
- if ($function = ctools_plugin_get_function($plugin, 'admin info')) {
- $output = $function($subtype, $conf, $context);
- }
- if (empty($output) || !is_object($output)) {
- $output = new stdClass();
-
- $subtype = check_plain(str_replace("_", " ", $subtype));
- $output->title = $subtype;
- $output->content = t('No info available.');
- }
- return $output;
- }
- function ctools_content_configure_form_defaults($form, &$form_state) {
- $plugin = $form_state['plugin'];
- $subtype = $form_state['subtype'];
- $contexts = isset($form_state['contexts']) ? $form_state['contexts'] : NULL;
- $conf = $form_state['conf'];
- $add_submit = FALSE;
- if (!empty($subtype['required context']) && is_array($contexts)) {
- $form['context'] = ctools_context_selector($contexts, $subtype['required context'], isset($conf['context']) ? $conf['context'] : array());
- $add_submit = TRUE;
- }
- ctools_include('dependent');
-
-
- if (empty($plugin['no title override']) && empty($subtype['no title override'])) {
- $form['aligner_start'] = array(
- '#markup' => '<div class="option-text-aligner clearfix">',
- );
- $form['override_title'] = array(
- '#type' => 'checkbox',
- '#default_value' => isset($conf['override_title']) ? $conf['override_title'] : '',
- '#title' => t('Override title'),
- '#id' => 'override-title-checkbox',
- );
- $form['override_title_text'] = array(
- '#type' => 'textfield',
- '#default_value' => isset($conf['override_title_text']) ? $conf['override_title_text'] : '',
- '#size' => 35,
- '#id' => 'override-title-textfield',
- '#dependency' => array('override-title-checkbox' => array(1)),
- '#dependency_type' => 'hidden',
- );
- $form['override_title_heading'] = array(
- '#type' => 'select',
- '#default_value' => isset($conf['override_title_heading']) ? $conf['override_title_heading'] : 'h2',
- '#options' => array(
- 'h1' => t('h1'),
- 'h2' => t('h2'),
- 'h3' => t('h3'),
- 'h4' => t('h4'),
- 'h5' => t('h5'),
- 'h6' => t('h6'),
- 'div' => t('div'),
- 'span' => t('span'),
- ),
- '#id' => 'override-title-heading',
- '#dependency' => array('override-title-checkbox' => array(1)),
- '#dependency_type' => 'hidden',
- );
- $form['aligner_stop'] = array(
- '#markup' => '</div>',
- );
- if (is_array($contexts)) {
- $form['override_title_markup'] = array(
- '#prefix' => '<div class="description">',
- '#suffix' => '</div>',
- '#markup' => t('You may use %keywords from contexts, as well as %title to contain the original title.'),
- );
- }
- $add_submit = TRUE;
- }
- if ($add_submit) {
-
- $form['#submit'][] = 'ctools_content_configure_form_defaults_submit';
- }
- return $form;
- }
- function ctools_content_configure_form_defaults_submit(&$form, &$form_state) {
- if (isset($form_state['values']['context'])) {
- $form_state['conf']['context'] = $form_state['values']['context'];
- }
- if (isset($form_state['values']['override_title'])) {
- $form_state['conf']['override_title'] = $form_state['values']['override_title'];
- $form_state['conf']['override_title_text'] = $form_state['values']['override_title_text'];
- $form_state['conf']['override_title_heading'] = $form_state['values']['override_title_heading'];
- }
- }
- function ctools_content_form($op, $form_info, &$form_state, $plugin, $subtype_name, $subtype, &$conf, $step = NULL) {
- $form_state += array(
- 'plugin' => $plugin,
- 'subtype' => $subtype,
- 'subtype_name' => $subtype_name,
- 'conf' => &$conf,
- 'op' => $op,
- );
- $form_info += array(
- 'id' => 'ctools_content_form',
- 'show back' => TRUE,
- );
-
- if ($op == 'add') {
- if (!empty($subtype['add form'])) {
- _ctools_content_create_form_info($form_info, $subtype['add form'], $subtype, $subtype, $op);
- }
- else if (!empty($plugin['add form'])) {
- _ctools_content_create_form_info($form_info, $plugin['add form'], $plugin, $subtype, $op);
- }
- }
- if (empty($form_info['order'])) {
-
- if (!empty($subtype['edit form'])) {
- _ctools_content_create_form_info($form_info, $subtype['edit form'], $subtype, $subtype, $op);
- }
- else if (!empty($plugin['edit form'])) {
- _ctools_content_create_form_info($form_info, $plugin['edit form'], $plugin, $subtype, $op);
- }
- }
- if (empty($form_info['order'])) {
- return FALSE;
- }
- ctools_include('wizard');
- return ctools_wizard_multistep_form($form_info, $step, $form_state);
- }
- function _ctools_content_create_form_info(&$form_info, $info, $plugin, $subtype, $op) {
- if (is_string($info)) {
- if (empty($subtype['title'])) {
- $title = t('Configure');
- }
- else if ($op == 'add') {
- $title = t('Configure new !subtype_title', array('!subtype_title' => $subtype['title']));
- }
- else {
- $title = t('Configure !subtype_title', array('!subtype_title' => $subtype['title']));
- }
- $form_info['order'] = array('form' => $title);
- $form_info['forms'] = array(
- 'form' => array(
- 'title' => $title,
- 'form id' => $info,
- 'wrapper' => 'ctools_content_configure_form_defaults',
- ),
- );
- }
- else if (is_array($info)) {
- $form_info['order'] = array();
- $form_info['forms'] = array();
- $count = 0;
- $base = 'step';
- $wrapper = NULL;
- foreach ($info as $form_id => $title) {
-
- $step = $base . ++$count;
- if (empty($wrapper)) {
- $wrapper = $step;
- }
- if (is_array($title)) {
- if (!empty($title['default'])) {
- $wrapper = $step;
- }
- $title = $title['title'];
- }
- $form_info['order'][$step] = $title;
- $form_info['forms'][$step] = array(
- 'title' => $title,
- 'form id' => $form_id,
- );
- }
- if ($wrapper) {
- $form_info['forms'][$wrapper]['wrapper'] = 'ctools_content_configure_form_defaults';
- }
- }
- }
- function ctools_content_get_available_types($contexts = NULL, $has_content = FALSE, $allowed_types = NULL, $default_types = NULL) {
- $plugins = ctools_get_content_types();
- $available = array();
- foreach ($plugins as $id => $plugin) {
- foreach (ctools_content_get_subtypes($plugin) as $subtype_id => $subtype) {
-
-
- if (!empty($subtype['requires content']) && !$has_content) {
- continue;
- }
-
- if (!empty($subtype['required context'])) {
- if (!ctools_context_match_requirements($contexts, $subtype['required context'])) {
- continue;
- }
- }
-
- if ($allowed_types) {
- $key = $id . '-' . $subtype_id;
- if (!isset($allowed_types[$key])) {
- $allowed_types[$key] = isset($default_types[$id]) ? $default_types[$id] : $default_types['other'];
- }
- if (!$allowed_types[$key]) {
- continue;
- }
- }
-
- if (isset($subtype['create content access']) && function_exists($subtype['create content access']) && !$subtype['create content access']($plugin, $subtype)) {
- continue;
- }
-
- $available[$id][$subtype_id] = $subtype;
- }
- }
- return $available;
- }
- function ctools_content_get_all_types() {
- $plugins = ctools_get_content_types();
- $available = array();
- foreach ($plugins as $id => $plugin) {
- foreach (ctools_content_get_subtypes($plugin) as $subtype_id => $subtype) {
-
- $available[$id][$subtype_id] = $subtype;
- }
- }
- return $available;
- }
- function ctools_content_select_context($plugin, $subtype, $conf, $contexts) {
-
- if (empty($subtype)) {
- return;
- }
- $subtype_info = ctools_content_get_subtype($plugin, $subtype);
- if (empty($subtype_info)) {
- return;
- }
- if (!empty($subtype_info['all contexts']) || !empty($plugin['all contexts'])) {
- return $contexts;
- }
-
-
- if (empty($subtype_info['required context'])) {
- return;
- }
-
-
-
-
-
-
- if (is_array($subtype_info['required context'])) {
- if (empty($conf['context']) || count($subtype_info['required context']) != count($conf['context'])) {
- foreach ($subtype_info['required context'] as $index => $required) {
- if (!isset($conf['context'][$index])) {
- $filtered = ctools_context_filter($contexts, $required);
- if ($filtered) {
- $keys = array_keys($filtered);
- $conf['context'][$index] = array_shift($keys);
- }
- }
- }
- }
- }
- else {
- if (empty($conf['context'])) {
- $filtered = ctools_context_filter($contexts, $subtype_info['required context']);
- if ($filtered) {
- $keys = array_keys($filtered);
- $conf['context'] = array_shift($keys);
- }
- }
- }
- if (empty($conf['context'])) {
- return;
- }
- $context = ctools_context_select($contexts, $subtype_info['required context'], $conf['context']);
- return $context;
- }
- function ctools_get_addressable_content($address, $type = 'content') {
- if (!is_array($address)) {
- $address = explode('::', $address);
- }
- if (!$address) {
- return;
- }
-
-
- $module = array_shift($address);
- return module_invoke($module, 'addressable_content', $address, $type);
- }
|