Channel Apps

navigation

β˜…Blog β˜…Anleitungen/Tutorials β˜…Lese-Log
Es gibt gesamt 11 Artikel
Anleitungen/Tutorials - WÀhle doch eine Kategorie zur besseren Übersicht
πŸ“Š Artikel pro Kategorie: - Android: 1 Artikel - Datenbank: 5 Artikel - Fediverse: 1 Artikel - GrapheneOS: 1 Artikel - Hubzilla: 11 Artikel - Nextcloud: 1 Artikel - Tutorials: 11 Artikel

Man kann sich in Hubzilla mit PHP jeden Wert aus der Datenbank holen, in einem Block ablegen und als Widget auf der Seite anzeigen lassen. Dazu muss die Hubzilla-App "Webseiten" installiert sein und die App "PDL Editor". Dann muss man auf seinem Kanal noch einstellen das Code zugelassen wird. Das aktiviert man unter Administration - KanΓ€le - Checkbox des Kanals anklicken - Code erlauben

Dann klickt man auf Webseiten - BlΓΆcke - Erstellen - Art des Seiteninhalts - PHP

Als Blockname vergibt man einen Namen unter dem man den Block spΓ€ter im PDL Editor unter Items findet

Translated with DeepL.com (free version)

In Hubzilla, you can use PHP to retrieve any value from the database, store it in a block and display it as a widget on the page. To do this, you need to install the Hubzilla app "Websites" and the app "PDL Editor". Then you have to set your channel to allow code. This can be activated under Administration - Channels - Click the channel checkbox - Allow code

Then click on Websites - Blocks - Create - Type of page content - PHP

Assign a name to the block that you can later find in the PDL Editor under Items.

Bildschirmfoto vom Blockeditor

Hier der Code zum kopieren:

Here is the code to copy:

$host = 'localhost';
$dbname = 'Name der Datenbank'; //=== Anpassen ===
$user = 'Name des Datenbankusers'; //=== Anpassen ===
$password = 'Datenbank-Passwort'; //=== Anpassen ===

try {
$pdo = new PDO(
"mysql:host=$host;dbname=$dbname;charset=utf8mb4",
$user,
$password,
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
} catch (PDOException $e) {
die('Verbindung fehlgeschlagen: ' . $e->getMessage());
}

$sql = "SELECT COUNT(*) AS anzahl FROM term WHERE term = :status";
$stmt = $pdo->prepare($sql);
$status = 'Kategoriename'; //=== Anpassen ===
$stmt->bindParam(':status', $status, PDO::PARAM_STR);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);

// ==== Ergebnis ausgeben ====
echo "Es gibt {$row['anzahl']} Artikel";

Anmerkung: Es müssen 4 Werte angepasst werden, wichtig ist der "Kategoriename", denn die Anzahl derer wird aus der Datenbank zusammengezÀhlt. Ich habe gestern noch keine anderen Werte in der riesigen Tabelle "term" gefunden wo scheinbar wirklich alles drin abgelegt wird woraus sich z.B. die Kategorie Artikel raus ableiten ließe.

Deswegen ist es wichtig, seinen Artikeln zusΓ€tzlich einen einzigartigen Kategorienamen zu geben der garantiert nicht anderweitig benutzt wird. Das sollte aber auch mit allem funktionieren was sich unter Kategorien ablegen lΓ€sst, z.B. Karten oder normale Posts, weil wie gesagt alles in der Tabelle Term abgelegt wird. Meine "term" hat nach 1 Woche bereits ΓΌber 37.000 EintrΓ€ge.

Ist das erledigt, geht man in den PDL Editor, wΓ€hlt unter Modules die Seite aus, auf der der Block angezeigt werden soll, z.B. articles und unter items ist der Block dann zu finden:

Note: Four values need to be adjusted, the most important being the "category name", as the number of these is calculated from the database. Yesterday, I couldn't find any other values in the huge "term" table, which seems to contain everything, from which the category "articles" could be derived, for example.

That is why it is important to give your articles a unique category name that is guaranteed not to be used elsewhere. However, this should also work with everything that can be stored under categories, e.g. cards or normal posts, because, as I said, everything is stored in the Term table. After one week, my "term" already has over 37,000 entries.

Once this is done, go to the PDL Editor, select the page on which the block is to be displayed under Modules, e.g. articles, and the block can then be found under items:

Bildschirmfoto des Blocks mit Ausgabe der Anzahl der Artikel

Wichtig/Important
https://voidofxulub.com/item/053efe40-7d7b-4bd4-ace1-f165f8d9ee54

#Hubzilla #Datenbank #MySQL