/** * Logging of search terms for improvements * * @param string $searchterm Search term * @return void */ public function logSearchTerm($searchterm) { if (PMF_String::strlen($searchterm) == 0) { return; } $date = new DateTime(); $query = sprintf("\n INSERT INTO\n %s\n (id, lang, searchterm, searchdate)\n VALUES\n (%d, '%s', '%s', '%s')", $this->_table, $this->db->nextID($this->_table, 'id'), $this->language, $this->db->escapeString($searchterm), $date->format('Y-m-d H:i:s')); $this->db->query($query); }
/** * Draw the Text * * @return resource */ private function drawText() { $len = PMF_String::strlen($this->code); $w1 = 15; $w2 = $this->width / ($len + 1); for ($p = 0; $p < $len; $p++) { $letter = $this->code[$p]; if (count($this->fonts) > 0) { $font = $this->fonts[rand(0, count($this->fonts) - 1)]; } $size = rand(20, $this->height / 2.2); $rotation = rand(-23, 23); $y = rand($size + 3, $this->height - 5); // $w1 += rand(- $this->width / 90, $this->width / 40 ); $x = $w1 + $w2 * $p; $c1 = array(); // fore char color $c2 = array(); // back char color do { $c1['r'] = mt_rand(30, 199); } while ($c1['r'] == $this->_backgroundColor['r']); do { $c1['g'] = mt_rand(30, 199); } while ($c1['g'] == $this->_backgroundColor['g']); do { $c1['b'] = mt_rand(30, 199); } while ($c1['b'] == $this->_backgroundColor['b']); $c1 = imagecolorallocate($this->img, $c1['r'], $c1['g'], $c1['b']); do { $c2['r'] = $c1['r'] < 100 ? $c1['r'] * 2 : mt_rand(30, 199); } while ($c2['r'] == $this->_backgroundColor['r'] && $c2['r'] == $c1['r']); do { $c2['g'] = $c1['g'] < 100 ? $c1['g'] * 2 : mt_rand(30, 199); } while ($c2['g'] == $this->_backgroundColor['g'] && $c2['g'] == $c1['g']); do { $c2['b'] = $c1['b'] < 100 ? $c1['b'] * 2 : mt_rand(30, 199); } while ($c2['b'] == $this->_backgroundColor['b'] && $c2['b'] == $c1['b']); $c2 = imagecolorallocate($this->img, $c2['r'], $c2['g'], $c2['b']); // Add the letter if (function_exists('imagettftext') && count($this->fonts) > 0) { imagettftext($this->img, $size, $rotation, $x + 2, $y, $c2, $font, $letter); imagettftext($this->img, $size, $rotation, $x + 1, $y + 1, $c2, $font, $letter); imagettftext($this->img, $size, $rotation, $x, $y - 2, $c1, $font, $letter); } else { $size = 5; $c3 = imagecolorallocate($this->img, 0, 0, 255); $x = 20; $y = 12; $s = 30; imagestring($this->img, $size, $x + 1 + $s * $p, $y + 1, $letter, $c3); imagestring($this->img, $size, $x + $s * $p, $y, $letter, $c1); } } return $this->img; }
$captcha->setSessionId($sids); if (!is_null($showCaptcha)) { $captcha->showCaptchaImg(); exit; } try { $faqsession->userTracking('new_entry', 0); } catch (PMF_Exception $e) { // @todo handle the exception } // Get possible user input $selectedQuestion = PMF_Filter::filterInput(INPUT_GET, 'question', FILTER_VALIDATE_INT); $selectedCategory = PMF_Filter::filterInput(INPUT_GET, 'cat', FILTER_VALIDATE_INT); $question = $readonly = ''; if (!is_null($selectedQuestion)) { $oQuestion = $faq->getQuestion($selectedQuestion); $question = $oQuestion['question']; if (PMF_String::strlen($question)) { $readonly = ' readonly'; } } $category->buildTree(); $categoryHelper = new PMF_Helper_Category(); $categoryHelper->setCategory($category); $captchaHelper = new PMF_Helper_Captcha($faqConfig); // Enable/Disable WYSIWYG editor if ($faqConfig->get('main.enableWysiwygEditorFrontend')) { $tpl->parseBlock('writeContent', 'enableWysiwygEditor', array('currentTimestamp' => $_SERVER['REQUEST_TIME'])); } $tpl->parse('writeContent', array('msgNewContentHeader' => $PMF_LANG['msgNewContentHeader'], 'msgNewContentAddon' => $PMF_LANG['msgNewContentAddon'], 'lang' => $Language->getLanguage(), 'openQuestionID' => $selectedQuestion, 'defaultContentMail' => $user instanceof PMF_User_CurrentUser ? $user->getUserData('email') : '', 'defaultContentName' => $user instanceof PMF_User_CurrentUser ? $user->getUserData('display_name') : '', 'msgNewContentName' => $PMF_LANG['msgNewContentName'], 'msgNewContentMail' => $PMF_LANG['msgNewContentMail'], 'msgNewContentCategory' => $PMF_LANG['msgNewContentCategory'], 'printCategoryOptions' => $categoryHelper->renderOptions($selectedCategory), 'msgNewContentTheme' => $PMF_LANG['msgNewContentTheme'], 'readonly' => $readonly, 'printQuestion' => $question, 'msgNewContentArticle' => $PMF_LANG['msgNewContentArticle'], 'msgNewContentKeywords' => $PMF_LANG['msgNewContentKeywords'], 'msgNewContentLink' => $PMF_LANG['msgNewContentLink'], 'captchaFieldset' => $captchaHelper->renderCaptcha($captcha, 'add', $PMF_LANG['msgCaptcha'], $auth), 'msgNewContentSubmit' => $PMF_LANG['msgNewContentSubmit'])); $tpl->merge('writeContent', 'index');
/** * The main search function for the full text search * * TODO: add filter for (X)HTML tag names and attributes! * * @param string Text/Number (solution id) * @param string '%' to avoid any category filtering * @param boolean true to search over all languages * @param boolean true to disable the results paging * @param boolean true to use it for Instant Response * @return string * @access public * @author Thorsten Rinne <*****@*****.**> * @author Matteo Scaramuccia <*****@*****.**> * @author Adrianna Musiol <*****@*****.**> * @since 2002-09-16 */ function searchEngine($searchterm, $cat = '%', $allLanguages = true, $hasMore = false, $instantRespnse = false) { global $sids, $PMF_LANG, $plr, $LANGCODE, $faq, $current_user, $current_groups, $categoryLayout; $_searchterm = PMF_htmlentities(stripslashes($searchterm), ENT_QUOTES, 'utf-8'); $seite = 1; $output = ''; $num = 0; $searchItems = array(); $langs = true == $allLanguages ? '&langs=all' : ''; $seite = PMF_Filter::filterInput(INPUT_GET, 'seite', FILTER_VALIDATE_INT, 1); $db = PMF_Db::getInstance(); $faqconfig = PMF_Configuration::getInstance(); $result = getSearchData(htmlentities($searchterm, ENT_COMPAT, 'utf-8'), true, $cat, $allLanguages); $num = $db->numRows($result); if (0 == $num) { $output = $PMF_LANG['err_noArticles']; } $confPerPage = $faqconfig->get('main.numberOfRecordsPerPage'); $pages = ceil($num / $confPerPage); $last = $seite * $confPerPage; $first = $last - $confPerPage; if ($last > $num) { $last = $num; } if ($num > 0) { $output .= '<p>' . $plr->GetMsg('plmsgSearchAmount', $num); if ($hasMore && $pages > 1) { $output .= sprintf($PMF_LANG['msgInstantResponseMaxRecords'], $confPerPage); } $output .= "</p>\n"; if (!$hasMore && $pages > 1) { $output .= "<p><strong>" . $PMF_LANG["msgPage"] . $seite . " " . $PMF_LANG["msgVoteFrom"] . " " . $plr->GetMsg('plmsgPagesTotal', $pages) . "</strong></p>"; } $output .= "<ul class=\"phpmyfaq_ul\">\n"; $faqUser = new PMF_Faq_User(); $faqGroup = new PMF_Faq_Group(); $counter = $displayedCounter = 0; while (($row = $db->fetchObject($result)) && $displayedCounter < $confPerPage) { $counter++; if ($counter <= $first) { continue; } $displayedCounter++; $b_permission = false; //Groups Permission Check if ($faqconfig->get('main.permLevel') == 'medium') { $perm_group = $faqGroup->fetch($row->id); foreach ($current_groups as $value) { if ($value == $perm_group->group_id) { $b_permission = true; } } } if ($faqconfig->get('main.permLevel') == 'basic' || $b_permission) { $perm_user = $faqUser->fetch($row->id); foreach ($perm_user as $value) { if ($value == -1) { $b_permission = true; break; } elseif ((int) $value == $current_user) { $b_permission = true; break; } else { $b_permission = false; } } } if ($b_permission) { $rubriktext = $categoryLayout->renderBreadcrumb(array($row->category_id)); $thema = chopString($row->thema, 15); $content = chopString(strip_tags($row->content), 25); $searchterm = str_replace(array('^', '.', '?', '*', '+', '{', '}', '(', ')', '[', ']', '"'), '', $searchterm); $searchterm = preg_quote($searchterm, '/'); $searchItems = explode(' ', $searchterm); if (PMF_String::strlen($searchItems[0]) > 1) { foreach ($searchItems as $item) { if (PMF_String::strlen($item) > 2) { $thema = PMF_String::preg_replace_callback('/' . '(' . $item . '="[^"]*")|' . '((href|src|title|alt|class|style|id|name|dir|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup)="[^"]*' . $item . '[^"]*")|' . '(' . $item . ')' . '/mis', "highlight_no_links", $thema); $content = PMF_String::preg_replace_callback('/' . '(' . $item . '="[^"]*")|' . '((href|src|title|alt|class|style|id|name|dir|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup)="[^"]*' . $item . '[^"]*")|' . '(' . $item . ')' . '/mis', "highlight_no_links", $content); } } } // Print the link to the faq record $url = sprintf('?%saction=artikel&cat=%d&id=%d&artlang=%s&highlight=%s', $sids, $row->category_id, $row->id, $row->lang, urlencode($_searchterm)); if ($instantRespnse) { $currentUrl = PMF_Link::getSystemRelativeUri('ajaxresponse.php') . 'index.php'; } else { $currentUrl = PMF_Link::getSystemRelativeUri(); } $oLink = new PMF_Link($currentUrl . $url); $oLink->itemTitle = $row->thema; $oLink->text = $thema; $oLink->tooltip = $row->thema; $output .= '<li><strong>' . $rubriktext . '</strong>: ' . $oLink->toHtmlAnchor() . '<br />' . '<div class="searchpreview"><strong>' . $PMF_LANG['msgSearchContent'] . '</strong> ' . $content . '...</div>' . '<br /></li>' . "\n"; } } $output .= "</ul>\n"; } else { $output = $PMF_LANG["err_noArticles"]; } if (!$hasMore && $num > $confPerPage) { if ($faqconfig->get('main.enableRewriteRules')) { $baseUrl = sprintf("search.html?search=%s&seite=%d%s&searchcategory=%d", urlencode($_searchterm), $seite, $langs, $cat); } else { $baseUrl = PMF_Link::getSystemRelativeUri() . '?' . (empty($sids) ? '' : "{$sids}&") . 'action=search&search=' . urlencode($_searchterm) . '&seite=' . $seite . $langs . "&searchcategory=" . $cat; } $options = array('baseUrl' => $baseUrl, 'total' => $num, 'perPage' => $confPerPage, 'pageParamName' => 'seite', 'nextPageLinkTpl' => '<a href="{LINK_URL}">' . $PMF_LANG["msgNext"] . '</a>', 'prevPageLinkTpl' => '<a href="{LINK_URL}">' . $PMF_LANG["msgPrevious"] . '</a>', 'layoutTpl' => '<p align="center"><strong>{LAYOUT_CONTENT}</strong></p>'); $pagination = new PMF_Pagination($options); $output .= $pagination->render(); } return $output; }
/** * Renders the list of the most popular search terms * * @param array $mostPopularSearches Array with popular search terms * * @return string */ public function renderMostPopularSearches(array $mostPopularSearches) { $html = '<ul class="mostpopularsearcheslist">'; foreach ($mostPopularSearches as $searchItem) { if (PMF_String::strlen($searchItem['searchterm']) > 0) { $html .= sprintf('<li><a href="?search=%s&submit=Search&action=search">%s</a> (%dx)</li>', urlencode($searchItem['searchterm']), $searchItem['searchterm'], $searchItem['number']); } } return $html . '</ul>'; }
} $faqvisits = PMF_Visits::getInstance(); $faqvisits->logViews($faq->faqRecord['id']); $content = $faq->faqRecord['content']; $thema = $faq->getRecordTitle($faq->faqRecord['id']); // Add Glossary entries $content = $oGlossary->insertItemsIntoContent($content); $thema = $oGlossary->insertItemsIntoContent($thema); // Set the path of the current category $categoryName = $categoryLayout->renderBreadcrumb($categoryPath); $changeLanguagePath = PMF_Link::getSystemRelativeUri() . sprintf('?%saction=artikel&cat=%d&id=%d&artlang=%s', $sids, $currentCategory, $id, $LANGCODE); $oLink = new PMF_Link($changeLanguagePath); $oLink->itemTitle = $faq->getRecordTitle($record_id, false); $changeLanguagePath = $oLink->toString(); $highlight = PMF_Filter::filterInput(INPUT_GET, 'highlight', FILTER_SANITIZE_STRIPPED); if (!is_null($highlight) && $highlight != "/" && $highlight != "<" && $highlight != ">" && PMF_String::strlen($highlight) > 3) { $highlight = str_replace("'", "´", $highlight); $highlight = str_replace(array('^', '.', '?', '*', '+', '{', '}', '(', ')', '[', ']'), '', $highlight); $highlight = preg_quote($highlight, '/'); $searchItems = explode(' ', $highlight); $attributes = array('href', 'src', 'title', 'alt', 'class', 'style', 'id', 'name', 'face', 'size', 'dir', 'onclick', 'ondblclick', 'onmousedown', 'onmouseup', 'onmouseover', 'onmousemove', 'onmouseout', 'onkeypress', 'onkeydown', 'onkeyup'); foreach ($searchItems as $item) { $thema = PMF_String::preg_replace_callback('/' . '(' . $item . '="[^"]*")|' . '((' . implode('|', $attributes) . ')="[^"]*' . $item . '[^"]*")|' . '(\\s+)(' . $item . ')(\\s+)' . '/mis', 'highlight_no_links', $thema); $content = PMF_String::preg_replace_callback('/' . '(' . $item . '="[^"]*")|' . '((' . implode('|', $attributes) . ')="[^"]*' . $item . '[^"]*")|' . '(\\s+)(' . $item . ')(\\s+)' . '/mis', 'highlight_no_links', $content); } } // Hack: Apply the new SEO schema to those HTML anchors to // other faq records (Internal Links) added with WYSIWYG Editor: // href="index.php?action=artikel&cat=NNN&id=MMM&artlang=XYZ" // Search for href attribute links $oLnk->resetPool();
// a. We use plain PMF urls w/o any SEO schema $link = str_replace($_SERVER['SCRIPT_NAME'], '/index.php', $item['url']); // b. We use SEO PMF urls if (PMF_SITEMAP_GOOGLE_USE_SEO) { if (isset($item['thema'])) { $oL = new PMF_Link($link); $oL->itemTitle = $item['thema']; $link = $oL->toString(); } } $sitemap .= buildSitemapNode(PMF_Link::getSystemUri('/sitemap.google.php') . $link, PMF_Date::createISO8601Date($item['date']), PMF_SITEMAP_GOOGLE_CHANGEFREQ_DAILY, $priority); } $sitemap .= '</urlset>'; $getgezip = PMF_Filter::filterInput(INPUT_GET, PMF_SITEMAP_GOOGLE_GET_GZIP, FILTER_VALIDATE_INT); if (!is_null($getgezip) && 1 == $getgezip) { if (function_exists('gzencode')) { $sitemapGz = gzencode($sitemap); header('Content-Type: application/x-gzip'); header('Content-Disposition: attachment; filename="' . PMF_SITEMAP_GOOGLE_FILENAME_GZ . '"'); header('Content-Length: ' . strlen($sitemapGz)); print $sitemapGz; } else { PMF_Helper_Http::getInstance()->printHTTPStatus404(); } } else { header('Content-Type: text/xml'); header('Content-Disposition: inline; filename="' . PMF_SITEMAP_GOOGLE_FILENAME . '"'); header('Content-Length: ' . PMF_String::strlen($sitemap)); print $sitemap; } $db->dbclose();
$record_ids = $tagging->getRecordsByTagId($inputTag); $printResult = $faq->showAllRecordsByIds($record_ids); } // // Handle the full text search stuff // if (!is_null($inputSearchTerm) || !is_null($search)) { if (!is_null($inputSearchTerm)) { $inputSearchTerm = $db->escapeString(strip_tags($inputSearchTerm)); } if (!is_null($search)) { $inputSearchTerm = $db->escapeString(strip_tags($search)); } $printResult = searchEngine($inputSearchTerm, $inputCategory, $allLanguages); $inputSearchTerm = stripslashes($inputSearchTerm); $faqsearch->logSearchTerm($inputSearchTerm); } // Change a little bit the $searchCategory value; $inputCategory = '%' == $inputCategory ? 0 : $inputCategory; $faqsession->userTracking('fulltext_search', $inputSearchTerm); $openSearchLink = sprintf('<a class="searchplugin" href="#" onclick="window.external.AddSearchProvider(\'%s/opensearch.php\');">%s</a>', PMF_Link::getSystemUri('/index.php'), $PMF_LANG['opensearch_plugin_install']); $mostPopularSearches = ''; $mostPopularSearchData = $faqsearch->getMostPopularSearches($faqconfig->get('main.numberSearchTerms')); foreach ($mostPopularSearchData as $searchItem) { if (PMF_String::strlen($searchItem['searchterm']) > 0) { $mostPopularSearches .= sprintf('<li><a href="?search=%s&submit=Search&action=search">%s</a> (%dx)</li>', urlencode($searchItem['searchterm']), $searchItem['searchterm'], $searchItem['number']); } } $categoryLayout = new PMF_Category_Layout(new PMF_Category_Tree_Helper(new PMF_Category_Tree($categoryData))); $tpl->processTemplate('writeContent', array('msgSearch' => $tagSearch ? $PMF_LANG['msgTagSearch'] : $PMF_LANG['msgSearch'], 'searchString' => PMF_String::htmlspecialchars($inputSearchTerm, ENT_QUOTES, 'utf-8'), 'searchOnAllLanguages' => $PMF_LANG['msgSearchOnAllLanguages'], 'checkedAllLanguages' => $allLanguages ? ' checked="checked"' : '', 'selectCategories' => $PMF_LANG['msgSelectCategories'], 'allCategories' => $PMF_LANG['msgAllCategories'], 'printCategoryOptions' => $categoryLayout->renderOptions(array($inputCategory)), 'writeSendAdress' => '?' . $sids . 'action=search', 'msgSearchWord' => $PMF_LANG['msgSearchWord'], 'printResult' => $printResult, 'openSearchLink' => $openSearchLink, 'msgMostPopularSearches' => $PMF_LANG['msgMostPopularSearches'], 'printMostPopularSearches' => '<ul class="phpmyfaq_ul">' . $mostPopularSearches . '</ul>')); $tpl->includeTemplate('writeContent', 'index');
/** * Returns the timestamp of a tracking file * * @param string $file Filename * @param boolean $endOfDay End of day? * * @return integer */ public static function getTrackingFileDate($file, $endOfDay = false) { if (PMF_String::strlen($file) >= 16) { $day = PMF_String::substr($file, 8, 2); $month = PMF_String::substr($file, 10, 2); $year = PMF_String::substr($file, 12, 4); if (!$endOfDay) { $time = mktime(0, 0, 0, $month, $day, $year); } else { $time = mktime(23, 59, 59, $month, $day, $year); } return $time; } else { return -1; } }
// @todo: Start transaction for better recovery if something really bad happens $dat = trim(PMF_String::substr($dat, 11)); $tbl = explode(' ', $dat); $num = count($tbl); for ($h = 0; $h < $num; $h++) { $mquery[] = 'DELETE FROM ' . $tbl[$h]; } $ok = 1; } if ($ok == 1) { $table_prefix = ''; printf("<p>%s</p>\n", $PMF_LANG['ad_csv_prepare']); while ($dat = fgets($handle, 65536)) { $dat = trim($dat); $backup_prefix_pattern = "-- pmftableprefix:"; $backup_prefix_pattern_len = PMF_String::strlen($backup_prefix_pattern); if (PMF_String::substr($dat, 0, $backup_prefix_pattern_len) == $backup_prefix_pattern) { $table_prefix = trim(PMF_String::substr($dat, $backup_prefix_pattern_len)); } if (PMF_String::substr($dat, 0, 2) != '--' && $dat != '') { $mquery[] = trim(PMF_String::substr($dat, 0, -1)); } } $k = 0; $g = 0; printf("<p>%s</p>\n", $PMF_LANG['ad_csv_process']); $num = count($mquery); $kg = ''; for ($i = 0; $i < $num; $i++) { $mquery[$i] = alignTablePrefix($mquery[$i], $table_prefix, SQLPREFIX); $kg = $db->query($mquery[$i]);
/** * Saves all tags from a FAQ record * * @param integer $record_id Record ID * @param array $tags Array of tags */ public function saveTags($record_id, $tags) { if (!is_array($tags)) { return false; } $current_tags = $this->getAllTags(); // Delete all tag references for the faq record if (count($tags) > 0) { $this->deleteTagsFromRecordId($record_id); } // Store tags and references for the faq record foreach ($tags as $tagging_name) { $tagging_name = trim($tagging_name); if (PMF_String::strlen($tagging_name) > 0) { if (!in_array(PMF_String::strtolower($tagging_name), array_map(array('PMF_String', 'strtolower'), $current_tags))) { // Create the new tag $new_tagging_id = $this->db->nextID(SQLPREFIX . 'faqtags', 'tagging_id'); $query = sprintf("\n INSERT INTO\n %sfaqtags\n (tagging_id, tagging_name)\n VALUES\n (%d, '%s')", SQLPREFIX, $new_tagging_id, $tagging_name); $this->db->query($query); // Add the tag reference for the faq record $query = sprintf("\n INSERT INTO\n %sfaqdata_tags\n (record_id, tagging_id)\n VALUES\n (%d, %d)", SQLPREFIX, $record_id, $new_tagging_id); $this->db->query($query); } else { // Add the tag reference for the faq record $query = sprintf("\n INSERT INTO\n %sfaqdata_tags\n (record_id, tagging_id)\n VALUES\n (%d, %d)", SQLPREFIX, $record_id, array_search(PMF_String::strtolower($tagging_name), array_map(array('PMF_String', 'strtolower'), $current_tags))); $this->db->query($query); } } } return true; }
/** * schreiben eines Textes * * Diese Funktion schreibt einen Text * * @param string $textString * @return string $textString * @author David Sauer <*****@*****.**> * @since 2005-07-21 */ function text(&$textString) { if (PMF_String::preg_match('/((<)(.*)(>)?)/', $textString, $matches)) { if (PMF_String::preg_match('/^((?!<)(.*?))((<(\\/?(.*)?)>)+)/', $textString, $matches) == true) { $textStringPart = PMF_String::substr($textString, 0, PMF_String::strlen($matches[1])); $textString = PMF_String::substr($textString, PMF_String::strlen($matches[1])); } else { $match = PMF_String::preg_match('/^(<\\/?(.*)>)/', $textString, $matchesRemainder); if ($match) { $textString = PMF_String::substr($textString, PMF_String::strlen($matchesRemainder[0])); $textStringPart = ''; } else { $textStringPart = ''; $textString = PMF_String::substr($textString, PMF_String::strlen($textString)); } } } else { $textStringPart = $textString; $textString = PMF_String::substr($textString, PMF_String::strlen($textString)); } if (!empty($textStringPart)) { $this->xmlContent .= '<para>'; $this->xmlContent .= $textStringPart; $this->xmlContent .= '</para>'; } }
// b. We use SEO PMF urls if (PMF_SITEMAP_GOOGLE_USE_SEO) { if (isset($item['thema'])) { $oL = new PMF_Link($link, $faqConfig); $oL->itemTitle = $item['thema']; $link = $oL->toString(); } } $sitemap .= buildSitemapNode($faqConfig->get('main.referenceURL') . $link, PMF_Date::createIsoDate($item['date'], DATE_W3C), PMF_SITEMAP_GOOGLE_CHANGEFREQ_DAILY, $priority); } $sitemap .= '</urlset>'; $response = new Response(); $getgezip = PMF_Filter::filterInput(INPUT_GET, PMF_SITEMAP_GOOGLE_GET_GZIP, FILTER_VALIDATE_INT); if (!is_null($getgezip) && 1 == $getgezip) { if (function_exists('gzencode')) { $sitemapGz = gzencode($sitemap); $response->headers->set('Content-Type', 'application/x-gzip'); $response->headers->set('Content-Disposition', 'attachment; filename="' . PMF_SITEMAP_GOOGLE_FILENAME_GZ . '"'); $response->headers->set('Content-Length', strlen($sitemapGz)); $response->setContent($sitemapGz); } else { $response->setStatusCode(404); } } else { $response->headers->set('Content-Type', 'text/xml'); $response->headers->set('Content-Disposition', 'inline; filename="' . PMF_SITEMAP_GOOGLE_FILENAME . '"'); $response->headers->set('Content-Length', PMF_String::strlen($sitemap)); $response->setContent($sitemap); } $response->send(); $faqConfig->getDb()->close();
/** * This converts an UTF-8 encoded string to its UCS-4 representation * By talking about UCS-4 "strings" we mean arrays of 32bit integers representing * each of the "chars". This is due to PHP not being able to handle strings with * bit depth different from 8. This apllies to the reverse method _ucs4_to_utf8(), too. * The following UTF-8 encodings are supported: * bytes bits representation * 1 7 0xxxxxxx * 2 11 110xxxxx 10xxxxxx * 3 16 1110xxxx 10xxxxxx 10xxxxxx * 4 21 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx * 5 26 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx * 6 31 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx * Each x represents a bit that can be used to store character data. * The five and six byte sequences are part of Annex D of ISO/IEC 10646-1:2000 * @param string $input * @return string */ private function _utf8_to_ucs4($input) { $output = array(); $out_len = 0; $inp_len = PMF_String::strlen($input); $mode = 'next'; $test = 'none'; for ($k = 0; $k < $inp_len; ++$k) { $v = ord($input[$k]); // Extract byte from input string if ($v < 128) { // We found an ASCII char - put into stirng as is $output[$out_len] = $v; ++$out_len; if ('add' == $mode) { $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte ' . $k); return false; } continue; } if ('next' == $mode) { // Try to find the next start byte; determine the width of the Unicode char $start_byte = $v; $mode = 'add'; $test = 'range'; if ($v >> 5 == 6) { // &110xxxxx 10xxxxx $next_byte = 0; // Tells, how many times subsequent bitmasks must rotate 6bits to the left $v = $v - 192 << 6; } elseif ($v >> 4 == 14) { // &1110xxxx 10xxxxxx 10xxxxxx $next_byte = 1; $v = $v - 224 << 12; } elseif ($v >> 3 == 30) { // &11110xxx 10xxxxxx 10xxxxxx 10xxxxxx $next_byte = 2; $v = $v - 240 << 18; } elseif ($v >> 2 == 62) { // &111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx $next_byte = 3; $v = $v - 248 << 24; } elseif ($v >> 1 == 126) { // &1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx $next_byte = 4; $v = $v - 252 << 30; } else { $this->_error('This might be UTF-8, but I don\'t understand it at byte ' . $k); return false; } if ('add' == $mode) { $output[$out_len] = (int) $v; ++$out_len; continue; } } if ('add' == $mode) { if (!$this->_allow_overlong && $test == 'range') { $test = 'none'; if ($v < 0xa0 && $start_byte == 0xe0 || $v < 0x90 && $start_byte == 0xf0 || $v > 0x8f && $start_byte == 0xf4) { $this->_error('Bogus UTF-8 character detected (out of legal range) at byte ' . $k); return false; } } if ($v >> 6 == 2) { // Bit mask must be 10xxxxxx $v = $v - 128 << $next_byte * 6; $output[$out_len - 1] += $v; --$next_byte; } else { $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte ' . $k); return false; } if ($next_byte < 0) { $mode = 'next'; } } } // for return $output; }
/** * Get string character count * * @param string $str String * * @return int */ public static function strlen($str) { return self::$instance->strlen($str); }
/** * Align the prefix of the table name used in the PMF backup file, * from the (old) value of the system upon which the backup was performed * to the (new) prefix of the system upon which the backup will be restored. * This alignment will be perfomed ONLY upon those given SQL queries starting * with the given pattern. * * @param string $query * @param string $startPattern * @param string $oldValue * @param string $newValue * * @return string */ private static function alignTablePrefixByPattern($query, $startPattern, $oldValue, $newValue) { $return = $query; $matches = []; PMF_String::preg_match_all("/^" . $startPattern . "\\s+(\\w+)(\\s+|\$)/i", $query, $matches); if (isset($matches[1][0])) { $oldTableFullName = $matches[1][0]; $newTableFullName = $newValue . PMF_String::substr($oldTableFullName, PMF_String::strlen($oldValue)); $return = str_replace($oldTableFullName, $newTableFullName, $query); } return $return; }
/** * Filter some text cutting out all non words and stop words * * @param string $input text to filter * * @return string */ public function clean($input) { $words = explode(' ', ereg_replace('[[:punct:][:space:]]+', ' ', $input)); $stop_words = $this->getByLang(null, true); $retval = array(); foreach ($words as $word) { $word = PMF_String::strtolower($word); if (!is_numeric($word) && 1 < PMF_String::strlen($word) && !in_array($word, $stop_words) && !in_array($word, $retval)) { $retval[] = $word; } } return $retval; }
/** * Macht an den String nen / dran, falls keiner da ist * @@ Bastian, 2002-01-06 */ function EndSlash($string) { if (PMF_String::substr($string, PMF_String::strlen($string) - 1, 1) != "/") { $string .= "/"; } return $string; }
$metaDescription = PMF_Utils::makeShorterText(strip_tags($faqData['content']), 12); } } // // Handle the Tagging ID // $tag_id = PMF_Filter::filterInput(INPUT_GET, 'tagging_id', FILTER_VALIDATE_INT); if (!is_null($tag_id)) { $title = ' - ' . $oTag->getTagNameById($tag_id); $keywords = ''; } // // Handle the SiteMap // $letter = PMF_Filter::filterInput(INPUT_GET, 'letter', FILTER_SANITIZE_STRIPPED); if (!is_null($letter) && 1 == PMF_String::strlen($letter)) { $title = ' - ' . $letter . '...'; $keywords = $letter; } // // Found a category ID? // $cat = PMF_Filter::filterInput(INPUT_GET, 'cat', FILTER_VALIDATE_INT, 0); $cat_from_id = -1; $categoryPath = array(0); if (is_numeric($id) && $id > 0) { $categoryRelations = new PMF_Category_Relations(); foreach ($categoryRelations->fetchAll() as $relation) { if ($relation->record_id == $id) { $cat_from_id = $relation->category_id; break;
/** * Gets the main categories and write them in an array * * @param string $categories Array of parent category ids * @param boolean $parent_id Only top level categories? * * @return array */ public function getCategories($categories, $parent_id = true) { $_query = ''; $query = sprintf(' SELECT id, lang, parent_id, name, description, user_id FROM %sfaqcategories WHERE ', PMF_Db::getTablePrefix()); if (true == $parent_id) { $query .= 'parent_id = 0'; } foreach (explode(',', $categories) as $cats) { $_query .= ' OR parent_id = ' . $cats; } if (false == $parent_id && 0 < PMF_String::strlen($_query)) { $query .= PMF_String::substr($_query, 4); } if (isset($this->language) && preg_match("/^[a-z\\-]{2,}\$/", $this->language)) { $query .= " AND lang = '" . $this->language . "'"; } $query .= " ORDER BY id"; $result = $this->_config->getDb()->query($query); while ($row = $this->_config->getDb()->fetchArray($result)) { $this->categories[$row['id']] = $row; } return $this->categories; }
/** * Clean up a filename: if anything goes wrong, an empty string will be returned * * @param string $filename Filename * * @return string */ private static function _basicFilenameClean($filename) { global $denyUploadExts; // Remove the magic quotes if enabled $filename = ini_get('magic_quotes_gpc') ? stripslashes($filename) : $filename; $path_parts = pathinfo($filename); // We need a filename without any path info if ($path_parts['basename'] !== $filename) { return ''; } // We need a filename with at least 1 chars plus the optional extension if (isset($path_parts['extension']) && $path_parts['basename'] == '.' . $path_parts['extension']) { return ''; } if (!isset($path_parts['extension']) && PMF_String::strlen($path_parts['basename']) == 0) { return ''; } // Deny some extensions (see inc/constants.php), if any if (!isset($path_parts['extension'])) { $path_parts['extension'] = ''; } if (count($denyUploadExts) > 0) { if (in_array(strtolower($path_parts['extension']), $denyUploadExts)) { return ''; } } // Clean the file to remove some chars depending on the server OS // 0. main/rfc1867.c: rfc1867_post_handler removes any char before the last occurence of \/ // 1. Besides \/ on Windows: :*?"<>| if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $reservedChars = array(':', '*', '?', '"', '<', '>', "'", '|'); $filename = str_replace($reservedChars, '_', $filename); } return $filename; }
/** * Bastelt aus den Dateinamen des Tracking einen Timestamp | @@ Bastian, 2002-01-05 * Last Update: @@ Thorsten, 2002-09-19 * Last Update: @@ Matteo, 2006-06-13 */ function FileToDate($file, $endOfDay = false) { if (PMF_String::strlen($file) >= 16) { $tag = PMF_String::substr($file, 8, 2); $mon = PMF_String::substr($file, 10, 2); $yea = PMF_String::substr($file, 12, 4); if (!$endOfDay) { $tim = mktime(0, 0, 0, $mon, $tag, $yea); } else { $tim = mktime(23, 59, 59, $mon, $tag, $yea); } return $tim; } else { return -1; } }