X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FItemContent.php;h=5268c49e953a6fa7b52bc4f7218bc2ddf27aea79;hb=8c328a3c60d3bcbc8b091158383bf829064d2c9c;hp=68b42af92857b42b6de41af5703f76c729637fab;hpb=b543ee8ac78168328c7a7f2d725ee01bb333e941;p=friendica.git diff --git a/src/Model/ItemContent.php b/src/Model/ItemContent.php index 68b42af928..5268c49e95 100644 --- a/src/Model/ItemContent.php +++ b/src/Model/ItemContent.php @@ -1,20 +1,79 @@ . + * */ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Content\Text; -use Friendica\Core\PConfig; +use Friendica\Content\Text\BBCode; use Friendica\Core\Protocol; +use Friendica\Database\DBA; +use Friendica\DI; -class ItemContent extends BaseObject +class ItemContent { /** - * @brief Convert a message into plaintext for connectors to other networks + * Search posts for given content + * + * @param string $search + * @param integer $uid + * @param integer $start + * @param integer $limit + * @param integer $last_uriid + * @return array + */ + public static function getURIIdListBySearch(string $search, int $uid = 0, int $start = 0, int $limit = 100, int $last_uriid = 0) + { + $condition = ["`uri-id` IN (SELECT `uri-id` FROM `item-content` WHERE MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE)) + AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid]; + + if (!empty($last_uriid)) { + $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $last_uriid]); + } + + $params = [ + 'order' => ['uri-id' => true], + 'group_by' => ['uri-id'], + 'limit' => [$start, $limit] + ]; + + $tags = DBA::select('item', ['uri-id'], $condition, $params); + + $uriids = []; + while ($tag = DBA::fetch($tags)) { + $uriids[] = $tag['uri-id']; + } + DBA::close($tags); + + return $uriids; + } + + public static function countBySearch(string $search, int $uid = 0) + { + $condition = ["`uri-id` IN (SELECT `uri-id` FROM `item-content` WHERE MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE)) + AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid]; + return DBA::count('item', $condition); + } + + /** + * Convert a message into plaintext for connectors to other networks * * @param array $item The message array that is about to be posted * @param int $limit The maximum number of characters when posting to that network @@ -27,7 +86,7 @@ class ItemContent extends BaseObject * @see \Friendica\Content\Text\BBCode::getAttachedData * */ - public static function getPlaintextPost($item, $limit = 0, $includedlinks = false, $htmlmode = 2, $target_network = '') + public static function getPlaintextPost($item, $limit = 0, $includedlinks = false, $htmlmode = BBCode::API, $target_network = '') { // Remove hashtags $URLSearchString = '^\[\]'; @@ -65,11 +124,11 @@ class ItemContent extends BaseObject } } else {// Try to guess the correct target network switch ($htmlmode) { - case 8: + case BBCode::TWITTER: $abstract = Text\BBCode::getAbstract($item['body'], Protocol::TWITTER); break; - case 7: + case BBCode::OSTATUS: $abstract = Text\BBCode::getAbstract($item['body'], Protocol::STATUSNET); break; @@ -125,8 +184,8 @@ class ItemContent extends BaseObject $msg = trim(str_replace($link, '', $msg)); } elseif (($limit == 0) || ($pos < $limit)) { // The limit has to be increased since it will be shortened - but not now - // Only do it with Twitter (htmlmode = 8) - if (($limit > 0) && (strlen($link) > 23) && ($htmlmode == 8)) { + // Only do it with Twitter + if (($limit > 0) && (strlen($link) > 23) && ($htmlmode == BBCode::TWITTER)) { $limit = $limit - 23 + strlen($link); } @@ -159,7 +218,7 @@ class ItemContent extends BaseObject $post['url'] = $item['plink']; } elseif (strpos($item['body'], '[share') !== false) { $post['url'] = $item['plink']; - } elseif (PConfig::get($item['uid'], 'system', 'no_intelligent_shortening')) { + } elseif (DI::pConfig()->get($item['uid'], 'system', 'no_intelligent_shortening')) { $post['url'] = $item['plink']; } $msg = Text\Plaintext::shorten($msg, $limit);