Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Hack to to show only i386 on subcat view pages

  • Loading branch information...
commit dd37c6830271cbffc05a373e7a93ed4b4d31db0b 1 parent 036883c
Robert Wiley authored April 16, 2012

Showing 1 changed file with 187 additions and 135 deletions. Show diff stats Hide diff stats

  1. 322  app/controllers/software_controller.php
322  app/controllers/software_controller.php
@@ -12,142 +12,160 @@ class SoftwareController extends AppController {
12 12
   #load the Sanitize module, we need this to prevent XSS and sql injection attacks.
13 13
   function beforeFilter()
14 14
   {
15  
-	$this->Sanitize = new Sanitize();
  15
+    $this->Sanitize = new Sanitize();
  16
+    #Adding in data for the Arch menu for every page.
  17
+    $archTypeDBList = $archTypeDBList = $this->Software->find('all',array('fields'=>'DISTINCT arch'));
  18
+    $this->set('archTypeDBList',$archTypeDBList);
16 19
   }
17 20
   #softbundles are here!
18 21
   function softbundles() {
19  
- 	$id = $this->params['pass'][0];
20  
-	$data = $this->Softbundle->find('all',array('conditions'=>'Softbundle.id='."'".$id."'"));
21  
-	if(!empty($data))
22  
-	{
23  
-		$this->set('data',$data);
24  
-	}
25  
-	else
26  
-	{
27  
-			    $this->cakeError('oopsError', array('page'=>'softbundles'.$id));
28  
-	}
  22
+    $id = $this->params['pass'][0];
  23
+    $data = $this->Softbundle->find('all',array('conditions'=>'Softbundle.id='."'".$id."'"));
  24
+    if(!empty($data))
  25
+    {
  26
+        $this->set('data',$data);
  27
+    }
  28
+    else
  29
+    {
  30
+                $this->cakeError('oopsError', array('page'=>'softbundles'.$id));
  31
+    }
29 32
   }
30 33
   #function to handle subcategories.
31 34
   function showL2()
32 35
   {
33  
-	#fetch params
34  
-	$params = $this->params['pass'];
35  
-	$softSubCat= $params[0];
36  
-	#search for subcategory
37  
-	$data = $this->Software->find('all',array('conditions'=>'Software.softSubCat='."'".$softSubCat."'",'order'=>array('Software.softName ASC'),'fields' => array('Software.softName')));
38  
-	#create error handler
39  
-	if(!empty($data))
40  
-	{
41  
-		#set display variables
42  
-		$this->set('data',$data);
43  
-		$this->set('softSubCat',$softSubCat);
44  
-	}
45  
-	else
46  
-	{
47  
-			    $this->cakeError('oopsError', array('page'=>'showL2'.$softSubCat));
48  
-	}
  36
+    #fetch params
  37
+    $params = $this->params['pass'];
  38
+    $archType = "i386";
  39
+    $softSubCat= $params[0];
  40
+    #search for subcategory
  41
+    $data = $this->Software->find('all',array('conditions'=>'Software.softSubCat='."'".$softSubCat."' AND Software.arch='".$archType."'",'order'=>array('Software.softName ASC'),'fields' => array('DISTINCT Software.softName')));
  42
+    #create error handler
  43
+    if(!empty($data))
  44
+    {
  45
+        #set display variables
  46
+        $this->set('data',$data);
  47
+        $this->set('softSubCat',$softSubCat);
  48
+    }
  49
+    else
  50
+    {
  51
+                $this->cakeError('oopsError', array('page'=>'showL2'.$softSubCat));
  52
+    }
49 53
   }
50  
-  
  54
+
51 55
   #show each software and its full description, added meta.
52 56
   function showDesc()
53  
-  {	
54  
-	$params = $this->params['pass'];
55  
-	$softName= $params[0];
56  
-	$data = $this->Software->find('all',array('conditions'=>'Software.softName='."'".$softName."'"));
57  
-	#Call to meta Handler
58  
-	$metaSoftList = $this->metaHandler($data[0]['Software']['softName'],$data[0]['Software']['softSubCat'],$data[0]['Software']['softCat']);
59  
-	if(!empty($data))
60  
-	{
61  
-		#append subcategory to the meta array
62  
-		$list = $this->Software->find('all',array('conditions'=>'Software.softSubCat='."'".$data[0]['Software']['softSubCat']."'",'fields'=>array('Software.softName')));
63  
-		foreach($list as $var)
64  
-		{
65  
-			array_push($metaSoftList,$var['Software']['softName']);
66  
-		}
67  
-		#remove duplicates
68  
-		$metaSoftList = array_unique($metaSoftList);
69  
-		#remove test value
70  
-		array_shift($metaSoftList);
71  
-		#reverse for priority, show subcat first then meta.
72  
-		$metaSoftList = array_reverse($metaSoftList);
73  
-		$this->set('data',$data);
74  
-		#set the new meta variable, no change to view, only to the core logic!
75  
-		$this->set('list',$metaSoftList);
76  
-	}
77  
-	else
78  
-	{
79  
-			    $this->cakeError('oopsError', array('page'=>'showDesc'.$softName));
80  
-	}
  57
+  {
  58
+    $params = $this->params['pass'];
  59
+    $softName= $params[0];
  60
+    #Filter and handle architecture parameters
  61
+    if($params[1]!="")
  62
+    {
  63
+        $archType = $params[1];
  64
+    }
  65
+    else
  66
+    {#defaults to i386 if no arch is specified.
  67
+        $archType = "i386";
  68
+    }
  69
+    #added architecture filter condition
  70
+    $data = $this->Software->find('all',array('conditions'=>'Software.softName='."'".$softName."' AND Software.arch='".$archType."'"));
  71
+    #Total architectures supported for a particular application
  72
+    $archTypeList = $this->Software->find('all',array('fields'=>'DISTINCT arch','conditions'=>'Software.softName='."'".$softName."'"));
  73
+    #Call to meta Handler
  74
+    $metaSoftList = $this->metaHandler($data[0]['Software']['softName'],$data[0]['Software']['softSubCat'],$data[0]['Software']['softCat']);
  75
+    if(!empty($data))
  76
+    {
  77
+        #append subcategory to the meta array
  78
+        $list = $this->Software->find('all',array('conditions'=>'Software.softSubCat='."'".$data[0]['Software']['softSubCat']."'",'fields'=>array('Software.softName')));
  79
+        foreach($list as $var)
  80
+        {
  81
+            array_push($metaSoftList,$var['Software']['softName']);
  82
+        }
  83
+        #remove duplicates
  84
+        $metaSoftList = array_unique($metaSoftList);
  85
+        #remove test value
  86
+        array_shift($metaSoftList);
  87
+        #reverse for priority, show subcat first then meta.
  88
+        $metaSoftList = array_reverse($metaSoftList);
  89
+        $this->set('data',$data);
  90
+        #set the new meta variable, no change to view, only to the core logic!
  91
+        $this->set('list',$metaSoftList);
  92
+        #set the archtype list for display
  93
+        $this->set('archTypeList',$archTypeList);
  94
+    }
  95
+    else
  96
+    {
  97
+                $this->cakeError('oopsError', array('page'=>'showDesc'.$softName));
  98
+    }
81 99
   }
82 100
 
83 101
 #live search handler
84 102
 function search() {
85  
-	#postback characters
86  
-	if (!empty($this->data['Software']['search']))
87  
-	{
88  
-		#santize and remove any stupid typo errors/ sql injection code
89  
-		$query = $this -> Sanitize -> paranoid($this->data['Software']['search'],array(' '));
90  
-		#future handler to ensure that we can limit the search to trigger only for more than N characters
91  
-		if (strlen($query) > 3)
92  
-		{
93  
-			#Call to meta Handler
94  
-			$metaSoftList = $this->metaHandler($query,$query,$query);
95  
-			#woah launch a mega DB search
96  
-			$result = $this -> Software -> find('all',array('conditions'=>"softName LIKE '%".$query."%' OR softCat LIKE '%".str_replace(" ","_",$query)."%' OR softSubCat LIKE '%".str_replace(" ","_",$query)."%'"));
97  
-			foreach($result as $var)
98  
-			{
99  
-				array_push($metaSoftList,$var['Software']['softName']);
100  
-			}
101  
-			#remove duplicates
102  
-			$metaSoftList = array_unique($metaSoftList);
103  
-			#remove test value
104  
-			array_shift($metaSoftList);
105  
-			#reverse for priority, show subcat first then meta.
106  
-			$metaSoftList = array_reverse($metaSoftList);
107  
-			$this->set('result', $metaSoftList);
108  
-			$this->layout = 'ajax';
109  
-		}
110  
-	}
  103
+    #postback characters
  104
+    if (!empty($this->data['Software']['search']))
  105
+    {
  106
+        #santize and remove any stupid typo errors/ sql injection code
  107
+        $query = $this -> Sanitize -> paranoid($this->data['Software']['search'],array(' '));
  108
+        #future handler to ensure that we can limit the search to trigger only for more than N characters
  109
+        if (strlen($query) >= 3)
  110
+        {
  111
+            #Call to meta Handler
  112
+            $metaSoftList = $this->metaHandler($query,$query,$query);
  113
+            #woah launch a mega DB search
  114
+            $result = $this -> Software -> find('all',array('conditions'=>"softName LIKE '%".$query."%' OR softCat LIKE '%".str_replace(" ","_",$query)."%' OR softSubCat LIKE '%".str_replace(" ","_",$query)."%'"));
  115
+            foreach($result as $var)
  116
+            {
  117
+                array_push($metaSoftList,$var['Software']['softName']);
  118
+            }
  119
+            #remove duplicates
  120
+            $metaSoftList = array_unique($metaSoftList);
  121
+            #remove test value
  122
+            array_shift($metaSoftList);
  123
+            #reverse for priority, show subcat first then meta.
  124
+            $metaSoftList = array_reverse($metaSoftList);
  125
+            $this->set('result', $metaSoftList);
  126
+            $this->layout = 'ajax';
  127
+        }
  128
+    }
111 129
 }
112 130
 
113 131
 #description similar to search function, but handles only on clicking enter button in the search box. (Future disable the enter button).
114 132
 #duplicated code, need a fix for this in a future version.
115 133
 function searchPost()
116 134
 {
117  
-	#postback characters
118  
-	if (!empty($this->data['Software']['search']))
119  
-	{
120  
-		#santize and remove any stupid typo errors/ sql injection code
121  
-		$query = $this -> Sanitize -> paranoid($this->data['Software']['search'],array(' '));
122  
-		#future handler to ensure that we can limit the search to trigger only for more than N characters
123  
-		if (strlen($query) > 3)
124  
-		{
125  
-			#Call to meta Handler
126  
-			$metaSoftList = $this->metaHandler($query,$query,$query);
127  
-			#woah launch a mega DB search
128  
-			$result = $this -> Software -> find('all',array('conditions'=>"softName LIKE '%".$query."%' OR softCat LIKE '%".str_replace(" ","_",$query)."%' OR softSubCat LIKE '%".str_replace(" ","_",$query)."%'"));
129  
-			foreach($result as $var)
130  
-			{
131  
-				array_push($metaSoftList,$var['Software']['softName']);
132  
-			}
133  
-			#remove duplicates
134  
-			$metaSoftList = array_unique($metaSoftList);
135  
-			#remove test value
136  
-			array_shift($metaSoftList);
137  
-			#reverse for priority, show subcat first then meta.
138  
-			$metaSoftList = array_reverse($metaSoftList);
139  
-			$this->set('result', $metaSoftList);	
140  
-			$this->render('search');
141  
-		}
142  
-	}
  135
+    #postback characters
  136
+    if (!empty($this->data['Software']['search']))
  137
+    {
  138
+        #santize and remove any stupid typo errors/ sql injection code
  139
+        $query = $this -> Sanitize -> paranoid($this->data['Software']['search'],array(' '));
  140
+        #future handler to ensure that we can limit the search to trigger only for more than N characters
  141
+        if (strlen($query) >= 3)
  142
+        {
  143
+            #Call to meta Handler
  144
+            $metaSoftList = $this->metaHandler($query,$query,$query);
  145
+            #woah launch a mega DB search
  146
+            $result = $this -> Software -> find('all',array('conditions'=>"softName LIKE '%".$query."%' OR softCat LIKE '%".str_replace(" ","_",$query)."%' OR softSubCat LIKE '%".str_replace(" ","_",$query)."%'"));
  147
+            foreach($result as $var)
  148
+            {
  149
+                array_push($metaSoftList,$var['Software']['softName']);
  150
+            }
  151
+            #remove duplicates
  152
+            $metaSoftList = array_unique($metaSoftList);
  153
+            #remove test value
  154
+            array_shift($metaSoftList);
  155
+            #reverse for priority, show subcat first then meta.
  156
+            $metaSoftList = array_reverse($metaSoftList);
  157
+            $this->set('result', $metaSoftList);
  158
+            $this->render('search');
  159
+        }
  160
+    }
143 161
 }
144 162
 
145 163
 #Lets burn a feed for the people.
146 164
 function generatefeed(){
147  
-	#grab the top 20 changed/updated softwares
148  
-	$software = $this->Software->find('all',array('order'=>array('Software.entry_date DESC'),'limit' => 20));
149  
-	#hmm checking for particular feed (feed.rss).
150  
-	if(isset($this->params['requested'])) {
  165
+    #grab the top 20 changed/updated softwares
  166
+    $software = $this->Software->find('all',array('order'=>array('Software.entry_date DESC'),'limit' => 20));
  167
+    #hmm checking for particular feed (feed.rss).
  168
+    if(isset($this->params['requested'])) {
151 169
                          return $software;
152 170
                  }
153 171
                  $this->set('software',$software );
@@ -155,30 +173,64 @@ function generatefeed(){
155 173
 
156 174
 function metaHandler($softName,$softSubCat,$softCat)
157 175
 {
158  
-	#meta search results added :)
159  
-	$metaSoftList[]="test";
160  
-	#find similar soft
161  
-	$simSoft = $this->Meta-> find('all',array('conditions'=>"metainfo LIKE '%".$softName."%' OR metainfo LIKE '%".str_replace(" ","_",$softSubCat)."%' OR metainfo LIKE '%".str_replace(" ","_",$softCat)."%'"));
162  
-	#split similar software
163  
-	$simSoft = explode(':',$simSoft[0]['Meta']['metaInfo']);
164  
-	#prevent sql table dump
165  
-	if ($simSoft[0]!="")
166  
-	{
167  
-		#create similar software to display from meta
168  
-		foreach($simSoft as $var)
169  
-		{
170  
-			#take a crack with each meta record to find a match, this is a greedy database search statement.
171  
-			$metaSoft = $this -> Software -> find('all',array('conditions'=>"softName LIKE '%".$var."%' OR softCat LIKE '%".str_replace(" ","_",$var)."%' OR softSubCat LIKE '%".str_replace(" ","_",$var)."%'",'fields'=>array('Software.softName')));
172  
-			foreach($metaSoft as $metaSoftName)
173  
-			{
174  
-				#push everything into a single array, easier to manage
175  
-				array_push($metaSoftList,$metaSoftName['Software']['softName']);
176  
-			}
177  
-		}
178  
-		#chuck back the data
179  
-	}
180  
-	return $metaSoftList;
  176
+    #meta search results added :)
  177
+    $metaSoftList[]="test";
  178
+    #find similar soft
  179
+    $simSoft = $this->Meta-> find('all',array('conditions'=>"metainfo LIKE '%".$softName."%' OR metainfo LIKE '%".str_replace(" ","_",$softSubCat)."%' OR metainfo LIKE '%".str_replace(" ","_",$softCat)."%'"));
  180
+    #split similar software
  181
+    $simSoft = explode(':',$simSoft[0]['Meta']['metaInfo']);
  182
+    #prevent sql table dump
  183
+    if ($simSoft[0]!="")
  184
+    {
  185
+        #create similar software to display from meta
  186
+        foreach($simSoft as $var)
  187
+        {
  188
+            #take a crack with each meta record to find a match, this is a greedy database search statement.
  189
+            $metaSoft = $this -> Software -> find('all',array('conditions'=>"softName LIKE '%".$var."%' OR softCat LIKE '%".str_replace(" ","_",$var)."%' OR softSubCat LIKE '%".str_replace(" ","_",$var)."%'",'fields'=>array('Software.softName')));
  190
+            foreach($metaSoft as $metaSoftName)
  191
+            {
  192
+                #push everything into a single array, easier to manage
  193
+                array_push($metaSoftList,$metaSoftName['Software']['softName']);
  194
+            }
  195
+        }
  196
+        #chuck back the data
  197
+    }
  198
+    return $metaSoftList;
  199
+}
  200
+
  201
+#Arch pages and listing.
  202
+function arch()
  203
+{
  204
+    $params = $this->params['pass'];
  205
+    if($params[0]!="")
  206
+    {
  207
+        $archType = $params[0];
  208
+    }
  209
+    else
  210
+    {#defaults to i386 if no arch is specified.
  211
+        $archType = "i386";
  212
+    }
  213
+    $archTypeDBList = $archTypeDBList = $this->Software->find('all',array('fields'=>'DISTINCT arch'));
  214
+    $flag = "noSupport";
  215
+    foreach($archTypeDBList as $var)
  216
+    {
  217
+        if($var['Software']['arch']==$archType)
  218
+        {
  219
+            $flag = "archSupported";
  220
+        }
  221
+    }
  222
+    if($flag=="archSupported")
  223
+    {
  224
+        $data = $this->Software->find('all',array('fields'=>'DISTINCT Software.softName','conditions'=>"Software.arch='".$archType."' ORDER BY Software.softName ASC"));
  225
+        $this->set('softNames',$data);
  226
+        $this->set('archType',$archType);
  227
+    }
  228
+    else
  229
+    {
  230
+        $this->set('archError',"Not supported");
  231
+    }
181 232
 }
182 233
 
  234
+
183 235
 }
184 236
 ?>

0 notes on commit dd37c68

Please sign in to comment.
Something went wrong with that request. Please try again.