Merge pull request #4198 from zeroadam/Files-#3878
Move include/files to src
This commit is contained in:
commit
a2d3cee006
|
@ -1,55 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
function create_files_from_item($itemid)
|
|
||||||
{
|
|
||||||
$messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `file`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
|
|
||||||
if (!$messages) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$message = $messages[0];
|
|
||||||
|
|
||||||
// Clean up all tags
|
|
||||||
q("DELETE FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)",
|
|
||||||
intval(TERM_OBJ_POST),
|
|
||||||
intval($itemid),
|
|
||||||
intval(TERM_FILE),
|
|
||||||
intval(TERM_CATEGORY));
|
|
||||||
|
|
||||||
if ($message["deleted"])
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (preg_match_all("/\[(.*?)\]/ism", $message["file"], $files)) {
|
|
||||||
foreach ($files[1] as $file) {
|
|
||||||
q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`) VALUES (%d, %d, %d, %d, '%s')",
|
|
||||||
intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_FILE), dbesc($file));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preg_match_all("/\<(.*?)\>/ism", $message["file"], $files)) {
|
|
||||||
foreach ($files[1] as $file) {
|
|
||||||
q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`) VALUES (%d, %d, %d, %d, '%s')",
|
|
||||||
intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), dbesc($file));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_files_from_itemuri($itemuri, $uid)
|
|
||||||
{
|
|
||||||
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
|
|
||||||
|
|
||||||
if (count($messages)) {
|
|
||||||
foreach ($messages as $message)
|
|
||||||
create_files_from_item($message["id"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function update_files_for_items()
|
|
||||||
{
|
|
||||||
$messages = q("SELECT `id` FROM `item` where file !=''");
|
|
||||||
|
|
||||||
foreach ($messages as $message) {
|
|
||||||
echo $message["id"] . "\n";
|
|
||||||
create_files_from_item($message["id"]);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,6 +12,7 @@ use Friendica\Database\DBM;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\GContact;
|
use Friendica\Model\GContact;
|
||||||
use Friendica\Model\Group;
|
use Friendica\Model\Group;
|
||||||
|
use Friendica\Model\Term;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Object\Image;
|
use Friendica\Object\Image;
|
||||||
use Friendica\Protocol\DFRN;
|
use Friendica\Protocol\DFRN;
|
||||||
|
@ -21,7 +22,6 @@ use Friendica\Util\ParseUrl;
|
||||||
|
|
||||||
require_once 'include/bbcode.php';
|
require_once 'include/bbcode.php';
|
||||||
require_once 'include/tags.php';
|
require_once 'include/tags.php';
|
||||||
require_once 'include/files.php';
|
|
||||||
require_once 'include/text.php';
|
require_once 'include/text.php';
|
||||||
require_once 'include/threads.php';
|
require_once 'include/threads.php';
|
||||||
require_once 'include/plaintext.php';
|
require_once 'include/plaintext.php';
|
||||||
|
@ -1109,7 +1109,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
|
||||||
* This is not perfect - but a workable solution until we found the reason for the problem.
|
* This is not perfect - but a workable solution until we found the reason for the problem.
|
||||||
*/
|
*/
|
||||||
create_tags_from_item($current_post);
|
create_tags_from_item($current_post);
|
||||||
create_files_from_item($current_post);
|
Term::createFromItem($current_post);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If this is now the last-child, force all _other_ children of this parent to *not* be last-child
|
* If this is now the last-child, force all _other_ children of this parent to *not* be last-child
|
||||||
|
@ -2157,7 +2157,7 @@ function drop_item($id, $interactive = true) {
|
||||||
array('id' => $item['id']));
|
array('id' => $item['id']));
|
||||||
|
|
||||||
create_tags_from_item($item['id']);
|
create_tags_from_item($item['id']);
|
||||||
create_files_from_item($item['id']);
|
Term::createFromItem($item['id']);
|
||||||
delete_thread($item['id'], $item['parent-uri']);
|
delete_thread($item['id'], $item['parent-uri']);
|
||||||
|
|
||||||
// clean up categories and tags so they don't end up as orphans
|
// clean up categories and tags so they don't end up as orphans
|
||||||
|
@ -2230,7 +2230,7 @@ function drop_item($id, $interactive = true) {
|
||||||
array('parent-uri' => $item['parent-uri'], 'uid' => $item['uid']));
|
array('parent-uri' => $item['parent-uri'], 'uid' => $item['uid']));
|
||||||
|
|
||||||
create_tags_from_itemuri($item['parent-uri'], $item['uid']);
|
create_tags_from_itemuri($item['parent-uri'], $item['uid']);
|
||||||
create_files_from_itemuri($item['parent-uri'], $item['uid']);
|
Term::createFromItemURI($item['parent-uri'], $item['uid']);
|
||||||
delete_thread_uri($item['parent-uri'], $item['uid']);
|
delete_thread_uri($item['parent-uri'], $item['uid']);
|
||||||
// ignore the result
|
// ignore the result
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Friendica\Core\Config;
|
||||||
use Friendica\Core\PConfig;
|
use Friendica\Core\PConfig;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\DBM;
|
use Friendica\Database\DBM;
|
||||||
|
use Friendica\Model\Term;
|
||||||
use Friendica\Util\Map;
|
use Friendica\Util\Map;
|
||||||
|
|
||||||
require_once "include/friendica_smarty.php";
|
require_once "include/friendica_smarty.php";
|
||||||
|
@ -1895,9 +1896,8 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function file_tag_save_file($uid, $item, $file) {
|
function file_tag_save_file($uid, $item, $file)
|
||||||
require_once "include/files.php";
|
{
|
||||||
|
|
||||||
if (! intval($uid)) {
|
if (! intval($uid)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1915,7 +1915,7 @@ function file_tag_save_file($uid, $item, $file) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
create_files_from_item($item);
|
Term::createFromItem($item);
|
||||||
|
|
||||||
$saved = PConfig::get($uid, 'system', 'filetags');
|
$saved = PConfig::get($uid, 'system', 'filetags');
|
||||||
if (!strlen($saved) || !stristr($saved, '[' . file_tag_encode($file) . ']')) {
|
if (!strlen($saved) || !stristr($saved, '[' . file_tag_encode($file) . ']')) {
|
||||||
|
@ -1926,9 +1926,8 @@ function file_tag_save_file($uid, $item, $file) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function file_tag_unsave_file($uid, $item, $file, $cat = false) {
|
function file_tag_unsave_file($uid, $item, $file, $cat = false)
|
||||||
require_once "include/files.php";
|
{
|
||||||
|
|
||||||
if (! intval($uid)) {
|
if (! intval($uid)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1955,7 +1954,7 @@ function file_tag_unsave_file($uid, $item, $file, $cat = false) {
|
||||||
intval($uid)
|
intval($uid)
|
||||||
);
|
);
|
||||||
|
|
||||||
create_files_from_item($item);
|
Term::createFromItem($item);
|
||||||
|
|
||||||
$r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d",
|
$r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d",
|
||||||
dbesc($file),
|
dbesc($file),
|
||||||
|
|
|
@ -29,7 +29,6 @@ use Friendica\Util\Emailer;
|
||||||
|
|
||||||
require_once 'include/enotify.php';
|
require_once 'include/enotify.php';
|
||||||
require_once 'include/tags.php';
|
require_once 'include/tags.php';
|
||||||
require_once 'include/files.php';
|
|
||||||
require_once 'include/threads.php';
|
require_once 'include/threads.php';
|
||||||
require_once 'include/text.php';
|
require_once 'include/text.php';
|
||||||
require_once 'include/items.php';
|
require_once 'include/items.php';
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
namespace Friendica\Model;
|
namespace Friendica\Model;
|
||||||
|
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
|
use Friendica\Model\Term;
|
||||||
use dba;
|
use dba;
|
||||||
|
|
||||||
require_once 'include/tags.php';
|
require_once 'include/tags.php';
|
||||||
require_once 'include/files.php';
|
|
||||||
require_once 'include/threads.php';
|
require_once 'include/threads.php';
|
||||||
|
|
||||||
class Item
|
class Item
|
||||||
|
@ -52,7 +52,7 @@ class Item
|
||||||
}
|
}
|
||||||
|
|
||||||
create_tags_from_item($item['id']);
|
create_tags_from_item($item['id']);
|
||||||
create_files_from_item($item['id']);
|
Term::createFromItem($item['id']);
|
||||||
update_thread($item['id']);
|
update_thread($item['id']);
|
||||||
|
|
||||||
Worker::add(PRIORITY_HIGH, "Notifier", 'edit_post', $item['id']);
|
Worker::add(PRIORITY_HIGH, "Notifier", 'edit_post', $item['id']);
|
||||||
|
|
64
src/Model/Term.php
Normal file
64
src/Model/Term.php
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file src/Model/Term
|
||||||
|
*/
|
||||||
|
namespace Friendica\Model;
|
||||||
|
|
||||||
|
use dba;
|
||||||
|
|
||||||
|
require_once "include/dba.php";
|
||||||
|
|
||||||
|
class Term
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param integer $itemid item id
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function createFromItem($itemid)
|
||||||
|
{
|
||||||
|
$messages = dba::select('item', ['uid', 'deleted', 'file'], ['id' => $itemid], ['limit' => 1]);
|
||||||
|
if (!$messages) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = $messages[0];
|
||||||
|
|
||||||
|
// Clean up all tags
|
||||||
|
q("DELETE FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)",
|
||||||
|
intval(TERM_OBJ_POST),
|
||||||
|
intval($itemid),
|
||||||
|
intval(TERM_FILE),
|
||||||
|
intval(TERM_CATEGORY));
|
||||||
|
|
||||||
|
if ($message["deleted"])
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (preg_match_all("/\[(.*?)\]/ism", $message["file"], $files)) {
|
||||||
|
foreach ($files[1] as $file) {
|
||||||
|
dba::insert('term', ['uid' => $message["uid"], 'oid' => $itemid, 'otype' => TERM_OBJ_POST, 'type' => TERM_FILE, 'term' => $file]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match_all("/\<(.*?)\>/ism", $message["file"], $files)) {
|
||||||
|
foreach ($files[1] as $file) {
|
||||||
|
dba::insert('term', ['uid' => $message["uid"], 'oid' => $itemid, 'otype' => TERM_OBJ_POST, 'type' => TERM_CATEGORY, 'term' => $file]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $itemuri item uri
|
||||||
|
* @param integer $uid uid
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function createFromItemURI($itemuri, $uid)
|
||||||
|
{
|
||||||
|
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
|
||||||
|
|
||||||
|
if (count($messages)) {
|
||||||
|
foreach ($messages as $message) {
|
||||||
|
self::createFromItem($message["id"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ use Friendica\Model\Contact;
|
||||||
use Friendica\Model\GContact;
|
use Friendica\Model\GContact;
|
||||||
use Friendica\Model\Group;
|
use Friendica\Model\Group;
|
||||||
use Friendica\Model\Profile;
|
use Friendica\Model\Profile;
|
||||||
|
use Friendica\Model\Term;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Object\Image;
|
use Friendica\Object\Image;
|
||||||
use Friendica\Protocol\OStatus;
|
use Friendica\Protocol\OStatus;
|
||||||
|
@ -32,7 +33,6 @@ require_once "include/enotify.php";
|
||||||
require_once "include/threads.php";
|
require_once "include/threads.php";
|
||||||
require_once "include/items.php";
|
require_once "include/items.php";
|
||||||
require_once "include/tags.php";
|
require_once "include/tags.php";
|
||||||
require_once "include/files.php";
|
|
||||||
require_once "include/event.php";
|
require_once "include/event.php";
|
||||||
require_once "include/text.php";
|
require_once "include/text.php";
|
||||||
require_once "include/html2bbcode.php";
|
require_once "include/html2bbcode.php";
|
||||||
|
@ -2912,7 +2912,7 @@ class DFRN
|
||||||
intval($importer["uid"])
|
intval($importer["uid"])
|
||||||
);
|
);
|
||||||
create_tags_from_itemuri($uri, $importer["uid"]);
|
create_tags_from_itemuri($uri, $importer["uid"]);
|
||||||
create_files_from_itemuri($uri, $importer["uid"]);
|
Term::createFromItemURI($uri, $importer["uid"]);
|
||||||
update_thread_uri($uri, $importer["uid"]);
|
update_thread_uri($uri, $importer["uid"]);
|
||||||
} else {
|
} else {
|
||||||
$r = q(
|
$r = q(
|
||||||
|
@ -2925,7 +2925,7 @@ class DFRN
|
||||||
intval($importer["uid"])
|
intval($importer["uid"])
|
||||||
);
|
);
|
||||||
create_tags_from_itemuri($uri, $importer["uid"]);
|
create_tags_from_itemuri($uri, $importer["uid"]);
|
||||||
create_files_from_itemuri($uri, $importer["uid"]);
|
Term::createFromItemURI($uri, $importer["uid"]);
|
||||||
update_thread_uri($uri, $importer["importer_uid"]);
|
update_thread_uri($uri, $importer["importer_uid"]);
|
||||||
if ($item["last-child"]) {
|
if ($item["last-child"]) {
|
||||||
// ensure that last-child is set in case the comment that had it just got wiped.
|
// ensure that last-child is set in case the comment that had it just got wiped.
|
||||||
|
|
Loading…
Reference in a new issue