00001 <?php
00002
00003
00004
00005
00006
00007
00008 function panels_block_panels_content_types() {
00009 $items['block'] = array(
00010 'title' => t('Block'),
00011 'content_types' => 'panels_admin_content_types_block',
00012 'render callback' => 'panels_content_block',
00013 'add callback' => 'panels_admin_add_block',
00014 'edit callback' => 'panels_admin_edit_block',
00015 'title callback' => 'panels_admin_title_block',
00016 'add submit callback' => 'panels_admin_submit_block',
00017 'edit submit callback' => 'panels_admin_submit_block',
00018
00019 );
00020 return $items;
00021 }
00022
00023
00024
00025
00026
00027 function panels_content_block($conf) {
00028 $block = (object) module_invoke($conf['module'], 'block', 'view', $conf['delta']);
00029 if (empty($block)) {
00030 return;
00031 }
00032
00033 $block->module = $conf['module'];
00034 $block->delta = $conf['delta'];
00035
00036 if (user_access('administer blocks')) {
00037 $block->admin_links = array(
00038 array(
00039 'title' => t('Configure block'),
00040 'alt' => t("Configure this pane's 'block settings' in administer >> site building >> blocks"),
00041 'href' => "admin/build/block/configure/$block->module/$block->delta",
00042 'query' => drupal_get_destination(),
00043 ),
00044 );
00045 }
00046
00047
00048 if (empty($conf['block_visibility']) && $block->module != 'block') {
00049 return $block;
00050 }
00051
00052
00053 $result = db_query("SELECT title, pages, visibility FROM {blocks} WHERE module = '%s' AND delta = '%s'", $block->module, $block->delta);
00054 $block_visibility = db_fetch_object($result);
00055
00056 if ($block->module == 'block') {
00057 $block->title = $block_visibility->title;
00058 }
00059
00060 if (empty($conf['block_visibility'])) {
00061 return $block;
00062 }
00063
00064 if ($block_visibility && $block_visibility->pages) {
00065 if ($block_visibility->visibility < 2) {
00066 $path = drupal_get_path_alias($_GET['q']);
00067 $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block_visibility->pages, '/')) .')$/';
00068 $page_match = !($block_visibility->visibility xor preg_match($regexp, $path));
00069 }
00070 else {
00071 $page_match = drupal_eval($block_visibility->pages);
00072 }
00073 }
00074 else {
00075 $page_match = TRUE;
00076 }
00077
00078 if ($page_match) {
00079 return $block;
00080 }
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 function panels_admin_content_types_block() {
00093 $types = array();
00094 foreach (module_list() as $module) {
00095 $module_blocks = module_invoke($module, 'block', 'list');
00096 if ($module_blocks) {
00097 foreach ($module_blocks as $delta => $block) {
00098
00099
00100 $info = array(
00101 'title' => strip_tags($block['info']),
00102 );
00103
00104
00105 $function = $module . '_panels_block_info';
00106 if (!function_exists($function)) {
00107 $function = 'panels_default_block_info';
00108 }
00109 $function($module, $delta, $info);
00110
00111
00112
00113 if ($info) {
00114 $types["$module-$delta"] = $info;
00115 }
00116 }
00117 }
00118 }
00119 return $types;
00120 }
00121
00122
00123
00124
00125 function panels_admin_add_block($id, $parents, $conf = array()) {
00126 list($conf['module'], $conf['delta']) = explode('-', $id, 2);
00127 return panels_admin_edit_block($id, $parents, $conf);
00128 }
00129
00130
00131
00132
00133 function panels_admin_edit_block($id, $parents, $conf) {
00134 $form['module'] = array(
00135 '#type' => 'value',
00136 '#value' => $conf['module'],
00137 );
00138 $form['delta'] = array(
00139 '#type' => 'value',
00140 '#value' => $conf['delta'],
00141 );
00142
00143 if (user_access('administer advanced pane settings')) {
00144 $form['block_visibility'] = array(
00145 '#type' => 'checkbox',
00146 '#title' => t('Use block visibility settings (see block config)'),
00147 '#default_value' => $conf['block_visibility'],
00148 '#description' => t('If checked, the block visibility settings for this block will apply to this block.'),
00149 );
00150
00151 if ($settings = module_invoke($conf['module'], 'block', 'configure', $conf['delta'])) {
00152
00153 if ($conf['module'] == 'block') {
00154 unset($settings['submit']);
00155 $settings['info']['#type'] = 'value';
00156 $settings['info']['#value'] = $settings['info']['#default_value'];
00157 }
00158 panels_admin_fix_block_tree($settings);
00159 $form['block_settings'] = array(
00160 '#type' => 'fieldset',
00161 '#title' => t('Block settings'),
00162 '#description' => t('Settings in this section are global and are for all blocks of this type, anywhere in the system.'),
00163 '#tree' => FALSE,
00164 );
00165
00166
00167 $form['block_settings'] += $settings;
00168 }
00169 }
00170
00171 return $form;
00172 }
00173
00174 function panels_admin_submit_block(&$form_values) {
00175 if (!empty($form_values['block_settings'])) {
00176 module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values['block_settings']);
00177 }
00178 }
00179
00180
00181
00182
00183
00184 function panels_admin_fix_block_tree(&$form, $key = NULL) {
00185 if ($key) {
00186 if (!empty($form['#parents'])) {
00187 $form['#parents'] = array_merge(array('configuration', 'block_settings'), $form['#parents']);
00188 }
00189 else if (empty($form['#tree'])) {
00190 $form['#parents'] = array('configuration', 'block_settings', $key);
00191 }
00192 }
00193
00194 if ($form['#type'] == 'textarea' && !empty($form['#rows']) && $form['#rows'] > 10) {
00195 $form['#rows'] = 10;
00196 }
00197
00198 foreach (element_children($form) as $key) {
00199 panels_admin_fix_block_tree($form[$key], $key);
00200 }
00201 }
00202
00203
00204
00205
00206 function panels_admin_title_block($conf) {
00207 $block = module_invoke($conf['module'], 'block', 'list');
00208 if (empty($block) || empty($block[$conf['delta']])) {
00209 return t('Deleted/missing block @module-@delta', array('@module' => $conf['module'], '@delta' => $conf['delta']));
00210 }
00211
00212 $title = filter_xss_admin($block[$conf['delta']]['info']);
00213 return $title;
00214 }
00215
00216 function panels_default_block_info($module, $delta, &$info) {
00217 $core_modules = array('aggregator', 'block', 'blog', 'blogapi', 'book', 'color', 'comment', 'contact', 'drupal', 'filter', 'forum', 'help', 'legacy', 'locale', 'menu', 'node', 'path', 'ping', 'poll', 'profile', 'search', 'statistics', 'taxonomy', 'throttle', 'tracker', 'upload', 'user', 'watchdog', 'system');
00218
00219 if (in_array($module, $core_modules)) {
00220 $info['icon'] = 'icon_core_block.png';
00221 $info['category'] = array(t('Core blocks'), -5);
00222 }
00223 else {
00224 $info['icon'] = 'icon_contrib_block.png';
00225 $info['category'] = t('Contributed blocks');
00226 }
00227 }
00228
00229
00230
00231 function menu_panels_block_info($module, $delta, &$info) {
00232 $info['icon'] = 'icon_core_block_menu.png';
00233 $info['category'] = array(t('Menus'), -2);
00234 }
00235
00236 function forum_panels_block_info($module, $delta, &$info) {
00237 $info['category'] = t('Core blocks');
00238 switch ($delta) {
00239 case '0':
00240 $info['icon'] = 'icon_core_activeforumtopics.png';
00241 break;
00242
00243 case '1':
00244 $info['icon'] = 'icon_core_newforumtopics.png';
00245 break;
00246
00247 default:
00248
00249 panels_default_block_info($module, $delta, $info);
00250 }
00251 }
00252
00253 function profile_panels_block_info($module, $delta, &$info) {
00254 $info['icon'] = 'icon_core_authorinformation.png';
00255 $info['category'] = t('Core blocks');
00256 }
00257
00258 function book_panels_block_info($module, $delta, &$info) {
00259 $info['icon'] = 'icon_core_booknavigation.png';
00260 $info['category'] = t('Core blocks');
00261 }
00262
00263 function blog_panels_block_info($module, $delta, &$info) {
00264 $info['icon'] = 'icon_core_recentblogposts.png';
00265 $info['category'] = t('Core blocks');
00266 }
00267
00268 function poll_panels_block_info($module, $delta, &$info) {
00269 $info['icon'] = 'icon_core_recentpoll.png';
00270 $info['category'] = t('Core blocks');
00271 }
00272
00273 function comment_panels_block_info($module, $delta, &$info) {
00274 $info['icon'] = 'icon_core_recentcomments.png';
00275 $info['category'] = t('Core blocks');
00276 }
00277
00278 function search_panels_block_info($module, $delta, &$info) {
00279 $info['icon'] = 'icon_core_searchform.png';
00280 $info['category'] = t('Core blocks');
00281 }
00282
00283 function node_panels_block_info($module, $delta, &$info) {
00284 $info['icon'] = 'icon_core_syndicate.png';
00285 $info['category'] = t('Core blocks');
00286 }
00287
00288 function aggregator_panels_block_info($module, $delta, &$info) {
00289 $info['icon'] = 'icon_core_syndicate.png';
00290 $info['category'] = array(t('Syndicated Feeds'), -3);
00291 }
00292
00293 function block_panels_block_info($module, $delta, &$info) {
00294 $info['icon'] = 'icon_core_block_empty.png';
00295 $info['category'] = array(t('Custom'), -10);
00296 }
00297
00298 function user_panels_block_info($module, $delta, &$info) {
00299 $info['category'] = t('Core blocks');
00300 switch ($delta) {
00301 case '0':
00302 $info['icon'] = 'icon_core_userlogin.png';
00303 break;
00304
00305 case '1':
00306 $info['icon'] = 'icon_core_navigation.png';
00307 $info['category'] = array(t('Menus'), -2);
00308 break;
00309
00310 case '2':
00311 $info['icon'] = 'icon_core_whosnew.png';
00312 break;
00313
00314 case '2':
00315 $info['icon'] = 'icon_core_whosonline.png';
00316 break;
00317
00318 default:
00319
00320 panels_default_block_info($module, $delta, $info);
00321 }
00322 }
00323