HomeHelpTrac

source: trunk/inc/tags.inc.php @ 15211

Revision 15211, 1.5 KB checked in by Alexander Trofimov, 12 months ago (diff)

Code cleaning:

  • converting new lines to \n
  • deleting spaces at the end of every line
  • converting all tabs to 4 spaces
  • automated script for future cleaning was added
Line 
1<?php
2/**
3 * @package     Dolphin Core
4 * @copyright   Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
5 * @license     CC-BY - http://creativecommons.org/licenses/by/3.0/
6 */
7defined('BX_DOL') or die('hack attempt');
8
9
10function explodeTags( $text ) {
11
12    //$text = preg_replace( '/[^a-zA-Z0-9_\'-]/', ' ', $text );
13
14    $aTags = preg_split( '/[' . BX_DOL_TAGS_DIVIDER . ']/', $text, 0, PREG_SPLIT_NO_EMPTY );
15
16    foreach( $aTags as $iInd => $sTag )
17    {
18        if( strlen( $sTag ) < 3 )
19            unset( $aTags[$iInd] );
20        else
21            $aTags[$iInd] = trim(mb_strtolower( $sTag , 'UTF-8'));
22    }
23    $aTags = array_unique( $aTags );
24    $sTagsNotParsed = getParam( 'tags_non_parsable' );
25    $aTagsNotParsed = preg_split( '/[' . BX_DOL_TAGS_DIVIDER . ']/', $sTagsNotParsed, 0, PREG_SPLIT_NO_EMPTY );
26
27    $aTags = array_diff( $aTags, $aTagsNotParsed ); //drop non parsable tags
28
29    return $aTags;
30}
31
32function storeTags( $iID, $sTags, $sType ) {
33    $oDb = BxDolDb::getInstance();
34
35    $sQuery = $oDb->prepare("DELETE FROM `sys_tags` WHERE `ID` = ? AND `Type` = ?", $iID, $sType);
36    $oDb->res($sQuery);
37
38    $aTags = explodeTags($sTags);
39    foreach ($aTags as $sTag) {
40        $sQuery = $oDb->prepare("INSERT INTO `sys_tags` VALUES (?, ?, ?, CURRENT_TIMESTAMP)", $sTag, $iID, $sType);
41        $oDb->res($sQuery, 0);
42    }
43}
44
45function reparseObjTags( $sType, $iID ) {
46    bx_import('BxDolTags');
47    $oTags = new BxDolTags();
48    $oTags->reparseObjTags($sType, $iID);
49}
50
Note: See TracBrowser for help on using the repository browser.