Hide main-component class in homepage - php

I have a template that has the feature to hide front-page component.
Unfortunately setting this feature to "hide" does hide the component but not the wrapper that surrounds it so, i need help to hide it manually in the home page only with id '101'.
The code that uses that feature is below:
function setMainContent() {
global $mainbody_block, $editmode, $side_block, $subnav, $active, $splitmenu_col, $leftcolumn_width, $rightcolumn_width, $mainmod2_width, $frontpage_component, $mainmod3_width;
$row = 'section-row3';
$cases = array(
'case3' => modulesClasses('case3'),
'case4' => modulesClasses('case4')
);
$this->maincontent = '<div id="section-row3" class="section-row"><div id="section-row3-inner">
<div id="main-body-surround" class="spacer">';
function mainbody($t, $c) {
global $mainbody_block, $leftcolumn_width, $mainmod2_width, $editmode, $frontpage_component, $mainmod3_width, $leftcolumn_width, $splitmenu_col, $subnav, $active;
$tmp = "";
$tmp .= '<div id="main-body" class="spacing">
<div class="module-'.$mainbody_block.'">';
$main = '
<div id="main-content">';
Is the best way to do this with php or css?

Related

Adding activity in a section in Moodle - not saving the section

So I've been looking for 2 days into this problem, I can't find either where the code exists, or how to edit/fix it.
What is happening is that when you click "Add Activity or Resource" while editing a course, it adds the activity or resource, but always into section 0. It doesn't save which section I've clicked from, and when the redirect to course/modedit.php happens, the URL shows section=0, no matter if from section 1 or 10. Further to this, moving the activity into other sections also does not save - it simply re-orders the activity to the last one in section 0.
I am unsure as to which code is causing this issue. I need some help or guidance on where to look to begin debugging and fixing this.
I also can't be sure when this issue first appeared, as I have modified a few files in between while developing this site. The only one that may be relevant (from what I can surmise), and may help give some clue for anyone better informed than I is the following:
protected function section_header($section, $course, $onsectionpage, $sectionreturn=null) {
global $PAGE;
$o = '';
$currenttext = '';
$sectionstyle = '';
if ($section->section != 0) {
// Only in the non-general sections.
if (!$section->visible) {
$sectionstyle = ' hidden';
} else if (course_get_format($course)->is_section_current($section)) {
$sectionstyle = ' current';
}
}
$o.= html_writer::start_tag('li', array('class' => 'section main'.$sectionstyle));
// Create a span that contains the section title to be used to create the keyboard section move menu.
$o .= html_writer::tag('span', $this->section_title($section, $course), array('class' => 'hidden sectionname'));
$leftcontent = $this->section_left_content($section, $course, $onsectionpage);
$o.= html_writer::tag('div', $leftcontent, array('class' => 'left side'));
$rightcontent = $this->section_right_content($section, $course, $onsectionpage);
$o.= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
$sectionname = html_writer::tag('span', $this->section_title($section, $course));
$o.= html_writer::start_tag('a', array('href' => '#section-'.$section->section, 'class' => 'title'));
$o.= $this->output->heading($sectionname, 3, 'sectionname' . $classes);
$o.= html_writer::end_tag('a');
$o.= html_writer::start_tag('div', array('id' => 'section-'.$section->section, 'class' => 'content'));
// When not on a section page, we display the section titles except the general section if null
$hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));
// When on a section page, we only display the general section title, if title is not the default one
$hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));
$classes = ' accesshide';
if ($hasnamenotsecpg || $hasnamesecpg) {
$classes = '';
}
$o.= html_writer::start_tag('div', array('class' => 'summary'));
$o.= $this->format_summary_text($section);
$context = context_course::instance($course->id);
$o .= $this->section_availability_message($section, has_capability('moodle/course:viewhiddensections', $context));
return $o;
}
That is my rework of the layout - allowing for a simple Jquery accordian to show/hide the sections. The Jquery is:
$(document).ready(function() {
function close_accordion_section() {
$(".topics .title").removeClass("active");
$(".topics .content").slideUp(300).removeClass("open");
$("#section-0").stop();
}
$(".title").click(function(e) {
// Grab current anchor value
var currentAttrValue = $(this).attr("href");
if($(e.target).is(".active")) {
close_accordion_section();
}else {
close_accordion_section();
// Add active class to section title
$(this).addClass("active");
// Open up the hidden content panel
$(".topics " + currentAttrValue).slideDown(300).addClass("open");
}
e.preventDefault();
});
});
I have edited nothing else in relation to the course page, but that doesn't mean the issue might not be elsewhere.
Sorry for the wall of text, but please could someone help me find why the Activity isn't adding to the right section, nor allowing me to move into the right section afterwards? I'd really appreciate it.

PHP widget use class selector instead of <tag> to build menu

I hope on of you clever chaps might be able to answer this riddle.
I have an excellent widget I am trying to integrate into my site. It creates menus from <H1>, <H2> etc, tags in the document. This is very useful as I can create sub menu navigation for each of my pages by styling the titles.
I am however using a wordpress theme that has extensions added to the editor that style various parts of the pages, including for example titles.
So the output from how it styles the title in HTML output is as follows for example:
<h1 class="grve-element grve-align-left grve-title-striped" style="">Visit</h1>
The PHP script I will load in below, the relevant section it appears to grab tags is:
$tags_to_parse = "<h1>";
Is there a way I can tell this PHP script to grab this particular H1 class?
Cheers,
Tomek
<?php
/*
Plugin Name: Anchors Menu
Description: Check Wordpress static pages content and create a widget menu with links that point to words between the HTML tags you chose.
Author: Gonçalo Rodrigues
Version: 1.2
Author URI: http://www.goncalorodrigues.com
*/
/* Copyright 2010 Gonçalo Rodrigues (email : gonafr [AT] gmail [DOT] com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
//ERROR_REPORTING(E_ALL);
$count = -1;
add_action("init", "anc_insert_init");
add_filter("the_content", "anc_add_link_text");
// renders the list in your theme;
function anc_insert()
{
$tags_to_parse = "<h1>";
$current_page_id = get_the_ID();
$page_data = get_page($current_page_id);
$current_page_name = $page_data->post_name;
$current_page_cat_id = get_cat_ID($current_page_name);
$page_id = get_the_ID();
// if it's blog style page
if (is_home()){
$count = 0;
$content = "";
if ( have_posts() ) : while ( have_posts() ) : the_post();
$id_post = get_the_ID();
$post = get_post($id_post);
$content .= "<a name=\"$count\"></a>";
$content .= $post->post_content;
$count++;
endwhile; else:
//_e("Sorry, no posts matched your criteria.");
endif;
anc_list_menu($content);
//echo "Sorry but this plugin only work on Wordpress pages.";
}
//if it's page style page
else if(is_page()){
$page_id = get_the_ID();
$page_data = get_page( $page_id );
//$title = $page_data->post_title; // Get title
$content = $page_data->post_content;
//if content is empty i will fetch all pages that are child of the current page and get their titles
$fetch_children_pages = true;
if (fetch_children_pages == true && $content==""){
$content = "";
$pages = get_pages('child_of='.$page_id.'&sort_column=post_date&sort_order=desc');
foreach($pages as $page)
{
$content .= "<".$tags_to_parse.">".$page->post_title."</".$tags_to_parse.">";
if(!$content)
continue;
$count++;
}
}
anc_list_menu($content);
}
// if it's single post
else if (is_single()){
$content = "";
$content .= get_the_content();
anc_list_menu($content);
//echo "Sorry but this plugin only work on Wordpress pages.";
}
//if it's a category page
else if(is_category){
//echo $current_page_cat_id;
//echo $current_page_name;
//echo $current_page_id;
$current_cat = get_the_category();
//echo 'teste'.$current_cat[0]->cat_name;
$current_cat_id = get_cat_ID($current_cat[0]->cat_name);
$posts = get_posts('$category_name='.$current_cat[0]->cat_name);
$content = "";
if ( have_posts() ) : while ( have_posts() ) : the_post();
$id_post = get_the_ID();
$post = get_post($id_post);
$content .= "<".$tags_to_parse.">".$post->post_title."</".$tags_to_parse.">";
endwhile; else:
//_e("Sorry, no posts matched your criteria.");
endif;
anc_list_menu($content);
//echo "Sorry but this plugin only work on Wordpress pages.";
}
else {
//_e("Error: This page is not a tradicional Wordpress Page or a Wordpress Blog!");
}
}
// prints the menu with the links to the titles
function anc_list_menu($content){
// list all tags
$foo_tags = anc_get_tags($content);
if($foo_tags[1] != 0){
$foo = -1;
echo "<ul>";
foreach($foo_tags[0] as $key => $val){
$foo++;
echo "<li>".$val."</li>";
}
echo "</ul>";
}else{
//no tags found
//_e("Not found any tag of the type that was selected to be parsed.");
}
}
// retrieve all words between tags
function anc_get_tags($content){
global $tags_to_parse;
$options = get_option("anc_tags");
$tags_to_parse = $options["anc_tags"];
$pattern_search = "/(<".$tags_to_parse.".*>)(.*)(<\/".$tags_to_parse.">)/isxmU";
preg_match_all($pattern_search, $content, $patterns);
$res = array();
array_push($res, $patterns[2]);
array_push($res, count($patterns[2]));
return $res;
}
// insert widget
function anc_insert_init()
{
//register the widget
register_sidebar_widget("Anchors Menu", "anc_widget_insert");
//register the widget control
register_widget_control("Anchors Menu", "anc_widget_insert_control");
}
function anc_widget_insert($args) {
global $title, $tags_to_parse;
extract($args);
//get our options
$options = get_option("anc_title");
$title = $options["anc_title"];
$options = get_option("anc_tags");
$tags_to_parse = $options["anc_tags"];
echo $before_widget;
/*Insert any headers you want in the next line, between "?>" and "<?". Leave blank for no header. */
echo $before_title . $title . $after_title;
anc_insert();
echo $after_widget;
}
// responsable for options in backoffice
function anc_widget_insert_control() {
global $title, $tags_to_parse;
//get saved options if user change things
//handle user input
if (isset($_POST["anc_insert_submit"])){
$foo_title = strip_tags(stripslashes($_POST["anc_title"]));
$foo_tags = strtolower(stripslashes($_POST["anc_tags"]));
$options["anc_title"] = $foo_title;
$options["anc_tags"] = $foo_tags;
update_option("anc_title", $options);
update_option("anc_tags", $options);
}
else {
//default options
$options["anc_title"] = "Menu";
$options["anc_tags"] = "h2";
update_option("anc_title", $options);
update_option("anc_tags", $options);
}
//get our options
$options = get_option("anc_title");
$title = $options["anc_title"];
$options = get_option("anc_tags");
$tags_to_parse = $options["anc_tags"];
//print the widget control
include("anc-insert-widget-control.php");
}
// adds anchors to content tags
function anc_add_link_text($content){
global $tags_to_parse, $count;
$options = get_option("anc_tags");
$tags_to_parse = $options["anc_tags"];
$pattern_search = array();
$pattern_search = "/(<".$tags_to_parse.".*>)(.*)(<\/".$tags_to_parse.">)/isxmU";
return preg_replace_callback($pattern_search, "anc_replacement", $content, -1);
}
// aux funtion to add_link_text
function anc_replacement($matches){
global $tags_to_parse, $count;
$count++;
return "<a name=\"".$count."\"></a>"."<".$tags_to_parse.">".$matches[2]."</".$tags_to_parse.">";
}
?>
Replace your $pattern_search variable with this:
$pattern_search = "/(<h1 .*(".$tags_to_parse.")+ .*>)+(.*)+(<\/h1>)/isxmU";
Now you can pass class to your function:
$tags_to_parse = "grve-element";
Update
$tags_to_parse = "grve-element";
$content = '<h1 class="grve-element grve-align-left grve-title-striped" style="">Visit</h1>sf efew <h1 grve-element>rffef</h1>';
$pattern_search = "/\<h1 .(".$tags_to_parse.")?[^\>]*\>(.*?)\<\/h1\>/";
preg_match_all($pattern_search, $content, $patterns);
print_r($patterns[2]);
Output
Array ( [0] => Visit [1] => rffef )

Showing Category Count on Html Links

I have html links on my wordpress website sidebar and I would like to show the number of posts related to that link.
The posts are placed under custom listing category defined by the following function:
Php:
function va_cat_menu_drop_down( $location = 'menu', $taxonomy ) {
global $va_options;
$key = 'categories_' . $location;
$options = $va_options->$key;
$args['menu_cols'] = ( $location == 'menu' ? 3 : 2 );
$args['menu_depth'] = $options['depth'];
$args['menu_sub_num'] = $options['sub_num'];
$args['cat_parent_count'] = $options['count'];
$args['cat_child_count'] = $options['count'];
$args['cat_hide_empty'] = $options['hide_empty'];
$args['cat_nocatstext'] = true;
$args['cat_order'] = 'ASC';
$args['taxonomy'] = $taxonomy;
$terms_args['pad_counts'] = false;
$terms_args['app_pad_counts'] = true;
return va_categories_list($args, $terms_args);
}
How can I show that number of posts in a particular category next to my Html link as the following does not work (I guess as the listing category is probably custom taxonomy?)
<?php echo get_category(17)->count; ?>
There is a very simple method to do this. Use wp_list_categories and enter the argument 'show_count' => 1
http://codex.wordpress.org/Template_Tags/wp_list_categories

drupal 6 mini pager theming

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

php creating css class dynamically

I have a code which is completed and I want to add another code inside my completed code.
completed code:
function module( $prefix, $comma_seperated_suffixes ) {
foreach( (array)explode( ",", $comma_seperated_suffixes ) as $suffix ) {
$module_name = $prefix.trim($suffix);
if(count(JModuleHelper::getModules($module_name))) {
module_block($module_name);
}
}
}
I moved count(JModuleHelper::getModules($module_name)) to module function, previously it was in module_block
please dont use tovolt class, I mean simple code without php class
Module count block
i am assuming That I am calling this modules module("top-col-", "1,2,3"); then I have three modules called top-col-1, top-col-2, top-col-3
then my count module will look like this:
$TopCol1 = (int)(count(JModuleHelper::getModules($module_name)) > 0);
$TopCol2 = (int)(count(JModuleHelper::getModules($module_name)) > 0);
$TopCol3 = (int)(count(JModuleHelper::getModules($module_name)) > 0);
above code is will just count for active module (the only way to check active module), If a module is active then its var will be 1 .
and now the time to count active module:
$topColCount = $TopCol1 + $TopCol2 + $TopCol3;
if ($topColCount) : $TopColClass = 'count-' . $topColCount;
endif;
I am counting modules case I want to set a CSS class like this count-1, count-2, count-3 to active modules. and I want that class to be used in module_block.
please keep in mind that, above variable is static cause I made them manually. but if I call function then var need to be change with the function value like if user call module("bottom", "1,2,3"); then its count_modules will be $bottom1, $bottom2, $bottom3 and class will be $bottomClass.
I want to generate count_module using the same code module("bottom", "1,2,3");
Thanks #steve for your help
If I am understanding this correctly, this should help.
tovolt class: (note the new function 'prep_modules' added to this class)
<?php
////////////////// BEGIN CLASS tovolt
class tovolt{
function tovolt() {
//// constructor function - used to setup default variable states, etc. - if this is omitted PHP may have a fit ( depending on version and config )
}
public static $TopColClass = 'default-value';
function code_block( $jdoc_name ) {
?>
<div id="top-col" class="<?php echo self::$TopColClass; ?> columns">
<div class="panel">
<jdoc:include type="modules" name="<?php echo $jdoc_name; ?>" style="html5" />
</div>
</div>
<?php
}
function module( $prefix, $comma_seperated_suffixes ) {
foreach( (array)explode( ",", $comma_seperated_suffixes ) as $suffix ) {
$module_name = $prefix.trim($suffix);
self::code_block( $module_name );
}
}
////////////////// BEGIN NEW FUNCTIONS
function prep_modules( $MODULE_LIST ) {
$READY_MODULES = array();
foreach( (array)$MODULE_LIST as $module_name ) {
$MATCHED_MODULES = JModuleHelper::getModules($module_name);
$matched_count = count( $MATCHED_MODULES );
$matched_list = implode( ',', range( 1, $matched_count ) );
$READY_MODULES[$module_name] = array(
'MODULES' => $MATCHED_MODULES,
'count' => $matched_count,
'list' => $matched_list,
);
}
}
////////////////// END NEW FUNCTIONS
}
////////////////// END CLASS tovolt
?>
content page code - near top: (prepare this page's modules)
////////////////// SOMEWHERE BEFORE THE OUTPUT SECTION, LOAD MODULES FOR THIS PAGE
$READY_MODULES = tovolt::prep_modules( 'top', 'side', 'etc' );
content page code - content output area: ( choose the method that best fits your design )
method 1 - output a single section:
////////////////// DOWN IN THE MODULE OUTPUT SECTION - TO OUTPUT A SINGLE SECTION USE:
$section = 'top';
if( #$READY_MODULES[$section]['count'] > 0 ) {
tovolt::$TopColClass = $section; //// if you need to change: $TopColClass
tovolt::module( $section."-col-", $READY_MODULES[$section]['list'] );
}
method 2 - output all in order of loading:
////////////////// DOWN IN THE MODULE OUTPUT SECTION - TO OUTPUT ALL SECTIONS IN LOADED SEQUENCE USE:
foreach( (array)$READY_MODULES as $section=>$THIS_VAR_IS_NOT_DIRECTLY_REFERENCED ) {
if( #$READY_MODULES[$section]['count'] > 0 ) {
tovolt::$TopColClass = $section; //// if you need to change: $TopColClass
tovolt::module( $section."-col-", $READY_MODULES[$section]['list'] );
}
}
method 3 - arbitrary output:
////////////////// DOWN IN THE MODULE OUTPUT SECTION - TO OUTPUT MULTIPLE SECTIONS IN AN ARBITRARY ORDER:
foreach( array( 'side', 'top' ) as $section ) {
if( #$READY_MODULES[$section]['count'] > 0 ) {
tovolt::$TopColClass = $section; //// if you need to change: $TopColClass
tovolt::module( $section."-col-", $READY_MODULES[$section]['list'] );
}
}

Categories