<?php require_once 'AMP/Base/Config.php'; require_once 'AMP/Content/RouteSlug/RouteSlug.php'; if (!($raw_slug_name = AMP_params('slug_name'))) { exit; } $finder = new AMP_Content_RouteSlug(AMP_dbcon()); $slug_name = $finder->clean($raw_slug_name); $raw_matches = $finder->find(array('name' => $slug_name)); $exceptions = AMP_params('ignore'); $matches = array(); if (!empty($raw_matches) && $exceptions) { foreach ($exceptions as $ignore) { foreach ($raw_matches as $match_key => $match) { if (!($match->getData('owner_type') == $ignore['owner_type'] and $match->getData('owner_id') == $ignore['owner_id'])) { $matches[] = $match; } } } } else { $matches = $raw_matches; } if (empty($matches)) { print AMP_to_json(array('clean_url' => $slug_name, 'conflicts' => array())); exit; } $match_results = array(); foreach ($matches as $route) { $owner = $route->getOwner(); $match_results[] = array_merge($route->getData(), array('owner_edit_url' => $owner->get_url_edit()));
function _save_route_slug() { if (!AMP_CONTENT_HUMANIZE_URLS) { return true; } $finder = new AMP_Content_RouteSlug(AMP_dbcon()); $slugs = $finder->find(array('owner_type' => 'section', 'owner_id' => $this->id)); $assigned_slug = $this->getData('route_slug'); if (empty($slugs) && !$assigned_slug) { return true; } $slug_exists = false; foreach ($slugs as $slug) { if ($slug->getName() == $assigned_slug) { $slug_exists = true; continue; } $slug->delete(); } if ($slug_exists) { return true; } $slug = $finder; $slug->mergeData(array('owner_type' => 'section', 'owner_id' => $this->id, 'name' => $assigned_slug)); $slug->force_valid_slug(); return $slug->save(); }