• Subcategories don’t show colors into calendar table.
    So I have add transparency option to category’s definition.

    File: em-category.php

    var $transparent;
    ...
    ...
    function is_transparent_bg(){
    		if( empty($this->transparent) ){
    			global $wpdb;
                            $transparent = $wpdb->get_var('SELECT meta_value FROM '.EM_META_TABLE." WHERE object_id='{$this->term_id}' AND meta_key='category_transparent_bgcolor' LIMIT 1");
    			$this->transparent = ($transparent == 'on');
    		}
    		return $this->transparent;
    	}

    File: em-categories-taxonomy.php

    function form($tag){
                    $category_transparent_bgcolor = false;
    		$category_color = '#FFFFFF';
    		$category_image = '';
    		if( $tag != EM_TAXONOMY_CATEGORY ){ //not an add new tag form
    			$EM_Category = new EM_Category($tag);
    			$category_color = $EM_Category->get_color();
    			$category_image = $EM_Category->get_image_url();
    			$category_image_id = $EM_Category->get_image_id();
                            $category_transparent_bgcolor = $EM_Category->is_transparent_bg();
    		}
    		?>
    	    <tr class="form-field">
    	        <th scope="row" valign="top"><label for="category-bgcolor">Calendar Color</label></th>
    	        <td>
                        <br/>
                        <input type="checkbox" id="category_transparent_bgcolor" name="category_transparent_bgcolor" <?php echo $category_transparent_bgcolor ? 'checked="checked"':''; ?>/> Check to set transparent background color.
                        <br/><br/>
    	            <input type="text" name="category_bgcolor" id="category-bgcolor" class="colorwell" value="<?php echo esc_attr($category_color); ?>" style="width:100px;"/><br />
    	            <p class="description"><?php echo sprintf(__('Choose a color for your category. You can access this using the %s placeholder.','dbem'),'<code>#_CATEGORYCOLOR</code>'); ?></p>
    	            <div id="picker" style="position:absolute; display:none; background:#DEDEDE"></div>
    	        </td>
    	    </tr>
    	    <tr class="form-field">
    	        <th scope="row" valign="top"><label for="category-image">Image</label></th>
    	        <td>
    	        	<?php if( !empty($category_image) ): ?>
    	        	<p><img src="<?php echo $category_image; ?>" /></p>
    	        	<?php endif; ?>
    	            <input type="text" name="category_image" id="category-image" value="<?php echo esc_attr($category_image); ?>" style="width:300px;" />
    	            <input type="hidden" name="category_image_id" id="category-image-id" value="<?php echo esc_attr($category_image); ?>" />
    	            <input id="upload_image_button" type="button" value="<?php _e('Choose/Upload Image','dbem'); ?>" class="button-secondary" style="width:auto;" /><br />
    	            <p class="description"><?php echo sprintf(__('Choose an image for your category, which can be displayed using the %s placeholder.','dbem'),'<code>#_CATEGORYIMAGE</code>'); ?></p>
    	        </td>
    	    </tr>
    	    <?php
    	}
    
    ...
    ...
    
    function save($term_id, $tt_id){
    		global $wpdb;
    	    if (!$term_id) return;
                    if( !empty($_POST['category_transparent_bgcolor']) ){
                            $prev_settings = $wpdb->get_results('SELECT meta_value FROM '.EM_META_TABLE." WHERE object_id='{$term_id}' AND meta_key='category_transparent_bgcolor'");
    			if( count($prev_settings) > 0 ){
    				$wpdb->update(EM_META_TABLE, array('object_id'=>$term_id,'meta_value'=>$_POST['category_transparent_bgcolor']), array('object_id'=>$term_id,'meta_key'=>'category_transparent_bgcolor'));
    			}else{
    				$wpdb->insert(EM_META_TABLE, array('object_id'=>$term_id,'meta_key'=>'category_transparent_bgcolor','meta_value'=>$_POST['category_transparent_bgcolor']));
    			}
                    }
    ...
    ...
    }

    You can test effects modifying

    File: templates/templates/calendar-small.php

    <table class="em-calendar">
    	<thead>
    		<tr>
    			<td><a class="em-calnav em-calnav-prev" href="<?php echo $calendar['links']['previous_url']; ?>" rel="nofollow"><<</a></td>
    			<td class="month_name" colspan="5"><?php echo ucfirst(date_i18n(get_option('dbem_small_calendar_month_format'), $calendar['month_start'])); ?></td>
    			<td><a class="em-calnav em-calnav-next" href="<?php echo $calendar['links']['next_url']; ?>" rel="nofollow">>></a></td>
    		</tr>
    	</thead>
    	<tbody>
    		<tr class="days-names">
    			<td><?php echo implode('</td><td>',$calendar['row_headers']); ?></td>
    		</tr>
    		<tr>
    			<?php
    			$cal_count = count($calendar['cells']);
    			$col_count = $count = 1; //this counts collumns in the $calendar_array['cells'] array
    			$col_max = count($calendar['row_headers']); //each time this collumn number is reached, we create a new collumn, the number of cells should divide evenly by the number of row_headers
    			foreach($calendar['cells'] as $date => $cell_data ){
    				$eventful = ( !empty($cell_data['events']) && count($cell_data['events']) > 0 );
    				$class = ( !empty($cell_data['events']) && count($cell_data['events']) > 0 ) ? 'eventful':'eventless';
    				if(!empty($cell_data['type'])){
    					$class .= "-".$cell_data['type'];
    				}
    				?>
    				<!-- <?php print_r($cell_data); ?>-->
    				<td class="<?php echo $class; ?>" style="background-color:<?php
    						if ( ! empty($cell_data['events']) ){
    							foreach( $cell_data['events'] as $EM_Event ){
                                                                try{
                                                                    $categories = $EM_Event->get_categories()->categories;
                                                                    foreach( $categories as $category){
                                                                        if( $category->is_transparent_bg()==false && $category->get_color()!='#FFFFFF' ) echo $category->get_color();
                                                                    }
                                                                } catch (Exception $e){
                                                                    echo '<!--Caught exception: ',  $e->getMessage(), "-->\n";
                                                                }
    							}
    						}
    					?>;">
    					<?php if( !empty($cell_data['events']) && count($cell_data['events']) > 0 ): ?>
    					<a href="<?php echo esc_url($cell_data['link']); ?>" title="<?php echo esc_attr($cell_data['link_title']); ?>"><?php echo date('j',$cell_data['date']); ?></a>
    					<?php else:?>
    					<?php echo date('j',$cell_data['date']); ?>
    					<?php endif; ?>
    				</td>
    				<?php
    				//create a new row once we reach the end of a table collumn
    				$col_count= ($col_count == $col_max ) ? 1 : $col_count+1;
    				echo ($col_count == 1 && $count < $cal_count) ? '</tr><tr>':'';
    				$count ++;
    			}
    			?>
    		</tr>
    	</tbody>
    </table>

    http://wordpress.org/extend/plugins/events-manager/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    hi,

    could it be because of your modification? what’s happen when you try the default calendar without the modification?

    Thread Starter nicola.boldrin

    (@nicolaboldrin)

    If I set categories’ tree like :

    Events
    +– Public Events (bgcolor: #AAAAAA)
    +– Private Events (bgcolor: #666666)

    I can’t see the colors for sub-categories (Public Events, Private Events) because category Events overwrite sub-categories’ colors with #FFFFFF.

    Adding transparency option I can set Events category’s bgcolor to transparent and it doesn’t overwrite sub-categories’ bgcolors.

    Plugin Author Marcus (aka @msykes)

    (@netweblogic)

    I think you can probably do all this just overriding the small-calendar.php file rather than hacking the plugin. We don’t define any colors by default to begin with in the calendar widget.

    Thread Starter nicola.boldrin

    (@nicolaboldrin)

    You’re right but I wanted to respect the object-oriented programming by adding the transparent property. I think that property simplifies color management.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Category colors’ is closed to new replies.