本文整理汇总了PHP中General::array_find_available_index方法的典型用法代码示例。如果您正苦于以下问题:PHP General::array_find_available_index方法的具体用法?PHP General::array_find_available_index怎么用?PHP General::array_find_available_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类General
的用法示例。
在下文中一共展示了General::array_find_available_index方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addElementToHead
public function addElementToHead($obj, $position = NULL)
{
if ($position && isset($this->_head[$position])) {
$position = General::array_find_available_index($this->_head, $position);
} elseif (!$position) {
$position = max(0, count($this->_head));
}
$this->_head[$position] = $obj;
return $position;
}
示例2: __buildNavigation
/**
* This function populates the `$_navigation` array with an associative array
* of all the navigation groups and their links. Symphony only supports one
* level of navigation, so children links cannot have children links. The default
* Symphony navigation is found in the `ASSETS/navigation.xml` folder. This is
* loaded first, and then the Section navigation is built, followed by the Extension
* navigation. Additionally, this function will set the active group of the navigation
* by checking the current page against the array of links.
*
* @link http://github.com/symphonycms/symphony-2/blob/master/symphony/assets/navigation.xml
*/
public function __buildNavigation()
{
$nav = array();
$xml = simplexml_load_file(ASSETS . '/navigation.xml');
// Loop over the default Symphony navigation file, converting
// it into an associative array representation
foreach ($xml->xpath('/navigation/group') as $n) {
$index = (string) $n->attributes()->index;
$children = $n->xpath('children/item');
$content = $n->attributes();
// If the index is already set, increment the index and check again.
// Rinse and repeat until the index is not set.
if (isset($nav[$index])) {
do {
$index++;
} while (isset($nav[$index]));
}
$nav[$index] = array('name' => __(strval($content->name)), 'index' => $index, 'children' => array());
if (strlen(trim((string) $content->limit)) > 0) {
$nav[$index]['limit'] = (string) $content->limit;
}
if (count($children) > 0) {
foreach ($children as $child) {
$item = array('link' => (string) $child->attributes()->link, 'name' => __(strval($child->attributes()->name)), 'visible' => (string) $child->attributes()->visible == 'no' ? 'no' : 'yes');
$limit = (string) $child->attributes()->limit;
if (strlen(trim($limit)) > 0) {
$item['limit'] = $limit;
}
$nav[$index]['children'][] = $item;
}
}
}
// Build the section navigation, grouped by their navigation groups
$sections = Symphony::Database()->fetch("SELECT * FROM `tbl_sections` ORDER BY `sortorder` ASC");
if (is_array($sections) && !empty($sections)) {
foreach ($sections as $s) {
$group_index = self::__navigationFindGroupIndex($nav, $s['navigation_group']);
if ($group_index === false) {
$group_index = General::array_find_available_index($nav, 0);
$nav[$group_index] = array('name' => $s['navigation_group'], 'index' => $group_index, 'children' => array());
}
$nav[$group_index]['children'][] = array('link' => '/publish/' . $s['handle'] . '/', 'name' => $s['name'], 'type' => 'section', 'section' => array('id' => $s['id'], 'handle' => $s['handle']), 'visible' => $s['hidden'] == 'no' ? 'yes' : 'no');
}
}
// Loop over all the installed extensions to add in other navigation items
$extensions = Symphony::ExtensionManager()->listInstalledHandles();
foreach ($extensions as $e) {
$info = Symphony::ExtensionManager()->about($e);
if (isset($info['navigation']) && is_array($info['navigation']) && !empty($info['navigation'])) {
foreach ($info['navigation'] as $item) {
$type = isset($item['children']) ? Extension::NAV_GROUP : Extension::NAV_CHILD;
switch ($type) {
case Extension::NAV_GROUP:
$index = General::array_find_available_index($nav, $item['location']);
$nav[$index] = array('name' => $item['name'], 'index' => $index, 'children' => array(), 'limit' => !is_null($item['limit']) ? $item['limit'] : null);
foreach ($item['children'] as $child) {
if (!isset($child['relative']) || $child['relative'] == true) {
$link = '/extension/' . $e . '/' . ltrim($child['link'], '/');
} else {
$link = '/' . ltrim($child['link'], '/');
}
$nav[$index]['children'][] = array('link' => $link, 'name' => $child['name'], 'visible' => $child['visible'] == 'no' ? 'no' : 'yes', 'limit' => !is_null($child['limit']) ? $child['limit'] : null);
}
break;
case Extension::NAV_CHILD:
if (!isset($item['relative']) || $item['relative'] == true) {
$link = '/extension/' . $e . '/' . ltrim($item['link'], '/');
} else {
$link = '/' . ltrim($item['link'], '/');
}
if (!is_numeric($item['location'])) {
// is a navigation group
$group_name = $item['location'];
$group_index = self::__navigationFindGroupIndex($nav, $item['location']);
} else {
// is a legacy numeric index
$group_index = $item['location'];
}
$child = array('link' => $link, 'name' => $item['name'], 'visible' => $item['visible'] == 'no' ? 'no' : 'yes', 'limit' => !is_null($item['limit']) ? $item['limit'] : null);
if ($group_index === false) {
$group_index = General::array_find_available_index($nav, 0);
// add new navigation group
$nav[$group_index] = array('name' => $group_name, 'index' => $group_index, 'children' => array($child), 'limit' => !is_null($item['limit']) ? $item['limit'] : null);
} else {
// add new location by index
$nav[$group_index]['children'][] = $child;
}
break;
}
//.........这里部分代码省略.........
示例3: addElementToHead
/**
* Adds an XMLElement to the `$this->_head` array at a desired position.
* If no position is given, the object will be added to the end
* of the `$this->_head` array. If that position is already taken, it will
* add the object at the next available position.
*
* @see toolkit.General#array_find_available_index()
* @param XMLElement $object
* @param integer $position
* Defaults to null which will put the `$object` at the end of the
* `$this->_head`.
* @param boolean $allowDuplicate
* If set to false, make this function check if there is already an XMLElement that as the same name in the head.
* Defaults to true. @since Symphony 2.3.2
* @return integer
* Returns the position that the `$object` has been set in the `$this->_head`
*/
public function addElementToHead(XMLElement $object, $position = null, $allowDuplicate = true)
{
// find the right position
if ($position && isset($this->_head[$position])) {
$position = General::array_find_available_index($this->_head, $position);
} elseif (is_null($position)) {
if (count($this->_head) > 0) {
$position = max(array_keys($this->_head)) + 1;
} else {
$position = 0;
}
}
// check if we allow duplicate
if (!$allowDuplicate && !empty($this->_head)) {
$this->removeFromHead($object->getName());
}
// append new element
$this->_head[$position] = $object;
return $position;
}
示例4: __buildNavigation
function __buildNavigation()
{
$nav = array();
$xml = simplexml_load_file(ASSETS . '/navigation.xml');
foreach ($xml->xpath('/navigation/group') as $n) {
$index = (string) $n->attributes()->index;
$children = $n->xpath('children/item');
$content = $n->attributes();
if (isset($nav[$index])) {
do {
$index++;
} while (isset($nav[$index]));
}
$nav[$index] = array('name' => __(strval($content->name)), 'index' => $index, 'children' => array());
if (strlen(trim((string) $content->limit)) > 0) {
$nav[$index]['limit'] = (string) $content->limit;
}
if (count($children) > 0) {
foreach ($children as $child) {
$limit = (string) $child->attributes()->limit;
$item = array('link' => (string) $child->attributes()->link, 'name' => __(strval($child->attributes()->name)), 'visible' => (string) $child->attributes()->visible == 'no' ? 'no' : 'yes');
if (strlen(trim($limit)) > 0) {
$item['limit'] = $limit;
}
$nav[$index]['children'][] = $item;
}
}
}
$sections = Symphony::Database()->fetch("SELECT * FROM `tbl_sections` ORDER BY `sortorder` ASC");
if (is_array($sections) && !empty($sections)) {
foreach ($sections as $s) {
$group_index = self::__navigationFindGroupIndex($nav, $s['navigation_group']);
if ($group_index === false) {
$group_index = General::array_find_available_index($nav, 0);
$nav[$group_index] = array('name' => $s['navigation_group'], 'index' => $group_index, 'children' => array(), 'limit' => NULL);
}
$nav[$group_index]['children'][] = array('link' => '/publish/' . $s['handle'] . '/', 'name' => $s['name'], 'type' => 'section', 'section' => array('id' => $s['id'], 'handle' => $s['handle']), 'visible' => $s['hidden'] == 'no' ? 'yes' : 'no');
}
}
$extensions = Administration::instance()->ExtensionManager->listInstalledHandles();
foreach ($extensions as $e) {
$info = Administration::instance()->ExtensionManager->about($e);
if (isset($info['navigation']) && is_array($info['navigation']) && !empty($info['navigation'])) {
foreach ($info['navigation'] as $item) {
$type = isset($item['children']) ? Extension::NAV_GROUP : Extension::NAV_CHILD;
switch ($type) {
case Extension::NAV_GROUP:
$index = General::array_find_available_index($nav, $item['location']);
$nav[$index] = array('name' => $item['name'], 'index' => $index, 'children' => array(), 'limit' => !is_null($item['limit']) ? $item['limit'] : NULL);
foreach ($item['children'] as $child) {
if (!isset($child['relative']) || $child['relative'] == true) {
$link = '/extension/' . $e . '/' . ltrim($child['link'], '/');
} else {
$link = '/' . ltrim($child['link'], '/');
}
$nav[$index]['children'][] = array('link' => $link, 'name' => $child['name'], 'visible' => $child['visible'] == 'no' ? 'no' : 'yes', 'limit' => !is_null($child['limit']) ? $child['limit'] : NULL);
}
break;
case Extension::NAV_CHILD:
if (!isset($item['relative']) || $item['relative'] == true) {
$link = '/extension/' . $e . '/' . ltrim($item['link'], '/');
} else {
$link = '/' . ltrim($item['link'], '/');
}
if (!is_numeric($item['location'])) {
// is a navigation group
$group_name = $item['location'];
$group_index = $this->__findLocationIndexFromName($nav, $item['location']);
} else {
// is a legacy numeric index
$group_index = $item['location'];
}
$child = array('link' => $link, 'name' => $item['name'], 'visible' => $item['visible'] == 'no' ? 'no' : 'yes', 'limit' => !is_null($item['limit']) ? $item['limit'] : NULL);
if ($group_index === false) {
// add new navigation group
$nav[] = array('name' => $group_name, 'index' => $group_index, 'children' => array($child), 'limit' => !is_null($item['limit']) ? $item['limit'] : NULL);
} else {
// add new location by index
$nav[$group_index]['children'][] = $child;
}
break;
}
}
}
}
####
# Delegate: ExtensionsAddToNavigation
# Description: After building the Navigation properties array. This is specifically
# for extentions to add their groups to the navigation or items to groups,
# already in the navigation. Note: THIS IS FOR ADDING ONLY! If you need
# to edit existing navigation elements, use the 'NavigationPreRender' delegate.
# Global: Yes
Administration::instance()->ExtensionManager->notifyMembers('ExtensionsAddToNavigation', '/backend/', array('navigation' => &$nav));
$pageCallback = Administration::instance()->getPageCallback();
$pageRoot = $pageCallback['pageroot'] . (isset($pageCallback['context'][0]) ? $pageCallback['context'][0] . '/' : '');
$found = $this->__findActiveNavigationGroup($nav, $pageRoot);
## Normal searches failed. Use a regular expression using the page root. This is less
## efficent and should never really get invoked unless something weird is going on
if (!$found) {
$this->__findActiveNavigationGroup($nav, '/^' . str_replace('/', '\\/', $pageCallback['pageroot']) . '/i', true);
//.........这里部分代码省略.........
示例5: addElementToHead
/**
* Adds an XMLElement to the `$this->_head` array at a desired position.
* If no position is given, the object will be added to the end
* of the `$this->_head` array. If that position is already taken, it will
* add the object at the next available position.
*
* @see toolkit.General#array_find_available_index()
* @param XMLElement $object
* @param integer $position
* Defaults to null which will put the `$object` at the end of the
* `$this->_head`.
* @return integer
* Returns the position that the `$object` has been set in the `$this->_head`
*/
public function addElementToHead(XMLElement $object, $position = null)
{
if ($position && isset($this->_head[$position])) {
$position = General::array_find_available_index($this->_head, $position);
} else {
if (is_null($position)) {
if (count($this->_head) > 0) {
$position = max(array_keys($this->_head)) + 1;
} else {
$position = 0;
}
}
}
$this->_head[$position] = $object;
return $position;
}
示例6: __buildNavigation
function __buildNavigation()
{
$nav = array();
$xml = new XmlDoc();
if (!$xml->parseFile(ASSETS . '/navigation.xml')) {
$this->_Parent->customError(E_USER_ERROR, __('Failed to load Navigation'), __('There was a problem loading the Symphony navigation XML document.'));
}
$nodes = $xml->getArray();
$sections_index = 0;
$extension_index = 0;
foreach ($nodes['navigation'] as $n) {
$content = $n['group']['attributes'];
$children = $n['group'][0]['children'];
$index = $n['group']['attributes']['index'];
if ($n['group']['attributes']['sections'] == 'true') {
$sections_index = $index;
}
if (isset($nav[$index])) {
do {
$index++;
} while (isset($nav[$index]));
}
if (!empty($content)) {
$nav[$index] = $content;
}
if (@is_array($children)) {
foreach ($children as $n) {
if (!empty($n['item']['attributes'])) {
$nav[$index]['children'][] = $n['item']['attributes'];
}
}
}
}
$sections = $this->_Parent->Database->fetch("SELECT * FROM `tbl_sections` ORDER BY `sortorder` ASC");
if (is_array($sections) && !empty($sections)) {
foreach ($sections as $s) {
//$visible = ($this->_Parent->Author->isDeveloper() || (!$this->_Parent->Author->isDeveloper() && in_array($s['id'], $this->_Parent->Author->getAuthorAllowableSections())));
$nav[$sections_index]['children'][] = array('link' => '/publish/' . $s['handle'] . '/', 'name' => $s['name'], 'type' => 'section', 'section' => array('id' => $s['id'], 'handle' => $s['handle']), 'visible' => $s['hidden'] == 'no' ? 'yes' : 'no');
}
}
$extensions = $this->_Parent->ExtensionManager->listInstalledHandles();
foreach ($extensions as $e) {
$info = $this->_Parent->ExtensionManager->about($e);
if (isset($info['navigation']) && is_array($info['navigation']) && !empty($info['navigation'])) {
foreach ($info['navigation'] as $item) {
$type = isset($item['children']) ? Extension::NAV_GROUP : Extension::NAV_CHILD;
switch ($type) {
case Extension::NAV_GROUP:
$index = General::array_find_available_index($nav, $item['location']);
$nav[$index] = array('name' => $item['name'], 'index' => $index, 'children' => array(), 'limit' => !is_null($item['limit']) ? $item['limit'] : NULL);
foreach ($item['children'] as $child) {
if (!isset($child['relative']) || $child['relative'] == true) {
$link = '/extension/' . $e . '/' . ltrim($child['link'], '/');
} else {
$link = '/' . ltrim($child['link'], '/');
}
$nav[$index]['children'][] = array('link' => $link, 'name' => $child['name'], 'visible' => $child['visible'] == 'no' ? 'no' : 'yes', 'limit' => !is_null($child['limit']) ? $child['limit'] : NULL);
}
break;
case Extension::NAV_CHILD:
if (!isset($item['relative']) || $item['relative'] == true) {
$link = '/extension/' . $e . '/' . ltrim($item['link'], '/');
} else {
$link = '/' . ltrim($item['link'], '/');
}
$nav[$item['location']]['children'][] = array('link' => $link, 'name' => $item['name'], 'visible' => $item['visible'] == 'no' ? 'no' : 'yes', 'limit' => !is_null($item['limit']) ? $item['limit'] : NULL);
break;
}
}
}
}
####
# Delegate: ExtensionsAddToNavigation
# Description: After building the Navigation properties array. This is specifically for extentions to add their groups to the navigation or items to groups,
# already in the navigation. Note: THIS IS FOR ADDING ONLY! If you need to edit existing navigation elements, use the 'NavigationPreRender' delegate.
# Global: Yes
$this->_Parent->ExtensionManager->notifyMembers('ExtensionsAddToNavigation', '/administration/', array('navigation' => &$nav));
$pageCallback = $this->_Parent->getPageCallback();
$pageRoot = $pageCallback['pageroot'] . (isset($pageCallback['context'][0]) ? $pageCallback['context'][0] . '/' : '');
$found = $this->__findActiveNavigationGroup($nav, $pageRoot);
## Normal searches failed. Use a regular expression using the page root. This is less efficent and should never really get invoked
## unless something weird is going on
if (!$found) {
$this->__findActiveNavigationGroup($nav, '/^' . str_replace('/', '\\/', $pageCallback['pageroot']) . '/i', true);
}
ksort($nav);
$this->_navigation = $nav;
}
示例7: buildExtensionsNavigation
/**
* This method fills the `$nav` array with value
* from each Extension's `fetchNavigation` method
*
* @since Symphony 2.3.2
*
* @param array $nav
* The navigation array that will receive nav nodes
* @throws Exception
* @throws SymphonyErrorPage
*/
private function buildExtensionsNavigation(&$nav)
{
// Loop over all the installed extensions to add in other navigation items
$extensions = Symphony::ExtensionManager()->listInstalledHandles();
foreach ($extensions as $e) {
$extension = Symphony::ExtensionManager()->getInstance($e);
$extension_navigation = $extension->fetchNavigation();
if (is_array($extension_navigation) && !empty($extension_navigation)) {
foreach ($extension_navigation as $item) {
$type = isset($item['children']) ? Extension::NAV_GROUP : Extension::NAV_CHILD;
switch ($type) {
case Extension::NAV_GROUP:
$index = General::array_find_available_index($nav, $item['location']);
// Actual group
$nav[$index] = self::createParentNavItem($index, $item);
// Render its children
foreach ($item['children'] as $child) {
$nav[$index]['children'][] = self::createChildNavItem($child, $e);
}
break;
case Extension::NAV_CHILD:
if (!is_numeric($item['location'])) {
// is a navigation group
$group_name = $item['location'];
$group_index = self::__navigationFindGroupIndex($nav, $item['location']);
} else {
// is a legacy numeric index
$group_index = $item['location'];
}
$child = self::createChildNavItem($item, $e);
if ($group_index === false) {
$group_index = General::array_find_available_index($nav, 0);
$nav_parent = self::createParentNavItem($group_index, $item);
$nav_parent['name'] = $group_name;
$nav_parent['children'] = array($child);
// add new navigation group
$nav[$group_index] = $nav_parent;
} else {
// add new location by index
$nav[$group_index]['children'][] = $child;
}
break;
}
}
}
}
}
示例8: buildExtensionsNavigation
/**
* This method fills the `$nav` array with value
* from each Extension's `fetchNavigation` method
*
* @since Symphony 2.3.2
*
* @param array $nav
* The navigation array that will receive nav nodes
*/
private function buildExtensionsNavigation(&$nav)
{
// Loop over all the installed extensions to add in other navigation items
$extensions = Symphony::ExtensionManager()->listInstalledHandles();
foreach ($extensions as $e) {
$extension = Symphony::ExtensionManager()->getInstance($e);
$extension_navigation = $extension->fetchNavigation();
if (is_array($extension_navigation) && !empty($extension_navigation)) {
foreach ($extension_navigation as $item) {
$type = isset($item['children']) ? Extension::NAV_GROUP : Extension::NAV_CHILD;
switch ($type) {
case Extension::NAV_GROUP:
$index = General::array_find_available_index($nav, $item['location']);
// Actual group
$nav[$index] = array('name' => $item['name'], 'type' => isset($item['type']) ? $item['type'] : 'structure', 'index' => $index, 'children' => array(), 'limit' => isset($item['limit']) ? $item['limit'] : null);
// Render its children
foreach ($item['children'] as $child) {
if (!isset($child['relative']) || $child['relative'] == true) {
$link = '/extension/' . $e . '/' . ltrim($child['link'], '/');
} else {
$link = '/' . ltrim($child['link'], '/');
}
$nav[$index]['children'][] = array('link' => $link, 'name' => $child['name'], 'visible' => isset($child['visible']) && $child['visible'] == 'no' ? 'no' : 'yes', 'limit' => isset($child['limit']) ? $child['limit'] : null, 'target' => isset($child['target']) ? $child['target'] : null);
}
break;
case Extension::NAV_CHILD:
if (!isset($item['relative']) || $item['relative'] == true) {
$link = '/extension/' . $e . '/' . ltrim($item['link'], '/');
} else {
$link = '/' . ltrim($item['link'], '/');
}
if (!is_numeric($item['location'])) {
// is a navigation group
$group_name = $item['location'];
$group_index = self::__navigationFindGroupIndex($nav, $item['location']);
} else {
// is a legacy numeric index
$group_index = $item['location'];
}
$child = array('link' => $link, 'name' => $item['name'], 'visible' => isset($item['visible']) && $item['visible'] == 'no' ? 'no' : 'yes', 'limit' => isset($item['limit']) ? $item['limit'] : null, 'target' => isset($item['target']) ? $item['target'] : null);
if ($group_index === false) {
$group_index = General::array_find_available_index($nav, 0);
// add new navigation group
$nav[$group_index] = array('name' => $group_name, 'index' => $group_index, 'children' => array($child), 'limit' => isset($item['limit']) ? $item['limit'] : null);
} else {
// add new location by index
$nav[$group_index]['children'][] = $child;
}
break;
}
}
}
}
}