Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: /**
  3:  * This file contains the module search class.
  4:  * TODO: Rework comments of this class.
  5:  *
  6:  * @package    Core
  7:  * @subpackage Backend
  8:  * @version    SVN Revision $Rev:$
  9:  *
 10:  * @author     Rusmir Jusufovic
 11:  * @copyright  four for business AG <www.4fb.de>
 12:  * @license    http://www.contenido.org/license/LIZENZ.txt
 13:  * @link       http://www.4fb.de
 14:  * @link       http://www.contenido.org
 15:  */
 16: 
 17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 18: 
 19: /**
 20:  * This class performs the module search.
 21:  *
 22:  * @package    Core
 23:  * @subpackage Backend
 24:  */
 25: class cModuleSearch extends cModuleHandler {
 26: 
 27:     /**
 28:      * Items/Element per page
 29:      *
 30:      * @var int
 31:      */
 32:     protected $_elementPerPage = '';
 33: 
 34:     /**
 35:      * Order by
 36:      *
 37:      * @var string
 38:      */
 39:     protected $_orderBy = '';
 40: 
 41:     /**
 42:      * Sort order
 43:      *
 44:      * @var string
 45:      */
 46:     protected $_sortOrder = '';
 47: 
 48:     /**
 49:      * Module type
 50:      *
 51:      * @var string
 52:      */
 53:     protected $_moduleType = '';
 54: 
 55:     /**
 56:      * Filter string
 57:      *
 58:      * @var string
 59:      */
 60:     protected $_filter = '';
 61: 
 62:     /**
 63:      * Where should be searched (all, description, type, input, output)
 64:      *
 65:      * @var string
 66:      */
 67:     protected $_searchIn = '';
 68: 
 69:     /**
 70:      * Selected page
 71:      *
 72:      * @var int
 73:      */
 74:     protected $_selectedPage = 1;
 75: 
 76:     /**
 77:      * Result saved in a array
 78:      *
 79:      * @var array
 80:      */
 81:     protected $_result = array();
 82: 
 83:     /**
 84:      * Print a array
 85:      *
 86:      * @param array $arg
 87:      */
 88:     private function _echo($arg) {
 89:         echo '<pre>' . print_r($arg) . '</pre>';
 90:     }
 91: 
 92:     public function __construct($searchOptions) {
 93:         parent::__construct();
 94:         
 95:         $this->_elementPerPage = $searchOptions['elementPerPage'];
 96:         $this->_orderBy = $searchOptions['orderBy'];
 97:         $this->_sortOrder = $searchOptions['sortOrder'];
 98:         $this->_moduleType = $searchOptions['moduleType'];
 99:         $this->_filter = $searchOptions['filter'];
100:         $this->_searchIn = $searchOptions['searchIn'];
101:         $this->_selectedPage = $searchOptions['selectedPage'];
102:     }
103: 
104:     /**
105:      * Count result
106:      *
107:      * @return int count in result
108:      */
109:     public function getModulCount() {
110:         return count($this->_result);
111:     }
112: 
113:     /**
114:      * Search for modules in db columns and in filesystem (input and output
115:      * files)
116:      *
117:      * @return array result
118:      */
119:     public function searchForAllModules() {
120:         global $cfg, $client;
121: 
122:         $idClient = $client;
123:         // first fetch all modules for client
124:         // then apply _filter on input and output from files
125:         // then use the whitelisted id's and search for additional filter matches on database
126:         $sql = sprintf("SELECT * FROM %s WHERE idclient = %s", $cfg['tab']['mod'], $idClient);
127:         
128:         
129:         $db = cRegistry::getDb();
130:         $db->query($sql);
131:         $moduleIds = array();
132:         
133:         // filter modules based on input and output
134:         while (($modul = $db->nextRecord()) !== false) {
135:             $this->initWithDatabaseRow($db);
136:             if (strlen(stripslashes($this->_filter)) === 0
137:                     || strpos($this->readInput(), stripslashes($this->_filter)) !== false
138:                     || strpos($this->readOutput(), stripslashes($this->_filter)) !== false) {
139:                     $moduleIds[] = $db->f('idmod');
140:             }
141:         }
142:         
143:         // build query using whitelisted id's
144:         $idFilter = "";
145:         foreach ($moduleIds as $moduleId) {
146:             $idFilter .= " OR idmod=" . (int) $moduleId;
147:         }
148:         $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
149:                             type LIKE '%s'
150:                             AND type LIKE '%s'
151:                             OR description LIKE '%s'
152:                             OR name LIKE  '%s'" . $idFilter . ")
153:                             ORDER BY %s %s", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', '%' . $this->_filter . '%', '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
154: 
155:         $db = cRegistry::getDb();
156:         $db->query($sql);
157:         $result = array();
158: 
159:         while (($modul = $db->nextRecord()) !== false) {
160:             $this->initWithDatabaseRow($db);
161:             $result[$db->f('idmod')] = array(
162:                     'name' => $db->f('name'),
163:                     'description' => $db->f('description'),
164:                     'error' => $db->f('error'),
165:                     'input' => $this->readInput(),
166:                     'output' => $this->readOutput()
167:             );
168:         }
169: 
170:         return $result;
171:     }
172: 
173:     /**
174:      * Main method for the class. Search for modules in db and in input and
175:      * outputs files.
176:      *
177:      * @return array result
178:      */
179:     public function getModules() {
180:         $modules = array();
181: 
182:         switch ($this->_searchIn) {
183:             case 'all':
184:                 $modules = $this->searchForAllModules();
185:                 break;
186:             case 'name':
187:                 $modules = $this->findeModulWithName();
188:                 break;
189:             case 'description':
190:                 $modules = $this->findModuleWithDescription();
191:                 break;
192:             case 'type':
193:                 $modules = $this->findModuleWithType();
194:                 break;
195:             case 'input': // Search for modulname_input.php
196:                 $modules = $this->findModulWithInput();
197:                 break;
198:             case 'output': // Search fro modulname_output.php
199:                 $modules = $this->findModulWithOutput();
200:                 break;
201:         }
202: 
203:         $this->_result = $modules;
204:         if ($this->_elementPerPage > 0) {
205:             if (count($this->_result) < (($this->_page - 1) * $this->_elementPerPage)) {
206:                 $this->_page = 1;
207:             }
208: 
209:             if ($this->_elementPerPage * ($this->_page) >= count($this->_result) + $this->_elementPerPage && $this->_page != 1) {
210:                 $this->_page--;
211:             }
212:             return array_slice($modules, $this->_elementPerPage * ($this->_selectedPage - 1), $this->_elementPerPage, true);
213:         } else {
214:             return $modules;
215:         }
216:     }
217: 
218:     /**
219:      * Search for modules in "name" column of modul
220:      *
221:      * @return array result
222:      */
223:     public function findeModulWithName() {
224:         global $cfg, $client;
225:         $idClient = $client;
226: 
227:         $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (type LIKE '%s' AND name LIKE '%s')
228:                         ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
229: 
230:         $db = cRegistry::getDb();
231:         $db->query($sql);
232:         $result = array();
233: 
234:         while (($module = $db->nextRecord()) !== false) {
235:             $this->initWithDatabaseRow($db);
236:             $result[$db->f('idmod')] = array(
237:                     'name' => $db->f('name'),
238:                     'description' => $db->f('description'),
239:                     'error' => $db->f('error'),
240:                     'input' => $this->readInput(),
241:                     'output' => $this->readOutput()
242:             );
243:         }
244:         return $result;
245:     }
246: 
247:     /**
248:      * Search for modules in input file of the module
249:      *
250:      * @return array result
251:      */
252:     public function findModulWithInput() {
253:         global $cfg, $client;
254: 
255:         $idClient = $client;
256:         $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND type LIKE '%s'
257:                         ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, $this->_orderBy, $this->_sortOrder);
258: 
259:         $db = cRegistry::getDb();
260:         $db->query($sql);
261:         $result = array();
262:         while (($module = $db->nextRecord()) !== false) {
263:             $this->initWithDatabaseRow($db);
264:             if (strlen(stripslashes($this->_filter)) === 0
265:                 || strpos($this->readInput(), stripslashes($this->_filter)) !== false) {
266:                 $result[$db->f('idmod')] = array(
267:                         'name' => $db->f('name'),
268:                         'description' => $db->f('description'),
269:                         'error' => $db->f('error'),
270:                         'input' => $this->readInput(),
271:                         'output' => $this->readOutput()
272:                 );
273:             }
274:         }
275: 
276:         return $result;
277:     }
278: 
279:     /**
280:      * Search for modules in output of modules of current client
281:      *
282:      * @return array result
283:      */
284:     public function findModulWithOutput() {
285:          global $cfg, $client;
286:         
287:         $result = array();
288: 
289:         $idClient = $client;
290:         $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND type LIKE '%s'
291:                         ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, $this->_orderBy, $this->_sortOrder);
292: 
293:         $db = cRegistry::getDb();
294:         $db->query($sql);
295:         $result = array();
296:         while (($module = $db->nextRecord()) !== false) {
297:             $this->initWithDatabaseRow($db);
298:             if (strlen(stripslashes($this->_filter)) === 0
299:                 || strpos($this->readOutput(), stripslashes($this->_filter)) !== false) {
300:                 $result[$db->f('idmod')] = array(
301:                         'name' => $db->f('name'),
302:                         'description' => $db->f('description'),
303:                         'error' => $db->f('error'),
304:                         'input' => $this->readInput(),
305:                         'output' => $this->readOutput()
306:                 );
307:             }
308:         }
309: 
310:         return $result;
311:     }
312: 
313:     /**
314:      * Search for modules in type column
315:      *
316:      * @return array result
317:      */
318:     public function findModuleWithType() {
319:         global $cfg, $client;
320:         $idClient = $client;
321: 
322:         $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
323:                             type LIKE '%s'
324:                             AND type LIKE '%s')
325:                             ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
326: 
327:         $db = cRegistry::getDb();
328:         $db->query($sql);
329:         $result = array();
330: 
331:         while (($module = $db->nextRecord()) !== false) {
332:             $this->initWithDatabaseRow($db);
333:             $result[$db->f('idmod')] = array(
334:                     'name' => $db->f('name'),
335:                     'description' => $db->f('description'),
336:                     'error' => $db->f('error'),
337:                     'input' => $this->readInput(),
338:                     'output' => $this->readOutput()
339:             );
340:         }
341:         return $result;
342:     }
343: 
344:     /**
345:      * Search for modules in description column of modules
346:      *
347:      * @return array result
348:      */
349:     public function findModuleWithDescription() {
350:         global $cfg, $client;
351:         $idClient = $client;
352: 
353:         $sql = sprintf("SELECT * FROM %s WHERE idclient = %s AND (
354:                             type LIKE '%s'
355:                             AND description LIKE '%s')
356:                             ORDER BY %s %s ", $cfg['tab']['mod'], $idClient, $this->_moduleType, '%' . $this->_filter . '%', $this->_orderBy, $this->_sortOrder);
357: 
358:         $db = cRegistry::getDb();
359:         $db->query($sql);
360:         $result = array();
361: 
362:         while (($module = $db->nextRecord()) !== false) {
363:             $this->initWithDatabaseRow($db);
364:             $result[$db->f('idmod')] = array(
365:                     'name' => $db->f('name'),
366:                     'description' => $db->f('description'),
367:                     'error' => $db->f('error'),
368:                     'input' => $this->readInput(),
369:                     'output' => $this->readOutput()
370:             );
371:         }
372: 
373:         return $result;
374:     }
375: 
376: }
377: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen