Skip to content

Instantly share code, notes, and snippets.

View artlung's full-sized avatar
💭
🤖

Joe Crawford artlung

💭
🤖
View GitHub Profile
@artlung
artlung / excerpt.php
Created March 12, 2024 18:46
Yet another PHP excerpt function
/**
* @param $text
* @param int $maxLength (default 200 characters)
* @param string $ending (characters to append to the end of the excerpt)
* @return string
*/
function excerpt($text, int $maxLength = 200, string $ending = '...'): string
{
// collapse whitespace
$text = preg_replace('/\s+/', ' ', $text);
@artlung
artlung / update-wp-links-with-rss.php
Created March 7, 2024 07:19
UPDATE WORDPRESS LINKS DATABASE WITH FEED URLS via COMMAND LINE
@artlung
artlung / RoanokeVisualization.php
Last active March 4, 2024 07:39
ArtLung Blog "Roanoke" WordPress Theme Blog Visualization Shortcode. Not packed as a plugin, would need to be modified to add to your blog. I may at some point package it up into a plugin form but feel free to extend, modify, share.
<?php
/**
* Class RoanokeVisualization
* Creates a visualization of blog posts by year and month
* and breaks out posts, and posts with Instagram and Delicious tags
*
* Uses wp_get_archives to get the data
* Uses wp_cache to store the data from expensive operations
*
@artlung
artlung / composer.json
Last active February 26, 2024 21:36
Parse Images for Colors and Populate a CSS File. Uses composer library ColorExtractor
{
"name": "artlung/parse-images-for-color",
"autoload": {
"psr-4": {
"Artlung\\ParseImagesForColor\\": "src/"
}
},
"authors": [
{
"name": "Joe Crawford",
@artlung
artlung / tilde.map.php
Created February 22, 2024 01:40
Server Side Image Map for tilde.club
<?php
$defaultLink = 'https://tilde.club/~harper/link.html?action=join';
$links = [
'left' => [
'url' => 'https://tilde.club/~harper/link.html?action=join',
'x1' => 0,
'y1' => 0,
'x2' => 129,
@artlung
artlung / 2004.html
Last active January 4, 2024 15:27
Header 2004 vs 2024
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<td colspan="3" bgcolor="#534741"><img src="https://artlung.com/images/blank.gif" height="1" width="1" alt=""></td>
</tr>
<tr valign="top">
<td align="left" width="33%" rowspan="2">
<img src="https://artlung.com/images/20040604_artlung.gif" width="231" height="75" alt="artlung.">
</td>
<td align="center" width="33%" rowspan="2">
<img src="https://artlung.com/images/20040613_farmer_joe.jpg" width="303" height="200" alt="in a hat to protect from the sun, making some sort of funny face.">
@artlung
artlung / Roanoke.php
Last active November 9, 2023 02:25
This was because I wanted a sentence on my about page that would read: "This blog has 8,586 posts, 2,353 comments, 5,936 embedded images, and 3,258 outbound links." https://artlung.com/about/ -- I use a cron to run the CLI prefixed files to update the outbound links and images. For your use, possibly.
<?php
/**
* class Roanoke
*/
class Roanoke {
// Note, this depends on every post having a post_image_count and post_link_count
public static function postStatsSentence() {
$number_of_published_posts = wp_count_posts()->publish;
<?php
$year = 2024;
$adult_days_and_prices = [
'wed' => 59,
'thu' => 79,
'fri' => 79,
'sat' => 79,
'sun' => 54,
@artlung
artlung / RoanokeMenuExampleUsage.php
Last active October 26, 2023 21:53
I wanted to replace the text of my menu with font awesome icons so I created a new walker class to do replacements for links with specific outbound links. Not at all generic but I wanted to stash it. I'm sure there are better ways to do this.
<?php
// https://developer.wordpress.org/reference/functions/wp_nav_menu/
$args = [
'menu' => 'roanoke-menu-bar',
'container' => 'nav',
'container_class' => 'roanoke-menu-bar',
'container_aria_label' => 'Menu Bar',
'walker' => new RoanokeMenuWalker(),
];
@artlung
artlung / thumb.php
Last active September 27, 2023 15:04
Multiple Image Thumbnails - Command line PHP tool to generate image to represent multiple images
<?php
// By Joe Crawford joe@artlung.com
// September 2023
// intended to be run from the command line
// php thumb.php
// place images in the same directory as this script and their names in the array below
// or place urls in the array below - filenames must be unique
// height and width of the final image, for now the math relies on everything being square