Commits

Anonymous committed 5fe318e

Transition to wordpress-style theme integration, reduce logic in view

Comments (0)

Files changed (7)

admin/application/config/autoload.php

 |	$autoload['libraries'] = array('database', 'session', 'xmlrpc');
 */
 
-$autoload['libraries'] = array('Template', 'session', 'mantis_auth');
+$autoload['libraries'] = array('Template', 'session', 'mantis_auth', 'phphgadmin', 'form_validation');
 
 
 /*
 |	$autoload['helper'] = array('url', 'file');
 */
 
-$autoload['helper'] = array('language', 'url', 'hg_directory');
+$autoload['helper'] = array('language', 'form', 'url');
 
 
 /*

admin/application/controllers/hgdir.php

 	function HgDir()
 	{
 		parent::Private_Controller();
-		$this->load->helper(array('form', 'url'));
-		$this->load->library('form_validation');
-		$this->load->library('phphgadmin');
+		$this->load->helper('hg_directory');
 	}
 	
 	function index()
 		
 		$this->session->set_flashdata('ofl_hgwebconf', $this->ofl_lock_hgwebconf);
 
-		$this->template->build('repo_directory', array('lsdir'=>$lsdir));
+		$this->template->build('repo_directory');
 	}
 	
 	function create()

admin/application/controllers/hgrepo.php

 	function HgRepo()
 	{
 		parent::Private_Controller();
-		$this->load->library('phphgadmin');
+		$this->load->helper('hg_repo');
 		$this->load->library('iniparser');
 	}
 	
 		}
 		
 		$this->template->title($repositoryName, 'Mercurial Repository Editor');
-		$this->template->build('repo_browse', array('r_name' => $repositoryName));
+		$this->template->build('repo_browse');
 	}
 	
 	function manage()
 		
 		$this->session->set_flashdata('ofl_hgrc_' . $repositoryName, $ofl_lock_hgrc);
 		$this->template->build('repository', 
-			array('hgrc' => serialize($hgrc), 'r_name' => $repositoryName, 
+			array(
 					'hgrc_bools_arr'=>$this->config->item('hgrc_bools_arr'),
 					'hgrc_form' => $hgrc_form
 			));	

admin/application/helpers/hg_directory_helper.php

 <?php 
-
+// testing stuff here
+$_lsdir;
+$_lsdir_iter;
+$_lsdir_iter_count;
 function have_repos()
 {
+	global $_lsdir, $_lsdir_iter, $_lsdir_iter_count;
+	
+	if($_lsdir == null)
+	{
+		$ci =& get_instance();
+		$_lsdir = array_values($ci->phphgadmin->lsdir());
+		$_lsdir_iter_count = 0;
+	}
+	
+	$has_next = ($_lsdir_iter_count < count($_lsdir));
+	
+	if($has_next)
+	{
+		$_lsdir_iter = $_lsdir[$_lsdir_iter_count];
+		$_lsdir_iter_count += 1;
+	}
+	else
+	{
+		// reset
+		$_lsdir_iter_count = 0;
+	}
+	
+	return $has_next;
 }
 
-function the_title()
+function repo_name()
 {
-	
+	global $_lsdir_iter;
+	return $_lsdir_iter['name'];
 }
+
+function repo_status()
+{
+	global $_lsdir_iter;
+	return $_lsdir_iter['status'];
+}

admin/application/helpers/hg_repo_helper.php

+<?php 
+
+$_the_name;
+$_hgrc_ini64;
+$_sections;
+$_section_iter_keys;
+$_section_iter_count;
+$_section_hashname;
+$_items;
+$_item_iter_keys;
+$_item_iter_count;
+$_item_hashname;
+function the_name()
+{
+	global $_the_name;
+	
+	if($_the_name == null)
+	{
+		$ci =& get_instance();
+		$_the_name = rawurldecode($ci->uri->segment(3, 0));
+	}
+	return $_the_name;
+}
+
+function has_sections()
+{
+	global $_hgrc_ini64, $_sections, $_section_iter_keys, $_section_iter_count, $_section_hashname;
+	global $_items, $_item_iter_keys, $_item_iter_count;
+	if($_hgrc_ini64 == null)
+	{
+		$ci =& get_instance();
+		$_hgrc_ini64 = $ci->phphgadmin->stat_repository(the_name());
+		$_sections = $_hgrc_ini64->get();
+		$_section_iter_keys = array_keys($_sections);
+		$_section_iter_count = 0;
+		$_item_iter_count = 0;
+	}
+	
+	$has_section = ($_section_iter_count < count($_section_iter_keys));
+	if($has_section)
+	{
+		$_section_hashname = $_section_iter_keys[$_section_iter_count];
+		$_items = $_sections[$_section_hashname];
+		$_item_iter_keys = array_keys($_items);
+		$_section_iter_count += 1;
+	}
+	else
+	{
+		$_section_iter_count = 0;
+	}
+	
+	return $has_section;
+}
+
+function section_name()
+{
+	global $_section_hashname;
+	return base64_decode($_section_hashname);
+}
+
+function has_items()
+{
+	global $_items, $_item_iter_keys, $_item_iter_count, $_item_hashname;
+	
+	$has_items = ($_item_iter_count < count($_item_iter_keys));
+	if($has_items)
+	{
+		$_item_hashname = $_item_iter_keys[$_item_iter_count];
+		$_item_iter_count += 1;
+	}
+	else
+	{
+		$_item_iter_count = 0;
+	}
+	
+	return $has_items;
+}
+
+function item_name()
+{
+	global $_item_hashname;
+	return base64_decode($_item_hashname);
+}
+
+function item_current_value()
+{
+	global $_items, $_item_hashname;
+	return $_items[$_item_hashname];
+}

admin/application/views/repo_directory.php

         <th><?php echo lang('hgphp_title_status'); ?></th> 
         <th></th> 
     </tr> 
-<?php $parity=0; if(is_array($lsdir)): foreach($lsdir as $repo): ?>
+<?php $parity=0; while(have_repos()): ?>
 	<tr class="parity<?php echo $parity; $parity=($parity+1)%2;?>">
 	  <td>
 		<input type="checkbox" disabled="disabled"/>
 	  </td>
 	  <td>
-	    <a href="<?php echo site_url('hgrepo/manage/'.rawurlencode($repo['name'])); ?>"><?php echo htmlentities($repo['name']); ?></a>
+	    <a href="<?php echo site_url('hgrepo/manage/'.repo_name()); ?>"><?php echo htmlentities(repo_name()); ?></a>
 	  </td>
 	  <td>
-	    <?php if($repo['status'] == HGPHP_REPO_STATUS_ENABLED): echo lang('hgphp_repostatus_enabled'); ?>
-	    <?php elseif($repo['status'] == HGPHP_REPO_STATUS_DISABLED): echo lang('hgphp_repostatus_disabled');?>
-	    <?php elseif($repo['status'] == HGPHP_REPO_STATUS_MISSING): echo lang('hgphp_repostatus_missing');?>
+	    <?php if(repo_status() == HGPHP_REPO_STATUS_ENABLED): echo lang('hgphp_repostatus_enabled'); ?>
+	    <?php elseif(repo_status() == HGPHP_REPO_STATUS_DISABLED): echo lang('hgphp_repostatus_disabled');?>
+	    <?php elseif(repo_status() == HGPHP_REPO_STATUS_MISSING): echo lang('hgphp_repostatus_missing');?>
 	    <?php endif; ?>
 	  </td>
 	  <td>
-	  	<?php if($repo['status'] == HGPHP_REPO_STATUS_ENABLED): ?>
-	  	<a href="<?php echo site_url('hgrepo/browse/'.rawurlencode($repo['name'])); ?>" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php echo lang('hgphp_action_browse'); ?></a>
+	  	<?php if(repo_status() == HGPHP_REPO_STATUS_ENABLED): ?>
+	  	<a href="<?php echo site_url('hgrepo/browse/'.repo_name()); ?>" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php echo lang('hgphp_action_browse'); ?></a>
 	  	<?php endif; ?>
 	  </td>
 	</tr>
-<?php endforeach; endif; ?>
+<?php endwhile; ?>
 	<tr>
 	  <td colspan="4">
 		<p><a href="#" id="dialog_link2_create" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon ui-icon-newwin"></span><?php echo lang('hgphp_action_create'); ?></a>
 						<br />
 						<select style="width:100%" name="form_delete_name" id="form_delete_name">
 							<option selected="selected" value=""></option>
-							<?php if(isset($lsdir)): foreach($lsdir as $r_id => $repo): ?>
-							<option value="<?php echo $r_id; ?>"><?php echo $repo['name']; ?></option>
-							<?php endforeach; endif; ?>
+							<?php while(have_repos()): ?>
+							<option value="<?php echo repo_name(); ?>"><?php echo repo_name(); ?></option>
+							<?php endwhile; ?>
 						</select>
 						<br />
 					</td>

admin/application/views/repository.php

 	<tr>
 	  <td colspan="3" align="right">
 	  	<p>
-	  	<a href="<?php echo site_url('hgrepo/browse/'.rawurlencode($r_name)); ?>" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon ui-icon-newwin"></span><?php echo lang('hgphp_action_browse'); ?></a>
+	  	<a href="<?php echo site_url('hgrepo/browse/'.the_name()); ?>" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon ui-icon-newwin"></span><?php echo lang('hgphp_action_browse'); ?></a>
 	  	<a href="<?php echo site_url('hgdir'); ?>" id="dialog_link_cancel" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hgphp_action_cancel'); ?></a>
-	  	<a href="<?php echo site_url('hgrepo/manage/'.rawurlencode($r_name)); ?>" id="dialog_link_reset" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hgphp_action_reset'); ?></a>
+	  	<a href="<?php echo site_url('hgrepo/manage/'.the_name()); ?>" id="dialog_link_reset" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hgphp_action_reset'); ?></a>
 	  	<a href="#" id="dialog_link_save" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hgphp_action_save'); ?></a>
 	  	</p>
 	  </td>
-	</tr>
-	<?php 
-
-    ?>
-    	
-    <?php if(isset($hgrc) && $hgrc!== FALSE):
-    $hgrc = unserialize($hgrc);
+	</tr>    	
+    <?php 
     
-        function restore_value($hgrc, $hgrc_form, $section_name, $key_name)
+        function restore_value($current_value, $hgrc_form, $section_name, $key_name)
     	{
     		if(!empty($hgrc_form) && isset($hgrc_form[$section_name]) && isset($hgrc_form[$section_name][$key_name]))
     		{
     			return $hgrc_form[$section_name][$key_name];
     		}
-    		return $hgrc->get($key_name, $section_name);
+    		return $current_value;
     	}
     
     ?> 
     
-    <?php foreach($hgrc->get() as $hashsection_name => $section): $section_name = base64_decode($hashsection_name);?>
+      <?php while(has_sections()): ?>
     <tr> 
-        <th><?php echo htmlentities($section_name) ?></th> 
+        <th><?php echo htmlentities(section_name()) ?></th> 
         <th></th> 
-        <th><a href='<?php echo lang('hgphp_doclink_hgrc') . $section_name ?>' target="_blank"><?php echo lang('hgphp_title_help'); ?></a></th>  
+        <th><a href='<?php echo lang('hgphp_doclink_hgrc') . section_name() ?>' target="_blank"><?php echo lang('hgphp_title_help'); ?></a></th>  
     </tr> 
     
-    <?php $parity=0; foreach($section as $hashkey => $value): $key = base64_decode($hashkey); ?>
+    <?php $parity=0; while(has_items()): ?>
     <tr class="parity<?php echo $parity; $parity=($parity+1)%2;?>">
-      <td style="vertical-align:middle"><?php echo htmlentities($key); ?></td>
+      <td style="vertical-align:middle"><?php echo htmlentities(item_name()); ?></td>
       <td style="vertical-align:middle;text-align:right">
       <nobr>
-      <?php if(isset($hgrc_bools_arr) && isset($hgrc_bools_arr[$section_name]) && in_array($key, $hgrc_bools_arr[$section_name])):?>
-      	<select name="hgrc[<?php echo $section_name ?>][<?php echo $key; ?>]">
-      		<option value="false" <?php if(restore_value($hgrc, $hgrc_form, $section_name, $key) === 'false'){echo 'selected="selected"';} ?>>false</option>
-      		<option value="true" <?php if(restore_value($hgrc, $hgrc_form, $section_name, $key) === 'true'){echo 'selected="selected"';} ?>>true</option>
+      <?php if(isset($hgrc_bools_arr) && isset($hgrc_bools_arr[section_name()]) && in_array(item_name(), $hgrc_bools_arr[section_name()])):?>
+      	<select name="hgrc[<?php echo section_name() ?>][<?php echo item_name(); ?>]">
+      		<option value="false" <?php if(restore_value(item_current_value(), $hgrc_form, section_name(), item_name()) === 'false'){echo 'selected="selected"';} ?>>false</option>
+      		<option value="true" <?php if(restore_value(item_current_value(), $hgrc_form, section_name(), item_name()) === 'true'){echo 'selected="selected"';} ?>>true</option>
       	</select>
       <?php else: ?>
-        <input type="text" name="hgrc[<?php echo $section_name ?>][<?php echo $key; ?>]" value="<?php echo restore_value($hgrc, $hgrc_form, $section_name, $key); ?>" style="width:70%"/>
+        <input type="text" name="hgrc[<?php echo section_name() ?>][<?php echo item_name(); ?>]" value="<?php echo restore_value(item_current_value(), $hgrc_form, section_name(), item_name()); ?>" style="width:70%"/>
       <?php endif; ?> 
-      	<?php if(lang('hgphp_tooltip_hgrc_' . $section_name . '_' . $key) != FALSE):?>
-      	<a href="#" title="<?php echo htmlentities(lang('hgphp_tooltip_hgrc_' . $section_name . '_' . $key)); ?>" class="ui-state-default ui-corner-all">&nbsp;&nbsp;?&nbsp;&nbsp;</a>
+      	<?php if(lang('hgphp_tooltip_hgrc_' . section_name() . '_' . item_name()) != FALSE):?>
+      	<a href="#" title="<?php echo htmlentities(lang('hgphp_tooltip_hgrc_' . section_name() . '_' . item_name())); ?>" class="ui-state-default ui-corner-all">&nbsp;&nbsp;?&nbsp;&nbsp;</a>
       	<?php endif; ?>
       </nobr>
       </td>
-      <td style="vertical-align:middle"><?php echo htmlentities($value); ?></td>
+      <td style="vertical-align:middle"><?php echo htmlentities(item_current_value()); ?></td>
     </tr>
-    <?php endforeach; ?>
-    
-    <?php endforeach; endif; ?>
+    <?php endwhile; endwhile; ?>
+ 
 	<tr>
 	  <td colspan="3" align="right">
 	  	<p>
-	  	<a href="<?php echo site_url('hgrepo/browse/'.rawurlencode($r_name)); ?>" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon ui-icon-newwin"></span><?php echo lang('hgphp_action_browse'); ?></a>
+	  	<a href="<?php echo site_url('hgrepo/browse/'.the_name()); ?>" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon ui-icon-newwin"></span><?php echo lang('hgphp_action_browse'); ?></a>
 	  	<a href="<?php echo site_url('hgdir'); ?>" id="dialog_link2_cancel" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hgphp_action_cancel'); ?></a>
-	  	<a href="<?php echo site_url('hgrepo/manage/'.rawurlencode($r_name)); ?>" id="dialog_link2_reset" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hgphp_action_reset'); ?></a>
+	  	<a href="<?php echo site_url('hgrepo/manage/'.the_name()); ?>" id="dialog_link2_reset" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hgphp_action_reset'); ?></a>
 	  	<a href="#" id="dialog_link2_save" class="ui-state-default ui-corner-all dialog_link"><span class="ui-icon"></span><?php print lang('hgphp_action_save'); ?></a>
 	  	</p>
 	  </td>