/* -, since sometimes a dot is desired. Changed default alias to yyyy-mm-dd.id. 0.92 Added question mark to replacement array 0.91 Added punctuation to the replacement array. 0.90 Fixed problems with the strtr function in MODx 0.9.5.1 and above. Added more code comments. Added ability to use the document's ID in the alias. (thanks Doze.) @install: Paste this text into a new plugin called CustomAlias. Check the OnDocFormSave event checkbox. Customize. @defaults: The default output of this plugin is: pagetitle.yyyymmdd.id where yyyymmdd is set by the pub_date, createdon, or the current time, depending on which is available. @customize: Go through the code and change or comment as necessary to achieve desired results. */ // Get the relevant dates $published = $_POST['pub_date']; $created = $_POST['createdon']; $edited = time(); // Set which date value to use if ($published != '') { $date = $published; } elseif ($created != '') { $date = $created; } else { $date = $edited; } // Set the date formatting $dateFormatString = '%Y-%m-%d'; $date = strftime($dateFormatString, $date); // Get the ID of the document, if you want to use it in your alias $id = $modx->event->params['id']; // ***************************************************************** // EDIT HERE: // ***************************************************************** //$alias_new = $_POST['pagetitle'].'.'.$date.$id; $alias_new = $date . '.' . $id; // ***************************************************************** // YOU CAN STOP EDITING HERE. // ***************************************************************** // The cleansing and setting of the alias. $e = &$modx->Event; // Only on this event if ($e->name == 'OnDocFormSave') { // Check if the alias is empty if ($_POST['alias'] == '') { // Convert accented characters to their non-accented counterparts. $replace_array = array( // Punctuation and special characters ' ' => '-', ',' => '-', '?' => '-', '"' => '-', '\'' => '-', ',' => '-', ':' => '-', '/' => '-', '\\' => '-', //'.' => '-', '!' => '-', '@' => '-', '#' => '-', '$' => '-', '%' => '-', '^' => '-', '&' => 'and', '*' => '-', '(' => '-', ')' => '-', '[' => '-', ']' => '-', '=' => '-', // Letters 'À' => 'A', 'À' => 'A', 'Á' => 'A', 'Á' => 'A', 'Â' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ã' => 'A', 'Ä' => 'e', 'Ä' => 'A', 'Å' => 'A', 'Å' => 'A', 'Æ' => 'e', 'Æ' => 'E', 'Ā' => 'A', 'Ą' => 'A', 'Ă' => 'A', 'Ç' => 'C', 'Ç' => 'C', 'Ć' => 'C', 'Č' => 'C', 'Ĉ' => 'C', 'Ċ' => 'C', 'Ď' => 'D', 'Đ' => 'D', 'È' => 'E', 'È' => 'E', 'É' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ë' => 'E', 'Ē' => 'E', 'Ę' => 'E', 'Ě' => 'E', 'Ĕ' => 'E', 'Ė' => 'E', 'Ĝ' => 'G', 'Ğ' => 'G', 'Ġ' => 'G', 'Ģ' => 'G', 'Ĥ' => 'H', 'Ħ' => 'H', 'Ì' => 'I', 'Ì' => 'I', 'Í' => 'I', 'Í' => 'I', 'Î' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ï' => 'I', 'Ī' => 'I', 'Ĩ' => 'I', 'Ĭ' => 'I', 'Į' => 'I', 'İ' => 'I', 'IJ' => 'J', 'Ĵ' => 'J', 'Ķ' => 'K', 'Ľ' => 'K', 'Ĺ' => 'K', 'Ļ' => 'K', 'Ŀ' => 'K', 'Ñ' => 'N', 'Ñ' => 'N', 'Ń' => 'N', 'Ň' => 'N', 'Ņ' => 'N', 'Ŋ' => 'N', 'Ò' => 'O', 'Ò' => 'O', 'Ó' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Õ' => 'O', 'Ö' => 'e', 'Ö' => 'e', 'Ø' => 'O', 'Ø' => 'O', 'Ō' => 'O', 'Ő' => 'O', 'Ŏ' => 'O', 'Œ' => 'E', 'Ŕ' => 'R', 'Ř' => 'R', 'Ŗ' => 'R', 'Ś' => 'S', 'Ş' => 'S', 'Ŝ' => 'S', 'Ș' => 'S', 'Ť' => 'T', 'Ţ' => 'T', 'Ŧ' => 'T', 'Ț' => 'T', 'Ù' => 'U', 'Ù' => 'U', 'Ú' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Û' => 'U', 'Ü' => 'e', 'Ū' => 'U', 'Ü' => 'e', 'Ů' => 'U', 'Ű' => 'U', 'Ŭ' => 'U', 'Ũ' => 'U', 'Ų' => 'U', 'Ŵ' => 'W', 'Ŷ' => 'Y', 'Ÿ' => 'Y', 'Ź' => 'Z', 'Ż' => 'Z', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'e', 'ä' => 'e', 'å' => 'a', 'ā' => 'a', 'ą' => 'a', 'ă' => 'a', 'å' => 'a', 'æ' => 'e', 'ç' => 'c', 'ć' => 'c', 'č' => 'c', 'ĉ' => 'c', 'ċ' => 'c', 'ď' => 'd', 'đ' => 'd', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ē' => 'e', 'ę' => 'e', 'ě' => 'e', 'ĕ' => 'e', 'ė' => 'e', 'ƒ' => 'f', 'ĝ' => 'g', 'ğ' => 'g', 'ġ' => 'g', 'ģ' => 'g', 'ĥ' => 'h', 'ħ' => 'h', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ī' => 'i', 'ĩ' => 'i', 'ĭ' => 'i', 'į' => 'i', 'ı' => 'i', 'ij' => 'j', 'ĵ' => 'j', 'ķ' => 'k', 'ĸ' => 'k', 'ł' => 'l', 'ľ' => 'l', 'ĺ' => 'l', 'ļ' => 'l', 'ŀ' => 'l', 'ñ' => 'n', 'ń' => 'n', 'ň' => 'n', 'ņ' => 'n', 'ʼn' => 'n', 'ŋ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'e', 'ö' => 'e', 'ø' => 'o', 'ō' => 'o', 'ő' => 'o', 'ŏ' => 'o', 'œ' => 'e', 'ŕ' => 'r', 'ř' => 'r', 'ŗ' => 'r', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'e', 'ū' => 'u', 'ü' => 'e', 'ů' => 'u', 'ű' => 'u', 'ŭ' => 'u', 'ũ' => 'u', 'ų' => 'u', 'ŵ' => 'w', 'ÿ' => 'y', 'ŷ' => 'y', 'ż' => 'z', 'ź' => 'z', 'ß' => 's', 'ſ' => 's', 'Α' => 'A', 'Ά' => 'A', 'Β' => 'B', 'Γ' => 'G', 'Δ' => 'D', 'Ε' => 'E', 'Έ' => 'E', 'Ζ' => 'Z', 'Η' => 'I', 'Ή' => 'I', 'Θ' => 'TH', 'Ι' => 'I', 'Ί' => 'I', 'Ϊ' => 'I', 'Κ' => 'K', 'Λ' => 'L', 'Μ' => 'M', 'Ν' => 'N', 'Ξ' => 'KS', 'Ο' => 'O', 'Ό' => 'O', 'Π' => 'P', 'Ρ' => 'R', 'Σ' => 'S', 'Τ' => 'T', 'Υ' => 'Y', 'Ύ' => 'Y', 'Ϋ' => 'Y', 'Φ' => 'F', 'Χ' => 'X', 'Ψ' => 'PS', 'Ω' => 'O', 'Ώ' => 'O', 'α' => 'a', 'ά' => 'a', 'β' => 'b', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'έ' => 'e', 'ζ' => 'z', 'η' => 'i', 'ή' => 'i', 'θ' => 'th', 'ι' => 'i', 'ί' => 'i', 'ϊ' => 'i', 'ΐ' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => 'ks', 'ο' => 'o', 'ό' => 'o', 'π' => 'p', 'ρ' => 'r', 'σ' => 's', 'τ' => 't', 'υ' => 'y', 'ύ' => 'y', 'ϋ' => 'y', 'ΰ' => 'y', 'φ' => 'f', 'χ' => 'x', 'ψ' => 'ps', 'ω' => 'o', 'ώ' => 'o' ); $alias_new = strtr($alias_new, $replace_array); $alias_new = str_replace('--',"-",$alias_new); $alias_new = str_replace('--',"-",$alias_new); $alias_new = str_replace('--',"-",$alias_new); $alias_new = strtolower($alias_new); $alias_new = urlencode($alias_new); $fields = array('alias' => $alias_new); $table = $modx->getFullTableName('site_content'); // Update the database $rows_affected = $modx->db->update( $fields, $table, "id = {$e->params['id']}" ); //flush_cache(); // Generate an error if the DB was not updated if(!$rows_affected) { $modx->event->alert("CustomAlias: An error occurred when saving the alias."); } } } $e->output('hello'.$parentID); // ?>