Ejemplo n.º 1
0
 /**
  * Process the raw content blob using the speified content GUID processor
  *
  * This is the "object like" method. It should be more object like,
  * but for now, we'll just point to the old lib style "parse_data" - XOXO spiderr
  * @param         pMixed can be a string or a hash - if a string is given, it will be parsed without the use of cache
  * @param string  pMixed['data'] string to be parsed
  * @param int     pMixed['content_id'] content_id or the item to be parsed - required for caching and optimal parser performance
  * @param boolean pMixed['no_cache'] disable caching
  * @param string  pMixed['cache_extension'] cache to a separate file. useful for truncated displays of parsed content such as article front page
  * @param string pFormatGuid processor to use
  * @return string Formated data string
  */
 function parseData($pMixed = NULL, $pFormatGuid = NULL)
 {
     global $gLibertySystem, $gBitSystem, $gBitUser;
     // get the data into place
     if (empty($pMixed) && !empty($this->mInfo['data'])) {
         $parseHash = $this->mInfo;
     } elseif (is_array($pMixed)) {
         $parseHash = $pMixed;
         if (empty($parseHash['data'])) {
             $parseHash['data'] = '';
         }
     } else {
         $parseHash['data'] = $pMixed;
     }
     // sanitise parseHash a bit
     $parseHash['content_id'] = !empty($parseHash['content_id']) ? $parseHash['content_id'] : NULL;
     $parseHash['cache_extension'] = !empty($parseHash['cache_extension']) ? $parseHash['cache_extension'] : NULL;
     $parseHash['format_guid'] = !empty($parseHash['format_guid']) ? $parseHash['format_guid'] : $pFormatGuid;
     $parseHash['user_id'] = !empty($parseHash['user_id']) ? $parseHash['user_id'] : is_object($gBitUser) ? $gBitUser->mUserId : ANONYMOUS_USER_ID;
     // Ensure we have a format
     if (empty($parseHash['format_guid'])) {
         $parseHash['format_guid'] = $gBitSystem->getConfig('default_format', 'tikiwiki');
     }
     $ret = NULL;
     // Handle caching if it is enabled.
     if ($gBitSystem->isFeatureActive('liberty_cache') && !empty($parseHash['content_id']) && empty($parseHash['no_cache'])) {
         if ($cacheFile = LibertyContent::getCacheFile($parseHash['content_id'], $parseHash['cache_extension'])) {
             // Attempt to read cache file
             if (!($ret = LibertyContent::readCacheFile($cacheFile))) {
                 // failed to read from cache.
                 $parseAndCache = TRUE;
             } else {
                 // Note that we read from cache.
                 $this->mInfo['is_cached'] = TRUE;
             }
         }
     }
     // if $ret is empty, we haven't read anything from cache yet - we need to parse the raw data
     if (empty($ret) || !empty($parseAndCache)) {
         if (!empty($parseHash['data']) && $parseHash['format_guid']) {
             $replace = array();
             // extract and protect ~pp~...~/pp~ and ~np~...~/np~ sections
             parse_protect($parseHash['data'], $replace);
             // some few filters such as stencils need to be before the data plugins
             LibertyContent::filterData($parseHash['data'], $parseHash, 'preplugin');
             // this will handle all liberty data plugins like {code} and {attachment} usage in all formats
             parse_data_plugins($parseHash['data'], $replace, $this, $parseHash);
             // pre parse filter according to what we're parsing - split or full body
             $filter = empty($parseHash['split_parse']) ? 'parse' : 'split';
             LibertyContent::filterData($parseHash['data'], $parseHash, 'pre' . $filter);
             if ($func = $gLibertySystem->getPluginFunction($parseHash['format_guid'], 'load_function')) {
                 // get the beast parsed
                 if ($ret = $func($parseHash, $this)) {
                     // post parse filter
                     LibertyContent::filterData($ret, $parseHash, 'post' . $filter);
                     // before we cache we insert the protected sections back - currently this is even after the filters.
                     // this might not be ideal but it allows stuff like ~pp~{maketoc}~/pp~
                     $replace = array_reverse($replace);
                     foreach ($replace as $rep) {
                         $ret = str_replace($rep["key"], $rep["data"], $ret);
                     }
                     if (!empty($parseAndCache)) {
                         LibertyContent::writeCacheFile($cacheFile, $ret);
                     }
                 }
             }
         }
     }
     return $ret;
 }