Adding smAction on shiny datatables - menu

Here's an example of smAction on plot,.
library(shiny)
library(shinyBS)
library(shinyMenus)
app <- shinyApp(
ui =
fluidPage(
smNavBar("testMenu", "shinyMB", full.width = TRUE, fixed = FALSE,
textInput("n", "Sample Size", value = 1000)
),
plotOutput("testPlot"),
smContextMenu("context1","testPlot",
smAction("action1", "Normal"),
smAction("action2", "Lognormal"),
smAction("action3", "Uniform")
)
),
server =
function(input, output, session) {
output$testPlot <- renderPlot({
plot(rnorm(input$n))
})
})
runApp(app)
I am trying to do the same thing , user right clicks and the menu shows three actions on a datatable instead of plot , this is what I have so far
library(shiny)
library(shinyBS)
library(shinyMenus)
app <- shinyApp(
ui = basicPage(
h2('The mtcars data'),
dataTableOutput('mytable'),
smContextMenu("context1","mytable",
smAction("action1", "Action1"),
smAction("action2", "Action2"),
smAction("action3", "Action3")
)
),
server =
function(input, output, session) {
output$mytable <- renderDataTable({
mtcars
})
})
runApp(app)
This is not working. I am not sure what I am missing, any pointers are much appreciated. Thanks in advance.

Related

How to show primary menu of main site throughout multi-site network

I have managed to switch the primiary navigation menu of my subsites to show the main site primary navigation.
However, it renders above the site-header instead of in the menu location dictated in the code.
Here is the code I currently have:
function wp_multisite_nav_menu() {
global $blog_id;
}
if ( ! is_multisite() || 2 == $blog_id ) {
switch_to_blog( 1 );
wp_nav_menu( array(
'menu' => 2,
'fallback_cb' => false,
'menu_class' => 'genesis-nav-menu',
'theme_location' => 'Primary Navigation Menu',
));
restore_current_blog();
}
I was expecting the menu to be placed in the 'Primary Navigation Menu' location.
What have I missed?
Any clarity is appreciated.
UPDATE
I managed to figure it out for my primary and secondary menus however how do get the site title to change to the main site title and hyperlink?
Here is the code I currently have minus the site title switch
//*Multisite global menus
//*Primary global menu
add_action('genesis_after_header', 'primary_menu_switch');
function primary_menu_switch() {
global $blog_id;
if ( ! is_multisite() || 2 == $blog_id ) {
switch_to_blog( 1 );
wp_nav_menu( array(
'menu' => 2,
'fallback_cb' => false,
'menu_class' => 'genesis-nav-menu',
'theme_location' => 'primary'
) );
restore_current_blog();
}
}
//*Secondary global menu
add_action('genesis_header_right', 'secondary_menu_switch');
function secondary_menu_switch() {
global $blog_id;
if ( ! is_multisite() || 2 == $blog_id ) {
switch_to_blog( 1 );
wp_nav_menu( array(
'menu' => 17,
'fallback_cb' => false,
'menu_class' => 'genesis-nav-menu menu-primary responsive-menu',
'theme_location' => 'primary'
));
restore_current_blog();
}
}
//*Use main site title
function site_title_switch() {
global $blog_id;
if ( ! is_multisite() || 2 == $blog_id ) {
switch_to_blog( 1 );
restore_current_blog();
}
}
I am a complete novice so please excuse the hack job.
Your insights are appreciated.
This is an answer to the updated question, not the one in the title.
This should do the trick, if you put it in a network activated plugin. Read the comments to see what it does exactly. It might not work depending on how your theme is made. I made it for the Twenty Eleven theme.
Keep in mind that it will change the home URL everywhere where it is called with a path '/', not only in the header.
add_filter( 'option_blogname', 'function_to_filter_the_blogname' );
// Changes the blog name of all sites that are not the main one to the name of the main one, only outside of the admin panel
function function_to_filter_the_blogname( $name ) {
$main_site_id = get_main_site_id();
if ( get_current_blog_id() != $main_site_id && ! is_admin() ) {
return get_blog_option( $main_site_id, 'blogname' );
}
return $name;
}
add_filter( 'home_url', 'function_to_filter_the_home_url', 10, 4 );
// Changes the home URL of all sites that are not the main one to the home URL of the main one, only outside of the admin panel and only when the path is '/'
function function_to_filter_the_home_url( $url, $path, $orig_scheme, $blog_id ) {
$main_site_id = get_main_site_id();
if ( $blog_id != $main_site_id && ! is_admin() && '/' == $path ) {
return get_blog_option( $main_site_id, 'home' );
}
return $url;
}

Cakephp 3 - Remove empty post from pagination

I'm working on multi language website.
In the English version of the website all works properly, because I entered translations.
$blogPosts = $this->BlogPosts->find('all')->where(['BlogPosts.active' => 1]);
$this->set('blogPosts',$this->paginate($blogPosts));
If I changed the language of website I would like to remove all the posts whose translation of the title is not entered.
I tried this, but it does not work:
$blogPosts = $this->BlogPosts->find('all')->where(['BlogPosts.active' => 1,'BlogPosts.title IS NOT' => null]);
$this->set('blogPosts',$this->paginate($blogPosts));
Still printed posts without titles.
How to solve this problem?
Try this conditions:
public function index()
{
$this->paginate['conditions'] = ['BlogPosts.active' => true , 'BlogPosts.title IS NOT' => null, 'BlogPosts.title !=' => ' '];
$this->paginate['order'] = ['BlogPosts.id' => 'desc'];
$this->paginate['limit'] = 4;
$blogPosts = $this->paginate($this->BlogPosts);
$this->set(compact('blogPosts'));
$this->set('_serialize', ['blogPosts']);
}
Query:
SELECT *
FROM blogPosts BlogPosts
WHERE (
BlogPosts.active = 1
AND BlogPosts.title IS NOT NULL
AND BlogPosts.title != ''
)
ORDER BY BlogPosts.id desc
LIMIT 4 OFFSET 0
I think faced with simmilar issue before. The pagination didn't worked as I excepted when I set order, limit together with custom where condition.
Try this:
$this->paginate['order'] = ['BlogPosts.id' => 'desc'];
$this->paginate['limit'] = 4;
$query = $this->BlogPost->find()
->select(['id', 'title', 'active'])
->where(['BlogPost.active' => true, 'BlogPost.title IS NOT' => null, 'BlogPost.id !=' => ''])
$data = $this->paginate($query);
$this->set('BlogPost', $data);

Infinitescroll to finish after a certain number of posts

I am using Paul Irish's infinitescroll with masonry js on a wordpress site. It is a site with a lot of content. I want infintescroll to stop adding new content when it reaches post number 40 and to give the "No additional items" message at that point. I tried to customize the wordpress loop to only return 40 posts but that did not seem to work.
I thought that maybe one of the options in infinitecroll might do the trick but the infintescroll documentation is very sparse. For example, there is an infinitescroll option in the "loading" init section called "finished: undefined" Is it possible to change that parameter to stop the scrolling after a certain number of content items?
Is there some other obvious way to control when infinitescroll stops loading new content?
Any assistance would be greatly appreciated.
In the Administration -> Settings -> Reading you can set Blog pages show at most to 40.
With code:
Two ways I've done Masonry by numbers like your question I've had success with the following:
limit posts_per_page in your query arguments
$args = array(
'posts_per_page' => 40,
'offset' => 5,
'orderby' => 'post_date',
'order' => 'DESC',
'exclude' => 'none',
'post_type' => 'post',
'post_status' => 'publish',
'suppress_filters' => true
);
$posts = new WP_Query( $args );
if ( $posts -> have_posts()) {
while ( $posts -> have_posts() ) : $posts->the_post(); {
//do stuff with the posts returned here
}
}
or by incrementing:
$counts = 0 ;
$posts = new WP_Query( $args );
if ( $posts -> have_posts()) {
while ( $posts -> have_posts() ) : $posts->the_post(); {
//do stuff with the posts returned here
$counts = ++;
if($counts == 40) { return }
}
}

How to link custom results in Drupal

My first time here an a newbee in Drupal and programming .
So I have a problem I need to some help with.
function query_results($searchstring, $datefrom) {
$tidresult = db_query("SELECT tid FROM {term_data} WHERE LOWER(name) = '%s'", strtolower($searchstring));
$resultarray = array();
while ($obj = db_fetch_object($tidresult)) {
$tid = $obj->tid;
$noderesults = db_query("SELECT n.nid, n.title FROM {node} n
INNER JOIN {term_node} tn ON tn.nid = n.nid
WHERE tn.tid='%s'", $tid);
while ($nodeobj = db_fetch_object($noderesults)) {
$resultarray[$nodeobj->nid] = $nodeobj->title;
}
}
$header = array(
array('data' => 'Nr.'),
array('data' => 'Name'),
);
$rows = array();
$i = 0;
foreach($resultarray as $nid => $title) {
$i++;
$rows[] = array('data' =>
array(
$i,
$title,
),
);
}
$output = theme('table', $header, $rows);
print theme("page", $output);
}
It's driving me crazy , i dint put all of the search code but it takes taxonomy tags from the database ( you type in textbox that has autocomplete, '$searchstring' ) and date ( you choose a time line like one day , yesterday ect. , '$datefrom').
For example reasons lets say it looks like this example when you click search.
I can't post my one pictures but I just gives me the titles ( like above but the are not listed) that I cannot click to lead me to the content.
But I wont it to look like result that is like content ( story ) so you have a clickable Title and some description , like this click to see example
where it says lorem ipsum and that text belowe.
If it is hard to make like in the picture can someone show me just how to make( like in the first picture) the results that are non clickable titles into clickable links that lead me to the content.
To get linked titles you need to use the l() function.
looking at the code you provided, I am not entirely sure how you are getting any results since you save the titles in $resultArray but use $rows when rendering the table.
Unless, $rows is specified somewhere else, $resultarray[$nodeobj->nid] = $nodeobj->title; should become $rows[$nodeobj->nid] = $nodeobj->title;
To make it match your table header, you need to add another 'cell' for the number column
$rows[$nodeobj->nid] = array(
$count++,
l($nodeobj->title, 'node/'.$nodeobj->nid)
);
To provide the excerpt too, you need to join the node_revisions table and get either the body or teaser column, then add it to your rows like this:
$rows[$nodeobj->nid] = array(
$count++,
'<h2>'. l($nodeobj->title, 'node/'.$nodeobj->nid) .'</h2>'. $nodeobj->teaser
);
assuming you get the teaser.
EDIT
the previous answer still holds. You can also simplify the code a bit by processing $rows straight in the $noderesults loop.
function query_results($searchstring, $datefrom) {
$tidresult = db_query("SELECT tid FROM {term_data} WHERE LOWER(name) = '%s'", strtolower($searchstring));
$rows = array();
$count = 0;
while ($obj = db_fetch_object($tidresult)) {
$tid = $obj->tid;
$noderesults = db_query("SELECT n.nid, n.title FROM {node} n "
."INNER JOIN {term_node} tn ON tn.nid = n.nid "
."WHERE tn.tid='%s'", $tid);
while ($nodeobj = db_fetch_object($noderesults)) {
$rows[] = array(
++$count,
l($nodeobj->title, 'node/'. $nodeobj->title)
);
}
}
$header = array(
array('data' => 'Nr.'),
array('data' => 'Name'),
);
$output = theme('table', $header, $rows);
print theme("page", $output);
}
-OR-
move it all in one query (note: I did not get a chance to test this, but I usually get it right the first time):
function query_results($searchstring, $datefrom) {
$rows = array();
$count = 0;
$results = db_query("SELECT n.nid, n.title
FROM {node} n
INNER JOIN {term_node} tn ON tn.nid = n.nid
WHERE tn.tid IN (SELECT tid FROM {term_data} WHERE LOWER(name) = '%s')", strtolower($searchstring));
while ($nodeobj = db_fetch_object($results)) {
$rows[] = array(
++$count,
l($nodeobj->title, 'node/'. $nodeobj->title)
);
}
$header = array(
array('data' => 'Nr.'),
array('data' => 'Name'),
);
$output = theme('table', $header, $rows);
print theme("page", $output);
}

How to add custom blocks in drupal?

I have a simple module which will return a form , but now i have added this to a menu like
admin/settings/
But i want this form in another page ,so i added a hook_block() , my module showed up in the blocks page and i added it to be seen by all in all pages in content area but i dont get that form ? where did i go wrong ? I am new to drupal any help plz
function emp_form_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('New Block');
$blocks[0]['cache'] = BLOCK_NO_CACHE;
return $blocks;
}
}
i am using drupal 6
You should also implement the view op, like this:
case 'view':
return array(
'subject' => t('My awesome form'),
'content' => drupal_get_form('my_awesome_form'),
);
break;

Resources