Last active
October 29, 2015 02:24
-
-
Save atsu666/f0ad2f83182900b39ab1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadEntryFulltext($eid) | |
{ | |
$DB = DB::singleton(dsn()); | |
$SQL = SQL::newSelect('column'); | |
$SQL->addWhereOpr('column_entry_id', $eid); | |
$q = $SQL->get(dsn()); | |
$text = ''; | |
$meta = ''; | |
if ( $DB->query($q, 'fetch') and ($row = $DB->fetch($q)) ) { do { | |
if ( $row['column_align'] === 'hidden' ) continue; | |
$type = $row['column_type']; | |
if ( 'text' == $type ) { | |
$_text = $row['column_field_1']; | |
if ( 'markdown' == $row['column_field_2'] ) { | |
require_once LIB_DIR.'Markdown.php'; | |
$_text = Markdown($_text); | |
} | |
$text .= $_text.' '; | |
} else if ( 'custom' == $type ) { | |
$Custom = acmsUnserialize($row['column_field_6']); | |
foreach ( $Custom->listFields() as $f ) { | |
$text .= $Custom->get($f).' '; | |
} | |
} else { | |
$meta .= $row['column_field_1'].' '; | |
} | |
} while ( $row = $DB->fetch($q) ); } | |
$meta .= ACMS_RAM::entryTitle($eid).' '; | |
$SQL = SQL::newSelect('field'); | |
$SQL->addSelect('field_value'); | |
$SQL->addWhereOpr('field_search', 'on'); | |
$SQL->addWhereOpr('field_eid', $eid); | |
$q = $SQL->get(dsn()); | |
if ( $DB->query($q, 'fetch') and ($row = $DB->fetch($q)) ) { do { | |
$meta .= $row['field_value'].' '; | |
} while ( $row = $DB->fetch($q) ); } | |
$text = fulltextUnitData($text); | |
return preg_replace('@\s+@', ' ', strip_tags($text)) | |
."\x0d\x0a\x0a\x0d".preg_replace('@\s+@', ' ', strip_tags($meta)) | |
; | |
} | |
function saveFulltext($type, $id, $fulltext=null) | |
{ | |
$DB = DB::singleton(dsn()); | |
$SQL = SQL::newDelete('fulltext'); | |
$SQL->addWhereOpr('fulltext_'.$type, $id); | |
if ( $type !== 'bid' ) { | |
$SQL->addWhereOpr('fulltext_blog_id', BID); | |
} | |
$DB->query($SQL->get(dsn()), 'exec'); | |
if ( !empty($fulltext) ) { | |
$SQL = SQL::newInsert('fulltext'); | |
$SQL->addInsert('fulltext_value', $fulltext); | |
if ( config('ngram') ) { | |
$SQL->addInsert('fulltext_ngram', | |
preg_replace('@( |\s)+@', ' ', join(' ', ngram(strip_tags($fulltext), config('ngram')))) | |
); | |
} | |
$SQL->addInsert('fulltext_'.$type, $id); | |
$SQL->addInsert('fulltext_blog_id', BID); | |
$DB->query($SQL->get(dsn()), 'exec'); | |
} | |
return true; | |
} | |
function fulltextUnitData($text) | |
{ | |
return str_replace(':acms_unit_delimiter:', '', $text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment