/** * Prepare entity SEF data * * @param \ElggEntity $entity Entity * @return array|false */ function seo_prepare_entity_data(\ElggEntity $entity) { $path = seo_get_path($entity->getURL()); if (!$path || $path == '/') { return false; } $type = $entity->getType(); switch ($type) { case 'user': if (elgg_is_active_plugin('profile')) { $sef_path = "/profile/{$entity->username}"; } break; case 'group': $subtype = $entity->getSubtype(); $registered = (array) get_registered_entity_types('group'); if (!$subtype || in_array($subtype, $registered)) { if ($subtype && elgg_language_key_exists("item:group:{$subtype}", 'en')) { $prefix = elgg_get_friendly_title(elgg_echo("item:group:{$subtype}", array(), 'en')); } else { $prefix = elgg_get_friendly_title(elgg_echo('item:group', array(), 'en')); } $friendly_title = elgg_get_friendly_title($entity->getDisplayName() ?: ''); $sef_path = "/{$prefix}/{$entity->guid}-{$friendly_title}"; } break; case 'object': $subtype = $entity->getSubtype(); $registered = (array) get_registered_entity_types('object'); if (in_array($subtype, $registered)) { if (elgg_language_key_exists("item:object:{$subtype}", 'en')) { $prefix = elgg_get_friendly_title(elgg_echo("item:object:{$subtype}", array(), 'en')); } else { $prefix = elgg_get_friendly_title($subtype); } $friendly_title = elgg_get_friendly_title($entity->getDisplayName() ?: ''); $sef_path = "/{$prefix}/{$entity->guid}-{$friendly_title}"; } break; } if (!$sef_path) { $sef_path = $path; } $sef_data = seo_get_data($entity->getURL()); if (!is_array($sef_data)) { $sef_data = array(); } $entity_sef_data = ['path' => $path, 'sef_path' => $sef_path, 'title' => $entity->getDisplayName(), 'description' => elgg_get_excerpt($entity->description), 'keywords' => is_array($entity->tags) ? implode(',', $entity->tags) : $entity->tags, 'guid' => $entity->guid]; if ($entity->guid != $entity->owner_guid) { $owner = $entity->getOwnerEntity(); if ($owner) { $entity_sef_data['owner'] = seo_prepare_entity_data($owner); } } if ($entity->guid != $entity->container_guid && $entity->owner_guid != $entity->container_guid) { $container = $entity->getContainerEntity(); if ($container) { $entity_sef_data['container'] = seo_prepare_entity_data($container); } } if (empty($sef_data['admin_defined'])) { $sef_data = array_merge($sef_data, $entity_sef_data); } else { foreach ($entity_sef_data as $key => $value) { if (empty($sef_data[$key])) { $sef_data[$key] = $value; } } } $entity_sef_metatags = elgg_trigger_plugin_hook('metatags', 'discovery', ['entity' => $entity, 'url' => elgg_normalize_url($sef_path)], []); if (!empty($entity_sef_metatags)) { foreach ($entity_sef_metatags as $key => $value) { if (empty($sef_data['admin_defined']) || empty($sef_data['metatags'][$key])) { $sef_data['metatags'][$key] = $value; } } } return $sef_data; }
<?php $uri = elgg_extract('page_uri', $vars); if (!$uri) { return; } $data = seo_get_data($uri); if (!$data) { $data = array(); } echo elgg_view_input('hidden', ['name' => 'seo[admin_defined]', 'value' => true]); $path = elgg_extract('path', $data, seo_get_path($uri)); echo elgg_view_input('hidden', ['name' => 'seo[path]', 'value' => $path]); echo elgg_view_input('text', ['value' => $path, 'disabled' => true, 'label' => elgg_echo('seo:path')]); echo elgg_view_input('text', ['name' => 'seo[sef_path]', 'value' => elgg_extract('sef_path', $data, $path), 'required' => true, 'label' => elgg_echo('seo:sef_path'), 'help' => elgg_echo('seo:sef_path:help')]); echo elgg_view_input('text', ['name' => 'seo[title]', 'value' => elgg_extract('title', $data), 'label' => elgg_echo('seo:title')]); echo elgg_view_input('text', ['name' => 'seo[description]', 'value' => elgg_extract('description', $data), 'label' => elgg_echo('seo:description')]); echo elgg_view_input('tags', ['name' => 'seo[keywords]', 'value' => elgg_extract('keywords', $data), 'label' => elgg_echo('seo:keywords')]); $tags = array('og:type', 'og:title', 'og:site_name', 'og:image', 'og:url', 'og:description', 'og:image', 'og:image:width', 'og:image:height', 'article:published_time', 'profile:username', 'article:author', 'article:tags', 'twitter:creator', 'fb:app_id', 'twitter:card', 'twitter:site', 'twitter:creator'); $metatags = (array) elgg_extract('metatags', $data, array()); foreach ($tags as $tag) { if (!array_key_exists($tag, $metatags)) { $metatags[$tag] = ''; } } foreach ($metatags as $tag => $value) { echo elgg_view_input('text', ['name' => "seo[metatags][{$tag}]", 'value' => $value, 'label' => $tag]); } echo elgg_view_input('submit', ['wrapper_class' => 'elgg-foot', 'value' => elgg_echo('save')]); ?> <script>