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 CONTENIDO path resolver functions.
  4:  *
  5:  * @package          Core
  6:  * @subpackage       Backend
  7:  * @version          SVN Revision $Rev:$
  8:  *
  9:  * @author           Timo Hummel
 10:  * @copyright        four for business AG <www.4fb.de>
 11:  * @license          http://www.contenido.org/license/LIZENZ.txt
 12:  * @link             http://www.4fb.de
 13:  * @link             http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Resolves a path using some fuzzy logic.
 20:  *
 21:  * Warning: If you use this function, try to pass a 'good' path. This function
 22:  *          doesn't guarantee that the matches are logically best-matches.
 23:  *
 24:  * This function operates on the category aliases. It compares the given path with the
 25:  * urlpaths generated by function prCreateURLNameLocationString() based on category aliases.
 26:  *
 27:  * @param  string  $path  Path to resolve
 28:  * @return int Closest matching category ID (idcat)
 29:  */
 30: function prResolvePathViaURLNames($path) {
 31:     global $cfg, $lang, $client;
 32: 
 33:     $handle = startTiming('prResolvePathViaURLNames', array($path));
 34: 
 35:     // Initialize variables
 36:     $db = cRegistry::getDb();
 37:     $categories = array();
 38:     $results = array();
 39: 
 40:     // Pre-process path
 41:     $path = strtolower(str_replace(' ', '', $path));
 42: 
 43:     // Delete outdated entry in heapcache table, if enabled.
 44:     if ($cfg['pathresolve_heapcache'] == true) {
 45:         $oPathresolveCacheColl = new cApiPathresolveCacheCollection();
 46:         $oPathresolveCache = $oPathresolveCacheColl->fetchLatestByPathAndLanguage($path, $lang);
 47:         if (is_object($oPathresolveCache)) {
 48:             if ($oPathresolveCache->isCacheTimeExpired()) {
 49:                 $cacheIdcat = $oPathresolveCache->get('idcat');
 50:                 $oPathresolveCacheColl->delete($oPathresolveCache->get('idpathresolvecache'));
 51:                 return $cacheIdcat;
 52:             }
 53:         }
 54:     }
 55: 
 56:     // Fetch all category names, build path strings
 57:     // @todo change the where statement for get all languages
 58:     $sql = "SELECT * FROM " . $cfg["tab"]["cat_tree"] . " AS A, " . $cfg["tab"]["cat"] . " AS B, " . $cfg["tab"]["cat_lang"] . " AS C WHERE A.idcat=B.idcat AND B.idcat=C.idcat AND C.idlang=" . (int) $lang . "
 59:             AND C.visible = 1 AND B.idclient=" . (int) $client . " ORDER BY A.idtree";
 60:     $db->query($sql);
 61: 
 62:     $catpath = array();
 63:     while ($db->nextRecord()) {
 64:         $cat_str = '';
 65:         prCreateURLNameLocationString($db->f('idcat'), '/', $cat_str, false, '', 0, 0, true, true);
 66: 
 67:         // Store path
 68:         $catpath[$db->f('idcat')] = $cat_str;
 69:         $catnames[$db->f('idcat')] = $db->f('name');
 70:         $catlevels[$db->f('idcat')] = $db->f('level');
 71:     }
 72: 
 73:     // Compare strings using the similar_text algorythm
 74:     $percent = 0;
 75:     foreach ($catpath as $key => $value) {
 76:         $value = strtolower(str_replace(' ', '', $value));
 77: 
 78:         similar_text($value, $path, $percent);
 79: 
 80:         $firstpath = strpos($value, '/');
 81: 
 82:         if ($firstpath !== 0) {
 83:             $xpath = substr($value, $firstpath);
 84:             $ypath = substr($path, 0, strlen($path) - 1);
 85:             if ($xpath == $ypath) {
 86:                 $results[$key] = 100;
 87:             } else {
 88:                 $results[$key] = $percent;
 89:             }
 90:         } else {
 91:             $results[$key] = $percent;
 92:         }
 93:     }
 94: 
 95:     arsort($results, SORT_NUMERIC);
 96:     reset($results);
 97: 
 98:     endAndLogTiming($handle);
 99: 
100:     if ($cfg['pathresolve_heapcache'] == true) {
101:         $oPathresolveCacheColl = new cApiPathresolveCacheCollection();
102:         $oPathresolveCache = $oPathresolveCacheColl->create($path, key($results), $lang, time());
103:     }
104: 
105:     return (int) key($results);
106: }
107: 
108: /**
109:  * Resolves a path using some fuzzy logic.
110:  *
111:  * Warning: If you use this function, try to pass a 'good' path. This function
112:  *          doesn't guarantee that the matches are logically best-matches.
113:  *
114:  * This function operates on the actual category names.
115:  *
116:  * @param  string  $path  Path to resolve
117:  * @return  int  Closest matching category ID (idcat)
118:  */
119: function prResolvePathViaCategoryNames($path, &$iLangCheck) {
120:     global $cfg, $lang, $client;
121: 
122:     $handle = startTiming('prResolvePathViaCategoryNames', array($path));
123: 
124:     // Initialize variables
125:     $db = cRegistry::getDb();
126:     $categories = array();
127:     $results = array();
128:     $iLangCheckOrg = $iLangCheck;
129: 
130:     // To take only path body
131:     if (preg_match('/^\/(.*)\/$/', $path, $aResults)) {
132:         $aResult = explode('/', $aResults[1]);
133:     } elseif (preg_match('/^\/(.*)$/', $path, $aResults)) {
134:         $aResult = explode('/', $aResults[1]);
135:     } else {
136:         $aResults[1] = $path;
137:     }
138: 
139:     $aResults[1] = strtolower(preg_replace('/-/', ' ', $aResults[1]));
140: 
141:     // Init to Compare, save path in array
142:     $aPathsToCompare = explode('/', $aResults[1]);
143:     $iCountPath = count($aPathsToCompare);
144: 
145:     // init lang id
146:     $iLangCheck = 0;
147: 
148:     // Pre-process path
149:     $path = strtolower(str_replace(' ', '', $path));
150: 
151:     // Fetch all category names, build path strings
152:     // @todo change the where statement for get all languages
153:     $sql = "SELECT * FROM " . $cfg["tab"]["cat_tree"] . " AS A, " . $cfg["tab"]["cat"] . " AS B, " . $cfg["tab"]["cat_lang"] . " AS C WHERE A.idcat=B.idcat AND B.idcat=C.idcat
154:             AND C.visible = 1 AND B.idclient= " . (int) $client . " ORDER BY A.idtree";
155:     $db->query($sql);
156: 
157:     $catpath = array();
158:     $arrLangMatches = array();
159: 
160:     while ($db->nextRecord()) {
161:         $cat_str = '';
162:         $aTemp = '';
163:         $iFor = 0;
164:         $bLang = false;
165: 
166:         // $level is changeless 0!!!
167:         conCreateLocationString($db->f('idcat'), '/', $cat_str, false, '', 0, $db->f('idlang'));
168:         // Store path
169:         $catpath[$db->f('idcat')] = $cat_str;
170:         $catnames[$db->f('idcat')] = $db->f('name');
171:         $catlevels[$db->f('idcat')] = $db->f('level');
172: 
173:         // Init variables for take a language id
174:         $aTemp = strtolower($cat_str);
175:         $aDBToCompare = explode('/', $aTemp);
176:         $iCountDB = count($aDBToCompare);
177:         $iCountDBFor = $iCountDB - 1;
178:         // take min. count of two arrays
179:         ($iCountDB > $iCountPath) ? $iFor = $iCountPath : $iFor = $iCountDB;
180:         $iCountM = $iFor - 1;
181: 
182:         for ($i = 0; $i < $iFor; $i++) {
183:             if ($aPathsToCompare[$iCountM] == $aDBToCompare[$iCountDBFor]) {
184:                 $bLang = true;
185:             } else {
186:                 $bLang = false;
187:             }
188:             $iCountM--;
189:             $iCountDBFor--;
190:             // compare, only if current element is lastone and we are in true path
191:             if ($i == $iFor - 1 && $bLang) {
192:                 $iLangCheck = $db->f('idlang');
193:                 $arrLangMatches[] = $iLangCheck;
194:             }
195:         }
196:     }
197: 
198:     // Suppress wrongly language change if url name can be found in current language
199:     if ($iLangCheckOrg == 0) {
200:         if (in_array($lang, $arrLangMatches)) {
201:             $iLangCheck = $lang;
202:         }
203:     }
204: 
205:     // Compare strings using the similar_text algorythm
206:     $percent = 0;
207:     foreach ($catpath as $key => $value) {
208:         $value = strtolower(str_replace(' ', '', $value));
209:         similar_text($value, $path, $percent);
210:         $results[$key] = $percent;
211:     }
212: 
213:     foreach ($catnames as $key => $value) {
214:         $value = strtolower(str_replace(' ', '', $value));
215:         similar_text($value, $path, $percent);
216: 
217:         // Apply weight
218:         $percent = $percent * $catlevels[$key];
219: 
220:         if ($results[$key] > $percent) {
221:             $results[$key] = $percent;
222:         }
223:     }
224: 
225:     arsort($results, SORT_NUMERIC);
226:     reset($results);
227: 
228:     endAndLogTiming($handle);
229:     return (int) key($results);
230: }
231: 
232: /**
233:  * Recursive function to create an URL name location string.
234:  *
235:  * @param int $idcat ID of the starting category
236:  * @param string $seperator Seperation string
237:  * @param string $cat_str Category location string (by reference)
238:  * @param bool $makeLink create location string with links
239:  * @param string $linkClass stylesheet class for the links
240:  * @param int first navigation level location string should be printed out (first level = 0!!)
241:  * @return string location string
242:  */
243: function prCreateURLNameLocationString($idcat, $seperator, & $cat_str, $makeLink = false, $linkClass = '', $firstTreeElementToUse = 0, $uselang = 0, $final = true, $usecache = false) {
244:     global $cfg, $client, $cfgClient, $lang, $sess, $_URLlocationStringCache;
245: 
246:     if ($final == true) {
247:         $cat_str = '';
248:     }
249: 
250:     if ($idcat == 0) {
251:         $cat_str = i18n("Lost and found");
252:         return;
253:     }
254: 
255:     if ($uselang == 0) {
256:         $uselang = $lang;
257:     }
258: 
259:     if ($final == true && $usecache == true) {
260:         if (!is_array($_URLlocationStringCache)) {
261:             $_URLlocationStringCache = prGetCacheFileContent($client, $uselang);
262:         }
263: 
264:         if (array_key_exists($idcat, $_URLlocationStringCache)) {
265:             if ($_URLlocationStringCache[$idcat]['expires'] > time()) {
266:                 $cat_str = $_URLlocationStringCache[$idcat]['name'];
267:                 return;
268:             }
269:         }
270:     }
271: 
272:     $db = cRegistry::getDb();
273: 
274:     $sql = "SELECT
275:                 a.urlname AS urlname,
276:                 a.name    AS name,
277:                 a.idcat AS idcat,
278:                 b.parentid AS parentid,
279:                 c.level as level,
280:                 d.idtpl as idtpl
281:             FROM
282:                 " . $cfg["tab"]["cat_lang"] . " AS a
283:                 LEFT JOIN " . $cfg["tab"]["tpl_conf"] . " AS d on a.idtplcfg  = d.idtplcfg,
284:                 " . $cfg["tab"]["cat"] . " AS b,
285:                 " . $cfg["tab"]["cat_tree"] . " AS c
286:             WHERE
287:                 a.idlang    = " . (int) $uselang . " AND
288:                 b.idclient  = " . (int) $client . " AND
289:                 b.idcat     = " . (int) $idcat . " AND
290:                 a.idcat     = b.idcat AND
291:                 c.idcat     = b.idcat";
292: 
293:     $db->query($sql);
294:     $db->nextRecord();
295: 
296:     if ($db->f('level') >= $firstTreeElementToUse) {
297:         $name = $db->f('urlname');
298: 
299:         if (trim($name) == '') {
300:             $name = $db->f('name');
301:         }
302: 
303:         $parentid = $db->f('parentid');
304:         $idtpl = (int) $db->f('idtpl');
305: 
306:         //create link
307: 
308:         if ($makeLink == true) {
309:             $linkUrl = $sess->url("front_content.php?idcat=$idcat&idtpl=$idtpl");
310:             $name = '<a href="' . $linkUrl . '" class="' . $linkClass . '">' . $name . '</a>';
311:         }
312: 
313:         $tmp_cat_str = $name . $seperator . $cat_str;
314:         $cat_str = $tmp_cat_str;
315:     }
316: 
317:     if ($parentid != 0) {
318:         prCreateURLNameLocationString($parentid, $seperator, $cat_str, $makeLink, $linkClass, $firstTreeElementToUse, $uselang, false, $usecache);
319:     } else {
320:         $sep_length = strlen($seperator);
321:         $str_length = strlen($cat_str);
322:         $tmp_length = $str_length - $sep_length;
323:         $cat_str = substr($cat_str, 0, $tmp_length);
324:     }
325: 
326:     if ($final == true && $usecache == true) {
327:         $_URLlocationStringCache[$idcat]['name'] = $cat_str;
328:         $_URLlocationStringCache[$idcat]['expires'] = time() + 3600;
329: 
330:         prWriteCacheFileContent($_URLlocationStringCache, $client, $uselang);
331:     }
332: }
333: 
334: /**
335:  * Writes path location string cache data file.
336:  * @global array $cfgClient
337:  * @param array $data
338:  * @param int $client
339:  * @param int $lang
340:  * @return bool
341:  */
342: function prWriteCacheFileContent($data, $client, $lang) {
343:     global $cfgClient;
344: 
345:     $path = $cfgClient[$client]['cache']['path'];
346:     $filename = "locationstring-url-cache-$lang.txt";
347: 
348:     $res = false;
349:     if (is_writable($path)) {
350:         $res = cFileHandler::write($path . $filename, serialize($data));
351:     }
352: 
353:     return ($res) ? true : false;
354: }
355: 
356: /**
357:  * Get path location string cache data file content.
358:  * @global array $cfgClient
359:  * @param int $client
360:  * @param int $lang
361:  * @return array $data
362:  */
363: function prGetCacheFileContent($client, $lang) {
364:     global $cfgClient;
365: 
366:     $path = $cfgClient[$client]['cache']['path'];
367:     $filename = "locationstring-url-cache-$lang.txt";
368: 
369:     if (cFileHandler::exists($path . $filename)) {
370:         $data = unserialize(cFileHandler::read($path . $filename));
371:     } else {
372:         $data = array();
373:     }
374: 
375:     return (is_array($data)) ? $data : array();
376: }
377: 
378: /**
379:  * Deletes path location string cache data file.
380:  * @global array $cfgClient
381:  * @param int $client
382:  * @param int $lang
383:  * @return bool
384:  */
385: function prDeleteCacheFileContent($client, $lang) {
386:     global $cfgClient;
387: 
388:     $path = $cfgClient[$client]['cache']['path'];
389:     $filename = "locationstring-url-cache-$lang.txt";
390: 
391:     $res = false;
392:     if (is_writable($path . $filename)) {
393:         $res = @unlink($path . $filename);
394:     }
395: 
396:     return ($res) ? true : false;
397: }
398: 
399: ?>
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen