/** * Make a generic slug for most tables * * @param string $title What are we basing the URL off of? * @param string $table Which table to check for duplicates? * @param string $column Which column to check for duplicates? * @return string */ protected function makeGenericSlug(string $title, string $table, string $column = 'slug') : string { if (IDE_HACKS) { $this->db = \Airship\get_database(); } $query = 'SELECT count(*) FROM ' . $this->db->escapeIdentifier($table) . ' WHERE ' . $this->db->escapeIdentifier($column) . ' = ?'; $slug = $base_slug = \Airship\slugFromTitle($title); $i = 1; while ($this->db->cell($query, $slug) > 0) { $slug = $base_slug . '-' . ++$i; } return $slug; }
/** * Make a generic slug for most tables * * @param string $title What are we basing the URL off of? * @param string $year * @param string $month * @return string */ protected function makeBlogPostSlug(string $title, string $year = '', string $month = '') : string { if (empty($year)) { $year = \date('Y'); } if (empty($month)) { $month = \date('m'); } $query = 'SELECT count(*) FROM view_hull_blog_list WHERE blogmonth = ? AND blogyear = ? AND slug = ?'; $slug = $base_slug = \Airship\slugFromTitle($title); $i = 1; while ($this->db->exists($query, $month, $year, $slug)) { $slug = $base_slug . '-' . ++$i; } return $slug; }
/** * @covers \Airship\slugFromTitle() */ public function testSlugFromTitle() { $this->assertSame('a-b', \Airship\slugFromTitle('A - B')); $this->assertSame('using-encryption-and-authentication-correctly-for-php-developers', \Airship\slugFromTitle('Using Encryption and Authentication Correctly (for PHP developers)')); $this->assertSame('using-encryption-and-authentication-correctly-for-php-developers', \Airship\slugFromTitle('--- --- -- - Using Encryption and Authentication Correctly (for PHP developers) --- --- --')); $this->assertSame('implementing-secure-user-authentication-in-php-applications-with-long-term-persistence-login-with-remember-me-cookies', \Airship\slugFromTitle('Implementing Secure User Authentication in PHP Applications with Long-Term Persistence (Login with "Remember Me" Cookies)')); }