I am finishing some edits on a drupal project that was done by another programmer (I have no contact with him). I'm a newbie and trying to find out how the Paging module works. There are no numbers of pages showing. I suppose the programmer added some custom module or something.
I found a file named "pager.php" in the project's own theme folder with this function, that is probably doing the pagination:
function _my_pager_link($page, $text, $class, $title) {
$query = array();
$query[] = drupal_query_string_encode(array(
'page' => implode(',', $page)), array());
$querystring = pager_get_querystring();
if ($querystring != '') {
$query[] = $querystring;
}
$attributes['title'] = $title;
$attributes['class'] = $class;
return l("<span>$text</span>", $_GET['q'], array('html' => TRUE,
'attributes' => $attributes,
'query' => count($query) ? implode('&', $query) : NULL));
}
function my_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 5) {
global $pager_page_array, $pager_total;
$curr = $pager_page_array[$element];
$total = $pager_total[$element];
$output = '';
if ($total > 1) {
$output .= '<div class="pager">';
if ($curr > 0) {
$page_new = pager_load_array($curr - 1, $element, $pager_page_array);
$output .= _my_pager_link($page_new, t('‹ previous'), 'pager-prev', t('Go to previous page'));
}
if ($curr < $total - 1) {
$page_new = pager_load_array($curr + 1, $element, $pager_page_array);
$output .= _my_pager_link($page_new, t('next ›'), 'pager-next', t('Go to next page'));
}
$output .= '<div class="cleaner"></div>';
$output .= '</div>';
}
return $output;
}
Now there is just 'previous page' and 'next page' on the web. I would like it to be like this
'previous page '... 2 3 4 ... 'next page'
How can I add the list of pages there?
Thank You
Copy and paste http://api.drupal.org/api/function/theme_pager/6
Add salt and voila!
You need to set the global values like so:
global $pager_page_array, $pager_total;
$pager_page_array[0] = $your_page_count_goes_here;
$pager_total[0] = $your_page_total_goes_here;
And then you can call theme('pager', ...) or any custom paging theme function that you may have.
Related
I've taken over managing our site from MIA developers and have spent the day trying to find this answer.
After upgrading to v 7.56 there's just ONE specific page in a list of pages that I am unable to access as an admin. (and unfortunately it's probably the most needed report in our admin panel).
Here's what I know:
Drupal Version 7.56
PHP 7.0.20
No errors when status report is run
Chron - no errors
Here's what I've done:
added $cookie_domain = '.example.com'; to settings.php
cleared browser cache and cookies
ensured admin has access to everything
cleared site cache
made sure code on page(s) was exactly the same as it was before I did the update
Not sure what to do or where to go from here. Any help is much appreciated.
UPDATE: When logged in as super admin, received HTTP 500 error. After more research, I updated the php.ini to include memory_limit = 64M ;
Now I can view the page as the superadmin, but it still isn't available for other admins.
Image 1: viewing page as admin
Image 2: viewing page as superadmin
function custom_reports_menu() {
$items['administration/upcoming-classes'] = array(
'title' => 'Upcoming Classes',
'page callback' => 'custom_reports_upcoming_classes_page',
'access callback' => 'user_access',
'access arguments' => array('admin wdcc reports'),
'file' => 'includes/custom_reports.upcoming-classes.inc',
'type' => MENU_CALLBACK,
);
$items['administration/class-details'] = array(
'title' => 'Class Details',
'page callback' => 'custom_reports_class_details_page',
'access callback' => 'user_access',
'access arguments' => array('admin wdcc reports'),
'file' => 'includes/custom_reports.class-details.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
function custom_reports_upcoming_classes_page() {
drupal_add_css(base_path().path_to_theme().'/assets/css/outburst-accounts.css', array('type' => 'external'));
global $user;
$uid = $user->uid;
$output = '';
$upcoming_classes = custom_reports_get_upcoming_classes();
$attendee_count = custom_reports_get_attendee_count();
// upcoming classes
$output .= '<h2>Upcoming Classes</h2>';
$output .= custom_reports_format_upcoming_classes($upcoming_classes, $attendee_count);
return $output;
}
function custom_reports_permission() {
return array(
'admin wdcc reports' => array(
'title' => t('Admin WDCC Reports'),
'description' => t('Perform administration tasks for WDCC.'),
//'cache' => DRUPAL_NO_CACHE,
),
);
}
function custom_reports_get_upcoming_classes() {
$today = date('Y-m-d');
$x = 0;
$classes = '';
// get classes from new db tables
$today = date('Y-m-d H:i:s');
$result = db_query("SELECT n.nid FROM node n, field_data_field_date fdfd WHERE n.status = :status AND n.type = :type AND n.nid = fdfd.entity_id AND fdfd.field_date_value >= :today ORDER BY fdfd.field_date_value ASC", array(':status' => 1, ':type' => 'public_class_date', ':today' => $today));
if ($result->rowCount() > 0) {
foreach ($result as $row) {
$nid = $row->nid;
$node = node_load($nid);
$product_id = $nid;
$product_title = $node->title;
$product_type = 'public_class_date';
$product_date = $node->field_date[$node->language][0]['value'];
$product_datestamp = strtotime($product_date);
//$product_datestamp = strtotime($product_date);
// set vars
$classes[$x]['product_id'] = $product_id;
$classes[$x]['product_title'] = $product_title;
$classes[$x]['product_type'] = $product_type;
$classes[$x]['product_date'] = $product_date;
$classes[$x]['product_datestamp'] = $product_datestamp;
$x++;
}
}
return $classes;
}
function custom_reports_get_attendee_count() {
$attendees = array();
$old_attendees = array();
$new_attendees = array();
$result = db_query("SELECT itemID, attendeeID, attendeeName FROM wdcc_old_attendee");
if ($result->rowCount() > 0) {
foreach ($result as $row) {
$item_id = $row->itemID;
$attendee_id = 'B'.$row->attendeeID;
$attendee_name = $row->attendeeName;
$old_attendees[$item_id][$attendee_id]['old_attendee_id'] = $attendee_id;
if (strpos($attendee_name, '&') > 0 || strpos($attendee_name, ' and') > 0) { // couples
$old_attendees[$item_id][$attendee_id]['total_attendees'] = 2;
} else {
$old_attendees[$item_id][$attendee_id]['total_attendees'] = 1;
}
}
}
if (is_array($old_attendees)) {
$connect_class_ids = custom_accounts_connect_class_ids();
foreach ($old_attendees as $old_item_id => $attendee_list) {
if (isset($connect_class_ids[$old_item_id])) {
$product_id = $connect_class_ids[$old_item_id];
foreach ($attendee_list as $attendee_id => $attendee) {
$old_attendee_id = $attendee['old_attendee_id'];
$attendees[$product_id][$old_attendee_id]['total_attendees'] = $attendee['total_attendees'];
}
}
}
}
$result = db_query("SELECT id, product_id FROM wdcc_attendees WHERE transaction_id > 0");
if ($result->rowCount() > 0) {
foreach ($result as $row) {
$attendee_id = $row->id;
$product_id = $row->product_id;
$attendees[$product_id][$attendee_id]['total_attendees'] = 1;
}
}
$cancelled_attendees = array();
$result = db_query("SELECT * FROM wdcc_attendees_cancelled");
if ($result->rowCount() > 0) {
foreach ($result as $row) {
$attendee_id = $row->attendee_id;
$old_attendee_id = 'B'.$row->old_attendee_id;
if ($attendee_id > 0) {
$cancelled_attendees[] = $attendee_id;
} else {
$cancelled_attendees[] = $old_attendee_id;
}
}
}
foreach ($attendees as $product_id => $product_attendees) {
foreach ($product_attendees as $attendee_id => $attendee) {
if (in_array($attendee_id, $cancelled_attendees)) {
unset($attendees[$product_id][$attendee_id]);
}
}
}
$attendee_count = array();
foreach ($attendees as $product_id => $product_attendees) {
foreach ($product_attendees as $attendee_id => $attendee) {
if (!isset($attendee_count[$product_id])) {
$attendee_count[$product_id] = $attendee['total_attendees'];
} else {
$attendee_count[$product_id] = $attendee_count[$product_id] + $attendee['total_attendees'];
}
}
}
return $attendee_count;
}
function custom_reports_format_upcoming_classes($upcoming_classes, $attendee_count) {
$output = '';
if (is_array($upcoming_classes)) {
$output .= '<div class="table-responsive table-container">';
$output .= '<table class="table">';
$output .= '<tr><td>Class</td><td>Guests</td><td>Actions</td></tr>';
foreach ($upcoming_classes as $class) {
$nid = $class['product_id'];
$node_url = url('node/'.$nid, array('absolute' => TRUE));
$attendees = 0;
if (isset($attendee_count[$nid])) {
$attendees = $attendee_count[$nid];
}
$output .= '<tr><td>'.$class['product_title'].'<br />'.date('m/d/Y - g:i A', $class['product_datestamp']).'</td><td>'.$attendees.'</td><td>View roster</td></tr>';
}
$output .= '</table>';
$output .= '</div>';
} else {
$output .= '<p>No upcoming classes found.</p>';
}
return $output;
}
Probably would need more info, but it seems like a case of custom or hardcoded permissions.
Here's potential cases to explore:
Assign all the roles to the admin user
Search custom modules for this page URL. See if page is only certain users are allowed to access this page.
If report is Drupal View, find this view and check the permissions section.
In the current menu items you are using access callback attribute in a wrong way. Your menu items do not require to specify access callback. Only access argument is sufficient.
Please add an access argument to which only admin has access.
"access callback": A function returning TRUE if the user has access rights to this menu item, and FALSE if not. It can also be a boolean constant instead of a function, and you can also use numeric values (will be cast to boolean). Defaults to user_access() unless a value is inherited from the parent menu item; only MENU_DEFAULT_LOCAL_TASK items can inherit access callbacks. To use the user_access() default callback, you must specify the permission to check as 'access arguments' (see below).
Source: https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7.x
Replace this below code in settings.php file
PHP variable name:
$cookie_domain = 'example.com'; (line 340)
I was getting this error while login Drupal. After lots of reacher I found that we mistakenly blocked some internal IP of Drupal which is trigger while login the Drupal. So my suggestion is here Your should have to check if you have block any IP at your end (index.php file or anywhere). And You can TRUNCATE the Table session and flood from DB it also help you out.
I need help with a wordpress question.
I created a custom shortcode that retrieves a list of data inside a table with specific paramenter:
add_shortcode("archive", "archive_render");
function archive_render($atts) {
extract(shortcode_atts(array(
"rientro" => "no",
"year" => "",
), $atts));
global $wpdb;
$rientro == "si" ? $rientro = "yes" : "no";
$query = "SELECT event_name FROM wp_em_events WHERE EXTRACT(YEAR FROM event_end_date) = ".$year." AND event_end_date < CURDATE()";
$pasts_event = $wpdb->get_col($query);
function get_pasts_event( $pasts_event ){
foreach ( $pasts_event as $past_event_slug ) {
$output .= "<li><a href='".get_site_url()."/eventi/".$past_event_slug."'>$past_event_slug</a></li>";
}
return $output;
}
$string = '[one_third last="'.$rientro.'" class="" id=""][accordian class="" id=""][toggle title="'.$year.'" open="no"]<ul>'.get_pasts_event($pasts_event).'</ul>[/toggle][/accordian][/one_third]';
echo do_shortcode( $string );
}
I want to retrieve all events that has past date compared with the current date.
If I add the shortcode twice in the page, only the first shortcode works and the page stop to display the rest of the content.
Anybody can help me to solve this problem?
wordpress shortcode should return a string, not echoing it
let me re-arrange your code
function get_pasts_event( $pasts_event ){
foreach ( $pasts_event as $past_event_slug ) {
$output .= "<li><a href='".get_site_url()."/eventi/".$past_event_slug."'>$past_event_slug</a></li>";
}
return $output;
}
add_shortcode("archive", "archive_render");
function archive_render($atts) {
extract(shortcode_atts(array(
"rientro" => "no",
"year" => "",
), $atts));
global $wpdb;
$rientro == "si" ? $rientro = "yes" : "no";
$query = "SELECT event_name FROM wp_em_events WHERE EXTRACT(YEAR FROM event_end_date) = ".$year." AND event_end_date < CURDATE()";
$pasts_event = $wpdb->get_col($query);
$string = '[one_third last="'.$rientro.'" class="" id=""][accordian class="" id=""][toggle title="'.$year.'" open="no"]<ul>'.get_pasts_event($pasts_event).'</ul>[/toggle][/accordian][/one_third]';
return $string;
}
Hi I am trying to add html to the "t('Older Posts')" and "t('Newer Posts')" Is this possible ? I can figure it out ????
I am in a Drupal 6 template.php file.
This is the code I am trying to add as html -
<span>Newer Posts</span>
<span>Older Posts</span>
I need to replace the above in these spots located in the full function below ?
t('Older Posts')
t('Newer Posts')
I want to create something like this
t('<span>Older Posts</span>')
t('<span>Newer Posts</span>')
Full Function
function theme_views_mini_pager($tags = array(), $limit = 10,
$element = 0, $parameters = array(), $quantity = 9) {
global $pager_page_array, $pager_total;
// Calculate various markers within this pager piece:
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// current is the page we are currently paged to
$pager_current = $pager_page_array[$element] + 1;
// max is the maximum page number
$pager_max = $pager_total[$element];
// End of marker calculations.
$li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] :
t('Older Posts')), $limit, $element, 1, $parameters);
if (empty($li_previous)) {
$li_previous = " ";
}
$li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('Newer Posts')),
$limit,$element, 1, $parameters);
if (empty($li_next)) {
$li_next = " ";
}
if ($pager_total[$element] > 5) {
$items[] = array(
'class' => 'action back pager-previous',
'data' => $li_previous,
);
$items[] = array(
'class' => 'action pager-next',
'data' => $li_next,
);
return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
}
}
I am trying to figure out if this is possible I have tried many things and nothing has worked yet.
You can use
$link = '<span>' . t('Older Posts') . '</span>';
OR
$link = t('!link_startOlder Posts!link_end', array(
'!link_start' => '<a href="" class="action back"><span>',
'!link_end' => '</span></a>',
));
I am trying to theme particular pagers on the site and no matter what id I try it doesn't seem to get picked up. This is what I am using to theme all pagers now.
function Subtle_Hightlights_views_mini_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
global $pager_page_array, $pager_total;
// Calculate various markers within this pager piece:
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// current is the page we are currently paged to
$pager_current = $pager_page_array[$element] + 1;
// max is the maximum page number
$pager_max = $quantity;
// End of marker calculations.
$li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('')), $limit, $element, 1, $parameters);
if (empty($li_previous)) {
$li_previous = "";
}
$li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('')), $limit, $element, 1, $parameters);
if (empty($li_next)) {
$li_next = "";
}
if ($pager_total[$element] > 1) {
$items[] = array(
'class' => 'pager-previous-mini',
'data' => $li_previous,
);
if ($pager_current == 9){
$li_next = "";
}
$items[] = array(
'class' => 'pager-current-mini',
'data' => t('#current of #max', array('#current' => $pager_current, '#max' => $pager_max)),
);
$items[] = array(
'class' => 'pager-next-mini',
'data' => $li_next,
);
return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
}
}
now this works to theme all mini pagers but when I try to apply the name of the view and block like this.
function Subtle_Hightlights_views_mini_pager__news_items__block_2($tags = array(), $limit = ``10, $element = 0, $parameters = array(), $quantity = 9) {
does nothing acts as though the code isnt there anymore. Anyone else tried this and it actually worked?
There is a good step by step instructions on how you can overwrite the pager (mini or full). The only step that I would suggest that you do different is when you get to list of theme function names that you can use to override your views pager inside your template.php file, just use this module: Theme developer. Once it's enabled it will provide in a much easier way the suggestions. If that fails, then just try the article's methods.
Drupal 6 Override views pager theme function
This is the issue.
I have a block called 'User Favorites Block'
It's placed in the region 'First Sidebar'
'First Sidebar' appears on the front-page.
The function is supposed to grab the data from the f25_favorites table and list them inside the block. Right now the table is an empty array.
When I return $output, none of my divs or anything are output.
When I do print($output), everything is displayed.
This is my test code to show that my 'if' statement is returning true. http://d.pr/zDph
/*
* f25_favorites_my_favorites theme
*/
function theme_f25_favorites_my_favorites($mypaths) {
dsm($mypaths);
print_r(count($mypaths));
$output .= 'n<div id="f25-favorites">n';
$output .= '<div id="f25-favorites-list">n';
if (count($mypaths) == 0) {
$output .= "No favorites have been added";
print "No favorites have been added";
}
else {
foreach ($mypaths as $indpath) {
$output .= l($indpath->title, $indpath->path, $attributes = array());
}
}
$output .= '</div>n';
$output .= '<div id="f25-favorites-add">n';
$output .= '</div>n';
$output .= 'n</div>n';
return $output;
}
This outputs this: http://d.pr/Uhrs
Note the 0 on the top left, that's the output of the 'count()'
And the print of the text within the 'if'
So, this is my theme:
/*
* f25_favorites_my_favorites theme
*/
function theme_f25_favorites_my_favorites($mypaths) {
/*dsm($mypaths);
print_r(count($mypaths));*/
$output .= '\n<div id="f25-favorites">\n';
$output .= '<div id="f25-favorites-list">\n';
if (count($mypaths) == 0) {
$output .= "No favorites have been added";
}
else {
foreach ($mypaths as $indpath) {
$output .= l($indpath->title, $indpath->path, $attributes = array());
}
}
$output .= '</div>\n';
$output .= '<div id="f25-favorites-add">\n';
$output .= '</div>\n';
$output .= '\n</div>\n';
return $output;
}
It's called with this hook_theme() function:
/*
* Implentation of hook_theme().
*/
function f25_favorites_theme () {
return array(
'f25_favorites_my_favorites' => array (
'arguments' => array ('mypaths' => array())
),
);
}
Which is called with this hook_block() function:
/*
* Implementation of hook_block().
*
*/
function f25_favorites_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$blocks = array();
$blocks['f25-favorites'] = array(
'info' => t('User Favorites Block'),
'cache' => BLOCK_NO_CACHE,
);
return $blocks;
}
if ($op == 'view') {
switch ($delta) {
case 0:
$mypaths = f25_favorites_user_favorites();
$block = array(
'subject' => t('User Favorites Block'),
'content' => theme_f25_favorites_my_favorites($mypaths)
);
return $block;
};
}
}
Noteworthy
My theme is a 'Sub-theme' of a theme called 'Zen'
Zen has a block.tpl.php which looks like this: http://d.pr/AaO1
Here is the full code of my module: http://d.pr/cGqc
It could be a region-related problem. Try switching to Garland and add the block to a plain old Garland region, and see if it appears.
If you see it in Garland then make sure your sub-theme really is defining that "First Sidebar" region and then actually printing its variable in the tpl files.
(FWIW I tried your code on Garland and it displays the block fine.)
Also, you might want to change your function call from:
theme_f25_favorites_my_favorites($mypaths)
to:
theme('f25_favorites_my_favorites', $mypaths)
...if you want to keep the code flexible (i.e. have Drupal call any preprocess functions and allow other people, or yourself in the future, to override the template's output)